]> granicus.if.org Git - neomutt/commitdiff
Update autosetup, use negated and nested conditionals in @if substitutions
authorPietro Cerutti <gahr@gahr.ch>
Tue, 13 Feb 2018 11:00:45 +0000 (11:00 +0000)
committerPietro Cerutti <gahr@gahr.ch>
Tue, 13 Feb 2018 11:00:45 +0000 (11:00 +0000)
Makefile.autosetup
auto.def
autosetup/autosetup
autosetup/system.tcl

index 1e6e8c8c00517907d27d65bbaace400bab5fa4e9..86ec4c970c1b7768aaf7d9881a8b2a2ecc44ae8b 100644 (file)
@@ -69,8 +69,7 @@ NEOMUTTOBJS=  mutt_account.o addrbook.o alias.o attach.o bcache.o body.o \
                smtp.o sort.o state.o status.o system.o thread.o url.o \
                version.o
 
-@if HAVE_WCSCASECMP
-@else
+@if !HAVE_WCSCASECMP
 NEOMUTTOBJS+=  wcscasecmp.o
 @endif
 @if HAVE_RESIZETERM
@@ -165,7 +164,6 @@ LIBHCACHEOBJS=      hcache/hcache.o
 CLEANFILES+=   $(LIBHCACHE) $(LIBHCACHEOBJS)
 MUTTLIBS+=     $(LIBHCACHE)
 ALLOBJS+=      $(LIBHCACHEOBJS)
-@endif
 @if HAVE_BDB
 LIBHCACHEOBJS+=        hcache/bdb.o
 @endif
@@ -184,6 +182,7 @@ LIBHCACHEOBJS+=     hcache/qdbm.o
 @if HAVE_TC
 LIBHCACHEOBJS+=        hcache/tc.o
 @endif
+@endif # USE_HCACHE
 
 ###############################################################################
 # pgpewrap
index 10948935559a3de7a6d50c7b7441e7d014611cac..45d80b7caacb959f21e40eb6951ec11db66c7057 100644 (file)
--- a/auto.def
+++ b/auto.def
@@ -6,6 +6,8 @@ if {![catch {exec uname} out] && $out eq {Linux}} {
   define defaultprefix /usr
 }
 
+autosetup-require-version 0.6.8
+
 # Standard autosetup modules and our own modules
 use system cc cc-lib mutt-gettext mutt-iconv
 
