home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 18 / CD_ASCQ_18_111294_W.iso / dos / prg / pas / theprn25 / demo_prn.c < prev    next >
C/C++ Source or Header  |  1994-07-24  |  5KB  |  214 lines

  1. /************************************************************************
  2.  
  3.    Demo_Prn.C     The Printer (tm) demo.  Copyright 1994, Rob W. Smetana
  4.  
  5.    << BEFORE running this, turn screen-swapping ON if appropriate. >>
  6.  
  7.    Purpose:       * Demonstrate reading printer code records.
  8.  
  9.                   * Show how one might display printer codes.
  10.  
  11.                     Something like this might be used inside a
  12.                     program to show users which codes are
  13.                     available (ie., not blank) and perhaps what
  14.                     they should do to invoke each option.
  15.  
  16.       NOTE:       Some printer codes may contain control codes which
  17.                   will screw up the display.  Try a different printer.
  18.                   And in your own programs you might want to use an ASM
  19.                   "quickprint" routine to overcome this problem.
  20.  
  21.    Requires:
  22.  
  23.     1. Printer.Cfg -- a 2k printer code file saved by Printer.Exe.
  24.                       BEFORE you run this, you MUST run Printer.Exe,
  25.                       select a printer, then press F2 to save Printer.Cfg.
  26.  
  27.     2. The_Prn.C   -- an include file with data structures (although
  28.                       we won't use those structures here)
  29.  
  30. ************************************************************************/
  31.  
  32. #include "the_prn.h"        /* for database structures */
  33.  
  34. #include <string.h>         /* for function prototypes */
  35. #include <conio.h>          /* ditto */
  36. #include <stdio.h>          /* ditto */
  37.  
  38. #include <dos.h>            /* for CLS (Clear Screen) and LOCATE */
  39. #define  VIDEO  0x10        /* ditto */
  40.  
  41. /*
  42.    For what we're about to do here, it's easier reading printer codes
  43.    with some simple variables -- rather than our types.
  44.  
  45.    Printer.Cfg consists of 2 1024-byte records (Labels and Codes).
  46.    Both records start with a 44-byte header, followed by 980 bytes
  47.    of labels or printer codes.
  48. */
  49.  
  50. char Header [44];
  51. char Labels [980];
  52. char Codes  [980];
  53.  
  54.  
  55. /* prototypes for local functions */
  56. void locate (unsigned char , unsigned char);
  57. void cls (unsigned char);
  58. void PrintHeader (void);
  59.  
  60. /* locate the cursor using BIOS SetCursor function -- page 0 hardcoded */
  61.  
  62. void locate (row, col)
  63. unsigned char row, col;
  64. {
  65.    union REGS reg;
  66.    reg.h.ah = 2;
  67.    reg.h.dh = row-1;           /* we use 1,1 as top, left; BIOS uses 0,0 */
  68.    reg.h.dl = col-1;
  69.    reg.h.bh = 0;
  70.    int86(VIDEO, ®, ®);
  71. }
  72.  
  73. /* CLS using BIOS Scroll function.  ALSO homes cursor:  Locate (1,1). */
  74.  
  75. void cls (colr)
  76.  
  77. unsigned char colr;
  78.  
  79. {
  80.     union REGS reg;
  81.  
  82.     reg.h.ah = 6;           /* service 6 -- scroll up  */
  83.     reg.h.al = 0;           /* scroll 0 lines -- clear */
  84.  
  85.     reg.h.ch = 0;           /* scroll 25 x 80 screen:  0,0 to 24,79 */
  86.     reg.h.cl = 0;
  87.     reg.h.dh = 24;
  88.     reg.h.dl = 79;
  89.     reg.h.bh = colr;
  90.     int86(VIDEO, ®, ®);
  91.  
  92.     locate (1, 1);
  93. }
  94.  
  95.  
  96. /* print Manufacturer, model, etc. */
  97.  
  98. /*************************************************************************/
  99. void PrintHeader ()
  100. /*************************************************************************/
  101.  
  102. {
  103.   unsigned char n;
  104.  
  105.   cls (27);
  106.  
  107.   for (n = 0; n < 44; ++n)            /* print our 44-byte header */
  108.   {
  109.     switch (n)
  110.       {
  111.       case 1:
  112.         printf (" Manufacturer: ");
  113.         break;
  114.       case 16:
  115.         printf ("  Model: ");
  116.         break;
  117.       case 30:
  118.         printf ("  Emulates: ");
  119.         break;
  120.       }
  121.      printf("%c",Header [n]);
  122.   }
  123. }
  124.  
  125.  
  126. /************************************************************************/
  127.  
  128. int main (void)
  129.  
  130.    {
  131.  
  132.    char Cfg_File[64];
  133.    FILE *fp;
  134.  
  135.    int c, offset;
  136.    char n, row, col;
  137.  
  138.    /* home cursor */
  139.    cls (27);
  140.  
  141.    strcpy (Cfg_File, "PRINTER.CFG");
  142.  
  143.    fp = fopen (Cfg_File, "rb");
  144.  
  145.    if (fp == NULL)
  146.       {
  147.         return(-999);     /* file not found */
  148.       }
  149.  
  150.    /* Read 2 1024-byte records:  Labels and Printer Codes. */
  151.    /* Both records begin with the same 44-byte header.     */
  152.  
  153.    fread (Header, sizeof Header, 1, fp);
  154.    fread (Labels, sizeof Labels, 1, fp);
  155.  
  156.    fread (Header, sizeof Header, 1, fp);
  157.    fread (Codes, sizeof Codes, 1, fp);
  158.    PrintHeader();
  159.  
  160.    offset =1 ;
  161.    row = 3;
  162.    col = 4;
  163.  
  164.    for (n = 1; n < 71; ++n)
  165.    {
  166.  
  167.      locate (row,col);
  168.  
  169.      /* Print the labels */
  170.      for (c = 0; c < 14; ++c)
  171.          printf("%c",Labels[offset+c-1]);
  172.  
  173.      printf("    ");
  174.  
  175.      /* and now the codes */
  176.      for (c = 0; c < 14; ++c)
  177.          printf("%c",Codes[offset+c-1]);
  178.  
  179.      /* move to the next Label/Printer Code */
  180.      offset = offset + 14;
  181.  
  182.      /*
  183.        There are more codes than will fit on a screen.
  184.        So pause after 1st screen.
  185.      */
  186.  
  187.      if (n == 42)
  188.      {
  189.        locate(25,15);
  190.        printf ("There's more.   Press <SPACE> to continue . . .");
  191.        getche();
  192.        PrintHeader ();
  193.        row = 2;
  194.        col = 4;
  195.      }
  196.  
  197.      row++;
  198.  
  199.      if (row > 23)
  200.         {
  201.          row =3;
  202.          col = 40;
  203.         }
  204.    }
  205.  
  206.    locate (25, 15);
  207.    printf ("That's all.     Press <SPACE> to continue . . .");
  208.    getche();
  209.    cls(7);
  210.    return (0);
  211.  
  212. }
  213.  
  214.