Browse Source

Enhancement in option parsing errors

Telling getopt to produce an error message by setting opterr to 1
Yann Weber 7 years ago
parent
commit
42457370ba
1 changed files with 3 additions and 10 deletions
  1. 3
    10
      src/ttail_init.c

+ 3
- 10
src/ttail_init.c View File

65
 		goto ttail_init_alloc_err;
65
 		goto ttail_init_alloc_err;
66
 	}
66
 	}
67
 
67
 
68
-	opterr = 0;
68
+	opterr = 1;
69
 	optind = 0;
69
 	optind = 0;
70
 	res->verbose = 0;
70
 	res->verbose = 0;
71
 	res->fmt = NULL;
71
 	res->fmt = NULL;
151
 				strcpy(date, optarg);
151
 				strcpy(date, optarg);
152
 				dates[c=='d'?0:1] = date;
152
 				dates[c=='d'?0:1] = date;
153
 				break;
153
 				break;
154
-			case '?':
155
-				optind--;
156
-				goto init_badarg;
157
-				break;
158
-			default:
159
-				fprintf(stderr, "Bad argument\n");
160
-				goto init_badarg;
154
+			default: /* ? */
155
+				goto ttail_init_err;
161
 				
156
 				
162
 		}
157
 		}
163
 	}
158
 	}
177
 	}
172
 	}
178
 
173
 
179
 	return res;
174
 	return res;
180
-	init_badarg:
181
-	fprintf(stderr, "Unknown option '%s'\n", argv[optind]);
182
 	ttail_init_err:
175
 	ttail_init_err:
183
 	if(dates[0]) { free(dates[0]); }
176
 	if(dates[0]) { free(dates[0]); }
184
 	if(dates[1]) { free(dates[1]); }
177
 	if(dates[1]) { free(dates[1]); }

Loading…
Cancel
Save