home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource3
/
183_01
/
letter.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-02-04
|
21KB
|
817 lines
/*
* letter A short, savage, document processor designed to serve one
* function; format a one page letter.
*
* I don't know about anybody else, but I write about 25 one-
* pagers a week and I like my letters to look pretty. This
* requires vertical centering and I've not found a word
* processor yet that can do it (although qnxs' document
* processor 'doc' did provide sufficient primitives to
* write a REALLY complex macro that did and UNIXs' nroff and
* a whole bunch of shell commands could do the job as well).
*
* letter will vertically center a one page letter, will
* divert the address to a file (suitable for printing on
* an envelope by address) and support a small set of document
* processing functions. It is weak on error checking and
* semantic analysis (so don't push it!). See the separate
* document 'letter.doc' for more detail.
*
* This program took less than six hours to write. It is
* probably far from perfect. I'm not offering this as a
* replacement for nroff (or even WordStar), but it does
* what I need acceptably.
*
* This is thrown freely into the public domain and can be
* used, modified, and distributed by any person or agency
* that wants to. I would appreciate it if the original
* author credit remains and would also request that no
* compensation be charged by anyone passing this turkey
* around.
*
* This program was written by Jon Simkins and tested using the DeSmet C
* compiler and MS-DOS 3.0.
*
* Revision Notes
*
* Date Revision
* --------------------
* 86.02.04 Added UL_ON and BF_ON control strings for printers that
* directly support underlining and boldface (most if them
* these days).
* Changed setDate() function for Wizard C and recompiled. js.
*
* Copyright (c) 1985 SoftFocus
* 1343 Stanbury Dr.,
* Oakville, Ontario, Canada
* L6L 2J5
* (416)825-0903
*
* Compuserve: 76566, 1172
*/
#include <stdio.h>
#include <bdos.h> /* for getdate() structure */
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#define MAXLINE 200 /* maximum input line. Assumed larger than */
/* maximum print line. */
#define LPP 66 /* maximum lines per page. */
#define ERROR -1
#define HEAD 6 /* lines left at top of page when paper is loaded */
/*
* program defaults and printer controls.
* If your printer cannot backspace one character, don't use underline or
* boldface.
*/
#define DEFIN 0 /* default indent */
#define DEFRM 65 /* default right margin */
#define DEFPO 5 /* default page offset */
#define DEFJU FALSE /* justification off */
#define DEFFI TRUE /* fill on */
#define FF "\014" /* string to formfeed the printer */
#define BACKSPACE 8 /* character to backspace the printer */
/*
* Printer Control Strings
* -----------------------
* If your printer supports such niceties as automatic underlining and
* boldface, then fill in the following defines in the logical manner.
* If they are left undefined, then letter will underline by backspacing
* and printing a '_' and boldface by doublestriking.
* The given examples are for a Brother HR-35 daisywheel. This is disabled
* in the distribution version.
*/
/* #define UL_ON "\033E" *//* enable auto underline */
/* #define UL_OFF "\033R" *//* disable auto underline */
/* #define BF_ON "\033O" *//* enable auto boldface */
/* #define BF_OFF "\033&" *//* disable auto boldface */
FILE *fd; /* main input file */
FILE *fdAdd; /* address file */
FILE *printer; /* printer device */
int hardCopy; /* true if printed */
#define PRINTER "LPT1" /* hardcopy output */
#define CONSOLE "CON" /* console output */
/*
* letter array, line buffer, and counters
*/
char *lines[LPP]; /* build the page here */
int lineCount;
char pLine[MAXLINE]; /* build the current line here */
int pCount;
int saveJu, saveFi;
/*
* command array & defines
*/
#define COMCOUNT 13
char *commands[] = {". ", "in", "po", "ju", "rm", "ti", "br",
"as", "ae", "sp", "dt", "sg", "ce", "fi"};
#define COMMENT 0
#define INDENT 1
#define PAGEOFF 2
#define JUSTIFY 3
#define RM 4
#define TI 5
#define BR 6
#define AS 7
#define AE 8
#define SP 9
#define DT 10
#define SG 11
#define CENTER 12
#define FILL 13
/*
* margins, switches.
* There is currently no way to disable the interpretation of the characters
* listed below.
*/
#define BC '^' /* boldface toggle */
#define UC '_' /* underline toggle */
#define HS '~' /* 'hard' space (not spread by justification) */
int rm, in, ti, ju, po, fi, br, sp, ce;
int addFlag; /* whether address redirection in effect */
int ul, bf; /* underline, boldface currently selected */
/*
* off and away
*/
main(argc, argv)
int argc;
char *argv[];
{
char buff[MAXLINE], word[MAXLINE];
int index, len;
char *pr;
register j;
/*
* check argument count
*/
if (argc > 3 || argc < 2)
erExit("usage: letter [-p] <fName>");
/*
* get command line option(s)
*/
j=1;
if (argv[j][0] == '-' && argv[j][1] == 'p') {
pr = PRINTER;
hardCopy = TRUE;
j++;
}
else {
pr = CONSOLE;
hardCopy = FALSE;
}
/*
* open input file
*/
if ( (fd=fopen(argv[j], "r")) == 0) {
printf("Could not open '%s'\n", argv[j]);
exit(ERROR);
}
/*
* set defaults
*/
ul = bf = addFlag = FALSE;
in = DEFIN;
rm = DEFRM;
ju = DEFJU;
fi = DEFFI;
if (hardCopy)
po = DEFPO;
else
po = 0;
ti = ce = lineCount = 0;
/*
* input/process loop
*/
pCount = 0;
pLine[0] = '\0';
while( fgets(buff, MAXLINE, fd) != NULL) {
trim(buff);
/*
* blank line?
*/
if (buff[0] == '\0') {
pFlush(FALSE);
pCount=1;
pFlush(FALSE);
continue;
}
/*
* check for any command lines
*/
if (buff[0] == '.') {
dotComm(buff);
continue;
}
/*
* if fill mode is off, just pass the line on through.
*/
if ( !(fi)) {
strcpy(pLine, buff);
pCount = lenCal(pLine);
pFlush(ju);
}
else {
/*
* must be text; add it (word at a time) to the current print
* line.
*/
index=0;
do {
index = getWord(index, buff, word);
if (index == 0)
continue;
len = lenCal(word);
/*
* if there's still room, add word to current line
*/