home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / pcpilot.zip / PRTCODES.C < prev    next >
Text File  |  1990-01-13  |  6KB  |  267 lines

  1. /*
  2.     PRTCODES.C - Display and modify printer codes.
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <process.h>
  7. #include <ctype.h>
  8. #include <dos.h>
  9. #include <kbd.h>
  10.  
  11. extern int BorderClr;
  12. extern int TitleClr;
  13. extern int TextClr;
  14. extern int FooterClr;
  15. extern int HighlightClr;
  16.  
  17. void PrintCodes (void);
  18. static void PrtTimeout (unsigned Seconds);
  19. static int GetCode(int idx);
  20. static int SendCode (char *ControlString);
  21. static int ErrRtn (void);
  22. static void DrawMenu (void);
  23. static int IsOn(int code);
  24. static void Highlight(int code, int idx, int row);
  25. static void ResetAll(void);
  26.  
  27. struct PrtMnu {
  28.     char *name;
  29.     int status;
  30. };
  31.  
  32. struct PrtMnu Pmnu[] = {
  33.     " Wide       :    ", 0,
  34.     " Condensed  :    ", 0,
  35.     " Italics    :    ", 0,
  36.     " Emphasized :    ", 0,
  37.     " Bold       :    ", 0,
  38.     " Elite      :    ", 0,
  39.     " Subscript  :    ", 0,
  40.     " Near LQ    :    ", 0,
  41.     " Send Line Feed  ", 0,
  42.     " Send Form Feed  ", 0,
  43.     "    Reset All    ", 0
  44.     };
  45.  
  46.  
  47. static int OldRow, OldCol;
  48.  
  49. void PrintCodes ()
  50. {
  51.     int Row = 5;
  52.     int Quit = 0;
  53.     int Index = 0;
  54.  
  55.     ScrGetCur (&OldCol, &OldRow, 0);
  56.     ScrPush();
  57.     HideCur();
  58.     DrawMenu();
  59.  
  60.     SetAttrib(HighlightClr, 52,Row,68,Row);
  61.     while (!Quit)    {
  62.         Highlight(1, Index, Row);
  63.         switch (KbdGetC())    {
  64.             case RET:
  65.                 if (GetCode(Index))
  66.                     Quit = 1;
  67.                 else    {
  68.                     if (IsOn(Index))
  69.                         Pmnu[Index].status = 0;
  70.                     else
  71.                         Pmnu[Index].status = 1;
  72.                 }
  73.                 break;
  74.             case UP:
  75.                 Highlight(0, Index, Row);
  76.                 Row--;
  77.                 Index--;
  78.                 if (Row < 5)    {
  79.                     Row = 15;
  80.                     Index = 10;
  81.                 }
  82.                 break;
  83.             case DN:
  84.                 Highlight(0, Index, Row);
  85.                 Row++;
  86.                 Index++;
  87.                 if (Row > 15)    {
  88.                     Row = 5;
  89.                     Index = 0;
  90.                 }
  91.                 break;
  92.             case PGUP:
  93.             case HOME:
  94.                 Highlight(0, Index, Row);
  95.                 Row = 5;
  96.                 Index = 0;
  97.                 break;
  98.             case PGDN:
  99.             case END:
  100.                 Highlight(0, Index, Row);
  101.                 Row = 15;
  102.                 Index = 10;
  103.                 break;
  104.             case ESC:
  105.                 Quit = 1;
  106.                 break;
  107.             default :
  108.                 break;
  109.         }
  110.     }
  111.  
  112.     PrtTimeout (20);
  113.     ScrPop(1);
  114.     ScrSetCur(OldCol, OldRow, 0);
  115.     return;
  116. }
  117.  
  118. static int GetCode(int idx)
  119. {
  120.     char *OnStr[] =    {
  121.         "\x1b\x57\x31",        /* wide                  */
  122.         "\x1b\x0f",         /* condensed             */
  123.         "\x1b\x34",            /* italics               */
  124.         "\x1b\x45",            /* emphasized            */
  125.         "\x1b\x47",            /* bold                  */
  126.         "\x1b\x4d",            /* elite                 */
  127.         "\x1b\x53\x01",        /* subscript             */
  128.         "\x1b\x78\x01",        /* near letter quality   */
  129.         "\x0a",                /* line feed             */
  130.         "\x0c",                /* form feed             */
  131.         "\x1b\x40",            /* reset all             */
  132.     };
  133.     char *OffStr[] =    {
  134.         "\x1b\x57\x30",        /* wide off                 */
  135.         "\x12",                /* condensed off            */
  136.         "\x1b\x35",            /* italics off              */
  137.         "\x1b\x46",            /* emphasized off           */
  138.         "\x1b\x48",            /* bold off                 */
  139.         "\x1b\x50",            /* elite off                */
  140.         "\x1b\x54",            /* subscript off            */
  141.         "\x1b\x78\x00",        /* near letter quality off  */
  142.         "\x0a",                /* line feed off            */
  143.         "\x0c",                /* form feed off            */
  144.         "\x1b\x40",            /* reset all off            */
  145.     };
  146.  
  147.     if (IsOn(idx))    {
  148.         if (SendCode(OffStr[idx]))
  149.             return(1);
  150.     }
  151.     else
  152.         if (SendCode(OnStr[idx]))
  153.             return(1);
  154.     if (idx == 10)
  155.         ResetAll();
  156.     return(0);
  157. }
  158.  
  159. static void ResetAll()
  160. {
  161.     register int i;
  162.  
  163.     for (i=0; i<8; i++)    {
  164.         PutStr(65,5+i, FooterClr, "OFF ");
  165.         Pmnu[i].status = 0;
  166.     }
  167. }
  168.  
  169. static int SendCode (char *ControlString)
  170. {
  171.     while (*ControlString)    {
  172.         _DX = 0;
  173.         _AH = 0;
  174.         _AL = *ControlString;
  175.         geninterrupt (0x17);
  176.         if (_AH & 0x29)    {
  177.             if (ErrorRtn())
  178.                 return (1);
  179.             else
  180.                 continue;
  181.         }
  182.         ++ControlString;
  183.     }
  184.     return (0);
  185. }
  186.  
  187. static int ErrorRtn()
  188. {
  189.     ScrPush();
  190.     ShadowBox(35,9,62,13, 2, BorderClr);
  191.     PutStr(46,9, TitleClr,            " Error ");
  192.     PutStr(36,10, TextClr,  " Error writing to printer ");
  193.     PutStr(35,11, BorderClr, "╞══════════════════════════╡");
  194.     PutStr(36,12, FooterClr,  "      A)bort  R)etry?     ");
  195.     PutStr(42,12, TextClr, "A");
  196.     PutStr(50,12, TextClr, "R");
  197.     ScrSetCur(58,12, 0);
  198.     for (;;)
  199.         switch (toupper(GetKey()))    {
  200.             case 'R':
  201.                 HideCur();
  202.                 ScrPop(1);
  203.                 return(0);
  204.             case 'A':
  205.                 HideCur();
  206.                 ScrPop(1);
  207.                 return(1);
  208.         }
  209. }
  210.  
  211.  
  212. static void PrtTimeout (unsigned Seconds)
  213. {
  214.     *((char far *)0x00400078) = ++Seconds;
  215. }
  216.  
  217. static void DrawMenu ()
  218. {
  219.     register int i;
  220.  
  221.     ShadowBox(51,2,69,18, 2, BorderClr);
  222.     PutStr(51,4, BorderClr,  "╞═════════════════╡");
  223.     PutStr(51,16, BorderClr, "╞═════════════════╡");
  224.     PutStr(52,3, TitleClr,   "  Printer Setup  ");
  225.     PutStr(52,17, FooterClr, " %c %c  %c%c%c  <Esc> ", 24, 25, 17,196,217);
  226.  
  227.     for (i=0; i<11; i++)    {
  228.         PutStr(52,5+i, TextClr, "%s", Pmnu[i].name);
  229.         if (i < 8)    {
  230.             if (IsOn(i))
  231.                 PutStr(65,5+i, FooterClr, "ON  ");
  232.             else
  233.                 PutStr(65,5+i, FooterClr, "OFF ");
  234.         }
  235.     }
  236. }
  237.  
  238. static void Highlight(int code, int idx, int row)
  239. {
  240.     switch (code)    {
  241.         case 0:
  242.             PutStr(52,row, TextClr, "%s", Pmnu[idx].name);
  243.             if (idx < 8)    {
  244.                 if (IsOn(idx))
  245.                     PutStr(65,row, FooterClr, "ON  ");
  246.                 else
  247.                     PutStr(65,row, FooterClr, "OFF ");
  248.             }
  249.             break;
  250.         case 1:
  251.             SetAttrib(HighlightClr, 52,row,68,row);
  252.             if (idx < 8)    {
  253.                 if (IsOn(idx))
  254.                     PutStr(65,row, HighlightClr, "ON  ");
  255.                 else
  256.                     PutStr(65,row, HighlightClr, "OFF ");
  257.             }
  258.             break;
  259.     }
  260. }
  261.  
  262. static int IsOn(int code)
  263. {
  264.     if (Pmnu[code].status)
  265.         return(1);
  266.     return(0);
  267. }