main.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "appl.h"
  2. #include "tool.h"
  3. #include <stdarg.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <syslog.h>
  8. #include <unistd.h>
  9. extern int _binary_version_dat_start;
  10. int DAEMON = 0;
  11. int RUNTYPE = -1;
  12. int VERSION[3] = {1, 1, 4};
  13. static char *s_optstr = "a:bcdet:v";
  14. int main(int argc, char *argv[])
  15. {
  16. int ret = 0;
  17. int i = 0;
  18. int ch;
  19. opterr = 0;
  20. char *version = (char *)&_binary_version_dat_start;
  21. char *temp = NULL;
  22. char *v_dup = strdup(version);
  23. temp = strtok(version, "-");
  24. int tok = 0;
  25. while (temp)
  26. {
  27. if (tok == 0)
  28. {
  29. VERSION[tok] = (int)strtol(temp, NULL, 16);
  30. }
  31. else
  32. {
  33. VERSION[tok] = (int)strtol(temp, NULL, 10);
  34. }
  35. tok++;
  36. temp = strtok(NULL, "-");
  37. }
  38. free(v_dup);
  39. misc_install_sigsegv_signal_handler();
  40. openlog(argv[0], LOG_CONS | LOG_PID, 0);
  41. syslog(LOG_INFO, "%s,++", __func__);
  42. for (i = 0; i < argc; i++)
  43. {
  44. syslog(LOG_INFO, "%s,arg list,argv[%d]:%s", __func__, i, argv[i]);
  45. }
  46. while ((ch = getopt(argc, argv, s_optstr)) != -1)
  47. {
  48. switch (ch)
  49. {
  50. case 'a':
  51. syslog(LOG_INFO, "option a:'%s'\n", optarg); // optarg不需自己声明!
  52. break;
  53. case 'b':
  54. syslog(LOG_INFO, "option b :b\n");
  55. break;
  56. case 'd':
  57. DAEMON = 1;
  58. syslog(LOG_INFO, "option d\n");
  59. break;
  60. case 'v':
  61. printf("version : %d-%d-%d\n", VERSION[0], VERSION[1], VERSION[2]);
  62. case 't':
  63. if (strcmp("appl", optarg) == 0)
  64. {
  65. RUNTYPE = 0;
  66. }
  67. if (strcmp("tool", optarg) == 0)
  68. {
  69. RUNTYPE = 1;
  70. }
  71. break;
  72. default:
  73. syslog(LOG_INFO, "other option :%c\n", ch);
  74. }
  75. }
  76. if (RUNTYPE == 0)
  77. {
  78. appl_main();
  79. }
  80. else if (RUNTYPE == 1)
  81. {
  82. tool_main();
  83. }
  84. else
  85. {
  86. syslog(LOG_INFO, "%s, unknown runtype:%d", __func__, RUNTYPE);
  87. }
  88. syslog(LOG_INFO, "%s, --", __func__);
  89. closelog();
  90. return 0;
  91. }