📄 lyforms.c
字号:
#include "HTUtils.h"#include "tcp.h"#include "HTCJK.h"#include "HTTP.h"#include "HTAlert.h"#include "LYCurses.h"#include "GridText.h"#include "LYCharSets.h"#include "UCAux.h"#include "LYUtils.h"#include "LYStructs.h" /* includes HTForms.h */#include "LYStrings.h"#include "LYGlobalDefs.h"#include "LYKeymap.h"#include "LYSignal.h"#include "LYLeaks.h"#ifdef USE_COLOR_STYLE#include "AttrList.h"#include "LYHash.h"#endifextern HTCJKlang HTCJK;PRIVATE int form_getstr PARAMS(( struct link * form_link));PRIVATE int popup_options PARAMS(( int cur_selection, OptionType * list, int ly, int lx, int width, int i_length, int disabled));PUBLIC int change_form_link ARGS6( struct link *, form_link, int, mode, document *, newdoc, BOOLEAN *, refresh_screen, char *, link_name, char *, link_value){ FormInfo *form = form_link->form; int c = DO_NOTHING; int OrigNumValue; /* * If there is no form to perform action on, don't do anything. */ if (form == NULL) { return(c); } /* * Move to the link position. */ move(form_link->ly, form_link->lx); switch(form->type) { case F_CHECKBOX_TYPE: if (form->disabled == YES) break; if (form->num_value) { form_link->hightext = unchecked_box; form->num_value = 0; } else { form_link->hightext = checked_box; form->num_value = 1; } break; case F_OPTION_LIST_TYPE: if (!form->select_list) { HTAlert(BAD_HTML_NO_POPUP); c = DO_NOTHING; break; } if (form->disabled == YES) { int dummy; dummy = popup_options(form->num_value, form->select_list, form_link->ly, form_link->lx, form->size, form->size_l, form->disabled);#if defined(FANCY_CURSES) || defined(USE_SLANG) if (!enable_scrollback)#if defined(VMS) && !defined(USE_SLANG) c = DO_NOTHING;#else c = 23; /* CTRL-W refresh without clearok */#endif /* VMS && !USE_SLANG */ else#endif /* FANCY_CURSES || USE_SLANG */ c = 12; /* CTRL-L for repaint */ break; } OrigNumValue = form->num_value; form->num_value = popup_options(form->num_value, form->select_list, form_link->ly, form_link->lx, form->size, form->size_l, form->disabled); { OptionType * opt_ptr = form->select_list; int i; for (i = 0; i < form->num_value; i++, opt_ptr = opt_ptr->next) ; /* null body */ /* * Set the name. */ form->value = opt_ptr->name; /* * Set the value. */ form->cp_submit_value = opt_ptr->cp_submit_value; /* * Set charset in which we have the submit value. - kw */ form->value_cs = opt_ptr->value_cs; }#if defined(FANCY_CURSES) || defined(USE_SLANG) if (!enable_scrollback)#if defined(VMS) && !defined(USE_SLANG) if (form->num_value == OrigNumValue) c = DO_NOTHING; else#endif /* VMS && !USE_SLANG*/ c = 23; /* CTRL-W refresh without clearok */ else#endif /* FANCY_CURSES || USE_SLANG */ c = 12; /* CTRL-L for repaint */ break; case F_RADIO_TYPE: if (form->disabled == YES) break; /* * Radio buttons must have one and * only one down at a time! */ if (form->num_value) { _statusline(NEED_CHECKED_RADIO_BUTTON); sleep(MessageSecs); } else { int i; /* * Run though list of the links on the screen and * unselect any that are selected. :) */ lynx_start_radio_color (); for (i = 0; i < nlinks; i++) { if (links[i].type == WWW_FORM_LINK_TYPE && links[i].form->type == F_RADIO_TYPE && links[i].form->number == form->number && /* * If it has the same name and its on... */ !strcmp(links[i].form->name, form->name) && links[i].form->num_value) { move(links[i].ly, links[i].lx); addstr(unchecked_radio); links[i].hightext = unchecked_radio; } } lynx_stop_radio_color (); /* * Will unselect other button and select this one. */ HText_activateRadioButton(form); /* * Now highlight this one. */ form_link->hightext = checked_radio; } break; case F_TEXT_TYPE: case F_TEXTAREA_TYPE: case F_PASSWORD_TYPE: c = form_getstr(form_link); if (form->type == F_PASSWORD_TYPE) form_link->hightext = STARS(strlen(form->value)); else form_link->hightext = form->value; break; case F_RESET_TYPE: if (form->disabled == YES) break; HText_ResetForm(form); *refresh_screen = TRUE; break; case F_TEXT_SUBMIT_TYPE: c = form_getstr(form_link); if (form->disabled == YES && (c == '\r' || c == '\n')) { c = '\t'; break; } if (c == '\r' || c == '\n') { form_link->hightext = form->value; if (!form->submit_action || *form->submit_action == '\0') { _statusline(NO_FORM_ACTION); sleep(MessageSecs); c = DO_NOTHING; break; } else if (form->submit_method == URL_MAIL_METHOD && no_mail) { HTAlert(FORM_MAILTO_DISALLOWED); c = DO_NOTHING; break; } else { if (form->no_cache && form->submit_method != URL_MAIL_METHOD) { LYforce_no_cache = TRUE; reloading = TRUE; } HText_SubmitForm(form, newdoc, link_name, form->value); } if (form->submit_method == URL_MAIL_METHOD) { *refresh_screen = TRUE; } else { /* * Returns new document URL. */ newdoc->link = 0; newdoc->internal_link = FALSE; } c = DO_NOTHING; break; } else { form_link->hightext = form->value; } break; case F_SUBMIT_TYPE: case F_IMAGE_SUBMIT_TYPE: if (form->disabled == YES) break; if (form->no_cache && form->submit_method != URL_MAIL_METHOD) { LYforce_no_cache = TRUE; reloading = TRUE; } HText_SubmitForm(form, newdoc, link_name, link_value); if (form->submit_method == URL_MAIL_METHOD) *refresh_screen = TRUE; else { /* returns new document URL */ newdoc->link = 0; newdoc->internal_link = FALSE; } break; } return(c);}PRIVATE int form_getstr ARGS1( struct link *, form_link){ FormInfo *form = form_link->form; char *value = form->value; int ch; int far_col; int max_length; int startcol, startline; BOOL HaveMaxlength = FALSE; int action;#ifdef VMS extern BOOLEAN HadVMSInterrupt; /* Flag from cleanup_sig() AST */#endif EditFieldData MyEdit; BOOLEAN Edited = FALSE; /* Value might be updated? */ /* * Get the initial position of the cursor. */ LYGetYX(startline, startcol); if ((startcol + form->size) > (LYcols - 1)) far_col = (LYcols - 1); else far_col = (startcol + form->size); /* * Make sure the form field value does not exceed our buffer. - FM */ max_length = ((form->maxlength > 0 && form->maxlength < sizeof(MyEdit.buffer)) ? form->maxlength : (sizeof(MyEdit.buffer) - 1)); if (strlen(form->value) > max_length) { /* * We can't fit the entire value into the editing buffer, * so enter as much of the tail as fits. - FM */ value += (strlen(form->value) - max_length); if (!form->disabled && !(form->submit_method == URL_MAIL_METHOD && no_mail)) { /* * If we can edit it, report that we are using the tail. - FM */ _statusline(FORM_VALUE_TOO_LONG); sleep(MessageSecs); switch(form->type) { case F_PASSWORD_TYPE: statusline(FORM_LINK_PASSWORD_MESSAGE); break; case F_TEXT_SUBMIT_TYPE: if (form->submit_method == URL_MAIL_METHOD) { statusline(FORM_LINK_TEXT_SUBMIT_MAILTO_MSG); } else if (form->no_cache) { statusline(FORM_LINK_TEXT_RESUBMIT_MESSAGE); } else { statusline(FORM_LINK_TEXT_SUBMIT_MESSAGE); } break; case F_TEXT_TYPE: case F_TEXTAREA_TYPE: statusline(FORM_LINK_TEXT_MESSAGE); break; default: break; } move(startline, startcol); } } /* * Print panned line */ LYSetupEdit(&MyEdit, value, max_length, (far_col - startcol)); MyEdit.pad = '_'; MyEdit.hidden = (form->type == F_PASSWORD_TYPE); LYRefreshEdit(&MyEdit); /* * And go for it! */ for (;;) {again: ch = LYgetch();#ifdef VMS if (HadVMSInterrupt) { HadVMSInterrupt = FALSE; ch = 7; }#endif /* VMS */ /* * Filter out global navigation keys that should not be passed * to line editor, and LYK_REFRESH. */ action = EditBinding(ch); if (action == LYE_ENTER) break; if (action == LYE_LKCMD) { _statusline(ENTER_LYNX_COMMAND); ch = LYgetch();#ifdef VMS if (HadVMSInterrupt) { HadVMSInterrupt = FALSE; ch = 7; }#endif /* VMS */ break; } if (action == LYE_AIX && (HTCJK == NOCJK && LYlowest_eightbit[current_char_set] > 0x97)) break; if (action == LYE_TAB) { ch = (int)('\t'); break; } if (action == LYE_ABORT) { return(DO_NOTHING); } if (keymap[ch + 1] == LYK_REFRESH) break; switch (ch) { case DNARROW: case UPARROW: case PGUP: case PGDOWN:#ifdef NOTDEFINED case HOME: case END: case FIND_KEY: case SELECT_KEY:#endif /* NOTDEFINED */ goto breakfor; /* * Left arrrow in column 0 deserves special treatment here, * else you can get trapped in a form without submit button! */ case LTARROW: if (MyEdit.pos == 0) { int c = 'Y'; /* Go back immediately if no changes */ if (strcmp(MyEdit.buffer, value)) { _statusline(PREV_DOC_QUERY); c = LYgetch(); } if (TOUPPER(c) == 'Y') { return(ch); } else { if (form->disabled == YES) _statusline(ARROWS_OR_TAB_TO_MOVE); else _statusline(ENTER_TEXT_ARROWS_OR_TAB); } } /* fall through */ default: if (form->disabled == YES) goto again; /* * Make sure the statusline uses editmode help. */ LYLineEdit(&MyEdit, ch, TRUE); if (MyEdit.strlen >= max_length) { HaveMaxlength = TRUE; } else if (HaveMaxlength && MyEdit.strlen < max_length) { HaveMaxlength = FALSE; _statusline(ENTER_TEXT_ARROWS_OR_TAB); } if (strcmp(value, MyEdit.buffer)) { Edited = TRUE; } LYRefreshEdit(&MyEdit); } }breakfor: if (Edited) { char *p; /* * Load the new value. */ if (value == form->value) { /* * The previous value did fit in the line buffer, * so replace it with the new value. - FM */ StrAllocCopy(form->value, MyEdit.buffer); } else { /* * Combine the modified tail with the unmodified head. - FM */ form->value[(strlen(form->value) - strlen(value))] = '\0'; StrAllocCat(form->value, MyEdit.buffer); _statusline(FORM_TAIL_COMBINED_WITH_HEAD); sleep(MessageSecs); } /* * Remove trailing spaces * * Do we really need to do that here? Trailing spaces will only * be there if user keyed them in. Rather rude to throw away * their hard earned spaces. Better deal with trailing spaces * when submitting the form???? */ p = &(form->value[strlen(form->value)]); while ((p != form->value) && (p[-1] == ' ')) p--; *p = '\0'; /* * If the field has been changed, assume that it is now in * current display character set, even if for some reason * it wasn't! Hopefully a user will only submit the form * if the non-ASCII characters are displayed correctly, which * means (assuming that the display character set has been set * truthfully) the user confirms by changing the field that * the character encoding is right. - kw */ if (form->value && *form->value) form->value_cs = current_char_set; } return(ch);}/*** This function prompts for an option or page number.** If a 'g' or 'p' suffix is included, that will be** loaded into c. Otherwise, c is zeroed. - FM & LE*/PRIVATE int get_popup_option_number ARGS1( int *, c){ char temp[120]; /* * Load the c argument into the prompt buffer. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -