/* $Header: head.c,v 4.3.1.2 85/05/10 13:47:25 lwall Exp $
* Revision 4.3.1.2 85/05/10 13:47:25 lwall
* Revision 4.3.1.1 85/05/10 11:32:30 lwall
* Revision 4.3 85/05/01 11:38:21 lwall
* Baseline for release with 4.3bsd.
bool first_one
; /* is this the 1st occurance of this header line? */
static char htypeix
[26] =
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
for (i
=HEAD_FIRST
+1; i
<HEAD_LAST
; i
++)
htypeix
[*htype
[i
].ht_name
- 'a'] = i
;
printf("header: %d %s", parsed_art
, where
);
for (i
=0; i
<HEAD_LAST
; i
++) {
printf("%15s %4d %4d %03o\n",htype
[i
].ht_name
,
htype
[i
].ht_flags
) FLUSH
;
set_line_type(bufptr
,colon
)
for (t
=lc
,f
=bufptr
; f
<colon
; f
++, t
++) {
/* guard against space before : */
*t
= isupper(*f
) ? tolower(*f
) : *f
;
f
= lc
; /* get lc into register */
/* now scan the headtype table, backwards so we don't have to supply an
* extra terminating value, using first letter as index, and length as
* optimization to avoid calling subroutine strEQ unnecessarily. Hauls.
for (i
= htypeix
[*f
- 'a']; *htype
[i
].ht_name
== *f
; --i
) {
if (len
== htype
[i
].ht_length
&& strEQ(f
, htype
[i
].ht_name
)) {
dumpheader("start_header\n");
for (i
=0; i
<HEAD_LAST
; i
++) {
parseline(art_buf
,newhide
,oldhide
)
if (*art_buf
== ' ' || *art_buf
== '\t')
/* header continuation line? */
else { /* maybe another header line */
if (first_one
) { /* did we just pass 1st occurance? */
htype
[in_header
].ht_maxpos
= artpos
;
/* remember where line left off */
if (s
== Nullch
|| s
-art_buf
> LONGKEY
+2) {
/* is it the end of the header? */
htype
[PAST_HEADER
].ht_minpos
=
(*art_buf
== '\n') ? ftell(artfp
) : artpos
;
/* remember where body starts */
else { /* it is a new header line */
in_header
= set_line_type(art_buf
,s
);
first_one
= (htype
[in_header
].ht_minpos
< 0);
htype
[in_header
].ht_minpos
= artpos
;
if (htype
[in_header
].ht_flags
& HT_HIDE
)
return FALSE
; /* don't hide this line */
if (parsed_art
== artnum
)
/* no maybe about it now */
if (artopen(artnum
) == Nullfp
) {
if (fgets(tmpbuf
,LBUFLEN
,artfp
) == Nullch
)
parseline(tmpbuf
,FALSE
,FALSE
);
/* get the subject line for an article */
fetchsubj(artnum
,current_subject
,copy
)
ART_NUM artnum
; /* article to get subject from */
bool current_subject
; /* is it in a parsed header? */
bool copy
; /* do you want it savestr()ed? */
(char**)safemalloc((MEM_SIZE
)((OFFSET(lastart
)+2)*sizeof(char *)));
for (i
=0; i
<=OFFSET(lastart
); i
++)
if (!artnum
|| artnum
> lastart
)
s
= subj_list
[OFFSET(artnum
)];
s
= fetchlines(artnum
,SUBJ_LINE
);
subj_list
[OFFSET(artnum
)] = s
;
s
= safemalloc((MEM_SIZE
)256);
if (artopen(artnum
) != Nullfp
) {
if (fgets(s
,256,artfp
) == Nullch
)
} while (strnNE(s
,"Title:",6) && strnNE(s
,"Subject:",8));
s
= saferealloc(s
, (MEM_SIZE
)strlen(s
)+1);
subj_list
[OFFSET(artnum
)] = s
;
safecpy(cmd_buf
,s
,CBUFLEN
); /* hope this is okay--we're */
return cmd_buf
; /* really scraping for space here */
/* get header lines from an article */
fetchlines(artnum
,which_line
)
ART_NUM artnum
; /* article to get line from */
int which_line
; /* type of line desired */
char *newbuf
, *t
, tmp_buf
[LBUFLEN
];
register ART_POS firstpos
;
register ART_POS lastpos
;
firstpos
= htype
[which_line
].ht_minpos
;
lastpos
= htype
[which_line
].ht_maxpos
;
if (!artnum
|| firstpos
< 0 || artopen(artnum
) == Nullfp
) {
newbuf
= safemalloc((unsigned int)1);
size
= lastpos
- firstpos
+ 1;
if (debug
&& (size
< 1 || size
> 1000)) {
printf("Firstpos = %ld, lastpos = %ld\n",(long)firstpos
,(long)lastpos
);
newbuf
= safemalloc((unsigned int)size
);
for (curpos
= firstpos
; curpos
< lastpos
; curpos
= ftell(artfp
)) {
if (fgets(tmp_buf
,LBUFLEN
,artfp
) == Nullch
)
if (*tmp_buf
== ' ' || *tmp_buf
== '\t')
t
= index(tmp_buf
,':')+1;
while (*t
== ' ' || *t
== '\t') t
++;