Wapp

Check-in [627a5a8bbc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Alternative implementation of wapp-subst that does not allow command substitution within unquoted sections.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | new-subst-algorithm
Files: files | file ages | folders
SHA3-256: 627a5a8bbc076ee5bb77e913bf2f72e43e7ba693cde5766a0bcea4b6e85f81be
User & Date: drh 2019-03-06 19:32:50
Context
2019-03-06
19:32
Alternative implementation of wapp-subst that does not allow command substitution within unquoted sections. Leaf check-in: 627a5a8bbc user: drh tags: new-subst-algorithm
17:44
Update the fileupload.tcl example so that uploaded images are shown in-line. This demonstrates how to use the TCL "binary encode" command to generate base64 from the raw image content and how to modify content-security-policy to allow "data:" sources for images. check-in: af9968656c user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Makefile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/make

CC = gcc -Os -static
TCLLIB = /home/drh/tcl/lib/libtcl8.6.a -lm -lz -lpthread -ldl
TCLINC = /home/drh/tcl/include
TCLSH = tclsh

all: wapptclsh

wapptclsh: wapptclsh.c
	$(CC) -I. -I$(TCLINC) -o $@ wapptclsh.c $(TCLLIB)

wapptclsh.c:	wapptclsh.c.in wapp.tcl wapptclsh.tcl tclsqlite3.c mkccode.tcl
	$(TCLSH) mkccode.tcl wapptclsh.c.in >$@

clean:	
	rm wapptclsh wapptclsh.c



|













1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/make

CC = gcc -Os -static
TCLLIB = /home/drh/tcl/lib/libtcl8.7.a -lm -lz -lpthread -ldl
TCLINC = /home/drh/tcl/include
TCLSH = tclsh

all: wapptclsh

wapptclsh: wapptclsh.c
	$(CC) -I. -I$(TCLINC) -o $@ wapptclsh.c $(TCLLIB)

wapptclsh.c:	wapptclsh.c.in wapp.tcl wapptclsh.tcl tclsqlite3.c mkccode.tcl
	$(TCLSH) mkccode.tcl wapptclsh.c.in >$@

clean:	
	rm wapptclsh wapptclsh.c

Changes to wapp.tcl.

71
72
73
74
75
76
77

78
79





80
81
82
83
84
85
86
87
88
89
90




91
92
93
94
95
96
97
98
#
# The %unsafe substitution should be avoided whenever possible, obviously.
# In addition to the substitutions above, the text also does backslash
# escapes.
#
proc wapp-subst {txt} {
  global wapp

  regsub -all {%(html|url|qp|string|unsafe){1,1}?(|%)\((.+)\)\2} $txt \
         {[wappInt-enc-\1 "\3"]} txt





  dict append wapp .reply [uplevel 1 [list subst -novariables $txt]]
}

# Works like wapp-subst, but also removes whitespace from the beginning
# of lines.
#
proc wapp-trim {txt} {
  global wapp
  regsub -all {\n\s+} [string trim $txt] \n txt
  regsub -all {%(html|url|qp|string|unsafe){1,1}?(|%)\((.+)\)\2} $txt \
         {[wappInt-enc-\1 "\3"]} txt




  dict append wapp .reply [uplevel 1 [list subst -novariables $txt]]
}

# There must be a wappInt-enc-NAME routine for each possible substitution
# in wapp-subst.  Thus there are routines for "html", "url", "qp", and "unsafe".
#
#    wappInt-enc-html           Escape text so that it is safe to use in the
#                               body of an HTML document.







>
|
<
>
>
>
>
>
|







|
|
|
>
>
>
>
|







71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#
# The %unsafe substitution should be avoided whenever possible, obviously.
# In addition to the substitutions above, the text also does backslash
# escapes.
#
proc wapp-subst {txt} {
  global wapp
  set txt [subst -novar -nocom $txt]
  while {[regexp {^(.*?)%(html|url|qp|string|unsafe)(|%)\((.+?)\)\3(.*)$} \

          $txt all before verb m1 arg after]} {
    set arg [uplevel 1 [list subst $arg]]
    dict append wapp .reply $before[wappInt-enc-$verb $arg]
    set txt $after
  }
  dict append wapp .reply $txt
}

# Works like wapp-subst, but also removes whitespace from the beginning
# of lines.
#
proc wapp-trim {txt} {
  global wapp
  regsub -all {\n\s+} [subst -nocom -novar [string trim $txt]] \n txt
  while {[regexp {^(.*?)%(html|url|qp|string|unsafe)(|%)\((.+?)\)\3(.*)$} \
          $txt all before verb m1 arg after]} {
    set arg [uplevel 1 [list subst $arg]]
    dict append wapp .reply $before[wappInt-enc-$verb $arg]
    set txt $after
  }
  dict append wapp .reply $txt
}

# There must be a wappInt-enc-NAME routine for each possible substitution
# in wapp-subst.  Thus there are routines for "html", "url", "qp", and "unsafe".
#
#    wappInt-enc-html           Escape text so that it is safe to use in the
#                               body of an HTML document.