[augeas-devel] [PATCH] Add xorg.aug and associated test

Raphael Pinson raphink at gmail.com
Mon Feb 9 16:04:11 UTC 2009


From: Raphael Pinson <rpinson at lab64.echo-net.net>

---
 lenses/tests/test_xorg.aug |   38 +++++++++
 lenses/xorg.aug            |  183 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 221 insertions(+), 0 deletions(-)

diff --git a/lenses/tests/test_xorg.aug b/lenses/tests/test_xorg.aug
new file mode 100644
index 0000000..d180d49
--- /dev/null
+++ b/lenses/tests/test_xorg.aug
@@ -0,0 +1,38 @@
+(* Tests for the Xorg module *)
+
+module Test_xorg =
+
+  let conf = "
+# xorg.conf
+
+Section \"InputDevice\"
+	Identifier	\"Generic Keyboard\"
+        # that's a driver
+	Driver		\"kbd\"
+	Option		\"XkbOptions\"	\"lv3:ralt_switch\"
+EndSection
+
+Section \"Device\"
+	Identifier	\"Configured Video Device\"
+	Option 		\"MonitorLayout\" \"LVDS,VGA\"
+	VideoRam	229376
+EndSection
+"
+
+  test Xorg.lns get conf =  
+     { }
+     { "#comment" = "xorg.conf" }
+     { }
+     { "InputDevice"
+        { "Identifier" = "\"Generic Keyboard\"" }
+        { "#comment"   = "that's a driver" }
+        { "Driver"     = "\"kbd\"" }
+        { "Option"     = "\"XkbOptions\""
+             { "value"  = "\"lv3:ralt_switch\"" } } }
+     { }
+     { "Device"
+        { "Identifier" = "\"Configured Video Device\"" }
+        { "Option"     = "\"MonitorLayout\""
+             { "value"  = "\"LVDS,VGA\"" } }
+        { "VideoRam"   = "229376" } }
+
diff --git a/lenses/xorg.aug b/lenses/xorg.aug
new file mode 100644
index 0000000..92c0265
--- /dev/null
+++ b/lenses/xorg.aug
@@ -0,0 +1,183 @@
+(*
+Module: Xorg
+ Parses /etc/X11/xorg.conf
+
+Author: Raphael Pinson <raphink at gmail.com>
+
+About: Reference
+ This lens tries to keep as close as possible to `man xorg.conf` where possible.
+
+The definitions from `man xorg.conf` are put as commentaries for reference
+throughout the file. More information can be found in the manual.
+
+About: License
+  This file is licensed under the GPL.
+
+About: Lens Usage
+  Sample usage of this lens in augtool
+
+    * Get the identifier of the devices with a "Clone" option:
+      > match "/files/etc/X11/xorg.conf/Device[Option = 'Clone']/Identifier"
+
+About: Quotes in values
+  In this file, values may or may not be quoted (with double quotes) unless they
+contain spaces or tabulations. For this reason, the quotes are included in the 
+parsed values when present. New values with no spaces will not have quotes by default,
+unless you type the quotes yourself around them. New values with spaces will not be
+accepted unless they are explicitely surrounded by double qutoes.
+
+About: Configuration files
+  This lens applies to /etc/X11/xorg.conf. See <filter>.
+*)
+
+module Xorg =
+  autoload xfm
+
+(************************************************************************
+ * Group:                 USEFUL PRIMITIVES
+ *************************************************************************)
+
+(* Group: Generic primitives *)
+
+(* Variable: eol *)
+let eol     = Util.eol
+
+(* Variable: indent *)
+let indent  = Util.indent
+
+(* Variable: comment *)
+let comment = Util.comment
+
+(* Variable: empty *)
+let empty   = Util.empty
+
+
+(* Group: Separators *)
+
+(* Variable: sep_spc *)
+let sep_spc = Util.del_ws_spc
+
+(* Variable: sep_dquote *)
+let sep_dquote  = Util.del_str "\""
+
+
+(* Group: Fields and values *)
+
+(* Variable: entry_re *)
+let entry_re    = /[^# \t\n\/]+/ - "Option"
+
+
+(* Variable: word_space
+ *  TODO: refine possible values by Section
+ *  words with spaces require quotes 
+ *)
+let word_space  = /"[^"\n]+"/
+
+(*
+ * Variable: word 
+ *   Words without spaces may have quotes or not
+ *   the quotes are then part of the value
+ *)
+let word        = /[^" \t\n]+/
+
+(* Variable: quoted_word *)
+let quoted_word = /"[^" \t\n]+"/
+
+(* Variable: word_all *)
+let word_all = word_space | word | quoted_word
+
+
+
+(************************************************************************
+ * Group:                          ENTRIES AND OPTIONS
+ *************************************************************************)
+
+
+(* View: entry *)
+let entry  = [ indent . key entry_re
+                . sep_spc . store word_all . eol ]
+
+(* View: option_value *)
+let option_value = 
+                [ label "value" . store word_all ]
+
+(* View: option *)
+let option = [ indent . key "Option" . sep_spc
+                . store word_all
+                . (sep_spc . option_value)* . eol ]
+
+(* View: section_entry *)
+let section_entry = empty | comment | entry | option
+
+
+(************************************************************************
+ * Group:                       SECTIONS
+ *************************************************************************)
+
+
+(************************************************************************
+ * Variable: section_re
+ *   Known values for Section names
+ * 
+ *   Definition:
+ *     >   The section names are:
+ *     >
+ *     >   Files          File pathnames
+ *     >   ServerFlags    Server flags
+ *     >   Module         Dynamic module loading
+ *     >   InputDevice    Input device description
+ *     >   Device         Graphics device description
+ *     >   VideoAdaptor   Xv video adaptor description
+ *     >   Monitor        Monitor description
+ *     >   Modes          Video modes descriptions
+ *     >   Screen         Screen configuration
+ *     >   ServerLayout   Overall layout
+ *     >   DRI            DRI-specific configuration
+ *     >   Vendor         Vendor-specific configuration
+ *************************************************************************)
+let section_re = /(Files|ServerFlags|Module|InputDevice|Device|VideoAdaptor
+                        |Monitor|Modes|Screen|ServerLayout|DRI|Vendor)/
+
+
+(************************************************************************
+ * Variable: secton_re_obsolete
+ *   The  following obsolete section names are still recognised for 
+ *   compatibility purposes.  In new config files, the InputDevice 
+ *   section should be used instead.
+ *
+ *   Definition:
+ *     >  Keyboard       Keyboard configuration
+ *     >  Pointer        Pointer/mouse configuration
+ *************************************************************************)
+let section_re_obsolete = /(Keyboard|Pointer)/
+
+(************************************************************************
+ * View: section
+ *   A section in xorg.conf
+ * 
+ *   Definition:
+ *     > Section  "SectionName"
+ *     >    SectionEntry
+ *     >    ...
+ *     > EndSection
+ *************************************************************************)
+let section = [ indent . del "Section" "Section"
+                       . sep_spc . sep_dquote
+                       . key (section_re|section_re_obsolete) . sep_dquote
+                       . eol
+                .  section_entry*
+                . indent . del "EndSection" "EndSection" . eol ]
+
+(*
+ * View: lns
+ *   The xorg.conf lens
+ *)
+let lns = ( empty | comment | section )*
+
+
+(* Variable: filter *)
+let filter = (incl "/etc/X11/xorg.conf")
+
+let xfm = transform lns filter
+
+
-- 
1.4.4.4




More information about the augeas-devel mailing list