home *** CD-ROM | disk | FTP | other *** search
- #include "defs.h"
- #include "memalloc.h"
- #include "headers.h"
-
- #define DISABLE_GADGETS 1
-
- // #define PROCDEBUG
-
- #ifdef PROCDEBUG
- #define D(x) printf x
- #else
- #define D(x)
- #endif
-
- extern char *NewsGroupToFileName (char *newsgroup);
- extern void AppendSignature (int outfd);
- extern void AppendNewsGroupSignature (int outfd);
- extern void DisableWindow (void);
- extern void EnableWindow (void);
-
- static LIST msgList;
-
- ART *currentArticle;
- char *ArticleName (ART *ap); /* FORWARD */
-
- /*
- Parameters to Mail()
- */
- #define MAIL_MAIL 0
- #define MAIL_REPLY 1
- #define MAIL_FORWARD 2 // much like a MAIL_REPLY
-
- /************************************************************************/
-
- /*
- * As each gadget in the GadDefs array above is created, it is assigned a UserID
- * field value, incremented from zero. The following defines are useful for switch
- * statements, etc. Enum would also work. Be careful, if you add new gadgets in
- * the middle of the initializations above, because you will need to renumber these
- * defines.
- */
- static enum GADGET_IDS {
- ARTLIST_ID,
- HIDEHEADERS_ID,
- HIDEREAD_ID,
- SORT_ID,
- QUIT_ID,
- PREV_ID,
- NEXT_ID,
- NEXTUNREAD_ID,
- NEXTTHREAD_ID,
- CATCHUP_ID,
- PREVGROUP_ID,
- NEXTGROUP_ID,
- FROM_ID,
- ORGANIZATION_ID,
- DATE_ID,
- SUBJECT_ID,
- MSGLIST_ID,
- STATUS_ID,
- SAVE_ID,
- REPLY_ID,
- FORWARD_ID,
- FOLLOWUP_ID,
- POST_ID,
- PRINT_ID,
- MAXGADGET,
- };
-
- static GADGET *gadgetArray[MAXGADGET];
-
- static char *sortLabels[] = { "Number", "From", "Subject", 0 };
-
- static int viewHeight; // height of MSGLIST listview in character lines
- static int viewTop = 0; // top line of MSGLIST view (for GTLV_Top pagedown
- static int messageLines = 0; // number of lines in message
- static int idcmp_shifted = 0; // if you really want to know, see the
- // 2.0 "Includes" RKM, page 347 right
- // after IDCMP_VANILLAKEY, and remember
- // that we set RAWKEY | VANILLAKEY
-
- /*
- * Misc tags arrays
- */
- static TAGS nullTags[] = { GT_Underscore, '_', TAG_DONE,0 };
- static TAGS disableTags[] = { GT_Underscore, '_', GA_Disabled,TRUE, TAG_DONE,0 };
- static TAGS enableTags[] = { GT_Underscore, '_', GA_Disabled,FALSE, TAG_DONE,0 };
-
- static TAGS sortTags[] = {
- GT_Underscore, '_',
- GTCY_Labels, &sortLabels[0],
- GTCY_Active, 0,
- TAG_DONE, 0,
- };
-
- static TAGS artListTags[] = {
- GT_Underscore, '_',
- GTLV_Top, 0,
- GTLV_Labels, 0,
- GTLV_ReadOnly, FALSE,
- GTLV_ScrollWidth, 16,
- #ifdef MYKE_REMOVED_THIS
- GTLV_ShowSelected, NULL,
- #endif
- GTBB_Recessed, FALSE,
- TAG_DONE, 0,
- };
-
- static TAGS msgListTags[] = { // LISTVIEW_KIND
- GT_Underscore, '_',
- GTLV_Top, 0,
- GTLV_Labels, &msgList,
- GTLV_ReadOnly, TRUE,
- GTLV_ScrollWidth, 16,
- GTBB_Recessed, TRUE,
- TAG_DONE, 0,
- };
-
- static char *nullText = "";
- static TAGS textTags[] = {
- GT_Underscore, '_',
- GTTX_Text, (ULONG)"",
- GTTX_CopyText, TRUE,
- GTTX_Border, TRUE,
- TAG_DONE, 0,
- };
-
- /*
- * The Array of Gadget definitions. To create a new gadget, add an initializer
- * here, and create the necessary tags...
- */
- static GADDEF gadDefs[] = {
- artListTags, LISTVIEW_KIND,0,0,0,0, NG_HIGHLABEL, "",
- nullTags, CHECKBOX_KIND, 0,0,0,0, NG_HIGHLABEL, "Hide Headers:",
- disableTags, CHECKBOX_KIND, 0,0,0,0, NG_HIGHLABEL, "Hide Read Messages:",
- sortTags, CYCLE_KIND, 0,0,0,0, NG_HIGHLABEL, "Sort By:",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Groups",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_prev",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_next",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_unread",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_thread",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Catch up",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Prev Group",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Next Group",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "From:",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "Org:",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "Date:",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "Subj:",
- msgListTags, LISTVIEW_KIND, 0,0,0,0, NG_HIGHLABEL, "",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Save",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Reply",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "Forward",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_FollowUp",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "Post",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "Print",
- 0,0,0,0,0,0,0,0,
- };
-
- static GADGET *gList = 0;
-
- static void LayoutGadgets (FONT *font, short width, short height,short top)
- {
- short i, x,y, fh, lh;
- RPORT rPort, *rp = &rPort;
-
- InitRastPort (rp);
- SetFont (rp, font);
- y = top + INTERHEIGHT / 2;
-
- lh = windowHeight / 50;
- if (lh > 10)
- lh = 10;
- fh = rp->TxHeight + 2;
- gadDefs [ARTLIST_ID].left = INTERWIDTH;
- gadDefs [ARTLIST_ID].top = y;
- gadDefs [ARTLIST_ID].width = width - INTERWIDTH - INTERWIDTH;
- gadDefs [ARTLIST_ID].height = (lh * fh) + INTERHEIGHT;
- y += (lh * fh) + INTERHEIGHT + 2;
-
- fh = topazRP->TxHeight+2;
- x = INTERWIDTH;
- gadDefs [HIDEHEADERS_ID].left = x + TextLen (topazRP, gadDefs [HIDEHEADERS_ID].text) + 20;
- gadDefs [HIDEHEADERS_ID].top = y;
- gadDefs [HIDEHEADERS_ID].width = 12;
- gadDefs [HIDEHEADERS_ID].height = fh + 2;
- x = gadDefs [HIDEHEADERS_ID].left + gadDefs [HIDEHEADERS_ID].width + INTERWIDTH;
-
- gadDefs [HIDEREAD_ID].left = x + TextLen (topazRP, gadDefs [HIDEREAD_ID].text) + 20;
- gadDefs [HIDEREAD_ID].top = y;
- gadDefs [HIDEREAD_ID].width = 12;
- gadDefs [HIDEREAD_ID].height = fh + 2;
- x = gadDefs [HIDEREAD_ID].left + gadDefs [HIDEREAD_ID].width + INTERWIDTH;
-
- gadDefs [SORT_ID].left = x + TextLen (topazRP, gadDefs [SORT_ID].text) + 20;
- gadDefs [SORT_ID].top = y;
- gadDefs [SORT_ID].width = TextLen (topazRP, "Subject") + 24;
- gadDefs [SORT_ID].height = fh + 2;
- x = gadDefs [SORT_ID].left + gadDefs [SORT_ID].width + INTERWIDTH;
-
- y += fh + 4;
-
- x = INTERWIDTH;
- for (i = QUIT_ID; i <= NEXTGROUP_ID; i++) {
- gadDefs [i].left = x;
- gadDefs [i].top = y;
- gadDefs [i].width = TextLen (topazRP, gadDefs [i].text) + 4;
- gadDefs [i].height = fh + 4;
- x += gadDefs [i].width + INTERWIDTH;
- }
-
- y += fh + 4 + INTERHEIGHT;
-
- for (i = FROM_ID; i <= SUBJECT_ID; i++) {
- gadDefs [i].left = INTERWIDTH + 48;
- gadDefs [i].top = y;
- gadDefs [i].width = width - 48 - INTERWIDTH - INTERWIDTH;
- gadDefs [i].height = fh + 2;
- y += fh + INTERHEIGHT;
- }
-
- fh = rp->TxHeight + 2;
- gadDefs [MSGLIST_ID].left = INTERWIDTH;
- gadDefs [MSGLIST_ID].top = y;
- gadDefs [MSGLIST_ID].width = width - INTERWIDTH - INTERWIDTH;
- gadDefs [MSGLIST_ID].height = height - y - fh - fh - INTERHEIGHT - INTERHEIGHT;
- y += gadDefs [MSGLIST_ID].height;
- viewHeight = gadDefs [MSGLIST_ID].height / (fh - 2); // MBS-FIX
-
- fh = topazRP->TxHeight + 2;
- // viewHeight = gadDefs [MSGLIST_ID].height / (fh - 2); MBS-FIX
- gadDefs [STATUS_ID].left = INTERWIDTH;
- gadDefs [STATUS_ID].top = y;
- gadDefs [STATUS_ID].width = width - INTERWIDTH - INTERWIDTH;
- gadDefs [STATUS_ID].height = fh + 2;
- y += fh + 4;
-
- x = INTERWIDTH;
- for (i = SAVE_ID; i <= PRINT_ID; i++) {
- gadDefs [i].left = x;
- gadDefs [i].top = y;
- gadDefs [i].width = TextLen (topazRP, gadDefs [i].text) + 4;
- gadDefs [i].height = fh+2;
- x += gadDefs [i].width + INTERWIDTH;
- }
- y += fh + 4;
- return;
- }
-
- /************************************************************************/
-
- void CloseArticles (void)
- {
- D (("CloseArticles(): enter\n"));
-
- if (!gList)
- return;
- if (RemoveGList (mainWindow, gList, -1) == -1) {
- D (("CloseArticles(): exit: RemoveGList() failed\n"));
- return;
- }
- FreeGadgets (gList);
- gList = 0;
- ClearWindow ();
- RefreshGList (mainWindow->FirstGadget, mainWindow, 0, -1);
- GT_RefreshWindow (mainWindow, NULL);
- D (("CloseArticles(): exit\n"));
- return;
- }
-
- /************************************************************************/
-
- GLIST *NextGroup (void)
- {
- GLIST *gp = currentGroup;
-
- D (("NextGroup(): enter\n"));
-
- do {
- if (groupList.lh_TailPred == (NODE *)gp)
- gp = (GLIST *)groupList.lh_Head;
- else
- gp = (GLIST *)gp->node.ln_Succ;
- } while (!gp->articles && gp != currentGroup);
-
- D (("NextGroup(): exit\n"));
-
- return gp;
- }
-
- GLIST *PrevGroup (void)
- {
- GLIST *gp = currentGroup;
-
- D (("PrevGroup(): enter\n"));
-
- do {
- if (groupList.lh_Head == (NODE *)gp)
- gp = (GLIST *)groupList.lh_TailPred;
- else
- gp = (GLIST *)gp->node.ln_Pred;
- } while (!gp->articles && gp != currentGroup);
-
- D (("PrevGroup(): exit\n"));
-
- return gp;
- }
-
- void SortArticles (void)
- {
- D (("SortArticles(): enter\n"));
-
- switch (currentGroup->sortActive) {
- case 0:
- SortArticlesByNumber (¤tGroup->artList);
- break;
- case 1:
- SortArticlesByFrom (¤tGroup->artList);
- break;
- case 2:
- SortArticlesBySubject (¤tGroup->artList);
- break;
- }
-
- D (("SortArticles(): exit\n"));
- return;
- }
-
- void Save (void)
- {
- char *temp; // I/O buffer to disk
- char *filename; // filename to save article to
- char *ptr; // fully qualified article filename
- int fd; // article fd
- int outfd; // output file fd
- int len;
- ULONG size, count = 0, pct;
-
- D (("Save(): enter\n"));
-
- // first, have user specify filename to save the article to
- if (!AslRequest (saveReq, NULL))
- return;
- len = strlen (saveReq->rf_Dir) + strlen (saveReq->rf_File) + 10;
- if (!(filename = malloc (len))) {
- t_printf (mainWindow, "Can't malloc %d bytes for filename", len);
- D (("Save(): memory failure, exit\n"));
- return;
- }
- strcpy (filename, saveReq->rf_Dir);
- AddPart (filename, saveReq->rf_File, len);
-
- // find the article, and see how big it is
- ptr = ArticleName (currentArticle);
- if ((fd = open (ptr, O_RDONLY)) < 0) {
- t_printf (mainWindow, "Can't open '%s' for input\n", ptr);
- D (("Save(): open input failure, exit\n"));
- return;
- }
- size = lseek (fd, 0, 2);
- lseek (fd, 0, 0);
-
- // create output file (APPEND to it if it already exists)
- if ((outfd = open (filename, O_WRONLY | O_APPEND | O_CREAT)) < 0) {
- t_printf (mainWindow, "Can't open '%s' for output\n", ptr);
- close (fd);
- free (filename);
- D (("Save(): open output failure, exit\n"));
- return;
- }
-
- // get memory for I/O buffer
- if (!(temp = malloc (512))) {
- t_printf (mainWindow, "Can't malloc 512 bytes for I/O");
- close (outfd);
- close (fd);
- free (filename);
- D (("Save(): get mem failure, exit\n"));
- return;
- }
-
- // save the article
- while ((len = read (fd, temp, 512)) > 0) {
- count += len;
- pct = 100 * count / size;
- if (GuageRequest (pct, "GRn - Please Wait...",
- " Saving ", "Abort"))
- break;
- // FIXME - check for errors on write() [DISK full, etc.]
- write (outfd, temp, len);
- }
- GuageRequest (1000, "GRn - Please Wait...",
- " Saving ", "Abort");
- free (temp);
- free (filename);
- close (fd);
- close (outfd);
- D (("Save(): exit\n"));
- return;
- }
-
- void Print (void)
- {
- char *temp;
- char *ptr;
- int fd;
- int outfd;
- int len;
- ULONG size, count = 0, pct;
-
- D (("Print(): enter\n"));
- if (!(temp = malloc (256))) {
- t_printf ("Can't malloc 256 bytes to print");
- D (("Print(): get mem failure, exit\n"));
- return;
- }
- ptr = ArticleName (currentArticle);
-
- if ((fd = open (ptr, O_READ)) < 0) {
- t_printf (mainWindow, "Can't open '%s'", ptr);
- free (temp);
- D (("Print(): open input failure, exit\n"));
- return;
- }
- size = lseek (fd, 0, 2);
- lseek (fd, 0, 0);
- if ((outfd = open ("prt:", O_WRONLY)) < 0) {
- t_printf (mainWindow, "Can't open printer");
- free (temp);
- close (fd);
- D (("Print(): open output failure, exit\n"));
- return;
- }
- while ((len = read (fd, temp, 256)) > 0) {
- count += len;
- pct = 100 * count / size;
- // FIXME - check for output errors
- write (outfd, temp, len);
- if (GuageRequest (pct, "GRn - Please Wait...",
- " Printing ", "Abort")) break;
- }
- GuageRequest (1000, "GRn - Please Wait...",
- " Printing ", "Abort");
- close (fd);
- // output formfeed
- *temp = 12;
- write (outfd, temp, 1);
- close (outfd);
- free (temp);
- D (("Print(): exit\n"));
- return;
- }
-
- #ifndef SLOW
- // in our unending quest for more speed on a puny 68000 processor....
- // I wish DICE supported __inline
- #define Store_Text(xbuf, xlen) \
- { \
- xbuf [xlen] = '\0'; \
- AddTail (&msgList, AllocNODE (xbuf, xlen)); \
- messageLines++; \
- }
- #else
- void Store_Text (char *buf, int len)
- {
- NODE *np;
-
- buf [len] = '\0';
- np = AllocNODE (buf, len);
- AddTail (&msgList, np);
- messageLines++;
-
- return;
- }
- #endif
-
- int OutputFile (int fd, int doing_headers)
- {
- #define output(x) { Store_Text (x, outlen); pout = outbuf; outlen = 0; }
-
- static char temp [512], outbuf [512];
- register char *pout;
- register char *p;
- register int len;
- register int outlen;
- register int last_was_newline;
-
- // on entry, we assume that the file is positioned appropriately
-
- D (("OutputFile(): enter\n"));
-
- pout = outbuf;
- outlen = 0;
- last_was_newline = 0;
- while ((len = read (fd, temp, 512)) > 0) {
- p = temp;
-
- while (len > 0) {
- len--;
- if (*p == '\t') {
- p++;
- // a tab should consume a minimum of one space
- do {
- *pout++ = ' ';
- outlen++;
- } while ((outlen < wrapCol) && (outlen % 8));
- last_was_newline = 0;
- continue;
- }
- if (*p == '\n') {
- if (last_was_newline && doing_headers)
- goto done;
- last_was_newline = 1;
- p++;
- if (outlen == 0) {
- *pout = ' ';
- outlen++;
- }
- output (outbuf);
- continue;
- }
- last_was_newline = 0;
- *pout++ = *p++;
- outlen++;
- if ((outlen >= wrapCol) && (*p != '\n')) {
- *pout = '\\';
- outlen++;
- output (outbuf);
- }
- }
- }
- if (outlen)
- output (outbuf);
- done:
- D (("OutputFile(): exit\n"));
-
- return 0;
- #undef output
- }
-
- void ShowMessage (ART *ap)
- {
- NODE *np;
- GLIST *gp;
- BOOL flag = !0;
- int fd;
- static char artStatus [256];
- static char blank [2];
-
- D (("ShowMessage(): enter\n"));
-
- blank [0] = ' ';
- messageLines = 0;
- if (currentArticle == ap)
- flag = 0;
- currentArticle = ap;
- GT_SetGadgetAttrs (gadgetArray [MSGLIST_ID], mainWindow, NULL,
- GTLV_Labels, ~0, TAG_DONE);
- FreeListNode (&msgList);
- NewList (&msgList);
-
- Organization = NULL;
- Date = NULL;
- X_NewsSoftware = NULL;
-
- fd = ScanAndLoadHeaders (ArticleName (ap), HEADER_ORGANIZATION | HEADER_X_NEWSSOFTWARE | HEADER_DATE, OPT_DONT_CLOSE);
- if (fd < 0) {
- t_printf (mainWindow, "Can't open %s", ArticleName (ap));
- D (("ShowMessage(): open input failure, exit\n"));
- return;
- }
-
- if (currentGroup->hideHeaders) {
- if (X_NewsSoftware) {
- // display X-NewsSoftware header only
- X_NewsSoftware -= 16; // strlen ("X-NewsSoftware: ")
- Store_Text (X_NewsSoftware, strlen (X_NewsSoftware));
- X_NewsSoftware += 16;
- Store_Text (blank, 1);
- }
- }
- else {
- // Display ALL header lines
- lseek (fd, 0, 0);
- OutputFile (fd, 1);
- Store_Text (blank, 1);
- }
- // point file to immediately after the last header
- if (header_len <= 0) {
- t_printf (mainWindow, "Internal error ScanHeaders()");
- close (fd);
- D (("ShowMessage(): ScanHeaders() error, exit\n"));
- return;
- }
- lseek (fd, header_len + 1, 0);
-
- // Display the file.
- OutputFile (fd, 0);
-
- close (fd);
-
- if (ap->state == UNREAD) {
- treeDirty = !0;
- if (currentGroup->unread)
- currentGroup->unread--;
- }
- ap->state = READ;
- sprintf (ap->node.ln_Name, "%s %6d %-32.32s %.64s",
- ap->state?" READ ":"UNREAD ",
- ap->filenum,
- ap->from,
- ap->subject
- );
- GT_SetGadgetAttrs (gadgetArray [MSGLIST_ID], mainWindow, NULL,
- GTLV_Labels, &msgList, TAG_DONE);
- if (flag) {
- GT_SetGadgetAttrs (gadgetArray [MSGLIST_ID], mainWindow, NULL,
- GTLV_Top, 0, TAG_DONE);
- viewTop = 0;
- }
- gp = NextGroup ();
- sprintf (artStatus, " *** Article %6d (%d remaining) Next Group is %s",
- ap->filenum,
- currentGroup->unread,
- currentGroup != gp ? gp->groupName : "No More"
- );
-
- GT_SetGadgetAttrs (gadgetArray [STATUS_ID], mainWindow, NULL,
- GTTX_Text, artStatus, TAG_DONE);
-
- GT_SetGadgetAttrs (gadgetArray [FROM_ID], mainWindow, NULL,
- GTTX_Text, ap->from, TAG_DONE);
-
- GT_SetGadgetAttrs (gadgetArray [ORGANIZATION_ID], mainWindow, NULL,
- GTTX_Text, Organization, TAG_DONE);
-
- GT_SetGadgetAttrs (gadgetArray [DATE_ID], mainWindow, NULL,
- GTTX_Text, Date, TAG_DONE);
-
- GT_SetGadgetAttrs (gadgetArray [SUBJECT_ID], mainWindow, NULL,
- GTTX_Text, ap->subject, TAG_DONE);
-
- GT_SetGadgetAttrs (gadgetArray [ARTLIST_ID], mainWindow, NULL,
- GTLV_Top, ap->index, TAG_DONE);
-
- GT_RefreshWindow (mainWindow, NULL);
-
- D (("ShowMessage(): exit\n"));
- return;
- }
-
- void NextArticle (void)
- {
- D (("NextArticle(): enter\n"));
-
- if (currentGroup->artList.lh_TailPred == (NODE *) currentArticle)
- return;
- ShowMessage ((ART *) currentArticle->node.ln_Succ);
-
- D (("NextArticle(): exit\n"));
- return;
- }
-
- void PrevArticle (void)
- {
- D (("PrevArticle(): enter\n"));
-
- if (currentGroup->artList.lh_Head == (NODE *) currentArticle)
- return;
- ShowMessage ((ART *) currentArticle->node.ln_Pred);
-
- D (("PrevArticle(): exit\n"));
- return;
- }
-
- void Post (BOOL followupFlag)
- {
- char temp [512], work [512];
- char *ptr; // temporary
- char *p; // temporary
- char *pout; // output pointer to work
- char *fname; // name of the temporary output file
- int fd; // the input file (currentArticle)
- int outfd; // the article we are building
- int len; // input read length
- int outlen; // output write length
-
- D (("Post(): enter\n"));
-
- Newsgroups = From = Message_ID = References = Subject =
- Distribution = Followup_To = NULL;
- fd = -1;
-
- if (followupFlag && !currentArticle) {
- t_printf (mainWindow, "I shouldn't be here");
- D (("Post(): why am I here, exit\n"));
- return;
- }
-
- if (currentArticle) {
- ptr = ArticleName (currentArticle);
- fd = ScanAndLoadHeaders (ptr,
- (HEADER_NEWSGROUPS |
- HEADER_FROM |
- HEADER_MESSAGE_ID |
- HEADER_REFERENCES |
- HEADER_SUBJECT |
- HEADER_FOLLOWUP_TO |
- HEADER_DISTRIBUTION),
- OPT_DONT_CLOSE);
-
- if (fd < 0) {
- t_printf (mainWindow, "Can't open %s for input", ptr);
- D (("Post(): open input failure, exit\n"));
- return;
- }
- }
-
- ptr = TempName ();
- fname = malloc (strlen (ptr) + 1);
- if (!fname) {
- t_printf (mainWindow, "Can't get memory for filename");
- if (fd >= 0)
- close (fd);
-
- D (("Post(): get mem failure, exit\n"));
- return;
- }
- strcpy (fname, ptr);
-
- if ((outfd = creat (ptr, 0660)) < 0) {
- t_printf (mainWindow, "Can't open %s for output", ptr);
- free (fname);
- if (fd >= 0)
- close (fd);
-
- D (("Post(): open output failure, exit\n"));
- return;
- }
-
- if (followupFlag)
- if (Followup_To && *Followup_To) {
- // FIXME: do Followup-To: poster logic
- p = Followup_To;
- }
- else
- if (Newsgroups && *Newsgroups)
- p = Newsgroups;
- else
- p = currentGroup->groupName;
- else
- p = currentGroup->groupName;
-
- OutputStrings (outfd, "Newsgroups: ", p, "\n", NULL);
-
- OutputStrings (outfd, "Subject: ", NULL);
- if (followupFlag) {
- if (strncmp (Subject, "Re:", 3) != 0)
- OutputStrings (outfd, "Re: ", NULL);
-
- OutputStrings (outfd, Subject, NULL);
- }
- OutputStrings (outfd, "\n", NULL);
-
- OutputStrings (outfd, "Distribution: ", NULL);
- if (Distribution)
- OutputStrings (outfd, Distribution, NULL);
- else
- OutputStrings (outfd, "world", NULL);
-
- OutputStrings (outfd, "\n\n", NULL);
-
- if (followupFlag) {
- OutputStrings (outfd, "In article ",
- Message_ID ? Message_ID : "???",
- " ",
- From ? From : "???",
- " writes:\n",
- NULL);
-
- // point file to immediately after the last header
- if (header_len <= 0) {
- t_printf (mainWindow, "Internal error from ScanHeaders()");
- close (fd);
- remove (fname);
- free (fname);
-
- D (("Post(): ScanHeaders() error, exit\n"));
- return;
- }
- lseek (fd, header_len + 1, 0);
-
- // This is the same algorithm as from OutputFile(), we just
- // don't worry about wrapCol (instead we use 500 chars as a
- // limit). And we don't do tab expansion.
-
- // This is EXACTLY the same algorithm as in Mail().
-
- // FIXME: The prefix "> " should be an option.
-
- #define output(x) { *pout = '\0'; OutputStrings (outfd, "> ", work, "\n", NULL); outlen = 0; pout = work; *pout = '\0'; }
-
- pout = work;
- *pout = '\0';
- outlen = 0;
- while ((len = read (fd, temp, 512)) > 0) {
- p = temp;
-
- while (len > 0) {
- len--;
- // tab expansion was here....
- if (*p == '\n') {
- p++;
- output (work);
- continue;
- }
- *pout++ = *p++;
- outlen++;
- if ((outlen >= 500) && (*p != '\n')) {
- *pout++ = '\\';
- outlen++;
- output (work);
- }
- }
- }
- if (outlen)
- output (work);
- #undef output
- }
-
- if (fd >= 0)
- close (fd);
- OutputStrings (outfd, "\n-- \n", NULL);
-
- AppendNewsGroupSignature (outfd);
- close (outfd);
-
- PostNews (followupFlag, fname);
- free (fname);
-
- D (("Post(): exit\n"));
- return;
- }
-
- void Mail (BOOL replyFlag)
- {
- char temp [512], work [512];
- char *ptr;
- char *p;
- char *fname;
- char *pout;
- int len;
- int outlen;
- int fd;
- int outfd;
- int rslt;
- int rfd;
- int i;
-
- D (("Mail(): enter\n"));
-
- Path = From = Reply_To = Message_ID = Subject = NULL;
- fd = -1;
-
- if (replyFlag && !currentArticle) {
- t_printf (mainWindow, "I shouldn't be here....");
-
- D (("Mail(): exit, why am I here?\n"));
- return;
- }
- if (currentArticle) {
- fd = ScanAndLoadHeaders (p = ArticleName (currentArticle),
- (HEADER_FROM |
- HEADER_REPLY_TO |
- HEADER_PATH |
- HEADER_MESSAGE_ID |
- HEADER_SUBJECT),
- OPT_DONT_CLOSE);
- if (fd < 0) {
- t_printf (mainWindow, "Can't open article %s", p);
-
- D (("Mail(): open input error\n"));
- return;
- }
- }
-
- fname = TempName ();
- if ((outfd = creat (fname, 0660)) < 0) {
- t_printf (mainWindow, "Can't open %s for output", fname);
- if (fd >= 0)
- close (fd);
-
- D (("Mail(): open output error, exit\n"));
- return;
- }
- OutputStrings (outfd, "To: ", NULL);
- if (replyFlag == MAIL_REPLY)
- if (Reply_To)
- OutputStrings (outfd, Reply_To, NULL);
- else
- if (From)
- OutputStrings (outfd, From, NULL);
- else
- OutputStrings (outfd, Path, NULL);
- OutputStrings (outfd, "\n", NULL);
-
- OutputStrings (outfd, "Subject: ", NULL);
- if (replyFlag && Subject) {
- if (strncmp (Subject, "Re: ", 4) != 0)
- OutputStrings (outfd, "Re: ", NULL);
-
- OutputStrings (outfd, Subject, NULL);
-
- if (replyFlag == MAIL_FORWARD) {
- if (p = strrchr (Subject, '(')) {
- if (strncmp (p, "(fwd)", 5) != 0)
- OutputStrings (outfd, " (fwd)", NULL);
- }
- else
- OutputStrings (outfd, " (fwd)", NULL);
- }
- }
- OutputStrings (outfd, "\n", NULL);
-
- if (Message_ID)
- OutputStrings (outfd, "References: ", Message_ID, "\n", NULL);
-
- OutputStrings (outfd, "X-NewsSoftware: ", GRN_VERSION, "\n", NULL);
-
- ApplyMailHeaders (outfd); // also writes the "empty line"
-
- if (replyFlag == MAIL_REPLY) {
- i = TwoGadgetRequest ("GRn - Reply to Article",
- "Include original text in Reply?",
- "_Yes", "_No");
- }
- else
- i = 0;
-
- if ((i && replyFlag == MAIL_REPLY) || replyFlag == MAIL_FORWARD) {
- if (replyFlag == MAIL_FORWARD)
- OutputStrings (outfd, "Originally From: ", From, NULL);
- else {
- OutputStrings (outfd, "In article ",
- Message_ID ? Message_ID : "???",
- " ",
- NULL);
-
- if (From && *From)
- ptr = From;
- else
- ptr = "some unknown individual";
-
- OutputStrings (outfd, ptr, " writes:\n", NULL);
- }
-
- // point file to immediately after the last header
- if (header_len <= 0) {
- t_printf (mainWindow, "Internal error from ScanHeaders()");
- close (fd);
- close (outfd);
- remove (fname);
-
- D (("Mail(): ScanHeaders() error, exit\n"));
- return;
- }
- lseek (fd, header_len + 1, 0);
-
- // This is the same algorithm as from OutputFile(), we just
- // don't worry about wrapCol (instead we use 500 chars as a
- // limit). And we don't do tab expansion.
-
- // This is EXACTLY the same algorithm as in Post().
-
- // FIXME: The prefix "> " should be an option.
-
- #define output(x) { \
- *pout = '\0'; \
- if (replyFlag == MAIL_REPLY) \
- OutputStrings (outfd, "> ", work, "\n", NULL); \
- else \
- if (strncmp (work, "From ", 5) == 0) \
- OutputStrings (outfd, ">", work, "\n", NULL); \
- else \
- OutputStrings (outfd, work, "\n", NULL); \
- outlen = 0; \
- pout = work; \
- *pout = '\0'; \
- }
-
- pout = work;
- *pout = '\0';
- outlen = 0;
- while ((len = read (fd, temp, 512)) > 0) {
- p = temp;
-
- while (len > 0) {
- len--;
- if (*p == '\n') {
- p++;
- output (work);
- continue;
- }
- *pout++ = *p++;
- outlen++;
- if ((outlen >= 500) && (*p != '\n')) {
- *pout++ = '\\';
- outlen++;
- output (work);
- }
- }
- }
- if (outlen)
- output (work);
- #undef output
- if (replyFlag == MAIL_FORWARD)
- OutputStrings (outfd, "---------- End of Forwarded Article ----------\n", NULL);
-
- }
-
- if (fd >= 0)
- close (fd);
- OutputStrings (outfd, "\n-- \n", NULL);
-
- AppendSignature (outfd);
- close (outfd);
-
- SendMail (fname);
-
- D (("Mail(): exit\n"));
- return;
- }
-
- /************************************************************************/
-
- BOOL ParseThread (char *filename, char *refs, char *msgid)
- {
- #if 1
- int fd;
- register char *ps;
-
- References = Message_ID = NULL;
- fd = ScanAndLoadHeaders (filename, HEADER_REFERENCES | HEADER_MESSAGE_ID, 0);
- if (fd < 0)
- return 0;
-
- // FIXME - this only gets the first line of the References header
- if (refs) {
- *refs = '\0';
- if (References) {
- ps = References;
- while (*ps == ' ')
- ps++;
- strcpy (refs, ps);
- }
- }
-
- if (msgid) {
- *msgid = '\0';
- if (Message_ID) {
- ps = Message_ID;
- while (*ps == ' ')
- ps++;
- strcpy (msgid, ps);
- }
- }
- #else
- char temp[512], *ps;
- FILE *fp;
-
- fp = fopen(filename, "r");
- if (!fp) return 0;
- if (refs) *refs = 0;
- if (msgid) *msgid = 0;
- while (fgets(temp, 512, fp)) {
- temp[strlen(temp)-1] = '\0';
- if (!strlen(temp)) break;
- // FIXME - this only gets the first line of the References:
- // header. The header MAY span multiple lines per RFC.
- if (!strnicmp(temp, "References:", 11)) {
- ps = &temp[11];
- while (*ps == ' ') ps++;
- strcpy(refs, ps);
- }
- else if (!strnicmp(temp, "Message-ID:", 11)) {
- ps = &temp[11];
- while (*ps == ' ') ps++;
- strcpy(msgid, ps);
- }
- }
- fclose(fp);
- #endif
- return 1;
- }
-
- char *ArticleName (ART *ap)
- {
- static char temp1 [256];
-
- D (("ArticleName(): enter\n"));
- strcpy (temp1, uunews);
- AddPart (temp1, NewsGroupToFileName (currentGroup->groupName), 256);
- AddPart (temp1, itoa (ap->filenum), 256);
-
- D (("ArticleName(): exit\n"));
- return temp1;
- }
-
- BOOL RefCmp (char *ref1, char *ref2)
- {
- static char r1 [256], r2 [256];
- register char *pd;
- register char *ps;
-
- while (*ref1) {
- // get a reference from ref1 into r1
- pd = r1;
- while (*ref1 && *ref1 != '<')
- ref1++;
- if (*ref1 == '\0')
- return 0;
- while (*ref1 && *ref1 != '>')
- *pd++ = *ref1++;
- if (*ref1 == '>')
- *pd++ = *ref1++;
- *pd = '\0';
- // now compare against all refs in ref2
- ps = ref2;
- while (*ref2) {
- // get a reference from ref2 into r2
- pd = r2;
- while (*ps && *ps != '<')
- ps++;
- if (*ps == '\0')
- return 0;
- while (*ps && *ps != '>')
- *pd++ = *ps++;
- if (*ps == '>')
- *pd++ = *ps++;
- *pd = '\0';
- if (strcmp (r1, r2) == 0) // was stricmp
- return !0;
- }
- }
- return 0;
- }
-
- BOOL NextThread (void)
- {
- ART *ap;
- static char myrefs[512], myid[256], refs[512], msgid[256], subj[256];
- register char *ps;
-
- ps = currentArticle->subject;
- while (*ps == ' ')
- ps++;
- if (strncmp(ps, "Re:", 3) == 0) // was strnicmp
- ps += 3;
- while (*ps == ' ')
- ps++;
- strcpy (subj, ps);
- if (!ParseThread (ArticleName (currentArticle), myrefs, myid))
- return 0;
- ap = currentArticle;
- do {
- if (currentGroup->artList.lh_TailPred == (NODE *) ap)
- ap = (ART *) currentGroup->artList.lh_Head;
- else
- ap = (ART *) ap->node.ln_Succ;
- if (ap->state == UNREAD) {
- if (!ParseThread (ArticleName (ap), refs, msgid))
- continue;
- ps = ap->subject;
- while (*ps == ' ')
- ps++;
- if (strncmp(ps, "Re:", 3) == 0) // was strnicmp
- ps += 3;
- while (*ps == ' ')
- ps++;
- if (RefCmp (myid, refs) || RefCmp (myrefs, refs) ||
- RefCmp (msgid, myrefs) || strcmp (subj, ps) == 0) {
- // was stricmp
- ShowMessage (ap);
- return !0;
- }
- }
- } while (ap != currentArticle);
- return 0;
- }
-
- /************************************************************************/
-
- /*
- * void ProcessGadget(id, code);
- * UWORD id; gadgetID of gadget to process
- * UWORD code; IntuiMessage Code
- *
- * Synopsis:
- * Process IDCMP message for GadTools gadget. Simply prints an appropriate
- * string into the event listview, unless it is palette related (handles
- * palette appropriately).
- */
- static void ProcessGadget (UWORD id, UWORD code)
- {
- /* GADGET *gad = gadgetArray[id]; */
- ART *ap;
- GLIST *start_gp;
- GLIST *gp;
-
- D (("ProcessGadget(): enter, Article Mode\n"));
-
- idcmp_shifted = 0; // if non-zero, someone is screwing with us....
- // they've hit shift, then clicked on a mouse,
- // without hitting any characters....
-
- #if DISABLE_GADGETS
- DisableWindow();
- #endif
- switch (id) {
- case HIDEHEADERS_ID:
- currentGroup->hideHeaders = !currentGroup->hideHeaders;
- treeDirty = 1;
- GT_SetGadgetAttrs (gadgetArray [HIDEHEADERS_ID], mainWindow, NULL,
- GTCB_Checked, currentGroup->hideHeaders ? TRUE : FALSE,
- TAG_DONE
- );
- ShowMessage (currentArticle);
- break;
- case HIDEREAD_ID:
- currentGroup->hideRead = !currentGroup->hideRead;
- treeDirty = 1;
- GT_SetGadgetAttrs (gadgetArray [HIDEREAD_ID], mainWindow, NULL,
- GTCB_Checked, currentGroup->hideRead ? TRUE : FALSE,
- TAG_DONE
- );
- break;
- case NEXTGROUP_ID:
- gp = NextGroup ();
- if (gp != currentGroup) {
- // this circuitous code finds the next non-empty
- // group if one exists, and just goes to the
- // next group if one doesn't.
- start_gp = currentGroup;
- while (gp && gp != start_gp && gp->unread == 0) {
- gp = NextGroup ();
- currentGroup = gp;
- }
- if (!gp)
- gp = start_gp;
- if (gp->unread == 0 && gp == start_gp) {
- currentGroup = gp;
- gp = NextGroup ();
- }
- mode = NEXTGROUPS_MODE;
- currentGroup = gp;
- }
- return; // note: no EnableWindow()!!!
- case PREVGROUP_ID:
- gp = PrevGroup ();
- if (gp != currentGroup) {
- mode = PREVGROUPS_MODE;
- currentGroup = gp;
- }
- return; // note: no EnableWindow()!!!
- case QUIT_ID:
- mode = GROUPS_MODE;
- return; // note: no EnableWindow()!!!
- case SORT_ID:
- currentGroup->sortActive = code;
- treeDirty = !0;
- GT_SetGadgetAttrs (gadgetArray [ARTLIST_ID], mainWindow, NULL,
- GTLV_Labels, ~0, TAG_DONE);
- SortArticles ();
- GT_SetGadgetAttrs (gadgetArray [ARTLIST_ID], mainWindow, NULL,
- GTLV_Labels, ¤tGroup->artList, TAG_DONE);
- ShowMessage (currentArticle);
- break;
- case ARTLIST_ID:
- ap = (ART *) FindListItem (¤tGroup->artList, code);
- if (!ap)
- printf ("Error: Can't FindListItem(%d)\n", code);
- else {
- ShowMessage (ap);
- }
- break;
- case PREV_ID:
- PrevArticle ();
- break;
- case NEXT_ID:
- NextArticle ();
- break;
- case NEXTUNREAD_ID:
- ap = currentArticle;
- do {
- if (currentGroup->artList.lh_TailPred == (NODE *)ap)
- ap = (ART *)currentGroup->artList.lh_Head;
- else
- ap = (ART *)ap->node.ln_Succ;
- if (ap->state == UNREAD) {
- ShowMessage (ap);
- #if DISABLE_GADGETS
- EnableWindow ();
- #endif
- return;
- }
- } while (ap != currentArticle);
- break;
- case NEXTTHREAD_ID:
- if (!NextThread ()) {
- ap = currentArticle;
- do {
- if (currentGroup->artList.lh_TailPred == (NODE *)ap)
- ap = (ART *)currentGroup->artList.lh_Head;
- else
- ap = (ART *)ap->node.ln_Succ;
- if (ap->state == UNREAD) {
- ShowMessage (ap);
- #if DISABLE_GADGETS
- EnableWindow ();
- #endif
- return;
- }
- } while (ap != currentArticle);
- }
- break;
- case CATCHUP_ID:
- Catchup ();
- mode = NEXTGROUPS_MODE;
- return; // note: no EnableWindow()!!!
- case REPLY_ID:
- Mail (MAIL_REPLY);
- break;
- case FOLLOWUP_ID:
- Post (TRUE);
- break;
- case POST_ID:
- Post (FALSE);
- break;
- case FORWARD_ID:
- Mail (MAIL_FORWARD);
- break;
- case PRINT_ID:
- Print ();
- break;
- case SAVE_ID:
- Save ();
- break;
- default:
- t_printf (mainWindow, "ProcessGadget - id = %d", id); break;
- }
- #if DISABLE_GADGETS
- EnableWindow ();
- #endif
-
- D (("ProcessGadget(): exit, Article Mode\n"));
-
- return;
- }
-
- static void IDCMPFunc (IMSG *m)
- {
- GLIST *gp;
- GLIST *start_gp;
- ART *ap;
-
- D (("IDCMPFunc(): enter, Article Mode, m->Class = 0x%x, m->Code = 0x%x\n", m->Class, m->Code));
-
- #if DISABLE_GADGETS
- DisableWindow();
- #endif
- switch (m->Class) {
- default:
- idcmp_shifted = 0;
- break;
-
- case IDCMP_CLOSEWINDOW:
- idcmp_shifted = 0;
- mode = ABORT_MODE;
- D (("IDCMPFunc(): exit 1\n"));
- return; // note: no EnableWindow()!!!
-
- case IDCMP_VANILLAKEY:
- idcmp_shifted = 0;
- switch (m->Code) {
-
- case 0x0d:
- // ENTER (numeric keypad)
- // RETURN (main keypad)
- viewTop++;
- if (viewTop > (messageLines - viewHeight))
- viewTop = messageLines -
- viewHeight;
- if (viewTop < 0)
- viewTop = 0;
- GT_SetGadgetAttrs (gadgetArray [MSGLIST_ID], mainWindow, NULL,
- GTLV_Top, viewTop, TAG_DONE);
- break;
-
- case 'F':
- Post (TRUE);
- break;
-
- case 'R':
- Mail (MAIL_REPLY);
- break;
-
- case 'n':
- NextArticle ();
- break;
-
- case 'b':
- case 'p':
- PrevArticle ();
- break;
-
- case 'C':
- Catchup ();
- mode = NEXTGROUPS_MODE;
- D (("IDCMPFunc(): exit 2\n"));
- return; // note: no EnableWindow()!!!
-
- case 'N':
- gp = NextGroup ();
- if (gp == currentGroup)
- break;
- start_gp = currentGroup;
- while (gp && gp != start_gp && gp->unread == 0) {
- gp = NextGroup ();
- currentGroup = gp;
- }
- if (!gp)
- gp = start_gp;
- if (gp->unread == 0 && gp == start_gp) {
- currentGroup = start_gp;
- gp = NextGroup ();
- }
- mode = NEXTGROUPS_MODE;
- currentGroup = gp;
- D (("IDCMPFunc(): exit 3\n"));
- return; // note: no EnableWindow()!!!
-
- case 'P':
- gp = PrevGroup ();
- if (gp == currentGroup)
- break;
- mode = PREVGROUPS_MODE;
- currentGroup = gp;
- D (("IDCMPFunc(): exit 4\n"));
- return; // note: no EnableWindow()!!!
-
- case ' ':
- viewTop += viewHeight - 1;
- if (viewTop > messageLines-viewHeight)
- viewTop = messageLines - viewHeight;
- if (viewTop < 0)
- viewTop = 0;
- GT_SetGadgetAttrs (gadgetArray [MSGLIST_ID], mainWindow, NULL,
- GTLV_Top, viewTop, TAG_DONE);
- break;
-
- case 'G':
- mode = GROUPS_MODE;
- D (("IDCMPFunc(): exit 5\n"));
- return; // note: no EnableWindow()!!!
-
- case 'S':
- Save ();
- break;
-
- case 't':
- if (!NextThread ()) {
- ap = currentArticle;
- do {
- if (currentGroup->artList.lh_TailPred == (NODE *)ap)
- ap = (ART *)currentGroup->artList.lh_Head;
- else
- ap = (ART *)ap->node.ln_Succ;
- if (ap->state == UNREAD) {
- ShowMessage (ap);
- #if DISABLE_GADGETS
- EnableWindow ();
- #endif
- return;
- }
- } while (ap != currentArticle);
- }
- break;
-
- case 'u':
- ap = currentArticle;
- do {
- if (currentGroup->artList.lh_TailPred == (NODE *)ap)
- ap = (ART *)currentGroup->artList.lh_Head;
- else
- ap = (ART *)ap->node.ln_Succ;
- if (ap->state == UNREAD) {
- ShowMessage (ap);
- #if DISABLE_GADGETS
- EnableWindow();
- #endif
- return;
- }
- } while (ap != currentArticle);
- break;
- }
- break;
-
- case IDCMP_RAWKEY:
- switch (m->Code) {
- case 0x4c: // up arrow key
- if (idcmp_shifted)
- viewTop = 0;
- else {
- viewTop--;
- if (viewTop < 0)
- viewTop = 0;
- }
- GT_SetGadgetAttrs (gadgetArray [MSGLIST_ID], mainWindow, NULL,
- GTLV_Top, viewTop, TAG_DONE);
- idcmp_shifted = 0;
- break;
- #if 0
- // These never make it here. They are "cooked"
- // and returned as vanilla-keys (newline)
- case 0x43: // enter key (numeric keypad)
- case 0x44: // return key (main keypad)
- idcmp_shifted = 0;
- // fall-through on purpose
- #endif
- case 0x4d: // down arrow key
- if (idcmp_shifted)
- viewTop = messageLines -
- viewHeight;
- else {
- viewTop++;
- if (viewTop > (messageLines - viewHeight))
- viewTop = messageLines -
- viewHeight;
- if (viewTop < 0)
- viewTop = 0;
- }
- GT_SetGadgetAttrs (gadgetArray [MSGLIST_ID], mainWindow, NULL,
- GTLV_Top, viewTop, TAG_DONE);
- idcmp_shifted = 0;
- break;
- case 0x60:
- case 0x61:
- D (("IDCMPFunc(): Shift in\n"));
- idcmp_shifted = 1;
- break;
- #if 0
- // These never happen. They get "cooked".
- case 0xe0:
- case 0xe1:
- // Tthis will never happen, since we set
- // RAWKEY | VANILLAKEY. See the Includes
- // RKM (2.0), page 347, right after the
- // discussion on IDCMP_VANILLAKEY.
- D (("IDCMPFunc(): Shift out\n"));
- idcmp_shifted = 0;
- break;
- #endif
- default:
- idcmp_shifted = 0;
- D (("IDCMPFunc(): m->Code = 0x%x\n", m->Code & 0xff));
- }
- break;
-
- }
- #if DISABLE_GADGETS
- EnableWindow();
- #endif
-
- D (("IDCMPFunc(): exit, Article Mode\n"));
- return;
- }
-
- void ArticlesWindow (void)
- {
- ART *ap;
- UWORD n = 0;
-
- D (("ArticlesWindow(): enter\n"));
-
- if (!currentGroup || currentGroup->articles == 0) {
- mode = GROUPS_MODE;
-
- D (("ArticlesWindow(): no group, exit\n"));
- return;
- }
-
- #if DISABLE_GADGETS
- DisableWindow ();
- #endif
- NewList (&msgList);
- LayoutGadgets (defaultFont, prefWidth, windowHeight, screenTop);
- gList = CreateGadgets (gadgetArray, gadDefs);
- AddGList (mainWindow, gList, -1, -1, 0);
- RefreshGList (gList, mainWindow, 0, -1);
-
- while (1) {
- // stay in here while we get Next Group and/or Prev Group click
-
- t_printf (mainWindow, "GRn - %s", currentGroup->groupName);
-
- // FIX-ME: do we need to do this every time we enter a group?
- // ANSWER -- this is a net win if the user only enters some newsgroups,
- // and/or only enters a newsgroup a single time. If he goes back, he
- // pays a price. Don't change right now.
-
- GT_SetGadgetAttrs (gadgetArray [ARTLIST_ID], mainWindow, NULL,
- GTLV_Labels, ~0, TAG_DONE);
-
- GT_SetGadgetAttrs (gadgetArray [MSGLIST_ID], mainWindow, NULL,
- GTLV_Labels, ~0, TAG_DONE);
-
- GT_RefreshWindow (mainWindow, NULL);
-
- for (ap = (ART *) currentGroup->artList.lh_Head;
- ap->node.ln_Succ;
- ap = (ART *) ap->node.ln_Succ) {
-
- sprintf (ap->node.ln_Name, "%s %6d %-32.32s %s",
- ap->state?" READ ":"UNREAD ",
- ap->filenum,
- ap->from,
- ap->subject
- );
- }
- // FIX-ME -- sort EVERY time? why?
- // ANSWER: see the above.
- SortArticles ();
-
- GT_SetGadgetAttrs (gadgetArray [ARTLIST_ID], mainWindow, NULL,
- GTLV_Labels, ¤tGroup->artList, TAG_DONE);
- GT_SetGadgetAttrs (gadgetArray [SORT_ID], mainWindow, NULL,
- GTCY_Active, currentGroup->sortActive, TAG_DONE);
-
- if (currentGroup->unread == 0) { // show last READ message
- #ifdef MICHAEL_REMOVED_THIS
- // this is only need if the section MYKE_REMOVED_THIS below
- // is re-enabled
- for (ap=(ART *)currentGroup->artList.lh_Head;
- ap->node.ln_Succ;
- ap = (ART *)ap->node.ln_Succ) {
-
- n++;
- }
- #endif
- ShowMessage ((ART *) currentGroup->artList.lh_TailPred);
- }
- else { // show first unread message
- for (ap=(ART *)currentGroup->artList.lh_Head;
- ap->node.ln_Succ;
- ap = (ART *)ap->node.ln_Succ) {
-
- if (ap->state == UNREAD)
- break;
- #ifdef MICHAEL_REMOVED_THIS
- n++;
- #endif
- }
- ShowMessage (ap);
- }
- #ifdef MYKE_REMOVED_THIS
- GT_SetGadgetAttrs (gadgetArray [ARTLIST_ID], mainWindow, NULL,
- GTLV_Selected, n,
- GTLV_Top, n,
- TAG_DONE
- );
- #endif
-
- GT_SetGadgetAttrs (gadgetArray [HIDEHEADERS_ID], mainWindow, NULL,
- GTCB_Checked, currentGroup->hideHeaders ? TRUE : FALSE,
- TAG_DONE
- );
- GT_SetGadgetAttrs (gadgetArray [HIDEREAD_ID], mainWindow, NULL,
- GTCB_Checked, currentGroup->hideRead ? TRUE : FALSE,
- TAG_DONE
- );
- #if DISABLE_GADGETS
- EnableWindow();
- #endif
- while (mode == ARTICLES_MODE) {
- WaitPort (mainWindow->UserPort);
- EventHandler (mainWindow, ProcessGadget, IDCMPFunc, NULL);
- }
-
- FreeListNode (&msgList);
-
- if ((mode != NEXTGROUPS_MODE) && (mode != PREVGROUPS_MODE)) {
- CloseArticles ();
- #if DISABLE_GADGETS
- EnableWindow ();
- #endif
- D (("ArticlesWindow(): new mode, exit\n"));
- return;
- }
- // so, we did a next group or a prev group. Do it again.
- mode = ARTICLES_MODE;
- NewList (&msgList);
- // loop...
- } // ... while (1) ...
- /* NOTREACHED */
- D (("ArticlesWindow(): exit, how the hell did we get here?\n"));
- return;
- }
-