[augeas-devel] [PATCH 1/2] Parse more directives in xorg.conf

Matthew Booth mbooth at redhat.com
Thu Jul 30 17:03:24 UTC 2009


The default xorg.conf generated by pyxf86config on Red Hat/Fedora systems is not
parsed by the current xorg.conf. Specifically it does not understand:

* Screen, in ServerLayout
* InputDevice, in ServerLayout
* SubSection "Display" ..., in Screen

This patch adds support for those values, so that the default xorg.conf on Red
Hat/Fedora systems now parses.

It should also add support for all directives in the Display subsection, however
they are not covered by the test.
---
 lenses/tests/test_xorg.aug |   44 ++++++++++++-
 lenses/xorg.aug            |  149 +++++++++++++++++++++++++++++++++++++-------
 2 files changed, 168 insertions(+), 25 deletions(-)

diff --git a/lenses/tests/test_xorg.aug b/lenses/tests/test_xorg.aug
index 7a09c88..9284f2b 100644
--- a/lenses/tests/test_xorg.aug
+++ b/lenses/tests/test_xorg.aug
@@ -5,6 +5,12 @@ module Test_xorg =
   let conf = "
 # xorg.conf
 
+Section \"ServerLayout\"
+        Identifier     \"single head configuration\"
+        Screen      0  \"Screen0\" 0 0
+        InputDevice    \"Generic Keyboard\" \"CoreKeyboard\"
+EndSection
+
 Section \"InputDevice\"
 	Identifier	\"Generic Keyboard\"
         # that's a driver
@@ -16,6 +22,18 @@ Section \"Device\"
 	Identifier	\"Configured Video Device\"
 	Option 		\"MonitorLayout\" \"LVDS,VGA\"
 	VideoRam	229376
+        Option          \"NoAccel\"
+EndSection
+
+Section \"Screen\"
+        Identifier \"Screen0\"
+        Device     \"Configured Video Device\"
+        DefaultDepth     24
+        SubSection \"Display\"
+                Viewport   0 0
+                Depth     24
+                Modes    \"1280x1024\" \"1280x960\" \"1280x800\"
+        EndSubSection
 EndSection
 "
 
@@ -23,6 +41,14 @@ EndSection
      { }
      { "#comment" = "xorg.conf" }
      { }
+     { "ServerLayout"
+        { "Identifier" = "\"single head configuration\"" }
+        { "Screen"     = "\"Screen0\""
+           { "num"      = "0" }
+           { "position" = "0 0" } }
+        { "InputDevice" = "\"Generic Keyboard\""
+           { "option"   = "\"CoreKeyboard\"" } } }
+     { }
      { "InputDevice"
         { "Identifier" = "\"Generic Keyboard\"" }
         { "#comment"   = "that's a driver" }
@@ -34,5 +60,19 @@ EndSection
         { "Identifier" = "\"Configured Video Device\"" }
         { "Option"     = "\"MonitorLayout\""
              { "value"  = "\"LVDS,VGA\"" } }
-        { "VideoRam"   = "229376" } }
-
+        { "VideoRam"   = "229376" }
+        { "Option"     = "\"NoAccel\"" } }
+     { }
+     { "Screen"
+        { "Identifier" = "\"Screen0\"" }
+        { "Device"     = "\"Configured Video Device\"" }
+        { "DefaultDepth" = "24" }
+        { "Display"
+           { "ViewPort"
+              { "x" = "0" }
+              { "y" = "0" } }
+           { "Depth"    = "24" }
+           { "Modes"
+              { "mode" = "\"1280x1024\"" }
+              { "mode" = "\"1280x960\"" }
+              { "mode" = "\"1280x800\"" } } } }
diff --git a/lenses/xorg.aug b/lenses/xorg.aug
index 157168b..1aa7495 100644
--- a/lenses/xorg.aug
+++ b/lenses/xorg.aug
@@ -2,7 +2,8 @@
 Module: Xorg
  Parses /etc/X11/xorg.conf
 
-Author: Raphael Pinson <raphink at gmail.com>
+Authors: Raphael Pinson <raphink at gmail.com>
+         Matthew Booth <mbooth at redhat.com>
 
 About: Reference
  This lens tries to keep as close as possible to `man xorg.conf` where
@@ -44,6 +45,11 @@ module Xorg =
 (* Variable: eol *)
 let eol     = Util.eol
 
+(* Variable: to_eol
+ * Match everything from here to eol, cropping whitespace at both ends
+ *)
+let to_eol  = /[^ \t\n](.*[^ \t\n])?/
+
 (* Variable: indent *)
 let indent  = Util.indent
 
@@ -65,29 +71,28 @@ let sep_dquote  = Util.del_str "\""
 
 (* Group: Fields and values *)
 
-(* Variable: entry_re *)
-let entry_re    = /[^# \t\n\/]+/ - "Option"
+(* Variable: entries_re *)
+let entries_re  = /(Option|Screen|InputDevice|SubSection|Display)/
 
+(* Variable: generic_entry_re *)
+let generic_entry_re = /[^# \t\n\/]+/ - entries_re
 
-(* Variable: word_space
- *  TODO: refine possible values by Section
- *  words with spaces require quotes
- *)
-let word_space  = /"[^"\n]+"/
 
 (*
- * Variable: word
+ * Variable: unquoted_word
  *   Words without spaces may have quotes or not
  *   the quotes are then part of the value
  *)
-let word        = /[^" \t\n]+/
+let unquoted_word = /[^" \t\n]+/
 
-(* Variable: quoted_word *)
-let quoted_word = /"[^" \t\n]+"/   (* " relax Emacs *)
+(* Variable: quoted_words *)
+let quoted_words = /"[^"\n]+"/   (* " relax Emacs *)
 
 (* Variable: word_all *)
