[augeas-devel] [PATCH] Require quotes around strings in xorg.conf

Matthew Booth mbooth at redhat.com
Fri Jul 31 08:22:21 UTC 2009


man xorg.conf appears to support this:
           String      a string enclosed in double quote marks (")

This change means that explicitly parsed values will remove quotes in the get
directory and insert them in the put direction.

Currently, only the following entries are explicitly parsed:
* Option
* Screen
* InputDevice
* Driver
* SubSection
* Identifier
* VideoRam
* DefaultDepth
* Device
* All entries in the Display Subsection

The lens will also accept any other entry name not in this list. However, as it
does not know what types to expect, it stores a bare string. This will include
quote marks.
---
 lenses/tests/test_xorg.aug |   34 +++++++++++++++++-----------------
 lenses/xorg.aug            |   43 ++++++++++++++-----------------------------
 2 files changed, 31 insertions(+), 46 deletions(-)

diff --git a/lenses/tests/test_xorg.aug b/lenses/tests/test_xorg.aug
index 9284f2b..4fd937f 100644
--- a/lenses/tests/test_xorg.aug
+++ b/lenses/tests/test_xorg.aug
@@ -42,30 +42,30 @@ EndSection
      { "#comment" = "xorg.conf" }
      { }
      { "ServerLayout"
-        { "Identifier" = "\"single head configuration\"" }
-        { "Screen"     = "\"Screen0\""
+        { "Identifier" = "single head configuration" }
+        { "Screen"     = "Screen0"
            { "num"      = "0" }
            { "position" = "0 0" } }
-        { "InputDevice" = "\"Generic Keyboard\""
-           { "option"   = "\"CoreKeyboard\"" } } }
+        { "InputDevice" = "Generic Keyboard"
+           { "option"   = "CoreKeyboard" } } }
      { }
      { "InputDevice"
-        { "Identifier" = "\"Generic Keyboard\"" }
+        { "Identifier" = "Generic Keyboard" }
         { "#comment"   = "that's a driver" }
-        { "Driver"     = "\"kbd\"" }
-        { "Option"     = "\"XkbOptions\""
-             { "value"  = "\"lv3:ralt_switch\"" } } }
+        { "Driver"     = "kbd" }
+        { "Option"     = "XkbOptions"
+             { "value"  = "lv3:ralt_switch" } } }
      { }
      { "Device"
-        { "Identifier" = "\"Configured Video Device\"" }
-        { "Option"     = "\"MonitorLayout\""
-             { "value"  = "\"LVDS,VGA\"" } }
+        { "Identifier" = "Configured Video Device" }
+        { "Option"     = "MonitorLayout"
+             { "value"  = "LVDS,VGA" } }
         { "VideoRam"   = "229376" }
-        { "Option"     = "\"NoAccel\"" } }
+        { "Option"     = "NoAccel" } }
      { }
      { "Screen"
-        { "Identifier" = "\"Screen0\"" }
-        { "Device"     = "\"Configured Video Device\"" }
+        { "Identifier" = "Screen0" }
+        { "Device"     = "Configured Video Device" }
         { "DefaultDepth" = "24" }
         { "Display"
            { "ViewPort"
@@ -73,6 +73,6 @@ EndSection
               { "y" = "0" } }
            { "Depth"    = "24" }
            { "Modes"
-              { "mode" = "\"1280x1024\"" }
-              { "mode" = "\"1280x960\"" }
-              { "mode" = "\"1280x800\"" } } } }
+              { "mode" = "1280x1024" }
+              { "mode" = "1280x960" }
+              { "mode" = "1280x800" } } } }
diff --git a/lenses/xorg.aug b/lenses/xorg.aug
index e9256b1..1f30647 100644
--- a/lenses/xorg.aug
+++ b/lenses/xorg.aug
@@ -21,14 +21,6 @@ About: Lens Usage
     * 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>.
 *)
@@ -75,24 +67,13 @@ let sep_dquote  = Util.del_str "\""
  * This is a list of all patterns which have specific handlers, and should
  * therefore not be matched by the generic handler
  *)
-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)/
+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)/
 
 (* Variable: generic_entry_re *)
 let generic_entry_re = /[^# \t\n\/]+/ - entries_re
 
-
-(*
- * Variable: unquoted_word
- *   Words without spaces may have quotes or not
- *   the quotes are then part of the value
- *)
-let unquoted_word = /[^" \t\n]+/
-
-(* Variable: quoted_words *)
-let quoted_words = /"[^"\n]+"/   (* " relax Emacs *)
-
-(* Variable: word_all *)
-let word_all = unquoted_word | quoted_words
+(* Variable: quoted_string_val *)
+let quoted_string_val = del "\"" "\"" . store /[^"\n]+/ . del "\"" "\"" 
 
 (* Variable: int *)
 let int = /[0-9]+/
@@ -135,7 +116,7 @@ let entry_xy (canon:string)(match:regexp) =
  *)
 let entry_str (canon:string)(match:regexp) =
         [ indent . del match canon . label canon
-          . sep_spc . store quoted_words . eol ]
+          . sep_spc . quoted_string_val . eol ]
 
 (* View: entry_generic
  * An entry without a specific handler. Store everything after the keyword,
@@ -146,8 +127,8 @@ let entry_generic  = [ indent . key generic_entry_re
 
 (* View: option *)
 let option = [ indent . del /[oO]ption/ "Option" . label "Option" . sep_spc
-               . store quoted_words
-               . [ label "value" . sep_spc . store quoted_words ]* 
+               . quoted_string_val
+               . [ label "value" . sep_spc . quoted_string_val ]* 
                . eol ]
 
 (* View: screen
@@ -155,14 +136,14 @@ let option = [ indent . del /[oO]ption/ "Option" . label "Option" . sep_spc
  *)
 let screen = [ indent . del /[sS]creen/ "Screen" . label "Screen" . sep_spc
                . [ label "num" . store int . sep_spc ]?
-               . store quoted_words . sep_spc
+               . quoted_string_val . sep_spc
                . [ label "position" . store to_eol ]
                . eol ]
 
 (* View: input_device *)
 let input_device = [ indent . del /[iI]nput[dD]evice/ "InputDevice"
-                     . label "InputDevice" . sep_spc . store quoted_words
-                     . [ label "option" . sep_spc . store quoted_words ]*
+                     . label "InputDevice" . sep_spc . quoted_string_val
+                     . [ label "option" . sep_spc . quoted_string_val ]*
                      . eol ]
 
 (* View: driver *)
@@ -177,6 +158,9 @@ let videoram = entry_int "VideoRam" /[vV]ideo[rR]am/
 (* View: default_depth *)
 let default_depth = entry_int "DefaultDepth" /[dD]efault[dD]epth/
 
+(* View: device *)
+let device = entry_str "Device" /[dD]evice/
+
 (************************************************************************
  * Group:                          DISPLAY SUBSECTION
  *************************************************************************)
@@ -184,7 +168,7 @@ let default_depth = entry_int "DefaultDepth" /[dD]efault[dD]epth/
 
 (* View: display_modes *)
 let display_modes = [ indent . del /[mM]odes/ "Modes" . label "Modes"
-                      . [ label "mode" . sep_spc . store quoted_words ]+
+                      . [ label "mode" . sep_spc . quoted_string_val ]+
                       . eol ]
 
 (*************************************************************************
@@ -274,6 +258,7 @@ let section_entry = option |
                     identifier |
                     videoram |
                     default_depth |
+                    device |
                     entry_generic |
                     empty | comment
 
-- 
1.6.2.5




More information about the augeas-devel mailing list