[augeas-devel] augeas: master - Parse more directives in xorg.conf

David Lutterkort lutter at fedoraproject.org
Tue Aug 4 22:37:18 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=5bf7d42a1344503dd3be66235368988a29e1e988
Commit:        5bf7d42a1344503dd3be66235368988a29e1e988
Parent:        a390a82360da536c5a69a50558578047ac91647e
Author:        Matthew Booth <mbooth at redhat.com>
AuthorDate:    Thu Jul 30 18:03:24 2009 +0100
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Tue Aug 4 15:20:07 2009 -0700

Parse more directives in xorg.conf

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.
---
 AUTHORS                    |    1 +
 lenses/tests/test_xorg.aug |   44 +++++++++++++-
 lenses/xorg.aug            |  147 +++++++++++++++++++++++++++++++++++++-------
 3 files changed, 168 insertions(+), 24 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 05df3c1..7920733 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -6,6 +6,7 @@ Contributions by:
 
   Sylvain Baubeau  <bob at glumol.com>
   Anders F Björklund <afb at users.sourceforge.net>
+  Matthew Booth    <mbooth at redhat.com>
   Francois Deppierraz <francois.deppierraz at camptocamp.com>
   Dominique Dumont <dominique.dumont at hp.com>
   Free Ekanayaka   <free at 64studio.com>
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..f17774d 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]+/                   (* " relax Emacs *)
 
 (* Variable: quoted_word *)
-let quoted_word = /"[^" \t\n]+"/   (* " relax Emacs *)
+let quoted_word = /"[^"\n]+"/                     (* " relax Emacs *)
 
 (* Variable: word_all *)
-let word_all = word_space | word | quoted_word
+let word_all = unquoted_word | quoted_word
 
+(* 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) (re:regexp) =
+        [ indent . del re 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) (re:regexp) =
+        [ indent . del re 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) (re:regexp) =
+        [ indent . del re 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) (re:regexp) =
+        [ indent . del re 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: screen
+ * The Screen entry of ServerLayout
+ *)
+let screen = [ indent . key "Screen" . sep_spc
+               . [ label "num" . store int . sep_spc ]?
+               . store quoted_word . 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 ]
 
-(* View: section_entry *)
-let section_entry = empty | comment | entry | option
+
+(************************************************************************
+ * Group:                          DISPLAY SUBSECTION
+ *************************************************************************)
+
+
+(* View: display_modes *)
+let display_modes = [ indent . del /[mM]odes/ "Modes" . label "Modes"
+                      . [ label "mode" . sep_spc . store quoted_word ]+
+                      . 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




More information about the augeas-devel mailing list