10 extern int optind, opterr, optopt;
12 static struct option long_options[] = {
13 {"verbose", no_argument, 0, 'V'},
14 {"help", no_argument, 0, 'h'},
15 {"print-info", no_argument, 0, 'p'},
16 {"list-needed-libs", no_argument, 0, 'n'},
17 {"lookup", required_argument, 0, 'L'},
21 /* This array must parallel long_options[] */
22 static const char *descriptions[] = {
23 "print verbose output",
25 "for each file, generate a listing of all dependencies that each symbol "
27 "print out a list of needed libraries",
28 "provide a directory for library lookup"
35 "\tlsd file1 [file2 file3 ... fileN] [-Ldir1 -Ldir2 ... -LdirN] "
39 fprintf(stdout, "options:\n");
40 struct option *opt = long_options;
41 const char **desc = descriptions;
43 fprintf(stdout, "\t-%c\n"
53 int get_options(int argc, char **argv,
54 int *list_needed_libs,
62 ASSERT(list_needed_libs);
63 *list_needed_libs = 0;
75 /* getopt_long stores the option index here. */
78 c = getopt_long (argc, argv,
82 /* Detect the end of the options. */
86 INFO ("option -%c with value `%s'\n", c, (optarg ?: "(null)"));
89 #define SET_STRING_OPTION(name) do { \
91 (*name) = strdup(optarg); \
96 /* If this option set a flag, do nothing else now. */
97 if (long_options[option_index].flag != 0)
99 INFO ("option %s", long_options[option_index].name);
101 INFO (" with arg %s", optarg);
104 case 'h': print_help(); exit(1); break;
105 case 'V': *verbose = 1; break;
106 case 'p': *info = 1; break;
107 case 'n': *list_needed_libs = 1; break;
110 if (*num_dirs == size) {
112 *dirs = (char **)REALLOC(*dirs, size * sizeof(char *));
114 SET_STRING_OPTION(((*dirs) + *num_dirs));
119 /* getopt_long already printed an error message. */
122 #undef SET_STRING_OPTION
125 FAILIF(1, "Unknown option");