home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
3
/
3899
< prev
next >
Wrap
Internet Message Format
|
1991-08-23
|
50KB
Path: wupost!uunet!mcsun!unido!estevax!norisc!iain
From: iain@norisc.UUCP (Iain Lea)
Newsgroups: alt.sources
Subject: tin v1.00 - YAN (Yet Another Newsreader) Part 04/08
Message-ID: <585@norisc.UUCP>
Date: 23 Aug 91 13:53:58 GMT
Sender: iain@norisc.UUCP (Iain Lea)
Organization: What organization?
Lines: 2414
Submitted-by: iain@estevax.uucp
Archive-name: tin/part04
#!/bin/sh
# this is tin.shar.04 (part 4 of tin)
# do not concatenate these parts, unpack them in order with /bin/sh
# file misc.c continued
#
if touch 2>&1 | fgrep '[-amc]' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
if test ! -r shar3_seq_.tmp; then
echo "Please unpack part 1 first!"
exit 1
fi
(read Scheck
if test "$Scheck" != 4; then
echo "Please unpack part $Scheck next!"
exit 1
else
exit 0
fi
) < shar3_seq_.tmp || exit 1
echo "x - Continuing file misc.c"
sed 's/^X//' << 'SHAR_EOF' >> misc.c &&
X * the head of a thread, linked with arts[].thread. For any q: arts[q],
X * find i such that base[i]->arts[n]->arts[o]->...->arts[q]
X */
X
Xint which_base (n)
X int n;
X{
X register int i, j;
X
X for (i = 0; i < top_base; i++) {
X for (j = base[i] ; j >= 0 ; j = arts[j].thread) {
X if (j == n) {
X return i;
X }
X }
X }
X
X error_message (txt_cannot_find_base_art, (char *) atoi (n));
X return -1;
X}
X
X/*
X * Find how deep in a thread a response is. Start counting at zero
X */
X
Xint which_resp (n)
X int n;
X{
X int i, j;
X int num = 0;
X
X i = which_base (n);
X
X for (j = base[i]; j != -1; j = arts[j].thread)
X if (j == n)
X break;
X else
X num++;
X
X return num;
X}
X
X/*
X * Given an index into base[], find the number of responses for
X * that basenote
X */
X
Xint nresp (n)
X int n;
X{
X int i;
X int oldi = -3;
X int sum = 0;
X
X assert(n < top_base);
X
X for (i = base[n]; i != -1; i = arts[i].thread) {
X assert(i != -2);
X assert(i != oldi);
X oldi = i;
X sum++;
X }
X
X return sum - 1;
X}
X
X
Xvoid asfail(file, line, cond)
X char *file;
X int line;
X char *cond;
X{
X fprintf(stderr, "%s: assertion failure: %s (%d): %s\n",
X progname,file, line, cond);
X exit(1);
X}
X
X
Xvoid copy_fp(a, b, prefix)
X FILE *a;
X FILE *b;
X char *prefix;
X{
X char buf[8192];
X
X while (fgets(buf, 8192, a) != NULL)
X fprintf(b, "%s%s", prefix, buf);
X}
X
X
Xchar *get_val(env, def)
X char *env; /* Environment variable we're looking for */
X char *def; /* Default value if no environ value found */
X{
X extern char *getenv();
X char *ptr;
X
X if ((ptr = getenv(env)) != NULL)
X return(ptr);
X else
X return(def);
X}
X
X
Xint invoke_editor(nam)
X char *nam;
X{
X char buf[LEN+1];
X static char editor[LEN+1];
X static int first = TRUE;
X
X if (first) {
X strcpy (editor, get_val("EDITOR", DEFAULT_EDITOR));
X first = FALSE;
X }
X
X#ifdef DONT_USE_START_LINE
X sprintf(buf, "%s %s", editor, nam);
X#else
X sprintf(buf, "%s +%d %s", editor, start_line_offset, nam);
X#endif
X
X printf("%s", buf);
X return invoke_cmd(buf);
X}
X
X
Xvoid shell_escape()
X{
X char shell[LEN+1];
X char *p;
X
X#ifdef SIGTSTP
X void (*susp)();
X#endif
X
X if (!parse_string("!", shell))
X strcpy (shell, get_val("SHELL", DEFAULT_SHELL));
X
X for (p = shell; *p && (*p == ' ' || *p == '\t'); p++) ;
X
X if (!*p)
X strcpy (shell, get_val("SHELL", DEFAULT_SHELL));
X
X Raw(FALSE);
X
X setuid(real_uid);
X setgid(real_gid);
X
X fputs("\r\n", stdout);
X
X#ifdef SIGTSTP
X susp = signal(SIGTSTP, SIG_DFL);
X#endif
X
X system(p);
X
X#ifdef SIGTSTP
X signal(SIGTSTP, susp);
X#endif
X
X setuid(tin_uid);
X setgid(tin_gid);
X
X Raw(TRUE);
X
X mail_setup();
X}
X
X
Xvoid tin_done (ret)
X int ret;
X{
X free_all_arrays (); /* deallocate all arrays */
X ClearScreen();
X Raw(FALSE);
X exit(ret);
X}
X
X/*
X * Load the active file into active[]
X */
X
Xvoid read_active()
X{
X FILE *fp;
X char *p, *q;
X char buf[LEN+1];
X long h;
X int i;
X
X num_active = 0;
X
X if ((fp = open_active_fp ()) == NULL) {
X fprintf (stderr, txt_cannot_open, active_file);
X fprintf (stderr, "\n");
X exit(1);
X }
X
X while (fgets(buf, LEN, fp) != NULL) {
X for (p = buf; *p && *p != ' '; p++) ;
X if (*p != ' ') {
X fprintf(stderr, txt_bad_active_file);
X continue;
X }
X *p++ = '\0';
X
X if (num_active >= max_active)
X expand_active();
X
X h = hash_groupname (buf);
X
X if (group_hash[h] == -1) {
X group_hash[h] = num_active;
X } else { /* hash linked list chaining */
X for (i=group_hash[h]; active[i].next >= 0; i=active[i].next) {
X if (strcmp(active[i].name, buf) == 0) {
X goto read_active_continue; /* kill dups */
X }
X }
X if (strcmp(active[i].name, buf) == 0)
X goto read_active_continue;
X active[i].next = num_active;
X }
X
X for (q = p; *q && *q != ' '; q++) ;
X if (*q != ' ') {
X fprintf(stderr, txt_bad_active_file);
X continue;
X }
X
X active[num_active].name = str_dup (buf);
X active[num_active].max = atol (p);
X active[num_active].min = atol (q);
X active[num_active].next = -1; /* hash chaining */
X active[num_active].flag = NOTGOT; /* not in my_group[] yet */
X
X num_active++;
X
Xread_active_continue:;
X
X }
X
X#ifdef SORT_ACTIVE_FILE /* DOES NOT WORK - ERROR */
X if (num_active) {
X qsort (active, num_active, sizeof (struct group_ent), active_comp);
X }
X#endif
X
X debug_print_active ();
X
X fclose(fp);
X}
X
X
X#ifdef SORT_ACTIVE_FILE /* DOES NOT WORK - ERROR */
Xint active_comp (s1, s2)
X struct group_ent *s1;
X struct group_ent *s2;
X{
X /* s1->name less than s2->name */
X if (strcmp (s1->name, s2->name) < 0) {
X return -1;
X }
X /* s1->name greater than s2->name */
X if (strcmp (s1->name, s2->name) > 0) {
X return 1;
X }
X return 0;
X}
X#endif
X
Xvoid add_signature (fp, flag)
X FILE *fp;
X int flag;
X{
X FILE *sigf;
X
X if ((sigf = fopen(signature, "r")) != NULL) {
X if (flag) {
X fprintf(fp, "\n--\n");
X copy_fp(sigf, fp, "");
X }
X fclose(sigf);
X return;
X }
X
X if ((sigf = fopen(sig, "r")) != NULL) {
X fprintf(fp, "\n--\n");
X copy_fp(sigf, fp, "");
X fclose(sigf);
X }
X}
X
X
X#ifdef USE_MKDIR
Xmkdir (path, mode)
X char *path;
X int mode;
X{
X char buf[LEN+1];
X struct stat sb;
X
X sprintf(buf, "mkdir %s", path);
X if (stat (path, &sb) == -1) {
X system(buf);
X chmod(path, mode);
X }
X}
X#endif
X
X
Xlong hash_groupname(buf) /* hash group name for fast lookup later */
X char *buf;
X{
X char *t = buf;
X unsigned long h;
X
X h = *t++;
X while (*t)
X h = ((h << 1) ^ *t++) % TABLE_SIZE;
X
X return h;
X}
X
X
Xvoid rename_file (old_filename, new_filename)
X char *old_filename;
X char *new_filename;
X{
X unlink (new_filename);
X link (old_filename, new_filename);
X unlink (old_filename);
X}
X
X
Xchar *str_dup (str)
X char *str;
X{
X char *dup = (char *) 0;
X
X assert (str != NULL);
X
X if (str) {
X dup = my_malloc (strlen (str)+1);
X strcpy (dup, str);
X }
X return dup;
X}
X
X
Xint invoke_cmd(nam)
X char *nam;
X{
X int ret;
X
X#ifdef SIGTSTP
X void (*susp)();
X#endif
X
X Raw(FALSE);
X setuid(real_uid);
X setgid(real_gid);
X
X#ifdef SIGTSTP
X susp = signal(SIGTSTP, SIG_DFL);
X#endif
X
X ret = system(nam);
X
X#ifdef SIGTSTP
X signal(SIGTSTP, susp);
X#endif
X
X setuid(tin_uid);
X setgid(tin_gid);
X Raw(TRUE);
X
X return ret == 0;
X}
SHAR_EOF
echo "File misc.c is complete" &&
$TOUCH -am 0822125891 misc.c &&
chmod 0600 misc.c ||
echo "restore of misc.c failed"
set `wc -c misc.c`;Wc_c=$1
if test "$Wc_c" != "12707"; then
echo original size 12707, current size $Wc_c
fi
# ============= newsrc.c ==============
echo "x - extracting newsrc.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > newsrc.c &&
X/*
X * Project : tin - a visual threaded usenet newsreader
X * Module : newsrc.c
X * Author : R.Skrenta / I.Lea
X * Created : 01-04-91
X * Updated : 10-08-91
X * Release : 1.0
X * Notes :
X * Copyright : (c) Copyright 1991 by Rich Skrenta & Iain Lea
X * You may freely copy or redistribute this software,
X * so long as there is no profit made from its use, sale
X * trade or reproduction. You may not change this copy-
X * right notice, and it must be included in any copy made
X */
X
X#include "tin.h"
X
X/*
X * Read $HOME/.newsrc into my_group[]. my_group[] ints point to
X * active[] entries. Sub_only determines whether we just read
X * subscribed groups or all of them.
X */
X
Xvoid read_newsrc (sub_only)
X int sub_only; /* TRUE=subscribed groups only, FALSE=all groups */
X{
X FILE *fp;
X char *p;
X char buf[8192];
X char c;
X int i;
X
X local_top = 0;
X
X if ((fp = fopen(newsrc, "r")) == NULL) { /* attempt to make a .newsrc */
X for (i = 0; i < num_active; i++) {
X if (local_top >= max_active)
X expand_active();
X my_group[local_top] = i;
X active[i].flag = 0;
X unread[local_top] = -1;
X local_top++;
X }
X write_newsrc ();
X return;
X }
X
X while (fgets(buf, 8192, fp) != NULL) {
X p = buf;
X while (*p && *p != '\n' && *p != ' ' && *p != ':' && *p != '!')
X p++;
X c = *p;
X *p++ = '\0';
X if (c == '!' && sub_only)
X continue; /* unsubscribed */
X
X if ((i = add_group (buf, FALSE)) < 0) {
X fprintf (stderr, txt_not_in_active_file, buf);
X fprintf (stderr, "\n");
X continue;
X }
X
X if (c != '!') /* if we're subscribed to it */
X active[my_group[i]].flag |= SUBS;
X
X unread[i] = parse_unread (p, my_group[i]);
X }
X fclose(fp);
X}
X
X
X/*
X * Write a new newsrc from my_group[] and active[]
X * Used to a create a new .newsrc if there isn't one already, or when
X * the newsrc is reset.
X */
X
Xvoid write_newsrc ()
X{
X FILE *fp;
X int i;
X
X setuid(real_uid); /* become the user to write in his */
X setgid(real_gid); /* home directory */
X
X if ((fp = fopen(newsrc, "w")) == NULL)
X goto write_newsrc_done;
X
X for (i = 0; i < num_active; i++) {
X fprintf(fp, "%s: \n", active[i].name);
X }
X
X fclose(fp);
X
Xwrite_newsrc_done:
X setuid(tin_uid);
X setgid(tin_gid);
X}
X
X/*
X * Load the sequencer rang lists and mark arts[] according to the
X * .newsrc info for a particular group. i.e. rec.arts.comics: 1-94,97
X */
X
Xvoid read_newsrc_line(group)
X char *group;
X{
X FILE *fp;
X char buf[8192];
X char *p;
X
X if ((fp = fopen(newsrc, "r")) == NULL)
X return;
X
X while (fgets(buf, 8192, fp) != NULL) {
X p = buf;
X while (*p && *p != '\n' && *p != ' ' && *p != ':' && *p != '!')
X p++;
X *p++ = '\0';
X if (strcmp(buf, group) != 0)
X continue;
X parse_seq(p);
X break;
X }
X
X fclose(fp);
X}
X
X
X/*
X * For our current group, update the sequencer information in .newsrc
X */
X
Xvoid update_newsrc (group, groupnum)
X char *group;
X int groupnum; /* index into active[] for this group */
X{
X FILE *fp;
X FILE *newfp;
X char buf[8192];
X char *p;
X char c;
X
X setuid (real_uid);
X setgid (real_gid);
X
X if ((newfp = fopen (newnewsrc, "w")) == NULL)
X goto update_done;
X
X if ((fp = fopen (newsrc, "r")) != NULL) {
X while (fgets (buf, 8192, fp) != NULL) {
X for (p = buf; *p; p++)
X if (*p == '\n') {
X *p = '\0';
X break;
X }
X
X p = buf;
X while (*p && *p != ' ' && *p != ':' && *p != '!')
X p++;
X c = *p;
X if (c != '\0')
X *p++ = '\0';
X
X if (c != '!')
X c = ':';
X
X if (strcmp (buf, group) == 0) {
X fprintf (newfp, "%s%c ", buf, c);
X print_seq (newfp, groupnum);
X fprintf (newfp, "\n");
X } else
X fprintf (newfp, "%s%c%s\n", buf, c, p);
X }
X fclose (fp);
X }
X
X fclose (newfp);
X rename_file (newnewsrc, newsrc);
X
Xupdate_done:
X setuid (tin_uid);
X setgid (tin_gid);
X}
X
X
X/*
X * Subscribe/unsubscribe to a group in .newsrc. ch should either be
X * '!' to unsubscribe or ':' to subscribe. num is the group's index
X * in active[].
X */
X
Xvoid subscribe (group, ch, num, out_seq)
X char *group;
X char ch;
X int num;
X int out_seq; /* output sequencer info? */
X{
X FILE *fp;
X FILE *newfp;
X char buf[8192];
X char *p;
X char c;
X int gotit = FALSE;
X
X if (ch == '!')
X active[num].flag &= ~SUBS;
X else
X active[num].flag |= SUBS;
X
X setuid (real_uid);
X setgid (real_gid);
X
X if ((newfp = fopen (newnewsrc, "w")) == NULL)
X goto subscribe_done;
X
X if ((fp = fopen (newsrc, "r")) != NULL) {
X while (fgets (buf, 8192, fp) != NULL) {
X for (p = buf; *p; p++)
X if (*p == '\n') {
X *p = '\0';
X break;
X }
X
X p = buf;
X while (*p && *p != ' ' && *p != ':' && *p != '!')
X p++;
X c = *p;
X if (c != '\0')
X *p++ = '\0';
X
X if (c != '!')
X c = ':';
X
X if (strcmp (buf, group) == 0) {
X fprintf (newfp, "%s%c%s\n", buf, ch, p);
X gotit = TRUE;
X } else
X fprintf (newfp, "%s%c%s\n", buf, c, p);
X }
X fclose (fp);
X }
X
X if (!gotit) {
X if (out_seq) {
X fprintf(newfp, "%s%c ", group, ch);
X print_seq(newfp, num);
X fprintf(newfp, "\n");
X } else
X fprintf(newfp, "%s%c\n", group, ch);
X }
X
X fclose (newfp);
X rename_file (newnewsrc, newsrc);
X
Xsubscribe_done:
X setuid (tin_uid);
X setgid (tin_gid);
X}
X
X
Xvoid reset_newsrc ()
X{
X FILE *fp;
X FILE *newfp;
X char buf[8192];
X char *p;
X char c;
X int i;
X
X setuid(real_uid);
X setgid(real_gid);
X
X if ((newfp = fopen(newnewsrc, "w")) == NULL)
X goto update_done;
X
X if ((fp = fopen(newsrc, "r")) != NULL) {
X while (fgets(buf, 8192, fp) != NULL) {
X for (p = buf; *p && *p != '\n'; p++) ;
X *p = '\0';
X
X p = buf;
X while (*p && *p != ' ' && *p != ':' && *p != '!')
X p++;
X c = *p;
X if (c != '\0')
X *p++ = '\0';
X
X if (c != '!')
X c = ':';
X
X fprintf(newfp, "%s%c\n", buf, c);
X }
X fclose(fp);
X }
X
X fclose(newfp);
X rename_file (newnewsrc, newsrc);
X
Xupdate_done:
X setuid(tin_uid);
X setgid(tin_gid);
X
X for (i = 0; i < local_top; i++)
X unread[i] = -1;
X}
X
X
Xvoid delete_group(group)
X char *group;
X{
X FILE *fp;
X FILE *newfp;
X char buf[8192];
X char *p;
X char c;
X int gotit = FALSE;
X FILE *del;
X
X setuid(real_uid);
X setgid(real_gid);
X
X if ((newfp = fopen(newnewsrc, "w")) == NULL)
X goto del_done;
X
X if ((del = fopen(delgroups, "a+")) == NULL)
X goto del_done;
X
X if ((fp = fopen(newsrc, "r")) != NULL) {
X while (fgets(buf, 8192, fp) != NULL) {
X for (p = buf; *p && *p != '\n'; p++) ;
X *p = '\0';
X
X p = buf;
X while (*p && *p != ' ' && *p != ':' && *p != '!')
X p++;
X c = *p;
X if (c != '\0')
X *p++ = '\0';
X
X if (c != '!')
X c = ':';
X
X if (strcmp(buf, group) == 0) {
X fprintf(del, "%s%c%s\n", buf, c, p);
X gotit = TRUE;
X } else
X fprintf(newfp, "%s%c%s\n", buf, c, p);
X }
X fclose(fp);
X }
X
X fclose(newfp);
X
X if (!gotit)
X fprintf(del, "%s! \n", group);
X
X fclose(del);
X rename_file (newnewsrc, newsrc);
X
Xdel_done:
X setuid(tin_uid);
X setgid(tin_gid);
X}
X
X
Xint undel_group()
X{
X FILE *del;
X FILE *newfp;
X FILE *fp;
X char buf[2][8192];
X char *p;
X int which = 0;
X long h;
X extern int cur_groupnum;
X int i, j;
X char c;
X
X setuid(real_uid);
X setgid(real_gid);
X
X if ((del = fopen(delgroups, "r")) == NULL) {
X setuid(tin_uid);
X setgid(tin_gid);
X return FALSE;
X }
X
X unlink(delgroups);
X
X if ((newfp = fopen(delgroups, "w")) == NULL) {
X setuid(tin_uid);
X setgid(tin_gid);
X return FALSE;
X }
X
X buf[0][0] = '\0';
X buf[1][0] = '\0';
X
X while (fgets(buf[which], 8192, del) != NULL) {
X which = !which;
X if (*buf[which])
X fputs(buf[which], newfp);
X }
X
X fclose(del);
X fclose(newfp);
X which = !which;
X
X if (!*buf[which]) {
X setuid(tin_uid);
X setgid(tin_gid);
X return FALSE;
X }
X
X for (p = buf[which]; *p && *p != '\n'; p++) ;
X *p = '\0';
X
X p = buf[which];
X while (*p && *p != ' ' && *p != ':' && *p != '!')
X p++;
X c = *p;
X if (c != '\0')
X *p++ = '\0';
X
X if (c != '!')
X c = ':';
X
X { /* find the hash of the group name */
X char *t = buf[which];
X
X h = *t++;
X while (*t)
X h = (h * 64 + *t++) % TABLE_SIZE;
X }
X
X for (i = group_hash[h]; i >= 0; i = active[i].next) {
X if (strcmp(buf[which], active[i].name) == 0) {
X for (j = 0; j < local_top; j++)
X if (my_group[j] == i) {
X setuid(tin_uid);
X setgid(tin_gid);
X return j;
X }
X
X active[i].flag &= ~NOTGOT; /* mark that we got it */
X if (c != '!')
X active[i].flag |= SUBS;
X
X if (local_top >= max_active)
X expand_active();
X local_top++;
X for (j = local_top; j > cur_groupnum; j--) {
X my_group[j] = my_group[j-1];
X unread[j] = unread[j-1];
X }
X my_group[cur_groupnum] = i;
X unread[cur_groupnum] = parse_unread(p, i);
X
X if ((fp = fopen(newsrc, "r")) == NULL) {
X setuid(tin_uid);
X setgid(tin_gid);
X return FALSE;
X }
X if ((newfp = fopen(newnewsrc, "w")) == NULL) {
X fclose(fp);
X setuid(tin_uid);
X setgid(tin_gid);
X return FALSE;
X }
X i = 0;
X while (fgets(buf[!which], 8192, fp) != NULL) {
X for (p = buf[!which]; *p && *p != '\n'; p++) ;
X *p = '\0';
X
X p = buf[!which];
X while (*p && *p!=' ' && *p != ':' && *p != '!')
X p++;
X c = *p;
X if (c != '\0')
X *p++ = '\0';
X
X if (c != '!')
X c = ':';
X
X while (i < cur_groupnum) {
X if (strcmp(buf[!which],
X active[my_group[i]].name) == 0) {
X fprintf(newfp, "%s%c%s\n",
X buf[!which], c, p);
X goto foo_cont;
X }
X i++;
X }
X fprintf(newfp, "%s%c%s\n", buf[which], c, p);
X fprintf(newfp, "%s%c%s\n", buf[!which], c, p);
X break;
Xfoo_cont:;
X }
X
X while (fgets(buf[!which], 8192, fp) != NULL)
X fputs(buf[!which], newfp);
X
X fclose(newfp);
X fclose(fp);
X rename_file (newnewsrc, newsrc);
X setuid(tin_uid);
X setgid(tin_gid);
X return TRUE;
X }
X }
X
X setuid(tin_uid);
X setgid(tin_gid);
X
X return FALSE;
X}
X
X
Xvoid mark_group_read(group, groupnum)
X char *group;
X int groupnum; /* index into active[] for this group */
X{
X FILE *fp;
X FILE *newfp;
X char buf[8192];
X char *p;
X char c;
X
X if (active[groupnum].max < 2)
X return;
X
X setuid(real_uid);
X setgid(real_gid);
X
X if ((newfp = fopen(newnewsrc, "w")) == NULL)
X goto mark_group_read_done;
X
X if ((fp = fopen(newsrc, "r")) != NULL) {
X while (fgets(buf, 8192, fp) != NULL) {
X for (p = buf; *p; p++)
X if (*p == '\n') {
X *p = '\0';
X break;
X }
X
X p = buf;
X while (*p && *p != ' ' && *p != ':' && *p != '!')
X p++;
X c = *p;
X if (c != '\0')
X *p++ = '\0';
X
X if (c != '!')
X c = ':';
X
X if (strcmp(buf, group) == 0) {
X fprintf(newfp, "%s%c 1-%ld\n", buf, c,
X active[groupnum].max);
X } else
X fprintf(newfp, "%s%c%s\n", buf, c, p);
X }
X fclose(fp);
X }
X
X fclose(newfp);
X rename_file (newnewsrc, newsrc);
X
Xmark_group_read_done:
X setuid(tin_uid);
X setgid(tin_gid);
X}
X
X
Xvoid parse_seq(s)
X char *s;
X{
X long low, high;
X int i;
X
X while (*s) {
X while (*s && (*s < '0' || *s > '9'))
X s++;
X
X if (*s && *s >= '0' && *s <= '9') {
X low = atol(s);
X while (*s && *s >= '0' && *s <= '9')
X s++;
X if (*s == '-') {
X s++;
X high = atol(s);
X while (*s && *s >= '0' && *s <= '9')
X s++;
X } else
X high = low;
X
X for (i = 0; i < top; i++)
X if (arts[i].artnum >= low && arts[i].artnum <= high)
X arts[i].unread = ART_READ;
X }
X }
X}
X
X
Xint parse_unread (s, groupnum)
X char *s;
X int groupnum; /* index for group in active[] */
X{
X long low, high;
X long last_high;
X int sum = 0;
X int gotone = FALSE;
X int n;
X
X/*
X * Read the first range from the .newsrc sequencer information. If the
X * top of the first range is higher than what the active file claims is
X * the bottom, use it as the new bottom instead
X */
X
X high = 0;
X if (*s) {
X while (*s && (*s < '0' || *s > '9'))
X s++;
X
X if (*s && *s >= '0' && *s <= '9') {
X low = atol(s);
X while (*s && *s >= '0' && *s <= '9')
X s++;
X if (*s == '-') {
X s++;
X high = atol(s);
X while (*s && *s >= '0' && *s <= '9')
X s++;
X } else
X high = low;
X gotone = TRUE;
X }
X }
X
X if (high < active[groupnum].min)
X high = active[groupnum].min;
X
X while (*s) {
X last_high = high;
X
X while (*s && (*s < '0' || *s > '9'))
X s++;
X
X if (*s && *s >= '0' && *s <= '9') {
X low = atol(s);
X while (*s && *s >= '0' && *s <= '9')
X s++;
X if (*s == '-') {
X s++;
X high = atol(s);
X while (*s && *s >= '0' && *s <= '9')
X s++;
X } else
X high = low;
X
X if (low > last_high) /* otherwise seq out of order */
X sum += (low - last_high) - 1;
X }
X }
X
X if (gotone) {
X if (active[groupnum].max > high)
X sum += active[groupnum].max - high;
X return sum;
X }
X
X n = (int) (active[groupnum].max - active[groupnum].min);
X if (n < 2)
X return 0;
X
X return -1;
X}
X
X
Xint get_line_unread(group, groupnum)
X char *group;
X int groupnum; /* index for group in active[] */
X{
X FILE *fp;
X char buf[8192];
X char *p;
X int ret = -1;
X
X if ((fp = fopen(newsrc, "r")) == NULL)
X return -1;
X
X while (fgets(buf, 8192, fp) != NULL) {
X p = buf;
X while (*p && *p != '\n' && *p != ' ' && *p != ':' && *p != '!')
X p++;
X *p++ = '\0';
X
X if (strcmp (buf, group) != 0)
X continue;
X
X ret = parse_unread (p, groupnum);
X break;
X }
X
X fclose(fp);
X return ret;
X}
X
X
Xvoid print_seq (fp, groupnum)
X FILE *fp;
X int groupnum; /* index into active[] for this group */
X{
X int i;
X int flag = FALSE;
X
X if (top <= 0) {
X if (active[groupnum].min > 1) {
X fprintf (fp, "1-%ld", active[groupnum].min);
X fflush (fp);
X }
X return;
X }
X
X /*
X * sort into the same order as in the spool area for writing
X * read article numbers to ~/.newsrc
X */
X qsort (arts, top, sizeof (struct header), artnum_comp);
X
X i = 0;
X if (arts[0].artnum > 1) {
X for (; i < top && !arts[i].unread; i++) ;
X if (i > 0)
X fprintf (fp, "1-%ld", arts[i-1].artnum);
X else
X fprintf (fp, "1-%ld", arts[0].artnum - 1);
X flag = TRUE;
X }
X
X for (; i < top; i++) {
X if (! arts[i].unread) {
X if (flag)
X fprintf(fp, ",");
X else
X flag = TRUE;
X fprintf (fp, "%ld", arts[i].artnum);
X if (i+1 < top && !arts[i+1].unread) {
X while (i+1 < top && ! arts[i+1].unread)
X i++;
X fprintf (fp, "-%ld", arts[i].artnum);
X }
X }
X }
X
X if (! flag && active[groupnum].min > 1)
X fprintf (fp, "1-%ld", active[groupnum].min);
X fflush (fp);
X
X /*
X * resort into required sort order
X */
X switch (sort_art_type) {
X case SORT_BY_NONE: /* already sorted above */
X break;
X case SORT_BY_SUBJ:
X qsort (arts, top, sizeof (struct header), subj_comp);
X break;
X case SORT_BY_FROM:
X qsort (arts, top, sizeof (struct header), from_comp);
X break;
X case SORT_BY_DATE:
X qsort (arts, top, sizeof (struct header), date_comp);
X break;
X }
X}
X
X/*
X * rewrite .newsrc and position group at specifed position
X */
X
Xint pos_group_in_newsrc (group, pos)
X char *group;
X int pos;
X{
X char sub[LEN+1];
X char unsub[LEN+1];
X char buf[LEN+1], *ptr;
X char newsgroup[LEN+1];
X extern int cur_groupnum;
X FILE *fp_in, *fp_out;
X FILE *fp_sub, *fp_unsub;
X int repositioned = FALSE;
X int subscribed_pos = 1;
X int group_len;
X
X if ((fp_in = fopen (newsrc, "r")) == NULL) {
X return FALSE;
X }
X if ((fp_out = fopen (newnewsrc, "w")) == NULL) {
X return FALSE;
X }
X
X sprintf (sub, "/tmp/.subrc%d", getpid ());
X sprintf (unsub, "/tmp/.unsubrc.%d", getpid ());
X
X if ((fp_sub = fopen (sub, "w")) == NULL) {
X return FALSE;
X }
X if ((fp_unsub = fopen (unsub, "w")) == NULL) {
X return FALSE;
X }
X
X /*
X * split newsrc into subscribed and unsubscribed to files
X */
X group_len = strlen (group);
X
X while (fgets (buf, LEN, fp_in) != NULL) {
X if (strncmp (group, buf, group_len) == 0 && buf[group_len] == ':') {
X my_strncpy (newsgroup, buf, LEN);
X } else if (ptr = (char *) strchr (buf, ':')) {
X fprintf (fp_sub, "%s", buf);
X } else {
X fprintf (fp_unsub, "%s", buf);
X }
X }
X
X fclose (fp_in);
X fclose (fp_sub);
X fclose (fp_unsub);
X
X /*
X * write subscribed groups & position group to newnewsrc
X */
X if ((fp_sub = fopen (sub, "r")) == NULL) {
X unlink (sub);
X return FALSE;
X }
X while (fgets (buf, LEN, fp_sub) != NULL) {
X if (pos == subscribed_pos) {
X fprintf (fp_out, "%s\n", newsgroup);
X repositioned = TRUE;
X }
X
X fprintf (fp_out, "%s", buf);
X
X subscribed_pos++;
X }
X if (! repositioned) {
X fprintf (fp_out, "%s", newsgroup);
X repositioned = TRUE;
X }
X
X fclose (fp_sub);
X unlink (sub);
X
X /*
X * write unsubscribed groups to newnewsrc
X */
X if ((fp_unsub = fopen (unsub, "r")) == NULL) {
X unlink (unsub);
X return FALSE;
X }
X while (fgets (buf, LEN, fp_unsub) != NULL) {
X fprintf (fp_out, "%s", buf);
X }
X
X fclose (fp_unsub);
X unlink (unsub);
X fclose (fp_out);
X
X if (repositioned) {
X cur_groupnum = pos;
X rename_file (newnewsrc, newsrc);
X return TRUE;
X } else {
X return FALSE;
X }
X}
SHAR_EOF
$TOUCH -am 0822182691 newsrc.c &&
chmod 0600 newsrc.c ||
echo "restore of newsrc.c failed"
set `wc -c newsrc.c`;Wc_c=$1
if test "$Wc_c" != "16290"; then
echo original size 16290, current size $Wc_c
fi
# ============= nntp.h ==============
echo "x - extracting nntp.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > nntp.h &&
X/*
X * Project : tin - a visual threaded usenet newsreader
X * Module : nntp.h
X * Author : R.Skrenta
X * Created : 01-04-91
X * Updated : 10-08-91
X * Release : 1.0
X * Notes : Changed a bit so nntp knows about Tass
X * This file is originally from the nntp 1.5 source.
X * Copyright : (c) Copyright 1991 by Rich Skrenta
X * You may freely copy or redistribute this software,
X * so long as there is no profit made from its use, sale
X * trade or reproduction. You may not change this copy-
X * right notice, and it must be included in any copy made
X */
X
X#define NNTP_SERVER_FILE "/etc/nntpserver"
X
X/*
X * External routine declarations
X */
X
Xextern char *getserverbyfile();
Xextern int server_init();
Xextern int get_tcp_socket();
Xextern int handle_server_response();
Xextern void put_server();
Xextern int get_server();
Xextern void close_server();
X
X/*
X * External file descriptors for the server connection
X */
X
Xextern FILE *ser_wr_fp;
Xextern FILE *ser_wr_fp;
X
X
X/*
X * Response codes for NNTP server
X *
X * @(#)nntp.h 1.7 (Berkeley) 1/11/88
X *
X * First digit:
X *
X * 1xx Informative message
X * 2xx Command ok
X * 3xx Command ok so far, continue
X * 4xx Command was correct, but couldn't be performed
X * for some specified reason.
X * 5xx Command unimplemented, incorrect, or a
X * program error has occured.
X *
X * Second digit:
X *
X * x0x Connection, setup, miscellaneous
X * x1x Newsgroup selection
X * x2x Article selection
X * x3x Distribution
X * x4x Posting
X */
X
X#define CHAR_INF '1'
X#define CHAR_OK '2'
X#define CHAR_CONT '3'
X#define CHAR_ERR '4'
X#define CHAR_FATAL '5'
X
X#define INF_HELP 100 /* Help text on way */
X#define INF_DEBUG 199 /* Debug output */
X
X#define OK_CANPOST 200 /* Hello; you can post */
X#define OK_NOPOST 201 /* Hello; you can't post */
X#define OK_SLAVE 202 /* Slave status noted */
X#define OK_GOODBYE 205 /* Closing connection */
X#define OK_GROUP 211 /* Group selected */
X#define OK_GROUPS 215 /* Newsgroups follow */
X
X#define OK_TASSINDEX 218 /* Tass index follows */
X
X#define OK_ARTICLE 220 /* Article (head & body) follows */
X#define OK_HEAD 221 /* Head follows */
X#define OK_BODY 222 /* Body follows */
X#define OK_NOTEXT 223 /* No text sent -- stat, next, last */
X#define OK_NEWNEWS 230 /* New articles by message-id follow */
X#define OK_NEWGROUPS 231 /* New newsgroups follow */
X#define OK_XFERED 235 /* Article transferred successfully */
X#define OK_POSTED 240 /* Article posted successfully */
X
X#define CONT_XFER 335 /* Continue to send article */
X#define CONT_POST 340 /* Continue to post article */
X
X#define ERR_GOODBYE 400 /* Have to hang up for some reason */
X#define ERR_NOGROUP 411 /* No such newsgroup */
X#define ERR_NCING 412 /* Not currently in newsgroup */
X
X#define ERR_NOTASS 418 /* No tin index for this group */
X
X#define ERR_NOCRNT 420 /* No current article selected */
X#define ERR_NONEXT 421 /* No next article in this group */
X#define ERR_NOPREV 422 /* No previous article in this group */
X#define ERR_NOARTIG 423 /* No such article in this group */
X#define ERR_NOART 430 /* No such article at all */
X#define ERR_GOTIT 435 /* Already got that article, don't send */
X#define ERR_XFERFAIL 436 /* Transfer failed */
X#define ERR_XFERRJCT 437 /* Article rejected, don't resend */
X#define ERR_NOPOST 440 /* Posting not allowed */
X#define ERR_POSTFAIL 441 /* Posting failed */
X
X#define ERR_COMMAND 500 /* Command not recognized */
X#define ERR_CMDSYN 501 /* Command syntax error */
X#define ERR_ACCESS 502 /* Access to server denied */
X#define ERR_FAULT 503 /* Program fault, command not performed */
X
X/* RFC 977 defines this; don't change it. */
X
X#define NNTP_STRLEN 512
SHAR_EOF
$TOUCH -am 0819090591 nntp.h &&
chmod 0600 nntp.h ||
echo "restore of nntp.h failed"
set `wc -c nntp.h`;Wc_c=$1
if test "$Wc_c" != "3688"; then
echo original size 3688, current size $Wc_c
fi
# ============= open.c ==============
echo "x - extracting open.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > open.c &&
X/*
X * Project : tin - a visual threaded usenet newsreader
X * Module : open.c
X * Author : R.Skrenta / I.Lea
X * Created : 01-04-91
X * Updated : 19-08-91
X * Release : 1.0
X * Notes : reads news locally (/usr/spool/news) or via NNTP
X * Copyright : (c) Copyright 1991 by Rich Skrenta & Iain Lea
X * You may freely copy or redistribute this software,
X * so long as there is no profit made from its use, sale
X * trade or reproduction. You may not change this copy-
X * right notice, and it must be included in any copy made
X */
X
X#include "tin.h"
X#ifdef USE_NNTP
X#include "nntp.h"
X#endif
X
X/* Hopefully one of these is right for you. */
X
X#ifdef BSD
X# include <sys/types.h>
X# include <sys/dir.h>
X# define DIR_BUF struct direct
X# define D_LENGTH d_namlen
X#endif
X#ifdef M_XENIX
X# include <sys/ndir.h>
X# define DIR_BUF struct direct
X# define D_LENGTH d_namlen
X#endif
X#ifndef DIR_BUF
X# include <sys/types.h>
X# include <dirent.h>
X# define DIR_BUF struct dirent
X# define D_LENGTH d_reclen
X#endif
X
X
Xchar server_name[LEN+1];
X
Xchar *is_remote ()
X{
X server_name[0] = '\0';
X
X#ifdef USE_NNTP
X if (read_news_via_nntp) {
X if (nntp_server[0]) {
X sprintf (server_name, " (%s)", nntp_server);
X } else {
X if (getserverbyfile (NNTP_SERVER_FILE)) {
X sprintf (server_name, " (%s)", getserverbyfile (NNTP_SERVER_FILE));
X } else {
X strcpy (server_name, " (NO SERVER)");
X }
X }
X }
X#endif
X
X return (server_name);
X}
X
X
Xvoid nntp_startup()
X{
X#ifdef USE_NNTP
X char *server_name;
X int ret;
X extern char *getenv();
X
X if (read_news_via_nntp) {
X if (nntp_server[0]) {
X strcpy (server_name, nntp_server);
X } else {
X server_name = getserverbyfile (NNTP_SERVER_FILE);
X }
X if (server_name == NULL) {
X fprintf(stderr, txt_cannot_get_nntp_server_name);
X fprintf(stderr, txt_server_name_in_file_env_var, NNTP_SERVER_FILE);
X exit(1);
X }
X
X ret = server_init (server_name);
X/*
X handle_server_response (ret, server_name);
X*/
X switch (ret) {
X case OK_CANPOST:
X case OK_NOPOST:
X break;
X
X case -1:
X fprintf (stderr, txt_failed_to_connect_to_server, server_name);
X exit (1);
X
X default:
X fprintf (stderr, txt_rejected_by_nntpserver, ret);
X exit (1);
X }
X }
X#endif
X}
X
Xvoid nntp_finish()
X{
X#ifdef USE_NNTP
X if (read_news_via_nntp) {
X close_server();
X }
X#endif
X}
X
X
XFILE *open_active_fp()
X{
X FILE *fp;
X
X if (read_news_via_nntp) {
X#ifdef USE_NNTP
X put_server("list");
X if (get_respcode() != OK_GROUPS) {
X return NULL;
X }
X return nntp_to_fp();
X#endif
X } else {
X if ((fp = fopen(active_file, "r")) == NULL) {
X fprintf(stderr, txt_cannot_open, active_file);
X perror("");
X exit(1);
X }
X return fp;
X }
X}
X
X
XFILE *open_art_fp(group_path, art)
X char *group_path;
X long art;
X{
X char buf[LEN+1];
X struct stat sb;
X extern long note_size;
X
X if (read_news_via_nntp) {
X#ifdef USE_NNTP
X sprintf(buf, "article %ld", art);
X
X put_server(buf);
X if (get_respcode() != OK_ARTICLE) {
X return NULL;
X }
X
X return nntp_to_fp();
X#endif
X } else {
X sprintf(buf, "%s/%s/%ld", SPOOLDIR, group_path, art);
X
X if (stat(buf, &sb) < 0) {
X note_size = 0;
X } else {
X note_size = sb.st_size;
X }
X
X return fopen(buf, "r");
X }
X}
X
X
Xint open_header_fd (group_path, art)
X char *group_path;
X long art;
X{
X char buf[LEN+1];
X
X if (read_news_via_nntp) {
X#ifdef USE_NNTP
X sprintf(buf, "head %ld", art);
X
X put_server (buf);
X if (get_respcode () != OK_HEAD) {
X return -1;
X }
X
X return nntp_to_fd ();
X#endif
X } else {
X sprintf(buf, "%s/%s/%ld", SPOOLDIR, group_path, art);
X return open(buf, 0);
X }
X}
X
X/*
X * Longword comparison routine for the qsort()
X */
X
Xint base_comp (a, b)
X long *a;
X long *b;
X{
X
X if (*a < *b)
X return -1;
X if (*a > *b)
X return 1;
X return 0;
X}
X
X
X/*
X * Read the article numbers existing in a group's spool directory
X * into base[] and sort them. base_top is one past top.
X */
X
Xvoid setup_base (group, group_path)
X char *group;
X char *group_path;
X{
X char buf[LEN+1];
X#ifdef USE_NNTP
X char line[NNTP_STRLEN];
X#endif
X DIR *d;
X DIR_BUF *e;
X long art, start, last, dummy, count;
X
X top_base = 0;
X
X if (read_news_via_nntp) {
X#ifdef USE_NNTP
X sprintf (buf, "group %s", group);
X put_server (buf);
X
X if (get_server(line, NNTP_STRLEN) == -1) {
X fprintf(stderr, txt_connection_to_server_broken);
X tin_done(1);
X }
X
X if (atoi(line) != OK_GROUP) {
X return;
X }
X
X sscanf (line,"%ld %ld %ld %ld", &dummy, &count, &start, &last);
X if (last - count > start) {
X start = last - count;
X }
X
X while (start <= last) {
X if (top_base >= max_art) {
X expand_art();
X }
X base[top_base++] = start++;
X }
X#endif
X } else {
X sprintf(buf, "%s/%s", SPOOLDIR, group_path);
X
X if (access(buf, 4) != 0) {
X return;
X }
X
X d = opendir(buf);
X if (d != NULL) {
X while ((e = readdir(d)) != NULL) {
X art = my_atol (e->d_name, (int) e->D_LENGTH);
X if (art >= 0) {
X if (top_base >= max_art)
X expand_art();
X base[top_base++] = art;
X }
X }
X closedir(d);
X qsort(base, top_base, sizeof(long), base_comp);
X }
X }
X}
X
X/*
X * get_respcode
X * get a response code from the server and return it to the caller
X */
X
Xint get_respcode()
X{
X#ifdef USE_NNTP
X char line[NNTP_STRLEN];
X
X if (get_server(line, NNTP_STRLEN) == -1) {
X fprintf(stderr, txt_connection_to_server_broken);
X tin_done(1);
X }
X
X return atoi(line);
X#endif
X}
X
X
Xint stuff_nntp (fnam)
X char *fnam;
X{
X#ifdef USE_NNTP
X FILE *fp;
X char line[NNTP_STRLEN];
X extern char *mktemp();
X struct stat sb;
X extern long note_size;
X
X strcpy(fnam, "/tmp/tin_nntpXXXXXX");
X mktemp(fnam);
X
X if ((fp = fopen(fnam, "w")) == NULL) {
X error_message (txt_stuff_nntp_cannot_open, fnam);
X return FALSE;
X }
X
X while (1) {
X if (get_server(line, NNTP_STRLEN) == -1) {
X fprintf(stderr, txt_connection_to_server_broken);
X tin_done (1);
X }
X if (strcmp(line, ".") == 0)
X break; /* end of text */
X strcat(line, "\n");
X if (line[0] == '.') /* reduce leading .'s */
X fputs(&line[1], fp);
X else
X fputs(line, fp);
X }
X fclose(fp);
X
X if (stat(fnam, &sb) < 0)
X note_size = 0;
X else
X note_size = sb.st_size;
X
X return TRUE;
X#endif
X}
X
X
XFILE *nntp_to_fp()
X{
X char fnam[LEN+1];
X FILE *fp;
X
X if (!stuff_nntp(fnam))
X return NULL;
X
X fp = fopen(fnam, "r");
X if (fp == NULL) {
X fprintf(stderr, txt_nntp_to_fp_cannot_reopen, fnam);
X perror("");
X return NULL;
X }
X unlink(fnam);
X return fp;
X}
X
X
Xint nntp_to_fd ()
X{
X#ifdef USE_NNTP
X char fnam[LEN+1];
X int fd;
X
X if (!stuff_nntp(fnam))
X return NULL;
X
X fd = open(fnam, 0);
X if (fd == NULL) {
X fprintf(stderr, txt_nntp_to_fd_cannot_reopen, fnam);
X perror("");
X return -1;
X }
X unlink(fnam);
X return fd;
X#endif
X}
X
SHAR_EOF
$TOUCH -am 0819130491 open.c &&
chmod 0600 open.c ||
echo "restore of open.c failed"
set `wc -c open.c`;Wc_c=$1
if test "$Wc_c" != "6594"; then
echo original size 6594, current size $Wc_c
fi
# ============= page.c ==============
echo "x - extracting page.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > page.c &&
X/*
X * Project : tin - a visual threaded usenet newsreader
X * Module : page.c
X * Author : R.Skrenta / I.Lea
X * Created : 01-04-91
X * Updated : 19-08-91
X * Release : 1.0
X * Notes :
X * Copyright : (c) Copyright 1991 by Rich Skrenta & Iain Lea
X * You may freely copy or redistribute this software,
X * so long as there is no profit made from its use, sale
X * trade or reproduction. You may not change this copy-
X * right notice, and it must be included in any copy made
X */
X
X#include "tin.h"
X
X#define NOTE_UNAVAIL -1
X
Xextern int cur_groupnum;
X
Xchar note_h_path[LEN+1]; /* Path: */
Xchar note_h_date[LEN+1]; /* Date: */
Xchar note_h_subj[LEN+1]; /* Subject: */
Xchar note_h_from[LEN+1]; /* From: */
Xchar note_h_org[LEN+1]; /* Organization: */
Xchar note_h_newsgroups[LEN+1]; /* Newsgroups: */
Xchar note_h_messageid[LEN+1]; /* Message-ID: */
Xchar note_h_distrib[LEN+1]; /* Distribution: */
Xchar note_h_followup[LEN+1]; /* Followup-To: */
X
Xchar note_full_name[100];
Xchar note_from_addr[100];
Xchar *glob_page_group;
X
XFILE *note_fp; /* the body of the current article */
X
Xint note_line;
Xint note_page; /* what page we're on */
Xint note_end; /* we're done showing this article */
Xint rotate; /* 0=normal, 13=rot13 decode */
Xint last_resp; /* current & previous article for - command */
Xint this_resp;
Xint glob_respnum;
X
Xlong note_mark[MAX_PAGES]; /* ftells on beginnings of pages */
Xlong note_size; /* stat size in bytes of article */
X
X
X#ifdef SIGTSTP
Xvoid page_susp (sig)
X int sig;
X{
X
X Raw(FALSE);
X putchar('\n');
X signal(SIGTSTP, SIG_DFL);
X#ifdef BSD
X sigsetmask(sigblock(0) & ~(1 << (SIGTSTP -1)));
X#endif
X kill(0, SIGTSTP);
X
X signal(SIGTSTP, page_susp);
X mail_setup();
X
X if (! update) {
X Raw(TRUE);
X }
X
X#ifndef USE_CLEARSCREEN
X ClearScreen ();
X#endif
X redraw_page(glob_respnum, glob_page_group);
X}
X#endif
X
X
Xint show_page (respnum, group, group_path)
X int respnum;
X char *group;
X char *group_path;
X{
X char ch;
X int i, n;
X int kill_state = NO_KILLING;
X int old_artnum;
X int old_sort_art_type = sort_art_type;
X int old_top;
X long art;
X
Xrestart:
X
X glob_respnum = respnum;
X glob_page_group = group;
X
X#ifdef SIGTSTP
X signal(SIGTSTP, page_susp);
X#endif
X
X if (respnum != this_resp) { /* remember current & previous */
X last_resp = this_resp; /* articles for - command */
X this_resp = respnum;
X }
X
X rotate = 0; /* normal mode, not rot13 */
X art = arts[respnum].artnum;
X arts[respnum].unread = ART_READ; /* mark article as read */
X open_note(art, group_path);
X
X if (note_page == NOTE_UNAVAIL) {
X ClearScreen();
X printf(txt_art_unavailable, art);
X fflush(stdout);
X } else {
X show_note_page (respnum, group);
X }
X
X while (1) {
X ch = ReadCh();
X
X if (ch >= '0' && ch <= '9') {
X
X n = prompt_response(ch, respnum);
X if (n != -1) {
X respnum = n;
X goto restart;
X }
X
X } else switch (ch) {
X case 27:
X ch = ReadCh ();
X if (ch == '[' || ch == 'O')
X ch = ReadCh ();
X switch (ch) {
X case 'G': /* ansi PgDn */
X case 'U': /* at386 PgDn */
X goto page_down;
X
X case 'I': /* ansi PgUp */
X case 'V': /* at386 PgUp */
X goto page_up;
X
X case 'H': /* at386 Home */
X goto begin_of_article;
X
X case 'F': /* ansi End */
X case 'Y': /* at386 End */
X goto end_of_article;
X }
X break;
X
X case '!':
X shell_escape();
X redraw_page(respnum, group);
X break;
X
X case '$': /* goto end of article */
Xend_of_article:
X if (show_last_page ()) {
X show_note_page(respnum, group);
X }
X break;
X
X case '-': /* show last viewed article */
X if (last_resp < 0) {
X info_message(txt_no_last_message);
X break;
X }
X note_cleanup();
X respnum = last_resp;
X goto restart;
X
X case '|': /* pipe article into command */
X pipe_article ();
X redraw_page (respnum, group);
X break;
X
X case '/': /* search forwards in article */
X if (search_article (TRUE)) {
X show_note_page (respnum, group);
X }
X break;
X
X case ctrl('D'):
X case ' ': /* next page or response */
Xpage_down:
X if (note_page == NOTE_UNAVAIL) {
X n = next_response (respnum);
X if (n == -1) {
X return (which_base (respnum));
X }
X respnum = n;
X goto restart;
X } else if (note_end) {
X note_cleanup ();
X n = next_response (respnum);
X if (n == -1) {
X return (which_base (respnum));
X }
X respnum = n;
X goto restart;
X } else
X show_note_page (respnum, group);
X break;
X
X case '\r':
X case '\n': /* go to start of next thread */
X note_cleanup ();
X n = next_basenote (respnum);
X if (n == -1)
X return (which_base (respnum));
X
X respnum = n;
X goto restart;
X
X case '\t': /* next page or unread response */
X if (note_page == NOTE_UNAVAIL) {
X n = next_unread (next_response (respnum));
X if (n == -1)
X return (which_base (respnum));
X
X respnum = n;
X goto restart;
X
X } else if (note_end) {
X note_cleanup();
X n = next_unread(next_response(respnum));
X if (n == -1)
X return (which_base (respnum));
X
X respnum = n;
X goto restart;
X } else
X show_note_page(respnum, group);
X break;
X
X case ctrl('H'): /* show article headers */
X if (note_page == NOTE_UNAVAIL) {
X n = next_response (respnum);
X if (n == -1)
X return (which_base (respnum));
X
X respnum = n;
X goto restart;
X } else {
X note_page = 0;
X note_end = FALSE;
X fseek(note_fp, 0L, 0);
X show_note_page(respnum, group);
X }
X break;
X
X case ctrl('K'): /* kill article */
X if (kill_articles) {
X if (kill_art_menu (group, respnum)) {
X if (kill_any_articles (group)) {
X reload_index_file (group, TRUE);
X }
X }
X redraw_page(respnum, group);
X } else {
X info_message (txt_switch_on_kill_art_menu);
X }
X break;
X
X case ctrl('L'): /* redraw current page of article */
X redraw_page (respnum, group);
X break;
X
X case ctrl('R'): /* redraw beginning of article */
Xbegin_of_article:
X if (note_page == NOTE_UNAVAIL) {
X ClearScreen();
X printf(txt_art_unavailable,arts[respnum].artnum);
X fflush(stdout);
X } else {
X note_page = 0;
X note_end = FALSE;
X fseek(note_fp, note_mark[0], 0);
X show_note_page(respnum, group);
X }
X break;
X
X case ctrl('X'):
X case '%':
X case 'd': /* toggle rot-13 mode */
X if (rotate)
X rotate = 0;
X else
X rotate = 13;
X redraw_page (respnum, group);
X break;
X
X case 'a': /* author search forward */
X case 'A': /* author search backward */
X i = (ch == 'a');
X n = search_author (respnum, i);
X if (n < 0)
X break;
X respnum = n;
X goto restart;
X break;
X
X case ctrl('U'):
X case 'b': /* back a page */
Xpage_up:
X if (note_page == NOTE_UNAVAIL) {
X note_cleanup();
X n = prev_response(respnum);
X if (n == -1)
X return( which_resp(respnum) );
X
X respnum = n;
X goto restart;
X
X } else {
X if (note_page <= 1) {
X info_message (txt_begin_of_art);
X } else {
X note_page -= 2;
X note_end = FALSE;
X fseek(note_fp, note_mark[note_page], 0);
X show_note_page(respnum, group);
X }
X }
X break;
X
X case 'B': /* bug/gripe/comment mailed to author */
X mail_bug_report ();
X redraw_page (respnum, group);
X break;
X
X case 'c': /* catchup--mark all articles as read */
X if (prompt_yn (LINES, txt_mark_all_read, 'y')) {
X for (n = 0; n < top; n++) {
X arts[n].unread = ART_READ;
X }
X fix_new_highest(cur_groupnum);
X if (cur_groupnum + 1 < local_top) {
X cur_groupnum++;
X }
X note_cleanup();
X return -1;
X }
X break;
X
X case 'f': /* post a followup to this article */
X if (post_response (group, FALSE)) {
X update_newsrc (group, my_group[cur_groupnum]);
X n = which_base (respnum);
X note_cleanup ();
X index_group (group, group_path);
X read_newsrc_line (group);
X respnum = choose_resp (n, nresp(n));
X goto restart;
X } else
X redraw_page (respnum, group);
X break;
X
X case 'F': /* post a followup to this article */
X if (post_response (group, TRUE)) {
X update_newsrc (group, my_group[cur_groupnum]);
X n = which_base (respnum);
X note_cleanup ();
X index_group (group, group_path);
X read_newsrc_line (group);
X respnum = choose_resp (n, nresp(n));
X goto restart;
X } else
X redraw_page (respnum, group);
X break;
X
X case 'h': /* help overview */
X help_page_commands ();
X redraw_page (respnum, group);
X break;
X
X case 'H': /* help in-depth */
X help_page_info ();
X redraw_page(respnum, group);
X break;
X
X case 'i': /* return to index page */
Xreturn_to_index:
X note_cleanup ();
X if (kill_state == NO_KILLING &&
X sort_art_type != old_sort_art_type) {
X make_threads (TRUE);
X find_base ();
X }
X if (kill_state == KILLING) {
X old_top = top;
X old_artnum = arts[respnum].artnum;
X if (kill_articles) {
X kill_any_articles (group);
X reload_index_file (group, TRUE); /* kill arts */
X } else {
X reload_index_file (group, FALSE); /* unkill arts */
X }
X return find_new_pos (old_top, old_artnum, respnum);
X }
X return (which_base (respnum));
X
X case 'I': /* toggle inverse video */
X inverse_okay = !inverse_okay;
X if (inverse_okay)
X info_message(txt_inverse_on);
X else
X info_message(txt_inverse_off);
X redraw_page (respnum, group);
X break;
X
X case 'k':
X if (note_page == NOTE_UNAVAIL) {
X n = next_unread(next_response(respnum));
X if (n == -1)
X return (which_base (respnum));
X
X respnum = n;
X goto restart;
X
X } else {
X note_cleanup();
X n = next_unread(next_response(respnum));
X if (n == -1)
X return (which_base (respnum));
X
X respnum = n;
X goto restart;
X }
X break;
X
X case 'K': /* mark rest of thread as read */
X for (n = respnum; n >= 0; n = arts[n].thread)
X arts[n].unread = ART_READ;
X n = next_unread(next_response(respnum));
X if (n == -1)
X goto return_to_index;
X else {
X note_cleanup();
X respnum = n;
X goto restart;
X }
X break;
X
X case 'm': /* mail article to somebody */
X mail_to_someone ();
X redraw_page (respnum, group);
X break;
X
X case 'M': /* options menu */
X if (change_rcfile (group, FALSE) == KILLING) {
X kill_state = KILLING;
X }
X redraw_page (respnum, group);
X break;
X
X case 'n': /* skip to next article */
X note_cleanup ();
X n = next_response (respnum);
X if (n == -1)
X return (which_base(respnum));
X
X respnum = n;
X goto restart;
X
X case 'N': /* next unread article */
X n = next_unread(next_response(respnum));
X if (n == -1)
X info_message(txt_no_next_unread_art);
X else {
X note_cleanup();
X respnum = n;
X goto restart;
X }
X break;
X
X case 'o': /* output article to printer */
X if (prompt_yn (LINES, txt_print_art_yn, 'y')) {
X print_article ();
X }
X break;
X
X case 'O': /* output thread to printer */
X if (prompt_yn (LINES, txt_print_thread_yn, 'y')) {
X print_thread (respnum, group_path);
X }
X break;
X
X case 'p': /* previous article */
X note_cleanup ();
X n = prev_response (respnum);
X if (n == -1)
X return (which_resp (respnum));
X
X respnum = n;
X goto restart;
X
X case 'P': /* previous unread article */
X n = prev_unread(prev_response(respnum));
X if (n == -1)
X info_message(txt_no_prev_unread_art);
X else {
X note_cleanup();
X respnum = n;
X goto restart;
X }
X break;
X
X case 'q': /* quit */
X if (prompt_yn (LINES, txt_quit, 'y')) {
X return -2;
X }
X break;
X
X case 'r': /* reply to author through mail */
X mail_to_author (FALSE);
X redraw_page (respnum, group);
X break;
X
X case 'R': /* reply to author, copy text */
X mail_to_author (TRUE);
X redraw_page (respnum, group);
X break;
X
X case 's':
X save_art_to_file (respnum, 0, FALSE, NULL);
X if (post_process_files ()) {
X redraw_page (respnum, group);
X }
X free_save_array ();
X break;
X
X case 'S':
X save_thread_to_file (respnum, group_path);
X if (post_process_files ()) {
X redraw_page (respnum, group);
X }
X break;
X
X case 't': /* return to group selection page */
X note_cleanup();
X if (kill_state == KILLING) {
X if (kill_articles) {
X kill_any_articles (group);
X reload_index_file (group, TRUE); /* kill arts */
X } else {
X reload_index_file (group, FALSE); /* unkill arts */
X }
X }
X update_newsrc (group, my_group[cur_groupnum]);
X fix_new_highest (cur_groupnum);
X return -1;
X
X case 'v':
X info_message (cvers);
X break;
X
X case 'w': /* post a basenote */
X post_base (group);
X update_newsrc (group, my_group[cur_groupnum]);
X index_group (group, group_path);
X read_newsrc_line (group);
X redraw_page (respnum, group);
X break;
X
X case 'W': /* display messages posted by user */
X if (user_posted_messages ()) {
X redraw_page(respnum, group);
X }
X break;
X
X case 'z': /* mark article as unread (to return) */
SHAR_EOF
echo "End of tin part 4"
echo "File page.c is continued in part 5"
echo "5" > shar3_seq_.tmp
exit 0
--
NAME Iain Lea
EMAIL norisc!iain@estevax.UUCP ...!unido!estevax!norisc!iain
SNAIL Siemens AG, AUT 922C, Postfach 4848, Nuernberg, Germany
PHONE +49-911-895-3853, +49-911-895-3877, +49-911-331963