home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / tn3270 / tools / mkastosc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-26  |  4.9 KB  |  167 lines

  1. /*-
  2.  * Copyright (c) 1988 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. char copyright[] =
  36. "@(#) Copyright (c) 1988 The Regents of the University of California.\n\
  37.  All rights reserved.\n";
  38. #endif /* not lint */
  39.  
  40. #ifndef lint
  41. static char sccsid[] = "@(#)mkastosc.c    4.2 (Berkeley) 4/26/91";
  42. #endif /* not lint */
  43.  
  44. #include <stdio.h>
  45. #if    defined(unix)
  46. #include <strings.h>
  47. #else    /* defined(unix) */
  48. #include <string.h>
  49. #endif    /* defined(unix) */
  50. #include <ctype.h>
  51.  
  52. #include "../general/general.h"
  53. #include "../ctlr/function.h"
  54.  
  55. #include "dohits.h"
  56.  
  57. static struct tbl {
  58.     unsigned char
  59.     scancode,
  60.     used;
  61.     char
  62.     *shiftstate;
  63. } tbl[128];
  64.  
  65. int
  66. main(argc, argv)
  67. int    argc;
  68. char    *argv[];
  69. {
  70.     int scancode;
  71.     int asciicode;
  72.     int empty;
  73.     int i;
  74.     int c;
  75.     int found;
  76.     struct hits *ph;
  77.     struct Hits *Ph;
  78.     struct thing *this;
  79.     struct thing **attable;
  80.     struct tbl *Pt;
  81.     static char *shiftof[] =
  82.         { "0", "SHIFT_UPSHIFT", "SHIFT_ALT", "SHIFT_ALT|SHIFT_UPSHIFT" };
  83.     char *aidfile = 0, *fcnfile = 0;
  84.  
  85.     if (argc > 1) {
  86.     if (argv[1][0] != '-') {
  87.         aidfile = argv[1];
  88.     }
  89.     }
  90.     if (argc > 2) {
  91.     if (argv[2][0] != '-') {
  92.         fcnfile = argv[2];
  93.     }
  94.     }
  95.  
  96.     dohits(aidfile, fcnfile);        /* Set up "Hits" */
  97.  
  98.     printf("/*\n");
  99.     printf(" * Ascii to scancode conversion table.  First\n");
  100.     printf(" * 128 bytes (0-127) correspond with actual Ascii\n");
  101.     printf(" * characters; the rest are functions from ctrl/function.h\n");
  102.     printf(" */\n");
  103.     /* Build the ascii part of the table. */
  104.     for (Ph = Hits, scancode = 0; Ph <= Hits+highestof(Hits);
  105.                             Ph++, scancode++) {
  106.     ph = &Ph->hits;
  107.     for (i = 0; i < 4; i++) {
  108.         if (ph->hit[i].ctlrfcn == FCN_CHARACTER) {
  109.         c = Ph->name[i][0];    /* "name" of this one */
  110.         if (tbl[c].used == 0) {
  111.             tbl[c].used = 1;
  112.             tbl[c].shiftstate = shiftof[i];
  113.             tbl[c].scancode = scancode;
  114.         }
  115.         }
  116.     }
  117.     }
  118.     /* Now, output the table */
  119.     for (Pt = tbl, asciicode = 0; Pt <= tbl+highestof(tbl); Pt++, asciicode++) {
  120.     if (Pt->used == 0) {
  121.         if (isprint(asciicode) && (asciicode != ' ')) {
  122.         fprintf(stderr, "Unable to produce scancode sequence for");
  123.         fprintf(stderr, " ASCII character [%c]!\n", asciicode);
  124.         }
  125.         printf("\t{ 0, 0, undefined, 0 },\t");
  126.     } else {
  127.         printf("\t{ 0x%02x, %s, FCN_CHARACTER, 0 },",
  128.                     Pt->scancode, Pt->shiftstate);
  129.     }
  130.     printf("\t/* 0x%x", asciicode);
  131.     if (isprint(asciicode)) {
  132.         printf(" [%c]", asciicode);
  133.     }
  134.     printf(" */\n");
  135.     }
  136.         
  137.  
  138.     for (attable = &table[0]; attable <= &table[highestof(table)]; attable++) {
  139.     for (this = *attable; this; this = this->next) {
  140.         Ph = this->hits;
  141.         if (Ph == 0) {
  142.         continue;
  143.         }
  144.         for (i = 0; i < 4; i++) {
  145.         if ((Ph->name[i] != 0) &&
  146.             (Ph->name[i][0] == this->name[0]) &&
  147.             (strcmp(Ph->name[i], this->name) == 0)) {
  148.             printf("\t{ 0x%02x, %s, ",
  149.                 Ph-Hits, shiftof[i]);
  150.             if (memcmp("AID_", this->name, 4) == 0) {    /* AID key */
  151.             printf("FCN_AID, ");
  152.             } else {
  153.             printf("%s, ", Ph->name[i]);
  154.             }
  155.             if (memcmp("PF", this->name+4, 2) == 0) {
  156.             printf("\"PFK%s\" },\n", Ph->name[i]+4+2);
  157.             } else {
  158.             printf("\"%s\" },\n", Ph->name[i]+4);
  159.             }
  160.         }
  161.         }
  162.     }
  163.     }
  164.  
  165.     return 0;
  166. }
  167.