/*************************************************************************** * Copyright (C) 1994 Charles P. Peterson * * 4007 Enchanted Sun, San Antonio, Texas 78244-1254 * * Email: Charles_P_Peterson@fcircus.sat.tx.us * * * * This is free software with NO WARRANTY. * * See gfft.c, or run program itself, for details. * * Support is available for a fee. * *************************************************************************** * * Program: gfft--General FFT analysis * File: prompt.c * Purpose: prompt for and receive GFFT command string * Author: Charles Peterson (CPP) * History: 29-May-1993 CPP; Created. * Comments: * (1) Just to be nice, I'm considering EOF as an acceptable * way to terminate gfft. If it is preceded by a command on * the same line, that is allowed to complete first. * However, if DEBUG is defined, a message will be displayed * on the detection of EOF. (I seem to get EOF's for some * reason when debugging. Don't understand it yet.) * * (2) Currently commands are quite limited in length * inherently, so a limited buffer is quite OK. Sure, * it takes a few static bytes, but who's perfect? If * ever commands are allowed to get much larger I'll make it * dynamic, but now that seems like overdoing it in view of * how difficult C makes dealing with dynamic strings. * * (3) However, I'm not going to let an excessively long * command overwrite any other program data. That's why * this function is a little more tedious than it might * be if I used 'gets' or 'scanf'. */ #include #include /* _OSERR */ #include /* errno */ #include "gfft.h" void prompt_command (void) { static int iclosed = FALSE; int icharacter = 0; int i; if (iclosed) { gabort (EXIT_SUCCESS); } printf ("%s",PROMPT); for (i=0; i < COMMAND_BUFFER_SIZE-1; i++) { icharacter = getc (stdin); if (icharacter == EOF) { #ifdef _DEBUG fprintf (stderr,"\nerrno = %d; _OSERR = %d\n", errno, _OSERR); #endif if (i <= 0) /* error or EOF; shouldn't usually happen */ { gabort (EXIT_SUCCESS); } else /* Command termined by EOF; exit on next call */ { iclosed = TRUE; Command[i] = '\0'; break; } } else if (icharacter == '\n') { Command[i] = '\0'; break; } else { Command[i] = (char) icharacter; } } }