mirror of https://git.qorg11.net/k9core.git
trying EBIN indentation style :-------DDDDDDDDDDDD
This commit is contained in:
parent
fbff968b27
commit
8a477a0cb7
144
src/wc.c
144
src/wc.c
|
@ -8,94 +8,94 @@ struct wc_values data;
|
|||
|
||||
struct wc_values
|
||||
{
|
||||
int lines;
|
||||
int bytes;
|
||||
int words;
|
||||
int lines;
|
||||
int bytes;
|
||||
int words;
|
||||
};
|
||||
|
||||
struct wc_values
|
||||
wc(FILE *file)
|
||||
{
|
||||
if(file == NULL)
|
||||
{
|
||||
fprintf(stderr,"error opening file\n");
|
||||
}
|
||||
struct wc_values foobar;
|
||||
char c;
|
||||
int newlines, spaces, bytes = 0;
|
||||
newlines = spaces = bytes = 0;
|
||||
while((c = fgetc(file)) > 0)
|
||||
{
|
||||
bytes++;
|
||||
if(c == '\n')
|
||||
newlines++;
|
||||
if(isspace(c))
|
||||
spaces++;
|
||||
}
|
||||
foobar.bytes = bytes;
|
||||
foobar.lines = newlines;
|
||||
foobar.words = spaces;
|
||||
if(file == NULL)
|
||||
{
|
||||
fprintf(stderr,"error opening file\n");
|
||||
}
|
||||
struct wc_values foobar;
|
||||
char c;
|
||||
int newlines, spaces, bytes = 0;
|
||||
newlines = spaces = bytes = 0;
|
||||
while((c = fgetc(file)) > 0)
|
||||
{
|
||||
bytes++;
|
||||
if(c == '\n')
|
||||
newlines++;
|
||||
if(isspace(c))
|
||||
spaces++;
|
||||
}
|
||||
foobar.bytes = bytes;
|
||||
foobar.lines = newlines;
|
||||
foobar.words = spaces;
|
||||
|
||||
fclose(file);
|
||||
return foobar;
|
||||
fclose(file);
|
||||
return foobar;
|
||||
}
|
||||
void
|
||||
print_values(const char*filename)
|
||||
{
|
||||
if(show_bytes && show_lines && show_words)
|
||||
printf("%i %i %i",
|
||||
data.lines,
|
||||
data.words,
|
||||
data.bytes);
|
||||
else
|
||||
{
|
||||
if(!show_lines)
|
||||
printf("%i ",data.lines);
|
||||
if(!show_words)
|
||||
printf("%i ",data.words);
|
||||
if(!show_bytes)
|
||||
printf("%i ",data.bytes);
|
||||
}
|
||||
printf(" %s\n",filename);
|
||||
if(show_bytes && show_lines && show_words)
|
||||
printf("%i %i %i",
|
||||
data.lines,
|
||||
data.words,
|
||||
data.bytes);
|
||||
else
|
||||
{
|
||||
if(!show_lines)
|
||||
printf("%i ",data.lines);
|
||||
if(!show_words)
|
||||
printf("%i ",data.words);
|
||||
if(!show_bytes)
|
||||
printf("%i ",data.bytes);
|
||||
}
|
||||
printf(" %s\n",filename);
|
||||
}
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
|
||||
show_lines = show_words = show_bytes = 1;
|
||||
/* Process arguments */
|
||||
show_lines = show_words = show_bytes = 1;
|
||||
/* Process arguments */
|
||||
|
||||
while((c = getopt(argc,argv,"lwcm")) > 0)
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case 'l':
|
||||
show_lines = 0;
|
||||
break;
|
||||
case 'w':
|
||||
show_words = 0;
|
||||
break;
|
||||
case 'c':
|
||||
case 'm':
|
||||
show_bytes = 0;
|
||||
break;
|
||||
while((c = getopt(argc,argv,"lwcm")) > 0)
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case 'l':
|
||||
show_lines = 0;
|
||||
break;
|
||||
case 'w':
|
||||
show_words = 0;
|
||||
break;
|
||||
case 'c':
|
||||
case 'm':
|
||||
show_bytes = 0;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(optind == argc)
|
||||
{
|
||||
data = wc(stdin);
|
||||
print_values("stdin");
|
||||
}
|
||||
else for(int i = optind; i<argc; i++)
|
||||
{
|
||||
if(argv[i][0] == '-')
|
||||
data = wc(stdin);
|
||||
else
|
||||
data = wc(fopen(argv[i],"r"));
|
||||
print_values(argv[i]);
|
||||
}
|
||||
return 0;
|
||||
if(optind == argc)
|
||||
{
|
||||
data = wc(stdin);
|
||||
print_values("stdin");
|
||||
}
|
||||
else for(int i = optind; i<argc; i++)
|
||||
{
|
||||
if(argv[i][0] == '-')
|
||||
data = wc(stdin);
|
||||
else
|
||||
data = wc(fopen(argv[i],"r"));
|
||||
print_values(argv[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue