Hex Artifact Content
Not logged in

Artifact 00e0d408b7eef3699b49fc6fef60b6ef598d7f56:

File src/tagview.c part of check-in [2cb3290e67] - Fixed a memory leak in tagview_page_list_tags(). Minor other refactorings. by stephan on 2008-02-03 18:00:27.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68  (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 20 43 6f 70 79  ard Hipp.** Copy
0030: 72 69 67 68 74 20 28 63 29 20 32 30 30 38 20 53  right (c) 2008 S
0040: 74 65 70 68 61 6e 20 42 65 61 6c 0a 2a 2a 0a 2a  tephan Beal.**.*
0050: 2a 20 54 68 69 73 20 70 72 6f 67 72 61 6d 20 69  * This program i
0060: 73 20 66 72 65 65 20 73 6f 66 74 77 61 72 65 3b  s free software;
0070: 20 79 6f 75 20 63 61 6e 20 72 65 64 69 73 74 72   you can redistr
0080: 69 62 75 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a  ibute it and/or.
0090: 2a 2a 20 6d 6f 64 69 66 79 20 69 74 20 75 6e 64  ** modify it und
00a0: 65 72 20 74 68 65 20 74 65 72 6d 73 20 6f 66 20  er the terms of 
00b0: 74 68 65 20 47 4e 55 20 47 65 6e 65 72 61 6c 20  the GNU General 
00c0: 50 75 62 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73  Public.** Licens
00d0: 65 20 61 73 20 70 75 62 6c 69 73 68 65 64 20 62  e as published b
00e0: 79 20 74 68 65 20 46 72 65 65 20 53 6f 66 74 77  y the Free Softw
00f0: 61 72 65 20 46 6f 75 6e 64 61 74 69 6f 6e 3b 20  are Foundation; 
0100: 65 69 74 68 65 72 0a 2a 2a 20 76 65 72 73 69 6f  either.** versio
0110: 6e 20 32 20 6f 66 20 74 68 65 20 4c 69 63 65 6e  n 2 of the Licen
0120: 73 65 2c 20 6f 72 20 28 61 74 20 79 6f 75 72 20  se, or (at your 
0130: 6f 70 74 69 6f 6e 29 20 61 6e 79 20 6c 61 74 65  option) any late
0140: 72 20 76 65 72 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a  r version..**.**
0150: 20 54 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73   This program is
0160: 20 64 69 73 74 72 69 62 75 74 65 64 20 69 6e 20   distributed in 
0170: 74 68 65 20 68 6f 70 65 20 74 68 61 74 20 69 74  the hope that it
0180: 20 77 69 6c 6c 20 62 65 20 75 73 65 66 75 6c 2c   will be useful,
0190: 0a 2a 2a 20 62 75 74 20 57 49 54 48 4f 55 54 20  .** but WITHOUT 
01a0: 41 4e 59 20 57 41 52 52 41 4e 54 59 3b 20 77 69  ANY WARRANTY; wi
01b0: 74 68 6f 75 74 20 65 76 65 6e 20 74 68 65 20 69  thout even the i
01c0: 6d 70 6c 69 65 64 20 77 61 72 72 61 6e 74 79 20  mplied warranty 
01d0: 6f 66 0a 2a 2a 20 4d 45 52 43 48 41 4e 54 41 42  of.** MERCHANTAB
01e0: 49 4c 49 54 59 20 6f 72 20 46 49 54 4e 45 53 53  ILITY or FITNESS
01f0: 20 46 4f 52 20 41 20 50 41 52 54 49 43 55 4c 41   FOR A PARTICULA
0200: 52 20 50 55 52 50 4f 53 45 2e 20 20 53 65 65 20  R PURPOSE.  See 
0210: 74 68 65 20 47 4e 55 0a 2a 2a 20 47 65 6e 65 72  the GNU.** Gener
0220: 61 6c 20 50 75 62 6c 69 63 20 4c 69 63 65 6e 73  al Public Licens
0230: 65 20 66 6f 72 20 6d 6f 72 65 20 64 65 74 61 69  e for more detai
0240: 6c 73 2e 0a 2a 2a 0a 2a 2a 20 59 6f 75 20 73 68  ls..**.** You sh
0250: 6f 75 6c 64 20 68 61 76 65 20 72 65 63 65 69 76  ould have receiv
0260: 65 64 20 61 20 63 6f 70 79 20 6f 66 20 74 68 65  ed a copy of the
0270: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
0280: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61  lic.** License a
0290: 6c 6f 6e 67 20 77 69 74 68 20 74 68 69 73 20 6c  long with this l
02a0: 69 62 72 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20  ibrary; if not, 
02b0: 77 72 69 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20  write to the.** 
02c0: 46 72 65 65 20 53 6f 66 74 77 61 72 65 20 46 6f  Free Software Fo
02d0: 75 6e 64 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20  undation, Inc., 
02e0: 35 39 20 54 65 6d 70 6c 65 20 50 6c 61 63 65 20  59 Temple Place 
02f0: 2d 20 53 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20  - Suite 330,.** 
0300: 42 6f 73 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31  Boston, MA  0211
0310: 31 2d 31 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a  1-1307, USA..**.
0320: 2a 2a 20 41 75 74 68 6f 72 20 63 6f 6e 74 61 63  ** Author contac
0330: 74 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a  t information:.*
0340: 2a 20 20 20 64 72 68 40 68 77 61 63 69 2e 63 6f  *   drh@hwaci.co
0350: 6d 0a 2a 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77  m.**   http://ww
0360: 77 2e 68 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f  w.hwaci.com/drh/
0370: 0a 2a 2a 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .**.************
0380: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0390: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
03a0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
03b0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
03c0: 2a 2a 2a 0a 2a 2a 0a 2a 2a 20 49 6d 70 6c 65 6d  ***.**.** Implem
03d0: 65 6e 74 61 74 69 6f 6e 20 6f 66 20 74 68 65 20  entation of the 
03e0: 54 61 67 20 56 69 65 77 20 70 61 67 65 0a 2a 2f  Tag View page.*/
03f0: 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73 73 65 72  .#include <asser
0400: 74 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 22 63  t.h>.#include "c
0410: 6f 6e 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75 64  onfig.h".#includ
0420: 65 20 22 74 61 67 76 69 65 77 2e 68 22 0a 0a 0a  e "tagview.h"...
0430: 23 69 66 20 31 0a 23 20 20 64 65 66 69 6e 65 20  #if 1.#  define 
0440: 54 41 47 56 49 45 57 5f 44 45 46 41 55 4c 54 5f  TAGVIEW_DEFAULT_
0450: 46 49 4c 54 45 52 20 22 41 4e 44 20 74 2e 74 61  FILTER "AND t.ta
0460: 67 6e 61 6d 65 20 4e 4f 54 20 47 4c 4f 42 20 27  gname NOT GLOB '
0470: 77 69 6b 69 2d 2a 27 20 22 0a 23 65 6c 73 65 0a  wiki-*' ".#else.
0480: 23 20 20 64 65 66 69 6e 65 20 54 41 47 56 49 45  #  define TAGVIE
0490: 57 5f 44 45 46 41 55 4c 54 5f 46 49 4c 54 45 52  W_DEFAULT_FILTER
04a0: 0a 23 65 6e 64 69 66 0a 0a 0a 2f 2a 2a 0a 74 61  .#endif.../**.ta
04b0: 67 76 69 65 77 5f 73 74 72 78 66 6f 72 6d 5f 66  gview_strxform_f
04c0: 20 69 73 20 61 20 74 79 70 65 64 65 66 20 66 6f   is a typedef fo
04d0: 72 20 66 75 6e 63 73 20 77 69 74 68 20 74 68 65  r funcs with the
04e0: 20 66 6f 6c 6c 6f 77 69 6e 67 20 70 6f 6c 69 63   following polic
04f0: 79 3a 0a 0a 54 68 65 79 20 61 63 63 65 70 74 20  y:..They accept 
0500: 61 20 63 6f 6e 73 74 20 73 74 72 69 6e 67 20 77  a const string w
0510: 68 69 63 68 20 74 68 65 79 20 74 68 65 6e 20 74  hich they then t
0520: 72 61 6e 73 66 6f 72 6d 20 69 6e 74 6f 20 73 6f  ransform into so
0530: 6d 65 20 6f 74 68 65 72 0a 66 6f 72 6d 2e 20 54  me other.form. T
0540: 68 65 79 20 72 65 74 75 72 6e 20 61 20 74 72 61  hey return a tra
0550: 6e 73 66 6f 72 6d 65 64 20 63 6f 70 79 2c 20 77  nsformed copy, w
0560: 68 69 63 68 20 74 68 65 20 63 61 6c 6c 65 72 20  hich the caller 
0570: 69 73 20 72 65 73 70 6f 6e 73 69 62 6c 65 0a 66  is responsible.f
0580: 6f 72 20 66 72 65 65 69 6e 67 2e 0a 0a 54 68 65  or freeing...The
0590: 20 69 6e 74 65 6e 74 69 6f 6e 20 6f 66 20 74 68   intention of th
05a0: 69 73 20 69 73 20 74 6f 20 70 72 6f 76 69 64 65  is is to provide
05b0: 20 61 20 77 61 79 20 66 6f 72 20 61 20 67 65 6e   a way for a gen
05c0: 65 72 69 63 20 71 75 65 72 79 20 72 6f 75 74 69  eric query routi
05d0: 6e 65 0a 74 6f 20 66 6f 72 6d 61 74 20 73 70 65  ne.to format spe
05e0: 63 69 66 69 63 20 63 6f 6c 75 6d 6e 20 64 61 74  cific column dat
05f0: 61 20 28 65 2e 67 2e 20 74 72 61 6e 73 66 6f 72  a (e.g. transfor
0600: 6d 20 61 6e 20 6f 62 6a 65 63 74 20 49 44 20 69  m an object ID i
0610: 6e 74 6f 20 61 0a 6c 69 6e 6b 20 74 6f 20 74 68  nto a.link to th
0620: 61 74 20 6f 62 6a 65 63 74 29 2e 0a 2a 2f 0a 74  at object)..*/.t
0630: 79 70 65 64 65 66 20 63 68 61 72 20 2a 20 28 2a  ypedef char * (*
0640: 74 61 67 76 69 65 77 5f 73 74 72 78 66 6f 72 6d  tagview_strxform
0650: 5f 66 29 28 20 63 68 61 72 20 63 6f 6e 73 74 20  _f)( char const 
0660: 2a 20 29 3b 0a 0a 23 69 66 20 30 0a 2f 2a 2a 20  * );..#if 0./** 
0670: 41 20 6e 6f 2d 6f 70 20 74 72 61 6e 73 66 6f 72  A no-op transfor
0680: 6d 65 72 20 77 68 69 63 68 20 63 61 6e 20 62 65  mer which can be
0690: 20 75 73 65 64 20 61 73 20 61 20 70 6c 61 63 65   used as a place
06a0: 68 6f 6c 64 65 72 2e 20 2a 2f 0a 73 74 61 74 69  holder. */.stati
06b0: 63 20 63 68 61 72 20 2a 20 74 61 67 76 69 65 77  c char * tagview
06c0: 5f 78 66 5f 63 6f 70 79 28 20 63 68 61 72 20 63  _xf_copy( char c
06d0: 6f 6e 73 74 20 2a 20 75 75 69 64 20 29 0a 7b 0a  onst * uuid ).{.
06e0: 20 20 69 6e 74 20 6c 65 6e 20 3d 20 73 74 72 6c    int len = strl
06f0: 65 6e 28 75 75 69 64 29 20 2b 20 31 3b 0a 20 20  en(uuid) + 1;.  
0700: 63 68 61 72 20 2a 20 72 65 74 20 3d 20 28 63 68  char * ret = (ch
0710: 61 72 20 2a 29 20 6d 61 6c 6c 6f 63 28 20 6c 65  ar *) malloc( le
0720: 6e 20 29 3b 0a 20 20 72 65 74 5b 6c 65 6e 5d 20  n );.  ret[len] 
0730: 3d 20 27 5c 30 27 3b 0a 20 20 73 74 72 6e 63 70  = '\0';.  strncp
0740: 79 28 20 72 65 74 2c 20 75 75 69 64 2c 20 6c 65  y( ret, uuid, le
0750: 6e 2d 31 20 29 3b 0a 20 20 72 65 74 75 72 6e 20  n-1 );.  return 
0760: 72 65 74 3b 0a 7d 0a 23 65 6e 64 69 66 0a 0a 2f  ret;.}.#endif../
0770: 2a 2a 20 52 65 74 75 72 6e 73 20 61 20 68 79 70  ** Returns a hyp
0780: 65 72 6c 69 6e 6b 20 74 6f 20 75 75 69 64 2e 20  erlink to uuid. 
0790: 2a 2f 0a 73 74 61 74 69 63 20 63 68 61 72 20 2a  */.static char *
07a0: 20 74 61 67 76 69 65 77 5f 78 66 5f 6c 69 6e 6b   tagview_xf_link
07b0: 5f 74 6f 5f 75 75 69 64 28 20 63 68 61 72 20 63  _to_uuid( char c
07c0: 6f 6e 73 74 20 2a 20 75 75 69 64 20 29 0a 7b 0a  onst * uuid ).{.
07d0: 20 20 63 6f 6e 73 74 20 69 6e 74 20 6f 66 66 73    const int offs
07e0: 65 74 20 3d 20 31 30 3b 0a 20 20 63 68 61 72 20  et = 10;.  char 
07f0: 73 68 6f 72 74 6e 61 6d 65 5b 6f 66 66 73 65 74  shortname[offset
0800: 2b 31 5d 3b 0a 20 20 73 68 6f 72 74 6e 61 6d 65  +1];.  shortname
0810: 5b 6f 66 66 73 65 74 5d 20 3d 20 27 5c 30 27 3b  [offset] = '\0';
0820: 0a 20 20 6d 65 6d 63 70 79 28 20 73 68 6f 72 74  .  memcpy( short
0830: 6e 61 6d 65 2c 20 75 75 69 64 2c 20 6f 66 66 73  name, uuid, offs
0840: 65 74 20 29 3b 0a 20 20 72 65 74 75 72 6e 20 6d  et );.  return m
0850: 70 72 69 6e 74 66 28 20 22 3c 74 74 3e 3c 61 20  printf( "<tt><a 
0860: 68 72 65 66 3d 27 25 73 2f 76 69 6e 66 6f 2f 25  href='%s/vinfo/%
0870: 73 27 3e 3c 73 70 61 6e 20 73 74 79 6c 65 3d 27  s'><span style='
0880: 66 6f 6e 74 2d 73 69 7a 65 3a 31 2e 35 65 6d 27  font-size:1.5em'
0890: 3e 25 73 3c 2f 73 70 61 6e 3e 25 73 3c 2f 61 3e  >%s</span>%s</a>
08a0: 3c 2f 74 74 3e 22 2c 0a 20 20 20 20 20 20 20 20  </tt>",.        
08b0: 20 20 20 20 20 20 20 20 20 20 67 2e 7a 42 61 73            g.zBas
08c0: 65 55 52 4c 2c 20 75 75 69 64 2c 20 73 68 6f 72  eURL, uuid, shor
08d0: 74 6e 61 6d 65 2c 20 75 75 69 64 2b 6f 66 66 73  tname, uuid+offs
08e0: 65 74 20 29 3b 0a 7d 0a 0a 2f 2a 2a 20 52 65 74  et );.}../** Ret
08f0: 75 72 6e 73 20 61 20 68 79 70 65 72 6c 69 6e 6b  urns a hyperlink
0900: 20 74 6f 20 74 68 65 20 67 69 76 65 6e 20 74 61   to the given ta
0910: 67 2e 20 2a 2f 0a 73 74 61 74 69 63 20 63 68 61  g. */.static cha
0920: 72 20 2a 20 74 61 67 76 69 65 77 5f 78 66 5f 6c  r * tagview_xf_l
0930: 69 6e 6b 5f 74 6f 5f 74 61 67 69 64 28 20 63 68  ink_to_tagid( ch
0940: 61 72 20 63 6f 6e 73 74 20 2a 20 74 61 67 69 64  ar const * tagid
0950: 20 29 0a 7b 0a 20 20 72 65 74 75 72 6e 20 6d 70   ).{.  return mp
0960: 72 69 6e 74 66 28 20 22 3c 61 20 68 72 65 66 3d  rintf( "<a href=
0970: 27 25 73 2f 74 61 67 76 69 65 77 3f 74 61 67 69  '%s/tagview?tagi
0980: 64 3d 25 73 27 3e 25 73 3c 2f 61 3e 22 2c 0a 20  d=%s'>%s</a>",. 
0990: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
09a0: 20 67 2e 7a 42 61 73 65 55 52 4c 2c 20 74 61 67   g.zBaseURL, tag
09b0: 69 64 2c 20 74 61 67 69 64 20 29 3b 0a 7d 0a 0a  id, tagid );.}..
09c0: 2f 2a 2a 20 52 65 74 75 72 6e 73 20 61 20 68 79  /** Returns a hy
09d0: 70 65 72 6c 69 6e 6b 20 74 6f 20 74 68 65 20 6e  perlink to the n
09e0: 61 6d 65 64 20 74 61 67 2e 20 2a 2f 0a 73 74 61  amed tag. */.sta
09f0: 74 69 63 20 63 68 61 72 20 2a 20 74 61 67 76 69  tic char * tagvi
0a00: 65 77 5f 78 66 5f 6c 69 6e 6b 5f 74 6f 5f 74 61  ew_xf_link_to_ta
0a10: 67 6e 61 6d 65 28 20 63 68 61 72 20 63 6f 6e 73  gname( char cons
0a20: 74 20 2a 20 74 61 67 69 64 20 29 0a 7b 0a 20 20  t * tagid ).{.  
0a30: 72 65 74 75 72 6e 20 6d 70 72 69 6e 74 66 28 20  return mprintf( 
0a40: 22 3c 61 20 68 72 65 66 3d 27 25 73 2f 74 61 67  "<a href='%s/tag
0a50: 76 69 65 77 2f 25 73 27 3e 25 73 3c 2f 61 3e 22  view/%s'>%s</a>"
0a60: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,.              
0a70: 20 20 20 20 67 2e 7a 42 61 73 65 55 52 4c 2c 20      g.zBaseURL, 
0a80: 74 61 67 69 64 2c 20 74 61 67 69 64 20 29 3b 0a  tagid, tagid );.
0a90: 7d 0a 0a 0a 0a 2f 2a 2a 0a 2a 20 74 61 67 76 69  }..../**.* tagvi
0aa0: 65 77 5f 72 75 6e 5f 71 75 65 72 79 28 29 3a 0a  ew_run_query():.
0ab0: 2a 0a 2a 20 41 20 76 65 72 79 20 70 72 69 6d 69  *.* A very primi
0ac0: 74 69 76 65 20 68 65 6c 70 65 72 20 74 6f 20 72  tive helper to r
0ad0: 75 6e 20 61 6e 20 53 51 4c 20 71 75 65 72 79 20  un an SQL query 
0ae0: 61 6e 64 20 74 61 62 6c 65 2d 69 7a 65 20 74 68  and table-ize th
0af0: 65 0a 2a 20 72 65 73 75 6c 74 73 2e 0a 2a 0a 2a  e.* results..*.*
0b00: 20 54 68 65 20 73 71 6c 20 70 61 72 61 6d 65 74   The sql paramet
0b10: 65 72 20 73 68 6f 75 6c 64 20 62 65 20 61 20 73  er should be a s
0b20: 69 6e 67 6c 65 2c 20 63 6f 6d 70 6c 65 74 65 20  ingle, complete 
0b30: 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a  SQL statement..*
0b40: 0a 2a 20 54 68 65 20 63 6f 6c 6e 20 70 61 72 61  .* The coln para
0b50: 6d 65 74 65 72 20 69 73 20 6f 70 74 69 6f 6e 61  meter is optiona
0b60: 6c 20 28 69 74 20 6d 61 79 20 62 65 20 30 29 2e  l (it may be 0).
0b70: 20 49 66 20 69 74 20 69 73 20 30 20 74 68 65 6e   If it is 0 then
0b80: 20 74 68 65 0a 2a 20 63 6f 6c 75 6d 6e 20 6e 61   the.* column na
0b90: 6d 65 73 20 75 73 65 64 20 69 6e 20 74 68 65 20  mes used in the 
0ba0: 6f 75 74 70 75 74 20 77 69 6c 6c 20 62 65 20 74  output will be t
0bb0: 61 6b 65 6e 20 64 69 72 65 63 74 6c 79 20 66 72  aken directly fr
0bc0: 6f 6d 20 74 68 65 0a 2a 20 53 51 4c 2e 20 49 66  om the.* SQL. If
0bd0: 20 69 74 20 69 73 20 6e 6f 74 20 6e 75 6c 6c 20   it is not null 
0be0: 74 68 65 6e 20 69 74 20 6d 75 73 74 20 68 61 76  then it must hav
0bf0: 65 20 61 73 20 6d 61 6e 79 20 65 6e 74 72 69 65  e as many entrie
0c00: 73 20 61 73 20 74 68 65 20 53 51 4c 0a 2a 20 72  s as the SQL.* r
0c10: 65 73 75 6c 74 20 68 61 73 20 63 6f 6c 75 6d 6e  esult has column
0c20: 73 2e 20 45 61 63 68 20 65 6e 74 72 79 20 69 73  s. Each entry is
0c30: 20 61 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 20 66   a column name f
0c40: 6f 72 20 74 68 65 20 53 51 4c 20 72 65 73 75 6c  or the SQL resul
0c50: 74 0a 2a 20 63 6f 6c 75 6d 6e 20 6f 66 20 74 68  t.* column of th
0c60: 65 20 73 61 6d 65 20 69 6e 64 65 78 2e 20 41 6e  e same index. An
0c70: 79 20 67 69 76 65 6e 20 65 6e 74 72 79 20 6d 61  y given entry ma
0c80: 79 20 62 65 20 30 2c 20 69 6e 20 77 68 69 63 68  y be 0, in which
0c90: 20 63 61 73 65 0a 2a 20 74 68 65 20 63 6f 6c 75   case.* the colu
0ca0: 6d 6e 20 6e 61 6d 65 20 66 72 6f 6d 20 74 68 65  mn name from the
0cb0: 20 53 51 4c 20 69 73 20 75 73 65 64 2e 0a 2a 0a   SQL is used..*.
0cc0: 2a 20 54 68 65 20 78 66 6f 72 6d 20 61 72 67 75  * The xform argu
0cd0: 6d 65 6e 74 20 69 73 20 61 6e 20 61 72 72 61 79  ment is an array
0ce0: 20 6f 66 20 74 72 61 6e 73 66 6f 72 6d 61 74 69   of transformati
0cf0: 6f 6e 20 66 75 6e 63 74 69 6f 6e 73 20 28 74 79  on functions (ty
0d00: 70 65 0a 2a 20 74 61 67 76 69 65 77 5f 73 74 72  pe.* tagview_str
0d10: 78 66 6f 72 6d 5f 66 29 2e 20 54 68 65 20 61 72  xform_f). The ar
0d20: 72 61 79 2c 20 6f 72 20 61 6e 79 20 73 69 6e 67  ray, or any sing
0d30: 6c 65 20 65 6e 74 72 79 2c 20 6d 61 79 20 62 65  le entry, may be
0d40: 20 30 2c 20 62 75 74 0a 2a 20 69 66 20 74 68 65   0, but.* if the
0d50: 20 61 72 72 61 79 20 69 73 20 6e 6f 6e 2d 30 20   array is non-0 
0d60: 74 68 65 6e 20 69 74 20 6d 75 73 74 20 68 61 76  then it must hav
0d70: 65 20 61 74 20 6c 65 61 73 74 20 61 73 20 6d 61  e at least as ma
0d80: 6e 79 20 65 6e 74 72 69 65 73 20 61 73 0a 2a 20  ny entries as.* 
0d90: 63 6f 6c 6e 61 6d 65 73 20 64 6f 65 73 2e 20 45  colnames does. E
0da0: 61 63 68 20 69 6e 64 65 78 20 63 6f 72 72 65 73  ach index corres
0db0: 70 6f 6e 64 73 20 64 69 72 65 63 74 6c 79 20 74  ponds directly t
0dc0: 6f 20 61 6e 20 65 6e 74 72 79 20 69 6e 0a 2a 20  o an entry in.* 
0dd0: 63 6f 6c 6e 61 6d 65 73 20 61 6e 64 20 74 68 65  colnames and the
0de0: 20 53 51 4c 20 72 65 73 75 6c 74 73 2e 20 20 41   SQL results.  A
0df0: 6e 79 20 67 69 76 65 6e 20 65 6e 74 72 79 20 6d  ny given entry m
0e00: 61 79 20 62 65 20 30 2e 20 49 66 20 69 74 20 68  ay be 0. If it h
0e10: 61 73 0a 2a 20 66 65 77 65 72 2c 20 75 6e 64 65  as.* fewer, unde
0e20: 66 69 6e 65 64 20 62 65 68 61 76 69 6f 75 72 20  fined behaviour 
0e30: 72 65 73 75 6c 74 73 2e 20 20 49 66 20 61 20 63  results.  If a c
0e40: 6f 6c 75 6d 6e 20 68 61 73 20 61 6e 20 65 6e 74  olumn has an ent
0e50: 72 79 20 69 6e 0a 2a 20 78 66 6f 72 6d 2c 20 74  ry in.* xform, t
0e60: 68 65 6e 20 74 68 65 20 78 66 6f 72 6d 20 66 75  hen the xform fu
0e70: 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 62 65 20 63  nction will be c
0e80: 61 6c 6c 65 64 20 74 6f 20 74 72 61 6e 73 66 6f  alled to transfo
0e90: 72 6d 20 74 68 65 0a 2a 20 63 6f 6c 75 6d 6e 20  rm the.* column 
0ea0: 64 61 74 61 20 62 65 66 6f 72 65 20 72 65 6e 64  data before rend
0eb0: 65 72 69 6e 67 20 69 74 2e 20 54 68 69 73 20 66  ering it. This f
0ec0: 75 6e 63 74 69 6f 6e 20 74 61 6b 65 73 20 63 61  unction takes ca
0ed0: 72 65 20 6f 66 20 66 72 65 65 69 6e 67 0a 2a 20  re of freeing.* 
0ee0: 74 68 65 20 73 74 72 69 6e 67 73 20 63 72 65 61  the strings crea
0ef0: 74 65 64 20 62 79 20 74 68 65 20 78 66 6f 72 6d  ted by the xform
0f00: 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a 0a 2a 20   functions..*.* 
0f10: 45 78 61 6d 70 6c 65 3a 0a 2a 0a 2a 20 20 63 68  Example:.*.*  ch
0f20: 61 72 20 63 6f 6e 73 74 20 2a 20 63 6f 6e 73 74  ar const * const
0f30: 20 63 6f 6c 6e 61 6d 65 73 5b 5d 20 3d 20 7b 0a   colnames[] = {.
0f40: 2a 20 20 20 22 54 61 67 20 49 44 22 2c 20 22 54  *   "Tag ID", "T
0f50: 61 67 20 4e 61 6d 65 22 2c 20 22 53 6f 6d 65 74  ag Name", "Somet
0f60: 68 69 6e 67 20 45 6c 73 65 22 2c 20 22 55 55 49  hing Else", "UUI
0f70: 44 22 0a 2a 20 20 7d 3b 0a 2a 20 20 74 61 67 76  D".*  };.*  tagv
0f80: 69 65 77 5f 73 74 72 78 66 6f 72 6d 5f 66 20 78  iew_strxform_f x
0f90: 66 5b 5d 20 3d 20 7b 0a 2a 20 20 20 20 74 61 67  f[] = {.*    tag
0fa0: 76 69 65 77 5f 78 66 5f 6c 69 6e 6b 5f 74 6f 5f  view_xf_link_to_
0fb0: 74 61 67 69 64 2c 0a 2a 20 20 20 20 74 61 67 76  tagid,.*    tagv
0fc0: 69 65 77 5f 78 66 5f 6c 69 6e 6b 5f 74 6f 5f 74  iew_xf_link_to_t
0fd0: 61 67 6e 61 6d 65 2c 0a 2a 20 20 20 20 30 2c 0a  agname,.*    0,.
0fe0: 2a 20 20 20 20 74 61 67 76 69 65 77 5f 78 66 5f  *    tagview_xf_
0ff0: 6c 69 6e 6b 5f 74 6f 5f 75 75 69 64 0a 2a 20 20  link_to_uuid.*  
1000: 7d 3b 0a 2a 20 20 74 61 67 76 69 65 77 5f 72 75  };.*  tagview_ru
1010: 6e 5f 71 75 65 72 79 28 20 22 73 65 6c 65 63 74  n_query( "select
1020: 20 61 2c 62 2c 63 2c 64 20 66 72 6f 6d 20 66 6f   a,b,c,d from fo
1030: 6f 22 2c 20 63 6f 6c 6e 61 6d 65 73 2c 20 78 66  o", colnames, xf
1040: 20 29 3b 0a 2a 0a 2a 2f 0a 73 74 61 74 69 63 20   );.*.*/.static 
1050: 76 6f 69 64 20 74 61 67 76 69 65 77 5f 72 75 6e  void tagview_run
1060: 5f 71 75 65 72 79 28 0a 20 20 63 68 61 72 20 63  _query(.  char c
1070: 6f 6e 73 74 20 2a 20 73 71 6c 2c 0a 20 20 63 68  onst * sql,.  ch
1080: 61 72 20 63 6f 6e 73 74 20 2a 20 63 6f 6e 73 74  ar const * const
1090: 20 2a 20 63 6f 6c 6e 2c 0a 20 20 74 61 67 76 69   * coln,.  tagvi
10a0: 65 77 5f 73 74 72 78 66 6f 72 6d 5f 66 20 2a 20  ew_strxform_f * 
10b0: 78 66 6f 72 6d 20 29 0a 7b 0a 20 20 0a 20 20 53  xform ).{.  .  S
10c0: 74 6d 74 20 73 74 3b 0a 20 20 40 20 3c 74 61 62  tmt st;.  @ <tab
10d0: 6c 65 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 27  le cellpadding='
10e0: 34 70 78 27 20 62 6f 72 64 65 72 3d 27 31 27 3e  4px' border='1'>
10f0: 3c 74 62 6f 64 79 3e 0a 20 20 69 6e 74 20 69 20  <tbody>.  int i 
1100: 3d 20 30 3b 0a 20 20 69 6e 74 20 72 63 20 3d 20  = 0;.  int rc = 
1110: 64 62 5f 70 72 65 70 61 72 65 28 20 26 73 74 2c  db_prepare( &st,
1120: 20 73 71 6c 20 29 3b 0a 20 20 2f 2a 2a 0a 20 20   sql );.  /**.  
1130: 20 20 41 63 68 74 75 6e 67 3a 20 6d 61 6b 65 68    Achtung: makeh
1140: 65 61 64 65 72 73 20 61 70 70 61 72 65 6e 74 6c  eaders apparentl
1150: 79 20 63 61 6e 27 74 20 70 75 6c 6c 20 74 68 65  y can't pull the
1160: 20 66 75 6e 63 74 69 6f 6e 0a 20 20 20 20 6e 61   function.    na
1170: 6d 65 20 66 72 6f 6d 20 74 68 69 73 3a 0a 20 20  me from this:.  
1180: 20 69 66 28 20 53 51 4c 49 54 45 5f 4f 4b 20 21   if( SQLITE_OK !
1190: 3d 20 64 62 5f 70 72 65 70 61 72 65 28 20 26 73  = db_prepare( &s
11a0: 74 2c 20 73 71 6c 20 29 20 29 0a 20 20 2a 2f 0a  t, sql ) ).  */.
11b0: 20 20 69 66 28 20 53 51 4c 49 54 45 5f 4f 4b 20    if( SQLITE_OK 
11c0: 21 3d 20 72 63 20 29 0a 20 20 7b 0a 20 20 20 20  != rc ).  {.    
11d0: 40 20 74 61 67 76 69 65 77 5f 72 75 6e 5f 71 75  @ tagview_run_qu
11e0: 65 72 79 28 29 3a 20 45 72 72 6f 72 20 70 72 6f  ery(): Error pro
11f0: 63 65 73 73 69 6e 67 20 53 51 4c 3a 20 5b 25 73  cessing SQL: [%s
1200: 28 73 71 6c 29 5d 0a 20 20 20 20 72 65 74 75 72  (sql)].    retur
1210: 6e 3b 0a 20 20 7d 0a 20 20 69 6e 74 20 63 6f 6c  n;.  }.  int col
1220: 63 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 63 6f  c = db_column_co
1230: 75 6e 74 28 26 73 74 29 3b 0a 20 20 40 20 3c 74  unt(&st);.  @ <t
1240: 72 3e 0a 20 20 66 6f 72 28 20 69 20 3d 20 30 3b  r>.  for( i = 0;
1250: 20 69 20 3c 20 63 6f 6c 63 3b 20 2b 2b 69 20 29   i < colc; ++i )
1260: 20 7b 0a 20 20 20 20 69 66 28 20 63 6f 6c 6e 20   {.    if( coln 
1270: 29 0a 20 20 20 20 7b 0a 20 20 20 20 20 20 40 20  ).    {.      @ 
1280: 3c 74 68 3e 25 73 28 63 6f 6c 6e 5b 69 5d 20 3f  <th>%s(coln[i] ?
1290: 20 63 6f 6c 6e 5b 69 5d 20 3a 20 64 62 5f 63 6f   coln[i] : db_co
12a0: 6c 75 6d 6e 5f 6e 61 6d 65 28 26 73 74 2c 69 29  lumn_name(&st,i)
12b0: 29 3c 2f 74 68 3e 0a 20 20 20 20 7d 0a 20 20 20  )</th>.    }.   
12c0: 20 65 6c 73 65 0a 20 20 20 20 7b 0a 20 20 20 20   else.    {.    
12d0: 20 20 40 20 3c 74 64 3e 25 73 28 64 62 5f 63 6f    @ <td>%s(db_co
12e0: 6c 75 6d 6e 5f 6e 61 6d 65 28 26 73 74 2c 69 29  lumn_name(&st,i)
12f0: 29 3c 2f 74 64 3e 0a 20 20 20 20 7d 0a 20 20 7d  )</td>.    }.  }
1300: 0a 20 20 40 20 3c 2f 74 72 3e 0a 0a 20 20 77 68  .  @ </tr>..  wh
1310: 69 6c 65 28 20 53 51 4c 49 54 45 5f 52 4f 57 20  ile( SQLITE_ROW 
1320: 3d 3d 20 64 62 5f 73 74 65 70 28 26 73 74 29 20  == db_step(&st) 
1330: 29 7b 0a 20 20 20 20 40 20 3c 74 72 3e 0a 20 20  ){.    @ <tr>.  
1340: 20 20 20 20 66 6f 72 28 20 69 20 3d 20 30 3b 20      for( i = 0; 
1350: 69 20 3c 20 63 6f 6c 63 3b 20 2b 2b 69 20 29 20  i < colc; ++i ) 
1360: 7b 0a 20 20 20 20 20 20 20 20 63 68 61 72 20 2a  {.        char *
1370: 20 78 66 20 3d 20 30 3b 0a 20 20 20 20 20 20 20   xf = 0;.       
1380: 20 63 68 61 72 20 63 6f 6e 73 74 20 2a 20 78 63   char const * xc
1390: 66 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 78  f = 0;.        x
13a0: 63 66 20 3d 20 28 78 66 6f 72 6d 20 26 26 20 78  cf = (xform && x
13b0: 66 6f 72 6d 5b 69 5d 29 0a 20 20 20 20 20 20 20  form[i]).       
13c0: 20 20 20 3f 20 28 78 66 3d 28 78 66 6f 72 6d 5b     ? (xf=(xform[
13d0: 69 5d 29 28 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65  i])(db_column_te
13e0: 78 74 28 26 73 74 2c 69 29 29 29 0a 20 20 20 20  xt(&st,i))).    
13f0: 20 20 20 20 20 20 3a 20 64 62 5f 63 6f 6c 75 6d        : db_colum
1400: 6e 5f 74 65 78 74 28 26 73 74 2c 69 29 3b 0a 20  n_text(&st,i);. 
1410: 20 20 20 20 20 20 20 40 20 3c 74 64 3e 25 73 28         @ <td>%s(
1420: 78 63 66 29 3c 2f 74 64 3e 0a 20 20 20 20 20 20  xcf)</td>.      
1430: 20 20 69 66 28 20 78 66 20 29 20 66 72 65 65 28    if( xf ) free(
1440: 20 78 66 20 29 3b 0a 20 20 20 20 20 20 7d 0a 20   xf );.      }. 
1450: 20 20 20 40 20 3c 2f 74 72 3e 0a 20 20 7d 0a 20     @ </tr>.  }. 
1460: 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 20 26 73   db_finalize( &s
1470: 74 20 29 3b 0a 20 20 40 20 3c 2f 74 62 6f 64 79  t );.  @ </tbody
1480: 3e 3c 2f 74 61 62 6c 65 3e 0a 7d 0a 0a 2f 2a 2a  ></table>.}../**
1490: 0a 20 20 4c 69 73 74 73 20 61 6c 6c 20 74 61 67  .  Lists all tag
14a0: 73 20 6d 61 74 63 68 69 6e 67 20 74 68 65 20 67  s matching the g
14b0: 69 76 65 6e 20 4c 49 4b 45 20 63 6c 61 75 73 65  iven LIKE clause
14c0: 20 28 77 68 69 63 68 0a 6d 61 79 20 62 65 20 30   (which.may be 0
14d0: 29 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69  )..*/.static voi
14e0: 64 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f 6c  d tagview_page_l
14f0: 69 73 74 5f 74 61 67 73 28 20 63 68 61 72 20 63  ist_tags( char c
1500: 6f 6e 73 74 20 2a 20 6c 69 6b 65 20 29 0a 7b 0a  onst * like ).{.
1510: 20 20 63 68 61 72 20 2a 20 6c 69 6b 65 63 6c 61    char * likecla
1520: 75 73 65 20 3d 20 30 3b 0a 20 20 63 6f 6e 73 74  use = 0;.  const
1530: 20 69 6e 74 20 6c 69 6d 69 74 20 3d 20 31 30 3b   int limit = 10;
1540: 0a 20 20 63 68 61 72 20 2a 20 6c 69 6d 69 74 73  .  char * limits
1550: 74 72 20 3d 20 30 3b 0a 20 20 69 66 28 20 6c 69  tr = 0;.  if( li
1560: 6b 65 20 26 26 20 73 74 72 6c 65 6e 28 6c 69 6b  ke && strlen(lik
1570: 65 29 20 29 0a 20 20 7b 0a 20 20 20 20 6c 69 6b  e) ).  {.    lik
1580: 65 63 6c 61 75 73 65 20 3d 20 6d 70 72 69 6e 74  eclause = mprint
1590: 66 28 20 22 41 4e 44 20 74 2e 74 61 67 6e 61 6d  f( "AND t.tagnam
15a0: 65 20 4c 49 4b 45 20 27 25 25 25 25 25 71 25 25  e LIKE '%%%%%q%%
15b0: 25 25 27 22 2c 20 6c 69 6b 65 20 29 3b 0a 20 20  %%'", like );.  
15c0: 20 20 40 20 3c 68 32 3e 54 61 67 73 20 6d 61 74    @ <h2>Tags mat
15d0: 63 68 69 6e 67 20 5b 25 73 28 6c 69 6b 65 63 6c  ching [%s(likecl
15e0: 61 75 73 65 29 5d 3a 3c 2f 68 32 3e 0a 20 20 7d  ause)]:</h2>.  }
15f0: 0a 20 20 65 6c 73 65 0a 20 20 7b 0a 20 20 20 20  .  else.  {.    
1600: 6c 69 6d 69 74 73 74 72 20 3d 20 6d 70 72 69 6e  limitstr = mprin
1610: 74 66 28 20 22 4c 49 4d 49 54 20 25 64 22 2c 20  tf( "LIMIT %d", 
1620: 6c 69 6d 69 74 20 29 3b 0a 20 20 20 20 40 20 3c  limit );.    @ <
1630: 68 32 3e 25 64 28 6c 69 6d 69 74 29 20 6d 6f 73  h2>%d(limit) mos
1640: 74 20 72 65 63 65 6e 74 20 74 61 67 73 3a 3c 2f  t recent tags:</
1650: 68 32 3e 0a 20 20 7d 0a 20 20 63 68 61 72 20 2a  h2>.  }.  char *
1660: 20 73 71 6c 20 3d 20 6d 70 72 69 6e 74 66 28 20   sql = mprintf( 
1670: 0a 20 20 20 20 22 53 45 4c 45 43 54 20 74 2e 74  .    "SELECT t.t
1680: 61 67 69 64 2c 20 74 2e 74 61 67 6e 61 6d 65 2c  agid, t.tagname,
1690: 20 44 41 54 45 54 49 4d 45 28 74 78 2e 6d 74 69   DATETIME(tx.mti
16a0: 6d 65 29 2c 20 62 2e 75 75 69 64 20 22 0a 20 20  me), b.uuid ".  
16b0: 20 20 22 46 52 4f 4d 20 74 61 67 20 74 2c 20 74    "FROM tag t, t
16c0: 61 67 78 72 65 66 20 74 78 2c 20 62 6c 6f 62 20  agxref tx, blob 
16d0: 62 20 22 0a 20 20 20 20 22 57 48 45 52 45 20 28  b ".    "WHERE (
16e0: 74 2e 74 61 67 69 64 3d 74 78 2e 74 61 67 69 64  t.tagid=tx.tagid
16f0: 29 20 61 6e 64 20 28 74 78 2e 73 72 63 69 64 3d  ) and (tx.srcid=
1700: 62 2e 72 69 64 29 20 22 0a 20 20 20 20 22 41 4e  b.rid) ".    "AN
1710: 44 20 28 74 78 2e 74 61 67 74 79 70 65 20 21 3d  D (tx.tagtype !=
1720: 20 30 29 20 25 73 20 22 0a 20 20 20 20 54 41 47   0) %s ".    TAG
1730: 56 49 45 57 5f 44 45 46 41 55 4c 54 5f 46 49 4c  VIEW_DEFAULT_FIL
1740: 54 45 52 0a 20 20 20 20 22 4f 52 44 45 52 20 42  TER.    "ORDER B
1750: 59 20 74 78 2e 6d 74 69 6d 65 20 44 45 53 43 20  Y tx.mtime DESC 
1760: 25 73 22 2c 0a 20 20 20 20 6c 69 6b 65 63 6c 61  %s",.    likecla
1770: 75 73 65 20 3f 20 6c 69 6b 65 63 6c 61 75 73 65  use ? likeclause
1780: 20 3a 20 22 20 22 2c 0a 20 20 20 20 6c 69 6d 69   : " ",.    limi
1790: 74 73 74 72 20 3f 20 6c 69 6d 69 74 73 74 72 20  tstr ? limitstr 
17a0: 3a 20 22 20 22 0a 20 20 20 20 29 3b 0a 20 20 69  : " ".    );.  i
17b0: 66 28 20 6c 69 6d 69 74 73 74 72 20 29 20 66 72  f( limitstr ) fr
17c0: 65 65 28 6c 69 6d 69 74 73 74 72 29 3b 0a 20 20  ee(limitstr);.  
17d0: 69 66 28 20 6c 69 6b 65 63 6c 61 75 73 65 20 29  if( likeclause )
17e0: 20 66 72 65 65 28 6c 69 6b 65 63 6c 61 75 73 65   free(likeclause
17f0: 29 3b 0a 20 20 63 68 61 72 20 63 6f 6e 73 74 20  );.  char const 
1800: 2a 20 63 6f 6e 73 74 20 63 6f 6c 6e 61 6d 65 73  * const colnames
1810: 5b 5d 20 3d 20 7b 0a 20 20 20 20 22 54 61 67 20  [] = {.    "Tag 
1820: 49 44 22 2c 20 22 4e 61 6d 65 22 2c 20 22 54 69  ID", "Name", "Ti
1830: 6d 65 73 74 61 6d 70 22 2c 20 22 56 65 72 73 69  mestamp", "Versi
1840: 6f 6e 22 0a 20 20 7d 3b 0a 20 20 74 61 67 76 69  on".  };.  tagvi
1850: 65 77 5f 73 74 72 78 66 6f 72 6d 5f 66 20 78 66  ew_strxform_f xf
1860: 5b 5d 20 3d 20 7b 0a 20 20 20 20 74 61 67 76 69  [] = {.    tagvi
1870: 65 77 5f 78 66 5f 6c 69 6e 6b 5f 74 6f 5f 74 61  ew_xf_link_to_ta
1880: 67 69 64 2c 0a 20 20 20 20 74 61 67 76 69 65 77  gid,.    tagview
1890: 5f 78 66 5f 6c 69 6e 6b 5f 74 6f 5f 74 61 67 6e  _xf_link_to_tagn
18a0: 61 6d 65 2c 0a 20 20 20 20 30 2c 0a 20 20 20 20  ame,.    0,.    
18b0: 74 61 67 76 69 65 77 5f 78 66 5f 6c 69 6e 6b 5f  tagview_xf_link_
18c0: 74 6f 5f 75 75 69 64 0a 20 20 7d 3b 0a 20 20 74  to_uuid.  };.  t
18d0: 61 67 76 69 65 77 5f 72 75 6e 5f 71 75 65 72 79  agview_run_query
18e0: 28 20 73 71 6c 2c 20 63 6f 6c 6e 61 6d 65 73 2c  ( sql, colnames,
18f0: 20 78 66 20 29 3b 0a 20 20 66 72 65 65 28 20 73   xf );.  free( s
1900: 71 6c 20 29 3b 0a 7d 0a 0a 2f 2a 2a 0a 41 20 73  ql );.}../**.A s
1910: 6d 61 6c 6c 20 73 65 61 72 63 68 20 66 6f 72 6d  mall search form
1920: 20 77 68 69 63 68 20 66 6f 72 77 61 72 64 73 20   which forwards 
1930: 74 6f 20 3f 6c 69 6b 65 3d 53 45 41 52 43 48 5f  to ?like=SEARCH_
1940: 53 54 52 49 4e 47 0a 2a 2f 0a 73 74 61 74 69 63  STRING.*/.static
1950: 20 76 6f 69 64 20 74 61 67 76 69 65 77 5f 70 61   void tagview_pa
1960: 67 65 5f 73 65 61 72 63 68 5f 6d 69 6e 69 66 6f  ge_search_minifo
1970: 72 6d 28 76 6f 69 64 29 7b 0a 20 20 63 68 61 72  rm(void){.  char
1980: 20 63 6f 6e 73 74 20 2a 20 6c 69 6b 65 20 3d 20   const * like = 
1990: 50 28 22 6c 69 6b 65 22 29 3b 0a 20 20 40 20 3c  P("like");.  @ <
19a0: 64 69 76 20 73 74 79 6c 65 3d 27 66 6f 6e 74 2d  div style='font-
19b0: 73 69 7a 65 3a 73 6d 61 6c 6c 65 72 27 3e 0a 20  size:smaller'>. 
19c0: 20 40 20 3c 66 6f 72 6d 20 61 63 74 69 6f 6e 3d   @ <form action=
19d0: 27 2f 74 61 67 76 69 65 77 27 20 6d 65 74 68 6f  '/tagview' metho
19e0: 64 3d 27 70 6f 73 74 27 3e 0a 20 20 40 20 53 65  d='post'>.  @ Se
19f0: 61 72 63 68 20 66 6f 72 20 74 61 67 73 3a 20 0a  arch for tags: .
1a00: 20 20 40 20 3c 69 6e 70 75 74 20 74 79 70 65 3d    @ <input type=
1a10: 27 74 65 78 74 27 20 6e 61 6d 65 3d 27 6c 69 6b  'text' name='lik
1a20: 65 27 20 76 61 6c 75 65 3d 27 25 73 28 28 6c 69  e' value='%s((li
1a30: 6b 65 3f 6c 69 6b 65 3a 22 22 29 29 27 20 73 69  ke?like:""))' si
1a40: 7a 65 3d 27 31 30 27 2f 3e 0a 20 20 40 20 3c 69  ze='10'/>.  @ <i
1a50: 6e 70 75 74 20 74 79 70 65 3d 27 73 75 62 6d 69  nput type='submi
1a60: 74 27 2f 3e 0a 20 20 40 20 3c 2f 66 6f 72 6d 3e  t'/>.  @ </form>
1a70: 0a 20 20 40 20 3c 2f 64 69 76 3e 0a 7d 0a 0a 2f  .  @ </div>.}../
1a80: 2a 2a 0a 20 74 61 67 76 69 65 77 5f 70 61 67 65  **. tagview_page
1a90: 5f 64 65 66 61 75 6c 74 28 29 20 72 65 6e 64 65  _default() rende
1aa0: 72 73 20 74 68 65 20 64 65 66 61 75 6c 74 20 70  rs the default p
1ab0: 61 67 65 20 66 6f 72 20 74 61 67 76 69 65 77 5f  age for tagview_
1ac0: 70 61 67 65 28 29 2e 0a 2a 2f 0a 73 74 61 74 69  page()..*/.stati
1ad0: 63 20 76 6f 69 64 20 74 61 67 76 69 65 77 5f 70  c void tagview_p
1ae0: 61 67 65 5f 64 65 66 61 75 6c 74 28 76 6f 69 64  age_default(void
1af0: 29 7b 0a 20 20 74 61 67 76 69 65 77 5f 70 61 67  ){.  tagview_pag
1b00: 65 5f 6c 69 73 74 5f 74 61 67 73 28 20 30 20 29  e_list_tags( 0 )
1b10: 3b 0a 7d 0a 0a 2f 2a 2a 0a 20 20 4c 69 73 74 73  ;.}../**.  Lists
1b20: 20 61 6c 6c 20 74 61 67 73 20 6d 61 74 63 68 69   all tags matchi
1b30: 6e 67 20 74 68 65 20 67 69 76 65 6e 20 74 61 67  ng the given tag
1b40: 69 64 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f  id..*/.static vo
1b50: 69 64 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f  id tagview_page_
1b60: 74 61 67 5f 62 79 5f 69 64 28 20 69 6e 74 20 74  tag_by_id( int t
1b70: 61 67 69 64 20 29 0a 7b 0a 20 20 40 20 3c 68 32  agid ).{.  @ <h2
1b80: 3e 54 61 67 20 23 25 64 28 74 61 67 69 64 29 3a  >Tag #%d(tagid):
1b90: 3c 2f 68 32 3e 0a 20 20 63 68 61 72 20 2a 20 73  </h2>.  char * s
1ba0: 71 6c 20 3d 20 6d 70 72 69 6e 74 66 28 20 0a 20  ql = mprintf( . 
1bb0: 20 20 20 22 53 45 4c 45 43 54 20 44 49 53 54 49     "SELECT DISTI
1bc0: 4e 43 54 20 28 74 2e 74 61 67 6e 61 6d 65 29 2c  NCT (t.tagname),
1bd0: 20 44 41 54 45 54 49 4d 45 28 74 78 2e 6d 74 69   DATETIME(tx.mti
1be0: 6d 65 29 2c 20 62 2e 75 75 69 64 20 22 0a 20 20  me), b.uuid ".  
1bf0: 20 20 22 46 52 4f 4d 20 74 61 67 20 74 2c 20 74    "FROM tag t, t
1c00: 61 67 78 72 65 66 20 74 78 2c 20 62 6c 6f 62 20  agxref tx, blob 
1c10: 62 20 22 0a 20 20 20 20 22 57 48 45 52 45 20 28  b ".    "WHERE (
1c20: 74 2e 74 61 67 69 64 3d 25 64 29 20 41 4e 44 20  t.tagid=%d) AND 
1c30: 28 74 2e 74 61 67 69 64 3d 74 78 2e 74 61 67 69  (t.tagid=tx.tagi
1c40: 64 29 20 41 4e 44 20 28 74 78 2e 73 72 63 69 64  d) AND (tx.srcid
1c50: 3d 62 2e 72 69 64 29 20 22 0a 20 20 20 20 54 41  =b.rid) ".    TA
1c60: 47 56 49 45 57 5f 44 45 46 41 55 4c 54 5f 46 49  GVIEW_DEFAULT_FI
1c70: 4c 54 45 52 0a 20 20 20 20 22 4f 52 44 45 52 20  LTER.    "ORDER 
1c80: 42 59 20 74 78 2e 6d 74 69 6d 65 20 44 45 53 43  BY tx.mtime DESC
1c90: 22 2c 0a 20 20 74 61 67 69 64 29 3b 0a 20 20 63  ",.  tagid);.  c
1ca0: 68 61 72 20 63 6f 6e 73 74 20 2a 20 63 6f 6e 73  har const * cons
1cb0: 74 20 63 6f 6c 6e 61 6d 65 73 5b 5d 20 3d 20 7b  t colnames[] = {
1cc0: 0a 20 20 20 20 20 20 22 54 61 67 20 4e 61 6d 65  .      "Tag Name
1cd0: 22 2c 20 22 54 69 6d 65 73 74 61 6d 70 22 2c 20  ", "Timestamp", 
1ce0: 22 56 65 72 73 69 6f 6e 22 0a 20 20 7d 3b 0a 20  "Version".  };. 
1cf0: 20 74 61 67 76 69 65 77 5f 73 74 72 78 66 6f 72   tagview_strxfor
1d00: 6d 5f 66 20 78 66 5b 5d 20 3d 20 7b 0a 20 20 20  m_f xf[] = {.   
1d10: 20 20 20 74 61 67 76 69 65 77 5f 78 66 5f 6c 69     tagview_xf_li
1d20: 6e 6b 5f 74 6f 5f 74 61 67 6e 61 6d 65 2c 0a 20  nk_to_tagname,. 
1d30: 20 20 20 20 20 30 2c 0a 20 20 20 20 20 20 74 61       0,.      ta
1d40: 67 76 69 65 77 5f 78 66 5f 6c 69 6e 6b 5f 74 6f  gview_xf_link_to
1d50: 5f 75 75 69 64 0a 20 20 7d 3b 0a 20 20 74 61 67  _uuid.  };.  tag
1d60: 76 69 65 77 5f 72 75 6e 5f 71 75 65 72 79 28 20  view_run_query( 
1d70: 73 71 6c 2c 20 63 6f 6c 6e 61 6d 65 73 2c 20 78  sql, colnames, x
1d80: 66 20 29 3b 0a 20 20 66 72 65 65 28 73 71 6c 29  f );.  free(sql)
1d90: 3b 0a 7d 0a 0a 2f 2a 2a 0a 20 20 4c 69 73 74 73  ;.}../**.  Lists
1da0: 20 61 6c 6c 20 74 61 67 73 20 6d 61 74 63 68 69   all tags matchi
1db0: 6e 67 20 74 68 65 20 67 69 76 65 6e 20 74 61 67  ng the given tag
1dc0: 20 6e 61 6d 65 2e 0a 2a 2f 0a 73 74 61 74 69 63   name..*/.static
1dd0: 20 76 6f 69 64 20 74 61 67 76 69 65 77 5f 70 61   void tagview_pa
1de0: 67 65 5f 74 61 67 5f 62 79 5f 6e 61 6d 65 28 20  ge_tag_by_name( 
1df0: 63 68 61 72 20 63 6f 6e 73 74 20 2a 20 74 61 67  char const * tag
1e00: 6e 61 6d 65 20 29 0a 7b 0a 20 20 40 20 3c 68 32  name ).{.  @ <h2
1e10: 3e 54 61 67 20 27 25 73 28 74 61 67 6e 61 6d 65  >Tag '%s(tagname
1e20: 29 27 3a 3c 2f 68 32 3e 0a 20 20 63 68 61 72 20  )':</h2>.  char 
1e30: 2a 20 73 71 6c 20 3d 20 6d 70 72 69 6e 74 66 28  * sql = mprintf(
1e40: 20 0a 20 20 20 20 22 53 45 4c 45 43 54 20 44 49   .    "SELECT DI
1e50: 53 54 49 4e 43 54 20 74 2e 74 61 67 69 64 2c 20  STINCT t.tagid, 
1e60: 44 41 54 45 54 49 4d 45 28 74 78 2e 6d 74 69 6d  DATETIME(tx.mtim
1e70: 65 29 2c 20 62 2e 75 75 69 64 20 22 0a 20 20 20  e), b.uuid ".   
1e80: 20 22 46 52 4f 4d 20 74 61 67 20 74 2c 20 74 61   "FROM tag t, ta
1e90: 67 78 72 65 66 20 74 78 2c 20 62 6c 6f 62 20 62  gxref tx, blob b
1ea0: 20 22 0a 20 20 20 20 22 57 48 45 52 45 20 28 74   ".    "WHERE (t
1eb0: 2e 74 61 67 6e 61 6d 65 3d 27 25 71 27 29 20 41  .tagname='%q') A
1ec0: 4e 44 20 28 74 2e 74 61 67 69 64 3d 74 78 2e 74  ND (t.tagid=tx.t
1ed0: 61 67 69 64 29 20 41 4e 44 20 28 74 78 2e 73 72  agid) AND (tx.sr
1ee0: 63 69 64 3d 62 2e 72 69 64 29 20 22 0a 20 20 20  cid=b.rid) ".   
1ef0: 20 54 41 47 56 49 45 57 5f 44 45 46 41 55 4c 54   TAGVIEW_DEFAULT
1f00: 5f 46 49 4c 54 45 52 0a 20 20 20 20 22 4f 52 44  _FILTER.    "ORD
1f10: 45 52 20 42 59 20 74 78 2e 6d 74 69 6d 65 20 44  ER BY tx.mtime D
1f20: 45 53 43 22 2c 0a 20 20 20 20 74 61 67 6e 61 6d  ESC",.    tagnam
1f30: 65 29 3b 0a 20 20 63 68 61 72 20 63 6f 6e 73 74  e);.  char const
1f40: 20 2a 20 63 6f 6e 73 74 20 63 6f 6c 6e 61 6d 65   * const colname
1f50: 73 5b 5d 20 3d 20 7b 0a 20 20 20 20 20 20 22 54  s[] = {.      "T
1f60: 61 67 20 49 44 22 2c 20 22 54 69 6d 65 73 74 61  ag ID", "Timesta
1f70: 6d 70 22 2c 20 22 56 65 72 73 69 6f 6e 22 0a 20  mp", "Version". 
1f80: 20 7d 3b 0a 20 20 74 61 67 76 69 65 77 5f 73 74   };.  tagview_st
1f90: 72 78 66 6f 72 6d 5f 66 20 78 66 5b 5d 20 3d 20  rxform_f xf[] = 
1fa0: 7b 0a 20 20 20 20 20 20 74 61 67 76 69 65 77 5f  {.      tagview_
1fb0: 78 66 5f 6c 69 6e 6b 5f 74 6f 5f 74 61 67 69 64  xf_link_to_tagid
1fc0: 2c 0a 20 20 20 20 20 20 30 2c 0a 20 20 20 20 20  ,.      0,.     
1fd0: 20 74 61 67 76 69 65 77 5f 78 66 5f 6c 69 6e 6b   tagview_xf_link
1fe0: 5f 74 6f 5f 75 75 69 64 0a 20 20 7d 3b 0a 20 20  _to_uuid.  };.  
1ff0: 74 61 67 76 69 65 77 5f 72 75 6e 5f 71 75 65 72  tagview_run_quer
2000: 79 28 20 73 71 6c 2c 20 63 6f 6c 6e 61 6d 65 73  y( sql, colnames
2010: 2c 20 78 66 20 29 3b 0a 20 20 66 72 65 65 28 20  , xf );.  free( 
2020: 73 71 6c 20 29 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a  sql );.}.../*.**
2030: 20 57 45 42 50 41 47 45 3a 20 2f 74 61 67 76 69   WEBPAGE: /tagvi
2040: 65 77 0a 2a 2f 0a 76 6f 69 64 20 74 61 67 76 69  ew.*/.void tagvi
2050: 65 77 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a 20  ew_page(void){. 
2060: 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65   login_check_cre
2070: 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69 66  dentials();.  if
2080: 28 20 21 67 2e 6f 6b 52 64 57 69 6b 69 20 29 7b  ( !g.okRdWiki ){
2090: 0a 20 20 20 20 6c 6f 67 69 6e 5f 6e 65 65 64 65  .    login_neede
20a0: 64 28 29 3b 0a 20 20 7d 0a 20 20 73 74 79 6c 65  d();.  }.  style
20b0: 5f 68 65 61 64 65 72 28 22 54 61 67 73 22 29 3b  _header("Tags");
20c0: 0a 20 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f  .  tagview_page_
20d0: 73 65 61 72 63 68 5f 6d 69 6e 69 66 6f 72 6d 28  search_miniform(
20e0: 29 3b 0a 20 20 40 20 3c 68 72 2f 3e 0a 20 20 63  );.  @ <hr/>.  c
20f0: 68 61 72 20 63 6f 6e 73 74 20 2a 20 63 68 65 63  har const * chec
2100: 6b 20 3d 20 30 3b 0a 20 20 69 66 28 20 30 20 21  k = 0;.  if( 0 !
2110: 3d 20 28 63 68 65 63 6b 20 3d 20 50 28 22 74 61  = (check = P("ta
2120: 67 69 64 22 29 29 20 29 0a 20 20 7b 0a 20 20 20  gid")) ).  {.   
2130: 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f 74 61   tagview_page_ta
2140: 67 5f 62 79 5f 69 64 28 20 61 74 6f 69 28 63 68  g_by_id( atoi(ch
2150: 65 63 6b 29 20 29 3b 0a 20 20 7d 0a 20 20 65 6c  eck) );.  }.  el
2160: 73 65 20 69 66 28 20 30 20 21 3d 20 28 63 68 65  se if( 0 != (che
2170: 63 6b 20 3d 20 50 28 22 6c 69 6b 65 22 29 29 20  ck = P("like")) 
2180: 29 0a 20 20 7b 0a 20 20 20 20 74 61 67 76 69 65  ).  {.    tagvie
2190: 77 5f 70 61 67 65 5f 6c 69 73 74 5f 74 61 67 73  w_page_list_tags
21a0: 28 20 63 68 65 63 6b 20 29 3b 0a 20 20 7d 0a 20  ( check );.  }. 
21b0: 20 65 6c 73 65 20 69 66 28 20 30 20 21 3d 20 28   else if( 0 != (
21c0: 63 68 65 63 6b 20 3d 20 50 28 22 6e 61 6d 65 22  check = P("name"
21d0: 29 29 20 29 0a 20 20 7b 0a 20 20 20 20 74 61 67  )) ).  {.    tag
21e0: 76 69 65 77 5f 70 61 67 65 5f 74 61 67 5f 62 79  view_page_tag_by
21f0: 5f 6e 61 6d 65 28 20 63 68 65 63 6b 20 29 3b 0a  _name( check );.
2200: 20 20 7d 0a 20 20 65 6c 73 65 0a 20 20 7b 0a 20    }.  else.  {. 
2210: 20 20 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f     tagview_page_
2220: 64 65 66 61 75 6c 74 28 29 3b 0a 20 20 7d 0a 20  default();.  }. 
2230: 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b   style_footer();
2240: 0a 7d 0a 0a 23 75 6e 64 65 66 20 54 41 47 56 49  .}..#undef TAGVI
2250: 45 57 5f 44 45 46 41 55 4c 54 5f 46 49 4c 54 45  EW_DEFAULT_FILTE
2260: 52 0a                                            R.