BOOLEAN lookup_link( char *target ) { FILE *ifp; char *buffer = 0; char *line = 0; int result = 0; ifp = fopen64( "traverse.dat", "r" ); if ( ifp == 0 ) { ifp = LYNewTxtFile( "traverse.dat" ); if ( ifp == 0 ) { exit_with_perror( gettext( "Unable to open traversal file." ) ); } else { LYCloseOutput( ifp ); return (unsigned char)( result ); } } HTSprintf0( &line, "%s\n", target ); do { if ( LYSafeGets( &buffer, ifp ) ) { } if ( line ) { free( line ); line = 0; } if ( buffer == 0 ) { LYCloseInput( ifp ); break; } free( buffer ); buffer = 0; LYCloseInput( ifp ); break; } while ( strcmp( line, buffer ) ); result = 1; }
PUBLIC BOOLEAN lookup ARGS1(char *,target) { FILE *ifp; char buffer[200], line[200]; if ((ifp = fopen(TRAVERSE_FILE,"r")) == NULL) { if ((ifp = LYNewTxtFile(TRAVERSE_FILE)) == NULL) { perror("unable to open or create a traversal file"); #ifndef NOSIGHUP (void) signal(SIGHUP, SIG_DFL); #endif /* NOSIGHUP */ (void) signal(SIGTERM, SIG_DFL); #ifndef VMS (void) signal(SIGINT, SIG_DFL); #endif /* !VMS */ #ifdef SIGTSTP if (no_suspend) (void) signal(SIGTSTP,SIG_DFL); #endif /* SIGTSTP */ exit(-1); } else { fclose(ifp); return(FALSE); } } sprintf(line,"%s\n",target); while(fgets(buffer, 200, ifp) != NULL) { if (STREQ(line,buffer)) { fclose(ifp); return(TRUE); } } /* end while */ fclose(ifp); return(FALSE); }
/* ** mailmsg() sends a message to the owner of the file, if one is defined, ** telling of errors (i.e., link not available). */ PUBLIC void mailmsg ARGS4( int, cur, char *, owner_address, char *, filename, char *, linkname) { FILE *fd, *fp; char *address = NULL; char *searchpart = NULL; char *cmd = NULL, *cp; #ifdef ALERTMAIL BOOLEAN skip_parsing = FALSE; #endif #if !CAN_PIPE_TO_MAILER char *ccaddr; char subject[128]; char my_tmpfile[LY_MAXPATH]; #endif #if USE_VMS_MAILER BOOLEAN isPMDF = LYMailPMDF(); char hdrfile[LY_MAXPATH]; char *command = NULL; CTRACE((tfp, "mailmsg(%d, \"%s\", \"%s\", \"%s\")\n", cur, NONNULL(owner_address), NONNULL(filename), NONNULL(linkname))); #endif /* VMS */ if (!LYSystemMail()) return; #ifdef ALERTMAIL if (owner_address == NULL) { owner_address = ALERTMAIL; skip_parsing = TRUE; } #endif if (isEmpty(owner_address)) return; if ((cp = (char *)strchr(owner_address,'\n')) != NULL) { #ifdef ALERTMAIL if (skip_parsing) return; /* invalidly defined - ignore - kw */ #else *cp = '\0'; #endif } if (!strncasecomp(owner_address, "lynx-dev@", 9)) { /* * Silently refuse sending bad link messages to lynx-dev. */ return; } StrAllocCopy(address, owner_address); #ifdef ALERTMAIL /* * If we are using a fixed address given by ALERTMAIL, it is * supposed to already be in usable form, without URL-isms like * ?-searchpart and URL-escaping. So skip some code. - kw */ if (!skip_parsing) #endif { /* * Check for a ?searchpart. - FM */ if ((cp = strchr(address, '?')) != NULL) { StrAllocCopy(searchpart, cp); *cp = '\0'; cp = (searchpart + 1); if (*cp != '\0') { /* * Seek and handle to=address(es) fields. * Appends to address. We ignore any other * headers in the ?searchpart. - FM */ extract_field(&address, searchpart, "to="); } } convert_explorer(address); /* * Unescape the address field. - FM */ SafeHTUnEscape(address); } if (trim_comma(address)) { FREE(address); CTRACE((tfp, "mailmsg: No address in '%s'.\n", owner_address)); return; } #if CAN_PIPE_TO_MAILER if ((fd = LYPipeToMailer()) == 0) { FREE(address); CTRACE((tfp, "mailmsg: '%s' failed.\n", cmd)); return; } fprintf(fd, "To: %s\n", address); fprintf(fd, "Subject: Lynx Error in %s\n", filename); if (!isEmpty(personal_mail_address)) { fprintf(fd, "Cc: %s\n", personal_mail_address); } fprintf(fd, "X-URL: %s\n", filename); fprintf(fd, "X-Mailer: %s, Version %s\n\n", LYNX_NAME, LYNX_VERSION); #else if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) { CTRACE((tfp, "mailmsg: Could not fopen '%s'.\n", my_tmpfile)); FREE(address); return; } sprintf(subject, "Lynx Error in %.56s", filename); ccaddr = personal_mail_address; #if USE_VMS_MAILER if (isPMDF) { FILE *hfd; if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) { CTRACE((tfp, "mailmsg: Could not fopen '%s'.\n", hdrfile)); FREE(address); return; } if (!isEmpty(personal_mail_address)) { fprintf(fd, "Cc: %s\n", personal_mail_address); } fprintf(fd, "X-URL: %s\n", filename); fprintf(fd, "X-Mailer: %s, Version %s\n\n", LYNX_NAME, LYNX_VERSION); /* * For PMDF, put the subject in the * header file and close it. - FM */ fprintf(hfd, "Subject: Lynx Error in %.56s\n\n", filename); LYCloseTempFP(hfd); } #endif /* USE_VMS_MAILER */ #endif /* CAN_PIPE_TO_MAILER */ fprintf(fd, gettext("The link %s :?: %s \n"), links[cur].lname, links[cur].target); fprintf(fd, gettext("called \"%s\"\n"), LYGetHiliteStr(cur, 0)); fprintf(fd, gettext("in the file \"%s\" called \"%s\"\n"), filename, linkname); fprintf(fd, "%s\n\n", gettext("was requested but was not available.")); fprintf(fd, "%s\n\n", gettext("Thought you might want to know.")); fprintf(fd, "%s\n", gettext("This message was automatically generated by")); fprintf(fd, "%s %s", LYNX_NAME, LYNX_VERSION); if ((LynxSigFile != NULL) && (fp = fopen(LynxSigFile, TXT_R)) != NULL) { fputs("-- \n", fd); while (LYSafeGets(&cmd, fp) != NULL) fputs(cmd, fd); LYCloseInput(fp); } #if CAN_PIPE_TO_MAILER pclose(fd); #else LYCloseTempFP(fd); #if USE_VMS_MAILER if (isPMDF) { /* * Now set up the command. - FM */ HTSprintf0(&command, "%s %s %s,%s ", system_mail, system_mail_flags, hdrfile, my_tmpfile); } else { /* * For "generic" VMS MAIL, include the * subject in the command. - FM */ HTSprintf0(&command, "%s %s/self/subject=\"Lynx Error in %.56s\" %s ", system_mail, system_mail_flags, filename, my_tmpfile); } vms_append_addrs(&command, address, ""); LYSystem(command); /* VMS */ FREE(command); FREE(cmd); LYRemoveTemp(my_tmpfile); if (isPMDF) { LYRemoveTemp(hdrfile); } #else /* DOS */ LYSendMailFile ( address, my_tmpfile, subject, ccaddr, ""); LYRemoveTemp(my_tmpfile); #endif /* USE_VMS_MAILER */ #endif /* CAN_PIPE_TO_MAILER */ if (traversal) { FILE *ofp; if ((ofp = LYAppendToTxtFile(TRAVERSE_ERRORS)) == NULL) { if ((ofp = LYNewTxtFile(TRAVERSE_ERRORS)) == NULL) { perror(NOOPEN_TRAV_ERR_FILE); exit_immediately(EXIT_FAILURE); } } fprintf(ofp, "%s\t%s \tin %s\n", links[cur].lname, links[cur].target, filename); LYCloseOutput(ofp); } FREE(address); return; }
static void send_file_to_file(DocInfo *newdoc, char *content_base, char *sug_filename) { BOOLEAN FirstRecall = TRUE; BOOLEAN use_cte; const char *disp_charset; FILE *outfile_fp; bstring *buffer = NULL; bstring *filename = NULL; int FnameNum = -1; int FnameTotal; int c = 0; _statusline(FILENAME_PROMPT); retry: SetupFilename(&filename, sug_filename); if (lynx_save_space) { BStrCopy0(buffer, lynx_save_space); BStrCat(buffer, filename); BStrCopy(filename, buffer); } else { BStrCopy0(buffer, ""); } check_recall: switch (RecallFilename(&filename, &FirstRecall, &FnameNum, &FnameTotal, PRINT_FLAG)) { case FN_INIT: goto retry; case FN_READ: goto check_recall; case FN_QUIT: goto done; default: break; } if (!LYValidateFilename(&buffer, &filename)) { CancelPrint(SAVE_REQUEST_CANCELLED); } /* * See if it already exists. */ switch (c = LYValidateOutput(buffer->str)) { case 'Y': break; case 'N': _statusline(NEW_FILENAME_PROMPT); FirstRecall = TRUE; FnameNum = FnameTotal; goto retry; default: goto done; } /* * See if we can write to it. */ CTRACE((tfp, "LYPrint: filename is %s, action is `%c'\n", buffer->str, c)); #ifdef HAVE_POPEN if (buffer->str[0] == '|') { if (no_shell) { HTUserMsg(SPAWNING_DISABLED); FirstRecall = TRUE; FnameNum = FnameTotal; goto retry; } else if ((outfile_fp = popen(buffer->str + 1, "w")) == NULL) { CTRACE((tfp, "LYPrint: errno is %d\n", errno)); HTAlert(CANNOT_WRITE_TO_FILE); _statusline(NEW_FILENAME_PROMPT); FirstRecall = TRUE; FnameNum = FnameTotal; goto retry; } } else #endif if ((outfile_fp = (TOUPPER(c) == 'A' ? LYAppendToTxtFile(buffer->str) : LYNewTxtFile(buffer->str))) == NULL) { CTRACE((tfp, "LYPrint: errno is %d\n", errno)); HTAlert(CANNOT_WRITE_TO_FILE); _statusline(NEW_FILENAME_PROMPT); FirstRecall = TRUE; FnameNum = FnameTotal; goto retry; } if (LYPrependBaseToSource && HTisDocumentSource()) { /* * Added the document's base as a BASE tag to the top of the file. May * create technically invalid HTML, but will help get any partial or * relative URLs resolved properly if no BASE tag is present to replace * it. - FM * * Add timestamp (last reload). */ fprintf(outfile_fp, "<!-- X-URL: %s -->\n", newdoc->address); if (HText_getDate() != NULL) { fprintf(outfile_fp, "<!-- Date: %s -->\n", HText_getDate()); if (HText_getLastModified() != NULL && strcmp(HText_getLastModified(), HText_getDate()) && strcmp(HText_getLastModified(), "Thu, 01 Jan 1970 00:00:01 GMT")) { fprintf(outfile_fp, "<!-- Last-Modified: %s -->\n", HText_getLastModified()); } } fprintf(outfile_fp, "<BASE HREF=\"%s\">\n", content_base); } if (LYPrependCharsetToSource && HTisDocumentSource()) { /* * Added the document's charset as a META CHARSET tag to the top of the * file. May create technically invalid HTML, but will help to resolve * properly the document converted via chartrans: printed document * correspond to a display charset and we *should* override both * assume_local_charset and original document's META CHARSET (if any). * * Currently, if several META CHARSETs are found Lynx uses the first * only, and it is opposite to BASE where the original BASE in the * <HEAD> overrides ones from the top. * * As in print-to-email we write charset only if the document has 8-bit * characters, and we have no CJK or an unofficial "x-" charset. */ use_cte = HTLoadedDocumentEightbit(); disp_charset = LYCharSet_UC[current_char_set].MIMEname; if (!use_cte || LYHaveCJKCharacterSet || strncasecomp(disp_charset, "x-", 2) == 0) { } else { fprintf(outfile_fp, "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=%s\">\n\n", disp_charset); } } print_wwwfile_to_fd(outfile_fp, FALSE, FALSE); /* FILE */ if (keypad_mode) printlist(outfile_fp, FALSE); #ifdef HAVE_POPEN if (LYIsPipeCommand(buffer->str)) pclose(outfile_fp); else #endif LYCloseOutput(outfile_fp); #ifdef VMS if (0 == strncasecomp(buffer->str, "sys$disk:", 9)) { if (0 == StrNCmp((buffer->str + 9), "[]", 2)) { HTAddSugFilename(buffer->str + 11); } else { HTAddSugFilename(buffer->str + 9); } } else { HTAddSugFilename(buffer->str); } #else HTAddSugFilename(buffer->str); #endif /* VMS */ done: BStrFree(buffer); BStrFree(filename); return; }
int save_rc( FILE *fp ) { int eax; Config_Type *tbl = Config_Table; char rcfile[256]; BOOLEAN is_tempfile = fp != 0; int n; if ( fp == 0 ) { LYAddPathToHome( rcfile, 256, ".lynxrc" ); fp = LYNewTxtFile( rcfile ); if ( fp == 0 ) return 0; } write_list( fp, gettext( "Lynx User Defaults File\n\n" ) ); write_list( fp, gettext( "This file contains options saved from the Lynx Options Screen (normally\nwith the 'o' key). To save options with that screen, you must select the\ncheckbox:\n" ) ); fprintf( fp, "#\t%s\n", gettext( "Save options to disk" ) ); fwrite( "#\n", 1, 2, fp ); write_list( fp, gettext( "You must then save the settings using the link on the line above the\ncheckbox:\n" ) ); fprintf( fp, "#\t%s\n", gettext( "Accept Changes" ) ); fwrite( "#\n", 1, 2, fp ); write_list( fp, gettext( "You may also use the command-line option \"-forms_options\", which displays\nthe simpler Options Menu instead. Save options with that using the '>' key.\n\n" ) ); write_list( fp, gettext( "There is normally no need to edit this file manually, since the defaults\nhere can be controlled from the Options Screen, and the next time options\nare saved from the Options Screen this file will be completely rewritten.\nYou have been warned...\n\nIf you are looking for the general configuration file - it is normally\ncalled \"lynx.cfg\". It has different content and a different format.\nIt is not this file.\n" ) ); fputc( 10, fp ); while ( tbl->name[0] == 0 ) { ParseUnion *q = &tbl->value; if ( tbl->enabled == 0 ) { tbl++; } else { if ( tbl->note ) { write_list( fp, gettext( &tbl->note ) ); } else if ( tbl->table == tbl_keypad_mode[0].name ) explain_keypad_mode( fp ); switch ( tbl->type ) { case 2: fprintf( fp, "%s=%s\n\n", &tbl->name[0], "off" ); tbl++; break; case 3: if ( tbl->write_it ) tbl->write_it( fp, tbl ); break; case 1: n = 0; for ( ; tbl->strings[ n ]; n++ ) { fprintf( fp, "# %s\n", &tbl->strings[ n ] ); // n++; } fprintf( fp, "%s=%s\n\n", &tbl->name[0], &tbl->strings[ q->add_value ] ); break; case 5: fprintf( fp, "%s=%s\n\n", &tbl->name[0], LYputEnum( &tbl->table, q->add_value ) ); break; case 4: fprintf( fp, "%s=%d\n\n", &tbl->name[0], q->add_value ); break; case 7: n = 1; for ( ; n <= 25; n++ ) { fprintf( fp, "multi_bookmark%c=", LYindex2MBM( n ) ); fputs( "", fp ); if ( MBM_A_subdescript[ n ] && MBM_A_subdescript[ n ][0] ) fprintf( fp, ",%s", MBM_A_subdescript[ n ] ); fputc( 10, fp ); // n++; } fputc( 10, fp ); break; case 6: case 8: fprintf( fp, "%s=%s\n\n", &tbl->name[0], "" ); break; case 0: break; } } } }