Added defines file parsing to kconfig.ml.
svn path=/dists/trunk/linux-2.6/; revision=5342
This commit is contained in:
parent
f7b3530157
commit
9d15e69bb8
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/ocamlrun /usr/bin/ocaml
|
||||
|
||||
(* Command line arguments parsing *)
|
||||
let basedir = ref "debian/arch"
|
||||
let arch = ref ""
|
||||
let subarch = ref ""
|
||||
|
@ -8,6 +9,11 @@ let config_name = ref ""
|
|||
let verbose = ref false
|
||||
let archindir = ref false
|
||||
|
||||
type action = Single | Create | Check
|
||||
let action = ref Create
|
||||
|
||||
let set_action a () = action := a
|
||||
|
||||
let spec = [
|
||||
"-b", Arg.Set_string basedir, "base dir of the arch configurations [default: debian/arch]";
|
||||
"-ba", Arg.Set archindir, "basedir includes arch";
|
||||
|
@ -15,18 +21,21 @@ let spec = [
|
|||
"-s", Arg.Set_string subarch, "subarch";
|
||||
"-f", Arg.Set_string flavour, "flavour";
|
||||
"-v", Arg.Set verbose, "verbose";
|
||||
"-c", Arg.Unit (set_action Check), "check";
|
||||
]
|
||||
let usage =
|
||||
"./kconfig.ml [ -b basedir ] -a arch [ -s subarch ] -f flavour" ^ "\n" ^
|
||||
"./kconfig.ml config_file"
|
||||
"Check single config file : ./kconfig.ml config_file\n" ^
|
||||
"Create config file : ./kconfig.ml [ -ba ] [ -b basedir ] -a arch [ -s subarch ] -f flavour" ^ "\n" ^
|
||||
"Check all config files : ./kconfig.ml -c [ -b basedir ] -a arch [ -s subarch ] -f flavour" ^ "\n"
|
||||
|
||||
let () = Arg.parse
|
||||
spec
|
||||
(function s -> config_name := s)
|
||||
(function s -> config_name := s; action := Single)
|
||||
usage
|
||||
|
||||
let usage () = Arg.usage spec usage
|
||||
|
||||
(* Config file parsing *)
|
||||
type options =
|
||||
| Config_Yes of string
|
||||
| Config_No of string
|
||||
|
@ -44,8 +53,9 @@ let print_option = function
|
|||
| Config_Empty -> Printf.printf "\n"
|
||||
|
||||
exception Comment
|
||||
exception Error
|
||||
|
||||
let parse_line fd =
|
||||
let parse_config_line fd =
|
||||
let line = input_line fd in
|
||||
let len = String.length line in
|
||||
if len = 0 then Config_Empty else
|
||||
|
@ -83,7 +93,7 @@ module C = Map.Make (String)
|
|||
(* Map.add behavior ensures the latest entry is the one staying *)
|
||||
let rec parse_config fd m =
|
||||
try
|
||||
let line = parse_line fd in
|
||||
let line = parse_config_line fd in
|
||||
match line with
|
||||
| Config_Comment _ | Config_Empty -> parse_config fd m
|
||||
| Config_Yes s | Config_No s | Config_Module s | Config_Value (s,_) ->
|
||||
|
@ -101,35 +111,114 @@ let parse_config_file name m force =
|
|||
with Sys_error s ->
|
||||
if force then raise (Sys_error s) else m
|
||||
|
||||
let () =
|
||||
begin
|
||||
if !verbose then
|
||||
if !config_name <> "" then
|
||||
Printf.eprintf "Reading config file %s" !config_name
|
||||
else
|
||||
(* Defines parsing *)
|
||||
type define =
|
||||
| Defines_Base of string
|
||||
| Defines_Field of string * string
|
||||
| Defines_List of string
|
||||
| Defines_Comment of string
|
||||
| Defines_Error of string
|
||||
| Defines_Empty
|
||||
|
||||
let print_define = function
|
||||
| Defines_Base s -> Printf.printf "[%s]\n" s
|
||||
| Defines_Field (n, v) -> Printf.printf "%s:%s\n" n v
|
||||
| Defines_List s -> Printf.printf " %s\n" s
|
||||
| Defines_Comment s -> Printf.printf "#%s\n" s
|
||||
| Defines_Error s -> Printf.printf "*** ERROR *** %s\n" s
|
||||
| Defines_Empty -> Printf.printf "\n"
|
||||
|
||||
let parse_define_line fd =
|
||||
let line = input_line fd in
|
||||
let len = String.length line in
|
||||
if len = 0 then begin Defines_Empty end else
|
||||
try
|
||||
match line.[0] with
|
||||
| '#' -> Defines_Comment (String.sub line 1 (len - 1))
|
||||
| '[' -> begin
|
||||
try
|
||||
let c = String.index_from line 1 ']' in
|
||||
Defines_Base (String.sub line 1 (c - 1))
|
||||
with Not_found | Invalid_argument "String.sub" -> raise Error
|
||||
end
|
||||
| ' ' -> Defines_List (String.sub line 1 (len - 1))
|
||||
| _ -> begin
|
||||
try
|
||||
let c = String.index_from line 1 ':' in
|
||||
Defines_Field (String.sub line 0 c, String.sub line (c + 1) (len - c - 1))
|
||||
with Not_found | Invalid_argument "String.sub" -> raise Error
|
||||
end
|
||||
with Error -> Defines_Error line
|
||||
|
||||
let rec parse_defines fd m l =
|
||||
try
|
||||
let line = parse_define_line fd in
|
||||
match line with
|
||||
| Defines_Comment _ | Defines_Empty -> parse_defines fd (line::m) (l+1)
|
||||
| Defines_Error error ->
|
||||
Printf.eprintf "*** Error at line %d : %s\n" l error;
|
||||
parse_defines fd m (l+1)
|
||||
| Defines_Base _ | Defines_Field _ | Defines_List _ -> parse_defines fd (line::m) (l+1)
|
||||
with End_of_file -> List.rev m
|
||||
|
||||
let parse_defines_file name m force =
|
||||
try
|
||||
let defines = open_in name in
|
||||
let m = parse_defines defines m 0 in
|
||||
close_in defines;
|
||||
m
|
||||
with Sys_error s ->
|
||||
if force then raise (Sys_error s) else m
|
||||
|
||||
let print_defines m = List.iter print_define m
|
||||
|
||||
(* Main functionality *)
|
||||
let get_archdir () = if !archindir then Filename.dirname !basedir else !basedir
|
||||
|
||||
let do_single () =
|
||||
try
|
||||
begin if !verbose then Printf.eprintf "Reading config file %s" !config_name end;
|
||||
let config = open_in !config_name in
|
||||
let m = parse_config config C.empty in
|
||||
print_config m;
|
||||
close_in config
|
||||
with Sys_error s -> Printf.eprintf "Error: %s\n" s
|
||||
|
||||
let do_create () =
|
||||
if !arch <> "" && !flavour <> "" then
|
||||
try
|
||||
begin if !verbose then
|
||||
Printf.eprintf "Creating config file for arch %s, subarch %s, flavour %s (basedir is %s)\n" !arch !subarch !flavour !basedir
|
||||
end;
|
||||
if !config_name <> "" then
|
||||
try
|
||||
let config = open_in !config_name in
|
||||
let m = parse_config config C.empty in
|
||||
print_config m;
|
||||
close_in config
|
||||
with Sys_error s -> Printf.eprintf "Error: %s\n" s
|
||||
else if !arch <> "" && !flavour <> "" then
|
||||
try
|
||||
let dir = if !archindir then Filename.dirname !basedir else !basedir in
|
||||
end;
|
||||
let dir = get_archdir () in
|
||||
let m = parse_config_file (dir ^ "/config") C.empty false in
|
||||
let archdir = dir ^ "/" ^ !arch in
|
||||
let m = parse_config_file (archdir ^ "/config") m false in
|
||||
let m, archdir =
|
||||
if !subarch <> "" && !subarch <> "none" then
|
||||
let archdir = archdir ^ "/" ^ !subarch in
|
||||
let archdir = archdir ^ "/" ^ !subarch in
|
||||
parse_config_file (archdir ^ "/config") m false, archdir
|
||||
else m, archdir
|
||||
else m, archdir
|
||||
in
|
||||
let m = parse_config_file (archdir ^ "/config." ^ !flavour) m true in
|
||||
print_config m;
|
||||
with Sys_error s -> Printf.eprintf "Error: %s\n" s
|
||||
else
|
||||
usage ()
|
||||
|
||||
let do_check () =
|
||||
if !arch <> "" && !flavour <> "" then
|
||||
let dir = get_archdir () in
|
||||
begin if !verbose then Printf.eprintf "Checking config files in %s\n" dir end;
|
||||
try
|
||||
let m = parse_defines_file (dir ^ "/defines") [] true in
|
||||
print_defines m
|
||||
with Sys_error s -> Printf.eprintf "Error: %s\n" s
|
||||
else
|
||||
usage ()
|
||||
|
||||
let () =
|
||||
match !action with
|
||||
| Single -> do_single ()
|
||||
| Create -> do_create ()
|
||||
| Check -> do_check ()
|
||||
|
|
Loading…
Reference in New Issue