Checkpoint.

This commit is contained in:
wkj 2004-05-16 07:54:22 +00:00
parent 61f5c35c94
commit b855148c9b
74 changed files with 5281 additions and 130 deletions

View file

@ -0,0 +1,4 @@
ibmfont
laserbar
macfont
pscrypt

View file

@ -0,0 +1,15 @@
Miscellaneous programs - all are unsupported.
ibmfont.c IBM PC to Unix font conversion program
laserbar.[c1] Barcode filter and man page - Jan Wolitzky
lp.model Sample lp interface (not for Unix 4.0) - Maryann Csaszar
macfont.c Macintosh to Unix font conversion program
pscrypt.c Quick implementation of Adobe's encryption/decryption algorithm
setbaud.ps Example of how to change the printer's baudrate
Use make to compile C programs. For example,
make macfont
compiles macfont.c.

View file

@ -0,0 +1,296 @@
/*
*
* Program that converts IBM font files to a format that works on Unix systems.
* Essentially all the information needed came from the Adobe paper "Supporting
* Downloadable PostScript Fonts". To use the program type,
*
* ibmfont font.ibm >font.unix
*
* where font.ibm is the font file, exactly as it came over from an IBM PC,
* and font.unix is equivalent host resident font file usable on Unix systems.
*
*/
#include <stdio.h>
#include <signal.h>
#define OFF 0
#define ON 1
#define NON_FATAL 0
#define FATAL 1
#define FALSE 0
#define TRUE 1
char **argv;
int argc;
char *prog_name;
int x_stat;
int debug = OFF;
int ignore = OFF;
FILE *fp_in;
FILE *fp_out;
/*****************************************************************************/
main(agc, agv)
int agc;
char *agv[];
{
/*
*
* IBM PC to Unix font converter.
*
*/
argc = agc;
argv = agv;
prog_name = argv[0];
fp_in = stdin;
fp_out = stdout;
options();
arguments();
exit(x_stat);
} /* End of main */
/*****************************************************************************/
options()
{
int ch;
char *names = "DI";
extern char *optarg;
extern int optind;
/*
*
* Command line options.
*
*/
while ( (ch = getopt(argc, argv, names)) != EOF ) {
switch ( ch ) {
case 'D': /* debug flag */
debug = ON;
break;
case 'I': /* ignore FATAL errors */
ignore = ON;
break;
case '?': /* don't understand the option */
error(FATAL, "");
break;
default: /* don't know what to do for ch */
error(FATAL, "missing case for option %c\n", ch);
break;
} /* End switch */
} /* End while */
argc -= optind;
argv += optind;
} /* End of options */
/*****************************************************************************/
arguments()
{
/*
*
* Everything esle is an input file. No arguments or '-' means stdin.
*
*/
if ( argc < 1 )
conv();
else
while ( argc > 0 ) {
if ( strcmp(*argv, "-") == 0 )
fp_in = stdin;
else if ( (fp_in = fopen(*argv, "r")) == NULL )
error(FATAL, "can't open %s", *argv);
conv();
if ( fp_in != stdin )
fclose(fp_in);
argc--;
argv++;
} /* End while */
} /* End of arguments */
/*****************************************************************************/
conv()
{
int blocksize;
int blocktype;
int seg;
long ftell();
/*
*
* Font files on the IBM PC are stored in a compressed binary format. Individual
* segments in the file are preceeded by a header that looks like,
*
* Byte 1: 128
* Byte 2: segment type (1=ASCII, 2=TOHEX, or 3=EOF)
* Bytes 3-6: length of the segment
* Bytes 7 ... data
*
*/
while ( 1 ) {
seg = ftell(fp_in);
if ( getc(fp_in) != 128 )
error(FATAL, "bad file format");
blocktype = getc(fp_in);
blocksize = getint(fp_in);
if ( debug == ON ) {
fprintf(stderr, "blocktype = %d, blocksize = %d\n", blocktype, blocksize);
fprintf(stderr, "start=0%o, end=0%o\n", seg, seg+blocksize+6);
fprintf(stderr, "start=%d, end=%d\n", seg, seg+blocksize+6);
} /* End if */
switch ( blocktype ) {
case 1:
asciitext(blocksize);
break;
case 2:
hexdata(blocksize);
break;
case 3:
return;
default:
error(FATAL, "unknown resource type %d", blocktype);
} /* End switch */
} /* End while */
} /* End of conv */
/*****************************************************************************/
asciitext(count)
int count; /* bytes left in the block */
{
int ch;
int i = 0;
/*
*
* Handles type 1 (ie. ASCII text) blocks. Changing carriage returns to newlines
* is all I've done.
*
*/
for ( i = 0; i < count; i++ ) {
if ( (ch = getc(fp_in)) == '\r' )
ch = '\n';
putc(ch, fp_out);
} /* End for */
} /* End of asciitext */
/*****************************************************************************/
hexdata(count)
int count; /* bytes left in the block */
{
int i;
int n;
/*
*
* Reads the next count bytes and converts each byte to hex. Also starts a new
* line every 80 hex characters.
*
*/
for ( i = 0, n = 0; i < count; i++ ) {
fprintf(fp_out, "%.2X", getc(fp_in));
if ( (++n % 40) == 0 )
putc('\n', fp_out);
} /* End for */
} /* End of hexdata */
/*****************************************************************************/
getint()
{
int val;
/*
*
* Reads the next four bytes into an integer and returns the value to the caller.
* First two bytes are probably always 0.
*
*/
val = getc(fp_in);
val |= (getc(fp_in) << 8);
val |= (getc(fp_in) << 16);
val |= (getc(fp_in) << 24);
return(val);
} /* End of getint */
/*****************************************************************************/
error(kind, mesg, a1, a2, a3)
int kind;
char *mesg;
unsigned a1, a2, a3;
{
/*
*
* Print mesg and quit if kind is FATAL.
*
*/
if ( mesg != NULL && *mesg != '\0' ) {
fprintf(stderr, "%s: ", prog_name);
fprintf(stderr, mesg, a1, a2, a3);
putc('\n', stderr);
} /* End if */
if ( kind == FATAL && ignore == OFF )
exit(x_stat | 01);
} /* End of error */
/*****************************************************************************/

