@@ -88,7 +88,7 @@ shuffile(const char *input, int argn, size_t inputlen)
88
88
size_t len ;
89
89
90
90
if ((args = reallocarray (args , argn , sizeof (char * ))) == NULL )
91
- errx (1 , "shuffile" );
91
+ err (1 , "shuffile" );
92
92
93
93
while (i < argn ) {
94
94
for (s = input ; * s != delimiter ; s ++ ) {
@@ -98,18 +98,15 @@ shuffile(const char *input, int argn, size_t inputlen)
98
98
len = s - input ;
99
99
100
100
if ((args [i ] = malloc (len + 1 )) == NULL )
101
- err (1 , "malloc " );
101
+ err (1 , "shuffile " );
102
102
argt = args [i ++ ];
103
103
104
104
while (len -- > 0 )
105
105
* argt ++ = * input ++ ;
106
106
* argt = '\0' ;
107
107
108
108
input ++ ;
109
- if (inputlen > 0 ) {
110
- if (-- inputlen == 0 )
111
- break ;
112
- }
109
+ -- inputlen ;
113
110
}
114
111
115
112
most = (most < argn ? most : argn );
@@ -134,12 +131,13 @@ shufintegers(int range, int lo)
134
131
int * args = NULL , argt , i , j ;
135
132
136
133
if ((args = reallocarray (args , range , sizeof (int ))) == NULL )
137
- errx (1 , "range size will exhaust memory" );
134
+ err (1 , "range size will exhaust memory" );
138
135
139
136
if (rflag ) {
140
- while ((most == -1 ? 1 : most -- > 0 ))
137
+ while ((most == -1 ? 1 : most -- > 0 )) {
141
138
fprintf (ofile , "%u%c" ,
142
139
arc4random_uniform (range ) + lo , delimiter );
140
+ }
143
141
} else {
144
142
for (i = 0 ; i < range ; i ++ )
145
143
args [i ] = lo + i ;
@@ -196,7 +194,7 @@ static void
196
194
version (void )
197
195
{
198
196
199
- fputs ("shuf 2.2 \n"
197
+ fputs ("shuf 2.3 \n"
200
198
"Copyright (c) 2017-2019 Brian Callahan <[email protected] >\n"
201
199
"\nPermission to use, copy, modify, and distribute this software"
202
200
" for any\npurpose with or without fee is hereby granted, "
@@ -263,10 +261,11 @@ main(int argc, char *argv[])
263
261
break ;
264
262
case 'n' :
265
263
most = strtonum (optarg , 0 , INT_MAX , & errstr );
266
- if (errstr != NULL )
264
+ if (errstr != NULL ) {
267
265
errx (1 ,
268
266
"-n count must be from 0 to %d, not %s" ,
269
267
INT_MAX , optarg );
268
+ }
270
269
break ;
271
270
case 'o' :
272
271
if (oflag ++ )
@@ -294,12 +293,12 @@ main(int argc, char *argv[])
294
293
if (oflag == 0 )
295
294
ofile = stdout ;
296
295
297
- if (eflag == 0 && argc > 1 )
298
- errx (1 , "extra operand '%s'" , * ++ argv );
296
+ if (eflag == 0 && (( iflag == 1 && argc != 0 ) || argc > 1 ) )
297
+ errx (1 , "extra operand '%s'" , iflag == 1 ? * argv : * ++ argv );
299
298
300
299
if (eflag ) {
301
- if (argc < 1 )
302
- errx ( 1 , "must provide at least one argument with -e" ) ;
300
+ if (argc == 0 )
301
+ goto out ;
303
302
repledge (oflag );
304
303
shufecho (argc , argv );
305
304
goto out ;
0 commit comments