Path: utzoo!mnetor!uunet!bbn.com!rsalz From: rsalz@bbn.com (Rich Salz) Newsgroups: comp.sources.unix Subject: v13i046: Program to make mailing labels Message-ID: <411@fig.bbn.com> Date: 17 Feb 88 01:28:31 GMT Organization: BBN Laboratories Inc., Cambridge MA Lines: 1687 Approved: rsalz@uunet.UU.NET Submitted-by: Joe Chen Posting-number: Volume 13, Issue 46 Archive-name: labels LABELS is a label formatting program. It formats labels/mailing lists according to user-defined label forms. This program has been fully tested under Sun Unix 3.2 (BSD UNIX) and should work on any BSD UNIX systems. It should also work under other UNIX systems with little changes. As for non-Unix systems, like MS-DOS, you would need lex and yacc for the PC, or obtain lex.yy.c and y.tab.* from an UNIX system. Joe S. Chen --------------------------------------------------------------------------- Phones at work: (213) 743-5363, (213) 743-5935; at home: (818) 571-5304 University Computing Services, University of Southern California UUCP: {sdcrdcf, uscvax}!oberon!wasat!joec ARPA: joec@wasat.usc.edu, joec@ecla.usc.edu --------------------------------------------------------------------------- ----------CUT HERE----------CUT HERE----------CUT HERE----------CUT HERE------ #!/bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #!/bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # INSTALL # Makefile # main.c # labels.l # labels.y # labels.man # 1083.lbl # 1083f.lbl # 1083t.lbl # 6080.lbl # 6080f.lbl # 6080t.lbl # 6083.lbl # 6083f.lbl # 6083t.lbl export PATH; PATH=/bin:$PATH echo shar: extracting "'INSTALL'" '(891 characters)' if test -f 'INSTALL' then echo shar: over-writing existing file "'INSTALL'" fi cat << \SHAR_EOF > 'INSTALL' Installation Procedure: After extracting files from the shell archive, modify the following variables in Makefile: DESTDIR Destination directory, where the program will be installed. FRMDIR Directory (doesn't have to exist) where pre-defined forms will reside. LNAME Name of the program. CFLAGS Define System where this program will run under. If you want to set a default form, you must edit the beginning section of main.c. To compile LABELS, type: %make and press carriage return. To install LABELS, type %make install and press carriage return, and the program and preset forms will be installed in the proper directories. To install the man page, you can simply copy the file 'labels.1' to your man directory (e.g. /usr/man/man1). To re-package labels, type %make shar and press return. The archived file 'labels.shar' will be the new shell archive. SHAR_EOF echo shar: extracting "'Makefile'" '(2809 characters)' if test -f 'Makefile' then echo shar: over-writing existing file "'Makefile'" fi cat << \SHAR_EOF > 'Makefile' # -- MAKEFILE (UNIX) -- # # @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ # @@ @@ # @@ Mailing List Label Formatter @@ # @@ Program Maintenance Specification @@ # @@ (C) Copyright 1987 by Joe Chen @@ # @@ All Rights Reserved @@ # @@ @@ # @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ # # Program created by Joe Chen - Jul 24, 1987 # # *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* # Directory where LABELS is to be installed (please specify the full path) DESTDIR = /usr/pollux/jchen/bin # Directory where label forms can be found (please specify the full path) FRMDIR = /usr/pollux/jchen/bin/lib # Program name LNAME = labels # Compiling flags UNIX, BSD (USG and MSDOS are valid, but not fully supported) # NOTE: This program has been fully tested on Sun UNIX only. CFLAGS = -DBSD -DUNIX CC = cc -c -g $(CFLAGS) YACC = yacc LEX = lex LINK = cc # *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* OBJS = y.tab.o lex.yy.o main.o labels: $(OBJS) @echo char \*rev_date = \"`date`\"\; > revdate.c @echo Linking $(LNAME)... @${LINK} $(OBJS) revdate.c -o $(LNAME) @rm -f revdate.c revdate.o @echo @echo \`$(LNAME)\' Compiled. y.tab.c: labels.y @echo Running Yacc... @${YACC} -d labels.y y.tab.o: y.tab.c @echo Compiling: y.tab.c @${CC} y.tab.c lex.yy.c: labels.l @echo Running Lex... @${LEX} labels.l lex.yy.o: lex.yy.c y.tab.h @echo Compiling: lex.yy.c @${CC} lex.yy.c main.o: main.c Makefile @echo Compiling: main.c @${CC} -DFDIR=\"$(FRMDIR)\" main.c install: @echo Installing \`$(LNAME)\' in $(DESTDIR)... @rm -f $(DESTDIR/$(LNAME) @cp $(LNAME) $(DESTDIR)/$(LNAME) @strip $(DESTDIR)/$(LNAME) @chmod 755 $(DESTDIR)/$(LNAME) @echo @echo Placing Form Definitions in $(FRMDIR)... @echo mkdir $(FRMDIR) 2\> /dev/null \; exit 0 > mklib @chmod u+x mklib @./mklib @rm -f mklib @chmod 755 $(FRMDIR) @cp *.lbl $(FRMDIR) @chmod 644 $(FRMDIR)/*.lbl @make man @echo @echo \`$(LNAME)\' installed. clean: @echo Cleaning Directory... @rm -f *.o *\~ y.tab.* lex.yy.c $(LNAME) @echo @echo Done! man: @echo @echo Processing a raw man page: $(LNAME).1 @/lib/cpp -P -DLIBDIR=$(FRMDIR) -DLNAME=$(LNAME) -DPROGDIR=$(DESTDIR) \ $(LNAME).man > $(LNAME).1 shar: @echo Shell Archiving \($(LNAME)\.shar\)... @shar INSTALL Makefile main.c labels.l labels.y labels.man \ *.lbl > $(LNAME).shar @echo @echo Done! SHAR_EOF echo shar: extracting "'main.c'" '(17102 characters)' if test -f 'main.c' then echo shar: over-writing existing file "'main.c'" fi cat << \SHAR_EOF > 'main.c' /* -- MAIN.C -- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ @@ @@ Mailing List Label Formatter @@ @@ Main Module @@ @@ (C) Copyright 1987 by Joe Chen @@ @@ All Rights Reserved @@ @@ @@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ You may freely distribute this software to others. But there are few rules you must follow: 1. You don't profit from it. You may however ask for minimal fees to cover shipping and handling. 2. This program is copyrighted, meaning you may not modify or enhance this software and market it. You may make changes to suit your local needs. Any enhancements are welcomed. 3. Please honor the author by not removing or replacing his name from the source codes. Feel free to contact me if you have any questions. Joe Chen --------------------------------------------------------------------------- Phones at work: (213) 743-5363, (213) 743-5935; at home: (818) 571-5304 University Computing Services, University of Southern California UUCP: {sdcrdcf, uscvax}!oberon!wasat!joec ARPA: joec@wasat.usc.edu, joec@ecla.usc.edu --------------------------------------------------------------------------- Program created by Joe Chen - Jul 24, 1987 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* */ /* Internal default form: 32x11x3 */ #define DEF_FORM "1083" /* form name here at USC */ #define ISTRING NULL /* initial escape sequence */ #define IFILL 12 /* fill n rows for adjustments */ #define FOFFS 0 /* form offset (from top) */ #define POFFS 0 /* page offset (from left) */ #define LWIDTH 32 /* width (in chars) of each label */ #define LHGAP 4 /* horizontal gap (in chars) between labels */ #define LVGAP 1 /* vertical gap (# of lines) between labels */ #define LCROSS 3 /* number of labels accross */ #define LMLINES 11 /* Maximum lines per label */ #define LOFFSET 4 /* offset (in chars) from left edge */ /* of each label */ #define LROWS 0 /* labels per page, 0=don't care*/ /*****************************************************************************/ #include #define QUIT (perror(argv[0]),dsp_usg(argv[0]),exit(-1)) #define FEXT ".lbl" /* file extension for form definition file */ #define GETC(x) (((ch=getc(x))=='\n')?line_num++,ch:ch); #ifdef BSD #include #include #endif BSD char *def_form = DEF_FORM; /* default label form */ char *def_istring = ISTRING; /* initial string/escape sequence */ char *l_istring; int l_ifill = IFILL; /* Initial label fill for manual adjustments*/ int l_foffs = FOFFS; /* form offset (from top) */ int l_poffs = POFFS; /* page offset (from left) */ int l_width = LWIDTH; /* width of one label (in characters) */ int l_hgap = LHGAP; /* horizontal gap between labels (in chars) */ int l_vgap = LVGAP; /* vertical gap between labels (in chars) */ int l_cross = LCROSS; /* number of labels across one row */ int l_mlines= LMLINES; /* maximum printable lines per label */ int l_offset= LOFFSET; /* offset printing of data (in chars) */ int l_lrows = LROWS; /* rows of labels per page */ FILE *infile = stdin, *outfile = stdout; int line_num = 1; #define T 1 #define F 0 extern char *malloc(), *getcwd(); extern char *rev_date; /* supplied by Makefile */ extern FILE *yyin; /* from lex */ char *inpf = NULL, *outf = NULL; /* pointer to file names */ char *form = NULL; /* pointer to form name */ char **fmt_arry; /* line formatter */ char *version = "1.1"; #ifdef UNIX #ifdef BSD static char *os_title = "BSD UNIX Version"; #else #ifdef USG static char *os_title = "AT&T UNIX Version"; #endif USG #endif BSD #endif UNIX #ifdef MSDOS static char *os_title = "MS-DOS Verson"; #endif MSDOS /**************************************************************************** dsp_usg() [Private function] - Display a brief usage info parameters: name Name of this program exit flags: none ****************************************************************************/ static void dsp_usg(name) char *name; { printf("\nUsage: %s [-f