home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / rn_4_3_blars.lzh / newsetup.c < prev    next >
C/C++ Source or Header  |  1992-03-08  |  2KB  |  74 lines

  1. /* newsetup.c created from newsetup.SH by blarson@usc.edu */
  2.  
  3. #include <stdio.h>
  4. #include "config.h"
  5.  
  6. char *getenv(), *index(), *strtok();
  7.  
  8. static char WHITE[] = " \t\n";
  9.  
  10. main(argc, argv)
  11. int argc;
  12. char **argv;
  13. {
  14.     register char *cp, *cp2;
  15.     char *dotdir;
  16.     FILE *fp, *ap;
  17. #define MAXLINE 1023
  18.     char line[MAXLINE+1];
  19.  
  20.     dotdir = getenv("DOTDIR");
  21.     if(dotdir == NULL) {
  22.     dotdir = getenv("HOME");
  23.     if(dotdir == NULL) {
  24.         printf("Could not determine DOTDIR or HOME\n");
  25.         exit(1);
  26.     }
  27.     }
  28.     chdir(dotdir);
  29.     if (rename(".oldnewsrc",".newsrc") == 0) {
  30.         printf(".oldnewsrc restored as .newsrc\n");
  31.     exit(0);
  32.     }
  33. /*    unlink(".oldnewsrc"); */
  34.     printf("Creating .newsrc in %s to be used by news programs.\n", dotdir);
  35.     rename(".newsrc", ".oldnewsrc");
  36.     if((fp = fopen(".newsrc", "w")) == NULL) {
  37.         printf("Could not open %s/.newsrc for writing\n", dotdir);
  38.     exit(1);
  39.     }
  40.     chdir(LIB);
  41.     if((ap = fopen("active", "r")) == NULL) {
  42.         printf("Could not open %s/active\n", LIB);
  43.     exit(1);
  44.     }
  45.     while(fgets(line, MAXLINE, ap) != NULL) {
  46.         cp = strtok(line, WHITE);
  47.     strtok(NULL, WHITE);
  48.     strtok(NULL, WHITE);
  49.     cp2 = strtok(NULL, WHITE);
  50.     if(cp != NULL && (cp2 == NULL || (*cp2!='x' && *cp2!='='))) {
  51.         cp += strlen(cp);
  52.         *cp++ = ':';
  53.         *cp++ = '\n';
  54.         *cp = '\0';
  55.         if(strncmp(line, "compuserve", 10) != 0) {
  56.             if(strcmp(line, "control:\n") == 0 ||
  57.             strcmp(line, "junk:\n") == 0
  58.                 || strncmp(line, "test", 4) == 0 ||
  59.             strncmp(line, "to.", 3) == 0 ||
  60.                 ((cp > (line + 6)) && strcmp(cp-6, "test:\n")==0))
  61.                 cp[-2] = '!';
  62.         fputs(line, fp);
  63.         }
  64.     }
  65.     }
  66.     fclose(ap);
  67.     fclose(fp);
  68.     printf("If you have never used the news system before, you may find the articles\n");
  69.     printf("in news.announce.newusers to be helpful.  There is also a manual entry for rn.\n");
  70.     printf("\n");
  71.     printf("To get rid of newsgroups you aren't interested in, use the 'u' command.\n");
  72.     printf("Type h for help at any time while running rn.\n");
  73. }
  74.