Skip to content

Instantly share code, notes, and snippets.

@Luzifer
Created December 29, 2013 17:32
Show Gist options
  • Save Luzifer/8172663 to your computer and use it in GitHub Desktop.
Save Luzifer/8172663 to your computer and use it in GitHub Desktop.
Augeas lens to parse /etc/mail/sendmail.conf file
(*
Module: Sendmail
Parses simple key = "value" conffiles
Author: Knut Ahlers <[email protected]>
About: License
This file is licenced under the LGPL v2+, like the rest of Augeas.
*)
module Sendmail =
autoload xfm
(* View: delim *)
let delim (op:string) = del (/[ \t]*/ . op . /[ \t]*/)
(" " . op . " ")
(* Variable: space_equal *)
let space_equal = delim "="
(* Variable: word
An alphanumeric string *)
let word = /[A-Za-z0-9_.-]+/
(************************************************************************
* View: key_value
* Same as <key_value_line>, but does not end with an end of line
*
* Parameters:
* kw:regexp - the pattern to match as key
* sep:lens - the separator lens, which can be taken from the <Sep> module
* sto:lens - the storing lens
************************************************************************)
let key_value (kw: regexp) (sep:lens) (sto:lens) =
[ key kw . sep . sto ]
(* View: quote *)
let quote = del "\""
(* Variable: to_comment_re *)
let to_comment_re = /[^"\n]*/
(* View: entry *)
let entry = key_value word space_equal
(del /"/ "\"" . store to_comment_re . del /";/ "\";")
(* View: lns *)
let lns = (Util.empty | Util.comment | entry)*
(* Variable: filter *)
let filter = incl "/etc/mail/sendmail.conf"
let xfm = transform lns filter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment