Subversion Repositories SvarDOS

Rev

Rev 1908 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
68 mv_fox 1
/*
190 mateuszvis 2
 * This program creates a header file for the SvarDOS installer, that
68 mv_fox 3
 * contains the list of all supported keyboard layouts, along with a way to
4
 * select sets of keyboard layouts that apply to only a specific region.
5
 *
1624 mateusz.vi 6
 * Copyright (C) 2016-2024 Mateusz Viste
68 mv_fox 7
 */
8
 
9
/* the kblayouts list is a NULL-terminated array that contains entries in the
10
 * following format:
96 mv_fox 11
 * human description string <0> layout code string <0> <codepage number as a 16bit value> <ega.sys file number as a single byte> <keyboard.sys file number as a single byte> <sub keyb ID as a 16bit value, zero if none>
68 mv_fox 12
 
13
    char *kblayouts[] = {
14
    "English (US)\0xxxx",
15
    "Polish\0pl\0xxxx"};
16
  };
17
 */
18
 
19
 
20
#include <stdio.h>
21
#include <string.h>
22
 
23
 
1921 mateusz.vi 24
static unsigned char EGAFILES_USED[20];
25
 
68 mv_fox 26
/* global file pointers */
27
FILE *fdkeyb, *fdoff;
28
 
29
 
30
/* Converts a positive base_10 into base_8 */
31
static unsigned int dec2oct(int n) {
32
  int res=0, digitPos=1;
33
  while (n) {
34
    res += (n & 7) * digitPos;
35
    n >>= 3;
36
    digitPos *= 10;
37
  }
38
  return(res);
39
}
40
 
41
 
1908 mateusz.vi 42
static void addnew(char *countrycode, unsigned short countryid, char *humanlang, char *keybcode, unsigned short cp, unsigned char egafile, unsigned char keybfile, unsigned int subid) {
68 mv_fox 43
  static char lastcountry[4] = {0};
44
  static int curoffset = 0, curcountryoffset = 0;
1921 mateusz.vi 45
  int i;
46
 
47
  /* remember the EGA file */
48
  for (i = 0; (EGAFILES_USED[i] != egafile) && (EGAFILES_USED[i] != 0xff); i++);
49
  EGAFILES_USED[i] = egafile;
50
 
68 mv_fox 51
  /* if new country, declare an offset */
52
  if (strcmp(countrycode, lastcountry) != 0) {
53
    /* close previous one, if any */
54
    if (lastcountry[0] != 0) {
55
      fprintf(fdoff, "#define OFFLEN_%s %d\r\n", lastcountry, curoffset - curcountryoffset);
56
    } else {
624 mateuszvis 57
      fprintf(fdkeyb, "const char *kblayouts[] = {\r\n");
68 mv_fox 58
    }
59
    /* open new one, if any */
60
    if (countrycode[0] != 0) {
61
      fprintf(fdkeyb, "  /****** %s ******/\r\n", countrycode);
62
      curcountryoffset = curoffset;
63
      fprintf(fdoff, "#define OFFLOC_%s %d\r\n", countrycode, curoffset);
64
      strcpy(lastcountry, countrycode);
65
    } else {
66
      fprintf(fdoff, "#define OFFCOUNT %d\r\n", curoffset);
67
    }
68
  }
69
  /* */
70
  if (countrycode[0] != 0) {
1908 mateusz.vi 71
    fprintf(fdkeyb, "  \"%s\\0%s\\0\\%d\\%d\\%d\\%d\\%d\\%d\\%d\\%d\",\r\n", humanlang, keybcode, dec2oct(cp >> 8), dec2oct(cp & 0xff), dec2oct(egafile), dec2oct(keybfile), dec2oct(subid >> 8), dec2oct(subid & 0xff), dec2oct(countryid >> 8), dec2oct(countryid & 0xff));
68 mv_fox 72
  } else {
73
    fprintf(fdkeyb, "  NULL};\r\n");
74
  }
75
  curoffset++;
76
}
77
 
78
 
