diff options
Diffstat (limited to 'src/LYNews.c')
-rw-r--r-- | src/LYNews.c | 211 |
1 files changed, 103 insertions, 108 deletions
diff --git a/src/LYNews.c b/src/LYNews.c index 76e60ceb..94902bf2 100644 --- a/src/LYNews.c +++ b/src/LYNews.c @@ -21,14 +21,13 @@ #include <LYLeaks.h> /* -** Global variable for async i/o. -*/ + * Global variable for async i/o. + */ BOOLEAN term_message = FALSE; -static void terminate_message (int sig); +static void terminate_message(int sig); -static BOOLEAN message_has_content ( - const char * filename, - BOOLEAN * nonspaces) +static BOOLEAN message_has_content(const char *filename, + BOOLEAN *nonspaces) { FILE *fp; char *buffer = NULL; @@ -38,12 +37,13 @@ static BOOLEAN message_has_content ( if (!filename || (fp = fopen(filename, "r")) == NULL) { CTRACE((tfp, "Failed to open file %s for reading!\n", - NONNULL(filename))); + NONNULL(filename))); return FALSE; } while (LYSafeGets(&buffer, fp) != NULL) { char *cp = buffer; char firstnonblank = '\0'; + LYTrimNewline(cp); for (; *cp; cp++) { if (!firstnonblank && isgraph(UCH(*cp))) { @@ -69,25 +69,24 @@ static BOOLEAN message_has_content ( } /* -** This function is called from HTLoadNews() to have the user -** create a file with news headers and a body for posting of -** a new message (based on a newspost://nntp_host/newsgroups -** or snewspost://secure_nntp_host/newsgroups URL), or to post -** a followup (based on a newsreply://nntp_host/newsgroups or -** snewsreply://secure_nntp_host/newsgroups URL). The group -** or comma-separated list of newsgroups is passed without -** a lead slash, and followup is TRUE for newsreply or -** snewsreply URLs. - FM -*/ -char *LYNewsPost ( - char * newsgroups, - BOOLEAN followup) + * This function is called from HTLoadNews() to have the user + * create a file with news headers and a body for posting of + * a new message (based on a newspost://nntp_host/newsgroups + * or snewspost://secure_nntp_host/newsgroups URL), or to post + * a followup (based on a newsreply://nntp_host/newsgroups or + * snewsreply://secure_nntp_host/newsgroups URL). The group + * or comma-separated list of newsgroups is passed without + * a lead slash, and followup is TRUE for newsreply or + * snewsreply URLs. - FM + */ +char *LYNewsPost(char *newsgroups, + BOOLEAN followup) { char user_input[1024]; char CJKinput[1024]; char *cp = NULL; const char *kp = NULL; - int c = 0; /* user input */ + int c = 0; /* user input */ int len; FILE *fd = NULL; char my_tempfile[LY_MAXPATH]; @@ -102,22 +101,21 @@ char *LYNewsPost ( BOOLEAN nonspaces = FALSE; /* - * Make sure a non-zero length newspost, newsreply, - * snewspost or snewsreply path was sent to us. - FM + * Make sure a non-zero length newspost, newsreply, snewspost or snewsreply + * path was sent to us. - FM */ if (!(newsgroups && *newsgroups)) - return(postfile); + return (postfile); /* - * Return immediately if we do get called, maybe by some quirk - * of HTNews.c, when we shouldn't. - kw + * Return immediately if we do get called, maybe by some quirk of HTNews.c, + * when we shouldn't. - kw */ if (no_newspost) - return(postfile); + return (postfile); /* - * Open a temporary file for the headers - * and message body. - FM + * Open a temporary file for the headers and message body. - FM */ #ifdef __DJGPP__ if ((fd = LYOpenTemp(my_tempfile, HTML_SUFFIX, BIN_W)) == NULL) @@ -126,12 +124,12 @@ char *LYNewsPost ( #endif /* __DJGPP__ */ { HTAlert(CANNOT_OPEN_TEMP); - return(postfile); + return (postfile); } /* - * If we're using a Japanese display character set, - * open a temporary file for a conversion to JIS. - FM + * If we're using a Japanese display character set, open a temporary file + * for a conversion to JIS. - FM */ CJKfile[0] = '\0'; if (current_char_set == UCGetLYhndl_byMIME("euc-jp") || @@ -139,14 +137,13 @@ char *LYNewsPost ( if ((fc = LYOpenTemp(CJKfile, HTML_SUFFIX, "w")) == NULL) { HTAlert(CANNOT_OPEN_TEMP); LYRemoveTemp(my_tempfile); - return(postfile); + return (postfile); } } /* - * The newsgroups could be a comma-seperated list. - * It need not have spaces, but deal with any that - * may also have been hex escaped. - FM + * The newsgroups could be a comma-seperated list. It need not have + * spaces, but deal with any that may also have been hex escaped. - FM */ StrAllocCopy(NewsGroups, newsgroups); if ((cp = strstr(NewsGroups, ";ref="))) { @@ -167,68 +164,66 @@ char *LYNewsPost ( } HTUnEscape(NewsGroups); if (!*NewsGroups) { - LYCloseTempFP(fd); /* Close the temp file. */ + LYCloseTempFP(fd); /* Close the temp file. */ goto cleanup; } /* - * Allow ^C to cancel the posting, - * i.e., don't let SIGINTs exit Lynx. + * Allow ^C to cancel the posting, i.e., don't let SIGINTs exit Lynx. */ signal(SIGINT, terminate_message); term_message = FALSE; /* - * Show the list of newsgroups. - FM + * Show the list of newsgroups. - FM */ LYclear(); - LYmove(2,0); - scrollok(LYwin, TRUE); /* Enable scrolling. */ + LYmove(2, 0); + scrollok(LYwin, TRUE); /* Enable scrolling. */ LYaddstr(gettext("You will be posting to:")); LYaddstr("\n\t"); LYaddstr(NewsGroups); LYaddch('\n'); /* - * Get the mail address for the From header, - * offering personal_mail_address as default. + * Get the mail address for the From header, offering personal_mail_address + * as default. */ LYaddstr(gettext("\n\n Please provide your mail address for the From: header\n")); - sprintf(user_input, "From: %.*s", (int)sizeof(user_input) - 8, + sprintf(user_input, "From: %.*s", (int) sizeof(user_input) - 8, NonNull(personal_mail_address)); if (LYgetstr(user_input, VISIBLE, sizeof(user_input), NORECALL) < 0 || term_message) { HTInfoMsg(NEWS_POST_CANCELLED); - LYCloseTempFP(fd); /* Close the temp file. */ - scrollok(LYwin, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(LYwin, FALSE); /* Stop scrolling. */ goto cleanup; } fprintf(fd, "%s\n", user_input); /* - * Get the Subject header, offering the current - * document's title as the default if this is a - * followup rather than a new post. - FM + * Get the Subject header, offering the current document's title as the + * default if this is a followup rather than a new post. - FM */ LYaddstr(gettext("\n\n Please provide or edit the Subject: header\n")); strcpy(user_input, "Subject: "); if ((followup == TRUE && nhist > 0) && (kp = HText_getTitle()) != NULL) { /* - * Add the default subject. + * Add the default subject. */ kp = LYSkipCBlanks(kp); -#ifdef CJK_EX /* 1998/05/15 (Fri) 09:10:38 */ +#ifdef CJK_EX /* 1998/05/15 (Fri) 09:10:38 */ if (HTCJK == JAPANESE) { CJKinput[0] = '\0'; - switch(kanji_code) { + switch (kanji_code) { case EUC: - TO_EUC((const unsigned char *)kp, (unsigned char *)CJKinput); + TO_EUC((const unsigned char *) kp, (unsigned char *) CJKinput); kp = CJKinput; break; case SJIS: - TO_SJIS((const unsigned char *)kp, (unsigned char *)CJKinput); + TO_SJIS((const unsigned char *) kp, (unsigned char *) CJKinput); kp = CJKinput; break; default: @@ -247,14 +242,14 @@ char *LYNewsPost ( sizeof(user_input), NORECALL) < 0 || term_message) { HTInfoMsg(NEWS_POST_CANCELLED); - LYCloseTempFP(fd); /* Close the temp file. */ - scrollok(LYwin, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(LYwin, FALSE); /* Stop scrolling. */ goto cleanup; } - fprintf(fd,"%s\n",user_input); + fprintf(fd, "%s\n", user_input); /* - * Add Organization: header. + * Add Organization: header. */ StrAllocCopy(cp, "Organization: "); if ((org = LYGetEnv("ORGANIZATION")) != NULL) { @@ -265,6 +260,7 @@ char *LYNewsPost ( #ifdef UNIX else if ((fp = fopen("/etc/organization", TXT_R)) != NULL) { char *buffer = 0; + if (LYSafeGets(&buffer, fp) != NULL) { if (user_input[0] != '\0') { LYTrimNewline(buffer); @@ -275,7 +271,7 @@ char *LYNewsPost ( LYCloseInput(fp); } #else -#ifdef _WINDOWS /* 1998/05/14 (Thu) 17:47:01 */ +#ifdef _WINDOWS /* 1998/05/14 (Thu) 17:47:01 */ else { char *p, fname[LY_MAXPATH]; @@ -305,8 +301,8 @@ char *LYNewsPost ( sizeof(user_input), NORECALL) < 0 || term_message) { HTInfoMsg(NEWS_POST_CANCELLED); - LYCloseTempFP(fd); /* Close the temp file. */ - scrollok(LYwin, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(LYwin, FALSE); /* Stop scrolling. */ goto cleanup; } fprintf(fd, "%s\n", user_input); @@ -315,39 +311,39 @@ char *LYNewsPost ( fprintf(fd, "References: %s\n", References); } /* - * Add Newsgroups Summary and Keywords headers. + * Add Newsgroups Summary and Keywords headers. */ fprintf(fd, "Newsgroups: %s\nSummary: \nKeywords: \n\n", NewsGroups); /* - * Have the user create the message body. + * Have the user create the message body. */ if (!no_editor && editor && *editor != '\0') { if (followup && nhist > 0) { /* - * Ask if the user wants to include the original message. + * Ask if the user wants to include the original message. */ if (term_message) { _statusline(INC_ORIG_MSG_PROMPT); } else if (HTConfirm(INC_ORIG_MSG_PROMPT) == YES) { /* - * The 'TRUE' will add the reply ">" in front of every line. - * We're assuming that if the display character set is - * Japanese and the document did not have a CJK charset, - * any non-EUC or non-SJIS 8-bit characters in it where - * converted to 7-bit equivalents. - FM + * The 'TRUE' will add the reply ">" in front of every line. + * We're assuming that if the display character set is Japanese + * and the document did not have a CJK charset, any non-EUC or + * non-SJIS 8-bit characters in it where converted to 7-bit + * equivalents. - FM */ print_wwwfile_to_fd(fd, FALSE, TRUE); } } - LYCloseTempFP(fd); /* Close the temp file. */ - scrollok(LYwin, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(LYwin, FALSE); /* Stop scrolling. */ if (term_message || LYCharIsINTERRUPT(c)) goto cleanup; /* - * Spawn the user's editor on the news file. + * Spawn the user's editor on the news file. */ edit_temporary_file(my_tempfile, "", SPAWNING_EDITOR_FOR_NEWS); @@ -355,7 +351,7 @@ char *LYNewsPost ( } else { /* - * Use the built in line editior. + * Use the built in line editior. */ LYaddstr(gettext("\n\n Please enter your message below.")); LYaddstr(gettext("\n When you are done, press enter and put a single period (.)")); @@ -367,13 +363,13 @@ char *LYNewsPost ( sizeof(user_input), NORECALL) < 0 || term_message) { HTInfoMsg(NEWS_POST_CANCELLED); - LYCloseTempFP(fd); /* Close the temp file. */ - scrollok(LYwin, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(LYwin, FALSE); /* Stop scrolling. */ goto cleanup; } - while (!STREQ(user_input,".") && !term_message) { + while (!STREQ(user_input, ".") && !term_message) { LYaddch('\n'); - fprintf(fd,"%s\n",user_input); + fprintf(fd, "%s\n", user_input); if (!nonempty && strlen(user_input)) nonempty = TRUE; *user_input = '\0'; @@ -381,43 +377,45 @@ char *LYNewsPost ( sizeof(user_input), NORECALL) < 0) { HTInfoMsg(NEWS_POST_CANCELLED); LYCloseTempFP(fd); /* Close the temp file. */ - scrollok(LYwin, FALSE); /* Stop scrolling. */ + scrollok(LYwin, FALSE); /* Stop scrolling. */ goto cleanup; } } fprintf(fd, "\n"); - LYCloseTempFP(fd); /* Close the temp file. */ - scrollok(LYwin, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(LYwin, FALSE); /* Stop scrolling. */ } if (nonempty) { /* - * Confirm whether to post, and if so, - * whether to append the sig file. - FM + * Confirm whether to post, and if so, whether to append the sig file. + * - FM */ LYStatusLine = (LYlines - 1); c = HTConfirm(POST_MSG_PROMPT); LYStatusLine = -1; if (c != YES) { - LYclear(); /* clear the screen */ + LYclear(); /* clear the screen */ goto cleanup; } } else { HTAlert(gettext("Message has no original text!")); if (!nonspaces - || HTConfirmDefault(POST_MSG_PROMPT, NO) != YES) + || HTConfirmDefault(POST_MSG_PROMPT, NO) != YES) goto cleanup; } if ((LynxSigFile != NULL) && (fp = fopen(LynxSigFile, TXT_R)) != NULL) { char *msg = NULL; + HTSprintf0(&msg, APPEND_SIG_FILE, LynxSigFile); LYStatusLine = (LYlines - 1); if (term_message) { _user_message(APPEND_SIG_FILE, LynxSigFile); } else if (HTConfirm(msg) == YES) { - if ((fd = LYAppendToTxtFile (my_tempfile)) != NULL) { + if ((fd = LYAppendToTxtFile(my_tempfile)) != NULL) { char *buffer = NULL; + fputs("-- \n", fd); while (LYSafeGets(&buffer, fp) != NULL) { fputs(buffer, fd); @@ -429,21 +427,21 @@ char *LYNewsPost ( FREE(msg); LYStatusLine = -1; } - LYclear(); /* clear the screen */ + LYclear(); /* clear the screen */ /* - * If we are using a Japanese display character - * set, convert the contents of the temp file to - * JIS (nothing should change if it does not, in - * fact, contain EUC or SJIS di-bytes). Otherwise, - * use the temp file as is. - FM + * If we are using a Japanese display character set, convert the contents + * of the temp file to JIS (nothing should change if it does not, in fact, + * contain EUC or SJIS di-bytes). Otherwise, use the temp file as is. - + * FM */ if (CJKfile[0] != '\0') { if ((fd = fopen(my_tempfile, TXT_R)) != NULL) { char *buffer = NULL; + while (LYSafeGets(&buffer, fd) != NULL) { - TO_JIS((unsigned char *)buffer, - (unsigned char *)CJKinput); + TO_JIS((unsigned char *) buffer, + (unsigned char *) CJKinput); fputs(CJKinput, fc); } LYCloseTempFP(fc); @@ -460,13 +458,11 @@ char *LYNewsPost ( } if (!followup) { /* - * If it's not a followup, the current document - * most likely is the group listing, so force a - * to have the article show up in the list after - * the posting. Note, that if it's a followup - * via a link in a news article, the user must - * do a reload manually on returning to the - * group listing. - FM + * If it's not a followup, the current document most likely is the + * group listing, so force a to have the article show up in the list + * after the posting. Note, that if it's a followup via a link in a + * news article, the user must do a reload manually on returning to the + * group listing. - FM */ LYforce_no_cache = TRUE; } @@ -475,9 +471,9 @@ char *LYNewsPost ( LYStatusLine = -1; /* - * Come here to cleanup and exit. + * Come here to cleanup and exit. */ -cleanup: + cleanup: #ifndef VMS signal(SIGINT, cleanup_sig); #endif /* !VMS */ @@ -488,20 +484,19 @@ cleanup: FREE(NewsGroups); FREE(References); - return(postfile); + return (postfile); } -static void terminate_message ( - int sig GCC_UNUSED) +static void terminate_message(int sig GCC_UNUSED) { term_message = TRUE; /* - * Reassert the AST. + * Reassert the AST. */ signal(SIGINT, terminate_message); #ifdef VMS /* - * Refresh the screen to get rid of the "interrupt" message. + * Refresh the screen to get rid of the "interrupt" message. */ lynx_force_repaint(); LYrefresh(); |