home *** CD-ROM | disk | FTP | other *** search
- #include "defs.h"
-
- extern char *FileNameToNewsGroup (char *filename);
- extern char *NewsGroupToFileName (char *newsgroup);
-
- static LIST nullList;
- GLIST *currentGroup = 0;
-
- ULONG totalGroups = 0, totalArticles = 0, unreadArticles = 0;
-
- /************************************************************************/
-
- /*
- * 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 {
- GROUPLIST_ID,
- QUIT_ID,
- READ_ID,
- POST_ID,
- CATCHUP_ID,
- PUBLISH_ID,
- JUNK_ID,
- BUGREPORT_ID,
- UUCPBUG_ID,
- STATUS_ID,
- MAXGADGET,
- };
-
- static GADGET *gadgetArray[MAXGADGET];
-
- /*
- * 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 groupListTags[] = {
- GT_Underscore, '_',
- GTLV_Top, 0,
- GTLV_Labels, &groupList,
- GTLV_ReadOnly, FALSE,
- GTLV_ScrollWidth, 16,
- GTLV_ShowSelected, NULL,
- GTBB_Recessed, FALSE,
- TAG_DONE, 0,
- };
-
- static TAGS nullListTags[] = {
- GT_Underscore, '_',
- GTLV_Top, 0,
- GTLV_Labels, &nullList,
- GTLV_ReadOnly, FALSE,
- GTLV_ScrollWidth, 16,
- GTBB_Recessed, FALSE,
- 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[] = {
- groupListTags, LISTVIEW_KIND,0,0,0,0, NG_HIGHLABEL, "",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "Quit",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Read",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Post",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Catch up",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "Publish",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Junk",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Bug Report",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_UUCP Bug Report",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "",
- 0,0,0,0,0,0,0,0,
- };
-
- static GADGET *gList = 0;
-
- static void LayoutGadgets(font,width,height,top)
- FONT *font;
- short width,height,top;
- {
- short i, x,y, fh;
- RPORT rPort, *rp = &rPort;
-
- InitRastPort(rp);
- SetFont(rp, font);
- y = top+INTERHEIGHT/2;
-
- fh = rp->TxHeight+2;
- gadDefs[GROUPLIST_ID].left = INTERWIDTH;
- gadDefs[GROUPLIST_ID].top = y;
- gadDefs[GROUPLIST_ID].width = width-INTERWIDTH-INTERWIDTH;
- gadDefs[GROUPLIST_ID].height = 12*fh+INTERHEIGHT;
- y += 12*fh+INTERHEIGHT;
-
- fh = topazRP->TxHeight+2;
- x = INTERWIDTH;
- for (i=QUIT_ID; i<=UUCPBUG_ID; i++) {
- gadDefs[i].left = x;
- gadDefs[i].top = y;
- gadDefs[i].width = TextLen(topazRP, gadDefs[i].text)+8;
- gadDefs[i].height = fh+2;
- x += gadDefs[i].width + INTERWIDTH;
- }
- y += fh+INTERHEIGHT+fh+INTERHEIGHT+fh+INTERHEIGHT;
- y += height-y-fh-fh-INTERHEIGHT-4;
-
- 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;
- }
-
- /************************************************************************/
-
- void CloseGroups() {
- if (!gList) return;
- if (RemoveGList(mainWindow, gList, -1) == -1) {
- printf("RemoveGList() failed\n");
- return;
- }
- FreeGadgets(gList);
- gList = 0;
- ClearWindow();
- }
-
- void GroupsStatus() {
- GLIST *gp;
- ART *ap;
- static char groupStatus[256];
-
-
- totalGroups = 0; totalArticles = 0; unreadArticles = 0;
- for (gp=(GLIST *)groupList.lh_Head; gp->node.ln_Succ; gp=(GLIST *)gp->node.ln_Succ) {
- gp->articles = gp->unread = 0;
- totalGroups++;
- for (ap=(ART *)gp->artList.lh_Head; ap->node.ln_Succ; ap = (ART *)ap->node.ln_Succ) {
- totalArticles++; gp->articles++;
- if (ap->state == UNREAD) { unreadArticles++; gp->unread++; }
- }
- sprintf(gp->header, "%-40.40s %6d articles %6d UnRead", gp->groupName, gp->articles, gp->unread);
- }
- sprintf(groupStatus, " *** %d groups, %d articles (%d unread)", totalGroups, totalArticles, unreadArticles);
- GT_SetGadgetAttrs(gadgetArray[STATUS_ID], mainWindow, NULL, GTTX_Text, groupStatus, TAG_DONE);
- }
-
- UWORD GroupID() {
- UWORD n;
- GLIST *gp = (GLIST *)groupList.lh_Head;
- n = 0;
- while (gp->node.ln_Succ) {
- if (gp == currentGroup) return n;
- gp = (GLIST *)gp->node.ln_Succ;
- n++;
- }
- return ~0;
- }
-
- static void ValidateOptions() {
- short i;
-
- if (!currentGroup) {
- for (i=READ_ID; i<=PUBLISH_ID; i++) {
- GT_SetGadgetAttrs(gadgetArray[i], mainWindow, NULL, GA_Disabled, TRUE, TAG_DONE);
- }
- return;
- }
- if (currentGroup->articles == 0) {
- GT_SetGadgetAttrs(gadgetArray[READ_ID], mainWindow, NULL, GA_Disabled, TRUE, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[CATCHUP_ID], mainWindow, NULL, GA_Disabled, TRUE, TAG_DONE);
- return;
- }
- if (currentGroup->unread == 0) {
- GT_SetGadgetAttrs(gadgetArray[READ_ID], mainWindow, NULL, GA_Disabled, FALSE, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[CATCHUP_ID], mainWindow, NULL, GA_Disabled, TRUE, TAG_DONE);
- return;
- }
- for (i=READ_ID; i<=PUBLISH_ID; i++) {
- GT_SetGadgetAttrs(gadgetArray[i], mainWindow, NULL, GA_Disabled, FALSE, TAG_DONE);
- }
- }
-
- /************************************************************************/
-
- // Junk an existing newsgroup
- //
- // This only involves removing the group (and its articles) from the newstree
- // THEY WILL STAY IN THE UUNEWS: DIRECTORY
- //
- void Junk(BOOL flag) {
- ART *ap;
- GLIST *gp;
-
- if (flag) {
- if (!TwoGadgetRequest("GRn - Request", " Remove this group from your Active list?", "_YES", "_NO")) return;
- }
- while (!EmptyList(¤tGroup->artList)) {
- ap = (ART *)RemHead(¤tGroup->artList);
- if (ap->from) free(ap->from);
- if (ap->subject) free(ap->subject);
- free(ap);
- }
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Labels, ~0, TAG_DONE);
- gp = (groupList.lh_TailPred == (NODE *)currentGroup) ? (GLIST *)groupList.lh_Head : (GLIST *)currentGroup->node.ln_Succ;
- Remove((NODE *)currentGroup);
- free(currentGroup);
- currentGroup = gp;
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Labels, &groupList, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Selected, GroupID(), TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Top, GroupID(), TAG_DONE);
- treeDirty = !0;
- }
-
- /************************************************************************/
-
- void BugReport() {
- char fname[256], temp[512], work[256];
- FILE *fp, *outfp;
-
- sprintf(fname, "t:%s%x-text.txt", userName, FindTask(0));
- unlink(fname);
- outfp = fopen(fname, "w");
- if (!outfp) {
- t_printf(mainWindow, "Can't open %s for output", fname);
- return;
- }
- fprintf(outfp, "To: grnbugs@amiga0.sf-bay.org\n");
- fprintf(outfp, "Subject: Bug Report For %s\n", GRN_VERSION);
- fprintf(outfp, "X-NewsSoftware: %s\n\n", GRN_VERSION);
- fprintf(outfp, "\n--\n");
- strcpy(temp, uulib);
- sprintf(work, "%s.signature", userName);
- AddPart(temp, work, 256);
- fp = fopen(temp, "r");
- if (!fp) {
- strcpy(temp, uulib);
- AddPart(temp, ".signature", 256);
- fp = fopen(temp, "r");
- }
- if (!fp) {
- fprintf(outfp, ".signature under construction\n");
- }
- else {
- while (fgets(temp, 512, fp)) {
- fprintf(outfp, "%s", temp);
- }
- fclose(fp);
- }
- fclose(outfp);
- sprintf(temp, "%s %s", mailEditor, fname);
- Execute(temp, 0,0);
- if (!TwoGadgetRequest("GRn - Request", " Send it off? ", "_YES", "_NO")) return;
- sprintf(temp, "%s >nil: <%s -f %s",
- sendMail, fname, userName
- );
- Execute(temp, 0,0);
- unlink(fname);
- }
-
- /************************************************************************/
-
- void UUCPBugReport() {
- char fname[256], rname[256], temp[512];
- char work[256];
- FILE *fp, *outfp;
-
- sprintf(fname, "t:%s%x-text.txt", userName, FindTask(0));
- unlink(fname);
- outfp = fopen(fname, "w");
- if (!outfp) {
- t_printf(mainWindow, "Can't open %s for output", fname);
- return;
- }
- fprintf(outfp, "Newsgroups: alt.sys.amiga.uucp\n");
- fprintf(outfp, "Subject: UUCP Bug report from GRn\n");
- fprintf(outfp, "Distribution: world\n\n");
- fprintf(outfp, "##B <personal identifier>\n\n");
- fprintf(outfp, "The above <personal identifier> is for the\n");
- fprintf(outfp, "bug reporter can use for whatever internal tracking he wants\n");
- fprintf(outfp, "to do (it should be unique on a person by person basis).\n");
- fprintf(outfp, "\n##\n");
- fprintf(outfp, "\n--\n");
-
- strcpy(temp, uulib);
- sprintf(work, "%s.signature", userName);
- AddPart(temp, work, 256);
- fp = fopen(temp, "r");
- if (!fp) {
- strcpy(temp, uulib);
- AddPart(temp, ".signature", 256);
- fp = fopen(temp, "r");
- }
- if (!fp) {
- fprintf(outfp, ".signature under construction\n");
- }
- else {
- while (fgets(temp, 512, fp)) {
- fprintf(outfp, "%s", temp);
- }
- fclose(fp);
- }
- fclose(outfp);
- sprintf(temp, "%s %s", newsEditor, fname);
- Execute(temp, 0,0);
- if (!SendItRequest()) return;
- sprintf(rname, "t:%s%x-refs.txt", userName, FindTask(0));
- unlink(rname);
- outfp = fopen(rname, "w");
- if (outfp) fprintf(outfp, "X-NewsSoftware: %s\n", GRN_VERSION);
- if (outfp) {
- fclose(outfp);
- sprintf(temp, "RUN <nil: >nil: %s %s -R %s -x %s -x %s",
- postNews, fname, rname, fname, rname
- );
- }
- else {
- sprintf(temp, "RUN <nil: >nil: %s %s -x %s",
- postNews, fname, fname
- );
- }
- Execute(temp, 0,0);
- GT_RefreshWindow(mainWindow, NULL);
- }
-
- /************************************************************************/
-
- void Catchup() {
- ART *ap;
-
- if (!currentGroup) return;
- currentGroup->articles = currentGroup->unread = 0;
- for (ap=(ART *)currentGroup->artList.lh_Head; ap->node.ln_Succ; ap = (ART *)ap->node.ln_Succ) {
- ap->state = READ;
- currentGroup->articles++;
- treeDirty = !0;
- }
- }
-
- /************************************************************************/
-
- void Publish() {
- char inname[256], outname[256], partname[256], rname[256], temp[512], work[256];
- STRPTR filename;
- FILE *infp, *outfp, *fp;
- UWORD i, line, lineCount = 0, parts, part;
-
- if (!AslRequestTags(publishReq, TAG_DONE)) return;
- strcpy(inname, publishReq->rf_Dir);
- AddPart(inname, publishReq->rf_File, 256);
-
- if (!SendItRequest()) return;
- sprintf(outname, "t:%s%x-text.uu", userName, FindTask(0));
- unlink(outname);
- filename = FilePart(inname);
- sprintf(work, "uuencode >%s %s %s", outname, inname, filename);
- t_printf(mainWindow, "GRn - UUEncoding %s", filename);
- Execute(work, 0,0);
- infp = fopen(outname, "r");
- if (!infp) {
- OneGadgetRequest("GRN Error", "Can't open uuencoded file", "Cancel Publish");
- return;
- }
- while (fgets(work, 512, infp)) lineCount++;
- fclose(infp);
- parts = (lineCount+499) / 500;
-
- infp = fopen(outname, "r");
- if (!infp) {
- OneGadgetRequest("GRN Error", "Can't open uuencoded file", "Cancel Publish");
- return;
- }
-
- line = 0;
- for (part = 1; part <= parts; part++) {
- t_printf(mainWindow, "Publishing part %d of %d", part, parts);
- sprintf(partname, "t:%s%x-text.txt", userName, FindTask(0));
- outfp = fopen(partname, "w");
- if (!outfp) {
- fclose(infp);
- OneGadgetRequest("GRN Error", "Can't open uuencoded file", "Cancel Publish");
- return;
- }
- fprintf(outfp, "Newsgroups: %s\n", currentGroup->groupName);
- if (parts > 9 && part < 10) {
- fprintf(outfp, "Subject: Posting of %s (Part %02d/%d)\n", filename, part, parts);
- }
- else {
- fprintf(outfp, "Subject: Posting of %s (Part %d/%d)\n", filename, part, parts);
- }
- fprintf(outfp, "Distribution: world\n\n");
-
- sprintf(work, "Posting %s in %d parts", filename, parts);
- for (i=0; line<lineCount && i < 500; i++, line++) {
- GuageRequest(100*line/lineCount, "GRn - Publishing", work, "STOP");
- if (!fgets(temp, 512, infp)) { line = lineCount; part = parts+1; break; }
- fprintf(outfp, "%s", temp);
- }
- fprintf(outfp, "\n--\n");
-
- strcpy(temp, uulib);
- sprintf(work, "%s.signature", userName);
- AddPart(temp, work, 256);
- fp = fopen(temp, "r");
- if (!fp) {
- strcpy(temp, uunews);
- AddPart(temp, NewsGroupToFileName (currentGroup->groupName), 256);
- AddPart(temp, work, 256);
- fp = fopen(temp, "r");
- }
- if (!fp) {
- strcpy(temp, uulib);
- AddPart(temp, ".signature", 256);
- fp = fopen(temp, "r");
- }
- if (!fp) {
- fprintf(outfp, ".signature under construction\n");
- }
- else {
- while (fgets(temp, 512, fp)) {
- fprintf(outfp, "%s", temp);
- }
- fclose(fp);
- }
- fclose(outfp);
-
- sprintf(rname, "t:%s%x-refs.txt", userName, FindTask(0));
- unlink(rname);
- outfp = fopen(rname, "w");
- if (outfp) fprintf(outfp, "X-NewsSoftware: %s\n", GRN_VERSION);
- if (outfp) {
- fclose(outfp);
- sprintf(temp, "%s %s -R %s -x %s -x %s",
- postNews, partname, rname, partname, rname
- );
- }
- else {
- sprintf(temp, "%s %s -x %s",
- postNews, partname, partname
- );
- }
- Execute(temp, 0,0);
- unlink(partname);
- }
- GuageRequest(1000, "GRn - Publishing", work, "STOP");
- fclose(infp);
- t_printf(mainWindow, "GRn - News Directory");
- GT_RefreshWindow(mainWindow, NULL);
- }
-
- /************************************************************************/
-
- /*
- * 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]; */
- GLIST *gp;
-
- switch (id) {
- case GROUPLIST_ID:
- gp = (GLIST *)FindListItem(&groupList, code);
- if (gp == currentGroup) { mode = ARTICLES_MODE; break; }
- if (!gp) {
- t_printf(mainWindow, "Error: Can't FindListItem(%d)\n", code);
- break;
- }
- currentGroup = gp;
- ValidateOptions();
- break;
- case QUIT_ID:
- mode = QUIT_MODE;
- break;
- case READ_ID:
- mode = ARTICLES_MODE;
- break;
- case CATCHUP_ID:
- Catchup();
- GroupsStatus();
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Labels, ~0, TAG_DONE);
- sprintf(currentGroup->header, "%-40.40s %6d articles %6d UnRead",
- currentGroup->groupName,
- currentGroup->articles,
- currentGroup->unread
- );
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Labels, &groupList, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Selected, GroupID(), TAG_DONE);
- break;
- case POST_ID:
- Post(FALSE);
- break;
- case BUGREPORT_ID:
- BugReport();
- break;
- case JUNK_ID:
- Junk(!0);
- break;
- case PUBLISH_ID:
- Publish();
- break;
- case UUCPBUG_ID:
- UUCPBugReport();
- break;
- default:
- t_printf(mainWindow, "ProcessGadget - id = %d", id); break;
- }
- }
-
- static void IDCMPFunc(m)
- IMSG *m;
- {
- GLIST *NextGroup(), *PrevGroup();
-
- switch (m->Class) {
- case IDCMP_CLOSEWINDOW:
- mode = ABORT_MODE;
- break;
- case IDCMP_VANILLAKEY:
- switch (m->Code) {
- case 'R': if (currentGroup->articles) mode = ARTICLES_MODE;
- break;
- case 'P': Post(FALSE); break;
- case 'C': if (currentGroup->unread) {
- Catchup();
- GroupsStatus();
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Labels, ~0, TAG_DONE);
- sprintf(currentGroup->header, "%-40.40s %6d articles %6d UnRead",
- currentGroup->groupName,
- currentGroup->articles,
- currentGroup->unread
- );
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Labels, &groupList, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Selected, GroupID(), TAG_DONE);
- }
- break;
- case 'B': BugReport(); break;
- case 'J': Junk(0); break;
- case 'U': UUCPBugReport(); break;
- }
- break;
- case IDCMP_RAWKEY:
- switch (m->Code) {
- case 0x4c: // up key
- currentGroup = PrevGroup();
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Selected, GroupID(), TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Top, GroupID(), TAG_DONE);
- break;
- case 0x4d: // down key
- currentGroup = NextGroup();
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Selected, GroupID(), TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Top, GroupID(), TAG_DONE);
- break;
- }
- default:
- break;
- }
- }
-
- void GroupsWindow() {
- if (!currentGroup) currentGroup = (GLIST *)groupList.lh_Head;
- if (mode == NEXTGROUPS_MODE || mode == PREVGROUPS_MODE) {
- mode = ARTICLES_MODE;
- return;
- }
- NewList(&nullList);
- LayoutGadgets(defaultFont, prefWidth,windowHeight, screenTop);
- gList = CreateGadgets(&gadgetArray[0], &gadDefs[0]);
- AddGList(mainWindow, gList, -1, -1, 0);
- RefreshGList(gList, mainWindow, 0, -1);
- GT_RefreshWindow(mainWindow, NULL);
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Labels, ~0, TAG_DONE);
- GroupsStatus();
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Labels, &groupList, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Selected, GroupID(), TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[GROUPLIST_ID], mainWindow, NULL, GTLV_Top, GroupID(), TAG_DONE);
- ValidateOptions();
- t_printf(mainWindow, "GRn - News Directory");
- while (mode == GROUPS_MODE) {
- WaitPort (mainWindow->UserPort);
- EventHandler(mainWindow, ProcessGadget, IDCMPFunc, NULL);
- }
- CloseGroups();
- }
-