1 
2 /******************************************************************************
3  *
4  *  This file is part of meryl-utility, a collection of miscellaneous code
5  *  used by Meryl, Canu and others.
6  *
7  *  This software is based on:
8  *    'Canu' v2.0              (https://github.com/marbl/canu)
9  *  which is based on:
10  *    'Celera Assembler' r4587 (http://wgs-assembler.sourceforge.net)
11  *    the 'kmer package' r1994 (http://kmer.sourceforge.net)
12  *
13  *  Except as indicated otherwise, this is a 'United States Government Work',
14  *  and is released in the public domain.
15  *
16  *  File 'README.licenses' in the root directory of this distribution
17  *  contains full conditions and disclaimers.
18  */
19 
20 #include "types.H"
21 
22 int
main(int argc,char ** argv)23 main(int argc, char **argv) {
24 
25   if (argc != 2) {
26     fprintf(stderr, "usage: %s text-file\n", argv[0]);
27     fprintf(stderr, "  Converts the input text-file into 64-bit and 32-bit integer\n");
28     fprintf(stderr, "  constants, for use as magic numbers in data files.  If you then\n");
29     fprintf(stderr, "  write this integer constant to a file, it'll appear as readable\n");
30     fprintf(stderr, "  text in the file.  The input file is limited to 4 KB.\n");
31     return(1);
32   }
33 
34   uint32  ccLen = 0;
35   uint32  ccMax = 4096;
36   char   *cc    = new char [ccMax];
37   FILE   *F;
38 
39   memset(cc, 0, ccMax);
40 
41   F = fopen(argv[1], "r");
42   ccLen = fread(cc, sizeof(char), 4096, F);
43   fclose(F);
44 
45   F = fopen(argv[1], "r");
46   for (uint32 ii=0, nn=0; ii<ccLen; ii += 8, nn++) {
47     uint64 u64;
48 
49     fread(&u64, sizeof(uint64), 1, F);       //  You can get away with only the char array,
50     assert(u64 == *((uint64 *)(cc + ii)));   //  but I'm not sure what will happen on big-endian.
51 
52     fprintf(stdout, "uint64 u64_%02u = 0x%016lxllu;  //  %c%c%c%c%c%c%c%c\n",
53             nn, u64,
54             integerToLetter(cc[ii+0]),
55             integerToLetter(cc[ii+1]),
56             integerToLetter(cc[ii+2]),
57             integerToLetter(cc[ii+3]),
58             integerToLetter(cc[ii+4]),
59             integerToLetter(cc[ii+5]),
60             integerToLetter(cc[ii+6]),
61             integerToLetter(cc[ii+7]));
62   }
63   fclose(F);
64 
65   F = fopen(argv[1], "r");
66   for (uint32 ii=0, nn=0; ii<ccLen; ii += 4, nn++) {
67     uint32 u32;
68 
69     fread(&u32, sizeof(uint32), 1, F);
70     assert(u32 == *((uint32 *)(cc + ii)));
71 
72     fprintf(stdout, "uint32 u32_%02u = 0x%08xlu;  //  %c%c%c%c\n",
73             nn, u32,
74             integerToLetter(cc[ii+0]),
75             integerToLetter(cc[ii+1]),
76             integerToLetter(cc[ii+2]),
77             integerToLetter(cc[ii+3]));
78   }
79   fclose(F);
80 
81   delete [] cc;
82 
83   return(0);
84 }
85