home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume30
/
tin
/
part14
/
prompt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-20
|
4KB
|
218 lines
/*
* Project : tin - a threaded Netnews reader
* Module : prompt.c
* Author : I.Lea
* Created : 01-04-91
* Updated : 12-04-92
* Notes :
* Copyright : (c) Copyright 1991-92 by Iain Lea
* You may freely copy or redistribute this software,
* so long as there is no profit made from its use, sale
* trade or reproduction. You may not change this copy-
* right notice, and it must be included in any copy made
*/
#include "tin.h"
/*
* prompt_num
* get a number from the user
* Return -1 if missing or bad number typed
*/
int prompt_num (ch, prompt)
char ch;
char *prompt;
{
char *p;
int num;
int time_remaining;
#ifndef NO_RESYNC_ACTIVE_FILE
time_remaining = alarm (0);
#endif
clear_message ();
sprintf (msg, "%c", ch);
if ((p = getline (prompt, TRUE, msg)) != (char *) 0) {
strcpy (msg, p);
num = atoi (msg);
} else {
num = -1;
}
clear_message ();
#ifndef NO_RESYNC_ACTIVE_FILE
alarm (time_remaining);
#endif
return (num);
}
/*
* prompt_string
* get a string from the user
* Return TRUE if a valid string was typed, FALSE otherwise
*/
int prompt_string (prompt, buf)
char *prompt;
char *buf;
{
char *p;
int time_remaining;
#ifndef NO_RESYNC_ACTIVE_FILE
time_remaining = alarm (0);
#endif
clear_message ();
if ((p = getline (prompt, FALSE, (char *) 0)) == (char *) 0) {
buf[0] = '\0';
clear_message ();
#ifndef NO_RESYNC_ACTIVE_FILE
alarm (time_remaining);
#endif
return FALSE;
}
strcpy (buf, p);
clear_message ();
#ifndef NO_RESYNC_ACTIVE_FILE
alarm (time_remaining);
#endif
return TRUE;
}
/*
* prompt_menu_string
* get a string from the user
* Return TRUE if a valid string was typed, FALSE otherwise
*/
int prompt_menu_string (line, col, var)
int line;
int col;
char *var;
{
char *p;
int time_remaining;
#ifndef NO_RESYNC_ACTIVE_FILE
time_remaining = alarm (0);
#endif
MoveCursor (line, col);
if ((p = getline ("", FALSE, var)) == (char *) 0) {
#ifndef NO_RESYNC_ACTIVE_FILE
alarm (time_remaining);
#endif
return FALSE;
}
strcpy (var, p);
#ifndef NO_RESYNC_ACTIVE_FILE
alarm (time_remaining);
#endif
return TRUE;
}
int prompt_yn (line, prompt, prompt_ch)
int line;
char *prompt;
int prompt_ch;
{
char ch;
int time_remaining;
#ifndef NO_RESYNC_ACTIVE_FILE
time_remaining = alarm (0);
#endif
MoveCursor (line, 0);
CleartoEOLN ();
printf ("%s%c", prompt, prompt_ch);
fflush (stdout);
MoveCursor (line, (int) strlen (prompt));
if ((ch = (char) ReadCh()) == CR) {
ch = prompt_ch;
}
if (line == LINES) {
clear_message();
} else {
MoveCursor (line, (int) strlen (prompt));
if (ch == ESC) {
fputc (prompt_ch, stdout);
} else {
fputc (ch, stdout);
}
fflush (stdout);
}
#ifndef NO_RESYNC_ACTIVE_FILE
alarm (time_remaining);
#endif
return (ch == 'y' ? TRUE : FALSE);
}
void prompt_on_off (row, col, var, help_text, prompt_text)
int row;
int col;
int *var;
char *help_text;
char *prompt_text;
{
int ch, var_orig;
int time_remaining;
#ifndef NO_RESYNC_ACTIVE_FILE
time_remaining = alarm (0);
#endif
var_orig = *var;
show_menu_help (help_text);
do {
MoveCursor (row, col + (int) strlen (prompt_text));
if ((ch = (char) ReadCh ()) == ' ') {
*var = !*var;
printf ("%s", (*var ? "ON " : "OFF"));
fflush (stdout);
}
} while (ch != CR && ch != ESC);
if (ch == ESC) {
*var = var_orig;
printf ("%s", (*var ? "ON " : "OFF"));
fflush (stdout);
}
#ifndef NO_RESYNC_ACTIVE_FILE
alarm (time_remaining);
#endif
}
void continue_prompt ()
{
char ch;
int time_remaining;
#ifndef NO_RESYNC_ACTIVE_FILE
time_remaining = alarm (0);
#endif
info_message (txt_hit_any_key);
ch = (char) ReadCh ();
#ifndef NO_RESYNC_ACTIVE_FILE
alarm (time_remaining);
#endif
}