diff options
Diffstat (limited to 'contrib/texinfo/util')
-rw-r--r-- | contrib/texinfo/util/README | 2 | ||||
-rw-r--r-- | contrib/texinfo/util/install-info.c | 295 | ||||
-rw-r--r-- | contrib/texinfo/util/texindex.c | 241 |
3 files changed, 223 insertions, 315 deletions
diff --git a/contrib/texinfo/util/README b/contrib/texinfo/util/README index d3f8a7593d57..5354c3520b2c 100644 --- a/contrib/texinfo/util/README +++ b/contrib/texinfo/util/README @@ -1,4 +1,4 @@ -$Id: README,v 1.4 2002/12/29 17:47:20 karl Exp $ +$Id: README,v 1.5 2004/04/11 17:56:47 karl Exp $ texinfo/util/README Copyright (C) 2002 Free Software Foundation, Inc. diff --git a/contrib/texinfo/util/install-info.c b/contrib/texinfo/util/install-info.c index d346fb7c3a71..bbc7a8c25a50 100644 --- a/contrib/texinfo/util/install-info.c +++ b/contrib/texinfo/util/install-info.c @@ -1,7 +1,7 @@ /* install-info -- create Info directory entry(ies) for an Info file. - $Id: install-info.c,v 1.9 2003/05/19 13:10:59 karl Exp $ + $Id: install-info.c,v 1.12 2004/04/11 17:56:47 karl Exp $ - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -23,11 +23,14 @@ static char *progname = "install-info"; -struct line_data *findlines (); -void insert_entry_here (); -int compare_section_names (), compare_entries_text (); - struct spec_entry; +struct spec_section; + +struct line_data *findlines (char *data, int size, int *nlinesp); +void insert_entry_here (struct spec_entry *entry, int line_number, + struct line_data *dir_lines, int n_entries); +int compare_section_names (const void *s1, const void *s2); +int compare_entries_text (const void *e1, const void *e2); /* Data structures. */ @@ -137,8 +140,7 @@ struct option longopts[] = /* VARARGS1 */ void -error (s1, s2, s3) - char *s1, *s2, *s3; +error (const char *s1, const char *s2, const char *s3) { fprintf (stderr, "%s: ", progname); fprintf (stderr, s1, s2, s3); @@ -147,8 +149,7 @@ error (s1, s2, s3) /* VARARGS1 */ void -warning (s1, s2, s3) - char *s1, *s2, *s3; +warning (const char *s1, const char *s2, const char *s3) { fprintf (stderr, _("%s: warning: "), progname); fprintf (stderr, s1, s2, s3); @@ -158,8 +159,7 @@ warning (s1, s2, s3) /* Print error message and exit. */ void -fatal (s1, s2, s3) - char *s1, *s2, *s3; +fatal (const char *s1, const char *s2, const char *s3) { error (s1, s2, s3); xexit (1); @@ -168,8 +168,7 @@ fatal (s1, s2, s3) /* Return a newly-allocated string whose contents concatenate those of S1, S2, S3. */ char * -concat (s1, s2, s3) - char *s1, *s2, *s3; +concat (const char *s1, const char *s2, const char *s3) { int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); char *result = (char *) xmalloc (len1 + len2 + len3 + 1); @@ -186,9 +185,7 @@ concat (s1, s2, s3) copied from starting at STRING. */ char * -copy_string (string, size) - char *string; - int size; +copy_string (const char *string, int size) { int i; char *copy = (char *) xmalloc (size + 1); @@ -201,19 +198,71 @@ copy_string (string, size) /* Print fatal error message based on errno, with file name NAME. */ void -pfatal_with_name (name) - char *name; +pfatal_with_name (const char *name) { char *s = concat ("", strerror (errno), _(" for %s")); fatal (s, name, 0); } +/* Compare the menu item names in LINE1 (line length LEN1) + and LINE2 (line length LEN2). Return 1 if the item name + in LINE1 is less, 0 otherwise. */ + +static int +menu_line_lessp (char *line1, int len1, char *line2, int len2) +{ + int minlen = (len1 < len2 ? len1 : len2); + int i; + + for (i = 0; i < minlen; i++) + { + /* If one item name is a prefix of the other, + the former one is less. */ + if (line1[i] == ':' && line2[i] != ':') + return 1; + if (line2[i] == ':' && line1[i] != ':') + return 0; + /* If they both continue and differ, one is less. */ + if (line1[i] < line2[i]) + return 1; + if (line1[i] > line2[i]) + return 0; + } + /* With a properly formatted dir file, + we can only get here if the item names are equal. */ + return 0; +} + +/* Compare the menu item names in LINE1 (line length LEN1) + and LINE2 (line length LEN2). Return 1 if the item names are equal, + 0 otherwise. */ + +static int +menu_line_equal (char *line1, int len1, char *line2, int len2) +{ + int minlen = (len1 < len2 ? len1 : len2); + int i; + + for (i = 0; i < minlen; i++) + { + /* If both item names end here, they are equal. */ + if (line1[i] == ':' && line2[i] == ':') + return 1; + /* If they both continue and differ, one is less. */ + if (line1[i] != line2[i]) + return 0; + } + /* With a properly formatted dir file, + we can only get here if the item names are equal. */ + return 1; +} + + /* Given the full text of a menu entry, null terminated, return just the menu item name (copied). */ char * -extract_menu_item_name (item_text) - char *item_text; +extract_menu_item_name (char *item_text) { char *p; @@ -231,8 +280,7 @@ extract_menu_item_name (item_text) return just the menu item file (copied). */ char * -extract_menu_file_name (item_text) - char *item_text; +extract_menu_file_name (char *item_text) { char *p = item_text; @@ -275,8 +323,7 @@ extract_menu_file_name (item_text) /* Return FNAME with any [.info][.gz] suffix removed. */ static char * -strip_info_suffix (fname) - char *fname; +strip_info_suffix (char *fname) { char *ret = xstrdup (fname); unsigned len = strlen (ret); @@ -320,14 +367,32 @@ strip_info_suffix (fname) TERM_CHAR) and still match. */ static int -menu_item_equal (item, term_char, name) - char *item; - char term_char; - char *name; +menu_item_equal (const char *item, char term_char, const char *name) { + int ret; + const char *item_basename = item; unsigned name_len = strlen (name); + + /* We must compare the basename in ITEM, since we are passed the + basename of the original info file. Otherwise, a new entry like + "lilypond/lilypond" won't match "lilypond". + + Actually, it seems to me that we should really compare the whole + name, and not just the basename. Couldn't there be dir1/foo.info + and dir2/foo.info? Also, it seems like we should be using the + filename from the new dir entries, not the filename on the command + line. Not worrying about those things right now, though. --karl, + 26mar04. */ + while (*item_basename && !IS_SLASH (*item_basename) + && *item_basename != term_char) + item_basename++; + if (! *item_basename || *item_basename == term_char) + item_basename = item; /* no /, use original */ + else + item_basename++; /* have /, move past it */ + /* First, ITEM must actually match NAME (usually it won't). */ - int ret = strncasecmp (item, name, name_len) == 0; + ret = strncasecmp (item_basename, name, name_len) == 0; if (ret) { /* Then, `foobar' doesn't match `foo', so be sure we've got all of @@ -345,8 +410,8 @@ menu_item_equal (item, term_char, name) { char *suffix = suffixes[i]; unsigned suffix_len = strlen (suffix); - ret = strncasecmp (item + name_len, suffix, suffix_len) == 0 - && item[name_len + suffix_len] == term_char; + ret = strncasecmp (item_basename + name_len, suffix, suffix_len) == 0 + && item_basename[name_len + suffix_len] == term_char; } } @@ -356,7 +421,7 @@ menu_item_equal (item, term_char, name) void -suggest_asking_for_help () +suggest_asking_for_help (void) { fprintf (stderr, _("\tTry `%s --help' for a complete list of options.\n"), progname); @@ -364,7 +429,7 @@ suggest_asking_for_help () } void -print_help () +print_help (void) { printf (_("Usage: %s [OPTION]... [INFO-FILE [DIR-FILE]]\n\ \n\ @@ -409,8 +474,7 @@ Texinfo home page: http://www.gnu.org/software/texinfo/")); already exists, do nothing. */ void -ensure_dirfile_exists (dirfile) - char *dirfile; +ensure_dirfile_exists (char *dirfile) { int desc = open (dirfile, O_RDONLY); if (desc < 0 && errno == ENOENT) @@ -424,7 +488,7 @@ ensure_dirfile_exists (dirfile) fprintf (f, _("This is the file .../info/dir, which contains the\n\ topmost node of the Info hierarchy, called (dir)Top.\n\ The first time you invoke Info you start off looking at this node.\n\ -\n\ +\x1f\n\ %s\tThis is the top of the INFO tree\n\ \n\ This (the Directory node) gives a menu of major topics.\n\ @@ -466,13 +530,9 @@ The first time you invoke Info you start off looking at this node.\n\ magic number, not the filename. */ FILE * -open_possibly_compressed_file (filename, create_callback, - opened_filename, compression_program, is_pipe) - char *filename; - void (*create_callback) (); - char **opened_filename; - char **compression_program; - int *is_pipe; +open_possibly_compressed_file (char *filename, + void (*create_callback) (char *), + char **opened_filename, char **compression_program, int *is_pipe) { char *local_opened_filename, *local_compression_program; int nread; @@ -602,13 +662,9 @@ open_possibly_compressed_file (filename, create_callback, a fatal error. */ char * -readfile (filename, sizep, create_callback, - opened_filename, compression_program) - char *filename; - int *sizep; - void (*create_callback) (); - char **opened_filename; - char **compression_program; +readfile (char *filename, int *sizep, + void (*create_callback) (char *), char **opened_filename, + char **compression_program) { char *real_name; FILE *f; @@ -659,16 +715,9 @@ readfile (filename, sizep, create_callback, we'll write dir.gz on output. */ static void -output_dirfile (dirfile, dir_nlines, dir_lines, - n_entries_to_add, entries_to_add, input_sections, - compression_program) - char *dirfile; - int dir_nlines; - struct line_data *dir_lines; - int n_entries_to_add; - struct spec_entry *entries_to_add; - struct spec_section *input_sections; - char *compression_program; +output_dirfile (char *dirfile, int dir_nlines, struct line_data *dir_lines, + int n_entries_to_add, struct spec_entry *entries_to_add, + struct spec_section *input_sections, char *compression_program) { int i; FILE *output; @@ -797,11 +846,8 @@ output_dirfile (dirfile, dir_nlines, dir_lines, /* Parse the input to find the section names and the entry names it specifies. Return the number of entries to add from this file. */ int -parse_input (lines, nlines, sections, entries) - const struct line_data *lines; - int nlines; - struct spec_section **sections; - struct spec_entry **entries; +parse_input (const struct line_data *lines, int nlines, + struct spec_section **sections, struct spec_entry **entries) { int n_entries = 0; int prefix_length = strlen ("INFO-DIR-SECTION "); @@ -927,11 +973,8 @@ parse_input (lines, nlines, sections, entries) /* Parse the dir file whose basename is BASE_NAME. Find all the nodes, and their menus, and the sections of their menus. */ int -parse_dir_file (lines, nlines, nodes, base_name) - struct line_data *lines; - int nlines; - struct node **nodes; - const char *base_name; +parse_dir_file (struct line_data *lines, int nlines, struct node **nodes, + const char *base_name) { int node_header_flag = 0; int something_deleted = 0; @@ -1081,15 +1124,12 @@ parse_dir_file (lines, nlines, nodes, base_name) } int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { char *opened_dirfilename; char *compression_program; char *infile_sans_info; char *infile = 0, *dirfile = 0; - unsigned infilelen_sans_info; /* Record the text of the Info file, as a sequence of characters and as a sequence of lines. */ @@ -1148,8 +1188,8 @@ main (argc, argv) case 'd': if (dirfile) { - fprintf (stderr, _("%s: Specify the Info directory only once.\n"), - progname); + fprintf (stderr, _("%s: already have dir file: %s\n"), + progname, dirfile); suggest_asking_for_help (); } dirfile = optarg; @@ -1158,8 +1198,8 @@ main (argc, argv) case 'D': if (dirfile) { - fprintf (stderr, _("%s: Specify the Info directory only once.\n"), - progname); + fprintf (stderr, _("%s: already have dir file: %s\n"), + progname, dirfile); suggest_asking_for_help (); } dirfile = concat (optarg, "", "/dir"); @@ -1222,11 +1262,10 @@ main (argc, argv) case 'V': printf ("install-info (GNU %s) %s\n", PACKAGE, VERSION); puts (""); - printf (_("Copyright (C) %s Free Software Foundation, Inc.\n\ -There is NO warranty. You may redistribute this software\n\ + puts ("Copyright (C) 2004 Free Software Foundation, Inc."); + printf (_("There is NO warranty. You may redistribute this software\n\ under the terms of the GNU General Public License.\n\ -For more information about these matters, see the files named COPYING.\n"), - "2003"); +For more information about these matters, see the files named COPYING.\n")); xexit (0); default: @@ -1320,7 +1359,6 @@ For more information about these matters, see the files named COPYING.\n"), infile_basename--; infile_sans_info = strip_info_suffix (infile_basename); - infilelen_sans_info = strlen (infile_sans_info); } something_deleted @@ -1330,7 +1368,6 @@ For more information about these matters, see the files named COPYING.\n"), Find the menu sections to add them in. In each section, find the proper alphabetical place to add each of the entries. */ - if (!delete_flag) { struct node *node; @@ -1423,10 +1460,7 @@ For more information about these matters, see the files named COPYING.\n"), Store the length of that vector into *NLINESP. */ struct line_data * -findlines (data, size, nlinesp) - char *data; - int size; - int *nlinesp; +findlines (char *data, int size, int *nlinesp) { int i; int lineflag = 1; @@ -1471,75 +1505,16 @@ findlines (data, size, nlinesp) return lines; } -/* Compare the menu item names in LINE1 (line length LEN1) - and LINE2 (line length LEN2). Return 1 if the item name - in LINE1 is less, 0 otherwise. */ - -int -menu_line_lessp (line1, len1, line2, len2) - char *line1; - int len1; - char *line2; - int len2; -{ - int minlen = (len1 < len2 ? len1 : len2); - int i; - - for (i = 0; i < minlen; i++) - { - /* If one item name is a prefix of the other, - the former one is less. */ - if (line1[i] == ':' && line2[i] != ':') - return 1; - if (line2[i] == ':' && line1[i] != ':') - return 0; - /* If they both continue and differ, one is less. */ - if (line1[i] < line2[i]) - return 1; - if (line1[i] > line2[i]) - return 0; - } - /* With a properly formatted dir file, - we can only get here if the item names are equal. */ - return 0; -} - -/* Compare the menu item names in LINE1 (line length LEN1) - and LINE2 (line length LEN2). Return 1 if the item names are equal, - 0 otherwise. */ - -int -menu_line_equal (line1, len1, line2, len2) - char *line1; - int len1; - char *line2; - int len2; -{ - int minlen = (len1 < len2 ? len1 : len2); - int i; - - for (i = 0; i < minlen; i++) - { - /* If both item names end here, they are equal. */ - if (line1[i] == ':' && line2[i] == ':') - return 1; - /* If they both continue and differ, one is less. */ - if (line1[i] != line2[i]) - return 0; - } - /* With a properly formatted dir file, - we can only get here if the item names are equal. */ - return 1; -} - -/* This is the comparison function for qsort - for a vector of pointers to struct spec_section. +/* This is the comparison function for qsort for a vector of pointers to + struct spec_section. (Have to use const void * as the parameter type + to avoid incompatible-with-qsort warnings.) Compare the section names. */ int -compare_section_names (sec1, sec2) - struct spec_section **sec1, **sec2; +compare_section_names (const void *p1, const void *p2) { + struct spec_section **sec1 = (struct spec_section **) p1; + struct spec_section **sec2 = (struct spec_section **) p2; char *name1 = (*sec1)->name; char *name2 = (*sec2)->name; return strcmp (name1, name2); @@ -1550,9 +1525,10 @@ compare_section_names (sec1, sec2) Compare the entries' text. */ int -compare_entries_text (entry1, entry2) - struct spec_entry **entry1, **entry2; +compare_entries_text (const void *p1, const void *p2) { + struct spec_entry **entry1 = (struct spec_entry **) p1; + struct spec_entry **entry2 = (struct spec_entry **) p2; char *text1 = (*entry1)->text; char *text2 = (*entry2)->text; char *colon1 = strchr (text1, ':'); @@ -1576,11 +1552,8 @@ compare_entries_text (entry1, entry2) in main. */ void -insert_entry_here (entry, line_number, dir_lines, n_entries) - struct spec_entry *entry; - int line_number; - struct line_data *dir_lines; - int n_entries; +insert_entry_here (struct spec_entry *entry, int line_number, + struct line_data *dir_lines, int n_entries) { int i, j; diff --git a/contrib/texinfo/util/texindex.c b/contrib/texinfo/util/texindex.c index f63fdb5ecf27..569f877be0d9 100644 --- a/contrib/texinfo/util/texindex.c +++ b/contrib/texinfo/util/texindex.c @@ -1,8 +1,8 @@ /* texindex -- sort TeX index dribble output into an actual index. - $Id: texindex.c,v 1.9 2003/05/19 13:10:59 karl Exp $ + $Id: texindex.c,v 1.11 2004/04/11 17:56:47 karl Exp $ Copyright (C) 1987, 1991, 1992, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003 Free Software Foundation, Inc. + 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ static char *program_name = "texindex"; #define memset(ptr, ignore, count) bzero (ptr, count) #endif -char *mktemp (); +char *mktemp (char *); #if !defined (SEEK_SET) # define SEEK_SET 0 @@ -45,6 +45,8 @@ char *mktemp (); # define SEEK_END 2 #endif /* !SEEK_SET */ +struct linebuffer; + /* When sorting in core, this structure describes one line and the position and length of its first keyfield. */ struct lineinfo @@ -121,34 +123,34 @@ char first_initial; int keep_tempfiles; /* Forward declarations of functions in this file. */ -void decode_command (); -void sort_in_core (); -void sort_offline (); -char **parsefile (); -char *find_field (); -char *find_pos (); -long find_value (); -char *find_braced_pos (); -char *find_braced_end (); -void writelines (); -int compare_field (); -int compare_full (); -long readline (); -int merge_files (); -int merge_direct (); -void pfatal_with_name (); -void fatal (); -void error (); +void decode_command (int argc, char **argv); +void sort_in_core (char *infile, int total, char *outfile); +void sort_offline (char *infile, off_t total, char *outfile); +char **parsefile (char *filename, char **nextline, char *data, long int size); +char *find_field (struct keyfield *keyfield, char *str, long int *lengthptr); +char *find_pos (char *str, int words, int chars, int ignore_blanks); +long find_value (char *start, long int length); +char *find_braced_pos (char *str, int words, int chars, int ignore_blanks); +char *find_braced_end (char *str); +void writelines (char **linearray, int nlines, FILE *ostream); +int compare_field (struct keyfield *keyfield, char *start1, + long int length1, long int pos1, char *start2, + long int length2, long int pos2); +int compare_full (const void *, const void *); +long readline (struct linebuffer *linebuffer, FILE *stream); +int merge_files (char **infiles, int nfiles, char *outfile); +int merge_direct (char **infiles, int nfiles, char *outfile); +void pfatal_with_name (const char *name); +void fatal (const char *format, const char *arg); +void error (const char *format, const char *arg); void *xmalloc (), *xrealloc (); -char *concat (); -void flush_tempfiles (); +char *concat (char *s1, char *s2); +void flush_tempfiles (int to_count); #define MAX_IN_CORE_SORT 500000 int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { int i; @@ -260,8 +262,7 @@ TEXINDEX_OPTION texindex_options[] = { }; void -usage (result_value) - int result_value; +usage (int result_value) { register int i; FILE *f = result_value ? stderr : stdout; @@ -301,9 +302,7 @@ Texinfo home page: http://www.gnu.org/software/texinfo/"), f); and set up the vector of keyfields and the vector of input files. */ void -decode_command (argc, argv) - int argc; - char **argv; +decode_command (int argc, char **argv) { int arg_index = 1; char **ip; @@ -340,11 +339,10 @@ decode_command (argc, argv) { printf ("texindex (GNU %s) %s\n", PACKAGE, VERSION); puts (""); - printf (_("Copyright (C) %s Free Software Foundation, Inc.\n\ -There is NO warranty. You may redistribute this software\n\ + puts ("Copyright (C) 2004 Free Software Foundation, Inc."); + printf (_("There is NO warranty. You may redistribute this software\n\ under the terms of the GNU General Public License.\n\ -For more information about these matters, see the files named COPYING.\n"), - "2003"); +For more information about these matters, see the files named COPYING.\n")); xexit (0); } else if ((strcmp (arg, "--keep") == 0) || @@ -389,8 +387,7 @@ For more information about these matters, see the files named COPYING.\n"), /* Return a name for temporary file COUNT. */ static char * -maketempname (count) - int count; +maketempname (int count) { static char *tempbase = NULL; char tempsuffix[10]; @@ -413,8 +410,7 @@ maketempname (count) /* Delete all temporary files up to TO_COUNT. */ void -flush_tempfiles (to_count) - int to_count; +flush_tempfiles (int to_count) { if (keep_tempfiles) return; @@ -426,9 +422,10 @@ flush_tempfiles (to_count) /* Compare LINE1 and LINE2 according to the specified set of keyfields. */ int -compare_full (line1, line2) - char **line1, **line2; +compare_full (const void *p1, const void *p2) { + char **line1 = (char **) p1; + char **line2 = (char **) p2; int i; /* Compare using the first keyfield; @@ -440,7 +437,8 @@ compare_full (line1, line2) long length1, length2; char *start1 = find_field (&keyfields[i], *line1, &length1); char *start2 = find_field (&keyfields[i], *line2, &length2); - int tem = compare_field (&keyfields[i], start1, length1, *line1 - text_base, + int tem = compare_field (&keyfields[i], start1, length1, + *line1 - text_base, start2, length2, *line2 - text_base); if (tem) { @@ -457,11 +455,11 @@ compare_full (line1, line2) in which the first keyfield is identified in advance. For positional sorting, assumes that the order of the lines in core reflects their nominal order. */ - int -compare_prepared (line1, line2) - struct lineinfo *line1, *line2; +compare_prepared (const void *p1, const void *p2) { + struct lineinfo *line1 = (struct lineinfo *) p1; + struct lineinfo *line2 = (struct lineinfo *) p2; int i; int tem; char *text1, *text2; @@ -498,7 +496,8 @@ compare_prepared (line1, line2) long length1, length2; char *start1 = find_field (&keyfields[i], text1, &length1); char *start2 = find_field (&keyfields[i], text2, &length2); - int tem = compare_field (&keyfields[i], start1, length1, text1 - text_base, + int tem = compare_field (&keyfields[i], start1, length1, + text1 - text_base, start2, length2, text2 - text_base); if (tem) { @@ -517,10 +516,7 @@ compare_prepared (line1, line2) the two lines in the input. */ int -compare_general (str1, str2, pos1, pos2, use_keyfields) - char *str1, *str2; - long pos1, pos2; - int use_keyfields; +compare_general (char *str1, char *str2, long int pos1, long int pos2, int use_keyfields) { int i; @@ -551,10 +547,7 @@ compare_general (str1, str2, pos1, pos2, use_keyfields) is stored into the int that LENGTHPTR points to. */ char * -find_field (keyfield, str, lengthptr) - struct keyfield *keyfield; - char *str; - long *lengthptr; +find_field (struct keyfield *keyfield, char *str, long int *lengthptr) { char *start; char *end; @@ -594,10 +587,7 @@ find_field (keyfield, str, lengthptr) after finding the specified word. */ char * -find_pos (str, words, chars, ignore_blanks) - char *str; - int words, chars; - int ignore_blanks; +find_pos (char *str, int words, int chars, int ignore_blanks) { int i; char *p = str; @@ -630,10 +620,7 @@ find_pos (str, words, chars, ignore_blanks) and that braces within fields are balanced. */ char * -find_braced_pos (str, words, chars, ignore_blanks) - char *str; - int words, chars; - int ignore_blanks; +find_braced_pos (char *str, int words, int chars, int ignore_blanks) { int i; int bracelevel; @@ -682,8 +669,7 @@ find_braced_pos (str, words, chars, ignore_blanks) The position returned is just before the closing brace. */ char * -find_braced_end (str) - char *str; +find_braced_end (char *str) { int bracelevel; char *p = str; @@ -704,9 +690,7 @@ find_braced_end (str) } long -find_value (start, length) - char *start; - long length; +find_value (char *start, long int length) { while (length != 0L) { @@ -724,7 +708,7 @@ find_value (start, length) int char_order[256]; void -init_char_order () +init_char_order (void) { int i; for (i = 1; i < 256; i++) @@ -745,14 +729,8 @@ init_char_order () The sign of the value reports the relation between the fields. */ int -compare_field (keyfield, start1, length1, pos1, start2, length2, pos2) - struct keyfield *keyfield; - char *start1; - long length1; - long pos1; - char *start2; - long length2; - long pos2; +compare_field (struct keyfield *keyfield, char *start1, long int length1, + long int pos1, char *start2, long int length2, long int pos2) { if (keyfields->positional) { @@ -836,8 +814,7 @@ struct linebuffer /* Initialize LINEBUFFER for use. */ void -initbuffer (linebuffer) - struct linebuffer *linebuffer; +initbuffer (struct linebuffer *linebuffer) { linebuffer->size = 200; linebuffer->buffer = (char *) xmalloc (200); @@ -847,9 +824,7 @@ initbuffer (linebuffer) Return the length of the line. */ long -readline (linebuffer, stream) - struct linebuffer *linebuffer; - FILE *stream; +readline (struct linebuffer *linebuffer, FILE *stream) { char *buffer = linebuffer->buffer; char *p = linebuffer->buffer; @@ -879,10 +854,7 @@ readline (linebuffer, stream) /* Sort an input file too big to sort in core. */ void -sort_offline (infile, total, outfile) - char *infile; - off_t total; - char *outfile; +sort_offline (char *infile, off_t total, char *outfile) { /* More than enough. */ int ntemps = 2 * (total + MAX_IN_CORE_SORT - 1) / MAX_IN_CORE_SORT; @@ -978,10 +950,7 @@ fail: then indexify it and send the output to OUTFILE (or to stdout). */ void -sort_in_core (infile, total, outfile) - char *infile; - int total; - char *outfile; +sort_in_core (char *infile, int total, char *outfile) { char **nextline; char *data = (char *) xmalloc (total + 1); @@ -1049,7 +1018,7 @@ sort_in_core (infile, total, outfile) Make a `struct lineinfo' for each line, which records the keyfield as well as the line, and sort them. */ - lineinfo = (struct lineinfo *) malloc ((nextline - linearray) * sizeof (struct lineinfo)); + lineinfo = malloc ((nextline - linearray) * sizeof (struct lineinfo)); if (lineinfo) { @@ -1099,11 +1068,7 @@ sort_in_core (infile, total, outfile) Value 0 means input file contents are invalid. */ char ** -parsefile (filename, nextline, data, size) - char *filename; - char **nextline; - char *data; - long size; +parsefile (char *filename, char **nextline, char *data, long int size) { char *p, *end; char **line = nextline; @@ -1144,7 +1109,7 @@ parsefile (filename, nextline, data, size) if (line == linearray + nlines) { char **old = linearray; - linearray = (char **) xrealloc (linearray, sizeof (char *) * (nlines *= 4)); + linearray = xrealloc (linearray, sizeof (char *) * (nlines *= 4)); line += linearray - old; } } @@ -1200,7 +1165,7 @@ char lastinitial1[2]; /* Initialize static storage for writing an index. */ void -init_index () +init_index (void) { pending = 0; lastinitial = lastinitial1; @@ -1219,9 +1184,7 @@ init_index () insert headers for each initial character, etc. */ void -indexify (line, ostream) - char *line; - FILE *ostream; +indexify (char *line, FILE *ostream) { char *primary, *secondary, *pagenumber; int primarylength, secondarylength = 0, pagelength; @@ -1321,7 +1284,8 @@ indexify (line, ostream) lastsecondary[0] = 0; } - /* Should not have an entry with no subtopic following one with a subtopic. */ + /* Should not have an entry with no subtopic following one with a + subtopic. */ if (nosecondary && *lastsecondary) error (_("entry %s follows an entry with a secondary name"), line); @@ -1354,15 +1318,14 @@ indexify (line, ostream) /* Here to add one more page number to the current entry. */ if (pending++ != 1) - fputs (", ", ostream); /* Punctuate first, if this is not the first. */ + fputs (", ", ostream); /* Punctuate first, if this is not the first. */ fwrite (pagenumber, pagelength, 1, ostream); } /* Close out any unfinished output entry. */ void -finish_index (ostream) - FILE *ostream; +finish_index (FILE *ostream) { if (pending) fputs ("}\n", ostream); @@ -1374,10 +1337,7 @@ finish_index (ostream) Each line is copied out of the input file it was found in. */ void -writelines (linearray, nlines, ostream) - char **linearray; - int nlines; - FILE *ostream; +writelines (char **linearray, int nlines, FILE *ostream) { char **stop_line = linearray + nlines; char **next_line; @@ -1388,11 +1348,13 @@ writelines (linearray, nlines, ostream) for (next_line = linearray; next_line != stop_line; next_line++) { - /* If -u was specified, output the line only if distinct from previous one. */ + /* If -u was specified, output the line only if distinct from + previous one. */ if (next_line == linearray /* Compare previous line with this one, using only the explicitly specd keyfields. */ - || compare_general (*(next_line - 1), *next_line, 0L, 0L, num_keyfields - 1)) + || compare_general (*(next_line - 1), *next_line, 0L, 0L, + num_keyfields - 1)) { char *p = *next_line; char c; @@ -1417,10 +1379,7 @@ writelines (linearray, nlines, ostream) #define MAX_DIRECT_MERGE 10 int -merge_files (infiles, nfiles, outfile) - char **infiles; - int nfiles; - char *outfile; +merge_files (char **infiles, int nfiles, char *outfile) { char **tempfiles; int ntemps; @@ -1468,10 +1427,7 @@ merge_files (infiles, nfiles, outfile) use it only with a bounded number of input files. */ int -merge_direct (infiles, nfiles, outfile) - char **infiles; - int nfiles; - char *outfile; +merge_direct (char **infiles, int nfiles, char *outfile) { struct linebuffer *lb1, *lb2; struct linebuffer **thisline, **prevline; @@ -1499,20 +1455,20 @@ merge_direct (infiles, nfiles, outfile) return 0; } - /* For each file, make two line buffers. - Also, for each file, there is an element of `thisline' - which points at any time to one of the file's two buffers, - and an element of `prevline' which points to the other buffer. - `thisline' is supposed to point to the next available line from the file, - while `prevline' holds the last file line used, - which is remembered so that we can verify that the file is properly sorted. */ + /* For each file, make two line buffers. Also, for each file, there + is an element of `thisline' which points at any time to one of the + file's two buffers, and an element of `prevline' which points to + the other buffer. `thisline' is supposed to point to the next + available line from the file, while `prevline' holds the last file + line used, which is remembered so that we can verify that the file + is properly sorted. */ /* lb1 and lb2 contain one buffer each per file. */ lb1 = (struct linebuffer *) xmalloc (nfiles * sizeof (struct linebuffer)); lb2 = (struct linebuffer *) xmalloc (nfiles * sizeof (struct linebuffer)); - /* thisline[i] points to the linebuffer holding the next available line in file i, - or is zero if there are no lines left in that file. */ + /* thisline[i] points to the linebuffer holding the next available + line in file i, or is zero if there are no lines left in that file. */ thisline = (struct linebuffer **) xmalloc (nfiles * sizeof (struct linebuffer *)); /* prevline[i] points to the linebuffer holding the last used line @@ -1625,8 +1581,7 @@ merge_direct (infiles, nfiles, outfile) /* Print error message and exit. */ void -fatal (format, arg) - char *format, *arg; +fatal (const char *format, const char *arg) { error (format, arg); xexit (1); @@ -1634,8 +1589,7 @@ fatal (format, arg) /* Print error message. FORMAT is printf control string, ARG is arg for it. */ void -error (format, arg) - char *format, *arg; +error (const char *format, const char *arg) { printf ("%s: ", program_name); printf (format, arg); @@ -1644,16 +1598,14 @@ error (format, arg) } void -perror_with_name (name) - char *name; +perror_with_name (const char *name) { fprintf (stderr, "%s: ", program_name); perror (name); } void -pfatal_with_name (name) - char *name; +pfatal_with_name (const char *name) { perror_with_name (name); xexit (1); @@ -1663,8 +1615,7 @@ pfatal_with_name (name) /* Return a newly-allocated string concatenating S1 and S2. */ char * -concat (s1, s2) - char *s1, *s2; +concat (char *s1, char *s2) { int len1 = strlen (s1), len2 = strlen (s2); char *result = (char *) xmalloc (len1 + len2 + 1); @@ -1675,19 +1626,3 @@ concat (s1, s2) return result; } - -#if !defined (HAVE_STRCHR) -char * -strrchr (string, character) - char *string; - int character; -{ - register int i; - - for (i = strlen (string) - 1; i > -1; i--) - if (string[i] == character) - return (string + i); - - return ((char *)NULL); -} -#endif /* HAVE_STRCHR */ |