Fix parameter parsing in cut

This commit is contained in:
Erik van der Kouwe 2010-01-21 10:16:05 +00:00
parent 9baf8059fb
commit 0bc2aad4af
3 changed files with 28 additions and 5 deletions

10
LICENSE
View file

@ -50,3 +50,13 @@ observe the conditions of the GPL with respect to this software. As
clearly stated in Article 2 of the GPL, when GPL and nonGPL software are clearly stated in Article 2 of the GPL, when GPL and nonGPL software are
distributed together on the same medium, this aggregation does not cause distributed together on the same medium, this aggregation does not cause
the license of either part to apply to the other part. the license of either part to apply to the other part.
Acknowledgements
This product includes software developed by the University of
California, Berkeley and its contributors.
This product includes software developed by Softweyr LLC, the
University of California, Berkeley, and its contributors.

View file

@ -134,7 +134,10 @@ void get_args()
args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0'; args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0';
if (!args[arg_ptr]) cuterror(POSITION_ERROR); if (!args[arg_ptr]) cuterror(POSITION_ERROR);
arg_ptr++; arg_ptr++;
} else if (line[i] != '-') {
cuterror(SYNTAX_ERROR);
} }
if (line[i] == '-') { if (line[i] == '-') {
arg_ptr |= 1; arg_ptr |= 1;
i++; i++;
@ -208,6 +211,7 @@ int main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
char *linearg;
int i = 1; int i = 1;
int numberFilenames = 0; int numberFilenames = 0;
name = argv[0]; name = argv[0];
@ -220,22 +224,29 @@ char *argv[];
case 'd': case 'd':
if (mode == OPTIONC || mode == OPTIONB) if (mode == OPTIONC || mode == OPTIONB)
warn(DELIMITER_NOT_APPLICABLE, "d"); warn(DELIMITER_NOT_APPLICABLE, "d");
delim = argv[i++][0]; delim = argv[i - 1][2] ?
argv[i - 1][2] : argv[i++][0];
break; break;
case 'f': case 'f':
sprintf(line, "%s", argv[i++]); linearg = argv[i - 1][2] ?
(argv[i - 1] + 2) : argv[i++];
sprintf(line, "%s", linearg);
if (mode == OPTIONC || mode == OPTIONB) if (mode == OPTIONC || mode == OPTIONB)
warn(OVERRIDING_PREVIOUS_MODE, "f"); warn(OVERRIDING_PREVIOUS_MODE, "f");
mode = OPTIONF; mode = OPTIONF;
break; break;
case 'b': case 'b':
sprintf(line, "%s", argv[i++]); linearg = argv[i - 1][2] ?
(argv[i - 1] + 2) : argv[i++];
sprintf(line, "%s", linearg);
if (mode == OPTIONF || mode == OPTIONC) if (mode == OPTIONF || mode == OPTIONC)
warn(OVERRIDING_PREVIOUS_MODE, "b"); warn(OVERRIDING_PREVIOUS_MODE, "b");
mode = OPTIONB; mode = OPTIONB;
break; break;
case 'c': case 'c':
sprintf(line, "%s", argv[i++]); linearg = argv[i - 1][2] ?
(argv[i - 1] + 2) : argv[i++];
sprintf(line, "%s", linearg);
if (mode == OPTIONF || mode == OPTIONB) if (mode == OPTIONF || mode == OPTIONB)
warn(OVERRIDING_PREVIOUS_MODE, "c"); warn(OVERRIDING_PREVIOUS_MODE, "c");
mode = OPTIONC; mode = OPTIONC;
@ -281,7 +292,7 @@ char *argv[];
case 'f': case 'f':
case 'c': case 'c':
case 'b': case 'b':
case 'd': i += 2; break; case 'd': i += argv[i][2] ? 1 : 2; break;
case 'n': case 'n':
case 'i': case 'i':
case 's': i++; break; case 's': i++; break;

View file

@ -59,6 +59,8 @@ _PROTOTYPE( char *asctime, (const struct tm *_timeptr) );
_PROTOTYPE( char *ctime, (const time_t *_timer) ); _PROTOTYPE( char *ctime, (const time_t *_timer) );
_PROTOTYPE( struct tm *gmtime, (const time_t *_timer) ); _PROTOTYPE( struct tm *gmtime, (const time_t *_timer) );
_PROTOTYPE( struct tm *localtime, (const time_t *_timer) ); _PROTOTYPE( struct tm *localtime, (const time_t *_timer) );
_PROTOTYPE( struct tm *localtime_r, (const time_t *const timep,
struct tm *tmp) );
_PROTOTYPE( size_t strftime, (char *_s, size_t _max, const char *_fmt, _PROTOTYPE( size_t strftime, (char *_s, size_t _max, const char *_fmt,
const struct tm *_timep) ); const struct tm *_timep) );