~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to libmysql_r/conf_to_src.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2004 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation.
 
6
 
 
7
   There are special exceptions to the terms and conditions of the GPL as it
 
8
   is applied to this software. View the full text of the exception in file
 
9
   EXCEPTIONS-CLIENT in the directory of this software distribution.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software
 
18
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
19
 
 
20
/* can't use -lmysys because this prog is used to create -lstrings */
 
21
 
 
22
 
 
23
#include <my_global.h>
 
24
#include <ctype.h>
 
25
#include <string.h>
 
26
#include <unistd.h>
 
27
 
 
28
#define CHARSETS_SUBDIR "sql/share/charsets"
 
29
#define CTYPE_TABLE_SIZE      257
 
30
#define TO_LOWER_TABLE_SIZE   256
 
31
#define TO_UPPER_TABLE_SIZE   256
 
32
#define SORT_ORDER_TABLE_SIZE 256
 
33
#define ROW_LEN 16
 
34
 
 
35
void print_arrays_for(char *set);
 
36
 
 
37
char *prog;
 
38
char buf[1024], *p, *endptr;
 
39
 
 
40
int
 
41
main(int argc, char **argv)
 
42
{
 
43
  prog = *argv;
 
44
 
 
45
  if (argc < 2) {
 
46
    fprintf(stderr, "usage: %s source-dir [charset [, charset]]\n", prog);
 
47
    exit(EXIT_FAILURE);
 
48
  }
 
49
 
 
50
  --argc; ++argv;       /* skip program name */
 
51
 
 
52
  if (chdir(*argv) != 0) {
 
53
    fprintf(stderr, "%s: can't cd to %s\n", prog, *argv);
 
54
    exit(EXIT_FAILURE);
 
55
  }
 
56
  --argc; ++argv;
 
57
 
 
58
  if (chdir(CHARSETS_SUBDIR) != 0) {
 
59
    fprintf(stderr, "%s: can't cd to %s\n", prog, CHARSETS_SUBDIR);
 
60
    exit(EXIT_FAILURE);
 
61
  }
 
62
 
 
63
  while (argc--)
 
64
    print_arrays_for(*argv++);
 
65
 
 
66
  exit(EXIT_SUCCESS);
 
67
}
 
68
 
 
69
void
 
70
print_array(FILE *f, const char *set, const char *name, int n)
 
71
{
 
72
  int i;
 
73
  char val[100];
 
74
 
 
75
  printf("uchar %s_%s[] = {\n", name, set);
 
76
 
 
77
  p = buf;
 
78
  *buf = '\0';
 
79
  for (i = 0; i < n; ++i)
 
80
  {
 
81
    /* get a word from f */
 
82
    endptr = p;
 
83
    for (;;)
 
84
    {
 
85
      while (isspace(*endptr))
 
86
        ++endptr;
 
87
      if (*endptr && *endptr != '#')    /* not comment */
 
88
        break;
 
89
      if ((fgets(buf, sizeof(buf), f)) == NULL)
 
90
        return;         /* XXX: break silently */
 
91
      endptr = buf;
 
92
    }
 
93
 
 
94
    p = val;
 
95
    while (!isspace(*endptr))
 
96
      *p++ = *endptr++;
 
97
    *p = '\0';
 
98
    p = endptr;
 
99
 
 
100
    /* write the value out */
 
101
 
 
102
    if (i == 0 || i % ROW_LEN == n % ROW_LEN)
 
103
      printf("  ");
 
104
 
 
105
    printf("%3d", (unsigned char) strtol(val, (char **) NULL, 16));
 
106
 
 
107
    if (i < n - 1)
 
108
      printf(",");
 
109
 
 
110
    if ((i+1) % ROW_LEN == n % ROW_LEN)
 
111
      printf("\n");
 
112
  }
 
113
 
 
114
  printf("};\n\n");
 
115
}
 
116
 
 
117
void
 
118
print_arrays_for(char *set)
 
119
{
 
120
  FILE *f;
 
121
 
 
122
  sprintf(buf, "%s.conf", set);
 
123
 
 
124
  if ((f = fopen(buf, "r")) == NULL) {
 
125
    fprintf(stderr, "%s: can't read conf file for charset %s\n", prog, set);
 
126
    exit(EXIT_FAILURE);
 
127
  }
 
128
 
 
129
  printf("\
 
130
/* The %s character set.  Generated automatically by configure and\n\
 
131
 * the %s program\n\
 
132
 */\n\n",
 
133
         set, prog);
 
134
 
 
135
  /* it would be nice if this used the code in mysys/charset.c, but... */
 
136
  print_array(f, set, "ctype",      CTYPE_TABLE_SIZE);
 
137
  print_array(f, set, "to_lower",   TO_LOWER_TABLE_SIZE);
 
138
  print_array(f, set, "to_upper",   TO_UPPER_TABLE_SIZE);
 
139
  print_array(f, set, "sort_order", SORT_ORDER_TABLE_SIZE);
 
140
  printf("\n");
 
141
 
 
142
  fclose(f);
 
143
 
 
144
  return;
 
145
}