Initial German translation of the build tutorial
[anjuta.git] / plugins / symbol-db / readtags.c
blobf1b0d95e92a941bd81966663cc893cf5abe759ce
1 /*
2 * $Id: readtags.c 592 2007-07-31 03:30:41Z dhiebert $
4 * Copyright (c) 1996-2003, Darren Hiebert
6 * This source code is released into the public domain.
8 * This module contains functions for reading tag files.
9 */
12 * INCLUDE FILES
14 #include <stdlib.h>
15 #include <string.h>
16 #include <ctype.h>
17 #include <stdio.h>
18 #include <errno.h>
19 #include <sys/types.h> /* to declare off_t */
21 #include "readtags.h"
24 * MACROS
26 #define TAB '\t'
30 * DATA DECLARATIONS
32 typedef struct {
33 size_t size;
34 char *buffer;
35 } vstring;
37 /* Information about current tag file */
38 struct sTagFile {
39 /* has the file been opened and this structure initialized? */
40 short initialized;
41 /* format of tag file */
42 short format;
43 /* how is the tag file sorted? */
44 sortType sortMethod;
45 /* pointer to file structure */
46 FILE* fp;
47 /* file position of first character of `line' */
48 off_t pos;
49 /* size of tag file in seekable positions */
50 off_t size;
51 /* last line read */
52 vstring line;
53 /* name of tag in last line read */
54 vstring name;
55 /* defines tag search state */
56 struct {
57 /* file position of last match for tag */
58 off_t pos;
59 /* name of tag last searched for */
60 char *name;
61 /* length of name for partial matches */
62 size_t nameLength;
63 /* peforming partial match */
64 short partial;
65 /* ignoring case */
66 short ignorecase;
67 } search;
68 /* miscellaneous extension fields */
69 struct {
70 /* number of entries in `list' */
71 unsigned short max;
72 /* list of key value pairs */
73 tagExtensionField *list;
74 } fields;
75 /* buffers to be freed at close */
76 struct {
77 /* name of program author */
78 char *author;
79 /* name of program */
80 char *name;
81 /* URL of distribution */
82 char *url;
83 /* program version */
84 char *version;
85 } program;
89 * DATA DEFINITIONS
91 const char *const EmptyString = "";
92 const char *const PseudoTagPrefix = "!_";
95 * FUNCTION DEFINITIONS
99 * Compare two strings, ignoring case.
100 * Return 0 for match, < 0 for smaller, > 0 for bigger
101 * Make sure case is folded to uppercase in comparison (like for 'sort -f')
102 * This makes a difference when one of the chars lies between upper and lower
103 * ie. one of the chars [ \ ] ^ _ ` for ascii. (The '_' in particular !)
105 static int struppercmp (const char *s1, const char *s2)
107 int result;
110 result = toupper ((int) *s1) - toupper ((int) *s2);
111 } while (result == 0 && *s1++ != '\0' && *s2++ != '\0');
112 return result;
115 static int strnuppercmp (const char *s1, const char *s2, size_t n)
117 int result;
120 result = toupper ((int) *s1) - toupper ((int) *s2);
121 } while (result == 0 && --n > 0 && *s1++ != '\0' && *s2++ != '\0');
122 return result;
125 static int growString (vstring *s)
127 int result = 0;
128 size_t newLength;
129 char *newLine;
130 if (s->size == 0)
132 newLength = 128;
133 newLine = (char*) malloc (newLength);
134 *newLine = '\0';
136 else
138 newLength = 2 * s->size;
139 newLine = (char*) realloc (s->buffer, newLength);
141 if (newLine == NULL)
142 perror ("string too large");
143 else
145 s->buffer = newLine;
146 s->size = newLength;
147 result = 1;
149 return result;
152 /* Copy name of tag out of tag line */
153 static void copyName (tagFile *const file)
155 size_t length;
156 const char *end = strchr (file->line.buffer, '\t');
157 if (end == NULL)
159 end = strchr (file->line.buffer, '\n');
160 if (end == NULL)
161 end = strchr (file->line.buffer, '\r');
163 if (end != NULL)
164 length = end - file->line.buffer;
165 else
166 length = strlen (file->line.buffer);
167 while (length >= file->name.size)
168 growString (&file->name);
169 strncpy (file->name.buffer, file->line.buffer, length);
170 file->name.buffer [length] = '\0';
173 static int readTagLineRaw (tagFile *const file)
175 int result = 1;
176 int reReadLine;
178 /* If reading the line places any character other than a null or a
179 * newline at the last character position in the buffer (one less than
180 * the buffer size), then we must resize the buffer and reattempt to read
181 * the line.
185 char *const pLastChar = file->line.buffer + file->line.size - 2;
186 char *line;
188 file->pos = ftell (file->fp);
189 reReadLine = 0;
190 *pLastChar = '\0';
191 line = fgets (file->line.buffer, (int) file->line.size, file->fp);
192 if (line == NULL)
194 /* read error */
195 if (! feof (file->fp))
196 perror ("readTagLine");
197 result = 0;
199 else if (*pLastChar != '\0' &&
200 *pLastChar != '\n' && *pLastChar != '\r')
202 /* buffer overflow */
203 growString (&file->line);
204 fseek (file->fp, file->pos, SEEK_SET);
205 reReadLine = 1;
207 else
209 size_t i = strlen (file->line.buffer);
210 while (i > 0 &&
211 (file->line.buffer [i - 1] == '\n' || file->line.buffer [i - 1] == '\r'))
213 file->line.buffer [i - 1] = '\0';
214 --i;
217 } while (reReadLine && result);
218 if (result)
219 copyName (file);
220 return result;
223 static int readTagLine (tagFile *const file)
225 int result;
228 result = readTagLineRaw (file);
229 } while (result && *file->name.buffer == '\0');
230 return result;
233 static tagResult growFields (tagFile *const file)
235 tagResult result = TagFailure;
236 unsigned short newCount = (unsigned short) 2 * file->fields.max;
237 tagExtensionField *newFields = (tagExtensionField*)
238 realloc (file->fields.list, newCount * sizeof (tagExtensionField));
239 if (newFields == NULL)
240 perror ("too many extension fields");
241 else
243 file->fields.list = newFields;
244 file->fields.max = newCount;
245 result = TagSuccess;
247 return result;
250 static void parseExtensionFields (tagFile *const file, tagEntry *const entry,
251 char *const string)
253 char *p = string;
254 while (p != NULL && *p != '\0')
256 while (*p == TAB)
257 *p++ = '\0';
258 if (*p != '\0')
260 char *colon;
261 char *field = p;
262 p = strchr (p, TAB);
263 if (p != NULL)
264 *p++ = '\0';
265 colon = strchr (field, ':');
266 if (colon == NULL)
267 entry->kind = field;
268 else
270 const char *key = field;
271 const char *value = colon + 1;
272 *colon = '\0';
273 if (strcmp (key, "kind") == 0)
274 entry->kind = value;
275 else if (strcmp (key, "file") == 0)
276 entry->fileScope = 1;
277 else if (strcmp (key, "line") == 0)
278 entry->address.lineNumber = atol (value);
279 else
281 if (entry->fields.count == file->fields.max)
282 growFields (file);
283 file->fields.list [entry->fields.count].key = key;
284 file->fields.list [entry->fields.count].value = value;
285 ++entry->fields.count;
292 static void parseTagLine (tagFile *file, tagEntry *const entry)
294 int i;
295 char *p = file->line.buffer;
296 char *tab = strchr (p, TAB);
298 entry->fields.list = NULL;
299 entry->fields.count = 0;
300 entry->kind = NULL;
301 entry->fileScope = 0;
303 entry->name = p;
304 if (tab != NULL)
306 *tab = '\0';
307 p = tab + 1;
308 entry->file = p;
309 tab = strchr (p, TAB);
310 if (tab != NULL)
312 int fieldsPresent;
313 *tab = '\0';
314 p = tab + 1;
315 if (*p == '/' || *p == '?')
317 /* parse pattern */
318 int delimiter = *(unsigned char*) p;
319 entry->address.lineNumber = 0;
320 entry->address.pattern = p;
323 p = strchr (p + 1, delimiter);
324 } while (p != NULL && *(p - 1) == '\\');
325 if (p == NULL)
327 /* invalid pattern */
329 else
330 ++p;
332 else if (isdigit ((int) *(unsigned char*) p))
334 /* parse line number */
335 entry->address.pattern = p;
336 entry->address.lineNumber = atol (p);
337 while (isdigit ((int) *(unsigned char*) p))
338 ++p;
340 else
342 /* invalid pattern */
344 fieldsPresent = (strncmp (p, ";\"", 2) == 0);
345 *p = '\0';
346 if (fieldsPresent)
347 parseExtensionFields (file, entry, p + 2);
350 if (entry->fields.count > 0)
351 entry->fields.list = file->fields.list;
352 for (i = entry->fields.count ; i < file->fields.max ; ++i)
354 file->fields.list [i].key = NULL;
355 file->fields.list [i].value = NULL;
359 static char *duplicate (const char *str)
361 char *result = NULL;
362 if (str != NULL)
364 result = strdup (str);
365 if (result == NULL)
366 perror (NULL);
368 return result;
371 static void readPseudoTags (tagFile *const file, tagFileInfo *const info)
373 fpos_t startOfLine;
374 const size_t prefixLength = strlen (PseudoTagPrefix);
375 if (info != NULL)
377 info->file.format = 1;
378 info->file.sort = TAG_UNSORTED;
379 info->program.author = NULL;
380 info->program.name = NULL;
381 info->program.url = NULL;
382 info->program.version = NULL;
384 while (1)
386 fgetpos (file->fp, &startOfLine);
387 if (! readTagLine (file))
388 break;
389 if (strncmp (file->line.buffer, PseudoTagPrefix, prefixLength) != 0)
390 break;
391 else
393 tagEntry entry;
394 const char *key, *value;
395 parseTagLine (file, &entry);
396 key = entry.name + prefixLength;
397 value = entry.file;
398 if (strcmp (key, "TAG_FILE_SORTED") == 0)
399 file->sortMethod = (sortType) atoi (value);
400 else if (strcmp (key, "TAG_FILE_FORMAT") == 0)
401 file->format = (short) atoi (value);
402 else if (strcmp (key, "TAG_PROGRAM_AUTHOR") == 0)
403 file->program.author = duplicate (value);
404 else if (strcmp (key, "TAG_PROGRAM_NAME") == 0)
405 file->program.name = duplicate (value);
406 else if (strcmp (key, "TAG_PROGRAM_URL") == 0)
407 file->program.url = duplicate (value);
408 else if (strcmp (key, "TAG_PROGRAM_VERSION") == 0)
409 file->program.version = duplicate (value);
410 if (info != NULL)
412 info->file.format = file->format;
413 info->file.sort = file->sortMethod;
414 info->program.author = file->program.author;
415 info->program.name = file->program.name;
416 info->program.url = file->program.url;
417 info->program.version = file->program.version;
421 fsetpos (file->fp, &startOfLine);
424 static void gotoFirstLogicalTag (tagFile *const file)
426 fpos_t startOfLine;
427 const size_t prefixLength = strlen (PseudoTagPrefix);
428 rewind (file->fp);
429 while (1)
431 fgetpos (file->fp, &startOfLine);
432 if (! readTagLine (file))
433 break;
434 if (strncmp (file->line.buffer, PseudoTagPrefix, prefixLength) != 0)
435 break;
437 fsetpos (file->fp, &startOfLine);
440 static tagFile *initialize (const char *const filePath, tagFileInfo *const info)
442 tagFile *result = (tagFile*) calloc ((size_t) 1, sizeof (tagFile));
443 if (result != NULL)
445 growString (&result->line);
446 growString (&result->name);
447 result->fields.max = 20;
448 result->fields.list = (tagExtensionField*) calloc (
449 result->fields.max, sizeof (tagExtensionField));
450 result->fp = fopen (filePath, "r");
451 if (result->fp == NULL)
453 /* free the result struct */
454 if (result->fields.list)
455 free (result->fields.list);
456 if (result->line.buffer)
457 free (result->line.buffer);
458 if (result->name.buffer)
459 free (result->name.buffer);
461 free (result);
462 result = NULL;
463 info->status.error_number = errno;
465 else
467 fseek (result->fp, 0, SEEK_END);
468 result->size = ftell (result->fp);
469 rewind (result->fp);
470 readPseudoTags (result, info);
471 info->status.opened = 1;
472 result->initialized = 1;
475 return result;
478 static tagFile *initialize_1 (const FILE* fd, tagFileInfo *const info)
480 tagFile *result = (tagFile*) malloc (sizeof (tagFile));
481 if (result != NULL)
483 memset (result, 0, sizeof (tagFile));
484 growString (&result->line);
485 growString (&result->name);
486 result->fields.max = 20;
487 result->fields.list = (tagExtensionField*) malloc (
488 result->fields.max * sizeof (tagExtensionField));
489 result->fp = (FILE*)fd;
490 if (result->fp == NULL)
492 /* free the result struct */
493 if (result->fields.list)
494 free (result->fields.list);
495 if (result->line.buffer)
496 free (result->line.buffer);
497 if (result->name.buffer)
498 free (result->name.buffer);
500 free (result);
501 result = NULL;
502 info->status.error_number = errno;
504 else
506 fseek (result->fp, 0, SEEK_END);
507 result->size = ftell (result->fp);
508 rewind (result->fp);
509 readPseudoTags (result, info);
510 info->status.opened = 1;
511 result->initialized = 1;
514 return result;
517 static void terminate (tagFile *const file)
519 fclose (file->fp);
521 free (file->line.buffer);
522 free (file->name.buffer);
523 free (file->fields.list);
525 if (file->program.author != NULL)
526 free (file->program.author);
527 if (file->program.name != NULL)
528 free (file->program.name);
529 if (file->program.url != NULL)
530 free (file->program.url);
531 if (file->program.version != NULL)
532 free (file->program.version);
533 if (file->search.name != NULL)
534 free (file->search.name);
536 memset (file, 0, sizeof (tagFile));
538 free (file);
541 static tagResult readNext (tagFile *const file, tagEntry *const entry)
543 tagResult result;
544 if (file == NULL || ! file->initialized)
545 result = TagFailure;
546 else if (! readTagLine (file))
547 result = TagFailure;
548 else
550 if (entry != NULL)
551 parseTagLine (file, entry);
552 result = TagSuccess;
554 return result;
557 static const char *readFieldValue (
558 const tagEntry *const entry, const char *const key)
560 const char *result = NULL;
561 int i;
562 if (strcmp (key, "kind") == 0)
563 result = entry->kind;
564 else if (strcmp (key, "file") == 0)
565 result = EmptyString;
566 else for (i = 0 ; i < entry->fields.count && result == NULL ; ++i)
567 if (strcmp (entry->fields.list [i].key, key) == 0)
568 result = entry->fields.list [i].value;
569 return result;
572 static int readTagLineSeek (tagFile *const file, const off_t pos)
574 int result = 0;
575 if (fseek (file->fp, pos, SEEK_SET) == 0)
577 result = readTagLine (file); /* read probable partial line */
578 if (pos > 0 && result)
579 result = readTagLine (file); /* read complete line */
581 return result;
584 static int nameComparison (tagFile *const file)
586 int result;
587 if (file->search.ignorecase)
589 if (file->search.partial)
590 result = strnuppercmp (file->search.name, file->name.buffer,
591 file->search.nameLength);
592 else
593 result = struppercmp (file->search.name, file->name.buffer);
595 else
597 if (file->search.partial)
598 result = strncmp (file->search.name, file->name.buffer,
599 file->search.nameLength);
600 else
601 result = strcmp (file->search.name, file->name.buffer);
603 return result;
606 static void findFirstNonMatchBefore (tagFile *const file)
608 #define JUMP_BACK 512
609 int more_lines;
610 int comp;
611 off_t start = file->pos;
612 off_t pos = start;
615 if (pos < (off_t) JUMP_BACK)
616 pos = 0;
617 else
618 pos = pos - JUMP_BACK;
619 more_lines = readTagLineSeek (file, pos);
620 comp = nameComparison (file);
621 } while (more_lines && comp == 0 && pos > 0 && pos < start);
624 static tagResult findFirstMatchBefore (tagFile *const file)
626 tagResult result = TagFailure;
627 int more_lines;
628 off_t start = file->pos;
629 findFirstNonMatchBefore (file);
632 more_lines = readTagLine (file);
633 if (nameComparison (file) == 0)
634 result = TagSuccess;
635 } while (more_lines && result != TagSuccess && file->pos < start);
636 return result;
639 static tagResult findBinary (tagFile *const file)
641 tagResult result = TagFailure;
642 off_t lower_limit = 0;
643 off_t upper_limit = file->size;
644 off_t last_pos = 0;
645 off_t pos = upper_limit / 2;
646 while (result != TagSuccess)
648 if (! readTagLineSeek (file, pos))
650 /* in case we fell off end of file */
651 result = findFirstMatchBefore (file);
652 break;
654 else if (pos == last_pos)
656 /* prevent infinite loop if we backed up to beginning of file */
657 break;
659 else
661 const int comp = nameComparison (file);
662 last_pos = pos;
663 if (comp < 0)
665 upper_limit = pos;
666 pos = lower_limit + ((upper_limit - lower_limit) / 2);
668 else if (comp > 0)
670 lower_limit = pos;
671 pos = lower_limit + ((upper_limit - lower_limit) / 2);
673 else if (pos == 0)
674 result = TagSuccess;
675 else
676 result = findFirstMatchBefore (file);
679 return result;
682 static tagResult findSequential (tagFile *const file)
684 tagResult result = TagFailure;
685 if (file->initialized)
687 while (result == TagFailure && readTagLine (file))
689 if (nameComparison (file) == 0)
690 result = TagSuccess;
693 return result;
696 static tagResult find (tagFile *const file, tagEntry *const entry,
697 const char *const name, const int options)
699 tagResult result;
700 if (file->search.name != NULL)
701 free (file->search.name);
702 file->search.name = duplicate (name);
703 file->search.nameLength = strlen (name);
704 file->search.partial = (options & TAG_PARTIALMATCH) != 0;
705 file->search.ignorecase = (options & TAG_IGNORECASE) != 0;
706 fseek (file->fp, 0, SEEK_END);
707 file->size = ftell (file->fp);
708 rewind (file->fp);
709 if ((file->sortMethod == TAG_SORTED && !file->search.ignorecase) ||
710 (file->sortMethod == TAG_FOLDSORTED && file->search.ignorecase))
712 #ifdef DEBUG
713 printf ("<performing binary search>\n");
714 #endif
715 result = findBinary (file);
717 else
719 #ifdef DEBUG
720 printf ("<performing sequential search>\n");
721 #endif
722 result = findSequential (file);
725 if (result != TagSuccess)
726 file->search.pos = file->size;
727 else
729 file->search.pos = file->pos;
730 if (entry != NULL)
731 parseTagLine (file, entry);
733 return result;
736 static tagResult findNext (tagFile *const file, tagEntry *const entry)
738 tagResult result;
739 if ((file->sortMethod == TAG_SORTED && !file->search.ignorecase) ||
740 (file->sortMethod == TAG_FOLDSORTED && file->search.ignorecase))
742 result = tagsNext (file, entry);
743 if (result == TagSuccess && nameComparison (file) != 0)
744 result = TagFailure;
746 else
748 result = findSequential (file);
749 if (result == TagSuccess && entry != NULL)
750 parseTagLine (file, entry);
752 return result;
756 * EXTERNAL INTERFACE
759 extern tagFile *tagsOpen (const char *const filePath, tagFileInfo *const info)
761 return initialize (filePath, info);
764 extern tagFile *tagsOpen_1 (const FILE *fd, tagFileInfo *const info)
766 return initialize_1 (fd, info);
769 extern tagResult tagsSetSortType (tagFile *const file, const sortType type)
771 tagResult result = TagFailure;
772 if (file != NULL && file->initialized)
774 file->sortMethod = type;
775 result = TagSuccess;
777 return result;
780 extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry)
782 tagResult result = TagFailure;
783 if (file != NULL && file->initialized)
785 gotoFirstLogicalTag (file);
786 result = readNext (file, entry);
788 return result;
791 extern tagResult tagsNext (tagFile *const file, tagEntry *const entry)
793 tagResult result = TagFailure;
794 if (file != NULL && file->initialized)
795 result = readNext (file, entry);
796 return result;
799 extern const char *tagsField (const tagEntry *const entry, const char *const key)
801 const char *result = NULL;
802 if (entry != NULL)
803 result = readFieldValue (entry, key);
804 return result;
807 extern tagResult tagsFind (tagFile *const file, tagEntry *const entry,
808 const char *const name, const int options)
810 tagResult result = TagFailure;
811 if (file != NULL && file->initialized)
812 result = find (file, entry, name, options);
813 return result;
816 extern tagResult tagsFindNext (tagFile *const file, tagEntry *const entry)
818 tagResult result = TagFailure;
819 if (file != NULL && file->initialized)
820 result = findNext (file, entry);
821 return result;
824 extern tagResult tagsClose (tagFile *const file)
826 tagResult result = TagFailure;
827 if (file != NULL && file->initialized)
829 terminate (file);
830 result = TagSuccess;
832 return result;
836 * TEST FRAMEWORK
839 #ifdef READTAGS_MAIN
841 static const char *TagFileName = "tags";
842 static const char *ProgramName;
843 static int extensionFields;
844 static int SortOverride;
845 static sortType SortMethod;
847 static void printTag (const tagEntry *entry)
849 int i;
850 int first = 1;
851 const char* separator = ";\"";
852 const char* const empty = "";
853 /* "sep" returns a value only the first time it is evaluated */
854 #define sep (first ? (first = 0, separator) : empty)
855 printf ("%s\t%s\t%s",
856 entry->name, entry->file, entry->address.pattern);
857 if (extensionFields)
859 if (entry->kind != NULL && entry->kind [0] != '\0')
860 printf ("%s\tkind:%s", sep, entry->kind);
861 if (entry->fileScope)
862 printf ("%s\tfile:", sep);
863 #if 0
864 if (entry->address.lineNumber > 0)
865 printf ("%s\tline:%lu", sep, entry->address.lineNumber);
866 #endif
867 for (i = 0 ; i < entry->fields.count ; ++i)
868 printf ("%s\t%s:%s", sep, entry->fields.list [i].key,
869 entry->fields.list [i].value);
871 putchar ('\n');
872 #undef sep
875 static void findTag (const char *const name, const int options)
877 tagFileInfo info;
878 tagEntry entry;
879 tagFile *const file = tagsOpen (TagFileName, &info);
880 if (file == NULL)
882 fprintf (stderr, "%s: cannot open tag file: %s: %s\n",
883 ProgramName, strerror (info.status.error_number), name);
884 exit (1);
886 else
888 if (SortOverride)
889 tagsSetSortType (file, SortMethod);
890 if (tagsFind (file, &entry, name, options) == TagSuccess)
894 printTag (&entry);
895 } while (tagsFindNext (file, &entry) == TagSuccess);
897 tagsClose (file);
901 static void listTags (void)
903 tagFileInfo info;
904 tagEntry entry;
905 tagFile *const file = tagsOpen (TagFileName, &info);
906 if (file == NULL)
908 fprintf (stderr, "%s: cannot open tag file: %s: %s\n",
909 ProgramName, strerror (info.status.error_number), TagFileName);
910 exit (1);
912 else
914 while (tagsNext (file, &entry) == TagSuccess)
915 printTag (&entry);
916 tagsClose (file);
920 const char *const Usage =
921 "Find tag file entries matching specified names.\n\n"
922 "Usage: %s [-ilp] [-s[0|1]] [-t file] [name(s)]\n\n"
923 "Options:\n"
924 " -e Include extension fields in output.\n"
925 " -i Perform case-insensitive matching.\n"
926 " -l List all tags.\n"
927 " -p Perform partial matching.\n"
928 " -s[0|1|2] Override sort detection of tag file.\n"
929 " -t file Use specified tag file (default: \"tags\").\n"
930 "Note that options are acted upon as encountered, so order is significant.\n";
932 extern int main (int argc, char **argv)
934 int options = 0;
935 int actionSupplied = 0;
936 int i;
937 ProgramName = argv [0];
938 if (argc == 1)
940 fprintf (stderr, Usage, ProgramName);
941 exit (1);
943 for (i = 1 ; i < argc ; ++i)
945 const char *const arg = argv [i];
946 if (arg [0] != '-')
948 findTag (arg, options);
949 actionSupplied = 1;
951 else
953 size_t j;
954 for (j = 1 ; arg [j] != '\0' ; ++j)
956 switch (arg [j])
958 case 'e': extensionFields = 1; break;
959 case 'i': options |= TAG_IGNORECASE; break;
960 case 'p': options |= TAG_PARTIALMATCH; break;
961 case 'l': listTags (); actionSupplied = 1; break;
963 case 't':
964 if (arg [j+1] != '\0')
966 TagFileName = arg + j + 1;
967 j += strlen (TagFileName);
969 else if (i + 1 < argc)
970 TagFileName = argv [++i];
971 else
973 fprintf (stderr, Usage, ProgramName);
974 exit (1);
976 break;
977 case 's':
978 SortOverride = 1;
979 ++j;
980 if (arg [j] == '\0')
981 SortMethod = TAG_SORTED;
982 else if (strchr ("012", arg[j]) != NULL)
983 SortMethod = (sortType) (arg[j] - '0');
984 else
986 fprintf (stderr, Usage, ProgramName);
987 exit (1);
989 break;
990 default:
991 fprintf (stderr, "%s: unknown option: %c\n",
992 ProgramName, arg[j]);
993 exit (1);
994 break;
999 if (! actionSupplied)
1001 fprintf (stderr,
1002 "%s: no action specified: specify tag name(s) or -l option\n",
1003 ProgramName);
1004 exit (1);
1006 return 0;
1009 #endif
1011 /* vi:set tabstop=4 shiftwidth=4: */