1 # ===================================================================== 2 # mtGetCategoryList.awk: Movable Type API. 3 # 4 # Copyright (c) 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 delete a; delete b 24 25 printf("\n") 26 } 27 28 /^\001/ { next } # skip table header, if any. 29 30 { 31 # k_page, p_name, p_descr 32 33 split($0,a,"\t") # split each record into fields. 34 35 split(a[2],b,".") # page category name, if any. 36 37 # Note that we do not need to test for redirected/hidden/restricted 38 # pages here, and possibly skip them, because categories exist regardless 39 # of what the pages belonging into them may contain. Also note that 40 # the MetaWeblog API specs are debatable regarding the getCategories 41 # method, as reported in many places, among which: 42 # 43 # http://www.truerwords.net/articles/web-tech/metaweblog.getrecentposts.html 44 # http://roy.tabulas.com/2008/04/02/xml-rpc-interfaces-and-standards-oh-yeah/ 45 # 46 # I am currently sticking to the widely adopted interpretation of 47 # returning an array of structs as the result, but the original specs 48 # (which nobody seems to implement except maybe Userland's Radio), say 49 # that a struct of structs should be returned. See the specs at 50 # http://www.xmlrpc.com/metaWeblogApi . 51 # 52 # OTOH, even if one wanted to stick to the specs and return a struct of 53 # structs, it is not at all clear how this could possibly be accomplished, 54 # since a struct is an unordered list of name/value pairs, and the specs 55 # do not tell what names should be used in the outer struct. 56 57 print "\n\n" \ 58 "\n" \ 59 "categoryId\n" \ 60 "" unixify(b[1]) "\n" \ 61 "\n" \ 62 "\n" \ 63 "categoryName\n" \ 64 "" _xmlencode(b[1]) "\n" \ 65 "" 66 67 printf("") 68 69 } 70 71 END { 72 73 print "\n\n" 74 } 75 76 # EOF