/* ================================================================== */
/*                                                                    */
/* This part is rewritten by Matthias Pfuetzner in order to get a     */
/* quite simple possibility to redefine the keys.                     */
/*                                                                    */
/* ================================================================== */

/* strek_keydef_subs.f -- translated by f2c (version of 19 December 1990  16:50:21).
   You must link the resulting object file with the libraries:
	-lF77 -lI77 -lm -lc   (in that order)
*/

#include "f2c.h"

/* Common Block Declarations */

struct {
    char means[256];
} key_defs__;

#define key_defs__1 key_defs__

/* Table of constant values */

static integer c__1 = 1;

/* Subroutine */ int strek_parse_key_defs__(key_file__, found, key_file_len)
char *key_file__;
logical *found;
ftnlen key_file_len;
{
    /* Initialized data */

    static char pf[1*32+1] = "abcdefghijklmnopqrstuvwxyz ,./;[";

    /* Format strings */
    static char fmt_100[] = "(6x,a)";

    /* System generated locals */
    olist o__1;
    cllist cl__1;
    inlist ioin__1;

    /* Builtin functions */
    integer f_inqu(), f_open(), s_rsfe(), do_fio(), e_rsfe(), f_clos();

    /* Local variables */
    static char temp[1];
    static integer j;
    static logical fyn;

    /* Fortran I/O blocks */
    static cilist io___4 = { 0, 1, 0, "(a)", 0 };
    static cilist io___6 = { 0, 1, 0, "(a)", 0 };
    static cilist io___7 = { 0, 1, 0, fmt_100, 0 };



/*    STREK_PARSE_KEY_DEFS interprets the user input key */
/*    definitions file in terms of the actual keys and */
/*    KBD.INS.FTN parameters */

/*    version 2 */
/*                                         -jsr 8/85 */
/*    modified 11/20/85 */

/* % include '/sys/ins/base.ins.ftn' */
/* % include '/sys/ins/kbd.ins.ftn' */

/*      character*1 means(256), temp, pf(90) */

/*    common block of key def's */

/*      data pf /'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', */
/*     &         'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', */
/*     &         'u', 'v', 'w', 'x', 'y', 'z', kbdl1, kbdl2, */
/*     &         kbdl3, kbdl4, kbdl5, kbdl6, kbdl7, kbdl8, */
/*     &         kbdl9, kbdla, kbdlb, kbdlc, kbdld, kbdle, */
/*     &         kbdlf, kbdl1a, kbdl2a, kbdl3a, kbdl1u, */
/*     &         kbdl2u, kbdl3u, kbdl4u, kbdl5u, kbdl6u, */
/*     &         kbdl7u, kbdl8u, kbdl9u, kbdlau, kbdlbu, */
/*     &         kbdlcu, kbdldu, kbdleu, kbdlfu, kbdl1au, */
/*     &         kbdl2au, kbdl3au, kbdf1, kbdf2, kbdf3, kbdf4, */
/*     &         kbdf5, kbdf6, kbdf7, kbdf8, kbdf1u, kbdf2u, */
/*     &         kbdf3u, kbdf4u, kbdf5u, kbdf6u, kbdf7u, */
/*     &         kbdf8u, kbdr1, kbdr2, kbdr3, kbdr4, kbdr5, */
/*     &         kbdr6, ' ', ',', '.', '/', ';', '['/ */

/*    read in file */

/*
    ioin__1.inerr = 0;
    ioin__1.infilen = 256;
    ioin__1.infile = key_file__;
    ioin__1.inex = &fyn;
    ioin__1.inopen = 0;
    ioin__1.innum = 0;
    ioin__1.innamed = 0;
    ioin__1.inname = 0;
    ioin__1.inacc = 0;
    ioin__1.inseq = 0;
    ioin__1.indir = 0;
    ioin__1.infmt = 0;
    ioin__1.inform = 0;
    ioin__1.inunf = 0;
    ioin__1.inrecl = 0;
    ioin__1.innrec = 0;
    ioin__1.inblank = 0;
    f_inqu(&ioin__1);
    if (! fyn) {
	*found = FALSE_;
	return 0;
    }
    *found = TRUE_;
    for (j = 1; j <= 256; ++j) {
	key_defs__1.means[j - 1] = j;
*/
/* L10: */
/*
    }
    o__1.oerr = 0;
    o__1.ounit = 1;
    o__1.ofnmlen = 256;
    o__1.ofnm = key_file__;
    o__1.orl = 0;
    o__1.osta = 0;
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);
    s_rsfe(&io___4);
    do_fio(&c__1, temp, 1L);
    e_rsfe();
    s_rsfe(&io___6);
    do_fio(&c__1, temp, 1L);
    e_rsfe();
    for (j = 1; j <= 90; ++j) {
	s_rsfe(&io___7);
	do_fio(&c__1, temp, 1L);
	e_rsfe();
	if (*temp != ' ') {
	    key_defs__1.means[pf[j - 1] - 1] = *temp;
	}
*/
/* L20: */
/*
    }
    cl__1.cerr = 0;
    cl__1.cunit = 1;
    cl__1.csta = 0;
    f_clos(&cl__1);
    return 0;
*/


#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>

   KeySym            keysym;
   KeySym            list[1];   /* Modifier List [shift etc.] ignored */
   int               mod_count = 0;
   unsigned char     string[1];
   int               bytes_string = 1;
   char              key_string[50];
   char              cmd_string[10];
   char              dummy_string[256];
   KeyCode           keycode;
   FILE              *file;
   extern Display    *d;
   char              tmp_file[256];
   int               tmp_char;



   list[1] = NoSymbol;

   sscanf(key_file__,"%s %s",tmp_file,dummy_string);

   if (( file = fopen(tmp_file,"r")) == NULL)
   {
      fprintf(stderr, "File not found: \"%s\"", key_file__);
      *found = FALSE_;
      return 0;
   }

   *found = TRUE_;

   if (d == 0)
      d = XOpenDisplay (0);
   if (d == 0)
   {
      printf("can't open display! bye.\n");
      exit(1);
   }


   while (feof(file) == NULL)
   {
      fscanf(file,"%s",key_string);
      fscanf(file,"%s",cmd_string);

      while (1 == 1)
      {
         tmp_char = fgetc(file);
         if (tmp_char == (int) '\n')
            break;
         if (tmp_char == (int) EOF)
            break;
      }

/*
      dummy_string = fgets(dummy_string, 256, file);
*/

      string[0] = cmd_string[0];

      if (( keysym = XStringToKeysym(key_string)) == NoSymbol)
         fprintf(stderr,
                 "strek_parse_key_defs__: No valid KeySym-string: %s",
                  key_string);
/*
      if (( keycode = XKeysymToKeycode(d, keysym)) == 0)
         fprintf(stderr,
         "strek_parse_key_defs__: Undefined KeySym (No key for this?)");

      bytes_string = strlen(string);
*/
      XRebindKeysym(d, keysym, list, mod_count, string, bytes_string);
   }
   fclose(file);
} /* strek_parse_key_defs__ */





/* Subroutine */ int strek_interpret_key__(t_key__, t_key_len)
char *t_key__;
ftnlen t_key_len;
{

/*    STREK_INTERPRET_KEY interprets an keystroke event datum */
/*    in terms of it's users defined key. */

/*    version 2 */
/*                                  -jsr 8/85 */
/*    modified 11/20/85 */

/*    *t_key__ = key_defs__1.means[*t_key__ - 1]; */
} /* strek_interpret_key__ */

