Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / soltools / cpp / _unix.c
blob274ee5acaf3a3543349257180d0c2f161b50bd38
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(_WIN32)
35 #include <_getopt.h>
36 #else
37 #include <getopt.h>
38 #endif
40 int Pflag = 0; /* print no line information */
41 int Iflag = 0; /* print includes */
42 int Mflag = 0; /* print macro expansion */
43 int Aflag = 0; /* translate character sets */
44 int Xflag = 0; /* print pragma for include/import */
45 int Vflag = 0; /* verbose flag */
46 int Cflag = 0; /* do not remove any comments */
47 int Dflag = 0; /* add parameter check to delete op */
48 int Cplusplus = 0;
50 void
51 setup(int argc, char **argv)
53 int c, fd, i, n;
54 char *fp, *dp;
55 Tokenrow tr;
57 setup_kwtab();
58 #if defined(MACOSX) || defined(AIX) || defined(_WIN32)
59 while ((c = stgetopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
60 #else
61 while ((c = getopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
62 #endif
63 switch (c)
65 case 'N':
66 for (i = 0; i < NINCLUDE; i++)
67 if (includelist[i].always == 1)
68 includelist[i].deleted = 1;
69 break;
71 case 'I':
72 for (i = NINCLUDE - 2; i >= 0; i--)
74 if (includelist[i].file == NULL)
76 includelist[i].always = 1;
77 includelist[i].file = optarg;
78 break;
81 if (i < 0)
82 error(FATAL, "Too many -I directives");
83 break;
85 case 'D':
86 case 'U':
87 case 'A':
88 setsource("<cmdarg>", -1, -1, optarg, 0);
89 maketokenrow(3, &tr);
90 gettokens(&tr, 1);
91 doadefine(&tr, c);
92 dofree(tr.bp);
93 unsetsource();
94 break;
96 case 'P': /* Lineinfo */
97 Pflag++;
98 break;
100 case 'V':
101 for (n = 0; (c = optarg[n]) != '\0'; n++)
102 switch (c)
104 case 'i':
105 Iflag++;
106 break;
108 case 'm':
109 Mflag = 1;
110 break;
112 case 'x':
113 Mflag = 2;
114 break;
116 case 't':
117 Vflag++;
118 break;
120 case 'v':
121 fprintf(stderr, "%s\n", argv[0]);
122 break;
124 default:
125 error(WARNING, "Unknown verbose option %c", c);
127 break;
129 case 'X':
130 for (n = 0; (c = optarg[n]) != '\0'; n++)
131 switch (c)
133 case 'a':
134 Aflag++;
135 break;
137 case 'i':
138 Xflag++;
139 break;
141 case 'c':
142 Cflag++;
143 break;
145 case 'd':
146 Dflag++;
147 break;
149 case 'w':
150 dp = &optarg[n + 1];
151 n += (int)strlen(dp);
152 while (isspace((unsigned char)*dp)) dp++;
154 for (i = NINCLUDE - 1; i >= 0; i--)
156 if (wraplist[i].file == NULL)
158 wraplist[i].file = dp;
159 break;
162 if (i < 0)
163 error(WARNING, "Too many -Xw directives");
164 break;
166 default:
167 error(WARNING, "Unknown extension option %c", c);
169 break;
171 case '+':
172 Cplusplus++;
173 break;
175 case 'u': /* -undef fuer GCC (dummy) */
176 case 'l': /* -lang-c++ fuer GCC (dummy) */
177 break;
179 default:
180 break;
182 dp = ".";
183 fp = "<stdin>";
184 fd = 0;
185 if (optind < argc)
187 if ((fp = strrchr(argv[optind], '/')) != NULL)
189 int len = (int)(fp - argv[optind]);
191 dp = (char *) newstring((uchar *) argv[optind], len + 1, 0);
192 dp[len] = '\0';
194 fp = (char *) newstring((uchar *) argv[optind], strlen(argv[optind]), 0);
195 if ((fd = open(fp, O_RDONLY)) <= 0)
196 error(FATAL, "Can't open input file %s", fp);
199 if (optind + 1 < argc)
201 int fdo = creat(argv[optind + 1], 0666);
203 if (fdo < 0)
204 error(FATAL, "Can't open output file %s", argv[optind + 1]);
206 dup2(fdo, 1);
208 includelist[NINCLUDE - 1].always = 0;
209 includelist[NINCLUDE - 1].file = dp;
210 setsource(fp, -1, fd, NULL, 0);
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */