⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htbrowse.c

📁 www工具包. 这是W3C官方支持的www支撑库. 其中提供通用目的的客户端的WebAPI: complete HTTP/1.1 (with caching, pipelining, PUT, POS
💻 C
📖 第 1 页 / 共 5 页
字号:
{    char * the_choice=NULL;		           /* preserved user command */    char * token=NULL;        	   	    	    /* First word of command */    char * this_command;	       	              /* token and following */    char * next_word;			                      /* Second word */    char * other_words;				/* Second word and following */    BOOL is_index = HTAnchor_isIndex(HTMainAnchor);    BOOL found = YES;    BOOL OutSource = NO;			    /* Output source, YES/NO */    int status = YES;    HTRequest * cur_req = NULL;    Context * cur_context = NULL;    LineMode * lm = NULL;    cur_req = req;    cur_context = (Context *) HTRequest_context(req);    lm = cur_context->lm;    StrAllocCopy (the_choice, choice);		       /* Remember it as is, */    if (*the_choice && the_choice[strlen(the_choice)-1] == '\n') /* final \n */	the_choice[strlen(the_choice)-1] = '\0';        token = strtok (choice, " \t\n\r");	      /* Tokenize user input */    this_command = the_choice;    if (token) {	next_word = strtok (NULL, " \t\n\r");	other_words = the_choice + (next_word - choice);    }    else	goto down;				/* Empty input : scroll down */        /* Process Command */  loop:    switch (TOUPPER(*token)) {      case '0':      case '1':      case '2':      case '3':      case '4':      case '5':      case '6':      case '7':      case '8':      case '9':	{	    int  ref_num;	    sscanf(token,"%d",&ref_num);	    if (ref_num>0 && ref_num<=HText_sourceAnchors(HTMainText)) {		HTChildAnchor *source = HText_childNumber(HTMainText, ref_num);		if (source) {		    HTLink * link = HTAnchor_mainLink((HTAnchor *) source);		    HTAnchor * destination = HTLink_destination(link);		    req = Thread_new(lm, YES, LM_UPDATE);		    		    /* Continous browsing, so we want Referer field */		    HTRequest_setParent(req, HTAnchor_parent((HTAnchor*)source));		    HTLoadAnchor(destination, req);		} else {		    status = NO;				/* No anchor */		}	    } else {		if (SHOW_MSG)		    HTPrint("Warning: Invalid Reference Number: (%d)\n",			    ref_num);	    }	}	break;	      case 'B':			if (CHECK_INPUT("BACK", token)) {	  /* Return to previous node */	    if (HTHistory_canBacktrack(lm->history)) {		req = Thread_new(lm, YES, LM_NO_UPDATE);		status = HTLoadAnchor(HTHistory_back(lm->history), req);	    } else {		OutputData(lm->pView, "\nThis is the first document in history list\n");	    }	} else if (CHECK_INPUT("BOTTOM", token)) {	/* Scroll to bottom  */	    HText_scrollBottom(HTMainText);	} else if (CHECK_INPUT("BYE", token)) {		    /* Quit program? */	    HTNet_killAll();				/* Kill all requests */	    status = NO;	} else	    found = NO;	break;	      case 'C':#ifdef HAVE_CHDIR	if (CHECK_INPUT("CD", token)) {        /* Change working directory ? */	    goto lcd;	} else#endif /* HAVE_CHDIR */	if (CHECK_INPUT("CLEAR", token)) {	       /* Clear History list */	    HTHistory_removeFrom(lm->history, 1);	} else	    found = NO;	break;	      case 'D':	if (CHECK_INPUT("DELETE", token)) {	    		   /* DELETE */	    status = DeleteAnchor(lm, req);	} else if (CHECK_INPUT("DOWN", token)) {    /* Scroll down one page  */	  down:	    if (HText_canScrollDown(HTMainText))		HText_scrollDown(HTMainText);	} else	    found = NO;	break;	      case 'E':	if (CHECK_INPUT("EDIT", token)) {	    status = PutAnchor(lm, req);	} else if (CHECK_INPUT("EXIT", token)) {	    /* Quit program? */	    HTNet_killAll();				/* Kill all requests */	    status = NO;	} else	    found = NO;	break;	      case 'F':						 /* Keyword search ? */	if (is_index && CHECK_INPUT("FIND", token)) {	  find:	    {		if (next_word) {		    req = Thread_new(lm, YES, LM_UPDATE);		    status = HTSearchString(other_words,					    (HTAnchor *) HTMainAnchor, req);		}	    }	} else if (CHECK_INPUT("FLUSH", token)) {	 /* Flush file cache */	    if (confirm(req, "Flush Persistent Cache?") == YES)		HTCache_flushAll();	} else if (CHECK_INPUT("FORWARD", token)) {	    if (HTHistory_canForward(lm->history)) {		req = Thread_new(lm, YES, LM_NO_UPDATE);		status = HTLoadAnchor(HTHistory_forward(lm->history), req);	    } else {		OutputData(lm->pView, "\nThis is the last document in history list.\n");	    }	} else	    found = NO;	break;	      case 'G':	if (CHECK_INPUT("GOTO", token)) {			     /* GOTO */	    if (next_word)	        status = LineMode_load(lm, HTMainAnchor, next_word, NO, &req);	} else	    found = NO;	break;	      case '?':	status = LineMode_load(lm, HTMainAnchor, C_HELP, YES, &req);	break;	      case 'H':	if (CHECK_INPUT("HELP", token)) {		     /* help menu, ..*/	    status = LineMode_load(lm, HTMainAnchor, C_HELP, YES, &req);	} else if (CHECK_INPUT("HOME", token)) {		/* back HOME */	    if (!HTHistory_canBacktrack(lm->history)) {		HText_scrollTop(HTMainText);	    } else {		req = Thread_new(lm, YES, LM_NO_UPDATE);		status = HTLoadAnchor(HTHistory_find(lm->history, 1), req);	    }	} else	    found = NO;	break;	      case 'K':						 /* Keyword search ? */	if (is_index && CHECK_INPUT("KEYWORDS", token)) {	    goto find;	} else	    found = NO;	break;	      case 'L':	if (CHECK_INPUT("LIST", token)) {	     /* List of references ? */	    Reference_List(lm, !OutSource);	}#ifdef HAVE_CHDIR	else if (CHECK_INPUT ("LCD", token)) {	       /* Local change dir ? */	  lcd:	    if (!next_word) {				 /* Missing argument */		OutputData(lm->pView, "\nName of the new local directory missing.\n");	    } else if (chdir (next_word)) {		 /* failed : say why */		OutputData(lm->pView, "\n  ");		perror (next_word);	    } else {		    /* Success : display new local directory */#ifdef HAVE_GETCWD		OutputData(lm->pView, "\nLocal directory is now:\n %s\n",			   getcwd (choice, sizeof(choice)));#else#ifdef HAVE_GETWD		OutputData(lm->pView, "\nLocal directory is now:\n %s\n",			   (char *) getwd (choice));#else#error "This platform doesn't support getwd or getcwd"		if (SHOW_MSG)		    HTPrint("This platform doesn't support getwd or getcwd\n");#endif /* HAVE_GETWD */#endif /* HAVE_GETCWD */	    }	}#endif /* HAVE_CHDIR */	else if (CHECK_INPUT("LUSER", token)) {	     /* List of references ? */	    if (next_word) {	        LoadPICSUser(lm, next_word);	    } else {	        HTPrint("URL needed\n");	    }	} else	    found = NO;	break;	      case 'M':	if (CHECK_INPUT("MANUAL", token)) {		 /* Read User manual */	    status = LineMode_load(lm, HTMainAnchor, MANUAL, YES, &req);	} else	    found = NO;	break;	      case 'O':	if (CHECK_INPUT("OPTIONS", token)) {		   /* OPTIONS method */	    req = Thread_new(lm, YES, LM_NO_UPDATE);	    status = HTOptionsAnchor((HTAnchor*)				     (HTMainAnchor ? HTMainAnchor:lm->anchor),				     req);	} else	    found = NO;	break;	      case 'P':                    	if (CHECK_INPUT("POST", token)) {	    status = PutAnchor(lm, req);	}#ifdef HAVE_SYSTEM	    	else if (!lm->host && CHECK_INPUT("PRINT", token)) {	    char * address = HTAnchor_address((HTAnchor *) HTMainAnchor);	    char * command;	    char * tmplate = (char *) getenv("WWW_PRINT_COMMAND");	    int result;	    	    if (!tmplate) tmplate = "www -n -na -p66 '%s' | lpr";	    if ((command = (char *) HT_MALLOC(strlen(address)+strlen(tmplate)+20)) == NULL)	        HT_OUTOFMEM("command");	    sprintf(command, tmplate, address);	    result = system(command);	    HT_FREE(address);	    HT_FREE(command);	    if (result) OutputData(lm->pView, "  %s\n  returns %d\n", command, result);	}#endif	/* this command prints the entire current text to the	   terminal's printer; at the end it displays the top of the text */#ifdef SLAVE_PRINTER#define SLAVE_PRINTER_ON  "\033\133\065\151"#define SLAVE_PRINTER_OFF "\033\133\064\151"		else if (CHECK_INPUT("PS", token)) {	    OutputData(lm->pView, "%s",SLAVE_PRINTER_ON);	    OutputData(lm->pView, "\f");			   /* Form feed for new page */	    HText_scrollTop(HTMainText);	    while(HText_canScrollDown(HTMainText)) {		HText_scrollDown(HTMainText);	    }	    OutputData(lm->pView, "\f");  			   /* Form feed for new page */	    OutputData(lm->pView, "%s",SLAVE_PRINTER_OFF);	    HText_scrollTop(HTMainText);	}	#endif	else if (CHECK_INPUT("PUT", token)) {	    status = PutAnchor(lm, req);	} else	    found = NO;	break;	      case 'Q':						   /* Quit program ? */	if (CHECK_INPUT("QUIT", token)) {	    /* 	JFG 9/7/92, following a complaint of 'q' mis-typed for '1'.		JFG Then made optional because I hate it !!!		TBL made it only affect remote logged on users. 921122 */	    	    if (lm->host && (strcasecomp(token, "quit") != 0) ) {		OutputData(lm->pView, "\n Please type \"quit\" in full to leave www.\n");	    } else {		HTNet_killAll();			/* Kill all requests */		status = NO;	    }	} else	    found = NO;	break;	      case 'R':		if (CHECK_INPUT("RECALL", token)) {	    if (HTHistory_count(lm->history) <= 1) {		OutputData(lm->pView, "\n  No other documents to recall.\n");	    } else {		/* Previous node number exists, or does the user just */		/* require a list of nodes visited? */		if (next_word) {			    int cnt;		    if ((cnt = atoi(next_word)) > 0) {			req = Thread_new(lm, YES, LM_NO_UPDATE);			status = HTLoadAnchor(HTHistory_find(lm->history,cnt), req);		    } else {			if (SHOW_MSG)			    HTPrint("Bad command (%s), for list of commands type help\n", this_command);		    }		} else {		    History_List(lm);		}	    }	} else if (CHECK_INPUT("REFRESH", token)) {	    HText_setStale(HTMainText);			    /* Force refresh */	    HText_refresh(HTMainText);			   /* Refresh screen */	} else if (CHECK_INPUT("REVALIDATE", token)) {	    req = Thread_new(lm, YES, LM_NO_UPDATE);	    /*	    **  Add a end-to-end validator to the request	    */	    HTRequest_setReloadMode(req, HT_CACHE_END_VALIDATE);	    status = HTLoadAnchor((HTAnchor*) (HTMainAnchor ? HTMainAnchor : 					       lm->anchor), req);	} else if (CHECK_INPUT("RELOAD", token)) {	    req = Thread_new(lm, YES, LM_NO_UPDATE);	    /*	    **  Make sure that we do a complete flush of the cache	    */	    HTRequest_setReloadMode(req, HT_CACHE_FLUSH);	    status = HTLoadAnchor((HTAnchor*) (HTMainAnchor ? HTMainAnchor : 				  lm->anchor), req);	} else	    found = NO;	break;	      case 'S':						       /* TBL 921009 */	if (CHECK_INPUT("SOURCE", token)) {    	  	  /* Apply to source */	    if (next_word) {		OutSource = YES;		 /* Load and print as source */		token = next_word;		         /* Move up one word */		next_word = strtok (NULL, " \t\n\r");		this_command = the_choice + (token - choice);		other_words = the_choice + (next_word - choice);		goto loop;	                       /* Go treat as before */	    }	} else if (CHECK_INPUT("SET", token)) {        	           /* config */	    HTList * rules = HTRule_global();	    HTRule_parseLine(rules, other_words);	} else	    found = NO;	break;	      case 'T':	if (CHECK_INPUT("TOP", token)) {		   /* Return to top  */	    HText_scrollTop(HTMainText);	} else	    found = NO;	break;	      case 'U':	if (CHECK_INPUT("UP", token)) {		      /* Scroll up one page  */	    HText_scrollUp(HTMainText);	} else if (CHECK_INPUT("USER", token)) {	    if (next_word) {			if (!strcasecomp(next_word, "?")) {				ShowPICSUsers(lm);				SetPICSUser(lm, 0);			} else {				SetPICSUser(lm, next_word);			}	    } else {	        SetPICSUser(lm, 0);		}	} else 	    found = NO;	break;	      case 'V':	if (CHECK_INPUT("VALIDATE", token)) {    	   /* Cache validate */	    req = Thread_new(lm, YES, LM_NO_UPDATE);	    /*	    **  Add a validator to the request	    */	    HTRequest_setReloadMode(req, HT_CACHE_VALIDATE);	    status = HTLoadAnchor((HTAnchor*) (HTMainAnchor ? HTMainAnchor : 					       lm->anchor), req);	} else if (CHECK_INPUT("VERBOSE", token)) {  /* Switch verbose mode  */	    WWWTRACE = WWWTRACE ? 0 : lm->trace;	    OutputData(lm->pView, "\n  Verbose mode %s.\n", WWWTRACE ? "ON":"OFF");	} else if (CHECK_INPUT("VERSION", token)) {	 	  /* Version */	    VersionInfo(lm);	} else	    found = NO;	break;      case 'W':	if (CHECK_INPUT("WHICH", token)) {     /* Show title/URL of current page */	    HTView * pView = lm ? lm->pView : NULL;	    char * current_address = HTAnchor_address((HTAnchor *) HTMainAnchor);	    const char * title = HTAnchor_title(HTMainAnchor);	    if (title)		OutputData(pView, "\n\nYou are reading\n\t`%s\'\nwith address\n\t%s\n\n",			   title, current_address);	} else	    found = NO;	break;	      case 'Z':	HText_setStale(HTMainText);			    /* Force refresh */	HText_refresh(HTMainText);			   /* Refresh screen */	HTNet_killAll();				/* Kill all requests */	break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -