$NetBSD: patch-aa,v 1.11 2014/03/17 07:07:40 dholland Exp $ - Don't issue own declarations of malloc, free, exit, perror, errno, getopt. - Use standard headers. - Avoid symbol conflicts with restrict, setprogname, getline. - Fix build with current readline. --- cdecl.c.orig 1996-01-16 03:54:46.000000000 +0000 +++ cdecl.c @@ -59,7 +59,9 @@ */ char cdeclsccsid[] = "@(#)cdecl.c 2.5 1/15/96"; - + +#include + #include #include #if __STDC__ || defined(DOS) @@ -71,11 +73,12 @@ char cdeclsccsid[] = "@(#)cdecl.c 2.5 1/ # ifndef NOVARARGS # include # endif /* ndef NOVARARGS */ +#if !(defined(__sun__) && defined(__svr4__)) && !(defined(BSD) && (BSD >= 199306)) && !defined(__INTERIX) char *malloc(); void free(), exit(), perror(); +#endif # ifdef BSD # include - extern int errno; # define strrchr rindex # define NOTMPFILE # else @@ -87,13 +90,12 @@ void free(), exit(), perror(); # endif /* NOVOID */ #endif /* __STDC__ || DOS */ +#include + #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); +char * command_completion(const char *, int); #endif /* maximum # of chars from progname to display in prompt */ @@ -124,7 +126,11 @@ char real_prompt[MAX_NAME+3]; #if __STDC__ char *ds(char *), *cat(char *, ...), *visible(int); +#if !(defined(BSD) && BSD >= 199306) && \ + !(defined(__sun__) && defined(__svr4__)) && \ + !(defined(__linux__)) && !(defined(__INTERIX)) int getopt(int,char **,char *); +#endif int main(int, char **); int yywrap(void); int dostdin(void); @@ -138,7 +144,7 @@ char real_prompt[MAX_NAME+3]; void docast(char*, char*, char*, char*); void dodexplain(char*, char*, char*, char*); void docexplain(char*, char*, char*, char*); - void setprogname(char *); + void mysetprogname(char *); int dotmpfile(int, char**), dofileargs(int, char**); #else char *ds(), *cat(), *visible(); @@ -148,7 +154,7 @@ char real_prompt[MAX_NAME+3]; void unsupp(), notsupported(); void yyerror(); void doset(), dodeclare(), docast(), dodexplain(), docexplain(); - void setprogname(); + void mysetprogname(); int dotmpfile(), dofileargs(); #endif /* __STDC__ */ FILE *tmpfile(); @@ -241,7 +247,7 @@ struct /* for unsupported combinations of types. */ void mbcheck() { - register int i, j, restrict; + register int i, j, xrestrict; char *t1, *t2; /* Loop through the types */ @@ -258,26 +264,26 @@ void mbcheck() if (!(modbits & crosstypes[j].bit)) continue; /* check the type of restriction */ - restrict = crosscheck[i][j]; - if (restrict == ALWAYS) + xrestrict = crosscheck[i][j]; + if (xrestrict == ALWAYS) continue; t1 = crosstypes[i].name; t2 = crosstypes[j].name; - if (restrict == NEVER) + if (xrestrict == NEVER) { notsupported("", t1, t2); } - else if (restrict == RITCHIE) + else if (xrestrict == RITCHIE) { if (RitchieFlag) notsupported(" (Ritchie Compiler)", t1, t2); } - else if (restrict == PREANSI) + else if (xrestrict == PREANSI) { if (PreANSIFlag || RitchieFlag) notsupported(" (Pre-ANSI Compiler)", t1, t2); } - else if (restrict == ANSI) + else if (xrestrict == ANSI) { if (!RitchieFlag && !PreANSIFlag) notsupported(" (ANSI Compiler)", t1, t2); @@ -286,7 +292,7 @@ void mbcheck() { (void) fprintf (stderr, "%s: Internal error in crosscheck[%d,%d]=%d!\n", - progname, i, j, restrict); + progname, i, j, xrestrict); exit(1); /* NOTREACHED */ } } @@ -375,7 +381,7 @@ char *options[] = { static char *line_read = NULL; /* Read a string, and return a pointer to it. Returns NULL on EOF. */ -char * getline () +char * get_line () { /* If the buffer has already been allocated, return the memory to the free pool. */ @@ -399,12 +405,12 @@ char ** attempt_completion(char *text, i { char **matches = NULL; - if (start == 0) matches = completion_matches(text, command_completion); + if (start == 0) matches = rl_completion_matches(text, command_completion); return matches; } -char * command_completion(char *text, int flag) +char * command_completion(const char *text, int flag) { static int index, len; char *command; @@ -421,7 +427,7 @@ char * command_completion(char *text, in return NULL; } -char * keyword_completion(char *text, int flag) +char * keyword_completion(const char *text, int flag) { static int index, len, set, into; char *keyword, *option; @@ -803,7 +809,7 @@ void prompt() } /* Save away the name of the program from argv[0] */ -void setprogname(argv0) +void mysetprogname(argv0) char *argv0; { #ifdef DOS @@ -887,7 +893,7 @@ int dostdin() if (!quiet) (void) printf("Type `help' or `?' for help\n"); ret = 0; - while ((line = getline())) { + while ((line = get_line())) { if (!strcmp(line, "quit") || !strcmp(line, "exit")) { free(line); return ret; @@ -1251,11 +1257,11 @@ char **argv; #ifdef USE_READLINE /* install completion handlers */ - rl_attempted_completion_function = (CPPFunction *)attempt_completion; - rl_completion_entry_function = (Function *)keyword_completion; + rl_attempted_completion_function = (rl_completion_func_t *)attempt_completion; + rl_completion_entry_function = keyword_completion; #endif - setprogname(argv[0]); + mysetprogname(argv[0]); #ifdef DOS if (strcmp(progname, "cppdecl") == 0) #else