Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / cemcom.ansi / input.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 /* $Id: input.c,v 1.14 1995/03/24 13:56:20 ceriel Exp $ */
6
7 #include "inputtype.h"
8 #include "file_info.h"
9 #include "input.h"
10
11 #define INP_PUSHBACK    3
12 #define INP_TYPE        struct file_info
13 #define INP_VAR         finfo
14 struct file_info        finfo;
15 #include "nopp.h"
16 #include <inp_pkg.body>
17 #include <alloc.h>
18
19 #include        "dbsymtab.h"
20 #include        "lint.h"
21 #ifndef NOPP
22 #ifdef DBSYMTAB
23 #include <stb.h>
24 #include <em.h>
25 extern int      IncludeLevel;
26 extern char     options[];
27 #endif
28
29 char *
30 getwdir(fn)
31         register char *fn;
32 {
33         register char *p;
34         char *strrindex();
35
36         p = strrindex(fn, '/');
37         while (p && *(p + 1) == '\0') { /* remove trailing /'s */
38                 *p = '\0';
39                 p = strrindex(fn, '/');
40         }
41
42         if (fn[0] == '\0' || (fn[0] == '/' && p == &fn[0])) /* absolute path */
43                 return "";
44         if (p) {
45                 *p = '\0';
46                 fn = Salloc(fn,(unsigned) (p - &fn[0] + 1));
47                 *p = '/';
48                 return fn;
49         }
50         return "";
51 }
52
53 int     InputLevel;
54 extern int              nestlevel;
55 #endif /* NOPP */
56
57 int     NoUnstack;
58
59 AtEoIT()
60 {
61 #ifndef NOPP
62         InputLevel--;
63         unstackrepl();
64 #endif /* NOPP */
65         return 0;
66 }
67
68 extern char *source;
69
70 AtEoIF()
71 {
72 #ifndef NOPP
73         if (nestlevel != nestlow) lexwarning("missing #endif");
74         else
75 #endif /* NOPP */
76         if (NoUnstack) lexerror("unexpected EOF");
77 #ifndef NOPP
78         nestlevel = nestlow;
79 #ifdef DBSYMTAB
80         if (options['g'] && IncludeLevel > 0) {
81                 C_ms_stb_cst(FileName, N_EINCL, 0, (arith) 0);
82         }
83         IncludeLevel--;
84 #endif
85         if (WorkingDir[0] != '\0') free(WorkingDir);
86 #endif /* NOPP */
87 #ifndef LINT
88         if (FileName != source) free(FileName);
89 #endif
90         return 0;
91 }