summaryrefslogtreecommitdiffstats
path: root/src/toptions.c
blob: 18648805a963dbeaf93d0b5010217f0a26920308 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*

    File: toptions.c

    Copyright (C) 2008 Christophe GRENIER <grenier@cgsecurity.org>
  
    This software is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
  
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
  
    You should have received a copy of the GNU General Public License along
    with this program; if not, write the Free Software Foundation, Inc., 51
    Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

 */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
 
#include <stdio.h>
#include "types.h"
#include "common.h"
#include "intrf.h"
#ifdef HAVE_NCURSES
#include "intrfn.h"
#endif
#include "log.h"
#include "toptions.h"

#ifdef HAVE_NCURSES
static void interface_options_ncurses(int *dump_ind, int *align, unsigned int *expert)
{
  unsigned int menu = 3;
  /* ncurses interface */
  while (1)
  {
    int car;
    int real_key;
    struct MenuItem menuOptions[]=
    {
      { 'E',NULL,"Expert mode adds some functionalities"},
      { 'C',NULL,"Partitions are aligned on cylinder/head boundaries" },
      { 'D',NULL,"Dump essential sectors" },
      { 'Q',"[ Ok ]","Done with changing options"},
      { 0, NULL, NULL }
    };
    menuOptions[0].name=*expert?"Expert mode : Yes":"Expert mode : No";
    switch(*align)
    {
      case 0:
	menuOptions[1].name="Cylinder boundary : No";
	break;
      case 1:
	menuOptions[1].name="Cylinder boundary : Head boundary only";
	break;
      case 2:
	menuOptions[1].name="Cylinder boundary : Yes";
	break;
    }
    menuOptions[2].name=*dump_ind?"Dump : Yes":"Dump : No";
    aff_copy(stdscr);
    car=wmenuSelect_ext(stdscr, 23, INTER_OPTION_Y, INTER_OPTION_X, menuOptions, 0, "ECDQ", MENU_VERT|MENU_VERT_ARROW2VALID, &menu,&real_key);
    switch(car)
    {
      case 'd':
      case 'D':
	*dump_ind=!*dump_ind;
	break;
      case 'c':
      case 'C':
	if(*align<2)
	  (*align)++;
	else
	  *align=0;
	break;
      case 'e':
      case 'E':
	*expert=!*expert;
	break;
      case key_ESC:
      case 'q':
      case 'Q':
	return;
    }
  }
}
#endif

void interface_options(int *dump_ind, int *align, unsigned int *expert, char**current_cmd)
{
  if(*current_cmd==NULL)
  {
#ifdef HAVE_NCURSES
    interface_options_ncurses(dump_ind, align, expert);
#endif
  }
  /* write new options to log file */
  log_info("New options :\n Dump : %s\n ", (*dump_ind?"Yes":"No"));
  switch(*align)
  {
    case 0:
      log_info("Cylinder boundary : No\n");
      break;
    case 1:
      log_info("Cylinder boundary : Head boundary only\n");
      break;
    case 2:
      log_info("Cylinder boundary : Yes\n");
      break;
  }
  log_info(" Expert mode : %s\n", *expert?"Yes":"No");
}