?? htbrowse.c
字號:
case '>': if (!lm->host) { HText *curText = HTMainText; /* Remember current main vindow */ req = Thread_new(lm, NO, LM_NO_UPDATE); HTRequest_setReloadMode(req, HT_CACHE_FLUSH_MEM); if (OutSource) HTRequest_setOutputFormat(req, WWW_SOURCE); SaveOutputStream(req, token, next_word); HText_select(curText); } break; #ifdef GOT_PIPE case '|': if (!lm->host) { /* Local only!!!! */ char * address = HTAnchor_address((HTAnchor *) HTMainAnchor); char * command; int result; if ((command = (char *) HT_MALLOC(strlen(address) +strlen(this_command)+30)) == NULL) HT_OUTOFMEM("command"); sprintf(command, "www %s \"%s\" %s", OutSource ? "-source" : "-n -na -p", address,this_command); OutputData(lm->pView, "Command: %s\n", command); result = system(command); if (result) OutputData(lm->pView, " %s returns %d\n", command, result); HT_FREE(command); HT_FREE(address); } break;#endif #ifdef HAVE_SYSTEM case '!': if (!lm->host) { /* Local only! */ int result; if (SHOW_MSG) HTPrint("Executing `%s\'\n", this_command); result = system(strchr(this_command, '!') + 1); if (result) OutputData(lm->pView, " %s returns %d\n", strchr(this_command, '!') + 1, result); } break;#endif /* HAVE_SYSTEM */ default: found = NO; break; } /* Switch on 1st character */ if (!found) { if (is_index && *token) { /* No commands, search keywords */ next_word = other_words = this_command; found = YES; goto find; } else { if (SHOW_MSG) HTPrint("Bad command (%s), for list of commands type help\n", this_command); } } MakeCommandLine(lm, is_index); HT_FREE(the_choice); /* ** If we have created a new Request and is to update the history list then ** we can set the inactive bit on this request object. */ if (cur_req == req) cur_context->state |= LM_NO_UPDATE; else cur_context->state |= LM_INACTIVE; return (status==YES) ? HT_OK : HT_ERROR;}/* readConsole** -----------** non-blocking read of the WIN32 console. EGP*/#ifdef WWW_WIN_CONSOLEPUBLIC BOOL readConsole(HANDLE conIn, char* buf, int len, int* pRed){ DWORD recordIndex, bufferIndex, toRead, red; PINPUT_RECORD pInput; /* grab the pending input records (keystrokes plus other garbage). */ GetNumberOfConsoleInputEvents(conIn, &toRead); if (len < (int)toRead) /* we'll get the rest on the next pass(es). */ toRead = len; if ((pInput = (PINPUT_RECORD) HT_MALLOC(toRead * sizeof(INPUT_RECORD))) == NULL) /* room for n input records */ return (FALSE); ReadConsoleInput(conIn, pInput, toRead, &red); for (recordIndex = bufferIndex = 0; recordIndex < red; recordIndex++) { /* grab all keydown events */#if 1 KEY_EVENT_RECORD keyEvent = pInput[recordIndex].Event.KeyEvent; /* only used if EventType == KEY_EVENT */ if (pInput[recordIndex].EventType == KEY_EVENT && keyEvent.bKeyDown) { while (keyEvent.wRepeatCount && keyEvent.uChar.AsciiChar) { /* stuff the buffer with the keys */ buf[bufferIndex] = keyEvent.uChar.AsciiChar; if (buf[bufferIndex] == '\r') buf[bufferIndex] = '\n'; if (buf[bufferIndex] == '\b') OutputData(lm->pView, "\b "); OutputData(lm->pView, "%c", buf[bufferIndex]); bufferIndex++; keyEvent.wRepeatCount--; } }#else if (pInput[recordIndex].EventType == KEY_EVENT && pInput[recordIndex].Event.KeyEvent.bKeyDown) { while (pInput[recordIndex].Event.KeyEvent.wRepeatCount && pInput[recordIndex].Event.KeyEvent.uChar.AsciiChar) { /* stuff the buffer with the keys */ buf[bufferIndex] = pInput[recordIndex].Event.KeyEvent.uChar.AsciiChar; if (buf[bufferIndex] == '\r') buf[bufferIndex] = '\n'; if (buf[bufferIndex] == '\b') OutputData(lm->pView, "\b "); OutputData(lm->pView, "%c", buf[bufferIndex]); bufferIndex++; pInput[recordIndex].Event.KeyEvent.wRepeatCount--; } }#endif } HT_FREE(pInput); *pRed = bufferIndex; /* actual characters stuck into buffer */ return (TRUE);}#endif /* WWW_WIN_CONSOLE *//* bufferInput** -----------** Read available characters from buf into stat. buf maybe bigger or** smaller than stat.*/PUBLIC int bufferInput (char* buf, int len, SOCKET s, HTRequest * req, HTEventType type){ static char stat[RESPONSE_LENGTH]; static int iStat = 0; static int ignoreNext = 0; int iBuf; for (iBuf = 0; iBuf < len; iBuf++) { switch (buf[iBuf]) { case '\r': case '\n': if (ignoreNext) ignoreNext = 0; else { int ret; stat[iStat] = 0; iStat = 0; if ((ret = (*PInputParser)(stat, s, req, type)) != HT_OK) return (ret); } break; case '\b': if (iStat) /* don't worry about ignoreNext as iStat will be 0*/ iStat--; break; default: if (!ignoreNext) stat[iStat++] = buf[iBuf]; } if (iStat == sizeof(stat)) { HTPrint("Read Console... BUFFER OVERRUN\n"); iStat = 0; ignoreNext = 1; } } return (HT_OK);}/* timeout_handler** ---------------** This function is registered to handle timeout in select eventloop*/PRIVATE int timeout_handler (SOCKET s, void * param, HTEventType type){ if (!HTAlert_interactive()) { HTRequest * req = (HTRequest *) param; Context * context = (Context *) HTRequest_context(req); LineMode * lm = context->lm; if (SHOW_MSG) HTPrint("Request timed out"); HTNet_killAll(); Cleanup(lm, -1); } if (HTNet_count() > 0) if (SHOW_MSG) HTPrint("."); return 0;}PRIVATE int scan_command (SOCKET s, void * param, HTEventType type){ HTRequest * req = (HTRequest *)param; /* buf happens to == eatText's buffer but not neccesary */ static char buf[RESPONSE_LENGTH];#ifdef WWW_MSWINDOWS int red; int ret;#endif /* Handle any timeout here */ if (type == HTEvent_TIMEOUT) return timeout_handler (s, param, type);#ifdef WWW_MSWINDOWS while(1) {#ifdef WWW_WIN_CONSOLE if (!readConsole((HANDLE)s, buf, sizeof(buf), &red)) { HTTRACE(PROT_TRACE, "Read Console... READ ERROR\n"); return HT_ERROR; }#endif /* WWW_WIN_CONSOLE */ if (!red) return (HT_OK); ret = bufferInput(buf, red, s, req, type); if (ret != HT_OK) return (ret); }#else /* WWW_MSWINDOWS */ if (!fgets(buf, sizeof(buf), stdin)) /* Read User Input */ return HT_ERROR; /* Exit if EOF */ return ((*PInputParser)(buf, s, req, type));#endif /* !WWW_MSWINOWS */}/* terminate_handler** -----------------** This function is registered to handle the result of the request*/PRIVATE int terminate_handler (HTRequest * request, HTResponse * response, void * param, int status) { Context * context = (Context *) HTRequest_context(request); LineMode * lm; BOOL is_index; if (!context) return HT_OK; lm = context->lm; if (context->state == LM_IGNORE) return HT_OK; if (CSApp_unregisterReq(request) == NO && lm->pCSUser) HTPrint("PICS request not found\n"); is_index = HTAnchor_isIndex(HTMainAnchor); if (status == HT_LOADED) { /* Should we output a command line? */ if (HTAlert_interactive()) { HText_setStale(HTMainText); MakeCommandLine(lm, is_index); } else { if (lm->flags & LM_REFS) Reference_List(lm, NO); Cleanup(lm, 0); } /* Record new history if we have not moved around in the old one */ if (context->state & LM_UPDATE) HTHistory_replace(lm->history, (HTAnchor *) HTMainAnchor); /* Now generate the new prompt line as a function of the result */ if (!HText_canScrollDown(HTMainText) && !HTAnchor_hasChildren(HTMainAnchor) && !is_index && (!HTHistory_canBacktrack(lm->history))) { return HT_OK; } } else { /* No page loaded so sit around and wait for a go command */ /* was MakeCommandLine(lm, is_index); */ /* ** stolen from above */ if (HTAlert_interactive()) {/* HText_setStale(HTMainText); */ MakeCommandLine(lm, is_index); } else { if (lm->flags & LM_REFS) Reference_List(lm, NO); Cleanup(lm, 0); } } context->state |= LM_DONE; Thread_cleanup(lm); if (!HTAlert_interactive()) Cleanup(lm, -1); return HT_OK;}/*** Check the Memory Cache (History list) BEFORE filter** ---------------------------------------------------** Check if document is already loaded. The user can define whether** the history list should follow normal expiration or work as a** traditional history list where expired documents are not updated.** We don't check for anything but existence proof of a document** associated with the anchor as the definition is left to the application*/PRIVATE int MemoryCacheFilter (HTRequest * request, void * param, int mode){ HTReload validation = HTRequest_reloadMode(request); HTParentAnchor * anchor = HTRequest_anchor(request); void * document = HTAnchor_document(anchor); /* ** We only check the memory cache if it's a GET method */ if (HTRequest_method(request) != METHOD_GET) { HTTRACE(APP_TRACE, "Mem Cache... We only check GET methods\n"); return HT_OK; } /* ** If we are asked to flush the persistent cache then there is no reason ** to do anything here - we're flushing it anyway. Also if no document ** then just exit from this filter. */ if (!document || validation > HT_CACHE_FLUSH_MEM) { HTTRACE(APP_TRACE, "Mem Cache... No fresh document...\n"); return HT_OK; } /* ** If we have a document object associated with this anchor then we also ** have the object in the history list. Depending on what the user asked, ** we can add a cache validator */ if (document && validation != HT_CACHE_FLUSH_MEM) { HTParentAnchor * parent = HTRequest_anchor(request); HTChildAnchor * child = HTRequest_childAnchor(request); HText * document = HTAnchor_document(parent); HTTRACE(APP_TRACE, "Mem Cache... Document %p already in memory\n" _ document); /* ** Make sure that we have selected the HText object. This is normally ** done by the HText interface but must be repeated here. */ if (child && (HTAnchor *) child != (HTAnchor *) parent) HText_selectAnchor(document, child); else HText_select(document); return HT_LOADED; } return HT_OK;}/* ------------------------------------------------------------------------- *//* MAIN PROGRAM *//* ------------------------------------------------------------------------- */int main (int argc, char ** argv){ int status = 0; int arg; /* Index into argv */ HTChunk * keywords = NULL; /* From command line */ int keycnt = 0; HTRequest * request = NULL; LineMode * lm; char * picsUser = NULL;#ifndef WWW_WIN_WINDOW OUTPUT = stdout;#endif /* Starts Mac GUSI socket library */#ifdef GUSI GUSISetup(GUSIwithSIOUXSockets); GUSISetup(GUSIwithInternetSockets);#endif#ifdef __MWERKS__ /* STR */ InitGraf((Ptr) &qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(nil); InitCursor(); SIOUXSettings.asktosaveonclose = false; argc=ccommand(&argv);#endif /* HWL 18/7/94: patch from agl@glas2.glas.apc.org (Anton Tropashko) */#ifdef CYRILLIC arc.locale=0; arc.encoding=0; arc.i_encoding=0; doinull();#endif#ifdef HT_MEMLOG HTMemLog_open(DEFAULT_MEMLOG, 8192, YES); HTTraceData_setCallback(HTMemLog_callback);#endif /* Initiate W3C Reference Library with a client profile */ HTProfile_newClient(APP_NAME, APP_VERSION); /* It's confusing to have progress notofications in linemode browser */ HTAlert_deleteOpcode(HT_A_PROGRESS); /* Add the default HTML parser to the set of converters */ { HTList * converters = HTFormat_conversion(); HTMLInit(converters); } /* Create a new Line Mode object */ lm = LineMode_new(); request = Thread_new(lm, NO, LM_UPDATE); /* Scan command Line for parameters */ for (arg=1; arg<argc ; arg++) { if (*argv[arg] == '-') { /* - alone => filter */ if (argv[arg][1] == '\0') { lm->flags |= LM_FILTER; HTAlert_setInteractive(NO); /* non-interactive */ } else if (!strcmp(argv[arg], "-n")) { HTAlert_setInteractive(NO); /* from -- Initial represntation (only with filter) */ } else if (!strcmp(argv[arg], "-from")) { lm->format = (arg+1 < argc && *argv[arg+1] != '-') ? HTAtom_for(argv[++arg]) : WWW_HTML; HTAlert_setInteractive(NO);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -