proto.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens/***********************************************************************
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* This software is part of the ast package *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* Copyright (c) 1990-2012 AT&T Intellectual Property *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* and is licensed under the *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* Eclipse Public License, Version 1.0 *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* by AT&T Intellectual Property *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* A copy of the License is available at *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* Information and Software Systems Research *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* AT&T Research *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* Florham Park NJ *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens* Glenn Fowler <gsf@research.att.com> *
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens***********************************************************************/
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * Glenn Fowler
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * AT&T Research
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * proto - make prototyped C compatible with K&R, ANSI, C++
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * output to stdout unless -r
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * NOTE: coded for minimal library support
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrensstatic const char usage[] =
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens"[-?\n@(#)$Id: proto (AT&T Research) 2012-02-20 $\n]"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens"[+NAME?proto - make prototyped C source compatible with K&R, ANSI and C++]"
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens"[+DESCRIPTION?\bproto\b converts ANSI C prototype constructs in \afile\a"
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens" to constructs compatible with K&R C, ANSI C, and C++. Only files"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens" with the line \b#pragma prototyped\b appearing in one of the first"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens" 64 lines are processed; other files are silently ignored. Output is"
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens" written to the standard output unless the \b--replace\b option is"
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens" specified, in which case \afile\a is modified in-place.]"
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens"[c:comment?\ab[m[e]]]]\a are the beginning, middle, and end comment"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens" characters. If \ae\a is omitted then it defaults to \ab\a. If \am\a is"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens" omitted then it defaults to \ab\a. Use \"\b/*\b\" for C comments,"
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens" \"\b#\b\" for shell, and \"\b(*)\b\" for pascal. If \abme\a is \"\""
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens" (the empty string) then the comment style is determined from the"
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens" input \afile\a suffix; no notice is prepended if the comment"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens" style cannot be determined.]:[bme:=\"/*\"]"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens"[d:disable?Disable prototype conversion but still emit the identification"
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens"[e:externs?All \bextern\b references are for \apackage\a. Some systems"
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens" require special attributes for imported and exported dll data symbols."
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens" If \b_BLD_\b\apackage\a is not defined then \bextern\b data references"
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens" will be assigned the dll import attribute when supported by the local"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens" compiler.]:[package]"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens"[f:force?Force conversion for files that do not contain"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens" \b#pragma prototyped\b.]"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens"[h!:header?Emit the \bproto\b header definition preamble.]"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens"[i:inverse?Specifies inverse proto: classic function definitions are"
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens" converted to ANSI prototype form and non-ANSI directives are"
" that should be placed in a \b.h\b file shared by \b*.c\b and then"
"[s:include?Output \b#include <prototyped.h>\b rather than expanding the"
#include <ast.h>
#include <error.h>
#include <times.h>
#ifndef __STDC__
#ifndef creat
#if PROTO_STANDALONE
#ifndef access
#ifndef ctime
#ifndef mkdir
#include <fcntl.h>
#if PROTO_STANDALONE
#include <stdio.h>
#include <time.h>
#ifndef __STDC__
#ifndef O_RDONLY
#define O_RDONLY 0
#ifndef S_IRUSR
#ifndef S_IWUSR
#ifndef S_IXUSR
#ifndef S_IRGRP
#ifndef S_IWGRP
#ifndef S_IXGRP
#ifndef S_IROTH
#ifndef S_IWOTH
#ifndef S_IXOTH
#ifndef __STDC__
#if PROTO_STANDALONE
extern int access(const char*, int);
extern int mkdir(const char*, int);
#if PROTO_STANDALONE
if (preserve)
if (preserve)
return preserve;
#include "ppproto.c"
proto(char* file, char* license, char* options, char* package, char* copy, char* comment, int flags)
int fd;
if (!file)
pppclose(b);
else if (copy)
pppclose(b);
e = buf + n;
pppclose(b);
pppclose(b);
while ((n = pppread(b)) > 0)
pppclose(b);
return flags;
#if !PROTO_STANDALONE
typedef struct Sufcom_s
} Sufcom_t;
register char* suffix;
suffix = 0;
while (*file)
return comment;
char* file;
int fd;
char* op;
char* oe;
char* comment = 0;
char* copy = 0;
char* list = 0;
char* license = 0;
char* options = 0;
char* package = 0;
#if PROTO_STANDALONE
switch (*++file)
if (!options)
n = strlen(b);
op += n;
b = "Usage: proto [-dfhinprstvzP+S] [-C directory] [-e package] [-l file]\n [-o \"name='value' ...\"] [-L file] file ...\n";
if (!options)
op += n;
if (list)
fd = 0;
if (b > buf)
if (fd > 0)
if (file)
do flags = proto(file, license, options, package, copy, type(file, comment), flags); while (file = *++argv);
else if (!list)