File: main.c

package info (click to toggle)
levee 3.4o-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 360 kB
  • ctags: 646
  • sloc: ansic: 5,484; makefile: 73; asm: 29; sh: 25
file content (312 lines) | stat: -rw-r--r-- 6,061 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
 * LEVEE, or Captain Video;  A vi clone
 *
 * Copyright (c) 1982-1997 David L Parsons
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, without or
 * without modification, are permitted provided that the above
 * copyright notice and this paragraph are duplicated in all such
 * forms and that any documentation, advertising materials, and
 * other materials related to such distribution and use acknowledge
 * that the software was developed by David L Parsons (orc@pell.chi.il.us).
 * My name may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

#include "levee.h"
#include "extern.h"

#include <stdlib.h>
#if (SYS5 & !ST)	/* if system 5 compatable, it has signals */
#include <signal.h>
#endif

#if RMX
    extern alien token rq$get$task$tokens();	/* for unique files */
#endif

VOID PROC
stamp(s, template)
/* make a unique temporary file */
char *s;
char *template;
{
#if RMX
    token dummy;

    strcpy(s, ":work:");
    strcat(s, template);
    numtoa(&s[strlen(s)], rq$get$task$tokens(0,&dummy));
#else
#if MSDOS || ST
    char *p;
#endif

#if UNIX
    strcpy(s, "/tmp/");
#endif

#if FLEXOS
    s[0] = 0;
#endif

#if MSDOS
    if (p=getenv("TMP")) {
	strcpy(s, p);
	if (s[strlen(s)-1] != '\\')
	    strcat(s, "\\");
    }
    else
	s[0] = 0;
#endif
#if ST
    if (p=getenv("_TMP")) {
	strcpy(s, p);
	if (s[strlen(s)-1] != '\\')
	    strcat(s, "\\");
    }
    else
	s[0] = 0;
#endif
    strcat(s, template);
    numtoa(&s[strlen(s)], getpid());
#endif
}

#if RMX|UNIX
PROC void
ctrlc()
/* ctrlc: RMX control-C handler */
{
    count = 0;	/* clear count, eh? */
}
#endif

#if RMX
PROC
settty()
/* settty: set up the terminal for raw input */
{
    unsigned dummy;
    /* transparent mode? */
    dq$special(1,&fileno(stdin),&dummy);
    
    /* turn off control character assignments */
    strput("\033]T:C15=0,C18=0,C20=0,C21=0,C23=0\033\\");
}
#endif

