buffer new implementation, first step of implementing fs
[quarnos.git] / scripts / text_config.pl
blob82c074910a09c3943be16bd3078c8da9a4903953
1 #!/usr/bin/perl
3 # Quarn OS
5 # Configuration tool
7 # Copyright (C) 2008 Pawel Dziepak
9 # This tool loads file that consist of configuration possibilities and asks
10 # user questions about each option. The purpose of the tool is the same as
11 # the nc_config, but this script does not need ncurses installed.
14 # Open configuration file
15 open (CONF_IN, "scripts/config_options");
16 @confin = <CONF_IN>;
18 if ($ARGV[0] !~ /\Adef/) {
19 print "Configuration tool for Quarn OS $ARGV[0] (text version)\nCopyright (C) 2008 Pawel Dziepak\n\n";
22 # go through config config and ask questions
23 $count = 0;
24 for $line (@confin) {
25 if ($line =~ /\Aname (.*)/) {
26 $name = $1;
27 $count++;
28 } elsif ($line =~ /\Alongname (.*)/) {
29 $descr =$1;
30 $count++;
31 } elsif ($line =~ /\Aopts (.*)/) {
32 $opts =$1;
33 $count++;
34 } elsif ($line =~ /\Ahelp (.*)/) {
35 $help =$1;
36 $count++;
37 } else {
38 $help = $name = $descr = $opts = "";
39 $count = 0;
41 $usera = "";
42 $def = "";
44 if ($opts =~ /(\A|\s)yes/) {
45 $usera .= "y/";
47 if ($opts =~ /(\A|\s)dyes/) {
48 $usera .= "Y/";
49 $def = "y";
51 if ($opts =~ /(\A|\s)module/) {
52 $usera .= "m/";
54 if ($opts =~ /(\A|\s)dmodule/) {
55 $usera .= "M/";
56 $def = "m";
58 if ($opts =~ /(\A|\s)no/) {
59 $usera .= "n/";
61 if ($opts =~ /(\A|\s)dno/) {
62 $usera .= "N/";
63 $def = "n";
65 $usera .= "?";
67 while ($count == 4) {
68 $count = 0;
69 if ($ARGV[0] !~ /\Adef/) {
70 print "Do you want to enable \"$descr\" [$usera]: ";
71 $ans = <STDIN>;
73 if ($ans !~ /(\w|\?)/) {
74 $ans = $def;
76 if ($ans =~ /\Ay/ && $opts =~ /yes/) {
77 push(@confout, "#define $name\t\t2\n");
78 } elsif ($ans =~ /\Am/ && $opts =~ /module/) {
79 push(@confout, "#define $name\t\t1\n");
80 } elsif ($ans =~ /\An/ && $opts =~ /no/) {
81 push(@confout, "#define $name\t\t0\n");
82 } elsif ($ans =~ /\A\?/) {
83 print $help . "\n";
84 $count = 4;
85 } else {
86 print "Unknown answer. ";
87 $count = 4;
92 push(@confout, "\n#define CONF_NO\t\t\t0\n");
93 push(@confout, "#define CONF_MODULE\t\t1\n");
94 push(@confout, "#define CONF_YES\t\t2\n");
96 open (CONF_OUT, ">quarnconf.h");
97 print CONF_OUT @confout;