Subversion Repositories SvarDOS

Rev

Rev 67 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 67 Rev 68
Line 1... Line 1...
1
/*
1
/*
2
 * This program creates a header file for the Svarog386 installer, that
2
 * This program creates a header file for the Svarog386 installer, that
3
 * contains the list of all supported keyboard layouts, along with a way to
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.
4
 * select sets of keyboard layouts that apply to only a specific region.
5
 *
5
 *
6
 * Copyright (C) 2016 Mateusz Viste
6
 * Copyright (C) 2016 Mateusz Viste
7
 */
7
 */
8
 
8
 
9
/* the kblayouts list is a NULL-terminated array that contains entries in the
9
/* the kblayouts list is a NULL-terminated array that contains entries in the
10
 * following format:
10
 * following format:
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>
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>
12
 
12

13
    char *kblayouts[] = {
13
    char *kblayouts[] = {
14
    "English (US)\0xxxx",
14
    "English (US)\0xxxx",
15
    "Polish\0pl\0xxxx"};
15
    "Polish\0pl\0xxxx"};
16
  };
16
  };
17
 */
17
 */
18
 
18
 
19
 
19
 
20
#include <stdio.h>
20
#include <stdio.h>
21
#include <string.h>
21
#include <string.h>
22
 
22
 
23
 
23
 
24
/* global file pointers */
24
/* global file pointers */
25
FILE *fdkeyb, *fdoff;
25
FILE *fdkeyb, *fdoff;
26
 
26
 
27
 
27
 
28
/* Converts a positive base_10 into base_8 */
28
/* Converts a positive base_10 into base_8 */
29
static unsigned int dec2oct(int n) {
29
static unsigned int dec2oct(int n) {
30
  int res=0, digitPos=1;
30
  int res=0, digitPos=1;
31
  while (n) {
31
  while (n) {
32
    res += (n & 7) * digitPos;
32
    res += (n & 7) * digitPos;
33
    n >>= 3;
33
    n >>= 3;
34
    digitPos *= 10;
34
    digitPos *= 10;
35
  }
35
  }
36
  return(res);
36
  return(res);
37
}
37
}
38
 
38
 
39
 
39
 
40
static void addnew(char *countrycode, char *humanlang, char *keybcode, unsigned short cp, unsigned char egafile, unsigned char keybfile) {
40
static void addnew(char *countrycode, char *humanlang, char *keybcode, unsigned short cp, unsigned char egafile, unsigned char keybfile) {
41
  static char lastcountry[4] = {0};
41
  static char lastcountry[4] = {0};
42
  static int curoffset = 0, curcountryoffset = 0;
42
  static int curoffset = 0, curcountryoffset = 0;
43
  /* if new country, declare an offset */
43
  /* if new country, declare an offset */
44
  if (strcmp(countrycode, lastcountry) != 0) {
44
  if (strcmp(countrycode, lastcountry) != 0) {
45
    /* close previous one, if any */
45
    /* close previous one, if any */
46
    if (lastcountry[0] != 0) {
46
    if (lastcountry[0] != 0) {
47
      fprintf(fdoff, "#define OFFLEN_%s %d\r\n", lastcountry, curoffset - curcountryoffset);
47
      fprintf(fdoff, "#define OFFLEN_%s %d\r\n", lastcountry, curoffset - curcountryoffset);
48
    } else {
48
    } else {
49
      fprintf(fdkeyb, "char *kblayouts[] = {\r\n");
49
      fprintf(fdkeyb, "char *kblayouts[] = {\r\n");
50
    }
50
    }
51
    /* open new one, if any */
51
    /* open new one, if any */
52
    if (countrycode[0] != 0) {
52
    if (countrycode[0] != 0) {
53
      fprintf(fdkeyb, "  /****** %s ******/\r\n", countrycode);
53
      fprintf(fdkeyb, "  /****** %s ******/\r\n", countrycode);
54
      curcountryoffset = curoffset;
54
      curcountryoffset = curoffset;
55
      fprintf(fdoff, "#define OFFLOC_%s %d\r\n", countrycode, curoffset);
55
      fprintf(fdoff, "#define OFFLOC_%s %d\r\n", countrycode, curoffset);
56
      strcpy(lastcountry, countrycode);
56
      strcpy(lastcountry, countrycode);
57
    } else {
57
    } else {
58
      fprintf(fdoff, "#define OFFCOUNT %d\r\n", curoffset);
58
      fprintf(fdoff, "#define OFFCOUNT %d\r\n", curoffset);
59
    }
59
    }
60
  }
60
  }
61
  /* */
61
  /* */
62
  if (countrycode[0] != 0) {
62
  if (countrycode[0] != 0) {
63
    fprintf(fdkeyb, "  \"%s\\0%s\\0\\%d\\%d\\%d\\%d\",\r\n", humanlang, keybcode, dec2oct(cp >> 8), dec2oct(cp & 0xff), dec2oct(egafile), dec2oct(keybfile));
63
    fprintf(fdkeyb, "  \"%s\\0%s\\0\\%d\\%d\\%d\\%d\",\r\n", humanlang, keybcode, dec2oct(cp >> 8), dec2oct(cp & 0xff), dec2oct(egafile), dec2oct(keybfile));
64
  } else {
64
  } else {
65
    fprintf(fdkeyb, "  NULL};\r\n");
65
    fprintf(fdkeyb, "  NULL};\r\n");
66
  }
66
  }
67
  curoffset++;
67
  curoffset++;
68
}
68
}
69
 
