static void munge_file_in_editor(const char *filename, int lineno, int colno) { int ret; char *editor_command1, *editor_command2, *editor_command3, *editor_command4, *line_number_as_string, *column_number_as_string, **possible_editor_commands; /* find out which editor command we have to use */ possible_editor_commands = list4(getenv("RLWRAP_EDITOR"), getenv("EDITOR"), getenv("VISUAL"), "vi +%L"); editor_command1 = first_of(possible_editor_commands); line_number_as_string = as_string(lineno); column_number_as_string = as_string(colno); editor_command2 = search_and_replace("%L", line_number_as_string, editor_command1, 0, NULL, NULL); editor_command3 = search_and_replace("%C", column_number_as_string, editor_command2, 0, NULL, NULL); editor_command4 = strstr(editor_command3, "%F") ? search_and_replace("%F", filename, editor_command3, 0, NULL, NULL) : add3strings(editor_command3, " ", filename); /* call editor, temporarily restoring terminal settings */ if (terminal_settings_saved && (tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_terminal_settings) < 0)) /* reset terminal */ myerror(FATAL|USE_ERRNO, "tcsetattr error on stdin"); DPRINTF1(DEBUG_READLINE, "calling %s", editor_command4); if ((ret = system(editor_command4))) { if (WIFSIGNALED(ret)) { fprintf(stderr, "\n"); myerror(FATAL|NOERRNO, "editor killed by signal"); } else { myerror(FATAL|USE_ERRNO, "failed to invoke editor with '%s'", editor_command4); } } completely_mirror_slaves_terminal_settings(); ignore_queued_input = TRUE; free_multiple(possible_editor_commands, editor_command2, editor_command3, editor_command4, line_number_as_string, column_number_as_string, FMEND); }
int main(int argc, char* argv[]) { srand(time(NULL)); previoustime = 0; previoustime_deaths = currenttime; previoustime_creation_enemies = -10000; previoustime_bonus = -15000; time_bouclier = -5000; previoustime = currenttime; Uint8 *key = SDL_GetKeyState(NULL); /* initialize video system */ SDL_Init(SDL_INIT_VIDEO); /* set the title bar */ SDL_WM_SetCaption("SDL Move", "SDL Move"); /* create window */ screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0); /*begin*/ printf("Appuyez sur Entrée pour commencer la partie\n"); temp = SDL_LoadBMP("debut.bmp"); wall = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); while (!begin) { if (SDL_PollEvent(&event)) { HandleEvent(event); } SDL_BlitSurface(wall, NULL, screen, &imWall); SDL_UpdateRect(screen,0,0,0,0); } /* load sprite */ temp = SDL_LoadBMP("salameche.bmp"); spritetemp = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); perso = sprite_cons(0, 362, 110, 0, spritetemp, colorkey, 5, NULL, 's', 5, 22); temp = SDL_LoadBMP("heart.bmp"); heart = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); SDL_SetColorKey(heart, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); bonus_vie = sprite_cons(rand()%(LEVEL_WIDTH-16), rand()%(LEVEL_HEIGHT/2-16)+LEVEL_HEIGHT/2, 0, 0, heart, colorkey, 0, NULL,'b', 0, 16); temp = SDL_LoadBMP("abri.bmp"); abri = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); SDL_SetColorKey(heart, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); bonus_abri = sprite_cons(rand()%(LEVEL_WIDTH-40), rand()%(LEVEL_HEIGHT/2-40)+LEVEL_HEIGHT/2, 0, 0, abri, colorkey, 0, NULL,'b', 0, 40); /*temp = SDL_LoadBMP("lanceflamme.bmp"); lance_flamme = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); SDL_SetColorKey(heart, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); bonus_lf = sprite_cons(rand()%(LEVEL_WIDTH-47), rand()%(LEVEL_HEIGHT/2-8)+LEVEL_HEIGHT/2, 0, 0, lance_flamme, colorkey, 7, NULL,'b', 0, 30);*/ temp = SDL_LoadBMP("bloc.bmp"); stone1 = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); temp = SDL_LoadBMP("bloc2.bmp"); stone2 = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); temp = SDL_LoadBMP("bloc3.bmp"); stone3 = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); /* load wall */ temp = SDL_LoadBMP("fond.bmp"); wall = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); /* set wall position */ imWall.x = 0; imWall.y = 0; gameover = 0; /* message pump */ currenttime2 = SDL_GetTicks(); int nb_enemies, randnumber; while (!gameover) { currenttime = SDL_GetTicks(); if (SDL_PollEvent(&event)) { HandleEvent(event); } if (currenttime - currenttime2 > 50){ currenttime2 = currenttime; MultiEvent(key); //apparition ennemis if (currenttime - previoustime_creation_enemies > delta_creation_enemies && niveau !=3) { for (nb_enemies = 0; nb_enemies < 5; nb_enemies = nb_enemies +1) { randnumber = rand()%3; if (randnumber == 0) { temp = SDL_LoadBMP("taupi.bmp"); spritetemp = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); list_enemy = cons(sprite_cons(rand()%(LEVEL_WIDTH-22),rand()%(LEVEL_HEIGHT-22), 0, 0, spritetemp, colorkey, 0, NULL, 't', 2, 22),list_enemy); } else if (randnumber == 1) { temp = SDL_LoadBMP("cara.bmp"); spritetemp = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); list_enemy = cons(sprite_cons(rand()%(LEVEL_WIDTH-25),rand()%(LEVEL_HEIGHT-25), 0, 0, spritetemp, colorkey, -3, NULL, 'c',2, 25),list_enemy); } else { temp = SDL_LoadBMP("meta.bmp"); spritetemp = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); list_enemy = cons(sprite_cons(rand()%(LEVEL_WIDTH-20),rand()%(LEVEL_HEIGHT-20), 0, 0, spritetemp, colorkey, -5, NULL, 'm',2, 20),list_enemy); } test_apparition(first_of(list_enemy)); } previoustime_creation_enemies = currenttime; } // test arret gauche if (pasgauche && !pasdroit) { arret_gauche(perso); pasgauche = false; } // test arret droit if (pasdroit && !pasgauche) { arret_droit(perso); pasdroit = false; } // saut if (jump) { jump_perso(perso); } else { //gravitation i = (perso -> imSprite.x + perso -> posSprite.h/2)/32; j = (perso -> imSprite.y + perso -> posSprite.h +vy)/32; surbloc = tab_blocs[j][i] != 0; sursol = perso ->imSprite.y == 383 - perso -> posSprite.h ; if (!surbloc && perso->imSprite.y < 361) { vy = 7; perso->imSprite.y += vy; } j = (perso -> imSprite.y + perso -> posSprite.h + vy)/32; surbloc = tab_blocs[j][i] != 0; sursol = perso->imSprite.y >= 361; if (surbloc && !sursol) { perso->imSprite.y = j*32 - perso->posSprite.h; } if (sursol) { perso->imSprite.y = 361; } } //bonus if (currenttime - previoustime_bonus > 15000 && currenttime-time_bouclier>=5000) { placement_bonus(); } if (collision(perso, bonus_vie)) { deaths = deaths - 1; bonus_vie->imSprite.x = LEVEL_WIDTH + 1; previoustime_bonus = currenttime; } if (currenttime-time_bouclier >= 5000 && immunite){ bonus_abri->imSprite.x = LEVEL_WIDTH + 1; immunite = false; } if (collision(perso, bonus_abri)) { bonus_abri->imSprite.x = perso->imSprite.x - (45 - perso->posSprite.h)/3; bonus_abri->imSprite.y = perso->imSprite.y - (45 - perso->posSprite.h)/3; if (!immunite){ time_bouclier = currenttime; } immunite = true; } else { immunite = false; } move_enemy(list_enemy, list_fire_enemy); positionfire(list_fire); list_enemy = list_enemy_destruction (list_fire, list_enemy, &list_fire_enemy, camera); list_fire = list_fire_destruction (list_fire, camera); list_fire_enemy = list_fire_destruction (list_fire_enemy, camera); level_2(); level_3(); } if (currenttime - previoustime_deaths > 1000){ death_temp = deaths; deaths = collision_enemy(list_enemy, perso, deaths, camera); if (death_temp != deaths){ previoustime_deaths = currenttime; } } Setcamera(); SDL_BlitSurface(wall, NULL, screen, &imWall); print_tab (tab_blocs, camera); printlist (list_enemy); imCamera = Calculposition(bonus_vie ->imSprite.x, bonus_vie ->imSprite.y, camera); SDL_BlitSurface(bonus_vie -> spr, &bonus_vie -> posSprite, screen, &imCamera); imCamera = Calculposition(bonus_abri ->imSprite.x, bonus_abri ->imSprite.y, camera); SDL_BlitSurface(bonus_abri -> spr, &bonus_abri -> posSprite, screen, &imCamera); /* draw the sprite */ imCamera = Calculposition(perso ->imSprite.x, perso ->imSprite.y, camera); if (imCamera.x < 0) { imCamera.x = 0; perso -> imSprite.x = 0; } if (imCamera.x > SCREEN_WIDTH-22) { imCamera.x = SCREEN_WIDTH-22; perso -> imSprite.x = LEVEL_WIDTH-22; } SDL_BlitSurface(perso -> spr, &perso ->posSprite, screen, &imCamera); printlist(list_fire); printlist(list_fire_enemy); heart_pos.x = 0; for (i = 0; i < 5 - deaths; i = i+1) { SDL_BlitSurface(heart, NULL, screen, &heart_pos); heart_pos.x = heart_pos.x + 17; } if (niveau==3){ if (!is_empty(list_enemy)){ heart_pos.x = 624; for (i = 0; i < first_of(list_enemy)->life; i = i+1) { SDL_BlitSurface(heart, NULL, screen, &heart_pos); heart_pos.x = heart_pos.x - 17; } }else{ printf("BRAVO, VOUS AVEZ GAGNÉ !\n"); gameover = 1; } } if (deaths >= 5){ printf("DÉSOLÉ, VOUS AVEZ PERDU !\n"); gameover = 1; } /* update the screen */ SDL_UpdateRect(screen,0,0,0,0); SDL_Delay(5); } /* clean up */ SDL_FreeSurface(stone1); SDL_FreeSurface(stone2); SDL_FreeSurface(stone3); SDL_FreeSurface(heart); SDL_FreeSurface(screen); SDL_FreeSurface(wall); free (bonus_vie); SDL_FreeSurface(bonus_abri->spr); free (bonus_abri); SDL_FreeSurface(perso -> spr); free (perso); free_list(&list_fire); free_list(&list_enemy); SDL_Quit(); return 0; }
static int munge_line_in_editor(int count, int key) { int line_number = 0, column_number = 0, tmpfile_OK, ret, tmpfile_fd, bytes_read; size_t tmpfilesize; char *p, *tmpdir, *tmpfilename, *text_to_edit; char *editor_command1, *editor_command2, *editor_command3, *editor_command4, *line_number_as_string, *column_number_as_string; char *input, *rewritten_input, *rewritten_input2, **possible_tmpdirs, **possible_editor_commands; if (!multiline_separator) return 0; possible_tmpdirs = list4(getenv("TMPDIR"), getenv("TMP"), getenv("TEMP"), "/tmp"); possible_editor_commands = list4(getenv("RLWRAP_EDITOR"), getenv("EDITOR"), getenv("VISUAL"), "vi +%L"); /* create temporary filename */ #ifdef HAVE_MKSTEMP tmpdir = first_of(possible_tmpdirs); tmpfilename = add3strings(tmpdir, "/rlwrap_", "XXXXXX"); tmpfile_OK = mkstemp(tmpfilename); #else tmpfilename = mymalloc(L_tmpnam); tmpfile_OK = (int)tmpnam(tmpfilename); /* manpage says: Never use this function. Use mkstemp(3) instead */ #endif if (!tmpfile_OK) myerror("could not find unique temporary file name"); /* write current input to it, replacing the newline substitute (multiline_separator) with the real thing */ tmpfile_fd = open(tmpfilename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); if (tmpfile_fd < 0) myerror("could not create temporary file %s", tmpfilename); text_to_edit = search_and_replace(multiline_separator, "\n", rl_line_buffer, rl_point, &line_number, &column_number); write_patiently(tmpfile_fd, text_to_edit, strlen(text_to_edit), "to temporary file"); if (close(tmpfile_fd) != 0) /* improbable */ myerror("couldn't close temporary file %s", tmpfilename); /* find out which editor command we have to use */ editor_command1 = first_of(possible_editor_commands); line_number_as_string = as_string(line_number); column_number_as_string = as_string(column_number); editor_command2 = search_and_replace("%L", line_number_as_string, editor_command1, 0, NULL, NULL); editor_command3 = search_and_replace("%C", column_number_as_string, editor_command2, 0, NULL, NULL); editor_command4 = add3strings(editor_command3, " ", tmpfilename); /* call editor, temporarily restoring terminal settings */ if (terminal_settings_saved && (tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_terminal_settings) < 0)) /* reset terminal */ myerror("tcsetattr error on stdin"); DPRINTF1(DEBUG_READLINE, "calling %s", editor_command4); if ((ret = system(editor_command4))) { if (WIFSIGNALED(ret)) { fprintf(stderr, "\n"); errno = 0; myerror("editor killed by signal"); } else { myerror("failed to invoke editor with '%s'", editor_command4); } } completely_mirror_slaves_terminal_settings(); ignore_queued_input = TRUE; /* read back edited input, replacing real newline with substitute */ tmpfile_fd = open(tmpfilename, O_RDONLY); if (tmpfile_fd < 0) myerror("could not read temp file %s", tmpfilename); tmpfilesize = filesize(tmpfilename); input = mymalloc(tmpfilesize + 1); bytes_read = read(tmpfile_fd, input, tmpfilesize); if (bytes_read < 0) myerror("unreadable temp file %s", tmpfilename); input[bytes_read] = '\0'; rewritten_input = search_and_replace("\t", " ", input, 0, NULL, NULL); /* rlwrap cannot handle tabs in input lines */ rewritten_input2 = search_and_replace("\n", multiline_separator, rewritten_input, 0, NULL, NULL); for(p = rewritten_input2; *p ;p++) if(*p < ' ') *p = ' '; /* replace all control characters (like \r) by spaces */ rl_delete_text(0, strlen(rl_line_buffer)); rl_point = 0; clear_line(); cr(); my_putstr(saved_rl_state.cooked_prompt); rl_insert_text(rewritten_input2); rl_point = 0; /* leave cursor on predictable place */ rl_done = 1; /* accept line immediately */ /* wash those dishes */ if (unlink(tmpfilename)) myerror("could not delete temporary file %s", tmpfilename); free(editor_command2); free(editor_command3); free(editor_command4); free(line_number_as_string); free(column_number_as_string); free(tmpfilename); free(text_to_edit); free(input); free(rewritten_input); free(rewritten_input2); return_key = (char)'\n'; return 0; }
static gdb::unique_xmalloc_ptr<char> explicit_location_lex_one_function (const char **inp, const struct language_defn *language, explicit_completion_info *completion_info) { const char *start = *inp; if (*start == '\0') return NULL; /* If quoted, skip to the ending quote. */ if (strchr (get_gdb_linespec_parser_quote_characters (), *start)) { char quote_char = *start; /* If the input is not an Ada operator, skip to the matching closing quote and return the string. */ if (!(language->la_language == language_ada && quote_char == '\"' && is_ada_operator (start))) { if (completion_info != NULL) completion_info->quoted_arg_start = start; const char *end = find_toplevel_char (start + 1, quote_char); if (end == NULL) { if (completion_info == NULL) error (_("Unmatched quote, %s."), start); end = start + strlen (start); *inp = end; char *saved = savestring (start + 1, *inp - start - 1); return gdb::unique_xmalloc_ptr<char> (saved); } if (completion_info != NULL) completion_info->quoted_arg_end = end; *inp = end + 1; char *saved = savestring (start + 1, *inp - start - 2); return gdb::unique_xmalloc_ptr<char> (saved); } } const char *comma = find_toplevel_char (start, ','); /* If we have "-function -myfunction", or perhaps better example, "-function -[BasicClass doIt]" (objc selector), treat "-myfunction" as the function name. I.e., skip the first char if it is an hyphen. Don't skip the first char always, because we may have C++ "operator<", and find_toplevel_char needs to see the 'o' in that case. */ const char *hyphen = (*start == '-' ? find_toplevel_char (start + 1, '-') : find_toplevel_char (start, '-')); /* Check for C++ "operator," and "operator-". */ comma = skip_op_false_positives (start, comma); hyphen = skip_op_false_positives (start, hyphen); /* Pick the one that appears first. */ const char *end = first_of (hyphen, comma); /* See if a linespec keyword appears first. */ const char *s = start; const char *ws = find_toplevel_char (start, ' '); while (ws != NULL && linespec_lexer_lex_keyword (ws + 1) == NULL) { s = ws + 1; ws = find_toplevel_char (s, ' '); } if (ws != NULL) end = first_of (end, ws + 1); /* If we don't have any terminator, then take the whole string. */ if (end == NULL) end = start + strlen (start); /* Trim whitespace at the end. */ while (end > start && end[-1] == ' ') end--; *inp = end; if (*inp - start > 0) return gdb::unique_xmalloc_ptr<char> (savestring (start, *inp - start)); return NULL; }
static int munge_line_in_editor(int count, int key) { int line_number = 0, column_number = 0, ret, tmpfile_fd, bytes_read; size_t tmpfilesize; char *p, *tmpfilename, *text_to_edit; char *editor_command1, *editor_command2, *editor_command3, *editor_command4, *line_number_as_string, *column_number_as_string; char *input, *rewritten_input, *rewritten_input2, **possible_editor_commands; if (!multiline_separator) return 0; tmpfile_fd = open_unique_tempfile(multi_line_tmpfile_ext, &tmpfilename); text_to_edit = search_and_replace(multiline_separator, "\n", rl_line_buffer, rl_point, &line_number, &column_number); write_patiently(tmpfile_fd, text_to_edit, strlen(text_to_edit), "to temporary file"); if (close(tmpfile_fd) != 0) /* improbable */ myerror(FATAL|USE_ERRNO, "couldn't close temporary file %s", tmpfilename); /* find out which editor command we have to use */ possible_editor_commands = list4(getenv("RLWRAP_EDITOR"), getenv("EDITOR"), getenv("VISUAL"), "vi +%L"); editor_command1 = first_of(possible_editor_commands); line_number_as_string = as_string(line_number); column_number_as_string = as_string(column_number); editor_command2 = search_and_replace("%L", line_number_as_string, editor_command1, 0, NULL, NULL); editor_command3 = search_and_replace("%C", column_number_as_string, editor_command2, 0, NULL, NULL); editor_command4 = add3strings(editor_command3, " ", tmpfilename); /* call editor, temporarily restoring terminal settings */ if (terminal_settings_saved && (tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_terminal_settings) < 0)) /* reset terminal */ myerror(FATAL|USE_ERRNO, "tcsetattr error on stdin"); DPRINTF1(DEBUG_READLINE, "calling %s", editor_command4); if ((ret = system(editor_command4))) { if (WIFSIGNALED(ret)) { fprintf(stderr, "\n"); myerror(FATAL|NOERRNO, "editor killed by signal"); } else { myerror(FATAL|USE_ERRNO, "failed to invoke editor with '%s'", editor_command4); } } completely_mirror_slaves_terminal_settings(); ignore_queued_input = TRUE; /* read back edited input, replacing real newline with substitute */ tmpfile_fd = open(tmpfilename, O_RDONLY); if (tmpfile_fd < 0) myerror(FATAL|USE_ERRNO, "could not read temp file %s", tmpfilename); tmpfilesize = filesize(tmpfilename); input = mymalloc(tmpfilesize + 1); bytes_read = read(tmpfile_fd, input, tmpfilesize); if (bytes_read < 0) myerror(FATAL|USE_ERRNO, "unreadable temp file %s", tmpfilename); input[bytes_read] = '\0'; rewritten_input = search_and_replace("\t", " ", input, 0, NULL, NULL); /* rlwrap cannot handle tabs in input lines */ rewritten_input2 = search_and_replace("\n", multiline_separator, rewritten_input, 0, NULL, NULL); for(p = rewritten_input2; *p ;p++) if(*p >= 0 && *p < ' ') /* @@@FIXME: works for UTF8, but not UTF16 or UTF32 (Mention this in manpage?)*/ *p = ' '; /* replace all control characters (like \r) by spaces */ rl_delete_text(0, strlen(rl_line_buffer)); rl_point = 0; clear_line(); cr(); my_putstr(saved_rl_state.cooked_prompt); rl_insert_text(rewritten_input2); rl_point = 0; /* leave cursor on predictable place */ rl_done = 1; /* accept line immediately */ /* wash those dishes */ if (unlink(tmpfilename)) myerror(FATAL|USE_ERRNO, "could not delete temporary file %s", tmpfilename); free(editor_command2); free(editor_command3); free(editor_command4); free(line_number_as_string); free(column_number_as_string); free(tmpfilename); free(text_to_edit); free(input); free(rewritten_input); free(rewritten_input2); return_key = (char)'\n'; return 0; }