execprg(f, n) { register int s; char line[NLINE]; /* don't allow this command if restricted */ if (restflag) return(resterr()); if ((s=mlreply("!", line, NLINE)) != TRUE) return(s); TTputc('\n'); /* Already have '\r' */ TTflush(); TTclose(); /* stty to old modes */ system(line); TTopen(); mlputs(TEXT188); /* Pause. */ /* "[End]" */ TTflush(); while ((s = tgetc()) != '\r' && s != ' ') ; sgarbf = TRUE; return(TRUE); }
/* * Create a subjob with a copy of the command intrepreter in it. When the * command interpreter exits, mark the screen as garbage so that you do a full * repaint. Bound to "^X C". The message at the start in VMS puts out a newline. * Under some (unknown) condition, you don't get one free when DCL starts up. */ spawncli(f, n) { register char *cp; char *getenv(); /* don't allow this command if restricted */ if (restflag) return(resterr()); movecursor(term.t_nrow, 0); /* Seek to last line. */ TTflush(); TTclose(); /* stty to old settings */ if ((cp = getenv("SHELL")) != NULL && *cp != '\0') system(cp); else #if BSD | SUN system("exec /bin/csh"); #else system("exec /bin/sh"); #endif sgarbf = TRUE; sleep(2); TTopen(); return(TRUE); }
/* * Run a one-liner in a subjob. When the command returns, wait for a single * character to be typed, then mark the screen as garbage so a full repaint is * done. Bound to "C-X !". */ spawn(f, n) { register int s; char line[NLINE]; /* don't allow this command if restricted */ if (restflag) return(resterr()); if ((s=mlreply("!", line, NLINE)) != TRUE) return(s); TTputc('\n'); /* Already have '\r' */ TTflush(); TTclose(); /* stty to old modes */ system(line); TTopen(); TTflush(); /* if we are interactive, pause here */ if (clexec == FALSE) { mlputs(TEXT6); /* "\r\n\n[End]" */ tgetc(); } sgarbf = TRUE; return(TRUE); }
int execprg(int f, int n) { #ifndef WINNT int s; char line[NLINE]; #endif /* don't allow this command if restricted */ if (restflag) return resterr(); #if WINNT mlwrite("(unsupported)"); return FALSE; #endif #if VMS if ((s = mlreply("!", line, NLINE)) != TRUE) return s; TTflush(); s = sys(line); /* Run the command. */ mlputs("\r\n\n(End)"); /* Pause. */ TTflush(); tgetc(); sgarbf = TRUE; return s; #endif #if MSDOS if ((s = mlreply("$", line, NLINE)) != TRUE) return s; movecursor(term.t_nrow, 0); TTkclose(); execprog(line); TTkopen(); /* if we are interactive, pause here */ if (clexec == FALSE) { mlputs("\r\n(End)"); tgetc(); } sgarbf = TRUE; return TRUE; #endif #if V7 | USG | BSD if ((s = mlreply("!", line, NLINE)) != TRUE) return s; TTputc('\n'); /* Already have '\r' */ TTflush(); TTclose(); /* stty to old modes */ TTkclose(); system(line); fflush(stdout); /* to be sure P.K. */ TTopen(); mlputs("(End)"); /* Pause. */ TTflush(); while ((s = tgetc()) != '\r' && s != ' '); sgarbf = TRUE; return TRUE; #endif }
/* * Read a file into the current * buffer. This is really easy; all you do it * find the name of the file, and call the standard * "read a file into the current buffer" code. * Bound to "C-X C-R". */ fileread(f, n) { register int s; char fname[NFILEN]; if (restflag) /* don't allow this command if restricted */ return(resterr()); if ((s=mlreply("Read file: ", fname, NFILEN)) != TRUE) return(s); return(readin(fname, TRUE)); }
/* * Read a file into the current * buffer. This is really easy; all you do it * find the name of the file, and call the standard * "read a file into the current buffer" code. * Bound to "C-X C-R". */ int fileread(int f, int n) { int s; char fname[NFILEN]; if (restflag) /* don't allow this command if restricted */ return resterr(); if ((s = mlreply("Read file: ", fname, NFILEN)) != TRUE) return s; return readin(fname, TRUE); }
/* * Select a file for editing. * Look around to see if you can find the * fine in another buffer; if you can find it * just switch to the buffer. If you cannot find * the file, create a new buffer, read in the * text, and switch to the new buffer. * Bound to C-X C-F. */ int filefind(int f, int n) { char fname[NFILEN]; /* file user wishes to find */ int s; /* status return */ if (restflag) /* don't allow this command if restricted */ return resterr(); if ((s = mlreply("Find file: ", fname, NFILEN)) != TRUE) return s; return getfile(fname, TRUE); }
/* * Insert a file into the current * buffer. This is really easy; all you do it * find the name of the file, and call the standard * "insert a file into the current buffer" code. * Bound to "C-X C-I". */ insfile(f, n) { register int s; char fname[NFILEN]; if (restflag) /* don't allow this command if restricted */ return(resterr()); if (curbp->b_mode&MDVIEW) /* don't allow this command if */ return(rdonly()); /* we are in read only mode */ if ((s=mlreply("Insert file: ", fname, NFILEN)) != TRUE) return(s); return(ifile(fname)); }
/* * Create a subjob with a copy of the command intrepreter in it. When the * command interpreter exits, mark the screen as garbage so that you do a full * repaint. Bound to "^X C". The message at the start in VMS puts out a newline. * Under some (unknown) condition, you don't get one free when DCL starts up. */ spawncli(f, n) { /* don't allow this command if restricted */ if (restflag) return(resterr()); movecursor(term.t_nrow, 0); /* Seek to last line. */ TTflush(); TTkclose(); shell(); TTkopen(); sgarbf = TRUE; return(TRUE); }
/* * Insert a file into the current * buffer. This is really easy; all you do it * find the name of the file, and call the standard * "insert a file into the current buffer" code. * Bound to "C-X C-I". */ int insfile(int f, int n) { int s; char fname[NFILEN]; if (restflag) /* don't allow this command if restricted */ return resterr(); if (curbp->b_mode & MDVIEW) /* don't allow this command if */ return rdonly(); /* we are in read only mode */ if ((s = mlreply("Insert file: ", fname, NFILEN)) != TRUE) return s; if ((s = ifile(fname)) != TRUE) return s; return reposition(TRUE, -1); }
/* * Ask for a file name, and write the * contents of the current buffer to that file. * Update the remembered file name and clear the * buffer changed flag. This handling of file names * is different from the earlier versions, and * is more compatable with Gosling EMACS than * with ITS EMACS. Bound to "C-X C-W". */ int filewrite(int f, int n) { struct window *wp; int s; char fname[NFILEN]; if (restflag) /* don't allow this command if restricted */ return resterr(); if ((s = mlreply("Write file: ", fname, NFILEN)) != TRUE) return s; if ((s = writeout(fname)) == TRUE) { strcpy(curbp->b_fname, fname); curbp->b_flag &= ~BFCHG; wp = wheadp; /* Update mode lines. */ while (wp != NULL) { if (wp->w_bufp == curbp) wp->w_flag |= WFMODE; wp = wp->w_wndp; } } return s; }
/* * The command allows the user * to modify the file name associated with * the current buffer. It is like the "f" command * in UNIX "ed". The operation is simple; just zap * the name in the buffer structure, and mark the windows * as needing an update. You can type a blank line at the * prompt if you wish. */ int filename(int f, int n) { struct window *wp; int s; char fname[NFILEN]; if (restflag) /* don't allow this command if restricted */ return resterr(); if ((s = mlreply("Name: ", fname, NFILEN)) == ABORT) return s; if (s == FALSE) strcpy(curbp->b_fname, ""); else strcpy(curbp->b_fname, fname); wp = wheadp; /* Update mode lines. */ while (wp != NULL) { if (wp->w_bufp == curbp) wp->w_flag |= WFMODE; wp = wp->w_wndp; } curbp->b_mode &= ~MDVIEW; /* no longer read only mode */ return TRUE; }
int viewfile(int f, int n) { /* visit a file in VIEW mode */ char fname[NFILEN]; /* file user wishes to find */ int s; /* status return */ struct window *wp; /* scan for windows that need updating */ if (restflag) /* don't allow this command if restricted */ return resterr(); if ((s = mlreply("View file: ", fname, NFILEN)) != TRUE) return s; s = getfile(fname, FALSE); if (s) { /* if we succeed, put it in view mode */ curwp->w_bufp->b_mode |= MDVIEW; /* scan through and update mode lines of all windows */ wp = wheadp; while (wp != NULL) { wp->w_flag |= WFMODE; wp = wp->w_wndp; } } return s; }
execprg(f, n) { register int s; char line[NLINE]; /* don't allow this command if restricted */ if (restflag) return(resterr()); if ((s=mlreply("$", line, NLINE)) != TRUE) return(s); movecursor(term.t_nrow - 1, 0); TTkclose(); execprog(line); TTkopen(); /* if we are interactive, pause here */ if (clexec == FALSE) { puts(TEXT6); /* "\r\n\n[End]" */ tgetc(); } sgarbf = TRUE; return (TRUE); }
/* * Pipe a one line command into a window * Bound to ^X @ */ pipecmd(f, n) { register int s; /* return status from CLI */ register WINDOW *wp; /* pointer to new window */ register BUFFER *bp; /* pointer to buffer to zot */ char line[NLINE]; /* command line send to shell */ static char bname[] = "command"; static char filnam[NFILEN] = "command"; /* don't allow this command if restricted */ if (restflag) return(resterr()); /* get the command to pipe in */ if ((s=mlreply("@", line, NLINE)) != TRUE) return(s); /* get rid of the command output buffer if it exists */ if ((bp=bfind(bname, FALSE, 0)) != FALSE) { /* try to make sure we are off screen */ wp = wheadp; while (wp != NULL) { if (wp->w_bufp == bp) { onlywind(FALSE, 1); break; } wp = wp->w_wndp; } if (zotbuf(bp) != TRUE) return(FALSE); } TTputc('\n'); /* Already have '\r' */ TTflush(); TTclose(); /* stty to old modes */ strcat(line,">"); strcat(line,filnam); system(line); TTopen(); TTflush(); sgarbf = TRUE; s = TRUE; if (s != TRUE) return(s); /* split the current window to make room for the command output */ if (splitwind(FALSE, 1) == FALSE) return(FALSE); /* and read the stuff in */ if (getfile(filnam, FALSE) == FALSE) return(FALSE); /* make this window in VIEW mode, update all mode lines */ curwp->w_bufp->b_mode |= MDVIEW; wp = wheadp; while (wp != NULL) { wp->w_flag |= WFMODE; wp = wp->w_wndp; } /* and get rid of the temporary file */ unlink(filnam); return(TRUE); }
/* * filter a buffer through an external DOS program * Bound to ^X # */ int filter_buffer(int f, int n) { int s; /* return status from CLI */ struct buffer *bp; /* pointer to buffer to zot */ char line[NLINE]; /* command line send to shell */ char tmpnam[NFILEN]; /* place to store real file name */ static char bname1[] = "fltinp"; static char filnam1[] = "fltinp"; static char filnam2[] = "fltout"; /* don't allow this command if restricted */ if (restflag) return resterr(); if (curbp->b_mode & MDVIEW) /* don't allow this command if */ return rdonly(); /* we are in read only mode */ #if VMS mlwrite("Not available under VMS"); return FALSE; #endif /* get the filter name and its args */ if ((s = mlreply("#", line, NLINE)) != TRUE) return s; /* setup the proper file names */ bp = curbp; xstrcpy(tmpnam, bp->b_fname); /* save the original name */ xstrcpy(bp->b_fname, bname1); /* set it to our new one */ /* write it out, checking for errors */ if (writeout(filnam1) != TRUE) { mlwrite("(Cannot write filter file)"); xstrcpy(bp->b_fname, tmpnam); return FALSE; } #if MSDOS strcat(line, " <fltinp >fltout"); movecursor(term.t_nrow - 1, 0); TTkclose(); shellprog(line); TTkopen(); sgarbf = TRUE; s = TRUE; #endif #if V7 | USG | BSD TTputc('\n'); /* Already have '\r' */ TTflush(); TTclose(); /* stty to old modes */ TTkclose(); strcat(line, " <fltinp >fltout"); system(line); TTopen(); TTkopen(); TTflush(); sgarbf = TRUE; s = TRUE; #endif /* on failure, escape gracefully */ if (s != TRUE || (readin(filnam2, FALSE) == FALSE)) { mlwrite("(Execution failed)"); xstrcpy(bp->b_fname, tmpnam); unlink(filnam1); unlink(filnam2); return s; } /* reset file name */ xstrcpy(bp->b_fname, tmpnam); /* restore name */ bp->b_flag |= BFCHG; /* flag it as changed */ /* and get rid of the temporary file */ unlink(filnam1); unlink(filnam2); return TRUE; }
/* * filter a buffer through an external DOS program * Bound to ^X # * We use unique temporary file names so that multiple instances of * MicroEMACS don't try to use the same file. */ filter(f, n) { register int s; /* return status from CLI */ register BUFFER *bp; /* pointer to buffer to zot */ char line[NLINE]; /* command line send to shell */ char tmpnam[NFILEN]; /* place to store real file name */ char *tmp; /* ptr to TMP DOS environment variable */ static char filnam1[NSTRING]; static char filnam2[NSTRING]; /* don't allow this command if restricted */ if (restflag) return(resterr()); if (curbp->b_mode&MDVIEW) /* don't allow this command if */ return(rdonly()); /* we are in read only mode */ /* get the filter name and its args */ if ((s=mlreply("#", line, NLINE)) != TRUE) return(s); /* Call mktemp() to get unique filenames in the tmp directory. */ if ((tmp = getenv("TMP")) == NULL) filnam1[0] = filnam2[0] = 0; else { strcpy(filnam1, tmp); strcpy(filnam2, tmp); if (filnam1[strlen(filnam1) - 1] != '\\') { strcat(filnam1, "\\"); strcat(filnam2, "\\"); } } strcat(filnam1,"eXXXXXX"); strcat(filnam2,"eXXXXXX"); mktemp(filnam1); /* setup the proper file names */ bp = curbp; strcpy(tmpnam, bp->b_fname); /* save the original name */ strcpy(bp->b_fname, filnam1); /* set it to our new one */ /* write it out, checking for errors */ if (writeout(filnam1, "w") != TRUE) { mlwrite(TEXT2); /* "[Cannot write filter file]" */ strcpy(bp->b_fname, tmpnam); return(FALSE); } mktemp(filnam2); strcat(line, " <"); /* construct the command line */ strcat(line, filnam1); strcat(line, " >"); strcat(line, filnam2); movecursor(term.t_nrow - 1, 0); TTkclose(); system(line); TTkopen(); sgarbf = TRUE; s = TRUE; /* on failure, escape gracefully */ if (s != TRUE || (readin(filnam2,FALSE) == FALSE)) { mlwrite(TEXT3); /* "[Execution failed]" */ strcpy(bp->b_fname, tmpnam); unlink(filnam1); unlink(filnam2); return(s); } /* reset file name */ strcpy(bp->b_fname, tmpnam); /* restore name */ bp->b_flag |= BFCHG; /* flag it as changed */ /* and get rid of the temporary file */ unlink(filnam1); unlink(filnam2); return(TRUE); }
/* * Pipe a one line command into a window * Bound to ^X @ * We use a unique temporary file name so that multiple instances of * MicroEMACS don't try to use the same file. */ pipecmd(f, n) { register WINDOW *wp; /* pointer to new window */ register BUFFER *bp; /* pointer to buffer to zot */ register char *tmp; /* ptr to TMP DOS environment variable */ char line[NLINE]; /* command line send to shell */ static char bname[] = "command"; static char filnam[NSTRING]; char *getenv(); /* don't allow this command if restricted */ if (restflag) return(resterr()); /* get rid of the command output buffer if it exists */ if ((bp=bfind(bname, FALSE, 0)) != FALSE) { /* try to make sure we are off screen */ wp = wheadp; while (wp != NULL) { if (wp->w_bufp == bp) { onlywind(FALSE, 1); break; } wp = wp->w_wndp; } /* get rid of the existing command buffer */ if (zotbuf(bp) != TRUE) return(FALSE); } /* get the command to pipe in */ if (mlreply("@", line, NLINE) != TRUE) return(FALSE); /* Call mktemp() to get a unique filename in the tmp directory. */ if ((tmp = getenv("TMP")) == NULL) filnam[0] = 0; else { strcpy(filnam, tmp); if (filnam[strlen(filnam) - 1] != '\\') strcat(filnam, "\\"); } strcat(filnam,"eXXXXXX"); mktemp(filnam); /* redirect the command output to the output file */ strcat(line, " >>"); strcat(line, filnam); movecursor(term.t_nrow - 1, 0); /* execute the command */ TTkclose(); system(line); TTkopen(); sgarbf = TRUE; /* did the output file get generated? */ if (access( filnam, 0) != 0) return(FALSE); /* split the current window to make room for the command output */ if (splitwind(FALSE, 1) == FALSE) return(FALSE); /* and read the stuff in */ if (getfile(filnam, FALSE) == FALSE) return(FALSE); /* rename the buffer */ strcpy( curwp->w_bufp->b_bname, "command"); /* make this window in VIEW mode, update all mode lines */ curwp->w_bufp->b_mode |= MDVIEW; wp = wheadp; while (wp != NULL) { wp->w_flag |= WFMODE; wp = wp->w_wndp; } /* and get rid of the temporary file */ unlink(filnam); return(TRUE); }
/* * Create a subjob with a copy of the command intrepreter in it. When the * command interpreter exits, mark the screen as garbage so that you do a full * repaint. Bound to "^X C". The message at the start in VMS puts out a newline. * Under some (unknown) condition, you don't get one free when DCL starts up. */ int spawncli(int f, int n) { #if V7 | USG | BSD char *cp; #endif /* don't allow this command if restricted */ if (restflag) return resterr(); #if WINNT mlwrite("(unsupported)"); return FALSE; #endif #if VMS movecursor(term.t_nrow, 0); /* In last line. */ mlputs("(Starting DCL)\r\n"); TTflush(); /* Ignore "ttcol". */ sgarbf = TRUE; sys(NULL); sleep(1); mlputs("\r\n(Returning from DCL)\r\n"); TTflush(); sleep(1); return TRUE; #endif #if MSDOS & (MSC | TURBO) movecursor(term.t_nrow, 0); /* Seek to last line. */ TTflush(); TTkclose(); shellprog(""); TTkopen(); sgarbf = TRUE; return TRUE; #endif #if V7 | USG | BSD movecursor(term.t_nrow, 0); /* Seek to last line. */ TTflush(); TTclose(); /* stty to old settings */ TTkclose(); /* Close "keyboard" */ if ((cp = getenv("SHELL")) != NULL && *cp != '\0') system(cp); else #if BSD system("exec /bin/csh"); #else system("exec /bin/sh"); #endif sgarbf = TRUE; sleep(2); TTopen(); TTkopen(); #ifdef SIGWINCH /* * This fools the update routines to force a full * redraw with complete window size checking. * -lbt */ chg_width = term.t_ncol; chg_height = term.t_nrow + 1; term.t_nrow = term.t_ncol = 0; #endif return TRUE; #endif }
/* * Pipe a one line command into a window * Bound to ^X @ */ int pipecmd(int f, int n) { int s; /* return status from CLI */ struct window *wp; /* pointer to new window */ struct buffer *bp; /* pointer to buffer to zot */ char line[NLINE]; /* command line send to shell */ static char bname[] = "command"; static char filnam[NSTRING] = "command"; #if MSDOS char *tmp; FILE *fp; int len; #endif /* don't allow this command if restricted */ if (restflag) return resterr(); #if MSDOS if ((tmp = getenv("TMP")) == NULL && (tmp = getenv("TEMP")) == NULL) xstrcpy(filnam, "command"); else { xstrcpy(filnam, tmp); len = strlen(tmp); if (len <= 0 || filnam[len - 1] != '\\' && filnam[len - 1] != '/') strcat(filnam, "\\"); strcat(filnam, "command"); } #endif #if VMS mlwrite("Not available under VMS"); return FALSE; #endif /* get the command to pipe in */ if ((s = mlreply("@", line, NLINE)) != TRUE) return s; /* get rid of the command output buffer if it exists */ if ((bp = bfind(bname, FALSE, 0)) != FALSE) { /* try to make sure we are off screen */ wp = wheadp; while (wp != NULL) { if (wp->w_bufp == bp) { #if PKCODE if (wp == curwp) delwind(FALSE, 1); else onlywind(FALSE, 1); break; #else onlywind(FALSE, 1); break; #endif } wp = wp->w_wndp; } if (zotbuf(bp) != TRUE) return FALSE; } #if MSDOS strcat(line, " >>"); strcat(line, filnam); movecursor(term.t_nrow, 0); TTkclose(); shellprog(line); TTkopen(); sgarbf = TRUE; if ((fp = fopen(filnam, "r")) == NULL) { s = FALSE; } else { fclose(fp); s = TRUE; } #endif #if V7 | USG | BSD TTflush(); TTclose(); /* stty to old modes */ TTkclose(); strcat(line, ">"); strcat(line, filnam); system(line); TTopen(); TTkopen(); TTflush(); sgarbf = TRUE; s = TRUE; #endif if (s != TRUE) return s; /* split the current window to make room for the command output */ if (splitwind(FALSE, 1) == FALSE) return FALSE; /* and read the stuff in */ if (getfile(filnam, FALSE) == FALSE) return FALSE; /* make this window in VIEW mode, update all mode lines */ curwp->w_bufp->b_mode |= MDVIEW; wp = wheadp; while (wp != NULL) { wp->w_flag |= WFMODE; wp = wp->w_wndp; } /* and get rid of the temporary file */ unlink(filnam); return TRUE; }