69
 
70
 
70
 
71
int main(void) {
71
int main(void) {
72
 
72
 
73
  /*** open files ***/
73
  /*** open files ***/
74
  fdkeyb = fopen("keylay.h", "wb");
74
  fdkeyb = fopen("keylay.h", "wb");
75
  fdoff = fopen("keyoff.h", "wb");
75
  fdoff = fopen("keyoff.h", "wb");
76
 
76
 
77
  /******************* LAYOUTS LIST START *******************/
77
  /******************* LAYOUTS LIST START *******************/
78
 
78
 
79
  /* English */
79
  /* English */
80
  addnew("EN", "English (US)", "en", 437, 0, 0);
80
  addnew("EN", "English (US)", "en", 437, 0, 0);
81
  addnew("EN", "English (UK)", "uk", 437, 0, 1);
81
  addnew("EN", "English (UK)", "uk", 437, 0, 1);
82
 
82
 
83
  /* French */
83
  /* French */
84
  addnew("FR", "French (France)", "fr", 858, 1, 1);
84
  addnew("FR", "French (France)", "fr", 858, 1, 1);
85
  addnew("FR", "French (Canada, standard)", "cf", 863, 9, 1);
85
  addnew("FR", "French (Canada, standard)", "cf", 863, 9, 1);
86
  addnew("FR", "French (Canada, legacy)", "cf501", 863, 9, 1);
86
  addnew("FR", "French (Canada, legacy)", "cf501", 863, 9, 1);
87
 
87
 
88
  /* German */
88
  /* German */
89
  addnew("DE", "German", "de", 858, 1, 1);
89
  addnew("DE", "German", "de", 858, 1, 1);
90
 
90
 
91
  /* Polish */
91
  /* Polish */
92
  addnew("PL", "Polish", "pl", 991, 10, 1);
92
  addnew("PL", "Polish", "pl", 991, 10, 1);
93
 
93
 
94
  /* Spanish */
94
  /* Spanish */
95
  addnew("ES", "Spanish", "es", 858, 1, 1);
95
  addnew("ES", "Spanish", "es", 858, 1, 1);
96
 
96
 
97
  /* Turkish */
97
  /* Turkish */
98
  addnew("TR", "Turkish", "tr", 857, 1, 2);
98
  addnew("TR", "Turkish", "tr", 857, 1, 2);
99
 
99
 
100
  /******************* LAYOUTS LIST STOP *******************/
100
  /******************* LAYOUTS LIST STOP *******************/
101
 
101
 
102
  /* end of list - DO NOT REMOVE */
102
  /* end of list - DO NOT REMOVE */
103
  addnew("", "", "", 0, 0, 0);
103
  addnew("", "", "", 0, 0, 0);
104
 
104
 
105
  /* close files */
105
  /* close files */
106
  fclose(fdoff);
106
  fclose(fdoff);
107
  fclose(fdkeyb);
107
  fclose(fdkeyb);
108
 
108
 
109
  return(0);
109
  return(0);
110
}
110
}