+#ifdef errno_h
+#undef errno_h
+#endif
+ errno_h,
+#ifdef stdio_h
+#undef stdio_h
+#endif
+ stdio_h,
+#ifdef stdlib_h
+#undef stdlib_h
+#endif
+ stdlib_h,
+#ifdef sys_stat_h
+#undef sys_stat_h
+#endif
+ sys_stat_h
+};
+
+/* A NAMELIST is a sequence of names, separated by '\0', and terminated
+ by an empty name (i.e. by "\0\0"). */
+
+typedef const char *namelist;
+
+/* The following macros provide the bits for symbol_flags. */
+typedef int symbol_flags;
+
+/* Used to mark names defined in the ANSI/ISO C standard. */
+#define ANSI_SYMBOL 1
+
+/* We no longer massage include files for POSIX or XOPEN symbols,
+ as there are now several versions of the POSIX and XOPEN standards,
+ and it would be a maintenance nightmare for us to track them all.
+ Better to be compatible with the system include files. */
+/*#define ADD_MISSING_POSIX 1 */
+/*#define ADD_MISSING_XOPEN 1 */
+
+#if ADD_MISSING_POSIX
+/* Used to mark names defined in the Posix.1 or Posix.2 standard. */
+#define POSIX1_SYMBOL 2
+#define POSIX2_SYMBOL 4
+#else
+#define POSIX1_SYMBOL 0
+#define POSIX2_SYMBOL 0
+#endif
+
+#if ADD_MISSING_XOPEN
+/* Used to mark names defined in X/Open Portability Guide. */
+#define XOPEN_SYMBOL 8
+/* Used to mark names defined in X/Open UNIX Extensions. */
+#define XOPEN_EXTENDED_SYMBOL 16
+#else
+#define XOPEN_SYMBOL 0
+#define XOPEN_EXTENDED_SYMBOL 0
+#endif
+
+/* Used to indicate names that are not functions */
+#define MACRO_SYMBOL 512
+
+struct symbol_list {
+ symbol_flags flags;
+ namelist names;
+};
+
+#define SYMBOL_TABLE_SIZE 10
+struct symbol_list symbol_table[SYMBOL_TABLE_SIZE];
+int cur_symbol_table_size;
+
+static void add_symbols (symbol_flags, namelist);
+static struct fn_decl *lookup_std_proto (const char *, int);
+static void write_lbrac (void);
+static void recognized_macro (const char *);
+static void check_macro_names (cpp_reader *, namelist);
+static void read_scan_file (char *, int, char **);
+static void write_rbrac (void);
+static int inf_skip_spaces (int);
+static int inf_read_upto (sstring *, int);
+static int inf_scan_ident (sstring *, int);
+static int check_protection (int *, int *);
+static void cb_file_change (cpp_reader *, const struct line_map *);
+
+static void
+add_symbols (symbol_flags flags, namelist names)
+{
+ symbol_table[cur_symbol_table_size].flags = flags;
+ symbol_table[cur_symbol_table_size].names = names;
+ cur_symbol_table_size++;
+ if (cur_symbol_table_size >= SYMBOL_TABLE_SIZE)
+ fatal ("too many calls to add_symbols");
+ symbol_table[cur_symbol_table_size].names = NULL; /* Termination. */
+}
+
+struct std_include_entry {
+ const char *const name;
+ const symbol_flags flags;
+ const namelist names;
+};
+
+const char NONE[] = ""; /* The empty namelist. */
+
+/* Special name to indicate a continuation line in std_include_table. */
+const char CONTINUED[] = "";
+
+const struct std_include_entry *include_entry;
+
+const struct std_include_entry std_include_table [] = {
+ { "ctype.h", ANSI_SYMBOL,
+ "isalnum\0isalpha\0iscntrl\0isdigit\0isgraph\0islower\0\
+isprint\0ispunct\0isspace\0isupper\0isxdigit\0tolower\0toupper\0" },
+
+ { "dirent.h", POSIX1_SYMBOL, "closedir\0opendir\0readdir\0rewinddir\0"},
+
+ { "errno.h", ANSI_SYMBOL|MACRO_SYMBOL, "errno\0" },
+
+ /* ANSI_SYMBOL is wrong, but ... */
+ { "curses.h", ANSI_SYMBOL, "box\0delwin\0endwin\0getcurx\0getcury\0initscr\0\
+mvcur\0mvwprintw\0mvwscanw\0newwin\0overlay\0overwrite\0\
+scroll\0subwin\0touchwin\0waddstr\0wclear\0wclrtobot\0wclrtoeol\0\
+waddch\0wdelch\0wdeleteln\0werase\0wgetch\0wgetstr\0winsch\0winsertln\0\
+wmove\0wprintw\0wrefresh\0wscanw\0wstandend\0wstandout\0" },
+
+ { "fcntl.h", POSIX1_SYMBOL, "creat\0fcntl\0open\0" },
+
+ /* Maybe also "getgrent fgetgrent setgrent endgrent" */
+ { "grp.h", POSIX1_SYMBOL, "getgrgid\0getgrnam\0" },
+
+/*{ "limit.h", ... provided by gcc }, */
+
+ { "locale.h", ANSI_SYMBOL, "localeconv\0setlocale\0" },
+
+ { "math.h", ANSI_SYMBOL,
+ "acos\0asin\0atan\0atan2\0ceil\0cos\0cosh\0exp\0\
+fabs\0floor\0fmod\0frexp\0ldexp\0log10\0log\0modf\0pow\0sin\0sinh\0sqrt\0\
+tan\0tanh\0" },
+
+ { CONTINUED, ANSI_SYMBOL|MACRO_SYMBOL, "HUGE_VAL\0" },
+
+ { "pwd.h", POSIX1_SYMBOL, "getpwnam\0getpwuid\0" },
+
+ /* Left out siglongjmp sigsetjmp - these depend on sigjmp_buf. */
+ { "setjmp.h", ANSI_SYMBOL, "longjmp\0setjmp\0" },
+
+ /* Left out signal() - its prototype is too complex for us!
+ Also left out "sigaction sigaddset sigdelset sigemptyset
+ sigfillset sigismember sigpending sigprocmask sigsuspend"
+ because these need sigset_t or struct sigaction.
+ Most systems that provide them will also declare them. */
+ { "signal.h", ANSI_SYMBOL, "raise\0" },
+ { CONTINUED, POSIX1_SYMBOL, "kill\0" },
+
+ { "stdio.h", ANSI_SYMBOL,
+ "clearerr\0fclose\0feof\0ferror\0fflush\0fgetc\0fgetpos\0\
+fgets\0fopen\0fprintf\0fputc\0fputs\0fread\0freopen\0fscanf\0fseek\0\
+fsetpos\0ftell\0fwrite\0getc\0getchar\0gets\0perror\0\
+printf\0putc\0putchar\0puts\0remove\0rename\0rewind\0scanf\0setbuf\0\
+setvbuf\0sprintf\0sscanf\0vprintf\0vsprintf\0vfprintf\0tmpfile\0\
+tmpnam\0ungetc\0" },
+ { CONTINUED, POSIX1_SYMBOL, "fdopen\0fileno\0" },
+ { CONTINUED, POSIX2_SYMBOL, "pclose\0popen\0" }, /* I think ... */
+/* Should perhaps also handle NULL, EOF, ... ? */
+
+ /* "div ldiv", - ignored because these depend on div_t, ldiv_t
+ ignore these: "mblen mbstowcs mbstowc wcstombs wctomb"
+ Left out getgroups, because SunOS4 has incompatible BSD and SVR4 versions.
+ Should perhaps also add NULL */
+ { "stdlib.h", ANSI_SYMBOL,
+ "abort\0abs\0atexit\0atof\0atoi\0atol\0bsearch\0calloc\0\
+exit\0free\0getenv\0labs\0malloc\0qsort\0rand\0realloc\0\
+srand\0strtod\0strtol\0strtoul\0system\0" },
+ { CONTINUED, ANSI_SYMBOL|MACRO_SYMBOL, "EXIT_FAILURE\0EXIT_SUCCESS\0" },
+ { CONTINUED, POSIX1_SYMBOL, "putenv\0" },
+
+ { "string.h", ANSI_SYMBOL, "memchr\0memcmp\0memcpy\0memmove\0memset\0\
+strcat\0strchr\0strcmp\0strcoll\0strcpy\0strcspn\0strerror\0\
+strlen\0strncat\0strncmp\0strncpy\0strpbrk\0strrchr\0strspn\0strstr\0\
+strtok\0strxfrm\0" },
+/* Should perhaps also add NULL and size_t */
+
+ { "strings.h", XOPEN_EXTENDED_SYMBOL,
+ "bcmp\0bcopy\0bzero\0ffs\0index\0rindex\0strcasecmp\0strncasecmp\0" },
+
+ { "strops.h", XOPEN_EXTENDED_SYMBOL, "ioctl\0" },
+
+ /* Actually, XPG4 does not seem to have <sys/ioctl.h>, but defines
+ ioctl in <strops.h>. However, many systems have it is sys/ioctl.h,
+ and many systems do have <sys/ioctl.h> but not <strops.h>. */
+ { "sys/ioctl.h", XOPEN_EXTENDED_SYMBOL, "ioctl\0" },
+
+ { "sys/socket.h", XOPEN_EXTENDED_SYMBOL, "socket\0" },
+
+ { "sys/stat.h", POSIX1_SYMBOL,
+ "chmod\0fstat\0mkdir\0mkfifo\0stat\0lstat\0umask\0" },
+ { CONTINUED, POSIX1_SYMBOL|MACRO_SYMBOL,
+ "S_ISDIR\0S_ISBLK\0S_ISCHR\0S_ISFIFO\0S_ISREG\0S_ISLNK\0S_IFDIR\0\
+S_IFBLK\0S_IFCHR\0S_IFIFO\0S_IFREG\0S_IFLNK\0" },
+ { CONTINUED, XOPEN_EXTENDED_SYMBOL, "fchmod\0" },
+
+#if 0
+/* How do we handle fd_set? */
+ { "sys/time.h", XOPEN_EXTENDED_SYMBOL, "select\0" },
+ { "sys/select.h", XOPEN_EXTENDED_SYMBOL /* fake */, "select\0" },
+#endif
+
+ { "sys/times.h", POSIX1_SYMBOL, "times\0" },
+ /* "sys/types.h" add types (not in old g++-include) */
+
+ { "sys/utsname.h", POSIX1_SYMBOL, "uname\0" },
+
+ { "sys/wait.h", POSIX1_SYMBOL, "wait\0waitpid\0" },
+ { CONTINUED, POSIX1_SYMBOL|MACRO_SYMBOL,
+ "WEXITSTATUS\0WIFEXITED\0WIFSIGNALED\0WIFSTOPPED\0WSTOPSIG\0\
+WTERMSIG\0WNOHANG\0WNOTRACED\0" },
+
+ { "tar.h", POSIX1_SYMBOL, NONE },
+
+ { "termios.h", POSIX1_SYMBOL,
+ "cfgetispeed\0cfgetospeed\0cfsetispeed\0cfsetospeed\0tcdrain\0tcflow\0tcflush\0tcgetattr\0tcsendbreak\0tcsetattr\0" },
+
+ { "time.h", ANSI_SYMBOL,
+ "asctime\0clock\0ctime\0difftime\0gmtime\0localtime\0mktime\0strftime\0time\0" },
+ { CONTINUED, POSIX1_SYMBOL, "tzset\0" },
+
+ { "unistd.h", POSIX1_SYMBOL,
+ "_exit\0access\0alarm\0chdir\0chown\0close\0ctermid\0cuserid\0\
+dup\0dup2\0execl\0execle\0execlp\0execv\0execve\0execvp\0fork\0fpathconf\0\
+getcwd\0getegid\0geteuid\0getgid\0getlogin\0getpgrp\0getpid\0\
+getppid\0getuid\0isatty\0link\0lseek\0pathconf\0pause\0pipe\0read\0rmdir\0\
+setgid\0setpgid\0setsid\0setuid\0sleep\0sysconf\0tcgetpgrp\0tcsetpgrp\0\
+ttyname\0unlink\0write\0" },
+ { CONTINUED, POSIX2_SYMBOL, "getopt\0" },
+ { CONTINUED, XOPEN_EXTENDED_SYMBOL,
+ "lockf\0gethostid\0gethostname\0readlink\0symlink\0" },
+
+ { "utime.h", POSIX1_SYMBOL, "utime\0" },
+
+ { NULL, 0, NONE }