View file

@ -0,0 +1,41 @@
.TH LASERBAR 1
.SH NAME
laserbar \- produce bar codes on a PostScript laser printer
.SH SYNOPSIS
.B laserbar
[\fB-r\fP rotate] [\fB-x\fP xoffset] [\fB-y\fP yoffset]
[\fB-X\fP xscale] [\fB-Y\fP yscale] [\fB-lns\fP] string
.SH DESCRIPTION
.I Laserbar
prints on the standard output the PostScript text that will produce
(on a suitable laser printer) the \s-2CODE-39\s+2 bar code
corresponding to
.I string.
The \fBr\fP option may be used to specify a rotation (in
degrees) of the bar code.
The \fBx\fP, \fBy\fP, \fBX\fP, and \fBY\fP options may be used to specify
an x- or y-axis offset (in inches) or scaling factor, respectively.
(The offset is measured from the lower left corner of the page
to the upper left corner of the bar
code. By default, the bar code produced is one inch high, and is scaled
so that the narrowest elements are each 1/72-inch \- i.e., one point \- wide.)
If the \fBl\fP option is specified, the bar code produced is labeled.
If the \fBn\fP option is specified, the resulting PostScript text
includes a leading \f(CWnewpath\fP command, so that the text may stand
alone or precede any other PostScript commands.
If the \fBs\fP option is specified, the resulting PostScript text includes
a trailing \f(CWshowpage\fP command, so that the text may stand alone
or follow any other PostScript commands.
.P
This manual page (if it appears with a bar code printed on it) was
produced by something like the following sequence:
.IP
.ft CW
laserbar -x 2.5 -y 3 -l -n ABC123xyz > tempfile
.br
troff -man -Tpost laserbar.1 | dpost >> tempfile
.br
prt -dprinter -lpostscript tempfile
.ft P
.SH SEE ALSO
laserbar(3), prt(1), dpost(1), postbgi(1), postprint(1), postdmd(1), posttek(1), etc.

View file

@ -0,0 +1,166 @@
/* laserbar -- filter to print barcodes on postscript printer */
#define MAIN 1
#define LABEL 01
#define NFLAG 02
#define SFLAG 04
#include <stdio.h>
#include <ctype.h>
static int code39[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* sp ! " # $ % & ' */
0304, 0, 0, 0, 0250, 0052, 0, 0,
/* ( ) * + , - - / */
0, 0, 0224, 0212, 0, 0205, 0604, 0242,
/* 0 1 2 3 4 5 6 7 */
0064, 0441, 0141, 0540, 0061, 0460, 0160, 0045,
/* 8 9 : ; < = > ? */
0444, 0144, 0, 0, 0, 0, 0, 0,
/* @ A B C D E F G */
0, 0411, 0111, 0510, 0031, 0430, 0130, 0015,
/* H I J K L M N O */
0414, 0114, 0034, 0403, 0103, 0502, 0023, 0422,
/* P Q R S T U V W */
0122, 0007, 0406, 0106, 0026, 0601, 0301, 0700,
/* X Y Z [ \ ] ^ _ */
0221, 0620, 0320, 0, 0, 0, 0, 0,
/* ` a b c d e f g */
0, 0411, 0111, 0510, 0031, 0430, 0130, 0015,
/* h i j k l m n o */
0414, 0114, 0034, 0403, 0103, 0502, 0023, 0422,
/* p q r s t u v w */
0122, 0007, 0406, 0106, 0026, 0601, 0301, 0700,
/* x y z { | } ~ del */
0221, 0620, 0320, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
static void barprt();
void laserbar();
#ifdef MAIN
main(argc, argv)
char **argv;
{
int c, flags = 0, error = 0;
double rotate = 0, xoffset = 0, yoffset = 0, xscale = 1, yscale = 1;
extern char *optarg;
extern int optind;
extern double atof();
extern void exit();
while ((c = getopt(argc, argv, "r:x:y:X:Y:lns")) != EOF) {
switch(c) {
case 'r':
rotate = atof(optarg);
break;
case 'x':
xoffset = atof(optarg);
break;
case 'y':
yoffset = atof(optarg);
break;
case 'X':
xscale = atof(optarg);
break;
case 'Y':
yscale = atof(optarg);
break;
case 'l':
flags |= LABEL;
break;
case 'n':
flags |= NFLAG;
break;
case 's':
flags |= SFLAG;
break;
case '?':
++error;
}
}
if ((argc - optind) != 1)
++error;
if (error) {
(void) fprintf(stderr,
"Usage: %s [-r rotate] [-x xoffset] [-y yoffset] [-X xscale] [-Y yscale] [-lns] string\n",
*argv);
exit(1);
}
laserbar(stdout, argv[optind], rotate, xoffset, yoffset, xscale, yscale, flags);
return 0;
}
#endif /*MAIN*/
static int right = 0;
void
laserbar(fp, str, rotate, xoffset, yoffset, xscale, yscale, flags)
FILE *fp;
char *str;
double rotate, xoffset, yoffset, xscale, yscale;
int flags;
{
xoffset *= 72.;
yoffset *= 72.;
(void) fprintf(fp, "gsave %s\n", (flags & NFLAG) ? "newpath" : "");
if (xoffset || yoffset)
(void) fprintf(fp, "%f %f moveto\n", xoffset, yoffset);
if (xscale != 1 || yscale != 1)
(void) fprintf(fp, "%f %f scale\n", xscale, yscale);
if (rotate)
(void) fprintf(fp, "%f rotate\n", rotate);
(void) fputs("/Helvetica findfont 16 scalefont setfont\n", fp);
(void) fputs("/w { 0 rmoveto gsave 3 setlinewidth 0 -72 rlineto stroke grestore } def\n", fp);
(void) fputs("/n { 0 rmoveto gsave 1 setlinewidth 0 -72 rlineto stroke grestore } def\n", fp);
(void) fputs("/l { gsave 2 -88 rmoveto show grestore } def\n", fp);
barprt(fp, '*', 0);
while (*str)
barprt(fp, *(str++), (flags & LABEL));
barprt(fp, '*', 0);
(void) fprintf(fp, "%sgrestore\n", (flags & SFLAG) ? "showpage " : "");
right = 0;
}
static void
barprt(fp, c, label)
FILE *fp;
int c, label;
{
int i, mask, bar, wide;
if (!(i = code39[c]))
return;
if (islower(c))
c = toupper(c);
if (label)
(void) fprintf(fp, "(%c) l", c);
else
(void) fputs(" ", fp);
for (bar = 1, mask = 0400; mask; bar = 1 - bar, mask >>= 1) {
wide = mask & i;
if (bar) {
if (wide)
++right;
(void) fprintf(fp, " %d %s", right, wide ? "w" : "n");
right = (wide ? 2 : 1);
}
else
right += (wide ? 3 : 1);
}
(void) fputs("\n", fp);
++right;
}

View file

@ -0,0 +1,66 @@
# qmsps800 mac 10/22/86
#
LPDEST=`basename $0`
QMS_FILE="$1"
DATE="`date +%D`"
TIME="`date +%T`"
owner="$2"
site=`uname`
port="`/usr/bin/lpstat -v$LPDEST | sed -e 's/.*: //'`"
filter_cmd="/usr/lbin/postscript/postio"
filter="$filter_cmd -l $port"
landscape="" formsperpage=""
path=/usr/lbin/postscript
printer=postprint
bannerflag=ON
prev="| $path/postreverse"
for i in $5
do
case "$i" in
L2)
formsperpage="-n2"
;;
land)
landscape="-pland"
;;
dpost|postprint|posttek|postbgi|postdmd|postio)
printer="$i"
;;
postreverse)
prev=""
;;
nobanner)
bannerflag=OFF
;;
F*)
QMS_FILE="`expr $i : 'F\(.*\)'`"
;;
esac
done
if [ -n "$filter_cmd" -a ! -x "$filter_cmd" ]
then
disable -r"can't execute filter: $filter_cmd" $LPDEST
exit 1
fi
shift; shift; shift; shift; shift
files="$*"
cp /usr/spool/lp/model/banner.ps /tmp/ban.$$
echo "($QMS_FILE) ($LPDEST) ($TIME) ($DATE) ($owner) banner" >> /tmp/ban.$$
if [ "$printer" = "postio" ]
then
eval $filter $files 2> /dev/null
else
eval $path/$printer $landscape $formsperpage $files $prev | $filter 2> /dev/null
fi
if [ "$bannerflag" = "ON" ]
then
eval $filter /tmp/ban.$$ 2> /dev/null
fi
rm -f /tmp/ban.$$
exit 0