79
int main(void) {
80
 
1921 mateusz.vi 81
  /* reset EGAFILES_USED, it will be used to remember which EGA*.CPX files are
82
   * required by the SvarDOS installer */
83
  memset(EGAFILES_USED, 0xff, sizeof(EGAFILES_USED));
84
 
68 mv_fox 85
  /*** open files ***/
86
  fdkeyb = fopen("keylay.h", "wb");
87
  fdoff = fopen("keyoff.h", "wb");
116 mv_fox 88
  fprintf(fdkeyb, "/* DO NOT EDIT THIS FILE, IT IS AUTO-GENERATED BY LOCALES.EXE */\r\n");
89
  fprintf(fdoff, "/* DO NOT EDIT THIS FILE, IT IS AUTO-GENERATED BY LOCALES.EXE */\r\n");
68 mv_fox 90
 
91
  /******************* LAYOUTS LIST START *******************/
92
 
1908 mateusz.vi 93
  /* addnew(countrycode, countryid, humanlang, keybcode, cp, egafile, keybfile, subid) */
118 mv_fox 94
 
68 mv_fox 95
  /* English */
1908 mateusz.vi 96
  addnew("EN",  1, "English (US)", "en", 437, 0, 0, 0);
97
  addnew("EN", 44, "English (UK)", "uk", 437, 0, 1, 0);
68 mv_fox 98
 
118 mv_fox 99
  /* Armenian */
1908 mateusz.vi 100
  addnew("HY", 374, "Armenian", "hy", 899, 6, 3, 0);
118 mv_fox 101
 
1177 mateusz.vi 102
  /* Brazilian */
1908 mateusz.vi 103
  addnew("BR", 55, "Brazilian", "br", 850, 1, 1, 0);
104
  addnew("BR", 55, "Brazilian (US layout)", "br274", 850, 1, 1, 0);
1177 mateusz.vi 105
 
118 mv_fox 106
  /* Bulgarian */
1908 mateusz.vi 107
  addnew("BG", 359, "Bulgarian", "bg", 872, 3, 2, 0);
118 mv_fox 108
 
68 mv_fox 109
  /* French */
1908 mateusz.vi 110
  addnew("FR", 33, "French (France)", "fr", 858, 1, 1, 0);
111
  addnew("FR", 1, "French (Canada, standard)", "cf", 863, 9, 1, 0);
112
  addnew("FR", 1, "French (Canada, legacy)", "cf", 863, 9, 1, 501);
113
  addnew("FR", 41, "French (Switzerland)", "sf", 858, 1, 1, 0);
68 mv_fox 114
 
115
  /* German */
1908 mateusz.vi 116
  addnew("DE", 49, "German", "de", 858, 1, 1, 0);
68 mv_fox 117
 
92 mv_fox 118
  /* Hungarian */
1908 mateusz.vi 119
  addnew("HU", 36, "Hungarian", "hu", 852, 1, 1, 208);
92 mv_fox 120
 
118 mv_fox 121
  /* Italian */
1908 mateusz.vi 122
  addnew("IT", 39, "Italian", "it", 858, 1, 1, 0);
118 mv_fox 123
 
1624 mateusz.vi 124
  /* Latin-American */
1908 mateusz.vi 125
  addnew("LA", 54, "Latin-American", "la", 437, 0, 1, 0);
1624 mateusz.vi 126
 
118 mv_fox 127
  /* Norvegian */
1908 mateusz.vi 128
  addnew("NO", 47, "Norvegian", "no", 858, 9, 1, 0);
118 mv_fox 129
 
68 mv_fox 130
  /* Polish */
1908 mateusz.vi 131
  addnew("PL", 48, "Polish (Programmer)", "pl", 991, 10, 1, 0);
132
  addnew("PL", 48, "Polish (Typewriter)", "pl", 991, 10, 1, 214);
68 mv_fox 133
 
116 mv_fox 134
  /* Russian */
1908 mateusz.vi 135
  addnew("RU", 7, "Russian (Standard)", "ru", 866, 3, 2, 0);
136
  addnew("RU", 7, "Russian (Typewriter)", "ru", 866, 3, 2, 443);
116 mv_fox 137
 
118 mv_fox 138
  /* Slovenian */
1908 mateusz.vi 139
  addnew("SI", 386, "Slovenian", "si", 852, 1, 1, 0);
118 mv_fox 140
 
68 mv_fox 141
  /* Spanish */
1908 mateusz.vi 142
  addnew("ES", 34, "Spanish", "es", 858, 1, 1, 0);
68 mv_fox 143
 
118 mv_fox 144
  /* Swedish */
1908 mateusz.vi 145
  addnew("SV", 46, "Swedish", "sv", 858, 1, 1, 0);
118 mv_fox 146
 
68 mv_fox 147
  /* Turkish */
1908 mateusz.vi 148
  addnew("TR", 90, "Turkish", "tr", 857, 1, 2, 0);
68 mv_fox 149
 
150
  /******************* LAYOUTS LIST STOP *******************/
151
 
152
  /* end of list - DO NOT REMOVE */
1908 mateusz.vi 153
  addnew("", 0, "", "", 0, 0, 0, 0);
68 mv_fox 154
 
155
  /* close files */
156
  fclose(fdoff);
157
  fclose(fdkeyb);
158
 
1921 mateusz.vi 159
  /* report what ega files are needed */
160
  {
161
    int i, ii;
162
    puts("Required EGA files:");
163
    for (ii = 0; ii < 20; ii++) {
164
      for (i = 0; EGAFILES_USED[i] != 0xff; i++) {
165
        if (EGAFILES_USED[i] != ii) continue;
166
        if (EGAFILES_USED[i] == 0) {
167
          printf("EGA.CPX\r\n");
168
        } else {
169
          printf("EGA%u.CPX\r\n", EGAFILES_USED[i]);
170
        }
171
        break;
172
      }
173
    }
174
  }
175
 
68 mv_fox 176
  return(0);
177
}