1 # ===================================================================== 2 # pageAttachments.awk: W-TW static page-level attachment list creator. 3 # 4 # Copyright (c) 2011 Carlo Strozzi 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; version 2 dated June, 1991. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # ===================================================================== 20 21 BEGIN { 22 23 fmt = tmp = ""; delete a; delete e; delete f 24 25 # build links to recent pages. 26 27 fmt = readfmt("tw-attachments-static") 28 gsub(/%/,"%%",fmt) # turn plain '%' into '%%'. 29 gsub(/\\/,"\\\\&",fmt) # turn '\' into '\\'. 30 gsub(/[\n\r]+/,"",fmt) # just in case. 31 tmp = fmt 32 33 # Handle custom positioning of output tokens. 34 sub(/.*\[:/,_NULL,tmp); sub(/:].*/,_NULL,tmp) 35 tmp = _strip(tmp,_O_MIDDLE) 36 if (tmp !~ /^[0-3 ]+$/) tmp = "1 2 3" 37 38 # pad missing arg specs with "0". 39 if ((i=split(tmp,f," ")) < 3) { 40 while (i++ <= 3) tmp = tmp " 0" 41 i = split(tmp,f," ") 42 } 43 44 tmp = _NULL 45 46 for (j=1; j<=i; j++) { 47 if (j > 3) break # ignore excess arg specs. 48 if (!sub(//,"%s",fmt)) fmt = fmt "" 49 tmp = tmp " " f[j] 50 } 51 52 # encode any extra markers. 53 gsub(//,"\\<tw:s/\\>",fmt) 54 55 fmt = fmt "\n" 56 57 split(_strip(tmp),f," "); f[0] = 0 58 59 g_uri = _rcget("tbl_group.g_uri") 60 p_uri = _rcget("tbl_page.p_uri") 61 62 e[0] = _NULL 63 64 print "" # documentation. 65 } 66 67 /^\001/ { next } # skip table header, if any. 68 69 { 70 # k_attach, a_mtime, a_descr 71 72 split($0,a,"\t") 73 74 sub(/^wiki\//,_NULL,a[1]) # strip leading "wiki/" 75 76 # Make the listing more compact. 77 sub(/T/," ",a[2]); sub(/\+.*/,_NULL,a[2]) 78 79 # Set default description if unset. 80 if (a[3] == "") a[3] = a[1] 81 82 # Exclude entries which description field begins with "!". 83 if (a[3] ~ /^ *!/) next 84 85 e[1] = _xmlencode(a[2]) 86 e[2] = ENVIRON["CSA_RPC_URI"] "/" ENVIRON["CSA_LANG"] \ 87 "/" g_uri "/" p_uri "/wikifile/" a[1] 88 e[3] = _xmlencode(a[3]) 89 printf(fmt,e[f[1]],e[f[2]],e[f[3]]) 90 } 91 92 # EOF