CTRACE(tfp, "\nsave_bookmark_link: SEEKING %s\n   AS %s\n\n", BookmarkPage, filename_buffer); if ((fp = fopen(filename_buffer, (first_time ? "w" : "a+"))) == NULL) {
CTRACE((tfp, "\nsave_bookmark_link: SEEKING %s\n   AS %s\n\n", BookmarkPage, filename_buffer)); if ((fp = fopen(filename_buffer, (first_time ? TXT_W : TXT_A))) == NULL) {
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[LY_MAXPATH];    char string_buffer[BUFSIZ];    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     */    do {	LYstrncpy(string_buffer, title, sizeof(string_buffer)-1);	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;	}    } while(!havevisible(string_buffer));    /*     *	Create the Title with any left-angle-brackets     *	converted to &lt; entities and any ampersands     *	converted to &amp; entities.  - FM     *     *  Convert 8-bit letters to &#xUUUU to avoid dependencies     *  from display character set which may need changing.     *  Do NOT convert any 8-bit chars if we have CJK display. - LP     */    StrAllocCopy(Title, string_buffer);    LYEntify(&Title, TRUE);    if (UCSaveBookmarksInUnicode &&	have8bit(Title) && (!LYHaveCJKCharacterSet)) {	char *p = title_convert8bit(Title);	FREE(Title);	Title = p;    }    /*     *	Create the bookmark file, if it doesn't exist already,     *	Otherwise, open the pre-existing bookmark file. - FM     */    SetDefaultMode(O_TEXT);    if (first_time) {	/*	 *  Seek it in the home path. - FM	 */	LYAddPathToHome(filename_buffer,			sizeof(filename_buffer),			BookmarkPage);    }    CTRACE(tfp, "\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(Title);	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     *  Once and forever...     */    if (first_time) {	fprintf(fp,"<head>\n");	LYAddMETAcharsetToFD(fp, -1);	fprintf(fp,"<title>%s</title>\n</head>\n", BOOKMARK_TITLE);	fprintf(fp, "%s<br>\n%s\n\n<!--\n%s\n-->\n\n<p>\n<ol>",		    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\     administrator."),		    gettext("\     This file also may be edited with a standard text editor to delete\n\     outdated or invalid links, or to change their order."),		    gettext("\Note: if you edit this file manually\n\      you should not change the format within the lines\n\      or add other HTML markup.\n\      Make sure any bookmark link is saved as a single line."));    }    /*     *	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);    SetDefaultMode(O_BINARY);    /*     *	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);}