From 09edd94f131ec64c31b17cb3a26fa0a8069af9c6 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Tue, 26 Jul 2022 14:39:20 +0000 Subject: snapshot of project "lynx", label v2-9-0dev_10k --- src/LYBookmark.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++-------- src/LYUtils.c | 7 +++---- 2 files changed, 50 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/LYBookmark.c b/src/LYBookmark.c index 47531b13..69622d4a 100644 --- a/src/LYBookmark.c +++ b/src/LYBookmark.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYBookmark.c,v 1.81 2022/04/02 00:12:18 Paul.G.Fox Exp $ + * $LynxId: LYBookmark.c,v 1.86 2022/07/26 14:39:20 tom Exp $ */ #include #include @@ -17,6 +17,10 @@ #include #include +#ifdef _WINDOWS +#include /* for _chsize() */ +#endif + #ifdef VMS #include #endif /* VMS */ @@ -176,10 +180,10 @@ static const char *convert_mosaic_bookmark_file(const char *filename_buffer) if ((line % 2) == 0) { /* even lines */ if (*buf != '\0') { strtok(buf, " "); /* kill everything after the space */ - fprintf(nfp, "
  • ", buf); /* the URL */ + fprintf(nfp, "
  • ", buf); /* the URL */ } } else { /* odd lines */ - fprintf(nfp, "%s\n", buf); /* the title */ + fprintf(nfp, "%s
  • \n", buf); /* the title */ } } /* else - ignore the line (this gets rid of first two lines) */ @@ -194,6 +198,10 @@ static BOOLEAN havevisible(const char *Title); static BOOLEAN have8bit(const char *Title); static char *title_convert8bit(const char *Title); +#ifdef _WINDOWS +#define ftruncate(fd, len) _chsize(fd, len) +#endif + /* * 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, @@ -358,28 +366,58 @@ void save_bookmark_link(const char *address, StrAllocCopy(Address, address); LYEntify(&Address, FALSE); + if (!first_time) { + BOOLEAN empty_file = TRUE; + FILE *bp = tmpfile(); + char *buffer = NULL; + + while (LYSafeGets(&buffer, fp)) { + empty_file = FALSE; + if (LYstrstr(buffer, "")) + break; + fprintf(bp, "%s", buffer); + } + + fflush(bp); + rewind(bp); + + rewind(fp); + ftruncate(fileno(fp), 0); + + while (LYSafeGets(&buffer, bp)) { + fprintf(fp, "%s", buffer); + } + fclose(bp); + + if (empty_file) + first_time = TRUE; + } + /* * If we created a new bookmark file, write the headers. - FM * Once and forever... */ if (first_time) { + fprintf(fp, "%s\n", LYNX_DOCTYPE); + fprintf(fp, "\n"); fprintf(fp, "\n"); #if defined(SH_EX) && !defined(_WINDOWS) /* 1997/12/11 (Thu) 19:13:40 */ if (HTCJK != JAPANESE) LYAddMETAcharsetToFD(fp, -1); else - fprintf(fp, "\n", + fprintf(fp, "\n", "http-equiv=\"content-type\"", "content=\"" STR_HTML ";charset=iso-2022-jp\""); #else LYAddMETAcharsetToFD(fp, -1); #endif /* !_WINDOWS */ fprintf(fp, "%s\n\n", BOOKMARK_TITLE); + fprintf(fp, "\n"); #ifdef _WINDOWS - fprintf(fp, + fprintf(fp, "

    %s", gettext(" You can delete links by the 'R' key
    \n

      \n")); #else - fprintf(fp, "%s
      \n%s\n\n\n\n

      \n

        \n", + fprintf(fp, "

        %s
        \n%s\n\n

        \n\n
          \n", gettext("\ 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\ @@ -407,7 +445,8 @@ Note: if you edit this file manually\n\ */ fprintf(fp, "%s %s%s\n", Address, TimeString, Title); } else { - fprintf(fp, "
        1. %s\n", Address, Title); + fprintf(fp, "
        2. %s
        3. \n", Address, Title); + fprintf(fp, "
        \n"); } LYCloseOutput(fp); @@ -536,7 +575,7 @@ void remove_bookmark_link(int cur, retain = TRUE; seen = 0; cp = buf; - if ((cur == 0) && LYstrstr(cp, "
        1. ")) + if ((cur == 0) && LYstrstr(cp, "
          1. ")) keep_ol = TRUE; /* Do not erase, this corrects a bug in an older version */ while (n < cur && (cp = LYstrstr(cp, "\n" #define PUT_STRING(buf) (*(target)->isa->put_string)(target, buf) /* @@ -6823,7 +6822,7 @@ void WriteStreamTitle(HTStream *target, const char *Title) { char *buf = 0; - PUT_STRING(MY_DOCTYPE); + PUT_STRING(LYNX_DOCTYPE); PUT_STRING("\n\n"); LYAddMETAcharsetToStream(target, -1); HTSprintf0(&buf, "%s\n\n\n", Title); @@ -6857,7 +6856,7 @@ FILE *InternalPageFP(char *filename, */ void WriteInternalTitle(FILE *fp0, const char *Title) { - fprintf(fp0, MY_DOCTYPE); + fprintf(fp0, LYNX_DOCTYPE); fprintf(fp0, "\n\n"); LYAddMETAcharsetToFD(fp0, -1); -- cgit 1.4.1-2-gfad0