Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
/*
|
|
|
|
BINPRINT.C
|
|
|
|
|
|
|
|
Displays files in hex-dump format (with ascii subdisplay if desired)
|
|
|
|
|
1999-01-16 18:35:57 +00:00
|
|
|
v1.3 Incorporated sources into GNO base build. Reformatted sources,
|
|
|
|
prototyped functions, added calls to fflush(3). (Devin Reade)
|
|
|
|
v1.2 Optimized and fixed input from terminal bug (Phil Vandry)
|
|
|
|
v1.1 Added stacksize directive (Jawaid Bazyar)
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
v1.0 Original version by Derek Taubert
|
|
|
|
|
1999-01-16 18:35:57 +00:00
|
|
|
$Id: binprint.c,v 1.3 1999/01/16 18:35:57 gdr-ftp Exp $
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
*/
|
|
|
|
|
1999-01-16 18:35:57 +00:00
|
|
|
#define VERSION "1.3"
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
1999-01-16 18:35:57 +00:00
|
|
|
#include <gno/gno.h> /* for stack checking routines */
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
1999-01-16 18:35:57 +00:00
|
|
|
unsigned int doline(char *dest, char *source, unsigned int actual,
|
|
|
|
unsigned int cols);
|
|
|
|
static void printGood(long off, unsigned char *buf, int real, int form);
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
|
|
|
unsigned char *buffer2;
|
|
|
|
|
1999-01-16 18:35:57 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
{
|
1999-01-15 15:54:40 +00:00
|
|
|
int duh;
|
|
|
|
int a;
|
1999-01-16 18:35:57 +00:00
|
|
|
int c, errflg = 0, columns = 16;
|
1999-01-15 15:54:40 +00:00
|
|
|
size_t pos = 0;
|
|
|
|
unsigned char *buffer;
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
1999-01-16 18:35:57 +00:00
|
|
|
__REPORT_STACK();
|
1999-01-15 15:54:40 +00:00
|
|
|
while ((c = getopt(argc,argv, "Vc:")) != EOF)
|
|
|
|
switch (c) {
|
|
|
|
case 'c' :
|
|
|
|
columns = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'V' :
|
1999-01-16 18:35:57 +00:00
|
|
|
fprintf(stdout, "binprint v%s for GNO/ME\n", VERSION);
|
1999-01-15 15:54:40 +00:00
|
|
|
exit(0);
|
1999-01-16 18:35:57 +00:00
|
|
|
default :
|
|
|
|
errflg++;
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|
1999-01-15 15:54:40 +00:00
|
|
|
if (errflg) {
|
|
|
|
fprintf(stderr,"usage: binprint [-c<columns>] files...\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
argv += optind;
|
|
|
|
if (columns < 8) columns = 8;
|
|
|
|
if ((buffer2 = (unsigned char *)malloc((size_t)(columns*4)+1)) == NULL) {
|
|
|
|
fprintf(stderr,"Cannot allocate buffer space\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
buffer = (unsigned char *)(buffer2+(columns*3));
|
|
|
|
if (optind == argc) {
|
|
|
|
duh = STDIN_FILENO;
|
|
|
|
goto action;
|
|
|
|
}
|
|
|
|
for (;optind<argc;optind++) {
|
|
|
|
if ((duh = open(*argv,O_RDONLY|O_BINARY)) == -1) {
|
|
|
|
fprintf(stderr,"error opening %s\n",*argv);
|
|
|
|
exit(1);
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|
1999-01-15 15:54:40 +00:00
|
|
|
printf("\n%s\n",*argv);
|
1999-01-16 18:35:57 +00:00
|
|
|
fflush(stdout); /* we write to STDOUT_FILENO directly */
|
1999-01-15 15:54:40 +00:00
|
|
|
action:
|
|
|
|
while ((a = (int)read(duh, buffer,
|
|
|
|
(size_t)(columns * sizeof(unsigned char)))) != 0) {
|
|
|
|
printGood(pos,buffer,a,columns);
|
|
|
|
pos += a;
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|
1999-01-15 15:54:40 +00:00
|
|
|
close(duh);
|
|
|
|
}
|
|
|
|
free(buffer);
|
|
|
|
free(buffer2);
|
|
|
|
exit(0);
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|
|
|
|
|
1999-01-16 18:35:57 +00:00
|
|
|
static void
|
|
|
|
printGood(long off, unsigned char *buf, int real, int form)
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
{
|
1999-01-15 15:54:40 +00:00
|
|
|
if (!real) return;
|
|
|
|
#if 0
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
printf("%8lX: ",off);
|
1999-01-16 18:35:57 +00:00
|
|
|
fflush(stdout);
|
1999-01-15 15:54:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The following is a hack required because of buffering by the stdio
|
|
|
|
libraries. I wish it was not necesary... */
|
|
|
|
|
|
|
|
{
|
|
|
|
static char puthere[11];
|
|
|
|
int howmany;
|
|
|
|
|
|
|
|
howmany = sprintf(puthere,"%8lX: ",off);
|
|
|
|
write(STDOUT_FILENO, puthere, (size_t)howmany);
|
|
|
|
}
|
|
|
|
|
|
|
|
write(STDOUT_FILENO, buffer2, (size_t)doline(buffer2,buf,form,real));
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|