cdecl-2.5.orig/ 40755 1750 1750 0 6076635641 12346 5ustar hallonhalloncdecl-2.5.orig/README100644 1750 1750 5656 6076634730 13335 0ustar hallonhallon Cdecl version 2.5 Cdecl is a program which will turn English-like phrases such as "declare foo as array 5 of pointer to function returning int" into C declarations such as "int (*foo[5])()". It can also translate the C into the pseudo- English. And it handles typecasts, too. Plus C++. And in this version it has command line editing and history with the GNU readline library. The files in this distribution are: cdecl.c The cdecl source code. cdlex.l The lex source for the cdecl lexer. cdgram.y The yacc source for the cdecl parser. cdecl.1 The cdecl man page. c++decl.1 The c++decl man page (really just cdecl.1). testset A script to test the operation of cdecl. testset++ A script to test the operation of c++decl. Makefile The makefile to build and install cdecl. README See file README for description of this file. If you have the GNU readline library and its headers in readline/*.h and termcap then you can install cdecl by "make" followed by "make install". To compile without readline and termcap, you must edit the Makefile and remove -DUSE_READLINE from the CFLAGS and -lreadline and -ltermcap from the LIBS. You will, unfortunately, lose the command line editing, history, and keyword completion. By default cdecl installs in /usr/bin, but this is configurable in the Makefile. I debated with myself whether to provide a precompiled libreadline.a and associated headers with the cdecl distribution, however that would have made the tar file *much* bigger, so I have decided not to. If you think I should, or you would like me to send you readline, please get in touch with me at conrad@detroit.freenet.org. You can find the source for readline in the bash distribution on prep.ai.mit.edu:/pub/gnu or on ftp.uu.net:/pub/gnu, or wherever fine GNU source isn't sold. You should also be able to find a ready-to-run ELF binary of cdecl in the same place you got this from. It should be on sunsite.unc.edu in the directory /pub/Linux/devel/lang/c/, or on any of the many sunsite mirrors. My three favorites are ftp.cc.gatech.edu, ftp.cdrom.com, and uiarchive.cso.uiuc.edu. You may well be wondering what the status of cdecl is. So am I. It was twice posted to comp.sources.unix, but neither edition carried any mention of copyright. This version is derived from the second edition. I have no reason to believe there are any limitations on its use, and strongly believe it to be in the Public Domain. GNU readline is, of course, covered by the GNU General Public License. I was inspired to port cdecl to Linux as there was no version of it available in the various Linux software archives that I am aware of. The addition of GNU readline support seemed like a logical extension of the program. Be warned, however, that linking with readline more than doubles the size of the program. Those whose main concern is space might wish to build a version without readline. David R. Conrad conrad@detroit.freenet.org Detroit, Michigan, USA 16 January 1996 cdecl-2.5.orig/Makefile100644 1750 1750 3262 6076634546 14111 0ustar hallonhallon# @(#)makefile 2.3 1/16/96 # the following can be added to CFLAGS for various things # # add -DNOVOID If your compiler can not handle the void keyword. # add -DBSD For BSD4.[23] UNIX Systems. # add -DDOS For MS-DOS/PC-DOS Systems, Micro-Soft C 4.0, Turbo C # Use the ANSI option. # add -DNOGETOPT If your library doesn't have getopt(). # Another routine will be used in its place. # add -DNOVARARGS If you have neither (ANSI C) or # (pre-ANSI C). # Another method will be compiled instead. # add -Ddodebug To compile in debugging trace statements. # add -Ddoyydebug To compile in yacc trace statements. # # add -DUSE_READLINE To compile in support for the GNU readline library. CFLAGS= -s -O2 -DUSE_READLINE CC= gcc LIBS= -lreadline -ltermcap ALLFILES= makefile cdgram.y cdlex.l cdecl.c cdecl.1 testset testset++ BINDIR= /usr/bin MANDIR= /usr/man/man1 CATDIR= /usr/man/cat1 INSTALL= install -c INSTALL_DATA= install -c -m 644 cdecl: c++decl ln c++decl cdecl c++decl: cdgram.c cdlex.c cdecl.c $(CC) $(CFLAGS) -o c++decl cdecl.c $(LIBS) rm -f cdecl cdlex.c: cdlex.l lex cdlex.l && mv lex.yy.c cdlex.c cdgram.c: cdgram.y yacc cdgram.y && mv y.tab.c cdgram.c test: ./cdecl < testset ./c++decl < testset++ install: cdecl $(INSTALL) cdecl $(BINDIR) ln $(BINDIR)/cdecl $(BINDIR)/c++decl $(INSTALL_DATA) cdecl.1 $(MANDIR) $(INSTALL_DATA) c++decl.1 $(MANDIR) clean: rm -f cdgram.c cdlex.c cdecl y.output c++decl clobber: clean rm -f $(BINDIR)/cdecl $(BINDIR)/c++decl rm -f $(MANDIR)/cdecl.1 $(MANDIR)/c++decl.1 rm -f $(CATDIR)/cdecl.1.gz cdecl.cpio: $(ALLFILES) ls $(ALLFILES) | cpio -ocv > cdecl.cpio cdecl.shar: $(ALLFILES) shar $(ALLFILES) > cdecl.shar cdecl-2.5.orig/cdecl.c100644 1750 1750 77343 6076620606 13712 0ustar hallonhallon/* * cdecl - ANSI C and C++ declaration composer & decoder * * originally written * Graham Ross * once at tektronix!tekmdp!grahamr * now at Context, Inc. * * modified to provide hints for unsupported types * added argument lists for functions * added 'explain cast' grammar * added #ifdef for 'create program' feature * ???? (sorry, I lost your name and login) * * conversion to ANSI C * David Wolverton * ihnp4!houxs!daw * * merged D. Wolverton's ANSI C version w/ ????'s version * added function prototypes * added C++ declarations * made type combination checking table driven * added checks for void variable combinations * made 'create program' feature a runtime option * added file parsing as well as just stdin * added help message at beginning * added prompts when on a TTY or in interactive mode * added getopt() usage * added -a, -r, -p, -c, -d, -D, -V, -i and -+ options * delinted * added #defines for those without getopt or void * added 'set options' command * added 'quit/exit' command * added synonyms * Tony Hansen * attmail!tony, ihnp4!pegasus!hansen * * added extern, register, static * added links to explain, cast, declare * separately developed ANSI C support * Merlyn LeRoy * merlyn@rose3.rosemount.com * * merged versions from LeRoy * added tmpfile() support * allow more parts to be missing during explanations * Tony Hansen * attmail!tony, ihnp4!pegasus!hansen * * added GNU readline() support * added dotmpfile_from_string() to support readline() * outdented C help text to prevent line from wrapping * minor tweaking of makefile && mv makefile Makefile * took out interactive and nointeractive commands when * compiled with readline support * added prompt and noprompt commands, -q option * Dave Conrad * conrad@detroit.freenet.org */ char cdeclsccsid[] = "@(#)cdecl.c 2.5 1/15/96"; #include #include #if __STDC__ || defined(DOS) # include # include # include # include #else # ifndef NOVARARGS # include # endif /* ndef NOVARARGS */ char *malloc(); void free(), exit(), perror(); # ifdef BSD # include extern int errno; # define strrchr rindex # define NOTMPFILE # else # include # include # endif /* BSD */ # ifdef NOVOID # define void int # endif /* NOVOID */ #endif /* __STDC__ || DOS */ #ifdef USE_READLINE # include /* prototypes for functions related to readline() */ char * getline(); char ** attempt_completion(char *, int, int); char * keyword_completion(char *, int); char * command_completion(char *, int); #endif /* maximum # of chars from progname to display in prompt */ #define MAX_NAME 32 /* this is the prompt for readline() to display */ char cdecl_prompt[MAX_NAME+3]; /* backup copy of prompt to save it while prompting is off */ char real_prompt[MAX_NAME+3]; #define MB_SHORT 0001 #define MB_LONG 0002 #define MB_UNSIGNED 0004 #define MB_INT 0010 #define MB_CHAR 0020 #define MB_FLOAT 0040 #define MB_DOUBLE 0100 #define MB_VOID 0200 #define MB_SIGNED 0400 #define NullCP ((char*)NULL) #ifdef dodebug # define Debug(x) do { if (DebugFlag) (void) fprintf x; } while (0) #else # define Debug(x) /* nothing */ #endif #if __STDC__ char *ds(char *), *cat(char *, ...), *visible(int); int getopt(int,char **,char *); int main(int, char **); int yywrap(void); int dostdin(void); void mbcheck(void), dohelp(void), usage(void); void prompt(void), doprompt(void), noprompt(void); void unsupp(char *, char *); void notsupported(char *, char *, char *); void yyerror(char *); void doset(char *); void dodeclare(char*, char*, char*, char*, char*); void docast(char*, char*, char*, char*); void dodexplain(char*, char*, char*, char*); void docexplain(char*, char*, char*, char*); void setprogname(char *); int dotmpfile(int, char**), dofileargs(int, char**); #else char *ds(), *cat(), *visible(); int getopt(); void mbcheck(), dohelp(), usage(); void prompt(), doprompt(), noprompt(); void unsupp(), notsupported(); void yyerror(); void doset(), dodeclare(), docast(), dodexplain(), docexplain(); void setprogname(); int dotmpfile(), dofileargs(); #endif /* __STDC__ */ FILE *tmpfile(); /* variables used during parsing */ unsigned modbits = 0; int arbdims = 1; char *savedname = 0; char unknown_name[] = "unknown_name"; char prev = 0; /* the current type of the variable being examined */ /* values type */ /* p pointer */ /* r reference */ /* f function */ /* a array (of arbitrary dimensions) */ /* A array with dimensions */ /* n name */ /* v void */ /* s struct | class */ /* t simple type (int, long, etc.) */ /* options */ int RitchieFlag = 0; /* -r, assume Ritchie PDP C language */ int MkProgramFlag = 0; /* -c, output {} and ; after declarations */ int PreANSIFlag = 0; /* -p, assume pre-ANSI C language */ int CplusplusFlag = 0; /* -+, assume C++ language */ int OnATty = 0; /* stdin is coming from a terminal */ int Interactive = 0; /* -i, overrides OnATty */ int KeywordName = 0; /* $0 is a keyword (declare, explain, cast) */ char *progname = "cdecl"; /* $0 */ int quiet = 0; /* -q, quiets prompt and initial help msg */ #if dodebug int DebugFlag = 0; /* -d, output debugging trace info */ #endif #ifdef doyydebug /* compile in yacc trace statements */ #define YYDEBUG 1 #endif /* doyydebug */ #include "cdgram.c" #include "cdlex.c" /* definitions (and abbreviations) for type combinations cross check table */ #define ALWAYS 0 /* combo always okay */ #define _ ALWAYS #define NEVER 1 /* combo never allowed */ #define X NEVER #define RITCHIE 2 /* combo not allowed in Ritchie compiler */ #define R RITCHIE #define PREANSI 3 /* combo not allowed in Pre-ANSI compiler */ #define P PREANSI #define ANSI 4 /* combo not allowed anymore in ANSI compiler */ #define A ANSI /* This is an lower left triangular array. If we needed */ /* to save 9 bytes, the "long" row can be removed. */ char crosscheck[9][9] = { /* L, I, S, C, V, U, S, F, D, */ /* long */ _, _, _, _, _, _, _, _, _, /* int */ _, _, _, _, _, _, _, _, _, /* short */ X, _, _, _, _, _, _, _, _, /* char */ X, X, X, _, _, _, _, _, _, /* void */ X, X, X, X, _, _, _, _, _, /* unsigned */ R, _, R, R, X, _, _, _, _, /* signed */ P, P, P, P, X, X, _, _, _, /* float */ A, X, X, X, X, X, X, _, _, /* double */ P, X, X, X, X, X, X, X, _ }; /* the names and bits checked for each row in the above array */ struct { char *name; int bit; } crosstypes[9] = { { "long", MB_LONG }, { "int", MB_INT }, { "short", MB_SHORT }, { "char", MB_CHAR }, { "void", MB_VOID }, { "unsigned", MB_UNSIGNED }, { "signed", MB_SIGNED }, { "float", MB_FLOAT }, { "double", MB_DOUBLE } }; /* Run through the crosscheck array looking */ /* for unsupported combinations of types. */ void mbcheck() { register int i, j, restrict; char *t1, *t2; /* Loop through the types */ /* (skip the "long" row) */ for (i = 1; i < 9; i++) { /* if this type is in use */ if ((modbits & crosstypes[i].bit) != 0) { /* check for other types also in use */ for (j = 0; j < i; j++) { /* this type is not in use */ if (!(modbits & crosstypes[j].bit)) continue; /* check the type of restriction */ restrict = crosscheck[i][j]; if (restrict == ALWAYS) continue; t1 = crosstypes[i].name; t2 = crosstypes[j].name; if (restrict == NEVER) { notsupported("", t1, t2); } else if (restrict == RITCHIE) { if (RitchieFlag) notsupported(" (Ritchie Compiler)", t1, t2); } else if (restrict == PREANSI) { if (PreANSIFlag || RitchieFlag) notsupported(" (Pre-ANSI Compiler)", t1, t2); } else if (restrict == ANSI) { if (!RitchieFlag && !PreANSIFlag) notsupported(" (ANSI Compiler)", t1, t2); } else { (void) fprintf (stderr, "%s: Internal error in crosscheck[%d,%d]=%d!\n", progname, i, j, restrict); exit(1); /* NOTREACHED */ } } } } } /* undefine these as they are no longer needed */ #undef _ #undef ALWAYS #undef X #undef NEVER #undef R #undef RITCHIE #undef P #undef PREANSI #undef A #undef ANSI #ifdef USE_READLINE /* this section contains functions and declarations used with readline() */ /* the readline info pages make this clearer than any comments possibly * could, so see them for more information */ char *commands[] = { "declare", "explain", "cast", "help", "set", "exit", "quit", NULL }; char *keywords[] = { "function", "returning", "array", "pointer", "reference", "member", "const", "volatile", "noalias", "struct", "union", "enum", "class", "extern", "static", "auto", "register", "short", "long", "signed", "unsigned", "char", "float", "double", "void", NULL }; char *options[] = { "options", "create", "nocreate", "prompt", "noprompt", #if 0 "interactive", "nointeractive", #endif "ritchie", "preansi", "ansi", "cplusplus", NULL }; /* A static variable for holding the line. */ static char *line_read = NULL; /* Read a string, and return a pointer to it. Returns NULL on EOF. */ char * getline () { /* If the buffer has already been allocated, return the memory to the free pool. */ if (line_read != NULL) { free (line_read); line_read = NULL; } /* Get a line from the user. */ line_read = readline (cdecl_prompt); /* If the line has any text in it, save it on the history. */ if (line_read && *line_read) add_history (line_read); return (line_read); } char ** attempt_completion(char *text, int start, int end) { char **matches = NULL; if (start == 0) matches = completion_matches(text, command_completion); return matches; } char * command_completion(char *text, int flag) { static int index, len; char *command; if (!flag) { index = 0; len = strlen(text); } while (command = commands[index]) { index++; if (!strncmp(command, text, len)) return strdup(command); } return NULL; } char * keyword_completion(char *text, int flag) { static int index, len, set, into; char *keyword, *option; if (!flag) { index = 0; len = strlen(text); /* completion works differently if the line begins with "set" */ set = !strncmp(rl_line_buffer, "set", 3); into = 0; } if (set) { while (option = options[index]) { index++; if (!strncmp(option, text, len)) return strdup(option); } } else { /* handle "int" and "into" as special cases */ if (!into) { into = 1; if (!strncmp(text, "into", len) && strncmp(text, "int", len)) return strdup("into"); if (strncmp(text, "int", len)) return keyword_completion(text, into); /* normally "int" and "into" would conflict with one another when * completing; cdecl tries to guess which one you wanted, and it * always guesses correctly */ if (!strncmp(rl_line_buffer, "cast", 4) && !strstr(rl_line_buffer, "into")) return strdup("into"); else return strdup("int"); } else while (keyword = keywords[index]) { index++; if (!strncmp(keyword, text, len)) return strdup(keyword); } } return NULL; } #endif /* USE_READLINE */ /* Write out a message about something */ /* being unsupported, possibly with a hint. */ void unsupp(s,hint) char *s,*hint; { notsupported("", s, NullCP); if (hint) (void) fprintf(stderr, "\t(maybe you mean \"%s\")\n", hint); } /* Write out a message about something */ /* being unsupported on a particular compiler. */ void notsupported(compiler, type1, type2) char *compiler, *type1, *type2; { if (type2) (void) fprintf(stderr, "Warning: Unsupported in%s C%s -- '%s' with '%s'\n", compiler, CplusplusFlag ? "++" : "", type1, type2); else (void) fprintf(stderr, "Warning: Unsupported in%s C%s -- '%s'\n", compiler, CplusplusFlag ? "++" : "", type1); } /* Called by the yacc grammar */ void yyerror(s) char *s; { (void) printf("%s\n",s); Debug((stdout, "yychar=%d\n", yychar)); } /* Called by the yacc grammar */ int yywrap() { return 1; } /* * Support for dynamic strings: * cat() creates a string from the concatenation * of a null terminated list of input strings. * The input strings are free()'d by cat() * (so they better have been malloc()'d). * * the different methods of and * are handled within these macros */ #if __STDC__ # define VA_DCL(type,var) (type var,...) # define VA_START(list,var,type) ((va_start(list,var)) , (var)) #else #if defined(DOS) # define VA_DCL(type,var) (var,...) type var; # define VA_START(list,var,type) ((va_start(list,var)) , (var)) #else #ifndef NOVARARGS # define VA_DCL(type,var) (va_alist) va_dcl # define VA_START(list,var,type) ((va_start(list)) , va_arg(list,type)) #else /* * it is assumed here that machines which don't have either * or will put its arguments on * the stack in the "usual" way and consequently can grab * the arguments using the "take the address of the first * parameter and increment by sizeof" trick. */ # define VA_DCL(type,var) (var) type var; # define VA_START(list,var,type) (list = (va_list)&(var) , (var)) # define va_arg(list,type) ((type *)(list += sizeof(type)))[-1] # define va_end(p) /* nothing */ typedef char *va_list; #endif /* NOVARARGS */ #endif /* DOS */ #endif /* __STDC__ */ /* VARARGS */ char *cat VA_DCL(char*, s1) { register char *newstr; register unsigned len = 1; char *str; va_list args; /* find the length which needs to be allocated */ str = VA_START(args, s1, char*); for ( ; str; str = va_arg(args, char*)) len += strlen(str); va_end(args); /* allocate it */ newstr = malloc(len); if (newstr == 0) { (void) fprintf (stderr, "%s: out of malloc space within cat()!\n", progname); exit(1); } newstr[0] = '\0'; /* copy in the strings */ str = VA_START(args, s1, char*); for ( ; str; str = va_arg(args, char*)) { (void) strcat(newstr,str); free(str); } va_end(args); Debug((stderr, "\tcat created '%s'\n", newstr)); return newstr; } /* * ds() makes a malloc()'d string from one that's not. */ char *ds(s) char *s; { register char *p = malloc((unsigned)(strlen(s)+1)); if (p) (void) strcpy(p,s); else { (void) fprintf (stderr, "%s: malloc() failed!\n", progname); exit(1); } return p; } /* return a visible representation of a character */ char *visible(c) int c; { static char buf[5]; c &= 0377; if (isprint(c)) { buf[0] = c; buf[1] = '\0'; } else (void) sprintf(buf,"\\%03o",c); return buf; } #ifdef NOTMPFILE /* provide a conservative version of tmpfile() */ /* for those systems without it. */ /* tmpfile() returns a FILE* of a file opened */ /* for read&write. It is supposed to be */ /* automatically removed when it gets closed, */ /* but here we provide a separate rmtmpfile() */ /* function to perform that function. */ /* Also provide several possible file names to */ /* try for opening. */ static char *file4tmpfile = 0; FILE *tmpfile() { static char *listtmpfiles[] = { "/usr/tmp/cdeclXXXXXX", "/tmp/cdeclXXXXXX", "/cdeclXXXXXX", "cdeclXXXXXX", 0 }; char **listp = listtmpfiles; for ( ; *listp; listp++) { FILE *retfp; (void) mktemp(*listp); retfp = fopen(*listp, "w+"); if (!retfp) continue; file4tmpfile = *listp; return retfp; } return 0; } void rmtmpfile() { if (file4tmpfile) (void) unlink(file4tmpfile); } #else /* provide a mock rmtmpfile() for normal systems */ # define rmtmpfile() /* nothing */ #endif /* NOTMPFILE */ #ifndef NOGETOPT extern int optind; #else /* This is a miniature version of getopt() which will */ /* do just barely enough for us to get by below. */ /* Options are not allowed to be bunched up together. */ /* Option arguments are not supported. */ int optind = 1; int getopt(argc,argv,optstring) char **argv; char *optstring; { int ret; char *p; if ((argv[optind][0] != '-') #ifdef DOS && (argv[optind][0] != '/') #endif /* DOS */ ) return EOF; ret = argv[optind][1]; optind++; for (p = optstring; *p; p++) if (*p == ret) return ret; (void) fprintf (stderr, "%s: illegal option -- %s\n", progname, visible(ret)); return '?'; } #endif /* the help messages */ struct helpstruct { char *text; /* generic text */ char *cpptext; /* C++ specific text */ } helptext[] = { /* up-to 23 lines of help text so it fits on (24x80) screens */ /* 1 */{ "[] means optional; {} means 1 or more; <> means defined elsewhere", 0 }, /* 2 */{ " commands are separated by ';' and newlines", 0 }, /* 3 */{ "command:", 0 }, /* 4 */{ " declare as ", 0 }, /* 5 */{ " cast into ", 0 }, /* 6 */{ " explain ", 0 }, /* 7 */{ " set or set options", 0 }, /* 8 */{ " help, ?", 0 }, /* 9 */{ " quit or exit", 0 }, /* 10 */{ "english:", 0 }, /* 11 */{ " function [( )] returning ", 0 }, /* 12 */{ " array [] of ", 0 }, /* 13 */{ " [{ const | volatile | noalias }] pointer to ", " [{const|volatile}] {pointer|reference} to [member of class ] " }, /* 14 */{ " ", 0 }, /* 15 */{ "type:", 0 }, /* 16 */{ " {[] [{}] []}", 0 }, /* 17 */{ " { struct | union | enum } ", " {struct|class|union|enum} " }, /* 18 */{ "decllist: a comma separated list of , or as ", 0 }, /* 19 */{ "name: a C identifier", 0 }, /* 20 */{ "gibberish: a C declaration, like 'int *x', or cast, like '(int *)x'", 0 }, /* 21 */{ "storage-class: extern, static, auto, register", 0 }, /* 22 */{ "C-type: int, char, float, double, or void", 0 }, /* 23 */{ "modifier: short, long, signed, unsigned, const, volatile, or noalias", "modifier: short, long, signed, unsigned, const, or volatile" }, { 0, 0 } }; /* Print out the help text */ void dohelp() { register struct helpstruct *p; register char *fmt = CplusplusFlag ? " %s\n" : " %s\n"; for (p = helptext; p->text; p++) if (CplusplusFlag && p->cpptext) (void) printf(fmt, p->cpptext); else (void) printf(fmt, p->text); } /* Tell how to invoke cdecl. */ void usage() { (void) fprintf (stderr, "Usage: %s [-r|-p|-a|-+] [-ciq%s%s] [files...]\n", progname, #ifdef dodebug "d", #else "", #endif /* dodebug */ #ifdef doyydebug "D" #else "" #endif /* doyydebug */ ); (void) fprintf (stderr, "\t-r Check against Ritchie PDP C Compiler\n"); (void) fprintf (stderr, "\t-p Check against Pre-ANSI C Compiler\n"); (void) fprintf (stderr, "\t-a Check against ANSI C Compiler%s\n", CplusplusFlag ? "" : " (the default)"); (void) fprintf (stderr, "\t-+ Check against C++ Compiler%s\n", CplusplusFlag ? " (the default)" : ""); (void) fprintf (stderr, "\t-c Create compilable output (include ; and {})\n"); (void) fprintf (stderr, "\t-i Force interactive mode\n"); (void) fprintf (stderr, "\t-q Quiet prompt\n"); #ifdef dodebug (void) fprintf (stderr, "\t-d Turn on debugging mode\n"); #endif /* dodebug */ #ifdef doyydebug (void) fprintf (stderr, "\t-D Turn on YACC debugging mode\n"); #endif /* doyydebug */ exit(1); /* NOTREACHED */ } /* Manage the prompts. */ static int prompting; void doprompt() { prompting = 1; } void noprompt() { prompting = 0; } void prompt() { #ifndef USE_READLINE if ((OnATty || Interactive) && prompting) { (void) printf("%s", cdecl_prompt); # if 0 (void) printf("%s> ", progname); # endif /* that was the old way to display the prompt */ (void) fflush(stdout); } #endif } /* Save away the name of the program from argv[0] */ void setprogname(argv0) char *argv0; { #ifdef DOS char *dot; #endif /* DOS */ progname = strrchr(argv0, '/'); #ifdef DOS if (!progname) progname = strrchr(argv0, '\\'); #endif /* DOS */ if (progname) progname++; else progname = argv0; #ifdef DOS dot = strchr(progname, '.'); if (dot) *dot = '\0'; for (dot = progname; *dot; dot++) *dot = tolower(*dot); #endif /* DOS */ /* this sets up the prompt, which is on by default */ { int len; len = strlen(progname); if (len > MAX_NAME) len = MAX_NAME; strncpy(real_prompt, progname, len); real_prompt[len] = '>'; real_prompt[len+1] = ' '; real_prompt[len+2] = '\0'; } } /* Run down the list of keywords to see if the */ /* program is being called named as one of them */ /* or the first argument is one of them. */ int namedkeyword(argn) char *argn; { static char *cmdlist[] = { "explain", "declare", "cast", "help", "?", "set", 0 }; /* first check the program name */ char **cmdptr = cmdlist; for ( ; *cmdptr; cmdptr++) if (strcmp(*cmdptr, progname) == 0) { KeywordName = 1; return 1; } /* now check $1 */ for (cmdptr = cmdlist; *cmdptr; cmdptr++) if (strcmp(*cmdptr, argn) == 0) return 1; /* nope, must be file name arguments */ return 0; } /* Read from standard input, turning */ /* on prompting if necessary. */ int dostdin() { int ret; if (OnATty || Interactive) { #ifndef USE_READLINE if (!quiet) (void) printf("Type `help' or `?' for help\n"); prompt(); #else char *line, *oldline; int len, newline; if (!quiet) (void) printf("Type `help' or `?' for help\n"); ret = 0; while ((line = getline())) { if (!strcmp(line, "quit") || !strcmp(line, "exit")) { free(line); return ret; } newline = 0; /* readline() strips newline, we add semicolon if necessary */ len = strlen(line); if (len && line[len-1] != '\n' && line[len-1] != ';') { newline = 1; oldline = line; line = malloc(len+2); strcpy(line, oldline); line[len] = ';'; line[len+1] = '\0'; } if (len) ret = dotmpfile_from_string(line); if (newline) free(line); } puts(""); return ret; #endif } yyin = stdin; ret = yyparse(); OnATty = 0; return ret; } #ifdef USE_READLINE /* Write a string into a file and treat that file as the input. */ int dotmpfile_from_string(s) char *s; { int ret = 0; FILE *tmpfp = tmpfile(); if (!tmpfp) { int sverrno = errno; (void) fprintf (stderr, "%s: cannot open temp file\n", progname); errno = sverrno; perror(progname); return 1; } if (fputs(s, tmpfp) == EOF) { int sverrno; sverrno = errno; (void) fprintf (stderr, "%s: error writing to temp file\n", progname); errno = sverrno; perror(progname); (void) fclose(tmpfp); rmtmpfile(); return 1; } rewind(tmpfp); yyin = tmpfp; ret += yyparse(); (void) fclose(tmpfp); rmtmpfile(); return ret; } #endif /* USE_READLINE */ /* Write the arguments into a file */ /* and treat that file as the input. */ int dotmpfile(argc, argv) int argc; char **argv; { int ret = 0; FILE *tmpfp = tmpfile(); if (!tmpfp) { int sverrno = errno; (void) fprintf (stderr, "%s: cannot open temp file\n", progname); errno = sverrno; perror(progname); return 1; } if (KeywordName) if (fputs(progname, tmpfp) == EOF) { int sverrno; errwrite: sverrno = errno; (void) fprintf (stderr, "%s: error writing to temp file\n", progname); errno = sverrno; perror(progname); (void) fclose(tmpfp); rmtmpfile(); return 1; } for ( ; optind < argc; optind++) if (fprintf(tmpfp, " %s", argv[optind]) == EOF) goto errwrite; if (putc('\n', tmpfp) == EOF) goto errwrite; rewind(tmpfp); yyin = tmpfp; ret += yyparse(); (void) fclose(tmpfp); rmtmpfile(); return ret; } /* Read each of the named files for input. */ int dofileargs(argc, argv) int argc; char **argv; { FILE *ifp; int ret = 0; for ( ; optind < argc; optind++) if (strcmp(argv[optind], "-") == 0) ret += dostdin(); else if ((ifp = fopen(argv[optind], "r")) == NULL) { int sverrno = errno; (void) fprintf (stderr, "%s: cannot open %s\n", progname, argv[optind]); errno = sverrno; perror(argv[optind]); ret++; } else { yyin = ifp; ret += yyparse(); } return ret; } /* print out a cast */ void docast(name, left, right, type) char *name, *left, *right, *type; { int lenl = strlen(left), lenr = strlen(right); if (prev == 'f') unsupp("Cast into function", "cast into pointer to function"); else if (prev=='A' || prev=='a') unsupp("Cast into array","cast into pointer"); (void) printf("(%s%*s%s)%s\n", type, lenl+lenr?lenl+1:0, left, right, name ? name : "expression"); free(left); free(right); free(type); if (name) free(name); } /* print out a declaration */ void dodeclare(name, storage, left, right, type) char *name, *storage, *left, *right, *type; { if (prev == 'v') unsupp("Variable of type void", "variable of type pointer to void"); if (*storage == 'r') switch (prev) { case 'f': unsupp("Register function", NullCP); break; case 'A': case 'a': unsupp("Register array", NullCP); break; case 's': unsupp("Register struct/class", NullCP); break; } if (*storage) (void) printf("%s ", storage); (void) printf("%s %s%s%s", type, left, name ? name : (prev == 'f') ? "f" : "var", right); if (MkProgramFlag) { if ((prev == 'f') && (*storage != 'e')) (void) printf(" { }\n"); else (void) printf(";\n"); } else { (void) printf("\n"); } free(storage); free(left); free(right); free(type); if (name) free(name); } void dodexplain(storage, constvol, type, decl) char *storage, *constvol, *type, *decl; { if (type && (strcmp(type, "void") == 0)) if (prev == 'n') unsupp("Variable of type void", "variable of type pointer to void"); else if (prev == 'a') unsupp("array of type void", "array of type pointer to void"); else if (prev == 'r') unsupp("reference to type void", "pointer to void"); if (*storage == 'r') switch (prev) { case 'f': unsupp("Register function", NullCP); break; case 'A': case 'a': unsupp("Register array", NullCP); break; case 's': unsupp("Register struct/union/enum/class", NullCP); break; } (void) printf("declare %s as ", savedname); if (*storage) (void) printf("%s ", storage); (void) printf("%s", decl); if (*constvol) (void) printf("%s ", constvol); (void) printf("%s\n", type ? type : "int"); } void docexplain(constvol, type, cast, name) char *constvol, *type, *cast, *name; { if (strcmp(type, "void") == 0) if (prev == 'a') unsupp("array of type void", "array of type pointer to void"); else if (prev == 'r') unsupp("reference to type void", "pointer to void"); (void) printf("cast %s into %s", name, cast); if (strlen(constvol) > 0) (void) printf("%s ", constvol); (void) printf("%s\n",type); } /* Do the appropriate things for the "set" command. */ void doset(opt) char *opt; { if (strcmp(opt, "create") == 0) { MkProgramFlag = 1; } else if (strcmp(opt, "nocreate") == 0) { MkProgramFlag = 0; } else if (strcmp(opt, "prompt") == 0) { prompting = 1; strcpy(cdecl_prompt, real_prompt); } else if (strcmp(opt, "noprompt") == 0) { prompting = 0; cdecl_prompt[0] = '\0'; } #ifndef USE_READLINE /* I cannot seem to figure out what nointeractive was intended to do -- * it didn't work well to begin with, and it causes problem with * readline, so I'm removing it, for now. -i still works. */ else if (strcmp(opt, "interactive") == 0) { Interactive = 1; } else if (strcmp(opt, "nointeractive") == 0) { Interactive = 0; OnATty = 0; } #endif else if (strcmp(opt, "ritchie") == 0) { CplusplusFlag=0; RitchieFlag=1; PreANSIFlag=0; } else if (strcmp(opt, "preansi") == 0) { CplusplusFlag=0; RitchieFlag=0; PreANSIFlag=1; } else if (strcmp(opt, "ansi") == 0) { CplusplusFlag=0; RitchieFlag=0; PreANSIFlag=0; } else if (strcmp(opt, "cplusplus") == 0) { CplusplusFlag=1; RitchieFlag=0; PreANSIFlag=0; } #ifdef dodebug else if (strcmp(opt, "debug") == 0) { DebugFlag = 1; } else if (strcmp(opt, "nodebug") == 0) { DebugFlag = 0; } #endif /* dodebug */ #ifdef doyydebug else if (strcmp(opt, "yydebug") == 0) { yydebug = 1; } else if (strcmp(opt, "noyydebug") == 0) { yydebug = 0; } #endif /* doyydebug */ else { if ((strcmp(opt, unknown_name) != 0) && (strcmp(opt, "options") != 0)) (void) printf("Unknown set option: '%s'\n", opt); (void) printf("Valid set options (and command line equivalents) are:\n"); (void) printf("\toptions\n"); (void) printf("\tcreate (-c), nocreate\n"); (void) printf("\tprompt, noprompt (-q)\n"); #ifndef USE_READLINE (void) printf("\tinteractive (-i), nointeractive\n"); #endif (void) printf("\tritchie (-r), preansi (-p), ansi (-a) or cplusplus (-+)\n"); #ifdef dodebug (void) printf("\tdebug (-d), nodebug\n"); #endif /* dodebug */ #ifdef doyydebug (void) printf("\tyydebug (-D), noyydebug\n"); #endif /* doyydebug */ (void) printf("\nCurrent set values are:\n"); (void) printf("\t%screate\n", MkProgramFlag ? " " : " no"); (void) printf("\t%sprompt\n", cdecl_prompt[0] ? " " : " no"); (void) printf("\t%sinteractive\n", (OnATty || Interactive) ? " " : " no"); if (RitchieFlag) (void) printf("\t ritchie\n"); else (void) printf("\t(noritchie)\n"); if (PreANSIFlag) (void) printf("\t preansi\n"); else (void) printf("\t(nopreansi)\n"); if (!RitchieFlag && !PreANSIFlag && !CplusplusFlag) (void) printf("\t ansi\n"); else (void) printf("\t(noansi)\n"); if (CplusplusFlag) (void) printf("\t cplusplus\n"); else (void) printf("\t(nocplusplus)\n"); #ifdef dodebug (void) printf("\t%sdebug\n", DebugFlag ? " " : " no"); #endif /* dodebug */ #ifdef doyydebug (void) printf("\t%syydebug\n", yydebug ? " " : " no"); #endif /* doyydebug */ } } void versions() { (void) printf("Version:\n\t%s\n\t%s\n\t%s\n", cdeclsccsid, cdgramsccsid, cdlexsccsid); exit(0); } int main(argc, argv) char **argv; { int c, ret = 0; #ifdef USE_READLINE /* install completion handlers */ rl_attempted_completion_function = (CPPFunction *)attempt_completion; rl_completion_entry_function = (Function *)keyword_completion; #endif setprogname(argv[0]); #ifdef DOS if (strcmp(progname, "cppdecl") == 0) #else if (strcmp(progname, "c++decl") == 0) #endif /* DOS */ CplusplusFlag = 1; prompting = OnATty = isatty(0); while ((c = getopt(argc, argv, "cipqrpa+dDV")) != EOF) switch (c) { case 'c': MkProgramFlag=1; break; case 'i': Interactive=1; doprompt(); break; case 'q': quiet=1; noprompt(); break; /* The following are mutually exclusive. */ /* Only the last one set prevails. */ case 'r': CplusplusFlag=0; RitchieFlag=1; PreANSIFlag=0; break; case 'p': CplusplusFlag=0; RitchieFlag=0; PreANSIFlag=1; break; case 'a': CplusplusFlag=0; RitchieFlag=0; PreANSIFlag=0; break; case '+': CplusplusFlag=1; RitchieFlag=0; PreANSIFlag=0; break; #ifdef dodebug case 'd': DebugFlag=1; break; #endif /* dodebug */ #ifdef doyydebug case 'D': yydebug=1; break; #endif /* doyydebug */ case 'V': versions(); break; case '?': usage(); break; } /* Set up the prompt. */ if (prompting) strcpy(cdecl_prompt, real_prompt); else cdecl_prompt[0] = '\0'; /* Run down the list of arguments, parsing each one. */ /* Use standard input if no file names or "-" is found. */ if (optind == argc) ret += dostdin(); /* If called as explain, declare or cast, or first */ /* argument is one of those, use the command line */ /* as the input. */ else if (namedkeyword(argv[optind])) ret += dotmpfile(argc, argv); else ret += dofileargs(argc, argv); exit(ret); /* NOTREACHED */ } cdecl-2.5.orig/cdlex.l100644 1750 1750 4514 6075375202 13714 0ustar hallonhallon%{ /* Lexical analyzer description for ANSI and C++ cdecl. */ /* The output of this file is included */ /* into the C file cdecl.c. */ char cdlexsccsid[] = "@(#)cdlex.l 2.2 3/30/88"; %} N [0-9] A [A-Z_a-z] AN [0-9A-Z_a-z] %% array return ARRAY; as return AS; cast return CAST; declare return DECLARE; exit return 0; explain return EXPLAIN; function return FUNCTION; func return FUNCTION; help return HELP; into return INTO; member return MEMBER; of return OF; pointer return POINTER; ptr return POINTER; quit return 0; reference return REFERENCE; ref return REFERENCE; returning return RETURNING; ret return RETURNING; set return SET; to return TO; vector return ARRAY; :: return DOUBLECOLON; [?] return HELP; [,] return COMMA; auto { yylval.dynstr = ds(yytext); return AUTO; } character { yylval.dynstr = ds("char"); return CHAR; } char { yylval.dynstr = ds(yytext); return CHAR; } class { yylval.dynstr = ds(yytext); return CLASS; } constant { yylval.dynstr = ds("const"); return CONSTVOLATILE; } const { yylval.dynstr = ds(yytext); return CONSTVOLATILE; } double { yylval.dynstr = ds(yytext); return DOUBLE; } enumeration { yylval.dynstr = ds("enum"); return ENUM; } enum { yylval.dynstr = ds(yytext); return ENUM; } extern { yylval.dynstr = ds(yytext); return EXTERN; } float { yylval.dynstr = ds(yytext); return FLOAT; } integer { yylval.dynstr = ds("int"); return INT; } int { yylval.dynstr = ds(yytext); return INT; } long { yylval.dynstr = ds(yytext); return LONG; } noalias { yylval.dynstr = ds(yytext); return CONSTVOLATILE; } register { yylval.dynstr = ds(yytext); return REGISTER; } short { yylval.dynstr = ds(yytext); return SHORT; } signed { yylval.dynstr = ds(yytext); return SIGNED; } static { yylval.dynstr = ds(yytext); return STATIC; } structure { yylval.dynstr = ds("struct"); return STRUCT; } struct { yylval.dynstr = ds(yytext); return STRUCT; } union { yylval.dynstr = ds(yytext); return UNION; } unsigned { yylval.dynstr = ds(yytext); return UNSIGNED; } void { yylval.dynstr = ds(yytext); return VOID; } volatile { yylval.dynstr = ds(yytext); return CONSTVOLATILE; } {A}{AN}* { yylval.dynstr = ds(yytext); return NAME; } {N}+ { yylval.dynstr = ds(yytext); return NUMBER; } [#].* ; [\t ] ; [&*[\]();\n] return *yytext; . { (void) printf("bad character '%s'\n",visible(*yytext)); return *yytext; } %% cdecl-2.5.orig/cdgram.y100644 1750 1750 54332 6075375202 14112 0ustar hallonhallon%{ /* Yacc grammar for ANSI and C++ cdecl. */ /* The output of this file is included */ /* into the C file cdecl.c. */ char cdgramsccsid[] = "@(#)cdgram.y 2.2 3/30/88"; %} %union { char *dynstr; struct { char *left; char *right; char *type; } halves; } %token ARRAY AS CAST COMMA DECLARE DOUBLECOLON EXPLAIN FUNCTION %token HELP INTO OF MEMBER POINTER REFERENCE RETURNING SET TO %token CHAR CLASS CONSTVOLATILE DOUBLE ENUM FLOAT INT LONG NAME %token NUMBER SHORT SIGNED STRUCT UNION UNSIGNED VOID %token AUTO EXTERN REGISTER STATIC %type adecllist adims c_type cast castlist cdecl cdecl1 cdims %type constvol_list ClassStruct mod_list mod_list1 modifier %type opt_constvol_list optNAME opt_storage storage StrClaUniEnum %type tname type %type adecl %start prog %% prog : /* empty */ | prog stmt { prompt(); prev = 0; } ; stmt : HELP NL { Debug((stderr, "stmt: help\n")); dohelp(); } | DECLARE NAME AS opt_storage adecl NL { Debug((stderr, "stmt: DECLARE NAME AS opt_storage adecl\n")); Debug((stderr, "\tNAME='%s'\n", $2)); Debug((stderr, "\topt_storage='%s'\n", $4)); Debug((stderr, "\tacdecl.left='%s'\n", $5.left)); Debug((stderr, "\tacdecl.right='%s'\n", $5.right)); Debug((stderr, "\tacdecl.type='%s'\n", $5.type)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); dodeclare($2, $4, $5.left, $5.right, $5.type); } | DECLARE opt_storage adecl NL { Debug((stderr, "stmt: DECLARE opt_storage adecl\n")); Debug((stderr, "\topt_storage='%s'\n", $2)); Debug((stderr, "\tacdecl.left='%s'\n", $3.left)); Debug((stderr, "\tacdecl.right='%s'\n", $3.right)); Debug((stderr, "\tacdecl.type='%s'\n", $3.type)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); dodeclare(NullCP, $2, $3.left, $3.right, $3.type); } | CAST NAME INTO adecl NL { Debug((stderr, "stmt: CAST NAME AS adecl\n")); Debug((stderr, "\tNAME='%s'\n", $2)); Debug((stderr, "\tacdecl.left='%s'\n", $4.left)); Debug((stderr, "\tacdecl.right='%s'\n", $4.right)); Debug((stderr, "\tacdecl.type='%s'\n", $4.type)); docast($2, $4.left, $4.right, $4.type); } | CAST adecl NL { Debug((stderr, "stmt: CAST adecl\n")); Debug((stderr, "\tacdecl.left='%s'\n", $2.left)); Debug((stderr, "\tacdecl.right='%s'\n", $2.right)); Debug((stderr, "\tacdecl.type='%s'\n", $2.type)); docast(NullCP, $2.left, $2.right, $2.type); } | EXPLAIN opt_storage opt_constvol_list type cdecl NL { Debug((stderr, "stmt: EXPLAIN opt_storage opt_constvol_list type cdecl\n")); Debug((stderr, "\topt_storage='%s'\n", $2)); Debug((stderr, "\topt_constvol_list='%s'\n", $3)); Debug((stderr, "\ttype='%s'\n", $4)); Debug((stderr, "\tcdecl='%s'\n", $5)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); dodexplain($2, $3, $4, $5); } | EXPLAIN storage opt_constvol_list cdecl NL { Debug((stderr, "stmt: EXPLAIN storage opt_constvol_list cdecl\n")); Debug((stderr, "\tstorage='%s'\n", $2)); Debug((stderr, "\topt_constvol_list='%s'\n", $3)); Debug((stderr, "\tcdecl='%s'\n", $4)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); dodexplain($2, $3, NullCP, $4); } | EXPLAIN opt_storage constvol_list cdecl NL { Debug((stderr, "stmt: EXPLAIN opt_storage constvol_list cdecl\n")); Debug((stderr, "\topt_storage='%s'\n", $2)); Debug((stderr, "\tconstvol_list='%s'\n", $3)); Debug((stderr, "\tcdecl='%s'\n", $4)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); dodexplain($2, $3, NullCP, $4); } | EXPLAIN '(' opt_constvol_list type cast ')' optNAME NL { Debug((stderr, "stmt: EXPLAIN ( opt_constvol_list type cast ) optNAME\n")); Debug((stderr, "\topt_constvol_list='%s'\n", $3)); Debug((stderr, "\ttype='%s'\n", $4)); Debug((stderr, "\tcast='%s'\n", $5)); Debug((stderr, "\tNAME='%s'\n", $7)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); docexplain($3, $4, $5, $7); } | SET optNAME NL { Debug((stderr, "stmt: SET optNAME\n")); Debug((stderr, "\toptNAME='%s'\n", $2)); doset($2); } | NL | error NL { yyerrok; } ; NL : '\n' { doprompt(); } | ';' { noprompt(); } ; optNAME : NAME { Debug((stderr, "optNAME: NAME\n")); Debug((stderr, "\tNAME='%s'\n", $1)); $$ = $1; } | /* empty */ { Debug((stderr, "optNAME: EMPTY\n")); $$ = ds(unknown_name); } ; cdecl : cdecl1 | '*' opt_constvol_list cdecl { Debug((stderr, "cdecl: * opt_constvol_list cdecl\n")); Debug((stderr, "\topt_constvol_list='%s'\n", $2)); Debug((stderr, "\tcdecl='%s'\n", $3)); $$ = cat($3,$2,ds(strlen($2)?" pointer to ":"pointer to "),NullCP); prev = 'p'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | NAME DOUBLECOLON '*' cdecl { Debug((stderr, "cdecl: NAME DOUBLECOLON '*' cdecl\n")); Debug((stderr, "\tNAME='%s'\n", $1)); Debug((stderr, "\tcdecl='%s'\n", $4)); if (!CplusplusFlag) unsupp("pointer to member of class", NullCP); $$ = cat($4,ds("pointer to member of class "),$1,ds(" "),NullCP); prev = 'p'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | '&' opt_constvol_list cdecl { Debug((stderr, "cdecl: & opt_constvol_list cdecl\n")); Debug((stderr, "\topt_constvol_list='%s'\n", $2)); Debug((stderr, "\tcdecl='%s'\n", $3)); if (!CplusplusFlag) unsupp("reference", NullCP); $$ = cat($3,$2,ds(strlen($2)?" reference to ":"reference to "),NullCP); prev = 'r'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } ; cdecl1 : cdecl1 '(' ')' { Debug((stderr, "cdecl1: cdecl1()\n")); Debug((stderr, "\tcdecl1='%s'\n", $1)); $$ = cat($1,ds("function returning "),NullCP); prev = 'f'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | cdecl1 '(' castlist ')' { Debug((stderr, "cdecl1: cdecl1(castlist)\n")); Debug((stderr, "\tcdecl1='%s'\n", $1)); Debug((stderr, "\tcastlist='%s'\n", $3)); $$ = cat($1, ds("function ("), $3, ds(") returning "), NullCP); prev = 'f'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | cdecl1 cdims { Debug((stderr, "cdecl1: cdecl1 cdims\n")); Debug((stderr, "\tcdecl1='%s'\n", $1)); Debug((stderr, "\tcdims='%s'\n", $2)); $$ = cat($1,ds("array "),$2,NullCP); prev = 'a'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | '(' cdecl ')' { Debug((stderr, "cdecl1: (cdecl)\n")); Debug((stderr, "\tcdecl='%s'\n", $2)); $$ = $2; /* prev = prev; */ Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | NAME { Debug((stderr, "cdecl1: NAME\n")); Debug((stderr, "\tNAME='%s'\n", $1)); savedname = $1; $$ = ds(""); prev = 'n'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } ; castlist : castlist COMMA castlist { Debug((stderr, "castlist: castlist1, castlist2\n")); Debug((stderr, "\tcastlist1='%s'\n", $1)); Debug((stderr, "\tcastlist2='%s'\n", $3)); $$ = cat($1, ds(", "), $3, NullCP); } | opt_constvol_list type cast { Debug((stderr, "castlist: opt_constvol_list type cast\n")); Debug((stderr, "\topt_constvol_list='%s'\n", $1)); Debug((stderr, "\ttype='%s'\n", $2)); Debug((stderr, "\tcast='%s'\n", $3)); $$ = cat($3, $1, ds(strlen($1) ? " " : ""), $2, NullCP); } | NAME { $$ = $1; } ; adecllist : /* empty */ { Debug((stderr, "adecllist: EMPTY\n")); $$ = ds(""); } | adecllist COMMA adecllist { Debug((stderr, "adecllist: adecllist1, adecllist2\n")); Debug((stderr, "\tadecllist1='%s'\n", $1)); Debug((stderr, "\tadecllist2='%s'\n", $3)); $$ = cat($1, ds(", "), $3, NullCP); } | NAME { Debug((stderr, "adecllist: NAME\n")); Debug((stderr, "\tNAME='%s'\n", $1)); $$ = $1; } | adecl { Debug((stderr, "adecllist: adecl\n")); Debug((stderr, "\tadecl.left='%s'\n", $1.left)); Debug((stderr, "\tadecl.right='%s'\n", $1.right)); Debug((stderr, "\tadecl.type='%s'\n", $1.type)); $$ = cat($1.type, ds(" "), $1.left, $1.right, NullCP); } | NAME AS adecl { Debug((stderr, "adecllist: NAME AS adecl\n")); Debug((stderr, "\tNAME='%s'\n", $1)); Debug((stderr, "\tadecl.left='%s'\n", $3.left)); Debug((stderr, "\tadecl.right='%s'\n", $3.right)); Debug((stderr, "\tadecl.type='%s'\n", $3.type)); $$ = cat($3.type, ds(" "), $3.left, $1, $3.right, NullCP); } ; cast : /* empty */ { Debug((stderr, "cast: EMPTY\n")); $$ = ds(""); /* prev = prev; */ Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | '(' ')' { Debug((stderr, "cast: ()\n")); $$ = ds("function returning "); prev = 'f'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | '(' cast ')' '(' ')' { Debug((stderr, "cast: (cast)()\n")); Debug((stderr, "\tcast='%s'\n", $2)); $$ = cat($2,ds("function returning "),NullCP); prev = 'f'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | '(' cast ')' '(' castlist ')' { Debug((stderr, "cast: (cast)(castlist)\n")); Debug((stderr, "\tcast='%s'\n", $2)); Debug((stderr, "\tcastlist='%s'\n", $5)); $$ = cat($2,ds("function ("),$5,ds(") returning "),NullCP); prev = 'f'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | '(' cast ')' { Debug((stderr, "cast: (cast)\n")); Debug((stderr, "\tcast='%s'\n", $2)); $$ = $2; /* prev = prev; */ Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | NAME DOUBLECOLON '*' cast { Debug((stderr, "cast: NAME::*cast\n")); Debug((stderr, "\tcast='%s'\n", $4)); if (!CplusplusFlag) unsupp("pointer to member of class", NullCP); $$ = cat($4,ds("pointer to member of class "),$1,ds(" "),NullCP); prev = 'p'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | '*' cast { Debug((stderr, "cast: *cast\n")); Debug((stderr, "\tcast='%s'\n", $2)); $$ = cat($2,ds("pointer to "),NullCP); prev = 'p'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | '&' cast { Debug((stderr, "cast: &cast\n")); Debug((stderr, "\tcast='%s'\n", $2)); if (!CplusplusFlag) unsupp("reference", NullCP); $$ = cat($2,ds("reference to "),NullCP); prev = 'r'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | cast cdims { Debug((stderr, "cast: cast cdims\n")); Debug((stderr, "\tcast='%s'\n", $1)); Debug((stderr, "\tcdims='%s'\n", $2)); $$ = cat($1,ds("array "),$2,NullCP); prev = 'a'; Debug((stderr, "\tprev = '%s'\n", visible(prev))); } ; cdims : '[' ']' { Debug((stderr, "cdims: []\n")); $$ = ds("of "); } | '[' NUMBER ']' { Debug((stderr, "cdims: [NUMBER]\n")); Debug((stderr, "\tNUMBER='%s'\n", $2)); $$ = cat($2,ds(" of "),NullCP); } ; adecl : FUNCTION RETURNING adecl { Debug((stderr, "adecl: FUNCTION RETURNING adecl\n")); Debug((stderr, "\tadecl.left='%s'\n", $3.left)); Debug((stderr, "\tadecl.right='%s'\n", $3.right)); Debug((stderr, "\tadecl.type='%s'\n", $3.type)); if (prev == 'f') unsupp("Function returning function", "function returning pointer to function"); else if (prev=='A' || prev=='a') unsupp("Function returning array", "function returning pointer"); $$.left = $3.left; $$.right = cat(ds("()"),$3.right,NullCP); $$.type = $3.type; prev = 'f'; Debug((stderr, "\n\tadecl now =\n")); Debug((stderr, "\t\tadecl.left='%s'\n", $$.left)); Debug((stderr, "\t\tadecl.right='%s'\n", $$.right)); Debug((stderr, "\t\tadecl.type='%s'\n", $$.type)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | FUNCTION '(' adecllist ')' RETURNING adecl { Debug((stderr, "adecl: FUNCTION (adecllist) RETURNING adecl\n")); Debug((stderr, "\tadecllist='%s'\n", $3)); Debug((stderr, "\tadecl.left='%s'\n", $6.left)); Debug((stderr, "\tadecl.right='%s'\n", $6.right)); Debug((stderr, "\tadecl.type='%s'\n", $6.type)); if (prev == 'f') unsupp("Function returning function", "function returning pointer to function"); else if (prev=='A' || prev=='a') unsupp("Function returning array", "function returning pointer"); $$.left = $6.left; $$.right = cat(ds("("),$3,ds(")"),$6.right,NullCP); $$.type = $6.type; prev = 'f'; Debug((stderr, "\n\tadecl now =\n")); Debug((stderr, "\t\tadecl.left='%s'\n", $$.left)); Debug((stderr, "\t\tadecl.right='%s'\n", $$.right)); Debug((stderr, "\t\tadecl.type='%s'\n", $$.type)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | ARRAY adims OF adecl { Debug((stderr, "adecl: ARRAY adims OF adecl\n")); Debug((stderr, "\tadims='%s'\n", $2)); Debug((stderr, "\tadecl.left='%s'\n", $4.left)); Debug((stderr, "\tadecl.right='%s'\n", $4.right)); Debug((stderr, "\tadecl.type='%s'\n", $4.type)); if (prev == 'f') unsupp("Array of function", "array of pointer to function"); else if (prev == 'a') unsupp("Inner array of unspecified size", "array of pointer"); else if (prev == 'v') unsupp("Array of void", "pointer to void"); if (arbdims) prev = 'a'; else prev = 'A'; $$.left = $4.left; $$.right = cat($2,$4.right,NullCP); $$.type = $4.type; Debug((stderr, "\n\tadecl now =\n")); Debug((stderr, "\t\tadecl.left='%s'\n", $$.left)); Debug((stderr, "\t\tadecl.right='%s'\n", $$.right)); Debug((stderr, "\t\tadecl.type='%s'\n", $$.type)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | opt_constvol_list POINTER TO adecl { char *op = "", *cp = "", *sp = ""; Debug((stderr, "adecl: opt_constvol_list POINTER TO adecl\n")); Debug((stderr, "\topt_constvol_list='%s'\n", $1)); Debug((stderr, "\tadecl.left='%s'\n", $4.left)); Debug((stderr, "\tadecl.right='%s'\n", $4.right)); Debug((stderr, "\tadecl.type='%s'\n", $4.type)); if (prev == 'a') unsupp("Pointer to array of unspecified dimension", "pointer to object"); if (prev=='a' || prev=='A' || prev=='f') { op = "("; cp = ")"; } if (strlen($1) != 0) sp = " "; $$.left = cat($4.left,ds(op),ds("*"), ds(sp),$1,ds(sp),NullCP); $$.right = cat(ds(cp),$4.right,NullCP); $$.type = $4.type; prev = 'p'; Debug((stderr, "\n\tadecl now =\n")); Debug((stderr, "\t\tadecl.left='%s'\n", $$.left)); Debug((stderr, "\t\tadecl.right='%s'\n", $$.right)); Debug((stderr, "\t\tadecl.type='%s'\n", $$.type)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | opt_constvol_list POINTER TO MEMBER OF ClassStruct NAME adecl { char *op = "", *cp = "", *sp = ""; Debug((stderr, "adecl: opt_constvol_list POINTER TO MEMBER OF ClassStruct NAME adecl\n")); Debug((stderr, "\topt_constvol_list='%s'\n", $1)); Debug((stderr, "\tClassStruct='%s'\n", $6)); Debug((stderr, "\tNAME='%s'\n", $7)); Debug((stderr, "\tadecl.left='%s'\n", $8.left)); Debug((stderr, "\tadecl.right='%s'\n", $8.right)); Debug((stderr, "\tadecl.type='%s'\n", $8.type)); if (!CplusplusFlag) unsupp("pointer to member of class", NullCP); if (prev == 'a') unsupp("Pointer to array of unspecified dimension", "pointer to object"); if (prev=='a' || prev=='A' || prev=='f') { op = "("; cp = ")"; } if (strlen($1) != 0) sp = " "; $$.left = cat($8.left,ds(op),$7,ds("::*"), ds(sp),$1,ds(sp),NullCP); $$.right = cat(ds(cp),$8.right,NullCP); $$.type = $8.type; prev = 'p'; Debug((stderr, "\n\tadecl now =\n")); Debug((stderr, "\t\tadecl.left='%s'\n", $$.left)); Debug((stderr, "\t\tadecl.right='%s'\n", $$.right)); Debug((stderr, "\t\tadecl.type='%s'\n", $$.type)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | opt_constvol_list REFERENCE TO adecl { char *op = "", *cp = "", *sp = ""; Debug((stderr, "adecl: opt_constvol_list REFERENCE TO adecl\n")); Debug((stderr, "\topt_constvol_list='%s'\n", $1)); Debug((stderr, "\tadecl.left='%s'\n", $4.left)); Debug((stderr, "\tadecl.right='%s'\n", $4.right)); Debug((stderr, "\tadecl.type='%s'\n", $4.type)); if (!CplusplusFlag) unsupp("reference", NullCP); if (prev == 'v') unsupp("Reference to void", "pointer to void"); else if (prev == 'a') unsupp("Reference to array of unspecified dimension", "reference to object"); if (prev=='a' || prev=='A' || prev=='f') { op = "("; cp = ")"; } if (strlen($1) != 0) sp = " "; $$.left = cat($4.left,ds(op),ds("&"), ds(sp),$1,ds(sp),NullCP); $$.right = cat(ds(cp),$4.right,NullCP); $$.type = $4.type; prev = 'r'; Debug((stderr, "\n\tadecl now =\n")); Debug((stderr, "\t\tadecl.left='%s'\n", $$.left)); Debug((stderr, "\t\tadecl.right='%s'\n", $$.right)); Debug((stderr, "\t\tadecl.type='%s'\n", $$.type)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); } | opt_constvol_list type { Debug((stderr, "adecl: opt_constvol_list type\n")); Debug((stderr, "\topt_constvol_list='%s'\n", $1)); Debug((stderr, "\ttype='%s'\n", $2)); $$.left = ds(""); $$.right = ds(""); $$.type = cat($1,ds(strlen($1)?" ":""),$2,NullCP); if (strcmp($2, "void") == 0) prev = 'v'; else if ((strncmp($2, "struct", 6) == 0) || (strncmp($2, "class", 5) == 0)) prev = 's'; else prev = 't'; Debug((stderr, "\n\tadecl now =\n")); Debug((stderr, "\t\tadecl.left='%s'\n", $$.left)); Debug((stderr, "\t\tadecl.right='%s'\n", $$.right)); Debug((stderr, "\t\tadecl.type='%s'\n", $$.type)); Debug((stderr, "\tprev = '%s'\n", visible(prev))); } ; adims : /* empty */ { Debug((stderr, "adims: EMPTY\n")); arbdims = 1; $$ = ds("[]"); } | NUMBER { Debug((stderr, "adims: NUMBER\n")); Debug((stderr, "\tNUMBER='%s'\n", $1)); arbdims = 0; $$ = cat(ds("["),$1,ds("]"),NullCP); } ; type : tinit c_type { Debug((stderr, "type: tinit c_type\n")); Debug((stderr, "\ttinit=''\n")); Debug((stderr, "\tc_type='%s'\n", $2)); mbcheck(); $$ = $2; } ; tinit : /* empty */ { Debug((stderr, "tinit: EMPTY\n")); modbits = 0; } ; c_type : mod_list { Debug((stderr, "c_type: mod_list\n")); Debug((stderr, "\tmod_list='%s'\n", $1)); $$ = $1; } | tname { Debug((stderr, "c_type: tname\n")); Debug((stderr, "\ttname='%s'\n", $1)); $$ = $1; } | mod_list tname { Debug((stderr, "c_type: mod_list tname\n")); Debug((stderr, "\tmod_list='%s'\n", $1)); Debug((stderr, "\ttname='%s'\n", $2)); $$ = cat($1,ds(" "),$2,NullCP); } | StrClaUniEnum NAME { Debug((stderr, "c_type: StrClaUniEnum NAME\n")); Debug((stderr, "\tStrClaUniEnum='%s'\n", $1)); Debug((stderr, "\tNAME='%s'\n", $2)); $$ = cat($1,ds(" "),$2,NullCP); } ; StrClaUniEnum : ClassStruct | ENUM | UNION { $$ = $1; } ; ClassStruct : STRUCT | CLASS { $$ = $1; } ; tname : INT { Debug((stderr, "tname: INT\n")); Debug((stderr, "\tINT='%s'\n", $1)); modbits |= MB_INT; $$ = $1; } | CHAR { Debug((stderr, "tname: CHAR\n")); Debug((stderr, "\tCHAR='%s'\n", $1)); modbits |= MB_CHAR; $$ = $1; } | FLOAT { Debug((stderr, "tname: FLOAT\n")); Debug((stderr, "\tFLOAT='%s'\n", $1)); modbits |= MB_FLOAT; $$ = $1; } | DOUBLE { Debug((stderr, "tname: DOUBLE\n")); Debug((stderr, "\tDOUBLE='%s'\n", $1)); modbits |= MB_DOUBLE; $$ = $1; } | VOID { Debug((stderr, "tname: VOID\n")); Debug((stderr, "\tVOID='%s'\n", $1)); modbits |= MB_VOID; $$ = $1; } ; mod_list : modifier mod_list1 { Debug((stderr, "mod_list: modifier mod_list1\n")); Debug((stderr, "\tmodifier='%s'\n", $1)); Debug((stderr, "\tmod_list1='%s'\n", $2)); $$ = cat($1,ds(" "),$2,NullCP); } | modifier { Debug((stderr, "mod_list: modifier\n")); Debug((stderr, "\tmodifier='%s'\n", $1)); $$ = $1; } ; mod_list1 : mod_list { Debug((stderr, "mod_list1: mod_list\n")); Debug((stderr, "\tmod_list='%s'\n", $1)); $$ = $1; } | CONSTVOLATILE { Debug((stderr, "mod_list1: CONSTVOLATILE\n")); Debug((stderr, "\tCONSTVOLATILE='%s'\n", $1)); if (PreANSIFlag) notsupported(" (Pre-ANSI Compiler)", $1, NullCP); else if (RitchieFlag) notsupported(" (Ritchie Compiler)", $1, NullCP); else if ((strcmp($1, "noalias") == 0) && CplusplusFlag) unsupp($1, NullCP); $$ = $1; } ; modifier : UNSIGNED { Debug((stderr, "modifier: UNSIGNED\n")); Debug((stderr, "\tUNSIGNED='%s'\n", $1)); modbits |= MB_UNSIGNED; $$ = $1; } | SIGNED { Debug((stderr, "modifier: SIGNED\n")); Debug((stderr, "\tSIGNED='%s'\n", $1)); modbits |= MB_SIGNED; $$ = $1; } | LONG { Debug((stderr, "modifier: LONG\n")); Debug((stderr, "\tLONG='%s'\n", $1)); modbits |= MB_LONG; $$ = $1; } | SHORT { Debug((stderr, "modifier: SHORT\n")); Debug((stderr, "\tSHORT='%s'\n", $1)); modbits |= MB_SHORT; $$ = $1; } ; opt_constvol_list: CONSTVOLATILE opt_constvol_list { Debug((stderr, "opt_constvol_list: CONSTVOLATILE opt_constvol_list\n")); Debug((stderr, "\tCONSTVOLATILE='%s'\n", $1)); Debug((stderr, "\topt_constvol_list='%s'\n", $2)); if (PreANSIFlag) notsupported(" (Pre-ANSI Compiler)", $1, NullCP); else if (RitchieFlag) notsupported(" (Ritchie Compiler)", $1, NullCP); else if ((strcmp($1, "noalias") == 0) && CplusplusFlag) unsupp($1, NullCP); $$ = cat($1,ds(strlen($2) ? " " : ""),$2,NullCP); } | /* empty */ { Debug((stderr, "opt_constvol_list: EMPTY\n")); $$ = ds(""); } ; constvol_list: CONSTVOLATILE opt_constvol_list { Debug((stderr, "constvol_list: CONSTVOLATILE opt_constvol_list\n")); Debug((stderr, "\tCONSTVOLATILE='%s'\n", $1)); Debug((stderr, "\topt_constvol_list='%s'\n", $2)); if (PreANSIFlag) notsupported(" (Pre-ANSI Compiler)", $1, NullCP); else if (RitchieFlag) notsupported(" (Ritchie Compiler)", $1, NullCP); else if ((strcmp($1, "noalias") == 0) && CplusplusFlag) unsupp($1, NullCP); $$ = cat($1,ds(strlen($2) ? " " : ""),$2,NullCP); } ; storage : AUTO | EXTERN | REGISTER | STATIC { Debug((stderr, "storage: AUTO,EXTERN,STATIC,REGISTER (%s)\n", $1)); $$ = $1; } ; opt_storage : storage { Debug((stderr, "opt_storage: storage=%s\n", $1)); $$ = $1; } | /* empty */ { Debug((stderr, "opt_storage: EMPTY\n")); $$ = ds(""); } ; %% cdecl-2.5.orig/cdecl.1100644 1750 1750 34057 6076617435 13631 0ustar hallonhallon.\" @(#)cdecl.1 2.5 1/15/96 .TH CDECL 1 "15 January 1996" "Version 2.5" "Linux Programmer's Manual" .SH NAME cdecl, c++decl \- Compose C and C++ type declarations .SH SYNOPSIS .B cdecl [\-a | \-+ | \-p | \-r] [\-ciqdDV] .br .RS .5i .RI "[[ " files " ...] |" .BR explain " ... | " declare " ... | " cast " ... | " set " ... | " .BR help " | " ? " ]" .RE .br .B c++decl [\-a | \-+ | \-p | \-r] [\-ciqdDV] .br .RS .5i .RI "[[ " files " ...] |" .BR explain " ... | " declare " ... | " cast " ... | " set " ... | " .BR help " | " ? " ]" .RE .br .BR explain " ..." .br .BR declare " ..." .br .BR cast " ..." .SH DESCRIPTION .I Cdecl (and .IR c++decl ) is a program for encoding and decoding C (or C++) type declarations. The C language is based on the (draft proposed) X3J11 ANSI Standard; optionally, the C language may be based on the pre-ANSI definition defined by Kernighan & Ritchie's .I "The C Programming Language" book, or the C language defined by the Ritchie PDP-11 C compiler. The C++ language is based on Bjarne Stroustrup's .IR "The C++ Programming Language" , plus the version 2.0 additions to the language. .SH OPTIONS .IP -a Use the ANSI C dialect of the C language. .IP -p Use the pre-ANSI dialect defined by Kernighan & Ritchie's book. .IP -r Use the dialect defined by the Ritchie PDP-11 C compiler. .IP -+ Use the C++ language, rather than C. .IP -i Run in interactive mode (the default when reading from a terminal). This also turns on prompting, line editing, and line history. .IP -q Quiet the prompt. Turns off the prompt in interactive mode. .IP -c Create compilable C or C++ code as output. .I Cdecl will add a semicolon to the end of a declaration and a pair of curly braces to the end of a function definition. .IP -d Turn on debugging information (if compiled in). .IP -D Turn on YACC debugging information (if compiled in). .IP -V Display version information and exit. .SH INVOKING .I Cdecl may be invoked under a number of different names (by either renaming the executable, or creating a symlink or hard link to it). If it is invoked as .I cdecl then ANSI C is the default language. If it is invoked as .I c++decl then C++ is the default. If it is invoked as either .IR explain ", " cast ", or " declare then it will interpret the rest of the command line options as parameters to that command, execute the command, and exit. It will also do this if the first non-switch argument on the command line is one of those three commands. Input may also come from a file. .PP .I Cdecl reads the named files for statements in the language described below. A transformation is made from that language to C (C++) or pseudo-English. The results of this transformation are written on standard output. If no files are named, or a filename of ``\-'' is encountered, standard input will be read. If standard input is coming from a terminal, (or the .B \-i option is used), a prompt will be written to the terminal before each line. The prompt can be turned off by the .B \-q option (or the .I set noprompt command). If .I cdecl is invoked as .IR explain , .I declare or .IR cast , or the first argument is one of the commands discussed below, the argument list will be interpreted according to the grammar shown below instead of as file names. .PP When it is run interactively, .I cdecl uses the GNU readline library to provide keyword completion and command line history, very much like .IR bash (1) (q.v.). Pressing TAB will complete the partial keyword before the cursor, unless there is more than one possible completion, in which case a second TAB will show the list of possible completions and redisplay the command line. The left and right arrow keys and backspace can be used for editing in a natural way, and the up and down arrow keys retrieve previous command lines from the history. Most other familiar keys, such as Ctrl-U to delete all text from the cursor back to the beginning of the line, work as expected. There is an ambiguity between the .IR int " and " into keywords, but .I cdecl will guess which one you meant, and it always guesses correctly. .PP You can use .I cdecl as you create a C program with an editor like .IR vi "(1) or " emacs (1). You simply type in the pseudo-English version of the declaration and apply .I cdecl as a filter to the line. (In .IR vi (1), .RB "type ``" !!cdecl ''.) .PP If the .I "create program" option .B \-c is used, the output will include semi-colons after variable declarations and curly brace pairs after function declarations. .PP The .B \-V option will print out the version numbers of the files used to create the process. If the source is compiled with debugging information turned on, the .B \-d option will enable it to be output. If the source is compiled with YACC debugging information turned on, the .B \-D option will enable it to be output. .SH "COMMAND LANGUAGE" There are six statements in the language. The .I "declare" statement composes a C type declaration from a verbose description. The .I "cast" statement composes a C type cast as might appear in an expression. The .I "explain" statement decodes a C type declaration or cast, producing a verbose description. The .I "help" (or .IR ? ) statement provides a help message. The .I "quit" (or .IR "exit" ) statement (or the end of file) exits the program. The .I "set" statement allows the command line options to be set interactively. Each statement is separated by a semi-colon or a newline. .SH SYNONYMS Some synonyms are permitted during a declaration: .sp .nf character is a synonym for char constant is a synonym for const enumeration is a synonym for enum func is a synonym for function integer is a synonym for int ptr is a synonym for pointer ref is a synonym for reference ret is a synonym for returning structure is a synonym for struct vector is a synonym for array .fi .PP The TAB completion feature only knows about the keywords in the right column of the structure, not the ones in the left column. TAB completion is a lot less useful when the leading characters of different keywords are the same (the keywords confict with one another), and putting both columns in would cause quite a few conflicts. .SH GRAMMAR The following grammar describes the language. In the grammar, words in "<>" are non-terminals, bare lower-case words are terminals that stand for themselves. Bare upper-case words are other lexical tokens: NOTHING means the empty string; NAME means a C identifier; NUMBER means a string of decimal digits; and NL means the new-line or semi-colon characters. .LP .nf ::= NOTHING | NL ::= NOTHING | declare NAME as | declare | cast NAME into | cast | explain | explain | explain ( ) optional-NAME | set | help | ? | quit | exit ::= array of | array NUMBER of | function returning | function ( ) returning | pointer to | pointer to member of class NAME | reference to | ::= | * | NAME :: * | & ::= ( ) | ( ) | [ ] | [ NUMBER ] | ( ) | NAME ::= NOTHING | ( ) | ( ) ( ) | ( ) ( ) | ( ) | NAME :: * | * | & | [ ] | [ NUMBER ] ::= | | | struct NAME | union NAME | enum NAME | class NAME ::= , | | ::= , | NOTHING | | | as ::= int | char | double | float | void ::= | ::= short | long | unsigned | signed | ::= | NOTHING ::= const | volatile | noalias ::= auto | extern | register | auto ::= NOTHING | ::= NOTHING | | create | nocreate | prompt | noprompt | ritchie | preansi | ansi | cplusplus | debug | nodebug | yydebug | noyydebug .fi .SH "SET OPTIONS" The .I set command takes several options. You can type .IR set " or " "set options" to see the currently selected options and a summary of the options which are available. The first four correspond to the .IR -a ", " -p ", " -r ", and " -+ command line options, respectively. .IP ansi Use the ANSI C dialect of the C language. .IP preansi Use the pre-ANSI dialect defined by Kernighan & Ritchie's book. .IP ritchie Use the dialect defined by the Ritchie PDP-11 C compiler. .IP cplusplus Use the C++ language, rather than C. .IP [no]prompt Turn on or off the prompt in interactive mode. .IP [no]create Turn on or off the appending of semicolon or curly braces to the declarations output by .IR cdecl . This corresponds to the .I -c command line option. .IP [no]debug Turn on or off debugging information. .IP [no]yydebug Turn on or off YACC debugging information. .PP Note: debugging information and YACC debugging information are only available if they have been compiled into .IR cdecl . The last two options correspond to the .IR -d " and " -D command line options, respectively. Debugging information is normally used in program development, and is not generally compiled into distributed executables. .SH EXAMPLES .de Ex . PP . RS .. .de Ee . RE . PP .. To declare an array of pointers to functions that are like .IR malloc (3), do .Ex declare fptab as array of pointer to function returning pointer to char .Ee The result of this command is .Ex char *(*fptab[])() .Ee When you see this declaration in someone else's code, you can make sense out of it by doing .Ex explain char *(*fptab[])() .Ee The proper declaration for signal(2), ignoring function prototypes, is easily described in .IR cdecl 's language: .Ex declare signal as function returning pointer to function returning void .Ee which produces .Ex void (*signal())() .Ee The function declaration that results has two sets of empty parentheses. The author of such a function might wonder where to put the parameters: .Ex declare signal as function (arg1,arg2) returning pointer to function returning void .Ee provides the following solution (when run with the .I \-c option): .Ex void (*signal(arg1,arg2))() { } .Ee If we want to add in the function prototypes, the function prototype for a function such as _exit(2) would be declared with: .Ex declare _exit as function (retvalue as int) returning void .Ee giving .Ex void _exit(int retvalue) { } .Ee As a more complex example using function prototypes, signal(2) could be fully defined as: .Ex declare signal as function(x as int, y as pointer to function(int) returning void) returning pointer to function(int) returning void .Ee giving (with \-c) .Ex void (*signal(int x, void (*y)(int )))(int ) { } .Ee .I Cdecl can help figure out the where to put the "const" and "volatile" modifiers in declarations, thus .Ex declare foo as pointer to const int .Ee gives .Ex const int *foo .Ee while .Ex declare foo as const pointer to int .Ee gives .Ex int * const foo .Ee .I C++decl can help with declaring references, thus .Ex declare x as reference to pointer to character .Ee gives .Ex char *&x .Ee .I C++decl can help with pointers to member of classes, thus declaring a pointer to an integer member of a class X with .Ex declare foo as pointer to member of class X int .Ee gives .Ex int X::*foo .Ee and .Ex declare foo as pointer to member of class X function (arg1, arg2) returning pointer to class Y .Ee gives .Ex class Y *(X::*foo)(arg1, arg2) .Ee .SH DIAGNOSTICS The declare, cast and explain statements try to point out constructions that are not supported in C. In some cases, a guess is made as to what was really intended. In these cases, the C result is a toy declaration whose semantics will work only in Algol-68. The list of unsupported C constructs is dependent on which version of the C language is being used (see the ANSI, pre-ANSI, and Ritchie options). The set of supported C++ constructs is a superset of the ANSI set, with the exception of the .B noalias keyword. .SH REFERENCES ANSI Standard X3.159-1989 (ANSI C) .sp ISO/IEC 9899:1990 (the ISO standard) .sp The comp.lang.c FAQ .br .I http://www.eskimo.com/~scs/C-faq.top.html .sp Section 8.4 of the C Reference Manual within .I "The C Programming Language" by B. Kernighan & D. Ritchie. .sp Section 8 of the C++ Reference Manual within .I "The C++ Programming Language" by B. Stroustrup. .SH CAVEATS The pseudo-English syntax is excessively verbose. .PP There is a wealth of semantic checking that isn't being done. .PP .I Cdecl was written before the ANSI C standard was completed, and no attempt has been made to bring it up-to-date. Nevertheless, it is very close to the standard, with the obvious exception of .IR noalias . .PP .IR Cdecl 's scope is intentionally small. It doesn't help you figure out initializations. It expects storage classes to be at the beginning of a declaration, followed by the the const, volatile and noalias modifiers, followed by the type of the variable. .I Cdecl doesn't know anything about variable length argument lists. (This includes the .RI `` ,... '' syntax.) .PP .I Cdecl thinks all the declarations you utter are going to be used as external definitions. Some declaration contexts in C allow more flexibility than this. An example of this is: .Ex declare argv as array of array of char .Ee where .I cdecl responds with .Ex .nf Warning: Unsupported in C -- 'Inner array of unspecified size' (maybe you mean "array of pointer") char argv[][] .fi .Ee .PP Tentative support for the .I noalias keyword was put in because it was in the draft ANSI specifications. .SH AUTHORS Originally written by Graham Ross, improved and expanded by David Wolverton, Tony Hansen, and Merlyn LeRoy. .sp GNU readline support and Linux port by David R. Conrad, .SH "SEE ALSO" .IR bash "(1), " emacs "(1), " malloc "(3), " vi (1). cdecl-2.5.orig/c++decl.1100644 1750 1750 21 6076625724 13657 0ustar hallonhallon.so man1/cdecl.1 cdecl-2.5.orig/testset100644 1750 1750 2016 6075375203 14052 0ustar hallonhallonhelp set options # test some declarations declare x as ptr to character declare x as func(w as ptr to char, y as int) ret ptr to int declare x as func(ptr to char) ret ptr to int declare x as func(int) ret ptr to int declare x as func(ptr to char, int) ret ptr to int declare x as function (args) returning pointer to int # test some explain functions explain char *x explain int *x() explain int *x(args) explain int *x(char *) explain int *x(char *, int ) explain int *x(char *, int, float) explain int *x(int ) # test some casts cast x into ptr to char cast x into ptr to func ret int cast x into ptr to func() ret int cast x into ptr to func(args) ret int cast x into ptr to func(x as ptr to char, y as int) ret int cast x into ptr to func(ptr to char) ret int cast x into ptr to func(ptr to char, int) ret int cast x into ptr to func(ptr to char, int, float) ret int # test explaining some casts explain (char *)x explain (int (*)())x explain (int (*)(char *))x explain (int (*)(char *, int))x explain (int (*)(char *, int, float))x cdecl-2.5.orig/testset++100644 1750 1750 2471 6075375203 14205 0ustar hallonhallonhelp set options # test some declarations declare x as ptr to character declare x as reference to character declare foo as pointer to member of class X int declare foo as pointer to member of class X function (arg1, arg2) returning pointer to class Y declare x as func(w as ptr to char, y as int) ret ptr to int declare x as func(ptr to char) ret ptr to int declare x as func(int) ret ptr to int declare x as func(ptr to char, int) ret ptr to int declare x as function (args) returning pointer to int # test some explain functions explain char *x explain int X::*foo explain class Y *(X::*foo)(arg1, arg2) explain int *x() explain int *x(args) explain int *x(char *) explain int *x(char *, int ) explain int *x(char *, int, float) explain int *x(int ) # test some casts cast x into ptr to char cast x into ptr to member of class X int cast x into ptr to func ret int cast x into ptr to func() ret int cast x into ptr to func(args) ret int cast x into ptr to func(x as ptr to char, y as int) ret int cast x into ptr to func(ptr to char) ret int cast x into ptr to func(ptr to char, int) ret int cast x into ptr to func(ptr to char, int, float) ret int # test explaining some casts explain (char *)x explain (int X::*)x explain (int (*)())x explain (int (*)(char *))x explain (int (*)(char *, int))x explain (int (*)(char *, int, float))x