|
Packit Service |
a2ae7a |
(* Generic lens for shell-script config files like the ones found *)
|
|
Packit Service |
a2ae7a |
(* in /etc/sysconfig, where a string needs to be split into *)
|
|
Packit Service |
a2ae7a |
(* single words. *)
|
|
Packit Service |
a2ae7a |
module Shellvars_list =
|
|
Packit Service |
a2ae7a |
autoload xfm
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let eol = Util.eol
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let key_re = /[A-Za-z0-9_]+/
|
|
Packit Service |
a2ae7a |
let eq = Util.del_str "="
|
|
Packit Service |
a2ae7a |
let comment = Util.comment
|
|
Packit Service |
a2ae7a |
let comment_or_eol = Util.comment_or_eol
|
|
Packit Service |
a2ae7a |
let empty = Util.empty
|
|
Packit Service |
a2ae7a |
let indent = Util.indent
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let sqword = /[^ '\t\n]+/
|
|
Packit Service |
a2ae7a |
let dqword = /([^ "\\\t\n]|\\\\.)+/
|
|
Packit Service |
a2ae7a |
let uqword = /([^ `"'\\\t\n]|\\\\.)+/
|
|
Packit Service |
a2ae7a |
let bqword = /`[^`\n]*`/
|
|
Packit Service |
a2ae7a |
let space_or_nl = /[ \t\n]+/
|
|
Packit Service |
a2ae7a |
let space_or_cl = space_or_nl | Rx.cl
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* lists values of the form ... val1 val2 val3 ... *)
|
|
Packit Service |
a2ae7a |
let list (word:regexp) (sep:regexp) =
|
|
Packit Service |
a2ae7a |
let list_value = store word in
|
|
Packit Service |
a2ae7a |
indent .
|
|
Packit Service |
a2ae7a |
[ label "value" . list_value ] .
|
|
Packit Service |
a2ae7a |
[ del sep " " . label "value" . list_value ]* . indent
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* handle single quoted lists *)
|
|
Packit Service |
a2ae7a |
let squote_arr = [ label "quote" . store /'/ ]
|
|
Packit Service |
a2ae7a |
. (list sqword space_or_nl)? . del /'/ "'"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* similarly handle double quoted lists *)
|
|
Packit Service |
a2ae7a |
let dquote_arr = [ label "quote" . store /"/ ]
|
|
Packit Service |
a2ae7a |
. (list dqword space_or_cl)? . del /"/ "\""
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* handle unquoted single value *)
|
|
Packit Service |
a2ae7a |
let unquot_val = [ label "quote" . store "" ]
|
|
Packit Service |
a2ae7a |
. [ label "value" . store (uqword+ | bqword)]?
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* lens for key value pairs *)
|
|
Packit Service |
a2ae7a |
let kv = [ key key_re . eq .
|
|
Packit Service |
a2ae7a |
( (squote_arr | dquote_arr) . comment_or_eol
|
|
Packit Service |
a2ae7a |
| unquot_val . eol )
|
|
Packit Service |
a2ae7a |
]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let lns = ( comment | empty | kv )*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let filter = incl "/etc/sysconfig/bootloader"
|
|
Packit Service |
a2ae7a |
. incl "/etc/sysconfig/kernel"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let xfm = transform lns filter
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Local Variables: *)
|
|
Packit Service |
a2ae7a |
(* mode: caml *)
|
|
Packit Service |
a2ae7a |
(* End: *)
|