Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtksh / ksh93 / src / lib / libast / vec / vecload.c
1 /* $XConsortium: vecload.c /main/3 1995/11/01 18:57:26 rswiston $ */
2 /***************************************************************
3 *                                                              *
4 *                      AT&T - PROPRIETARY                      *
5 *                                                              *
6 *         THIS IS PROPRIETARY SOURCE CODE LICENSED BY          *
7 *                          AT&T CORP.                          *
8 *                                                              *
9 *                Copyright (c) 1995 AT&T Corp.                 *
10 *                     All Rights Reserved                      *
11 *                                                              *
12 *           This software is licensed by AT&T Corp.            *
13 *       under the terms and conditions of the license in       *
14 *       http://www.research.att.com/orgs/ssr/book/reuse        *
15 *                                                              *
16 *               This software was created by the               *
17 *           Software Engineering Research Department           *
18 *                    AT&T Bell Laboratories                    *
19 *                                                              *
20 *               For further information contact                *
21 *                     gsf@research.att.com                     *
22 *                                                              *
23 ***************************************************************/
24
25 /* : : generated by proto : : */
26
27 #if !defined(__PROTO__)
28 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
29 #if defined(__cplusplus)
30 #define __MANGLE__      "C"
31 #else
32 #define __MANGLE__
33 #endif
34 #define __STDARG__
35 #define __PROTO__(x)    x
36 #define __OTORP__(x)
37 #define __PARAM__(n,o)  n
38 #if !defined(__STDC__) && !defined(__cplusplus)
39 #if !defined(c_plusplus)
40 #define const
41 #endif
42 #define signed
43 #define void            int
44 #define volatile
45 #define __V_            char
46 #else
47 #define __V_            void
48 #endif
49 #else
50 #define __PROTO__(x)    ()
51 #define __OTORP__(x)    x
52 #define __PARAM__(n,o)  o
53 #define __MANGLE__
54 #define __V_            char
55 #define const
56 #define signed
57 #define void            int
58 #define volatile
59 #endif
60 #if defined(__cplusplus) || defined(c_plusplus)
61 #define __VARARG__      ...
62 #else
63 #define __VARARG__
64 #endif
65 #if defined(__STDARG__)
66 #define __VA_START__(p,a)       va_start(p,a)
67 #else
68 #define __VA_START__(p,a)       va_start(p)
69 #endif
70 #endif
71 #include <ast.h>
72 #include <vecargs.h>
73
74 /*
75  * load a string vector from lines in buf
76  * buf may be modified on return
77  *
78  * each line in buf is treated as a new vector element
79  * lines with # as first char are comments
80  * \ as the last char joins consecutive lines
81  *
82  * the vector ends with a 0 sentinel
83  *
84  * the string array pointer is returned
85  */
86
87 char**
88 vecload __PARAM__((char* buf), (buf)) __OTORP__(char* buf;){
89         register char*  s;
90         register int    n;
91         register char** p;
92         char**          vec;
93
94         vec = 0;
95         n = (*buf == '#') ? -1 : 0;
96         for (s = buf;; s++)
97         {
98                 if (*s == '\n')
99                 {
100                         if (s > buf && *(s - 1) == '\\') *(s - 1) = *s = ' ';
101                         else
102                         {
103                                 *s = 0;
104                                 if (*(s + 1) != '#')
105                                 {
106                                         n++;
107                                         if (!*(s + 1)) break;
108                                 }
109                         }
110                 }
111                 else if (!*s)
112                 {
113                         n++;
114                         break;
115                 }
116         }
117         if (n < 0) n = 0;
118         if (p = newof(0, char*, n + 3, 0))
119         {
120                 *p++ = s = buf;
121                 vec = ++p;
122                 if (n > 0) for (;;)
123                 {
124                         if (*s != '#')
125                         {
126                                 *p++ = s;
127                                 if (--n <= 0) break;
128                         }
129                         while (*s) s++;
130                         s++;
131                 }
132                 *p = 0;
133                 *(vec - 1) = (char*)p;
134         }
135         return(vec);
136 }