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

📄 lybookmark.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "HTUtils.h"#include "tcp.h"#include "HTAlert.h"#include "LYUtils.h"#include "LYStrings.h"#include "LYBookmark.h"#include "LYGlobalDefs.h"#include "LYSignal.h"#include "LYSystem.h"#include "LYKeymap.h"#include "LYCharUtils.h"#include "LYCurses.h"#include "GridText.h"#ifdef DOSPATH#include "HTDOS.h"#endif#ifdef VMS#include "HTVMSUtils.h"#include <nam.h>extern BOOLEAN HadVMSInterrupt;	/* Flag from cleanup_sig() AST */#endif /* VMS */#include "LYLeaks.h"#define FREE(x) if (x) {free(x); x = NULL;}PUBLIC char *MBM_A_subbookmark[MBM_V_MAXFILES+1];PUBLIC char *MBM_A_subdescript[MBM_V_MAXFILES+1];PRIVATE BOOLEAN is_mosaic_hotlist = FALSE;PRIVATE char * convert_mosaic_bookmark_file PARAMS((char *filename_buffer));/* *  Tries to open a bookmark file for reading, which may be *  the default, or based on offering the user a choice from *  the MBM_A_subbookmark[] array.  If successful the file is *  closed, and the filename in system path specs is returned, *  the URL is allocated into *URL, and the MBM_A_subbookmark[] *  filepath is allocated into the BookmarkPage global.  Returns *  a zero-length pointer to flag a cancel, or a space to flag *  an undefined selection, without allocating into *URL or *  BookmarkPage.  Returns NULL with allocating into BookmarkPage *  but not *URL is the selection is valid but the file doesn't *  yet exist. - FM */PUBLIC char * get_bookmark_filename ARGS1(	char **,	URL){    char URL_buffer[256];    static char filename_buffer[256];    char string_buffer[256];    FILE *fp;    int MBM_tmp;    /*     *  Multi_Bookmarks support. - FMG & FM     *  Let user select a bookmark file.     */    MBM_tmp = select_multi_bookmarks();    if (MBM_tmp == -2)        /*	 *  Zero-length pointer flags a cancel. - FM	*/        return("");    if (MBM_tmp == -1) {	sprintf(string_buffer,		BOOKMARK_FILE_NOT_DEFINED,		key_for_func(LYK_OPTIONS));	_statusline(string_buffer);	sleep(AlertSecs);	/*	 *  Space flags an undefined selection. - FMG	 */	return(" ");    } else {        /*	 *  Save the filepath as a global.  The system path will be	 *  loaded into to the (static) filename_buffer as the return	 *  value, the URL will be allocated into *URL, and we also	 *  need the filepath available to calling functions.  This	 *  is all pitifully non-reentrant, a la the original Lynx,	 *  and should be redesigned someday. - FM	 */	StrAllocCopy(BookmarkPage, MBM_A_subbookmark[MBM_tmp]);    }    /*     *  Seek it in the home path. - FM     */    filename_buffer[255] = '\0';    LYAddPathToHome(filename_buffer,		    sizeof(filename_buffer),		    BookmarkPage);    if (TRACE)        fprintf(stderr, "\nget_bookmark_filename: SEEKING %s\n   AS %s\n\n",		BookmarkPage, filename_buffer);    if ((fp = fopen(filename_buffer,"r")) != NULL) {	goto success;    }    /*     *  Failure.     */    return(NULL);success:    /*     *  We now have the file open.     *  Check if it is a mosaic hotlist.     */    if (fgets(string_buffer, 255, fp) &&	!strncmp(string_buffer, "ncsa-xmosaic-hotlist-format-1", 29)) {	char *newname;	/*	 *  It is a mosaic hotlist file.	 */	is_mosaic_hotlist = TRUE;	fclose(fp);	newname = convert_mosaic_bookmark_file(filename_buffer);#ifdef DOSPATH	sprintf(URL_buffer, "file://localhost/%s",		HTDOS_wwwName((char *)newname));#else#ifdef VMS	sprintf(URL_buffer,"file://localhost%s",		HTVMS_wwwName((char *)newname));#else	sprintf(URL_buffer,"file://localhost%s", newname);#endif /* VMS */#endif /* DOSPATH */    } else {	fclose(fp);	is_mosaic_hotlist = FALSE;#ifdef DOSPATH        sprintf(URL_buffer,"file://localhost/%s",		HTDOS_wwwName((char *)filename_buffer));#else#ifdef VMS	sprintf(URL_buffer,"file://localhost%s",    		HTVMS_wwwName((char *)filename_buffer));#else	sprintf(URL_buffer,"file://localhost%s", filename_buffer);#endif /* VMS */#endif /* DOSPATH */     }    StrAllocCopy(*URL, URL_buffer);    return(filename_buffer);  /* bookmark file exists */} /* big end *//* *  Converts a Mosaic hotlist file into an HTML *  file for handling as a Lynx bookmark file. - FM */PRIVATE char * convert_mosaic_bookmark_file ARGS1(	char *,		filename_buffer){    static char newfile[256];    static BOOLEAN first = TRUE;    FILE *fp, *nfp;    char buf[BUFSIZ];    int line = -2;    char *endline;    if (first) {        tempname(newfile, NEW_FILE);	first = FALSE;#ifdef VMS    } else {        remove(newfile);   /* Remove duplicates on VMS. */#endif /* VMS */    }    if ((nfp = fopen(newfile, "w")) == NULL) {        LYMBM_statusline(NO_TEMP_FOR_HOTLIST);	sleep(AlertSecs);	return ("");    }    if ((fp = fopen(filename_buffer, "r")) == NULL)	return ("");  /* should always open */    fprintf(nfp,"<head>\n<title>%s</title>\n</head>\n",MOSAIC_BOOKMARK_TITLE);    fprintf(nfp,"\     This file is an HTML representation of the X Mosaic hotlist file.\n\     Outdated or invalid links may be removed by using the\n\     remove bookmark command, it is usually the 'R' key but may have\n\     been remapped by you or your system administrator.\n\n<p>\n<ol>\n");    while (fgets(buf, sizeof(buf), fp) != NULL) {	if(line >= 0) {	    endline = &buf[strlen(buf)-1];	    if(*endline == '\n')		*endline = '\0';	    if((line % 2) == 0) { /* even lines */		if(*buf != '\0') {		    strtok(buf," "); /* kill everything after the space */	            fprintf(nfp,"<LI><a href=\"%s\">",buf); /* the URL */		}	    } else { /* odd lines */	        fprintf(nfp,"%s</a>\n",buf);  /* the title */	    }	} 	/* else - ignore the line (this gets rid of first two lines) */	line++;    }    fclose(nfp);    fclose(fp);    return(newfile);}/* *  Adds a link to a bookmark file, creating the file *  if it doesn't already exist, and making sure that *  no_cache is set for a pre-existing, cached file, *  so that the change will be evident on return to *  to that file. - FM */PUBLIC void save_bookmark_link ARGS2(	char *,		address,	char *,		title){    FILE *fp;    BOOLEAN first_time = FALSE;    char *filename;    char *bookmark_URL = NULL;    char filename_buffer[256];    char string_buffer[256];    char *Address = NULL;    char *Title = NULL;    int i, c;    DocAddress WWWDoc;    HTParentAnchor *tmpanchor;    HText *text;    /*     *  Make sure we were passed something to save. - FM     */    if (!(address && *address)) {        HTAlert(MALFORMED_ADDRESS);	return;    }    /*     *  Offer a choice of bookmark files,     *  or get the default. - FMG     */    filename = get_bookmark_filename(&bookmark_URL);    /*     *  If filename is NULL, must create a new file.  If     *  filename is a space, an invalid bookmark file was     *  selected, or if zero-length, the user cancelled.     *  Ignore request in both cases.  Otherwise, make     *  a copy before anything might change the static     *  get_bookmark_filename() buffer. - FM     */    if (filename == NULL) {        first_time = TRUE;	filename_buffer[0] = '\0';    } else {        if (*filename == '\0' || !strcmp(filename," ")) {	    FREE(bookmark_URL);	    return;	}	strcpy(filename_buffer, filename);    }    /*     *  If BookmarkPage is NULL, something went     *  wrong, so ignore the request. - FM     */    if (BookmarkPage == NULL) {        FREE(bookmark_URL);	return;    }    /*     *  If the link will be added to the same     *  bookmark file, get confirmation. - FM     */    if (LYMultiBookmarks == TRUE &&        strstr(HTLoadedDocumentURL(),    	       (*BookmarkPage == '.' ?	            (BookmarkPage+1) : BookmarkPage)) != NULL) {	LYMBM_statusline(MULTIBOOKMARKS_SELF);	c = LYgetch();	if (TOUPPER(c) != 'L') {	    FREE(bookmark_URL);	    return;	}    }    /*     *  Allow user to change the title. - FM     */    string_buffer[255] = '\0';    LYstrncpy(string_buffer, title, 255);    convert_to_spaces(string_buffer, FALSE);    LYMBM_statusline(TITLE_PROMPT);    LYgetstr(string_buffer, VISIBLE, sizeof(string_buffer), NORECALL);    if (*string_buffer == '\0') {	LYMBM_statusline(CANCELLED);	sleep(MessageSecs);	FREE(bookmark_URL);	return;    }    /*     *  Create the Title with any left-angle-brackets     *  converted to &lt; entities and any ampersands     *  converted to &amp; entities.  - FM     */    StrAllocCopy(Title, string_buffer);    LYEntify(&Title, TRUE);    /*     *  Create the bookmark file, if it doesn't exist already,     *  Otherwise, open the pre-existing bookmark file. - FM     */#if defined(__DJGPP__) || defined(_WINDOWS)	_fmode = O_TEXT;#endif /* __DJGPP__  or _WINDOWS */    if (first_time) {        /*	 *  Seek it in the home path. - FM	 */	LYAddPathToHome(filename_buffer,			sizeof(filename_buffer),			BookmarkPage);    }    if (TRACE)        fprintf(stderr, "\nsave_bookmark_link: SEEKING %s\n   AS %s\n\n",		BookmarkPage, filename_buffer);    if ((fp = fopen(filename_buffer, (first_time ? "w" : "a+"))) == NULL) {	LYMBM_statusline(BOOKMARK_OPEN_FAILED);	sleep(AlertSecs);	FREE(bookmark_URL);	return;    }    /*     *  Convert all ampersands in the address to &amp; entities. - FM     */    StrAllocCopy(Address, address);    LYEntify(&Address, FALSE);    /*     *  If we created a new bookmark file, write the headers. - FM     */    if (first_time) {	fprintf(fp,"<head>\n");	LYAddMETAcharsetToFD(fp, -1);	fprintf(fp,"<title>%s</title>\n</head>\n",BOOKMARK_TITLE);	fprintf(fp,"\     You can delete links using the remove bookmark command.  It is usually\n\     the 'R' key but may have been remapped by you or your system\n\     administrator.<br>\n\     This file also may be edited with a standard text editor to delete\n\     outdated or invalid links, or to change their order, but you should\n\     not change the format within the lines or add other HTML markup.\n\n\     <p>\n<ol>\n");    }    /*     *  Add the bookmark link, in Mosaic hotlist or Lynx format. - FM     */    if (is_mosaic_hotlist) {	time_t NowTime = time(NULL);	char *TimeString = (char *)ctime (&NowTime);	/*	 *  TimeString has a \n at the end.	 */	fprintf(fp,"%s %s%s\n", Address, TimeString, Title);    } else {	fprintf(fp,"<LI><a href=\"%s\">%s</a>\n", Address, Title);    }    fclose(fp);#if defined(__DJGPP__) || defined(_WINDOWS)    _fmode = O_BINARY;#endif /* __DJGPP__ or _WINDOWS */    /*     *  If this is a cached bookmark file, set nocache for     *  it so we'll see the new bookmark link when that     *  cache is retrieved. - FM     */    if (!first_time && nhist > 0 && bookmark_URL) {    	for (i = 0; i < nhist; i++) {	    if (history[i].bookmark &&	    	!strcmp(history[i].address, bookmark_URL)) {		WWWDoc.address = history[i].address;		WWWDoc.post_data = NULL;		WWWDoc.post_content_type = NULL;		WWWDoc.bookmark = history[i].bookmark;		WWWDoc.isHEAD = FALSE;		WWWDoc.safe = FALSE;		if (((tmpanchor = HTAnchor_parent(					HTAnchor_findAddress(&WWWDoc)				    		 )) != NULL) &&		    (text = (HText *)HTAnchor_document(tmpanchor)) != NULL) {		    HText_setNoCache(text);		}		break;	    }	}    }    /*     *  Clean up and report success.     */    FREE(Title);    FREE(Address);    FREE(bookmark_URL);    LYMBM_statusline(OPERATION_DONE);    sleep(MessageSecs);}	/* *  Remove a link from a bookmark file.  The calling *  function is expected to have used get_filename_link(), *  pass us the link number as cur, the MBM_A_subbookmark[] *  string as cur_bookmark_page, and to have set up no_cache *  itself. - FM */PUBLIC void remove_bookmark_link ARGS2(	int,		cur,	char *,		cur_bookmark_page){    FILE *fp, *nfp;    char buf[BUFSIZ];    int n;#ifdef VMS    char filename_buffer[NAM$C_MAXRSS+12];    char newfile[NAM$C_MAXRSS+12];#else    char filename_buffer[256];    char newfile[256];    struct stat stat_buf;    mode_t mode;#endif /* VMS */    if (TRACE)	fprintf(stderr, "remove_bookmark_link: deleting link number: %d\n",			cur);    if (!cur_bookmark_page)	return;    LYAddPathToHome(filename_buffer,		    sizeof(filename_buffer),		    cur_bookmark_page);    if (TRACE)        fprintf(stderr, "\nremove_bookmark_link: SEEKING %s\n   AS %s\n\n",		cur_bookmark_page, filename_buffer);    if ((fp = fopen(filename_buffer, "r")) == NULL) {	_statusline(BOOKMARK_OPEN_FAILED_FOR_DEL);	sleep(AlertSecs);	return;

⌨️ 快捷键说明

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