static int listbuf_goto_buffer_helper(int f, int n, int only) { struct buffer *bp; struct mgwin *wp; char *line = NULL; int i, ret = FALSE; if (curwp->w_dotp->l_text[listbuf_ncol/2 - 1] == '$') { dobeep(); ewprintf("buffer name truncated"); return (FALSE); } if ((line = malloc(listbuf_ncol/2)) == NULL) return (FALSE); memcpy(line, curwp->w_dotp->l_text + 4, listbuf_ncol/2 - 5); for (i = listbuf_ncol/2 - 6; i > 0; i--) { if (line[i] != ' ') { line[i + 1] = '\0'; break; } } if (i == 0) goto cleanup; for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { if (strcmp(bp->b_bname, line) == 0) break; } if (bp == NULL) goto cleanup; if ((wp = popbuf(bp, WNONE)) == NULL) goto cleanup; curbp = bp; curwp = wp; if (only) ret = (onlywind(FFRAND, 1)); else ret = TRUE; cleanup: free(line); return (ret); }
/* * 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); }
int buffermenu(int f, int n) { BUFFER *bp; BUFFER *org_bp = curbp; int c,k; int bufptr; int bufcount = 0; bufptr = 1; start: listbuffers(f,n); swbuffer(blistp); onlywind(0,0); bufcount = count_buffers(); if (bufptr > bufcount) bufptr = bufcount; if (bufcount > 0) forwline(0, bufptr + 1); else forwline(0, 2); for (;;) { mlwrite("Buffer Menu: 1,2,s,v,k,q "); update(); c = ttgetc(); /* if no buffers, only allow exit */ if (bufcount == 0) { switch (c) { case 'q': case 'Q': case 'x': case 'X': break; default: (*term.t_beep) (); continue; } } /* * pre process escape sequence to get up/down arrows * convert to CTRL+N, CTRL+P */ if (c == ESC) { k = getctl(); if (k == '[') { k = getctl(); switch(k) { case 'A': c = CTRL_P; break; case 'B': c = CTRL_N; break; default: (*term.t_beep)(); continue; } } else { k = getctl(); (*term.t_beep) (); continue; } } /* if ESC */ switch (c) { case 'n': case 'N': case CTRL_N: if (bufcount == bufptr) { (*term.t_beep) (); break; } forwline(0,1); bufptr++; break; case 'p': case 'P': case CTRL_P: if (bufptr == 1) { (*term.t_beep) (); break; } backline(0,1); bufptr--; break; case '1': bp = get_buffer(bufptr); swbuffer(bp); onlywind(0,0); mlerase(); return TRUE; case '2': bp = get_buffer(bufptr); swbuffer(bp); onlywind(0,0); /* need to check or is still valid */ if (valid_buf(org_bp) == TRUE && bufcount > 1) { splitwind(0,0); swbuffer(org_bp); nextwind(0,0); } mlerase(); return TRUE; /* save file */ case 's': case 'S': bp = get_buffer(bufptr); if (bp != NULL) { curbp = bp; (void)filesave(0,0); curbp = blistp; goto start; } break; /* toggle read only */ case 'v': case 'V': case '%': bp = get_buffer(bufptr); if (bp != NULL) /* be defensive */ bp->b_flag ^= BFRO; goto start; break; /* kill buffer */ case 'k': case 'K': bp = get_buffer(bufptr); if (bp != NULL) zotbuf(bp); goto start; break; /* exit buffer menu */ case 'q': case 'Q': case 'x': case 'X': if (bufcount == 0) { bp = get_scratch(); swbuffer(bp); onlywind(0,0); mlerase(); return TRUE; } if (valid_buf(org_bp) == TRUE) swbuffer(org_bp); else swbuffer(bheadp); onlywind(0,0); mlerase(); return TRUE; /* any other key */ default: (*term.t_beep) (); break; } } mlerase(); 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); }
/* * 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; }