Skip to content

Commit

Permalink
Fix parameter parsing in cut
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik van der Kouwe committed Jan 21, 2010
1 parent 9baf805 commit 0bc2aad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
10 changes: 10 additions & 0 deletions LICENSE
Expand Up @@ -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
distributed together on the same medium, this aggregation does not cause
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.

21 changes: 16 additions & 5 deletions commands/simple/cut.c
Expand Up @@ -134,7 +134,10 @@ void get_args()
args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0';
if (!args[arg_ptr]) cuterror(POSITION_ERROR);
arg_ptr++;
} else if (line[i] != '-') {
cuterror(SYNTAX_ERROR);
}

if (line[i] == '-') {
arg_ptr |= 1;
i++;
Expand Down Expand Up @@ -208,6 +211,7 @@ int main(argc, argv)
int argc;
char *argv[];
{
char *linearg;
int i = 1;
int numberFilenames = 0;
name = argv[0];
Expand All @@ -220,22 +224,29 @@ char *argv[];
case 'd':
if (mode == OPTIONC || mode == OPTIONB)
warn(DELIMITER_NOT_APPLICABLE, "d");
delim = argv[i++][0];
delim = argv[i - 1][2] ?
argv[i - 1][2] : argv[i++][0];
break;
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)
warn(OVERRIDING_PREVIOUS_MODE, "f");
mode = OPTIONF;
break;
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)
warn(OVERRIDING_PREVIOUS_MODE, "b");
mode = OPTIONB;
break;
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)
warn(OVERRIDING_PREVIOUS_MODE, "c");
mode = OPTIONC;
Expand Down Expand Up @@ -281,7 +292,7 @@ char *argv[];
case 'f':
case 'c':
case 'b':
case 'd': i += 2; break;
case 'd': i += argv[i][2] ? 1 : 2; break;
case 'n':
case 'i':
case 's': i++; break;
Expand Down
2 changes: 2 additions & 0 deletions include/time.h
Expand Up @@ -59,6 +59,8 @@ _PROTOTYPE( char *asctime, (const struct tm *_timeptr) );
_PROTOTYPE( char *ctime, (const time_t *_timer) );
_PROTOTYPE( struct tm *gmtime, (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,
const struct tm *_timep) );

Expand Down

0 comments on commit 0bc2aad

Please sign in to comment.