void init_SDL() { const SDL_VideoInfo* inf = NULL; int width, height, flags = 0; if(SDL_Init(SDL_INIT_EVERYTHING) != 0){ fprintf(stderr, "Failed to initialise SDL: %s", SDL_GetError()); exit_prog(1); } inf = SDL_GetVideoInfo(); if(!inf){ fprintf(stderr, "Failed to get Video Info: %s", SDL_GetError()); exit_prog(1); } width = inf->current_w; height = inf->current_h; bpp = inf->vfmt->BitsPerPixel; SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); flags = SDL_OPENGL | SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF; // screen = SDL_SetVideoMode(width >> 1, height >> 1, bpp, flags); screen = SDL_SetVideoMode(width >> 1, width >> 1, bpp, flags); if(screen == 0){ fprintf(stderr, "Failed to set Video Mode: %s", SDL_GetError()); exit_prog(1); } // glViewport(0, 0, width >> 1, height >> 1); glViewport(0, 0, width >> 1, width >> 1); glMatrixMode(GL_PROJECTION); // glOrtho(0, width >> 1, 0, height >> 1, -1, 1); glOrtho(0, width >> 1, 0, width >> 1, -1, 1); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); atexit(terminate_prog); }
int init_game(t_player *player, int argc, char **argv) { if (argc < 1 || argc > 2) return (exit_prog("USAGE: ./allum1 [matches]\n")); if (argv[1]) { if ((player->nb_matches = my_getnbr(argv[1])) == 0) return (exit_prog("Error : tu dois au moins mettre une allumette(s)\n")); if (player->nb_matches > 100) return (exit_prog("Matches must be <= 100\n")); } else player->nb_matches = 4; return (0); }
void find_TS_sync_byte(void) { // scan file looking for sync_bytes int sync_data = 0; // storage for data read from file int occurance = 0; // keep track of how many sync_bytes have been found long int current_file_pos = 0; // where are we? while ( !feof(ip_file) && occurance < 6) { current_file_pos = ftell(ip_file); sync_data = 0; fread(&sync_data, 1, 1, ip_file); switch (sync_data) { // if sync_byte is found then remember it in sync_bytes[] case 0x47 : sync_bytes[occurance] = current_file_pos; occurance++; file_seek(187); // look for next one break; default : // if byte is not equal to 0x47 occurance = 0; } } if ( occurance < 6 ) { // report error if 5 cannot be found exit_prog("Error: End of file reached before 5 sync_bytes found."); } }
void sig_intr(struct terminal *t) { if (!t) { unhandle_basic_signals(t); terminate = 1; } else { unhandle_basic_signals(t); exit_prog(t, NULL, NULL); } }
long get_ip_file_length(char *ip_filepath) { // find length of file int ip_file2 = 0; ip_file2 = _open( ip_filepath, _O_RDONLY ); if( ip_file2 == -1 ) { exit_prog("Error: cannot open input file"); } ip_file_length = _filelength(ip_file2); _close( ip_file2 ); return ip_file_length; }
int read_file(char* filename) { FILE* conf_file = fopen(filename, "r"); if (conf_file==NULL) { fprintf(stderr, "%s not found!\n", filename); return -1; } printf("%s is a valid config file\n", filename); char line[128]; dbllist_init(vertex_list); while(fgets(line, sizeof line, conf_file)!=NULL) { char* ch = (char*) &line; //parse line only if the first char is a legal value between 0-4 ! if (*ch>=48 && *ch<=52) { switch (*ch) { case 48: //0 add vertex add_vertex(ch+2); break; case 49: //1 add edge add_edge(ch+2); break; case 50: //2 remove edge remove_edge(ch+2); break; case 51: //3 calculate dijkstra calculate_dijkstra(ch+2); break; case 52: //4 exit exit_prog(); break; } } } fclose(conf_file); return 0; }
void add_found_packet(void) { // save found packets in an linked list struct found_packet *new_item_ptr = NULL; // create a new structure if there is enough memory if (( new_item_ptr = (struct found_packet* ) malloc(sizeof(struct found_packet))) == NULL) { exit_prog("FATAL ERROR : out of memory!"); } new_item_ptr->index = index; new_item_ptr->header_address = current_header_add; new_item_ptr->payload_address = current_header_add + 4; new_item_ptr->PID = TS_header.PID; new_item_ptr->continuity_counter = TS_header.continuity_counter; new_item_ptr->payload_start_indicator = TS_header.payload_start_indicator; new_item_ptr->next_ptr = NULL; if ( first_ptr == NULL ) first_ptr = new_item_ptr; else last_ptr->next_ptr = new_item_ptr; last_ptr = new_item_ptr; index ++; }
void menu_option3() { printf("Looking for payload start of PID %d...", search_PID); int payload_start_found = 0; char op_pid_table_filepath[1024]; while ( end_of_file == 0 ) { TS_header_decode(); if (TS_header.PID == search_PID) { if ( payload_start_found == 0 && TS_header.payload_start_indicator == 1) { payload_start = ftell(ip_file); printf("\nPayload start found at: %x", current_header_add); printf("\nScanning the entire file... (may take some time)"); payload_start_found = 1; } if ( payload_start_found == 1 ) { add_found_packet(); } } file_seek(184); } display_pid_table(); puts("Enter a filepath to save this table:"); scanf("%s", op_pid_table_filepath); if (( op_pid_table_file = fopen(op_pid_table_filepath, "w")) == NULL) { exit_prog("ERROR : File cannot be created"); } fputs("Table showing PID address", op_pid_table_file); fputs("\nCreated by TSdecode from ", op_pid_table_file); fputs(ip_filepath, op_pid_table_file); fputs("\n\nIndex \t Payload Add \t Header Add \t PID \t Cont \t Payload", op_pid_table_file); fputs("\n================================================================\n", op_pid_table_file); save_pid_table(); printf("This table has been saved as %s.\n", op_pid_table_filepath); }
void resize_window(SDL_Event event) { int flags = SDL_OPENGL | SDL_HWSURFACE | SDL_RESIZABLE; screen = SDL_SetVideoMode(event.resize.w, event.resize.h, bpp, flags); if(screen == NULL){ fprintf(stderr, "Error resizing window: %s", SDL_GetError()); exit_prog(1); } int new_width = screen->w; int new_height = screen->h; glViewport(0, 0, new_width, new_height); glMatrixMode(GL_PROJECTION); glOrtho(0, new_width, 0, new_height, -1, 1); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); }
void lst_del(LP **first, LP **curr) { LP *new_curr; INF *infos; infos = get_infos(); new_curr = NULL; if ((get_infos())->nb_params == 1) exit_prog(); if ((*curr)->select) infos->nb_selected--; if (!(*curr)->prev) *first = (*curr)->next; else (*curr)->prev->next = (*curr)->next; if ((*curr)->next) (*curr)->next->prev = (*curr)->prev; new_curr = choose_curr(curr); ft_memdel((void **)curr); *curr = new_curr; if (*curr) (*curr)->on = 1; }
/* Many execution paths may lead to this code so it needs to take appropriate * precausions to stuff like doc_view and doc_view->vs being NULL. */ enum frame_event_status do_action(struct session *ses, enum main_action action_id, int verbose) { enum frame_event_status status = FRAME_EVENT_OK; struct terminal *term = ses->tab->term; struct document_view *doc_view = current_frame(ses); struct link *link = NULL; if (action_id == -1) goto unknown_action; if (doc_view && doc_view->vs) { if (action_prefix_is_link_number(KEYMAP_MAIN, action_id) && !try_jump_to_link_number(ses, doc_view)) goto ignore_action; link = get_current_link(doc_view); } else if (action_requires_view_state(KEYMAP_MAIN, action_id)) { goto ignore_action; } if (action_requires_location(KEYMAP_MAIN, action_id) && !have_location(ses)) return FRAME_EVENT_OK; if (action_requires_link(KEYMAP_MAIN, action_id) && !link) goto ignore_action; if (action_requires_form(KEYMAP_MAIN, action_id) && (!link || !link_is_form(link))) goto ignore_action; if (!action_is_anonymous_safe(KEYMAP_MAIN, action_id) && get_cmd_opt_bool("anonymous")) goto ignore_action; /* Please keep in alphabetical order for now. Later we can sort by most * used or something. */ switch (action_id) { case ACT_MAIN_ABORT_CONNECTION: abort_loading(ses, 1); print_screen_status(ses); break; case ACT_MAIN_ADD_BOOKMARK: #ifdef CONFIG_BOOKMARKS launch_bm_add_doc_dialog(term, NULL, ses); #endif break; case ACT_MAIN_ADD_BOOKMARK_LINK: #ifdef CONFIG_BOOKMARKS launch_bm_add_link_dialog(term, NULL, ses); #endif break; case ACT_MAIN_ADD_BOOKMARK_TABS: #ifdef CONFIG_BOOKMARKS bookmark_terminal_tabs_dialog(term); #endif break; case ACT_MAIN_AUTH_MANAGER: auth_manager(ses); break; case ACT_MAIN_BACKSPACE_PREFIX: if (!ses->kbdprefix.repeat_count) break; set_kbd_repeat_count(ses, ses->kbdprefix.repeat_count / 10); /* Keep send_event from resetting repeat_count. */ status = FRAME_EVENT_SESSION_DESTROYED; break; case ACT_MAIN_BOOKMARK_MANAGER: #ifdef CONFIG_BOOKMARKS bookmark_manager(ses); #endif break; case ACT_MAIN_CACHE_MANAGER: cache_manager(ses); break; case ACT_MAIN_CACHE_MINIMIZE: shrink_memory(1); break; case ACT_MAIN_COOKIES_LOAD: #ifdef CONFIG_COOKIES if (!get_opt_bool("cookies.save", NULL)) break; load_cookies(); #endif break; case ACT_MAIN_COOKIE_MANAGER: #ifdef CONFIG_COOKIES cookie_manager(ses); #endif break; case ACT_MAIN_COPY_CLIPBOARD: status = copy_current_link_to_clipboard(ses, doc_view, 0); break; case ACT_MAIN_DOCUMENT_INFO: document_info_dialog(ses); break; case ACT_MAIN_DOWNLOAD_MANAGER: download_manager(ses); break; case ACT_MAIN_EXMODE: #ifdef CONFIG_EXMODE exmode_start(ses); #endif break; case ACT_MAIN_FILE_MENU: activate_bfu_technology(ses, 0); break; case ACT_MAIN_FIND_NEXT: status = find_next(ses, doc_view, 1); break; case ACT_MAIN_FIND_NEXT_BACK: status = find_next(ses, doc_view, -1); break; case ACT_MAIN_FORGET_CREDENTIALS: free_auth(); shrink_memory(1); /* flush caches */ break; case ACT_MAIN_FORMHIST_MANAGER: #ifdef CONFIG_FORMHIST formhist_manager(ses); #endif break; case ACT_MAIN_FRAME_EXTERNAL_COMMAND: status = pass_uri_to_command(ses, doc_view, PASS_URI_FRAME); break; case ACT_MAIN_FRAME_NEXT: next_frame(ses, 1); draw_formatted(ses, 0); break; case ACT_MAIN_FRAME_MAXIMIZE: status = set_frame(ses, doc_view, 0); break; case ACT_MAIN_FRAME_PREV: next_frame(ses, -1); draw_formatted(ses, 0); break; case ACT_MAIN_GOTO_URL: goto_url_action(ses, NULL); break; case ACT_MAIN_GOTO_URL_CURRENT: goto_url_action(ses, get_current_url); break; case ACT_MAIN_GOTO_URL_CURRENT_LINK: goto_url_action(ses, get_current_link_url); break; case ACT_MAIN_GOTO_URL_HOME: goto_url_home(ses); break; case ACT_MAIN_HEADER_INFO: protocol_header_dialog(ses); break; case ACT_MAIN_HISTORY_MANAGER: #ifdef CONFIG_GLOBHIST history_manager(ses); #endif break; case ACT_MAIN_HISTORY_MOVE_BACK: { int count = int_max(1, eat_kbd_repeat_count(ses)); go_history_by_n(ses, -count); break; } case ACT_MAIN_HISTORY_MOVE_FORWARD: { int count = int_max(1, eat_kbd_repeat_count(ses)); go_history_by_n(ses, count); break; } case ACT_MAIN_JUMP_TO_LINK: break; case ACT_MAIN_KEYBINDING_MANAGER: keybinding_manager(ses); break; case ACT_MAIN_KILL_BACKGROUNDED_CONNECTIONS: abort_background_connections(); break; case ACT_MAIN_LINK_DIALOG: open_link_dialog(ses); break; case ACT_MAIN_LINK_DOWNLOAD: case ACT_MAIN_LINK_DOWNLOAD_IMAGE: case ACT_MAIN_LINK_DOWNLOAD_RESUME: status = download_link(ses, doc_view, action_id); break; case ACT_MAIN_LINK_EXTERNAL_COMMAND: status = pass_uri_to_command(ses, doc_view, PASS_URI_LINK); break; case ACT_MAIN_LINK_FOLLOW: status = enter(ses, doc_view, 0); break; case ACT_MAIN_LINK_FOLLOW_RELOAD: status = enter(ses, doc_view, 1); break; case ACT_MAIN_LINK_INFO: link_info_dialog(ses); break; case ACT_MAIN_LINK_MENU: link_menu(term, NULL, ses); break; case ACT_MAIN_LINK_FORM_MENU: link_form_menu(ses); break; case ACT_MAIN_LUA_CONSOLE: #ifdef CONFIG_SCRIPTING_LUA trigger_event_name("dialog-lua-console", ses); #endif break; case ACT_MAIN_MARK_SET: #ifdef CONFIG_MARKS ses->kbdprefix.mark = KP_MARK_SET; status = FRAME_EVENT_REFRESH; #endif break; case ACT_MAIN_MARK_GOTO: #ifdef CONFIG_MARKS /* TODO: Show promptly a menu (or even listbox?) * with all the marks. But the next letter must * still choose a mark directly! --pasky */ ses->kbdprefix.mark = KP_MARK_GOTO; status = FRAME_EVENT_REFRESH; #endif break; case ACT_MAIN_MENU: activate_bfu_technology(ses, -1); break; case ACT_MAIN_MOVE_CURRENT_TOP: status = move_current_top(ses, doc_view); break; case ACT_MAIN_MOVE_CURSOR_UP: status = move_cursor_up(ses, doc_view); break; case ACT_MAIN_MOVE_CURSOR_DOWN: status = move_cursor_down(ses, doc_view); break; case ACT_MAIN_MOVE_CURSOR_LEFT: status = move_cursor_left(ses, doc_view); break; case ACT_MAIN_MOVE_CURSOR_RIGHT: status = move_cursor_right(ses, doc_view); break; case ACT_MAIN_MOVE_CURSOR_LINE_START: status = move_cursor_line_start(ses, doc_view); break; case ACT_MAIN_MOVE_HALF_PAGE_DOWN: status = move_half_page_down(ses, doc_view); break; case ACT_MAIN_MOVE_HALF_PAGE_UP: status = move_half_page_up(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_DOWN: status = move_link_down(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_DOWN_LINE: status = move_link_down_line(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_LEFT: status = move_link_left(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_LEFT_LINE: status = move_link_prev_line(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_NEXT: status = move_link_next(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_PREV: status = move_link_prev(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_RIGHT: status = move_link_right(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_RIGHT_LINE: status = move_link_next_line(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_UP: status = move_link_up(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_UP_LINE: status = move_link_up_line(ses, doc_view); break; case ACT_MAIN_MOVE_PAGE_DOWN: status = move_page_down(ses, doc_view); break; case ACT_MAIN_MOVE_PAGE_UP: status = move_page_up(ses, doc_view); break; case ACT_MAIN_MOVE_DOCUMENT_START: status = move_document_start(ses, doc_view); break; case ACT_MAIN_MOVE_DOCUMENT_END: status = move_document_end(ses, doc_view); break; case ACT_MAIN_OPEN_LINK_IN_NEW_TAB: open_current_link_in_new_tab(ses, 0); break; case ACT_MAIN_OPEN_LINK_IN_NEW_TAB_IN_BACKGROUND: open_current_link_in_new_tab(ses, 1); break; case ACT_MAIN_OPEN_LINK_IN_NEW_WINDOW: open_in_new_window(term, send_open_in_new_window, ses); break; case ACT_MAIN_OPEN_NEW_TAB: open_uri_in_new_tab(ses, NULL, 0, 1); break; case ACT_MAIN_OPEN_NEW_TAB_IN_BACKGROUND: open_uri_in_new_tab(ses, NULL, 1, 1); break; case ACT_MAIN_OPEN_NEW_WINDOW: open_in_new_window(term, send_open_new_window, ses); break; case ACT_MAIN_OPEN_OS_SHELL: exec_shell(term); break; case ACT_MAIN_OPTIONS_MANAGER: options_manager(ses); break; case ACT_MAIN_QUIT: exit_prog(ses, 1); break; case ACT_MAIN_REALLY_QUIT: exit_prog(ses, 0); break; case ACT_MAIN_REDRAW: redraw_terminal_cls(term); break; case ACT_MAIN_RELOAD: reload(ses, CACHE_MODE_INCREMENT); break; case ACT_MAIN_RERENDER: draw_formatted(ses, 2); break; case ACT_MAIN_RESET_FORM: status = reset_form(ses, doc_view, 0); break; case ACT_MAIN_RESOURCE_INFO: resource_info(term); break; case ACT_MAIN_SAVE_AS: status = save_as(ses, doc_view, 0); break; case ACT_MAIN_SAVE_FORMATTED: status = save_formatted_dlg(ses, doc_view, 0); break; case ACT_MAIN_SAVE_OPTIONS: write_config(term); break; case ACT_MAIN_SAVE_URL_AS: save_url_as(ses); break; case ACT_MAIN_SCROLL_DOWN: status = scroll_down(ses, doc_view); break; case ACT_MAIN_SCROLL_LEFT: status = scroll_left(ses, doc_view); break; case ACT_MAIN_SCROLL_RIGHT: status = scroll_right(ses, doc_view); break; case ACT_MAIN_SCROLL_UP: status = scroll_up(ses, doc_view); break; case ACT_MAIN_SEARCH: status = search_dlg(ses, doc_view, 1); break; case ACT_MAIN_SEARCH_BACK: status = search_dlg(ses, doc_view, -1); break; case ACT_MAIN_SEARCH_TYPEAHEAD: case ACT_MAIN_SEARCH_TYPEAHEAD_LINK: case ACT_MAIN_SEARCH_TYPEAHEAD_TEXT: case ACT_MAIN_SEARCH_TYPEAHEAD_TEXT_BACK: status = search_typeahead(ses, doc_view, action_id); break; case ACT_MAIN_SHOW_TERM_OPTIONS: terminal_options(term, NULL, ses); break; case ACT_MAIN_SUBMIT_FORM: status = submit_form(ses, doc_view, 0); break; case ACT_MAIN_SUBMIT_FORM_RELOAD: status = submit_form(ses, doc_view, 1); break; case ACT_MAIN_TAB_CLOSE: close_tab(term, ses); status = FRAME_EVENT_SESSION_DESTROYED; break; case ACT_MAIN_TAB_CLOSE_ALL_BUT_CURRENT: close_all_tabs_but_current(ses); break; case ACT_MAIN_TAB_EXTERNAL_COMMAND: status = pass_uri_to_command(ses, doc_view, PASS_URI_TAB); break; case ACT_MAIN_TAB_MOVE_LEFT: move_current_tab(ses, -1); break; case ACT_MAIN_TAB_MOVE_RIGHT: move_current_tab(ses, 1); break; case ACT_MAIN_TAB_MENU: assert(ses->tab == get_current_tab(term)); if (ses->status.show_tabs_bar) tab_menu(ses, ses->tab->xpos, term->height - 1 - ses->status.show_status_bar, 1); else tab_menu(ses, 0, 0, 0); break; case ACT_MAIN_TAB_NEXT: switch_current_tab(ses, 1); break; case ACT_MAIN_TAB_PREV: switch_current_tab(ses, -1); break; case ACT_MAIN_TERMINAL_RESIZE: resize_terminal_dialog(term); break; case ACT_MAIN_TOGGLE_CSS: #ifdef CONFIG_CSS toggle_document_option(ses, "document.css.enable"); #endif break; case ACT_MAIN_TOGGLE_DISPLAY_IMAGES: toggle_document_option(ses, "document.browse.images.show_as_links"); break; case ACT_MAIN_TOGGLE_DISPLAY_TABLES: toggle_document_option(ses, "document.html.display_tables"); break; case ACT_MAIN_TOGGLE_DOCUMENT_COLORS: toggle_document_option(ses, "document.colors.use_document_colors"); break; case ACT_MAIN_TOGGLE_HTML_PLAIN: toggle_plain_html(ses, ses->doc_view, 0); break; case ACT_MAIN_TOGGLE_MOUSE: #ifdef CONFIG_MOUSE toggle_mouse(); #endif break; case ACT_MAIN_TOGGLE_NUMBERED_LINKS: toggle_document_option(ses, "document.browse.links.numbering"); break; case ACT_MAIN_TOGGLE_PLAIN_COMPRESS_EMPTY_LINES: toggle_document_option(ses, "document.plain.compress_empty_lines"); break; case ACT_MAIN_TOGGLE_WRAP_TEXT: toggle_wrap_text(ses, ses->doc_view, 0); break; case ACT_MAIN_VIEW_IMAGE: status = view_image(ses, doc_view, 0); break; case ACT_MAIN_SCRIPTING_FUNCTION: case ACT_MAIN_NONE: case MAIN_ACTIONS: default: unknown_action: if (verbose) { INTERNAL("No action handling defined for '%s'.", get_action_name(KEYMAP_MAIN, action_id)); } status = FRAME_EVENT_IGNORED; } ignore_action: /* XXX: At this point the session may have been destroyed */ if (status != FRAME_EVENT_SESSION_DESTROYED && ses->insert_mode == INSERT_MODE_ON && link != get_current_link(doc_view)) ses->insert_mode = INSERT_MODE_OFF; if (status == FRAME_EVENT_REFRESH && doc_view) refresh_view(ses, doc_view, 0); return status; }
int main(int argc, char ** argv){ TAILQ_INIT(&head); int nproc, numt, i, nhost, narch; int num_tasks = 0; struct pvmhostinfo *hostp; struct stat s; FILE * codefile = fopen("./codes", "w"); if(argc != 2){ exit_prog("USAGE: ./taskgen directory\n",1); } else { stat(argv[1], &s); if(s.st_mode & S_IFDIR){ char path[PATH_MAX+1]; realpath(argv[1],path); printf("Loading graphs from %s...", path); fflush(stdout); load_graph_dir(path, &num_tasks); printf("done. Found %d tasks.\n", num_tasks); } else{ printf("%s is not a directory. Please check arguments.\n", argv[1]); exit_prog(NULL, 1); } } pvm_config(&nhost, &narch, &hostp); /*Set number of slaves to start */ nproc = nhost * 3; /*3 processes per host */ printf("Spawning %d worker tasks on %d machines...", nproc, nhost); int tids[nproc]; /*hold the task ids of the workers */ int flags = PvmTaskDefault; // flags += PvmTaskDebug; numt =pvm_spawn("worker", (char**)0, flags, "", nproc, tids); /*start up the workers */ if(numt < nproc){ /*Error Checking */ printf("\n Trouble spawing slaves. Error codes are:\n"); for(i = numt; i < nproc; i++){ printf("TID %d: %d\n", i, tids[i]); } for(i = 0; i < numt; i++){ pvm_kill(tids[i]); } exit_prog("Failure.\n",1); } printf("done. Connected.\n"); /* Main loop */ int bufid, bytes, msgtype, source; int sent_tasks, comp_tasks, found_codes = 0; int finished = 0; int percent_comp = 0; char * buf; while(!finished){ bufid = pvm_recv(-1, -1); /*Accept any message from any task BLOCKING CALL*/ pvm_bufinfo(bufid, &bytes, &msgtype, &source); switch(msgtype){ case MSGREQTASK: if(!TAILQ_EMPTY(&head)){ send_task(source); /*send out the message */ sent_tasks++; } break; case MSGCODE: buf = malloc(bytes); pvm_upkstr(buf); fprintf(codefile, "%s\n", buf); fflush(codefile); comp_tasks++; found_codes++; break; case MSGNOCODE: comp_tasks++; break; default: printf("Incorrect MSGTYPE received from task %d. Received: %d\n", source, msgtype); break; } if(((float)comp_tasks/num_tasks * 100) > percent_comp + 1){ printf("Tasks Complete: %d Tasks Sent: %d Percent Complete: %.2f\n", comp_tasks, sent_tasks, (float)comp_tasks/num_tasks * 100); percent_comp = (float)comp_tasks/num_tasks * 100; } if(comp_tasks == num_tasks){ finished = 1; } } printf("All tasks complete.\n"); exit_prog(NULL, 0); return 0; }
int main (int argc, char ** argv) { int radius, ret; int xsize, ysize, colmax, i; struct timespec stime, etime; double w[MAX_RAD]; pixel *src = (pixel*) malloc(sizeof(pixel)*MAX_PIXELS); pixel *dst = (pixel*) malloc(sizeof(pixel)*MAX_PIXELS); /* Take care of the arguments */ if (argc != 5) { fprintf(stderr, "Usage: %s num_threads radius infile outfile\n", argv[0]); exit_prog(src, dst, 1); } int num_threads = atoi(argv[1]); radius = atoi(argv[2]); if((radius > MAX_RAD) || (radius < 1)) { fprintf(stderr, "Radius (%d) must be greater than zero and less then %d\n", radius, MAX_RAD); exit_prog(src, dst, 1); } /* read file */ if(read_ppm (argv[3], &xsize, &ysize, &colmax, (char *) src) != 0){ exit_prog(src, dst, 1); } if( num_threads < 1 || num_threads > ysize){ fprintf(stderr, "Number of threads needs to be bigger than 0 and smaller than ysize of image\n"); exit_prog(src, dst, 1); } if (colmax > 255) { fprintf(stderr, "Too large maximum color-component value\n"); exit_prog(src, dst, 1); } pthread_t threads[num_threads]; blur_data *pdata[num_threads]; int l_ysize = ysize/num_threads; // Calculate gauss weights get_gauss_weights(radius, w); printf("Calling filter\n"); clock_gettime(CLOCK_REALTIME, &stime); for(i=0;i<num_threads;i++){ pdata[i] = malloc(sizeof(blur_data)); pdata[i]->xsize = xsize; pdata[i]->ysize = l_ysize; if(i == num_threads - 1){ pdata[i]->ysize += ysize - l_ysize*num_threads; } pdata[i]->src = src + i*l_ysize*xsize; pdata[i]->dst = dst + i*l_ysize*xsize; pdata[i]->radius = radius; pdata[i]->w = w; // Number of rows above the threads part of the image pdata[i]->rows_up = i*l_ysize; // Number of rows below the threads part of the image pdata[i]->rows_down = ysize - l_ysize - pdata[i]->rows_up; ret = pthread_create(&threads[i], NULL, blurfilter_x, (void*)pdata[i]); if(ret){ fprintf(stderr, "ERROR creating thread\n"); free(pdata[i]); exit_prog(src, dst, 1); } } for(i=0;i<num_threads;i++){ pthread_join(threads[i], NULL); } for(i=0;i<num_threads;i++){ ret = pthread_create(&threads[i], NULL, blurfilter_y, (void*)pdata[i]); if(ret){ fprintf(stderr, "ERROR creating thread\n"); free(pdata[i]); exit_prog(src, dst, 1); } } for(i=0;i<num_threads;i++){ pthread_join(threads[i], NULL); } clock_gettime(CLOCK_REALTIME, &etime); printf("Filtering took: %g secs\n", (etime.tv_sec - stime.tv_sec) + 1e-9*(etime.tv_nsec - stime.tv_nsec)) ; /* write result */ printf("Writing output file\n"); if(write_ppm (argv[4], xsize, ysize, (char *)src) != 0){ exit_prog(src, dst, 1); } free(src); free(dst); return 0; }
int main(int argc, char *argv[]) { puts ("MPEG-2 decoder : TSdecode.exe"); printf("Peter Daniel Version : %s \n", version); puts ("=============================\n"); if (argc == 1) { display_usage(); exit_prog(""); } while ((argc > 1) && (argv[1][0] == '-')) { switch (argv[1][1]) { case 'i': ip_filepath = &argv[1][2]; break; case 'p': search_PID = atoi(&argv[1][2]); break; case 'q': quite_mode = 1; break; default: printf("Bad option %s\n", argv[1]); display_usage(); exit_prog(""); } ++argv; --argc; } ip_file_length = get_ip_file_length(ip_filepath); printf("Opening MPEG-2 file %s, %d bytes.\n", ip_filepath, ip_file_length); printf("Search PID : %d", search_PID); ip_file = fopen(ip_filepath, "rb"); char menu_choice = 0; find_TS_sync_byte(); // synchronise to sync_bytes // display_sync_byte_table(); // display location of sync_bytes puts("\n5 occurances of Transport Stream sync_byte 0x47 found ok.\n"); fseek(ip_file, sync_bytes[1], 0); // go back to first sync_byte menu_choice = menu(); // display menu options switch (menu_choice) // decode menu choice { case '1' : // TS header decode menu_option1(); break; case '2' : // PID address table menu_option2(); break; case '3' : // Save PID address table menu_option3(); break; case '4' : // Extract PES menu_option4(); break; case '5' : // exit exit_prog(""); break; default: puts("\nERROR : Not a valid menu entry."); } exit_prog(""); return 0; }
void menu_option4() { int count = 0; int payload_add = 0; int next_packet = 0; int payload_start_found = 0; char op_pes_filepath[1024]; printf("Enter a filepath to extract the PES of PID %d to:\n", search_PID); scanf("%s", op_pes_filepath); if (( op_pes_file = fopen(op_pes_filepath, "wb")) == NULL) { exit_prog("ERROR : File cannot be created"); } printf("\nLooking for payload start of PID %d...", search_PID); while ( end_of_file == 0 ) { int data = 0; // temp space used when copying between files int loop = 0; // loop counter for copying payload (184 bytes) // decode the header TS_header_decode(); if (TS_header.PID == search_PID) { // loop until payload start is found if ( payload_start_found == 0 && TS_header.payload_start_indicator == 1) { payload_start = ftell(ip_file); printf("\nPayload start found at: x%x", current_header_add); printf("\nProcessing..."); payload_start_found = 1; // store_found_packet(); } if ( payload_start_found == 1 ) { // ie, payload start has been found add_found_packet(); // record data about TS header in array found_packets[] next_packet = last_ptr->continuity_counter; // check continuity // printf("\nCurrent packet continuity: %d \nTS header continuity: %d ",next_packet, TS_header.continuity_counter); // press_key(""); if (TS_header.continuity_counter != next_packet) { printf("\nERROR : The continuity count is not correct. \nContinuity count from stream: %d \nExpected: %d ", TS_header.continuity_counter, next_packet); press_key("\nPress a key to continue or Control C to exit"); } // copy payload to new file payload_add = ftell(ip_file); if (quite_mode == 0) printf("\nSaving payload, start address: x%x \t continuity: d%d", payload_add, TS_header.continuity_counter); // press_key("... press key"); for (loop = 0; loop < 184; loop ++) { // loop for 184 bytes of payload and copy to new file fread(&data, 1, 1, ip_file); fwrite(&data, 1, 1, op_pes_file); } // end of loop fseek(ip_file, -184, 1); // move back because next header will probably have a different PID next_packet = ++ next_packet %16; } } file_seek(184); // next header // printf("Current location: x%x", ftell(ip_file)); // printf("payload_add: x%x", payload_add); // press_key(""); } printf("\nPES stream with PID %d extracted from %s and saved as %s.",search_PID, ip_filepath, op_pes_filepath); printf("\nEnd of source file, %s.\n", ip_filepath); press_key("Press a key..."); fclose(op_pes_file); }
static void exit_print(char *buf) { if (BUFFER == RET_KEY) (get_infos())->print = 1; exit_prog(); }
void terminate_prog( void ) { exit_prog(0); }