home *** CD-ROM | disk | FTP | other *** search
- #include "defs.h"
-
- extern char *FileNameToNewsGroup (char *filename); /* IMPORT */
- extern char *NewsGroupToFileName (char *newsgroup); /* IMPORT */
- extern int BuildHierarchicalList (void); /* IMPORT */
-
- int hierarchical = 0; /* EXPORT */
-
- #include <stdarg.h>
- #include <stdio.h>
-
- ULONG grnrcVersion = '1.20';
- UWORD windowHeight;
- UWORD wrapCol = 82; // selectable wrap point for articles
-
- /************************************************************************/
-
- FILEREQ *saveReq = 0;
- FILEREQ *publishReq = 0;
-
- static MPORT *port = 0;
- char userName[256], grnrcName[256];
- char newsEditor[256], mailEditor[256];
- char postNews[256], sendMail[256];
- char uunews[256] = "UUNEWS:";
- char uulib[256] = "UULIB:";
- char uuspool[256] = "UUSPOOL:";
- char logfile[256] = "";
-
- BOOL treeDirty = 0;
-
- LIST groupList;
-
- LOCK lock = 0;
- FIB *fib = 0;
-
- WINDOW *mainWindow = 0;
-
- UWORD mode = GROUPS_MODE;
-
- void ClearWindow( void ) {
- WORD x, y, x1, y1;
-
- x = mainWindow->BorderLeft;
- y = mainWindow->BorderTop;
- x1 = mainWindow->Width - mainWindow->BorderRight - 1;
- y1 = mainWindow->Height - mainWindow->BorderBottom - 1;
-
- SetAPen( mainWindow->RPort, 0);
- SetDrMd( mainWindow->RPort, JAM1 );
- RectFill( mainWindow->RPort, x, y, x1, y1 );
-
- RefreshWindowFrame( mainWindow );
- }
-
- void CloseMain() {
- if (publishReq) { FreeFileRequest(publishReq); publishReq = 0; }
- if (saveReq) { FreeFileRequest(saveReq); saveReq = 0; }
- if (fib) {
- FreeDosObject(DOS_FIB, (void *)fib);
- fib = 0;
- }
- if (lock) {
- UnLock(lock);
- lock = 0;
- }
- if (mainWindow) {
- CloseWindow(mainWindow);
- mainWindow = 0;
- }
- }
-
- /*
- * void Abort(void);
- *
- * Synopsis:
- * Cleanup and exit. Can be called anywhere, anytime, including from
- * the debugger by setting PC = Abort.
- */
- long abort_code = 0;
- void Abort(void) {
- CloseGroups();
- CloseMain();
- if (port) DeletePort(port);
- CloseSystem();
- exit(abort_code);
- }
-
- /*
- * void panic0(v, s,a1,a2,a3,a4);
- * ULONG v;
- * char *s;
- * ULONG a1,a2,a3,a4;
- *
- * Synopsis:
- * Anywhere you use:
- * v = (some function);
- * if (!v) {
- * printf("some string");
- * Abort();
- * }
- * You can use:
- * v = (some function);
- * panic0(v, "some string");
- * The string and args (a1,a2,a3,a4) are passed to printf...
- */
- void panic0(APTR v, const char *s, ...) {
- FILE *outfp;
- va_list va;
-
- va_start(va, s);
- if (v) return;
- printf("Panic: ");
- _pfmt(s, va, fwrite, stdout);
- printf("\n");
- if (!logfile[0]) sprintf(logfile, "UUSPOOL:logfile");
- outfp = fopen(logfile, "a");
- if (outfp) {
- fprintf(outfp, "GRn panic: ");
- _pfmt(s, va, fwrite, outfp);
- fprintf(outfp, "\n");
- fclose(outfp);
- }
- va_end(va);
- abort_code = 999;
- Abort();
- }
-
- void panic(const char *s, ...) {
- FILE *outfp;
- va_list va;
-
- va_start(va, s);
- printf("Panic: ");
- printf(s, va);
- _pfmt(s, va, fwrite, stdout);
- printf("\n");
- if (!logfile[0]) sprintf(logfile, "UUSPOOL:logfile");
- outfp = fopen(logfile, "a");
- if (outfp) {
- fprintf(outfp, "GRn panic: ");
- _pfmt(s, va, fwrite, outfp);
- fprintf(outfp, "\n");
- fclose(outfp);
- }
- va_end(va);
- abort_code = 999;
- Abort();
- }
-
- /************************************************************************/
-
- UBYTE *mbuf = 0, *mbufp, *mbufe;
-
- void mclose(void) { if (mbuf) { free(mbuf); mbuf = 0; } }
- BOOL mopen(char *fn) {
- int fd;
- ULONG size;
-
- mclose();
- fd = open(fn, O_READ);
- if (fd == -1) return 0;
- size = lseek(fd, 0, 2); lseek(fd, 0, 0);
- mbuf = (UBYTE *)malloc(size);
- if (!mbuf) { close(fd); return 0; }
- read(fd, mbuf, size);
- close(fd);
- mbufp = mbuf;
- mbufe = &mbufp[size];
- return !0;
- }
-
- BOOL mread(buf, size)
- UBYTE *buf;
- ULONG size;
- {
- ULONG i;
-
- if (!mbuf || mbufp == mbufe) return 0;
- for (i=0; i<size; i++) *buf++ = (mbufp == mbufe) ? 0 : *mbufp++;
- return !0;
- }
-
- BOOL mgets(buf)
- UBYTE *buf;
- {
- if (mbufp == mbufe) return 0;
- while (mbufp != mbufe && (*buf++ = *mbufp++));
- *buf++ = '\0';
- return !0;
- }
-
- /************************************************************************/
-
- BOOL EmptyList(list)
- LIST *list;
- {
- if (list->lh_TailPred == (NODE *)list) return !0;
- return 0;
- }
-
- NODE *FindListItem(list, num)
- LIST *list;
- short num;
- {
- NODE *np;
-
- for (np = list->lh_Head; np->ln_Succ; np=np->ln_Succ) {
- if (!num) return np;
- num--;
- }
- return 0;
- }
-
- void SortList(list, col)
- LIST *list;
- short col;
- {
- LIST tmp;
- NODE *np, *np2;
-
- if (EmptyList(list)) return;
- NewList(&tmp);
- while (!EmptyList(list)) {
- np = RemHead(list);
- if (EmptyList(&tmp)) {
- AddHead(&tmp, np);
- }
- else {
- if (strcmp(&np->ln_Name[col], &tmp.lh_Head->ln_Name[col]) < 0) {
- AddHead(&tmp, np);
- }
- else if (strcmp(&np->ln_Name[col], &tmp.lh_TailPred->ln_Name[col]) > 0) {
- AddTail(&tmp, np);
- }
- else {
- for (np2=tmp.lh_Head; np2->ln_Succ; np2=np2->ln_Succ) {
- if (strcmp(&np->ln_Name[col], &np2->ln_Name[col]) < 0) {
- Insert(&tmp, np, np2->ln_Pred);
- break;
- }
- }
- }
- }
-
- }
- NewList(list);
- while (!EmptyList(&tmp)) {
- np = RemHead(&tmp);
- AddTail(list, np);
- }
- }
-
- void FreeListNodes(list, flag)
- LIST *list;
- BOOL flag;
- {
- NODE *np1, *np2;
- short count = 0;
-
- for (np1 = list->lh_Head; np1->ln_Succ;) {
- np2 = np1->ln_Succ;
- if (flag) free(np1->ln_Name);
- free(np1);
- count++;
- np1 = np2;
- }
- NewList(list);
- }
-
- /************************************************************************/
-
- void FixName(dst, src)
- char *dst, *src;
- {
- short i, j;
- BOOL ltFlag = 0;
- char *d = dst;
- short pcount = 0;
-
- for (i=0; src[i]; i++) if (src[i] == '<') ltFlag = !0;
-
- if (*src == '"') {
- for (j=1; src[j] && src[j] != '"'; j++) *dst++ = src[j];
- *dst++ = '\0';
- if (dst-d > 512) printf("FixName1 string to big: %d bytes '%s'\n", dst-d, d);
- return;
- }
- if (*src == '<') {
- for (j=1; src[j] && src[j] != '@' && src[j] != '>'; j++) {
- if (src[j] == '.')
- *dst++ = ' ';
- else
- *dst++ = src[j];
- }
- *dst++ = '\0';
- if (dst-d > 512) printf("FixName2 string to big: %d bytes '%s'\n", dst-d, d);
- return;
- }
- for (j=0; src[j]; j++) {
- if (src[j] == '<') {
- if (!j) {
- if (strlen(src) > 511) printf("FixName3 string to big: %d bytes '%s'\n", dst-d, src);
- strncpy(dst, src, 512);
- return;
- }
- else {
- for (i=0; i<j; i++) *dst++ = *src++;
- *dst++ = '\0';
- if (dst-d > 512) printf("FixName4 string to big: %d bytes '%s'\n", dst-d, d);
- return;
- }
- }
-
- // example nested parens: (Blonder (The one and Only :))
- if (src[j] == '(' && !ltFlag) {
- pcount++;
- j++;
- while (src[j] && pcount) {
- switch (src[j]) {
- case ')': pcount--;
- if (pcount) *dst++ = src[j];
- j++;
- break;
- case '(': pcount++;
- default: *dst++ = src[j++];
- break;
- }
- }
- *dst++ = '\0';
- if (dst-d > 512) printf("FixName5 string to big: %d bytes '%s'\n", dst-d, d);
- return;
- }
- }
- j=-1;
- for (i=0; src[i]; i++) if (src[i] == '!') j = i;
- if (j != -1) {
- j++;
- while (src[j] && src[j] != ',' && src[j] != '@') *dst++ = src[j++];
- *dst++ = '\0';
- }
- else {
- while (*src && *src != '%' && *src != '@') *dst++ = *src++;
- *dst++ = '\0';
- }
- if (dst-d > 512) printf("FixName6 string to big: %d bytes '%s'\n", dst-d, d);
- }
-
- /************************************************************************/
-
- void WriteNewsTree() {
- int fd;
- ART *ap;
- GLIST *gp;
- UWORD end = END;
-
- if (!treeDirty) return;
- t_printf(mainWindow, "GRn - Writing News Tree");
- fd = open(grnrcName, O_WRITE);
- if (fd == -1) panic("Can't open %s for output", grnrcName);
- write(fd, &grnrcVersion, 4);
-
- for (gp = (GLIST *)groupList.lh_Head; gp->node.ln_Succ; gp=(GLIST *)gp->node.ln_Succ) {
- write(fd, gp->groupName, strlen(gp->groupName)+1);
- write(fd, &gp->hideHeaders, 1);
- write(fd, &gp->hideRead, 1);
- write(fd, &gp->nextReceived, 4);
- write(fd, &gp->sortActive, 2);
- // sort the articles in this group by number
- SortArticlesByNumber(&gp->artList);
- for (ap=(ART *)gp->artList.lh_Head; ap->node.ln_Succ; ap=(ART *)ap->node.ln_Succ) {
- write(fd, &ap->state, 2);
- write(fd, &ap->filenum, 4);
- write(fd, ap->from, strlen(ap->from)+1);
- write(fd, ap->subject, strlen(ap->subject)+1);
- }
- write(fd, &end, 2);
- }
- close(fd);
- treeDirty = 0;
- }
-
- //
- // This routine scans uunews: and finds all the newsgroups and articles.
- // The news tree is built from scratch and all articles are marked as unread.
- //
- void BuildNewsTree(void) {
- ART *ap;
- GLIST *gp;
- UWORD groupCount = 0;
- char groupName[256], filename[256], temp[512], from[512], subject[512];
- FILE *fp;
-
- t_printf(mainWindow, "GRn - Building News Tree...");
- lock = Lock(uunews, SHARED_LOCK);
- panic0((APTR)lock, "Lock(%s) failed", uunews);
-
- hierarchical = 1; /* presume globally true, until proven otherwise */
- Examine (lock, fib);
- while (ExNext (lock, fib)) {
- if (fib->fib_DirEntryType < 0)
- continue;
- if (hierarchical && strchr (fib->fib_FileName, '.') == NULL) {
- /* This is the first directory (ALL modern newsgroups */
- /* have more than one level. So if the structure is */
- /* flat, and it WASNT hierarchical, we wouldn't get */
- /* here because it would have a period in it). If it */
- /* is hierarchical, then do the hierarchical thing */
- /* and then get out of here.... */
- groupCount = BuildHierarchicalList ();
- if (groupCount < 0) {
- panic0 (0, "There was an error building the newsgroup list\n");
- groupCount = -groupCount;
- }
- break;
- }
- hierarchical = 0;
- gp = (GLIST *) malloc (sizeof (GLIST));
- panic0 (gp, "Can't malloc GLIST %d bytes\n", sizeof (GLIST));
- gp->node.ln_Name = &gp->header [0];
- // since this is FLAT, it's already the newsgroup name,
- // it doesn't have to be translated.....
- strcpy (gp->groupName, fib->fib_FileName);
- strcpy (gp->header, fib->fib_FileName);
- AddTail (&groupList, (NODE *) gp);
- groupCount++;
- }
- UnLock (lock);
- lock = 0;
- SortList (&groupList, 0);
-
- gp = (GLIST *)groupList.lh_Head;
-
- for (; gp->node.ln_Succ; gp=(GLIST *)gp->node.ln_Succ) {
- t_printf(mainWindow, "GRn - Scanning %s...", gp->groupName);
- gp->articles = gp->unread = 0;
- strcpy(groupName, uunews);
- AddPart(groupName, NewsGroupToFileName (gp->groupName), 256);
- lock = Lock(groupName, SHARED_LOCK);
- panic0((APTR)lock, "Lock(%s) failed", groupName);
- sprintf(filename, "%s/.next", groupName);
- fp = fopen(filename, "r");
- if (!fp) {
- gp->nextReceived = 0;
- }
- else {
- fgets(temp, 512, fp);
- fclose(fp);
- gp->nextReceived = atoi(temp);
- }
- gp->hideHeaders = !0; gp->hideRead = !0;
- gp->sortActive = 0;
- NewList(&gp->artList);
- Examine(lock, fib);
- while (ExNext(lock, fib)) {
- if (fib->fib_DirEntryType > 0) continue;
- if (!atoi(fib->fib_FileName)) continue;
- ap = (ART *)malloc(sizeof(ART));
- panic0(ap, "Can't malloc ART %d bytes", sizeof(ART));
- ap->node.ln_Name = &ap->header[0];
- ap->state = UNREAD;
- ap->filenum = atoi(fib->fib_FileName);
-
- sprintf(filename, "%s/%s", groupName, fib->fib_FileName);
- fp = fopen(filename, "r");
- panic0(fp, "open on %s failed", filename);
- strcpy(from, "UNKNOWN");
- strcpy(subject, "NO SUBJECT");
- while (fgets(temp, 512, fp)) {
- temp[strlen(temp)-1] = '\0';
- if (!temp[0]) break;
- if (!strncmp(temp, "From: ", 6)) strcpy(from, &temp[6]);
- else if (!strncmp(temp, "Subject: ", 9)) strcpy(subject, &temp[9]);
- }
- fclose(fp);
-
- FixName(temp, from);
- ap->from = (char *)malloc(strlen(temp)+1);
- panic0(ap->from, "Can't allocate memory for From:\n");
- strcpy(ap->from, temp);
-
- ap->subject = (char *)malloc(strlen(subject)+1);
- panic0(ap->subject, "Can't allocate memory for subject:\n");
- strcpy(ap->subject, subject);
-
- AddTail(&gp->artList, (NODE *)ap);
- gp->articles++; gp->unread++;
- }
- sprintf(gp->header, "%-40.40s %6d articles %6d UnRead", gp->groupName, gp->articles, gp->unread);
- }
- UnLock(lock); lock = 0;
- treeDirty = !0;
- }
-
- void ReadNewsTree() {
- ART *ap;
- GLIST *gp;
- char groupName[256], temp[256];
- UWORD endTest;
- ULONG pct;
-
- t_printf(mainWindow, "GRn - Reading News Tree...");
- while (1) {
- if (!mgets(&groupName[0])) break;
- gp = (GLIST *)malloc(sizeof(GLIST));
- panic0(gp, "Can't malloc GLIST %d bytes", sizeof(GLIST));
- gp->node.ln_Name = &gp->header[0];
- AddTail(&groupList, (NODE *)gp);
- NewList(&gp->artList);
- gp->articles = gp->unread = 0;
- mread(&gp->hideHeaders, 1);
- mread(&gp->hideRead, 1);
- mread(&gp->nextReceived, 4);
- mread(&gp->sortActive, 2);
- pct = (100*(ULONG)(mbufp-mbuf))/(ULONG)(mbufe-mbuf);
- if (GuageRequest(pct,"Initializing", "Setting up News Tree", "Abort")) Abort();
- while (1) {
- mread(&endTest, 2);
- if (endTest == END) break;
- ap = (ART *)malloc(sizeof(ART));
- panic0(ap, "Can't malloc ART %d bytes", sizeof(ART));
- ap->node.ln_Name = &ap->header[0];
- ap->state = endTest;
- mread(&ap->filenum, 4);
- mgets(temp);
- ap->from = (char *)malloc(strlen(temp)+1);
- panic0(ap->from, "Can't allocate memory for From: field");
- strcpy(ap->from, temp);
-
- mgets(temp);
- ap->subject = (char *)malloc(strlen(temp)+1);
- panic0(ap->subject, "Can't allocate memory for Subject: field");
- strcpy(ap->subject, temp);
-
- AddTail(&gp->artList, (NODE *)ap);
- gp->articles++;
- if (ap->state == UNREAD || ap->state == NEW) gp->unread++;
- }
- strcpy(gp->groupName, groupName);
- sprintf(gp->header, "%-40.40s %6d articles %6d UnRead", gp->groupName, gp->articles, gp->unread);
- }
- mclose();
- }
-
- void UpdateNewsTree() {
- GLIST *gp;
- ART *ap;
- long num, last; // article number
- char fname[256], work[512], from[512], subject[512];
- FILE *fp;
- BOOL flag;
-
- // for each group
- for (gp=(GLIST *)groupList.lh_Head; gp->node.ln_Succ; gp = (GLIST *)gp->node.ln_Succ) {
- t_printf(mainWindow, "GRn - Pruning %s", gp->groupName);
- // scan through list and check to see if the files are still there!
- flag = 0;
- for (ap=(ART *)gp->artList.lh_Head; ap->node.ln_Succ; ap = (ART *)ap->node.ln_Succ) {
- strcpy(fname, uunews);
- AddPart(fname, NewsGroupToFileName (gp->groupName), 256);
- sprintf(work, "%d", ap->filenum);
- AddPart(fname, work, 256);
- if (!flag) {
- lock = Lock(fname, SHARED_LOCK);
- if (lock) {
- UnLock(lock); lock = 0;
- flag = !0;
- }
- else {
- if (ap->state == UNREAD) gp->unread--;
- gp->articles--;
- Remove((NODE *)ap);
- if (ap->subject) free(ap->subject);
- if (ap->from) free(ap->from);
- free(ap);
- treeDirty = !0;
- }
- }
- }
- // Find new articles, mark as unread!
- t_printf(mainWindow, "GRn - Getting new articles for %s", gp->groupName);
- strcpy(fname, uunews);
- AddPart(fname, NewsGroupToFileName (gp->groupName), 256);
- AddPart(fname, ".next", 256);
- fp = fopen(fname, "r");
- if (fp) {
- fgets(work, 512, fp);
- fclose(fp);
- last = atoi(work);
- }
- else {
- last = 1000000;
- }
- for (num = gp->nextReceived; num<last; num++) {
- strcpy(fname, uunews);
- AddPart(fname, NewsGroupToFileName (gp->groupName), 256);
- sprintf(work, "%d", num);
- AddPart(fname, work, 256);
- fp = fopen(fname, "r");
- if (!fp) {
- if (last == 1000000) break;
- continue;
- }
- ap = (ART *)malloc(sizeof(ART));
- panic0(ap, "Can't malloc ART %d bytes", sizeof(ART));
- ap->node.ln_Name = &ap->header[0];
- ap->state = UNREAD;
- ap->filenum = num;
-
- strcpy(from, "UNKNOWN");
- strcpy(subject, "NO SUBJECT");
- while (fgets(work, 512, fp)) {
- work[strlen(work)-1] = '\0';
- if (!work[0]) break;
- if (!strncmp(work, "From: ", 6)) strcpy(from, &work[6]);
- else if (!strncmp(work, "Subject: ", 9)) strcpy(subject, &work[9]);
- }
- fclose(fp);
- FixName(work, from);
- ap->from = (char *)malloc(strlen(work)+1);
- panic0(ap->from, "Can't allocate memory for From:\n");
- strcpy(ap->from, work);
- ap->subject = (char *)malloc(strlen(subject)+1);
- panic0(ap->subject, "Can't allocate memory for subject:\n");
- strcpy(ap->subject, subject);
- AddTail(&gp->artList, (NODE *)ap);
- gp->articles++;
- gp->unread++;
- treeDirty = !0;
- }
- sprintf(gp->header, "%-40.40s %6d articles %6d UnRead", gp->groupName, gp->articles, gp->unread);
- if (gp->nextReceived != last) {
- gp->nextReceived = last;
- treeDirty = !0;
- }
- }
- }
-
- void CheckNews() {
- ULONG testver = 0x0a0a5050;
-
- if (!mopen(grnrcName)) {
- BuildNewsTree();
- return;
- }
- mread(&testver, 4);
- if (testver != grnrcVersion) panic("grnrc is wrong version, delete it and run GRn again");
- if (GuageRequest(0,"Initializing", "Setting up News Tree", "Abort")) Abort();
- ReadNewsTree();
- GuageRequest(1000,"Initializing", "Setting up News Tree", "Abort");
- UpdateNewsTree();
- SortList(&groupList, 0);
- }
-
- /************************************************************************/
-
- void ParseConfig(void) {
- char buf[512], *ps;
- FILE *fp;
- BOOL uulibFlag = 0;
-
- userName[0] = mailEditor[0] = newsEditor[0] = '\0';
- GetVar("USERNAME", &userName[0], 256, GVF_GLOBAL_ONLY);
- GetVar("NEWSEDITOR", &newsEditor[0], 256, GVF_GLOBAL_ONLY);
- GetVar("MAILEDITOR", &mailEditor[0], 256, GVF_GLOBAL_ONLY);
- GetVar("SENDMAIL", &sendMail[0], 256, GVF_GLOBAL_ONLY);
- GetVar("POSTNEWS", &postNews[0], 256, GVF_GLOBAL_ONLY);
- if (userName[0] && newsEditor[0] && mailEditor[0] && sendMail[0] && postNews[0]) return;
-
- fp = fopen("s:uuconfig", "r");
- if (!fp) {
- fp = fopen("uulib:config", "r");
- panic0(fp, "Can't open uulib:config");
- uulibFlag = !0;
- }
- while (fgets(buf, 512, fp) && (!userName[0] || !newsEditor[0] || !mailEditor[0] || !sendMail[0] || !postNews[0])) {
- buf[strlen(buf)-1] = '\0';
- if (userName[0] == '\0' && !strnicmp(buf, "UserName", 8)) {
- ps = &buf[8];
- while (*ps == ' ' || *ps == '\t') ps++;
- if (*ps == '\0') panic("s:uuconfig or uulib:config UserName is NULL");
- strcpy(userName, ps);
- }
- else if (newsEditor[0] == '\0' && !strnicmp(buf, "NewsEditor", 10)) {
- ps = &buf[10];
- while (*ps == ' ' || *ps == '\t') ps++;
- if (*ps == '\0') panic("s:uuconfig or uulib:config NewsEditor is NULL");
- strcpy(newsEditor, ps);
- }
- else if (mailEditor[0] == '\0' && !strnicmp(buf, "MailEditor", 10)) {
- ps = &buf[10];
- while (*ps == ' ' || *ps == '\t') ps++;
- if (*ps == '\0') panic("s:uuconfig or uulib:config MailEditor is NULL");
- strcpy(mailEditor, ps);
- }
- else if (sendMail[0] == '\0' && !strnicmp(buf, "SendMail", 8)) {
- ps = &buf[8];
- while (*ps == ' ' || *ps == '\t') ps++;
- if (*ps == '\0') panic("s:uuconfig or uulib:config Sendmail is NULL");
- strcpy(sendMail, ps);
- }
- else if (postNews[0] == '\0' && !strnicmp(buf, "PostNews", 8)) {
- ps = &buf[8];
- while (*ps == ' ' || *ps == '\t') ps++;
- if (*ps == '\0') panic("s:uuconfig or uulib:config Postnews is NULL");
- strcpy(postNews, ps);
- }
- else if (!strnicmp(buf, "UUNews", 6)) {
- ps = &buf[6];
- while (*ps == ' ' || *ps == '\t') ps++;
- if (*ps) strcpy(uunews, ps);
- }
- else if (!uulibFlag && !strnicmp(buf, "UUlib", 5)) {
- ps = &buf[5];
- while (*ps == ' ' || *ps == '\t') ps++;
- if (*ps) strcpy(uulib, ps);
- }
- else if (!strnicmp(buf, "UUSpool", 7)) {
- ps = &buf[7];
- while (*ps == ' ' || *ps == '\t') ps++;
- if (*ps) strcpy(uuspool, ps);
- }
- }
- fclose(fp);
- if (userName[0]) {
- strcpy(grnrcName, uulib);
- sprintf(buf, "%s.grnrc", userName);
- AddPart(grnrcName, buf, 256);
- }
- else
- panic("s:uuconfig or uulib:config must contain UserName!");
- if (newsEditor[0] && !mailEditor[0])
- strcpy(mailEditor, newsEditor);
- else if (!newsEditor[0] && mailEditor[0])
- strcpy(newsEditor, mailEditor);
- panic0((APTR)newsEditor[0], "s:uuconfig or uulib:config must contain NewsEditor");
- panic0((APTR)mailEditor[0], "s:uuconfig or uulib:config must contain MailEditor");
- if (!sendMail[0]) strcpy(sendMail, "SendMail");
- if (!postNews[0]) strcpy(postNews, "PostNews");
- if (!logfile[0]) {
- strcpy(logfile, uuspool);
- AddPart(logfile, "logfile", 256);
- }
- }
-
- /************************************************************************/
-
- void QueryAbort() {
- if (!treeDirty) Abort();
- if (TwoGadgetRequest("GRN - Abort...", "Quit without updating News Tree?", "_YES", "_NO, I cnanged my mind")) Abort();
- mode = GROUPS_MODE;
- }
-
- void TRAP() {
- UWORD *custom = (UWORD *)0xdff180;
- UWORD i = 0;
-
- while (1) *custom = i++;
- }
-
- int main(int ac, char *av[]) {
- LIBRARY *check;
- STRPTR s;
- char **tt;
- BOOL lFlag = 0, tFlag = 0, hFlag = 0;
-
-
- check = OpenLibrary("intuition.library", 37);
- if (!check) {
- printf ("Can't open intuition.library\n");
- panic("Requires OS version 37 or higher");
- }
- CloseLibrary(check);
-
- if (ac == 0) {
- WorkbenchBase = OpenLibrary("workbench.library", 0);
- panic0(WorkbenchBase, "Can't open workbench.library");
- IconBase = OpenLibrary("icon.library", 0);
- panic0(IconBase, "Can't open icon.library");
- CxBase = OpenLibrary("commodities.library", 0);
- panic0(CxBase, "Can't open commodities.library");
- tt = ArgArrayInit(ac, av);
- panic0(tt, "Can't ArgArrayInit...");
-
- s = ArgString(tt, "TOP", "");
- if (s[0]) { prefTop = atoi(s); tFlag = !0; }
- s = ArgString(tt, "LEFT", "");
- if (s[0]) { prefLeft = atoi(s); lFlag = !0; }
- s = ArgString(tt, "WIDTH", "");
- if (s[0]) prefWidth = atoi(s);
- s = ArgString(tt, "HEIGHT", "");
- if (s[0]) { prefHeight = atoi(s); hFlag = !0; }
- s = ArgString(tt, "MSGFONT", "");
- if (s[0]) strcpy(prefFontName, s);
- s = ArgString(tt, "MSGFONTSIZE", "");
- if (s[0]) prefFontSize = atoi(s);
- s = ArgString(tt, "LOGFILE", "");
- if (s[0]) strcpy(logfile, s);
- s = ArgString(tt, "WRAP", "");
- if (s[0]) wrapCol = atoi(s);
- ArgArrayDone();
- CloseLibrary(CxBase);
- CloseLibrary(IconBase);
- CloseLibrary(WorkbenchBase);
- InitSystem();
- }
- else {
- InitSystem();
- prefLeft = screenWidth - prefWidth;
- prefTop = screenTop;
- prefHeight = screenHeight-screenTop;
- }
- if (ac == 0) {
- if (!lFlag) prefLeft = screenWidth - prefWidth;
- if (!tFlag) prefTop = screenTop;
- if (!hFlag) prefHeight = screenHeight-screenTop;
- }
-
- onbreak(Abort);
-
- port = FindPort("GRN_PORT");
- if (port) {
- port = 0;
- DisplayBeep(screen);
- Abort();
- }
- port = CreatePort("GRN_PORT", 0);
- panic0(port, "Can't create GRN_PORT");
-
- fib = (FIB *)AllocDosObject(DOS_FIB, TAG_DONE);
- panic0(fib, "Can't AllocDosObject(DOS_FIB)");
-
- NewList(&groupList);
-
- windowHeight = prefHeight;
- mainWindow = CreateWindow(NULL, prefLeft, prefTop, prefWidth,windowHeight, "GRn - Looking for news...");
- panic0(mainWindow, "Can't open main window");
-
- saveReq = (FILEREQ *)AllocAslRequestTags(ASL_FileRequest,
- ASL_Hail, "Save Message...",
- ASL_Window, mainWindow,
- ASL_FuncFlags, FILF_SAVE,
- TAG_DONE
- );
- panic0(saveReq, "Can't AllocFileRequest");
-
- publishReq = (FILEREQ *)AllocAslRequestTags(ASL_FileRequest,
- ASL_Hail, "Publish File...",
- ASL_Window, mainWindow,
- TAG_DONE
- );
- panic0(publishReq, "Can't AllocFileRequest");
-
- t_printf(mainWindow, "GRn - Getting your UserName");
- ParseConfig();
- CheckNews();
-
- currentGroup = (GLIST *)groupList.lh_Head;
-
- while (mode != QUIT_MODE) {
- switch (mode) {
- case NEXTGROUPS_MODE:
- case PREVGROUPS_MODE:
- case GROUPS_MODE: GroupsWindow(); break;
- case ARTICLES_MODE: ArticlesWindow(); break;
- case QUIT_MODE: break;
- case ABORT_MODE: QueryAbort(); break;
- default: break;
- }
- }
- WriteNewsTree();
- Abort();
- }
-
- int wbmain(struct WBStartup *msg) {
- LIBRARY *check;
- char *s;
- BOOL lFlag = 0, tFlag = 0, hFlag = 0;
- char **tt;
- union {
- char **args;
- struct WBStartup *msg;
- } argv;
-
- argv.msg = msg;
- check = OpenLibrary("intuition.library", 37);
- if (!check) panic("Requires OS version 37 or higher");
- CloseLibrary(check);
-
- WorkbenchBase = OpenLibrary("workbench.library", 0);
- panic0(WorkbenchBase, "Can't open workbench.library");
- IconBase = OpenLibrary("icon.library", 0);
- panic0(IconBase, "Can't open icon.library");
- CxBase = OpenLibrary("commodities.library", 0);
- panic0(CxBase, "Can't open commodities.library");
- CurrentDir(msg->sm_ArgList->wa_Lock); /* DICE's startup code doesn't do this */
- tt = ArgArrayInit(0, argv.args);
- panic0(tt, "Can't ArgArrayInit2...");
-
- s = ArgString(tt, "TOP", "");
- if (s[0]) { prefTop = atoi(s); tFlag = !0; }
- s = ArgString(tt, "LEFT", "");
- if (s[0]) { prefLeft = atoi(s); lFlag = !0; }
- s = ArgString(tt, "WIDTH", "");
- if (s[0]) prefWidth = atoi(s);
- s = ArgString(tt, "HEIGHT", "");
- if (s[0]) { prefHeight = atoi(s); hFlag = !0; }
- s = ArgString(tt, "MSGFONT", "");
- if (s[0]) strcpy(prefFontName, s);
- s = ArgString(tt, "MSGFONTSIZE", "");
- if (s[0]) prefFontSize = atoi(s);
- s = ArgString(tt, "LOGFILE", "");
- if (s[0]) strcpy(logfile, s);
- s = ArgString(tt, "WRAP", "");
- if (s[0]) wrapCol = atoi(s);
- ArgArrayDone();
- CloseLibrary(CxBase);
- CloseLibrary(IconBase);
- CloseLibrary(WorkbenchBase);
- if (!lFlag) prefLeft = screenWidth - prefWidth;
- if (!tFlag) prefTop = screenTop;
- if (!hFlag) prefHeight = screenHeight-screenTop;
- return main(1,NULL);
- }
-