1 /* $OpenBSD: main.c,v 1.67 2012/05/29 06:08:48 lum Exp $ */
3 /* This file is in the public domain. */
16 int thisflag; /* flags, this command */
17 int lastflag; /* flags, last command */
18 int curgoal; /* goal column */
19 int startrow; /* row to start */
20 struct buffer *curbp; /* current buffer */
21 struct buffer *bheadp; /* BUFFER list head */
22 struct mgwin *curwp; /* current window */
23 struct mgwin *wheadp; /* MGWIN listhead */
24 char pat[NPAT]; /* pattern */
26 static void edinit(struct buffer *);
27 static __dead void usage(void);
29 extern char *__progname;
30 extern void closetags(void);
35 fprintf(stderr, "usage: %s [-n] [-f mode] [+number] [file ...]\n",
41 main(int argc, char **argv)
43 char *cp, *init_fcn_name = NULL;
47 struct buffer *bp = NULL;
49 while ((o = getopt(argc, argv, "nf:")) != -1)
55 if (init_fcn_name != NULL)
56 errx(1, "cannot specify more than one "
58 init_fcn_name = optarg;
66 maps_init(); /* Keymaps and modes. */
67 funmap_init(); /* Functions. */
70 * This is where we initialize standalone extensions that should
71 * be loaded dynamically sometime in the future.
74 extern void grep_init(void);
75 extern void theo_init(void);
76 extern void cmode_init(void);
77 extern void dired_init(void);
86 (init_fcn = name_function(init_fcn_name)) == NULL)
87 errx(1, "Unknown function `%s'", init_fcn_name);
89 vtinit(); /* Virtual terminal. */
90 dirinit(); /* Get current directory. */
91 edinit(bp); /* Buffers, windows. */
92 ttykeymapinit(); /* Symbols, bindings. */
95 * doing update() before reading files causes the error messages from
96 * the file I/O show up on the screen. (and also an extra display of
97 * the mode line if there are files specified on the command line.)
101 /* user startup file. */
102 if ((cp = startupfile(NULL)) != NULL)
106 * Now ensure any default buffer modes from the startup file are
107 * given to any files opened when parsing the startup file.
108 * Note *scratch* will also be updated.
110 for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
111 bp->b_flag = defb_flag;
112 for (i = 0; i <= defb_nmodes; i++) {
113 bp->b_modes[i] = defb_modes[i];
117 /* Force FFOTHARG=1 so that this mode is enabled, not simply toggled */
119 init_fcn(FFOTHARG, 1);
122 makebkfile(FFARG, 0);
124 for (nfiles = 0, i = 0; i < argc; i++) {
125 if (argv[i][0] == '+' && strlen(argv[i]) >= 2) {
129 lval = strtonum(&argv[i][1], INT_MIN, INT_MAX, &errstr);
130 if (argv[i][1] == '\0' || errstr != NULL)
135 cp = adjustname(argv[i], FALSE);
140 if ((curbp = findbuffer(cp)) == NULL) {
142 errx(1, "Can't find current buffer!");
144 (void)showbuffer(curbp, curwp, 0);
145 if (readin(cp) != TRUE)
148 /* Ensure enabled, not just toggled */
150 init_fcn(FFOTHARG, 1);
160 /* fake last flags */
163 if (epresf == KCLEAR)
168 do_redraw(0, 0, TRUE);
190 * Initialize default buffer and window. Default buffer is called *scratch*.
193 edinit(struct buffer *bp)
198 bp = bfind("*scratch*", TRUE); /* Text buffer. */
204 panic("edinit: Out of memory");
206 curbp = bp; /* Current buffer. */
209 wp->w_wndp = NULL; /* Initialize window. */
210 wp->w_linep = wp->w_dotp = bp->b_headp;
211 wp->w_ntrows = nrow - 2; /* 2 = mode, echo. */
212 wp->w_rflag = WFMODE | WFFULL; /* Full. */
216 * Quit command. If an argument, always quit. Otherwise confirm if a buffer
217 * has been changed and not written out. Normally bound to "C-X C-C".
225 if ((s = anycb(FALSE)) == ABORT)
228 || eyesno("Modified buffers exist; really exit") == TRUE) {
237 * User abort. Should be called by any input routine that sees a C-g to abort
238 * whatever C-g is aborting these days. Currently does nothing.