1 # ===================================================================== 2 # groupUserVars.awk: apply user-defined name/value pairs. 3 # 4 # Copyright (c) 2010 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 delete a; delete b; delete c 24 25 split(_rcget("TNS_GROUP_MISC_PROP",7),c,":") 26 27 # Set sane defaults if necessary. 28 if ((c[1]/=1) <= 0) c[1] = 24 # default max var name length. 29 if ((c[2]/=1) <= 0) c[2] = 128 # default max var value length. 30 if ((c[3]/=1) <= 0) c[3] = 32 # default max no. of vars. 31 32 } 33 34 NR == 1 { input = $0 } 35 NR >= 2 { input = input "\n" $0 } 36 37 END { 38 39 # Neutralize any CSA tags first! This is done also by 40 # bloggerSetTemplate.awk, but it must be repeated here 41 # because the tv.xml file can be uploaded separately. 42 43 gsub(/\$\[/,"\\$[",input) 44 45 # Note that name/value defs are extracted from input regardless 46 # of whether they are enclosed inside XML comment blocks . 47 # To have them ignored they must be "broken", for example: < 48 # BlogUserVar .....> (note the blank space between "<" and 49 # "BlogUserVar"). Of course they can be broken also in many other 50 # ways, including sorrounding them with XML comment tags, such as 51 # , but this may make XML parser complain if 52 # the definition is already contained in a commented block of code. 53 54 if ((j=split(input,a,/ 1) { 55 56 # + 1 is to account for any leading garbage in array, 57 # otherwise we will accept one variable less than defined max. 58 if (j > c[3]) j = c[3] + 1 59 60 for (i=2; i<=j; i++) { 61 sub(/["'][^"'>]*>.*/,_NULL,a[i]) 62 if (split(a[i],b,/[ \t\n\r]*=[ \t\n\r]*["']/) == 2 && \ 63 b[1] !~ /^tw\./) 64 _rcset("tpl.var." substr(b[1],1,c[1]),\ 65 substr(_xmldecode(b[2]),1,c[2]), _STDOUT) 66 } 67 } 68 } 69 70 # EOF