int set_default_mode(int f, int n) { int i; struct maps_s *m; char modebuf[32], *bufp; if ((bufp = eread("Set Default Mode: ", modebuf, sizeof(modebuf), EFNEW)) == NULL) return (ABORT); else if (bufp[0] == '\0') return (FALSE); if ((m = name_mode(modebuf)) == NULL) { ewprintf("can't find mode %s", modebuf); return (FALSE); } if (!(f & FFARG)) { for (i = 0; i <= defb_nmodes; i++) if (defb_modes[i] == m) { /* mode already set */ n = 0; break; } } if (n > 0) { for (i = 0; i <= defb_nmodes; i++) if (defb_modes[i] == m) /* mode already set */ return (TRUE); if (defb_nmodes >= PBMODES - 1) { ewprintf("Too many modes"); return (FALSE); } defb_modes[++defb_nmodes] = m; } else { /* fundamental is defb_modes[0] and can't be unset */ for (i = 1; i <= defb_nmodes && m != defb_modes[i]; i++); if (i > defb_nmodes) /* mode was not set */ return (TRUE); for (; i < defb_nmodes; i++) defb_modes[i] = defb_modes[i + 1]; defb_nmodes--; } if (strcmp(modebuf, "overwrite") == 0) { if (n <= 0) defb_flag &= ~BFOVERWRITE; else defb_flag |= BFOVERWRITE; } #ifdef NOTAB if (strcmp(modebuf, "notab") == 0) { if (n <= 0) defb_flag &= ~BFNOTAB; else defb_flag |= BFNOTAB; } #endif /* NOTAB */ return (TRUE); }
KEYMAP * name_map(const char *name) { struct maps_s *mp; return ((mp = name_mode(name)) == NULL ? NULL : mp->p_map); }
/* ARGSUSED */ static int theo(int f, int n) { struct buffer *bp; struct mgwin *wp; bp = bfind("theo", TRUE); if (bclear(bp) != TRUE) return (FALSE); bp->b_modes[0] = name_mode("fundamental"); bp->b_modes[1] = name_mode("theo"); bp->b_nmodes = 1; if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; curwp = wp; return (TRUE); }
/* ARGSUSED */ int listbuffers(int f, int n) { static int initialized = 0; struct buffer *bp; struct mgwin *wp; if (!initialized) { maps_add((KEYMAP *)&listbufmap, "listbufmap"); initialized = 1; } if ((bp = makelist()) == NULL || (wp = popbuf(bp, WNONE)) == NULL) return (FALSE); wp->w_dotp = bp->b_dotp; /* fix up if window already on screen */ wp->w_doto = bp->b_doto; bp->b_modes[0] = name_mode("fundamental"); bp->b_modes[1] = name_mode("listbufmap"); bp->b_nmodes = 1; return (TRUE); }
int changemode(int f, int n, char *mode) { int i; struct maps_s *m; if ((m = name_mode(mode)) == NULL) { ewprintf("Can't find mode %s", mode); return (FALSE); } if (!(f & FFARG)) { for (i = 0; i <= curbp->b_nmodes; i++) if (curbp->b_modes[i] == m) { /* mode already set */ n = 0; break; } } if (n > 0) { for (i = 0; i <= curbp->b_nmodes; i++) if (curbp->b_modes[i] == m) /* mode already set */ return (TRUE); if (curbp->b_nmodes >= PBMODES - 1) { ewprintf("Too many modes"); return (FALSE); } curbp->b_modes[++(curbp->b_nmodes)] = m; } else { /* fundamental is b_modes[0] and can't be unset */ for (i = 1; i <= curbp->b_nmodes && m != curbp->b_modes[i]; i++); if (i > curbp->b_nmodes) return (TRUE); /* mode wasn't set */ for (; i < curbp->b_nmodes; i++) curbp->b_modes[i] = curbp->b_modes[i + 1]; curbp->b_nmodes--; } upmodes(curbp); return (TRUE); }
struct buffer * compile_mode(const char *name, const char *command) { struct buffer *bp; FILE *fpipe; char *buf; size_t len; int ret, n; char cwd[NFILEN], qcmd[NFILEN]; char timestr[NTIME]; time_t t; n = snprintf(qcmd, sizeof(qcmd), "%s 2>&1", command); if (n < 0 || n >= sizeof(qcmd)) return (NULL); bp = bfind(name, TRUE); if (bclear(bp) != TRUE) return (NULL); if (getbufcwd(bp->b_cwd, sizeof(bp->b_cwd)) != TRUE) return (NULL); addlinef(bp, "cd %s", bp->b_cwd); addline(bp, qcmd); addline(bp, ""); if (getcwd(cwd, sizeof(cwd)) == NULL) panic("Can't get current directory!"); if (chdir(bp->b_cwd) == -1) { dobeep(); ewprintf("Can't change dir to %s", bp->b_cwd); return (NULL); } if ((fpipe = popen(qcmd, "r")) == NULL) { dobeep(); ewprintf("Problem opening pipe"); return (NULL); } /* * We know that our commands are nice and the last line will end with * a \n, so we don't need to try to deal with the last line problem * in fgetln. */ while ((buf = fgetln(fpipe, &len)) != NULL) { buf[len - 1] = '\0'; addline(bp, buf); } ret = pclose(fpipe); t = time(NULL); strftime(timestr, sizeof(timestr), "%a %b %e %T %Y", localtime(&t)); addline(bp, ""); if (ret != 0) addlinef(bp, "Command exited abnormally with code %d" " at %s", ret, timestr); else addlinef(bp, "Command finished at %s", timestr); bp->b_dotp = bfirstlp(bp); bp->b_modes[0] = name_mode("fundamental"); bp->b_modes[1] = name_mode("compile"); bp->b_nmodes = 1; compile_buffer = bp; if (chdir(cwd) == -1) { dobeep(); ewprintf("Can't change dir back to %s", cwd); return (NULL); } return (bp); }
/* * XXX dname needs to have enough place to store an additional '/'. */ struct buffer * dired_(char *dname) { struct buffer *bp; FILE *dirpipe; char line[256]; int len, ret; #ifdef MONA DIR *dirp; struct dirent *dent; char* month_names[] = {"Jan", "Feb" ,"Mar" ,"Apr" ,"May" ,"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; #endif if ((dname = adjustname(dname, FALSE)) == NULL) { ewprintf("Bad directory name"); return (NULL); } /* this should not be done, instead adjustname() should get a flag */ len = strlen(dname); if (dname[len - 1] != '/') { dname[len++] = '/'; dname[len] = '\0'; } if ((bp = findbuffer(dname)) == NULL) { ewprintf("Could not create buffer"); return (NULL); } if (bclear(bp) != TRUE) return (NULL); bp->b_flag |= BFREADONLY; #ifdef MONA dirp = opendir(dname); assert(dirp); while ((dent = readdir(dirp)) != NULL) { snprintf(line, sizeof(line), "%s/%s", dname, dent->d_name); int year, month, day, hour, min, sec, size; mona_get_file_datetime_size(line, &year, &month, &day, &hour, &min, &sec, &size); char* month_name; if (month <= 12 && month >= 1) { month_name = month_names[month - 1]; } else { // assert(0); month_name = "---"; } snprintf(line, sizeof(line), " %crwxrwxrwx 1 mona mona %d %s %02d %02d:%02d %s", fisdir(line) ? 'd' : '-', size, month_name, day, hour, min, dent->d_name); addline(bp, line); } closedir(dirp); #else #ifdef GNU_LS # ifdef __CYGWIN__ /* On Windows platforms the user or group name can be two * words, such as "Domain Users" or "First Last." So, we must * use the --numeric-uid-gid option of ls, or else we don't * know where the filename starts. */ ret = snprintf(line, sizeof(line), "ls -aln --time-style='+%%b %%d %%H:%%M' '%s'", dname); # else ret = snprintf(line, sizeof(line), "ls -al --time-style='+%%b %%d %%H:%%M' '%s'", dname); # endif #else ret = snprintf(line, sizeof(line), "ls -al '%s'", dname); #endif /* GNU_LS */ if (ret < 0 || ret >= sizeof(line)) { ewprintf("Path too long"); return (NULL); } if ((dirpipe = popen(line, "r")) == NULL) { ewprintf("Problem opening pipe to ls"); return (NULL); } line[0] = line[1] = ' '; while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) { line[strcspn(line, "\n")] = '\0'; /* remove ^J */ (void) addline(bp, line); } if (pclose(dirpipe) == -1) { ewprintf("Problem closing pipe to ls : %s", strerror(errno)); return (NULL); } #endif bp->b_dotp = bfirstlp(bp); (void)strlcpy(bp->b_fname, dname, sizeof(bp->b_fname)); (void)strlcpy(bp->b_cwd, dname, sizeof(bp->b_cwd)); if ((bp->b_modes[1] = name_mode("dired")) == NULL) { bp->b_modes[0] = name_mode("fundamental"); ewprintf("Could not find mode dired"); return (NULL); } bp->b_nmodes = 1; return (bp); }