home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / tn3270 / tools / mkhits.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-26  |  4.3 KB  |  148 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[] = "@(#)mkhits.c    4.2 (Berkeley) 4/26/91";
  42. #endif /* not lint */
  43.  
  44. /*
  45.  * This program scans a file which describes a keyboard.  The output
  46.  * of the program is a series of 'C' declarations which describe a
  47.  * mapping between (scancode, shiftstate, altstate) and 3270 functions,
  48.  * characters, and AIDs.
  49.  *
  50.  * The format of the input file is as follows:
  51.  *
  52.  * keynumber [ scancode [ unshifted [ shifted [ alted [ shiftalted ] ] ] ] ]
  53.  *
  54.  * keynumber is in decimal, and starts in column 1.
  55.  * scancode is hexadecimal.
  56.  * unshifted, etc. - these are either a single ascii character,
  57.  *            or the name of a function or an AID-generating key.
  58.  *
  59.  * all fields are separated by a single space.
  60.  */
  61.  
  62. #include <stdio.h>
  63. #if    defined(unix)
  64. #include <strings.h>
  65. #else    /* defined(unix) */
  66. #include <string.h>
  67. #endif    /* defined(unix) */
  68. #include <ctype.h>
  69. #include "../ctlr/function.h"
  70.  
  71. #include "dohits.h"
  72.  
  73.  
  74. int
  75. main(argc, argv)
  76. int    argc;
  77. char    *argv[];
  78. {
  79.     int scancode;
  80.     int empty;
  81.     int i;
  82.     struct hits *ph;
  83.     struct Hits *Ph;
  84.     char *aidfile = 0, *fcnfile = 0;
  85.  
  86.     if (argc > 1) {
  87.     if (argv[1][0] != '-') {
  88.         aidfile = argv[1];
  89.     }
  90.     }
  91.     if (argc > 2) {
  92.     if (argv[2][0] != '-') {
  93.         fcnfile = argv[2];
  94.     }
  95.     }
  96.  
  97.     dohits(aidfile, fcnfile);        /* Set up "Hits" */
  98.  
  99.     printf("struct hits hits[] = {\n");
  100.     empty = 0;
  101.     scancode = -1;
  102.     for (Ph = Hits; Ph < Hits+(sizeof Hits/sizeof Hits[0]); Ph++) {
  103.     ph = &Ph->hits;
  104.     scancode++;
  105.     if ((ph->hit[0].ctlrfcn == undefined)
  106.         && (ph->hit[1].ctlrfcn == undefined)
  107.         && (ph->hit[2].ctlrfcn == undefined)
  108.         && (ph->hit[3].ctlrfcn == undefined)) {
  109.         empty++;
  110.         continue;
  111.     } else {
  112.         while (empty) {
  113.         printf("\t{ 0, {  {undefined}, {undefined}");
  114.         printf(", {undefined}, {undefined}  } },\n");
  115.         empty--;
  116.         }
  117.     }
  118.     printf("\t{ %d, {\t/* 0x%02x */\n\t", ph->keynumber, scancode);
  119.     for (i = 0; i < 4; i++) {
  120.         printf("\t{ ");
  121.         switch (ph->hit[i].ctlrfcn) {
  122.         case undefined:
  123.         printf("undefined");
  124.         break;
  125.         case FCN_CHARACTER:
  126.         printf("FCN_CHARACTER, 0x%02x", ph->hit[i].code);
  127.         break;
  128.         case FCN_AID:
  129.         printf("FCN_AID, %s", Ph->name[i]);
  130.         break;
  131.         case FCN_NULL:
  132.         default:
  133.         if ((Ph->name[i] != 0)
  134.                     && (strcmp(Ph->name[i], "FCN_NULL") != 0)) {
  135.             printf("%s", Ph->name[i]);
  136.         } else {
  137.             printf("undefined");
  138.         }
  139.         break;
  140.         }
  141.         printf(" },\n\t");
  142.     }
  143.     printf("} },\n");
  144.     }
  145.     printf("};\n");
  146.     return 0;
  147. }
  148.