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

📄 htbrowse.c

📁 www工具包. 这是W3C官方支持的www支撑库. 其中提供通用目的的客户端的WebAPI: complete HTTP/1.1 (with caching, pipelining, PUT, POS
💻 C
📖 第 1 页 / 共 5 页
字号:
/*         		    					     HTBrowse.c**	HYPERTEXT BROWSER FOR DUMB TERMINALS****	(c) COPRIGHT MIT 1995.**	Please first read the full copyright statement in the file COPYRIGH.**	@(#) $Id: HTBrowse.c,v 1.184 2000/07/28 10:09:48 kahan Exp $****  Authors:**	NP:  Nicola Pellow  Tech.Student CERN 1990-91**	TBL: Tim Berners-Lee CERN (timbl@w3.org)**	JFG: Jean-Francois Groff, Cooperant CERN 1991-92 (jfg@dxcern.cern.ch)**	DR:  Dudu Rashty +972-2-584848 <RASHTY@hujivms.bitnet>**	MD:  Mark Donszelmann, DELPHI CERN, (duns@vxdeop.cern.ch)**	HFN: Henrik Frystyk Nielsen, MIT, (frystyk@w3.org)****  History:****   4 Dec 90:  Written from scratch (NP)**  11 Feb 91:  Code written by TBL so that the browser could be linked with**              code produced by Bernd Pollermann, enabling access to the**              data on CERNVM. This involved changing the code to handle file**              numbers rather than file pointers.**  18 Mar 91:  The feature of history mechanism was included, enabling a  **              record of previous nodes visited to be kept.**   6 Apr 91:  When a node is accessed, it is immediately read into a **              buffer, in an unformatted state, as soon as the connection is  **              made, so that the server is freed as quickly as possible. **              The program now also uses the additional modules HTBufferFile.c**              and HTBufferFile.h.**  17 Apr 91:  Can be used on machines running ANSI C and ordinary C.**  10 May 91:  Formatted text is stored in a linked list buffer which allows**              scrolling and better page breaks in the middle of text.**              Code incorporated by Tim BL, to enable anonymous FTP.          **  21 May 91:  Accepts various parameters on the command line.**  19 Aug 91:  Currently available in Unix, VAX/VMS and MVS environments.**  21 Nov 91:	 Character grid uses new architecture. (TBL)**              added -w option, new commands, print,**	             ...	See Features.html for further details**  16 Jan 92:	 Put in VIOLA-compatible options - see \017 characters.**	             \017 and \016 bracket user-selectable input.**  27 Feb 92:	New handling of user input, enhanced command syntax. (JFG)**  18 May 92:	PS command see ifdef SLAVE_PRINTER (DR/TBL)**   6 Oct 92:  Painful recovery from someone(?)'s attept to pretty print.(TBL)**		Please see coding style guide before changing indentation etc!**     Mar 93:	Force on HTFile's HTDirAccess and HTDirReadme flags.**   3 Nov 93:	(MD) Changed vms into VMS**		(MD) Assigne OUTPUT in main, not at initialize (VMS only)**** Compilation-time macro options****	REF_MARK	Printf string to be used for printing anchor numbers**	END_MARK	String to be used to denote the end of a document*/#include "WWWLib.h"#include "WWWMIME.h"#include "WWWCache.h"#include "WWWApp.h"#include "WWWTrans.h"#include "WWWInit.h"#include "GridText.h"				     /* Hypertext definition */#include "HTBrowse.h"			     /* Things exported, short names */#include "CSLApp.h" /* the PICApp library should provide everything the app needs */#include "CSLL.h"#include "CSUser.h"#include "CSUsrLst.h"#ifndef W3C_VERSION#define W3C_VERSION		"Unspecified"#endif#define APP_NAME		"W3CLineMode"#define APP_VERSION		W3C_VERSION/* Default page for "Manual" command */#define MANUAL	"http://www.w3.org/LineMode/User/QuickGuide.html"/* Default page for "help" command */#define C_HELP	"http://www.w3.org/LineMode/User/Commands.html"/* Default page for "-help" command line option */#define L_HELP	"http://www.w3.org/LineMode/User/CommandLine.html"#define DEFAULT_OUTPUT_FILE	"www.out"#define DEFAULT_RULE_FILE	"www.conf"#define DEFAULT_LOG_FILE       	"www.log"#define DEFAULT_MEMLOG		"www.mem"#define DEFAULT_USERLIST_FILE	"PICSusrs.html"#if 0#define HT_MEMLOG#endif#define PROMPT			"%s"#define REF_MARK		"[%d]"#define END_MARK		"[END]"#define SCREEN_WIDTH		79  	      /* Default width of the screen */#define MIN_SCREEN_WIDTH	10 #define MAX_SCREEN_WIDTH	150	 #define SCREEN_HEIGHT		24 		  /* Default number of lines */#define MIN_SCREEN_HEIGHT	5 #define MAX_SCREEN_HEIGHT	200	 #define MAX_HISTORY		20	/* Don't list more than this in list */#define RESPONSE_LENGTH		1024     /* Maximum length of users response */#define SHOW_MSG		(WWWTRACE || HTAlert_interactive())#define CHECK_INPUT(a, b)	(!strncasecomp ((a), (b), strlen((b))))#define DEFAULT_I_TIMEOUT	1000       /* Interactive timeout in millies */#define DEFAULT_NI_TIMEOUT	10000  /* Non-interactive timeout in millies */#define DEFAULT_FORMAT		WWW_PRESENT#if defined(__svr4__)#define CATCH_SIG#endif/* HWL 18/7/94: applied patch from agl@glas2.glas.apc.org (Anton Tropashko) */#ifdef CYRILLIC#include "a_stdio.h"struct ARc arc;#endif/* Screen size parameters */PUBLIC int		HTScreenWidth   = SCREEN_WIDTH;	       /* By default */PUBLIC int		HTScreenHeight  = -1;		   /* -1 = Undefined *//* Anchor specific information */PUBLIC BOOL		display_anchors = YES;	    /* Show anchors in text? */PUBLIC char *		start_reference = NULL;   /* Format for start anchor */PUBLIC char *		end_reference = REF_MARK;	   /* for end anchor */PUBLIC char *		reference_mark = "[%d] ";     /* for reference lists */PUBLIC char *		end_mark = END_MARK;   	  /* Format string for [End] */typedef enum _LMFlags {    LM_FILTER	= 0x1,    LM_REFS	= 0x2,    LM_REFORMAT = 0x4,    LM_PREEMTIVE= 0x8} LMFlags;struct _LineMode {    HTRequest *		console;			   /* For user input */    HTParentAnchor *	anchor;    HTList *		active;			  /* List of acitve contexts */    HTList *		presenters;    HTHistory *		history;    			     /* History list */    char *		cwd;				  /* Current dir URL */    char *		rules;    char *		logfile;    HTLog * 		log;    char *		outputfile;    char *		host;    int			trace;    int			timer;    HTFormat		format;		        /* Input format from console */    LMFlags		flags;    HTView *		pView;    char *		userList;    CSUser_t * 		pCSUser;    BOOL		noPICSPasswords;};typedef enum _LMState {    LM_UPDATE	= 0x1,    LM_NO_UPDATE= 0x2,    LM_DONE	= 0x4,    LM_INACTIVE	= 0x8,    LM_IGNORE	= 0x10} LMState;typedef struct _Context {    LMState		state;    HTRequest *		request;    LineMode *		lm;    HTParentAnchor *	source;	   /* The source if we are using PUT or POST */} Context;PRIVATE int scan_command (SOCKET s, void * param, HTEventType type);PRIVATE HTEvent * ConsoleEvent = NULL;#ifndef WWW_WIN_WINDOWPRIVATE FILE *		OUTPUT = NULL;#endif PRIVATE InputParser_t parse_command;InputParser_t * PInputParser = &parse_command;/* Net callback handlers */PRIVATE HTNetBefore MemoryCacheFilter;PRIVATE HTNetAfter  terminate_handler;/* additions for browser update */extern HText * HTMainText;extern HTParentAnchor * HTMainAnchor;extern void LMHText_beginElement (HText * text,    int elem_num, const BOOL * present, const char ** value);extern void LMHText_endElement (HText * text, int elem_num);/* ------------------------------------------------------------------------- */PUBLIC int HTWatch(int id, void * obj, const char * fmt, ...){    va_list pArgs;    va_start(pArgs, fmt);    fprintf(stderr, "id: %x  obj: %p: ", id, obj);    return vfprintf(stderr, fmt, pArgs);}/*	Create a Context Object**	-----------------------*/PRIVATE Context * Context_new (LineMode *lm, HTRequest *request, LMState state){    Context * me;    if ((me = (Context  *) HT_CALLOC(1, sizeof (Context))) == NULL)        HT_OUTOFMEM("Context_new");    me->state = state;    me->request = request;    me->lm = lm;    HTRequest_setContext(request, (void *) me);     HTList_addObject(lm->active, (void *) me);    return me;}/*	Delete a Context Object**	-----------------------*/PRIVATE BOOL Context_delete (Context * old){    HT_FREE(old);    return YES;}PUBLIC LineMode * Context_getLineMode(HTRequest * request){    return ((Context *) HTRequest_context(request))->lm;}/***  This function creates a new request object and adds it to the global**  list of active threads*/CSDisposition_callback PICSCallback;PRIVATE HTRequest * Thread_new (LineMode * lm, BOOL Interactive, LMState state){    HTRequest * newreq = HTRequest_new();    if (!lm) return NULL;    Context_new(lm, newreq, state);    if (Interactive) HTRequest_setConversion(newreq, lm->presenters, NO);    if (lm->flags & LM_PREEMTIVE) HTRequest_setPreemptive(newreq, YES);    HTRequest_addRqHd(newreq, HT_C_HOST);    CSApp_registerReq(newreq, lm->pCSUser, PICSCallback, 		      CSApp_callOnBad, (void *)lm);    return newreq;}/***  This function deletes all unused request objects*/PRIVATE void Thread_cleanup (LineMode * lm){    if (lm && lm->active) {	HTList * cur = lm->active;	Context * pres;	while ((pres = (Context *) HTList_nextObject(cur))) {	    if (pres->state&LM_DONE && pres->state&LM_INACTIVE) {		if ((HTList_removeObject(lm->active, pres)) == NO)		    HTTRACE(APP_TRACE, "NOT FOUND\n");		HTRequest_delete(pres->request);		Context_delete(pres);		cur = lm->active;	    }	}    }}/***  This function deletes the whole list of active threads.*/PRIVATE void Thread_deleteAll (LineMode * lm){    if (lm && lm->active) {	HTList * cur = lm->active;	Context * pres;	while ((pres = (Context *) HTList_nextObject(cur))) {	    if (pres->request) {		HTRequest_delete(pres->request);		Context_delete(pres);	    }	}	HTList_delete(lm->active);	lm->active = NULL;    }}/*	Create a Line Mode Object**	-------------------------*/PRIVATE LineMode * LineMode_new (void){    LineMode * me;    if ((me = (LineMode *) HT_CALLOC(1, sizeof(LineMode))) == NULL)		HT_OUTOFMEM("LineMode_new");    me->cwd = HTGetCurrentDirectoryURL();    me->active = HTList_new();    me->console = HTRequest_new();    Context_new(me, me->console, LM_UPDATE);    me->trace = SHOW_ALL_TRACE;    me->timer = -1;    me->pCSUser = 0;    if (!(me->pView = HTView_create("'nother Window", 25, 80, me)))    	return 0;    return me;}/*	Delete a Line Mode Object**	-------------------------*/PRIVATE BOOL LineMode_delete (LineMode * lm){    if (lm) {	Thread_deleteAll(lm);	HTPresentation_deleteAll(lm->presenters);	HTHistory_delete(lm->history);	HT_FREE(lm->cwd);	if (lm->log) HTLog_close(lm->log);	if (lm->pCSUser)	    CSLoadedUser_remove(lm->pCSUser);	HTView_destroy(lm->pView);#ifndef WWW_WIN_WINDOW	if (OUTPUT && OUTPUT != stdout) fclose(OUTPUT);#endif	HText_freeAll();	/* Free all loaded documents */	HT_FREE(lm);	return YES;    }    return NO;}PUBLIC HTRequest * LineMode_getConsole(LineMode * pLm){    return pLm->console;}PUBLIC HTView * LineMode_getView(LineMode * pLm){    return pLm ? pLm->pView : 0;}PRIVATE BOOL LineMode_load(LineMode * lm, HTParentAnchor * anchor, 			   char * url, BOOL preemptive, HTRequest ** pPReq){    char * fullURL;    HTParentAnchor * pAnchor;    *pPReq = Thread_new(lm, YES, LM_UPDATE);    if (preemptive)        HTRequest_setPreemptive(*pPReq, YES);    if (anchor)	return HTLoadRelative(url, anchor, *pPReq);    fullURL = HTParse(url, lm->cwd, PARSE_ALL);    pAnchor = (HTParentAnchor *) HTAnchor_findAddress(fullURL);    HT_FREE(fullURL);    return HTLoadAnchor((HTAnchor *) pAnchor, *pPReq);}PRIVATE void Cleanup (LineMode * me, int status){    if (HTAlert_interactive())	   /* Terminate with a LF if not interactive */	OutputData(me->pView, "\n");    CSLoadedUser_deleteAll();    CSApp_unregisterApp();    LineMode_delete(me);    HTProfile_delete();#ifdef HT_MEMLOG    HTMemLog_close();#endif#ifdef VMS    exit(status ? status : 1);#else    exit(status ? status : 0);#endif}/*** Get size of the output screen. Stolen from less.*/PRIVATE void scrsize (int * p_height, int * p_width){#if defined(HAVE_IOCTL) && defined(HAVE_WINSIZE) && defined(TIOCGWINSZ)    register char *s;    /* int ioctl(); - henrik */    struct winsize w;    if (ioctl(2, TIOCGWINSZ, &w) == 0 && w.ws_row > 0)	*p_height = w.ws_row;    else if ((s = getenv("LINES")) != NULL)	*p_height = atoi(s);    else	*p_height = SCREEN_HEIGHT;        if (ioctl(2, TIOCGWINSZ, &w) == 0 && w.ws_col > 0)	*p_width = w.ws_col;    else if ((s = getenv("COLUMNS")) != NULL)	*p_width = atoi(s);    else	*p_width = 80;#else    *p_height = SCREEN_HEIGHT;    *p_width = SCREEN_WIDTH;#endif /* HAVE_IOCTL && HAVE_WINSIZE */}

⌨️ 快捷键说明

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