Skip to content

Commit

Permalink
fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
cospplredman committed Apr 24, 2024
1 parent 5f3d439 commit f153b7b
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/head/head.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
#include "version_info.h"

static const char usage[] = {
"Usage: head [Option]... [File]...\n"
" --version version information\n"
" --help display this help and exit\n"
" -n number of lines to print form each file\n"
" -q, --quiet do not print file headers\n"
};
"Usage: head [Option]... [File]...\n"
" --version version information\n"
" --help display this help and exit\n"
" -n number of lines to print form each file\n"
" -q, --quiet do not print file headers\n"};

// flags
static size_t lines = 10;
Expand All @@ -29,26 +28,24 @@ static struct option long_options[] = {
{"quiet", no_argument, NULL, 'q'},
};


static void print_head(char *path, FILE *file){
static void print_head(char *path, FILE *file) {
size_t nl_count = 0;
int cur_char;

if(path != NULL && verbose)
printf("\n==> %s <==\n", path);
if (path != NULL && verbose)
printf("\n==> %s <==\n", path);

while(nl_count < lines){
if((cur_char = getc(file)) == '\n')
nl_count++;
while (nl_count < lines) {
if ((cur_char = getc(file)) == '\n')
nl_count++;

if(cur_char == EOF)
return;
if (cur_char == EOF)
return;

putchar(cur_char);
putchar(cur_char);
}
}


int main(int argc, char **argv) {
int opt, option_index;
while ((opt = getopt_long(argc, argv, "n:q", long_options, &option_index)) !=
Expand All @@ -64,9 +61,9 @@ int main(int argc, char **argv) {
printf("%s\n", usage);
return EXIT_SUCCESS;
case 'n':
if(sscanf(optarg, "%lu", &lines) != 1){
fprintf(stderr, "head: line count should be a positive integer");
return EXIT_FAILURE;
if (sscanf(optarg, "%lu", &lines) != 1) {
fprintf(stderr, "head: line count should be a positive integer");
return EXIT_FAILURE;
}
break;
case 'q':
Expand All @@ -84,7 +81,7 @@ int main(int argc, char **argv) {
print_head(NULL, stdin);
return EXIT_SUCCESS;
}

if (argc > 1 && verbose)
print_header = 1;

Expand Down

0 comments on commit f153b7b

Please sign in to comment.