Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!sri-spam!mordor!lll-lcc!ptsfa!micropro!mp-mojo!mojo From: mojo@mp-mojo.UUCP Newsgroups: comp.sys.ibm.pc Subject: Newsort for UULINK Message-ID: <45.UUL1.1#119@mp-mojo.micropro.UUCP> Date: Tue, 10-Mar-87 18:36:09 EST Article-I.D.: mp-mojo.45.UUL1.1#119 Posted: Tue Mar 10 18:36:09 1987 Date-Received: Wed, 11-Mar-87 21:19:40 EST Organization: MicroPro Int'l Corp. Lines: 553 Here is source and executable for a UULINK news sorter. Newsort takes the filename of the news file as an argument, sorts by newsgroups and subject line, and writes to the same filename, leaving the original as a .BAK file. (Old MicroPro habits. :-) This source was written for Lattice C 3.00 with a private library, and will no doubt require some porting for other development environments. Executable is a uuencoded .ARC file. Address comments to mojo@mp-mojo.micropro.UUCP. ---------------begin newsort.c---------------------begin newsort.c------------ /* * Sort a news file for UULINK by newsgroup and subject * * compile in large model * * */ /* Includes */ #include #include /* Local Defines */ #define TRACE 0 #define MAXART 500 #define MAXFNAME 65 /* #define BUFSIZ 512 */ /* defined in stdio.h */ #define FAIL (int)1 #define SUCCESS (int)0 /* External and forward function declarations */ long ftell(); char *malloc(); char *getmem(); int readone(); void perror(); void newsread(); void cleanup(); int artcmp(); void changext(); void newswrite(); /* Global variable definitions */ int _stack = 5120; typedef struct { long offset; /* beginning of article in input file */ char *subject; /* Subject: line */ char *newsgroups; /* Newsgroups: line */ long length; /* length of article */ } ARTICLE; ARTICLE articles[MAXART]; /* array of article information */ int n_articles = 0; /* number of articles in file */ char infile[MAXFNAME]; char outfile[MAXFNAME]; char bakfile[MAXFNAME]; char msgterm[] = "\001\001\r\n"; /* ----------------------------------------------------------------------- */ /* main */ void main(argc,argv) int argc; char *argv[]; { int i; if (argc < 2) { fprintf(stderr,"usage: newsort newsfile\r\n"); exit(1); } strcpy(infile,argv[1]); strcpy(outfile,infile); strcpy(bakfile,infile); changext(outfile,".$$$"); changext(bakfile,".bak"); #if TRACE printf("infile: %s\r\n",infile); printf("outfile: %s\r\n",outfile); printf("bakfile: %s\r\n",bakfile); #endif newsread(infile); fprintf(stderr,"sorting...\r\n"); fflush(stderr); qsort(articles, n_articles, sizeof(ARTICLE), artcmp); #if TRACE for (i=0;i name) { if (*p == '.') { strcpy(p,ext); return; } if (*p == '/' || *p == '\\' || *p == ':') { strcat(name,ext); return; } --p; } strcat(name,ext); return; } /* ----------------------------------------------------------------------- */ /* compare two articles */ int artcmp(a1,a2) ARTICLE *a1, *a2; { int retval; if (retval = strcmp(a1->newsgroups,a2->newsgroups)) return retval; return strcmp(a1->subject,a2->subject); } /* ----------------------------------------------------------------------- */ /* Free all the allocated space */ void cleanup() { int i; if (n_articles == 0) return; for (i=0;i BUFSIZ) { if (fread(buf,1,BUFSIZ,fin) != BUFSIZ) perror("read error",in); if (fwrite(buf,1,BUFSIZ,fout) != BUFSIZ) perror("write error",out); size -= BUFSIZ; } fprintf(stderr,"writing %d... \r",n_articles-i); fflush(stderr); if (size > 0) { if (fread(buf,1,(int)size,fin) != (int)size) { perror("read error",in); } if (fwrite(buf,1,(int)size,fout) != (int)size) perror("write error",out); } } fprintf(stderr,"\n"); fclose(fin); fclose(fout); } /* ----------------------------------------------------------------------- */ /* Read in the article information */ void newsread(filename) char *filename; { FILE *fp; int art_index; fp = fopen(filename,"r"); if (fp == NULL) perror("Can't open",filename); n_articles = art_index = 0; while (readone(fp,art_index) != FAIL) { ++n_articles; fprintf(stderr,"reading %d... \r",n_articles); fflush(stderr); ++art_index; } fclose(fp); fprintf(stderr,"\n"); return; } /* ----------------------------------------------------------------------- */ /* read one article */ int readone(fp,index) FILE *fp; int index; { char linbuf[BUFSIZ]; int isheader; char *p; if (fgets(linbuf,BUFSIZ,fp) == NULL) return FAIL; if (strcmp(linbuf,msgterm) != 0) { fprintf(stderr,"Wrong format: %s\r\n",linbuf); return FAIL; } isheader = TRUE; articles[index].offset = ftell(fp) - 4; while (fgets(linbuf,BUFSIZ,fp) != NULL) { if (strcmp(linbuf,msgterm) == 0) { articles[index].length = ftell(fp) - articles[index].offset; return SUCCESS; } else if (strcmp(linbuf,"\r\n") == 0) isheader = FALSE; else if (isheader && strncmp(linbuf,"Newsgroups: ",12) == 0) { p = linbuf+12; articles[index].newsgroups = getmem(strlen(linbuf)-10); strcpy(articles[index].newsgroups,p); } else if (isheader && strncmp(linbuf,"Subject: Re: ",13) == 0) { p=linbuf+13; articles[index].subject = getmem(strlen(linbuf)-10); strcpy(articles[index].subject,p); } else if (isheader && strncmp(linbuf,"Subject: ",9) == 0) { p=linbuf+9; articles[index].subject = getmem(strlen(linbuf)-7); strcpy(articles[index].subject,p); } } return FAIL; } /* ---------------------------------------------------------------------- */ /* get memory and test for success */ char *getmem(size) int size; { char *p; p = malloc(size); if (p == NULL) perror("out of memory!",""); return p; } /* ---------------------------------------------------------------------- */ /* Print an error and exit */ void perror(s1,s2) char *s1; char *s2; { fprintf(stderr,"newsort: %s %s\r\n",s1,s2); exit(1); } ------------------end newsort.c--------------------end newsort.c-------------- begin 755 newsort.arc M&@A.15=33U)4+D5810"^4R4 $-"8_$MY!0 ,3;0 I "@"0 0 0 /#O M'S(""0<$ 0") >* R0 H"- ,9S&!,$ @ X ( $B27 ME5]C?N/YU6 I8S& *1 1@0Y%N1MD",<@+H9@);.D !TEM7Y6^<*"%#&2#V5 M=2#6N0)P! %@YHS:"'%+P:T%=R/0J!W[[D @#T![ ;A&P\&@$F%KU383(7S5#B$: (L M 8 # H@ @ 4"Q'"B $*L>%LY +P 0#L P#(C -C<6 , '@@P48\= - / 'T( MV9V1# 0P)!Q* B!*DTX-288 0]I")0#U7-G $..8\"0P" P9!,+#(E'F0 X M@J8) (@@P$4F"/ ! "H(T!X+ B0 @ L"L,FG$WL*X" - D @ $(R$B ^%#P '0$@,0H*Q[+#"#"+<#/(, ^D M.\TZC$0S0#8K8#,$+4HT$\(< JR3@R\#F: ( T;(T,XBV6PL0+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>TX0^R\2B1 BD4$2F00A&1 BD4$2F00A&1 BD4$2F00A&1 BD4$2F00A&1 M BD4$2F00A&1 BD4$2F00A&1 BD4$2F00A&1 BD4$2F00A&1 BD4$2F0$ 8: ! "D4 end Mojo ... Morris Jones, MicroPro Int'l Corp., Product Development Northern Calif. Motorcycle Safety Council, MSF Instructor {lll-crg,ptsfa,dual,well,pyramid}!micropro!mojo Not the opinion of MicroPro! Democracy: The bludgeoning of the people by the people for the people. -- John Galt