-let word_all = word_space | word | quoted_word
+let word_all = unquoted_word | quoted_words
 
+(* Variable: int *)
+let int = /[0-9]+/
 
 
 (************************************************************************
@@ -95,21 +100,114 @@ let word_all = word_space | word | quoted_word
  *************************************************************************)
 
 
-(* View: entry *)
-let entry  = [ indent . key entry_re
-                . sep_spc . store word_all . eol ]
+(* View: entry_int
+ * This matches an entry which takes a single integer for an argument
+ *)
+let entry_int (canon:string)(match:regexp) =
+        [ indent . del match canon . label canon . sep_spc . store int . eol ]
 
-(* View: option_value *)
-let option_value =
-                [ label "value" . store word_all ]
+(* View: entry_rgb
+ * This matches an entry which takes 3 integers as arguments representing red,
+ * green and blue components
+ *)
+let entry_rgb (canon:string)(match:regexp) =
+        [ indent . del match canon . label canon
+          . [ label "red"   . sep_spc . store int ]
+          . [ label "green" . sep_spc . store int ]
+          . [ label "blue"  . sep_spc . store int ]
+          . eol ]
+
+(* View: entry_xy
+ * This matches an entry which takes 2 integers as arguments representing X and
+ * Y coordinates
+ *)
+let entry_xy (canon:string)(match:regexp) =
+        [ indent . del match canon . label canon
+          . [ label "x" . sep_spc . store int ]
+          . [ label "y" . sep_spc . store int ]
+          . eol ]
+
+(* View: entry_str
+ * This matches an entry which takes a single, possibly quoted, string
+ *)
+let entry_str (canon:string)(match:regexp) =
+        [ indent . del match canon . label canon
+          . sep_spc . store word_all . eol ]
+
+(* View: entry_generic
+ * An entry without a specific handler. Store everything after the keyword,
+ * cropping whitespace at both ends.
+ *)
+let entry_generic  = [ indent . key generic_entry_re
+                       . sep_spc . store to_eol . eol ]
 
 (* View: option *)
 let option = [ indent . key "Option" . sep_spc
-                . store word_all
-                . (sep_spc . option_value)* . eol ]
+               . store word_all
+               . [ label "value" . sep_spc . store word_all ]* 
+               . eol ]
 
-(* View: section_entry *)
-let section_entry = empty | comment | entry | option
+(* View: screen
+ * The Screen entry of ServerLayout
+ *)
+let screen = [ indent . key "Screen" . sep_spc
+               . [ label "num" . store int . sep_spc ]?
+               . store quoted_words . sep_spc
+               . [ label "position" . store to_eol ]
+               . eol ]
+
+(* View: input_device *)
+let input_device = [ indent . key "InputDevice" . sep_spc . store word_all
+                     . [ label "option" . sep_spc . store word_all ]*
+                     . eol ]
+
+
+(************************************************************************
+ * Group:                          DISPLAY SUBSECTION
+ *************************************************************************)
+
+
+(* View: display_modes *)
+let display_modes = [ indent . del /[mM]odes/ "Modes" . label "Modes"
+                      . [ label "mode" . sep_spc . store quoted_words ]+
+                      . eol ]
+
+(*************************************************************************
+ * View: display_entry
+ *   Known values for entries in the Display subsection
+ *
+ *   Definition:
+ *     > Depth    depth
+ *     > FbBpp    bpp
+ *     > Weight   red-weight green-weight blue-weight
+ *     > Virtual  xdim ydim
+ *     > ViewPort x0 y0
+ *     > Modes    "mode-name" ...
+ *     > Visual   "visual-name"
+ *     > Black    red green blue
+ *     > White    red green blue
+ *     > Options
+ *)
+
+let display_entry = entry_int "Depth"    /[dD]epth/ |
+                    entry_int "FbBpp"    /[fF]b[bB]pp/ |
+                    entry_rgb "Weight"   /[wW]eight/ |
+                    entry_xy  "Virtual"  /[vV]irtual/ |
+                    entry_xy  "ViewPort" /[vV]iew[pP]ort/ |
+                    display_modes |
+                    entry_str "Visual"   /[vV]isual/ |
+                    entry_rgb "Black"    /[bB]lack/ |
+                    entry_rgb "White"    /[wW]hite/ |
+                    entry_str "Options"  /[oO]ptions/ |
+                    empty |
+                    comment
+
+(* View: display *)
+let display = [ indent . del "SubSection" "SubSection" . sep_spc
+                       . sep_dquote . key "Display" . sep_dquote
+                       . eol 
+                       . display_entry*
+                       . indent . del "EndSubSection" "EndSubSection" . eol ]
 
 
 (************************************************************************
@@ -153,6 +251,11 @@ let section_re = /(Files|ServerFlags|Module|InputDevice|Device|VideoAdaptor
  *************************************************************************)
 let section_re_obsolete = /(Keyboard|Pointer)/
 
+(* View: section_entry *)
+let section_entry = empty | comment |
+                    option | screen | display | input_device |
+                    entry_generic
+
 (************************************************************************
  * View: section
  *   A section in xorg.conf
-- 
1.6.2.5




More information about the augeas-devel mailing list