Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / bootconf.aug
1 (*
2 Module: BootConf
3     Parses (Open)BSD-stype /etc/boot.conf
4
5 Author: Jasper Lievisse Adriaanse <jasper@jasper.la>
6
7 About: Reference
8     This lens is used to parse the second-stage bootstrap configuration
9     file, /etc/boot.conf as found on OpenBSD. The format is largely MI,
10     with MD parts included:
11     http://www.openbsd.org/cgi-bin/man.cgi?query=boot.conf&arch=i386
12
13 About: Usage Example
14     To be documented
15
16 About: License
17     This file is licensed under the LGPL v2+, like the rest of Augeas.
18
19 About: Configuration files
20   This lens applies to /etc/boot.conf.
21 See <filter>.
22 *)
23
24 module BootConf =
25 autoload xfm
26
27 (************************************************************************
28  * Utility variables/functions
29  ************************************************************************)
30
31 (* View: comment *)
32 let comment = Util.comment
33 (* View:  empty *)
34 let empty   = Util.empty
35 (* View: eol *)
36 let eol     = Util.eol
37 (* View: fspath *)
38 let fspath  = Rx.fspath
39 (* View: space *)
40 let space   = Sep.space
41 (* View: word *)
42 let word    = Rx.word
43
44 (************************************************************************
45  * View: key_opt_value_line
46  *   A subnode with a keyword, an optional part consisting of a separator
47  *   and a storing lens, and an end of line
48  *
49  *   Parameters:
50  *     kw:regexp - the pattern to match as key
51  *     sto:lens  - the storing lens
52  ************************************************************************)
53 let key_opt_value_line (kw:regexp) (sto:lens) =
54     [ key kw . (space . sto)? . eol ]
55
56 (************************************************************************
57  * Commands
58  ************************************************************************)
59
60 (* View: single_command
61    single command such as 'help' or 'time' *)
62 let single_command =
63     let line_re = /help|time|reboot/
64       in [ Util.indent . key line_re . eol ]
65
66 (* View: ls
67    ls [directory] *)
68 let ls = Build.key_value_line
69                "ls" space (store fspath)
70
71 let set_cmd = "addr"
72             | "debug"
73             | "device"
74             | "howto"
75             | "image"
76             | "timeout"
77             | "tty"
78
79 (* View: set
80    set [varname [value]] *)
81 let set = Build.key_value
82                "set" space
83                (key_opt_value_line set_cmd (store Rx.space_in))
84
85 (* View: stty
86   stty [device [speed]] *)
87 let stty =
88     let device = [ label "device" . store fspath ]
89       in let speed = [ label "speed" . store Rx.integer ]
90         in key_opt_value_line "stty" (device . (space . speed)?)
91
92 (* View: echo
93    echo [args] *)
94 let echo = Build.key_value_line
95                  "echo" space (store word)
96
97 (* View: boot
98    boot [image [-acds]]
99    XXX: the last arguments are not always needed, so make them optional *)
100 let boot =
101     let image = [ label "image" . store fspath ]
102       in let arg = [ label "arg" . store word ]
103         in Build.key_value_line "boot" space (image . space . arg)
104
105 (* View: machine
106    machine [command] *)
107 let machine =
108       let machine_entry = Build.key_value ("comaddr"|"memory") 
109                                           space (store word)
110                         | Build.flag ("diskinfo"|"regs")
111             in Build.key_value_line
112                     "machine" space
113                     (Build.opt_list
114                            machine_entry
115                            space)
116
117 (************************************************************************
118  * Lens
119  ************************************************************************)
120
121 (* View: command *)
122 let command = boot | echo | ls | machine | set | stty
123
124 (* View: lns *)
125 let lns = ( empty | comment | command | single_command )*
126
127 (* Variable: filter *)
128 let filter = (incl "/etc/boot.conf")
129
130 let xfm = transform lns filter