Hex Artifact Content
Not logged in

Artifact 7353135aa6df8a9b939a355634f252dd6719348e:

File src/tagview.c part of check-in [10437374a7] - Stylistic changes to the C code that implements the tagview page. by drh on 2008-02-02 23:48: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 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61  lic.** License a
00b0: 73 20 70 75 62 6c 69 73 68 65 64 20 62 79 20 74  s published by t
00c0: 68 65 20 46 72 65 65 20 53 6f 66 74 77 61 72 65  he Free Software
00d0: 20 46 6f 75 6e 64 61 74 69 6f 6e 3b 20 65 69 74   Foundation; eit
00e0: 68 65 72 0a 2a 2a 20 76 65 72 73 69 6f 6e 20 32  her.** version 2
00f0: 20 6f 66 20 74 68 65 20 4c 69 63 65 6e 73 65 2c   of the License,
0100: 20 6f 72 20 28 61 74 20 79 6f 75 72 20 6f 70 74   or (at your opt
0110: 69 6f 6e 29 20 61 6e 79 20 6c 61 74 65 72 20 76  ion) any later v
0120: 65 72 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68  ersion..**.** Th
0130: 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69  is program is di
0140: 73 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65  stributed in the
0150: 20 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69   hope that it wi
0160: 6c 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a  ll be useful,.**
0170: 20 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59   but WITHOUT ANY
0180: 20 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f   WARRANTY; witho
0190: 75 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c  ut even the impl
01a0: 69 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a  ied warranty of.
01b0: 2a 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49  ** MERCHANTABILI
01c0: 54 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f  TY or FITNESS FO
01d0: 52 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50  R A PARTICULAR P
01e0: 55 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65  URPOSE.  See the
01f0: 20 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20   GNU.** General 
0200: 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66  Public License f
0210: 6f 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e  or more details.
0220: 0a 2a 2a 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c  .**.** You shoul
0230: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20  d have received 
0240: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e  a copy of the GN
0250: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63  U General Public
0260: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e  .** License alon
0270: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72  g with this libr
0280: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69  ary; if not, wri
0290: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65  te to the.** Fre
02a0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
02b0: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20  ation, Inc., 59 
02c0: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53  Temple Place - S
02d0: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73  uite 330,.** Bos
02e0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31  ton, MA  02111-1
02f0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20  307, USA..**.** 
0300: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69  Author contact i
0310: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20  nformation:.**  
0320: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a   drh@hwaci.com.*
0330: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68  *   http://www.h
0340: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a  waci.com/drh/.**
0350: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .***************
0360: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0370: 2a 2a 2a 2a 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: 0a 2a 2a 0a 2a 2a 20 49 6d 70 6c 65 6d 65 6e 74  .**.** Implement
03b0: 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 54 61 67  ation of the Tag
03c0: 20 56 69 65 77 20 70 61 67 65 0a 2a 2f 0a 23 69   View page.*/.#i
03d0: 6e 63 6c 75 64 65 20 3c 61 73 73 65 72 74 2e 68  nclude <assert.h
03e0: 3e 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e 66  >.#include "conf
03f0: 69 67 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22  ig.h".#include "
0400: 74 61 67 76 69 65 77 2e 68 22 0a 0a 0a 2f 2a 0a  tagview.h".../*.
0410: 2a 2a 20 4f 75 74 70 75 74 20 61 20 73 69 6e 67  ** Output a sing
0420: 6c 65 20 65 6e 74 72 79 20 66 6f 72 20 61 20 6d  le entry for a m
0430: 65 6e 75 20 67 65 6e 65 72 61 74 65 64 20 75 73  enu generated us
0440: 69 6e 67 20 61 6e 20 48 54 4d 4c 20 74 61 62 6c  ing an HTML tabl
0450: 65 2e 0a 2a 2a 20 49 66 20 7a 4c 69 6e 6b 20 69  e..** If zLink i
0460: 73 20 6e 6f 74 20 4e 55 4c 4c 20 6f 72 20 61 6e  s not NULL or an
0470: 20 65 6d 70 74 79 20 73 74 72 69 6e 67 2c 20 74   empty string, t
0480: 68 65 6e 20 69 74 20 69 73 20 74 68 65 20 70 61  hen it is the pa
0490: 67 65 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 6d  ge that.** the m
04a0: 65 6e 75 20 65 6e 74 72 79 20 77 69 6c 6c 20 68  enu entry will h
04b0: 79 70 65 72 6c 69 6e 6b 20 74 6f 2e 20 20 49 66  yperlink to.  If
04c0: 20 7a 4c 69 6e 6b 20 69 73 20 4e 55 4c 4c 20 6f   zLink is NULL o
04d0: 72 20 22 22 2c 20 74 68 65 6e 0a 2a 2a 20 74 68  r "", then.** th
04e0: 65 20 6d 65 6e 75 20 65 6e 74 72 79 20 68 61 73  e menu entry has
04f0: 20 6e 6f 20 68 79 70 65 72 6c 69 6e 6b 20 2d 20   no hyperlink - 
0500: 69 74 20 69 73 20 64 69 73 61 62 6c 65 64 2e 0a  it is disabled..
0510: 2a 2f 0a 76 6f 69 64 20 74 61 67 76 69 65 77 5f  */.void tagview_
0520: 6d 65 6e 75 5f 65 6e 74 72 79 28 0a 20 20 63 6f  menu_entry(.  co
0530: 6e 73 74 20 63 68 61 72 20 2a 7a 54 69 74 6c 65  nst char *zTitle
0540: 2c 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  ,.  const char *
0550: 7a 4c 69 6e 6b 2c 0a 20 20 63 6f 6e 73 74 20 63  zLink,.  const c
0560: 68 61 72 20 2a 7a 44 65 73 63 0a 29 7b 0a 20 20  har *zDesc.){.  
0570: 40 20 3c 74 72 3e 3c 74 64 20 76 61 6c 69 67 6e  @ <tr><td valign
0580: 3d 22 74 6f 70 22 20 61 6c 69 67 6e 3d 22 72 69  ="top" align="ri
0590: 67 68 74 22 3e 0a 20 20 69 66 28 20 7a 4c 69 6e  ght">.  if( zLin
05a0: 6b 20 26 26 20 7a 4c 69 6e 6b 5b 30 5d 20 29 7b  k && zLink[0] ){
05b0: 0a 20 20 20 20 40 20 3c 61 20 68 72 65 66 3d 22  .    @ <a href="
05c0: 25 73 28 7a 4c 69 6e 6b 29 22 3e 25 68 28 7a 54  %s(zLink)">%h(zT
05d0: 69 74 6c 65 29 3c 2f 61 3e 0a 20 20 7d 65 6c 73  itle)</a>.  }els
05e0: 65 7b 0a 20 20 20 20 40 20 25 68 28 7a 54 69 74  e{.    @ %h(zTit
05f0: 6c 65 29 0a 20 20 7d 0a 20 20 40 20 3c 2f 74 64  le).  }.  @ </td
0600: 3e 3c 74 64 20 76 61 6c 69 67 6e 3d 22 74 6f 70  ><td valign="top
0610: 22 3e 25 68 28 7a 44 65 73 63 29 3c 2f 74 64 3e  ">%h(zDesc)</td>
0620: 3c 2f 74 72 3e 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 57  </tr>.}../*.** W
0630: 45 42 50 41 47 45 3a 20 2f 74 61 67 76 69 65 77  EBPAGE: /tagview
0640: 0a 2a 2f 0a 76 6f 69 64 20 74 61 67 76 69 65 77  .*/.void tagview
0650: 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a 20 20 53  _page(void){.  S
0660: 74 6d 74 20 73 74 3b 0a 0a 20 20 6c 6f 67 69 6e  tmt st;..  login
0670: 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e 74 69 61  _check_credentia
0680: 6c 73 28 29 3b 0a 20 20 69 66 28 20 21 67 2e 6f  ls();.  if( !g.o
0690: 6b 53 65 74 75 70 20 29 7b 0a 20 20 20 20 6c 6f  kSetup ){.    lo
06a0: 67 69 6e 5f 6e 65 65 64 65 64 28 29 3b 0a 20 20  gin_needed();.  
06b0: 7d 0a 20 20 73 74 79 6c 65 5f 68 65 61 64 65 72  }.  style_header
06c0: 28 22 54 61 67 73 20 4c 69 73 74 22 29 3b 0a 20  ("Tags List");. 
06d0: 20 40 20 3c 74 61 62 6c 65 20 63 65 6c 6c 70 61   @ <table cellpa
06e0: 64 64 69 6e 67 3d 27 34 70 78 27 20 62 6f 72 64  dding='4px' bord
06f0: 65 72 3d 27 31 27 3e 3c 74 62 6f 64 79 3e 0a 20  er='1'><tbody>. 
0700: 20 40 20 3c 74 72 3e 3c 74 68 3e 54 61 67 20 6e   @ <tr><th>Tag n
0710: 61 6d 65 3c 2f 74 68 3e 3c 74 68 3e 54 69 6d 65  ame</th><th>Time
0720: 73 74 61 6d 70 3c 2f 74 68 3e 3c 74 68 3e 56 65  stamp</th><th>Ve
0730: 72 73 69 6f 6e 3c 2f 74 68 3e 3c 2f 74 72 3e 0a  rsion</th></tr>.
0740: 20 20 64 62 5f 70 72 65 70 61 72 65 28 20 26 73    db_prepare( &s
0750: 74 2c 0a 20 20 20 20 20 22 53 45 4c 45 43 54 20  t,.     "SELECT 
0760: 74 2e 74 61 67 6e 61 6d 65 2c 20 44 41 54 45 54  t.tagname, DATET
0770: 49 4d 45 28 74 78 2e 6d 74 69 6d 65 29 2c 20 62  IME(tx.mtime), b
0780: 2e 75 75 69 64 20 22 0a 20 20 20 20 20 22 20 20  .uuid ".     "  
0790: 46 52 4f 4d 20 74 61 67 20 74 2c 20 74 61 67 78  FROM tag t, tagx
07a0: 72 65 66 20 74 78 2c 20 62 6c 6f 62 20 62 22 0a  ref tx, blob b".
07b0: 20 20 20 20 20 22 20 57 48 45 52 45 20 74 2e 74       " WHERE t.t
07c0: 61 67 69 64 3d 74 78 2e 74 61 67 69 64 20 61 6e  agid=tx.tagid an
07d0: 64 20 74 78 2e 72 69 64 3d 62 2e 72 69 64 22 0a  d tx.rid=b.rid".
07e0: 20 20 20 20 20 22 20 20 20 41 4e 44 20 74 78 2e       "   AND tx.
07f0: 74 61 67 74 79 70 65 20 21 3d 20 30 22 0a 20 20  tagtype != 0".  
0800: 20 20 20 2f 2a 20 22 20 20 20 41 4e 44 20 74 2e     /* "   AND t.
0810: 74 61 67 6e 61 6d 65 20 4e 4f 54 20 47 4c 4f 42  tagname NOT GLOB
0820: 20 27 77 69 6b 69 2d 2a 27 22 20 2f 2f 20 44 6f   'wiki-*'" // Do
0830: 20 77 65 20 77 61 6e 74 20 74 68 69 73 3f 3f 20   we want this?? 
0840: 2a 2f 0a 20 20 20 20 20 22 20 4f 52 44 45 52 20  */.     " ORDER 
0850: 42 59 20 74 78 2e 6d 74 69 6d 65 20 44 45 53 43  BY tx.mtime DESC
0860: 22 0a 20 20 29 3b 0a 20 20 77 68 69 6c 65 28 20  ".  );.  while( 
0870: 53 51 4c 49 54 45 5f 52 4f 57 20 3d 3d 20 64 62  SQLITE_ROW == db
0880: 5f 73 74 65 70 28 26 73 74 29 20 29 7b 0a 20 20  _step(&st) ){.  
0890: 20 20 63 68 61 72 20 63 6f 6e 73 74 20 2a 20 74    char const * t
08a0: 61 67 6e 61 6d 65 20 3d 20 64 62 5f 63 6f 6c 75  agname = db_colu
08b0: 6d 6e 5f 74 65 78 74 28 20 26 73 74 2c 20 30 20  mn_text( &st, 0 
08c0: 29 3b 0a 20 20 20 20 63 68 61 72 20 63 6f 6e 73  );.    char cons
08d0: 74 20 2a 20 74 61 67 74 69 6d 65 20 3d 20 64 62  t * tagtime = db
08e0: 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 20 26 73  _column_text( &s
08f0: 74 2c 20 31 20 29 3b 0a 20 20 20 20 63 68 61 72  t, 1 );.    char
0900: 20 63 6f 6e 73 74 20 2a 20 75 75 69 64 20 3d 20   const * uuid = 
0910: 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 20  db_column_text( 
0920: 26 73 74 2c 20 32 20 29 3b 0a 20 20 20 20 63 6f  &st, 2 );.    co
0930: 6e 73 74 20 69 6e 74 20 6f 66 66 73 65 74 20 3d  nst int offset =
0940: 20 31 30 3b 0a 20 20 20 20 63 68 61 72 20 73 68   10;.    char sh
0950: 6f 72 74 6e 61 6d 65 5b 6f 66 66 73 65 74 2b 31  ortname[offset+1
0960: 5d 3b 0a 20 20 20 20 73 68 6f 72 74 6e 61 6d 65  ];.    shortname
0970: 5b 6f 66 66 73 65 74 5d 20 3d 20 27 5c 30 27 3b  [offset] = '\0';
0980: 0a 20 20 20 20 6d 65 6d 63 70 79 28 20 73 68 6f  .    memcpy( sho
0990: 72 74 6e 61 6d 65 2c 20 75 75 69 64 2c 20 6f 66  rtname, uuid, of
09a0: 66 73 65 74 20 29 3b 0a 20 20 20 20 40 20 3c 74  fset );.    @ <t
09b0: 72 3e 0a 20 20 20 20 40 20 3c 74 64 3e 3c 74 74  r>.    @ <td><tt
09c0: 3e 25 73 28 74 61 67 6e 61 6d 65 29 3c 2f 74 74  >%s(tagname)</tt
09d0: 3e 3c 2f 74 64 3e 0a 20 20 20 20 40 20 3c 74 64  ></td>.    @ <td
09e0: 20 61 6c 69 67 6e 3d 27 63 65 6e 74 65 72 27 3e   align='center'>
09f0: 3c 74 74 3e 25 73 28 74 61 67 74 69 6d 65 29 3c  <tt>%s(tagtime)<
0a00: 2f 74 74 3e 3c 2f 74 64 3e 0a 20 20 20 20 40 20  /tt></td>.    @ 
0a10: 3c 74 64 3e 3c 74 74 3e 0a 20 20 20 20 40 20 3c  <td><tt>.    @ <
0a20: 61 20 68 72 65 66 3d 27 2f 76 69 6e 66 6f 2f 25  a href='/vinfo/%
0a30: 73 28 75 75 69 64 29 27 3e 0a 20 20 20 20 40 20  s(uuid)'>.    @ 
0a40: 3c 73 74 72 6f 6e 67 3e 25 73 28 73 68 6f 72 74  <strong>%s(short
0a50: 6e 61 6d 65 29 3c 2f 73 74 72 6f 6e 67 3e 25 73  name)</strong>%s
0a60: 28 75 75 69 64 2b 6f 66 66 73 65 74 29 3c 2f 61  (uuid+offset)</a
0a70: 3e 3c 2f 74 74 3e 0a 20 20 20 20 40 20 3c 2f 74  ></tt>.    @ </t
0a80: 64 3e 3c 2f 74 72 3e 0a 20 20 7d 0a 20 20 64 62  d></tr>.  }.  db
0a90: 5f 66 69 6e 61 6c 69 7a 65 28 20 26 73 74 20 29  _finalize( &st )
0aa0: 3b 0a 20 20 40 20 3c 2f 74 62 6f 64 79 3e 3c 2f  ;.  @ </tbody></
0ab0: 74 61 62 6c 65 3e 0a 20 20 40 20 3c 68 72 2f 3e  table>.  @ <hr/>
0ac0: 54 4f 44 4f 73 20 69 6e 63 6c 75 64 65 3a 0a 20  TODOs include:. 
0ad0: 20 40 20 3c 75 6c 3e 0a 20 20 40 20 20 3c 6c 69   @ <ul>.  @  <li
0ae0: 3e 50 61 67 65 20 74 68 72 6f 75 67 68 20 6c 6f  >Page through lo
0af0: 6e 67 20 74 61 67 73 20 6c 69 73 74 73 2e 3c 2f  ng tags lists.</
0b00: 6c 69 3e 0a 20 20 40 20 20 3c 6c 69 3e 46 6f 72  li>.  @  <li>For
0b10: 6d 61 74 20 74 68 65 20 74 69 6d 65 73 74 61 6d  mat the timestam
0b20: 70 20 66 69 65 6c 64 2e 3c 2f 6c 69 3e 0a 20 20  p field.</li>.  
0b30: 40 20 20 3c 6c 69 3e 41 6c 6c 6f 77 20 64 69 66  @  <li>Allow dif
0b40: 66 65 72 65 6e 74 20 73 6f 72 74 69 6e 67 2e 3c  ferent sorting.<
0b50: 2f 6c 69 3e 0a 20 20 40 20 20 3c 6c 69 3e 3f 3c  /li>.  @  <li>?<
0b60: 2f 6c 69 3e 0a 20 20 40 20 3c 2f 75 6c 3e 0a 20  /li>.  @ </ul>. 
0b70: 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b   style_footer();
0b80: 0a 7d 0a                                         .}.