DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T m

⟦efdd5fa68⟧ TextFile

    Length: 3347 (0xd13)
    Types: TextFile
    Names: »manscreen.c«

Derivation

└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
    └─ ⟦this⟧ »cph85dist/mandelbrot/manscreen.c« 

TextFile

/*
 * (Textual) screen handling for Mandelbrot programs.
 * Also prompt/input routines and some other junk.
 */

#include		<stdio.h>
#include		<ctype.h>
#ifdef vms
#include		errno
#define	IO_ERROR	errno
#endif
#define FALSE	0
#define TRUE	1
#define	EOS	'\0'

extern char		line[];		/* General scratch (input line)	*/
extern double		atof();
extern char		*strchr();

/*
 * Prompt and read (integer/real/complex/string)
 */

getint(row, prompt, result, def_value, max_value)
int		row;
char		*prompt;
int		*result;
int		def_value;
int		max_value;
{
again:	*result = def_value;
	if (isatty(fileno(stdin))) {
	    scr_move(row, 1);
	    scr_eol();
	    printf("%s (0:%d) <%d>: ",
		prompt, max_value, def_value);
	    fflush(stdout);
	}
	if (gets(line) == NULL)
	    return (FALSE);
	if (line[0] != EOS)
	    *result = atoi(line);
	if (*result < 0 || *result > max_value) {
	    printf("\nvalue %d out of range 0 .. %d, try again",
		*result, max_value);
	    scr_eol();
	    goto again;
	}
	return (TRUE);
}

int
getdouble(row, prompt, result)
int		row;
char		*prompt;
double		*result;
{
again:	if (isatty(fileno(stdin))) {
	    scr_move(row, 1);
	    scr_eol();
	    printf("%s: ", prompt);
	    fflush(stdout);
	}
	if (gets(line) == NULL)
	    return (FALSE);
	if (line[0] == EOS) {
	    printf("No default permitted, try again\n");
	    goto again;
	}
	*result = atof(line);
	return (TRUE);
}

getcomplex(row, prompt, real, imag)
int		row;
char		*prompt;
double		*real, *imag;
{
	register char	*lp;

again:	if (isatty(fileno(stdin))) {
	    scr_move(row, 1);
	    scr_eol();
	    printf("%s: ", prompt);
	    fflush(stdout);
	}
	if (gets(line) == NULL)
	    return (FALSE);
	else if (line[0] == EOS) {
	    printf("No default permitted, try again\n");
	    goto again;
	}
	else if ((lp = strchr(line, ',')) == NULL) {
	    printf("Need two values, separated by a comma\n");
	    goto again;
	}
	*lp = EOS;
	*real = atof(line);
	*imag = atof(lp + 1);
	return (TRUE);
}

getstring(row, prompt, result, def_value)
int		row;
char		*prompt;
char		*result;
char		*def_value;
{
	strcpy(result, def_value);
	if (isatty(fileno(stdin))) {
	    scr_move(row, 1);
	    scr_eol();
	    printf("%s <%s>: ", prompt, result);
	    fflush(stdout);
	}
	if (gets(line) == NULL)
	    return (FALSE);
	if (line[0] != EOS)
	    strcpy(result, line);
	return (TRUE);
}
\f


/*
 * Display routines (text -- for commands)  These assume ANSI controls:
 *	scr_clear()	Clear screen, Home cursor
 *	scr_home()	Home cursor
 *	scr_move(r,c)	Move to row r, column c (upper-left == 1,1)
 *	scr_eol()	Clear to end of line
 */

scr_clear()
{
	scr_home();
	printf("\033[2J");			/* ANSI Erase display	*/
	printf("\033[?25h");			/* DEC force cursor on	*/
}

scr_home()
{
	scr_move(1, 1);
}

scr_move(row, col)
{
	printf("\033[%d;%dH", row, col);	/* ANSI Cursor Position	*/
}

scr_eol()
{
	printf("\033[K");			/* ANSI Erase Line	*/
}
\f


FILE *
fcreate(fname)
char		*fname;
/*
 * Create a text file
 */
{
	register FILE	*fd;
#ifdef vms
	/*
	 * This creates files in vanilla RMS on VMS V2
	 */
	int		channel;
	extern FILE *fdopen();

	if ((channel = creat(fname, 0, "rat=cr", "rfm=var")) == -1
	 || (fd = fdopen(channel, "w")) == NULL) {
	    perror(fname);
	    return (NULL);
	}
#else
	if ((fd = fopen(fname, "w")) == NULL) {
	    perror(fname);
	    return (NULL);
	}
#endif
	return (fd);
}