home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / turbo_c / tc130.arc / OKISET.C < prev    next >
Text File  |  1987-08-13  |  10KB  |  408 lines

  1. /*
  2. **                OKIDATA PRINTER SETUP UTILITY
  3. ** Copyright 1987, S.E. Margison
  4. ** 8-12-87 A
  5. **
  6. **   As distributed, this program requires (for compilation):
  7. **     "Steve's Turbo-C Library" version 1.30 or later
  8. **   which may be obtained without registration from many Bulletin
  9. **   Board Systems including:
  10. **      Compuserve IBMSW
  11. **      Cul-De-Sac (Holliston, MA.)
  12. **      GEnie
  13. **   and software library houses including:
  14. **      Public (Software) Library (Houston, TX.)
  15. **
  16. **   or by registration:
  17. **      $10 for Docs, Small Model Library
  18. **      $25 for Docs, C, S, M, L, H libraries, and complete library source
  19. **              in C and Assembler
  20. **     Steven E. Margison
  21. **     124 Sixth Street
  22. **     Downers Grove, IL, 60515
  23. **
  24. */
  25.  
  26. #include <stdio.h>
  27. #include <ctype.h>
  28. #include <smdefs.h>
  29. #include <keys.h>
  30.  
  31. #define NONE 0xff
  32. #define PICA 0
  33. #define COND 1
  34. #define DRAFT 0
  35. #define LQ 1
  36. #define beep putchar(BELL)
  37.  
  38. short length, linespc, lqspc, pitch, style;
  39. short printer;  /* 0 = PRN, 1 = LPT1, 2 = LPT2 */
  40.  
  41. char pica[] =  "NORMAL   ",
  42.      cond[] =  "CONDENSED",
  43.      draft[] = "DRAFT         ",
  44.      lq[] =    "LETTER QUALITY",
  45.      lpt1[] = "LPT1:",
  46.      lpt2[] = "LPT2:",
  47.      prn[] = "PRN: ";
  48.  
  49. char line1[] = "OKIDATA ML84 CONFIGURATOR V1.11",
  50.      line2[] = "- by Steven E. Margison -",
  51.      line3[] = "Copyright 1987 -- All Rights Reserved",
  52.      line4[] = "F1   Pitch: ",
  53.      line5[] = "F2   Style: ",
  54.      line6[] = "F3   LQ spacing: ",
  55.      line7[] = "F4   Form Length (lines): ",
  56.      line8[] = "F5   Line Spacing: ",
  57.      line9[] = "F6   ",
  58.      line10[]= "F7   Output Channel - ",
  59.      line11[]= "F8   Normal Defaults",
  60.      line12[]= "F9   Send Control Codes",
  61.      line13[]= "FK10  -- Return to DOS --",
  62.      line14[]= "Waiting...",
  63.      cline[]="                                                        ";
  64.  
  65. main() {           /* no command line arguments */
  66.    int key;
  67.    printer = 0;
  68.    lqspc = linespc = pitch = style = length = NONE;
  69.    domenu(NO);           /* initialize the screen */
  70.  
  71.    while(YES) {
  72.       key = getkey();    /* get a function code */
  73.       if(key < 0xff) {
  74.          beep;
  75.          continue;
  76.          }
  77.       key &= 0x7f;
  78.       switch(key) {
  79.          case FK1:   /* select pitch */
  80.             dofk1();
  81.             if((pitch is COND) and (style is LQ)) {
  82.                style = DRAFT;
  83.                putstyle();
  84.                }
  85.             prompt();
  86.             break;
  87.          case FK2:   /* select style */
  88.             dofk2();
  89.             if((style is LQ) and (pitch is COND)) {
  90.                pitch = PICA;
  91.                putpitch();
  92.                }
  93.             prompt();
  94.             break;
  95.          case FK3:   /* specify LQ character spacing */
  96.             if((lqspc = get2digs(9, 32)) is NONE) { prompt(); break; }
  97.             if(style isnot LQ) {
  98.                style = LQ;
  99.                putstyle();
  100.                if(pitch is COND) {
  101.                   pitch = PICA;
  102.                   putpitch();
  103.                   }
  104.                }
  105.             if(lqspc > 0x11) {
  106.                lqspc = 0;
  107.                warn(1);
  108.                putlqspc();
  109.                }
  110.             prompt();
  111.             break;
  112.          case FK4:   /* specify Form length in lines */
  113.             if((length = get2digs(10, 41)) is NONE) { prompt(); break; }
  114.             if(length is 0) {
  115.                length = 0x66;
  116.                warn(2);
  117.                putlength();
  118.                }
  119.             prompt();
  120.             break;
  121.          case FK5:  /* specify line spacing */
  122.             dofk5();
  123.             prompt();
  124.             break;
  125.          case FK6:
  126.             beep;
  127.             break;
  128.          case FK7:  /* select output channel */
  129.             dokey7();
  130.             prompt();
  131.             break;
  132.          case FK8:   /* set normal options */
  133.             linespc = 0;  /* 6 lpi */
  134.             putlinespc();
  135.             length = 0x66;
  136.             putlength();
  137.             style = DRAFT;
  138.             putstyle();
  139.             pitch = PICA;
  140.             putpitch();
  141.             lqspc = NONE;
  142.             putlqspc();
  143.             printer = 0;
  144.             putprinter();
  145.             prompt();
  146.             break;
  147.          case FK9:  /* write the codes out and exit */
  148.             dofk9();
  149.             break;
  150.          case FK10:
  151.             exit2dos();
  152.             domenu(YES);
  153.             break;
  154.          default:
  155.             beep;
  156.          }   /* end of switch */
  157.       }      /* end of main while */
  158.    }         /* end of main() */
  159.  
  160.  
  161. domenu(cmd) int cmd; {
  162.    int i;
  163.    /* if cmd is YES, then place current setting in menu for each item */
  164.    cls();
  165.    mkbox(0, 0, 80, 22, 0);   /* place the border on blank screen */
  166.    i = center(line1, 80);
  167.    d_say(3, i, line1);
  168.    i = center(line2, 80);
  169.    d_say(4, i, line2);
  170.    i = center(line3, 80);
  171.    d_say(5, i, line3);
  172.    d_say(7, 15, line4);
  173.    if(cmd and (pitch isnot NONE)) putpitch();
  174.    d_say(8, 15, line5);
  175.    if(cmd and (style isnot NONE)) putstyle();
  176.    d_say(9, 15, line6);
  177.    if(cmd and (lqspc isnot NONE)) putlqspc();
  178.    d_say(10, 15, line7);
  179.    if(cmd and (length isnot NONE)) putlength();
  180.    d_say(11, 15, line8);
  181.    if(cmd and (linespc isnot NONE)) putlinespc();
  182.    d_say(12, 15, line9);
  183.    d_say(13, 15, line10);
  184.    putprinter();
  185.    d_say(14, 15, line11);
  186.    d_say(15, 15, line12);
  187.    d_say(16, 15, line13);
  188.    prompt();
  189.    }
  190.  
  191.  
  192. prompt() {
  193.    d_say(19, 15, cline);
  194.    d_say(19, 15, line14);
  195.    }
  196.  
  197. warn(value) int value; {
  198.    beep;
  199.    switch(value) {
  200.       case 1:
  201.          d_say(19, 15, "Value too large.  Range is 0-11.");
  202.          break;
  203.       case 2:
  204.          d_say(19, 15, "Length value of 0 meaningless.");
  205.          break;
  206.       default:
  207.          prompt();
  208.          return;
  209.       }
  210.    d_say(20, 15, "Strike any key to continue...");
  211.    getkey();
  212.    d_say(20, 15, cline);
  213.    prompt();
  214.    }
  215.  
  216.  
  217. putpitch() {
  218.    if(pitch is PICA) { d_say(7, 27, pica); return; }
  219.    if(pitch is COND) { d_say(7, 27, cond); return; }
  220.    }
  221.  
  222. putstyle() {
  223.    if(style is DRAFT) { d_say(8, 27, draft); return; }
  224.    if(style is LQ) { d_say(8, 27, lq); return; }
  225.    }
  226.  
  227. putlqspc() {
  228.    char i;
  229.    d_pos(9, 32, 0);
  230.    if(lqspc is NONE) { fputs("  ", stdout); return; }
  231.    i = (char)((lqspc >>4) | '0');
  232.    fputc(i, stdout);
  233.    i = (char)((lqspc & 0x0f) | '0');
  234.    fputc(i, stdout);
  235.    }
  236.  
  237. putlength() {
  238.    char i;
  239.    d_pos(10, 41, 0);
  240.    i = (char)((length >>4) | '0');
  241.    fputc(i, stdout);
  242.    i = (char)((length & 0x0f) | '0');
  243.    fputc(i, stdout);
  244.    }
  245.  
  246. putlinespc() {
  247.    d_pos(11, 34, 0);
  248.    if(linespc is 0) puts("6 lpi");
  249.    else puts("8 lpi");
  250.    }
  251.  
  252. putprinter() {
  253.    d_pos(13, 37, 0);
  254.    switch(printer) {
  255.       case 0: default:
  256.          puts(prn);
  257.          return;
  258.       case 1:
  259.          puts(lpt1);
  260.          return;
  261.       case 2:
  262.          puts(lpt2);
  263.          return;
  264.       }
  265.    }
  266.  
  267. dofk1() {
  268.    int chr;
  269.    if(pitch is NONE) { pitch = PICA; putpitch(); }
  270.    d_pos(7, 27, 0);
  271.    while((chr = getkey()) isnot '\r') {
  272.       if(chr > 255) { beep; continue; }
  273.       if(chr isnot ' ') { beep; continue; }
  274.       ++pitch;
  275.       pitch &= 0x01;  /* toggle between 0 and 1 only */
  276.       putpitch();
  277.       d_pos(7, 27, 0);
  278.       }
  279.    }
  280.  
  281. dofk2() {
  282.    int chr;
  283.    if(style is NONE) { style = DRAFT; putstyle(); }
  284.    d_pos(8, 27, 0);
  285.    while((chr = getkey()) isnot '\r') {
  286.       if(chr > 255) { beep; continue; }
  287.       if(chr isnot ' ') { beep; continue; }
  288.       ++style;
  289.       style &= 0x01;  /* toggle between 0 and 1 only */
  290.       putstyle();
  291.       d_pos(8, 27, 0);
  292.       }
  293.    }
  294.  
  295. dofk5() {
  296.    int chr;
  297.    if(linespc is NONE) { linespc = 0; putlinespc(); }
  298.    d_pos(11, 34, 0);
  299.    while((chr = getkey()) isnot '\r') {
  300.       if(chr > 255) { beep; continue; }
  301.       if(chr isnot ' ') { beep; continue; }
  302.       ++linespc;
  303.       linespc &= 0x01;  /* toggle between 0 and 1 only */
  304.       putlinespc();
  305.       d_pos(11, 34, 0);
  306.       }
  307.    }
  308.  
  309. dokey7() {
  310.    int chr;
  311.    d_pos(13, 37, 0);
  312.    while((chr = getkey()) isnot '\r') {
  313.       if(chr > 255) { beep; continue; }
  314.       if(chr isnot ' ') { beep; continue; }
  315.       ++printer;
  316.       if(printer > 2) printer = 0;  /* trap wrap around */
  317.       putprinter();
  318.       d_pos(13, 37, 0);
  319.       }
  320.    }
  321.  
  322. dofk9() {
  323.    short i, j;
  324.    short codes[32];
  325.    FILE *fd;
  326.    i = 0;
  327.    fputs("  Sending codes...", stdout);
  328.    if(pitch is PICA) codes[i++] = 0x12;
  329.    if(pitch is COND) codes[i++] = 0x0f;
  330.    if(style isnot NONE) {
  331.       codes[i++] = ESC;
  332.       codes[i++] = 0x58;
  333.       switch(style) {
  334.          default:
  335.             --i; --i; break;
  336.          case DRAFT:
  337.             codes[i++] = 0;
  338.             break;
  339.          case LQ:
  340.             codes[i++] = 1;
  341.             break;
  342.          }
  343.       }
  344.    if((style is LQ) and (lqspc isnot NONE)) {
  345.       codes[i++] = ESC;
  346.       codes[i++] = 0x56;
  347.       codes[i++] = (((lqspc >> 4) * 10) + (lqspc & 0x0f));
  348.       }
  349.    if(length isnot NONE) {
  350.       codes[i++] = ESC;
  351.       codes[i++] = 0x43;
  352.       codes[i++] = (((length >> 4) * 10) + (length & 0x0f));
  353.       }
  354.    if(linespc is 0) {
  355.       codes[i++] = ESC;
  356.       codes[i++] = 0x32;
  357.       }
  358.    if(linespc is 1) {
  359.       codes[i++] = ESC;
  360.       codes[i++] = 0x30;
  361.       }
  362.    /* i has count of characters to place */
  363.  
  364.    if(printer is 1) fd = fopen("LPT1", "wb");
  365.    else if(printer is 2) fd = fopen("LPT2", "wb");
  366.    else fd = fopen("PRN", "wb");
  367.  
  368.    if(fd is NULL) error("Cannot open printer channel");
  369.  
  370.    for(j = 0; j < i; ++j) fputc(codes[j], fd);
  371.    cls();
  372.    exit(0);
  373.    }
  374.  
  375.  
  376. get2digs(row, col) int row, col; {
  377.    int i, j;
  378.    int chr;
  379.    i = j = 0;
  380.    d_pos(row, col, 0);
  381.    puts("  ");
  382.    d_pos(row, col, 0);
  383.    while((chr = getkey()) isnot '\r') {
  384.       if(i > 2) { beep; continue; }
  385.       if(chr > 255) { beep; continue; }
  386.       if(chr is '\b') {
  387.          j = i = 0;
  388.          d_pos(row, col, 0);
  389.          puts("  ");
  390.          d_pos(row, col, 0);
  391.          continue;
  392.          }
  393.       if(chr is ESC) {
  394.          d_pos(row, col, 0);
  395.          puts("  ");
  396.          return(NONE);
  397.          }
  398.       if(!isdigit(chr)) { beep; continue; }
  399.       putchar(chr);  /* echo it to screen */
  400.       j = j<<4;
  401.       j |= (chr & 0x0f);
  402.       ++i;
  403.       }
  404.    if(i is 0) return(NONE);
  405.    else return(j);
  406.    }
  407.  
  408.