diff --git a/src/frontend/numparam/general.h b/src/frontend/numparam/general.h index 7f4fb3667..f9e01eb87 100644 --- a/src/frontend/numparam/general.h +++ b/src/frontend/numparam/general.h @@ -42,7 +42,7 @@ bool alfanum(char c); char *stupcase(char *s); /***** primitive input-output ***/ -void rs(SPICE_DSTRINGPTR s); +int yes_or_no(void); char rc(void); int freadstr(FILE *f, SPICE_DSTRINGPTR dstr_p); diff --git a/src/frontend/numparam/mystring.c b/src/frontend/numparam/mystring.c index c7d4fc891..96e9d1a63 100644 --- a/src/frontend/numparam/mystring.c +++ b/src/frontend/numparam/mystring.c @@ -22,7 +22,35 @@ #include "ngspice/fteext.h" /* controlled_exit() */ -/***** primitive input-output ***/ +/* + * fetch a human answer to a y/n question from stdin + * insist on a single non white-space char on a '\n' terminated line + * return this char or '\n' or EOF + * return '\0' if the answer doesn't fit this pattern + */ + +int +yes_or_no(void) +{ + int first; + + do { + first = getchar(); + if (first == '\n' || first == EOF) + return first; + } while (isspace(first)); + + for (;;) { + int c = getchar(); + if (c == EOF) + return c; + if (c == '\n') + return tolower(first); + if (!isspace(c)) + first = '\0'; + } +} + bool ci_prefix(const char *p, const char *s) @@ -39,22 +67,6 @@ ci_prefix(const char *p, const char *s) } -void -rs(SPICE_DSTRINGPTR dstr_p) -{ - /* basic line input, limit= 80 chars */ - char c; - - spice_dstring_reinit(dstr_p); - do - { - c = (char) fgetc(stdin); - cadd(dstr_p, c); - } - while (!((c == '\r') || (c == '\n'))); -} - - /******* Strings ************ * are 0-terminated char arrays with a 2-byte trailer: max length. * the string mini-library is "overflow-safe" under these conditions: diff --git a/src/frontend/numparam/nupatest.c b/src/frontend/numparam/nupatest.c index 8437dd382..8c57e1d06 100644 --- a/src/frontend/numparam/nupatest.c +++ b/src/frontend/numparam/nupatest.c @@ -141,26 +141,6 @@ void gluepluslines( int imax) } } -#if 0 /* sjb - this is in mystring.c */ -void rs(char * s) /* 78 coumn limit */ -{ - int i; - unsigned char done; - char c; - int max=maxlen(s); - if ( max>78 ) { max=78 ;} - i=0; done=0; - scopy(s,""); - while ( ! done ) { - c=fgetc(stdin); - if ( (c>=' ')&&(c<='~') && (i