home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
tass.lzh
/
group.c
< prev
next >
Wrap
Text File
|
1993-01-24
|
28KB
|
825 lines
#include <stdio.h>
#include <signal.h>
#ifdef REGEXP
#include <regexp.h>
#endif /* REGEXP */
#ifdef OSK
#include <ctype.h>
#endif /* OSK */
#include "tass.h"
#ifdef GET_DIST
extern char *index ();
#endif /* GET_DIST */
int index_point;
int first_subj_on_screen;
int last_subj_on_screen;
char subject_search_string[LEN+1]; /* last search pattern */
extern int cur_groupnum;
extern int last_resp; /* page.c */
extern int this_resp; /* page.c */
extern int space_mode; /* select.c */
extern char *cvers;
char *glob_group;
#ifdef SIGTSTP
void
group_susp(i)
int i;
{
Raw(FALSE);
putchar('\n');
signal(SIGTSTP, SIG_DFL);
kill(0, SIGTSTP);
signal(SIGTSTP, group_susp);
Raw(TRUE);
mail_setup();
show_group_page(glob_group, TRUE);
}
#endif
group_page(group)
char *group;
{
char ch;
int i, n;
char group_path[200];
char *p;
char buf[200];
glob_group = group;
strcpy(group_path, group); /* turn comp.unix.amiga into */
for (p = group_path; *p; p++) /* comp/unix/amiga */
if (*p == '.')
*p = '/';
#ifdef OSK
else if ((!isalnum (*p)) || ((unsigned char) *p >= 0x80))
*p = '_';
#endif /* OSK */
last_resp = -1;
this_resp = -1;
index_group(group, group_path); /* update index file */
read_newsrc_line(group); /* get sequencer information */
if (space_mode) {
for (i = 0; i < top_base; i++)
if (new_responses(i))
break;
if (i < top_base)
index_point = i;
else
index_point = top_base - 1;
} else
index_point = top_base - 1;
show_group_page(group, TRUE);
while (1) {
if ((n = ReadCh()) == EOF)
longjmp (jmp_buffer, 1);
ch = (char) n;
if (ch > '0' && ch <= '9') { /* 0 goes to basenote */
prompt_subject_num(ch, group);
} else switch (ch) {
case 'I': /* toggle inverse video */
inverse_okay = !inverse_okay;
if (inverse_okay)
info_message("Inverse video enabled");
else
info_message("Inverse video disabled");
break;
case 's': /* subscribe to this group */
subscribe(group, ':', my_group[cur_groupnum],
TRUE);
sprintf(buf, "subscribed to %s", group);
info_message(buf);
break;
case 'u': /* unsubscribe to this group */
subscribe(group, '!', my_group[cur_groupnum],
TRUE);
sprintf(buf, "unsubscribed to %s", group);
info_message(buf);
break;
case 'g': /* choose a new group by name */
n = choose_new_group();
if (n >= 0 && n != cur_groupnum) {
fix_new_highest(cur_groupnum);
cur_groupnum = n;
index_point = -3;
goto group_done;
}
break;
case 'c': /* catchup--mark all articles as read */
if (prompt_yn("Mark everything as read? (y/n): ")) {
for (n = 0; n < top; n++)
arts[n].unread = 0;
show_group_page(group, FALSE);
info_message("All articles marked as read");
}
break;
#ifdef USE_ARROW
case 27: /* common arrow keys */
ch = ReadCh();
if (ch == '[' || ch == 'O')
ch = ReadCh();
switch (ch) {
case 'A':
case 'D':
case 'i':
goto group_up;
case 'B':
case 'I':
case 'C':
goto group_down;
}
break;
#endif /* USE_ARROW */
case 'n': /* next group */
clear_message();
if (cur_groupnum + 1 >= local_top)
info_message("No more groups");
else {
fix_new_highest(cur_groupnum);
cur_groupnum++;
index_point = -3;
space_mode = FALSE;
goto group_done;
}
break;
case 'p': /* previous group */
clear_message();
if (cur_groupnum <= 0)
info_message("No previous group");
else {
fix_new_highest(cur_groupnum);
cur_groupnum--;
index_point = -3;
space_mode = FALSE;
goto group_done;
}
break;
case ' ':
if (top_base <= 0)
info_message("*** No Articles ***");
else if (last_subj_on_screen == top_base)
info_message("*** End of Articles ***");
else
clear_message();
break;
case '\t':
fix_new_highest(cur_groupnum);
space_mode = TRUE;
if (index_point < 0
|| (n=next_unread((int) base[index_point]))<0) {
for (i = cur_groupnum+1;
i < local_top; i++)
if (unread[i] > 0)
break;
if (i >= local_top)
goto group_done;
cur_groupnum = i;
index_point = -3;
goto group_done;
}
index_point = show_page(n, group, group_path);
if (index_point < 0)
goto group_done;
show_group_page(group, TRUE);
break;
case 'N': /* go to next unread article */
if (index_point < 0) {
info_message("No next unread article");
break;
}
n = next_unread( (int) base[index_point]);
if (n == -1)
info_message("No next unread article");
else {
index_point =
show_page(n, group, group_path, TRUE);
if (index_point < 0) {
fix_new_highest(cur_groupnum);
space_mode = FALSE;
goto group_done;
}
show_group_page(group, TRUE);
}
break;
case 'P': /* go to previous unread article */
if (index_point < 0) {
info_message("No previous unread article");
break;
}
n = prev_response( (int) base[index_point]);
n = prev_unread(n);
if (n == -1)
info_message("No previous unread article");
else {
index_point =
show_page(n, group, group_path, TRUE);
if (index_point < 0) {
fix_new_highest(cur_groupnum);
space_mode = FALSE;
goto group_done;
}
show_group_page(group, TRUE);
}
break;
case 'w': /* post a basenote */
post_base(group);
update_newsrc(group, my_group[cur_groupnum]);
index_group(group, group_path);
read_newsrc_line(group);
index_point = top_base - 1;
show_group_page(group, TRUE);
break;
case 't': /* return to group selection page */
case ctrl('B'): /* cursor key */
fix_new_highest(cur_groupnum);
goto group_done;
#ifndef OSK
case '\r':
#else /* OSK */
case '\l':
#endif /* OSK */
case '\n': /* read current basenote */
case ctrl('F'): /* cursor key */
if (index_point < 0) {
info_message("*** No Articles ***");
break;
}
index_point = show_page((int) base[index_point],
group, group_path, TRUE);
if (index_point < 0) {
fix_new_highest(cur_groupnum);
space_mode = FALSE;
goto group_done;
}
show_group_page(group, TRUE);
break;
case ctrl('D'): /* page down */
case ctrl('V'): /* full page down */
if (!top_base || index_point == top_base - 1)
break;
erase_subject_arrow();
index_point += (ch == ctrl('V')) ?
NOTESLINES :
NOTESLINES / 2;
if (index_point >= top_base)
index_point = top_base - 1;
if (index_point < first_subj_on_screen
|| index_point >= last_subj_on_screen)
show_group_page(group, TRUE);
else
draw_subject_arrow();
break;
case '-': /* go to last viewed article */
if (this_resp < 0) {
info_message("No last message");
break;
}
index_point = show_page(this_resp,
group, group_path, TRUE);
if (index_point < 0) {
fix_new_highest(cur_groupnum);
space_mode = FALSE;
goto group_done;
}
show_group_page(group, TRUE);
break;
case ctrl('U'): /* page up */
case ctrl('Z'): /* full page up */
if (!top_base)
break;
erase_subject_arrow();
index_point -= (ch == ctrl('Z')) ?
NOTESLINES :
NOTESLINES / 2;
if (index_point < 0)
index_point = 0;
if (index_point < first_subj_on_screen
|| index_point >= last_subj_on_screen)
show_group_page(group, TRUE);
else
draw_subject_arrow();
break;
case 'v':
info_message(cvers);
break;
case '!':
shell_escape();
show_group_page(group, TRUE);
break;
case ctrl('N'):
case 'j': /* line down */
#ifdef USE_ARROW
group_down:
#endif /* USE_ARROW */
if (!top_base || index_point + 1 >= top_base)
break;
erase_subject_arrow();
index_point++;
if (index_point >= last_subj_on_screen)
show_group_page(group, FALSE);
else
draw_subject_arrow();
break;
case ctrl('P'):
case 'k': /* line up */
#ifdef USE_ARROW
group_up:
#endif /* USE_ARROW */
if (!top_base || !index_point)
break;
erase_subject_arrow();
index_point--;
if (index_point + 1 <= first_subj_on_screen)
show_group_page(group, FALSE);
else
draw_subject_arrow();
break;
case ctrl('R'):
case ctrl('L'):
case ctrl('W'):
case 'i': /* return to index */
show_group_page(group, FALSE);
break;
case '/': /* forward search */
search_subject(TRUE, group);
break;
case '?': /* backward search */
search_subject(FALSE, group);
break;
#ifndef OSK
case 'q': /* quit */
index_point = -2;
fix_new_highest(cur_groupnum);
space_mode = FALSE;
goto group_done;
#endif /* OSK */
case 'h':
tass_group_help();
show_group_page(group, TRUE);
break;
default:
info_message("Bad command. Type 'h' for help.");
}
}
group_done:
update_newsrc(group, my_group[cur_groupnum]);
if (index_point == -2)
tass_done(0);
}
/*
* Correct highest[] for the group selection page display since
* new articles may have been read or marked unread
*/
fix_new_highest(groupnum)
int groupnum;
{
int i;
int sum = 0;
for (i = 0; i < top; i++)
if (arts[i].unread)
sum++;
unread[groupnum] = sum;
}
show_mail () {
if (mail_check()) { /* you have mail message in */
MoveCursor(0, COLS - 14); /* upper right */
printf("you have mail");
fflush (stdout);
}
}
show_group_page(group, clr)
char *group;
int clr;
{
int i;
int n;
char resps[10];
char new_resps;
int respnum;
#ifdef SIGTSTP
signal(SIGTSTP, group_susp);
#endif
if (clr) {
ClearScreen();
printf("%s\r\012", nice_time()); /* time in upper left */
center_line(1, group);
}
show_mail ();
MoveCursor(INDEX_TOP, 0);
first_subj_on_screen = (index_point / NOTESLINES) * NOTESLINES;
if (first_subj_on_screen < 0)
first_subj_on_screen = 0;
last_subj_on_screen = first_subj_on_screen + NOTESLINES;
if (last_subj_on_screen >= top_base) {
last_subj_on_screen = top_base;
first_subj_on_screen = top_base - NOTESLINES;
if (first_subj_on_screen < 0)
first_subj_on_screen = 0;
}
for (i = first_subj_on_screen; i < last_subj_on_screen; i++) {
if (new_responses(i))
new_resps = '+';
else
new_resps = ' ';
n = nresp(i);
if (n)
sprintf(resps, "%4d", n);
else
strcpy(resps, " ");
respnum = base[i];
MoveCursor(INDEX_TOP + i - first_subj_on_screen, 3);
printf("%4d %c %s", i + 1, new_resps, arts[respnum].subject);
CleartoEOLN ();
MoveCursor(INDEX_TOP + i - first_subj_on_screen, COLS - 35);
printf ("%s %-.30s", resps, arts[respnum].from);
MoveCursor(INDEX_TOP + i - first_subj_on_screen, COLS - 1);
CleartoEOLN ();
}
if (top_base <= 0)
info_message("*** No Articles ***");
else if (last_subj_on_screen == top_base)
info_message("*** End of Articles ***");
if (top_base > 0)
draw_subject_arrow();
}
draw_subject_arrow() {
draw_arrow(INDEX_TOP + (index_point-first_subj_on_screen) );
}
erase_subject_arrow() {
erase_arrow(INDEX_TOP + (index_point-first_subj_on_screen) );
}
prompt_subject_num(ch, group)
char ch;
char *group;
{
int num;
clear_message();
if ((num = parse_num(ch, "Read article> ")) == -1) {
clear_message();
return FALSE;
}
num--; /* index from 0 (internal) vs. 1 (user) */
if (num >= top_base)
num = top_base - 1;
if (num >= first_subj_on_screen
&& num < last_subj_on_screen) {
erase_subject_arrow();
index_point = num;
draw_subject_arrow();
} else {
index_point = num;
show_group_page(group, TRUE);
}
}
void
search_subject(forward, group)
int forward;
char *group;
{
char buf[LEN+1];
int i;
#ifndef REGEXP
extern char *regcmp();
extern char *regex();
char *re;
#else /* REGEXP */
regexp *re;
#endif /* REGEXP */
char *prompt;
clear_message();
if (forward)
prompt = "/";
else
prompt = "?";
if (!parse_string(prompt, buf))
return;
if (strlen(buf))
strcpy(subject_search_string, buf);
else if (!strlen(subject_search_string)) {
info_message("No search pattern");
return;
}
i = index_point;
glob_name(subject_search_string, buf);
#ifndef REGEXP
if ((re = regcmp(buf, NULL)) == NULL) {
#else /* REGEXP */
if ((re = regcomp (buf)) == NULL) {
#endif /* REGEXP */
info_message("Bad search pattern");
return;
}
do {
if (forward)
i++;
else
i--;
if (i >= top_base)
i = 0;
if (i < 0)
i = top_base - 1;
#ifndef REGEXP
if (regex(re, arts[ base[i] ].subject) != NULL) {
#else /* REGEXP */
if (regexec (re, arts[ base[i] ].subject) != NULL) {
#endif /* REGEXP */
if (i >= first_subj_on_screen
&& i < last_subj_on_screen) {
erase_subject_arrow();
index_point = i;
draw_subject_arrow();
} else {
index_point = i;
show_group_page(group, TRUE);
}
return;
}
} while (i != index_point);
info_message("No match");
}
/*
* Post an original article (not a followup)
*/
post_base(group)
char *group;
{
FILE *fp;
char nam[100];
char ch;
char subj[LEN+1];
char buf[200];
int line;
#ifdef GET_DIST
char *ptr;
#endif /* GET_DIST */
if (!parse_string("Subject: ", subj))
return(FALSE);
if (subj[0] == '\0')
return(FALSE);
#ifdef USE_UID
setuid(real_uid);
setgid(real_gid);
#endif /* USE_UID */
sprintf(nam, "%s/.article", homedir);
umask (omask);
if ((fp = fopen(nam, "w")) == NULL) {
umask (0);
fprintf(stderr, "can't open %s: ", nam);
perror("");
return(FALSE);
}
#ifndef OSK
chmod(nam, 0600);
#else /* OSK */
chmod(nam, 013);
#endif /* OSK */
fprintf(fp, "Subject: %s\n", subj);
fprintf(fp, "Newsgroups: %s\n", group);
#ifndef GET_DIST
/* fprintf(fp, "Distribution: \n"); */
line = 2;
#else /* GET_DIST */
strcpy (buf, group);
if (ptr = index (buf, '.'))
*ptr = '\0';
fprintf(fp, "Distribution: %s\n", buf);
line = 3;
#endif /* GET_DIST */
if (*my_org) {
fprintf(fp, "Organization: %s\n", my_org);
++line;
}
fprintf(fp, "\n");
++line;
#ifdef APPEND_SIG
add_signature (fp);
#endif /* APPEND_SIG */
fclose(fp);
umask (0);
ch = 'e';
while (1) {
switch (ch) {
case 'e':
invoke_editor(nam, line);
break;
case 'a':
return FALSE;
case 'p':
printf("\rPosting... ");
CleartoEOLN ();
#ifndef OSK
sprintf(buf, "%s/inews -h < %s", LIBDIR, nam);
#else /* OSK */
sprintf(buf, "inews -h <%s", nam);
#endif /* OSK */
if (invoke_cmd(buf)) {
printf("article posted ");
fflush(stdout);
goto post_base_done;
} else {
printf("article rejected ");
fflush(stdout);
break;
}
}
do {
MoveCursor(LINES, 0);
fputs("abort, edit, post: ", stdout);
fflush(stdout);
ch = ReadCh();
} while (ch != 'a' && ch != 'e' && ch != 'p');
}
post_base_done:
#ifdef USE_UID
setuid(tass_uid);
setgid(tass_gid);
#endif /* USE_UID */
continue_prompt();
return(TRUE);
}
/*
* Return the number of unread articles there are within a thread
*/
new_responses(thread)
int thread;
{
int i;
int sum = 0;
for (i = base[thread]; i >= 0; i = arts[i].thread)
if (arts[i].unread)
sum++;
return sum;
}
void
tass_group_help() {
char ch;
group_help_start:
ClearScreen();
center_line(0, TASS_HEADER);
center_line(1, "Index Page Commands (page 1 of 2)");
MoveCursor(3, 0);
printf("4 Select article 4\r\012");
printf("^D, ^V half / full Page down\r\012");
printf("^U, ^Z half / full Page up\r\012");
printf("<CR> Read current article\r\012");
printf("<TAB> View next unread article or group\r\012");
printf("c Mark all articles as read\r\012");
printf("g Choose a new group by name\r\012");
printf("j Down a line\r\012");
printf("k Up a line\r\012");
printf("n Go to next group\r\012");
printf("N Go to next unread article\r\012");
printf("p Go to previous group\r\012");
printf("P Go to previous unread article\r\012");
printf("q Quit\r\012");
center_line(LINES, "-- hit space for more commands --");
ch = ReadCh();
if (ch != ' ')
return;
ClearScreen();
center_line(0, TASS_HEADER);
center_line(1, "Index Page Commands (page 2 of 2)");
MoveCursor(3, 0);
printf("s Subscribe to this group\r\012");
printf("t Return to group selection index\r\012");
printf("u Unsubscribe to this group\r\012");
printf("w Post an article\r\012");
printf("/ Search forward for subject\r\012");
printf("? Search backward for subject\r\012");
printf("- Show last message\r\012");
center_line(LINES, "-- hit any key --");
ch = ReadCh();
if (ch == 'b')
goto group_help_start;
}