summaryrefslogtreecommitdiff
path: root/setedit/tools/conv.cc
blob: 35c330921ac06c2c0a1aee3736c1f42883c4da1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Copyright (C) 1996,1997,1998,1999,2000 by Salvador E. Tropea (SET),
   see copyrigh file for details */
/*
  Este programa lo use para convertir los viejos archivos .h de teclado al
  nuevo formato (.lay)
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#define GetLine() fgets(buf,199,f)

char buf[200];
char Name[11];

typedef char ScanNamesType[128][11];
ScanNamesType ScanNames;

int main(int argc, char *argv[])
{
 char *s;
 int i,pos,unk,k;

 if (argc==1)
   {
    printf("Uso: %s archivos ...\n",argv[0]);
    return 1;
   }
 FILE *f;
 for (k=1; k<argc; k++)
    {
     printf("Procesando: %s\n",argv[k]);
     f=fopen(argv[k],"rt");
     if (!f)
        return 1;
     for (i=0; i<128; i++)
         ScanNames[i][0]=0;
     GetLine();
     while (!feof(f))
       {
        if (strncmp(buf,"#define",7)==0)
          {
           for (s=buf+7; *s && ucisspace(*s); s++);
           if (*s)
             {
              for (i=0;i<10 && *s && ucisalnum(*s); s++) Name[i++]=*s;
              Name[i]=0;
              if (Name[0]=='U' && Name[1]=='N' && Name[2]=='K')
                 *Name=0;
              if (ucisalnum(*s))
                {
                 printf("Mide m s de 10!:\n%s",buf);
                 return 1;
                }
              for (; *s && ucisspace(*s); s++);
              if (*s=='?')
                 pos=127;
              else
                 pos=atoi(s);
              if (pos>127)
                {
                 printf("Cuidado scan %d\n%s",pos,buf);
                 pos&=127;
                }
              strcpy(ScanNames[pos],Name);
             }
          }
        GetLine();
       }
     for (unk=1,i=0; i<128; i++)
         if (ScanNames[i][0]==0)
            sprintf(ScanNames[i],"UNK%d",unk++);
     fclose(f);
     f=fopen(argv[k],"wt");
     for (i=0; i<128; i++)
         fprintf(f,"%s %d\n",ScanNames[i],i);
     fclose(f);
    }
 return 0;
}