home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume26 / maint / part02 / options.c < prev    next >
C/C++ Source or Header  |  1992-05-13  |  12KB  |  504 lines

  1. /******************************************************************************
  2. *******************************************************************************
  3.  
  4.    Site:    Western Michigan University Academic Computer Center
  5.  
  6.    System:    Directory/File System Maintenance
  7.   
  8.    Program:    maint
  9.  
  10.    Version=01    Level=00    01/24/92    Leonard J. Peirce
  11.  
  12.    Purpose:    Allow the user to change the configuration options on the fly.
  13.  
  14.    Arguments:    See individual routine(s).
  15.  
  16.    External variables:    None
  17.  
  18.    Maint external functions:
  19.  
  20.     Defined:    config_options
  21.  
  22.     Called:
  23.  
  24.    Files accessed:    None
  25.  
  26.    Return codes:    See individual routine(s).
  27.  
  28.    Compiling instructions:    See Makefile
  29.  
  30.    Linking instructions:    See Makefile
  31.  
  32.    Other information:    (C) Copyright 1992, Leonard J. Peirce
  33.  
  34. ********************************************************************************
  35. *******************************************************************************/
  36.  
  37. /******************************************************************************/
  38. /*                                                                            */
  39. /*                        # I N C L U D E   F I L E S                         */
  40. /*                                                                            */
  41. /******************************************************************************/
  42.  
  43. #ifdef ultrix
  44. #include <cursesX.h>
  45. #else
  46. #include <curses.h>
  47. #endif
  48. #include "maint.h"
  49.  
  50. /******************************************************************************/
  51. /*                                                                            */
  52. /*                             # D E F I N E S                                */
  53. /*                                                                            */
  54. /******************************************************************************/
  55.  
  56. /******************************************************************************/
  57. /*                                                                            */
  58. /*          S T R U C T U R E S ,   U N I O N S ,   T Y P E D E F S           */
  59. /*                                                                            */
  60. /******************************************************************************/
  61.  
  62. /******************************************************************************/
  63. /*                                                                            */
  64. /*   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    */
  65. /*                                                                            */
  66. /******************************************************************************/
  67.  
  68. extern     ARG_STR  arg_strings[];
  69.  
  70.      int      config_options();
  71.  
  72. /******************************************************************************/
  73. /*                                                                            */
  74. /*     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      */
  75. /*                                                                            */
  76. /******************************************************************************/
  77.  
  78. /*******************************************************************************
  79. ********************************************************************************
  80.  
  81.   Function:    config_options
  82.  
  83.   Purpose:    Let the user view/change configuration options.
  84.  
  85.   Global variables:
  86.  
  87.     Name            Examine/Modify/Use/Read/Write
  88.     ----            -----------------------------
  89.     none
  90.  
  91.   Return Codes:
  92.  
  93.     Code            Reason
  94.     ----            ------
  95.     REBUILD_DIRECTORY    entire directory must be reinitialized
  96.     REBUILD_SCREEN        only screen layout was affected
  97.     REBUILD_WITH_FILEMARKS    include filemarks for files
  98.     REBUILD_WITH_SORT    sort files when rebuild is performed
  99.     NO_REBUILD        don't have to rebuild anything
  100.  
  101. ********************************************************************************
  102. *******************************************************************************/
  103.  
  104. int config_options(args)
  105.                     /*******   FORMAL  PARAMETERS   *******/
  106. register ARG_DEF *args;            /* run-time arguments              */
  107.  
  108. {    /*** config_options ***/
  109.                     /********   LOCAL  VARIABLES   ********/
  110. register short      term_code;        /* keystroke read in              */
  111.      WINDOW      *window;        /* for displaying/reading options     */
  112.      int      rows,            /* rows in option window          */
  113.           columns,        /* columns in option window          */
  114.           curr_row,        /* current screen row              */
  115.           curr_col,        /* current screen column          */
  116.           retval;        /* return code                  */
  117.      short      i;            /* loop and array index              */
  118.      ARG_DEF  tmp_args;        /* for saving current arguments          */
  119.      char      buf[MAX_SCREEN_COLS+1];
  120. static     char      *opt_banner[] = {
  121. "                               Configuration menu",
  122. "      Use Arrow Keys to select, space to toggle option, control-D to finish"};
  123.  
  124.  
  125.    /* save current run-time arguments to see if anything has actually
  126.     * changed when the user is done
  127.     */
  128.  
  129.    memcpy(&tmp_args,args,sizeof(tmp_args));
  130.  
  131.    /* set up the screen */
  132.  
  133.    rows = LINES - SPEC_WINDOW_ROWS;
  134.    columns = COLS;
  135.    window = newwin(rows,columns,2,0);
  136.    werase(window);
  137.    keypad(window,TRUE);
  138.    curr_row = 0;
  139.  
  140.    /* write the configuration options and their current values */
  141.  
  142.    while(curr_row < NUM_OPT_STRINGS)
  143.    {
  144.       /* create the line first */
  145.  
  146.       if(curr_row == SORT_OPT)
  147.       {
  148.      strcpy(buf,arg_strings[SORT_OPT].string);
  149.  
  150.      switch(args->sort)
  151.      {
  152.         case(DATE):
  153.  
  154.            strcat(buf,"date    ");
  155.            break;
  156.  
  157.         case(SIZE):
  158.  
  159.            strcat(buf,"size    ");
  160.            break;
  161.  
  162.         case(FILENAME):
  163.  
  164.            strcat(buf,"filename");
  165.            break;
  166.  
  167.         default:
  168.  
  169.            strcat(buf,"none    ");
  170.            break;
  171.      }
  172.       }
  173.       else
  174.       {
  175.      strcpy(buf,arg_strings[curr_row].string);
  176.      strcat(buf,*(arg_strings[curr_row].ptr) ? "yes" : "no ");
  177.       }
  178.  
  179.       mvwaddstr(window,curr_row++,1,buf);
  180.    }
  181.  
  182.    /* print the instructions for changing the options */
  183.  
  184.    i = rows - (sizeof(opt_banner) / sizeof(char *));
  185.  
  186.    while(curr_row < i)
  187.    {
  188.       wmove(window,curr_row,0);
  189.       waddch(window,'X');
  190.       wmove(window,curr_row,0);
  191.       wclrtoeol(window);
  192.       curr_row++;
  193.    }
  194.  
  195.    /* write the instructions to the screen */
  196.  
  197.    i = 0;
  198.    wattron(window,A_BOLD);
  199.  
  200.    while(i < (sizeof(opt_banner) / sizeof(char *)))
  201.       mvwaddstr(window,curr_row++,0,opt_banner[i++]);
  202.  
  203.    curr_row = 0;
  204.    curr_col = 0;
  205.    wmove(window,curr_row,curr_col);
  206.    wrefresh(window);
  207.  
  208.    /* now ask for input until the user presses ESCAPE to exit */
  209.  
  210.    term_code = wgetch(window);
  211.  
  212.    while(term_code != CONTROL_D)
  213.    {
  214.       switch(term_code)
  215.       {
  216.      case('G'):
  217.      case('g'):
  218.         term_code = ' ';
  219.         curr_row = GROUP_OPT;
  220.         break;
  221.  
  222.      case('O'):
  223.      case('o'):
  224.         term_code = ' ';
  225.         curr_row = OWNER_OPT;
  226.         break;
  227.  
  228.      case('s'):
  229.         term_code = ' ';
  230.         curr_row = SIZE_OPT;
  231.         break;
  232.  
  233.      case('P'):
  234.      case('p'):
  235.         term_code = ' ';
  236.         curr_row = PROT_OPT;
  237.         break;
  238.  
  239.      case('D'):
  240.      case('d'):
  241.         term_code = ' ';
  242.         curr_row = DATE_OPT;
  243.         break;
  244.  
  245.      case('T'):
  246.      case('t'):
  247.         term_code = ' ';
  248.         curr_row = TEXT_OPT;
  249.         break;
  250.  
  251.      case('C'):
  252.      case('c'):
  253.         term_code = ' ';
  254.         curr_row = CONFIRM_OPT;
  255.         break;
  256.  
  257.      case('A'):
  258.         term_code = ' ';
  259.         curr_row = AUTO_FEED_OPT;
  260.         break;
  261.  
  262.      case('a'):
  263.         term_code = ' ';
  264.         curr_row = DOT_FILES_OPT;
  265.         break;
  266.  
  267.      case('f'):
  268.         term_code = ' ';
  269.         curr_row = FILEMARKS_OPT;
  270.         break;
  271.  
  272.      case('S'):
  273.         term_code = ' ';
  274.         curr_row = SORT_OPT;
  275.         break;
  276.  
  277.      default:
  278.         break;
  279.       }
  280.  
  281.       switch(term_code)
  282.       {
  283.      case('j'):
  284.      case('J'):
  285.      case(CARRIAGE_RETURN):
  286.      case(KEY_DOWN):
  287.      case(LINEFEED):
  288.  
  289.         if(curr_row < (NUM_OPT_STRINGS - 1))
  290.            wmove(window,++curr_row,curr_col);
  291.         else
  292.         {
  293.            curr_row = 0;
  294.            wmove(window,curr_row,curr_col);
  295.         }
  296.  
  297.         break;
  298.  
  299.      case('^'):
  300.      case('K'):
  301.      case('k'):
  302.      case(KEY_UP):
  303.  
  304.         if(curr_row > 0)
  305.            wmove(window,--curr_row,curr_col);
  306.         else
  307.         {
  308.            curr_row = NUM_OPT_STRINGS - 1;
  309.            wmove(window,curr_row,curr_col);
  310.         }
  311.  
  312.         break;
  313.  
  314.      case(' '):
  315.  
  316.         /* see where the user was when they toggled */
  317.  
  318.         switch(curr_row)
  319.         {
  320.            case(SIZE_OPT):
  321.  
  322.           args->size = !args->size;
  323.           strcpy(buf,arg_strings[SIZE_OPT].string);
  324.           strcat(buf,*(arg_strings[SIZE_OPT].ptr) ? "yes" : "no ");
  325.           mvwaddstr(window,curr_row,1,buf);
  326.           wmove(window,curr_row,0);
  327.           break;
  328.  
  329.            case(PROT_OPT):
  330.  
  331.           args->prot = !args->prot;
  332.           strcpy(buf,arg_strings[PROT_OPT].string);
  333.           strcat(buf,*(arg_strings[PROT_OPT].ptr) ? "yes" : "no ");
  334.           mvwaddstr(window,curr_row,1,buf);
  335.           wmove(window,curr_row,0);
  336.           break;
  337.  
  338.            case(DATE_OPT):
  339.  
  340.           args->date = !args->date;
  341.           strcpy(buf,arg_strings[DATE_OPT].string);
  342.           strcat(buf,*(arg_strings[DATE_OPT].ptr) ? "yes" : "no ");
  343.           mvwaddstr(window,curr_row,1,buf);
  344.           wmove(window,curr_row,0);
  345.           break;
  346.  
  347.            case(GROUP_OPT):
  348.  
  349.           args->group = !args->group;
  350.           strcpy(buf,arg_strings[GROUP_OPT].string);
  351.           strcat(buf,*(arg_strings[GROUP_OPT].ptr) ? "yes" : "no ");
  352.           mvwaddstr(window,curr_row,1,buf);
  353.           wmove(window,curr_row,0);
  354.           break;
  355.  
  356.            case(OWNER_OPT):
  357.  
  358.           args->owner = !args->owner;
  359.           strcpy(buf,arg_strings[OWNER_OPT].string);
  360.           strcat(buf,*(arg_strings[OWNER_OPT].ptr) ? "yes" : "no ");
  361.           mvwaddstr(window,curr_row,1,buf);
  362.           wmove(window,curr_row,0);
  363.           break;
  364.  
  365.            case(CONFIRM_OPT):
  366.  
  367.           args->confirm = !args->confirm;
  368.           strcpy(buf,arg_strings[CONFIRM_OPT].string);
  369.           strcat(buf,*(arg_strings[CONFIRM_OPT].ptr) ? "yes" : "no ");
  370.           mvwaddstr(window,curr_row,1,buf);
  371.           wmove(window,curr_row,0);
  372.           break;
  373.  
  374.            case(AUTO_FEED_OPT):
  375.  
  376.           args->auto_feed = !args->auto_feed;
  377.           strcpy(buf,arg_strings[AUTO_FEED_OPT].string);
  378.           strcat(buf,*(arg_strings[AUTO_FEED_OPT].ptr) ? "yes" : "no ");
  379.           mvwaddstr(window,curr_row,1,buf);
  380.           wmove(window,curr_row,0);
  381.           break;
  382.  
  383.            case(TEXT_OPT):
  384.  
  385.           args->text = !args->text;
  386.  
  387.           /* set the text_startup flag so that the width of the
  388.            * of the text descriptors won't be taken into account
  389.            * when updating def_slot_wid in set_args()
  390.            */
  391.  
  392.           args->text_startup = !args->text_startup;
  393.           strcpy(buf,arg_strings[TEXT_OPT].string);
  394.           strcat(buf,*(arg_strings[TEXT_OPT].ptr) ? "yes" : "no ");
  395.           mvwaddstr(window,curr_row,1,buf);
  396.           wmove(window,curr_row,0);
  397.           break;
  398.  
  399.            case(DOT_FILES_OPT):
  400.  
  401.           args->dot_files = !args->dot_files;
  402.           strcpy(buf,arg_strings[DOT_FILES_OPT].string);
  403.           strcat(buf,*(arg_strings[DOT_FILES_OPT].ptr) ? "yes" : "no ");
  404.           mvwaddstr(window,curr_row,1,buf);
  405.           wmove(window,curr_row,0);
  406.           break;
  407.  
  408.            case(FILEMARKS_OPT):
  409.  
  410.           args->filemarks = !args->filemarks;
  411.           strcpy(buf,arg_strings[FILEMARKS_OPT].string);
  412.           strcat(buf,*(arg_strings[FILEMARKS_OPT].ptr) ? "yes" : "no ");
  413.           mvwaddstr(window,curr_row,1,buf);
  414.           wmove(window,curr_row,0);
  415.           break;
  416.  
  417.            case(SORT_OPT):
  418.  
  419.           args->sort = (args->sort + 1) % (NUM_SORT_OPT + 1);
  420.           strcpy(buf,arg_strings[SORT_OPT].string);
  421.  
  422.           switch(args->sort)
  423.           {
  424.              case(DATE):
  425.  
  426.             strcat(buf,"date    ");
  427.             break;
  428.  
  429.              case(TYPE):
  430.  
  431.             strcat(buf,"type    ");
  432.             break;
  433.  
  434.              case(SIZE):
  435.  
  436.             strcat(buf,"size    ");
  437.             break;
  438.  
  439.              case(FILENAME):
  440.  
  441.             strcat(buf,"filename");
  442.             break;
  443.  
  444.              default:
  445.  
  446.             strcat(buf,"none    ");
  447.             break;
  448.           }
  449.  
  450.           mvwaddstr(window,curr_row,1,buf);
  451.           wmove(window,curr_row,0);
  452.           break;
  453.  
  454.            default:            /* shouldn't happen              */
  455.  
  456.           break;
  457.         }
  458.  
  459.         break;
  460.  
  461.      default:
  462.  
  463.         beep();
  464.         break;
  465.       }
  466.  
  467.       wrefresh(window);
  468.       term_code = wgetch(window);
  469.    }
  470.  
  471.    werase(window);            /* kill everything              */
  472.    wrefresh(window);
  473.    delwin(window);
  474.  
  475.    retval = NO_REBUILD;
  476.  
  477.    if(memcmp(&tmp_args,args,sizeof(tmp_args)) != 0)
  478.    {
  479.       /* something really happened */
  480.  
  481.       if(args->dot_files != tmp_args.dot_files)
  482.      retval |= REBUILD_DIRECTORY;
  483.  
  484.       if(args->size != tmp_args.size ||
  485.      args->prot != tmp_args.prot ||
  486.      args->date != tmp_args.date ||
  487.      args->owner != tmp_args.owner ||
  488.      args->group != tmp_args.group ||
  489.      args->filemarks != tmp_args.filemarks ||
  490.      args->sort != tmp_args.sort ||
  491.      args->text != tmp_args.text)
  492.      retval |= REBUILD_SCREEN;
  493.  
  494.       if(args->filemarks != tmp_args.filemarks)
  495.      retval |= REBUILD_WITH_FILEMARKS;
  496.  
  497.       if(args->sort && !tmp_args.filemarks)
  498.      retval |= REBUILD_WITH_SORT;
  499.    }
  500.  
  501.    return(retval);
  502.  
  503. }    /*** config_options ***/
  504.