Cover V02, I04
Article
Figure 1
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6

jul93.tar


Listing 6: piocrypt.c

/* program piocrypt.c */

#include <stdio.h>
#include <ctype.h>
#include <piostruct.h>

/* STRING CONSTANTS */
/* Initialize Printer, Restore Printer, Form Feed */
#define INIT_CMD    "ci"
#define REST_CMD    "cr"
#define FF_CMD      "af"

/* INTEGER and STRING VARIABLES */
/* page length, page width, top margin, bottom margin */
#define Pglen          (*(_Pglen + piomode))
#define Pgwidth        (*(_Pgwidth + piomode))
#define Tmarg          (*(_Tmarg + piomode))
#define Bmarg          (*(_Bmarg + piomode))

/* indentation, begin page, form feed?, pass-through? */
#define Indent         (*(_Indent + piomode))
#define Beginpg        (*(_Beginpg + piomode))
#define Do_formfeed    (*(_Do_formfeed + piomode))
#define Passthru       (*(_Passthru + piomode))

/* initialize printer?, restore printer? */
#define Init_printer    (*(_Init_printer + piomode))
#define Restoreprinter  (*(_Restoreprinter + piomode))

/* Command names: form feed, vertical increment and decrement */
#define Ff_cmd         (*(_Ff_cmd + piomode))
#define Vincr_cmd      (*(_Vincr_cmd + piomode))
#define Vdecr_cmd      (*(_Vdecr_cmd + piomode))

/* Work variables for vertical increment and decrement */
#define Vincr          (*(_Vincr + piomode))
#define Vdecr          (*(_Vdecr + piomode))

/* Variables referenced by above #defines */
int *_Pglen, *_Pgwidth, *_Tmarg, *_Bmarg, *_Indent, *_Beginpg,
*_Do_formfeed, *_Passthru, *_Init_printer, *_Restoreprinter, *_Vincr,
*_Vdecr;

struct str_info *_Ff_cmd, *_Vincr_cmd, *_Vdecr_cmd;

/* TABLE OF ATTRIBUTE VALUES */
struct attrparms attrtable[] = { /*
name  data type  lookup  address of pointer */
"_b",  VAR_INT,   NULL,   (union dtypes *) &_Bmarg,
"_g",  VAR_INT,   NULL,   (union dtypes *) &_Beginpg,
"_i",  VAR_INT,   NULL,   (union dtypes *) &_Indent,
"_j",  VAR_INT,   NULL,   (union dtypes *) &_Init_printer,
"_l",  VAR_INT,   NULL,   (union dtypes *) &_Pglen,
"_t",  VAR_INT,   NULL,   (union dtypes *) &_Tmarg,
"_w",  VAR_INT,   NULL,   (union dtypes *) &_Pgwidth,
"_J",  VAR_INT,   NULL,   (union dtypes *) &_Restoreprinter,
"_Z",  VAR_INT,   NULL,   (union dtypes *) &_Do_formfeed,
"wp",  VAR_INT,   NULL,   (union dtypes *) &_Passthru,
"wf",  VAR_STR,   NULL,   (union dtypes *) &_Ff_cmd,
"wi",  VAR_STR,   NULL,   (union dtypes *) &_Vincr_cmd,
"wy",  VAR_STR,   NULL,   (union dtypes *) &_Vdecr_cmd,
"wV",  VAR_INT,   NULL,   (union dtypes *) &_Vincr,
"wD",  VAR_INT,   NULL,   (union dtypes *) &_Vdecr,
NULL,  0     ,   NULL,    NULL };

int pglen, tmarg, bmarg, vpos, vtab_base;
struct shar_vars sharevars;

struct shar_vars *setup(unsigned int argc, char *argv[], int passthru)

{

(void) piogetvals(attrtable, NULL);
(void) piogetopt(argc, argv, NULL, NULL);
pglen = Pglen * Vincr;
tmarg = Tmarg * Vincr;
bmarg = Bmarg * Vincr;
piopgskip = Beginpg - 1;

if (Passthru = passthru)
return(NULL);

sharevars._pl            = &pglen;
sharevars._tmarg         = &tmarg;
sharevars._bmarg         = &bmarg;
sharevars._vpos          = &vpos;
sharevars._vtab_base     = &vtab_base;
sharevars._vincr         = &Vincr;
sharevars._vincr_cmd     = (&Vincr_cmd)->ptr;
sharevars._vdecr         = &Vdecr;
sharevars._vdecr_cmd     = (&Vdecr_cmd)->ptr;
sharevars._ff_cmd        = (&Ff_cmd)->ptr;
sharevars._ff_at_eof     = &Do_formfeed;

return(&sharevars);

} /* end setup */

initialize() /*** Initialize the Printer ***/

{

if (Init_printer)
(void) piocmdout(INIT_CMD, NULL, 0, NULL);
return(0);

} /* end initialize */

lineout(FILE *fileptr)  /***  Format a Line  ***/

{

int ch,
offset,
charcount = 0;

for (ch = 0; ch < Indent; ch++)
pioputchar(' ');
while ((ch=piogetc(fileptr)) != '\n' && ch != EOF
&& charcount < Pgwidth) {
if (ch <= 79 && ch >= 33) {
offset = 79 - ch + 1;
ch = 79 + offset;
} /* end then */
else {
if (ch >= 80 && ch <= 126) {
offset = ch - 80 + 1;
ch = 80 - offset;
} /* end then */
} /* end else */
if (isupper(ch))
ch = tolower(ch);
else {
if (islower(ch))
ch = toupper(ch);
} /* end else */
pioputchar(ch);
charcount++;
} /* end while */
vpos += Vincr;
return(charcount);

} /* end lineout */

passthru()  /*** Pass-through Option ***/

{

int ch;

while ((ch = piogetc(stdin)) != EOF)
pioputchar(ch);
if (piodatasent && Do_formfeed)
(void) piocmdout(FF_CMD, NULL, 0, NULL);
return(0);

} /* end passthru */

restore() /*** Restore the Printer ***/

{

if (Restoreprinter)
(void) piocmdout(REST_CMD, NULL, 0, NULL);
return(0);

} /* end restore */

/* end program piocrypt.c */