1 # ===================================================================== 2 # genCalendar.awk: W-TW calendar applet generator. 3 # 4 # Copyright (c) 2007,2008 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 cal=tmp=""; i=j=x=y=0; delete a 24 25 url = ENVIRON["CSA_RPC_URI"] "/" \ 26 ENVIRON["CSA_LANG"] "/" _rcget("tbl_group.g_uri") "/" 27 } 28 29 /^\001/ { next } # skip table header, if any. 30 31 { 32 # p_uri, p_vtime, p_descr 33 34 split($0,a,"\t") # split each record into fields. 35 36 # Pages with nil descriptions are excluded from this view. 37 if (a[3] ~ /^ *-/) next 38 39 # strip ranking. 40 sub(/^.*,/,"",a[2]) 41 42 # retain only day no. 43 sub(/.*-/,"",a[2]); sub(/ .*/,"",a[2]) 44 45 a[2]/=1 # drop any leading "0" 46 47 # retain only the most recent link for a day. 48 if (page[a[2]] == "") page[a[2]] = a[1] 49 } 50 51 END { 52 while (getline tmp < ENVIRON["gencal_cal"] > 0) { 53 j=0 54 sub(/^ */,"",tmp); sub(/ *$/,"",tmp) 55 if (tmp == "") break 56 # turn "april" into "April", etc. 57 if (++i==1) cal = "" \ 58 toupper(substr(tmp,1,1)) substr(tmp,2) "" 59 else if (i==2) { 60 x = split(tmp,a,/ +/) 61 for (y=1; y<=x; y++) { 62 # turn "mo" into "Mo", etc. 63 a[y] = toupper(substr(a[y],1,1)) tolower(substr(a[y],2)) 64 if (y==1) tmp = a[y] 65 else tmp = tmp " " a[y] 66 } 67 gsub(/ /,"",tmp) 68 cal=cal "\n" tmp "" 69 } 70 else if (i==3) { 71 x = split(tmp,a,/ +/) 72 for (y=1; y<=x; y++) { 73 if (page[a[y]] != "") 74 link = "" a[y] "" 76 else link = a[y] 77 if (y==1) tmp = link 78 else tmp = tmp " " link 79 } 80 while (sub(/ +/,"",tmp)) j++ 81 j = 7-j 82 while (--j > 0) tmp = "" tmp 83 cal = cal "\n" tmp "" 84 } 85 else { 86 x = split(tmp,a,/ +/) 87 for (y=1; y<=x; y++) { 88 if (page[a[y]] != "") 89 link = "" a[y] "" 91 else link = a[y] 92 if (y==1) tmp = link 93 else tmp = tmp " " link 94 } 95 j = gsub(/ +/,"",tmp) 96 while (++j < 7) tmp = tmp "" 97 cal = cal "\n" tmp "" 98 } 99 } 100 101 close(ENVIRON["gencal_cal"]) 102 103 gsub(/\001/," ",cal) 104 print cal 105 } 106 107 # EOF