Print this page
10120 smatch indenting fixes for usr/src/cmd
Reviewed by: Gergő Doma <domag02@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/ar/common/main.c
+++ new/usr/src/cmd/sgs/ar/common/main.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /* Copyright (c) 1988 AT&T */
22 22 /* All Rights Reserved */
23 23
24 24 /*
25 25 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
26 26 */
27 27
28 +/*
29 + * Copyright (c) 2018, Joyent, Inc.
30 + */
31 +
28 32 #include "inc.h"
29 33 #include "conv.h"
30 34
31 35 /*
32 36 * Forward declarations
33 37 */
34 38 static void setup(int, char **, Cmd_info *);
35 39 static void setcom(Cmd_info *, Cmd_func);
36 40 static void usage(void);
37 41 static void sigexit(int sig);
38 42 static int notfound(Cmd_info *);
39 43 static void check_swap();
40 44
41 45 const char *
42 46 _ar_msg(Msg mid)
43 47 {
44 48 return (gettext(MSG_ORIG(mid)));
45 49 }
46 50
47 51
48 52 void
49 53 establish_sighandler(void (*handler)())
50 54 {
51 55 static const int signum[] = {SIGHUP, SIGINT, SIGQUIT, 0};
52 56 int i;
53 57
54 58 if (handler == SIG_IGN) {
55 59 /* Ignore all the specified signals */
56 60 for (i = 0; signum[i]; i++)
57 61 (void) signal(signum[i], SIG_IGN);
58 62
59 63 } else {
60 64 /*
61 65 * Set any signal that doesn't default to being ignored
62 66 * to our signal handler.
63 67 */
64 68 for (i = 0; signum[i]; i++)
65 69 if (signal(signum[i], SIG_IGN) != SIG_IGN)
66 70 (void) signal(signum[i], handler);
67 71 }
68 72 }
69 73
70 74 int
71 75 main(int argc, char **argv, char *envp[])
72 76 {
73 77 int fd;
74 78 Cmd_info *cmd_info;
75 79 int ret;
76 80 char *new = NULL;
77 81
78 82 #ifndef XPG4
79 83 /*
80 84 * Check for a binary that better fits this architecture.
81 85 */
82 86 (void) conv_check_native(argv, envp);
83 87 #endif
84 88
85 89 /*
86 90 * Establish locale.
87 91 */
88 92 (void) setlocale(LC_ALL, MSG_ORIG(MSG_STR_EMPTY));
89 93 (void) textdomain(MSG_ORIG(MSG_SUNW_OST_SGS));
90 94
91 95 /* Allow a graceful exit up until we start to write an archive */
92 96 establish_sighandler(sigexit);
93 97
94 98 /*
95 99 * Initialize cmd_info
96 100 */
97 101 cmd_info = (Cmd_info *)calloc(1, sizeof (Cmd_info));
98 102 if (cmd_info == NULL) {
99 103 int err = errno;
100 104 (void) fprintf(stderr, MSG_INTL(MSG_MALLOC), strerror(err));
101 105 exit(1);
102 106 }
103 107
104 108 if (argc < 2)
105 109 usage();
106 110
107 111 /*
108 112 * Option handling.
109 113 */
110 114 if (argv[1][0] != '-') {
111 115 new = (char *)malloc(strlen(argv[1]) + 2);
112 116 if (new == NULL) {
113 117 int err = errno;
114 118 (void) fprintf(stderr, MSG_INTL(MSG_MALLOC),
115 119 strerror(err));
116 120 exit(1);
117 121 }
118 122 (void) strcpy(new, MSG_ORIG(MSG_STR_HYPHEN));
119 123 (void) strcat(new, argv[1]);
120 124 argv[1] = new;
121 125 }
122 126 setup(argc, argv, cmd_info);
123 127
124 128 /*
125 129 * Check SWAP
126 130 */
127 131 if (cmd_info->opt_flgs & z_FLAG)
128 132 check_swap();
129 133
130 134 if (cmd_info->comfun == NULL) {
131 135 if ((cmd_info->opt_flgs & (d_FLAG | r_FLAG | q_FLAG |
132 136 t_FLAG | p_FLAG | m_FLAG | x_FLAG)) == 0) {
133 137 (void) fprintf(stderr, MSG_INTL(MSG_USAGE_01));
134 138 exit(1);
135 139 }
136 140 }
137 141
138 142 cmd_info->modified = (cmd_info->opt_flgs & s_FLAG);
139 143 fd = getaf(cmd_info);
140 144
141 145 if ((fd == -1) &&
142 146 (cmd_info->opt_flgs &
143 147 (d_FLAG | m_FLAG | p_FLAG | t_FLAG | x_FLAG)) ||
144 148 ((cmd_info->opt_flgs & r_FLAG) &&
145 149 (cmd_info->opt_flgs & (a_FLAG | b_FLAG)))) {
146 150 (void) fprintf(stderr, MSG_INTL(MSG_NOT_FOUND_AR),
147 151 cmd_info->arnam);
148 152 exit(1);
149 153 }
150 154
151 155 (*cmd_info->comfun)(cmd_info);
152 156 if (cmd_info->modified) {
153 157 writefile(cmd_info);
154 158 } else
155 159 (void) close(fd);
156 160
157 161 ret = notfound(cmd_info);
158 162
159 163 /*
160 164 * Check SWAP
161 165 */
162 166 if (cmd_info->opt_flgs & z_FLAG)
163 167 check_swap();
164 168
165 169 free(new);
166 170 free(cmd_info);
167 171 return (ret);
168 172
169 173 }
170 174
171 175 /*
172 176 * Option handing function.
173 177 * Using getopt(), following xcu4 convention.
174 178 */
175 179 static void
176 180 setup(int argc, char *argv[], Cmd_info *cmd_info)
177 181 {
178 182 int Vflag = 0;
179 183 int c;
180 184 int usage_err = 0;
181 185
182 186 while ((c = getopt(argc, argv, MSG_ORIG(MSG_STR_OPTIONS))) != -1) {
183 187 switch (c) {
184 188 case 'a': /* position after named archive member file */
185 189 cmd_info->opt_flgs |= a_FLAG;
186 190 cmd_info->ponam = trim(optarg);
187 191 break;
188 192 case 'b': /* position before named archive member file */
189 193 case 'i': /* position before named archive member: same as b */
190 194 cmd_info->opt_flgs |= b_FLAG;
191 195 cmd_info->ponam = trim(optarg);
192 196 break;
193 197 case 'c': /* supress messages */
194 198 cmd_info->opt_flgs |= c_FLAG;
195 199 break;
196 200 case 'd':
197 201 /*
198 202 * key operation:
199 203 * delete files from the archive
200 204 */
201 205 setcom(cmd_info, dcmd);
202 206 cmd_info->opt_flgs |= d_FLAG;
203 207 break;
204 208 case 'l': /* ignored */
205 209 break;
206 210 case 'm':
207 211 /*
208 212 * key operation:
209 213 * move files to end of the archive
210 214 * or as indicated by position flag
211 215 */
212 216 setcom(cmd_info, mcmd);
213 217 cmd_info->opt_flgs |= m_FLAG;
214 218 break;
215 219 case 'p':
216 220 /*
217 221 * key operation:
218 222 * print files in the archive
219 223 */
220 224 setcom(cmd_info, pcmd);
221 225 cmd_info->opt_flgs |= p_FLAG;
222 226 break;
223 227 case 'q':
224 228 /*
225 229 * key operation:
226 230 * quickly append files to end of the archive
227 231 */
228 232 setcom(cmd_info, qcmd);
229 233 cmd_info->opt_flgs |= q_FLAG;
230 234 break;
231 235 case 'r':
232 236 /*
233 237 * key operation:
234 238 * replace or add files to the archive
235 239 */
236 240 setcom(cmd_info, rcmd);
237 241 cmd_info->opt_flgs |= r_FLAG;
238 242 break;
239 243 case 's': /* force symbol table regeneration */
240 244 cmd_info->opt_flgs |= s_FLAG;
241 245 break;
242 246 case 'S': /* Build SYM64 symbol table */
243 247 cmd_info->opt_flgs |= S_FLAG;
244 248 break;
245 249 case 't':
246 250 /*
247 251 * key operation:
248 252 * print table of contents
249 253 */
250 254 setcom(cmd_info, tcmd);
251 255 cmd_info->opt_flgs |= t_FLAG;
252 256 break;
253 257 case 'u': /* update: change archive dependent on file dates */
254 258 cmd_info->opt_flgs |= u_FLAG;
255 259 break;
256 260 case 'v': /* verbose */
257 261 cmd_info->opt_flgs |= v_FLAG;
258 262 break;
259 263 case 'x':
260 264 /*
261 265 * key operation:
262 266 * extract files from the archive
263 267 */
264 268 setcom(cmd_info, xcmd);
265 269 cmd_info->opt_flgs |= x_FLAG;
266 270 break;
267 271 case 'z':
268 272 cmd_info->opt_flgs |= z_FLAG;
269 273 break;
↓ open down ↓ |
232 lines elided |
↑ open up ↑ |
270 274 case 'V':
271 275 /*
272 276 * print version information.
273 277 * adjust command line access accounting
274 278 */
275 279 if (Vflag == 0) {
276 280 (void) fprintf(stderr,
277 281 MSG_ORIG(MSG_FMT_VERSION),
278 282 (const char *)SGU_PKG,
279 283 (const char *)SGU_REL);
280 - Vflag++;
284 + Vflag++;
281 285 }
282 286 break;
283 287 case 'C':
284 288 cmd_info->opt_flgs |= C_FLAG;
285 289 break;
286 290 case 'M':
287 291 /*
288 292 * -M was an original undocumented AT&T feature that
289 293 * would force the use of mmap() instead of read()
290 294 * for pulling file data into the process before
291 295 * writing it to the archive. Ignored.
292 296 */
293 297 break;
294 298 case 'T':
295 299 cmd_info->opt_flgs |= T_FLAG;
296 300 break;
297 301 case ':':
298 302 (void) fprintf(stderr, MSG_INTL(MSG_USAGE_02), optopt);
299 303 usage_err++;
300 304 break;
301 305 case '?':
302 306 (void) fprintf(stderr, MSG_INTL(MSG_USAGE_03), optopt);
303 307 usage_err++;
304 308 break;
305 309 }
306 310 }
307 311
308 312 if (usage_err || argc - optind < 1)
309 313 usage();
310 314
311 315 cmd_info->arnam = argv[optind];
312 316 cmd_info->namv = &argv[optind+1];
313 317 cmd_info->namc = argc - optind - 1;
314 318 }
315 319
316 320
317 321 /*
318 322 * Set the function to be called to do the key operation.
319 323 * Check that only one key is indicated.
320 324 */
321 325 static void
322 326 setcom(Cmd_info *cmd_info, Cmd_func *fun)
323 327 {
324 328 if (cmd_info->comfun != 0) {
325 329 (void) fprintf(stderr, MSG_INTL(MSG_USAGE_04));
326 330 exit(1);
327 331 }
328 332 cmd_info->comfun = fun;
329 333 }
330 334
331 335 static void
332 336 usage(void)
333 337 {
334 338 (void) fprintf(stderr, MSG_INTL(MSG_USAGE));
335 339 exit(1);
336 340 }
337 341
338 342 /*ARGSUSED0*/
339 343 static void
340 344 sigexit(int sig)
341 345 {
342 346 exit(100);
343 347 }
344 348
345 349 /* tells the user which of the listed files were not found in the archive */
346 350
347 351 static int
348 352 notfound(Cmd_info *cmd_info)
349 353 {
350 354 int i, n;
351 355
352 356 n = 0;
353 357 for (i = 0; i < cmd_info->namc; i++)
354 358 if (cmd_info->namv[i]) {
355 359 (void) fprintf(stderr, MSG_INTL(MSG_NOT_FOUND_FILE),
356 360 cmd_info->namv[i]);
357 361 n++;
358 362 }
359 363 return (n);
360 364 }
361 365
362 366 /*
363 367 * Debugging info
364 368 */
365 369 static void
366 370 check_swap(void)
367 371 {
368 372 (void) system(MSG_ORIG(MSG_CMD_SWAP));
369 373 }
↓ open down ↓ |
79 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX