📄 textsw_file.c
字号:
msg2 = "An INTERNAL ERROR has occurred."; strcat(msg, msg1); strcat(msg, msg2);PostError: (void) alert_prompt( (Frame)window_get(VIEW_FROM_FOLIO_OR_VIEW(textsw), WIN_OWNER), &event, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, ALERT_MESSAGE_STRINGS, msg1, msg2, 0, 0); return(ES_UNKNOWN_ERROR);}extern unsignedtextsw_store_file(abstract, filename, locx, locy) Textsw abstract; char *filename; int locx, locy;{ register Es_status status; Textsw_view view = VIEW_ABS_TO_REP(abstract); register Textsw_folio textsw = FOLIO_FOR_VIEW(view); status = textsw_store_init(textsw, filename); switch (status) { case ES_SUCCESS: break; case ES_USE_SAVE: if (textsw->state & TXTSW_STORE_SELF_IS_SAVE) { return(textsw_save(abstract, locx, locy)); } /* Fall through */ default: status = textsw_process_store_error( textsw, filename, status, locx, locy); break; } if (status == ES_SUCCESS) { status = textsw_save_store_common(textsw, filename, (textsw->state & TXTSW_STORE_CHANGES_FILE) ? TRUE : FALSE); if (status == ES_SUCCESS) { if (textsw->state & TXTSW_STORE_CHANGES_FILE) textsw_notify(textsw->first_view, TEXTSW_ACTION_LOADED_FILE, filename, 0); } else { status = textsw_process_store_error( textsw, filename, status, locx, locy); } } return((unsigned)status);}pkg_private Es_statustextsw_store_to_selection(textsw, locx, locy) Textsw_folio textsw; int locx, locy;{ char filename[MAXNAMLEN]; if (textsw_get_selection_as_filename( textsw, filename, sizeof(filename), locx, locy)) return(ES_CANNOT_GET_NAME); return ((Es_status)textsw_store_file(VIEW_REP_TO_ABS(textsw->first_view), filename, locx, locy));}/* ARGSUSED */extern voidtextsw_reset_2(abstract, locx, locy, preserve_memory, cmd_is_undo_all_edit) Textsw abstract; int locx, locy; /* Currently ignored */ int preserve_memory; int cmd_is_undo_all_edit; /* This is for doing an "Undo All edit" */ /* in a cmdtool */{ static Es_status textsw_checkpoint_internal(); Es_handle piece_esh, old_original_esh, new_original_esh; char *name, save_name[MAXNAMLEN], scratch_name[MAXNAMLEN], *temp_name; int status; register Textsw_folio folio = FOLIO_FOR_VIEW(VIEW_ABS_TO_REP(abstract)); register int old_count = folio->again_count; int old_memory_length = 0; int wrap_around_size = (int)es_get( folio->views->esh, ES_PS_SCRATCH_MAX_LEN); if (preserve_memory) { /* Get info about original esh before possibly invalidating it. */ old_original_esh = (Es_handle)LINT_CAST(es_get( folio->views->esh, ES_PS_ORIGINAL)); if ((Es_enum)es_get(old_original_esh, ES_TYPE) == ES_TYPE_MEMORY) { old_memory_length = es_get_length(old_original_esh); } } if (textsw_has_been_modified(abstract) && (status = textsw_file_name(folio, &name)) == 0) { /* Have edited a file, so reset to the file, not memory. */ /* First take a checkpoint, so recovery is possible. */ if (folio->checkpoint_frequency > 0) { if (textsw_checkpoint_internal(folio) == ES_SUCCESS) { folio->checkpoint_number++; } } /* This is for cmdsw log file */ /* When empty document load up the original empty tmp file */ /* instead of the one we did a store in */ temp_name = cmd_is_undo_all_edit ? NULL : (char *)window_get(abstract, TEXTSW_TEMP_FILENAME); if (temp_name) (void) strcpy(save_name, temp_name); else (void) strcpy(save_name, name); status = textsw_load_file_internal(folio, save_name, scratch_name, &piece_esh, 0L, TXTSW_LFI_CLEAR_SELECTIONS); /* * It would be nice to preserve the old positioning of * the views, but all of the material in a view may * be either new or significantly rearranged. * One possiblity is to get the piece_stream to find * the nearest original stream position and use that * if we add yet another hack into ps_impl.c! */ if (status == ES_SUCCESS) goto Return; /* BUG ALERT: a few diagnostics might be appreciated. */ } if (old_memory_length > 0) { /* We are resetting from memory to memory, and the old * memory had preloaded contents that we should preserve. */ new_original_esh = es_mem_create(old_memory_length+1, ""); if (new_original_esh) { es_copy(old_original_esh, new_original_esh, FALSE); } } else { new_original_esh = es_mem_create(0, ""); } piece_esh = textsw_create_mem_ps(folio, new_original_esh); if (piece_esh != ES_NULL) { textsw_set_selection(abstract, ES_INFINITY, ES_INFINITY, EV_SEL_PRIMARY); textsw_set_selection(abstract, ES_INFINITY, ES_INFINITY, EV_SEL_SECONDARY); textsw_replace_esh(folio, piece_esh); (void) ev_set(folio->views->first_view, EV_FOR_ALL_VIEWS, EV_DISPLAY_LEVEL, EV_DISPLAY_NONE, EV_DISPLAY_START, 0, EV_DISPLAY_LEVEL, EV_DISPLAY, 0); textsw_update_scrollbars(folio, TEXTSW_VIEW_NULL); textsw_notify(folio->first_view, TEXTSW_ACTION_USING_MEMORY, 0); }Return: (void) textsw_set_insert(folio, 0L); textsw_init_again(folio, 0); textsw_init_again(folio, old_count); /* restore number of again level */ (void) es_set(folio->views->esh, ES_PS_SCRATCH_MAX_LEN, wrap_around_size, 0);}extern voidtextsw_reset(abstract, locx, locy) Textsw abstract; int locx, locy;{ textsw_reset_2(abstract, locx, locy, FALSE, FALSE);}pkg_private inttextsw_filename_is_all_blanks(filename) char *filename;{ int i = 0; while ((filename[i] == ' ') || (filename[i] == '\t')|| (filename[i] == '\n')) i++; return(filename[i] == '\0'); } /*** check filename for blanks and control chars ***/pkg_private inttextsw_filename_contains_blanks(filename)char *filename;{ int i = 0; while (filename[i] == ' ') /* skip leading blanks */ i++; while (filename[i] != '\0') { if (filename[i] < ' ' && filename[i] != '\n') return(TRUE); else if (filename[i] == ' ' || filename[i] == '\n') break; i++; } while (filename[i] == ' ') /* skip trailing blanks */ i++; if (filename[i] == '\0' || filename[i] == '\n') return(FALSE); return(TRUE); }/* Returns 0 iff a selection exists and it is matched by exactly one name. *//* ARGSUSED *//*** this function is not being referenced by anything in text directory ***/pkg_private inttextsw_expand_filename_quietly(textsw, buf, err_buf, sizeof_buf, locx, locy) Textsw_folio textsw; char *buf, *err_buf; int sizeof_buf; /* BUG ALERT! Being ignored. */ int locx, locy;{ struct namelist *nl; char *msg, *msg_extra = 0; nl = expand_name(buf); if ((buf[0] == '\0') || (nl == NONAMES)) { msg = "Unrecognized file name. Unable to match specified pattern."; msg_extra = buf; goto PostError; } if (textsw_filename_is_all_blanks(buf)) { msg = "Unrecognized file name. Filename contains only blank or tab characters."; goto PostError; } /*** check if filename contains blanks or control chars ***/ if (textsw_filename_contains_blanks(buf)) { msg = "Irregular file name. Filename contains blanks or control characters."; goto PostError; } /* * Below here we have dynamically allocated memory pointed at by nl * that we must make sure gets deallocated. */ if (nl->count == 0) { msg = "Unrecognized file name. No files match specified pattern."; msg_extra = buf; } else if (nl->count > 1) { msg = "Unrecognized file name. Too many files match specified pattern"; msg_extra = buf; goto PostError; } else (void) strcpy(buf, nl->names[0]); free_namelist(nl); if (msg_extra != 0) goto PostError; return(0);PostError: strcat(err_buf, msg);/* strcat(err_buf, msg_extra); */ return(1);}/* Returns 0 iff a selection exists and it is matched by exactly one name. */pkg_private inttextsw_expand_filename(textsw, buf, sizeof_buf, locx, locy) Textsw_folio textsw; char *buf; int sizeof_buf; /* BUG ALERT! Being ignored. */ int locx, locy;{ struct namelist *nl; char *msg_extra = 0; int result; Event event; nl = expand_name(buf); if ((buf[0] == '\0') || (nl == NONAMES)) { msg_extra = buf; result = alert_prompt( (Frame)window_get( VIEW_FROM_FOLIO_OR_VIEW(textsw), WIN_OWNER), &event, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, ALERT_MESSAGE_STRINGS, "Unrecognized file name.", "Unable to expand specified pattern:", buf, 0, 0); if (result == ALERT_FAILED) { goto PostError; } else { return (1); } } if (textsw_filename_is_all_blanks(buf)) { result = alert_prompt( (Frame)window_get(VIEW_FROM_FOLIO_OR_VIEW(textsw), WIN_OWNER), &event, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, ALERT_MESSAGE_STRINGS, "Unrecognized file name.", "File name contains only blank or tab characters.", "Please use a valid file name.", 0, 0); if (result == ALERT_FAILED) { goto PostError; } else { return (1); } } /*** check if filename contains blanks or control chars ***/ else if (textsw_filename_contains_blanks(buf)) { result = alert_prompt( (Frame)window_get(VIEW_FROM_FOLIO_OR_VIEW(textsw), WIN_OWNER), &event, ALERT_BUTTON_YES, "Confirm", ALERT_BUTTON_NO, "Cancel", ALERT_MESSAGE_STRINGS, "Irregular file name.", "File name contains blanks or control characters.", "Please confirm or cancel file name.", 0, 0); if (result == ALERT_FAILED) { goto PostError; } else { return ((result == ALERT_YES) ? ES_SUCCESS : ES_UNKNOWN_ERROR); } } /* * Below here we have dynamically allocated memory pointed at by nl * that we must make sure gets deallocated. */ if (nl->count == 0) { msg_extra = buf; result = alert_prompt( (Frame)window_get( VIEW_FROM_FOLIO_OR_VIEW(textsw), WIN_OWNER), &event, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, ALERT_MESSAGE_STRINGS, "Unrecognized file name.", "No files match specified pattern:", buf, 0, 0); if (result == ALERT_FAILED) { goto PostError; } else { return (1); } } else if (nl->count > 1) { msg_extra = buf; result = alert_prompt( (Frame)window_get(VIEW_FROM_FOLIO_OR_VIEW(textsw), WIN_OWNER), &event, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, ALERT_MESSAGE_STRINGS, "Unrecognized file name.", "Too many files match specified pattern:", buf, 0, 0); if (result == ALERT_FAILED) { goto PostError; } else { return (1); } } else (void) strcpy(buf, nl->names[0]); free_namelist(nl); if (msg_extra != 0) goto PostError; return(0);PostError: return(1);}/* Returns 0 iff there is a selection, and it is matched by exactly one name. */pkg_private inttextsw_get_selection_as_filename(textsw, buf, sizeof_buf, locx, locy) Textsw_folio textsw; char *buf; int sizeof_buf, locx, locy;{ Event event; if (!textsw_get_selection_as_string(textsw, EV_SEL_PRIMARY, buf, sizeof_buf)) { goto PostError; } return(textsw_expand_filename(textsw, buf, sizeof_buf, locx, locy));PostError: (void) alert_prompt( (Frame)window_get(VIEW_FROM_FOLIO_OR_VIEW(textsw), WIN_OWNER), &event, ALERT_MESSAGE_STRINGS, "Please select a filename and choose this menu option again.", 0, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, 0); return(1);}pkg_private inttextsw_possibly_edited_now_notify(textsw) Textsw_folio textsw;{ char *name; if (textsw_has_been_modified(VIEW_REP_TO_ABS(textsw->first_view))) { /* * WARNING: client may textsw_reset() during notification, hence * edit flag's state is only known BEFORE the notification and must be * set before the notification. */ textsw->state |= TXTSW_EDITED; if (textsw_file_name(textsw, &name) == 0) textsw_notify(textsw->first_view, TEXTSW_ACTION_EDITED_FILE, name, 0); else textsw_notify(textsw->first_view, TEXTSW_ACTION_EDITED_MEMORY, 0); }}extern inttextsw_has_been_modified(abstract) Textsw abstract;{ Textsw_folio folio = FOLIO_FOR_VIEW(VIEW_ABS_TO_REP(abstract)); if (folio->state & TXTSW_INITIALIZED) { return((int)es_get(folio->views->esh, ES_HAS_EDITS)); } return(0);}pkg_private inttextsw_file_name(textsw, name) Textsw_folio textsw; char **name;/* Returns 0 iff editing a file and name could be successfully acquired. */{ Es_handle original; original = (Es_handle)LINT_CAST( es_get(textsw->views->esh, ES_PS_ORIGINAL)); if (original == 0) return(1); if ((Es_enum)es_get(original, ES_TYPE) != ES_TYPE_FILE) return(2); if ((*name = (char *)es_get(original, ES_NAME)) == NULL) return(3); if (name[0] == '\0') return(4); return(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -