1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #include "appl.h"
- #include "tool.h"
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <syslog.h>
- #include <unistd.h>
- extern int _binary_version_dat_start;
- int DAEMON = 0;
- int RUNTYPE = -1;
- int VERSION[3] = {1, 1, 4};
- static char *s_optstr = "a:bcdet:v";
- int main(int argc, char *argv[])
- {
- int ret = 0;
- int i = 0;
- int ch;
- opterr = 0;
- char *version = (char *)&_binary_version_dat_start;
- char *temp = NULL;
- char *v_dup = strdup(version);
- temp = strtok(version, "-");
- int tok = 0;
- while (temp)
- {
- if (tok == 0)
- {
- VERSION[tok] = (int)strtol(temp, NULL, 16);
- }
- else
- {
- VERSION[tok] = (int)strtol(temp, NULL, 10);
- }
- tok++;
- temp = strtok(NULL, "-");
- }
- free(v_dup);
- misc_install_sigsegv_signal_handler();
- openlog(argv[0], LOG_CONS | LOG_PID, 0);
- syslog(LOG_INFO, "%s,++", __func__);
- for (i = 0; i < argc; i++)
- {
- syslog(LOG_INFO, "%s,arg list,argv[%d]:%s", __func__, i, argv[i]);
- }
- while ((ch = getopt(argc, argv, s_optstr)) != -1)
- {
- switch (ch)
- {
- case 'a':
- syslog(LOG_INFO, "option a:'%s'\n", optarg); // optarg不需自己声明!
- break;
- case 'b':
- syslog(LOG_INFO, "option b :b\n");
- break;
- case 'd':
- DAEMON = 1;
- syslog(LOG_INFO, "option d\n");
- break;
- case 'v':
- printf("version : %d-%d-%d\n", VERSION[0], VERSION[1], VERSION[2]);
- case 't':
- if (strcmp("appl", optarg) == 0)
- {
- RUNTYPE = 0;
- }
- if (strcmp("tool", optarg) == 0)
- {
- RUNTYPE = 1;
- }
- break;
- default:
- syslog(LOG_INFO, "other option :%c\n", ch);
- }
- }
- if (RUNTYPE == 0)
- {
- appl_main();
- }
- else if (RUNTYPE == 1)
- {
- tool_main();
- }
- else
- {
- syslog(LOG_INFO, "%s, unknown runtype:%d", __func__, RUNTYPE);
- }
- syslog(LOG_INFO, "%s, --", __func__);
- closelog();
- return 0;
- }
|