Pristine Ack-5.5
[Ack-5.5.git] / util / cpp / input.c
1 /* $Id: input.c,v 1.12 1995/08/17 13:33:53 ceriel Exp $ */
2 /*
3  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4  * See the copyright notice in the ACK home directory, in the file "Copyright".
5  */
6 #include "file_info.h"
7 #include "input.h"
8 #define INP_TYPE        struct file_info
9 #define INP_VAR         finfo
10 struct file_info        finfo;
11 #include <inp_pkg.body>
12 #include <alloc.h>
13
14 char *
15 getwdir(fn)
16         char *fn;
17 {
18         register char *p;
19         char *strrindex();
20
21         p = strrindex(fn, '/');
22         while (p && *(p + 1) == '\0') { /* remove trailing /'s */
23                 *p = '\0';
24                 p = strrindex(fn, '/');
25         }
26
27         if (fn[0] == '\0' || (fn[0] == '/' && p == &fn[0])) /* absolute path */
28                 return "";
29         else
30         if (p) {
31                 *p = '\0';
32                 fn = Salloc(fn, p - &fn[0] + 1);
33                 *p = '/';
34                 return fn;
35         }
36         else return "";
37 }
38
39 int     NoUnstack;
40 int     Unstacked;
41 int     InputLevel;
42
43 AtEoIT()
44 {
45         /* if (NoUnstack) warning("unexpected EOF"); ??? */
46         /* This is wrong; in an #elif, NoUnstack can be set, but you
47            can still get calls to AtEoIT().
48         */
49         InputLevel--;
50         DoUnstack();
51         return 0;
52 }
53
54 AtEoIF()
55 {
56         extern int nestlevel;
57         extern int nestcount;
58         extern int svnestlevel[];
59
60         if (nestlevel > svnestlevel[nestcount]) warning("missing #endif");
61         else if (NoUnstack) warning("unexpected EOF");
62         nestlevel = svnestlevel[nestcount--];
63         return 0;
64 }