comparison lwar/main.c @ 9:6eed14cccac9

Switched lwar to lw_cmdline and brought in lwlib
author lost@l-w.ca
date Sat, 22 Jan 2011 10:04:32 -0700
parents 2c24602be78f
children 4130ffdeb5c8
comparison
equal deleted inserted replaced
8:fdc11ef4115b 9:6eed14cccac9
20 20
21 Implements the program startup code 21 Implements the program startup code
22 22
23 */ 23 */
24 24
25 #include <argp.h>
26 #include <errno.h> 25 #include <errno.h>
27 #include <stdio.h> 26 #include <stdio.h>
28 #include <stdlib.h> 27 #include <stdlib.h>
29 #include <sys/types.h> 28 #include <sys/types.h>
30 #include <sys/stat.h> 29 #include <sys/stat.h>
31 #include <unistd.h> 30 #include <unistd.h>
32 31
32 #include <lw_cmdline.h>
33
33 #include "lwar.h" 34 #include "lwar.h"
34 35
35 // command line option handling 36 // command line option handling
36 const char *argp_program_version = "LWAR from " PACKAGE_STRING; 37 #define PROGVER "lwar from " PACKAGE_STRING
37 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
38 char *program_name; 38 char *program_name;
39 39
40 static error_t parse_opts(int key, char *arg, struct argp_state *state) 40 static int parse_opts(int key, char *arg, void *state)
41 { 41 {
42 switch (key) 42 switch (key)
43 { 43 {
44 case 'd': 44 case 'd':
45 // debug 45 // debug
73 case 'x': 73 case 'x':
74 // extract members 74 // extract members
75 operation = LWAR_OP_EXTRACT; 75 operation = LWAR_OP_EXTRACT;
76 break; 76 break;
77 77
78 case ARGP_KEY_ARG: 78 case lw_cmdline_key_arg:
79 if (archive_file) 79 if (archive_file)
80 { 80 {
81 // add archive member to list 81 // add archive member to list
82 add_file_name(arg); 82 add_file_name(arg);
83 } 83 }
84 else 84 else
85 archive_file = arg; 85 archive_file = arg;
86 break; 86 break;
87 87
88 default: 88 default:
89 return ARGP_ERR_UNKNOWN; 89 return lw_cmdline_err_unknown;
90 } 90 }
91 return 0; 91 return 0;
92 } 92 }
93 93
94 static struct argp_option options[] = 94 static struct lw_cmdline_options options[] =
95 { 95 {
96 { "replace", 'r', 0, 0, 96 { "replace", 'r', 0, 0,
97 "Add or replace archive members" }, 97 "Add or replace archive members" },
98 { "extract", 'x', 0, 0, 98 { "extract", 'x', 0, 0,
99 "Extract members from the archive" }, 99 "Extract members from the archive" },
108 { "debug", 'd', 0, 0, 108 { "debug", 'd', 0, 0,
109 "Set debug mode"}, 109 "Set debug mode"},
110 { 0 } 110 { 0 }
111 }; 111 };
112 112
113 static struct argp argp = 113 static struct lw_cmdline_parser argparser =
114 { 114 {
115 options, 115 options,
116 parse_opts, 116 parse_opts,
117 "<archive> [<file> ...]", 117 "ARCHIVE [FILE ...]",
118 "LWAR, a library file manager for LWLINK" 118 "lwar, a library file manager for lwlink",
119 PROGVER
119 }; 120 };
120 121
121 extern void do_list(void); 122 extern void do_list(void);
122 extern void do_add(void); 123 extern void do_add(void);
123 extern void do_remove(void); 124 extern void do_remove(void);
127 // main function; parse command line, set up assembler state, and run the 128 // main function; parse command line, set up assembler state, and run the
128 // assembler on the first file 129 // assembler on the first file
129 int main(int argc, char **argv) 130 int main(int argc, char **argv)
130 { 131 {
131 program_name = argv[0]; 132 program_name = argv[0];
132 argp_parse(&argp, argc, argv, 0, 0, NULL); 133 lw_cmdline_parse(&argparser, argc, argv, 0, 0, NULL);
133 if (archive_file == NULL) 134 if (archive_file == NULL)
134 { 135 {
135 fprintf(stderr, "You must specify an archive file.\n"); 136 fprintf(stderr, "You must specify an archive file.\n");
136 exit(1); 137 exit(1);
137 } 138 }