1
/* Copyright (C) 2004 MySQL AB
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; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
Written by Magnus Svensson
21
Converts a SQL file into a C file that can be compiled and linked
31
static void die(const char *fmt, ...)
35
/* Print the error message */
36
fprintf(stderr, "FATAL ERROR: ");
40
vfprintf(stderr, fmt, args);
44
fprintf(stderr, "unknown error");
45
fprintf(stderr, "\n");
48
/* Close any open files */
58
int main(int argc, char *argv[])
61
char* struct_name= argv[1];
62
char* infile_name= argv[2];
63
char* outfile_name= argv[3];
66
die("Usage: comp_sql <struct_name> <sql_filename> <c_filename>");
68
/* Open input and output file */
69
if (!(in= fopen(infile_name, "r")))
70
die("Failed to open SQL file '%s'", infile_name);
71
if (!(out= fopen(outfile_name, "w")))
72
die("Failed to open output file '%s'", outfile_name);
74
fprintf(out, "const char* %s={\n\"", struct_name);
76
while (fgets(buff, sizeof(buff), in))
84
Reached end of line, add escaped newline, escaped
85
backslash and a newline to outfile
87
fprintf(out, "\\n \"\n\"");
90
else if (*curr == '\r')
106
if (*(curr-1) != '\n')
109
Some compilers have a max string length,
110
insert a newline at every 512th char in long
113
fprintf(out, "\"\n\"");
117
fprintf(out, "\\\n\"};\n");