index dece81b880a5dde960a23d17daec9882469d8efb..63441bb8b27c110fd1d11efb43b8b9bd015cf2d5 100755 (executable)
@@ -81,6 +81,8 @@ proc main {argv} {
        set autosetup(optionhelp) {}
        set autosetup(showhelp) 0
 
+       use util
+
        # Parse options
        use getopt
 
@@ -745,6 +747,18 @@ proc is-defined {name} {
        info exists ::define($name)
 }
 
+# @is-define-set name
+#
+# Returns 1 if the given variable is defined and is set
+# to a value other than "" or 0
+#
+proc is-define-set {name} {
+       if {[get-define $name] in {0 ""}} {
+               return 0
+       }
+       return 1
+}
+
 # @all-defines
 #
 # Returns a dictionary (name, value list) of all defined variables.
@@ -1040,7 +1054,6 @@ proc maybe-show-timestamp {} {
 # A fatal error is generated if the current version is less than that required.
 #
 proc autosetup-require-version {required} {
-       use util
        if {[compare-versions $::autosetup(version) $required] < 0} {
                user-error "autosetup version $required is required, but this is $::autosetup(version)"
        }
@@ -1841,8 +1854,7 @@ proc autosetup_create_configure {shared} {
        if {$shared} {
                writefile configure \
 {#!/bin/sh
-# Note that WRAPPER is set here purely to detect an autosetup-created script
-WRAPPER="-"; "autosetup" "$@"
+WRAPPER="$0"; export WRAPPER; "autosetup" "$@"
 }
        } else {
                writefile configure \
@@ -2345,6 +2357,16 @@ proc prefix {pre list} {
        }
        return $result
 }
+
+# @lpop list
+#
+# Removes the last entry from the given list and returns it.
+proc lpop {listname} {
+       upvar $listname list
+       set val [lindex $list end]
+       set list [lrange $list 0 end-1]
+       return $val
+}
 }
 
 # ----- @module wiki-formatting.tcl -----
index 56054b4f3e1580a9702e043f4d47315497f764c6..7b62b3dc8f8c822f31d2962d1112b8516fdf627e 100644 (file)
@@ -141,29 +141,32 @@ proc write-if-changed {file buf {script {}}} {
 #
 # Each pattern of the form '@define@' is replaced with the corresponding
 # "define", if it exists, or left unchanged if not.
-# 
+#
 # The special value '@srcdir@' is substituted with the relative
 # path to the source directory from the directory where the output
 # file is created, while the special value '@top_srcdir@' is substituted
 # with the relative path to the top level source directory.
 #
 # Conditional sections may be specified as follows:
-## @if name == value
+## @if NAME eq "value"
 ## lines
 ## @else
 ## lines
 ## @endif
 #
-# Where 'name' is a defined variable name and '@else' is optional.
+# Where 'NAME' is a defined variable name and '@else' is optional.
+# Note that variables names *must* start with an uppercase letter.
 # If the expression does not match, all lines through '@endif' are ignored.
 #
 # The alternative forms may also be used:
-## @if name
-## @if name != value
+## @if NAME  (true if the variable is defined, but not empty and not "0")
+## @if !NAME  (opposite of the form above)
+## @if <general-tcl-expression>
 #
-# Where the first form is true if the variable is defined, but not empty nor 0.
+# In the general Tcl expression, any words beginning with an uppercase letter
+# are translated into [get-define NAME]
 #
-# Currently these expressions can't be nested.
+# Expressions may be nested
 #
 proc make-template {template {out {}}} {
        set infile [file join $::autosetup(srcdir) $template]
@@ -195,34 +198,62 @@ proc make-template {template {out {}}} {
        foreach {n v} [array get ::define] {
                lappend mapping @$n@ $v
        }
+
+       # A stack of true/false conditions, one for each nested conditional
+       # starting with "true"
+       set condstack {1}
        set result {}
+       set linenum 0
        foreach line [split [readfile $infile] \n] {
-               if {[info exists cond]} {
-                       set l [string trimright $line]
-                       if {$l eq "@endif"} {
-                               unset cond
-                               continue
+               incr linenum
+               if {[regexp {^@(if|else|endif)\s*(.*)} $line -> condtype condargs]} {
+                       if {$condtype eq "if"} {
+                               if {[llength $condargs] == 1} {
+                                       # ABC => [get-define ABC] ni {0 ""}
+                                       # !ABC => [get-define ABC] in {0 ""}
+                                       lassign $condargs condvar
+                                       if {[regexp {^!(.*)} $condvar -> condvar]} {
+                                               set op in
+                                       } else {
+                                               set op ni
+                                       }
+                                       set condexpr "\[[list get-define $condvar]\] $op {0 {}}"
+                               } else {
+                                       # Translate alphanumeric ABC into [get-define ABC] and leave the
+                                       # rest of the expression untouched
+                                       regsub -all {([A-Z][[:alnum:]_]*)} $condargs {[get-define \1]} condexpr
+                               }
+                               if {[catch [list expr $condexpr] condval]} {
+                                       dputs $condval
+                                       autosetup-error "$infile:$linenum: Invalid expression: $line"
+                               }
+                               dputs "@$condtype: $condexpr => $condval"
                        }
-                       if {$l eq "@else"} {
-                               set cond [expr {!$cond}]
-                               continue
+                       if {$condtype ne "if" && [llength $condstack] <= 1} {
+                               autosetup-error "$infile:$linenum: Error: @$condtype missing @if"
                        }
-                       if {$cond} {
-                               lappend result $line
+                       switch -exact $condtype {
+                               if {
+                                       # push condval
+                                       lappend condstack $condval
+                               }
+                               else {
+                                       # Toggle the last entry
+                                       set condval [lpop condstack]
+                                       set condval [expr {!$condval}]
+                                       lappend condstack $condval
+                               }
+                               endif {
+                                       if {[llength $condstack] == 0} {
+                                               user-notice "$infile:$linenum: Error: @endif missing @if"
+                                       }
+                                       lpop condstack
+                               }
                        }
                        continue
                }
-               if {[regexp {^@if\s+(\w+)(.*)} $line -> name expression]} {
-                       lassign $expression equal value
-                       set varval [get-define $name ""]
-                       if {$equal eq ""} {
-                               set cond [expr {$varval ni {"" 0}}]
-                       } else {
-                               set cond [expr {$varval eq $value}]
-                               if {$equal ne "=="} {
-                                       set cond [expr {!$cond}]
-                               }
-                       }
+               # Only output this line if the stack contains all "true"
+               if {"0" in $condstack} {
                        continue
                }
                lappend result $line