monitor() { register char chr; int timevec[2]; register int controlno; while (chr = getch()) { if (chr == '\\') { /* process control sequence */ if ((controlno = getescape(1)) == 0) continue; switch (controlno) { case C_EDIT: edit(); continue; case C_PRINT: print(); continue; case C_LIST: eval(1); continue; case C_EVAL: eval(0); Autoclear = TRUE; continue; case C_INCLUDE: include(0); cgprompt(); continue; case C_WRITE: writeout(); cgprompt(); continue; case C_CHDIR: newdirec(); cgprompt(); continue; case C_RESET: clear(1); continue; case C_GO: go(); continue; case C_QUIT: clrline(1); quit(); case C_SHELL: shell(); continue; case C_TIME: time(timevec); printf("%s", ctime(timevec)); clrline(0); continue; case C_APPEND: Autoclear = 0; clrline(0); continue; case C_MARK: getfilename(); prompt(0); continue; case C_BRANCH: branch(); prompt(0); continue; default: syserr("monitor: bad code %d", controlno); } } putch(chr); } if (Input == stdin) { if (Nodayfile >= 0) printf("\n"); } else fclose(Input); }
edit() { register char *p; LOCATION t_loc, loc; FILE *fp; char errbuf[ER_MAX_LEN + 1]; char input[MAX_LOC + 1]; char *editfile; char *ingedit; i4 rflag; STATUS status; i4 c; #ifdef CMS i4 Notempty = 1; #endif /* CMS */ GLOBALREF char *IIMOildInitLnDraw; FUNC_EXTERN char *getfilenm(); FUNC_EXTERN char *macro(); if (!Newline) { q_putc(Qryiop, '\n'); Newline = TRUE; } Autoclear = 0; editfile = getfilenm(); rflag = 0; if (*editfile == '\0') { rflag = 1; input[0] = EOS; if ((status = NMloc( TEMP, PATH, (char *)NULL, &t_loc)) || (status = LOuniq( ERx( "query" ), ERx( "edt" ), &t_loc))) { STcopy( ERx( "queryXXX" ), input ); } else { LOcopy( &t_loc, input, &loc ); } status = SIfopen( &loc, ERx( "w" ), (i4)SI_TXT, (i4)SI_MAX_TXT_REC, &fp ); } else { /* use the path and file name the user gave you */ STcopy(editfile, input); if (!(status = LOfroms(PATH & FILENAME, input, &loc))) status = SIfopen( &loc, ERx("w"), (i4)SI_TXT, (i4)SI_MAX_TXT_REC, &fp ); } if (status) { if (status == FAIL) errbuf[0] = '\0'; else ERreport(status, errbuf); putprintf(ERget(F_MO000C_Cant_create_qry_file), input, errbuf); cgprompt(); return(0); } if (q_ropen(Qryiop, 'r') == (struct qbuf *)NULL) /* edit: q_ropen 1 */ ipanic(E_MO0044_1500400); while ((c = (i4)q_getc(Qryiop)) > 0) SIputc((char)c, fp); SIclose(fp); if (Nodayfile >= 0) { putprintf(ERget(F_MO000D_editor_prompt)); SIflush(stdout); } /* ** macro returns NULL if undefined, UTedit uses ** default editor if passed NULL. */ /* Bug 4875 - Use editor defined by environment variable ING_EDIT. If that is not set then use the macro(editor). */ NMgtAt((ERx("ING_EDIT")), &ingedit); if ( ingedit != NULL && *ingedit != EOS ) p = ingedit; else p = macro(ERx("{editor}")); if (status = UTedit(p, &loc)) { ERreport(status, errbuf); putprintf(ERget(F_MO000E_Can_t_start_up_editor), errbuf); cgprompt(); return(0); } if (!rflag) { if (q_ropen(Qryiop, 'a') == (struct qbuf *)NULL) /* edit: q_ropen 2 */ ipanic(E_MO0045_1500401); } else { if (q_ropen(Qryiop, 'w') == (struct qbuf *)NULL) /* edit: q_ropen 3 */ ipanic(E_MO0046_1500402); if (status = SIfopen( &loc, ERx("r"), (i4)SI_TXT, (i4)SI_MAX_TXT_REC, &fp )) #ifdef CMS { Notempty = 0; } #else { ERreport(status, errbuf); /* can't reopen editfile %s: %s\n */ ipanic(E_MO0047_1500403, editfile, errbuf); } #endif /* CMS */ #ifdef CMS if (Notempty) { #endif /* CMS */ Notnull = 0; while ((c = SIgetc(fp)) != EOF) { if (status) { ERreport(status, errbuf); /* Error reading edit file: %s\n */ ipanic(E_MO0048_1500404, errbuf); } Notnull = 1; q_putc(Qryiop, (char)c); } SIclose(fp); if (status = LOpurge(&loc, 0)) { ERreport(status, errbuf); putprintf(ERget(F_MO000F_Cant_delete_file), editfile, errbuf); } #ifdef CMS } /* endif Notempty */ #endif /* CMS */ } #ifndef FT3270 /* Re-Initialize IT line drawing */ { if (Outisterm && IIMOildInitLnDraw != NULL) SIprintf(ERx("%s"), IIMOildInitLnDraw); } #endif cgprompt(); return(0); }