VOID PROC
initialize(count, args)
int count;
char **args;
/* initialize: set up everything I can in levee */
{
    int i;
#if RMX
    int xmode = E_INIT, xquit;
#else
    char *getenv();
#if ST
    extern int mapslash;
#endif
#endif

#if UNIX
    signal(SIGINT, ctrlc);
#else
    signal(SIGINT, SIG_IGN);
#endif
    initcon();

#if RMX
    exception(0);
    dq$trap$cc(ctrlc,&i);
#endif

#if ZTERM
    zconfig();
#endif /*ZTERM*/

#if ST
    screensz(&LINES, &COLS);
    dofscroll = LINES/2;
#endif

#if RMX
#if TERMCAP
    {	FILE *tcf;
	extern char termcap[];

	if (tcf=fopen(":termcap:","rb")) {
	    fgets(termcap,200,tcf);		/* get a line... */
	    termcap[strlen(termcap)-1] = 0;	/* erase \n at eof */
	    fclose(tcf);			/* close the file */
	}
    }
#endif /*TERMCAP*/
    settty();
#endif /*RMX*/

#if TERMCAP
    tc_init();
#endif

    version(); strput(".  Copyright (c) 1983-1989 by David Parsons");

    if (!CA) {
	lineonly = TRUE;
        mvcur(0, 0);
        strput(CE);
	prints("(line mode)");
    }
    else
	lineonly = FALSE;

    /* initialize macro table */
    for (i = 0;i < MAXMACROS;i++)
	mbuffer[i].token = 0;
    core[0] = EOL;
	
    yank.size = ERR;		/* no yanks yet */
    
    undo.blockp = undo.ptr = 0;
    
    fillchar(adjcurr, sizeof(adjcurr), 0);
    fillchar(adjendp, sizeof(adjendp), 0);
    
    adjcurr[BTO_WD]	=	/* more practical to just leave dynamic */
    adjcurr[SENT_BACK]	=
    adjendp[BTO_WD]	=
    adjendp[FORWD]	=
    adjendp[MATCHEXPR]	=
    adjendp[PATT_BACK]	=
    adjendp[TO_CHAR]	=
    adjendp[UPTO_CHAR]	=
    adjendp[PAGE_BEGIN]	=
    adjendp[PAGE_MIDDLE]=
    adjendp[PAGE_END]	= TRUE;

    fillchar(contexts, sizeof(contexts), -1);

    stamp(undobuf, "$un");
    stamp(yankbuf, "$ya");
    stamp(undotmp, "$tm");
    
    mvcur(LINES-1,0);
#if ST
    mapslash = getenv("mapslash") != 0L;
#endif
#if RMX
    do_file(":lvrc:", &xmode, &xquit);
#else /*!RMX	system has a environment.. */
    {	char *p;
	extern char *execstr;	/* [exec.c] */

	if ( (p=getenv("LVRC")) ) {
	    strcpy(instring,p);
	    execstr = instring;
	    setcmd();
	}
    }
#endif

    ++args, --count;
    if (count > 0 && **args == '+') {
	char *p = *args;
	strcpy(startcmd, p[1] ? (1+p) : "$");
	++args, --count;
    }
    argc = 0;
    while (count-- > 0)
	expandargs(*args++, &argc, &argv);
    if (argc > 0) {
	strcpy(filenm, argv[0]);
	if (argc > 1)
	    toedit(argc);
	inputf(filenm,TRUE);
    }
    else
	filenm[0] = 0;
}

bool PROC
execmode(emode)
exec_type emode;
{
    bool more,			/* used [more] at end of line */
	 noquit;		/* quit flag for :q, :xit, :wq */
    exec_type mode;

    zotscreen = diddled = FALSE;
    noquit = TRUE;

    if (lineonly)
	println();

    mode=emode;
    do {
	prompt(FALSE,":");
	if (getline(instring))
	    exec(instring, &mode, &noquit);
	indirect = FALSE;
	if (mode == E_VISUAL && zotscreen && noquit) {	/*ask for more*/
	    prints(" [more]");
	    if ((ch=peekc()) == 13 || ch == ' ' || ch == ':')
		readchar();
	    more = (ch != ' ' && ch != 13);
	}
	else
	    more = (mode == E_EDIT);
	if (mode != E_VISUAL && curpos.x > 0)
	    println();
	else
	    mvcur(-1,0);
    } while (more && noquit);
    if (zotscreen)
	clrprompt();
    return noquit;
}

#if ST
long _STKSIZ = 4096;
long _BLKSIZ = 4096;
#endif

int /* should be union { void a; int b; float c; } to annoy the purists */
main(argc,argv)
int argc;
char **argv;
{
    initialize(argc, argv);

    diddled = TRUE;	/* force screen redraw when we enter editcore() */
    if (lineonly)
	while (execmode(E_EDIT))
	    prints("(no visual mode)");
    else
	while (execmode(editcore()))
            /* do nada */;

    unlink(undobuf);
    unlink(yankbuf);

#if ZTERM
    zclose();
#endif

    fixcon();

#if RMX
    strputs("\033]T:C15=3,C18=13,C20=5,C21=6,C23=4\033\\\n");
    dq$special(2,&fileno(stdin),&curr);
#else
    println();
#endif
    exit(0);
}