main.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2009 Openmoko Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <stdbool.h>
  20. #include <string.h>
  21. #include <getopt.h>
  22. #include "hash.h"
  23. static struct option opts[] = {
  24. { "help", 0, 0, 'h' },
  25. { "verbose", 0, 0, 'v' },
  26. { "fnd", 1, 0, 'f' },
  27. { "pfx", 1, 0, 'p' },
  28. { "hsh", 1, 0, 'o' },
  29. { NULL, 0, NULL, 0 }
  30. };
  31. bool verbose = false;
  32. static void usage(const char *message)
  33. {
  34. if (NULL != message)
  35. {
  36. fprintf(stderr, "error: %s\n", message);
  37. }
  38. fprintf(stderr, "usage: %s <options>\n"
  39. " --help this message\n"
  40. " --verbose message output\n"
  41. " --fnd=file input fnd file\n"
  42. " --pfx=file input pfx file\n"
  43. " --hsh=file output hash file\n",
  44. "hash-gen");
  45. exit(1);
  46. }
  47. int main(int argc, char **argv)
  48. {
  49. char fnd_name[1024];
  50. char pfx_name[1024];
  51. char hsh_name[1024];
  52. printf("hash generator - (C) 2009 by Openmoko Inc.\n"
  53. "This program is Free Software and has ABSOLUTELY NO WARRANTY\n\n");
  54. memset(fnd_name, '\0', sizeof(fnd_name));
  55. memset(pfx_name, '\0', sizeof(pfx_name));
  56. memset(hsh_name, '\0', sizeof(hsh_name));
  57. for (;;)
  58. {
  59. int c, option_index = 0;
  60. c = getopt_long(argc, argv, "hvf:p:o:", opts, &option_index);
  61. if (c == -1)
  62. {
  63. break;
  64. }
  65. switch (c)
  66. {
  67. case 'h':
  68. usage(NULL);
  69. break;
  70. case 'f':
  71. strncpy(fnd_name, optarg, sizeof(fnd_name) - 1);
  72. fnd_name[sizeof(fnd_name) - 1] = '\0';
  73. break;
  74. case 'p':
  75. strncpy(pfx_name, optarg, sizeof(pfx_name) - 1);
  76. pfx_name[sizeof(pfx_name) - 1] = '\0';
  77. break;
  78. case 'o':
  79. strncpy(hsh_name, optarg, sizeof(hsh_name) - 1);
  80. hsh_name[sizeof(hsh_name) - 1] = '\0';
  81. break;
  82. case 'v':
  83. verbose = true;
  84. break;
  85. default:
  86. usage("invalid arguments");
  87. }
  88. }
  89. if ('\0' == fnd_name[0])
  90. {
  91. usage("missing --fnd=file");
  92. }
  93. if ('\0' == pfx_name[0])
  94. {
  95. usage("missing --pfx=file");
  96. }
  97. if ('\0' == hsh_name[0])
  98. {
  99. usage("missing --hsh=file");
  100. }
  101. generate_pedia_hsh(fnd_name, pfx_name, hsh_name);
  102. return 0;
  103. }