1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-05 13:16:09 +03:00

Temporary commit of merge of MariaDB 10.0-base and MySQL 5.6

This commit is contained in:
Michael Widenius
2012-08-01 17:27:34 +03:00
parent 5a86a61219
commit 1d0f70c2f8
557 changed files with 124450 additions and 30236 deletions

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2004 MySQL AB
/* Copyright (c) 2004, 2010, Oracle and/or its affiliates.
Copyright (c) 2012 Monty Program Ab
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -11,10 +12,10 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
/*
Written by Magnus Svensson
Originally written by Magnus Svensson
*/
/*
@@ -25,10 +26,18 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
/* Compiler-dependent constant for maximum string constant */
#define MAX_STRING_CONSTANT_LENGTH 65535
#include "../sql/sql_bootstrap.h"
/*
This is an internal tool used during the build process only,
- do not make a library just for this,
which would make the Makefiles and the server link
more complex than necessary,
- do not duplicate the code either.
so just add the sql_bootstrap.cc code as is.
*/
#include "../sql/sql_bootstrap.cc"
FILE *in, *out;
@@ -58,15 +67,60 @@ static void die(const char *fmt, ...)
exit(1);
}
char *fgets_fn(char *buffer, size_t size, fgets_input_t input)
{
return fgets(buffer, size, (FILE*) input);
}
static void print_query(FILE *out, const char *query)
{
const char *ptr= query;
int column= 0;
fprintf(out, "\"");
while (*ptr)
{
if (column >= 120)
{
/* Wrap to the next line, tabulated. */
fprintf(out, "\"\n \"");
column= 2;
}
switch(*ptr)
{
case '\n':
/*
Preserve the \n character in the query text,
and wrap to the next line, tabulated.
*/
fprintf(out, "\\n\"\n \"");
column= 2;
break;
case '\r':
/* Skipped */
break;
case '\"':
fprintf(out, "\\\"");
column++;
break;
default:
putc(*ptr, out);
column++;
break;
}
ptr++;
}
fprintf(out, "\\n\",\n");
}
int main(int argc, char *argv[])
{
char buff[512];
struct stat st;
char query[MAX_BOOTSTRAP_QUERY_SIZE];
char* struct_name= argv[1];
char* infile_name= argv[2];
char* outfile_name= argv[3];
int rc;
int query_length;
if (argc != 4)
die("Usage: comp_sql <struct_name> <sql_filename> <c_filename>");
@@ -74,86 +128,31 @@ int main(int argc, char *argv[])
/* Open input and output file */
if (!(in= fopen(infile_name, "r")))
die("Failed to open SQL file '%s'", infile_name);
if (!(out= fopen(outfile_name, "w")))
die("Failed to open output file '%s'", outfile_name);
fprintf(out, "const char %s[]={\n",struct_name);
/*
Some compilers have limitations how long a string constant can be.
We'll output very long strings as hexadecimal arrays, and short ones
as strings (prettier)
*/
stat(infile_name, &st);
if (st.st_size > MAX_STRING_CONSTANT_LENGTH)
fprintf(out, "/*\n");
fprintf(out, " Do not edit this file, it is automatically generated from:\n");
fprintf(out, " <%s>\n", infile_name);
fprintf(out, "*/\n");
fprintf(out, "const char* %s[]={\n", struct_name);
for ( ; ; )
{
int cnt=0;
int c;
for(cnt=0;;cnt++)
{
c= fgetc(in);
if (c== -1)
break;
rc= read_bootstrap_query(query, &query_length,
(fgets_input_t) in, fgets_fn);
if(cnt != 0)
fputc(',', out);
if (rc == READ_BOOTSTRAP_ERROR)
die("Failed to read the bootstrap input file.\n");
if (rc == READ_BOOTSTRAP_EOF)
break;
/* Put line break after each 16 hex characters */
if(cnt && (cnt%16 == 0))
fputc('\n', out);
fprintf(out,"0x%02x",c);
}
fprintf(out,",0x00");
print_query(out, query);
}
else
{
fprintf(out,"\"");
while (fgets(buff, sizeof(buff), in))
{
char *curr= buff;
while (*curr)
{
if (*curr == '\n')
{
/*
Reached end of line, add escaped newline, escaped
backslash and a newline to outfile
*/
fprintf(out, "\\n \"\n\"");
curr++;
}
else if (*curr == '\r')
{
curr++; /* Skip */
}
else
{
if (*curr == '"')
{
/* Needs escape */
fputc('\\', out);
}
fputc(*curr, out);
curr++;
}
}
if (*(curr-1) != '\n')
{
/*
Some compilers have a max string length,
insert a newline at every 512th char in long
strings
*/
fprintf(out, "\"\n\"");
}
}
fprintf(out, "\\\n\"");
}
fprintf(out, "};\n");
fprintf(out, "NULL\n};\n");
fclose(in);
fclose(out);