home *** CD-ROM | disk | FTP | other *** search
- /* prt_labl.c - prints ASCII file label data in parallel formats
-
- ************* Copyright 1985 by Vermont Creative Software **************
-
- Permission to use this program for personal use is granted. You
- may not sell or redistribute the program or adaptations of it
- without prior written consent.
-
-
- NAME
-
- prt_labl.c -- prints ASCII file label data in parallel formats
-
- DATE: February 5, 1986
-
- USAGE
-
- To print labels stored sequentially in a ASCII file in two or three across
- format.
-
- To illustrate the use of windows and the prt_wn() function for formatting and
- printing text.
-
- FUNCTION
-
- 1. Writes label data read from a disk file to a window. The window is moved
- across the screen after each label until the full width of the screen is full.
-
- 2. Places a window that is full-screen width over the label-data and uses
- prt_wn() to copy the contents of the window to the printer.
-
- CALL
-
- This is a main program. It must first be compiled and linked to produce
- prt_labl.exe. It also requires an ASCII file of label data. Assuming that the
- program and file are on the a: drive, the program is executed by the command:
-
- prt_labl labelfile.lbl,
-
- where "labelfile.lbl" is the name of the file containing label data.
-
- PROCEDURES
-
- The format in which the labels will be printed is determined by values specified
- in file label.h. at compile time. Two alternatives for this file are included
- on the system diskette: labels2.h for two-across labels and labels3.h for
- three-across labels (5 rows of text).
-
- Copy either labels2.h or labels3.h to labels.h, compile and link to produce
- prt_labl.exe.
-
- The program expects to find the label data in ASCII form, one line per row of
- address, with a blank line between addresses.
-
-
- */
-
- /* #define WN_DEBUG Commented out when debugging completed */
- #include <stdio.h>
- #include "labels.h"
- #include <wfc.h>
- #include <wfc_glob.h>
-
- #define LINEFEED 10
-
- char stlab[NCOLS + 1]; /*string for 1 row of label data */
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int rb, cb, i, j, nlines;
- int end; /*will equal -1 on end of label file */
- WINDOW wn, wn1, err_wn; /*declare windows */
- FILE *fopen(), *fp; /*file pointer for label data */
- rb = 0; /*start label window at origin */
- cb = 0;
-
- /*----------------------------------------------------------------------------*/
- /* Initialize the Windows for C System */
- /*----------------------------------------------------------------------------*/
- init_wfc();
-
- /*----------------------------------------------------------------------------*/
- /* define window for error messages */
- /*----------------------------------------------------------------------------*/
- defs_wn(&err_wn, 15, 0, 5, 50, BDR_DLNP);
- sw_plcsr(ON, &err_wn);
-
- /*----------------------------------------------------------------------------*/
- /* check label file designation for validity */
- /*----------------------------------------------------------------------------*/
- if (argc != 2)
- errout( "ERROR: Correct format is 'prt_labl filename.ext'\n", "");
- if (argc == 2)
- if ((fp = fopen(argv[1], "r")) == NULLP)
- errout("Can't open ", argv[1]);
-
- /*----------------------------------------------------------------------------*/
- /* define window of size of label + number of rows between labels */
- /* Call set_wn() to check dimensions for consistency and to adjust margins */
- /*----------------------------------------------------------------------------*/
- defs_wn(&wn, rb, 0, RDELTA, NCOLS, BDR_0P);
- sw_att(LDOS, &wn);
- sw_margin(0, 0, &wn); /*change margins */
- set_wn(&wn);
-
- /*----------------------------------------------------------------------------*/
- /* define window of number of rows of label but full width of screen (80 col) */
- /* It is used by prt_wn() to copy row of labels to the printer. */
- /*----------------------------------------------------------------------------*/
- defs_wn(&wn1, rb, 0, RDELTA, 80, BDR_0P);
- sw_att(LDOS, &wn1);
- sw_margin(0, 0, &wn1); /*change margins */
- set_wn(&wn1); /*check dimensions and set margins */
-
- /*----------------------------------------------------------------------------*/
- /* send message to align labels in printer */
- /*----------------------------------------------------------------------------*/
- cls(); /*clear screen for message */
- v_st("Align printer at top row of labels; press any key.",&wn0);
- ki();
- cls(); /*clear screen for label text */
-
- /*----------------------------------------------------------------------------*/
- /*read in data for one label until EOF reached */
- /*----------------------------------------------------------------------------*/
- for(;;)
- {
- pl_wn(rb,cb,&wn); /*place label window in postion */
- mv_cs(0, 0, &wn); /*set write position to beginning */
- for(i = 0; ; i++) /*read til find blank or EOF */
- {
- j = min(i, NROWS -1); /*keep index within array bounds */
- if((end = rd_st(fp, stlab, NCOLS +1, '\n', 8)) == -1)
- break; /*EOF detected */
- if(stlab[0] == '\n') /*done this label if empty line */
- break;
- if(i >= NROWS)
- wn.r--; /*decrement row to print on last */
- /*label line */
- v_st(stlab, &wn); /*put string to label window */
- }
- nlines =i; /* number of text lines in label */
- /*----------------------------------------------------------------------------*/
- /* Let user know if label data won't fit on label */
- /*----------------------------------------------------------------------------*/
- if(nlines > NROWS) /* error -- not enough room */
- {
- set_wn(&err_wn);
- v_st("ERROR: full address does not fit on label.\n", &err_wn);
- bell();
- v_st("Type ESC to exit, any other key to proceed: ", &err_wn);
- if(ki() == K_ESC)
- goto END;
- unset_wn(&err_wn);
- }
- if(nlines > 0 )
- cb += CDELTA; /*move label window to right */
- /*----------------------------------------------------------------------------*/
- /*if full width done, or EOF, print full-width window using print_wn() */
- /*----------------------------------------------------------------------------*/
- if((cb > 79 - NCOLS ) || (end == -1 && cb > 0))
- {
- if(prt_wn(&wn1) <= 0)
- errout("Error in copy_wc","");
- cb = 0; /*reset label window to left side */
- cl_wn(&wn1); /*clear for next set of labels */
- }
- if(end == -1)
- break; /*done if EOF */
- } /*else continue processing labels */
-
- END:
- fclose(fp);
- mv_csr(v_rwq - 2, 0, &wn0); /*move cursor to last line */
- exit_wfc();
- return(0);
- }