Hex Artifact Content
Not logged in

Artifact a7cfef3b71e4923fb19ddc4d9fa9007fcfe915ad:

File src/mkindex.c part of check-in [dbda8d6ce9] - Initial check-in of m1 sources. by drh on 2007-07-21 14:10:57.

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 32 20 44 2e 20 52 69 63 68  (c) 2002 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 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75  .** .** You shou
0230: 6c 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64  ld have received
0240: 20 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47   a copy of the G
0250: 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69  NU General Publi
0260: 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f  c.** License alo
0270: 6e 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62  ng with this lib
0280: 72 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72  rary; if not, wr
0290: 69 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72  ite to the.** Fr
02a0: 65 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e  ee Software Foun
02b0: 64 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39  dation, Inc., 59
02c0: 20 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20   Temple Place - 
02d0: 53 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f  Suite 330,.** Bo
02e0: 73 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d  ston, MA  02111-
02f0: 31 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a  1307, USA..**.**
0300: 20 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20   Author contact 
0310: 69 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20  information:.** 
0320: 20 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a    drh@hwaci.com.
0330: 2a 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e  **   http://www.
0340: 68 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a  hwaci.com/drh/.*
0350: 2a 0a 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: 2a 0a 2a 2a 0a 2a 2a 20 42 75 69 6c 64 20 61 20  *.**.** Build a 
03b0: 73 74 61 74 69 63 20 68 61 73 68 20 74 61 62 6c  static hash tabl
03c0: 65 20 74 68 61 74 20 6d 61 70 73 20 55 52 4c 73  e that maps URLs
03d0: 20 69 6e 74 6f 20 66 75 6e 63 74 69 6f 6e 73 20   into functions 
03e0: 74 6f 20 67 65 6e 65 72 61 74 65 0a 2a 2a 20 77  to generate.** w
03f0: 65 62 20 70 61 67 65 73 2e 0a 2a 2a 0a 2a 2a 20  eb pages..**.** 
0400: 54 68 65 20 73 6f 75 72 63 65 20 63 6f 64 65 20  The source code 
0410: 69 73 20 73 63 61 6e 6e 65 64 20 66 6f 72 20 63  is scanned for c
0420: 6f 6d 6d 65 6e 74 20 6c 69 6e 65 73 20 6f 66 20  omment lines of 
0430: 74 68 65 20 66 6f 72 6d 3a 0a 2a 2a 0a 2a 2a 20  the form:.**.** 
0440: 20 20 20 20 20 20 57 45 42 50 41 47 45 3a 20 20        WEBPAGE:  
0450: 2f 61 62 63 2f 78 79 7a 0a 2a 2a 0a 2a 2a 20 54  /abc/xyz.**.** T
0460: 68 69 73 20 63 6f 6d 6d 65 6e 74 20 73 68 6f 75  his comment shou
0470: 6c 64 20 62 65 20 66 6f 6c 6c 6f 77 65 64 20 62  ld be followed b
0480: 79 20 61 20 66 75 6e 63 74 69 6f 6e 20 64 65 66  y a function def
0490: 69 6e 69 74 69 6f 6e 20 6f 66 20 74 68 65 0a 2a  inition of the.*
04a0: 2a 20 66 6f 72 6d 3a 0a 2a 2a 0a 2a 2a 20 20 20  * form:.**.**   
04b0: 20 20 20 20 76 6f 69 64 20 66 75 6e 63 74 69 6f      void functio
04c0: 6e 5f 6e 61 6d 65 28 76 6f 69 64 29 7b 0a 2a 2a  n_name(void){.**
04d0: 0a 2a 2a 20 54 68 69 73 20 72 6f 75 74 69 6e 65  .** This routine
04e0: 20 63 72 65 61 74 65 73 20 43 20 73 6f 75 72 63   creates C sourc
04f0: 65 20 63 6f 64 65 20 66 6f 72 20 61 20 63 6f 6e  e code for a con
0500: 73 74 61 6e 74 20 74 61 62 6c 65 20 74 68 61 74  stant table that
0510: 20 6d 61 70 73 0a 2a 2a 20 77 65 62 70 61 67 65   maps.** webpage
0520: 20 6e 61 6d 65 20 69 6e 74 6f 20 70 6f 69 6e 74   name into point
0530: 65 72 73 20 74 6f 20 74 68 65 20 66 75 6e 63 74  ers to the funct
0540: 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 57 65 20 61 6c  ion..**.** We al
0550: 73 6f 20 73 63 61 6e 20 66 6f 72 20 63 6f 6d 6d  so scan for comm
0560: 65 6e 74 73 20 6c 69 6e 65 73 20 6f 66 20 74 68  ents lines of th
0570: 69 73 20 66 6f 72 6d 3a 0a 2a 2a 0a 2a 2a 20 20  is form:.**.**  
0580: 20 20 20 20 20 43 4f 4d 4d 41 4e 44 3a 20 20 63       COMMAND:  c
0590: 6d 64 6e 61 6d 65 0a 2a 2a 0a 2a 2a 20 54 68 65  mdname.**.** The
05a0: 73 65 20 65 6e 74 72 69 65 73 20 62 75 69 6c 64  se entries build
05b0: 20 61 20 63 6f 6e 73 74 61 6e 74 20 74 61 62 6c   a constant tabl
05c0: 65 20 75 73 65 64 20 74 6f 20 6d 61 70 20 63 6f  e used to map co
05d0: 6d 6d 61 6e 64 20 6e 61 6d 65 73 20 69 6e 74 6f  mmand names into
05e0: 0a 2a 2a 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a  .** functions..*
05f0: 2f 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69  /.#include <stdi
0600: 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73  o.h>.#include <s
0610: 74 64 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64  tdlib.h>.#includ
0620: 65 20 3c 63 74 79 70 65 2e 68 3e 0a 23 69 6e 63  e <ctype.h>.#inc
0630: 6c 75 64 65 20 3c 61 73 73 65 72 74 2e 68 3e 0a  lude <assert.h>.
0640: 23 69 6e 63 6c 75 64 65 20 3c 73 74 72 69 6e 67  #include <string
0650: 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20  .h>../*.** Each 
0660: 65 6e 74 72 79 20 6c 6f 6f 6b 73 20 6c 69 6b 65  entry looks like
0670: 20 74 68 69 73 3a 0a 2a 2f 0a 74 79 70 65 64 65   this:.*/.typede
0680: 66 20 73 74 72 75 63 74 20 45 6e 74 72 79 20 7b  f struct Entry {
0690: 0a 20 20 69 6e 74 20 65 54 79 70 65 3b 0a 20 20  .  int eType;.  
06a0: 63 68 61 72 20 2a 7a 46 75 6e 63 3b 0a 20 20 63  char *zFunc;.  c
06b0: 68 61 72 20 2a 7a 50 61 74 68 3b 0a 7d 20 45 6e  har *zPath;.} En
06c0: 74 72 79 3b 0a 0a 2f 2a 0a 2a 2a 20 4d 61 78 69  try;../*.** Maxi
06d0: 6d 75 6d 20 6e 75 6d 62 65 72 20 6f 66 20 65 6e  mum number of en
06e0: 74 72 69 65 73 0a 2a 2f 0a 23 64 65 66 69 6e 65  tries.*/.#define
06f0: 20 4e 5f 45 4e 54 52 59 20 35 30 30 0a 0a 2f 2a   N_ENTRY 500../*
0700: 0a 2a 2a 20 54 61 62 6c 65 20 6f 66 20 65 6e 74  .** Table of ent
0710: 72 69 65 73 0a 2a 2f 0a 45 6e 74 72 79 20 61 45  ries.*/.Entry aE
0720: 6e 74 72 79 5b 4e 5f 45 4e 54 52 59 5d 3b 0a 0a  ntry[N_ENTRY];..
0730: 2f 2a 0a 2a 2a 20 48 6f 77 20 6d 61 6e 79 20 65  /*.** How many e
0740: 6e 74 72 69 65 73 20 61 72 65 20 75 73 65 64 0a  ntries are used.
0750: 2a 2f 0a 69 6e 74 20 6e 55 73 65 64 3b 0a 69 6e  */.int nUsed;.in
0760: 74 20 6e 46 69 78 65 64 3b 0a 0a 2f 2a 0a 2a 2a  t nFixed;../*.**
0770: 20 43 75 72 72 65 6e 74 20 66 69 6c 65 6e 61 6d   Current filenam
0780: 65 20 61 6e 64 20 6c 69 6e 65 20 6e 75 6d 62 65  e and line numbe
0790: 72 0a 2a 2f 0a 63 68 61 72 20 2a 7a 46 69 6c 65  r.*/.char *zFile
07a0: 3b 0a 69 6e 74 20 6e 4c 69 6e 65 3b 0a 0a 2f 2a  ;.int nLine;../*
07b0: 0a 2a 2a 20 44 75 70 6c 69 63 61 74 65 20 4e 20  .** Duplicate N 
07c0: 63 68 61 72 61 63 74 65 72 73 20 6f 66 20 61 20  characters of a 
07d0: 73 74 72 69 6e 67 2e 0a 2a 2f 0a 63 68 61 72 20  string..*/.char 
07e0: 2a 73 74 72 69 6e 67 5f 64 75 70 28 63 6f 6e 73  *string_dup(cons
07f0: 74 20 63 68 61 72 20 2a 7a 53 72 63 2c 20 69 6e  t char *zSrc, in
0800: 74 20 6e 29 7b 0a 20 20 63 68 61 72 20 2a 7a 3b  t n){.  char *z;
0810: 0a 20 20 69 66 28 20 6e 3c 30 20 29 20 6e 20 3d  .  if( n<0 ) n =
0820: 20 73 74 72 6c 65 6e 28 7a 53 72 63 29 3b 0a 20   strlen(zSrc);. 
0830: 20 7a 20 3d 20 6d 61 6c 6c 6f 63 28 20 6e 2b 31   z = malloc( n+1
0840: 20 29 3b 0a 20 20 69 66 28 20 7a 3d 3d 30 20 29   );.  if( z==0 )
0850: 7b 20 66 70 72 69 6e 74 66 28 73 74 64 65 72 72  { fprintf(stderr
0860: 2c 22 4f 75 74 20 6f 66 20 6d 65 6d 6f 72 79 21  ,"Out of memory!
0870: 5c 6e 22 29 3b 20 65 78 69 74 28 31 29 3b 20 7d  \n"); exit(1); }
0880: 0a 20 20 73 74 72 6e 63 70 79 28 7a 2c 20 7a 53  .  strncpy(z, zS
0890: 72 63 2c 20 6e 29 3b 0a 20 20 7a 5b 6e 5d 20 3d  rc, n);.  z[n] =
08a0: 20 30 3b 0a 20 20 72 65 74 75 72 6e 20 7a 3b 0a   0;.  return z;.
08b0: 7d 0a 0a 2f 2a 0a 2a 2a 20 53 63 61 6e 20 61 20  }../*.** Scan a 
08c0: 6c 69 6e 65 20 6c 6f 6f 6b 69 6e 67 20 66 6f 72  line looking for
08d0: 20 63 6f 6d 6d 65 6e 74 73 20 63 6f 6e 74 61 69   comments contai
08e0: 6e 69 6e 67 20 7a 4c 61 62 65 6c 2e 20 20 4d 61  ning zLabel.  Ma
08f0: 6b 65 0a 2a 2a 20 6e 65 77 20 65 6e 74 72 69 65  ke.** new entrie
0900: 73 20 69 66 20 66 6f 75 6e 64 2e 0a 2a 2f 0a 76  s if found..*/.v
0910: 6f 69 64 20 73 63 61 6e 5f 66 6f 72 5f 6c 61 62  oid scan_for_lab
0920: 65 6c 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  el(const char *z
0930: 4c 61 62 65 6c 2c 20 63 68 61 72 20 2a 7a 4c 69  Label, char *zLi
0940: 6e 65 2c 20 69 6e 74 20 65 54 79 70 65 29 7b 0a  ne, int eType){.
0950: 20 20 69 6e 74 20 69 2c 20 6a 3b 0a 20 20 69 6e    int i, j;.  in
0960: 74 20 6c 65 6e 20 3d 20 73 74 72 6c 65 6e 28 7a  t len = strlen(z
0970: 4c 61 62 65 6c 29 3b 0a 20 20 69 66 28 20 6e 55  Label);.  if( nU
0980: 73 65 64 3e 3d 4e 5f 45 4e 54 52 59 20 29 20 72  sed>=N_ENTRY ) r
0990: 65 74 75 72 6e 3b 0a 20 20 66 6f 72 28 69 3d 30  eturn;.  for(i=0
09a0: 3b 20 69 73 73 70 61 63 65 28 7a 4c 69 6e 65 5b  ; isspace(zLine[
09b0: 69 5d 29 20 7c 7c 20 7a 4c 69 6e 65 5b 69 5d 3d  i]) || zLine[i]=
09c0: 3d 27 2a 27 3b 20 69 2b 2b 29 7b 7d 0a 20 20 69  ='*'; i++){}.  i
09d0: 66 28 20 7a 4c 69 6e 65 5b 69 5d 21 3d 7a 4c 61  f( zLine[i]!=zLa
09e0: 62 65 6c 5b 30 5d 20 29 20 72 65 74 75 72 6e 3b  bel[0] ) return;
09f0: 0a 20 20 69 66 28 20 73 74 72 6e 63 6d 70 28 26  .  if( strncmp(&
0a00: 7a 4c 69 6e 65 5b 69 5d 2c 7a 4c 61 62 65 6c 2c  zLine[i],zLabel,
0a10: 20 6c 65 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 20   len)==0 ){.    
0a20: 69 20 2b 3d 20 6c 65 6e 3b 0a 20 20 7d 65 6c 73  i += len;.  }els
0a30: 65 7b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20  e{.    return;. 
0a40: 20 7d 0a 20 20 77 68 69 6c 65 28 20 69 73 73 70   }.  while( issp
0a50: 61 63 65 28 7a 4c 69 6e 65 5b 69 5d 29 20 29 7b  ace(zLine[i]) ){
0a60: 20 69 2b 2b 3b 20 7d 0a 20 20 69 66 28 20 7a 4c   i++; }.  if( zL
0a70: 69 6e 65 5b 69 5d 3d 3d 27 2f 27 20 29 20 69 2b  ine[i]=='/' ) i+
0a80: 2b 3b 0a 20 20 66 6f 72 28 6a 3d 30 3b 20 7a 4c  +;.  for(j=0; zL
0a90: 69 6e 65 5b 69 2b 6a 5d 20 26 26 20 21 69 73 73  ine[i+j] && !iss
0aa0: 70 61 63 65 28 7a 4c 69 6e 65 5b 69 2b 6a 5d 29  pace(zLine[i+j])
0ab0: 3b 20 6a 2b 2b 29 7b 7d 0a 20 20 61 45 6e 74 72  ; j++){}.  aEntr
0ac0: 79 5b 6e 55 73 65 64 5d 2e 65 54 79 70 65 20 3d  y[nUsed].eType =
0ad0: 20 65 54 79 70 65 3b 0a 20 20 61 45 6e 74 72 79   eType;.  aEntry
0ae0: 5b 6e 55 73 65 64 5d 2e 7a 50 61 74 68 20 3d 20  [nUsed].zPath = 
0af0: 73 74 72 69 6e 67 5f 64 75 70 28 26 7a 4c 69 6e  string_dup(&zLin
0b00: 65 5b 69 5d 2c 20 6a 29 3b 0a 20 20 61 45 6e 74  e[i], j);.  aEnt
0b10: 72 79 5b 6e 55 73 65 64 5d 2e 7a 46 75 6e 63 20  ry[nUsed].zFunc 
0b20: 3d 20 30 3b 0a 20 20 6e 55 73 65 64 2b 2b 3b 0a  = 0;.  nUsed++;.
0b30: 7d 0a 0a 2f 2a 0a 2a 2a 20 53 63 61 6e 20 61 20  }../*.** Scan a 
0b40: 6c 69 6e 65 20 66 6f 72 20 61 20 66 75 6e 63 74  line for a funct
0b50: 69 6f 6e 20 74 68 61 74 20 69 6d 70 6c 65 6d 65  ion that impleme
0b60: 6e 74 73 20 61 20 77 65 62 20 70 61 67 65 20 6f  nts a web page o
0b70: 72 20 63 6f 6d 6d 61 6e 64 2e 0a 2a 2f 0a 76 6f  r command..*/.vo
0b80: 69 64 20 73 63 61 6e 5f 66 6f 72 5f 66 75 6e 63  id scan_for_func
0b90: 28 63 68 61 72 20 2a 7a 4c 69 6e 65 29 7b 0a 20  (char *zLine){. 
0ba0: 20 69 6e 74 20 69 2c 6a 2c 6b 3b 20 0a 20 20 69   int i,j,k; .  i
0bb0: 66 28 20 6e 55 73 65 64 3c 3d 6e 46 69 78 65 64  f( nUsed<=nFixed
0bc0: 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 66 6f 72   ) return;.  for
0bd0: 28 69 3d 30 3b 20 69 73 73 70 61 63 65 28 7a 4c  (i=0; isspace(zL
0be0: 69 6e 65 5b 69 5d 29 3b 20 69 2b 2b 29 7b 7d 0a  ine[i]); i++){}.
0bf0: 20 20 69 66 28 20 7a 4c 69 6e 65 5b 69 5d 3d 3d    if( zLine[i]==
0c00: 30 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 69 66  0 ) return;.  if
0c10: 28 20 73 74 72 6e 63 6d 70 28 26 7a 4c 69 6e 65  ( strncmp(&zLine
0c20: 5b 69 5d 2c 22 76 6f 69 64 22 2c 34 29 21 3d 30  [i],"void",4)!=0
0c30: 20 29 7b 0a 20 20 20 20 69 66 28 20 7a 4c 69 6e   ){.    if( zLin
0c40: 65 5b 69 5d 21 3d 27 2a 27 20 29 20 67 6f 74 6f  e[i]!='*' ) goto
0c50: 20 70 61 67 65 5f 73 6b 69 70 3b 0a 20 20 20 20   page_skip;.    
0c60: 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 69 20  return;.  }.  i 
0c70: 2b 3d 20 34 3b 0a 20 20 69 66 28 20 21 69 73 73  += 4;.  if( !iss
0c80: 70 61 63 65 28 7a 4c 69 6e 65 5b 69 5d 29 20 29  pace(zLine[i]) )
0c90: 20 67 6f 74 6f 20 70 61 67 65 5f 73 6b 69 70 3b   goto page_skip;
0ca0: 0a 20 20 77 68 69 6c 65 28 20 69 73 73 70 61 63  .  while( isspac
0cb0: 65 28 7a 4c 69 6e 65 5b 69 5d 29 20 29 7b 20 69  e(zLine[i]) ){ i
0cc0: 2b 2b 3b 20 7d 0a 20 20 66 6f 72 28 6a 3d 30 3b  ++; }.  for(j=0;
0cd0: 20 69 73 61 6c 6e 75 6d 28 7a 4c 69 6e 65 5b 69   isalnum(zLine[i
0ce0: 2b 6a 5d 29 20 7c 7c 20 7a 4c 69 6e 65 5b 69 2b  +j]) || zLine[i+
0cf0: 6a 5d 3d 3d 27 5f 27 3b 20 6a 2b 2b 29 7b 7d 0a  j]=='_'; j++){}.
0d00: 20 20 69 66 28 20 6a 3d 3d 30 20 29 20 67 6f 74    if( j==0 ) got
0d10: 6f 20 70 61 67 65 5f 73 6b 69 70 3b 0a 20 20 66  o page_skip;.  f
0d20: 6f 72 28 6b 3d 6e 46 69 78 65 64 3b 20 6b 3c 6e  or(k=nFixed; k<n
0d30: 55 73 65 64 3b 20 6b 2b 2b 29 7b 0a 20 20 20 20  Used; k++){.    
0d40: 61 45 6e 74 72 79 5b 6b 5d 2e 7a 46 75 6e 63 20  aEntry[k].zFunc 
0d50: 3d 20 73 74 72 69 6e 67 5f 64 75 70 28 26 7a 4c  = string_dup(&zL
0d60: 69 6e 65 5b 69 5d 2c 20 6a 29 3b 0a 20 20 7d 0a  ine[i], j);.  }.
0d70: 20 20 69 2b 3d 6a 3b 0a 20 20 77 68 69 6c 65 28    i+=j;.  while(
0d80: 20 69 73 73 70 61 63 65 28 7a 4c 69 6e 65 5b 69   isspace(zLine[i
0d90: 5d 29 20 29 7b 20 69 2b 2b 3b 20 7d 0a 20 20 69  ]) ){ i++; }.  i
0da0: 66 28 20 7a 4c 69 6e 65 5b 69 5d 21 3d 27 28 27  f( zLine[i]!='('
0db0: 20 29 20 67 6f 74 6f 20 70 61 67 65 5f 73 6b 69   ) goto page_ski
0dc0: 70 3b 0a 20 20 6e 46 69 78 65 64 20 3d 20 6e 55  p;.  nFixed = nU
0dd0: 73 65 64 3b 0a 20 20 72 65 74 75 72 6e 3b 0a 0a  sed;.  return;..
0de0: 70 61 67 65 5f 73 6b 69 70 3a 20 20 20 0a 20 20  page_skip:   .  
0df0: 20 66 6f 72 28 69 3d 6e 46 69 78 65 64 3b 20 69   for(i=nFixed; i
0e00: 3c 6e 55 73 65 64 3b 20 69 2b 2b 29 7b 0a 20 20  <nUsed; i++){.  
0e10: 20 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65      fprintf(stde
0e20: 72 72 2c 22 25 73 3a 25 64 3a 20 73 6b 69 70 70  rr,"%s:%d: skipp
0e30: 69 6e 67 20 70 61 67 65 20 5c 22 25 73 5c 22 5c  ing page \"%s\"\
0e40: 6e 22 2c 0a 20 20 20 20 20 20 20 20 20 7a 46 69  n",.         zFi
0e50: 6c 65 2c 20 6e 4c 69 6e 65 2c 20 61 45 6e 74 72  le, nLine, aEntr
0e60: 79 5b 69 5d 2e 7a 50 61 74 68 29 3b 0a 20 20 20  y[i].zPath);.   
0e70: 7d 0a 20 20 20 6e 55 73 65 64 20 3d 20 6e 46 69  }.   nUsed = nFi
0e80: 78 65 64 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 6f  xed;.}../*.** Co
0e90: 6d 70 61 72 65 20 74 77 6f 20 65 6e 74 72 69 65  mpare two entrie
0ea0: 73 0a 2a 2f 0a 69 6e 74 20 65 5f 63 6f 6d 70 61  s.*/.int e_compa
0eb0: 72 65 28 63 6f 6e 73 74 20 76 6f 69 64 20 2a 61  re(const void *a
0ec0: 2c 20 63 6f 6e 73 74 20 76 6f 69 64 20 2a 62 29  , const void *b)
0ed0: 7b 0a 20 20 63 6f 6e 73 74 20 45 6e 74 72 79 20  {.  const Entry 
0ee0: 2a 70 41 20 3d 20 28 63 6f 6e 73 74 20 45 6e 74  *pA = (const Ent
0ef0: 72 79 2a 29 61 3b 0a 20 20 63 6f 6e 73 74 20 45  ry*)a;.  const E
0f00: 6e 74 72 79 20 2a 70 42 20 3d 20 28 63 6f 6e 73  ntry *pB = (cons
0f10: 74 20 45 6e 74 72 79 2a 29 62 3b 0a 20 20 69 6e  t Entry*)b;.  in
0f20: 74 20 78 20 3d 20 70 41 2d 3e 65 54 79 70 65 20  t x = pA->eType 
0f30: 2d 20 70 42 2d 3e 65 54 79 70 65 3b 0a 20 20 69  - pB->eType;.  i
0f40: 66 28 20 78 3d 3d 30 20 29 7b 0a 20 20 20 20 78  f( x==0 ){.    x
0f50: 20 3d 20 73 74 72 63 6d 70 28 70 41 2d 3e 7a 50   = strcmp(pA->zP
0f60: 61 74 68 2c 20 70 42 2d 3e 7a 50 61 74 68 29 3b  ath, pB->zPath);
0f70: 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 78 3b  .  }.  return x;
0f80: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 42 75 69 6c 64 20  .}../*.** Build 
0f90: 74 68 65 20 62 69 6e 61 72 79 20 73 65 61 72 63  the binary searc
0fa0: 68 20 74 61 62 6c 65 2e 0a 2a 2f 0a 76 6f 69 64  h table..*/.void
0fb0: 20 62 75 69 6c 64 5f 74 61 62 6c 65 28 76 6f 69   build_table(voi
0fc0: 64 29 7b 0a 20 20 69 6e 74 20 69 3b 0a 0a 20 20  d){.  int i;..  
0fd0: 71 73 6f 72 74 28 61 45 6e 74 72 79 2c 20 6e 46  qsort(aEntry, nF
0fe0: 69 78 65 64 2c 20 73 69 7a 65 6f 66 28 61 45 6e  ixed, sizeof(aEn
0ff0: 74 72 79 5b 30 5d 29 2c 20 65 5f 63 6f 6d 70 61  try[0]), e_compa
1000: 72 65 29 3b 0a 20 20 66 6f 72 28 69 3d 30 3b 20  re);.  for(i=0; 
1010: 69 3c 6e 46 69 78 65 64 3b 20 69 2b 2b 29 7b 0a  i<nFixed; i++){.
1020: 20 20 20 20 70 72 69 6e 74 66 28 22 65 78 74 65      printf("exte
1030: 72 6e 20 76 6f 69 64 20 25 73 28 76 6f 69 64 29  rn void %s(void)
1040: 3b 5c 6e 22 2c 20 61 45 6e 74 72 79 5b 69 5d 2e  ;\n", aEntry[i].
1050: 7a 46 75 6e 63 29 3b 0a 20 20 7d 0a 20 20 70 72  zFunc);.  }.  pr
1060: 69 6e 74 66 28 0a 20 20 20 20 22 74 79 70 65 64  intf(.    "typed
1070: 65 66 20 73 74 72 75 63 74 20 4e 61 6d 65 4d 61  ef struct NameMa
1080: 70 20 4e 61 6d 65 4d 61 70 3b 5c 6e 22 0a 20 20  p NameMap;\n".  
1090: 20 20 22 73 74 72 75 63 74 20 4e 61 6d 65 4d 61    "struct NameMa
10a0: 70 20 7b 5c 6e 22 0a 20 20 20 20 22 20 20 63 6f  p {\n".    "  co
10b0: 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b  nst char *zName;
10c0: 5c 6e 22 0a 20 20 20 20 22 20 20 76 6f 69 64 20  \n".    "  void 
10d0: 28 2a 78 46 75 6e 63 29 28 76 6f 69 64 29 3b 5c  (*xFunc)(void);\
10e0: 6e 22 0a 20 20 20 20 22 7d 3b 5c 6e 22 0a 20 20  n".    "};\n".  
10f0: 20 20 22 73 74 61 74 69 63 20 63 6f 6e 73 74 20    "static const 
1100: 4e 61 6d 65 4d 61 70 20 61 57 65 62 70 61 67 65  NameMap aWebpage
1110: 5b 5d 20 3d 20 7b 5c 6e 22 0a 20 20 29 3b 0a 20  [] = {\n".  );. 
1120: 20 66 6f 72 28 69 3d 30 3b 20 69 3c 6e 46 69 78   for(i=0; i<nFix
1130: 65 64 20 26 26 20 61 45 6e 74 72 79 5b 69 5d 2e  ed && aEntry[i].
1140: 65 54 79 70 65 3d 3d 30 3b 20 69 2b 2b 29 7b 0a  eType==0; i++){.
1150: 20 20 20 20 70 72 69 6e 74 66 28 22 20 20 7b 20      printf("  { 
1160: 5c 22 25 73 5c 22 2c 25 2a 73 20 25 73 20 7d 2c  \"%s\",%*s %s },
1170: 5c 6e 22 2c 0a 20 20 20 20 20 20 61 45 6e 74 72  \n",.      aEntr
1180: 79 5b 69 5d 2e 7a 50 61 74 68 2c 20 28 69 6e 74  y[i].zPath, (int
1190: 29 28 32 35 2d 73 74 72 6c 65 6e 28 61 45 6e 74  )(25-strlen(aEnt
11a0: 72 79 5b 69 5d 2e 7a 50 61 74 68 29 29 2c 20 22  ry[i].zPath)), "
11b0: 22 2c 0a 20 20 20 20 20 20 61 45 6e 74 72 79 5b  ",.      aEntry[
11c0: 69 5d 2e 7a 46 75 6e 63 0a 20 20 20 20 29 3b 0a  i].zFunc.    );.
11d0: 20 20 7d 0a 20 20 70 72 69 6e 74 66 28 22 7d 3b    }.  printf("};
11e0: 5c 6e 22 29 3b 0a 20 20 70 72 69 6e 74 66 28 0a  \n");.  printf(.
11f0: 20 20 20 20 22 73 74 61 74 69 63 20 63 6f 6e 73      "static cons
1200: 74 20 4e 61 6d 65 4d 61 70 20 61 43 6f 6d 6d 61  t NameMap aComma
1210: 6e 64 5b 5d 20 3d 20 7b 5c 6e 22 0a 20 20 29 3b  nd[] = {\n".  );
1220: 0a 20 20 66 6f 72 28 3b 20 69 3c 6e 46 69 78 65  .  for(; i<nFixe
1230: 64 20 26 26 20 61 45 6e 74 72 79 5b 69 5d 2e 65  d && aEntry[i].e
1240: 54 79 70 65 3d 3d 31 3b 20 69 2b 2b 29 7b 0a 20  Type==1; i++){. 
1250: 20 20 20 70 72 69 6e 74 66 28 22 20 20 7b 20 5c     printf("  { \
1260: 22 25 73 5c 22 2c 25 2a 73 20 25 73 20 7d 2c 5c  "%s\",%*s %s },\
1270: 6e 22 2c 0a 20 20 20 20 20 20 61 45 6e 74 72 79  n",.      aEntry
1280: 5b 69 5d 2e 7a 50 61 74 68 2c 20 28 69 6e 74 29  [i].zPath, (int)
1290: 28 32 35 2d 73 74 72 6c 65 6e 28 61 45 6e 74 72  (25-strlen(aEntr
12a0: 79 5b 69 5d 2e 7a 50 61 74 68 29 29 2c 20 22 22  y[i].zPath)), ""
12b0: 2c 0a 20 20 20 20 20 20 61 45 6e 74 72 79 5b 69  ,.      aEntry[i
12c0: 5d 2e 7a 46 75 6e 63 0a 20 20 20 20 29 3b 0a 20  ].zFunc.    );. 
12d0: 20 7d 0a 20 20 70 72 69 6e 74 66 28 22 7d 3b 5c   }.  printf("};\
12e0: 6e 22 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 50 72  n");.}../*.** Pr
12f0: 6f 63 65 73 73 20 61 20 73 69 6e 67 6c 65 20 66  ocess a single f
1300: 69 6c 65 20 6f 66 20 69 6e 70 75 74 0a 2a 2f 0a  ile of input.*/.
1310: 76 6f 69 64 20 70 72 6f 63 65 73 73 5f 66 69 6c  void process_fil
1320: 65 28 76 6f 69 64 29 7b 0a 20 20 46 49 4c 45 20  e(void){.  FILE 
1330: 2a 69 6e 20 3d 20 66 6f 70 65 6e 28 7a 46 69 6c  *in = fopen(zFil
1340: 65 2c 20 22 72 22 29 3b 0a 20 20 63 68 61 72 20  e, "r");.  char 
1350: 7a 4c 69 6e 65 5b 32 30 30 30 5d 3b 0a 20 20 69  zLine[2000];.  i
1360: 66 28 20 69 6e 3d 3d 30 20 29 7b 0a 20 20 20 20  f( in==0 ){.    
1370: 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 22  fprintf(stderr,"
1380: 25 73 3a 20 63 61 6e 6e 6f 74 20 6f 70 65 6e 5c  %s: cannot open\
1390: 6e 22 2c 20 7a 46 69 6c 65 29 3b 0a 20 20 20 20  n", zFile);.    
13a0: 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 6e 4c  return;.  }.  nL
13b0: 69 6e 65 20 3d 20 30 3b 0a 20 20 77 68 69 6c 65  ine = 0;.  while
13c0: 28 20 66 67 65 74 73 28 7a 4c 69 6e 65 2c 20 73  ( fgets(zLine, s
13d0: 69 7a 65 6f 66 28 7a 4c 69 6e 65 29 2c 20 69 6e  izeof(zLine), in
13e0: 29 20 29 7b 0a 20 20 20 20 6e 4c 69 6e 65 2b 2b  ) ){.    nLine++
13f0: 3b 0a 20 20 20 20 73 63 61 6e 5f 66 6f 72 5f 6c  ;.    scan_for_l
1400: 61 62 65 6c 28 22 57 45 42 50 41 47 45 3a 22 2c  abel("WEBPAGE:",
1410: 7a 4c 69 6e 65 2c 30 29 3b 0a 20 20 20 20 73 63  zLine,0);.    sc
1420: 61 6e 5f 66 6f 72 5f 6c 61 62 65 6c 28 22 43 4f  an_for_label("CO
1430: 4d 4d 41 4e 44 3a 22 2c 7a 4c 69 6e 65 2c 31 29  MMAND:",zLine,1)
1440: 3b 0a 20 20 20 20 73 63 61 6e 5f 66 6f 72 5f 66  ;.    scan_for_f
1450: 75 6e 63 28 7a 4c 69 6e 65 29 3b 0a 20 20 7d 0a  unc(zLine);.  }.
1460: 20 20 66 63 6c 6f 73 65 28 69 6e 29 3b 0a 20 20    fclose(in);.  
1470: 6e 55 73 65 64 20 3d 20 6e 46 69 78 65 64 3b 20  nUsed = nFixed; 
1480: 0a 7d 0a 0a 69 6e 74 20 6d 61 69 6e 28 69 6e 74  .}..int main(int
1490: 20 61 72 67 63 2c 20 63 68 61 72 20 2a 2a 61 72   argc, char **ar
14a0: 67 76 29 7b 0a 20 20 69 6e 74 20 69 3b 0a 20 20  gv){.  int i;.  
14b0: 66 6f 72 28 69 3d 31 3b 20 69 3c 61 72 67 63 3b  for(i=1; i<argc;
14c0: 20 69 2b 2b 29 7b 0a 20 20 20 20 7a 46 69 6c 65   i++){.    zFile
14d0: 20 3d 20 61 72 67 76 5b 69 5d 3b 0a 20 20 20 20   = argv[i];.    
14e0: 70 72 6f 63 65 73 73 5f 66 69 6c 65 28 29 3b 0a  process_file();.
14f0: 20 20 7d 0a 20 20 62 75 69 6c 64 5f 74 61 62 6c    }.  build_tabl
1500: 65 28 29 3b 0a 20 20 72 65 74 75 72 6e 20 30 3b  e();.  return 0;
1510: 0a 7d 0a                                         .}.