home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c003 / 1.ddi / DEMOS / PRT_LABL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-13  |  6.8 KB  |  180 lines

  1. /* prt_labl.c - prints ASCII file label data in parallel formats
  2.  
  3.     ************* Copyright 1985 by Vermont Creative Software **************
  4.  
  5. Permission to use this program for personal use is granted.  You
  6. may not sell or redistribute the program or adaptations of it
  7. without prior written consent.
  8.  
  9.  
  10. NAME
  11.  
  12. prt_labl.c -- prints ASCII file label data in parallel formats
  13.  
  14. DATE:  February 5, 1986
  15.  
  16. USAGE
  17.  
  18. To print labels stored sequentially in a ASCII file in two or three across
  19. format.
  20.  
  21. To illustrate the use of windows and the prt_wn() function for formatting and
  22. printing text.
  23.  
  24. FUNCTION
  25.  
  26. 1.  Writes label data read from a disk file to a window.  The window is moved
  27. across the screen after each label until the full width of the screen is full.
  28.  
  29. 2.  Places a window that is full-screen width over the label-data and uses
  30. prt_wn() to copy the contents of the window to the printer.
  31.  
  32. CALL
  33.  
  34. This is a main program.  It must first be compiled and linked to produce
  35. prt_labl.exe.  It also requires an ASCII file of label data.  Assuming that the
  36. program and file are on the a: drive, the program is executed by the command:
  37.  
  38.      prt_labl labelfile.lbl,
  39.  
  40. where "labelfile.lbl" is the name of the file containing label data.
  41.  
  42. PROCEDURES
  43.  
  44. The format in which the labels will be printed is determined by values specified
  45. in file label.h. at compile time.  Two alternatives for this file are included
  46. on the system diskette: labels2.h for two-across labels and labels3.h for
  47. three-across labels (5 rows of text).
  48.  
  49. Copy either labels2.h or labels3.h to labels.h, compile and link to produce
  50. prt_labl.exe.
  51.  
  52. The program expects to find the label data in ASCII form, one line per row of
  53. address, with a blank line between addresses.
  54.  
  55.  
  56. */
  57.  
  58. /* #define WN_DEBUG        Commented out when debugging completed          */
  59. #include <stdio.h>
  60. #include "labels.h"
  61. #include <wfc.h>
  62. #include <wfc_glob.h>
  63.  
  64. #define LINEFEED 10
  65.  
  66. char stlab[NCOLS + 1];            /*string for 1 row of label data      */
  67.  
  68. main(argc, argv)
  69. int argc;
  70. char *argv[];
  71. {
  72.     int rb, cb, i, j, nlines;
  73.     int end;                /*will equal -1 on end of label file  */
  74.     WINDOW wn, wn1, err_wn;        /*declare windows              */
  75.     FILE *fopen(), *fp;         /*file pointer for label data          */
  76.     rb = 0;                /*start label window at origin          */
  77.     cb = 0;
  78.  
  79. /*----------------------------------------------------------------------------*/
  80. /*  Initialize the Windows for C System                       */
  81. /*----------------------------------------------------------------------------*/
  82.     init_wfc();
  83.  
  84. /*----------------------------------------------------------------------------*/
  85. /* define window for error messages                          */
  86. /*----------------------------------------------------------------------------*/
  87.     defs_wn(&err_wn, 15, 0, 5, 50, BDR_DLNP);
  88.     sw_plcsr(ON, &err_wn);
  89.  
  90. /*----------------------------------------------------------------------------*/
  91. /* check label file designation for validity                      */
  92. /*----------------------------------------------------------------------------*/
  93.     if (argc != 2)
  94.     errout( "ERROR: Correct format is 'prt_labl filename.ext'\n", "");
  95.     if (argc == 2)
  96.     if ((fp = fopen(argv[1], "r")) == NULLP)
  97.         errout("Can't open ", argv[1]);
  98.  
  99. /*----------------------------------------------------------------------------*/
  100. /* define window of size of label + number of rows between labels          */
  101. /* Call set_wn() to check dimensions for consistency and to adjust margins    */
  102. /*----------------------------------------------------------------------------*/
  103.     defs_wn(&wn, rb, 0, RDELTA, NCOLS, BDR_0P);
  104.     sw_att(LDOS, &wn);
  105.     sw_margin(0, 0, &wn);        /*change margins              */
  106.     set_wn(&wn);
  107.  
  108. /*----------------------------------------------------------------------------*/
  109. /* define window of number of rows of label but full width of screen (80 col) */
  110. /* It is used by prt_wn() to copy row of labels to the printer.           */
  111. /*----------------------------------------------------------------------------*/
  112.     defs_wn(&wn1, rb, 0, RDELTA, 80, BDR_0P);
  113.     sw_att(LDOS, &wn1);
  114.     sw_margin(0, 0, &wn1);        /*change margins              */
  115.     set_wn(&wn1);            /*check dimensions and set margins    */
  116.  
  117. /*----------------------------------------------------------------------------*/
  118. /* send message to align labels in printer                      */
  119. /*----------------------------------------------------------------------------*/
  120.     cls();                /*clear screen for message          */
  121.     v_st("Align printer at top row of labels; press any key.",&wn0);
  122.     ki();
  123.     cls();                /*clear screen for label text          */
  124.  
  125. /*----------------------------------------------------------------------------*/
  126. /*read in data for one label until EOF reached                      */
  127. /*----------------------------------------------------------------------------*/
  128.     for(;;)
  129.     {
  130.     pl_wn(rb,cb,&wn);            /*place label window in postion   */
  131.     mv_cs(0, 0, &wn);            /*set write position to beginning */
  132.     for(i = 0; ; i++)            /*read til find blank or EOF      */
  133.     {
  134.         j = min(i, NROWS -1);        /*keep index within array bounds  */
  135.         if((end = rd_st(fp, stlab, NCOLS +1, '\n', 8)) == -1)
  136.         break;                /*EOF detected              */
  137.         if(stlab[0] == '\n')            /*done this label if empty line   */
  138.         break;
  139.         if(i >= NROWS)
  140.         wn.r--;             /*decrement row to print on last  */
  141.                         /*label line              */
  142.         v_st(stlab, &wn);            /*put string to label window      */
  143.     }
  144.     nlines =i;                /* number of text lines in label  */
  145. /*----------------------------------------------------------------------------*/
  146. /*  Let user know if label data won't fit on label                            */
  147. /*----------------------------------------------------------------------------*/
  148.     if(nlines > NROWS)            /* error -- not enough room       */
  149.     {
  150.         set_wn(&err_wn);
  151.         v_st("ERROR:  full address does not fit on label.\n", &err_wn);
  152.         bell();
  153.         v_st("Type ESC to exit, any other key to proceed: ", &err_wn);
  154.         if(ki() == K_ESC)
  155.         goto END;
  156.         unset_wn(&err_wn);
  157.     }
  158.     if(nlines > 0 )
  159.         cb += CDELTA;           /*move label window to right       */
  160. /*----------------------------------------------------------------------------*/
  161. /*if full width done, or EOF, print full-width window using print_wn()          */
  162. /*----------------------------------------------------------------------------*/
  163.     if((cb > 79 - NCOLS ) || (end == -1 && cb > 0))
  164.     {
  165.         if(prt_wn(&wn1) <= 0)
  166.         errout("Error in copy_wc","");
  167.         cb = 0;              /*reset label window to left side   */
  168.         cl_wn(&wn1);          /*clear for next set of labels      */
  169.     }
  170.     if(end == -1)
  171.         break;              /*done if EOF               */
  172.     }                      /*else continue processing labels   */
  173.  
  174. END:
  175.     fclose(fp);
  176.     mv_csr(v_rwq - 2, 0, &wn0);     /*move cursor to last line          */
  177.     exit_wfc();
  178.     return(0);
  179. }
  180.