📄 www.c
字号:
unsigned char spaces, i; char *cptr; register struct ctk_widget *linksptr; if(starty > 0) { --starty; } else {#if WWW_CONF_RENDERSTATE /* Check if current line should be centered and if so, center it. */ if(renderstate & HTMLPARSER_RENDERSTATE_CENTER) { cptr = &webpage[(WWW_CONF_WEBPAGE_HEIGHT - 0) * WWW_CONF_WEBPAGE_WIDTH - 1]; for(spaces = 0; spaces < WWW_CONF_WEBPAGE_WIDTH; ++spaces) { if(*cptr-- != ' ') { break; } } spaces = spaces / 2; memcpy(tmpcenterline, &webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) * WWW_CONF_WEBPAGE_WIDTH], WWW_CONF_WEBPAGE_WIDTH); memcpy(&webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) * WWW_CONF_WEBPAGE_WIDTH] + spaces, tmpcenterline, WWW_CONF_WEBPAGE_WIDTH - spaces); memset(&webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) * WWW_CONF_WEBPAGE_WIDTH], ' ', spaces); linksptr = pagewidgets; for(i = 0; i < pagewidgetptr; ++i) { if(CTK_WIDGET_YPOS(linksptr) == 3 + WWW_CONF_WEBPAGE_HEIGHT - 1) { linksptr->x += spaces; linksptr->widget.hyperlink.text += spaces; } ++linksptr; } }#endif /* WWW_CONF_RENDERSTATE */ petsciiconv_topetscii(&webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) * WWW_CONF_WEBPAGE_WIDTH], WWW_CONF_WEBPAGE_WIDTH); /* redraw_window();*/ scroll(); ++scrolly;#if WWW_CONF_PAGEVIEW if(scrolly == scrollend) { run = 0; webclient_close(); }#else /* WWW_CONF_PAGEVIEW */ redraw_window();#endif /* WWW_CONF_PAGEVIEW */ }}/*-----------------------------------------------------------------------------------*//* webclient_datahandler(): * * Callback function. Called from the webclient module when HTTP data * has arrived. */voidwebclient_datahandler(char *data, u16_t len){ if(len > 0) { if(strcmp(webclient_mimetype(), http_texthtml) == 0) { count = (count + 1) & 3; show_statustext(receivingmsgs[count]); htmlparser_parse(data, len); } else { uip_abort(); ctk_dialog_open(&wgetdialog); } } else { /* Clear remaining parts of page. */ run = 0; } if(data == NULL) { run = 0; show_statustext("Done."); petsciiconv_topetscii(&webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) * WWW_CONF_WEBPAGE_WIDTH], WWW_CONF_WEBPAGE_WIDTH); redraw_window(); }}/*-----------------------------------------------------------------------------------*//* output_word(): * * Called from the rendering code when a full word has been received * and should be put on screen. */static voidoutput_word(char c){ char *webpageptr; if(nextwordptr == 0) { if(c == ISO_nl) { x = 0; inc_y(); } return; } if(x + nextwordptr > WWW_CONF_WEBPAGE_WIDTH) { inc_y(); x = 0; } nextword[nextwordptr] = 0; if(starty == 0) { webpageptr = &webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) * WWW_CONF_WEBPAGE_WIDTH + x]; if(nextwordptr > 0) { strcpy(webpageptr, nextword); } webpageptr[nextwordptr] = ' '; } if(c == ISO_nl) { x = 0; inc_y(); } else { x += nextwordptr + 1; } nextwordptr = 0; }/*-----------------------------------------------------------------------------------*/static void *add_pagewidget(char *text, unsigned char type, unsigned char border){ register struct ctk_widget *lptr; register unsigned char *webpageptr; static unsigned char len, maxwidth; static void *dataptr; len = strlen(text); if(len + border == 0) { return NULL; } maxwidth = WWW_CONF_WEBPAGE_WIDTH - (1 + 2 * border); /* If the text of the link is too long so that it does not fit into the width of the current window, counting from the current x coordinate, we first try to jump to the next line. */ if(len + x > maxwidth) { output_word(ISO_nl); } /* If the text of the link still is too long, we just chop it off! XXX: this is not really the right thing to do, we should probably either make the link a multiline button, or add multiple buttons. But this will do for now. */ if(len > maxwidth) { text[maxwidth] = 0; len = maxwidth; } dataptr = NULL; if(starty == 0) { webpageptr = &webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) * WWW_CONF_WEBPAGE_WIDTH + x]; /* To save memory, we'll copy the widget text to the web page drawing area and reference it from there. */ webpageptr[0] = 0; webpageptr += border; strncpy(webpageptr, text, len); webpageptr[len] = 0; webpageptr[len + border] = ' '; if(pagewidgetptr < WWW_CONF_MAX_NUMPAGEWIDGETS) { dataptr = &pagewidgetattribs[pagewidgetptr]; lptr = &pagewidgets[pagewidgetptr]; switch(type) { case CTK_WIDGET_HYPERLINK: CTK_HYPERLINK_NEW((struct ctk_hyperlink *)lptr, x, WWW_CONF_WEBPAGE_HEIGHT + 2, len, webpageptr, dataptr); break; case CTK_WIDGET_BUTTON: CTK_BUTTON_NEW((struct ctk_button *)lptr, x, WWW_CONF_WEBPAGE_HEIGHT + 2, len, webpageptr); ((struct formattribs *)dataptr)->inputvalue = webpageptr; break; case CTK_WIDGET_TEXTENTRY: CTK_TEXTENTRY_NEW((struct ctk_textentry *)lptr, x, WWW_CONF_WEBPAGE_HEIGHT + 2, len, 1, webpageptr, len); ((struct formattribs *)dataptr)->inputvalue = webpageptr; break; } CTK_WIDGET_ADD(&mainwindow, lptr); ++pagewidgetptr; } } /* Increase the x coordinate with the length of the link text plus the extra space behind it and the CTK button markers. */ x += len + 1 + 2 * border; if(x >= WWW_CONF_WEBPAGE_WIDTH) { inc_y(); x = 0; } return dataptr;}/*-----------------------------------------------------------------------------------*//* htmlparser_link: * * Callback function. Will be called when the HTML parser has parsed a * link. We will put a CTK hyperlink widget at the appropriate position * in the window. */voidhtmlparser_link(char *text, char *url){ static unsigned char *linkurlptr; linkurlptr = add_pagewidget(text, CTK_WIDGET_HYPERLINK, 0); if(linkurlptr != NULL && strlen(url) < WWW_CONF_MAX_URLLEN) { strcpy(linkurlptr, url); }}/*-----------------------------------------------------------------------------------*//* htmlparser_char(): * * Callback function. Called by the HTML parser module for every * printable character in the HTML file. */voidhtmlparser_char(char c){ if(c == ' ' || c == ISO_nl) { output_word(c); } else if(c != 0 && (c & 0x80) == 0) { nextword[nextwordptr] = c; if(nextwordptr < WWW_CONF_WEBPAGE_WIDTH) { ++nextwordptr; } }}/*-----------------------------------------------------------------------------------*/#if WWW_CONF_RENDERSTATEvoidhtmlparser_renderstate(unsigned char s){ if((s & HTMLPARSER_RENDERSTATE_STATUSMASK) == HTMLPARSER_RENDERSTATE_BEGIN) { renderstate |= s & ~HTMLPARSER_RENDERSTATE_STATUSMASK; } else { renderstate &= ~(s & ~HTMLPARSER_RENDERSTATE_STATUSMASK); }}#endif /* WWW_CONF_RENDERSTATE */#if WWW_CONF_FORMS/*-----------------------------------------------------------------------------------*/voidhtmlparser_submitbutton(char *text, char *name, char *formname, char *formaction){ register struct formattribs *form; form = add_pagewidget(text, CTK_WIDGET_BUTTON, 1); if(form != NULL) { strncpy(form->formaction, formaction, WWW_CONF_MAX_FORMACTIONLEN); strncpy(form->formname, formname, WWW_CONF_MAX_FORMNAMELEN); strncpy(form->inputname, name, WWW_CONF_MAX_INPUTNAMELEN); form->inputtype = FORMINPUTTYPE_SUBMITBUTTON; }}/*-----------------------------------------------------------------------------------*/voidhtmlparser_inputfield(char *text, char *name, char *formname, char *formaction){ register struct formattribs *form; form = add_pagewidget(text, CTK_WIDGET_TEXTENTRY, 1); if(form != NULL) { strncpy(form->formaction, formaction, WWW_CONF_MAX_FORMACTIONLEN); strncpy(form->formname, formname, WWW_CONF_MAX_FORMNAMELEN); strncpy(form->inputname, name, WWW_CONF_MAX_INPUTNAMELEN); form->inputtype = FORMINPUTTYPE_INPUTFIELD; }}/*-----------------------------------------------------------------------------------*/static voidformsubmit(struct formattribs *attribs){ unsigned char i, j; register char *urlptr, *valueptr; register struct formattribs *faptr; urlptr = &tmpurl[0]; strncpy(urlptr, attribs->formaction, WWW_CONF_MAX_URLLEN); tmpurl[WWW_CONF_MAX_URLLEN] = 0; urlptr += strlen(urlptr); *urlptr = ISO_questionmark; ++urlptr; /* Construct an URL by finding all input field forms with the same formname as the current submit button, and add the submit button URL stuff as well. */ for(i = 0; i < pagewidgetptr; ++i) { if(urlptr - &tmpurl[0] >= WWW_CONF_MAX_URLLEN) { break; } faptr = &pagewidgetattribs[i].form; if(strcmp(attribs->formaction, faptr->formaction) == 0 && strcmp(attribs->formname, faptr->formname) == 0 && (faptr->inputtype == FORMINPUTTYPE_INPUTFIELD || faptr == attribs)) { /* Copy the name of the input field into the URL and append a questionmark. */ strncpy(urlptr, faptr->inputname, WWW_CONF_MAX_URLLEN - strlen(tmpurl)); tmpurl[WWW_CONF_MAX_URLLEN] = 0; urlptr += strlen(urlptr); *urlptr = ISO_eq; ++urlptr; /* Convert and copy the contents of the input field to the URL and append an ampersand. */ valueptr = pagewidgets[i].widget.textentry.text; petsciiconv_toascii(valueptr, WWW_CONF_MAX_INPUTVALUELEN); for(j = 0; j < WWW_CONF_MAX_INPUTVALUELEN; ++j) { if(urlptr - &tmpurl[0] >= WWW_CONF_MAX_URLLEN) { break; } *urlptr = *valueptr; if(*urlptr == ISO_space) { *urlptr = ISO_plus; } if(*urlptr == 0) { break; } ++urlptr; ++valueptr; } *urlptr = ISO_ampersand; ++urlptr; } } --urlptr; *urlptr = 0; /* PRINTF(("formsubmit: URL '%s'\n", tmpurl));*/ log_back(); open_link(tmpurl);}/*-----------------------------------------------------------------------------------*/#endif /* WWW_CONF_FORMS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -