diff s4-funcs.sh @ 187:7dc0918ce321

Add PIPE to handled signals
author HIROSE Yuuji <yuuji@gentei.org>
date Tue, 29 Mar 2016 10:21:55 +0900
parents 5ba50e0850c9
children b1847cc3912a
line wrap: on
line diff
--- a/s4-funcs.sh	Sat Mar 05 11:27:58 2016 +0900
+++ b/s4-funcs.sh	Tue Mar 29 10:21:55 2016 +0900
@@ -323,7 +323,10 @@
   fi >&5
   cat $sqo
 }
-
+_m4() {
+  #_S4NAME_=f,f,f
+  m4 ${_S4NAME_:+"-D_S4NAME_=${_S4NAME_}"} "$@"
+}
 ismember() {
   # $1=user, $2=group
 err ismem: "select user from grp_mem where gname=$(sqlquote $2) and user='$1';"
@@ -920,7 +923,7 @@
   
 }
 putfooter() {
-  m4 -D_TITLE_="${TITLE:-$myname}" $layout/footer.m4.html
+  _m4 -D_TITLE_="${TITLE:-$myname}" $layout/footer.m4.html
 }
 getcookie() (
   for kv in `echo $HTTP_COOKIE|sed 's/[;, ]/ /g'`; do
@@ -938,7 +941,7 @@
   # $SMAIL_TO <- Recipient value of To: header
   rcpt=`echo $1`		# strip newlines
   subj=`echo $2|nkf -jM|tr -d '\n'`
-  (m4 -D_RCPT_="${SMAIL_TO:-$rcpt}" -D_SUBJ_="\`$subj'" -D_FROM_=$admin $msgdir/mail-header.m4
+  (_m4 -D_RCPT_="${SMAIL_TO:-$rcpt}" -D_SUBJ_="\`$subj'" -D_FROM_=$admin $msgdir/mail-header.m4
    cat $3 | nkf -jd ) | sendmail -f $admin $rcpt
 }
 setviastring() {
@@ -974,7 +977,7 @@
   user=$1
   if ! checkdomain $user; then
     contenttype; echo
-    m4 -D_TITLE_='Invalid email' $layout/title-only.html
+    _m4 -D_TITLE_='Invalid email' $layout/title-only.html
     echo "ユーザ名($user)には正しいメイルアドレスが必要です。" | html p
     putfooter
     exit 0
@@ -984,7 +987,7 @@
   encpswd=`echo $newpswd|mypwhash`
   dbsetbyid user $user pswd "$encpswd"
   # Avoid $user substitution with m4, because $url comes from user input.
-  m4 -D_PSWD_="$newpswd" -D_URL_="$url" -D_ADMIN_="$admin" \
+  _m4 -D_PSWD_="$newpswd" -D_URL_="$url" -D_ADMIN_="$admin" \
      $msgdir/mail-newaccount.m4 \
       | sed "s/_USER_/$user/g" \
       | smail $user "New Account"
@@ -1017,7 +1020,7 @@
 }
 showlogin() {
   args=`echo $myargs|tr ' ' '+'`
-  m4 -D_SYSNAME_="Welcome" -D_MYNAME_="$myname${args+?}$args" \
+  _m4 -D_SYSNAME_="Welcome" -D_MYNAME_="$myname${args+?}$args" \
      $layout/login.m4.html
   exit 0
 }
@@ -1026,7 +1029,7 @@
   st=$?
   if [ $st != 0 ]; then
     contenttype; echo
-    m4 -D_USER_="$user" -D_URL_="$url" -D_ADMIN_="$admin" \
+    _m4 -D_USER_="$user" -D_URL_="$url" -D_ADMIN_="$admin" \
        $msgdir/login-fail-$st.m4.html
     showlogin			# and EXIT
   fi
@@ -1034,7 +1037,7 @@
 
 # Do instant jobs here
 dbsetup
-trap cleanup INT HUP EXIT TERM
+trap cleanup INT HUP EXIT TERM PIPE
 # trap cleanup INT HUP
 
 err() {
@@ -1159,12 +1162,12 @@
   gecos=`gecos`
   name=$user"${gecos:+($gecos)}"
   regist="$urlbase?reg+$iss"
-  m4 -D_URL_="$urlbase" \
-     -D_USER_="$name" \
-     -D_EMAIL_="$1" \
-     -D_REGIST_="$regist" \
-     -D_ADMIN_="$admin" \
-     $msgdir/mail-invite.m4 \
+  _m4 -D_URL_="$urlbase" \
+      -D_USER_="$name" \
+      -D_EMAIL_="$1" \
+      -D_REGIST_="$regist" \
+      -D_ADMIN_="$admin" \
+      $msgdir/mail-invite.m4 \
       | smail $1 "BBSへの御招待"
   return 0
 )
@@ -1203,13 +1206,13 @@
   if [ -n "$addr" ]; then
     susp="<h2>招待済みで加入待ちのアドレス</h2><pre>$addr</pre>"
   fi
-  m4 -D_TITLE_="招待" -D_REPORT_="\`$repo'" -D_ACTION_="?invite" \
-     -D_BODYCLASS_="default" -D_SUSPENDED_="$susp" \
-     $layout/html.m4.html $layout/invite.m4.html
+  _m4 -D_TITLE_="招待" -D_REPORT_="\`$repo'" -D_ACTION_="?invite" \
+      -D_BODYCLASS_="default" -D_SUSPENDED_="$susp" \
+      $layout/html.m4.html $layout/invite.m4.html
 }
 regist() {
   # $1=session-id-for-invitation
-  m4 -D_TITLE_="Invitation" $layout/html.m4.html
+  _m4 -D_TITLE_="Invitation" $layout/html.m4.html
   if [ -z "$1" ]; then
     echo "bye bye" | html p
     reutrn
@@ -1232,8 +1235,8 @@
   echo "このアドレスに初期パスワードを送信しました。"	|html p
   echo "新着メイルを確認してログインしてください。"	|html p
   addsession $1			# for removal after 1 minute
-  m4 -D_SYSNAME_="Initial Login" -D_MYNAME_="$myname?userconf" \
-     $layout/login.m4.html
+  _m4 -D_SYSNAME_="Initial Login" -D_MYNAME_="$myname?userconf" \
+      $layout/login.m4.html
   return
 }
 newgrpchk() {
@@ -1297,20 +1300,20 @@
   GF_STAGE="grpconf"
   GF_STAGE=groupupdate
   DT_VIEW=grp dumptable html grp 'gname gecos:DESC mtime:TIME' 'order by b.TIME desc' \
-  |m4 -D_TITLE_="グループ作成" \
-     -D_FORM_="$note`genform $formdir/grp.def`" \
-     -D_DUMPTABLE_="syscmd(cat)" \
-     $layout/html.m4.html $layout/form+dump.m4.html
+  |_m4 -D_TITLE_="グループ作成" \
+       -D_FORM_="$note`genform $formdir/grp.def`" \
+       -D_DUMPTABLE_="syscmd(cat)" \
+       $layout/html.m4.html $layout/form+dump.m4.html
 }
 userconf() {
   [ -n "`getpar rowid`" ] && par2table $formdir/user.def
-  m4 -D_BODYCLASS_=userconf -D_TITLE_="ユーザ情報編集" $layout/html.m4.html
+  _m4 -D_BODYCLASS_=userconf -D_TITLE_="ユーザ情報編集" $layout/html.m4.html
   GF_ACTION="?home" edittable "$formdir/user.def" "user" "$user"
 }
 groupconf() {
   # $1=rowid in grp (2015-07-21 changed from gname)
   [ -n "`getpar rowid`" ] && par2table $formdir/grp.def
-  m4 -D_BODYCLASS_=groupconf -D_TITLE_="グループ情報編集" $layout/html.m4.html
+  _m4 -D_BODYCLASS_=groupconf -D_TITLE_="グループ情報編集" $layout/html.m4.html
   #rowid=`query "select rowid from grp where gname='$1';"`
   rowid=${1%%[!A-Z0-9a-z_]*}
 err gcon \$1=$1 rowid=$rowid
@@ -1318,18 +1321,18 @@
   GF_STAGE="groupupdate" edittable "$formdir/grp.def" "grp" "$rowid"
 }
 mems() {
-  m4 -D_TITLE_="参加者一覧" -D_BODYCLASS_=listmember $layout/html.m4.html
+  _m4 -D_TITLE_="参加者一覧" -D_BODYCLASS_=listmember $layout/html.m4.html
   kwd=`getpar kwd`
   listmember $kwd
 }
 grps() {
-  m4 -D_TITLE_="グループ一覧" -D_BODYCLASS_=listgroup $layout/html.m4.html
+  _m4 -D_TITLE_="グループ一覧" -D_BODYCLASS_=listgroup $layout/html.m4.html
   kwd=`getpar kwd`
   listgroup $kwd \
-      | m4 -D_DUMPTABLE_="syscmd(cat)" \
-	   -D_TITLE_="グループ関連操作" \
-	   -D_FORM_="<a href=\"?groupman\">新規グループ作成</a>" \
-	   $layout/form+dump.m4.html
+      | _m4 -D_DUMPTABLE_="syscmd(cat)" \
+	    -D_TITLE_="グループ関連操作" \
+	    -D_FORM_="<a href=\"?groupman\">新規グループ作成</a>" \
+	    $layout/form+dump.m4.html
 }
 grp() {	# $1=group-rowid
   gpg=`getpar grp`
@@ -1343,7 +1346,7 @@
     [ -n "$jg" -a -n "$grp" ] &&
 	joingrp "$grp" "$user" "$jg" "`getpar email`"
   fi
-  echo "グループ $grp"|m4 -D_TITLE_="syscmd(\`cat')" $layout/html.m4.html
+  echo "グループ $grp"|_m4 -D_TITLE_="syscmd(\`cat')" $layout/html.m4.html
   showgroup "$grid"
 }
 listnewblogsql() { # $1=user
@@ -1437,13 +1440,13 @@
 		val='$uname';"`
   listblog $uname			> $bf
   listgroupbytable $formdir/grp.def $cond \
-      | m4 -D_BODYCLASS_=home -D_TITLE_="spaste(\`$tf')" \
-	   -D_PROFILE_="spaste(\`$pf')$conflink" \
-	   -D_PROFIMG_="spaste(\`$imf')" \
-	   -D_BLOGS_="spaste(\`$bf')" \
-	   -D_NBLOG_="$nblog" \
-	   -D_GROUPS_="syscmd(\`cat')" \
-	   $layout/html.m4.html $layout/home.m4.html
+      | _m4 -D_BODYCLASS_=home -D_TITLE_="spaste(\`$tf')" \
+	    -D_PROFILE_="spaste(\`$pf')$conflink" \
+	    -D_PROFIMG_="spaste(\`$imf')" \
+	    -D_BLOGS_="spaste(\`$bf')" \
+	    -D_NBLOG_="$nblog" \
+	    -D_GROUPS_="syscmd(\`cat')" \
+	    $layout/html.m4.html $layout/home.m4.html
   
   if [ x"$user" = x"$uname" ]; then
     # Display NEWS
@@ -1485,7 +1488,7 @@
   err commission: "$@"
   gname=`getgroupbyid $1`
   echo "グループ $gname 管理者委任" \
-      | m4 -D_TITLE_="syscmd(\`cat')" $layout/html.m4.html
+      | _m4 -D_TITLE_="syscmd(\`cat')" $layout/html.m4.html
   if [ -n "$2" ]; then
     grp_reg_adm "$@"
   else
@@ -1641,7 +1644,7 @@
     files=`getvalbyid $tbl profimg $id $dir`
     # Pick up only first icon
     echo "<div class=\"iconlist xy$thumbxy\"><p class=\"tag _$tag\">$tag</p>" \
-	| m4 $tagconv
+	| _m4 $tagconv
     if [ -n "$files" ]; then
       icon=`echo "$files"|head -1`
       iconhref $dir/$icon "$hrb+$lnk" "$gecos"
@@ -1680,10 +1683,10 @@
     tf=$tmpd/title.$$
     echo "グループ $grp" > $tf
     showgroupsub $formdir/grp.def "$1" | \
-	m4 -D_TITLE_="spaste(\`$tf')" \
-	   -D_FORM_="syscmd(\`cat')" \
-	   -D_DUMPTABLE_="" \
-	   $layout/form+dump.m4.html
+	_m4 -D_TITLE_="spaste(\`$tf')" \
+	    -D_FORM_="syscmd(\`cat')" \
+	    -D_DUMPTABLE_="" \
+	    $layout/form+dump.m4.html
   else				# if $grp is removed at par2table
     listgroup
   fi
@@ -1785,7 +1788,7 @@
     echo "加入者のみに許可された操作です。" | html p; return
   fi
   echo "グループ $grp 個別選択操作" \
-      | m4 -D_TITLE_="syscmd(\`cat')" $layout/html.m4.html
+      | _m4 -D_TITLE_="syscmd(\`cat')" $layout/html.m4.html
 
   isowner=""
   isgrpowner "$user" "$grp" && isowner="yes"
@@ -1902,10 +1905,10 @@
   cgi_form grpaction<<EOF \
       	| sed  -e "s|^\(<TR><TD>\)k\([0-9]*\),\([^<]*\)|\1$ba\2$b2\3$b3|" \
 	       -e "s|^\(<TR><TD>\)\([0-9]*\),\([^<]*\)|\1$b1\2$b2\3$b3|" \
-	| m4 -D_TITLE_="spaste(\`$tf')" \
-	     -D_SUBTITLE_="チェック後操作ボタン" \
-	     -D_FORM_="syscmd(cat)" -D_DUMPTABLE_="" \
-	     $layout/form+dump.m4.html
+	| _m4 -D_TITLE_="spaste(\`$tf')" \
+	      -D_SUBTITLE_="チェック後操作ボタン" \
+	      -D_FORM_="syscmd(cat)" -D_DUMPTABLE_="" \
+	      $layout/form+dump.m4.html
 <div class="fold">
 `cgi_radio rm send id="sendmsg"`<label
  for="sendmsg">下でチェックした人にメッセージを送信する</label>
@@ -1930,11 +1933,11 @@
   owner=`getvalbyid blog owner $rowid`
   title=`getvalbyid blog title $rowid`
   GF_ACTION="?blog" edittable $formdir/blog.def blog $rowid \
-      | m4 -D_TITLE_="修正" \
-	   -D_SUBTITLE_="[$title]@$owner" -D_DIARY_="" \
-	   -D_BLOGS_="" -D_DUMPTABLE_="" \
-	   -D_FORM_="syscmd(\`cat')" \
-	   $layout/html.m4.html $layout/form+dump.m4.html
+      | _m4 -D_TITLE_="修正" \
+	    -D_SUBTITLE_="[$title]@$owner" -D_DIARY_="" \
+	    -D_BLOGS_="" -D_DUMPTABLE_="" \
+	    -D_FORM_="syscmd(\`cat')" \
+	    $layout/html.m4.html $layout/form+dump.m4.html
 }
 editart() {	# $1=article-rowid $2=blogrowid
   rowid=${1%%[!A-Z0-9a-z_]*}
@@ -1960,11 +1963,11 @@
 	   > $tmpout
   rm -f /tmp/editart.out
   # Cannot use pipelining to m4 with genform() because of stdin stack
-  m4 -D_TITLE_="コメントの修正" -D_DIARY_="" \
-	   -D_FORM_="syscmd(cat $tmpout)" \
-	   -D_SUBTITLE_="`gecos $owner`の「$title」" \
-	   -D_BLOGS_= -D_DUMPTABLE_= \
-	   $layout/html.m4.html $layout/form+dump.m4.html
+  _m4 -D_TITLE_="コメントの修正" -D_DIARY_="" \
+      -D_FORM_="syscmd(cat $tmpout)" \
+      -D_SUBTITLE_="`gecos $owner`の「$title」" \
+      -D_BLOGS_= -D_DUMPTABLE_= \
+      $layout/html.m4.html $layout/form+dump.m4.html
 }
 send2mem() {
   rowid=`getpar grp`
@@ -2003,7 +2006,7 @@
   t_usr=`session=$2 getpar user`
   t_grp=`session=$2 getpar group`
   err joingrpadmit: t_usr=$t_usr, t_grp=$t_grp
-  m4 -D_TITLE_="joingrp" $layout/html.m4.html
+  _m4 -D_TITLE_="joingrp" $layout/html.m4.html
   if [ -z "$t_usr" -o -z "$t_grp" ]; then
     echo "無効な加入依頼です。" | html p
     echo "有効期限が切れたか、
@@ -2743,27 +2746,27 @@
   query "select rowid from $tbl order by rowid desc;" \
       | while read rowid; do
 	  viewtable $1 $tbl $rowid
-	done | m4 -D_TITLE_="$tbl" \
-		  -D_FORM_="`genform $1`" \
-		  -D_DUMPTABLE_="syscmd(cat)" \
-		  $layout/html.m4.html $layout/form+dump.m4.html
+	done | _m4 -D_TITLE_="$tbl" \
+		   -D_FORM_="`genform $1`" \
+		   -D_DUMPTABLE_="syscmd(cat)" \
+		   $layout/html.m4.html $layout/form+dump.m4.html
 }
 default_viewtext() {	# $1=def-file
   ### DT_VIEW="edittable+$tbl" dumptable html $tbl "$cols" \
   default_storedb "$@"
   DT_VIEW="viewtable+$tbl" dumptable html $tbl "name memo file" \
-      | m4 -D_TITLE_="$tbl" \
-	   -D_FORM_="`genform $1`" \
-	   -D_DUMPTABLE_="syscmd(cat)" \
-	   $layout/html.m4.html $layout/form+dump.m4.html
+      | _m4 -D_TITLE_="$tbl" \
+	    -D_FORM_="`genform $1`" \
+	    -D_DUMPTABLE_="syscmd(cat)" \
+	    $layout/html.m4.html $layout/form+dump.m4.html
 }
 default_smail() {
   default_storedb "$@"
   if [ $? -eq 2 ]; then
-    m4 -D_TITLE_="入力" \
-       -D_FORM_="`genform $1`" \
-       -D_DUMPTABLE_="" \
-       $layout/html.m4.html $layout/form+dump.m4.html
+    _m4 -D_TITLE_="入力" \
+	-D_FORM_="`genform $1`" \
+	-D_DUMPTABLE_="" \
+	$layout/html.m4.html $layout/form+dump.m4.html
     return
   fi
   cond=""
@@ -2806,7 +2809,7 @@
   ) | (cd $tmpd &&
 	    err LS="`ls -lF`" &&
 	    $mydir/sendmultipart.sh -t "$admin" -s "$subj" $files)
-  m4 -D_TITLE_="入力完了" $layout/html.m4.html
+  _m4 -D_TITLE_="入力完了" $layout/html.m4.html
   echo "以下の内容で送信しました。" | html p
   viewtable $1 $tbl \
 	    `query "select rowid from $tbl order by rowid desc limit 1;"`

yatex.org