16 #include <ndb_global.h> 
   27     "Display this help and exit.",
 
   29     GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
 
   33     GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }
 
   37 load_default_groups[]= { 0 };
 
   42   ndb_short_usage_sub(
"*.frm ...");
 
   48   printf(
"%s: pack and dump *.frm as C arrays\n", my_progname);
 
   49   ndb_usage(short_usage_sub, load_default_groups, my_long_options);
 
   53 dodump(
const char* 
name, 
const uchar* frm_data, uint frm_len)
 
   55   printf(
"const uint g_%s_frm_len = %u;\n\n", name, frm_len);
 
   56   printf(
"const uint8 g_%s_frm_data[%u] =\n{\n", name, frm_len);
 
   65     printf(
"0x%02x", frm_data[n]);
 
   66     if (n + 1 < frm_len) {
 
   78 dofile(
const char* 
file)
 
   90     if (stat(file, &st) == -1)
 
   92       fprintf(stderr, 
"%s: stat: %s\n", file, strerror(errno));
 
   96     if ((data = (uchar*)malloc(size)) == 0)
 
   98       fprintf(stderr, 
"%s: malloc %u: %s\n", file, (uint)size, strerror(errno));
 
  101     if ((fd = open(file, O_RDONLY)) == -1)
 
  103       fprintf(stderr, 
"%s: open: %s\n", file, strerror(errno));
 
  107     if ((size2 = read(fd, data, size)) == -1)
 
  109       fprintf(stderr, 
"%s: read: %s\n", file, strerror(errno));
 
  112     if ((
size_t)size2 != size)
 
  114       fprintf(stderr, 
"%s: short read: %u != %u\n", file, (uint)size2, (uint)size);
 
  118     if ((error = packfrm(data, size, &pack_data, &pack_len)) != 0)
 
  120       fprintf(stderr, 
"%s: packfrm: error %d\n", file, error);
 
  123     namebuf = strdup(file);
 
  126       fprintf(stderr, 
"%s: strdup: %s\n", file, strerror(errno));
 
  129     char* name = namebuf;
 
  130     if (strchr(name, 
'/') != 0)
 
  131       name = strrchr(name, 
'/') + 1;
 
  133     if ((dot = strchr(name, 
'.')) != 0)
 
  136     printf(
"  name: %s\n", name);
 
  137     printf(
"  orig: %u\n", (uint)size);
 
  138     printf(
"  pack: %u\n", (uint)pack_len);
 
  140     dodump(name, pack_data, pack_len);
 
  156 main(
int argc, 
char** argv)
 
  158   my_progname = 
"ndb_pack_frm";
 
  162   ndb_opt_set_usage_funcs(short_usage_sub, usage);
 
  163   ret = handle_options(&argc, &argv, my_long_options, ndb_std_get_one_option);
 
  165     return NDBT_WRONGARGS;
 
  167   for (
int i = 0; 
i < argc; 
i++)
 
  169     ret = dofile(argv[
i]);