kernel - Update swapcache manual page, document meta-data/inode ratios
[dragonfly.git] / usr.bin / c89 / c89.c
blob0ae25013193693c2487375f10e8fa4fa765aec18
1 /*-
2 * This is the Posix.2 mandated C compiler. Basically, a hook to the
3 * cc(1) command.
5 * Copyright (c) 2001 by Jens Schweikhardt
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
28 * $FreeBSD: src/usr.bin/c89/c89.c,v 1.5 2005/05/21 09:55:04 ru Exp $
29 * $DragonFly: src/usr.bin/c89/c89.c,v 1.5 2008/05/25 08:18:26 swildner Exp $
32 #include <err.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
37 #include <unistd.h>
39 #define CC "/usr/bin/cc" /* The big kahuna doing the actual work. */
40 #define N_ARGS_PREPENDED __arysize(args_prepended)
43 * We do not add -D_POSIX_SOURCE here because any POSIX source is supposed to
44 * define it before inclusion of POSIX headers. This has the additional
45 * benefit of making c89 -D_ANSI_SOURCE do the right thing (or any other
46 * -D_FOO_SOURCE feature test macro we support.)
48 static const char *args_prepended[] = {
49 "cc",
50 "-std=iso9899:199409",
51 "-pedantic"
54 static void usage(void);
57 * Prepend the strings from args_prepended[] to the arg list; parse options,
58 * accepting only the POSIX c89 mandated options. Then exec cc to do the
59 * actual work.
61 int
62 main(int argc, char **argv)
64 int Argc, i;
65 const char **Argv;
67 Argc = 0;
68 Argv = malloc((argc + 1 + N_ARGS_PREPENDED) * sizeof *Argv);
69 if (Argv == NULL)
70 err(1, "malloc");
71 for (i = 0; i < (int)N_ARGS_PREPENDED; ++i)
72 Argv[Argc++] = args_prepended[i];
73 while ((i = getopt(argc, argv, "cD:EgI:l:L:o:OsU:")) != -1) {
74 if (i == '?')
75 usage();
76 if (i == 'l') {
77 if (argv[optind - 1][0] == '-') /* -llib */
78 optind -= 1;
79 else /* -l lib */
80 optind -= 2;
81 break; /* -llib or -l lib starts the operands. */
84 if (argc == optind) {
85 warnx("missing operand");
86 usage();
89 /* Append argv[1..] at the end of Argv[]. */
90 for (i = 1; i <= argc; ++i)
91 Argv[Argc++] = argv[i];
92 execv(CC, __DECONST(char **, Argv));
93 err(1, "execv(" CC ")");
96 static void
97 usage(void)
99 fprintf(stderr,
100 "usage: c89 [-cEgOs] [-D name[=value]] ... [-I directory] ... [-L directory] ...\n"
101 " [-o outfile] [-U name] ... operand ...\n"
102 "\n"
103 " where operand is one or more of file.c, file.o, file.a\n"
104 " or -llibrary\n");
105 exit(1);