home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / epson / printr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1983-09-09  |  4.2 KB  |  205 lines

  1. /*
  2. PRINTER.C  a command to set the flags on an Espon MX series
  3. printer.  I haven't bothered to type up a DOC on this one,
  4. so you'll have to look at the source to see what's going on.
  5.  
  6. It was knocked out late one night, when I got tired of using
  7. PIP to send the control codes.  Don't expect upgrades, and
  8. feel free to stick in your own favorite functions.
  9.  
  10. Copyright (c) 1982 by Gary P. Novosielski
  11. All rights reserved.
  12. Permission is hereby granted for unrestricted non-commercial
  13. use.  Any use for commercial advantage without prior written
  14. consent of the author is prohibited.
  15. */
  16.  
  17. #include "bdscio.h"    
  18.  
  19. /*      Return code definitions   */
  20. #define RESET    1
  21. #define    PITCH    2
  22. #define LPI     3
  23. #define    DRAFT    4
  24. #define TEXT    5
  25. #define    EJECT    6
  26. #define    TINY    7
  27. #define TABS    8
  28. #define SKIP    9
  29. #define NOSKIP    10
  30. #define WIDTH    11
  31. #define ITALIC    12
  32. #define ROMAN    13
  33.  
  34. #define LST    5    /* Bdos function for list output */
  35.  
  36. main(argc, argv)
  37. int  argc;
  38. char **argv;
  39. {
  40.     int  value, oldvalue;
  41.     char xlate();
  42.  
  43.     if (argc < 2)
  44.     {
  45.     puts("PRINTER  Ver:1.0    Copyright (c) 1982 Gary P. Novosielski\n");
  46.     puts("Correct syntax is:\n");
  47.     puts("PRINTER <opt> [<opt>...]\n");
  48.     puts("\twhere <opt> may be:\n\n");
  49.     puts("RESET\t\tPITCH n\t\tLPI n\t\tEJECT\n");
  50.     puts("SKIP\t\tNOSKIP\t\tDRAFT\t\tTEXT\n");
  51.     puts("TINY\t\tWIDTH n\t\tTABS n n n...\tITALIC\n");
  52.     puts("ROMAN\n");
  53.     puts("\nExample:\nPRINTER LPI 6 PITCH 10 DRAFT");
  54.     exit();
  55.     }
  56.  
  57.     while (--argc > 0)
  58.     {
  59.     switch (xlate(*++argv))
  60.     {
  61.     case RESET:
  62.         bdos(LST,ESC);
  63.         bdos(LST,'@');
  64.         bdos(LST,ESC);
  65.         bdos(LST,'C');
  66.         bdos(LST,0);
  67.         bdos(LST,11);
  68.         break;
  69.     case PITCH:
  70.         value = atoi((--argc,*++argv));
  71.         if (value == 10)
  72.         bdos(LST,18);
  73.         else if (value == 17)
  74.         bdos(LST,15);
  75.         else
  76.         abort ("%s--Invalid pitch.  Not 10 or 17.",*argv);
  77.         break;
  78.     case LPI:
  79.         if (!(value = atoi((--argc,*++argv))) || value > 216)
  80.         abort ("%s--Invalid Lines per Inch\nMust be 1 - 216.",*argv);
  81.         bdos(LST,ESC);
  82.         bdos(LST,'3');
  83.         bdos(LST,216/value);
  84.         break;
  85.     case DRAFT:
  86.         bdos(LST,ESC);
  87.         bdos(LST,'H');
  88.         bdos(LST,ESC);
  89.         bdos(LST,'T');
  90.         break;
  91.     case TEXT:
  92.         bdos(LST,ESC);
  93.         bdos(LST,'G');
  94.         bdos(LST,ESC);
  95.         bdos(LST,'U');
  96.         bdos(LST,1);
  97.         break;
  98.     case EJECT:
  99.         bdos(LST,12);
  100.         break;
  101.     case TINY:
  102.         bdos(LST,ESC);
  103.         bdos(LST,'S');
  104.         bdos(LST,0);
  105.         bdos(LST,ESC);
  106.         bdos(LST,'1');
  107.         break;
  108.     case TABS:
  109.         oldvalue = 0;
  110.         bdos(LST,ESC);
  111.         bdos(LST,'D');
  112.         while(--argc)
  113.         {
  114.         value = atoi(*++argv);
  115.         if(value && value <= oldvalue)
  116.         {
  117.             bdos(LST,0);
  118.             abort("Tabs not in increasing order");
  119.         }
  120.         if (!value)
  121.             --argv, ++argc;
  122.         else
  123.             bdos(LST,(oldvalue = value));
  124.         }
  125.         bdos(LST,0);
  126.         break;
  127.     case SKIP:
  128.         bdos(LST,ESC);
  129.         bdos(LST,'N');
  130.         bdos(LST,6);
  131.         break;
  132.     case NOSKIP:
  133.         bdos(LST,ESC);
  134.         bdos(LST,'N');
  135.         bdos(LST,0);
  136.         break;
  137.     case WIDTH:
  138.         if (!(--argc))
  139.         break;
  140.         if (!(value = atoi(*++argv)))
  141.         abort("%s--Invalid width.",*argv);
  142.         bdos(LST,ESC);
  143.         bdos(LST,'Q');
  144.         bdos(LST,value);
  145.         break;
  146.     case ITALIC:
  147.         bdos(LST,ESC);
  148.         bdos(LST,'4');
  149.         break;
  150.     case ROMAN:
  151.         bdos(LST,ESC);
  152.         bdos(LST,'5');
  153.         break;
  154.  
  155.  
  156.     default:
  157.         abort("%s--Unknown keyword.",*argv);
  158.     }
  159.     }  
  160. }
  161.  
  162. char xlate(string)
  163.   char *string;
  164. {
  165.     if (!strcmp(string,"RESET"))
  166.     return RESET;
  167.     else if (!strcmp(string,"PITCH"))
  168.     return PITCH;
  169.     else if (!strcmp(string,"LPI"))
  170.     return LPI;
  171.     else if (!strcmp(string,"DRAFT"))
  172.     return DRAFT;
  173.     else if (!strcmp(string,"TEXT"))
  174.     return TEXT;
  175.     else if (!strcmp(string,"EJECT"))
  176.     return EJECT;
  177.     else if (!strcmp(string,"TINY"))
  178.     return TINY;
  179.     else if (!strcmp(string,"TABS"))
  180.     return TABS;
  181.     else if (!strcmp(string,"TAB"))
  182.     return TABS;
  183.     else if (!strcmp(string,"SKIP"))
  184.     return SKIP;
  185.     else if (!strcmp(string,"NOSKIP"))
  186.     return NOSKIP;
  187.     else if (!strcmp(string,"WIDTH"))
  188.     return WIDTH;
  189.     else if (!strcmp(string,"ITALIC"))
  190.     return ITALIC;
  191.     else if (!strcmp(string,"ROMAN"))
  192.     return ROMAN;
  193.     else
  194.     return ERROR;
  195. }
  196.  
  197. abort(p1,p2,p3,p4,p5,p6,p7,p8)
  198. unsigned p1,p2,p3,p4,p5,p6,p7,p8;
  199. {
  200.     printf(p1,p2,p3,p4,p5,p6,p7,p8);
  201.     unlink("A:$$$.SUB");
  202.     puts("...ABORTED");
  203.     exit();
  204. }
  205.