fixed the formatting
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1480 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+85
-102
@@ -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
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
@@ -47,10 +47,9 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
void usage (void);
|
void chop_file (int, char *, off_t);
|
||||||
void do_chop (char *);
|
void do_chop (char *);
|
||||||
void chop_file (int, char *, off_t);
|
void usage (void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
@@ -63,73 +62,66 @@ static int KBytesPerChunk = 1400; // determines size of output files
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usage ()
|
usage()
|
||||||
{
|
{
|
||||||
puts ("usage: chop [-n kbyte_per_chunk] file");
|
printf("Usage: chop [-n kbyte_per_chunk] file\n");
|
||||||
puts ("Splits file into smaller files named file00, file01...");
|
printf("Splits file into smaller files named file00, file01...\n");
|
||||||
puts ("Default split size is 1400k");
|
printf("Default split size is 1400k\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *arg = NULL;
|
char *arg = NULL;
|
||||||
char *first;
|
char *first;
|
||||||
|
|
||||||
if ((argc < 2) || (argc > 4))
|
if ((argc < 2) || (argc > 4)) {
|
||||||
{
|
usage();
|
||||||
usage ();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
first = *++argv;
|
first = *++argv;
|
||||||
|
|
||||||
if (strcmp (first, "--help") == 0)
|
if (strcmp(first, "--help") == 0) {
|
||||||
{
|
usage();
|
||||||
usage ();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp (first, "-n") == 0)
|
if (strcmp(first, "-n") == 0) {
|
||||||
{
|
if (--argc > 1) {
|
||||||
if (--argc > 1)
|
|
||||||
{
|
|
||||||
char *num = *++argv;
|
char *num = *++argv;
|
||||||
|
|
||||||
if (!isdigit (*num))
|
if (!isdigit(*num))
|
||||||
printf ("-n option needs a numeric argument\n");
|
printf("-n option needs a numeric argument\n");
|
||||||
else
|
else {
|
||||||
{
|
int b = atoi(num);
|
||||||
int b = atoi (num);
|
KBytesPerChunk = (b < 1 ? 1 : b);
|
||||||
|
|
||||||
if (b < 1) b = 1;
|
|
||||||
KBytesPerChunk = b;
|
|
||||||
|
|
||||||
if (--argc > 1)
|
if (--argc > 1)
|
||||||
arg = *++argv;
|
arg = *++argv;
|
||||||
else
|
else
|
||||||
printf ("no file specified\n");
|
printf("no file specified\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
printf ("-n option needs a numeric argument\n");
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
printf("-n option needs a numeric argument\n");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
arg = first;
|
arg = first;
|
||||||
|
|
||||||
if (arg)
|
if (arg)
|
||||||
do_chop (arg);
|
do_chop(arg);
|
||||||
|
|
||||||
putchar ('\n');
|
putchar ('\n');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
do_chop (char *fname)
|
do_chop(char *fname)
|
||||||
{
|
{
|
||||||
// do some checks for validity
|
// do some checks for validity
|
||||||
// then call chop_file() to do the actual read/writes
|
// then call chop_file() to do the actual read/writes
|
||||||
|
|
||||||
@@ -138,55 +130,51 @@ do_chop (char *fname)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
// input file must exist
|
// input file must exist
|
||||||
if (stat (fname, &e) == -1)
|
if (stat(fname, &e) == -1) {
|
||||||
{
|
fprintf(stderr, "'%s': no such file or directory\n", fname);
|
||||||
fprintf (stderr, "'%s': no such file or directory\n", fname);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// and it must be not be a directory
|
// 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);
|
||||||
fprintf (stderr, "'%s' is a directory\n", fname);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// needs to be big enough such that splitting it actually does something
|
// needs to be big enough such that splitting it actually does something
|
||||||
fsize = e.st_size;
|
fsize = e.st_size;
|
||||||
if (fsize < (KBytesPerChunk * 1024))
|
if (fsize < (KBytesPerChunk * 1024)) {
|
||||||
{
|
fprintf(stderr, "'%s': file is already small enough\n", fname);
|
||||||
fprintf (stderr, "'%s': file is already small enough\n", fname);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// also, don't chop up if chunk files are already present
|
// also, don't chop up if chunk files are already present
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
strcpy (buf, fname);
|
|
||||||
strcat (buf, "00");
|
strcpy(buf, fname);
|
||||||
|
strcat(buf, "00");
|
||||||
if (stat (buf, &e) >= 0)
|
|
||||||
{
|
if (stat(buf, &e) >= 0) {
|
||||||
fprintf (stderr, "'%s' already exists - aborting\n", buf);
|
fprintf(stderr, "'%s' already exists - aborting\n", buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally! chop up the file
|
// finally! chop up the file
|
||||||
fd = open (fname, O_RDONLY);
|
fd = open(fname, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
fprintf (stderr, "can't open '%s': %s\n", fname, strerror (errno));
|
fprintf(stderr, "can't open '%s': %s\n", fname, strerror(errno));
|
||||||
else
|
else {
|
||||||
{
|
chop_file(fd, fname, fsize);
|
||||||
chop_file (fd, fname, fsize);
|
close(fd);
|
||||||
close (fd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
chop_file (int fdin, char *fname, off_t fsize)
|
chop_file(int fdin, char *fname, off_t fsize)
|
||||||
{
|
{
|
||||||
const off_t chunk_size = KBytesPerChunk * 1024; // max bytes written to any output file
|
const off_t chunk_size = KBytesPerChunk * 1024; // max bytes written to any output file
|
||||||
|
|
||||||
bool open_next_file = true; // when to open a new output file
|
bool open_next_file = true; // when to open a new output file
|
||||||
@@ -204,57 +192,52 @@ chop_file (int fdin, char *fname, off_t fsize)
|
|||||||
char *beg = Block; // pointer to the beginning of the block data to be written out
|
char *beg = Block; // pointer to the beginning of the block data to be written out
|
||||||
char *end = Block; // end of the current block (init to beginning to force first block read)
|
char *end = Block; // end of the current block (init to beginning to force first block read)
|
||||||
|
|
||||||
printf ("Chopping up %s into %d kbyte chunks\n", fname, KBytesPerChunk);
|
printf("Chopping up %s into %d kbyte chunks\n", fname, KBytesPerChunk);
|
||||||
|
|
||||||
while (total_written < fsize)
|
while (total_written < fsize) {
|
||||||
{
|
if (beg >= end) {
|
||||||
if (beg >= end)
|
|
||||||
{
|
|
||||||
// read in another block
|
// read in another block
|
||||||
got = read (fdin, Block, BLOCKSIZE);
|
got = read(fdin, Block, BLOCKSIZE);
|
||||||
if (got <= 0)
|
if (got <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
beg = Block;
|
beg = Block;
|
||||||
end = Block + got - 1;
|
end = Block + got - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (open_next_file)
|
if (open_next_file) {
|
||||||
{
|
|
||||||
// start a new output file
|
// start a new output file
|
||||||
sprintf (fnameN, "%s%02d", fname, index++);
|
sprintf(fnameN, "%s%02d", fname, index++);
|
||||||
fdout = open (fnameN, O_WRONLY|O_CREAT);
|
|
||||||
if (fdout < 0)
|
fdout = open(fnameN, O_WRONLY|O_CREAT);
|
||||||
{
|
if (fdout < 0) {
|
||||||
fprintf (stderr, "unable to create chunk file '%s': %s\n", fnameN, strerror (errno));
|
fprintf(stderr, "unable to create chunk file '%s': %s\n", fnameN, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
curr_written = 0;
|
curr_written = 0;
|
||||||
open_next_file = false;
|
open_next_file = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
needed = chunk_size - curr_written;
|
needed = chunk_size - curr_written;
|
||||||
avail = end - beg + 1;
|
avail = end - beg + 1;
|
||||||
if (needed > avail)
|
if (needed > avail)
|
||||||
needed = avail;
|
needed = avail;
|
||||||
|
|
||||||
if (needed > 0)
|
if (needed > 0) {
|
||||||
{
|
put = write(fdout, beg, needed);
|
||||||
put = write (fdout, beg, needed);
|
|
||||||
beg += put;
|
beg += put;
|
||||||
}
|
|
||||||
|
curr_written += put;
|
||||||
curr_written += put;
|
total_written += put;
|
||||||
total_written += put;
|
|
||||||
|
|
||||||
if (curr_written >= chunk_size)
|
|
||||||
{
|
|
||||||
// the current output file is full
|
|
||||||
close (fdout);
|
|
||||||
open_next_file = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (curr_written >= chunk_size) {
|
||||||
|
// the current output file is full
|
||||||
|
close(fdout);
|
||||||
|
open_next_file = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// close up the last output file
|
// close up the last output file
|
||||||
close (fdout);
|
close(fdout);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
//
|
//
|
||||||
// File: error.c
|
// File: error.c
|
||||||
// Author: Daniel Reinhold ([email protected])
|
// Author: Daniel Reinhold ([email protected])
|
||||||
// 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[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
printf("usage: error number\n"
|
printf("Usage: error number\n"
|
||||||
"Displays the message text for OS error codes. "
|
"Prints the message text for OS error codes. "
|
||||||
"The error number can be in decimal, hex or octal.\n");
|
"The error number can be in decimal, hex or octal.\n");
|
||||||
else
|
else
|
||||||
print_error(argv[1]);
|
print_error(argv[1]);
|
||||||
|
|||||||
+85
-100
@@ -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
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
@@ -19,188 +19,173 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
void do_hd (char *);
|
void display (uint32, uint8 *);
|
||||||
void dump_file (FILE *);
|
void do_hd (char *);
|
||||||
void display (uint32, uint8 *);
|
void dump_file (FILE *);
|
||||||
char *hexbytes (uint8 *);
|
char *hexbytes (uint8 *);
|
||||||
char *printable (uint8 *);
|
char *printable (uint8 *);
|
||||||
void usage ();
|
void usage (void);
|
||||||
|
|
||||||
|
|
||||||
int BytesBetweenSpaces = 1;
|
static int BytesBetweenSpace = 1;
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usage ()
|
usage ()
|
||||||
{
|
{
|
||||||
printf ("usage:\thd [-n N] [file]\n");
|
printf ("Usage:\thd [-n N] [file]\n");
|
||||||
puts ("\t-n expects a number between 1 and 16 and specifies");
|
printf("\t-n expects a number between 1 and 16 and specifies\n");
|
||||||
puts ("\tthe number of bytes between spaces.");
|
printf("\tthe number of bytes between spaces.\n");
|
||||||
puts ("");
|
printf("\n\tIf no file is specified, input is read from stdin\n");
|
||||||
puts ("\tIf no file is specified, input is read from stdin");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *arg = NULL;
|
char *arg = NULL;
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
dump_file(stdin);
|
||||||
dump_file (stdin);
|
|
||||||
}
|
else {
|
||||||
else
|
|
||||||
{
|
|
||||||
char *first = *++argv;
|
char *first = *++argv;
|
||||||
|
|
||||||
if (strcmp (first, "--help") == 0)
|
if (strcmp(first, "--help") == 0) {
|
||||||
{
|
usage();
|
||||||
usage ();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp (first, "-n") == 0)
|
if (strcmp(first, "-n") == 0) {
|
||||||
{
|
if (--argc > 1) {
|
||||||
if (--argc > 1)
|
|
||||||
{
|
|
||||||
char *num = *++argv;
|
char *num = *++argv;
|
||||||
|
|
||||||
if (!isdigit (*num))
|
if (!isdigit(*num))
|
||||||
printf ("-n option needs a numeric argument\n");
|
printf("-n option needs a numeric argument\n");
|
||||||
else
|
else {
|
||||||
{
|
int b = atoi(num);
|
||||||
int b = atoi (num);
|
|
||||||
|
|
||||||
if (b < 1) b = 1;
|
if (b < 1) b = 1;
|
||||||
if (b > 16) b = 16;
|
if (b > 16) b = 16;
|
||||||
BytesBetweenSpaces = b;
|
BytesBetweenSpace = b;
|
||||||
|
|
||||||
if (--argc > 1)
|
if (--argc > 1)
|
||||||
arg = *++argv;
|
arg = *++argv;
|
||||||
else
|
else
|
||||||
printf ("no file specified\n");
|
printf("no file specified\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
printf ("-n option needs a numeric argument\n");
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
printf("-n option needs a numeric argument\n");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
arg = first;
|
arg = first;
|
||||||
|
|
||||||
if (arg)
|
if (arg)
|
||||||
do_hd (arg);
|
do_hd(arg);
|
||||||
}
|
|
||||||
|
|
||||||
putchar ('\n');
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
putchar('\n');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
do_hd (char *fname)
|
do_hd(char *fname)
|
||||||
{
|
{
|
||||||
struct stat e;
|
struct stat e;
|
||||||
|
|
||||||
if (stat (fname, &e) == -1)
|
if (stat(fname, &e) == -1) {
|
||||||
{
|
fprintf(stderr, "'%s': no such file or directory\n", fname);
|
||||||
fprintf (stderr, "'%s': no such file or directory\n", fname);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (S_ISDIR (e.st_mode))
|
|
||||||
fprintf (stderr, "'%s' is a directory\n", fname);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FILE *fp = fopen (fname, "rb");
|
|
||||||
if (fp)
|
|
||||||
{
|
|
||||||
dump_file (fp);
|
|
||||||
fclose (fp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fprintf (stderr, "'%s': %s\n", fname, strerror (errno));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (S_ISDIR(e.st_mode))
|
||||||
|
fprintf(stderr, "'%s' is a directory\n", fname);
|
||||||
|
else {
|
||||||
|
FILE *fp = fopen(fname, "rb");
|
||||||
|
if (fp) {
|
||||||
|
dump_file(fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fprintf(stderr, "'%s': %s\n", fname, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
dump_file (FILE *fp)
|
dump_file(FILE *fp)
|
||||||
{
|
{
|
||||||
size_t got;
|
size_t got;
|
||||||
uint32 offset = 0;
|
uint32 offset = 0;
|
||||||
uint8 data[16];
|
uint8 data[16];
|
||||||
|
|
||||||
while ((got = fread (data, 1, 16, fp)) == 16)
|
while ((got = fread(data, 1, 16, fp)) == 16) {
|
||||||
{
|
display(offset, data);
|
||||||
display (offset, data);
|
|
||||||
offset += 16;
|
offset += 16;
|
||||||
}
|
|
||||||
|
|
||||||
if (got > 0)
|
|
||||||
{
|
|
||||||
memset (data+got, ' ', 16-got);
|
|
||||||
display (offset, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (got > 0) {
|
||||||
|
memset(data+got, ' ', 16-got);
|
||||||
|
display(offset, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
display (uint32 offset, uint8 *data)
|
display(uint32 offset, uint8 *data)
|
||||||
{
|
{
|
||||||
printf ("%08x ", offset);
|
printf("%08x ", offset);
|
||||||
printf (" %s ", hexbytes (data));
|
printf(" %s ", hexbytes(data));
|
||||||
printf ("%16s ", printable (data));
|
printf("%16s ", printable(data));
|
||||||
|
|
||||||
putchar ('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
hexbytes (uint8 *s)
|
hexbytes(uint8 *s)
|
||||||
{
|
{
|
||||||
static char buf[64];
|
static char buf[64];
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
uint8 c;
|
uint8 c;
|
||||||
int i;
|
int i;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
for (i = 0; i < 16; ++i)
|
for (i = 0; i < 16; ++i) {
|
||||||
{
|
|
||||||
c = *s++;
|
c = *s++;
|
||||||
*p++ = "0123456789abcdef"[c/16];
|
*p++ = "0123456789abcdef"[c/16];
|
||||||
*p++ = "0123456789abcdef"[c%16];
|
*p++ = "0123456789abcdef"[c%16];
|
||||||
|
|
||||||
if (++n == BytesBetweenSpaces)
|
if (++n == BytesBetweenSpace) {
|
||||||
{
|
|
||||||
*p++ = ' ';
|
*p++ = ' ';
|
||||||
n = 0;
|
n = 0;
|
||||||
}
|
|
||||||
|
|
||||||
if ((i == 7) && (BytesBetweenSpaces == 1))
|
|
||||||
*p++ = ' ';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((i == 7) && (BytesBetweenSpace == 1))
|
||||||
|
*p++ = ' ';
|
||||||
|
}
|
||||||
*p++ = ' ';
|
*p++ = ' ';
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
printable (uint8 *s)
|
printable (uint8 *s)
|
||||||
{
|
{
|
||||||
static char buf[16];
|
static char buf[16];
|
||||||
int n = 16;
|
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
uint8 c;
|
uint8 c;
|
||||||
|
int i = 16;
|
||||||
|
|
||||||
while (n--)
|
while (i--) {
|
||||||
{
|
|
||||||
c = *s++;
|
c = *s++;
|
||||||
*p++ = (isgraph (c) ? c : '.');
|
*p++ = (isgraph(c) ? c : '.');
|
||||||
}
|
}
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-50
@@ -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
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
@@ -23,80 +23,71 @@ void show_memory_totals (void);
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
//
|
show_memory_totals();
|
||||||
show_memory_totals ();
|
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1) {
|
||||||
{
|
|
||||||
// list for all teams
|
|
||||||
int32 cookie = 0;
|
int32 cookie = 0;
|
||||||
team_info info;
|
team_info info;
|
||||||
|
|
||||||
while (get_next_team_info (&cookie, &info) >= B_OK)
|
// list for all teams
|
||||||
{
|
while (get_next_team_info(&cookie, &info) >= B_OK)
|
||||||
list_area_info (info.team);
|
list_area_info(info.team);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
// list for each team_id on the command line
|
// list for each team_id on the command line
|
||||||
while (--argc)
|
while (--argc)
|
||||||
{
|
list_area_info(atoi(*++argv));
|
||||||
list_area_info (atoi (*++argv));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
show_memory_totals ()
|
show_memory_totals()
|
||||||
{
|
{
|
||||||
int32 max = 0, used = 0, left;
|
int32 max = 0, used = 0, left;
|
||||||
system_info sys;
|
system_info sys;
|
||||||
|
|
||||||
if (get_system_info (&sys) == B_OK)
|
if (get_system_info(&sys) == B_OK) {
|
||||||
{
|
|
||||||
// pages are 4KB
|
// pages are 4KB
|
||||||
max = sys.max_pages * 4;
|
max = sys.max_pages * 4;
|
||||||
used = sys.used_pages * 4;
|
used = sys.used_pages * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
left = max - used;
|
left = max - used;
|
||||||
|
|
||||||
printf ("memory: total: %4dKB, used: %4dKB, left: %4dKB\n", max, used, left);
|
printf("memory: total: %4dKB, used: %4dKB, left: %4dKB\n", max, used, left);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
list_area_info (team_id id)
|
list_area_info(team_id id)
|
||||||
{
|
{
|
||||||
int32 cookie = 0;
|
int32 cookie = 0;
|
||||||
team_info this_team;
|
team_info this_team;
|
||||||
area_info this_area;
|
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);
|
||||||
printf ("\nteam %d unknown\n", id);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
printf ("\nTEAM %4d (%s):\n", id, this_team.args);
|
|
||||||
printf (" ID name address size alloc. #-cow #-in #-out\n");
|
|
||||||
printf ("--------------------------------------------------------------------------------\n");
|
|
||||||
|
|
||||||
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,
|
|
||||||
this_area.address,
|
|
||||||
this_area.size,
|
|
||||||
this_area.ram_size,
|
|
||||||
this_area.copy_count,
|
|
||||||
this_area.in_count,
|
|
||||||
this_area.out_count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("\nTEAM %4d (%s):\n", id, this_team.args);
|
||||||
|
printf(" ID name address size alloc. #-cow #-in #-out\n");
|
||||||
|
printf("--------------------------------------------------------------------------------\n");
|
||||||
|
|
||||||
|
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,
|
||||||
|
this_area.address,
|
||||||
|
this_area.size,
|
||||||
|
this_area.ram_size,
|
||||||
|
this_area.copy_count,
|
||||||
|
this_area.in_count,
|
||||||
|
this_area.out_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+33
-41
@@ -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
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
@@ -18,62 +18,54 @@
|
|||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
|
|
||||||
void list_image_info (team_id id);
|
void list_image_info (team_id id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
//
|
if (argc == 1) {
|
||||||
if (argc == 1)
|
|
||||||
{
|
|
||||||
// list for all teams
|
|
||||||
int32 cookie = 0;
|
int32 cookie = 0;
|
||||||
team_info info;
|
team_info info;
|
||||||
|
|
||||||
while (get_next_team_info (&cookie, &info) >= B_OK)
|
// list for all teams
|
||||||
{
|
while (get_next_team_info(&cookie, &info) >= B_OK)
|
||||||
list_image_info (info.team);
|
list_image_info(info.team);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
// list for each team_id on the command line
|
// list for each team_id on the command line
|
||||||
while (--argc)
|
while (--argc)
|
||||||
{
|
list_image_info(atoi(*++argv));
|
||||||
list_image_info (atoi (*++argv));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
list_image_info (team_id id)
|
list_image_info(team_id id)
|
||||||
{
|
{
|
||||||
int32 cookie = 0;
|
int32 cookie = 0;
|
||||||
team_info this_team;
|
team_info this_team;
|
||||||
image_info this_image;
|
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);
|
||||||
printf ("\nteam %d unknown\n", id);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
printf ("\nTEAM %4d (%s):\n", id, this_team.args);
|
|
||||||
printf (" ID name text data seq# init#\n");
|
|
||||||
printf ("--------------------------------------------------------------------------------------------------------\n");
|
|
||||||
|
|
||||||
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,
|
|
||||||
this_image.text,
|
|
||||||
this_image.data,
|
|
||||||
this_image.sequence,
|
|
||||||
this_image.init_order);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("\nTEAM %4d (%s):\n", id, this_team.args);
|
||||||
|
printf(" ID name text data seq# init#\n");
|
||||||
|
printf("--------------------------------------------------------------------------------------------------------\n");
|
||||||
|
|
||||||
|
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,
|
||||||
|
this_image.text,
|
||||||
|
this_image.data,
|
||||||
|
this_image.sequence,
|
||||||
|
this_image.init_order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+34
-43
@@ -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
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
@@ -23,75 +23,66 @@ void show_port_totals (void);
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
//
|
show_port_totals();
|
||||||
show_port_totals ();
|
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1) {
|
||||||
{
|
|
||||||
// list for all teams
|
|
||||||
int32 cookie = 0;
|
int32 cookie = 0;
|
||||||
team_info info;
|
team_info info;
|
||||||
|
|
||||||
while (get_next_team_info (&cookie, &info) >= B_OK)
|
// list for all teams
|
||||||
{
|
while (get_next_team_info(&cookie, &info) >= B_OK)
|
||||||
list_team_ports (info.team);
|
list_team_ports(info.team);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
// list for each team_id on the command line
|
// list for each team_id on the command line
|
||||||
while (--argc)
|
while (--argc)
|
||||||
{
|
list_team_ports(atoi(*++argv));
|
||||||
list_team_ports (atoi (*++argv));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
show_port_totals ()
|
show_port_totals()
|
||||||
{
|
{
|
||||||
int32 max = 0, used = 0, left;
|
int32 max = 0, used = 0, left;
|
||||||
system_info sys;
|
system_info sys;
|
||||||
|
|
||||||
if (get_system_info (&sys) == B_OK)
|
if (get_system_info(&sys) == B_OK) {
|
||||||
{
|
|
||||||
max = sys.max_ports;
|
max = sys.max_ports;
|
||||||
used = sys.used_ports;
|
used = sys.used_ports;
|
||||||
}
|
}
|
||||||
|
|
||||||
left = max - used;
|
left = max - used;
|
||||||
|
|
||||||
printf ("port: total: %5d, used: %5d, left: %5d\n", max, used, left);
|
printf("port: total: %5d, used: %5d, left: %5d\n", max, used, left);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
list_team_ports (team_id id)
|
list_team_ports(team_id id)
|
||||||
{
|
{
|
||||||
int32 cookie = 0;
|
int32 cookie = 0;
|
||||||
port_info this_port;
|
port_info this_port;
|
||||||
team_info this_team;
|
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);
|
||||||
printf ("\nteam %d unknown\n", id);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
printf ("\nTEAM %4d (%s):\n", id, this_team.args);
|
|
||||||
printf (" ID name capacity queued\n");
|
|
||||||
printf ("----------------------------------------------------\n");
|
|
||||||
|
|
||||||
while (get_next_port_info (id, &cookie, &this_port) == B_OK)
|
|
||||||
{
|
|
||||||
printf ("%5d %28s %8d %6d\n",
|
|
||||||
this_port.port,
|
|
||||||
this_port.name,
|
|
||||||
this_port.capacity,
|
|
||||||
this_port.queue_count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("\nTEAM %4d (%s):\n", id, this_team.args);
|
||||||
|
printf(" ID name capacity queued\n");
|
||||||
|
printf("----------------------------------------------------\n");
|
||||||
|
|
||||||
|
while (get_next_port_info(id, &cookie, &this_port) == B_OK) {
|
||||||
|
printf("%5d %28s %8d %6d\n",
|
||||||
|
this_port.port,
|
||||||
|
this_port.name,
|
||||||
|
this_port.capacity,
|
||||||
|
this_port.queue_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-10
@@ -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
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
@@ -29,7 +29,7 @@ main(int argc, char *argv[])
|
|||||||
char *arg = (argc == 2 ? argv[1] : NULL);
|
char *arg = (argc == 2 ? argv[1] : NULL);
|
||||||
|
|
||||||
if ((argc > 2) || (arg && !strcmp(arg, "--help"))) {
|
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");
|
"If no environment VARIABLE is specified, print them all.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -45,26 +45,25 @@ print_env(char *arg)
|
|||||||
|
|
||||||
if (arg == NULL) {
|
if (arg == NULL) {
|
||||||
// print all environment 'key=value' pairs (one per line)
|
// print all environment 'key=value' pairs (one per line)
|
||||||
while (*env)
|
while (*env)
|
||||||
printf("%s\n", *env++);
|
printf("%s\n", *env++);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// print only the value of the specified variable
|
// print only the value of the specified variable
|
||||||
char *s;
|
char *s;
|
||||||
int len = strlen(arg);
|
int len = strlen(arg);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
while ((s = *env++) != NULL)
|
while ((s = *env++) != NULL)
|
||||||
if (!strncmp(s, arg, len)) {
|
if (!strncmp(s, arg, len)) {
|
||||||
char *p = strchr(s, '=');
|
char *p = strchr(s, '=');
|
||||||
if (p) {
|
if (p) {
|
||||||
printf("%s\n", p+1);
|
printf("%s\n", p+1);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return found ? 0 : 1;
|
return (found ? 0 : 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-13
@@ -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
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
@@ -80,7 +80,7 @@ int
|
|||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
printf("usage: printf format [arguments]\n");
|
printf("Usage: printf format [arguments]\n");
|
||||||
else
|
else
|
||||||
do_printf(argc, argv);
|
do_printf(argc, argv);
|
||||||
|
|
||||||
@@ -108,8 +108,7 @@ do_printf(int argc, char *argv[])
|
|||||||
++Format, putchar('%');
|
++Format, putchar('%');
|
||||||
else
|
else
|
||||||
print_next_arg();
|
print_next_arg();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
e = escaped(c, &Format);
|
e = escaped(c, &Format);
|
||||||
putchar(e);
|
putchar(e);
|
||||||
}
|
}
|
||||||
@@ -194,7 +193,7 @@ get_next_specifier(char *spec_buffer, int buflen)
|
|||||||
if (++len > buflen)
|
if (++len > buflen)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (isalpha (c) || c == '%' || c == '\\') {
|
if (isalpha(c) || c == '%' || c == '\\') {
|
||||||
fc = c;
|
fc = c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -272,13 +271,13 @@ print_escaped_string(char *fmt, char *s)
|
|||||||
char c;
|
char c;
|
||||||
char e;
|
char e;
|
||||||
|
|
||||||
while (lpad-- > 0) putchar (' '); // pad on the left
|
while (lpad-- > 0) putchar(' '); // pad on the left
|
||||||
while (len-- > 0) {
|
while (len-- > 0) {
|
||||||
c = *s++;
|
c = *s++;
|
||||||
e = escaped(c, &s);
|
e = escaped(c, &s);
|
||||||
putchar(e);
|
putchar(e);
|
||||||
}
|
}
|
||||||
while (rpad-- > 0) putchar (' '); // pad on the right
|
while (rpad-- > 0) putchar(' '); // pad on the right
|
||||||
}
|
}
|
||||||
|
|
||||||
if (halt)
|
if (halt)
|
||||||
@@ -383,7 +382,7 @@ escaped(char c, char **src)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
get_decimal (char **src)
|
get_decimal(char **src)
|
||||||
{
|
{
|
||||||
// grabs a decimal integer value from the source string
|
// grabs a decimal integer value from the source string
|
||||||
// and returns the full computed value.
|
// and returns the full computed value.
|
||||||
@@ -394,7 +393,7 @@ get_decimal (char **src)
|
|||||||
char c;
|
char c;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
while (isdigit (c = *s)) {
|
while (isdigit(c = *s)) {
|
||||||
++s;
|
++s;
|
||||||
n = n * 10 + (c - '0');
|
n = n * 10 + (c - '0');
|
||||||
}
|
}
|
||||||
@@ -407,7 +406,7 @@ get_decimal (char **src)
|
|||||||
#define isodigit(c) (isdigit(c) && !(c == '8' || c == '9'))
|
#define isodigit(c) (isdigit(c) && !(c == '8' || c == '9'))
|
||||||
|
|
||||||
bool
|
bool
|
||||||
parse_octal (char **src, int min_digits, int max_digits, char *octval)
|
parse_octal(char **src, int min_digits, int max_digits, char *octval)
|
||||||
{
|
{
|
||||||
// searches for an octal value in the source string.
|
// searches for an octal value in the source string.
|
||||||
// returns true if valid octal digits were found
|
// returns true if valid octal digits were found
|
||||||
@@ -427,7 +426,7 @@ parse_octal (char **src, int min_digits, int max_digits, char *octval)
|
|||||||
|
|
||||||
for (i = 0; i < max_digits; ++i) {
|
for (i = 0; i < max_digits; ++i) {
|
||||||
c = *s;
|
c = *s;
|
||||||
if (isodigit (c)) {
|
if (isodigit(c)) {
|
||||||
++s;
|
++s;
|
||||||
n = n * 8 + (c - '0');
|
n = n * 8 + (c - '0');
|
||||||
}
|
}
|
||||||
@@ -446,7 +445,7 @@ parse_octal (char **src, int min_digits, int max_digits, char *octval)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
parse_hex (char **src, int min_digits, int max_digits, char *hexval)
|
parse_hex(char **src, int min_digits, int max_digits, char *hexval)
|
||||||
{
|
{
|
||||||
// searches for a hex value in the source string.
|
// searches for a hex value in the source string.
|
||||||
// returns true if valid hex digits were found
|
// returns true if valid hex digits were found
|
||||||
@@ -466,7 +465,7 @@ parse_hex (char **src, int min_digits, int max_digits, char *hexval)
|
|||||||
|
|
||||||
for (i = 0; i < max_digits; ++i) {
|
for (i = 0; i < max_digits; ++i) {
|
||||||
c = tolower(*s);
|
c = tolower(*s);
|
||||||
if (isxdigit (c)) {
|
if (isxdigit(c)) {
|
||||||
++s;
|
++s;
|
||||||
n *= 16;
|
n *= 16;
|
||||||
if (c > '9')
|
if (c > '9')
|
||||||
|
|||||||
+77
-87
@@ -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
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
@@ -20,13 +20,12 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
void usage (void);
|
void append_file (int, int);
|
||||||
void do_unchop (char *, char *);
|
void do_unchop (char *, char *);
|
||||||
void concatenate (int, int);
|
|
||||||
bool valid_file (char *);
|
|
||||||
void replace (char *, char *);
|
void replace (char *, char *);
|
||||||
char *temp_file ();
|
char *temp_file ();
|
||||||
|
void usage (void);
|
||||||
|
bool valid_file (char *);
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
@@ -40,150 +39,141 @@ static int Errors = 0;
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usage ()
|
usage()
|
||||||
{
|
{
|
||||||
puts ("usage: unchop file");
|
printf("Usage: unchop file\n");
|
||||||
puts ("Concatenates files named file00, file01... into file");
|
printf("Concatenates files named file00, file01... into file\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 2)
|
if (argc != 2) {
|
||||||
{
|
usage();
|
||||||
usage ();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
char *origfile = argv[1];
|
char *origfile = argv[1];
|
||||||
char *tmpfile = origfile;
|
char *tmpfile = origfile;
|
||||||
bool needs_replace = false;
|
bool needs_replace = false;
|
||||||
|
|
||||||
if (valid_file (origfile))
|
if (valid_file(origfile)) {
|
||||||
{
|
|
||||||
// output file already exists -- write to temp file
|
// output file already exists -- write to temp file
|
||||||
tmpfile = temp_file ();
|
tmpfile = temp_file();
|
||||||
needs_replace = true;
|
needs_replace = true;
|
||||||
}
|
|
||||||
|
|
||||||
do_unchop (tmpfile, origfile);
|
|
||||||
|
|
||||||
if (needs_replace)
|
|
||||||
{
|
|
||||||
if (Errors == 0)
|
|
||||||
replace (origfile, tmpfile);
|
|
||||||
else
|
|
||||||
remove (tmpfile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
putchar ('\n');
|
do_unchop(tmpfile, origfile);
|
||||||
return Errors;
|
|
||||||
|
if (needs_replace) {
|
||||||
|
if (Errors == 0)
|
||||||
|
replace(origfile, tmpfile);
|
||||||
|
else
|
||||||
|
remove(tmpfile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
do_unchop (char *outfile, char *basename)
|
do_unchop(char *outfile, char *basename)
|
||||||
{
|
{
|
||||||
int fdout = open (outfile, O_WRONLY|O_CREAT|O_APPEND);
|
int fdout = open(outfile, O_WRONLY|O_CREAT|O_APPEND);
|
||||||
if (fdout < 0)
|
if (fdout < 0)
|
||||||
fprintf (stderr, "can't open '%s': %s\n", outfile, strerror (errno));
|
fprintf(stderr, "can't open '%s': %s\n", outfile, strerror(errno));
|
||||||
else
|
|
||||||
{
|
else {
|
||||||
int i;
|
int i;
|
||||||
char fnameN[256];
|
char fnameN[256];
|
||||||
|
|
||||||
for (i = 0; i < 999999; ++i)
|
for (i = 0; i < 999999; ++i) {
|
||||||
{
|
sprintf(fnameN, "%s%02d", basename, i);
|
||||||
sprintf (fnameN, "%s%02d", basename, i);
|
|
||||||
|
|
||||||
if (valid_file (fnameN))
|
if (valid_file(fnameN)) {
|
||||||
{
|
int fdin = open(fnameN, O_RDONLY);
|
||||||
int fdin = open (fnameN, O_RDONLY);
|
if (fdin < 0) {
|
||||||
if (fdin < 0)
|
fprintf(stderr, "can't open '%s': %s\n", fnameN, strerror(errno));
|
||||||
{
|
|
||||||
fprintf (stderr, "can't open '%s': %s\n", fnameN, strerror (errno));
|
|
||||||
++Errors;
|
++Errors;
|
||||||
}
|
} else {
|
||||||
else
|
append_file(fdin, fdout);
|
||||||
{
|
close(fdin);
|
||||||
concatenate (fdin, fdout);
|
|
||||||
close (fdin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
printf ("No chunk files present (%s)", fnameN);
|
printf("No chunk files present (%s)", fnameN);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
close (fdout);
|
|
||||||
}
|
}
|
||||||
|
close(fdout);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
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;
|
ssize_t got;
|
||||||
|
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
got = read(fdin, Block, BLOCKSIZE);
|
||||||
got = read (fdin, Block, BLOCKSIZE);
|
|
||||||
if (got <= 0)
|
if (got <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
write (fdout, Block, got);
|
write(fdout, Block, got);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
valid_file (char *fname)
|
valid_file(char *fname)
|
||||||
{
|
{
|
||||||
// for this program, a valid file is one that:
|
// for this program, a valid file is one that:
|
||||||
// a) exists (that always helps)
|
// a) exists (that always helps)
|
||||||
// b) is a regular file (not a directory, link, etc.)
|
// b) is a regular file (not a directory, link, etc.)
|
||||||
|
|
||||||
struct stat e;
|
struct stat e;
|
||||||
|
|
||||||
if (stat (fname, &e) == -1)
|
if (stat(fname, &e) == -1) {
|
||||||
{
|
|
||||||
// no such file
|
// no such file
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return (S_ISREG (e.st_mode));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (S_ISREG(e.st_mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
replace (char *origfile, char *newfile)
|
replace(char *origfile, char *newfile)
|
||||||
{
|
{
|
||||||
// replace the contents of the original file
|
// replace the contents of the original file
|
||||||
// with the contents of the new file
|
// with the contents of the new file
|
||||||
|
|
||||||
char buf[1000];
|
char buf[1000];
|
||||||
|
|
||||||
// delete the original file
|
// delete the original file
|
||||||
remove (origfile);
|
remove(origfile);
|
||||||
|
|
||||||
// rename the new file to the original file name
|
// rename the new file to the original file name
|
||||||
sprintf (buf, "mv \"%s\" \"%s\"", newfile, origfile);
|
sprintf(buf, "mv \"%s\" \"%s\"", newfile, origfile);
|
||||||
system (buf);
|
system(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
temp_file ()
|
temp_file()
|
||||||
{
|
{
|
||||||
char *tmp = tmpnam (NULL);
|
// creates a new, temporary file and returns its name
|
||||||
|
|
||||||
FILE *fp = fopen (tmp, "w");
|
char *tmp = tmpnam(NULL);
|
||||||
fclose (fp);
|
|
||||||
|
FILE *fp = fopen(tmp, "w");
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|||||||
+64
-81
@@ -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
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
//
|
//
|
||||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||||
|
|
||||||
|
#include <OS.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -25,107 +26,91 @@ void display (int, int, int, char *);
|
|||||||
|
|
||||||
// a few globals to brighten your day
|
// a few globals to brighten your day
|
||||||
|
|
||||||
int TotalLines = 0;
|
static int TotalLines = 0;
|
||||||
int TotalWords = 0;
|
static int TotalWords = 0;
|
||||||
int TotalBytes = 0;
|
static int TotalBytes = 0;
|
||||||
|
|
||||||
int ShowLines = 1;
|
|
||||||
int ShowWords = 1;
|
|
||||||
int ShowBytes = 1;
|
|
||||||
|
|
||||||
|
static bool ShowLines = true;
|
||||||
|
static bool ShowWords = true;
|
||||||
|
static bool ShowBytes = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
wc_file(stdin, "");
|
||||||
wc_file (stdin, "");
|
|
||||||
}
|
else {
|
||||||
else
|
int i;
|
||||||
{
|
int file_count = 0;
|
||||||
int i;
|
bool reset_opts = false;
|
||||||
int file_count = 0;
|
|
||||||
int reset_opts = 0;
|
|
||||||
char *arg;
|
char *arg;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
// pass 1: collect and set the options
|
// pass 1: collect and set the options
|
||||||
for (i = 1; i < argc; ++i)
|
for (i = 1; i < argc; ++i) {
|
||||||
{
|
|
||||||
arg = argv[i];
|
arg = argv[i];
|
||||||
if (arg[0] == '-')
|
if (arg[0] == '-') {
|
||||||
{
|
if (!reset_opts) {
|
||||||
if (!reset_opts)
|
ShowLines = ShowWords = ShowBytes = false;
|
||||||
{
|
reset_opts = true;
|
||||||
ShowLines = ShowWords = ShowBytes = 0;
|
}
|
||||||
reset_opts = 1;
|
while ((c = *++arg) != '\0') {
|
||||||
}
|
if (c == 'l') ShowLines = true;
|
||||||
while (c = *++arg)
|
else if (c == 'w') ShowWords = true;
|
||||||
{
|
else if (c == 'c') ShowBytes = true;
|
||||||
if (c == 'l') ShowLines = 1;
|
|
||||||
else if (c == 'w') ShowWords = 1;
|
|
||||||
else if (c == 'c') ShowBytes = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// pass 2: process filename args
|
// pass 2: process filename args
|
||||||
for (i = 1; i < argc; ++i)
|
for (i = 1; i < argc; ++i) {
|
||||||
{
|
|
||||||
arg = argv[i];
|
arg = argv[i];
|
||||||
if (arg[0] != '-')
|
if (arg[0] != '-')
|
||||||
file_count += do_wc (arg);
|
file_count += do_wc(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_count > 1)
|
if (file_count > 1)
|
||||||
display (TotalLines, TotalWords, TotalBytes, "total");
|
display(TotalLines, TotalWords, TotalBytes, "total");
|
||||||
}
|
}
|
||||||
|
|
||||||
putchar ('\n');
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
do_wc (char *fname)
|
do_wc(char *fname)
|
||||||
{
|
{
|
||||||
struct stat e;
|
struct stat e;
|
||||||
|
|
||||||
if (stat (fname, &e) == -1)
|
if (stat(fname, &e) == -1) {
|
||||||
{
|
fprintf(stderr, "'%s': no such file or directory\n", fname);
|
||||||
fprintf (stderr, "'%s': no such file or directory\n", fname);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISDIR (e.st_mode))
|
if (S_ISDIR(e.st_mode)) {
|
||||||
{
|
fprintf(stderr, "'%s' is a directory\n", fname);
|
||||||
fprintf (stderr, "'%s' is a directory\n", fname);
|
display(0, 0, 0, fname);
|
||||||
display (0, 0, 0, fname);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
else
|
FILE *fp = fopen(fname, "rb");
|
||||||
{
|
if (fp) {
|
||||||
FILE *fp = fopen (fname, "rb");
|
wc_file(fp, fname);
|
||||||
if (fp)
|
fclose(fp);
|
||||||
{
|
|
||||||
wc_file (fp, fname);
|
|
||||||
fclose (fp);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
else
|
fprintf(stderr, "'%s': %s\n", fname, strerror(errno));
|
||||||
{
|
|
||||||
fprintf (stderr, "'%s': %s\n", fname, strerror (errno));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
wc_file (FILE *fp, char *fname)
|
wc_file(FILE *fp, char *fname)
|
||||||
{
|
{
|
||||||
int lc = 0; // line count
|
int lc = 0; // line count
|
||||||
int wc = 0; // word count
|
int wc = 0; // word count
|
||||||
int bc = 0; // byte count
|
int bc = 0; // byte count
|
||||||
@@ -133,20 +118,18 @@ wc_file (FILE *fp, char *fname)
|
|||||||
int ns = 0; // non-spaces (consecutive count)
|
int ns = 0; // non-spaces (consecutive count)
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while ((c = fgetc (fp)) != EOF)
|
while ((c = fgetc(fp)) != EOF) {
|
||||||
{
|
|
||||||
++bc;
|
++bc;
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
++lc;
|
++lc;
|
||||||
|
|
||||||
if (isspace (c))
|
if (isspace(c)) {
|
||||||
{
|
|
||||||
if (ns > 0)
|
if (ns > 0)
|
||||||
++wc, ns = 0;
|
++wc, ns = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
++ns;
|
++ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ns > 0)
|
if (ns > 0)
|
||||||
++wc;
|
++wc;
|
||||||
@@ -155,18 +138,18 @@ wc_file (FILE *fp, char *fname)
|
|||||||
TotalWords += wc;
|
TotalWords += wc;
|
||||||
TotalBytes += bc;
|
TotalBytes += bc;
|
||||||
|
|
||||||
display (lc, wc, bc, fname);
|
display(lc, wc, bc, fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
display (int lc, int wc, int bc, char *fname)
|
display (int lc, int wc, int bc, char *fname)
|
||||||
{
|
{
|
||||||
if (ShowLines) printf ("%7d", lc);
|
if (ShowLines) printf("%7d", lc);
|
||||||
if (ShowWords) printf ("%8d", wc);
|
if (ShowWords) printf("%8d", wc);
|
||||||
if (ShowBytes) printf ("%8d", bc);
|
if (ShowBytes) printf("%8d", bc);
|
||||||
if (*fname) printf (" %s", fname);
|
if (*fname) printf(" %s", fname);
|
||||||
|
|
||||||
putchar ('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user