calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / soltools / cpp / _unix.c
blob7c411befebea696a3fa94caed3599d4f467aeb1a
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 Xflag = 0; /* print pragma for include/import */
44 int Vflag = 0; /* verbose flag */
45 int Cflag = 0; /* do not remove any comments */
46 int Dflag = 0; /* add parameter check to delete op */
47 int Cplusplus = 0;
49 void
50 setup(int argc, char **argv)
52 int c, fd, i, n;
53 char *fp, *dp;
54 Tokenrow tr;
56 setup_kwtab();
57 #if defined(MACOSX) || defined(AIX) || defined(_WIN32)
58 while ((c = stgetopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
59 #else
60 while ((c = getopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
61 #endif
62 switch (c)
64 case 'N':
65 for (i = 0; i < NINCLUDE; i++)
66 if (includelist[i].always == 1)
67 includelist[i].deleted = 1;
68 break;
70 case 'I':
71 for (i = NINCLUDE - 2; i >= 0; i--)
73 if (includelist[i].file == NULL)
75 includelist[i].always = 1;
76 includelist[i].file = optarg;
77 break;
80 if (i < 0)
81 error(FATAL, "Too many -I directives");
82 break;
84 case 'D':
85 case 'U':
86 case 'A':
87 setsource("<cmdarg>", -1, -1, optarg, 0);
88 maketokenrow(3, &tr);
89 // coverity[overrun-buffer-arg: FALSE] - a multiple of trp->max is allocated, not trp->max itself
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;; n++)
103 c = optarg[n];
104 if (c == '\0')
105 break;
106 switch (c)
108 case 'i':
109 Iflag++;
110 break;
112 case 'm':
113 Mflag = 1;
114 break;
116 case 'x':
117 Mflag = 2;
118 break;
120 case 't':
121 Vflag++;
122 break;
124 case 'v':
125 fprintf(stderr, "%s\n", argv[0]);
126 break;
128 default:
129 error(WARNING, "Unknown verbose option %c", c);
132 break;
134 case 'X':
135 for (n = 0;; n++)
137 c = optarg[n];
138 if (c == '\0')
139 break;
140 switch (c)
142 case 'i':
143 Xflag++;
144 break;
146 case 'c':
147 Cflag++;
148 break;
150 case 'd':
151 Dflag++;
152 break;
154 case 'w':
155 dp = &optarg[n + 1];
156 n += (int)strlen(dp);
157 while (isspace((unsigned char)*dp)) dp++;
159 for (i = NINCLUDE - 1; i >= 0; i--)
161 if (wraplist[i].file == NULL)
163 wraplist[i].file = dp;
164 break;
167 if (i < 0)
168 error(WARNING, "Too many -Xw directives");
169 break;
171 default:
172 error(WARNING, "Unknown extension option %c", c);
175 break;
177 case '+':
178 Cplusplus++;
179 break;
181 case 'u': /* -undef for GCC (dummy) */
182 case 'l': /* -lang-c++ for GCC (dummy) */
183 break;
185 default:
186 break;
188 dp = ".";
189 fp = "<stdin>";
190 fd = 0;
191 if (optind < argc)
193 if ((fp = strrchr(argv[optind], '/')) != NULL)
195 int len = (int)(fp - argv[optind]);
197 dp = (char *) newstring((uchar *) argv[optind], len + 1, 0);
198 dp[len] = '\0';
200 fp = (char *) newstring((uchar *) argv[optind], strlen(argv[optind]), 0);
201 if ((fd = open(fp, O_RDONLY)) <= 0)
202 error(FATAL, "Can't open input file %s", fp);
205 if (optind + 1 < argc)
207 int fdo = creat(argv[optind + 1], 0666);
209 if (fdo < 0)
210 error(FATAL, "Can't open output file %s", argv[optind + 1]);
212 dup2(fdo, 1);
213 // coverity[leaked_handle] - on purpose
215 includelist[NINCLUDE - 1].always = 0;
216 includelist[NINCLUDE - 1].file = dp;
217 setsource(fp, -1, fd, NULL, 0);
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */