#include <stdio.h>
#include <stdint.h>
#include "firebird/impl/msg_helper.h"
typedef unsigned short USHORT;
typedef USHORT ISC_USHORT;
typedef intptr_t ISC_STATUS;
typedef long SLONG;
FILE *fp;
#define stringify_literal(x) #x
#define FB_IMPL_MSG_NO_SYMBOL(facility, number, text)
#define FB_IMPL_MSG_SYMBOL(facility, number, symbol, text)
#define FB_IMPL_MSG(facility, number, symbol, sqlCode, sqlClass, sqlSubClass, text) \
output_message(make_isc_code(FB_IMPL_MSG_FACILITY_##facility, number), stringify_literal(text));
int make_isc_code(int facility, int code) {
ISC_USHORT t1 = facility;
t1 &= 0x1F;
ISC_STATUS t2 = t1;
t2 <<= 16;
ISC_STATUS t3 = code;
code &= 0x3FFF;
return t2 | t3 | ((ISC_STATUS) 0x14000000);
}
void process_messages() {
#include "firebird/impl/msg/all.h"
}
void output_message(int code, char* msg) {
fprintf(fp, " %d=> r#\%s#,\n", code, msg);
}
int main(int argc, char *argv[])
{
int i;
fp = fopen("../src/errmsgs.rs", "w");
fprintf(fp, "\
/////////////////////////////////////////////////////////////////////////////\n\
// The contents of this file are subject to the Interbase Public\n\
// License Version 1.0 (the \"License\"); you may not use this file\n\
// except in compliance with the License. You may obtain a copy\n\
// of the License at https://www.firebirdsql.org/en/interbase-public-license/\n\
//\n\
// Software distributed under the License is distributed on an\n\
// \"AS IS\" basis, WITHOUT WARRANTY OF ANY KIND, either express\n\
// or implied. See the License for the specific language governing\n\
// rights and limitations under the License.\n\n");
fprintf(fp, "// generated by ../misc/errmsgs.c\n\n");
fprintf(fp, "use maplit::hashmap;\n\n");
fprintf(fp, "pub fn error_message_by_id(id: u32) -> &'static str {\n");
fprintf(fp, " let map = hashmap! {\n");
process_messages();
fprintf(fp, " };\n");
fprintf(fp, " map[&id]\n");
fprintf(fp, "}\n");
fclose(fp);
return 0;
}