nl.c (f1e20ff77e2a9605845632dd9319dd946728661f) | nl.c (53e29ec5b43a8188f2a35fe1b14eba99cf87d2cf) |
---|---|
1/*- 2 * Copyright (c) 1999 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to The NetBSD Foundation 6 * by Klaus Klein. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 158 unchanged lines hidden (view full) --- 167 break; 168 case 'd': 169 if (optarg[0] != '\0') 170 delim[0] = optarg[0]; 171 if (optarg[1] != '\0') 172 delim[1] = optarg[1]; 173 /* at most two delimiter characters */ 174 if (optarg[2] != '\0') { | 1/*- 2 * Copyright (c) 1999 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to The NetBSD Foundation 6 * by Klaus Klein. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 158 unchanged lines hidden (view full) --- 167 break; 168 case 'd': 169 if (optarg[0] != '\0') 170 delim[0] = optarg[0]; 171 if (optarg[1] != '\0') 172 delim[1] = optarg[1]; 173 /* at most two delimiter characters */ 174 if (optarg[2] != '\0') { |
175 (void)fprintf(stderr, 176 "nl: invalid delim argument -- %s\n", | 175 errx(EXIT_FAILURE, 176 "invalid delim argument -- %s", |
177 optarg); | 177 optarg); |
178 exit(EXIT_FAILURE); | |
179 /* NOTREACHED */ 180 } 181 break; 182 case 'f': 183 parse_numbering(optarg, FOOTER); 184 break; 185 case 'h': 186 parse_numbering(optarg, HEADER); 187 break; 188 case 'i': 189 errno = 0; 190 val = strtol(optarg, &ep, 10); 191 if ((ep != NULL && *ep != '\0') || | 178 /* NOTREACHED */ 179 } 180 break; 181 case 'f': 182 parse_numbering(optarg, FOOTER); 183 break; 184 case 'h': 185 parse_numbering(optarg, HEADER); 186 break; 187 case 'i': 188 errno = 0; 189 val = strtol(optarg, &ep, 10); 190 if ((ep != NULL && *ep != '\0') || |
192 ((val == LONG_MIN || val == LONG_MAX) && errno != 0)) { 193 (void)fprintf(stderr, 194 "invalid incr argument -- %s\n", optarg); 195 exit(EXIT_FAILURE); 196 } | 191 ((val == LONG_MIN || val == LONG_MAX) && errno != 0)) 192 errx(EXIT_FAILURE, 193 "invalid incr argument -- %s", optarg); |
197 incr = (int)val; 198 break; 199 case 'l': 200 errno = 0; 201 uval = strtoul(optarg, &ep, 10); 202 if ((ep != NULL && *ep != '\0') || | 194 incr = (int)val; 195 break; 196 case 'l': 197 errno = 0; 198 uval = strtoul(optarg, &ep, 10); 199 if ((ep != NULL && *ep != '\0') || |
203 (uval == ULONG_MAX && errno != 0)) { 204 (void)fprintf(stderr, 205 "invalid num argument -- %s\n", optarg); 206 exit(EXIT_FAILURE); 207 } | 200 (uval == ULONG_MAX && errno != 0)) 201 errx(EXIT_FAILURE, 202 "invalid num argument -- %s", optarg); |
208 nblank = (unsigned int)uval; 209 break; 210 case 'n': 211 if (strcmp(optarg, "ln") == 0) { 212 format = FORMAT_LN; 213 } else if (strcmp(optarg, "rn") == 0) { 214 format = FORMAT_RN; 215 } else if (strcmp(optarg, "rz") == 0) { 216 format = FORMAT_RZ; | 203 nblank = (unsigned int)uval; 204 break; 205 case 'n': 206 if (strcmp(optarg, "ln") == 0) { 207 format = FORMAT_LN; 208 } else if (strcmp(optarg, "rn") == 0) { 209 format = FORMAT_RN; 210 } else if (strcmp(optarg, "rz") == 0) { 211 format = FORMAT_RZ; |
217 } else { 218 (void)fprintf(stderr, 219 "nl: illegal format -- %s\n", optarg); 220 exit(EXIT_FAILURE); 221 } | 212 } else 213 errx(EXIT_FAILURE, 214 "illegal format -- %s", optarg); |
222 break; 223 case 's': 224 sep = optarg; 225 break; 226 case 'v': 227 errno = 0; 228 val = strtol(optarg, &ep, 10); 229 if ((ep != NULL && *ep != '\0') || | 215 break; 216 case 's': 217 sep = optarg; 218 break; 219 case 'v': 220 errno = 0; 221 val = strtol(optarg, &ep, 10); 222 if ((ep != NULL && *ep != '\0') || |
230 ((val == LONG_MIN || val == LONG_MAX) && errno != 0)) { 231 (void)fprintf(stderr, 232 "invalid startnum value -- %s\n", optarg); 233 exit(EXIT_FAILURE); 234 } | 223 ((val == LONG_MIN || val == LONG_MAX) && errno != 0)) 224 errx(EXIT_FAILURE, 225 "invalid startnum value -- %s", optarg); |
235 startnum = (int)val; 236 break; 237 case 'w': 238 errno = 0; 239 val = strtol(optarg, &ep, 10); 240 if ((ep != NULL && *ep != '\0') || | 226 startnum = (int)val; 227 break; 228 case 'w': 229 errno = 0; 230 val = strtol(optarg, &ep, 10); 231 if ((ep != NULL && *ep != '\0') || |
241 ((val == LONG_MIN || val == LONG_MAX) && errno != 0)) { 242 (void)fprintf(stderr, 243 "invalid width value -- %s\n", optarg); 244 exit(EXIT_FAILURE); 245 } | 232 ((val == LONG_MIN || val == LONG_MAX) && errno != 0)) 233 errx(EXIT_FAILURE, 234 "invalid width value -- %s", optarg); |
246 width = (int)val; | 235 width = (int)val; |
247 if (!(width > 0)) { 248 (void)fprintf(stderr, 249 "nl: width argument must be > 0 -- %d\n", | 236 if (!(width > 0)) 237 errx(EXIT_FAILURE, 238 "width argument must be > 0 -- %d", |
250 width); | 239 width); |
251 exit(EXIT_FAILURE); 252 } | |
253 break; 254 case '?': 255 default: 256 usage(); 257 /* NOTREACHED */ 258 } 259 } 260 argc -= optind; --- 141 unchanged lines hidden (view full) --- 402 numbering_properties[section].type = number_regex; 403 404 /* Compile/validate the supplied regular expression. */ 405 if ((error = regcomp(&numbering_properties[section].expr, 406 &argstr[1], REG_NEWLINE|REG_NOSUB)) != 0) { 407 (void)regerror(error, 408 &numbering_properties[section].expr, 409 errorbuf, sizeof (errorbuf)); | 240 break; 241 case '?': 242 default: 243 usage(); 244 /* NOTREACHED */ 245 } 246 } 247 argc -= optind; --- 141 unchanged lines hidden (view full) --- 389 numbering_properties[section].type = number_regex; 390 391 /* Compile/validate the supplied regular expression. */ 392 if ((error = regcomp(&numbering_properties[section].expr, 393 &argstr[1], REG_NEWLINE|REG_NOSUB)) != 0) { 394 (void)regerror(error, 395 &numbering_properties[section].expr, 396 errorbuf, sizeof (errorbuf)); |
410 (void)fprintf(stderr, 411 "nl: %s expr: %s -- %s\n", | 397 errx(EXIT_FAILURE, 398 "%s expr: %s -- %s", |
412 numbering_properties[section].name, errorbuf, 413 &argstr[1]); | 399 numbering_properties[section].name, errorbuf, 400 &argstr[1]); |
414 exit(EXIT_FAILURE); | |
415 } 416 break; 417 default: | 401 } 402 break; 403 default: |
418 (void)fprintf(stderr, 419 "nl: illegal %s line numbering type -- %s\n", | 404 errx(EXIT_FAILURE, 405 "illegal %s line numbering type -- %s", |
420 numbering_properties[section].name, argstr); | 406 numbering_properties[section].name, argstr); |
421 exit(EXIT_FAILURE); | |
422 } 423} 424 425static void 426usage() 427{ 428 429 (void)fprintf(stderr, "usage: nl [-p] [-b type] [-d delim] [-f type] \ 430[-h type] [-i incr] [-l num]\n\t[-n format] [-s sep] [-v startnum] [-w width] \ 431[file]\n"); 432 exit(EXIT_FAILURE); 433} | 407 } 408} 409 410static void 411usage() 412{ 413 414 (void)fprintf(stderr, "usage: nl [-p] [-b type] [-d delim] [-f type] \ 415[-h type] [-i incr] [-l num]\n\t[-n format] [-s sep] [-v startnum] [-w width] \ 416[file]\n"); 417 exit(EXIT_FAILURE); 418} |