home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / KEYBOARD / TEMPL.ZIP / TEMPL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-03  |  14.5 KB  |  504 lines

  1.  
  2. /********************************************************************
  3.  
  4.     TEMPLATE GENERATOR for custom keyboard templates.  Helps learning
  5.         curve for common functions.
  6.  
  7. */
  8.  
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <dos.h>
  13. #include <conio.h>
  14. #include <ctype.h>
  15. #include <graphics.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <mem.h>
  19.  
  20. #define TRUE      1
  21. #define FALSE     0
  22. #define NUM_LINES 4
  23. #define NUM_KEYS  12
  24. #define NUM_CHARS 11
  25. #define DC2       0x12
  26. #define SI        0x0f
  27. #define ESC          0x1b
  28.  
  29. void fprnt(char *text, int auto_lf);
  30. char put_out(char character);
  31. void stretch( char *src, char *dst);
  32.  
  33. char vert_spacing[] = {ESC,'A',0x8,0};
  34.  
  35. char title[80];
  36.  
  37. struct {                        /* structure for the top half lines */
  38.     char            s1[2];
  39.     char            esc;
  40.     char            mode;
  41.     int             len;
  42.     unsigned char   v1[90];
  43.     unsigned char   v2[90];
  44.     unsigned char   v3[90];
  45.     unsigned char   v4[90];
  46.     unsigned char   v5[130];
  47.     unsigned char   v6[90];
  48.     unsigned char   v7[90];
  49.     unsigned char   v8[50];
  50. } top = {' ',' ',ESC,'L',720};
  51.  
  52. struct {                        /* stucture for the bottom half lines */
  53.     char            s1[2];
  54.     char            esc;
  55.     char            mode;
  56.     int             len;
  57.     unsigned char   v1[8];
  58.     unsigned char   v2[90];
  59.     unsigned char   v3[90];
  60.     unsigned char   v4[130];
  61.     unsigned char   v5[90];
  62.     unsigned char   v6[90];
  63.     unsigned char   v7[90];
  64.     unsigned char   v8[90];
  65.     unsigned char   v9[40];
  66.     unsigned char   v10[2];
  67. } bottom = {' ',' ',ESC,'L',720};
  68.  
  69. char func[NUM_LINES][NUM_KEYS][NUM_CHARS+2];    /* array to hold function key data */
  70. char *fptr;
  71. char buffer[128];
  72. char t0[200];
  73. char t1[200];
  74. char t2[200];
  75. char t3[200];
  76.  
  77. int f, l, j, flag;
  78. char c_cnt[3] = {0,0,0};
  79. char f_cnt[12] = {0,0,0, 0,0,0, 0,0,0, 0,0,0};
  80.  
  81. char col[3][15][40];
  82. char lines[15][120];
  83.  
  84. int len, col_line;
  85. char fname[40], mode, mode_num, ans;
  86. char buffer[128];
  87. FILE *fs;
  88.  
  89.  
  90. void main()
  91. {
  92.     register     int i;
  93.     int         pr_flag, ok_flag = TRUE, tlen;
  94.  
  95.     fptr = &func[0][0][0];      /* fill function array with spaces */
  96.     for(i = 0; i < sizeof(func); i++) *fptr++ = ' ';
  97.  
  98.     fptr = &col[0][0][0];
  99.     for(i = 0; i < sizeof(col); i++) *fptr++ = ' ';
  100.  
  101.     while(ok_flag) {
  102.         printf("\n\nDo you want the input from the KEYBOARD or a FILE? [K/F] ");
  103.         printf("\nNote: keyboard input onlys allows function key data ");
  104.         ans = tolower(getch());
  105.         if(ans == 'f' || ans == 'k')
  106.             ok_flag = FALSE;
  107.     }
  108.  
  109.     if(ans == 'f') {
  110.  
  111.         printf("\n");
  112.         ok_flag = TRUE;
  113.         while(ok_flag) {
  114.             printf("Enter filename: ");
  115.             gets(fname);
  116.                if((fs = fopen(fname, "r")) != NULL)
  117.                 ok_flag = 0;
  118.         }
  119.  
  120.         mode = 0;
  121.         while((fgets(buffer, 128, fs)) != NULL) {
  122.             if(buffer[0] == ';') continue;
  123.             if(buffer[0] == '*') continue;
  124.             if(buffer[0] == '\n') continue;
  125.  
  126.             if(buffer[0] == '.') {
  127.                 mode = tolower(buffer[1]);
  128.                 if(mode == 'f' || mode == 'c')
  129.                     mode_num = atoi(&buffer[2]) - 1;
  130.                 continue;
  131.             }
  132.             len = strlen(buffer) - 1;             /* eleminate the LF */
  133.             if(!(mode == 0 || mode == 'c' || mode == 'f' || mode == 't')) {
  134.                 printf("\n******* ERROR in input file (mode) *******");
  135.                 continue;
  136.             }
  137.  
  138.             if(mode == 't') {
  139.                 if(len > 50) {
  140.                     printf("\n******* ERROR in input file (title length) *******");
  141.                 }
  142.                 tlen = min(len,50);
  143.                 strncpy(title, buffer, tlen);
  144.                 mode = 0;
  145.                 continue;
  146.             }
  147.             if(mode == 'c') {
  148.                 if(mode_num > 3) {
  149.                     printf("\n******* ERROR in input file (column > 3) *******");
  150.                     continue;
  151.                 }
  152.                 if(c_cnt[0] > 15 || c_cnt[1] > 15 || c_cnt[2] > 15) {
  153.                     printf("\n******* ERROR in input file (column line count > 15) *******");
  154.                     continue;
  155.                 }
  156.                 if(len > 35) {
  157.                     printf("\n******* ERROR in input file (column text length > 35) *******");
  158.                 }
  159.                 if(buffer[0] == '/' && buffer[1] == '/')
  160.                     c_cnt[mode_num]++;
  161.                 else
  162.                     strncpy(&col[mode_num][c_cnt[mode_num]++][0], buffer, min(len, 35));
  163.                 continue;
  164.             }
  165.             if(mode == 'f') {
  166.                 if(mode_num > 11) {
  167.                     printf("\n******* ERROR in input file (function key number > 12) *******");
  168.                     continue;
  169.                 }
  170.                 for(i = 0; i < 12; i++) {
  171.                     if(f_cnt[i] > 4 ) {
  172.                         printf("\n******* ERROR in input file (line count for key %d > 4) *******",i);
  173.                         continue;
  174.                     }
  175.                 }
  176.                 if(len > 11) {
  177.                     printf("\n******* ERROR in input file (function key text length) *******");
  178.                 }
  179.                 if(buffer[0] == '/' && buffer[1] == '/')
  180.                     f_cnt[mode_num]++;
  181.                 else
  182.                     strncpy(&func[f_cnt[mode_num]++][mode_num][0], buffer, min(len, 11));
  183.                 continue;
  184.             }
  185.  
  186.         }
  187.         col_line = max(c_cnt[0], max(c_cnt[1], c_cnt[2]));
  188.  
  189.     } else {
  190.         ok_flag = TRUE;
  191.         printf("\n");               /* request the optional title */
  192.         while(ok_flag) {
  193.             printf("\nEnter title (50 chars max): ");
  194.             gets(title);
  195.             tlen = strlen(title);
  196.             if(tlen <= 50) ok_flag = 0;
  197.             else printf("%c%c", 0x07, 0x07);
  198.         }
  199.  
  200.         for(f = 0; f < NUM_KEYS;) {     /* get the data for all 12 function keys */
  201.             printf("\n\n");
  202.             for(l = 0; l < NUM_LINES;) {
  203.                 for(i = 0; i < NUM_CHARS; i++)
  204.                     func[l][f][i] = ' ';
  205.                 flag = TRUE;
  206.                 printf("\Enter F%d line %d ( 11 chars max): ", f+1, l+1);
  207.                 gets(buffer);
  208.                 if(buffer[0] == '\0') break;
  209.                 if(strlen(buffer) > NUM_CHARS) {
  210.                     printf("..... Too many characters .....\n");
  211.                     flag = FALSE;
  212.                     break;
  213.                 }
  214.                 strncpy(&func[l][f][0], buffer, strlen(buffer));
  215.                 l++;
  216.             }
  217.             if(flag) {
  218.                 printf("\nIs this correct? ");
  219.                 if(tolower(getche()) == 'y') f++;
  220.             }
  221.         }
  222.     }
  223.     
  224.     printf("\n\nPrepare printer, hit any key ");
  225.     getch();
  226.  
  227.     for(i = 0; i < 29; i++) putch(0x08);
  228.     printf(".......... Printing ..........");
  229.  
  230.     for(i = 0; i < 2; i++) put_out('\n');   /* skip some top of form      */
  231.  
  232.  
  233.     for(i = 0; i < 15; i++)
  234.         for(j = 0; j < 3; j++)
  235.             movmem(&col[j][i][0], &lines[i][40*j], 40);
  236.  
  237.     put_out(ESC); put_out('E');        /* emphasized */
  238.     put_out(ESC); put_out('M');        /* pica       */
  239.     put_out(ESC); put_out('2');     /* 6 LPI      */
  240.  
  241.     for(i = 0; i < col_line; i++) {
  242.         for(j = 0; j < 11; j++) put_out(' ');
  243.         for(j = 0; j < 63; j++) put_out(lines[i][j]);
  244.         put_out('\r'); put_out('\n');
  245.     }
  246.  
  247.     put_out(ESC); put_out('P');            /* go to 10 CPI */
  248.     put_out(DC2);                            /* reset if in condensed print */
  249.  
  250.     for(i = 0; i < 1; i++) put_out('\n');   /* skip some space      */
  251.     put_out('\r');
  252.  
  253.     stretch(&func[0][0][0], t0);            /* fill in the extra spaces   */
  254.     stretch(&func[1][0][0], t1);            /*  for the gaps at F4 and F8 */
  255.     stretch(&func[2][0][0], t2);
  256.     stretch(&func[3][0][0], t3);
  257.  
  258.  
  259.     put_out(ESC); put_out('E');            /* emphasized characters      */
  260.  
  261.     fputs(vert_spacing, stdprn);            /* set line spacing           */
  262.  
  263.     for(i = 0; i < 720; i++) top.v1[i] = 0xc0;
  264.     top.v1[0] = top.v1[1] = 0xff;
  265.     fprnt(&top.s1[0], 1);                           /* print upper line   */
  266.  
  267.     for(i = 2; i < 720; i++) top.v1[i] = 0;
  268.     fprnt(&top.s1[0], 1);                           /* print blank line   */
  269.  
  270.     top.v2[0] = top.v2[1] = top.v3[0] = top.v3[1] =
  271.     top.v4[0] = top.v4[1] = top.v5[0] = top.v5[1] =
  272.     top.v6[0] = top.v6[1] = top.v7[0] = top.v7[1] =
  273.     top.v8[0] = top.v8[1] = 0xff;
  274.  
  275.     fprnt(&top.s1[0], 0);                           /* vertical serriations  */
  276.  
  277.     put_out(SI);                                    /* print full top line */
  278.     for(i = 0; i < 17; i++) put_out(' ');           /* function key text   */
  279.     for(i = 0; i < 89; i++) put_out(t0[i]);
  280.     put_out(DC2);
  281.     put_out('\r');
  282.     put_out('\n');
  283.  
  284.     fprnt(&top.s1[0], 0);                           /* vertical serriations  */
  285.  
  286.     put_out(SI);
  287.     for(i = 0; i < 17; i++) put_out(' ');
  288.     for(i = 0; i < 89; i++) put_out(t1[i]);
  289.     put_out(DC2);
  290.     put_out('\r');
  291.     put_out('\n');
  292.  
  293.     fprnt(&top.s1[0], 0);                           /* vertical serriations  */
  294.  
  295.     put_out(SI);
  296.     for(i = 0; i < 17; i++) put_out(' ');
  297.     for(i = 0; i < 89; i++) put_out(t2[i]);
  298.     put_out(DC2);
  299.     put_out('\r');
  300.     put_out('\n');
  301.  
  302.     fprnt(&top.s1[0], 0);                           /* vertical serriations  */
  303.  
  304.     put_out(SI);
  305.     for(i = 0; i < 17; i++) put_out(' ');
  306.     for(i = 0; i < 89; i++) put_out(t3[i]);
  307.     put_out(DC2);
  308.     put_out('\r');
  309.     put_out('\n');
  310.  
  311.     for(i = 92; i < 720; i++) top.v1[i] = 0xc0;
  312.     fprnt(&top.s1[0], 1);                           /* top horizontal inside line  */
  313.  
  314.  
  315.     for(i = 92; i < 720; i++) top.v1[i] = 0;
  316.  
  317.     for(i = 0; i < 5; i++) fprnt(&top.s1[0], 1);    /* left side  --- 5 times */
  318.  
  319.     for(i = 92; i < 720; i++) top.v1[i] = 3;
  320.     fprnt(&top.s1[0], 1);                           /* bottom horizontal inside line  */
  321.  
  322.     for(i = 2; i < 720; i++) top.v1[i] = 0;
  323.     for(i = 0; i < 2; i++) fprnt(&top.s1[0], 1);    /* left edge and blank line 6 times */
  324.     fprnt(&top.s1[0], 0);
  325.  
  326.     if(tlen > 0) {
  327.         put_out(0x0e);
  328.         for(i = 0; i < 28 - (tlen/2); i++) put_out(' ');
  329.         for(i = 0; i < (tlen/2) + 3; i++) {
  330.             if(title[i] == '\0') break;
  331.             put_out(title[i]);
  332.         }
  333.     }
  334.     put_out('\r');
  335.     put_out('\n');
  336.  
  337.  
  338.     for(i = 0; i < 3; i++) fprnt(&top.s1[0], 1);    /* left edge and blank line 6 times */
  339.  
  340.     for(i = 0; i < 720; i++) top.v1[i] = 0xc0;
  341.     fprnt(&top.s1[0], 1);                           /* bottom line  */
  342.  
  343.  
  344.     /* print the bottom half   */
  345.  
  346.     for(i = 0; i < 4; i++) put_out('\n');          /* skip some form */
  347.     put_out('\r');
  348.  
  349.     put_out(ESC); put_out('M');        /* elite pitch */
  350.     put_out(ESC); put_out('2');        /* 6 LPI */
  351.     for(i = 0; i < col_line; i++) {
  352.         for(j = 0; j < 3; j++) put_out(' ');
  353.         for(j = 49; j < 120; j++) put_out(lines[i][j]);
  354.         put_out('\r'); put_out('\n');
  355.     }
  356.  
  357.     put_out(ESC); put_out('P');            /* go to 10 CPI */
  358.     for(i = 0; i < 1; i++) put_out('\n');   /* skip some space      */
  359.     put_out('\r');
  360.  
  361.     fputs(vert_spacing, stdprn);
  362.  
  363.     for(i = 0; i < 718; i++) bottom.v1[i] = 0xc0;
  364.     bottom.v10[0] = bottom.v10[1] = 0xff;
  365.     fprnt(&bottom.s1[0], 1);                        /* top line  */
  366.  
  367.     for(i = 0; i < 718; i++) bottom.v1[i] = 0;
  368.     fprnt(&bottom.s1[0], 1);                        /* blank line  */
  369.  
  370.     bottom.v2[0] = bottom.v2[1] = bottom.v3[0] = bottom.v3[1] =
  371.     bottom.v4[0] = bottom.v4[1] = bottom.v5[0] = bottom.v5[1] =
  372.     bottom.v6[0] = bottom.v6[1] = bottom.v7[0] = bottom.v7[1] =
  373.     bottom.v8[0] = bottom.v8[1] = 0xff;
  374.  
  375.     fprnt(&bottom.s1[0], 0);                        /* vertical serriations */
  376.  
  377.     put_out(SI);
  378.     for(i = 0; i < 5; i++) put_out(' ');
  379.     for(i = 70; i < 186; i++) put_out(t0[i]);
  380.     put_out(DC2);
  381.     put_out('\r');
  382.     put_out('\n');
  383.  
  384.     fprnt(&bottom.s1[0], 0);                        /* vertical serriations */
  385.  
  386.     put_out(SI);
  387.     for(i = 0; i < 5; i++) put_out(' ');
  388.     for(i = 70; i < 186; i++) put_out(t1[i]);
  389.     put_out(DC2);
  390.     put_out('\r');
  391.     put_out('\n');
  392.  
  393.     fprnt(&bottom.s1[0], 0);                        /* vertical serriations */
  394.  
  395.     put_out(SI);
  396.     for(i = 0; i < 5; i++) put_out(' ');
  397.     for(i = 70; i < 186; i++) put_out(t2[i]);
  398.     put_out(DC2);
  399.     put_out('\r');
  400.     put_out('\n');
  401.  
  402.     fprnt(&bottom.s1[0], 0);                        /* vertical serriations */
  403.  
  404.     put_out(SI);
  405.     for(i = 0; i < 5; i++) put_out(' ');
  406.     for(i = 70; i < 186; i++) put_out(t3[i]);
  407.     put_out(DC2);
  408.     put_out('\r');
  409.     put_out('\n');
  410.  
  411.     for(i = 0; i < 678; i++) bottom.v1[i] = 0xc0;
  412.     bottom.v9[0] = bottom.v9[1] = 0xff;
  413.     fprnt(&bottom.s1[0], 1);                        /* top inside line  */
  414.  
  415.  
  416.     for(i = 0; i < 678; i++) bottom.v1[i] = 0;
  417.     for(i = 0; i < 5; i++) fprnt(&bottom.s1[0], 1); /* right side  */
  418.  
  419.     for(i = 0; i < 678; i++) bottom.v1[i] = 3;
  420.     fprnt(&bottom.s1[0], 1);                        /* bottom inside line  */
  421.  
  422.     for(i = 0; i < 718; i++) bottom.v1[i] = 0;
  423.     for(i = 0; i < 2; i++) fprnt(&bottom.s1[0], 1); /* right side  */
  424.     fprnt(&bottom.s1[0], 0);
  425.  
  426.  
  427.     if(tlen > 0) {
  428.         put_out(0x0e);
  429.         put_out(' ');
  430.         for( i = (tlen/2) -3; title[i] != '\0'; i++)
  431.             put_out(title[i]);
  432.     }
  433.     put_out('\r');
  434.     put_out('\n');
  435.  
  436.  
  437.     for(i = 0; i < 3; i++) fprnt(&bottom.s1[0], 1); /* right side  */
  438.  
  439.     for(i = 0; i < 720; i++) bottom.v1[i] = 0xc0;
  440.     fprnt(&bottom.s1[0], 1);                        /* bottom line  */
  441.  
  442.     printf("\n\n");
  443.  
  444.     put_out(0xc);
  445.     fflush(stdprn);
  446.  
  447. }
  448.  
  449. /* not used - but someday ??? */
  450.  
  451. char status(void)
  452. {
  453.     union REGS regs;
  454.  
  455.     regs.h.ah = 2;
  456.     regs.x.dx = 0;
  457.     int86(0x17, ®s, ®s);
  458.     return(regs.h.ah & 0x80);
  459. }
  460.  
  461. /* out put to the printer */
  462.  
  463. char put_out(char character)
  464. {
  465.     union REGS regs;
  466.  
  467.     regs.h.ah = 0;
  468.     regs.h.al = character;
  469.     regs.x.dx = 0;
  470.     int86(0x17, ®s, ®s);
  471.     return(regs.h.ah);
  472. }
  473.  
  474. void fprnt(char *text, int auto_lf) /* print a line with optional CR */
  475. {
  476.     int i;
  477.  
  478.     for( i = 0; i < 726; i++)
  479.         put_out(*text++);
  480.     if(auto_lf) {
  481.         put_out('\r');
  482.         put_out('\n');
  483.     } else put_out('\r');
  484. }
  485.  
  486. /* take data from thefunction key array and put it in the Tx array */
  487. void stretch( char *src, char *dst)
  488. {
  489.     register int i;
  490.  
  491.     for(i = 0; i < 4*13; i++)
  492.         *dst++ = *src++;
  493.     for(i = 0; i < 6; i++)      /* 6 extra spaces for F4 */
  494.         *dst++ = ' ';
  495.  
  496.     for(i = 0; i < 4*13; i++)
  497.         *dst++ = *src++;
  498.     for(i = 0; i < 5; i++)      /* 5 extra spaces for F8 */
  499.         *dst++ = ' ';           /* I think my printer is non-linear or ??? */
  500.     for(i = 0; i < 4*13; i++)
  501.         *dst++ = *src++;
  502. }
  503.  
  504.