home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
maint
/
part02
/
options.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-13
|
12KB
|
504 lines
/******************************************************************************
*******************************************************************************
Site: Western Michigan University Academic Computer Center
System: Directory/File System Maintenance
Program: maint
Version=01 Level=00 01/24/92 Leonard J. Peirce
Purpose: Allow the user to change the configuration options on the fly.
Arguments: See individual routine(s).
External variables: None
Maint external functions:
Defined: config_options
Called:
Files accessed: None
Return codes: See individual routine(s).
Compiling instructions: See Makefile
Linking instructions: See Makefile
Other information: (C) Copyright 1992, Leonard J. Peirce
********************************************************************************
*******************************************************************************/
/******************************************************************************/
/* */
/* # I N C L U D E F I L E S */
/* */
/******************************************************************************/
#ifdef ultrix
#include <cursesX.h>
#else
#include <curses.h>
#endif
#include "maint.h"
/******************************************************************************/
/* */
/* # D E F I N E S */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* S T R U C T U R E S , U N I O N S , T Y P E D E F S */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* E X T E R N A L D E F I N I T I O N S & D E C L A R A T I O N S */
/* */
/******************************************************************************/
extern ARG_STR arg_strings[];
int config_options();
/******************************************************************************/
/* */
/* S T A T I C D E F I N I T I O N S & D E C L A R A T I O N S */
/* */
/******************************************************************************/
/*******************************************************************************
********************************************************************************
Function: config_options
Purpose: Let the user view/change configuration options.
Global variables:
Name Examine/Modify/Use/Read/Write
---- -----------------------------
none
Return Codes:
Code Reason
---- ------
REBUILD_DIRECTORY entire directory must be reinitialized
REBUILD_SCREEN only screen layout was affected
REBUILD_WITH_FILEMARKS include filemarks for files
REBUILD_WITH_SORT sort files when rebuild is performed
NO_REBUILD don't have to rebuild anything
********************************************************************************
*******************************************************************************/
int config_options(args)
/******* FORMAL PARAMETERS *******/
register ARG_DEF *args; /* run-time arguments */
{ /*** config_options ***/
/******** LOCAL VARIABLES ********/
register short term_code; /* keystroke read in */
WINDOW *window; /* for displaying/reading options */
int rows, /* rows in option window */
columns, /* columns in option window */
curr_row, /* current screen row */
curr_col, /* current screen column */
retval; /* return code */
short i; /* loop and array index */
ARG_DEF tmp_args; /* for saving current arguments */
char buf[MAX_SCREEN_COLS+1];
static char *opt_banner[] = {
" Configuration menu",
" Use Arrow Keys to select, space to toggle option, control-D to finish"};
/* save current run-time arguments to see if anything has actually
* changed when the user is done
*/
memcpy(&tmp_args,args,sizeof(tmp_args));
/* set up the screen */
rows = LINES - SPEC_WINDOW_ROWS;
columns = COLS;
window = newwin(rows,columns,2,0);
werase(window);
keypad(window,TRUE);
curr_row = 0;
/* write the configuration options and their current values */
while(curr_row < NUM_OPT_STRINGS)
{
/* create the line first */
if(curr_row == SORT_OPT)
{
strcpy(buf,arg_strings[SORT_OPT].string);
switch(args->sort)
{
case(DATE):
strcat(buf,"date ");
break;
case(SIZE):
strcat(buf,"size ");
break;
case(FILENAME):
strcat(buf,"filename");
break;
default:
strcat(buf,"none ");
break;
}
}
else
{
strcpy(buf,arg_strings[curr_row].string);
strcat(buf,*(arg_strings[curr_row].ptr) ? "yes" : "no ");
}
mvwaddstr(window,curr_row++,1,buf);
}
/* print the instructions for changing the options */
i = rows - (sizeof(opt_banner) / sizeof(char *));
while(curr_row < i)
{
wmove(window,curr_row,0);
waddch(window,'X');
wmove(window,curr_row,0);
wclrtoeol(window);
curr_row++;
}
/* write the instructions to the screen */
i = 0;
wattron(window,A_BOLD);
while(i < (sizeof(opt_banner) / sizeof(char *)))
mvwaddstr(window,curr_row++,0,opt_banner[i++]);
curr_row = 0;
curr_col = 0;
wmove(window,curr_row,curr_col);
wrefresh(window);
/* now ask for input until the user presses ESCAPE to exit */
term_code = wgetch(window);
while(term_code != CONTROL_D)
{
switch(term_code)
{
case('G'):
case('g'):
term_code = ' ';
curr_row = GROUP_OPT;
break;
case('O'):
case('o'):
term_code = ' ';
curr_row = OWNER_OPT;
break;
case('s'):
term_code = ' ';
curr_row = SIZE_OPT;
break;
case('P'):
case('p'):
term_code = ' ';
curr_row = PROT_OPT;
break;
case('D'):
case('d'):
term_code = ' ';
curr_row = DATE_OPT;
break;
case('T'):
case('t'):
term_code = ' ';
curr_row = TEXT_OPT;
break;
case('C'):
case('c'):
term_code = ' ';
curr_row = CONFIRM_OPT;
break;
case('A'):
term_code = ' ';
curr_row = AUTO_FEED_OPT;
break;
case('a'):
term_code = ' ';
curr_row = DOT_FILES_OPT;
break;
case('f'):
term_code = ' ';
curr_row = FILEMARKS_OPT;
break;
case('S'):
term_code = ' ';
curr_row = SORT_OPT;
break;
default:
break;
}
switch(term_code)
{
case('j'):
case('J'):
case(CARRIAGE_RETURN):
case(KEY_DOWN):
case(LINEFEED):
if(curr_row < (NUM_OPT_STRINGS - 1))
wmove(window,++curr_row,curr_col);
else
{
curr_row = 0;
wmove(window,curr_row,curr_col);
}
break;
case('^'):
case('K'):
case('k'):
case(KEY_UP):
if(curr_row > 0)
wmove(window,--curr_row,curr_col);
else
{
curr_row = NUM_OPT_STRINGS - 1;
wmove(window,curr_row,curr_col);
}
break;
case(' '):
/* see where the user was when they toggled */
switch(curr_row)
{
case(SIZE_OPT):
args->size = !args->size;
strcpy(buf,arg_strings[SIZE_OPT].string);
strcat(buf,*(arg_strings[SIZE_OPT].ptr) ? "yes" : "no ");
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
case(PROT_OPT):
args->prot = !args->prot;
strcpy(buf,arg_strings[PROT_OPT].string);
strcat(buf,*(arg_strings[PROT_OPT].ptr) ? "yes" : "no ");
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
case(DATE_OPT):
args->date = !args->date;
strcpy(buf,arg_strings[DATE_OPT].string);
strcat(buf,*(arg_strings[DATE_OPT].ptr) ? "yes" : "no ");
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
case(GROUP_OPT):
args->group = !args->group;
strcpy(buf,arg_strings[GROUP_OPT].string);
strcat(buf,*(arg_strings[GROUP_OPT].ptr) ? "yes" : "no ");
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
case(OWNER_OPT):
args->owner = !args->owner;
strcpy(buf,arg_strings[OWNER_OPT].string);
strcat(buf,*(arg_strings[OWNER_OPT].ptr) ? "yes" : "no ");
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
case(CONFIRM_OPT):
args->confirm = !args->confirm;
strcpy(buf,arg_strings[CONFIRM_OPT].string);
strcat(buf,*(arg_strings[CONFIRM_OPT].ptr) ? "yes" : "no ");
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
case(AUTO_FEED_OPT):
args->auto_feed = !args->auto_feed;
strcpy(buf,arg_strings[AUTO_FEED_OPT].string);
strcat(buf,*(arg_strings[AUTO_FEED_OPT].ptr) ? "yes" : "no ");
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
case(TEXT_OPT):
args->text = !args->text;
/* set the text_startup flag so that the width of the
* of the text descriptors won't be taken into account
* when updating def_slot_wid in set_args()
*/
args->text_startup = !args->text_startup;
strcpy(buf,arg_strings[TEXT_OPT].string);
strcat(buf,*(arg_strings[TEXT_OPT].ptr) ? "yes" : "no ");
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
case(DOT_FILES_OPT):
args->dot_files = !args->dot_files;
strcpy(buf,arg_strings[DOT_FILES_OPT].string);
strcat(buf,*(arg_strings[DOT_FILES_OPT].ptr) ? "yes" : "no ");
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
case(FILEMARKS_OPT):
args->filemarks = !args->filemarks;
strcpy(buf,arg_strings[FILEMARKS_OPT].string);
strcat(buf,*(arg_strings[FILEMARKS_OPT].ptr) ? "yes" : "no ");
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
case(SORT_OPT):
args->sort = (args->sort + 1) % (NUM_SORT_OPT + 1);
strcpy(buf,arg_strings[SORT_OPT].string);
switch(args->sort)
{
case(DATE):
strcat(buf,"date ");
break;
case(TYPE):
strcat(buf,"type ");
break;
case(SIZE):
strcat(buf,"size ");
break;
case(FILENAME):
strcat(buf,"filename");
break;
default:
strcat(buf,"none ");
break;
}
mvwaddstr(window,curr_row,1,buf);
wmove(window,curr_row,0);
break;
default: /* shouldn't happen */
break;
}
break;
default:
beep();
break;
}
wrefresh(window);
term_code = wgetch(window);
}
werase(window); /* kill everything */
wrefresh(window);
delwin(window);
retval = NO_REBUILD;
if(memcmp(&tmp_args,args,sizeof(tmp_args)) != 0)
{
/* something really happened */
if(args->dot_files != tmp_args.dot_files)
retval |= REBUILD_DIRECTORY;
if(args->size != tmp_args.size ||
args->prot != tmp_args.prot ||
args->date != tmp_args.date ||
args->owner != tmp_args.owner ||
args->group != tmp_args.group ||
args->filemarks != tmp_args.filemarks ||
args->sort != tmp_args.sort ||
args->text != tmp_args.text)
retval |= REBUILD_SCREEN;
if(args->filemarks != tmp_args.filemarks)
retval |= REBUILD_WITH_FILEMARKS;
if(args->sort && !tmp_args.filemarks)
retval |= REBUILD_WITH_SORT;
}
return(retval);
} /*** config_options ***/