wls@astrovax.UUCP (William L. Sebok) (10/15/84)
Included here are some fixes to the the handling of the NEWSBOX environment variable by the 's' and 'w' commands of version 2.10.2 vnews and readnews. 1) One fix is in the handling of the (unfortunately) undocumented %s feature of the NEWSBOX environment variable. If NEWSBOX contains directory/%s and a request is given to save an article in news group "newsgroup" under the name "filename", then the article is saved under the pathname: directory/newsgroup/filename. The fix causes "directory" to be created when it doesn't exist. When dealing with a large number of these subdirectories, it is a pain to have to exit the news reader to create subdirectories in which to save one's article. It also recognizes and rejects the case in which directory/newsgroup is not a directory. 2) The other fix is in the behavior of pathnames beginning with ~ when NEWSBOX is present. As distributed, when NEWSBOX is not present, if a request to save the article at ~/filename is given, the article is saved at $HOME/filename. However if NEWSBOX is present and equal to "directory" the article is be saved at directory/~/filename . Likewise if NEWSBOX were equal to directory/%s the article in news group "newsgroup" would be saved at directory/newsgroup/~/filename. The fix causes the article to be saved in $HOME/filename in all cases. This is consistent with the syntax requesting to save at article at a name beginning with a '/', which in all cases causes it to be saved at an absolute pathname. A form of these fixes was contained in the version of vnews 2.10.1 I posted in November. Unfortunately they didn't make it into the 2.10.2. This was very unfortunate as NEWSBOX is a lot less useful without these fixes. Bill Sebok Princeton University, Astrophysics {allegra,akgua,burl,cbosgd,decvax,ihnp4,noao,princeton,vax135}!astrovax!wls Changes to visual.c: *** visual.c.ORIG Sat Oct 6 20:44:48 1984 --- visual.c Sun Oct 14 23:47:19 1984 *************** *** 476,492 if (*bptr != PIPECHAR && *bptr != '/') { char hetyped[BUFLEN]; char *boxptr; strcpy(hetyped, bptr); ! if (boxptr = getenv("NEWSBOX")) ! if (index(boxptr, '%')) ! sprintf(bptr, boxptr, grn); ! else ! strcpy(bptr, boxptr); ! else if (hetyped[0] == '~' && hetyped[1] == '/') { strcpy(hetyped, bptr+2); strcpy(bptr, userhome); } else bptr[0] = '\0'; if (bptr[0]) strcat(bptr, "/"); if (hetyped[0] != '\0') --- 482,520 ----- if (*bptr != PIPECHAR && *bptr != '/') { char hetyped[BUFLEN]; char *boxptr; + struct stat stbf; + strcpy(hetyped, bptr); ! if (hetyped[0] == '~' && hetyped[1] == '/') { strcpy(hetyped, bptr+2); strcpy(bptr, userhome); + } else if (boxptr = getenv("NEWSBOX")) { + if (index(boxptr, '%')) { + sprintf(bptr, boxptr, grn); + if (stat(bptr,&stbf)<0) { + #ifdef BSD4_2 + if (mkdir(bptr,0777)<0) { + #else !BSD4_2 + int status, pid; + if ((pid = fork()) <= 0) { + execl("/bin/mkdir","mkdir", bptr,0); + exit(127); + } + while ( wait(&status) != pid); + if (status != 0) { + #endif !BSD4_2 + msg("Cannot create directory %s", bptr); + break; + } + } else if ((stbf.st_mode&S_IFMT) != S_IFDIR) { + msg("%s not a directory",bptr); + break; + } + } else + strcpy(bptr, boxptr); } else bptr[0] = '\0'; + if (bptr[0]) strcat(bptr, "/"); if (hetyped[0] != '\0') *************** Changes to readr.c: *** readr.c.ORIG Sat Oct 6 20:13:40 1984 --- readr.c Sun Oct 14 23:48:24 1984 *************** *** 305,319 if (*bptr != '|' && *bptr != '/') { char hetyped[BUFLEN]; char *boxptr; strcpy(hetyped, bptr); ! if (boxptr = getenv("NEWSBOX")) ! if (index(boxptr, '%')) ! sprintf(bptr, boxptr, grn); ! else ! strcpy(bptr, boxptr); ! else if (hetyped[0] == '~' && hetyped[1] == '/') { strcpy(hetyped, bptr+2); strcpy(bptr, userhome); } else strcpy(bptr, "."); strcat(bptr, "/"); --- 313,347 ----- if (*bptr != '|' && *bptr != '/') { char hetyped[BUFLEN]; char *boxptr; + struct stat stbf; strcpy(hetyped, bptr); ! if (hetyped[0] == '~' && hetyped[1] == '/') { strcpy(hetyped, bptr+2); strcpy(bptr, userhome); + } else if (boxptr = getenv("NEWSBOX")) { + if (index(boxptr, '%')) { + sprintf(bptr, boxptr, grn); + if (stat(bptr,&stbf)<0) { + #ifdef BSD4_2 + if (mkdir(bptr,0777) < 0) { + #else !BSD4_2 + int status, pid; + if ((pid = fork()) <= 0) { + execl("/bin/mkdir",mkdir,bptr,0); + exit(127); + } + while (wait(&status) != pid); + if (status != 0) { + #endif !BSD4_2 + fprintf(ofp,"Cannot create directory %s",bptr); + break; + } + } else if ((stbf.st_mode & S_IFMT) != S_IFDIR) { + fprintf(ofp,"%s is not a directory",bptr); + break; + } + } else + strcpy(bptr, boxptr); } else strcpy(bptr, "."); strcat(bptr, "/"); *************** -- Bill Sebok Princeton University, Astrophysics {allegra,akgua,burl,cbosgd,decvax,ihnp4,noao,princeton,vax135}!astrovax!wls