OLD | NEW |
1 /* $Id: genperf.c 1959 2007-09-18 05:38:06Z peter $ | 1 /* $Id: genperf.c 2235 2009-11-03 05:15:37Z peter $ |
2 * | 2 * |
3 * Generate Minimal Perfect Hash (genperf) | 3 * Generate Minimal Perfect Hash (genperf) |
4 * | 4 * |
5 * Copyright (C) 2006-2007 Peter Johnson | 5 * Copyright (C) 2006-2007 Peter Johnson |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
11 * notice, this list of conditions and the following disclaimer. | 11 * notice, this list of conditions and the following disclaimer. |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 fprintf(out, "\n"); | 227 fprintf(out, "\n"); |
228 } | 228 } |
229 fprintf(out, " };\n"); | 229 fprintf(out, " };\n"); |
230 | 230 |
231 /* output the hash tab[] array */ | 231 /* output the hash tab[] array */ |
232 make_c_tab(out, tab, smax, blen, scramble); | 232 make_c_tab(out, tab, smax, blen, scramble); |
233 | 233 |
234 /* The hash function body */ | 234 /* The hash function body */ |
235 fprintf(out, " const struct %s *ret;\n", struct_name); | 235 fprintf(out, " const struct %s *ret;\n", struct_name); |
236 for (i=0; i<final.used; ++i) | 236 for (i=0; i<final.used; ++i) |
237 fprintf(out, final.line[i]); | 237 fprintf(out, "%s", final.line[i]); |
238 fprintf(out, " if (rsl >= %lu) return NULL;\n", nkeys); | 238 fprintf(out, " if (rsl >= %lu) return NULL;\n", nkeys); |
239 fprintf(out, " ret = &pd[rsl];\n"); | 239 fprintf(out, " ret = &pd[rsl];\n"); |
240 fprintf(out, " if (strcmp(key, ret->name) != 0) return NULL;\n"); | 240 fprintf(out, " if (strcmp(key, ret->name) != 0) return NULL;\n"); |
241 fprintf(out, " return ret;\n"); | 241 fprintf(out, " return ret;\n"); |
242 fprintf(out, "}\n"); | 242 fprintf(out, "}\n"); |
243 fprintf(out, "\n"); | 243 fprintf(out, "\n"); |
244 | 244 |
245 free(tab); | 245 free(tab); |
246 free(tabh); | 246 free(tabh); |
247 } | 247 } |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 fclose(out); | 531 fclose(out); |
532 | 532 |
533 if (errors > 0) { | 533 if (errors > 0) { |
534 remove(argv[2]); | 534 remove(argv[2]); |
535 return EXIT_FAILURE; | 535 return EXIT_FAILURE; |
536 } | 536 } |
537 | 537 |
538 return EXIT_SUCCESS; | 538 return EXIT_SUCCESS; |
539 } | 539 } |
540 | 540 |
OLD | NEW |