static int process_resource_list(const char *rl_uri, process_params_t *params) { char *data = NULL; int dsize = 0; int res = 0; list_t *list = NULL; /* DEBUG_LOG("processing resource list\n"); */ /* do an xcap query */ if (xcap_query(rl_uri, params->xcap_params, &data, &dsize) != 0) { ERROR_LOG("XCAP problems for uri \'%s\'\n", rl_uri ? rl_uri: "???"); if (data) cds_free(data); return RES_BAD_GATEWAY_ERR; /* -> 502 Bad GW */ } /* parse query result */ if (parse_list_xml(data, dsize, &list) != 0) { if (data) cds_free(data); return RES_BAD_GATEWAY_ERR; /* -> 502 Bad GW */ } if (data) { cds_free(data); } if (!list) return RES_INTERNAL_ERR; /* ??? */ res = process_list(list, params); if (list) { free_list(list); } return res; }
static int create_flat_list(service_t *srv, xcap_query_params_t *xcap_params, flat_list_t **dst) { process_params_t params; int res = -1; if (!srv) return RES_INTERNAL_ERR; params.xcap_params = xcap_params; params.flat = NULL; params.flat_last = NULL; params.traversed = NULL; params.traversed_last = NULL; if (srv->content_type == stc_list) { res = process_list(srv->content.list, ¶ms); } else { res = process_resource_list(srv->content.resource_list, ¶ms); } if (dst) *dst = params.flat; free_traversed_list(params.traversed); return res; }
void process_list(list l) { if ( l == 0 ) return; if ( l->elem % 2 == 0 ) { list newnode = (list)malloc(sizeof(node)); newnode->elem = l->elem; newnode->next = l->next; if ( l->next != 0 ) l->next->prev = newnode; newnode->prev = l; l->next = newnode; process_list(newnode->next); } else { process_list(l->next); } }
static int process_list(list_t *list, process_params_t *params) { list_content_t *e; int res = 0; if (!list) return RES_INTERNAL_ERR; /* DEBUG_LOG("processing list \'%s\'\n", STR_OK(list->name)); */ e = SEQUENCE_FIRST(list->content); while (e) { switch (e->type) { case lct_list: res = process_list(e->u.list, params); break; case lct_entry: res = process_entry(e->u.entry, params); break; case lct_entry_ref: res = process_entry_ref(e->u.entry_ref, params); break; case lct_external: res = process_external(e->u.external, params); break; } if (res != 0) break; e = SEQUENCE_NEXT(e); } return res; }
int main (int argc, char* argv[]) { DWORD pid; if (argc <= 1) { process_list (); } else if (argc == 2) { pid = atoi (argv[1]); if (pid == 0) { printf ("invalid: %s\n", pid); return 1; } else { printf ("process: %u\n", pid); resume_process (pid); } } else { printf ("Usage:\n" "resume : show processlist\n" "resume PID: resuming thread\n"); } return 0; }
int main(int argc, char ** argv) { list l = 0; read_list(&l); process_list(l); print_list(l); return 0; }
void cpp_from_cloog::process( clast_guard* guard ) { auto if_stmt = new if_statement; if (guard->n > 0) { expression_ptr expr = process(guard->eq + 0); for (int i = 1; i < guard->n; ++i) { auto rhs = process(guard->eq + i); expr = make_shared<bin_op_expression>(op::logic_and, expr, rhs); } if_stmt->condition = expr; } else { if_stmt->condition = literal(false); } auto body = make_shared<block_statement>(); m_ctx->push(&body->statements); process_list(guard->then); m_ctx->pop(); if_stmt->true_part = body; m_ctx->add(statement_ptr(if_stmt)); }
int br_execute(br_control_info *cinfo) { /* * Run through a list of commands and execute them */ register int i; register int repeat = cinfo->repeat; int inverse = cinfo->inverse; int cmd; if (Verbose >= 2) printf("%s: Executing %d commands; repeat = %d, inverse = %d\n", MyName, cinfo->numcmds, repeat, inverse); /* * Pete and Repeat go into a store, Pete comes out... */ for (; repeat > 0; repeat--) { for (i = 0; i < cinfo->numcmds; i++) { cmd = cinfo->cmds[i]; if ((cmd == ON) || (cmd == OFF)) { cmd = (inverse >= 0) ? cmd : (cmd == OFF) ? ON:OFF; if (process_list(cinfo->fd, cinfo->houses[i], cinfo->devs[i], cmd) < 0) { return -1; } } else if ((cmd == ALL_ON) || (cmd == ALL_OFF)) { cmd = (inverse >= 0) ? cmd : (cmd == ALL_OFF) ? ALL_ON:ALL_OFF; if (x10_br_out(cinfo->fd, cinfo->houses[i] << 4, cmd) < 0) return -1; } else if ((cmd == ALL_LAMPS_ON) || (cmd == ALL_LAMPS_OFF)) { cmd = (inverse >= 0) ? cmd : (cmd == ALL_LAMPS_OFF) ? ALL_LAMPS_ON:ALL_LAMPS_OFF; if (x10_br_out(cinfo->fd, cinfo->houses[i] << 4, cmd) < 0) return -1; } else if (cmd == DIM) { if (process_dim(cinfo->fd, cinfo->houses[i], cinfo->devs[i], (inverse >= 0) ? cinfo->dimlevels[i]:-cinfo->dimlevels[i]) < 0) { return -1; } } } if (inverse) inverse = 0 - inverse; } return 0; }
void cpp_from_cloog::process( clast_block *block ) { auto stmt = make_shared<block_statement>(); m_ctx->push(&stmt->statements); process_list(block->body); m_ctx->pop(); m_ctx->add(stmt); }
int Instruments::load_soundfont(SFInfo *sf, struct timidity_file *fd) { SFChunk chunk; sf->preset = NULL; sf->sample = NULL; sf->inst = NULL; sf->sf_name = NULL; prbags.bag = inbags.bag = NULL; prbags.gen = inbags.gen = NULL; prbags.nbags = inbags.nbags = prbags.ngens = inbags.ngens = 0; /* check RIFF file header */ READCHUNK(&chunk, fd); if (chunkid(chunk.id) != RIFF_ID) { ctl_cmsg(CMSG_ERROR, VERB_NORMAL, "%s: *** not a RIFF file", fd->filename.c_str()); return -1; } /* check file id */ READID(chunk.id, fd); if (chunkid(chunk.id) != SFBK_ID) { ctl_cmsg(CMSG_ERROR, VERB_NORMAL, "%s: *** not a SoundFont file", fd->filename.c_str()); return -1; } for (;;) { if (READCHUNK(&chunk, fd) <= 0) break; else if (chunkid(chunk.id) == LIST_ID) { if (process_list(chunk.size, sf, fd)) break; } else { ctl_cmsg(CMSG_WARNING, VERB_NORMAL, "%s: *** illegal id in level 0: %4.4s %4d", fd->filename.c_str(), chunk.id, chunk.size); FSKIP(chunk.size, fd); // Not aborting here will inevitably crash. return -1; } } /* parse layer structure */ convert_layers(sf); /* free private tables */ if (prbags.bag) free(prbags.bag); if (prbags.gen) free(prbags.gen); if (inbags.bag) free(inbags.bag); if (inbags.gen) free(inbags.gen); return 0; }
int web_process_find(const char* appname, const char* module, process_t *pid) { Result result; result.name = appname; result.module = module; result.result = -1; result.pid = pid; process_list(OnListProcess, &result); return result.result; }
int awe_load_soundfont(SFInfo *sf, FILE *fd, int is_seekable) { SFChunk chunk; seekable = is_seekable; sf->preset = NULL; sf->sample = NULL; sf->inst = NULL; sf->sf_name = NULL; prbags.bag = inbags.bag = NULL; prbags.gen = inbags.gen = NULL; /* check RIFF file header */ READCHUNK(chunk, fd); if (chunkid(chunk.id) != RIFF_ID) { fprintf(stderr, "*** not a RIFF file\n"); return -1; } /* check file id */ READID(chunk.id, fd); if (chunkid(chunk.id) != SFBK_ID) { fprintf(stderr, "*** not a SoundFont file\n"); return -1; } for (;;) { READCHUNK(chunk, fd); if (feof(fd)) break; else if (chunkid(chunk.id) == LIST_ID) { if (process_list(chunk.size, sf, fd)) break; } else { fprintf(stderr, "*** illegal id in level 0: %4.4s %4d\n", chunk.id, chunk.size); FSKIP(chunk.size, fd); } } /* parse layer structure */ convert_layers(sf); /* free private tables */ if (prbags.bag) free(prbags.bag); if (prbags.gen) free(prbags.gen); if (inbags.bag) free(inbags.bag); if (inbags.gen) free(inbags.gen); return 0; }
/* PURPOSE: Creates a data connection whenever a LIST, GET or PUT command * is entered by client. */ void create_data_connect(char command[], char ip[], char portnum[]){ int sock_data; struct sockaddr_in inf; //create a tcp socket if ((sock_data = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("\nError in socket()"); exit(1); } //construct the struct memset(&inf, 0, sizeof(inf)); /* Clear struct */ inf.sin_family = AF_INET; /* Internet/IP */ inf.sin_addr.s_addr = inet_addr(ip); /* IP address */ //here we use the port number from the control connection + 1 inf.sin_port = htons(atoi(portnum) + 1); /* server port */ //connect to the server if (connect(sock_data, (struct sockaddr *) &inf, sizeof(inf)) < 0) { perror("\nError in connect()"); exit(1); } //if we issued a PUT command if(strncmp("PUT", command, 3) == 0){ process_put(command, sock_data); } else if(strncmp("GET", command, 3) == 0){ process_get(command, sock_data); } //we issued a LIST command else if(strncmp("LIST", command, 4) == 0){ process_list(sock_data); } else{ fprintf(stderr, "\nNot a valid command.\n\n"); } }
static int process_external(external_t *external, process_params_t *params) { char *data = NULL; int dsize = 0; list_t *list = NULL; int res; /* DEBUG_LOG("processing external with anchor \'%s\'\n", STR_OK(external->anchor)); */ if (!external) return RES_OK; if (!external->anchor) return RES_OK; if (add_uri_to_traversed(params, external->anchor) != 0) { /* It is existing yet? */ ERROR_LOG("Duplicate URI in traversed set\n"); return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */ } /* XCAP query for the ref uri */ res = xcap_query(external->anchor, params->xcap_params, &data, &dsize); if (res != 0) { ERROR_LOG("XCAP problems for uri \'%s\'\n", external->anchor ? external->anchor: "???"); if (data) cds_free(data); return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */ } /* parse document as an entry element */ if (parse_list_xml(data, dsize, &list) != 0) { ERROR_LOG("Parsing problems!\n"); if (list) free_list(list); if (data) cds_free(data); return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */ } if (data) cds_free(data); if (!list) return RES_INTERNAL_ERR; /* ??? */ res = process_list(list, params); free_list(list); return res; }
static gboolean module_declaration(TreeState *state) { /* do not use modules yet */ #if 0 IDL_tree scope = IDL_tree_get_scope(state->tree); char *module_name = IDL_IDENT(IDL_MODULE(state->tree).ident).str; printf("\n\n I've go a module declared!!! \n name: %s \n\n", module_name); fprintf(FILENAME(state), "package %s;\n", module_name); state->tree = IDL_MODULE(state->tree).definition_list; type = IDL_NODE_TYPE(state->tree); printf("\n type: %d\n\n", type); return process_list(state); #endif return TRUE; }
int main(int argc, char* argv[]) { FILE* outputFile; FILE* gridFile; FILE* listFile; process_command_line(argc, argv); /* printf("%d %s %s %s\n", sort, outputFileName, gridFileName, listFileName); */ /* Make sure we can open all the files - exit if we don't. */ /* Note that exiting will close any open files, we do not have to close ** them explicitly. */ gridFile = open_file(gridFileName, "r"); listFile = open_file(listFileName, "r"); outputFile = open_file(outputFileName, "w"); read_grid(gridFile); process_list(listFile, outputFile); return 0; }
void cpp_from_cloog::process( clast_for* loop ) { isl::set domain( isl_set_from_cloog_domain(loop->domain) ); isl::printer p(domain.ctx()); cout << "Generating loop for domain: "; p.print(domain); cout << endl; auto iterator = make_shared<id_expression>(loop->iterator); auto iterator_decl = make_shared<variable_decl>(make_shared<basic_type>("int"), loop->iterator); auto iterator_decl_expr = make_shared<var_decl_expression>(iterator_decl); auto for_stmt = new for_statement; for_stmt->initialization = make_shared<bin_op_expression>(op::assign, iterator_decl_expr, process(loop->LB)); for_stmt->condition = make_shared<bin_op_expression>(op::lesser_or_equal, iterator, process(loop->UB)); for_stmt->update = make_shared<bin_op_expression>(op::assign_add, iterator, literal(loop->stride)); auto body = make_shared<block_statement>(); m_ctx->push(&body->statements); process_list(loop->body); m_ctx->pop(); for_stmt->body = body; m_ctx->add(statement_ptr(for_stmt)); }
int main(int argc, char** argv) { const int seed = 1234; srand(seed); long list_size = 1000; int max_threads = omp_get_max_threads(); int num_threads = 1; int nodes_to_print = 10; int opt; while ((opt = getopt(argc, argv, "p:s:t:")) != -1) { switch (opt) { case 'p': nodes_to_print = strtol(optarg, NULL, 10); break; case 's': list_size = strtol(optarg, NULL, 10); break; case 't': num_threads = strtol(optarg, NULL, 10); break; default: printf("usage: %s -p <nodes_to_print> -s <list_size> -t <num_threads>\n", argv[0]); } } omp_set_num_threads(num_threads); printf("// list_size = %ld, num_threads = %d, max_threads = %d\n", list_size, num_threads, max_threads); struct node* first = make_list(list_size); print_list(first, nodes_to_print); printf("// processing...\n"); process_list(first); print_list(first, nodes_to_print); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { u32 i, argi, found, offset, listsign = 0, dumpsign = 0; u8 *pid = NULL, *dumpfile = NULL, *sign_file = NULL; setbuf(stdin, NULL); setbuf(stdout, NULL); setbuf(stderr, NULL); fputs("\n" "Signsrch "VER"\n" "by Luigi Auriemma\n" "e-mail: [email protected]\n" "web: aluigi.org\n" " optimized search function from Andrew http://www.team5150.com/~andrew/\n" "\n", stderr); if(argc < 2) { help(argv[0]); } for(i = 1; i < argc; i++) { if(!stricmp(argv[i], "--help")) help(argv[0]); if(((argv[i][0] != '-') && (argv[i][0] != '/')) || (strlen(argv[i]) != 2)) break; switch(argv[i][1]) { case '-': case 'h': case '?': { help(argv[0]); } break; case 'l': { listsign = 1; } break; case 'L': { if(!argv[++i]) { printf("\nError: signature number needed\n"); exit(1); } dumpsign = atoi(argv[i]); } break; case 's': { if(!argv[++i]) { printf("\nError: signature filename needed\n"); exit(1); } sign_file = argv[i]; } break; case 'p': { pid = ""; } break; case 'P': { if(!argv[++i]) { printf("\nError: process name or pid needed\n"); exit(1); } pid = argv[i]; } break; case 'd': { if(!argv[++i]) { printf("\nError: dump file name needed\n"); exit(1); } dumpfile = argv[i]; } break; case 'e': { exe_scan = 1; } break; case 'E': { exe_scan = -1; } break; case 'b': { alt_endian = 0; } break; default: { printf("\nError: wrong argument (%s)\n", argv[i]); exit(1); } break; } } argi = i; sign = NULL; signs = 0; sign_alloclen = 0; if(pid && !pid[0]) { process_list(NULL, NULL, NULL); goto quit; } redo: if(!listsign && !dumpsign) { if(pid) { filemem = process_read(pid, &filememsz); if(!exe_scan) exe_scan = 1; } else { if(i == argc) { printf("\nError: you must specify the file to scan\n"); exit(1); } filemem = fd_read(argv[argi], &filememsz); } printf("- %u bytes allocated\n", filememsz); } if(dumpfile) { fd_write(dumpfile, filemem, filememsz); goto quit; } if(!sign) { printf("- load signatures\n"); if(!sign_file) { read_cfg(get_main_path(SIGNFILE, argv[0])); } else { read_cfg(sign_file); } printf( "- %u bytes allocated for the signatures\n" "- %u signatures in the database\n", sign_alloclen, signs); if(!dumpsign) signcrc(); } if(dumpsign > 0) { dumpsign--; if(dumpsign >= signs) { printf("\nError: wrong signature number\n"); exit(1); } printf(" %s\n", sign[dumpsign]->title); show_dump(sign[dumpsign]->data, sign[dumpsign]->size, stdout); goto quit; } if(listsign) { printf("\n" " num description [bits.endian.size]\n" "-------------------------------------\n"); for(i = 0; i < signs; i++) { printf(" %-4u %s\n", i + 1, sign[i]->title); } printf("\n"); goto quit; } if(filememsz > (10 * 1024 * 1024)) { // more than 10 megabytes printf( "- WARNING:\n" " the file loaded in memory is very big so the scanning could take many time\n"); } if(exe_scan > 0) { if(parse_exe() < 0) { printf( "- input is not an executable or is not supported by this tool\n" " the data will be handled in raw mode\n"); exe_scan = 0; } } printf( "- start signatures scanning:\n" "\n" " offset num description [bits.endian.size]\n" " --------------------------------------------\n"); for(found = i = 0; i < signs; i++) { offset = search_hashed(filemem, filememsz, sign[i]->data, sign[i]->size, sign[i]->and); if(offset != -1) { if(exe_scan > 0) offset = file2rva(offset); if(exe_scan < 0) offset += fixed_rva; printf(" %08x %-4u %s\n", offset, i + 1, sign[i]->title); found++; } } printf("\n- %u signatures found in the file\n", found); if(filemem) free(filemem); if(section) free(section); filemem = NULL; section = NULL; if(++argi < argc) { fputc('\n', stdout); goto redo; } quit: if(sign) free_sign(); return(0); }
int main(int argc, char *argv[]) { int i; char buf[512]; SDL_Surface *screen = NULL, *message = NULL; SDL_PixelFormat fmt; TTF_Font *tmp_font; SDL_Color text_color_black = {0,0,0}; SDL_Color text_color_white = {255, 255, 255}; //Mix_Music *music = NULL; //Mix_Chunk *scratch = NULL; Uint32 timer_start = 0, timer_last_frame = 0; struct game game; // initialisation if(init_game(&game)) return 1; screen = SDL_GetVideoSurface(); fmt = *(screen->format); /////////////// // main loop // /////////////// timer_start = SDL_GetTicks(); timer_last_frame = SDL_GetTicks(); while(!game.quit) { // update time game.timer_delta = ((double)(SDL_GetTicks() - (double)timer_last_frame) / 1000); timer_last_frame = SDL_GetTicks(); /////////// // Input // /////////// read_input(&game); /////////// // Logic // /////////// if(game.finished) { //game.menu = MAPBROWSER; sscanf(game.map, "%d", &i); i++; sprintf(game.map, "%d", i); game.reset = 1; game.update = 1; game.finished = 0; } // Ingame if(game.menu == INGAME) { if(!game.paused || game.reset) { if(game.pause_screen) game.pause_screen = 0; // reset game if(game.reset) { if(!load_map(&game)) { printf("Invalid map!\n"); game.menu = MAINMENU; } game.reset = 0; game.paused = 0; game.update = 1; game.moves = 0; game.keys = 0; } // loop through all objects for(i=0; i<game.num_objects; i++) { // save old position game.object[i].x_Prev = game.object[i].x; game.object[i].y_Prev = game.object[i].y; // move object move(i, &game); // configure cursor if(!strcmp(game.object[i].type, "player")) { set_cursor (&game, i); } // check if screen refresh is needed if( (int)game.object[i].x != (int)game.object[i].x_Prev || (int)game.object[i].y != (int)game.object[i].y_Prev) { game.update = 1; } } // set camera to player for(i=0; i<game.num_objects; i++) { if(!strcmp(game.object[i].type, "player")) { game.camera.x = (game.object[i].x + game.object[i].w / 2) - game.screen_width / 2; game.camera.y = (game.object[i].y + game.object[i].h / 2) - game.screen_height / 2; } } if(game.camera.x < 0) game.camera.x = 0; if(game.camera.x + game.camera.w > game.level_width) game.camera.x = game.level_width - game.camera.w; if(game.camera.y < 0) game.camera.y = 0; if(game.camera.y + game.camera.h > game.level_height) game.camera.y = game.level_height - game.camera.h; } } // Editor else if(game.menu == EDITOR) { game.num_buttonlist = 0; if(game.mouse.x_input != game.mouse.x_prev || game.mouse.y_input != game.mouse.y_prev) process_buttons(&game); game.paused = 0; if(game.reset) { if(!game.map[0])// && !game.enter_mapname) new_map(&game); else load_map(&game); // remove "player" from toolbox // if the map contains a player tile game.tool_object[PLAYER].visible = 1; for(i=0; i<game.num_objects; i++) if(!strcmp(game.object[i].type, "player")) game.tool_object[PLAYER].visible = 0; game.reset = 0; } set_map_properties(&game); scroll_map(&game); drag_objects(&game); handle_tools(&game); if(game.enter_mapname) enter_mapname(&game); if(strcmp(game.map_prev, game.map)) { if(game.save_as) SDL_FreeSurface(game.save_as); game.save_as = TTF_RenderUTF8_Blended(game.font_yo_frankie, game.map, text_color_white); strcpy(game.map_prev, game.map); game.update = 1; } } // Mainmenu else if(game.menu == MAINMENU) { game.num_buttonlist = 0; if(game.mouse.x_input != game.mouse.x_prev || game.mouse.y_input != game.mouse.y_prev) process_buttons(&game); // reset cursor for(i=1; i<5; i++) { game.mouse.clip[i].x = 0; game.mouse.clip[1].y = 0; game.mouse.clip[i].x = 0; game.mouse.clip[2].y = 0; game.mouse.clip[i].x = 0; game.mouse.clip[3].y = 0; game.mouse.clip[i].x = 0; game.mouse.clip[4].y = 0; game.mouse.point_dir = 0; } } // Mapbrowser else if(game.menu == MAPBROWSER) { process_list(&game); // reset cursor for(i=1; i<5; i++) { game.mouse.clip[i].x = 0; game.mouse.clip[1].y = 0; game.mouse.clip[i].x = 0; game.mouse.clip[2].y = 0; game.mouse.clip[i].x = 0; game.mouse.clip[3].y = 0; game.mouse.clip[i].x = 0; game.mouse.clip[4].y = 0; game.mouse.point_dir = 0; } } if(game.mouse.x_input != game.mouse.x_prev || game.mouse.y_input != game.mouse.y_prev) { game.mouse.x_prev = game.mouse.x_input; game.mouse.y_prev = game.mouse.y_input; //if(SDL_GetTicks() % 2 == 0) game.update = 1; } //////////// // Render // //////////// // don't update screen if it is not required if(game.update) { //printf("updating screen\n"); //SDL_SetAlpha(wall_surface, SDL_SRCALPHA, 0); //printf("%d | %d » %d | %d || %d\n", game.mouse.x_prev, game.mouse.y_prev, game.mouse.x, game.mouse.y, game.mouse.click); if(game.menu == INGAME) { render_game(&game); message = SDL_CreateRGBSurface(0, 300, 50, fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, fmt.Amask); SDL_SetAlpha(message, SDL_SRCALPHA, 150); SDL_FillRect(message, &message->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF)); apply_surface(0, game.screen_height - message->h, message, screen, NULL); SDL_FreeSurface(message); sprintf(buf, "Moves: %d Keys: %d", game.moves, game.keys); message = TTF_RenderUTF8_Blended(game.font_yo_frankie, buf, text_color_black); apply_surface(5, game.screen_height - message->h - 5, message, screen, NULL); SDL_FreeSurface(message); } else if(game.menu == EDITOR) { render_game(&game); /*tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 18); message = TTF_RenderUTF8_Blended(tmp_font, "By Sören Wegener", text_color_black); apply_surface(game.screen_width / 2 - message->w / 2, 150, message, screen, NULL); TTF_CloseFont(tmp_font); SDL_FreeSurface(message);*/ render_toolbox(&game); render_buttons(&game); if(game.enter_mapname) { i = 450; if(game.save_as && game.save_as->w > 430) i = game.save_as->w + 20; message = SDL_CreateRGBSurface(0, i, 70, fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, fmt.Amask); SDL_SetAlpha(message, SDL_SRCALPHA, 180); SDL_FillRect(message, &message->clip_rect, SDL_MapRGB(screen->format, 0x00, 0x00, 0x00)); apply_surface(game.screen_width / 2 - message->w / 2, game.screen_height / 2 - message->h / 2, message, screen, NULL); SDL_FreeSurface(message); message = TTF_RenderUTF8_Blended(game.font_yo_frankie, "Enter Mapname and press Enter", text_color_white); apply_surface(game.screen_width / 2 - message->w / 2, game.screen_height / 2 - message->h / 2 - 15, message, screen, NULL); if(game.save_as) apply_surface(game.screen_width / 2 - game.save_as->w / 2, game.screen_height / 2 - game.save_as->h / 2 + 15, game.save_as, screen, NULL); } } else if(game.menu == MAINMENU) { SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF)); render_buttons(&game); tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 56); message = TTF_RenderUTF8_Blended(tmp_font, "<Lustiger Spielname hier>", text_color_black); apply_surface(game.screen_width / 2 - message->w / 2, 50, message, screen, NULL); TTF_CloseFont(tmp_font); SDL_FreeSurface(message); tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 18); message = TTF_RenderUTF8_Blended(tmp_font, "By Sören Wegener", text_color_black); apply_surface(game.screen_width / 2 - message->w / 2, 150, message, screen, NULL); TTF_CloseFont(tmp_font); SDL_FreeSurface(message); tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 14); message = TTF_RenderUTF8_Blended(tmp_font, "Yo Frankie font created by Pablo Vazquez and converted by Mango Jambo using FontForge 2.0", text_color_black); apply_surface(0, game.screen_height - message->h, message, screen, NULL); TTF_CloseFont(tmp_font); SDL_FreeSurface(message); } else if(game.menu == MAPBROWSER) { SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF)); render_list(&game); } render_cursor(&game); // refresh screen SDL_Flip(screen); game.update = 0; } // needed to prevent 100% CPU usage SDL_Delay(0); } cleanup(&game); return 0; }
void cpp_from_cloog::process( clast_root *root ) { process_list(root->stmt.next); }
u8 *process_read(u8 *pname, int *fdlen) { #ifdef WIN32 HANDLE process; DWORD pid, size; int len; u8 *baddr, *buff; if(!pname && !pname[0] && !pid) return(NULL); if(pname) { len = 0; sscanf(pname, "%lu%n", &pid, &len); if(len != strlen(pname)) pid = 0; } baddr = process_list(pid ? NULL : pname, &pid, &size); if(!baddr) { printf("\nError: process name/PID not found, use -p\n"); exit(1); } fixed_rva = (u32)baddr; printf( "- pid %u\n" "- base address 0x%08x\n", (u32)pid, fixed_rva); process = OpenProcess( PROCESS_VM_READ, FALSE, pid); if(!process) winerr(); buff = malloc(size); if(!buff) std_err(); if(!ReadProcessMemory( process, (LPCVOID)baddr, buff, size, &size) ) winerr(); CloseHandle(process); #else pid_t pid; u32 rva, size, memsize, data; u8 *buff; pid = atoi(pname); rva = 0x8048000; // sorry, not completely supported at the moment fixed_rva = rva; printf( "- pid %u\n" "- try using base address 0x%08x\n", pid, fixed_rva); if(ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) std_err(); size = 0; memsize = 0; buff = NULL; for(errno = 0; ; size += 4) { if(!(size & 0xfffff)) fputc('.', stdout); data = ptrace(PTRACE_PEEKDATA, pid, (void *)rva + size, NULL); if(errno) { if(errno != EIO) std_err(); break; } if(size >= memsize) { memsize += 0x7ffff; buff = realloc(buff, memsize); if(!buff) std_err(); } memcpy(buff + size, &data, 4); } fputc('\n', stdout); buff = realloc(buff, size); if(!buff) std_err(); if(ptrace(PTRACE_DETACH, pid, NULL, NULL) < 0) std_err(); #endif *fdlen = size; return(buff); }
int CommandHandler::process(const string& cmd, ImageDBConfig& config) { if (cmd == "list") { db::DB* db = db::open_db(config.src(), db::READ); if (!db) { LOG(ERROR) << "Failed to open db: " << config.src(); return -1; } for (db::Iterator* it = db->new_iterator(); it->valid(); it->next()) { cout << it->key() << endl; } return 0; } std::istream list_stream(cin.rdbuf()); std::ifstream list_file_stream; if (!config.listfile().empty()) { list_file_stream.open(config.listfile()); if (list_file_stream.is_open()) { list_stream.rdbuf(list_file_stream.rdbuf()); } else { LOG(ERROR) << "Failed to open listfile: " << config.listfile() << endl; return -1; } } int ret_code = 0; boost::shared_ptr<CommandProcessor> processor; std::vector<boost::shared_ptr<op::Operation>> ops; if (cmd == "pipe") { if (!op::create_ops_from_config(config.opsfile(), ops)) { return -1; } processor.reset(new PipeProcessor(ops)); } else if (cmd == "save") { processor.reset(new SaveProcessor(config.dst())); } else { std::map<string, string> ops_config; ops_config["cmd"] = cmd; if (!config.dst().empty()) { ops_config["db"] = config.dst(); } boost::shared_ptr<op::Operation> op_ptr = op::get_operation(ops_config); if (op_ptr) { ops.push_back(op_ptr); } else { LOG(ERROR) << "Unsupported command: " << cmd; return -1; } if (!config.dst().empty()) { ops_config["cmd"] = "save"; ops_config["key"] = "$2"; boost::shared_ptr<op::Operation> save_op = op::get_operation(ops_config); ops.push_back(save_op); op_ptr.get()->post(save_op); } processor.reset(new PipeProcessor(ops)); } if (processor->good()) { ret_code = process_list(config, list_stream, processor); } else { ret_code = -1; } if (list_file_stream.is_open()) { list_file_stream.close(); } return ret_code; }
void DB_Worker::run_handler(void) { process_list(); }
int dns_resolver(void *log_fp) { DNODEPTR h_entries; DNODEPTR l_list = NULL; int i; int save_verbose=verbose; u_long listEntries = 0; struct sigaction sigPipeAction; struct stat dbStat; struct tms mytms; /* aligned dnsRecord to prevent Solaris from doing a dump */ /* (not found in debugger, as it can dereference it :( */ struct dnsRecord alignedRecord; struct flock tmp_flock; tmp_flock.l_whence=SEEK_SET; /* default flock fields */ tmp_flock.l_start=0; tmp_flock.l_len=0; tmp_flock.l_pid=0; time(&runtime); start_time = times(&mytms); /* get start time */ /* minimal sanity check on it */ if(stat(dns_cache, &dbStat) < 0) { if(errno != ENOENT) { dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } } else { if(!dbStat.st_size) /* bogus file, probably from a crash */ { unlink(dns_cache); /* remove it so we can recreate... */ } } /* open cache file */ if(!(dns_db = dbopen(dns_cache, O_RDWR|O_CREAT, 0664, DB_HASH, NULL))) { /* Error: Unable to open DNS cache file <filename> */ if (verbose) fprintf(stderr,"%s %s\n",msg_dns_nodb,dns_cache); dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } /* get file descriptor */ dns_fd = dns_db->fd(dns_db); tmp_flock.l_type=F_WRLCK; /* set read/write lock type */ if (fcntl(dns_fd,F_SETLK,&tmp_flock) < 0) /* and barf if we cant lock */ { /* Error: Unable to lock DNS cache file <filename> */ if (verbose) fprintf(stderr,"%s %s\n",msg_dns_nolk,dns_cache); dns_db->close(dns_db); dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } /* Setup signal handlers */ sigPipeAction.sa_handler = SIG_IGN; sigPipeAction.sa_flags = SA_RESTART; sigemptyset(&sigPipeAction.sa_mask); sigaction(SIGPIPE, &sigPipeAction, NULL); /* disable warnings/errors for this run... */ verbose=0; /* Main loop to read log records (either regular or zipped) */ while ( (gz_log)?(our_gzgets((gzFile)log_fp,buffer,BUFSIZE) != Z_NULL): (fgets(buffer,BUFSIZE,log_fname?(FILE *)log_fp:stdin) != NULL)) { if (strlen(buffer) == (BUFSIZE-1)) { /* get the rest of the record */ while ( (gz_log)?(our_gzgets((gzFile)log_fp,buffer,BUFSIZE)!=Z_NULL): (fgets(buffer,BUFSIZE,log_fname?(FILE *)log_fp:stdin)!=NULL)) { if (strlen(buffer) < BUFSIZE-1) break; } continue; /* go get next record if any */ } memset(tmp_buf, 0, sizeof(tmp_buf)); strncpy(tmp_buf, buffer, sizeof(tmp_buf)-1); /* save buffer in case of error */ if(parse_record(buffer)) /* parse the record */ { if((log_rec.addr.s_addr = inet_addr(log_rec.hostname)) != INADDR_NONE) { DBT q, r; q.data = log_rec.hostname; q.size = strlen(log_rec.hostname); switch((dns_db->get)(dns_db, &q, &r, 0)) { case -1: break; /* Error while retrieving .. just ignore */ case 1: /* No record on file, queue up for resolving */ { put_dnode(log_rec.hostname, &log_rec.addr, host_table); break; } case 0: /* We have a record for this address */ { memcpy(&alignedRecord, r.data, sizeof(struct dnsRecord)); if((runtime - alignedRecord.timeStamp ) < DNS_CACHE_TTL) { if(!alignedRecord.numeric) /* It is a name. Do nothing */ break; /* otherise, it a number.. fall through */ } else { /* queue up stale entry for retrieval */ put_dnode(log_rec.hostname, &log_rec.addr, host_table); break; } } } } } } verbose = save_verbose; /* restore verbosity level... */ listEntries = 0; /* build our linked list l_list */ for(i=0;i < MAXHASH; i++) { for(h_entries=host_table[i]; h_entries ; h_entries = h_entries->next) { h_entries->llist = l_list; l_list = h_entries; listEntries++; } } if(!l_list) { /* No valid addresses found... */ if (verbose>1) printf("%s\n",msg_dns_none); tmp_flock.l_type=F_UNLCK; fcntl(dns_fd, F_SETLK, &tmp_flock); dns_db->close(dns_db); return 0; } /* process our list now... */ process_list(l_list); /* display timing totals ? */ end_time = times(&mytms); /* display timing totals? */ if (time_me || (verbose>1)) { if (verbose<2 && time_me) printf("DNS: "); printf("%lu %s ",listEntries, msg_addresses); /* get processing time (end-start) */ temp_time = (float)(end_time-start_time)/CLK_TCK; printf("%s %.2f %s", msg_in, temp_time, msg_seconds); /* calculate records per second */ if (temp_time) i=( (int)((float)listEntries/temp_time) ); else i=0; if ( (i>0) && (i<=listEntries) ) printf(", %d/sec\n", i); else printf("\n"); } /* processing done, exit */ tmp_flock.l_type=F_UNLCK; fcntl(dns_fd, F_SETLK, &tmp_flock); dns_db->close(dns_db); return 0; }
int process_kill_all(const char* name) { const char* p = path_basename(name); return process_list(on_process, (void*)p); }
int main(int argc, const char *argv[]) { int sockfd; int acceptfd; struct sockaddr_in serveraddr, clientaddr; char buf[N] = {}; if(argc < 3) { fprintf(stderr, "Usage:%s serverip port.", argv[0]); return -1; } if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { err_log("fail to socket"); } printf("sockfd = %d\n", sockfd); serveraddr.sin_family = AF_INET; serveraddr.sin_addr.s_addr = inet_addr(argv[1]); serveraddr.sin_port = htons(atoi(argv[2])); if(bind(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0) { err_log("fail to bind"); } if(listen(sockfd, 15) < 0) { err_log("fail to listen"); } socklen_t addrlen = sizeof(struct sockaddr); while(1) { if((acceptfd = accept(sockfd, (struct sockaddr *)&clientaddr,&addrlen)) < 0) { err_log("fail to accept"); } printf("acceptfd = %d\n", acceptfd); recv(acceptfd, buf, N, 0); switch(buf[0]) { case 'L': process_list(acceptfd); break; case 'P': process_upload(acceptfd, buf+2); break; case 'G': // G filename process_download(acceptfd,buf+2); break; case 'Q': process_quit(); break; default: printf("Error cmd.\n"); } } close(acceptfd); close(sockfd); return 0; }
void game (HDC hdc) { int zoom, count; POINTL at; if (game_duration != 0) // zooming intro of the game { zoom = game_duration / 2; if (zoom == 0) zoom = 1; process_list_zoom(hdc,zoom); game_duration--; } else { process_list(hdc); if (random(2500) == 0 && !game_over && nbr_asteroids>5) // yep the mystery ship arrives { add_list(init_objekt(OT_MYSTSHIP,edge(),edge(),random(360),random(8)+4,DT_POLY,0,CLR_BROWN,mysterydata,8),enemies); nbr_asteroids++; } if (random(1000) < game_level && !game_over && nbr_asteroids > 5) // enemy1 has arrived { add_list(init_objekt(OT_ENEMY1,random(2000),edge(),0,4,DT_POLY,0,CLR_BLUE,enemy1data,5),enemies); nbr_asteroids++; } if (random(1500) == 0 && !game_over && nbr_asteroids > 5) // enemy2 has arrived { add_list(init_objekt(OT_ENEMY2,edge(),random(2000),0,4,DT_POLY,0,CLR_CYAN,enemy2data,7),enemies); nbr_asteroids++; } if (game_shieldduration > 0) game_shieldduration--; if (game_shieldduration < 0) game_shieldduration = 0; if (game_over) { input_enabled = FALSE; // game over... the end if (end_count == 150) { insert_message (1200,0, "game over"); insert_message (800,0, "score %05d",game_score); WinPostMsg(hwndClient,DM_CHECKSCORE,(MPARAM)game_score,(MPARAM)0); // check for hiscore } if (end_count == 0) { //terminate all free_all(); game_status = GAME_INTRO; game_duration = 200; WinInvalidateRect(hwndClient, NULL, TRUE); return; } end_count--; } if (nbr_asteroids == 0) // end of game { // do some end stuff if (input_enabled) { for (count = 0; count < 10; count++) { at.x = random(2000); at.y = random(2000); insert_explosion(at,10); } insert_message (1200,0, "level %02d clear", game_level); insert_message (800,0, "score %05d",game_score); } input_enabled = FALSE; if ((llist_items == 1) || (llist_items == 2 && game_shieldduration != 0)) // real end of game { delete_list(ship,&start); if (llist_items != 0) free_all(); // frees the shield ship->current.x = 1000; ship->current.y = 1000; ship->thrust_speed = 0; game_level++; init_game(); game_duration = 25; WinInvalidateRect(hwndClient, NULL, TRUE); } } } }
void Gate_Manager::run_handler(void) { process_list(); }
int dns_resolver(void *log_fp) { DNODEPTR h_entries; DNODEPTR l_list = NULL; int i; int save_verbose=verbose; u_int64_t listEntries = 0; struct sigaction sigPipeAction; struct stat dbStat; /* aligned dnsRecord to prevent Solaris from doing a dump */ /* (not found in debugger, as it can dereference it :( */ struct dnsRecord alignedRecord; struct flock tmp_flock; tmp_flock.l_whence=SEEK_SET; /* default flock fields */ tmp_flock.l_start=0; tmp_flock.l_len=0; tmp_flock.l_pid=0; time(&runtime); /* get processing start time */ start_time = time(NULL); /* minimal sanity check on it */ if(stat(dns_cache, &dbStat) < 0) { if(errno != ENOENT) { dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } } else { if(!dbStat.st_size) /* bogus file, probably from a crash */ { unlink(dns_cache); /* remove it so we can recreate... */ } } /* open cache file */ if ( (db_create(&dns_db, NULL, 0) != 0) || (dns_db->open(dns_db, NULL, dns_cache, NULL, DB_HASH, DB_CREATE, 0644) != 0) ) { /* Error: Unable to open DNS cache file <filename> */ if (verbose) fprintf(stderr,"%s %s\n",msg_dns_nodb,dns_cache); dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } /* get file descriptor */ dns_db->fd(dns_db, &dns_fd); tmp_flock.l_type=F_WRLCK; /* set read/write lock type */ if (fcntl(dns_fd,F_SETLK,&tmp_flock) < 0) /* and barf if we cant lock */ { /* Error: Unable to lock DNS cache file <filename> */ if (verbose) fprintf(stderr,"%s %s\n",msg_dns_nolk,dns_cache); dns_db->close(dns_db, 0); dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } /* Setup signal handlers */ sigPipeAction.sa_handler = SIG_IGN; sigPipeAction.sa_flags = SA_RESTART; sigemptyset(&sigPipeAction.sa_mask); sigaction(SIGPIPE, &sigPipeAction, NULL); /* disable warnings/errors for this run... */ verbose=0; /* Main loop to read log records (either regular or zipped) */ while ( ourget(buffer,BUFSIZE,our_fp) != NULL) { int len = strlen(buffer); if (len == (BUFSIZE-1)) { /* get the rest of the record */ while ( ourget(buffer,BUFSIZE,our_fp) != NULL) { len = strlen(buffer); if (len < BUFSIZE-1) break; } continue; /* go get next record if any */ } strcpy(tmp_buf, buffer); /* save buffer in case of error */ if(parse_record(buffer, len)) /* parse the record */ { struct addrinfo hints, *ares; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_NUMERICHOST; if (0 == getaddrinfo(log_rec.hostname, "0", &hints, &ares)) { DBT q, r; memset(&q, 0, sizeof(q)); memset(&r, 0, sizeof(r)); q.data = log_rec.hostname; q.size = log_rec.hnamelen; /* Check if we have it in DB */ if ( (i=dns_db->get(dns_db, NULL, &q, &r, 0)) == 0 ) { /* have a record for this address */ memcpy(&alignedRecord, r.data, sizeof(struct dnsRecord)); if (alignedRecord.timeStamp != 0) /* If it's not permanent, check if it's TTL has expired */ if ( (runtime-alignedRecord.timeStamp ) > (86400*cache_ttl) ) put_dnode(log_rec.hostname, log_rec.hnamelen, ares->ai_addr, ares->ai_addrlen, host_table); } else { if (i==DB_NOTFOUND) put_dnode(log_rec.hostname, log_rec.hnamelen, ares->ai_addr, ares->ai_addrlen, host_table); } freeaddrinfo(ares); } } } verbose = save_verbose; /* restore verbosity level... */ listEntries = 0; /* build our linked list l_list */ for(i=0;i < MAXHASH; i++) { for(h_entries=host_table[i]; h_entries ; h_entries = h_entries->next) { h_entries->llist = l_list; l_list = h_entries; listEntries++; } } if(!l_list) { /* No valid addresses found... */ if (verbose>1) printf("%s\n",msg_dns_none); tmp_flock.l_type=F_UNLCK; fcntl(dns_fd, F_SETLK, &tmp_flock); dns_db->close(dns_db, 0); return 0; } /* process our list now... */ process_list(l_list); /* get processing end time */ end_time = time(NULL); /* display DNS processing statistics */ if (time_me || (verbose>1)) { if (verbose<2 && time_me) printf("DNS: "); printf("%llu %s ",listEntries, msg_addresses); /* total processing time in seconds */ temp_time = difftime(end_time,start_time); if (temp_time==0) temp_time=1; printf("%s %.0f %s", msg_in, temp_time, msg_seconds); /* calculate records per second */ if (temp_time) i=( (int)((float)listEntries/temp_time) ); else i=0; if ( (i>0) && (i<=listEntries) ) printf(", %d/sec\n", i); else printf("\n"); } /* processing done, exit */ tmp_flock.l_type=F_UNLCK; fcntl(dns_fd, F_SETLK, &tmp_flock); dns_db->close(dns_db, 0); return 0; }