View file

@ -0,0 +1,299 @@
/*
*
* Program that converts Macintosh font files to a format that works on Unix
* systems. Essentially all the information needed came from the Adobe paper
* "Supporting Downloadable PostScript Fonts". To use the program type,
*
* macfont font.mac >font.unix
*
* where font.mac is the font file, exactly as it came over from a Macintosh,
* and font.unix is equivalent host resident font file usable on Unix systems.
*
*/
#include <stdio.h>
#include <signal.h>
#define OFF 0
#define ON 1
#define NON_FATAL 0
#define FATAL 1
#define FALSE 0
#define TRUE 1
char **argv;
int argc;
char *prog_name;
int x_stat;
int debug = OFF;
int ignore = OFF;
FILE *fp_in;
FILE *fp_out;
/*****************************************************************************/
main(agc, agv)
int agc;
char *agv[];
{
/*
*
* Macintosh to Unix font converter.
*
*/
argc = agc;
argv = agv;
prog_name = argv[0];
fp_in = stdin;
fp_out = stdout;
options();
arguments();
exit(x_stat);
} /* End of main */
/*****************************************************************************/
options()
{
int ch;
char *names = "DI";
extern char *optarg;
extern int optind;
/*
*
* Command line options.
*
*/
while ( (ch = getopt(argc, argv, names)) != EOF ) {
switch ( ch ) {
case 'D': /* debug flag */
debug = ON;
break;
case 'I': /* ignore FATAL errors */
ignore = ON;
break;
case '?': /* don't understand the option */
error(FATAL, "");
break;
default: /* don't know what to do for ch */
error(FATAL, "missing case for option %c\n", ch);
break;
} /* End switch */
} /* End while */
argc -= optind;
argv += optind;
} /* End of options */
/*****************************************************************************/
arguments()
{
/*
*
* Everything else is an input file. No arguments or '-' means stdin.
*
*/
if ( argc < 1 )
conv();
else
while ( argc > 0 ) {
if ( strcmp(*argv, "-") == 0 )
fp_in = stdin;
else if ( (fp_in = fopen(*argv, "r")) == NULL )
error(FATAL, "can't open %s", *argv);
conv();
if ( fp_in != stdin )
fclose(fp_in);
argc--;
argv++;
} /* End while */
} /* End of arguments */
/*****************************************************************************/
conv()
{
int blocksize;
int blocktype;
/*
*
* The first four bytes (in a block) are the block size, the fifth is the block
* type, and the sixth always appears to be NULL. Type 0 blocks are comments and
* are always skipped. Type 1 blocks are ASCII text, type 2 is binary data that
* should be converted to hex, while type 5 blocks represent the end of the font
* file. Commment block lengths appear to be from the first byte, while other
* lengths seem to be measured from block type byte (ie. the fifth byte). Type
* four blocks aren't used, while type 3 blocks mean an end of file indication
* should be sent to the printer. Haven't done anything with type 3 blocks.
*
*/
while ( 1 ) {
blocksize = getint(fp_in);
blocktype = getc(fp_in);
getc(fp_in);
if ( debug == ON )
fprintf(stderr, "blocktype = %d, blocksize = %d\n", blocktype, blocksize);
switch ( blocktype ) {
case 0: /* comment - skip blockcount bytes */
fseek(fp_in, (long) blocksize - 6, 1);
break;
case 1:
asciitext(blocksize - 2);
break;
case 2:
hexdata(blocksize - 2);
break;
case 3:
case 4:
error(FATAL, "resource type %d not implemented", blocktype);
break;
case 5:
return;
default:
error(FATAL, "unknown resource type %d", blocktype);
} /* End switch */
} /* End while */
} /* End of conv */
/*****************************************************************************/
asciitext(count)
int count; /* bytes left in the block */
{
int ch;
int i = 0;
/*
*
* Handles type 1 (ie. ASCII text) blocks. Changing carriage returns to newlines
* is all I've done.
*
*/
for ( i = 0; i < count; i++ ) {
if ( (ch = getc(fp_in)) == '\r' )
ch = '\n';
putc(ch, fp_out);
} /* End for */
} /* End of asciitext */
/*****************************************************************************/
hexdata(count)
int count; /* bytes left in the block */
{
int i;
int n;
/*
*
* Reads the next count bytes and converts each byte to hex. Also starts a new
* line every 80 hex characters.
*
*/
for ( i = 0, n = 0; i < count; i++ ) {
fprintf(fp_out, "%.2X", getc(fp_in));
if ( (++n % 40) == 0 )
putc('\n', fp_out);
} /* End for */
} /* End of hexdata */
/*****************************************************************************/
getint()
{
int val;
int i;
/*
*
* Reads the next four bytes into an integer and returns the value to the caller.
* First two bytes are probably always 0.
*
*/
for ( i = 0, val = (getc(fp_in) & 0377); i < 3; i++ )
val = (val << 8) | (getc(fp_in) & 0377);
return(val);
} /* End of getint */
/*****************************************************************************/
error(kind, mesg, a1, a2, a3)
int kind;
char *mesg;
unsigned a1, a2, a3;
{
/*
*
* Print *mesg then quit if kind is FATAL.
*
*/
if ( mesg != NULL && *mesg != '\0' ) {
fprintf(stderr, "%s: ", prog_name);
fprintf(stderr, mesg, a1, a2, a3);
putc('\n', stderr);
} /* End if */
if ( kind == FATAL && ignore == OFF )
exit(x_stat | 01);
} /* End of error */
/*****************************************************************************/

