home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
tass.lzh
/
select.c
< prev
next >
Wrap
Text File
|
1993-01-24
|
22KB
|
633 lines
#include <stdio.h>
#include <signal.h>
#ifdef REGEXP
#include <regexp.h>
#endif /* REGEXP */
#include "tass.h"
int first_group_on_screen;
int last_group_on_screen;
int cur_groupnum = 0;
extern int index_point;
int space_mode;
extern char *cvers;
char group_search_string[LEN+1];
#ifdef SIGTSTP
void
select_susp(i)
int i;
{
Raw(FALSE);
putchar('\n');
signal(SIGTSTP, SIG_DFL);
kill(0, SIGTSTP);
signal(SIGTSTP, select_susp);
Raw(TRUE);
mail_setup();
group_selection_page(-1, FALSE);
}
#endif
selection_index()
{
char ch;
int n;
int i;
char buf[200];
group_selection_page(-1, FALSE); /* display group selection page */
while (1) {
if ((n = ReadCh()) == EOF)
longjmp (jmp_buffer, 1);
ch = (char) n;
if (ch > '0' && ch <= '9') {
prompt_group_num(ch);
} else switch (ch) {
case 'c': /* catchup--mark all articles as read */
if (prompt_yn("Mark group as read? (y/n): ")) {
unread[cur_groupnum] = 0;
mark_group_read(
active[my_group[cur_groupnum]].name,
my_group[cur_groupnum]);
group_selection_page(cur_groupnum, TRUE);
}
break;
case ctrl('K'):
if (local_top <= 0) {
info_message("No groups to delete");
break;
}
delete_group(
active[my_group[cur_groupnum]].name);
active[my_group[cur_groupnum]].flag = NOTGOT;
local_top--;
for (i = cur_groupnum; i < local_top; i++) {
my_group[i] = my_group[i+1];
unread[i] = unread[i+1];
}
if (cur_groupnum >= local_top)
cur_groupnum = local_top - 1;
group_selection_page(cur_groupnum, FALSE);
break;
case ctrl('Y'):
undel_group();
group_selection_page(cur_groupnum, FALSE);
break;
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 ctrl('R'): /* reset .newsrc */
if (prompt_yn("Reset newsrc? (y/n): ")) {
reset_newsrc();
cur_groupnum = 0;
group_selection_page(-1, FALSE);
}
break;
case '$': /* reread .newsrc, no unsub groups */
cur_groupnum = 0;
local_top = 0;
for (i = 0; i < num_active; i++)
active[i].flag = NOTGOT;
read_newsrc(TRUE);
group_selection_page(-1, FALSE);
break;
case 's': /* subscribe to current group */
MoveCursor(INDEX_TOP +
(cur_groupnum-first_group_on_screen), 3);
putchar(' ');
fflush(stdout);
MoveCursor(LINES, 0);
subscribe(active[my_group[cur_groupnum]].name,
':', my_group[cur_groupnum], FALSE);
sprintf(buf, "subscribed to %s",
active[my_group[cur_groupnum]].name);
info_message(buf);
break;
case 'u': /* unsubscribe to current group */
MoveCursor(INDEX_TOP +
(cur_groupnum-first_group_on_screen), 3);
putchar('u');
fflush(stdout);
MoveCursor(LINES, 0);
subscribe(active[my_group[cur_groupnum]].name,
'!', my_group[cur_groupnum], FALSE);
sprintf(buf, "unsubscribed to %s",
active[my_group[cur_groupnum]].name);
info_message(buf);
break;
case ' ':
clear_message();
break;
case '\t':
for (i = cur_groupnum; i < local_top; i++)
if (unread[i] != 0)
break;
if (i >= local_top) {
info_message("No more groups to read");
break;
}
erase_group_arrow();
cur_groupnum = i;
if (cur_groupnum >= last_group_on_screen)
group_selection_page(-1, FALSE);
else
draw_group_arrow();
space_mode = TRUE;
goto go_into_group;
case 'g': /* prompt for a new group name */
n = choose_new_group();
if (n >= 0) {
erase_group_arrow();
cur_groupnum = n;
if (cur_groupnum < first_group_on_screen
|| cur_groupnum >= last_group_on_screen)
group_selection_page(-1, FALSE);
else
draw_group_arrow();
}
break;
#ifdef USE_ARROW
case 27: /* (ESC) common arrow keys */
ch = ReadCh();
if (ch == '[' || ch == 'O')
ch = ReadCh();
switch (ch) {
case 'A':
case 'D':
case 'i':
goto select_up;
case 'B':
case 'I':
case 'C':
goto select_down;
}
break;
#endif /* USE_ARROW */
case 'y': /* pull in rest of groups from active */
n = local_top;
for (i = 0; i < num_active; i++)
active[i].flag = NOTGOT;
read_newsrc(FALSE);
for (i = 0; i < num_active; i++)
if (active[i].flag & NOTGOT) {
active[i].flag &= ~NOTGOT;
my_group[local_top] = i;
unread[local_top] = -1;
local_top++;
}
if (n < local_top) {
sprintf(buf, "Added %d group%s",
local_top - n,
local_top - n == 1 ? "" : "s");
group_selection_page(-1, FALSE);
info_message(buf);
} else
info_message("No more groups to yank in");
break;
case ctrl('U'): /* page up */
case ctrl('Z'): /* full page up */
erase_group_arrow();
cur_groupnum -= (ch == ctrl('Z')) ?
NOTESLINES :
NOTESLINES / 2;
if (cur_groupnum < 0)
cur_groupnum = 0;
if (cur_groupnum < first_group_on_screen
|| cur_groupnum >= last_group_on_screen)
group_selection_page(-1, FALSE);
else
draw_group_arrow();
break;
case ctrl('D'): /* page down */
case ctrl('V'): /* full page down */
erase_group_arrow();
cur_groupnum += (ch == ctrl ('V')) ?
NOTESLINES :
NOTESLINES / 2;
if (cur_groupnum >= local_top)
cur_groupnum = local_top - 1;
if (cur_groupnum <= first_group_on_screen
|| cur_groupnum >= last_group_on_screen)
group_selection_page(-1, FALSE);
else
draw_group_arrow();
break;
case '!':
shell_escape();
group_selection_page(-1, FALSE);
break;
case 'v':
info_message(cvers);
break;
case ctrl('N'): /* line down */
case 'j':
#ifdef USE_ARROW
select_down:
#endif /* USE_ARROW */
if (cur_groupnum + 1 >= local_top)
break;
if (cur_groupnum + 1 >= last_group_on_screen) {
cur_groupnum++;
group_selection_page(-1, FALSE);
} else {
erase_group_arrow();
cur_groupnum++;
draw_group_arrow();
}
break;
case ctrl('P'): /* line up */
case 'k':
#ifdef USE_ARROW
select_up:
#endif /* USE_ARROW */
if (!cur_groupnum)
break;
if (cur_groupnum <= first_group_on_screen) {
cur_groupnum--;
group_selection_page(-1, FALSE);
} else {
erase_group_arrow();
cur_groupnum--;
draw_group_arrow();
}
break;
case 't': /* redraw */
case ctrl('W'):
case ctrl('L'):
group_selection_page(-1, FALSE);
break;
#ifndef OSK
case '\r': /* go into group */
#else /* OSK */
case '\l': /* go into group */
#endif /* OSK */
case '\n':
case ctrl('F'): /* cursor key */
space_mode = FALSE;
go_into_group:
clear_message();
index_point = -1;
do {
group_page(
active[my_group[cur_groupnum]].name);
} while (index_point == -3);
group_selection_page(-1, FALSE);
break;
case '/': /* search forward */
search_group(TRUE);
break;
case '?': /* search backward */
search_group(FALSE);
break;
case 'q': /* quit */
case ctrl('B'): /* cursor key */
tass_done(0);
case 'h':
tass_select_help();
group_selection_page(-1, FALSE);
break;
default:
info_message("Bad command. Type 'h' for help.");
}
}
}
group_selection_page(ind, justone)
int ind;
int justone;
{
int i;
int n;
char new[10];
char subs;
#ifdef SIGTSTP
signal(SIGTSTP, select_susp);
#endif
if (ind < 0) {
ClearScreen();
printf("%s\r\012", nice_time()); /* print time in upper left */
}
show_mail ();
if (ind < 0)
center_line(1, "Group Selection");
MoveCursor(INDEX_TOP, 0);
first_group_on_screen = (cur_groupnum / NOTESLINES) * NOTESLINES;
last_group_on_screen = first_group_on_screen + NOTESLINES;
if (last_group_on_screen >= local_top)
last_group_on_screen = local_top;
for (i = first_group_on_screen; i < last_group_on_screen; i++) {
if ((ind >= 0) && (ind > i))
continue;
switch (unread[i]) {
case -2:
strcpy(new, "? ");
break;
case -1:
strcpy(new, "- ");
break;
case 0:
strcpy(new, " ");
break;
default:
sprintf(new, "%-4d", unread[i]);
}
n = my_group[i];
if (active[n].flag & SUBS) /* subscribed? */
subs = ' ';
else
subs = 'u'; /* u next to unsubscribed groups */
MoveCursor (INDEX_TOP + i - first_group_on_screen, 3);
printf("%c %4d", subs, i+1);
if (!justone)
printf (" %s", active[n].name);
MoveCursor (INDEX_TOP + i - first_group_on_screen, COLS - 8);
printf (" %s", new);
CleartoEOLN ();
if ((ind >= 0) && justone && (ind == i))
break;
}
if (last_group_on_screen < first_group_on_screen + NOTESLINES) {
MoveCursor (INDEX_TOP + last_group_on_screen + 1 - first_group_on_screen, 0);
CleartoEOLN ();
}
draw_group_arrow();
}
prompt_group_num(ch)
char ch;
{
int num;
clear_message();
if ((num = parse_num(ch, "Select group> ")) == -1) {
clear_message();
return FALSE;
}
num--; /* index from 0 (internal) vs. 1 (user) */
if (num >= local_top)
num = local_top - 1;
if (num >= first_group_on_screen
&& num < last_group_on_screen) {
erase_group_arrow();
cur_groupnum = num;
draw_group_arrow();
} else {
cur_groupnum = num;
group_selection_page(-1, FALSE);
}
return TRUE;
}
erase_group_arrow() {
erase_arrow(INDEX_TOP + (cur_groupnum-first_group_on_screen) );
}
draw_group_arrow() {
draw_arrow(INDEX_TOP + (cur_groupnum-first_group_on_screen) );
}
void
search_group(forward)
int forward;
{
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(group_search_string, buf);
else if (!strlen(group_search_string)) {
info_message("No search pattern");
return;
}
i = cur_groupnum;
glob_name(group_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 >= local_top)
i = 0;
if (i < 0)
i = local_top - 1;
#ifndef REGEXP
if (regex(re, active[my_group[i]].name) != NULL) {
#else /* REGEXP */
if (regexec (re, active[my_group[i]].name)) {
#endif /* REGEXP */
if (i >= first_group_on_screen
&& i < last_group_on_screen) {
erase_group_arrow();
cur_groupnum = i;
draw_group_arrow();
} else {
cur_groupnum = i;
group_selection_page(-1, FALSE);
}
return;
}
} while (i != cur_groupnum);
info_message("No match");
}
tass_select_help() {
ClearScreen();
center_line(0, TASS_HEADER);
center_line(1, "Group Selection Commands");
MoveCursor(3, 0);
printf("4 Select group 4\r\012");
printf("^D, ^V half / full Page down\r\012");
printf("^R Reset .newsrc\r\012");
printf("^U, ^Z half / full Page up\r\012");
printf("^K Delete group\r\012");
printf("^Y Undelete group\r\012");
printf("<CR> Read current group\r\012");
printf("<TAB> View next unread group\r\012");
printf("c Mark group as all 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("q Quit\r\012");
printf("s Subscribe to current group\r\012");
printf("u Unsubscribe to current group\r\012");
printf("y Yank in groups that are not in the .newsrc\r\012");
printf("$ Reread group list from .newsrc\r\012");
printf("/ Search forward for group\r\012");
printf("? Search backward for group\r\012");
center_line(LINES, "-- hit any key --");
ReadCh();
}
choose_new_group() {
char buf[LEN+1];
char *p;
int ret;
if (!parse_string("Newsgroup> ", buf))
return -1;
for (p = buf; *p && (*p == ' ' || *p == '\t'); p++) ;
if (*p == '\0')
return -1;
ret = add_group(p, TRUE);
if (ret < 0)
info_message("Group not found in active file");
return ret;
}
/*
* Add a group to the selection list (my_group[])
* Return the index of my_group[] if group is added or was already
* there. Return -1 if named group is not in active[].
*/
add_group(s, get_unread)
char *s;
int get_unread; /* look in .newsrc for sequencer unread info? */
{
long h;
int i, j;
{ /* find the hash of the group name */
char *t = s;
h = *t++;
while (*t)
h = (h * 64 + *t++) % TABLE_SIZE;
}
for (i = group_hash[h]; i >= 0; i = active[i].next)
if (strcmp(s, active[i].name) == 0) {
for (j = 0; j < local_top; j++)
if (my_group[j] == i)
return j;
active[i].flag &= ~NOTGOT; /* mark that we got it */
my_group[local_top] = i;
if (get_unread)
unread[local_top] = get_line_unread(s, i);
else
unread[local_top] = -2;
local_top++;
return local_top - 1;
}
return -1;
}