Imported Upstream version 0.10.0
[platform/upstream/augeas.git] / lenses / xorg.aug
1 (*
2 Module: Xorg
3  Parses /etc/X11/xorg.conf
4
5 Authors: Raphael Pinson <raphink@gmail.com>
6          Matthew Booth <mbooth@redhat.com>
7
8 About: Reference
9  This lens tries to keep as close as possible to `man xorg.conf` where
10  possible.
11
12 The definitions from `man xorg.conf` are put as commentaries for reference
13 throughout the file. More information can be found in the manual.
14
15 About: License
16   This file is licensed under the LGPLv2+, like the rest of Augeas.
17
18 About: Lens Usage
19   Sample usage of this lens in augtool
20
21     * Get the identifier of the devices with a "Clone" option:
22       > match "/files/etc/X11/xorg.conf/Device[Option = 'Clone']/Identifier"
23
24 About: Configuration files
25   This lens applies to /etc/X11/xorg.conf. See <filter>.
26 *)
27
28 module Xorg =
29   autoload xfm
30
31 (************************************************************************
32  * Group:                 USEFUL PRIMITIVES
33  *************************************************************************)
34
35 (* Group: Generic primitives *)
36
37 (* Variable: eol *)
38 let eol     = Util.eol
39
40 (* Variable: to_eol
41  * Match everything from here to eol, cropping whitespace at both ends
42  *)
43 let to_eol  = /[^ \t\n](.*[^ \t\n])?/
44
45 (* Variable: indent *)
46 let indent  = Util.indent
47
48 (* Variable: comment *)
49 let comment = Util.comment
50
51 (* Variable: empty *)
52 let empty   = Util.empty
53
54
55 (* Group: Separators *)
56
57 (* Variable: sep_spc *)
58 let sep_spc = Util.del_ws_spc
59
60 (* Variable: sep_dquote *)
61 let sep_dquote  = Util.del_str "\""
62
63
64 (* Group: Fields and values *)
65
66 (* Variable: entries_re
67  * This is a list of all patterns which have specific handlers, and should
68  * therefore not be matched by the generic handler
69  *)
70 let entries_re  = /([oO]ption|[sS]creen|[iI]nput[dD]evice|[dD]river|[sS]ub[sS]ection|[dD]isplay|[iI]dentifier|[vV]ideo[rR]am|[dD]efault[dD]epth|[dD]evice)/
71
72 (* Variable: generic_entry_re *)
73 let generic_entry_re = /[^# \t\n\/]+/ - entries_re
74
75 (* Variable: quoted_string_val *)
76 let quoted_string_val = del "\"" "\"" . store /[^"\n]+/ . del "\"" "\""
77                                               (* " relax, emacs *)
78
79 (* Variable: int *)
80 let int = /[0-9]+/
81
82
83 (************************************************************************
84  * Group:                          ENTRIES AND OPTIONS
85  *************************************************************************)
86
87
88 (* View: entry_int
89  * This matches an entry which takes a single integer for an argument
90  *)
91 let entry_int (canon:string) (re:regexp) =
92         [ indent . del re canon . label canon . sep_spc . store int . eol ]
93
94 (* View: entry_rgb
95  * This matches an entry which takes 3 integers as arguments representing red,
96  * green and blue components
97  *)
98 let entry_rgb (canon:string) (re:regexp) =
99         [ indent . del re canon . label canon
100           . [ label "red"   . sep_spc . store int ]
101           . [ label "green" . sep_spc . store int ]
102           . [ label "blue"  . sep_spc . store int ]
103           . eol ]
104
105 (* View: entry_xy
106  * This matches an entry which takes 2 integers as arguments representing X and
107  * Y coordinates
108  *)
109 let entry_xy (canon:string) (re:regexp) =
110         [ indent . del re canon . label canon
111           . [ label "x" . sep_spc . store int ]
112           . [ label "y" . sep_spc . store int ]
113           . eol ]
114
115 (* View: entry_str
116  * This matches an entry which takes a single quoted string
117  *)
118 let entry_str (canon:string) (re:regexp) =
119         [ indent . del re canon . label canon
120           . sep_spc . quoted_string_val . eol ]
121
122 (* View: entry_generic
123  * An entry without a specific handler. Store everything after the keyword,
124  * cropping whitespace at both ends.
125  *)
126 let entry_generic  = [ indent . key generic_entry_re
127                        . sep_spc . store to_eol . eol ]
128
129 (* View: option *)
130 let option = [ indent . del /[oO]ption/ "Option" . label "Option" . sep_spc
131                . quoted_string_val
132                . [ label "value" . sep_spc . quoted_string_val ]*
133                . eol ]
134
135 (* View: screen
136  * The Screen entry of ServerLayout
137  *)
138 let screen = [ indent . del /[sS]creen/ "Screen" . label "Screen" . sep_spc
139                . [ label "num" . store int . sep_spc ]?
140                . quoted_string_val
141                . [ sep_spc . label "position" . store to_eol ]?
142                . eol ]
143
144 (* View: input_device *)
145 let input_device = [ indent . del /[iI]nput[dD]evice/ "InputDevice"
146                      . label "InputDevice" . sep_spc . quoted_string_val
147                      . [ label "option" . sep_spc . quoted_string_val ]*
148                      . eol ]
149
150 (* View: driver *)
151 let driver = entry_str "Driver" /[dD]river/
152
153 (* View: identifier *)
154 let identifier = entry_str "Identifier" /[iI]dentifier/
155
156 (* View: videoram *)
157 let videoram = entry_int "VideoRam" /[vV]ideo[rR]am/
158
159 (* View: default_depth *)
160 let default_depth = entry_int "DefaultDepth" /[dD]efault[dD]epth/
161
162 (* View: device *)
163 let device = entry_str "Device" /[dD]evice/
164
165 (************************************************************************
166  * Group:                          DISPLAY SUBSECTION
167  *************************************************************************)
168
169
170 (* View: display_modes *)
171 let display_modes = [ indent . del /[mM]odes/ "Modes" . label "Modes"
172                       . [ label "mode" . sep_spc . quoted_string_val ]+
173                       . eol ]
174
175 (*************************************************************************
176  * View: display_entry
177  *   Known values for entries in the Display subsection
178  *
179  *   Definition:
180  *     > Depth    depth
181  *     > FbBpp    bpp
182  *     > Weight   red-weight green-weight blue-weight
183  *     > Virtual  xdim ydim
184  *     > ViewPort x0 y0
185  *     > Modes    "mode-name" ...
186  *     > Visual   "visual-name"
187  *     > Black    red green blue
188  *     > White    red green blue
189  *     > Options
190  *)
191
192 let display_entry = entry_int "Depth"    /[dD]epth/ |
193                     entry_int "FbBpp"    /[fF]b[bB]pp/ |
194                     entry_rgb "Weight"   /[wW]eight/ |
195                     entry_xy  "Virtual"  /[vV]irtual/ |
196                     entry_xy  "ViewPort" /[vV]iew[pP]ort/ |
197                     display_modes |
198                     entry_str "Visual"   /[vV]isual/ |
199                     entry_rgb "Black"    /[bB]lack/ |
200                     entry_rgb "White"    /[wW]hite/ |
201                     entry_str "Options"  /[oO]ptions/ |
202                     empty |
203                     comment
204
205 (* View: display *)
206 let display = [ indent . del "SubSection" "SubSection" . sep_spc
207                        . sep_dquote . key "Display" . sep_dquote
208                        . eol
209                        . display_entry*
210                        . indent . del "EndSubSection" "EndSubSection" . eol ]
211
212
213 (************************************************************************
214  * Group:                       SECTIONS
215  *************************************************************************)
216
217
218 (************************************************************************
219  * Variable: section_re
220  *   Known values for Section names
221  *
222  *   Definition:
223  *     >   The section names are:
224  *     >
225  *     >   Files          File pathnames
226  *     >   ServerFlags    Server flags
227  *     >   Module         Dynamic module loading
228  *     >   Extensions     Extension Enabling
229  *     >   InputDevice    Input device description
230  *     >   InputClass     Input Class description
231  *     >   Device         Graphics device description
232  *     >   VideoAdaptor   Xv video adaptor description
233  *     >   Monitor        Monitor description
234  *     >   Modes          Video modes descriptions
235  *     >   Screen         Screen configuration
236  *     >   ServerLayout   Overall layout
237  *     >   DRI            DRI-specific configuration
238  *     >   Vendor         Vendor-specific configuration
239  *************************************************************************)
240 let section_re = /(Extensions|Files|ServerFlags|Module|InputDevice|InputClass|Device|VideoAdaptor|Monitor|Modes|Screen|ServerLayout|DRI|Vendor)/
241
242
243 (************************************************************************
244  * Variable: secton_re_obsolete
245  *   The  following obsolete section names are still recognised for
246  *   compatibility purposes.  In new config files, the InputDevice
247  *   section should be used instead.
248  *
249  *   Definition:
250  *     >  Keyboard       Keyboard configuration
251  *     >  Pointer        Pointer/mouse configuration
252  *************************************************************************)
253 let section_re_obsolete = /(Keyboard|Pointer)/
254
255 (* View: section_entry *)
256 let section_entry = option |
257                     screen |
258                     display |
259                     input_device |
260                     driver |
261                     identifier |
262                     videoram |
263                     default_depth |
264                     device |
265                     entry_generic |
266                     empty | comment
267
268 (************************************************************************
269  * View: section
270  *   A section in xorg.conf
271  *
272  *   Definition:
273  *     > Section  "SectionName"
274  *     >    SectionEntry
275  *     >    ...
276  *     > EndSection
277  *************************************************************************)
278 let section = [ indent . del "Section" "Section"
279                        . sep_spc . sep_dquote
280                        . key (section_re|section_re_obsolete) . sep_dquote
281                        . eol
282                 .  section_entry*
283                 . indent . del "EndSection" "EndSection" . eol ]
284
285 (*
286  * View: lns
287  *   The xorg.conf lens
288  *)
289 let lns = ( empty | comment | section )*
290
291
292 (* Variable: filter *)
293 let filter = (incl "/etc/X11/xorg.conf") .
294   (incl "/etc/X11/xorg.conf.d/*.conf") .
295   Util.stdexcl
296
297 let xfm = transform lns filter