/* * Edit a message by writing the message into a funnily-named file * (which should not exist) and forking an editor on it. * We get the editor from the stuff above. */ int edit1(int *msgvec, int type) { int c, i; FILE *fp; struct sigaction oact; sigset_t oset; struct message *mp; off_t size; /* * Deal with each message to be edited . . . */ for (i = 0; msgvec[i] && i < msgCount; i++) { if (i > 0) { char buf[100]; char *p; printf("Edit message %d [ynq]? ", msgvec[i]); if (fgets(buf, sizeof(buf), stdin) == NULL) break; for (p = buf; *p == ' ' || *p == '\t'; p++) ; if (*p == 'q') break; if (*p == 'n') continue; } dot = mp = &message[msgvec[i] - 1]; touch(mp); (void)ignoresig(SIGINT, &oact, &oset); fp = run_editor(setinput(mp), (off_t)mp->m_size, type, readonly); if (fp != NULL) { (void)fseek(otf, 0L, SEEK_END); size = ftell(otf); mp->m_block = blockof(size); mp->m_offset = offsetof(size); mp->m_size = fsize(fp); mp->m_lines = 0; mp->m_flag |= MODIFY; rewind(fp); while ((c = getc(fp)) != EOF) { if (c == '\n') mp->m_lines++; if (putc(c, otf) == EOF) break; } if (ferror(otf)) warn("%s", tmpdir); (void)Fclose(fp); } (void)sigprocmask(SIG_SETMASK, &oset, NULL); (void)sigaction(SIGINT, &oact, NULL); } return(0); }
/* * Edit a message by writing the message into a funnily-named file * (which should not exist) and forking an editor on it. * We get the editor from the stuff above. */ int edit1(int *msgvec, int type) { int c, i; FILE *fp; struct message *mp; off_t size; /* * Deal with each message to be edited . . . */ for (i = 0; msgvec[i] && i < msgCount; i++) { sig_t sigint; if (i > 0) { char buf[100]; char *p; printf("Edit message %d [ynq]? ", msgvec[i]); if (fgets(buf, sizeof(buf), stdin) == 0) break; for (p = buf; *p == ' ' || *p == '\t'; p++) ; if (*p == 'q') break; if (*p == 'n') continue; } dot = mp = &message[msgvec[i] - 1]; touch(mp); sigint = signal(SIGINT, SIG_IGN); fp = run_editor(setinput(mp), mp->m_size, type, readonly); if (fp != NULL) { fseeko(otf, (off_t)0, SEEK_END); size = ftello(otf); mp->m_block = blockof(size); mp->m_offset = boffsetof(size); mp->m_size = (long)fsize(fp); mp->m_lines = 0; mp->m_flag |= MODIFY; rewind(fp); while ((c = getc(fp)) != EOF) { if (c == '\n') mp->m_lines++; if (putc(c, otf) == EOF) break; } if (ferror(otf)) warnx("/tmp"); Fclose(fp); } signal(SIGINT, sigint); } return (0); }
/* * Edit the message being collected on fp. * On return, make the edit file the new temp file. */ void mesedit(FILE *fp, int c) { sig_t sigint = signal(SIGINT, SIG_IGN); FILE *nf = run_editor(fp, (off_t)-1, c, 0); if (nf != NULL) { (void)fseeko(nf, (off_t)0, SEEK_END); collf = nf; (void)Fclose(fp); } (void)signal(SIGINT, sigint); }
/* * Edit the message being collected on fp. * On return, make the edit file the new temp file. */ void mesedit(FILE *fp, int c) { FILE *nf; struct sigaction oact; sigset_t oset; (void)ignoresig(SIGINT, &oact, &oset); nf = run_editor(fp, (off_t)-1, c, 0); if (nf != NULL) { fseek(nf, 0L, SEEK_END); collf = nf; (void)Fclose(fp); } (void)sigprocmask(SIG_SETMASK, &oset, NULL); (void)sigaction(SIGINT, &oact, NULL); }
/* * Edit a message list. */ static int edit1(struct msg* msgvec, int type) { register struct msg* ip; register struct msg* mp; FILE* fp; off_t size; sig_t sigint; /* * Deal with each message to be edited . . . */ for (ip = msgvec; ip->m_index; ip++) { if (ip > msgvec) { char buf[100]; char* p; note(PROMPT, "Edit message %d [ynq]? ", ip->m_index); if (!fgets(buf, sizeof buf, stdin)) break; for (p = buf; isspace(*p); p++); if (*p == 'q' || *p == 'Q') break; if (*p == 'n' || *p == 'N') continue; } state.msg.dot = mp = state.msg.list + ip->m_index - 1; touchmsg(mp); sigint = signal(SIGINT, SIG_IGN); if (fp = run_editor(setinput(mp), mp->m_size, NiL, type, state.readonly)) { if (!state.msg.op) settmp(NiL, 0); fseek(state.msg.op, (off_t)0, SEEK_END); size = ftell(state.msg.op); mp->m_block = blocknumber(size); mp->m_offset = blockoffset(size); msgflags(mp, MODIFY, 0); rewind(fp); filecopy(NiL, fp, state.tmp.dir, state.msg.op, NiL, (off_t)0, &mp->m_lines, &mp->m_size, 0); fileclose(fp); } signal(SIGINT, sigint); } return 0; }
/* * Edit the message being collected on fp. * On return, make the edit file the new temp file. */ static void mesedit(int c, struct header *hp) { sighandler_type sigint = safe_signal(SIGINT, SIG_IGN); FILE *nf = run_editor(collf, (off_t)-1, c, 0, hp, NULL, SEND_MBOX, sigint); if (nf != NULL) { if (hp) { rewind(nf); makeheader(nf, hp); } else { fseek(nf, 0L, SEEK_END); Fclose(collf); collf = nf; } } safe_signal(SIGINT, sigint); }
int main(int argc, char** argv) { int c; ruleset_name = "default"; while((c = getopt(argc, argv, "r:h")) != -1) { switch(c) { case 'r': ruleset_name = std::string(optarg); break; case 'h': usage(argv[0]); exit(2); break; case '?': default: fprintf(stderr, "Unrecognized option: -%c\n", optopt); exit(2); } } if(sdl_init_all()) exit(1); try { run_editor(); } catch (boost::archive::archive_exception& e) { printf("boost::archive::archive_exception: %s (code %d).\n", e.what(), e.code); } catch (std::exception& e) { printf("std::exception: %s\n", e.what()); } catch(...) { printf("Unknown exception.\n"); } TTF_Quit(); SDL_Quit(); return 0; }
static gboolean start_session(MMConversation *mmconv) { run_editor(mmconv); return TRUE; }
void main_game_loop(void) { ALLEGRO_EVENT ev; int fps = 0; int cps = 0; int force_display_update = 0; // display always runs at least once each second int playing = 1; view.fps = 0; view.cycles_per_second = 0; int skip_frame = 0; // if game is running too slowly, it will skip frames to save drawing time. // if (game.phase == GAME_PHASE_PREGAME) // skip_frame = 1; // display is not updated during pregame phase. do // main game loop { // if (game.phase != GAME_PHASE_PREGAME) // no input in pregame phase get_ex_control(0, (game.pause_soft == 0)); // ex_control needs to be updated even when halted (control will not be updated) run_input(); run_panels(); run_editor(); /* // should probably run display at the end of the loop rather than the start // - so that the game has run through at least once when loading game if (!skip_frame || force_display_update) { run_display(); fps ++; force_display_update = 0; } */ game.total_time++; // if (game.pause_hard == 0) // { // if (view.focus_proc != NULL // && view.focus_proc->exists != 1) // will be -1 if proc has just been deallocated // { // view.focus_proc = NULL; // reset_proc_box_height(NULL); // } // need to find a better place to put this if (game.phase == GAME_PHASE_WORLD || game.phase == GAME_PHASE_OVER) // game continues to run while over. { if (!game.pause_soft) { if (game.watching != WATCH_PAUSED_TO_WATCH) { // if (run_turns()) // returns 0 if game has left world phase (e.g. because time has run out), 1 if still in world phase { if (game.watching == WATCH_FINISHED_AND_STOP_WATCHING || game.watching == WATCH_FINISHED_BUT_STILL_WATCHING || game.watching == WATCH_FINISHED_JUST_STOP_PAUSING) { w.core[bcp_state.watch_core_index].next_execution_timestamp = w.world_time; run_cores_and_procs(bcp_state.watch_core_index); w.core[bcp_state.watch_core_index].next_execution_timestamp = w.world_time + EXECUTION_COUNT; switch(game.watching) { case WATCH_FINISHED_AND_STOP_WATCHING: game.watching = WATCH_OFF; bcp_state.watch_core_index = -1; bcp_state.bcp_mode = BCP_MODE_EMPTY; break; case WATCH_FINISHED_BUT_STILL_WATCHING: game.watching = WATCH_ON; break; case WATCH_FINISHED_JUST_STOP_PAUSING: game.watching = WATCH_OFF; break; } } else { run_world(); // runs the world and also the mission, if this is a mission. Can end the game. // should run_world be after the next three function calls? Maybe. // run_clouds(); clouds don't need to be run run_fragments(); run_cores_and_procs(-1); } if (game.watching != WATCH_PAUSED_TO_WATCH) // this may have been set in either of the run_cores_and_procs() calls above { run_packets(); cps ++; w.world_time ++; w.world_seconds = (w.world_time - BASE_WORLD_TIME) / 60; update_vision_area(); // update fog of war after w.world_time is incremented so that the vision_time timestamps are up to date if (game.phase != GAME_PHASE_OVER) { if (game.type == GAME_TYPE_BASIC) run_custom_game(); else run_mission(); // for now ignore return values } play_sound_list(); } } } // end if (!game.pause_watch) else run_bcode_watch(); } // end if (!game.pause_soft) } // end game phase test if (game.phase == GAME_PHASE_OVER) { game.fast_forward = 0; if (run_game_over()) break; // user clicked game over button } if (game.phase == GAME_PHASE_PREGAME) { game.fast_forward = 0; run_pregame(); } // w.total_time ++; // total_time is affected by hard pause, but unlike world_time is not affected by soft pause (so it can only be used for things that don't affect gameplay, like console line highlighting) // run_input(); // this derives control (available to programs) from ex_control. doesn't need to be run for user to be able to use mode buttons and interact with sysmenu/editor/templates etc (as these use ex_control directly) if (game.phase == GAME_PHASE_FORCE_QUIT) break; // can be set in run_input() if user clicks on quit in system menu run_commands(); view.just_resized = 0; // fps_queue generates an event once each second - used for calculating fps and forcing a display update at least once per second if (al_get_next_event(fps_queue, &ev)) { view.fps = fps; fps = 0; view.cycles_per_second = cps; cps = 0; // if (game.phase != GAME_PHASE_PREGAME) // force_display_update = 1; // this is checked next time through this loop (see display call above) } // if (!skip_frame) { // run_panels(); // run_editor(); // may need to set playing to 0 here if player quits using sysmenu /* switch(settings.edit_window) { case EDIT_WINDOW_EDITOR: run_editor(); break; case EDIT_WINDOW_TEMPLATES: run_templates(); break; case EDIT_WINDOW_SYSMENU: playing = run_sysmenu(); break; // case EDIT_WINDOW_PROGRAMS: // run_programs_menu(); break; }*/ } if (playing == 0) break; run_consoles(); // I think it's okay to call this even when halted skip_frame = 0; // check for fast-forward (skip). Ignore FF if not in world, or if paused if (game.fast_forward > 0 && game.phase == GAME_PHASE_WORLD // let's not allow ff in GAME_PHASE_OVER && game.pause_soft == 0 && game.watching != WATCH_PAUSED_TO_WATCH) // && game.pause_hard == 0) { switch (game.fast_forward_type) { case FAST_FORWARD_TYPE_NO_DISPLAY: if (game.fast_forward == FAST_FORWARD_JUST_STARTED) game.fast_forward = FAST_FORWARD_ON; // don't skip this frame (to prevent a delay before "FAST FORWARD" message appears on screen) else { /* if (fps == 0) { fps = 1; } else*/ skip_frame = 1; // else } break; case FAST_FORWARD_TYPE_SMOOTH: game.fast_forward = FAST_FORWARD_ON; al_flush_event_queue(event_queue); break; case FAST_FORWARD_TYPE_SKIP: game.fast_forward = FAST_FORWARD_ON; if (w.world_time % 8 != 0) skip_frame = 1; break; /* case FAST_FORWARD_TYPE_8X: game.fast_forward = FAST_FORWARD_ON; if (w.world_time % 8 != 0) skip_frame = 1; break;*/ } } // now check whether the timer has expired during game processing. If it has, don't generate a display this tick (unless force_display_update==1) if (al_get_next_event(event_queue, &ev)) { // switch(ev.type) // { // case ALLEGRO_EVENT_TIMER: this should be the only possible type. skip_frame = 1; // break; // } // al_flush_event_queue(event_queue); } if (!skip_frame || force_display_update) { run_display(); fps ++; force_display_update = 0; } // wait for the timer so we can go to the next tick (unless we're fast-forwarding or the timer has already expired) if (!skip_frame && (game.fast_forward == FAST_FORWARD_OFF || game.pause_soft || game.watching == WATCH_PAUSED_TO_WATCH)) // don't skip frames if paused, even if fast-forwarding { al_wait_for_event(event_queue, &ev); // al_flush_event_queue(event_queue); } } while (TRUE); // end main game loop // if game has been finished or quit, we can end up here outside the loop }
/* TODO: does this work under cygwin? mkstemp() may or may not open the file using O_BINARY, and then we *do* upload it using O_BINARY, so maybe this will screw things up. Maybe we should fcntl it and set O_BINARY, if that is allowed under cygwin? */ void execute_edit(const char *remote) { char *real_remote; unsigned int can_lock; /* can we LOCK it? */ struct ne_lock *lock = NULL; char fname[PATH_MAX] = "/tmp/cadaver-edit-XXXXXX"; const char *pnt; int fd; int is_checkout, is_checkin; real_remote = resolve_path(session.uri.path, remote, false); /* Don't let them edit a collection, since PUT to a collection is * bogus. Really we want to be able to fetch a "DefaultDocument" * property, and edit on that instead: IIS does expose such a * property. Would be a nice hack to add the support to mod_dav * too. */ if (getrestype(real_remote) == resr_collection) { printf(_("You cannot edit a collection resource (%s).\n"), real_remote); goto edit_bail; } can_lock = is_lockable(real_remote); /* Give the local temp file the same extension as the remote path, * so the editor can have a stab at the content-type. */ pnt = strrchr(real_remote, '.'); if (pnt != NULL && strchr(pnt, '/') == NULL) { strncat(fname, pnt, PATH_MAX); fname[PATH_MAX-1] = '\0'; } fd = cad_mkstemp(fname); if (fd == -1) { printf(_("Could not create temporary file %s:\n%s\n"), fname, strerror(errno)); goto edit_bail; } /* Sanity check on the file perms. */ #ifdef HAVE_FCHMOD if (fchmod(fd, 0600) == -1) { #else if (chmod(fname, 0600) == -1) { #endif printf(_("Could not set file permissions for %s:\n%s\n"), fname, strerror(errno)); goto edit_bail; } if (can_lock) { lock = ne_lock_create(); ne_fill_server_uri(session.sess, &lock->uri); lock->uri.path = ne_strdup(real_remote); lock->owner = getowner(); out_start("Locking", remote); if (out_handle(ne_lock(session.sess, lock))) { ne_lockstore_add(session.locks, lock); } else { ne_lock_destroy(lock); goto edit_close; } } else { /* TODO: HEAD and get the Etag/modtime */ } /* Return 1: Checkin, 2: Checkout, 0: otherwise */ is_checkin = is_vcr(real_remote); if (is_checkin==1) { execute_checkout(real_remote); } output(o_download, _("Downloading `%s' to %s"), real_remote, fname); /* Don't puke if get fails -- perhaps we are creating a new one? */ out_result(ne_get(session.sess, real_remote, fd)); if (close(fd)) { output(o_finish, _("Error writing to temporary file: %s\n"), strerror(errno)); } else if (!run_editor(fname)) { int upload_okay = 0; fd = open(fname, O_RDONLY | OPEN_BINARY_FLAGS); if (fd < 0) { output(o_finish, _("Could not re-open temporary file: %s\n"), strerror(errno)); } else { do { output(o_upload, _("Uploading changes to `%s'"), real_remote); /* FIXME: conditional PUT using fetched Etag/modtime if * !can_lock */ if (out_handle(ne_put(session.sess, real_remote, fd))) { upload_okay = 1; } else { /* TODO: offer to save locally instead */ printf(_("Try uploading again (y/n)? ")); if (!yesno()) { upload_okay = 1; } } } while (!upload_okay); close(fd); } } if (unlink(fname)) { printf(_("Could not delete temporary file %s:\n%s\n"), fname, strerror(errno)); } /* Return 1: Checkin, 2: Checkout, 0: otherwise */ is_checkout = is_vcr(real_remote); if (is_checkout==2) { execute_checkin(real_remote); } /* UNLOCK it again whether we succeed or failed in our mission */ if (can_lock) { output(o_start, "Unlocking `%s':", remote); out_result(ne_unlock(session.sess, lock)); ne_lockstore_remove(session.locks, lock); ne_lock_destroy(lock); } goto edit_bail; edit_close: close(fd); edit_bail: free(real_remote); return; }
int main(int argc, char *argv[]) { create_editor(); run_editor(); free_editor(); return EXIT_SUCCESS; }