int main(int argc, const char *argv[]) { init_function *fun; int id; //init signal(SIGPIPE,SIG_IGN); callback_tab["list"] = list; callback_tab["close"] = close; msg_t config = get_config_from_file("config.json"); sock::init(config); for(fun = &__initlist_start;fun < &__initlist_end;fun++) assert_perror((*fun)(config) < 0); //main message loop while(get_msg_source(id)){ process_msg(id); } return 0; }
int main(int argc, char *argv[]) { if (argc == 1) { debug("have no arguments!\n"); display_usage(); return 1; } if (*(*(argv + 1)) != '-') { printf("the argument must start with '-' .\n"); return 1; } // if(maincontrol()) {return 0;} debug("the argc is: %d, and the argv is: %s \n", argc, *argv); globalargs.iquery = 0; globalargs.iremove = 0; globalargs.chadd = NULL; globalargs.chwrite = NULL; globalargs.chget = NULL; globalargs.chput = NULL; globalargs.iversion = 0; globalargs.randomized = 0; char *greet = NULL; static const struct option longopts[] = { {"query", no_argument, NULL, 'q'}, {"add", required_argument, NULL, 'a'}, {"download", required_argument, NULL, 'd'}, {"remove", no_argument, NULL, 'r'}, {"write", required_argument, NULL, 'w'}, {"get", required_argument, NULL, 'g'}, {"put", required_argument, NULL, 'p'}, {"version", no_argument, NULL, 'v'}, {"randomize", no_argument, NULL, 0}, {"help", no_argument, NULL, 'h'}, {NULL, no_argument, NULL, 0} }; static const char *optstring = "qrd:a:w:g:p:vh?"; int opt = 0; int longindex = 0; opt = getopt_long(argc, argv, optstring, longopts, &longindex); while (opt != -1) { switch (opt) { case 'q': globalargs.iquery = 1; /* true */ debug("case q:-----------\n"); break; case 'r': globalargs.iremove = 1; debug("case r -----------\n"); break; case 'd': g_downfromfile = TRUE; case 'a': globalargs.chadd = optarg; debug("case a ----------: %s\n", globalargs.chadd); break; case 'w': globalargs.chwrite = optarg; debug("case w----------:%s \n", globalargs.chwrite); HAVE_NOT_THIS_FUNCTION(""); break; case 'g': globalargs.chget = optarg; debug("case g----------:%s \n", globalargs.chget); HAVE_NOT_THIS_FUNCTION(""); break; case 'p': globalargs.chput = optarg; debug("case p----------:%s \n", globalargs.chput); HAVE_NOT_THIS_FUNCTION(""); break; case 'v': globalargs.iversion = 1; debug("case v -----------\n"); break; case 'h': /* fall-through is intentional */ case '?': display_usage(); debug("case h or ?-------------\n"); return 0; break; case 0: /* long option without a short arg */ if (strcmp("randomize", longopts[longindex].name) == 0) { globalargs.randomized = 1; } debug("case 0 -----------\n"); return 0; break; default: /* you won't actually get here. */ debug("case default -----------\n"); return 0; break; } break; } if (getopt_long(argc, argv, optstring, longopts, &longindex) != -1) { display_usage(); return 0; } debug("the length of the second argv is--:%d\n", strlen(*(argv + 1))); if (*(*(argv + 1) + 1) != '-' && strlen(*(argv + 1)) != 2) { display_usage(); return 0; } /*---------------------------------------------------------------------------------*/ g_allowedmodes[0] = 0; g_allowedmodes[1] = 0; g_allowedmodes[2] = 0; g_defaultmode = 3; get_config_from_file(); // initial_tdsp_wb(); tdsp_query_power_state(); if (g_buspowerstate != PowerOn) { printf("please make sure the 3DSP_card(usb) is inserted!\n"); return 0; } if (set_hotkey_flag((unsigned long) m_nHotKeyFlag) != 0) debug("set the hotkey flag of uwb fail!\n"); /*---------------------------------------------------------------------------------*/ int ioffset; long length; if (globalargs.iquery && argc == 2) { debug("call the query device\n"); tdsp_query_device(); if (g_iscardin == 0) printf("no card in, please insert the tdsp card!\n"); else { switch (g_currentserialno) { case TDSP_SERIAL_NO_BT: printf("the current device is bluetooth \n"); break; case TDSP_SERIAL_NO_WLAN: printf("the current device is wlan \n"); break; case TDSP_SERIAL_NO_COEXIST: printf("the current device is bluetooth&wlan \n"); break; case TDSP_SERIAL_NO_NONE: printf("the current device is none\n"); break; default: printf("the current device is undefined \n"); break; } } } else if (globalargs.iquery && argc != 2) { printf("call the query device, don't need the argument\n"); } else if (globalargs.iremove && argc == 2) { printf("call the remove device\n"); if (maincontrol()) { return 0; } on_unplug_activate(); if (tdsp_query_device() == TDSP_SERIAL_NO_NONE) { printf("^_^ remove devices success!\n"); } else { printf("*_* remove devices fail!\n"); } } else if (globalargs.iremove && argc != 2) { printf("call the remove device don't need the argument\n"); } else if (globalargs.chadd != NULL) { if (*(*(argv + 1) + 1) == '-') { if (argc != 2) { display_usage(); return 0; } } else { if (argc != 3) { display_usage(); return 0; } } if (strcasecmp(globalargs.chadd, "bt") == 0) { printf("the device you want to add:--- %s\n", globalargs.chadd); if (maincontrol()) { return 0; } on_bluetooth_activate(); if (tdsp_query_device() == TDSP_SERIAL_NO_BT) { printf("^_^ add bluetooth success!\n"); } else { printf("*_* add bluetooth fail!\n"); } } else if (strcasecmp(globalargs.chadd, "wlan") == 0) { printf("the device you want to add:---%s\n", globalargs.chadd); if (maincontrol()) { return 0; } on_wlan_activate(); if (tdsp_query_device() == TDSP_SERIAL_NO_WLAN) { printf("^_^ add wlan success!\n"); } else { printf("*_* add wlan fail!\n"); } } else if (strcasecmp(globalargs.chadd, "combo") == 0) { printf("the devices you want to add:---%s\n", globalargs.chadd); if (maincontrol()) { return 0; } on_coexist_activate(); if (tdsp_query_device() == TDSP_SERIAL_NO_COEXIST) { printf("^_^ add bluetooth&wlan success!\n"); } else { printf("*_* add bluetooth&wlan fail!\n"); } } else { printf ("*_* only 'bt', 'wlan', 'combo' is promit! but the device you want to add:---: %s\n", globalargs.chadd); } } else if (globalargs.chwrite != NULL) { if (*(*(argv + 1) + 1) == '-') { if (argc != 3) { display_usage(); return 0; } greet = *(argv + 2); } else { if (argc != 4) { display_usage(); return 0; } greet = *(argv + 3); } tdsp_query_device(); if (g_iscardin == FALSE) { printf("no card in, please insert the tdsp card first!\n"); return 0; } if (g_currentserialno == TDSP_SERIAL_NO_NONE) { printf("please add a device bt or wlan ... \n"); return 0; } debug("write the eeprom \n"); if (strcasecmp(globalargs.chwrite, "bd") == 0) { printf("write eeprom ---------------bd\n"); if (get_eeprom_data_2write(greet, 12) == FALSE) { debug(""); return 0; } if (tdsp_write_eeprom(671, 6, g_eeprombuf) == FALSE) { printf("write eeprom bd fail!\n"); } else { printf("write eeprom bd success!\n"); } } else if (strcasecmp(globalargs.chwrite, "key") == 0) { printf("write eeprom ---------------key\n"); if (get_eeprom_data_2write(greet, 32) == FALSE) { debug(""); return 0; } if (tdsp_write_eeprom(677, 16, g_eeprombuf) == FALSE) { printf("write eeprom key fail!\n"); } else { printf("write eeprom key success!\n"); } } else { printf("write eeprom ---------------other\n"); int offset; offset = strtol(globalargs.chwrite, NULL, 0); if (offset >= 1024 || offset < 0) { printf("offset out of range! it must between 0~1023(decimal)\n"); return 0; } if (get_eeprom_data_2write(greet, 2) == FALSE) { debug(""); return 0; } printf("write eeprom offset=%d, content is: 0x%s\n", offset, greet); if (tdsp_write_eeprom(offset, 1, g_eeprombuf) == FALSE) { printf("write eeprom offset=%d fail!\n", offset); } else { printf("write eeprom offset=%d,content is: 0x%s,success!\n", offset, greet); } } } else if (globalargs.chget != NULL) { if (*(*(argv + 1) + 1) == '-') { if (argc != 3) { display_usage(); return 0; } greet = *(argv + 2); } else { if (argc != 4) { display_usage(); return 0; } greet = *(argv + 3); } tdsp_query_device(); if (g_iscardin == FALSE) { printf("no card in, please insert the tdsp card first!\n"); return 1; } /* if (g_currentserialno==TDSP_SERIAL_NO_NONE) {printf("please add a device bt or wlan ... \n"); return;}*/ debug("get the register %s %s \n", globalargs.chget, greet); if (strlen(globalargs.chget) != 4) { printf("the offset is too short, its length must be 4 \n"); return 1; } else { if (hexstr2intnum(globalargs.chget, 4, &ioffset) == FALSE) return 1; if (ioffset > 0x6000 || ioffset <= 0) { printf("offset out of range!\n"); return 1; } } length = strtol(greet, NULL, 0); if (length > 1024 || length <= 0) { printf("length out of range! it must between 1~1024 \n"); return 1; } else { debug("get register offset= %d, length = %ld\n", ioffset, length); tdsp_read_register((unsigned long) ioffset, length, NULL); } } else if (globalargs.chput != NULL) { if (*(*(argv + 1) + 1) == '-') { if (argc != 3) { display_usage(); return 1; } greet = *(argv + 2); } else { if (argc != 4) { display_usage(); return 1; } greet = *(argv + 3); } tdsp_query_device(); if (g_iscardin == FALSE) { printf("no card in, please insert the tdsp card first!\n"); return 1; } /* if (g_currentserialno==TDSP_SERIAL_NO_NONE) {printf("please add a device bt or wlan ... \n"); return;}*/ debug("write the register at offset= %s, the data= %s \n", globalargs.chput, greet); if (strlen(globalargs.chput) != 4) { printf("the offset is too short, its length must be 4 \n"); return 1; } else { if (hexstr2intnum(globalargs.chput, 4, &ioffset) == FALSE) return 1; if (ioffset > 0x6000 || ioffset <= 0) { printf("offset out of range!it must less then 0x6000\n"); return 1; } } length = strlen(greet); if (length != WTRGLEN) { length = WTRGLEN; printf("length error! its must be %d \n", WTRGLEN); return 1; } else { debug("put register-----------------!\n"); if (get_eeprom_data_2write(greet, WTRGLEN) == FALSE) { debug(""); return 1; } if (tdsp_write_register(ioffset, WTRGLEN, g_eeprombuf) == FALSE) { printf("write register fail!\n"); } else { printf("write register success!\n"); } } } else if (globalargs.iversion && argc == 2) { printf("Query the card version\n\n"); update_ver_string(); } else if (globalargs.iversion && argc != 2) { printf("query the card version don't need the argument\n"); } else { debug("other! at the end of main()\n"); printf ("use '--help' or '-r' to see a full list of available command line options.\n"); } return 0; }
int main(int argc, char* argv[]) { remote_config_t *remote; FILE *fp; int ret, i; int device_fd; unsigned int val; for(i =0; i < 256; i++) key_map[i] = KEY_RESERVED; for(i =0; i < 256; i++) repeat_key_map[i] = KEY_RESERVED; for(i =0; i < 4; i++) mouse_map[i] = 0xffff; remote = (remote_config_t *)malloc(sizeof(remote_config_t)); if(!remote){ printf("out of memory !\n"); return -1; } memset((unsigned char*)remote, 0xff, sizeof(remote_config_t)); remote->key_map = key_map; remote->repeat_key_map = repeat_key_map; remote->mouse_map = mouse_map; device_fd = open(DEVICE_NAME, O_RDWR); if(device_fd < 0){ printf("Can't open %s .\n", DEVICE_NAME); return -2; } if(argc < 2){ remote->factory_code = 0x40400001; remote->work_mode = 1; remote->repeat_enable = 1; remote->release_delay = 150; remote->debug_enable = 1; remote->reg_control = 0xfbe40; remote->repeat_delay = 250; remote->repeat_peroid = 33; memcpy(key_map, default_key_map, sizeof(key_map)); memcpy(mouse_map, default_mouse_map, sizeof(mouse_map)); } else if(argv[1][0]=='-'){ printf("Usage : %s configfile\n", argv[0]); return -3; } else{ fp=fopen(argv[1], "r"); if(!fp){ printf("Open file %s is failed!!!\n", argv[1]); return -4; } ret = get_config_from_file(fp, remote); fclose(fp); } remote->factory_code >>= 16; ret = set_config(remote, device_fd); ioctl(device_fd, REMOTE_IOC_RESET_KEY_MAPPING, NULL); for(i = 0; i < 256; i++) if(key_map[i] != KEY_RESERVED){ val = (i<<16) | key_map[i]; ioctl(device_fd, REMOTE_IOC_SET_KEY_MAPPING, &val); } for(i = 0; i < 256; i++) if(repeat_key_map[i] != KEY_RESERVED){ val = (i<<16) | repeat_key_map[i]; ioctl(device_fd, REMOTE_IOC_SET_REPEAT_KEY_MAPPING, &val); } for(i = 0; i < 4; i++) if(mouse_map[i] != 0xffff){ val = (i<<16) | mouse_map[i]; ioctl(device_fd, REMOTE_IOC_SET_MOUSE_MAPPING, &val); } close(device_fd); return 0; }
int main() { DIR *dirtry = NULL; api_config config_data; curl_version_info_data *curl_info_data; curl_global_init(CURL_GLOBAL_ALL); init_idname_mylist(); FreeImage_Initialise(TRUE); FreeImage_SetOutputMessage(FreeImageErrorHandler); curl_info_data = curl_version_info(CURLVERSION_NOW); log_info("Imgur Folder2Album Uploader " VERSION_NUMBER); log_info("Using Curl %s", curl_info_data->version); log_info("Using FreeImage %s", FreeImage_GetVersion()); memset(&config_data, 0, sizeof(api_config)); if(!get_config_from_file(&config_data)) { if(CONFIG_FILE_DOESNOT_EXIST == last_error) { if(!get_imgur_pin(&config_data)) { return 1; } if(!get_access_token(&config_data)) { return 1; } if(!save_config_data(&config_data)) { return 1; } } } log_info("Welcome %s", config_data.account_username); if(!load_idname() && CANT_OPEN_FILE == last_error) { log_info("File " ALBUM_DATA_FILE " does not exist."); } while(NULL == (dirtry = opendir(config_data.images_directory))) { log_err("Could not open dir %s\n", config_data.images_directory); get_imgur_dir(&config_data); } closedir(dirtry); if(!save_config_data(&config_data)) { return 1; } file_finder(&config_data, config_data.images_directory, NULL); curl_global_cleanup(); FreeImage_DeInitialise(); if(!save_config_data(&config_data)) { return 1; } if(!save_idname()) { return 1; } // print_albuns(); kill_idname_mylist(); log_info("Bye"); return 0; }