void FinishRc(char *rcfilename) { char buf[2048]; FILE *fp; char *oldrc_name = rc_name; rc_name = findrcfile(rcfilename); if (rc_name == NULL || (fp = secfopen(rc_name, "r")) == NULL) { const char *rc_nonnull = rc_name ? rc_name : rcfilename; if (rc_recursion) Msg(errno, "%s: source %s", oldrc_name, rc_nonnull); else if (RcFileName && !strcmp(RcFileName, rc_nonnull)) { /* * User explicitly gave us that name, * this is the only case, where we get angry, if we can't read * the file. */ Panic(0, "Unable to open \"%s\".", rc_nonnull); /* NOTREACHED */ } if (rc_name) Free(rc_name); rc_name = oldrc_name; return; } while (fgets(buf, sizeof buf, fp) != NULL) RcLine(buf, sizeof buf); (void)fclose(fp); Free(rc_name); rc_name = oldrc_name; }
int LayoutDumpCanvas(Canvas *cv, char *filename) { FILE *file = secfopen(filename, "a"); if (!file) return 0; dump_canvas(cv, file); fclose(file); return 1; }
/* * this will be called twice: * 1) rcfilename = "/etc/screenrc" * 2) rcfilename = RcFileName */ int StartRc(char *rcfilename, int nopanic) { int argc, len; char *p, *cp; char buf[2048]; char *args[MAXARGS]; int argl[MAXARGS]; FILE *fp; char *oldrc_name = rc_name; /* always fix termcap/info capabilities */ extra_incap = CatExtra("TF", extra_incap); /* Special settings for vt100 and others */ if (display && (!strncmp(D_termname, "vt", 2) || !strncmp(D_termname, "xterm", 5))) extra_incap = CatExtra ("xn:f0=\033Op:f1=\033Oq:f2=\033Or:f3=\033Os:f4=\033Ot:f5=\033Ou:f6=\033Ov:f7=\033Ow:f8=\033Ox:f9=\033Oy:f.=\033On:f,=\033Ol:fe=\033OM:f+=\033Ok:f-=\033Om:f*=\033Oj:f/=\033Oo:fq=\033OX", extra_incap); rc_name = findrcfile(rcfilename); if (rc_name == NULL || (fp = secfopen(rc_name, "r")) == NULL) { const char *rc_nonnull = rc_name ? rc_name : rcfilename; if (!rc_recursion && RcFileName && !strcmp(RcFileName, rc_nonnull)) { /* * User explicitly gave us that name, * this is the only case, where we get angry, if we can't read * the file. */ if (!nopanic) Panic(0, "Unable to open \"%s\".", rc_nonnull); /* possibly NOTREACHED */ } if (rc_name) Free(rc_name); rc_name = oldrc_name; return 1; } while (fgets(buf, sizeof buf, fp) != NULL) { if ((p = strrchr(buf, '\n')) != NULL) *p = '\0'; if ((argc = Parse(buf, sizeof buf, args, argl)) == 0) continue; if (strcmp(args[0], "echo") == 0) { if (!display) continue; if (argc < 2 || (argc == 3 && strcmp(args[1], "-n")) || argc > 3) { Msg(0, "%s: 'echo [-n] \"string\"' expected.", rc_name); continue; } AddStr(args[argc - 1]); if (argc != 3) { AddStr("\r\n"); Flush(0); } } else if (strcmp(args[0], "sleep") == 0) { if (!display) continue; if (argc != 2) { Msg(0, "%s: sleep: one numeric argument expected.", rc_name); continue; } DisplaySleep1000(1000 * atoi(args[1]), 1); } else if (!strcmp(args[0], "termcapinfo") || !strcmp(args[0], "terminfo")) { if (!display) continue; if (argc < 3 || argc > 4) { Msg(0, "%s: %s: incorrect number of arguments.", rc_name, args[0]); continue; } for (p = args[1]; p && *p; p = cp) { if ((cp = strchr(p, '|')) != 0) *cp++ = '\0'; len = strlen(p); if (p[len - 1] == '*') { if (!(len - 1) || !strncmp(p, D_termname, len - 1)) break; } else if (!strcmp(p, D_termname)) break; } if (!(p && *p)) continue; extra_incap = CatExtra(args[2], extra_incap); if (argc == 4) extra_outcap = CatExtra(args[3], extra_outcap); } else if (!strcmp(args[0], "source")) { if (rc_recursion <= 10) { rc_recursion++; (void)StartRc(args[1], 0); rc_recursion--; } } } fclose(fp); Free(rc_name); rc_name = oldrc_name; return 0; }