c99.c revision 104615
1104615Stjr/*-
2104615Stjr * Copyright (c) 2002 Tim J. Robbins.
3104615Stjr * All rights reserved.
4104615Stjr *
5104615Stjr * Redistribution and use in source and binary forms, with or without
6104615Stjr * modification, are permitted provided that the following conditions
7104615Stjr * are met:
8104615Stjr * 1. Redistributions of source code must retain the above copyright
9104615Stjr *    notice, this list of conditions and the following disclaimer.
10104615Stjr * 2. Redistributions in binary form must reproduce the above copyright
11104615Stjr *    notice, this list of conditions and the following disclaimer in the
12104615Stjr *    documentation and/or other materials provided with the distribution.
13104615Stjr *
14104615Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15104615Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16104615Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17104615Stjr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18104615Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19104615Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20104615Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21104615Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22104615Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23104615Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24104615Stjr * SUCH DAMAGE.
25104615Stjr */
26104615Stjr
27104615Stjr/*
28104615Stjr * c99 -- compile standard C programs
29104615Stjr *
30104615Stjr * This is essentially a wrapper around the system C compiler that forces
31104615Stjr * the compiler into C99 mode.
32104615Stjr */
33104615Stjr
34104615Stjr#include <sys/cdefs.h>
35104615Stjr__FBSDID("$FreeBSD: head/usr.bin/c99/c99.c 104615 2002-10-07 09:37:55Z tjr $");
36104615Stjr
37104615Stjr#include <sys/types.h>
38104615Stjr
39104615Stjr#include <err.h>
40104615Stjr#include <stdio.h>
41104615Stjr#include <stdlib.h>
42104615Stjr#include <string.h>
43104615Stjr#include <unistd.h>
44104615Stjr
45104615Stjrchar **args;
46104615Stjru_int cargs, nargs;
47104615Stjr
48104615Stjrvoid addarg(const char *item);
49104615Stjrvoid usage(void);
50104615Stjr
51104615Stjrint
52104615Stjrmain(int argc, char *argv[])
53104615Stjr{
54104615Stjr	int i;
55104615Stjr
56104615Stjr	args = NULL;
57104615Stjr	cargs = nargs = 0;
58104615Stjr
59104615Stjr	addarg("cc");
60104615Stjr	addarg("-std=iso9899:1999");
61104615Stjr	addarg("-pedantic");
62104615Stjr	for (i = 1; i < argc; i++)
63104615Stjr		addarg(argv[i]);
64104615Stjr	execv("/usr/bin/cc", args);
65104615Stjr	err(1, "/usr/bin/cc");
66104615Stjr}
67104615Stjr
68104615Stjrvoid
69104615Stjraddarg(const char *item)
70104615Stjr{
71104615Stjr	if (nargs + 1 > cargs) {
72104615Stjr		cargs += 16;
73104615Stjr		if ((args = realloc(args, sizeof(*args) * cargs)) == NULL)
74104615Stjr			err(1, "malloc");
75104615Stjr	}
76104615Stjr	if ((args[nargs++] = strdup(item)) == NULL)
77104615Stjr		err(1, "strdup");
78104615Stjr	args[nargs] = NULL;
79104615Stjr}
80104615Stjr
81104615Stjrvoid
82104615Stjrusage(void)
83104615Stjr{
84104615Stjr	fprintf(stderr,
85104615Stjr"usage: c99 [-cEgs] [-D name[=value]] [-I directory] ... [-L directory] ...\n");
86104615Stjr	fprintf(stderr,
87104615Stjr"       [-o outfile] [-O optlevel] [-U name]... operand ...\n");
88104615Stjr	exit(1);
89104615Stjr}
90