home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3024 < prev    next >
Encoding:
Text File  |  1991-03-09  |  2.1 KB  |  103 lines

  1. Newsgroups: alt.folklore.computers,misc.misc,alt.sources
  2. From: peter@ficc.ferranti.com (Peter da Silva)
  3. Subject: Re: Jargon File Version is 2.7.1
  4. Message-ID: <=LY9CM3@xds13.ferranti.com>
  5. Date: Thu, 7 Mar 91 19:17:43 GMT
  6.  
  7. What is this discussion doing in alt.sources?
  8.  
  9. In article <19090@rpp386.cactus.org> jfh@rpp386.cactus.org (John F Haugh II) writes:
  10. > Could you please limit it to newsgroups that I don't carry?  I am getting
  11. > a bit tired of Jargon File du jour.  Is there anyone else that feels the
  12. > same way?  Can I get an "Amen" brother?
  13.  
  14. I'm glad he finally started sending it to newsgroups I *do* carry. I've
  15. been wondering why the file hasn't been showing up recently. Alt.sources
  16. is a fine place for it.
  17. -- 
  18. Peter da Silva.  `-_-'  peter@ferranti.com
  19. +1 713 274 5180.  'U`  "Have you debugged your wolf today?"
  20. -- 
  21. Obligatory Source: a program to split mailbox files.
  22.  
  23. #include <stdio.h>
  24. #include <ctype.h>
  25.  
  26. #ifdef USG
  27. #define MAILBOX "/usr/mail/%s"
  28. #else
  29. #define MAILBOX "/usr/spool/mail/%s"
  30. #endif
  31.  
  32. #define STRLEN 255
  33. char line[STRLEN];
  34.  
  35. getline(fp, line)
  36. FILE *fp;
  37. char *line;
  38. {
  39.     fgets(line, STRLEN, fp);
  40.     line[strlen(line)-1] = 0;
  41. }
  42.  
  43. main(ac, av)
  44. int ac;
  45. char **av;
  46. {
  47.     FILE *fp = 0;
  48.  
  49.     while(--ac)
  50.         if(fp = fopen(*++av, "r")) {
  51.             fsplit(fp);
  52.             fclose(fp);
  53.         } else {
  54.             perror(*av);
  55.             exit(1);
  56.         }
  57.     if(!fp) {
  58.         char buffer[255];
  59.         char *p, *getenv(), *getlogin();
  60.  
  61.         if(!(p = getenv("MAIL"))) {
  62.             if(!(p = getenv("LOGNAME"))) {
  63.                 if(!(p = getlogin())) {
  64.                     fprintf(stderr,
  65.                         "/etc/passwd: No login name.\n");
  66.                     exit(1);
  67.                 }
  68.                 sprintf(buffer, MAILBOX, p);
  69.             }
  70.         } else
  71.             sprintf(buffer, "%s", p);
  72.         if(!(fp = fopen(buffer, "r"))) {
  73.             perror(buffer);
  74.             exit(1);
  75.         }
  76.         fsplit(fp);
  77.         fclose(fp);
  78.     }
  79. }
  80.  
  81. fsplit(fp)
  82. FILE *fp;
  83. {
  84.     char outname[16];
  85.     int outfile=0;
  86.     FILE *outfp = 0;
  87.  
  88.     while(1) {
  89.         getline(fp, line);
  90.         if(feof(fp)) break;
  91.         if(!strncmp(line, "From ", 5)) {
  92.             if(outfp) fclose(outfp);
  93.             sprintf(outname, "%d", ++outfile);
  94.             if(!(outfp = fopen(outname, "w"))) {
  95.                 perror(outname);
  96.                 exit(1);
  97.             }
  98.         }
  99.         if(outfp) fprintf(outfp, "%s\n", line);
  100.     }
  101.     if(outfp) fclose(outfp);
  102. }
  103.