c99.c revision 104615
11556Srgrimes/*-
21556Srgrimes * Copyright (c) 2002 Tim J. Robbins.
31556Srgrimes * All rights reserved.
41556Srgrimes *
51556Srgrimes * Redistribution and use in source and binary forms, with or without
61556Srgrimes * modification, are permitted provided that the following conditions
71556Srgrimes * are met:
81556Srgrimes * 1. Redistributions of source code must retain the above copyright
91556Srgrimes *    notice, this list of conditions and the following disclaimer.
101556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111556Srgrimes *    notice, this list of conditions and the following disclaimer in the
121556Srgrimes *    documentation and/or other materials provided with the distribution.
131556Srgrimes *
141556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241556Srgrimes * SUCH DAMAGE.
251556Srgrimes */
261556Srgrimes
271556Srgrimes/*
281556Srgrimes * c99 -- compile standard C programs
291556Srgrimes *
301556Srgrimes * This is essentially a wrapper around the system C compiler that forces
311556Srgrimes * the compiler into C99 mode.
321556Srgrimes */
331556Srgrimes
341556Srgrimes#include <sys/cdefs.h>
351556Srgrimes__FBSDID("$FreeBSD: head/usr.bin/c99/c99.c 104615 2002-10-07 09:37:55Z tjr $");
361556Srgrimes
371556Srgrimes#include <sys/types.h>
3850471Speter
391556Srgrimes#include <err.h>
401556Srgrimes#include <stdio.h>
411556Srgrimes#include <stdlib.h>
421556Srgrimes#include <string.h>
4390108Simp#include <unistd.h>
4490108Simp
4590108Simpchar **args;
4690108Simpu_int cargs, nargs;
4790108Simp
4890108Simpvoid addarg(const char *item);
4990108Simpvoid usage(void);
5090108Simp
5190108Simpint
5290108Simpmain(int argc, char *argv[])
5390108Simp{
5490108Simp	int i;
5590108Simp
561556Srgrimes	args = NULL;
571556Srgrimes	cargs = nargs = 0;
581556Srgrimes
5990108Simp	addarg("cc");
6089788Sgreen	addarg("-std=iso9899:1999");
6151208Sgreen	addarg("-pedantic");
621556Srgrimes	for (i = 1; i < argc; i++)
6348051Sgreen		addarg(argv[i]);
6451208Sgreen	execv("/usr/bin/cc", args);
6551208Sgreen	err(1, "/usr/bin/cc");
6651208Sgreen}
6751249Sgreen
6851208Sgreenvoid
69addarg(const char *item)
70{
71	if (nargs + 1 > cargs) {
72		cargs += 16;
73		if ((args = realloc(args, sizeof(*args) * cargs)) == NULL)
74			err(1, "malloc");
75	}
76	if ((args[nargs++] = strdup(item)) == NULL)
77		err(1, "strdup");
78	args[nargs] = NULL;
79}
80
81void
82usage(void)
83{
84	fprintf(stderr,
85"usage: c99 [-cEgs] [-D name[=value]] [-I directory] ... [-L directory] ...\n");
86	fprintf(stderr,
87"       [-o outfile] [-O optlevel] [-U name]... operand ...\n");
88	exit(1);
89}
90