Index: head/bin/pax/options.c =================================================================== --- head/bin/pax/options.c (revision 299354) +++ head/bin/pax/options.c (revision 299355) @@ -1,1590 +1,1590 @@ /*- * Copyright (c) 1992 Keith Muller. * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Keith Muller of the University of California, San Diego. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include "pax.h" #include "options.h" #include "cpio.h" #include "tar.h" #include "extern.h" /* * Routines which handle command line options */ static char flgch[] = FLGCH; /* list of all possible flags */ static OPLIST *ophead = NULL; /* head for format specific options -x */ static OPLIST *optail = NULL; /* option tail */ static int no_op(void); static void printflg(unsigned int); static int c_frmt(const void *, const void *); static off_t str_offt(char *); -static char *getline(FILE *fp); +static char *get_line(FILE *fp); static void pax_options(int, char **); static void pax_usage(void); static void tar_options(int, char **); static void tar_usage(void); static void cpio_options(int, char **); static void cpio_usage(void); -/* errors from getline */ +/* errors from get_line */ #define GETLINE_FILE_CORRUPT 1 #define GETLINE_OUT_OF_MEM 2 -static int getline_error; +static int get_line_error; char *chdname; #define GZIP_CMD "gzip" /* command to run as gzip */ #define COMPRESS_CMD "compress" /* command to run as compress */ #define BZIP2_CMD "bzip2" /* command to run as gzip */ /* * Format specific routine table - MUST BE IN SORTED ORDER BY NAME * (see pax.h for description of each function) * * name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read, * read, end_read, st_write, write, end_write, trail, * rd_data, wr_data, options */ FSUB fsub[] = { /* 0: OLD BINARY CPIO */ {"bcpio", 5120, sizeof(HD_BCPIO), 1, 0, 0, 1, bcpio_id, cpio_strd, bcpio_rd, bcpio_endrd, cpio_stwr, bcpio_wr, cpio_endwr, cpio_trail, NULL, rd_wrfile, wr_rdfile, bad_opt}, /* 1: OLD OCTAL CHARACTER CPIO */ {"cpio", 5120, sizeof(HD_CPIO), 1, 0, 0, 1, cpio_id, cpio_strd, cpio_rd, cpio_endrd, cpio_stwr, cpio_wr, cpio_endwr, cpio_trail, NULL, rd_wrfile, wr_rdfile, bad_opt}, /* 2: SVR4 HEX CPIO */ {"sv4cpio", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, vcpio_id, cpio_strd, vcpio_rd, vcpio_endrd, cpio_stwr, vcpio_wr, cpio_endwr, cpio_trail, NULL, rd_wrfile, wr_rdfile, bad_opt}, /* 3: SVR4 HEX CPIO WITH CRC */ {"sv4crc", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, crc_id, crc_strd, vcpio_rd, vcpio_endrd, crc_stwr, vcpio_wr, cpio_endwr, cpio_trail, NULL, rd_wrfile, wr_rdfile, bad_opt}, /* 4: OLD TAR */ {"tar", 10240, BLKMULT, 0, 1, BLKMULT, 0, tar_id, no_op, tar_rd, tar_endrd, no_op, tar_wr, tar_endwr, NULL, tar_trail, rd_wrfile, wr_rdfile, tar_opt}, /* 5: POSIX USTAR */ {"ustar", 10240, BLKMULT, 0, 1, BLKMULT, 0, ustar_id, ustar_strd, ustar_rd, tar_endrd, ustar_stwr, ustar_wr, tar_endwr, NULL, tar_trail, rd_wrfile, wr_rdfile, bad_opt}, }; #define F_OCPIO 0 /* format when called as cpio -6 */ #define F_ACPIO 1 /* format when called as cpio -c */ #define F_CPIO 3 /* format when called as cpio */ #define F_OTAR 4 /* format when called as tar -o */ #define F_TAR 5 /* format when called as tar */ #define DEFLT 5 /* default write format from list above */ /* * ford is the archive search order used by get_arc() to determine what kind * of archive we are dealing with. This helps to properly id archive formats * some formats may be subsets of others.... */ int ford[] = {5, 4, 3, 2, 1, 0, -1 }; /* * options() * figure out if we are pax, tar or cpio. Call the appropriate options * parser */ void options(int argc, char **argv) { /* * Are we acting like pax, tar or cpio (based on argv[0]) */ if ((argv0 = strrchr(argv[0], '/')) != NULL) argv0++; else argv0 = argv[0]; if (strcmp(NM_TAR, argv0) == 0) { tar_options(argc, argv); return; } else if (strcmp(NM_CPIO, argv0) == 0) { cpio_options(argc, argv); return; } /* * assume pax as the default */ argv0 = NM_PAX; pax_options(argc, argv); return; } /* * pax_options() * look at the user specified flags. set globals as required and check if * the user specified a legal set of flags. If not, complain and exit */ static void pax_options(int argc, char **argv) { int c; size_t i; unsigned int flg = 0; unsigned int bflg = 0; char *pt; FSUB tmp; /* * process option flags */ while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ")) != -1) { switch (c) { case 'a': /* * append */ flg |= AF; break; case 'b': /* * specify blocksize */ flg |= BF; if ((wrblksz = (int)str_offt(optarg)) <= 0) { paxwarn(1, "Invalid block size %s", optarg); pax_usage(); } break; case 'c': /* * inverse match on patterns */ cflag = 1; flg |= CF; break; case 'd': /* * match only dir on extract, not the subtree at dir */ dflag = 1; flg |= DF; break; case 'f': /* * filename where the archive is stored */ arcname = optarg; flg |= FF; break; case 'i': /* * interactive file rename */ iflag = 1; flg |= IF; break; case 'k': /* * do not clobber files that exist */ kflag = 1; flg |= KF; break; case 'l': /* * try to link src to dest with copy (-rw) */ lflag = 1; flg |= LF; break; case 'n': /* * select first match for a pattern only */ nflag = 1; flg |= NF; break; case 'o': /* * pass format specific options */ flg |= OF; if (opt_add(optarg) < 0) pax_usage(); break; case 'p': /* * specify file characteristic options */ for (pt = optarg; *pt != '\0'; ++pt) { switch(*pt) { case 'a': /* * do not preserve access time */ patime = 0; break; case 'e': /* * preserve user id, group id, file * mode, access/modification times */ pids = 1; pmode = 1; patime = 1; pmtime = 1; break; case 'm': /* * do not preserve modification time */ pmtime = 0; break; case 'o': /* * preserve uid/gid */ pids = 1; break; case 'p': /* * preserver file mode bits */ pmode = 1; break; default: paxwarn(1, "Invalid -p string: %c", *pt); pax_usage(); break; } } flg |= PF; break; case 'r': /* * read the archive */ flg |= RF; break; case 's': /* * file name substitution name pattern */ if (rep_add(optarg) < 0) { pax_usage(); break; } flg |= SF; break; case 't': /* * preserve access time on file system nodes we read */ tflag = 1; flg |= TF; break; case 'u': /* * ignore those older files */ uflag = 1; flg |= UF; break; case 'v': /* * verbose operation mode */ vflag = 1; flg |= VF; break; case 'w': /* * write an archive */ flg |= WF; break; case 'x': /* * specify an archive format on write */ tmp.name = optarg; if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub, sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL) { flg |= XF; break; } paxwarn(1, "Unknown -x format: %s", optarg); (void)fputs("pax: Known -x formats are:", stderr); for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i) (void)fprintf(stderr, " %s", fsub[i].name); (void)fputs("\n\n", stderr); pax_usage(); break; case 'z': /* * use gzip. Non standard option. */ gzip_program = GZIP_CMD; break; case 'B': /* * non-standard option on number of bytes written on a * single archive volume. */ if ((wrlimit = str_offt(optarg)) <= 0) { paxwarn(1, "Invalid write limit %s", optarg); pax_usage(); } if (wrlimit % BLKMULT) { paxwarn(1, "Write limit is not a %d byte multiple", BLKMULT); pax_usage(); } flg |= CBF; break; case 'D': /* * On extraction check file inode change time before the * modification of the file name. Non standard option. */ Dflag = 1; flg |= CDF; break; case 'E': /* * non-standard limit on read faults * 0 indicates stop after first error, values * indicate a limit, "NONE" try forever */ flg |= CEF; if (strcmp(NONE, optarg) == 0) maxflt = -1; else if ((maxflt = atoi(optarg)) < 0) { paxwarn(1, "Error count value must be positive"); pax_usage(); } break; case 'G': /* * non-standard option for selecting files within an * archive by group (gid or name) */ if (grp_add(optarg) < 0) { pax_usage(); break; } flg |= CGF; break; case 'H': /* * follow command line symlinks only */ Hflag = 1; flg |= CHF; break; case 'L': /* * follow symlinks */ Lflag = 1; flg |= CLF; break; case 'O': /* * Force one volume. Non standard option. */ Oflag = 1; break; case 'P': /* * do NOT follow symlinks (default) */ Lflag = 0; flg |= CPF; break; case 'T': /* * non-standard option for selecting files within an * archive by modification time range (lower,upper) */ if (trng_add(optarg) < 0) { pax_usage(); break; } flg |= CTF; break; case 'U': /* * non-standard option for selecting files within an * archive by user (uid or name) */ if (usr_add(optarg) < 0) { pax_usage(); break; } flg |= CUF; break; case 'X': /* * do not pass over mount points in the file system */ Xflag = 1; flg |= CXF; break; case 'Y': /* * On extraction check file inode change time after the * modification of the file name. Non standard option. */ Yflag = 1; flg |= CYF; break; case 'Z': /* * On extraction check modification time after the * modification of the file name. Non standard option. */ Zflag = 1; flg |= CZF; break; default: pax_usage(); break; } } /* * figure out the operation mode of pax read,write,extract,copy,append * or list. check that we have not been given a bogus set of flags * for the operation mode. */ if (ISLIST(flg)) { act = LIST; listf = stdout; bflg = flg & BDLIST; } else if (ISEXTRACT(flg)) { act = EXTRACT; bflg = flg & BDEXTR; } else if (ISARCHIVE(flg)) { act = ARCHIVE; bflg = flg & BDARCH; } else if (ISAPPND(flg)) { act = APPND; bflg = flg & BDARCH; } else if (ISCOPY(flg)) { act = COPY; bflg = flg & BDCOPY; } else pax_usage(); if (bflg) { printflg(flg); pax_usage(); } /* * if we are writing (ARCHIVE) we use the default format if the user * did not specify a format. when we write during an APPEND, we will * adopt the format of the existing archive if none was supplied. */ if (!(flg & XF) && (act == ARCHIVE)) frmt = &(fsub[DEFLT]); /* * process the args as they are interpreted by the operation mode */ switch (act) { case LIST: case EXTRACT: for (; optind < argc; optind++) if (pat_add(argv[optind], NULL) < 0) pax_usage(); break; case COPY: if (optind >= argc) { paxwarn(0, "Destination directory was not supplied"); pax_usage(); } --argc; dirptr = argv[argc]; /* FALLTHROUGH */ case ARCHIVE: case APPND: for (; optind < argc; optind++) if (ftree_add(argv[optind], 0) < 0) pax_usage(); /* * no read errors allowed on updates/append operation! */ maxflt = 0; break; } } /* * tar_options() * look at the user specified flags. set globals as required and check if * the user specified a legal set of flags. If not, complain and exit */ static void tar_options(int argc, char **argv) { int c; int fstdin = 0; int tar_Oflag = 0; int nincfiles = 0; int incfiles_max = 0; struct incfile { char *file; char *dir; }; struct incfile *incfiles = NULL; /* * Set default values. */ rmleadslash = 1; /* * process option flags */ while ((c = getoldopt(argc, argv, "b:cef:hjmopqruts:vwxyzBC:HI:LOPXZ014578")) != -1) { switch(c) { case 'b': /* * specify blocksize in 512-byte blocks */ if ((wrblksz = (int)str_offt(optarg)) <= 0) { paxwarn(1, "Invalid block size %s", optarg); tar_usage(); } wrblksz *= 512; /* XXX - check for int oflow */ break; case 'c': /* * create an archive */ act = ARCHIVE; break; case 'e': /* * stop after first error */ maxflt = 0; break; case 'f': /* * filename where the archive is stored */ if ((optarg[0] == '-') && (optarg[1]== '\0')) { /* * treat a - as stdin */ fstdin = 1; arcname = NULL; break; } fstdin = 0; arcname = optarg; break; case 'h': /* * follow symlinks */ Lflag = 1; break; case 'j': case 'y': /* * use bzip2. Non standard option. */ gzip_program = BZIP2_CMD; break; case 'm': /* * do not preserve modification time */ pmtime = 0; break; case 'o': if (opt_add("write_opt=nodir") < 0) tar_usage(); case 'O': tar_Oflag = 1; break; case 'p': /* * preserve uid/gid and file mode, regardless of umask */ pmode = 1; pids = 1; break; case 'q': /* * select first match for a pattern only */ nflag = 1; break; case 'r': case 'u': /* * append to the archive */ act = APPND; break; case 's': /* * file name substitution name pattern */ if (rep_add(optarg) < 0) { tar_usage(); break; } break; case 't': /* * list contents of the tape */ act = LIST; break; case 'v': /* * verbose operation mode */ vflag++; break; case 'w': /* * interactive file rename */ iflag = 1; break; case 'x': /* * extract an archive, preserving mode, * and mtime if possible. */ act = EXTRACT; pmtime = 1; break; case 'z': /* * use gzip. Non standard option. */ gzip_program = GZIP_CMD; break; case 'B': /* * Nothing to do here, this is pax default */ break; case 'C': chdname = optarg; break; case 'H': /* * follow command line symlinks only */ Hflag = 1; break; case 'I': if (++nincfiles > incfiles_max) { incfiles_max = nincfiles + 3; incfiles = realloc(incfiles, sizeof(*incfiles) * incfiles_max); if (incfiles == NULL) { paxwarn(0, "Unable to allocate space " "for option list"); exit(1); } } incfiles[nincfiles - 1].file = optarg; incfiles[nincfiles - 1].dir = chdname; break; case 'L': /* * follow symlinks */ Lflag = 1; break; case 'P': /* * do not remove leading '/' from pathnames */ rmleadslash = 0; break; case 'X': /* * do not pass over mount points in the file system */ Xflag = 1; break; case 'Z': /* * use compress. */ gzip_program = COMPRESS_CMD; break; case '0': arcname = DEV_0; break; case '1': arcname = DEV_1; break; case '4': arcname = DEV_4; break; case '5': arcname = DEV_5; break; case '7': arcname = DEV_7; break; case '8': arcname = DEV_8; break; default: tar_usage(); break; } } argc -= optind; argv += optind; /* Traditional tar behaviour (pax uses stderr unless in list mode) */ if (fstdin == 1 && act == ARCHIVE) listf = stderr; else listf = stdout; /* Traditional tar behaviour (pax wants to read file list from stdin) */ if ((act == ARCHIVE || act == APPND) && argc == 0 && nincfiles == 0) exit(0); /* * if we are writing (ARCHIVE) specify tar, otherwise run like pax * (unless -o specified) */ if (act == ARCHIVE || act == APPND) frmt = &(fsub[tar_Oflag ? F_OTAR : F_TAR]); else if (tar_Oflag) { paxwarn(1, "The -O/-o options are only valid when writing an archive"); tar_usage(); /* only valid when writing */ } /* * process the args as they are interpreted by the operation mode */ switch (act) { case LIST: case EXTRACT: default: { int sawpat = 0; char *file, *dir = NULL; while (nincfiles || *argv != NULL) { /* * If we queued up any include files, * pull them in now. Otherwise, check * for -I and -C positional flags. * Anything else must be a file to * extract. */ if (nincfiles) { file = incfiles->file; dir = incfiles->dir; incfiles++; nincfiles--; } else if (strcmp(*argv, "-I") == 0) { if (*++argv == NULL) break; file = *argv++; dir = chdname; } else file = NULL; if (file != NULL) { FILE *fp; char *str; if (strcmp(file, "-") == 0) fp = stdin; else if ((fp = fopen(file, "r")) == NULL) { paxwarn(1, "Unable to open file '%s' for read", file); tar_usage(); } - while ((str = getline(fp)) != NULL) { + while ((str = get_line(fp)) != NULL) { if (pat_add(str, dir) < 0) tar_usage(); sawpat = 1; } if (strcmp(file, "-") != 0) fclose(fp); - if (getline_error) { + if (get_line_error) { paxwarn(1, "Problem with file '%s'", file); tar_usage(); } } else if (strcmp(*argv, "-C") == 0) { if (*++argv == NULL) break; chdname = *argv++; } else if (pat_add(*argv++, chdname) < 0) tar_usage(); else sawpat = 1; } /* * if patterns were added, we are doing chdir() * on a file-by-file basis, else, just one * global chdir (if any) after opening input. */ if (sawpat > 0) chdname = NULL; } break; case ARCHIVE: case APPND: if (chdname != NULL) { /* initial chdir() */ if (ftree_add(chdname, 1) < 0) tar_usage(); } while (nincfiles || *argv != NULL) { char *file, *dir = NULL; /* * If we queued up any include files, pull them in * now. Otherwise, check for -I and -C positional * flags. Anything else must be a file to include * in the archive. */ if (nincfiles) { file = incfiles->file; dir = incfiles->dir; incfiles++; nincfiles--; } else if (strcmp(*argv, "-I") == 0) { if (*++argv == NULL) break; file = *argv++; dir = NULL; } else file = NULL; if (file != NULL) { FILE *fp; char *str; /* Set directory if needed */ if (dir) { if (ftree_add(dir, 1) < 0) tar_usage(); } if (strcmp(file, "-") == 0) fp = stdin; else if ((fp = fopen(file, "r")) == NULL) { paxwarn(1, "Unable to open file '%s' for read", file); tar_usage(); } - while ((str = getline(fp)) != NULL) { + while ((str = get_line(fp)) != NULL) { if (ftree_add(str, 0) < 0) tar_usage(); } if (strcmp(file, "-") != 0) fclose(fp); - if (getline_error) { + if (get_line_error) { paxwarn(1, "Problem with file '%s'", file); tar_usage(); } } else if (strcmp(*argv, "-C") == 0) { if (*++argv == NULL) break; if (ftree_add(*argv++, 1) < 0) tar_usage(); } else if (ftree_add(*argv++, 0) < 0) tar_usage(); } /* * no read errors allowed on updates/append operation! */ maxflt = 0; break; } if (!fstdin && ((arcname == NULL) || (*arcname == '\0'))) { arcname = getenv("TAPE"); if ((arcname == NULL) || (*arcname == '\0')) arcname = _PATH_DEFTAPE; } } static int mkpath(char *path) { struct stat sb; char *slash; int done = 0; slash = path; while (!done) { slash += strspn(slash, "/"); slash += strcspn(slash, "/"); done = (*slash == '\0'); *slash = '\0'; if (stat(path, &sb)) { if (errno != ENOENT || mkdir(path, 0777)) { paxwarn(1, "%s", path); return (-1); } } else if (!S_ISDIR(sb.st_mode)) { syswarn(1, ENOTDIR, "%s", path); return (-1); } if (!done) *slash = '/'; } return (0); } /* * cpio_options() * look at the user specified flags. set globals as required and check if * the user specified a legal set of flags. If not, complain and exit */ static void cpio_options(int argc, char **argv) { int c; size_t i; char *str; FSUB tmp; FILE *fp; kflag = 1; pids = 1; pmode = 1; pmtime = 0; arcname = NULL; dflag = 1; act = -1; nodirs = 1; while ((c=getopt(argc,argv,"abcdfiklmoprstuvzABC:E:F:H:I:LO:SZ6")) != -1) switch (c) { case 'a': /* * preserve access time on files read */ tflag = 1; break; case 'b': /* * swap bytes and half-words when reading data */ break; case 'c': /* * ASCII cpio header */ frmt = &(fsub[F_ACPIO]); break; case 'd': /* * create directories as needed */ nodirs = 0; break; case 'f': /* * invert meaning of pattern list */ cflag = 1; break; case 'i': /* * restore an archive */ act = EXTRACT; break; case 'k': break; case 'l': /* * use links instead of copies when possible */ lflag = 1; break; case 'm': /* * preserve modification time */ pmtime = 1; break; case 'o': /* * create an archive */ act = ARCHIVE; frmt = &(fsub[F_CPIO]); break; case 'p': /* * copy-pass mode */ act = COPY; break; case 'r': /* * interactively rename files */ iflag = 1; break; case 's': /* * swap bytes after reading data */ break; case 't': /* * list contents of archive */ act = LIST; listf = stdout; break; case 'u': /* * replace newer files */ kflag = 0; break; case 'v': /* * verbose operation mode */ vflag = 1; break; case 'z': /* * use gzip. Non standard option. */ gzip_program = GZIP_CMD; break; case 'A': /* * append mode */ act = APPND; break; case 'B': /* * Use 5120 byte block size */ wrblksz = 5120; break; case 'C': /* * set block size in bytes */ wrblksz = atoi(optarg); break; case 'E': /* * file with patterns to extract or list */ if ((fp = fopen(optarg, "r")) == NULL) { paxwarn(1, "Unable to open file '%s' for read", optarg); cpio_usage(); } - while ((str = getline(fp)) != NULL) { + while ((str = get_line(fp)) != NULL) { pat_add(str, NULL); } fclose(fp); - if (getline_error) { + if (get_line_error) { paxwarn(1, "Problem with file '%s'", optarg); cpio_usage(); } break; case 'F': case 'I': case 'O': /* * filename where the archive is stored */ if ((optarg[0] == '-') && (optarg[1]== '\0')) { /* * treat a - as stdin */ arcname = NULL; break; } arcname = optarg; break; case 'H': /* * specify an archive format on write */ tmp.name = optarg; if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub, sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL) break; paxwarn(1, "Unknown -H format: %s", optarg); (void)fputs("cpio: Known -H formats are:", stderr); for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i) (void)fprintf(stderr, " %s", fsub[i].name); (void)fputs("\n\n", stderr); cpio_usage(); break; case 'L': /* * follow symbolic links */ Lflag = 1; break; case 'S': /* * swap halfwords after reading data */ break; case 'Z': /* * use compress. Non standard option. */ gzip_program = COMPRESS_CMD; break; case '6': /* * process Version 6 cpio format */ frmt = &(fsub[F_OCPIO]); break; case '?': default: cpio_usage(); break; } argc -= optind; argv += optind; /* * process the args as they are interpreted by the operation mode */ switch (act) { case LIST: case EXTRACT: while (*argv != NULL) if (pat_add(*argv++, NULL) < 0) cpio_usage(); break; case COPY: if (*argv == NULL) { paxwarn(0, "Destination directory was not supplied"); cpio_usage(); } dirptr = *argv; if (mkpath(dirptr) < 0) cpio_usage(); --argc; ++argv; /* FALLTHROUGH */ case ARCHIVE: case APPND: if (*argv != NULL) cpio_usage(); /* * no read errors allowed on updates/append operation! */ maxflt = 0; - while ((str = getline(stdin)) != NULL) { + while ((str = get_line(stdin)) != NULL) { ftree_add(str, 0); } - if (getline_error) { + if (get_line_error) { paxwarn(1, "Problem while reading stdin"); cpio_usage(); } break; default: cpio_usage(); break; } } /* * printflg() * print out those invalid flag sets found to the user */ static void printflg(unsigned int flg) { int nxt; int pos = 0; (void)fprintf(stderr,"%s: Invalid combination of options:", argv0); while ((nxt = ffs(flg)) != 0) { flg = flg >> nxt; pos += nxt; (void)fprintf(stderr, " -%c", flgch[pos-1]); } (void)putc('\n', stderr); } /* * c_frmt() * comparison routine used by bsearch to find the format specified * by the user */ static int c_frmt(const void *a, const void *b) { return(strcmp(((const FSUB *)a)->name, ((const FSUB *)b)->name)); } /* * opt_next() * called by format specific options routines to get each format specific * flag and value specified with -o * Return: * pointer to next OPLIST entry or NULL (end of list). */ OPLIST * opt_next(void) { OPLIST *opt; if ((opt = ophead) != NULL) ophead = ophead->fow; return(opt); } /* * bad_opt() * generic routine used to complain about a format specific options * when the format does not support options. */ int bad_opt(void) { OPLIST *opt; if (ophead == NULL) return(0); /* * print all we were given */ paxwarn(1,"These format options are not supported"); while ((opt = opt_next()) != NULL) (void)fprintf(stderr, "\t%s = %s\n", opt->name, opt->value); pax_usage(); return(0); } /* * opt_add() * breaks the value supplied to -o into an option name and value. Options * are given to -o in the form -o name-value,name=value * multiple -o may be specified. * Return: * 0 if format in name=value format, -1 if -o is passed junk. */ int opt_add(const char *str) { OPLIST *opt; char *frpt; char *pt; char *endpt; char *lstr; if ((str == NULL) || (*str == '\0')) { paxwarn(0, "Invalid option name"); return(-1); } if ((lstr = strdup(str)) == NULL) { paxwarn(0, "Unable to allocate space for option list"); return(-1); } frpt = endpt = lstr; /* * break into name and values pieces and stuff each one into a * OPLIST structure. When we know the format, the format specific * option function will go through this list */ while ((frpt != NULL) && (*frpt != '\0')) { if ((endpt = strchr(frpt, ',')) != NULL) *endpt = '\0'; if ((pt = strchr(frpt, '=')) == NULL) { paxwarn(0, "Invalid options format"); free(lstr); return(-1); } if ((opt = (OPLIST *)malloc(sizeof(OPLIST))) == NULL) { paxwarn(0, "Unable to allocate space for option list"); free(lstr); return(-1); } lstr = NULL; /* parts of string going onto the OPLIST */ *pt++ = '\0'; opt->name = frpt; opt->value = pt; opt->fow = NULL; if (endpt != NULL) frpt = endpt + 1; else frpt = NULL; if (ophead == NULL) { optail = ophead = opt; continue; } optail->fow = opt; optail = opt; } free(lstr); return(0); } /* * str_offt() * Convert an expression of the following forms to an off_t > 0. * 1) A positive decimal number. * 2) A positive decimal number followed by a b (mult by 512). * 3) A positive decimal number followed by a k (mult by 1024). * 4) A positive decimal number followed by a m (mult by 512). * 5) A positive decimal number followed by a w (mult by sizeof int) * 6) Two or more positive decimal numbers (with/without k,b or w). * separated by x (also * for backwards compatibility), specifying * the product of the indicated values. * Return: * 0 for an error, a positive value o.w. */ static off_t str_offt(char *val) { char *expr; off_t num, t; # ifdef NET2_STAT num = strtol(val, &expr, 0); if ((num == LONG_MAX) || (num <= 0) || (expr == val)) # else num = strtoq(val, &expr, 0); if ((num == QUAD_MAX) || (num <= 0) || (expr == val)) # endif return(0); switch(*expr) { case 'b': t = num; num *= 512; if (t > num) return(0); ++expr; break; case 'k': t = num; num *= 1024; if (t > num) return(0); ++expr; break; case 'm': t = num; num *= 1048576; if (t > num) return(0); ++expr; break; case 'w': t = num; num *= sizeof(int); if (t > num) return(0); ++expr; break; } switch(*expr) { case '\0': break; case '*': case 'x': t = num; num *= str_offt(expr + 1); if (t > num) return(0); break; default: return(0); } return(num); } char * -getline(FILE *f) +get_line(FILE *f) { char *name, *temp; size_t len; name = fgetln(f, &len); if (!name) { - getline_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0; + get_line_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0; return(0); } if (name[len-1] != '\n') len++; temp = malloc(len); if (!temp) { - getline_error = GETLINE_OUT_OF_MEM; + get_line_error = GETLINE_OUT_OF_MEM; return(0); } memcpy(temp, name, len-1); temp[len-1] = 0; return(temp); } /* * no_op() * for those option functions where the archive format has nothing to do. * Return: * 0 */ static int no_op(void) { return(0); } /* * pax_usage() * print the usage summary to the user */ void pax_usage(void) { (void)fputs("usage: pax [-cdnOvz] [-E limit] [-f archive] ", stderr); (void)fputs("[-s replstr] ... [-U user] ...", stderr); (void)fputs("\n [-G group] ... ", stderr); (void)fputs("[-T [from_date][,to_date]] ... ", stderr); (void)fputs("[pattern ...]\n", stderr); (void)fputs(" pax -r [-cdiknOuvzDYZ] [-E limit] ", stderr); (void)fputs("[-f archive] [-o options] ... \n", stderr); (void)fputs(" [-p string] ... [-s replstr] ... ", stderr); (void)fputs("[-U user] ... [-G group] ...\n ", stderr); (void)fputs("[-T [from_date][,to_date]] ... ", stderr); (void)fputs(" [pattern ...]\n", stderr); (void)fputs(" pax -w [-dituvzHLOPX] [-b blocksize] ", stderr); (void)fputs("[ [-a] [-f archive] ] [-x format] \n", stderr); (void)fputs(" [-B bytes] [-s replstr] ... ", stderr); (void)fputs("[-o options] ... [-U user] ...", stderr); (void)fputs("\n [-G group] ... ", stderr); (void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr); (void)fputs("[file ...]\n", stderr); (void)fputs(" pax -r -w [-diklntuvDHLOPXYZ] ", stderr); (void)fputs("[-p string] ... [-s replstr] ...", stderr); (void)fputs("\n [-U user] ... [-G group] ... ", stderr); (void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr); (void)fputs("\n [file ...] directory\n", stderr); exit(1); } /* * tar_usage() * print the usage summary to the user */ void tar_usage(void) { (void)fputs("usage: tar [-]{crtux}[-befhjmopqsvwyzHLOPXZ014578] [blocksize] ", stderr); (void)fputs("[archive] [replstr] [-C directory] [-I file] [file ...]\n", stderr); exit(1); } /* * cpio_usage() * print the usage summary to the user */ void cpio_usage(void) { (void)fputs("usage: cpio -o [-aABcLvVzZ] [-C bytes] [-H format] [-O archive]\n", stderr); (void)fputs(" [-F archive] < name-list [> archive]\n", stderr); (void)fputs(" cpio -i [-bBcdfmnrsStuvVzZ6] [-C bytes] [-E file] [-H format]\n", stderr); (void)fputs(" [-I archive] [-F archive] [pattern...] [< archive]\n", stderr); (void)fputs(" cpio -p [-adlLmuvV] destination-directory < name-list\n", stderr); exit(1); } Index: head/usr.bin/csplit/csplit.c =================================================================== --- head/usr.bin/csplit/csplit.c (revision 299354) +++ head/usr.bin/csplit/csplit.c (revision 299355) @@ -1,467 +1,467 @@ /*- * Copyright (c) 2002 Tim J. Robbins. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * csplit -- split files based on context * * This utility splits its input into numbered output files by line number * or by a regular expression. Regular expression matches have an optional * offset with them, allowing the split to occur a specified number of * lines before or after the match. * * To handle negative offsets, we stop reading when the match occurs and * store the offset that the file should have been split at, then use * this output file as input until all the "overflowed" lines have been read. * The file is then closed and truncated to the correct length. * * We assume that the output files can be seeked upon (ie. they cannot be * symlinks to named pipes or character devices), but make no such * assumption about the input. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include static void cleanup(void); static void do_lineno(const char *); static void do_rexp(const char *); -static char *getline(void); +static char *get_line(void); static void handlesig(int); static FILE *newfile(void); static void toomuch(FILE *, long); static void usage(void); /* * Command line options */ static const char *prefix; /* File name prefix */ static long sufflen; /* Number of decimal digits for suffix */ static int sflag; /* Suppress output of file names */ static int kflag; /* Keep output if error occurs */ /* * Other miscellaneous globals (XXX too many) */ static long lineno; /* Current line number in input file */ static long reps; /* Number of repetitions for this pattern */ static long nfiles; /* Number of files output so far */ static long maxfiles; /* Maximum number of files we can create */ static char currfile[PATH_MAX]; /* Current output file */ static const char *infn; /* Name of the input file */ static FILE *infile; /* Input file handle */ static FILE *overfile; /* Overflow file for toomuch() */ static off_t truncofs; /* Offset this file should be truncated at */ static int doclean; /* Should cleanup() remove output? */ int main(int argc, char *argv[]) { struct sigaction sa; long i; int ch; const char *expr; char *ep, *p; FILE *ofp; setlocale(LC_ALL, ""); kflag = sflag = 0; prefix = "xx"; sufflen = 2; while ((ch = getopt(argc, argv, "ksf:n:")) > 0) { switch (ch) { case 'f': prefix = optarg; break; case 'k': kflag = 1; break; case 'n': errno = 0; sufflen = strtol(optarg, &ep, 10); if (sufflen <= 0 || *ep != '\0' || errno != 0) errx(1, "%s: bad suffix length", optarg); break; case 's': sflag = 1; break; default: usage(); /*NOTREACHED*/ } } if (sufflen + strlen(prefix) >= PATH_MAX) errx(1, "name too long"); argc -= optind; argv += optind; if ((infn = *argv++) == NULL) usage(); if (strcmp(infn, "-") == 0) { infile = stdin; infn = "stdin"; } else if ((infile = fopen(infn, "r")) == NULL) err(1, "%s", infn); if (!kflag) { doclean = 1; atexit(cleanup); sa.sa_flags = 0; sa.sa_handler = handlesig; sigemptyset(&sa.sa_mask); sigaddset(&sa.sa_mask, SIGHUP); sigaddset(&sa.sa_mask, SIGINT); sigaddset(&sa.sa_mask, SIGTERM); sigaction(SIGHUP, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); } lineno = 0; nfiles = 0; truncofs = 0; overfile = NULL; /* Ensure 10^sufflen < LONG_MAX. */ for (maxfiles = 1, i = 0; i < sufflen; i++) { if (maxfiles > LONG_MAX / 10) errx(1, "%ld: suffix too long (limit %ld)", sufflen, i); maxfiles *= 10; } /* Create files based on supplied patterns. */ while (nfiles < maxfiles - 1 && (expr = *argv++) != NULL) { /* Look ahead & see if this pattern has any repetitions. */ if (*argv != NULL && **argv == '{') { errno = 0; reps = strtol(*argv + 1, &ep, 10); if (reps < 0 || *ep != '}' || errno != 0) errx(1, "%s: bad repetition count", *argv + 1); argv++; } else reps = 0; if (*expr == '/' || *expr == '%') { do do_rexp(expr); while (reps-- != 0 && nfiles < maxfiles - 1); } else if (isdigit((unsigned char)*expr)) do_lineno(expr); else errx(1, "%s: unrecognised pattern", expr); } /* Copy the rest into a new file. */ if (!feof(infile)) { ofp = newfile(); - while ((p = getline()) != NULL && fputs(p, ofp) == 0) + while ((p = get_line()) != NULL && fputs(p, ofp) == 0) ; if (!sflag) printf("%jd\n", (intmax_t)ftello(ofp)); if (fclose(ofp) != 0) err(1, "%s", currfile); } toomuch(NULL, 0); doclean = 0; return (0); } static void usage(void) { fprintf(stderr, "usage: csplit [-ks] [-f prefix] [-n number] file args ...\n"); exit(1); } static void handlesig(int sig __unused) { const char msg[] = "csplit: caught signal, cleaning up\n"; write(STDERR_FILENO, msg, sizeof(msg) - 1); cleanup(); _exit(2); } /* Create a new output file. */ static FILE * newfile(void) { FILE *fp; if ((size_t)snprintf(currfile, sizeof(currfile), "%s%0*ld", prefix, (int)sufflen, nfiles) >= sizeof(currfile)) errc(1, ENAMETOOLONG, NULL); if ((fp = fopen(currfile, "w+")) == NULL) err(1, "%s", currfile); nfiles++; return (fp); } /* Remove partial output, called before exiting. */ static void cleanup(void) { char fnbuf[PATH_MAX]; long i; if (!doclean) return; /* * NOTE: One cannot portably assume to be able to call snprintf() * from inside a signal handler. It does, however, appear to be safe * to do on FreeBSD. The solution to this problem is worse than the * problem itself. */ for (i = 0; i < nfiles; i++) { snprintf(fnbuf, sizeof(fnbuf), "%s%0*ld", prefix, (int)sufflen, i); unlink(fnbuf); } } /* Read a line from the input into a static buffer. */ static char * -getline(void) +get_line(void) { static char lbuf[LINE_MAX]; FILE *src; src = overfile != NULL ? overfile : infile; again: if (fgets(lbuf, sizeof(lbuf), src) == NULL) { if (src == overfile) { src = infile; goto again; } return (NULL); } if (ferror(src)) err(1, "%s", infn); lineno++; return (lbuf); } -/* Conceptually rewind the input (as obtained by getline()) back `n' lines. */ +/* Conceptually rewind the input (as obtained by get_line()) back `n' lines. */ static void toomuch(FILE *ofp, long n) { char buf[BUFSIZ]; size_t i, nread; if (overfile != NULL) { /* * Truncate the previous file we overflowed into back to * the correct length, close it. */ if (fflush(overfile) != 0) err(1, "overflow"); if (ftruncate(fileno(overfile), truncofs) != 0) err(1, "overflow"); if (fclose(overfile) != 0) err(1, "overflow"); overfile = NULL; } if (n == 0) /* Just tidying up */ return; lineno -= n; /* * Wind the overflow file backwards to `n' lines before the * current one. */ do { if (ftello(ofp) < (off_t)sizeof(buf)) rewind(ofp); else fseeko(ofp, -(off_t)sizeof(buf), SEEK_CUR); if (ferror(ofp)) errx(1, "%s: can't seek", currfile); if ((nread = fread(buf, 1, sizeof(buf), ofp)) == 0) errx(1, "can't read overflowed output"); if (fseeko(ofp, -(off_t)nread, SEEK_CUR) != 0) err(1, "%s", currfile); for (i = 1; i <= nread; i++) if (buf[nread - i] == '\n' && n-- == 0) break; if (ftello(ofp) == 0) break; } while (n > 0); if (fseeko(ofp, nread - i + 1, SEEK_CUR) != 0) err(1, "%s", currfile); /* - * getline() will read from here. Next call will truncate to + * get_line() will read from here. Next call will truncate to * truncofs in this file. */ overfile = ofp; truncofs = ftello(overfile); } /* Handle splits for /regexp/ and %regexp% patterns. */ static void do_rexp(const char *expr) { regex_t cre; intmax_t nwritten; long ofs; int first; char *ecopy, *ep, *p, *pofs, *re; FILE *ofp; if ((ecopy = strdup(expr)) == NULL) err(1, "strdup"); re = ecopy + 1; if ((pofs = strrchr(ecopy, *expr)) == NULL || pofs[-1] == '\\') errx(1, "%s: missing trailing %c", expr, *expr); *pofs++ = '\0'; if (*pofs != '\0') { errno = 0; ofs = strtol(pofs, &ep, 10); if (*ep != '\0' || errno != 0) errx(1, "%s: bad offset", pofs); } else ofs = 0; if (regcomp(&cre, re, REG_BASIC|REG_NOSUB) != 0) errx(1, "%s: bad regular expression", re); if (*expr == '/') /* /regexp/: Save results to a file. */ ofp = newfile(); else { /* %regexp%: Make a temporary file for overflow. */ if ((ofp = tmpfile()) == NULL) err(1, "tmpfile"); } /* Read and output lines until we get a match. */ first = 1; - while ((p = getline()) != NULL) { + while ((p = get_line()) != NULL) { if (fputs(p, ofp) != 0) break; if (!first && regexec(&cre, p, 0, NULL, 0) == 0) break; first = 0; } if (p == NULL) errx(1, "%s: no match", re); if (ofs <= 0) { /* * Negative (or zero) offset: throw back any lines we should * not have read yet. */ if (p != NULL) { toomuch(ofp, -ofs + 1); nwritten = (intmax_t)truncofs; } else nwritten = (intmax_t)ftello(ofp); } else { /* * Positive offset: copy the requested number of lines * after the match. */ - while (--ofs > 0 && (p = getline()) != NULL) + while (--ofs > 0 && (p = get_line()) != NULL) fputs(p, ofp); toomuch(NULL, 0); nwritten = (intmax_t)ftello(ofp); if (fclose(ofp) != 0) err(1, "%s", currfile); } if (!sflag && *expr == '/') printf("%jd\n", nwritten); regfree(&cre); free(ecopy); } /* Handle splits based on line number. */ static void do_lineno(const char *expr) { long lastline, tgtline; char *ep, *p; FILE *ofp; errno = 0; tgtline = strtol(expr, &ep, 10); if (tgtline <= 0 || errno != 0 || *ep != '\0') errx(1, "%s: bad line number", expr); lastline = tgtline; if (lastline <= lineno) errx(1, "%s: can't go backwards", expr); while (nfiles < maxfiles - 1) { ofp = newfile(); while (lineno + 1 != lastline) { - if ((p = getline()) == NULL) + if ((p = get_line()) == NULL) errx(1, "%ld: out of range", lastline); if (fputs(p, ofp) != 0) break; } if (!sflag) printf("%jd\n", (intmax_t)ftello(ofp)); if (fclose(ofp) != 0) err(1, "%s", currfile); if (reps-- == 0) break; lastline += tgtline; } } Index: head/usr.bin/ctags/C.c =================================================================== --- head/usr.bin/ctags/C.c (revision 299354) +++ head/usr.bin/ctags/C.c (revision 299355) @@ -1,532 +1,532 @@ /* * Copyright (c) 1987, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)C.c 8.4 (Berkeley) 4/2/94"; #endif #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include "ctags.h" static int func_entry(void); static void hash_entry(void); static void skip_string(int); static int str_entry(int); /* * c_entries -- * read .c and .h files and call appropriate routines */ void c_entries(void) { int c; /* current character */ int level; /* brace level */ int token; /* if reading a token */ int t_def; /* if reading a typedef */ int t_level; /* typedef's brace level */ char *sp; /* buffer pointer */ char tok[MAXTOKEN]; /* token buffer */ lineftell = ftell(inf); sp = tok; token = t_def = NO; t_level = -1; level = 0; lineno = 1; while (GETC(!=, EOF)) { switch (c) { /* * Here's where it DOESN'T handle: { * foo(a) * { * #ifdef notdef * } * #endif * if (a) * puts("hello, world"); * } */ case '{': ++level; goto endtok; case '}': /* * if level goes below zero, try and fix * it, even though we've already messed up */ if (--level < 0) level = 0; goto endtok; case '\n': SETLINE; /* * the above 3 cases are similar in that they * are special characters that also end tokens. */ endtok: if (sp > tok) { *sp = EOS; token = YES; sp = tok; } else token = NO; continue; /* * We ignore quoted strings and character constants * completely. */ case '"': case '\'': skip_string(c); break; /* * comments can be fun; note the state is unchanged after * return, in case we found: * "foo() XX comment XX { int bar; }" */ case '/': if (GETC(==, '*') || c == '/') { skip_comment(c); continue; } (void)ungetc(c, inf); c = '/'; goto storec; /* hash marks flag #define's. */ case '#': if (sp == tok) { hash_entry(); break; } goto storec; /* * if we have a current token, parenthesis on * level zero indicates a function. */ case '(': if (!level && token) { int curline; if (sp != tok) *sp = EOS; /* * grab the line immediately, we may * already be wrong, for example, * foo\n * (arg1, */ - getline(); + get_line(); curline = lineno; if (func_entry()) { ++level; pfnote(tok, curline); } break; } goto storec; /* * semi-colons indicate the end of a typedef; if we find a * typedef we search for the next semi-colon of the same * level as the typedef. Ignoring "structs", they are * tricky, since you can find: * * "typedef long time_t;" * "typedef unsigned int u_int;" * "typedef unsigned int u_int [10];" * * If looking at a typedef, we save a copy of the last token * found. Then, when we find the ';' we take the current * token if it starts with a valid token name, else we take * the one we saved. There's probably some reasonable * alternative to this... */ case ';': if (t_def && level == t_level) { t_def = NO; - getline(); + get_line(); if (sp != tok) *sp = EOS; pfnote(tok, lineno); break; } goto storec; /* * store characters until one that can't be part of a token * comes along; check the current token against certain * reserved words. */ default: /* ignore whitespace */ if (c == ' ' || c == '\t') { int save = c; while (GETC(!=, EOF) && (c == ' ' || c == '\t')) ; if (c == EOF) return; (void)ungetc(c, inf); c = save; } storec: if (!intoken(c)) { if (sp == tok) break; *sp = EOS; if (tflag) { /* no typedefs inside typedefs */ if (!t_def && !memcmp(tok, "typedef",8)) { t_def = YES; t_level = level; break; } /* catch "typedef struct" */ if ((!t_def || t_level < level) && (!memcmp(tok, "struct", 7) || !memcmp(tok, "union", 6) || !memcmp(tok, "enum", 5))) { /* * get line immediately; * may change before '{' */ - getline(); + get_line(); if (str_entry(c)) ++level; break; /* } */ } } sp = tok; } else if (sp != tok || begtoken(c)) { if (sp == tok + sizeof tok - 1) /* Too long -- truncate it */ *sp = EOS; else *sp++ = c; token = YES; } continue; } sp = tok; token = NO; } } /* * func_entry -- * handle a function reference */ static int func_entry(void) { int c; /* current character */ int level = 0; /* for matching '()' */ /* * Find the end of the assumed function declaration. * Note that ANSI C functions can have type definitions so keep * track of the parentheses nesting level. */ while (GETC(!=, EOF)) { switch (c) { case '\'': case '"': /* skip strings and character constants */ skip_string(c); break; case '/': /* skip comments */ if (GETC(==, '*') || c == '/') skip_comment(c); break; case '(': level++; break; case ')': if (level == 0) goto fnd; level--; break; case '\n': SETLINE; } } return (NO); fnd: /* * we assume that the character after a function's right paren * is a token character if it's a function and a non-token * character if it's a declaration. Comments don't count... */ for (;;) { while (GETC(!=, EOF) && iswhite(c)) if (c == '\n') SETLINE; if (intoken(c) || c == '{') break; if (c == '/' && (GETC(==, '*') || c == '/')) skip_comment(c); else { /* don't ever "read" '/' */ (void)ungetc(c, inf); return (NO); } } if (c != '{') (void)skip_key('{'); return (YES); } /* * hash_entry -- * handle a line starting with a '#' */ static void hash_entry(void) { int c; /* character read */ int curline; /* line started on */ char *sp; /* buffer pointer */ char tok[MAXTOKEN]; /* storage buffer */ /* ignore leading whitespace */ while (GETC(!=, EOF) && (c == ' ' || c == '\t')) ; (void)ungetc(c, inf); curline = lineno; for (sp = tok;;) { /* get next token */ if (GETC(==, EOF)) return; if (iswhite(c)) break; if (sp == tok + sizeof tok - 1) /* Too long -- truncate it */ *sp = EOS; else *sp++ = c; } *sp = EOS; if (memcmp(tok, "define", 6)) /* only interested in #define's */ goto skip; for (;;) { /* this doesn't handle "#define \n" */ if (GETC(==, EOF)) return; if (!iswhite(c)) break; } for (sp = tok;;) { /* get next token */ if (sp == tok + sizeof tok - 1) /* Too long -- truncate it */ *sp = EOS; else *sp++ = c; if (GETC(==, EOF)) return; /* * this is where it DOESN'T handle * "#define \n" */ if (!intoken(c)) break; } *sp = EOS; if (dflag || c == '(') { /* only want macros */ - getline(); + get_line(); pfnote(tok, curline); } skip: if (c == '\n') { /* get rid of rest of define */ SETLINE if (*(sp - 1) != '\\') return; } (void)skip_key('\n'); } /* * str_entry -- * handle a struct, union or enum entry */ static int str_entry(int c) /* c is current character */ { int curline; /* line started on */ char *sp; /* buffer pointer */ char tok[LINE_MAX]; /* storage buffer */ curline = lineno; while (iswhite(c)) if (GETC(==, EOF)) return (NO); if (c == '{') /* it was "struct {" */ return (YES); for (sp = tok;;) { /* get next token */ if (sp == tok + sizeof tok - 1) /* Too long -- truncate it */ *sp = EOS; else *sp++ = c; if (GETC(==, EOF)) return (NO); if (!intoken(c)) break; } switch (c) { case '{': /* it was "struct foo{" */ --sp; break; case '\n': /* it was "struct foo\n" */ SETLINE; /*FALLTHROUGH*/ default: /* probably "struct foo " */ while (GETC(!=, EOF)) if (!iswhite(c)) break; if (c != '{') { (void)ungetc(c, inf); return (NO); } } *sp = EOS; pfnote(tok, curline); return (YES); } /* * skip_comment -- * skip over comment */ void skip_comment(int t) /* t is comment character */ { int c; /* character read */ int star; /* '*' flag */ for (star = 0; GETC(!=, EOF);) switch(c) { /* comments don't nest, nor can they be escaped. */ case '*': star = YES; break; case '/': if (star && t == '*') return; break; case '\n': if (t == '/') return; SETLINE; /*FALLTHROUGH*/ default: star = NO; break; } } /* * skip_string -- * skip to the end of a string or character constant. */ void skip_string(int key) { int c, skip; for (skip = NO; GETC(!=, EOF); ) switch (c) { case '\\': /* a backslash escapes anything */ skip = !skip; /* we toggle in case it's "\\" */ break; case '\n': SETLINE; /*FALLTHROUGH*/ default: if (c == key && !skip) return; skip = NO; } } /* * skip_key -- * skip to next char "key" */ int skip_key(int key) { int c, skip, retval; for (skip = retval = NO; GETC(!=, EOF);) switch(c) { case '\\': /* a backslash escapes anything */ skip = !skip; /* we toggle in case it's "\\" */ break; case ';': /* special case for yacc; if one */ case '|': /* of these chars occurs, we may */ retval = YES; /* have moved out of the rule */ break; /* not used by C */ case '\'': case '"': /* skip strings and character constants */ skip_string(c); break; case '/': /* skip comments */ if (GETC(==, '*') || c == '/') { skip_comment(c); break; } (void)ungetc(c, inf); c = '/'; goto norm; case '\n': SETLINE; /*FALLTHROUGH*/ default: norm: if (c == key && !skip) return (retval); skip = NO; } return (retval); } Index: head/usr.bin/ctags/ctags.h =================================================================== --- head/usr.bin/ctags/ctags.h (revision 299354) +++ head/usr.bin/ctags/ctags.h (revision 299355) @@ -1,96 +1,96 @@ /* * Copyright (c) 1987, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)ctags.h 8.3 (Berkeley) 4/2/94 * * $FreeBSD$ * */ #define bool char #define YES 1 #define NO 0 #define EOS '\0' #define ENDLINE 50 /* max length of pattern */ #define MAXTOKEN 250 /* max size of single token */ #define SETLINE {++lineno;lineftell = ftell(inf);} #define GETC(op,exp) ((c = getc(inf)) op (int)exp) /* * These character classification macros assume that the (EOF & 0xff) element * of the arrays is always 'NO', as the EOF return from getc() gets masked * to that value. Masking with 0xff has no effect for normal characters * returned by getc() provided chars have 8 bits. */ #define iswhite(arg) _wht[arg & 0xff] /* T if char is white */ #define begtoken(arg) _btk[arg & 0xff] /* T if char can start token */ #define intoken(arg) _itk[arg & 0xff] /* T if char can be in token */ #define endtoken(arg) _etk[arg & 0xff] /* T if char ends tokens */ #define isgood(arg) _gd[arg & 0xff] /* T if char can be after ')' */ typedef struct nd_st { /* sorting structure */ struct nd_st *left, *right; /* left and right sons */ char *entry, /* function or type name */ *file, /* file name */ *pat; /* search pattern */ int lno; /* for -x option */ bool been_warned; /* set if noticed dup */ } NODE; extern char *curfile; /* current input file name */ extern NODE *head; /* head of the sorted binary tree */ extern FILE *inf; /* ioptr for current input file */ extern FILE *outf; /* ioptr for current output file */ extern long lineftell; /* ftell after getc( inf ) == '\n' */ extern int lineno; /* line number of current line */ extern int dflag; /* -d: non-macro defines */ extern int tflag; /* -t: create tags for typedefs */ extern int vflag; /* -v: vgrind style index output */ extern int wflag; /* -w: suppress warnings */ extern int xflag; /* -x: cxref style output */ extern bool _wht[], _etk[], _itk[], _btk[], _gd[]; extern char lbuf[LINE_MAX]; extern char *lbp; extern char searchar; /* ex search character */ extern int cicmp(const char *); -extern void getline(void); +extern void get_line(void); extern void pfnote(const char *, int); extern int skip_key(int); extern void put_entries(NODE *); extern void toss_yysec(void); extern void l_entries(void); extern void y_entries(void); extern int PF_funcs(void); extern void c_entries(void); extern void skip_comment(int); Index: head/usr.bin/ctags/fortran.c =================================================================== --- head/usr.bin/ctags/fortran.c (revision 299354) +++ head/usr.bin/ctags/fortran.c (revision 299355) @@ -1,168 +1,168 @@ /* * Copyright (c) 1987, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)fortran.c 8.3 (Berkeley) 4/2/94"; #endif #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include #include "ctags.h" static void takeprec(void); char *lbp; /* line buffer pointer */ int PF_funcs(void) { bool pfcnt; /* pascal/fortran functions found */ char *cp; char tok[MAXTOKEN]; for (pfcnt = NO;;) { lineftell = ftell(inf); if (!fgets(lbuf, sizeof(lbuf), inf)) return (pfcnt); ++lineno; lbp = lbuf; if (*lbp == '%') /* Ratfor escape to fortran */ ++lbp; for (; isspace(*lbp); ++lbp) continue; if (!*lbp) continue; switch (*lbp | ' ') { /* convert to lower-case */ case 'c': if (cicmp("complex") || cicmp("character")) takeprec(); break; case 'd': if (cicmp("double")) { for (; isspace(*lbp); ++lbp) continue; if (!*lbp) continue; if (cicmp("precision")) break; continue; } break; case 'i': if (cicmp("integer")) takeprec(); break; case 'l': if (cicmp("logical")) takeprec(); break; case 'r': if (cicmp("real")) takeprec(); break; } for (; isspace(*lbp); ++lbp) continue; if (!*lbp) continue; switch (*lbp | ' ') { case 'f': if (cicmp("function")) break; continue; case 'p': if (cicmp("program") || cicmp("procedure")) break; continue; case 's': if (cicmp("subroutine")) break; default: continue; } for (; isspace(*lbp); ++lbp) continue; if (!*lbp) continue; for (cp = lbp + 1; *cp && intoken(*cp); ++cp) continue; if (cp == lbp + 1) continue; *cp = EOS; (void)strlcpy(tok, lbp, sizeof(tok)); /* possible trunc */ - getline(); /* process line for ex(1) */ + get_line(); /* process line for ex(1) */ pfnote(tok, lineno); pfcnt = YES; } /*NOTREACHED*/ } /* * cicmp -- * do case-independent strcmp */ int cicmp(const char *cp) { int len; char *bp; for (len = 0, bp = lbp; *cp && (*cp &~ ' ') == (*bp++ &~ ' '); ++cp, ++len) continue; if (!*cp) { lbp += len; return (YES); } return (NO); } static void takeprec(void) { for (; isspace(*lbp); ++lbp) continue; if (*lbp == '*') { for (++lbp; isspace(*lbp); ++lbp) continue; if (!isdigit(*lbp)) --lbp; /* force failure */ else while (isdigit(*++lbp)) continue; } } Index: head/usr.bin/ctags/lisp.c =================================================================== --- head/usr.bin/ctags/lisp.c (revision 299354) +++ head/usr.bin/ctags/lisp.c (revision 299355) @@ -1,106 +1,106 @@ /* * Copyright (c) 1987, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)lisp.c 8.3 (Berkeley) 4/2/94"; #endif #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include #include "ctags.h" /* * lisp tag functions * just look for (def or (DEF */ void l_entries(void) { int special; char *cp; char savedc; char tok[MAXTOKEN]; for (;;) { lineftell = ftell(inf); if (!fgets(lbuf, sizeof(lbuf), inf)) return; ++lineno; lbp = lbuf; if (!cicmp("(def")) continue; special = NO; switch(*lbp | ' ') { case 'm': if (cicmp("method")) special = YES; break; case 'w': if (cicmp("wrapper") || cicmp("whopper")) special = YES; } for (; !isspace(*lbp); ++lbp) continue; for (; isspace(*lbp); ++lbp) continue; for (cp = lbp; *cp && *cp != '\n'; ++cp) continue; *cp = EOS; if (special) { if (!(cp = strchr(lbp, ')'))) continue; for (; cp >= lbp && *cp != ':'; --cp) continue; if (cp < lbp) continue; lbp = cp; for (; *cp && *cp != ')' && *cp != ' '; ++cp) continue; } else for (cp = lbp + 1; *cp && *cp != '(' && *cp != ' '; ++cp) continue; savedc = *cp; *cp = EOS; (void)strlcpy(tok, lbp, sizeof(tok)); /* possible trunc */ *cp = savedc; - getline(); + get_line(); pfnote(tok, lineno); } /*NOTREACHED*/ } Index: head/usr.bin/ctags/print.c =================================================================== --- head/usr.bin/ctags/print.c (revision 299354) +++ head/usr.bin/ctags/print.c (revision 299355) @@ -1,113 +1,113 @@ /* * Copyright (c) 1987, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)print.c 8.3 (Berkeley) 4/2/94"; #endif #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include "ctags.h" /* - * getline -- + * get_line -- * get the line the token of interest occurred on, * prepare it for printing. */ void -getline(void) +get_line(void) { long saveftell; int c; int cnt; char *cp; saveftell = ftell(inf); (void)fseek(inf, lineftell, L_SET); if (xflag) for (cp = lbuf; GETC(!=, EOF) && c != '\n'; *cp++ = c) continue; /* * do all processing here, so we don't step through the * line more than once; means you don't call this routine * unless you're sure you've got a keeper. */ else for (cnt = 0, cp = lbuf; GETC(!=, EOF) && cnt < ENDLINE; ++cnt) { if (c == '\\') { /* backslashes */ if (cnt > ENDLINE - 2) break; *cp++ = '\\'; *cp++ = '\\'; ++cnt; } else if (c == (int)searchar) { /* search character */ if (cnt > ENDLINE - 2) break; *cp++ = '\\'; *cp++ = c; ++cnt; } else if (c == '\n') { /* end of keep */ *cp++ = '$'; /* can find whole line */ break; } else *cp++ = c; } *cp = EOS; (void)fseek(inf, saveftell, L_SET); } /* * put_entries -- * write out the tags */ void put_entries(NODE *node) { if (node->left) put_entries(node->left); if (vflag) printf("%s %s %d\n", node->entry, node->file, (node->lno + 63) / 64); else if (xflag) printf("%-16s %4d %-16s %s\n", node->entry, node->lno, node->file, node->pat); else fprintf(outf, "%s\t%s\t%c^%s%c\n", node->entry, node->file, searchar, node->pat, searchar); if (node->right) put_entries(node->right); } Index: head/usr.bin/ctags/yacc.c =================================================================== --- head/usr.bin/ctags/yacc.c (revision 299354) +++ head/usr.bin/ctags/yacc.c (revision 299355) @@ -1,151 +1,151 @@ /* * Copyright (c) 1987, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)yacc.c 8.3 (Berkeley) 4/2/94"; #endif #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include "ctags.h" /* * y_entries: * find the yacc tags and put them in. */ void y_entries(void) { int c; char *sp; bool in_rule; char tok[MAXTOKEN]; in_rule = NO; while (GETC(!=, EOF)) switch (c) { case '\n': SETLINE; /* FALLTHROUGH */ case ' ': case '\f': case '\r': case '\t': break; case '{': if (skip_key('}')) in_rule = NO; break; case '\'': case '"': if (skip_key(c)) in_rule = NO; break; case '%': if (GETC(==, '%')) return; (void)ungetc(c, inf); break; case '/': if (GETC(==, '*') || c == '/') skip_comment(c); else (void)ungetc(c, inf); break; case '|': case ';': in_rule = NO; break; default: if (in_rule || (!isalpha(c) && c != '.' && c != '_')) break; sp = tok; *sp++ = c; while (GETC(!=, EOF) && (intoken(c) || c == '.')) *sp++ = c; *sp = EOS; - getline(); /* may change before ':' */ + get_line(); /* may change before ':' */ while (iswhite(c)) { if (c == '\n') SETLINE; if (GETC(==, EOF)) return; } if (c == ':') { pfnote(tok, lineno); in_rule = YES; } else (void)ungetc(c, inf); } } /* * toss_yysec -- * throw away lines up to the next "\n%%\n" */ void toss_yysec(void) { int c; /* read character */ int state; /* * state == 0 : waiting * state == 1 : received a newline * state == 2 : received first % * state == 3 : received second % */ lineftell = ftell(inf); for (state = 0; GETC(!=, EOF);) switch (c) { case '\n': ++lineno; lineftell = ftell(inf); if (state == 3) /* done! */ return; state = 1; /* start over */ break; case '%': if (state) /* if 1 or 2 */ ++state; /* goto 3 */ break; default: state = 0; /* reset */ break; } }