char * get_query (query_data * qd) { char *line, *LinePtr; WritePrompt (); do { do { line = GetMultiLine (); if (line == NULL) { if (stdin == InFile) return (NULL); /* EOF */ if (InPipe) pclose (InFile); else fclose (InFile); InPipe = 0; InFile = stdin; } } while (line == NULL); LinePtr = ProcessCommands (line, qd); if (CommandsErrorStr) fprintf (stderr, "%s\n", CommandsErrorStr); } while (*LinePtr == '\0' && !Quitting); return (LinePtr); }
int main(void) { const OpenFileId INPUT = CONSOLE_INPUT; const OpenFileId OUTPUT = CONSOLE_OUTPUT; char line[MAX_LINE_SIZE]; char *argv[MAX_ARG_COUNT]; for (;;) { WritePrompt(OUTPUT); const unsigned lineSize = ReadLine(line, MAX_LINE_SIZE, INPUT); if (lineSize == 0) continue; if (PrepareArguments(line, argv, MAX_ARG_COUNT) == 0) { WriteError("too many arguments.", OUTPUT); continue; } // Comment and uncomment according to whether command line arguments // are given in the system call or not. const SpaceId newProc = Exec(line); //const SpaceId newProc = Exec(line, argv); // TO DO: check for errors when calling `Exec`; this depends on how // errors are reported. Join(newProc); // TO DO: is it necessary to check for errors after `Join` too, or // can you be sure that, with the implementation of the system // call handler you made, it will never give an error?; what // happens if tomorrow the implementation changes and new // error conditions appear? } return 0; // Never reached. }