Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site sdcrdcf.UUCP
Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!lwall
From: lwall@sdcrdcf.UUCP (Larry Wall)
Newsgroups: net.sources
Subject: rn version 4.1, part 5 of 8 (reposting 4,5,6 & 8)
Message-ID: <1381@sdcrdcf.UUCP>
Date: Fri, 12-Oct-84 20:33:01 EDT
Article-I.D.: sdcrdcf.1381
Posted: Fri Oct 12 20:33:01 1984
Date-Received: Sun, 14-Oct-84 07:44:18 EDT
Reply-To: lwall@sdcrdcf.UUCP (Larry Wall)
Organization: System Development Corp. R+D, Santa Monica
Lines: 2971
#! /bin/sh
# Make a new directory for the rn sources, cd to it, and run kits 1 thru 8
# through sh. When all 8 kits have been run, read README.
echo "This is rn kit 5 (of 8). If kit 5 is complete, the line"
echo '"'"End of kit 5 (of 8)"'" will echo at the end.'
echo ""
export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
echo Extracting rn.c
cat >rn.c <<'!STUFFY!FUNK!'
/* rn -- new readnews program
*
* From: lwall@sdcrdcf.UUCP (Larry Wall)
* Organization: System Development Corporation, Santa Monica
*
* begun: 01/14/83
* 1.0: 04/08/83
* 2.0: 09/01/83
*/
static char rnid[] = "@(#)$Header: rn.c,v 4.1 84/09/24 12:07:12 lwall Exp $";
/* $Log: rn.c,v $
* Revision 4.1 84/09/24 12:07:12 lwall
* Real baseline.
*
* Revision 4.0.1.1 84/09/10 15:28:58 lwall
* Delinted.
*
* Revision 4.0 84/09/04 09:52:16 lwall
* Baseline for netwide release
*
* Revision 3.0 84/06/04 16:22:45 lwall
* Baseline version for netwide release.
*
*/
#include "INTERN.h"
#include "common.h"
#include "rn.h"
#include "EXTERN.h"
#include "rcstuff.h"
#include "term.h"
#include "final.h"
#include "ngdata.h"
#include "util.h"
#include "only.h"
#include "ngsrch.h"
#include "help.h"
#include "last.h"
#include "init.h"
#include "intrp.h"
#include "rcln.h"
#include "sw.h"
#include "addng.h"
#include "INTERN.h"
void
rn_init()
{
;
}
void
main(argc,argv)
int argc;
char *argv[];
{
bool foundany = initialize(argc,argv);
register char *s;
if (maxngtodo)
starthere = 0;
else if (!foundany) { /* nothing to do? */
#ifdef VERBOSE
if (verbose)
fputs("\
No unread news in subscribed-to newsgroups. To subscribe to a new\n\
newsgroup use the g command.\n\
",stdout);
#endif
starthere = nextrcline;
}
/* loop through all unread news */
{
char promptbuf[80];
bool special = FALSE; /* temporarily allow newsgroup */
/* with no unread news? */
bool retry; /* cycle back to top of list? */
NG_NUM recent_ng = 0;
current_ng = 0;
do {
retry = FALSE;
if (findlast) {
findlast = FALSE;
starthere = 0;
if (*lastngname) {
if ((ng = find_ng(lastngname)) == nextrcline)
ng = 0;
else {
set_ngname(lastngname);
set_toread(ng);
if (toread[ng] <= TR_NONE)
ng = 0;
}
}
}
else {
ng = starthere;
starthere = 0;
}
while (ng <= nextrcline) { /* for each newsgroup */
if (ng >= nextrcline) { /* after the last newsgroup? */
ng = nextrcline; /* force it to 1 after */
#ifdef ONLY
if (maxngtodo) {
if (retry)
#ifdef VERBOSE
IF(verbose)
printf("\nRestriction %s%s still in effect.\n",
ngtodo[0],
maxngtodo > 1 ? ", etc." : nullstr);
ELSE
#endif
#ifdef TERSE
fputs("\n(\"Only\" mode.)\n",stdout);
#endif
else {
#ifdef VERBOSE
IF(verbose)
fputs("\nNo articles under restriction.",stdout);
ELSE
#endif
#ifdef TERSE
fputs("\nNo \"only\" articles.",stdout);
#endif
end_only(); /* release the restriction */
retry = TRUE;
}
}
#endif
dfltcmd = (retry ? "npq" : "qnp");
#ifdef VERBOSE
IF(verbose)
sprintf(promptbuf,
"\n******** End of newsgroups--what next? [%s] ",
dfltcmd);
ELSE
#endif
#ifdef TERSE
sprintf(promptbuf,
"\n**** End--next? [%s] ", dfltcmd);
#endif
}
else {
bool shoe_fits; /* newsgroup matches restriction? */
if (toread[ng] >= TR_NONE) { /* recalc toread? */
set_ngname(rcline[ng]);
if (shoe_fits = (special || inlist(ngname)))
set_toread(ng);
if (paranoid) {
recent_ng = current_ng;
current_ng = ng;
cleanup_rc();
/* this may move newsgroups around */
ng = current_ng;
set_ngname(rcline[ng]);
}
}
if (toread[ng] < (maxngtodo||special ? TR_NONE : TR_ONE) || !shoe_fits) {
/* unwanted newsgroup? */
ng++; /* then skip it */
continue;
}
dfltcmd = "ynq";
#ifdef VERBOSE
IF(verbose)
sprintf(promptbuf,
"\n******** %3ld unread article%s in %s--read now? [%s] ",
(long)toread[ng], (toread[ng]==TR_ONE ? nullstr : "s"),
ngname, dfltcmd); /* format prompt string */
ELSE
#endif
#ifdef TERSE
sprintf(promptbuf,
"\n**** %3ld in %s--read? [%s] ",
(long)toread[ng],
ngname,dfltcmd); /* format prompt string */
#endif
}
special = FALSE; /* go back to normal mode */
if (ng != current_ng) {
recent_ng = current_ng;
/* remember previous newsgroup */
current_ng = ng; /* remember current newsgroup */
}
reask_newsgroup:
fputs(promptbuf,stdout);/* print prompt */
fflush(stdout);
reinp_newsgroup:
eat_typeahead();
getcmd(buf);
if (errno || *buf == '\f') {
putchar('\n'); /* if return from stop signal */
goto reask_newsgroup; /* give them a prompt again */
}
setdef(buf,dfltcmd);
#ifdef VERIFY
printcmd();
#endif
switch (*buf) {
case 'p': /* find previous unread newsgroup */
do {
if (ng <= 0)
break;
ng--;
if (toread[ng] == TR_NONE)
set_toread(ng);
} while (toread[ng] <= TR_NONE);
break;
case 'P': /* goto previous newsgroup */
do {
if (ng <= 0)
break;
ng--;
} while (toread[ng] < TR_NONE);
special = TRUE; /* don't skip it if toread==0 */
break;
case '-':
ng = recent_ng; /* recall previous newsgroup */
special = TRUE; /* don't skip it if toread==0 */
break;
case 'q': case 'Q': /* quit? */
putchar('\n');
ng = nextrcline+1; /* satisfy */
retry = FALSE; /* loop conditions */
break;
case '^':
putchar('\n');
ng = 0;
break;
case 'n': case '+': /* find next unread newsgroup */
if (ng == nextrcline) {
putchar('\n');
retry = TRUE;
}
else if (toread[ng] > TR_NONE)
retry = TRUE;
ng++;
break;
case 'N': /* goto next newsgroup */
ng++;
special = TRUE; /* and don't skip it if toread==0 */
break;
case '1': /* goto 1st newsgroup */
ng = 0;
special = TRUE; /* and don't skip it if toread==0 */
break;
case '$':
ng = nextrcline; /* goto last newsgroup */
retry = TRUE;
break;
case 'L':
list_newsgroups();
goto reask_newsgroup;
case '/': case '?': /* scan for newsgroup pattern */
#ifdef NGSEARCH
switch (ng_search(buf,TRUE)) {
case NGS_ABORT:
goto reinp_newsgroup;
case NGS_INTR:
#ifdef VERBOSE
IF(verbose)
fputs("\n(Interrupted)\n",stdout);
ELSE
#endif
#ifdef TERSE
fputs("\n(Intr)\n",stdout);
#endif
ng = current_ng;
goto reask_newsgroup;
case NGS_FOUND:
special = TRUE; /* don't skip it if toread==0 */
break;
case NGS_NOTFOUND:
#ifdef VERBOSE
IF(verbose)
fputs("\n\nNot found--use g to add newsgroups\n",
stdout);
ELSE
#endif
#ifdef TERSE
fputs("\n\nNot found\n",stdout);
#endif
goto reask_newsgroup;
}
#else
notincl("/");
#endif
break;
case 'm':
#ifndef RELOCATE
notincl("m");
break;
#endif
case 'g': /* goto named newsgroup */
if (!finish_command(FALSE))
/* if they didn't finish command */
goto reinp_newsgroup; /* go try something else */
for (s = buf+1; *s == ' '; s++);
/* skip leading spaces */
if (!*s)
strcpy(s,ngname);
#ifdef RELOCATE
if (!get_ng(s,*buf=='m')) /* try to find newsgroup */
#else
if (!get_ng(s,FALSE)) /* try to find newsgroup */
#endif
ng = current_ng;/* if not found, go nowhere */
special = TRUE; /* don't skip it if toread==0 */
break;
#ifdef DEBUGGING
case 'D':
printf("\nTries: %d Hits: %d\n",
softtries,softtries-softmisses);
goto reask_newsgroup;
#endif
case '!': /* shell escape */
if (escapade()) /* do command */
goto reinp_newsgroup;
/* if rubbed out, re input */
goto reask_newsgroup;
case Ctl('k'): /* edit global KILL file */
edit_kfile();
goto reask_newsgroup;
case 'c': /* catch up */
#ifdef CATCHUP
if (ng < nextrcline) {
catch_up(ng);
}
else
retry = TRUE;
ng++;
#else
notincl("c");
#endif
break;
case 'u': /* unsubscribe */
if (ng < nextrcline && toread[ng] >= TR_NONE) {
/* unsubscribable? */
printf(unsubto,rcline[ng]);
rcchar[ng] = NEGCHAR;
/* unsubscribe to (from?) it */
toread[ng] = TR_UNSUB;
/* and make line invisible */
ng++; /* do an automatic 'n' */
}
break;
case 'h': /* help */
help_ng();
goto reask_newsgroup;
case 'a':
#ifndef FINDNEWNG
notincl("a");
goto reask_newsgroup;
#else
/* FALL THROUGH */
#endif
case 'o':
#ifdef ONLY
{
#ifdef FINDNEWNG
bool doscan = (*buf == 'a');
#endif
if (!finish_command(TRUE)) /* get rest of command */
goto reinp_newsgroup; /* if rubbed out, try something else */
end_only();
if (buf[1]) {
bool minusd = instr(buf+1,"-d") != Nullch;
sw_list(buf+1);
if (minusd)
cwd_check();
putchar('\n');
#ifdef FINDNEWNG
if (doscan && maxngtodo)
scanactive();
#endif
}
ng = 0; /* simulate ^ */
retry = FALSE;
break;
}
#else
notincl("o");
goto reask_newsgroup;
#endif
case '&':
if (switcheroo()) /* get rest of command */
goto reinp_newsgroup; /* if rubbed out, try something else */
goto reask_newsgroup;
case 'l': { /* list other newsgroups */
if (!finish_command(TRUE)) /* get rest of command */
goto reinp_newsgroup; /* if rubbed out, try something else */
for (s = buf+1; *s == ' '; s++);
/* skip leading spaces */
sprintf(cmd_buf,"%s '%s'",filexp(NEWSGROUPS),s);
resetty();
if (doshell(sh,cmd_buf))
#ifdef VERBOSE
IF(verbose)
fputs(" (Error from newsgroups program)\n",
stdout);
ELSE
#endif
#ifdef TERSE
fputs("(Error)\n",stdout);
#endif
noecho();
crmode();
goto reask_newsgroup;
}
case '.': case '=':
case 'y': case 'Y': /* do normal thing */
if (ng >= nextrcline) {
fputs("\nNot on a newsgroup.",stdout);
goto reask_newsgroup;
}
if (*buf == '=')
s = savestr("=");
else if (*buf == '.') { /* start command? */
if (!finish_command(FALSE)) /* get rest of command */
goto reinp_newsgroup;
s = savestr(buf+1);
/* do_newsgroup will free it */
}
else
s = Nullch;
if (toread[ng])
retry = TRUE;
do_newsgroup(s);
ng++;
break;
case '\n':
fputs(badcr,stdout);
goto reask_newsgroup;
case 'v':
printf("\n%s\n",rnid);
goto reask_newsgroup;
default:
printf("\n%s",hforhelp);
goto reask_newsgroup;
}
}
} while (retry);
}
/* now write .newsrc back out */
write_rc();
finalize(0); /* and exit */
}
/* set current newsgroup */
void
set_ngname(what)
char *what;
{
int len = strlen(what)+1;
growstr(&ngname,&ngnlen,len);
strcpy(ngname,what);
growstr(&ngdir,&ngdlen,len);
strcpy(ngdir,getngdir(ngname));
}
static char *myngdir;
static int ngdirlen = 0;
char *
getngdir(ngnam)
char *ngnam;
{
register char *s;
growstr(&myngdir,&ngdirlen,strlen(ngnam)+1);
strcpy(myngdir,ngnam);
for (s = myngdir; *s; s++)
if (*s == '.')
*s = '/';
return myngdir;
}
!STUFFY!FUNK!
echo Extracting Pnews.SH
cat >Pnews.SH <<'!STUFFY!FUNK!'
case $CONFIG in
'') . config.sh ;;
esac
echo "Extracting Pnews (with variable substitutions)"
$spitshell >Pnews <>Pnews <<'!NO!SUBS!'
if $test -f ${DOTDIR-${HOME-$LOGDIR}}/.pnewsexpert; then
expertise=expert
else
$cat <<'EOM'
I see you've never used this version of Pnews before. I will give you extra
help this first time through, but then you must remember what you learned.
If you don't understand any question, type h and a CR (carriage return) for
help.
If you've never posted an article to the net before, it is HIGHLY recommended
that you read the netiquette document found in net.announce.newusers so
that you'll know to avoid the commonest blunders. To do that, interrupt
Pnews, and get to the top-level prompt of rn. Say "g net.announce.newusers"
and you are on your way.
EOM
expertise=beginner
fi
case $cntry in
can) stpr=Province ;;
*) stpr=State ;;
esac
tmpart=/tmp/article$$
headerfile=""
case $# in
0) ;;
*) case $1 in
-h)
headerfile="$2"
shift
shift
case $# in
0)
oldart=""
;;
*)
oldart="$1"
shift
;;
esac
;;
esac
;;
esac
case $headerfile in
'')
case $# in
0)
ng=h
while $test "$ng" = h ; do
$echo ""
$echo $n "Newsgroup(s): $c"
read ng
case $ng in
h)
$cat <<'EOH'
Type the name of one or more newsgroups to which you wish to post an article.
If you want to post to multiple newsgroups, it is better to do them all at
once than to post to each newsgroup individually, which defeats the news
reading programs' strategies of eliminating duplicates.
Separate multiple newsgroup names with commas.
EOH
;;
esac
done
;;
*)
ng=$1
shift
;;
esac
case $ng in
*\ *)
ng=`$echo "$ng" | $sed 's/[, ] */,/g'`
;;
esac
dist=h
while $test "$dist" = h ; do
$egrep -v '[ ]none$' < $tmpart < $tmpart
;;
esac
rescue="sleep 1; $cat $tmpart >>${HOME-$LOGDIR}/dead.article ; $echo saved in ${HOME-$LOGDIR}/dead.article ; $rm -f $tmpart; exit"
trap "$rescue" 1
trap "$rescue" 2
$echo ""
set `$sed < $tmpart -n -e '/^Distribution: /{' -e p -e q -e '}' -e '/^$/q'`
case $# in
0|1)
set `$sed < $tmpart -n -e '/^Newsgroups: /{' -e p -e q -e '}'`
case $# in
0|1)
set "x net.whatever"
;;
esac
;;
esac
shift
#: play recorded message
#if $test -s ${_NEWSLIB}/recording ; then
# ng=`$echo $1 | $sed "s/,.*//"`
# _rec1=${_NEWSLIB}/`$sed -n "/^$ng/s/^.* //p" ${_NEWSLIB}/recording`
# _tmp=`$echo $ng |$sed "s/\..*//"`
# _rec2=${_NEWSLIB}/`$cat -s ${_NEWSLIB}/recording|$grep ${_tmp}.all|$sed "s/^.* //"`
# if $test -f ${_rec1} ; then
# $cat -s ${_rec1}
# fi
# if $test -f ${_rec2} ; then
# $cat -s ${_rec2}
# fi
#fi
# tell them what we think they are doing... !DIST!
case $1 in
net.*)
$echo 'This program posts news to many hundreds of machines throughout the world.'
;;
$cont*)
$echo 'This program posts news to many machines throughout the continent.'
;;
$cntry*)
$echo 'This program posts news to many machines throughout the country.'
;;
$state*)
$echo 'This program posts news to many machines throughout the state.'
;;
$city*)
$echo 'This program posts news to many machines throughout the city.'
;;
$org*)
$echo 'This program posts news to machines throughout the organization.'
;;
$loc*)
$echo 'This program posts news to machines throughout the local organization.'
;;
*.*)
$echo 'This program may post news to many machines.'
;;
*)
$echo 'This program posts news to everyone on the machine.'
;;
esac
ans=""
while $test "$ans" = "" ; do
$echo $n "Are you absolutely sure that you want to do this? [ny] $c"
read ans
case $ans in
y*) ;;
f*) suppressmess=y ;;
h*) $cat <<'EOH'
Type n or CR to exit, y to post.
EOH
ans="" ;;
*) exit ;;
esac
done
file=h
while $test "$file" = h ; do
$echo ""
$echo $n "Input file name? [RETURN for new file]: $c"
read file
case $file in
h)
$cat <<'EOH'
If you have already produced the body of your article, type the filename
for it here. If you just want to proceed directly to the editor, type a
RETURN. In any event, you will be allowed to edit as many times as you
want before you send off the article.
EOH
;;
'')
$echo "" >> $tmpart
state=edit
;;
*)
$cat $file >>$tmpart
state=ask
;;
esac
done
$echo ""
while true ; do
case $state in
edit)
case $expertise in
beginner)
$cat ${DOTDIR-${HOME-$LOGDIR}}/.pnewsexpert
$cat <<'EOMessage'
A temporary file has been created for you to edit. Be sure to leave at
least one blank line between the header and the body of your message.
(And until a certain bug is fixed all over the net, don't start the body of
your message with any indentation, or it may get eaten.)
Within the header may be fields that you don't understand. If you don't
understand a field (or even if you do), you can simply leave it blank, and
it will go away when the article is posted.
Type return to get the default editor, or type the name of your favorite
editor.
EOMessage
;;
esac
tmp=h
while $test "$tmp" = h ; do
$echo $n "Editor [${VISUAL-${EDITOR-$defeditor}}]: $c"
read tmp
case $tmp in
h)
$cat <<'EOH'
Type a return to get the default editor, or type the name of the editor you
prefer. The default editor depends on the VISUAL and EDITOR environment
variables.
EOH
;;
'')
;;
*)
VISUAL=$tmp
export VISUAL
;;
esac
done
trap "" 2
${VISUAL-${EDITOR-$defeditor}} $tmpart $oldart
trap "$rescue" 2
state=ask
;;
ask)
$echo ""
$echo $n "Send, abort, edit, or list? $c"
read ans
case $ans in
a*)
state=rescue
;;
e*)
state=edit
;;
l*)
$pager $tmpart
state=ask
;;
s*)
state=send
;;
h*)
$cat <<'EOH'
Type s to send the article, a to abort and append the article to dead.article,
e to edit the article again, or l to list the article.
EOH
esac
;;
send)
set `$sed < $tmpart -n -e '/^Newsgroups: /{' -e p -e q -e '}'`
case $# in
2)
if $inews -h < $tmpart ; then
state=cleanup
else
state=rescue
fi
;;
*)
$echo ""
$echo "Malformed Newsgroups line."
$echo ""
sleep 1
state=edit
;;
esac
;;
rescue)
$cat $tmpart >> ${HOME-$LOGDIR}/dead.article
$echo "Article saved to ${HOME-$LOGDIR}/dead.article"
state=cleanup
;;
cleanup)
$rm -f $tmpart
exit
;;
esac
done
!NO!SUBS!
$eunicefix Pnews
chmod 755 Pnews
!STUFFY!FUNK!
echo Extracting util.c
cat >util.c <<'!STUFFY!FUNK!'
/* $Header: util.c,v 4.1 84/09/24 12:11:16 lwall Exp $
*
* $Log: util.c,v $
* Revision 4.1 84/09/24 12:11:16 lwall
* Real baseline.
*
* Revision 4.0.1.4 84/09/12 17:15:08 lwall
* Ndir stuff.
*
* Revision 4.0.1.3 84/09/10 15:34:14 lwall
* Delinted.
*
* Revision 4.0.1.2 84/09/06 09:19:14 lwall
* Fixed bad cast.
*
* Revision 4.0.1.1 84/09/06 08:08:36 lwall
* Getwd now uses correct Null values.
*
* Revision 4.0 84/09/04 09:53:03 lwall
* Baseline for netwide release
*
*/
#include "EXTERN.h"
#include "common.h"
#include "final.h"
#include "ndir.h"
#include "INTERN.h"
#include "util.h"
void
util_init()
{
;
}
/* fork and exec a shell command */
int
doshell(shl,s)
char *s, *shl;
{
int status, pid, w;
register int (*istat)(), (*qstat)();
int (*signal())();
char *shell;
#ifdef SIGTSTP
sigset(SIGTSTP,SIG_DFL);
sigset(SIGCONT,SIG_DFL);
#endif
if (shl != Nullch)
shell = shl;
else if ((shell = getenv("SHELL")) == Nullch || !*shell)
shell = PREFSHELL;
if ((pid = vfork()) == 0) {
if (*s)
execl(shell, shell, "-c", s, 0);
else
execl(shell, shell, 0);
_exit(127);
}
istat = signal(SIGINT, SIG_IGN);
qstat = signal(SIGQUIT, SIG_IGN);
waiting = TRUE;
while ((w = wait(&status)) != pid && w != -1)
;
if (w == -1)
status = -1;
waiting = FALSE;
signal(SIGINT, istat);
signal(SIGQUIT, qstat);
#ifdef SIGTSTP
sigset(SIGTSTP,stop_catcher);
sigset(SIGCONT,cont_catcher);
#endif
return status;
}
static char nomem[] = "rn: out of memory!\n";
/* paranoid version of malloc */
char *
safemalloc(size)
MEM_SIZE size;
{
char *ptr;
char *malloc();
ptr = malloc(size?size:1); /* malloc(0) is NASTY on our system */
if (ptr != Nullch)
return ptr;
else {
fputs(nomem,stdout);
sig_catcher(0);
}
/*NOTREACHED*/
}
/* paranoid version of realloc */
char *
saferealloc(where,size)
char *where;
MEM_SIZE size;
{
char *ptr;
char *realloc();
ptr = realloc(where,size?size:1); /* realloc(0) is NASTY on our system */
if (ptr != Nullch)
return ptr;
else {
fputs(nomem,stdout);
sig_catcher(0);
}
/*NOTREACHED*/
}
/* safe version of string copy */
char *
safecpy(to,from,len)
char *to;
register char *from;
register int len;
{
register char *dest = to;
if (from != Nullch)
for (len--; len && (*dest++ = *from++); len--) ;
*dest = '\0';
return to;
}
/* safe version of string concatenate, with \n deletion and space padding */
char *
safecat(to,from,len)
char *to;
register char *from;
register int len;
{
register char *dest = to;
len--; /* leave room for null */
if (*dest) {
while (len && *dest++) len--;
if (len) {
len--;
*(dest-1) = ' ';
}
}
if (from != Nullch)
while (len && (*dest++ = *from++)) len--;
if (len)
dest--;
if (*(dest-1) == '\n')
dest--;
*dest = '\0';
return to;
}
/* copy a string up to some (non-backslashed) delimiter, if any */
char *
cpytill(to,from,delim)
register char *to, *from;
register int delim;
{
for (; *from; from++,to++) {
if (*from == '\\' && from[1] == delim)
from++;
else if (*from == delim)
break;
*to = *from;
}
*to = '\0';
return from;
}
/* return ptr to little string in big string, NULL if not found */
char *
instr(big, little)
char *big, *little;
{
register char *t, *s, *x;
for (t = big; *t; t++) {
for (x=t,s=little; *s; x++,s++) {
if (!*x)
return Nullch;
if (*s != *x)
break;
}
if (!*s)
return t;
}
return Nullch;
}
/* effective access */
#ifdef SETUIDGID
int
eaccess(filename, mode)
char *filename;
int mode;
{
int protection, euid;
mode &= 7; /* remove extraneous garbage */
if (stat(filename, &filestat) < 0)
return -1;
euid = geteuid();
if (euid == ROOTID)
return 0;
protection = 7 & (filestat.st_mode >>
(filestat.st_uid == euid ? 6 :
(filestat.st_gid == getegid() ? 3 : 0)
));
if ((mode & protection) == mode)
return 0;
errno = EACCES;
return -1;
}
#endif
/*
* Get working directory
*/
#ifdef GETWD
#define dot "."
#define dotdot ".."
static char *name;
static DIR *dirp;
static int off;
static struct stat d, dd;
static struct direct *dir;
char *
getwd(np)
char *np;
{
long rdev, rino;
*np++ = '/';
name = np;
off = -1;
stat("/", &d);
rdev = d.st_dev;
rino = d.st_ino;
for (;;) {
stat(dot, &d);
if (d.st_ino==rino && d.st_dev==rdev)
goto done;
if ((dirp = opendir(dotdot)) == Null(DIR *))
prexit("getwd: cannot open ..\n");
stat(dotdot, &dd);
chdir(dotdot);
if(d.st_dev == dd.st_dev) {
if(d.st_ino == dd.st_ino)
goto done;
do
if ((dir = readdir(dirp)) == Null(struct direct *))
prexit("getwd: read error in ..\n");
while (dir->d_ino != d.st_ino);
}
else do {
if ((dir = readdir(dirp)) == Null(struct direct *))
prexit("getwd: read error in ..\n");
stat(dir->d_name, &dd);
} while(dd.st_ino != d.st_ino || dd.st_dev != d.st_dev);
cat();
closedir(dirp);
}
done:
name--;
if (chdir(name) < 0) {
printf("getwd: can't cd back to %s\n",name);
sig_catcher(0);
}
return (name);
}
void
cat()
{
register i, j;
i = -1;
while (dir->d_name[++i] != 0);
if ((off+i+2) > 1024-1)
return;
for(j=off+1; j>=0; --j)
name[j+i+1] = name[j];
if (off >= 0)
name[i] = '/';
off=i+off+1;
name[off] = 0;
for(--i; i>=0; --i)
name[i] = dir->d_name[i];
}
void
prexit(cp)
char *cp;
{
write(2, cp, strlen(cp));
sig_catcher(0);
}
#else
char *
getwd(np) /* shorter but slower */
char *np;
{
FILE *popen();
FILE *pipefp = popen("/bin/pwd","r");
fgets(np,512,pipefp);
np[strlen(np)-1] = '\0'; /* wipe out newline */
pclose(pipefp);
return np;
}
#endif
/* just like fgets but will make bigger buffer as necessary */
char *
get_a_line(original_buffer,buffer_length,fp)
char *original_buffer;
register int buffer_length;
FILE *fp;
{
register int bufix = 0;
register int nextch;
register char *some_buffer_or_other = original_buffer;
do {
if (bufix >= buffer_length) {
buffer_length *= 2;
if (some_buffer_or_other == original_buffer) {
/* currently static? */
some_buffer_or_other = safemalloc((MEM_SIZE)buffer_length+1);
strncpy(some_buffer_or_other,original_buffer,buffer_length/2);
/* so we must copy it */
}
else { /* just grow in place, if possible */
some_buffer_or_other = saferealloc(some_buffer_or_other,
(MEM_SIZE)buffer_length+1);
}
}
if ((nextch = getc(fp)) == EOF)
return Nullch;
some_buffer_or_other[bufix++] = (char) nextch;
} while (nextch && nextch != '\n');
some_buffer_or_other[bufix] = '\0';
len_last_line_got = bufix;
return some_buffer_or_other;
}
/* copy a string to a safe spot */
char *
savestr(str)
char *str;
{
register char *newaddr = safemalloc((MEM_SIZE)(strlen(str)+1));
strcpy(newaddr,str);
return newaddr;
}
int
makedir(dirname,nametype)
register char *dirname;
int nametype;
{
#ifdef MAKEDIR
register char *end;
register char *s;
char tmpbuf[1024];
register char *tbptr = tmpbuf+5;
for (end = dirname; *end; end++) ; /* find the end */
if (nametype == MD_FILE) { /* not to create last component? */
for (--end; end != dirname && *end != '/'; --end) ;
if (*end != '/')
return 0; /* nothing to make */
*end = '\0'; /* isolate file name */
}
strcpy(tmpbuf,"mkdir");
s = end;
for (;;) {
if (stat(dirname,&filestat) >= 0) {
/* does this much exist? */
*s = '/'; /* mark this as existing */
break;
}
s = rindex(dirname,'/'); /* shorten name */
if (!s) /* relative path! */
break; /* hope they know what they are doing */
*s = '\0'; /* mark as not existing */
}
for (s=dirname; s <= end; s++) { /* this is grody but efficient */
if (!*s) { /* something to make? */
sprintf(tbptr," %s",dirname);
tbptr += strlen(tbptr); /* make it, sort of */
*s = '/'; /* mark it made */
}
}
if (nametype == MD_DIR) /* don't need final slash unless */
*end = '\0'; /* a filename follows the dir name */
return (tbptr==tmpbuf+5 ? 0 : doshell(sh,tmpbuf));
/* exercise our faith */
#else
sprintf(cmd_buf,"%s %s %d", filexp(DIRMAKER), dirname, nametype);
return doshell(sh,cmd_buf);
#endif
}
#ifdef SETENV
static bool firstsetenv = TRUE;
extern char **environ;
void
setenv(nam,val)
char *nam, *val;
{
register int i=envix(nam); /* where does it go? */
if (!environ[i]) { /* does not exist yet */
if (firstsetenv) { /* need we copy environment? */
int j;
/*NOSTRICT*/
char **tmpenv = (char**) /* point our wand at memory */
safemalloc((MEM_SIZE) (i+2) * sizeof(char*));
firstsetenv = FALSE;
for (j=0; j *curlen) { /* need more room? */
if (*curlen)
*strptr = saferealloc(*strptr,(MEM_SIZE)newlen);
else
*strptr = safemalloc((MEM_SIZE)newlen);
*curlen = newlen;
}
}
void
setdef(buffer,dflt)
char *buffer,*dflt;
{
if (*buffer == ' ') {
if (*dflt == '^' && isupper(dflt[1]))
*buffer = Ctl(dflt[1]);
else
*buffer = *dflt;
}
}
!STUFFY!FUNK!
echo Extracting respond.c
cat >respond.c <<'!STUFFY!FUNK!'
/* $Header: respond.c,v 4.1 84/09/24 12:06:33 lwall Exp $
*
* $Log: respond.c,v $
* Revision 4.1 84/09/24 12:06:33 lwall
* Real baseline.
*
* Revision 4.0.1.3 84/09/13 12:07:27 lwall
* UNLINK for Eunice.
*
* Revision 4.0.1.2 84/09/10 15:28:27 lwall
* Delinted.
*
* Revision 4.0.1.1 84/09/10 08:49:29 lwall
* MBOXCHAR now matches against 1st non-space type character.
*
* Revision 4.0 84/09/04 09:52:13 lwall
* Baseline for netwide release
*
*/
#include "EXTERN.h"
#include "common.h"
#include "intrp.h"
#include "head.h"
#include "term.h"
#include "ng.h"
#include "util.h"
#include "rn.h"
#include "intrp.h"
#include "artio.h"
#include "final.h"
#include "INTERN.h"
#include "respond.h"
static char nullart[] = "\nNull article\n";
void
respond_init()
{
;
}
int
save_article()
{
bool use_pref;
register char *s, *c;
char altbuf[256];
int iter;
bool interactive = (buf[1] == FINISHCMD);
if (!finish_command(interactive)) /* get rest of command */
return SAVE_ABORT;
use_pref = isupper(*buf);
#ifdef ASYNC_PARSE
parse_maybe(art);
#endif
savefrom = (*buf=='w' || *buf=='W' ? htype[PAST_HEADER].ht_minpos : 0);
if (artopen(art) == Nullfp) {
#ifdef VERBOSE
IF(verbose)
fputs("\n\
Saving null articles is not very productive! :-)\n\
",stdout);
ELSE
#endif
#ifdef TERSE
fputs(nullart,stdout);
#endif
return SAVE_DONE;
}
if (chdir(cwd)) {
printf(nocd,cwd);
sig_catcher(0);
}
if (savedest)
free(savedest);
if ((s = index(buf,'|')) != Nullch) {
/* is it a pipe command? */
s++; /* skip the | */
while (*s == ' ') s++;
safecpy(altbuf,filexp(s),sizeof altbuf);
savedest = altbuf;
interp(cmd_buf,getval("PIPESAVER",PIPESAVER));
/* then set up for command */
resetty(); /* restore tty state */
if (use_pref) /* use preferred shell? */
doshell(Nullch,cmd_buf);
/* do command with it */
else
doshell(sh,cmd_buf); /* do command with sh */
noecho(); /* and stop echoing */
crmode(); /* and start cbreaking */
savedest = savestr(savedest);
}
else { /* normal save */
bool there, mailbox;
char *savename = getval("SAVENAME",SAVENAME);
s = buf+1; /* skip s or S */
if (*s == '-') { /* if they are confused, skip - also */
#ifdef VERBOSE
IF(verbose)
fputs("Warning: '-' ignored. This isn't readnews.\n",stdout);
ELSE
#endif
#ifdef TERSE
fputs("'-' ignored.\n",stdout);
#endif
s++;
}
for (; *s == ' '; s++); /* skip spaces */
safecpy(altbuf,filexp(s),sizeof altbuf);
s = altbuf;
if (! index(s,'/')) {
interp(buf,getval("SAVEDIR",SAVEDIR));
if (makedir(buf,MD_DIR)) /* ensure directory exists */
strcpy(buf,cwd);
if (*s) {
for (c = buf; *c; c++) ;
*c++ = '/';
strcpy(c,s); /* add filename */
}
s = buf;
}
for (iter = 0;
(there = stat(s,&filestat) >= 0) &&
(filestat.st_mode & S_IFDIR);
iter++) { /* is it a directory? */
c = (s+strlen(s));
*c++ = '/'; /* put a slash before filename */
interp(c, iter ? "News" : savename );
/* generate a default name somehow or other */
if (index(c,'/')) { /* yikes, a '/' in the filename */
makedir(s,MD_FILE);
}
}
if (*s != '/') { /* relative path? */
c = (s==buf ? altbuf : buf);
sprintf(c, "%s/%s", cwd, s);
s = c; /* absolutize it */
}
s = savedest = savestr(s); /* doesn't move any more */
/* make it handy for %b */
if (!there) {
if (mbox_always)
mailbox = TRUE;
else if (norm_always)
mailbox = FALSE;
else {
char *dflt = (instr(savename,"%a") ? "nyq" : "ynq");
sprintf(cmd_buf,
"\nFile %s doesn't exist--\n use mailbox format? [%s] ",
s,dflt);
reask_save:
in_char(cmd_buf);
putchar('\n');
setdef(buf,dflt);
#ifdef VERIFY
printcmd();
#endif
if (*buf == 'h') {
#ifdef VERBOSE
IF(verbose)
printf("\n\
Type y to create %s as a mailbox.\n\
Type n to create it as a normal file.\n\
Type q to abort the save.\n\
",s);
ELSE
#endif
#ifdef TERSE
fputs("\n\
y to create mailbox.\n\
n to create normal file.\n\
q to abort.\n\
",stdout);
#endif
goto reask_save;
}
else if (*buf == 'n') {
mailbox = FALSE;
}
else if (*buf == 'y') {
mailbox = TRUE;
}
else if (*buf == 'q') {
goto s_bomb;
}
else {
fputs(hforhelp,stdout);
goto reask_save;
}
}
}
else if (filestat.st_mode & S_IFCHR)
mailbox = FALSE;
else {
int tmpfd;
tmpfd = open(s,0);
if (tmpfd == -1)
mailbox = FALSE;
else {
read(tmpfd,buf,LBUFLEN);
c = buf;
if (!isspace(MBOXCHAR))
while (isspace(*c))
c++;
mailbox = (*c == MBOXCHAR);
close(tmpfd);
}
}
safecpy(cmd_buf, filexp(mailbox ?
getval("MBOXSAVER",MBOXSAVER) :
getval("NORMSAVER",NORMSAVER) ), sizeof cmd_buf);
/* format the command */
resetty(); /* make terminal behave */
if (doshell(use_pref?Nullch:SH,cmd_buf))
fputs("Not saved",stdout);
else
printf("%s to %s %s",
there?"Appended":"Saved",
mailbox?"mailbox":"file",
s);
if (interactive)
putchar('\n');
noecho(); /* make terminal do what we want */
crmode();
}
s_bomb:
if (chdir(spool) || chdir(ngdir)) {
printf(nocd,ngdir);
sig_catcher(0);
}
return SAVE_DONE;
}
int
cancel_article()
{
char *artid_buf;
char *ngs_buf;
char *from_buf;
char *reply_buf;
int myuid = getuid();
int r = -1;
if (artopen(art) == Nullfp) {
#ifdef VERBOSE
IF(verbose)
fputs("\n\
Cancelling null articles is your idea of fun? :-)\n\
",stdout);
ELSE
#endif
#ifdef TERSE
fputs(nullart,stdout);
#endif
return r;
}
reply_buf = fetchlines(art,REPLY_LINE);
from_buf = fetchlines(art,FROM_LINE);
artid_buf = fetchlines(art,ARTID_LINE);
ngs_buf = fetchlines(art,NGS_LINE);
if (!instr(from_buf,sitename) ||
(!instr(from_buf,logname) &&
!instr(reply_buf,logname) &&
#ifdef NEWSADMIN
myuid != newsuid &&
#endif
myuid != ROOTID ) )
#ifdef VERBOSE
IF(verbose)
fputs("You can't cancel someone else's article\n",stdout);
ELSE
#endif
#ifdef TERSE
fputs("Not your article\n",stdout);
#endif
else {
tmpfp = fopen(headname,"w"); /* open header file */
interp(buf,getval("CANCELHEADER",CANCELHEADER));
fputs(buf,tmpfp);
fclose(tmpfp);
r = doshell(sh,filexp(getval("CANCEL",CANCEL)));
}
free(artid_buf);
free(ngs_buf);
free(from_buf);
free(reply_buf);
return r;
}
void
reply()
{
bool incl_body = (*buf == 'R');
char *maildoer = savestr(filexp(getval("MAILPOSTER",MAILPOSTER)));
if (artopen(art) == Nullfp) {
#ifdef VERBOSE
IF(verbose)
fputs("\nBut null articles are so dull! :-)\n",stdout);
ELSE
#endif
#ifdef TERSE
fputs(nullart,stdout);
#endif
free(maildoer);
return;
}
tmpfp = fopen(headname,"w"); /* open header file */
interp(buf,getval("MAILHEADER",MAILHEADER));
fputs(buf,tmpfp);
if (!instr(maildoer,"%h"))
#ifdef VERBOSE
IF(verbose)
printf("\n%s\n(Above lines saved in file %s)\n",buf,headname);
ELSE
#endif
#ifdef TERSE
printf("\n%s\n(Header in %s)\n",buf,headname);
#endif
if (incl_body) {
interp(buf,getval("YOUSAID",YOUSAID));
fprintf(tmpfp,"%s\n",buf);
#ifdef ASYNC_PARSE
parse_maybe(art);
#endif
fseek(artfp,htype[PAST_HEADER].ht_minpos,0);
while (fgets(buf,LBUFLEN,artfp) != Nullch) {
fprintf(tmpfp,"%s%s",indstr,buf);
}
fprintf(tmpfp,"\n");
}
fclose(tmpfp);
interp(cmd_buf,maildoer);
invoke(cmd_buf,origdir);
UNLINK(headname); /* kill the header file */
free(maildoer);
}
void
followup()
{
bool incl_body = (*buf == 'F');
if (artopen(art) == Nullfp) {
#ifdef VERBOSE
IF(verbose)
fputs("\nNull articles give me indigestion! :-)\n",stdout);
ELSE
#endif
#ifdef TERSE
fputs(nullart,stdout);
#endif
return;
}
tmpfp = fopen(headname,"w");
interp(buf,getval("NEWSHEADER",NEWSHEADER));
fprintf(tmpfp,"%s",buf);
if (incl_body) {
#ifdef VERBOSE
if (verbose)
fputs("\n\
(Be sure to double-check the attribution against the signature, and\n\
trim the quoted article down as much as possible.)\n\
",stdout);
#endif
interp(buf,getval("ATTRIBUTION",ATTRIBUTION));
fprintf(tmpfp,"%s\n",buf);
#ifdef ASYNC_PARSE
parse_maybe(art);
#endif
fseek(artfp,htype[PAST_HEADER].ht_minpos,0);
while (fgets(buf,LBUFLEN,artfp) != Nullch) {
fprintf(tmpfp,"%s%s",indstr,buf);
}
fprintf(tmpfp,"\n");
}
fclose(tmpfp);
safecpy(cmd_buf,filexp(getval("NEWSPOSTER",NEWSPOSTER)),sizeof cmd_buf);
invoke(cmd_buf,origdir);
UNLINK(headname);
}
void
invoke(cmd,dir)
char *cmd,*dir;
{
if (chdir(dir)) {
printf(nocd,dir);
return;
}
#ifdef VERBOSE
IF(verbose)
printf("\n(leaving cbreak mode; cwd=%s)\nInvoking command: %s\n\n",
dir,cmd);
ELSE
#endif
#ifdef TERSE
printf("\n(-cbreak; cwd=%s)\nInvoking: %s\n\n",dir,cmd);
#endif
resetty(); /* make terminal well-behaved */
doshell(sh,cmd); /* do the command */
noecho(); /* set no echo */
crmode(); /* and cbreak mode */
#ifdef VERBOSE
IF(verbose)
fputs("\n(re-entering cbreak mode)\n",stdout);
ELSE
#endif
#ifdef TERSE
fputs("\n(+cbreak)\n",stdout);
#endif
if (chdir(spool) || chdir(ngdir)) {
printf(nocd,ngdir);
sig_catcher(0);
}
}
!STUFFY!FUNK!
echo Extracting sw.c
cat >sw.c <<'!STUFFY!FUNK!'
/* $Header: sw.c,v 4.1 84/09/24 12:10:21 lwall Exp $
*
* $Log: sw.c,v $
* Revision 4.1 84/09/24 12:10:21 lwall
* Real baseline.
*
* Revision 4.0.1.1 84/09/10 15:31:49 lwall
* Delinted.
*
* Revision 4.0 84/09/04 09:52:46 lwall
* Baseline for netwide release
*
*/
#include "EXTERN.h"
#include "common.h"
#include "util.h"
#include "head.h"
#include "only.h"
#include "term.h"
#include "ng.h"
#include "intrp.h"
#include "INTERN.h"
#include "sw.h"
void
sw_init(argc,argv,tcbuf)
int argc;
char *argv[];
char *tcbuf;
{
register int i;
safecpy(tcbuf,getenv("RNINIT"),1024);
if (*tcbuf) {
if (*tcbuf == '/') {
int initfd = open(tcbuf,0);
if (initfd >= 0) {
fstat(initfd,&filestat);
if (filestat.st_size > 1024)
tcbuf = saferealloc(tcbuf,(MEM_SIZE)filestat.st_size);
if (filestat.st_size) {
read(initfd,tcbuf,(int)filestat.st_size);
tcbuf[filestat.st_size-1] = '\0';
/* wipe out last newline */
}
else
*tcbuf = '\0';
close(initfd);
}
else
*tcbuf = '\0';
}
sw_list(tcbuf);
}
for (i = 1; i < argc; i++)
decode_switch(argv[i]);
}
/* decode a list of space separated switches */
void
sw_list(swlist)
char *swlist;
{
char *tmplist = safemalloc((MEM_SIZE) strlen(swlist) + 2);
/* semi-automatic string */
register char *p, inquote = 0;
strcpy(tmplist,swlist);
for (p=tmplist; isspace(*p); p++) ; /* skip any initial spaces */
while (*p) { /* "String, or nothing" */
if (!inquote && isspace(*p)) { /* word delimiter? */
*p++ = '\0'; /* chop here */
while (isspace(*p)) /* these will be ignored later */
p++;
}
else if (inquote == *p) {
strcpy(p,p+1); /* delete trailing quote */
inquote = 0; /* no longer quoting */
}
else if (!inquote && *p == '"' || *p == '\'') {
/* OK, I know when I am not wanted */
inquote = *p; /* remember single or double */
strcpy(p,p+1); /* delete the quote */
} /* (crude, but effective) */
else if (*p == '\\') { /* quoted something? */
if (p[1] == '\n') /* newline? */
strcpy(p,p+2); /* "I didn't see anything" */
else {
strcpy(p,p+1); /* delete the backwhack */
p++; /* leave the whatever alone */
}
}
else
p++; /* normal char, leave it alone */
}
*++p = '\0'; /* put an extra null on the end */
if (inquote)
printf("Unmatched %c in switch\n",inquote);
for (p = tmplist; *p; /* p += strlen(p)+1 */ ) {
decode_switch(p);
while (*p++) ; /* point at null + 1 */
}
free(tmplist); /* this oughta be in Ada */
}
/* decode a single switch */
void
decode_switch(s)
register char *s;
{
while (isspace(*s)) /* ignore leading spaces */
s++;
#ifdef DEBUGGING
if (debug)
printf("Switch: %s\n",s);
#endif
if (*s != '-' && *s != '+') { /* newsgroup pattern */
setngtodo(s);
}
else { /* normal switch */
bool upordown = *s == '-' ? TRUE : FALSE;
char tmpbuf[LBUFLEN];
s++;
switch (*s) {
#ifdef BAUDMOD
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if (upordown ? (atoi(s) <= just_a_sec*10)
: (atoi(s) >= just_a_sec*10) ) {
while (isdigit(*s)) s++;
decode_switch(s);
}
break;
#endif
case '/':
#ifdef SETENV
setenv("SAVEDIR", upordown ? "%p/%c" : "%p" );
setenv("SAVENAME", upordown ? "%a" : "%^C");
#else
notincl("-/");
#endif
break;
case 'c':
checkflag = upordown;
break;
case 'C':
s++;
if (*s == '=') s++;
docheckwhen = atoi(s);
break;
case 'd': {
s++;
if (*s == '=') s++;
if (cwd) {
chdir(cwd);
free(cwd);
}
cwd = savestr(s);
break;
}
#ifdef DEBUGGING
case 'D':
s++;
if (*s == '=') s++;
if (*s)
if (upordown)
debug |= atoi(s);
else
debug &= ~atoi(s);
else
if (upordown)
debug |= 1;
else
debug = 0;
break;
#endif
case 'e':
erase_screen = upordown;
break;
case 'E':
#ifdef SETENV
s++;
if (*s == '=')
s++;
strcpy(tmpbuf,s);
s = index(tmpbuf,'=');
if (s) {
*s++ = '\0';
setenv(tmpbuf,s);
}
else
setenv(tmpbuf,nullstr);
#else
notincl("-E");
#endif
break;
case 'F':
s++;
indstr = savestr(s);
break;
#ifdef INNERSEARCH
case 'g':
gline = atoi(s+1)-1;
break;
#endif
case 'H':
case 'h': {
register int len, i;
char *t;
int flag = (*s == 'h' ? HT_HIDE : HT_MAGIC);
s++;
len = strlen(s);
for (t=s; *t; t++)
if (isupper(*t))
*t = tolower(*t);
for (i=HEAD_FIRST; iinews.c.2.pat <<'!STUFFY!FUNK!'
*** inews.c.orig Mon Sep 24 09:57:15 1984
--- inews.c Mon Sep 24 10:17:39 1984
***************
*** 416,421
/*
* Link ARTICLE into dir for ngname and update active file.
*/
localize(ngname)
char *ngname;
{
--- 416,424 -----
/*
* Link ARTICLE into dir for ngname and update active file.
*/
+ #ifdef DOXREFS
+ long
+ #endif
localize(ngname)
char *ngname;
{
***************
*** 453,458
mknewsg(cp, ngname);
sprintf(bfr, "%s/%ld", cp, ngsize+1);
#ifdef VMS
if ((f2 = creat(bfr, 0666)) >=0 ) {
f1 = open(article, 0);
--- 456,466 -----
mknewsg(cp, ngname);
sprintf(bfr, "%s/%ld", cp, ngsize+1);
+ #ifdef LINKART
+ if (mylink(ARTICLE, bfr) == 0) break;
+ /* on first file inits ARTICLE, on subsequent */
+ /* files "links" to first article */
+ #else !LINKART
#ifdef VMS
if ((f2 = creat(bfr, 0666)) >=0 ) {
f1 = open(article, 0);
***************
*** 468,473
if (link(ARTICLE, bfr) == 0)
break;
#endif !VMS
e = errno; /* keep log from clobbering it */
logerr("Cannot install article as %s", bfr);
if (e != EEXIST) {
--- 476,482 -----
if (link(ARTICLE, bfr) == 0)
break;
#endif !VMS
+ #endif !LINKART
e = errno; /* keep log from clobbering it */
logerr("Cannot install article as %s", bfr);
if (e != EEXIST) {
***************
*** 494,499
strcpy(firstbufname, bfr);
sprintf(bfr, "%s/%ld ", ngname, ngsize+1);
addhist(bfr);
return TRUE;
}
--- 503,509 -----
strcpy(firstbufname, bfr);
sprintf(bfr, "%s/%ld ", ngname, ngsize+1);
addhist(bfr);
+ #ifndef DOXREFS
return TRUE;
#else DOXREFS
return ngsize+1;
***************
*** 495,500
sprintf(bfr, "%s/%ld ", ngname, ngsize+1);
addhist(bfr);
return TRUE;
}
/*
--- 505,513 -----
addhist(bfr);
#ifndef DOXREFS
return TRUE;
+ #else DOXREFS
+ return ngsize+1;
+ #endif DOXREFS
}
/*
***************
*** 507,512
char c;
struct srec srec; /* struct for sys file lookup */
int is_invalid = FALSE;
/* Fill up the rest of header. */
if (mode != PROC) {
--- 520,529 -----
char c;
struct srec srec; /* struct for sys file lookup */
int is_invalid = FALSE;
+ #ifdef DOXREFS
+ register char *nextxref = header.xref;
+ int numxrefs = 0;
+ #endif DOXREFS
/* Fill up the rest of header. */
if (mode != PROC) {
***************
*** 527,532
if (!is_ctl && mode != CREATENG)
is_invalid = ngfcheck(mode == PROC);
/* Write article to temp file. */
tfp = xfopen(mktemp(ARTICLE), "w");
if ( (c=getc(infp)) == ' ' || c == '\t' ) {
--- 544,556 -----
if (!is_ctl && mode != CREATENG)
is_invalid = ngfcheck(mode == PROC);
+ #ifdef LINKART
+ *ARTICLE = '\0'; /* tell mylink() to snarf the name */
+ #else !LINKART
+ #ifdef DOXREFS
+ /* Open temp file for article, but link before writing */
+ tfp = xfopen(mktemp(ARTICLE), "w");
+ #else DOXREFS
/* Write article to temp file. */
tfp = xfopen(mktemp(ARTICLE), "w");
if ( (c=getc(infp)) == ' ' || c == '\t' ) {
***************
*** 545,550
putc('\n',tfp);
fclose(tfp);
fclose(infp);
if (is_invalid) {
logerr("No valid newsgroups found, moved to junk");
--- 569,576 -----
putc('\n',tfp);
fclose(tfp);
fclose(infp);
+ #endif DOXREFS
+ #endif LINKART
if (is_invalid) {
logerr("No valid newsgroups found, moved to junk");
***************
*** 550,555
logerr("No valid newsgroups found, moved to junk");
if (localize("junk"))
savehist(histline);
xxit(1);
}
--- 576,582 -----
logerr("No valid newsgroups found, moved to junk");
if (localize("junk"))
savehist(histline);
+ #ifndef LINKART
xxit(1);
#endif
}
***************
*** 551,556
if (localize("junk"))
savehist(histline);
xxit(1);
}
if (time((time_t)0) > (cgtdate(header.subdate) + DFLTEXP) ){
--- 578,584 -----
savehist(histline);
#ifndef LINKART
xxit(1);
+ #endif
}
#ifdef LINKART
else
***************
*** 552,558
savehist(histline);
xxit(1);
}
!
if (time((time_t)0) > (cgtdate(header.subdate) + DFLTEXP) ){
logerr("Article too old, moved to junk");
if (localize("junk"))
--- 580,588 -----
xxit(1);
#endif
}
! #ifdef LINKART
! else
! #endif
if (time((time_t)0) > (cgtdate(header.subdate) + DFLTEXP) ){
logerr("Article too old, moved to junk");
if (localize("junk"))
***************
*** 557,562
logerr("Article too old, moved to junk");
if (localize("junk"))
savehist(histline);
xxit(1);
}
--- 587,593 -----
logerr("Article too old, moved to junk");
if (localize("junk"))
savehist(histline);
+ #ifndef LINKART
xxit(1);
#endif
}
***************
*** 558,563
if (localize("junk"))
savehist(histline);
xxit(1);
}
if (is_ctl) {
--- 589,595 -----
savehist(histline);
#ifndef LINKART
xxit(1);
+ #endif
}
#ifdef LINKART
else
***************
*** 559,565
savehist(histline);
xxit(1);
}
!
if (is_ctl) {
control(&header);
localize("control");
--- 591,599 -----
xxit(1);
#endif
}
! #ifdef LINKART
! else
! #endif
if (is_ctl) {
control(&header);
localize("control");
***************
*** 566,571
} else {
if (s_find(&srec, FULLSYSNAME) == FALSE)
xerror("Cannot find my name '%s' in %s", FULLSYSNAME, SUBFILE);
for (ptr = nbuf; *ptr;) {
if (ngmatch(ptr, srec.s_nbuf) || index(ptr,'.') == NULL)
localize(ptr);
--- 600,609 -----
} else {
if (s_find(&srec, FULLSYSNAME) == FALSE)
xerror("Cannot find my name '%s' in %s", FULLSYSNAME, SUBFILE);
+ #ifdef DOXREFS
+ sprintf(nextxref,"%s ",FULLSYSNAME);
+ nextxref += strlen(nextxref);
+ #endif
for (ptr = nbuf; *ptr;) {
#ifndef DOXREFS
if (ngmatch(ptr, srec.s_nbuf) || index(ptr,'.') == NULL)
***************
*** 567,572
if (s_find(&srec, FULLSYSNAME) == FALSE)
xerror("Cannot find my name '%s' in %s", FULLSYSNAME, SUBFILE);
for (ptr = nbuf; *ptr;) {
if (ngmatch(ptr, srec.s_nbuf) || index(ptr,'.') == NULL)
localize(ptr);
while (*ptr++)
--- 605,611 -----
nextxref += strlen(nextxref);
#endif
for (ptr = nbuf; *ptr;) {
+ #ifndef DOXREFS
if (ngmatch(ptr, srec.s_nbuf) || index(ptr,'.') == NULL)
localize(ptr);
#else DOXREFS
***************
*** 569,574
for (ptr = nbuf; *ptr;) {
if (ngmatch(ptr, srec.s_nbuf) || index(ptr,'.') == NULL)
localize(ptr);
while (*ptr++)
;
}
--- 608,622 -----
#ifndef DOXREFS
if (ngmatch(ptr, srec.s_nbuf) || index(ptr,'.') == NULL)
localize(ptr);
+ #else DOXREFS
+ if (ngmatch(ptr, srec.s_nbuf) ||
+ index(ptr,'.') == NULL) {
+ sprintf(nextxref,"%s:%ld ",ptr,localize(ptr));
+ numxrefs++;
+ while (*nextxref)
+ nextxref++;
+ }
+ #endif DOXREFS
while (*ptr++)
;
}
***************
*** 577,582
localize("junk");
}
}
broadcast();
savehist(histline);
--- 625,636 -----
localize("junk");
}
}
+ #ifdef DOXREFS
+ if (numxrefs >= 2)
+ *(nextxref-1) = '\0'; /* wipe out the last space */
+ else
+ header.xref[0] = '\0'; /* wipe out the whole thing */
+ #endif
#ifdef LINKART
tfp = xfopen(ARTICLE,"w"); /* open 1st article localized */
***************
*** 578,583
}
}
broadcast();
savehist(histline);
xxit(0);
--- 632,662 -----
header.xref[0] = '\0'; /* wipe out the whole thing */
#endif
+ #ifdef LINKART
+ tfp = xfopen(ARTICLE,"w"); /* open 1st article localized */
+ #endif
+
+ #if defined(LINKART) || defined(DOXREFS)
+ /* Now that xref is constructed, write article to temp file. */
+ /* (We ought to detect no room at this point and clean up.) */
+ if ( (c=getc(infp)) == ' ' || c == '\t' ) {
+ header.intnumlines++;
+ sprintf(header.numlines,"%d",header.intnumlines);
+ }
+ lhwrite(&header, tfp);
+ /* Kludge to get around article truncation problem */
+ if (c == ' ' || c == '\t' )
+ putc('\n', tfp);
+ putc(c,tfp);
+ while (fgets(bfr, BUFLEN, infp) != NULL)
+ fputs(bfr, tfp);
+
+ if (bfr[strlen(bfr)-1] != '\n')
+ putc('\n',tfp);
+ fclose(tfp);
+ fclose(infp);
+ #endif LINKART || DOXREFS
+
broadcast();
savehist(histline);
xxit(0);
***************
*** 853,855
}
return(NULL);
}
--- 932,956 -----
}
return(NULL);
}
+
+ #ifdef LINKART
+ mylink(tmpart,linkfrom)
+ char *tmpart, *linkfrom;
+ {
+ struct stat statbuf;
+
+ if (stat(linkfrom,&statbuf)==0)
+ return -1;
+ if (!*tmpart) /* first article? */
+ strcpy(tmpart,linkfrom); /* just remember name */
+ else {
+ FILE *linkfp = fopen(linkfrom,"w");
+
+ if (!linkfp)
+ return -1;
+ fprintf(linkfp,"%s\n",tmpart); /* do "symbolic link" */
+ fclose(linkfp);
+ }
+ return 0;
+ }
+ #endif LINKART
!STUFFY!FUNK!
echo Extracting backpage.c
cat >backpage.c <<'!STUFFY!FUNK!'
/* $Header: backpage.c,v 4.1 84/09/24 11:42:53 lwall Exp $
*
* $Log: backpage.c,v $
* Revision 4.1 84/09/24 11:42:53 lwall
* Real baseline.
*
* Revision 4.0.1.3 84/09/18 16:44:22 lwall
* Added some sanity checks.
*
* Revision 4.0.1.2 84/09/13 12:01:37 lwall
* UNLINK for Eunice.
*
* Revision 4.0.1.1 84/09/10 15:06:04 lwall
* Delinted.
*
* Revision 4.0 84/09/04 09:49:46 lwall
* Baseline for netwide release
*
*/
#include "EXTERN.h"
#include "common.h"
#include "intrp.h"
#include "INTERN.h"
#include "backpage.h"
ART_LINE maxindx = -1;
void
backpage_init()
{
char *varyname;
varyname = filexp(VARYNAME);
close(creat(varyname,0600));
varyfd = open(varyname,2);
UNLINK(varyname);
}
/* virtual array read */
ART_POS
vrdary(indx)
ART_LINE indx;
{
int subindx;
long offset;
#ifdef DEBUGGING
if (indx > maxindx) {
printf("vrdary(%ld) > %ld\n",(long)indx, (long)maxindx);
return 0;
}
#endif
if (indx < 0)
return 0;
subindx = indx % VARYSIZE;
offset = (indx - subindx) * sizeof(varybuf[0]);
if (offset != oldoffset) {
if (oldoffset >= 0) {
lseek(varyfd,oldoffset,0);
write(varyfd, /*NOSTRICT*/(char *)varybuf,sizeof(varybuf));
}
lseek(varyfd,offset,0);
/*NOSTRICT*/
read(varyfd,(char *)varybuf,sizeof(varybuf));
oldoffset = offset;
}
return varybuf[subindx];
}
/* write to virtual array */
void
vwtary(indx,newvalue)
ART_LINE indx;
ART_POS newvalue;
{
int subindx;
long offset;
#ifdef DEBUGGING
if (indx < 0)
printf("vwtary(%ld)\n",(long)indx);
if (!indx)
maxindx = 0;
if (indx > maxindx) {
if (indx != maxindx + 1)
printf("indx skipped %d-%d\n",maxindx+1,indx-1);
maxindx = indx;
}
#endif
subindx = indx % VARYSIZE;
offset = (indx - subindx) * sizeof(varybuf[0]);
if (offset != oldoffset) {
if (oldoffset >= 0) {
lseek(varyfd,oldoffset,0);
/*NOSTRICT*/
write(varyfd,(char *)varybuf,sizeof(varybuf));
}
lseek(varyfd,offset,0);
/*NOSTRICT*/
read(varyfd,(char *)varybuf,sizeof(varybuf));
oldoffset = offset;
}
varybuf[subindx] = newvalue;
}
!STUFFY!FUNK!
echo ""
echo "End of kit 5 (of 8)"
cat /dev/null >kit5isdone
config=true
for iskit in 1 2 3 4 5 6 7 8; do
if test -f kit${iskit}isdone; then
echo "You have run kit ${iskit}."
else
echo "You still need to run kit ${iskit}."
config=false
fi
done
case $config in
true)
echo "You have run all your kits. Please read README and then type Configure."
chmod 755 Configure
;;
esac
: I do not append .signature, but someone might mail this.
exit