📄 www.c
字号:
show_statustext("Out of memory error."); } else { show_statustext("Connecting..."); } redraw_window();}/*-----------------------------------------------------------------------------------*//* open_link(link): * * Will format a link from the current web pages so that it suits the * open_url() function and finally call it to open the requested URL. */static voidopen_link(char *link){ char *urlptr; if(strncmp(link, http_http, 7) == 0) { /* The link starts with http://. We just copy the contents of the link into the url string and jump away. */ strncpy(url, link, WWW_CONF_MAX_URLLEN); } else if(*link == ISO_slash && *(link + 1) == ISO_slash) { /* The link starts with //, so we'll copy it into the url variable, starting after the http (which already is present in the url variable since we were able to open the web page on which this link was found in the first place). */ strncpy(&url[5], link, WWW_CONF_MAX_URLLEN); } else if(*link == ISO_slash) { /* The link starts with a slash, so it is a non-relative link within the same web site. We find the start of the filename of the current URL and paste the contents of this link there, and head off to the new URL. */ for(urlptr = &url[7]; *urlptr != 0 && *urlptr != ISO_slash; ++urlptr); strncpy(urlptr, link, WWW_CONF_MAX_URLLEN - (urlptr - url)); } else { /* A fully relative link is found. We find the last slash in the current URL and paste the link there. */ /* XXX: we should really parse any ../ in the link as well. */ for(urlptr = url + strlen(url); urlptr != url && *urlptr != ISO_slash; --urlptr); ++urlptr; strncpy(urlptr, link, WWW_CONF_MAX_URLLEN - (urlptr - url)); } /* Open the URL. */ scrolly = 0; show_url(); open_url();}/*-----------------------------------------------------------------------------------*//* log_back(): * * Copies the current URL from the url variable and into the log for * the back button. */static voidlog_back(void){ if(strncmp(url, history[(int)history_last], WWW_CONF_MAX_URLLEN) != 0) { memcpy(history[(int)history_last], url, WWW_CONF_MAX_URLLEN); ++history_last; if(history_last >= WWW_CONF_HISTORY_SIZE) { history_last = 0; } }}/*-----------------------------------------------------------------------------------*/static voidquit(void){ ctk_window_close(&mainwindow); dispatcher_exit(&p); id = EK_ID_NONE; LOADER_UNLOAD();}/*-----------------------------------------------------------------------------------*//* www_dispatcher(): * * The program's signal dispatcher function. Is called by the ek * dispatcher whenever a signal arrives. */staticDISPATCHER_SIGHANDLER(www_sighandler, s, data){ static struct ctk_widget *w; static unsigned char i; static char *argptr; DISPATCHER_SIGHANDLER_ARGS(s, data); w = (struct ctk_widget *)data; if(s == ctk_signal_widget_activate) { if(w == (struct ctk_widget *)&backbutton) { scrolly = 0; run = 1; --history_last; if(history_last > WWW_CONF_HISTORY_SIZE) { history_last = WWW_CONF_HISTORY_SIZE - 1; } memcpy(url, history[(int)history_last], WWW_CONF_MAX_URLLEN); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &backbutton); } else if(w == (struct ctk_widget *)&downbutton) { run = 1; open_url(); CTK_WIDGET_FOCUS(&mainwindow, &downbutton); } else if(w == (struct ctk_widget *)&gobutton || w == (struct ctk_widget *)&urlentry) { scrolly = 0;#if WWW_CONF_PAGEVIEW starty = 0;#endif /* WWW_CONF_PAGEVIEW */ run = 1; log_back(); memcpy(url, editurl, WWW_CONF_MAX_URLLEN); petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &gobutton); } else if(w == (struct ctk_widget *)&stopbutton) { run = 0; webclient_close(); } else if(w == (struct ctk_widget *)&wgetnobutton) { ctk_dialog_close(); } else if(w == (struct ctk_widget *)&wgetyesbutton) { ctk_dialog_close(); quit(); argptr = arg_alloc(WWW_CONF_MAX_URLLEN); if(argptr != NULL) { strncpy(argptr, url, WWW_CONF_MAX_URLLEN); } program_handler_load("wget.prg", argptr); #if WWW_CONF_FORMS } else { /* Check form buttons */ for(i = 0; i < pagewidgetptr; ++i) { if(&pagewidgets[i] == w) { formsubmit(&pagewidgetattribs[i].form); /* show_statustext(pagewidgetattribs[i].form.formaction);*/ /* PRINTF(("Formaction %s formname %s inputname %s\n", pagewidgetattribs[i].form.formaction, pagewidgetattribs[i].form.formname, pagewidgetattribs[i].form.inputname));*/ break; } }#endif /* WWW_CONF_FORMS */ } } else if(s == ctk_signal_hyperlink_activate) { log_back(); open_link(w->widget.hyperlink.url); CTK_WIDGET_FOCUS(&mainwindow, &stopbutton); /* ctk_window_open(&mainwindow);*/ run = 1; } else if(s == ctk_signal_hyperlink_hover) { if(CTK_WIDGET_TYPE((struct ctk_widget *)data) == CTK_WIDGET_HYPERLINK) { strncpy(statustexturl, w->widget.hyperlink.url, sizeof(statustexturl)); petsciiconv_topetscii(statustexturl, sizeof(statustexturl)); show_statustext(statustexturl); } } else if(s == resolv_signal_found) { /* Either found a hostname, or not. */ if((char *)data != NULL && resolv_lookup((char *)data) != NULL) { open_url(); } else { show_statustext("Host not found."); } } else if(s == ctk_signal_window_close || s == dispatcher_signal_quit) { quit(); }}/*-----------------------------------------------------------------------------------*//* set_url(): * * Constructs an URL from the arguments and puts it into the global * "url" variable and the visible "editurl" (which is shown in the URL * text entry widget in the browser window). */static voidset_url(char *host, u16_t port, char *file){ char *urlptr; memset(url, 0, WWW_CONF_MAX_URLLEN); if(strncmp(file, http_http, 7) == 0) { strncpy(url, file, sizeof(url)); } else { strncpy(url, http_http, 7); urlptr = url + 7; strcpy(urlptr, host); urlptr += strlen(host); strcpy(urlptr, file); } show_url();}/*-----------------------------------------------------------------------------------*//* webclient_aborted(): * * Callback function. Called from the webclient when the HTTP * connection was abruptly aborted. */voidwebclient_aborted(void){ show_statustext("Connection reset by peer");}/*-----------------------------------------------------------------------------------*//* webclient_timedout(): * * Callback function. Called from the webclient when the HTTP * connection timed out. */voidwebclient_timedout(void){ show_statustext("Connection timed out");}/*-----------------------------------------------------------------------------------*//* webclient_closed(): * * Callback function. Called from the webclient when the HTTP * connection was closed after a request from the "webclient_close()" * function. . */voidwebclient_closed(void){ show_statustext("Stopped."); petsciiconv_topetscii(&webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) * WWW_CONF_WEBPAGE_WIDTH], WWW_CONF_WEBPAGE_WIDTH); redraw_window();}/*-----------------------------------------------------------------------------------*//* webclient_closed(): * * Callback function. Called from the webclient when the HTTP * connection is connected. */voidwebclient_connected(void){ x = nextwordptr = 0; starty = scrolly; #if WWW_CONF_PAGEVIEW if(starty > 4) { starty = scrolly - 4; } scrollend = starty + WWW_CONF_WEBPAGE_HEIGHT - 4;#endif /* WWW_CONF_PAGEVIEW */ nextword[0] = 0; if(scrolly == 0) { clear_page(); redraw_window(); } show_statustext("Request sent..."); set_url(webclient_hostname(), webclient_port(), webclient_filename());#if WWW_CONF_RENDERSTATE renderstate = HTMLPARSER_RENDERSTATE_NONE;#endif /* WWW_CONF_RENDERSTATE */ htmlparser_init();}/*-----------------------------------------------------------------------------------*//* scroll(): * * Scrolls the entire web page display (text and hyperlinks) one line * upwards. */static voidscroll(void){ unsigned char i; unsigned char lptr, linkptrtmp; struct ctk_widget *linksptr; char *statustexttext; struct ctk_widget *focuswidget; /* Scroll text up. */ memcpy(webpage, &webpage[WWW_CONF_WEBPAGE_WIDTH], (WWW_CONF_WEBPAGE_HEIGHT - 1) * WWW_CONF_WEBPAGE_WIDTH); /* Clear last line of text. */ memset(&webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) * WWW_CONF_WEBPAGE_WIDTH], ' ', WWW_CONF_WEBPAGE_WIDTH); /* Scroll links and form widgets up. */ lptr = 0; linksptr = pagewidgets; for(i = 0; i < pagewidgetptr; ++i) { /* First, check which links that scroll off the top of the page and should be removed. */ if(CTK_WIDGET_YPOS(linksptr) == 3) { lptr = i + 1; } else { /* Else, move them upward one notch. */ /* XXX: this is really a hack! These values should not be used like this, but should be obtained and set using some CTK API function. */ linksptr->widget.hyperlink.text -= WWW_CONF_WEBPAGE_WIDTH; --(linksptr->y); } ++linksptr; } /* See if there are any links that scroll off the top. */ if(lptr != 0) { memcpy(pagewidgets, &pagewidgets[lptr], sizeof(struct ctk_widget) * (WWW_CONF_MAX_NUMPAGEWIDGETS - lptr)); memcpy(pagewidgetattribs, &pagewidgetattribs[lptr], sizeof(union pagewidgetattrib) * (WWW_CONF_MAX_NUMPAGEWIDGETS - lptr)); /* Compute new value of linkptr and tuck it away in linkptrtmp. make_window() destroys linkptr, so we need to restore it after the call. */ linkptrtmp = pagewidgetptr - lptr; /* XXX: hack - these values should *not* be obtained this way, but through some CTK API instead! */ statustexttext = statustext.text; focuswidget = mainwindow.focused; ctk_window_clear(&mainwindow); make_window(); CTK_WIDGET_FOCUS(&mainwindow, focuswidget); show_statustext(statustexttext); pagewidgetptr = linkptrtmp; linksptr = pagewidgets; for(i = 0; i < pagewidgetptr; ++i) { if(linksptr->type == CTK_WIDGET_HYPERLINK) { linksptr->widget.hyperlink.url -= lptr * sizeof(union pagewidgetattrib); } CTK_WIDGET_ADD(&mainwindow, linksptr); ++linksptr; } }}/*-----------------------------------------------------------------------------------*/static char tmpcenterline[WWW_CONF_WEBPAGE_WIDTH];/* inc_y(): * * Called from the rendering code when it is time to move on line * downwards. */static voidinc_y(void){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -