fixed the formatting

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1480 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Daniel Reinhold 2002-10-10 19:05:58 +00:00
parent 570f7d0456
commit 00d29fe4dd
10 changed files with 444 additions and 531 deletions

View File

@ -1,6 +1,6 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2001-2002, OpenBeOS
// Copyright (c) 2001-2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
@ -47,10 +47,9 @@
#include <sys/stat.h>
void usage (void);
void do_chop (char *);
void chop_file (int, char *, off_t);
void do_chop (char *);
void usage (void);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -65,9 +64,9 @@ static int KBytesPerChunk = 1400; // determines size of output files
void
usage()
{
puts ("usage: chop [-n kbyte_per_chunk] file");
puts ("Splits file into smaller files named file00, file01...");
puts ("Default split size is 1400k");
printf("Usage: chop [-n kbyte_per_chunk] file\n");
printf("Splits file into smaller files named file00, file01...\n");
printf("Default split size is 1400k\n");
}
@ -78,34 +77,27 @@ main (int argc, char *argv[])
char *arg = NULL;
char *first;
if ((argc < 2) || (argc > 4))
{
if ((argc < 2) || (argc > 4)) {
usage();
return 0;
}
first = *++argv;
if (strcmp (first, "--help") == 0)
{
if (strcmp(first, "--help") == 0) {
usage();
return 0;
}
if (strcmp (first, "-n") == 0)
{
if (--argc > 1)
{
if (strcmp(first, "-n") == 0) {
if (--argc > 1) {
char *num = *++argv;
if (!isdigit(*num))
printf("-n option needs a numeric argument\n");
else
{
else {
int b = atoi(num);
if (b < 1) b = 1;
KBytesPerChunk = b;
KBytesPerChunk = (b < 1 ? 1 : b);
if (--argc > 1)
arg = *++argv;
@ -138,23 +130,20 @@ do_chop (char *fname)
int fd;
// input file must exist
if (stat (fname, &e) == -1)
{
if (stat(fname, &e) == -1) {
fprintf(stderr, "'%s': no such file or directory\n", fname);
return;
}
// and it must be not be a directory
if (S_ISDIR (e.st_mode))
{
if (S_ISDIR(e.st_mode)) {
fprintf(stderr, "'%s' is a directory\n", fname);
return;
}
// needs to be big enough such that splitting it actually does something
fsize = e.st_size;
if (fsize < (KBytesPerChunk * 1024))
{
if (fsize < (KBytesPerChunk * 1024)) {
fprintf(stderr, "'%s': file is already small enough\n", fname);
return;
}
@ -162,11 +151,11 @@ do_chop (char *fname)
// also, don't chop up if chunk files are already present
{
char buf[256];
strcpy(buf, fname);
strcat(buf, "00");
if (stat (buf, &e) >= 0)
{
if (stat(buf, &e) >= 0) {
fprintf(stderr, "'%s' already exists - aborting\n", buf);
return;
}
@ -176,8 +165,7 @@ do_chop (char *fname)
fd = open(fname, O_RDONLY);
if (fd < 0)
fprintf(stderr, "can't open '%s': %s\n", fname, strerror(errno));
else
{
else {
chop_file(fd, fname, fsize);
close(fd);
}
@ -206,10 +194,8 @@ chop_file (int fdin, char *fname, off_t fsize)
printf("Chopping up %s into %d kbyte chunks\n", fname, KBytesPerChunk);
while (total_written < fsize)
{
if (beg >= end)
{
while (total_written < fsize) {
if (beg >= end) {
// read in another block
got = read(fdin, Block, BLOCKSIZE);
if (got <= 0)
@ -219,13 +205,12 @@ chop_file (int fdin, char *fname, off_t fsize)
end = Block + got - 1;
}
if (open_next_file)
{
if (open_next_file) {
// start a new output file
sprintf(fnameN, "%s%02d", fname, index++);
fdout = open(fnameN, O_WRONLY|O_CREAT);
if (fdout < 0)
{
if (fdout < 0) {
fprintf(stderr, "unable to create chunk file '%s': %s\n", fnameN, strerror(errno));
return;
}
@ -238,17 +223,15 @@ chop_file (int fdin, char *fname, off_t fsize)
if (needed > avail)
needed = avail;
if (needed > 0)
{
if (needed > 0) {
put = write(fdout, beg, needed);
beg += put;
}
curr_written += put;
total_written += put;
}
if (curr_written >= chunk_size)
{
if (curr_written >= chunk_size) {
// the current output file is full
close(fdout);
open_next_file = true;

View File

@ -1,6 +1,6 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2001-2002, OpenBeOS
// Copyright (c) 2001-2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
@ -8,7 +8,7 @@
//
// File: error.c
// Author: Daniel Reinhold (danielre@users.sf.net)
// Description: displays error message text for OS error codes
// Description: prints error message text for OS error codes
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
@ -26,8 +26,8 @@ int
main(int argc, char *argv[])
{
if (argc != 2)
printf("usage: error number\n"
"Displays the message text for OS error codes. "
printf("Usage: error number\n"
"Prints the message text for OS error codes. "
"The error number can be in decimal, hex or octal.\n");
else
print_error(argv[1]);

View File

@ -1,6 +1,6 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2001-2002, OpenBeOS
// Copyright (c) 2001-2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
@ -19,25 +19,24 @@
#include <sys/stat.h>
void display (uint32, uint8 *);
void do_hd (char *);
void dump_file (FILE *);
void display (uint32, uint8 *);
char *hexbytes (uint8 *);
char *printable (uint8 *);
void usage ();
void usage (void);
int BytesBetweenSpaces = 1;
static int BytesBetweenSpace = 1;
void
usage ()
{
printf ("usage:\thd [-n N] [file]\n");
puts ("\t-n expects a number between 1 and 16 and specifies");
puts ("\tthe number of bytes between spaces.");
puts ("");
puts ("\tIf no file is specified, input is read from stdin");
printf ("Usage:\thd [-n N] [file]\n");
printf("\t-n expects a number between 1 and 16 and specifies\n");
printf("\tthe number of bytes between spaces.\n");
printf("\n\tIf no file is specified, input is read from stdin\n");
}
@ -47,34 +46,28 @@ main (int argc, char *argv[])
char *arg = NULL;
if (argc == 1)
{
dump_file(stdin);
}
else
{
else {
char *first = *++argv;
if (strcmp (first, "--help") == 0)
{
if (strcmp(first, "--help") == 0) {
usage();
return 0;
}
if (strcmp (first, "-n") == 0)
{
if (--argc > 1)
{
if (strcmp(first, "-n") == 0) {
if (--argc > 1) {
char *num = *++argv;
if (!isdigit(*num))
printf("-n option needs a numeric argument\n");
else
{
else {
int b = atoi(num);
if (b < 1) b = 1;
if (b > 16) b = 16;
BytesBetweenSpaces = b;
BytesBetweenSpace = b;
if (--argc > 1)
arg = *++argv;
@ -102,19 +95,16 @@ do_hd (char *fname)
{
struct stat e;
if (stat (fname, &e) == -1)
{
if (stat(fname, &e) == -1) {
fprintf(stderr, "'%s': no such file or directory\n", fname);
return;
}
if (S_ISDIR(e.st_mode))
fprintf(stderr, "'%s' is a directory\n", fname);
else
{
else {
FILE *fp = fopen(fname, "rb");
if (fp)
{
if (fp) {
dump_file(fp);
fclose(fp);
}
@ -131,14 +121,12 @@ dump_file (FILE *fp)
uint32 offset = 0;
uint8 data[16];
while ((got = fread (data, 1, 16, fp)) == 16)
{
while ((got = fread(data, 1, 16, fp)) == 16) {
display(offset, data);
offset += 16;
}
if (got > 0)
{
if (got > 0) {
memset(data+got, ' ', 16-got);
display(offset, data);
}
@ -165,19 +153,17 @@ hexbytes (uint8 *s)
int i;
int n = 0;
for (i = 0; i < 16; ++i)
{
for (i = 0; i < 16; ++i) {
c = *s++;
*p++ = "0123456789abcdef"[c/16];
*p++ = "0123456789abcdef"[c%16];
if (++n == BytesBetweenSpaces)
{
if (++n == BytesBetweenSpace) {
*p++ = ' ';
n = 0;
}
if ((i == 7) && (BytesBetweenSpaces == 1))
if ((i == 7) && (BytesBetweenSpace == 1))
*p++ = ' ';
}
*p++ = ' ';
@ -191,12 +177,11 @@ char *
printable (uint8 *s)
{
static char buf[16];
int n = 16;
char *p = buf;
uint8 c;
int i = 16;
while (n--)
{
while (i--) {
c = *s++;
*p++ = (isgraph(c) ? c : '.');
}

View File

@ -1,6 +1,6 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2001-2002, OpenBeOS
// Copyright (c) 2001-2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
@ -25,26 +25,20 @@ void show_memory_totals (void);
int
main(int argc, char **argv)
{
//
show_memory_totals();
if (argc == 1)
{
// list for all teams
if (argc == 1) {
int32 cookie = 0;
team_info info;
// list for all teams
while (get_next_team_info(&cookie, &info) >= B_OK)
{
list_area_info(info.team);
}
}
else
// list for each team_id on the command line
while (--argc)
{
list_area_info(atoi(*++argv));
}
return 0;
}
@ -56,8 +50,7 @@ show_memory_totals ()
int32 max = 0, used = 0, left;
system_info sys;
if (get_system_info (&sys) == B_OK)
{
if (get_system_info(&sys) == B_OK) {
// pages are 4KB
max = sys.max_pages * 4;
used = sys.used_pages * 4;
@ -76,8 +69,7 @@ list_area_info (team_id id)
team_info this_team;
area_info this_area;
if (get_team_info (id, &this_team) == B_BAD_TEAM_ID)
{
if (get_team_info(id, &this_team) == B_BAD_TEAM_ID) {
printf("\nteam %d unknown\n", id);
return;
}
@ -86,8 +78,7 @@ list_area_info (team_id id)
printf(" ID name address size alloc. #-cow #-in #-out\n");
printf("--------------------------------------------------------------------------------\n");
while (get_next_area_info (id, &cookie, &this_area) == B_OK)
{
while (get_next_area_info(id, &cookie, &this_area) == B_OK) {
printf("%5d %29s %.8x %8x %8x %5d %5d %5d\n",
this_area.area,
this_area.name,

View File

@ -1,6 +1,6 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2001-2002, OpenBeOS
// Copyright (c) 2001-2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
@ -25,24 +25,18 @@ void list_image_info (team_id id);
int
main(int argc, char **argv)
{
//
if (argc == 1)
{
// list for all teams
if (argc == 1) {
int32 cookie = 0;
team_info info;
// list for all teams
while (get_next_team_info(&cookie, &info) >= B_OK)
{
list_image_info(info.team);
}
}
else
// list for each team_id on the command line
while (--argc)
{
list_image_info(atoi(*++argv));
}
return 0;
}
@ -55,8 +49,7 @@ list_image_info (team_id id)
team_info this_team;
image_info this_image;
if (get_team_info (id, &this_team) == B_BAD_TEAM_ID)
{
if (get_team_info(id, &this_team) == B_BAD_TEAM_ID) {
printf("\nteam %d unknown\n", id);
return;
}
@ -65,8 +58,7 @@ list_image_info (team_id id)
printf(" ID name text data seq# init#\n");
printf("--------------------------------------------------------------------------------------------------------\n");
while (get_next_image_info (id, &cookie, &this_image) == B_OK)
{
while (get_next_image_info(id, &cookie, &this_image) == B_OK) {
printf("%5d %64s %.8x %.8x %4d %10u\n",
this_image.id,
this_image.name,

View File

@ -1,6 +1,6 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2001-2002, OpenBeOS
// Copyright (c) 2001-2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
@ -25,26 +25,20 @@ void show_port_totals (void);
int
main(int argc, char **argv)
{
//
show_port_totals();
if (argc == 1)
{
// list for all teams
if (argc == 1) {
int32 cookie = 0;
team_info info;
// list for all teams
while (get_next_team_info(&cookie, &info) >= B_OK)
{
list_team_ports(info.team);
}
}
else
// list for each team_id on the command line
while (--argc)
{
list_team_ports(atoi(*++argv));
}
return 0;
}
@ -56,8 +50,7 @@ show_port_totals ()
int32 max = 0, used = 0, left;
system_info sys;
if (get_system_info (&sys) == B_OK)
{
if (get_system_info(&sys) == B_OK) {
max = sys.max_ports;
used = sys.used_ports;
}
@ -75,8 +68,7 @@ list_team_ports (team_id id)
port_info this_port;
team_info this_team;
if (get_team_info (id, &this_team) == B_BAD_TEAM_ID)
{
if (get_team_info(id, &this_team) == B_BAD_TEAM_ID) {
printf("\nteam %d unknown\n", id);
return;
}
@ -85,8 +77,7 @@ list_team_ports (team_id id)
printf(" ID name capacity queued\n");
printf("----------------------------------------------------\n");
while (get_next_port_info (id, &cookie, &this_port) == B_OK)
{
while (get_next_port_info(id, &cookie, &this_port) == B_OK) {
printf("%5d %28s %8d %6d\n",
this_port.port,
this_port.name,

View File

@ -1,6 +1,6 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2001-2002, OpenBeOS
// Copyright (c) 2001-2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
@ -29,7 +29,7 @@ main(int argc, char *argv[])
char *arg = (argc == 2 ? argv[1] : NULL);
if ((argc > 2) || (arg && !strcmp(arg, "--help"))) {
printf("usage: printenv [VARIABLE]\n"
printf("Usage: printenv [VARIABLE]\n"
"If no environment VARIABLE is specified, print them all.\n");
return 1;
}
@ -49,8 +49,7 @@ print_env(char *arg)
printf("%s\n", *env++);
return 0;
}
else {
} else {
// print only the value of the specified variable
char *s;
int len = strlen(arg);
@ -65,6 +64,6 @@ print_env(char *arg)
}
}
return found ? 0 : 1;
return (found ? 0 : 1);
}
}

View File

@ -1,6 +1,6 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2001-2002, OpenBeOS
// Copyright (c) 2001-2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
@ -80,7 +80,7 @@ int
main(int argc, char *argv[])
{
if (argc < 2)
printf("usage: printf format [arguments]\n");
printf("Usage: printf format [arguments]\n");
else
do_printf(argc, argv);
@ -108,8 +108,7 @@ do_printf(int argc, char *argv[])
++Format, putchar('%');
else
print_next_arg();
}
else {
} else {
e = escaped(c, &Format);
putchar(e);
}

View File

@ -1,6 +1,6 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2001-2002, OpenBeOS
// Copyright (c) 2001-2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
@ -20,13 +20,12 @@
#include <sys/stat.h>
void usage (void);
void append_file (int, int);
void do_unchop (char *, char *);
void concatenate (int, int);
bool valid_file (char *);
void replace (char *, char *);
char *temp_file ();
void usage (void);
bool valid_file (char *);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -42,27 +41,24 @@ static int Errors = 0;
void
usage()
{
puts ("usage: unchop file");
puts ("Concatenates files named file00, file01... into file");
printf("Usage: unchop file\n");
printf("Concatenates files named file00, file01... into file\n");
}
int
main(int argc, char *argv[])
{
if (argc != 2)
{
if (argc != 2) {
usage();
return 0;
}
else
{
else {
char *origfile = argv[1];
char *tmpfile = origfile;
bool needs_replace = false;
if (valid_file (origfile))
{
if (valid_file(origfile)) {
// output file already exists -- write to temp file
tmpfile = temp_file();
needs_replace = true;
@ -70,8 +66,7 @@ main (int argc, char *argv[])
do_unchop(tmpfile, origfile);
if (needs_replace)
{
if (needs_replace) {
if (Errors == 0)
replace(origfile, tmpfile);
else
@ -79,7 +74,6 @@ main (int argc, char *argv[])
}
}
putchar ('\n');
return Errors;
}
@ -90,31 +84,24 @@ do_unchop (char *outfile, char *basename)
int fdout = open(outfile, O_WRONLY|O_CREAT|O_APPEND);
if (fdout < 0)
fprintf(stderr, "can't open '%s': %s\n", outfile, strerror(errno));
else
{
else {
int i;
char fnameN[256];
for (i = 0; i < 999999; ++i)
{
for (i = 0; i < 999999; ++i) {
sprintf(fnameN, "%s%02d", basename, i);
if (valid_file (fnameN))
{
if (valid_file(fnameN)) {
int fdin = open(fnameN, O_RDONLY);
if (fdin < 0)
{
if (fdin < 0) {
fprintf(stderr, "can't open '%s': %s\n", fnameN, strerror(errno));
++Errors;
}
else
{
concatenate (fdin, fdout);
} else {
append_file(fdin, fdout);
close(fdin);
}
}
else
{
} else {
if (i == 0)
printf("No chunk files present (%s)", fnameN);
break;
@ -126,12 +113,14 @@ do_unchop (char *outfile, char *basename)
void
concatenate (int fdin, int fdout)
append_file(int fdin, int fdout)
{
// appends the entire contents of the input file
// to the output file
ssize_t got;
for (;;)
{
for (;;) {
got = read(fdin, Block, BLOCKSIZE);
if (got <= 0)
break;
@ -150,8 +139,7 @@ valid_file (char *fname)
struct stat e;
if (stat (fname, &e) == -1)
{
if (stat(fname, &e) == -1) {
// no such file
return false;
}
@ -180,6 +168,8 @@ replace (char *origfile, char *newfile)
char *
temp_file()
{
// creates a new, temporary file and returns its name
char *tmp = tmpnam(NULL);
FILE *fp = fopen(tmp, "w");

View File

@ -1,6 +1,6 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2001-2002, OpenBeOS
// Copyright (c) 2001-2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
@ -12,6 +12,7 @@
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#include <OS.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
@ -25,14 +26,13 @@ void display (int, int, int, char *);
// a few globals to brighten your day
int TotalLines = 0;
int TotalWords = 0;
int TotalBytes = 0;
int ShowLines = 1;
int ShowWords = 1;
int ShowBytes = 1;
static int TotalLines = 0;
static int TotalWords = 0;
static int TotalBytes = 0;
static bool ShowLines = true;
static bool ShowWords = true;
static bool ShowBytes = true;
@ -40,40 +40,33 @@ int
main(int argc, char *argv[])
{
if (argc == 1)
{
wc_file(stdin, "");
}
else
{
else {
int i;
int file_count = 0;
int reset_opts = 0;
bool reset_opts = false;
char *arg;
char c;
// pass 1: collect and set the options
for (i = 1; i < argc; ++i)
{
for (i = 1; i < argc; ++i) {
arg = argv[i];
if (arg[0] == '-')
{
if (!reset_opts)
{
ShowLines = ShowWords = ShowBytes = 0;
reset_opts = 1;
if (arg[0] == '-') {
if (!reset_opts) {
ShowLines = ShowWords = ShowBytes = false;
reset_opts = true;
}
while (c = *++arg)
{
if (c == 'l') ShowLines = 1;
else if (c == 'w') ShowWords = 1;
else if (c == 'c') ShowBytes = 1;
while ((c = *++arg) != '\0') {
if (c == 'l') ShowLines = true;
else if (c == 'w') ShowWords = true;
else if (c == 'c') ShowBytes = true;
}
}
}
// pass 2: process filename args
for (i = 1; i < argc; ++i)
{
for (i = 1; i < argc; ++i) {
arg = argv[i];
if (arg[0] != '-')
file_count += do_wc(arg);
@ -83,7 +76,6 @@ main (int argc, char *argv[])
display(TotalLines, TotalWords, TotalBytes, "total");
}
putchar ('\n');
return 0;
}
@ -93,29 +85,22 @@ do_wc (char *fname)
{
struct stat e;
if (stat (fname, &e) == -1)
{
if (stat(fname, &e) == -1) {
fprintf(stderr, "'%s': no such file or directory\n", fname);
return 0;
}
if (S_ISDIR (e.st_mode))
{
if (S_ISDIR(e.st_mode)) {
fprintf(stderr, "'%s' is a directory\n", fname);
display(0, 0, 0, fname);
return 1;
}
else
{
} else {
FILE *fp = fopen(fname, "rb");
if (fp)
{
if (fp) {
wc_file(fp, fname);
fclose(fp);
return 1;
}
else
{
} else {
fprintf(stderr, "'%s': %s\n", fname, strerror(errno));
return 0;
}
@ -133,14 +118,12 @@ wc_file (FILE *fp, char *fname)
int ns = 0; // non-spaces (consecutive count)
int c;
while ((c = fgetc (fp)) != EOF)
{
while ((c = fgetc(fp)) != EOF) {
++bc;
if (c == '\n')
++lc;
if (isspace (c))
{
if (isspace(c)) {
if (ns > 0)
++wc, ns = 0;
}