View file

@ -0,0 +1,335 @@
/*
*
* Adobe's encryption/decryption algorithm for eexec and show. Runs in
* eexec mode unless told otherwise. Use,
*
* pscrypt file.cypher > file.clear
*
* to decrypt eexec input. Assumes file.cypher is hex with the key as the
* first four bytes, and writes file.clear as binary (omitting the key).
* Use
*
* pscrypt -e12ab34ef file.clear >file.cypher
*
* to encrypt file.clear (for eexec) using 12ab34ef as the key. Input is
* binary and output is hex. The key must be given as a hex number. Use
* -sshow to encrypt or decrypt a CharString or Subr,
*
* pscrypt -sshow file.cypher > file.clear
*
* Use -b or -x to read binary or hex input, and -B or -X to output binary
* or hex.
*
*/
#include <stdio.h>
#include <ctype.h>
#define ENCRYPT 0
#define DECRYPT 1
#define NOTSET -1
#define BINARY 0
#define HEX 1
#define LINELENGTH 40
#define CHARSTRING 4330
#define EEXEC 55665
#define MAGIC1 52845
#define MAGIC2 22719
int argc;
char **argv;
int mode = DECRYPT;
int input = NOTSET;
int output = NOTSET;
int outoffset = NOTSET;
int inoffset = NOTSET;
int cryptkey = 0; /* encryption key set with -e */
int linelength = LINELENGTH; /* only for hex output */
int lastchar = 0;
unsigned long seed = EEXEC;
unsigned long key;
FILE *fp_in;
/*****************************************************************************/
main(agc, agv)
int agc;
char *agv[];
{
/*
*
* Implementation of the encryption/decryption used by eexec and show.
*
*/
argc = agc;
argv = agv;
fp_in = stdin;
options();
initialize();
arguments();
exit(0);
} /* End of main */
/*****************************************************************************/
options()
{
int ch;
char *names = "bde:l:os:xBSX";
extern char *optarg;
extern int optind;
/*
*
* Command line options.
*
*/
while ( (ch = getopt(argc, argv, names)) != EOF )
switch ( ch ) {
case 'b': /* binary input */
input = BINARY;
break;
case 'd': /* decrypt */
mode = DECRYPT;
break;
case 'e': /* encrypt */
mode = ENCRYPT;
if ( *optarg == '0' && *optarg == 'x' )
optarg += 2;
sscanf(optarg, "%8x", &cryptkey);
break;
case 'l': /* line length hex output */
linelength = atoi(optarg);
break;
case 'o': /* output all bytes - debugging */
outoffset = 0;
break;
case 's': /* seed */
if ( *optarg == 'e' )
seed = EEXEC;
else if ( *optarg == 's' )
seed = CHARSTRING;
else if ( *optarg == '0' && *(optarg+1) == 'x' )
sscanf(optarg+2, "%x", &seed);
else if ( *optarg == '0' )
sscanf(optarg, "%o", &seed);
else sscanf(optarg, "%d", &seed);
break;
case 'x': /* hex input */
input = HEX;
break;
case 'B': /* binary output */
output = BINARY;
break;
case 'X': /* hex output */
output = HEX;
break;
case '?': /* don't understand the option */
fprintf(stderr, "bad option -%c\n", ch);
exit(1);
break;
default: /* don't know what to do for ch */
fprintf(stderr, "missing case for option -%c\n", ch);
exit(1);
break;
} /* End switch */
argc -= optind; /* get ready for non-option args */
argv += optind;
} /* End of options */
/*****************************************************************************/
initialize()
{
/*
*
* Initialization that has to be done after the options.
*
*/
key = seed;
if ( mode == DECRYPT ) {
input = (input == NOTSET) ? HEX : input;
output = (output == NOTSET) ? BINARY : output;
inoffset = (inoffset == NOTSET) ? 0 : inoffset;
outoffset = (outoffset == NOTSET) ? -4 : outoffset;
} else {
input = (input == NOTSET) ? BINARY : input;
output = (output == NOTSET) ? HEX : output;
inoffset = (inoffset == NOTSET) ? 4 : inoffset;
outoffset = (outoffset == NOTSET) ? 0 : outoffset;
} /* End else */
if ( linelength <= 0 )
linelength = LINELENGTH;
} /* End of initialize */
/*****************************************************************************/
arguments()
{
/*
*
* Everything left is an input file. No arguments or '-' means stdin.
*
*/
if ( argc < 1 )
crypt();
else
while ( argc > 0 ) {
if ( strcmp(*argv, "-") == 0 )
fp_in = stdin;
else if ( (fp_in = fopen(*argv, "r")) == NULL ) {
fprintf(stderr, "can't open %s\n", *argv);
exit(1);
} /* End if */
crypt();
if ( fp_in != stdin )
fclose(fp_in);
argc--;
argv++;
} /* End while */
} /* End of arguments */
/*****************************************************************************/
crypt()
{
unsigned int cypher;
unsigned int clear;
/*
*
* Runs the encryption/decryption algorithm.
*
*/
while ( lastchar != EOF ) {
cypher = nextbyte();
clear = ((key >> 8) ^ cypher) & 0xFF;
key = (key + (mode == DECRYPT ? cypher : clear)) * MAGIC1 + MAGIC2;
if ( ++outoffset > 0 && lastchar != EOF ) {
if ( output == HEX ) {
printf("%.2X", clear);
if ( linelength > 0 && (outoffset % linelength) == 0 )
putchar('\n');
} else putchar(clear);
} /* End if */
} /* End while */
} /* End of crypt */
/*****************************************************************************/
nextbyte()
{
int val = EOF;
/*
*
* Returns the next byte. Uses cryptkey (i.e. what followed -e) while inoffset is
* positive, otherwise reads (hex or binary) from fp_in.
*
*/
if ( inoffset-- > 0 )
val = (cryptkey >> (inoffset*8)) & 0xFF;
else if ( input == HEX ) {
if ( (val = nexthexchar()) != EOF )
val = (val << 4) | nexthexchar();
} else if ( input == BINARY )
val = Getc(fp_in);
return(val);
} /* End of nextbyte */
/*****************************************************************************/
nexthexchar()
{
int ch;
/*
*
* Reads the next hex character.
*
*/
while ( (ch = Getc(fp_in)) != EOF && ! isxdigit(ch) ) ;
if ( isdigit(ch) )
ch -= '0';
else if ( isupper(ch) )
ch -= 'A' - 10;
else if ( islower(ch) )
ch -= 'a' - 10;
return(ch);
} /* End of nexthexchar */
/*****************************************************************************/
Getc(fp)
FILE *fp;
{
/*
*
* Reads the next byte from *fp, sets lastchar, and returns the character.
*
*/
return(lastchar = getc(fp));
} /* End of Getc */
/*****************************************************************************/

View file

@ -0,0 +1,9 @@
%
% Sets baud rate to 9600, options to 0 assuming the password is 0.
%
serverdict begin
0 exitserver
statusdict begin
25 9600 0 setsccbatch
end