fix an endless loop waiting for y/n when the input is at EOF
reported by Calin Andrian Subject: [Ngspice-devel] Invaild number bug
This commit is contained in:
parent
467eb58244
commit
2854fa71d4
|
|
@ -42,7 +42,7 @@ bool alfanum(char c);
|
||||||
char *stupcase(char *s);
|
char *stupcase(char *s);
|
||||||
|
|
||||||
/***** primitive input-output ***/
|
/***** primitive input-output ***/
|
||||||
void rs(SPICE_DSTRINGPTR s);
|
int yes_or_no(void);
|
||||||
char rc(void);
|
char rc(void);
|
||||||
|
|
||||||
int freadstr(FILE *f, SPICE_DSTRINGPTR dstr_p);
|
int freadstr(FILE *f, SPICE_DSTRINGPTR dstr_p);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,35 @@
|
||||||
#include "ngspice/fteext.h" /* controlled_exit() */
|
#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
|
bool
|
||||||
ci_prefix(const char *p, const char *s)
|
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 ************
|
/******* Strings ************
|
||||||
* are 0-terminated char arrays with a 2-byte trailer: max length.
|
* are 0-terminated char arrays with a 2-byte trailer: max length.
|
||||||
* the string mini-library is "overflow-safe" under these conditions:
|
* the string mini-library is "overflow-safe" under these conditions:
|
||||||
|
|
|
||||||
|
|
@ -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<max) ) {
|
|
||||||
cadd(s,c); Inc(i);
|
|
||||||
}
|
|
||||||
done= (c=='\n') || (c=='\r');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void fwrites(FILE * f, char * s)
|
void fwrites(FILE * f, char * s)
|
||||||
{
|
{
|
||||||
fputs(s,f);
|
fputs(s,f);
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ Todo:
|
||||||
#include "ngspice/fteext.h" /* controlled_exit() */
|
#include "ngspice/fteext.h" /* controlled_exit() */
|
||||||
|
|
||||||
|
|
||||||
|
extern bool ft_batchmode;
|
||||||
|
|
||||||
void dump_symbols(tdico *dico_p);
|
void dump_symbols(tdico *dico_p);
|
||||||
|
|
||||||
char *nupa_inst_name;
|
char *nupa_inst_name;
|
||||||
|
|
@ -498,7 +500,6 @@ static void
|
||||||
nupa_done(void)
|
nupa_done(void)
|
||||||
{
|
{
|
||||||
/* int i; not needed so far, see below */
|
/* int i; not needed so far, see below */
|
||||||
char *reply; /* user reply */
|
|
||||||
SPICE_DSTRING rep; /* dynamic report */
|
SPICE_DSTRING rep; /* dynamic report */
|
||||||
int dictsize, nerrors;
|
int dictsize, nerrors;
|
||||||
|
|
||||||
|
|
@ -530,12 +531,17 @@ nupa_done(void)
|
||||||
nadd(&rep, nerrors);
|
nadd(&rep, nerrors);
|
||||||
cadd(&rep, '\n');
|
cadd(&rep, '\n');
|
||||||
printf("%s", spice_dstring_value(&rep));
|
printf("%s", spice_dstring_value(&rep));
|
||||||
printf("Numparam expansion errors: Run Spice anyway? y/n ?\n");
|
if (ft_batchmode)
|
||||||
spice_dstring_reinit(&rep);
|
|
||||||
rs(&rep);
|
|
||||||
reply = spice_dstring_value(&rep);
|
|
||||||
if (upcase(reply[0]) != 'Y')
|
|
||||||
controlled_exit(EXIT_FAILURE);
|
controlled_exit(EXIT_FAILURE);
|
||||||
|
for (;;) {
|
||||||
|
int c;
|
||||||
|
printf("Numparam expansion errors: Run Spice anyway? y/n ?\n");
|
||||||
|
c = yes_or_no();
|
||||||
|
if (c == 'n' || c == EOF)
|
||||||
|
controlled_exit(EXIT_FAILURE);
|
||||||
|
if (c == 'y')
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
linecountS = 0;
|
linecountS = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue