/* $Header: rcln.c,v 4.3.1.2 85/07/23 17:39:08 lwall Exp $
* Revision 4.3.1.2 85/07/23 17:39:08 lwall
* Oops, was freeing a static buf on -c in checkexpired.
* Revision 4.3.1.1 85/05/10 11:37:08 lwall
* Revision 4.3 85/05/01 11:45:36 lwall
* Baseline for release with 4.3bsd.
printf("\nMarking %s as all read.\n",rcline
[ngx
]) FLUSH
;
fputs("\nMarked read\n",stdout
) FLUSH
;
sprintf(tmpbuf
,"%s: 1-%ld", rcline
[ngx
],(long)getngsize(ngx
));
rcline
[ngx
] = savestr(tmpbuf
);
*(rcline
[ngx
] + rcnums
[ngx
] - 1) = '\0';
/* add an article number to a newsgroup, if it isn't already read */
register NG_NUM ngnum
= find_ng(ngnam
);
register char *s
, *t
, *maxt
= Nullch
;
ART_NUM min
= 0, max
= -1, lastnum
= 0;
if (ngnum
== nextrcline
|| !rcnums
[ngnum
])
/* not found in newsrc? */
/* now is a good time to trim down */
set_toread(ngnum
); /* the list due to expires if we */
if (artnum
> ngmax
[ngnum
] + 10 /* allow for incoming articles */
printf("\nCorrupt Xref line!!! %ld --> %s(1..%ld)\n",
paranoid
= TRUE
; /* paranoia reigns supreme */
return -1; /* hope this was the first newsgroup */
if (toread
[ngnum
] == TR_BOGUS
)
if (debug
& DEB_XREF_MARKER
) {
printf("%ld->\n%s%c%s\n",(long)artnum
,rcline
[ngnum
],rcchar
[ngnum
],
rcline
[ngnum
] + rcnums
[ngnum
]) FLUSH
;
s
= rcline
[ngnum
] + rcnums
[ngnum
];
while (*s
== ' ') s
++; /* skip spaces */
while (isdigit(*s
) && artnum
>= (min
= atol(s
))) {
/* while it might have been read */
for (t
= s
; isdigit(*t
); t
++) ; /* skip number */
if (*t
== '-') { /* is it a range? */
t
++; /* skip to next number */
if (artnum
<= (max
= atol(t
)))
return 0; /* it is in range => already read */
lastnum
= max
; /* remember it */
maxt
= t
; /* remember position in case we */
/* want to overwrite the max */
while (isdigit(*t
)) t
++; /* skip second number */
if (artnum
== min
) /* explicitly a read article? */
lastnum
= min
; /* remember what the number was */
maxt
= Nullch
; /* last one was not a range */
while (*t
&& !isdigit(*t
)) t
++; /* skip comma and any spaces */
/* we have not read it, so insert the article number before s */
morenum
= isdigit(*s
); /* will it need a comma after? */
*(rcline
[ngnum
] + rcnums
[ngnum
] - 1) = rcchar
[ngnum
];
mbuf
= safemalloc((MEM_SIZE
)(strlen(s
) + (s
-rcline
[ngnum
]) + 8));
strcpy(mbuf
,rcline
[ngnum
]); /* make new rc line */
if (maxt
&& lastnum
&& artnum
== lastnum
+1)
/* can we just extend last range? */
t
= mbuf
+ (maxt
-rcline
[ngnum
]);/* then overwrite previous max */
t
= mbuf
+ (t
-rcline
[ngnum
]); /* point t into new line instead */
if (lastnum
) { /* have we parsed any line? */
if (!morenum
) /* are we adding to the tail? */
*t
++ = ','; /* supply comma before */
if (!maxt
&& artnum
== lastnum
+1 && *(t
-1) == ',')
/* adjacent singletons? */
*(t
-1) = '-'; /* turn them into a range */
if (morenum
) { /* is there more to life? */
if (min
== artnum
+1) { /* can we consolidate further? */
bool range_before
= (*(t
-1) == '-');
for (nextmax
= s
; isdigit(*nextmax
); nextmax
++) ;
range_after
= *nextmax
++ == '-';
*t
= '\0'; /* artnum is redundant */
sprintf(t
,"%ld-",(long)artnum
);/* artnum will be new min */
s
= nextmax
; /* *s is redundant */
s = s */ /* *s is new max */
sprintf(t
,"%ld,",(long)artnum
); /* put the number and comma */
sprintf(t
,"%ld",(long)artnum
); /* put the number there (wherever) */
strcat(t
,s
); /* copy remainder of line */
if (debug
& DEB_XREF_MARKER
) {
printf("%s\n",mbuf
) FLUSH
;
rcline
[ngnum
] = mbuf
; /* pull the switcheroo */
*(rcline
[ngnum
] + rcnums
[ngnum
] - 1) = '\0';
if (toread
[ngnum
] > TR_NONE
) /* lest we turn unsub into bogus */
/* delete an article number from a newsgroup, if it is there */
register NG_NUM ngnum
= find_ng(ngnam
);
register ART_NUM min
, max
;
if (ngnum
== nextrcline
|| !rcnums
[ngnum
])
return; /* not found in newsrc? */
if (debug
& DEB_XREF_MARKER
) {
printf("%ld<-\n%s%c%s\n",(long)artnum
,rcline
[ngnum
],rcchar
[ngnum
],
rcline
[ngnum
] + rcnums
[ngnum
]) FLUSH
;
s
= rcline
[ngnum
] + rcnums
[ngnum
];
while (*s
== ' ') s
++; /* skip spaces */
/* a little optimization, since it is almost always the last number */
for (t
=s
; *t
; t
++) ; /* find end of string */
curlen
= t
-rcline
[ngnum
];
for (t
--; isdigit(*t
); t
--) ; /* find previous delim */
if (*t
== ',' && atol(t
+1) == artnum
) {
if (toread
[ngnum
] >= TR_NONE
)
if (debug
& DEB_XREF_MARKER
)
printf("%s%c %s\n",rcline
[ngnum
],rcchar
[ngnum
],s
) FLUSH
;
/* not the last number, oh well, we may need the length anyway */
while (isdigit(*s
) && artnum
>= (min
= atol(s
))) {
/* while it might have been read */
for (t
= s
; isdigit(*t
); t
++) ; /* skip number */
if (*t
== '-') { /* is it a range? */
t
++; /* skip to next number */
while (isdigit(*t
)) t
++; /* skip second number */
/* it is in range => already read */
else if (artnum
== max
) {
*(rcline
[ngnum
] + rcnums
[ngnum
] - 1) = rcchar
[ngnum
];
mbuf
= safemalloc((MEM_SIZE
)(curlen
+ (artnum
?15:2)));
strcpy(mbuf
,rcline
[ngnum
]); /* make new rc line */
s
= mbuf
+ (s
-rcline
[ngnum
]);
/* point s into mbuf now */
if (artnum
) { /* split into two ranges? */
else /* only one range */
strcpy(s
,t
); /* copy remainder over */
if (debug
& DEB_XREF_MARKER
) {
printf("%s\n",mbuf
) FLUSH
;
rcline
[ngnum
] = mbuf
; /* pull the switcheroo */
*(rcline
[ngnum
] + rcnums
[ngnum
] - 1) = '\0';
if (toread
[ngnum
] >= TR_NONE
)
if (artnum
== min
) { /* explicitly a read article? */
if (*t
== ',') /* pick a comma, any comma */
else if (s
[-2] == ',') /* (in case of space) */
strcpy(s
,t
); /* no need to realloc */
if (toread
[ngnum
] >= TR_NONE
)
if (debug
& DEB_XREF_MARKER
) {
printf("%s%c%s\n",rcline
[ngnum
],rcchar
[ngnum
],
rcline
[ngnum
] + rcnums
[ngnum
]) FLUSH
;
while (*t
&& !isdigit(*t
)) t
++; /* skip comma and any spaces */
sprintf(where
,"%ld",(long)min
);
sprintf(where
,"%ld-%ld",(long)min
,(long)max
);
/* calculate the number of unread articles for a newsgroup */
register char *s
, *c
, *h
;
char tmpbuf
[64], *mybuf
= tmpbuf
;
bool virgin_ng
= (!abs1st
[ngnum
]);
ART_NUM ngsize
= getngsize(ngnum
);
ngmax
[ngnum
] = ngsize
; /* for checking out-of-range Xrefs */
if (ngsize
== TR_BOGUS
) {
printf("Warning! Bogus newsgroup: %s\n",rcline
[ngnum
]) FLUSH
;
toread
[ngnum
] = TR_BOGUS
;
sprintf(tmpbuf
," 1-%ld",(long)ngsize
);
if (strNE(tmpbuf
,rcline
[ngnum
]+rcnums
[ngnum
]))
checkexpired(ngnum
,ngsize
); /* this might realloc rcline */
nums
= rcline
[ngnum
]+rcnums
[ngnum
];
mybuf
= safemalloc((MEM_SIZE
)(length
+5));
for (s
= mybuf
; isspace(*s
); s
++)
for ( ; (c
= index(s
,',')) != Nullch
; s
= ++c
) {
*c
= '\0'; /* keep index from running off */
if ((h
= index(s
,'-')) != Nullch
) /* find - in range, if any */
unread
-= (newmax
= atol(h
+1)) - atol(s
) + 1;
else if (newmax
= atol(s
))
unread
--; /* recalculate length */
if (newmax
> ngsize
) { /* paranoia check */
if (unread
>= 0) /* reasonable number? */
toread
[ngnum
] = (ART_UNREAD
)unread
;
/* remember how many are left */
else { /* SOMEONE RESET THE NEWSGROUP!!! */
toread
[ngnum
] = (ART_UNREAD
)ngsize
;
/* assume nothing carried over */
printf("Warning! Somebody reset %s--assuming nothing read.\n",
*(rcline
[ngnum
] + rcnums
[ngnum
]) = '\0';
paranoid
= TRUE
; /* enough to make a guy paranoid */
if (rcchar
[ngnum
] == NEGCHAR
)
toread
[ngnum
] = TR_UNSUB
;
/* make sure expired articles are marked as read */
checkexpired(ngnum
,ngsize
)
register ART_NUM a1st
= getabsfirst(ngnum
,ngsize
);
register ART_NUM num
, lastnum
= 0;
if (debug
& DEB_XREF_MARKER
) {
printf("1-%ld->\n%s%c%s\n",(long)(a1st
-1),rcline
[ngnum
],rcchar
[ngnum
],
rcline
[ngnum
] + rcnums
[ngnum
]) FLUSH
;
for (s
= rcline
[ngnum
] + rcnums
[ngnum
]; isspace(*s
); s
++);
while (*s
&& (num
= atol(s
)) <= a1st
) {
while (*s
&& !isdigit(*s
)) s
++;
if (s
[-1] == '-') { /* landed in a range? */
sprintf(rcline
[ngnum
]+rcnums
[ngnum
]," 1-%s",s
);
/* s now points to what should follow first range */
if (s
- rcline
[ngnum
] > rcnums
[ngnum
] + 10)
mbuf
= safemalloc((MEM_SIZE
)(rcnums
[ngnum
] + strlen(s
) + 10));
strcpy(mbuf
,rcline
[ngnum
]);
newnum
= t
= mbuf
+rcnums
[ngnum
];
sprintf(t
," 1-%ld",(long)(a1st
- (lastnum
!= a1st
)));
if (mbuf
== rcline
[ngnum
]) {
rcline
[ngnum
] = saferealloc(rcline
[ngnum
],
(MEM_SIZE
)(rcnums
[ngnum
] + strlen(newnum
) + 1));
ret
:; /* semicolon in case DEBUGGING undefined */
if (debug
& DEB_XREF_MARKER
) {
printf("%s%c%s\n",rcline
[ngnum
],rcchar
[ngnum
],
rcline
[ngnum
] + rcnums
[ngnum
]) FLUSH
;