Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / channels.aug
1 (*
2 Module: Channels
3   Parses channels.conf files
4
5 Author: Raphael Pinson <raphink@gmail.com>
6
7 About: Reference
8   See http://linuxtv.org/vdrwiki/index.php/Syntax_of_channels.conf
9
10 About: License
11    This file is licenced under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14    To be documented
15
16 About: Configuration files
17    This lens applies to channels.conf files.
18
19 About: Examples
20    The <Test_Channels> file contains various examples and tests.
21 *)
22
23 module Channels =
24
25 (************************************************************************
26  * Group:                 USEFUL PRIMITIVES
27  *************************************************************************)
28
29 (* View: eol *)
30 let eol = Util.eol
31
32 (* View: comment *)
33 let comment = Util.comment_generic /;[ \t]*/ "; "
34
35
36 (* View: equal *)
37 let equal = Sep.equal
38
39 (* View: colon *)
40 let colon = Sep.colon
41
42 (* View: comma *)
43 let comma = Sep.comma
44
45 (* View: semicol *)
46 let semicol = Util.del_str ";"
47
48 (* View: plus *)
49 let plus = Util.del_str "+"
50
51 (* View: arroba *)
52 let arroba = Util.del_str "@"
53
54 (* View: no_colon *)
55 let no_colon = /[^: \t\n][^:\n]*[^: \t\n]|[^:\n]/
56
57 (* View: no_semicolon *)
58 let no_semicolon = /[^;\n]+/
59
60
61 (************************************************************************
62  * Group:                 FUNCTIONS
63  *************************************************************************)
64
65 (* View: field
66    A generic field *)
67 let field (name:string) (sto:regexp) = [ label name . store sto ]
68
69 (* View: field_no_colon
70    A <field> storing <no_colon> *)
71 let field_no_colon (name:string) = field name no_colon
72
73 (* View: field_int
74    A <field> storing <Rx.integer> *)
75 let field_int (name:string) = field name Rx.integer
76
77 (* View: field_word
78    A <field> storing <Rx.word> *)
79 let field_word (name:string) = field name Rx.word
80
81
82 (************************************************************************
83  * Group:                 ENTRIES
84  *************************************************************************)
85
86 (* View: vpid *)
87 let vpid =
88    let codec = 
89            [ equal . label "codec" . store Rx.integer ]
90    in let vpid_entry (lbl:string) =
91            [ label lbl . store Rx.integer . codec? ]
92    in vpid_entry "vpid"
93     . ( plus . vpid_entry "vpid_pcr" )?
94
95
96 (* View: langs *)
97 let langs =
98    let lang =
99            [ label "lang" . store Rx.word ]
100    in Build.opt_list lang plus
101
102
103 (* View: apid *)
104 let apid =
105    let codec =
106            [ arroba . label "codec" . store Rx.integer ]
107    in let options =
108            equal . ( (langs . codec?) | codec )
109    in let apid_entry (lbl:string) =
110            [ label lbl . store Rx.integer . options? ]
111    in Build.opt_list (apid_entry "apid") comma
112     . ( semicol
113       . Build.opt_list (apid_entry "apid_dolby") comma )?
114   
115 (* View: tpid *)
116 let tpid =
117    let tpid_bylang =
118            [ label "tpid_bylang" . store Rx.integer
119            . (equal . langs)? ]
120    in field_int "tpid"
121       . ( semicol . Build.opt_list tpid_bylang comma )?
122
123 (* View: caid *)
124 let caid =
125    let caid_entry =
126            [ label "caid" . store Rx.word ]
127    in Build.opt_list caid_entry comma
128
129 (* View: entry *)
130 let entry = [ label "entry" . store no_semicolon
131              . (semicol . field_no_colon "provider")? . colon
132              . field_int "frequency" . colon
133              . field_word "parameter" . colon
134              . field_word "signal_source" . colon
135              . field_int "symbol_rate" . colon
136              . vpid . colon
137              . apid . colon
138              . tpid . colon
139              . caid . colon
140              . field_int "sid" . colon
141              . field_int "nid" . colon
142              . field_int "tid" . colon
143              . field_int "rid" . eol ]
144
145 (* View: entry_or_comment *)
146 let entry_or_comment = entry | comment
147
148 (* View: group *)
149 let group =
150       [ Util.del_str ":" . label "group"
151       . store no_colon . eol
152       . entry_or_comment* ]
153
154 (* View: lns *)
155 let lns = entry_or_comment* . group*