put in | for vertical lines, - for horizontal lines.
[unix-history] / usr / src / usr.bin / window / context.c
CommitLineData
e020e0b3 1#ifndef lint
a40a2f9a 2static char *sccsid = "@(#)context.c 3.4 84/01/13";
e020e0b3
EW
3#endif
4
5#include <stdio.h>
6#include "value.h"
98c26215 7#include "string.h"
e020e0b3
EW
8#include "context.h"
9
10/*
11 * Context push/pop for nested command files.
12 */
13
14char *malloc();
15
16cx_alloc()
17{
18 register struct context *xp;
19
20 if (cx.x_type != 0) {
21 xp = (struct context *)
98c26215 22 malloc((unsigned) sizeof (struct context));
e020e0b3
EW
23 if (xp == 0)
24 return -1;
25 *xp = cx;
26 cx.x_link = xp;
27 cx.x_type = 0;
28 }
29 cx.x_erred = 0;
30 cx.x_synerred = 0;
31 cx.x_abort = 0;
32 return 0;
33}
34
35cx_free()
36{
98c26215
EW
37 struct context *xp;
38
39 if ((xp = cx.x_link) != 0) {
40 cx = *xp;
41 free((char *)xp);
e020e0b3
EW
42 } else
43 cx.x_type = 0;
44}
45
a40a2f9a 46cx_beginfile(filename)
e020e0b3
EW
47char *filename;
48{
49 if (cx_alloc() < 0)
50 return -1;
51 cx.x_type = X_FILE;
52 if ((cx.x_filename = str_cpy(filename)) == 0)
53 goto bad;
54 cx.x_fp = fopen(filename, "r");
55 if (cx.x_fp == 0)
56 goto bad;
57 cx.x_bol = 1;
58 cx.x_lineno = 0;
59 cx.x_errwin = 0;
a40a2f9a 60 cx.x_noerr = 0;
e020e0b3
EW
61 return 0;
62bad:
63 if (cx.x_filename != 0)
64 str_free(cx.x_filename);
65 cx_free();
66 return -1;
67}
68
a40a2f9a 69cx_beginbuf(buf)
e020e0b3
EW
70char *buf;
71{
72 if (cx_alloc() < 0)
73 return -1;
74 cx.x_type = X_BUF;
75 cx.x_bufp = cx.x_buf = buf;
76 return 0;
77}
78
79cx_end()
80{
81 switch (cx.x_type) {
82 case X_BUF:
83 break;
84 case X_FILE:
85 (void) fclose(cx.x_fp);
86 str_free(cx.x_filename);
87 break;
88 }
89 cx_free();
90}