int main(int argc, char* const argv[]) { memset(&p16pos, 0, sizeof p16pos); memset(&p16card, 0, sizeof p16card); char temp[PATH_MAX + 1]; realpath(argv[0], temp); strcpy(p16pos.base_dir, dirname(temp)); // LOG((LOG_DEBUG, "启动路径: %s", p16pos.base_dir)); int8 ret; ret = check_config_db(); if (ret) { error_exit(1, "初始化参数失败"); } /* //插入一条黑名单测试数据 p16_blackcard_t blackcard_t; blackcard_t.cardno = 184; blackcard_t.cardflag = 1; memcpy(blackcard_t.remark, "aaa", 3); blackcard_update_record(&blackcard_t); // */ ret = load_sys_config(); if (ret) { error_exit(2, "加载参数失败"); } load_ip_config(); // 初始化参数 do_init_all_hardware(); // 加载配置信息 do_load_config(); clear_transdtl(); test_printer(); do_check_desktop(); p16pos.app_running = 1; show_statusbar(); //创建上传流水线程 open_send_transdtl_thread(); // 显示主菜单 init_purchase_menu(); return 0; }
int main(int argc, char **argv) { /* 32 таблицы ип локальных адресов */ struct t_ip_groups groups; char ch; struct sockaddr_in tmp; const struct { char *local_ips_name; char *logfile_name; double bw; int print_report1; int print_report2; int print_report3; } defaults = {"locals.txt", "-", 4*1000000, 0, 0, 0}; struct { const char *local_ips_name; FILE *local_ips; const char *logfile_name; FILE *logfile; double bw; int print_report1; int print_report2; int print_report3; }params; params.local_ips_name = strdup(defaults.local_ips_name); params.logfile_name = strdup(defaults.logfile_name); params.bw = defaults.bw; params.print_report1 = defaults.print_report1; params.print_report2 = defaults.print_report2; params.print_report3 = defaults.print_report3; while ((ch = getopt(argc, argv, "123c:f:m:")) != -1) { switch (ch) { case '1': params.print_report1 = 1; break; case '2': params.print_report2 = 1; break; case '3': params.print_report3 = 1; break; case 'c': free((void *)params.local_ips_name); params.local_ips_name=strdup(optarg); break; case 'f': free((void *)params.logfile_name); params.logfile_name = strdup(optarg); break; case 'm': sscanf(optarg, "%lf", ¶ms.bw); params.bw = params.bw*1000000; break; case 'h': case '?': default: usage(); return 0; break; } } argc -= optind; argv += optind; params.local_ips = my_fopen(params.local_ips_name); if ( params.local_ips == NULL) { char buf[80]; snprintf(buf, sizeof(buf), "cannot open config file %s", params.local_ips_name); perror (buf); return -1; } rn_init(); if ( !rn_inithead((void **)&groups.ips, ((uint8_t *)&tmp.sin_addr - (uint8_t *)&tmp) * 8)) { fprintf(stderr, "cannot init group"); return -1; } if ( load_ip_config(params.local_ips, &groups) < 0) { fprintf(stderr, "can not load config file\n"); return -2; } params.logfile = my_fopen(params.logfile_name); if ( params.logfile == NULL) { char buf[80]; snprintf(buf, sizeof(buf), "cannot open log file %s", params.logfile_name); perror (buf); return -3; } if ( load_ip_stats(params.logfile, &groups) < 0) { fprintf(stderr, "cannot load stats file\n"); return -4; } groups.bw = params.bw; if (params.print_report1) print_full_time_log(stdout, &groups); if (params.print_report2) calc_n_print_hour_log(stdout, &groups); if (params.print_report3) print_unformatted_time_log(stdout, &groups); fclose(params.local_ips); fclose(params.logfile); return 0; }