File: samain.c

package info (click to toggle)
trn4 4.0-test77-18
  • links: PTS, VCS
  • area: non-free
  • in suites: sid, trixie
  • size: 4,016 kB
  • sloc: ansic: 48,332; sh: 6,795; tcl: 1,696; yacc: 662; perl: 108; makefile: 26
file content (241 lines) | stat: -rw-r--r-- 5,319 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
237
238
239
240
241
/* This file Copyright 1992 by Clifford A. Adams */
/* samain.c
 *
 * main working routines  (may change later)
 */

#include "EXTERN.h"
#include "common.h"
#ifdef SCAN_ART
#include "list.h"
#include "hash.h"
#include "cache.h"
#include "ngdata.h"
#include "bits.h"
#include "head.h" /* for fetching misc header lines... */
#include "util.h"
#ifdef SCORE
#include "score.h"
#endif
#include "scan.h"
#include "scmd.h"
#include "sdisp.h"
#include "smisc.h"	/* needed? */
#include "sorder.h"
#include "spage.h"
#include "scanart.h"
#include "samisc.h"
#include "sacmd.h"
#include "sadesc.h"
#include "sadisp.h"
#include "sathread.h"
#include "INTERN.h"
#include "samain.h"


void
sa_init()
{
    sa_init_context();
    if (lastart == 0 || absfirst > lastart)
	return;		/* no articles */
    if (s_initscreen())		/* If not able to init screen...*/
	return;				/* ...most likely dumb terminal */
    sa_initmode();			/*      mode differences */
    sa_init_threads();
    sa_mode_read_elig = FALSE;
    if (firstart > lastart)		/* none unread */
	sa_mode_read_elig = TRUE;	/* unread+read in some situations */
    if (!sa_initarts())			/* init article array(s) */
	return;				/* ... no articles */
#ifdef SCORE
#ifdef PENDING
    if (sa_mode_read_elig) {
	sc_fill_read = TRUE;
	sc_fill_max = absfirst - 1;
    }
#endif
#endif
    s_save_context();
    sa_initialized = TRUE;		/* all went well... */
}

void
sa_init_ents()
{
    sa_num_ents = sa_ents_alloc = 0;
    sa_ents = (SA_ENTRYDATA*)NULL;
}

void
sa_clean_ents()
{
    free(sa_ents);
}

/* returns entry number that was added */
long
sa_add_ent(artnum)
ART_NUM artnum;		/* article number to be added */
{
    long cur;

    sa_num_ents++;
    if (sa_num_ents > sa_ents_alloc) {
	sa_ents_alloc += 100;
	if (sa_ents_alloc == 100) {	/* newly allocated */
	    /* don't use number 0, just allocate it and skip it */
	    sa_num_ents = 2;
	    sa_ents = (SA_ENTRYDATA*)safemalloc(sa_ents_alloc
					* sizeof (SA_ENTRYDATA));
        } else {
	    sa_ents = (SA_ENTRYDATA*)saferealloc((char*)sa_ents,
			sa_ents_alloc * sizeof (SA_ENTRYDATA));
	}
    }
    cur = sa_num_ents-1;
    sa_ents[cur].artnum = artnum;
    sa_ents[cur].subj_thread_num = 0;
    sa_ents[cur].sa_flags = (char)0;
    s_order_add(cur);
    return cur;
}

void
sa_cleanmain()
{
    sa_clean_ents();

    sa_mode_zoom = FALSE;	/* doesn't survive across groups */
    /* remove the now-unused scan-context */
    s_delete_context(sa_scan_context);
    sa_context_init = FALSE;
    sa_scan_context = -1;
    /* no longer "in" article scan mode */
    sa_mode_read_elig = FALSE;	/* the default */
    sa_in = FALSE;
}

void
sa_growarts(oldlast,last)
long oldlast,last;
{
    int i;

    for (i = oldlast+1; i <= last; i++)
	(void)sa_add_ent(i);
}

/* Initialize the scan-context to enter article scan mode. */
void
sa_init_context()
{
    if (sa_context_init)
	return;		/* already initialized */
    if (sa_scan_context == -1)
	sa_scan_context = s_new_context(S_ART);
    s_change_context(sa_scan_context);
}

bool
sa_initarts()
{
    int a;

    sa_init_ents();
    /* add all available articles to entry list */
    for (a = article_first(absfirst); a <= lastart; a = article_next(a)) {
	if (article_exists(a))
	    (void)sa_add_ent(a);
    }
    sa_order_read = sa_mode_read_elig;
    return TRUE;
}

/* note: initscreen must be called before (for scr_width) */
void
sa_initmode()
{
    /* set up screen sizes */
    sa_set_screen();

    sa_mode_zoom = 0;			/* reset zoom */
}

int
sa_mainloop()
{
    int i;

#ifdef SCORE
/* Eventually, strn will need a variable in score.[ch] set when the
 * scoring initialization *failed*, so that strn could try to
 * initialize the scoring again or decide to disallow score operations.)
 */
    /* If strn is in score mode but scoring is not initialized,
     * then try to initialize.
     * If that fails then strn will just use arrival ordering.
     */
    if (!sc_initialized && sa_mode_order == 2) {
	sc_delay = FALSE;	/* yes, actually score... */
	sc_init(TRUE);		/* wait for articles to score */
	if (!sc_initialized)
	    sa_mode_order = 1;	/* arrival order */
    }
#endif
    /* redraw it *all* */
    s_ref_all = TRUE;
    if (s_top_ent < 1)
	s_top_ent = s_first();
    i = s_fillpage();
    if (i == -1 || i == 0) {
	/* for now just quit if no page could be filled. */
	return SA_QUIT;
    }
    i = s_cmdloop();
    if (i == SA_READ) {
	i = SA_NORM;
    }
    if (i > 0) {
	sa_art = sa_ents[i].artnum;
	return SA_NORM;
    }
    /* something else (quit, return, etc...) */
    return i;
}

/* do something useful until a key is pressed. */
void
sa_lookahead()
{
#ifdef PENDING
#ifdef SCORE
    sc_lookahead(TRUE,FALSE);		/* do resorting now... */
#else /* !SCORE */
/* consider looking forward from the last article on the page... */
    ;				/* so the function isn't empty */
#endif /* SCORE */
#else /* !PENDING */
    ;				/* so the function isn't empty */
#endif
}

/* Returns first marked entry number, or 0 if no articles are marked. */
long
sa_readmarked_elig()
{
    long e;

    e = s_first();
    if (!e)
	return 0L;
    for ( ; e; e = s_next(e)) {
	if (!sa_basic_elig(e))
	    continue;
	if (sa_marked(e))
	    return e;
    }
    /* This is possible since the marked articles might not be eligible. */
    return 0;
}
#endif /* SCAN */