[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
LYNX-DEV Patch to LYBookmark 2-7-1
From: |
Denis N. Antonioli |
Subject: |
LYNX-DEV Patch to LYBookmark 2-7-1 |
Date: |
Fri, 19 Dec 1997 14:53:26 +0100 (MET) |
-----BEGIN PGP SIGNED MESSAGE-----
Hi,
I've found two good things in Netscape's Navigator: its bookmark
editor and the idea to add new bookmarks in a user specified place
instead of just appending them at the end. So here is a small patch
to add the 2nd feature to my favorite browser.
This is a patch against stock 2-7-1 distribution; it modifies
userdefs.h, LYMessages_en.h and src/LYBookmark.c.
When patched, lynx looks for the qualifier 'NEWITEMHEADER' in a
H3 header and write the new link one line after that. If this fail
for any reason, lynx falls back to the old code.
This feature is a compile time option, controlled by the
NEWITEMHEADER_SUPPORT value in userdefs.h
Comments and corrections welcome, inclusion in the distribution
would be considered an honor ;-)
Greetings,
Denis N. Antonioli
- --
My general attitude towards garbage collectors is that people ought
to pick up after themselves and not expect their mother to do it.
-- Larry Wall
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: latin1
iQCVAwUBNJp8XH7lXFr6ofWlAQEkaAP/VGnuwwX2OzAUJWZFz2DMbVNi2gdG7Owi
YNfGRY2mYun8R432DCKxU85TLJGg9pcGcO305ctu5x/VgN2BoHGdu317sqYMEREB
6jCAHU5XvvChX44MCI2McLBc6HlFZavEZ/JX3wbUYD16NW1r8nt/Mxi56V0reLW3
+WV/dj+1agA=
=6//G
-----END PGP SIGNATURE-----
*** userdefs.h.orig Fri Dec 19 10:16:49 1997
--- userdefs.h Fri Dec 19 10:21:08 1997
***************
*** 596,601 ****
--- 596,609 ----
#define BLOCK_MULTI_BOOKMARKS FALSE
#endif /* BLOCK_MULTI_BOOKMARKS */
+ /*****************************
+ * If NEWITEMHEADER_SUPPORT is set TRUE, lynx will try to insert
+ * new links in what Netscape's Navigator calls the 'New Folder'.
+ */
+ #ifndef NEWITEMHEADER_SUPPORT
+ #define NEWITEMHEADER_SUPPORT TRUE
+ #endif /* NEWITEMHEADER_SUPPORT */
+
/********************************
* URL_DOMAIN_PREFIXES and URL_DOMAIN_SUFFIXES are strings which will be
* prepended (together with a scheme://) and appended to the first element
*** LYMessages_en.h.orig Fri Dec 19 09:58:23 1997
--- LYMessages_en.h Fri Dec 19 10:03:38 1997
***************
*** 200,215 ****
--- 200,222 ----
#ifdef VMS
#define BOOKSCRA_OPEN_FAILED_FOR_DEL \
"Unable to open scratch file for deletion of link."
+ #define BOOKSCRA_OPEN_FAILED_FOR_INS \
+ "Unable to open scratch file for insertion of link."
#define ERROR_RENAMING_SCRA "Error renaming scratch file."
#else
#define BOOKTEMP_OPEN_FAILED_FOR_DEL \
"Unable to open temporary file for deletion of link."
+ #define BOOKTEMP_OPEN_FAILED_FOR_INS \
+ "Unable to open temporary file for insertion of link."
#define ERROR_RENAMING_TEMP "Error renaming temporary file."
#define BOOKTEMP_REOPEN_FAIL_FOR_DEL \
"Unable to reopen temporary file for deletion of link."
+ #define BOOKTEMP_REOPEN_FAIL_FOR_INS \
+ "Unable to reopen temporary file for insertion of link."
#endif /* VMS */
#define BOOKMARK_LINK_NOT_ONE_LINE \
"Link is not by itself all on one line in bookmark file."
+ #define BOOKMARK_INS_NIH_FAILED "Smart bookmark insertion failed."
#define BOOKMARK_DEL_FAILED "Bookmark deletion failed."
#define BOOKMARKS_NOT_TRAVERSED \
"Bookmark files cannot be traversed (only http URLs)."
*** src/LYBookmark.c.orig Fri Dec 19 08:55:35 1997
--- src/LYBookmark.c Fri Dec 19 10:18:58 1997
***************
*** 24,30 ****
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
--- 24,36 ----
PRIVATE BOOLEAN is_mosaic_hotlist=FALSE;
PRIVATE char * convert_mosaic_bookmark_file PARAMS((char *filename_buffer));
! #ifdef NEWITEMHEADER_SUPPORT
! PRIVATE BOOLEAN insert_bookmark PARAMS((
! char *filename_buffer,
! char *Address,
! char *Title
! ));
! #endif
/*
* Tries to open a bookmark file for reading, which may be
* the default, or based on offering the user a choice from
***************
*** 304,309 ****
--- 310,321 ----
LYEntify(&Title, TRUE);
/*
+ * Convert all ampersands in the address to & entities. - FM
+ */
+ StrAllocCopy(Address, address);
+ LYEntify(&Address, FALSE);
+
+ /*
* Create the bookmark file, if it doesn't exist already,
* Otherwise, open the pre-existing bookmark file. - FM
*/
***************
*** 318,367 ****
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 & 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<title>%s</title>\n</head>\n",BOOKMARK_TITLE);
! fprintf(fp,"\
! You can delete links using the remove bookmark command. It\n\
! is usually the 'R' key but may have been remapped by you or\n\
! your system administrator.<br>\n\
! This file may also be edited with a standard text editor.\n\
! Outdated or invalid links may be removed by simply deleting\n\
! the line the link appears on in this file.\n\
! Please refer to the Lynx documentation or help files\n\
! for the HTML link syntax.\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 this is a cached bookmark file, set nocache for
* it so we'll see the new bookmark link when that
--- 330,380 ----
if (TRACE)
fprintf(stderr, "\nsave_bookmark_link: SEEKING %s\n AS %s\n\n",
BookmarkPage, filename_buffer);
! #ifdef NEWITEMHEADER_SUPPORT
! if (first_time || is_mosaic_hotlist
! || !insert_bookmark(filename_buffer, Address, Title)) {
! #endif
! if ((fp = fopen(filename_buffer, (first_time ? "w" : "a+"))) == NULL)
{
! LYMBM_statusline(BOOKMARK_OPEN_FAILED);
! sleep(AlertSecs);
! FREE(bookmark_URL);
! return;
! }
! /*
! * If we created a new bookmark file, write the headers. - FM
! */
! if (first_time) {
!
fprintf(fp,"<head>\n<title>%s</title>\n</head>\n",BOOKMARK_TITLE);
! fprintf(fp,"\
! You can delete links using the remove bookmark command. It\n\
! is usually the 'R' key but may have been remapped by you or\n\
! your system administrator.<br>\n\
! This file may also be edited with a standard text editor.\n\
! Outdated or invalid links may be removed by simply deleting\n\
! the line the link appears on in this file.\n\
! Please refer to the Lynx documentation or help files\n\
! for the HTML link syntax.\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);
+ #ifdef NEWITEMHEADER_SUPPORT
+ }
+ #endif
/*
* If this is a cached bookmark file, set nocache for
* it so we'll see the new bookmark link when that
***************
*** 397,403 ****
LYMBM_statusline(OPERATION_DONE);
sleep(MessageSecs);
}
!
/*
* Remove a link from a bookmark file. The calling
* function is expected to have used get_filename_link(),
--- 410,554 ----
LYMBM_statusline(OPERATION_DONE);
sleep(MessageSecs);
}
!
! #ifdef NEWITEMHEADER_SUPPORT
! PRIVATE BOOLEAN insert_bookmark ARGS3(
! char *, filename_buffer,
! char *, Address,
! char *, Title
! )
! {
! FILE *fp, *nfp;
! char buf[BUFSIZ];
! #ifdef VMS
! char newfile[NAM$C_MAXRSS+12];
! #else
! char newfile[256];
! struct stat stat_buf;
! #endif /* VMS */
!
! if ((fp = fopen(filename_buffer, "r")) == NULL)
! return FALSE;
!
! #ifdef VMS
! sprintf(newfile, "%s-%d", filename_buffer, getpid());
! #else
! tempname(newfile, NEW_FILE);
! #endif /* VMS */
! if ((nfp = fopen(newfile, "w")) == NULL) {
! fclose(fp);
! #ifdef VMS
! _statusline(BOOKSCRA_OPEN_FAILED_FOR_INS);
! #else
! _statusline(BOOKTEMP_OPEN_FAILED_FOR_INS);
! #endif /* VMS */
! sleep(AlertSecs);
! return FALSE;
! }
!
! #ifndef VMS
! /*
! * Explicitly preserve bookmark file mode on Unix. - DSL
! */
! if (stat(filename_buffer, &stat_buf) == 0) {
! mode_t mode = ((stat_buf.st_mode & 0777) | 0600);
! (void) fclose(nfp);
! nfp = NULL;
! (void) chmod(newfile, mode);
! if ((nfp = fopen(newfile, "a")) == NULL) {
! (void) fclose(fp);
! _statusline(BOOKTEMP_REOPEN_FAIL_FOR_INS);
! sleep(AlertSecs);
! return FALSE;
! }
! }
! #endif /* !VMS */
!
! while (fgets(buf, sizeof(buf), fp) != NULL) {
! char *cp = buf;
! BOOLEAN found = FALSE;
! /* \s*<DT><H? NEWITEMHEADER>...<\H?> */
! while (*cp && *cp < 0x21) cp++;
! if (cp == LYstrstr(cp, "<dt><h")) {
! char *nih;
! cp += 6;
! nih = LYstrstr(cp, "newitemheader");
! if (nih > cp && nih < LYstrstr(cp, ">")) {
! /* write the NEWITEMHEADER line, read the <DL> line that follow */
! if (fputs(buf, nfp) == EOF || fgets(buf, sizeof(buf), fp) == NULL)
! goto failure;
! found = TRUE;
! }
! }
! if (fputs(buf, nfp) == EOF)
! goto failure;
! if (found) {
! if (fprintf(nfp,"<DT><a href=\"%s\">%s</a>\n", Address, Title) ==
EOF)
! goto failure;
! break;
! }
! }
! while (fgets(buf, sizeof(buf), fp) != NULL) {
! if (fputs(buf, nfp) == EOF)
! goto failure;
! }
!
! fclose(fp);
! fp = NULL;
! fclose(nfp);
! nfp = NULL;
!
! if (rename(newfile, filename_buffer) != -1) {
! #ifdef VMS
! char VMSfilename[256];
! /*
! * Purge lower version of file.
! */
! sprintf(VMSfilename, "%s;-1", filename_buffer);
! while (remove(VMSfilename) == 0)
! ;
! /*
! * Reset version number.
! */
! sprintf(VMSfilename, "%s;1", filename_buffer);
! rename(filename_buffer, VMSfilename);
! #endif /* VMS */
! return TRUE;
! } else {
! #ifndef VMS
! /*
! * Rename won't work across file systems.
! * Check if this is the case and do something appropriate.
! * Used to be ODD_RENAME
! */
! if (errno == EXDEV) {
! char buffer[2048];
! sprintf(buffer, "%s %s %s", MV_PATH, newfile, filename_buffer);
! system(buffer);
! return TRUE;
! }
! #endif /* !VMS */
!
! #ifdef VMS
! _statusline(ERROR_RENAMING_SCRA);
! #else
! _statusline(ERROR_RENAMING_TEMP);
! #endif /* VMS */
! sleep(AlertSecs);
! }
!
! failure:
! _statusline(BOOKMARK_INS_NIH_FAILED);
! sleep(AlertSecs);
! if (nfp != NULL)
! fclose(nfp);
! if (fp != NULL)
! fclose(fp);
! remove(newfile);
! return FALSE;
! }
! #endif
!
/*
* Remove a link from a bookmark file. The calling
* function is expected to have used get_filename_link(),
- LYNX-DEV Patch to LYBookmark 2-7-1,
Denis N. Antonioli <=