bump product version to 4.1.6.2
[LibreOffice.git] / soltools / cpp / _unix.c
blobc3ba3dc176cb5b92eecb9dd128c021d903afd314
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <stdio.h>
21 #include <stddef.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <ctype.h>
25 #include <fcntl.h>
26 #if (defined(_WIN32) || defined(__IBMC__))
27 #include <io.h>
28 #else
29 #include <unistd.h>
30 #endif
32 #include "cpp.h"
34 #if defined MACOSX || defined AIX || !defined HAVE_GETOPT
35 extern int stgetopt(int, char *const *, const char *);
36 extern char *optarg;
37 extern int optind;
38 #else
39 #include <getopt.h>
40 #endif
42 int Pflag = 0; /* print no line information */
43 int Iflag = 0; /* print includes */
44 int Mflag = 0; /* print macor expansion */
45 int Aflag = 0; /* translate character sets */
46 int Xflag = 0; /* print pragma for include/import */
47 int Vflag = 0; /* verbose flag */
48 int Cflag = 0; /* do not remove any comments */
49 int Dflag = 0; /* add parameter check to delete op */
50 int Cplusplus = 0;
52 extern void setup_kwtab(void);
54 void
55 setup(int argc, char **argv)
57 int c, fd, i, n;
58 char *fp, *dp;
59 Tokenrow tr;
61 setup_kwtab();
62 #if defined MACOSX || defined(AIX) || !defined HAVE_GETOPT
63 while ((c = stgetopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
64 #else
65 while ((c = getopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
66 #endif
67 switch (c)
69 case 'N':
70 for (i = 0; i < NINCLUDE; i++)
71 if (includelist[i].always == 1)
72 includelist[i].deleted = 1;
73 break;
75 case 'I':
76 for (i = NINCLUDE - 2; i >= 0; i--)
78 if (includelist[i].file == NULL)
80 includelist[i].always = 1;
81 includelist[i].file = optarg;
82 break;
85 if (i < 0)
86 error(FATAL, "Too many -I directives");
87 break;
89 case 'D':
90 case 'U':
91 case 'A':
92 setsource("<cmdarg>", -1, -1, optarg, 0);
93 maketokenrow(3, &tr);
94 gettokens(&tr, 1);
95 doadefine(&tr, c);
96 unsetsource();
97 break;
99 case 'P': /* Lineinfo */
100 Pflag++;
101 break;
103 case 'V':
104 for (n = 0; (c = optarg[n]) != '\0'; n++)
105 switch (c)
107 case 'i':
108 Iflag++;
109 break;
111 case 'm':
112 Mflag = 1;
113 break;
115 case 'x':
116 Mflag = 2;
117 break;
119 case 't':
120 Vflag++;
121 break;
123 case 'v':
124 fprintf(stderr, "%s\n", argv[0]);
125 break;
127 default:
128 error(WARNING, "Unknown verbose option %c", c);
130 break;
132 case 'X':
133 for (n = 0; (c = optarg[n]) != '\0'; n++)
134 switch (c)
136 case 'a':
137 Aflag++;
138 break;
140 case 'i':
141 Xflag++;
142 break;
144 case 'c':
145 Cflag++;
146 break;
148 case 'd':
149 Dflag++;
150 break;
152 case 'w':
153 dp = &optarg[n + 1];
154 n += (int)strlen(dp);
155 while (isspace(*dp)) dp++;
157 for (i = NINCLUDE - 1; i >= 0; i--)
159 if (wraplist[i].file == NULL)
161 wraplist[i].file = dp;
162 break;
165 if (i < 0)
166 error(WARNING, "Too many -Xw directives");
167 break;
169 default:
170 error(WARNING, "Unknown extension option %c", c);
172 break;
174 case '+':
175 Cplusplus++;
176 break;
178 case 'u': /* -undef fuer GCC (dummy) */
179 case 'l': /* -lang-c++ fuer GCC (dummy) */
180 break;
182 default:
183 break;
185 dp = ".";
186 fp = "<stdin>";
187 fd = 0;
188 if (optind < argc)
190 if ((fp = strrchr(argv[optind], '/')) != NULL)
192 int len = (int)(fp - argv[optind]);
194 dp = (char *) newstring((uchar *) argv[optind], len + 1, 0);
195 dp[len] = '\0';
197 fp = (char *) newstring((uchar *) argv[optind], strlen(argv[optind]), 0);
198 if ((fd = open(fp, O_RDONLY)) <= 0)
199 error(FATAL, "Can't open input file %s", fp);
202 if (optind + 1 < argc)
204 int fdo = creat(argv[optind + 1], 0666);
206 if (fdo < 0)
207 error(FATAL, "Can't open output file %s", argv[optind + 1]);
209 dup2(fdo, 1);
211 includelist[NINCLUDE - 1].always = 0;
212 includelist[NINCLUDE - 1].file = dp;
213 setsource(fp, -1, fd, NULL, 0);
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */