File: samisc.c

package info (click to toggle)
trn4 4.0-test77-18
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid, trixie
  • size: 4,016 kB
  • sloc: ansic: 48,332; sh: 6,795; tcl: 1,696; yacc: 662; perl: 108; makefile: 26
file content (236 lines) | stat: -rw-r--r-- 5,249 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/* This file Copyright 1992 by Clifford A. Adams */
/* samisc.c
 *
 * lower-level routines
 */

#include "EXTERN.h"
#include "common.h"
#ifdef SCAN_ART
#include "list.h"
#include "hash.h"
#include "cache.h"
#include "artio.h"		/* openart */
#include "bits.h"
#include "final.h"		/* assert's sig_catcher() */
#include "term.h"		/* for "backspace" */
#include "util.h"
#include "scanart.h"
#include "samain.h"
#include "sathread.h"
#include "sorder.h"
#include "trn.h"
#include "ngdata.h"		/* several */
#include "rcstuff.h"
#include "ng.h"			/* for "art" */
#include "head.h"		/* fetchsubj */
#include "rthread.h"
#include "rt-select.h"		/* sel_mode */
#ifdef SCORE
#include "score.h"
#endif
#include "INTERN.h"
#include "samisc.h"

#ifdef UNDEF	/* use function for breakpoint debugging */
int
check_article(a)
long a;
{
    if (a < absfirst || a > lastart) {
	printf("\nArticle %d out of range\n",a) FLUSH;
	return FALSE;
    }
    return TRUE;
}
#else
/* note that argument is used twice. */
#define check_article(a) ((a) >= absfirst && (a) <= lastart)
#endif

/* ignoring "Fold" (or later recursive) mode(s), is this article eligible? */
bool
sa_basic_elig(a)
long a;
{
    ART_NUM artnum;

    artnum = sa_ents[a].artnum;
    assert(check_article(artnum));

    /* "run the gauntlet" style (:-) */
    if (!sa_mode_read_elig && was_read(artnum))
	return FALSE;
    if (sa_mode_zoom && !sa_selected1(a))
	return FALSE;
#ifdef SCORE
    if (sa_mode_order == 2)	/* score order */
	if (!SCORED(artnum))
	    return FALSE;
#endif
    /* now just check availability */
    if (is_unavailable(artnum)) {
	if (!was_read(artnum))
	    oneless_artnum(artnum);
	return FALSE;		/* don't try positively unavailable */
    }
    /* consider later positively checking availability */
    return TRUE;	/* passed all tests */
}

bool
sa_eligible(a)
long a;
{

    assert(check_article(sa_ents[a].artnum));
    if (!sa_basic_elig(a))
	return FALSE;		/* must always be basic-eligible */
    if (!sa_mode_fold)
	return TRUE;		/* just use basic-eligible */
    else {
	if (sa_subj_thread_prev(a))
	    return FALSE;	/* there was an earlier match */
	return TRUE;		/* no prior matches */
    }
}

/* given an article number, return the entry number for that article */
/* (There is no easy mapping between entry numbers and article numbers.) */
long
sa_artnum_to_ent(artnum)
ART_NUM artnum;
{
    long i;
    for (i = 1; i < sa_num_ents; i++)
	if (sa_ents[i].artnum == artnum)
	    return i;
    /* this had better not happen (complain?) */
    return -1;
}

/* select1 the articles picked in the TRN thread selector */
void
sa_selthreads()
{
    register SUBJECT *sp;
    register ARTICLE *ap;
    bool want_unread;
#if 0
    /* this does not work now, but maybe it will help debugging? */
    int subj_mask = (sel_mode == SM_THREAD? (SF_THREAD|SF_VISIT) : SF_VISIT);
#endif
    int subj_mask = SF_VISIT;

    long art;
    long i;

    want_unread = !sa_mode_read_elig;

    /* clear any old selections */
    for (i = 1; i < sa_num_ents; i++)
	sa_ents[i].sa_flags =
	    (sa_ents[i].sa_flags & 0xfd);

    /* Loop through all (selected) articles. */
    for (sp = first_subject; sp; sp = sp->next) {
	if ((sp->flags & subj_mask) == subj_mask) {
	    for (ap = first_art(sp); ap; ap = next_art(ap)) {
		art = article_num(ap);
		if ((ap->flags & AF_SEL)
		 && (!(ap->flags & AF_UNREAD) ^ want_unread)) {
		    /* this was a trn-thread selected article */
		    sa_select1(sa_artnum_to_ent(art));
#ifdef SCORE
    /* if scoring, make sure that this article is scored... */
		    if (sa_mode_order == 2)	/* score order */
			sc_score_art(art,FALSE);
#endif
		    }
		}/* for all articles */
	    }/* if selected */
	}/* for all threads */
    s_sort();
}

int
sa_number_arts()
{
    int total;
    long i;
    ART_NUM a;

    if (sa_mode_read_elig)
	i = absfirst;
    else
	i = firstart;
    total = 0;
    for (i = 1; i < sa_num_ents; i++) {
	a = sa_ents[i].artnum;
	if (is_unavailable(a))
	    continue;
	if (!article_unread(a) && !sa_mode_read_elig)
	    continue;
	total++;
    }
    return total;
}

/* needed for a couple functions which act within the
 * scope of an article.
 */
void
sa_go_art(a)
long a;
{
    art = a;
    (void)article_find(art);
    if (openart != art)
        artopen(art,(ART_POS)0);
}

int
sa_compare(a,b)
long a,b;		/* the entry numbers to compare */
{
    long i,j;
    
#ifdef SCORE
    if (sa_mode_order == 2) {	/* score order */
	/* do not score the articles here--move the articles to
	 * the end of the list if unscored.
	 */
	if (!SCORED(sa_ents[a].artnum)) {	/* a unscored */
	    if (!SCORED(sa_ents[b].artnum)) {	/* a+b unscored */
	        if (a < b)		/* keep ordering consistent */
		    return -1;
		return 1;
	    }
	    return 1;		/* move unscored (a) to end */
	}
	if (!SCORED(sa_ents[b].artnum))	/* only b unscored */
	    return -1;		/* move unscored (b) to end */

	i = sc_score_art(sa_ents[a].artnum,TRUE);
	j = sc_score_art(sa_ents[b].artnum,TRUE);
	if (i < j)
	    return 1;
	if (i > j)
	    return -1;
	/* i == j */
	if (score_newfirst) {
	    if (a < b)
		return 1;
	    return -1;
	} else {
	    if (a < b)
		return -1;
	    return 1;
	}
    }
#endif
    if (a < b)
	return -1;
    return 1;
}
#endif /* SCAN */