root/htags/cache.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cache_open
  2. cache_put
  3. cache_get
  4. cache_close

   1 /*
   2  * Copyright (c) 2004, 2005, 2010 Tama Communications Corporation
   3  *
   4  * This file is part of GNU GLOBAL.
   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, either version 3 of the License, or
   9  * (at your option) any later version.
  10  * 
  11  * This program is distributed in the hope that it will be useful,
  12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  * GNU General Public License for more details.
  15  * 
  16  * You should have received a copy of the GNU General Public License
  17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18  */
  19 #ifdef HAVE_CONFIG_H
  20 #include <config.h>
  21 #endif
  22 #include <stdio.h>
  23 #ifdef HAVE_STRING_H
  24 #include <string.h>
  25 #else
  26 #include <strings.h>
  27 #endif
  28 #include <errno.h>
  29 #include "global.h"
  30 #include "assoc.h"
  31 #include "htags.h"
  32 #include "cache.h"
  33 
  34 static ASSOC *assoc[GTAGLIM];
  35 /**
  36  * @file
  37  *
  38  * Cache file is used for duplicate object entry.
  39  *
  40  * @par
  41  * If function 'func()' is defined more than once then the cache record
  42  * of @NAME{GTAGS} has @STRONG{(1)} the frequency and the name of duplicate object entry file,
  43  * else it has @STRONG{(2)} the tag definition. <br>
  44  * It can be distinguished the first character of the cache record.
  45  * If it is a blank then it is the former else the latter.
  46  *
  47  * @par
  48  * @STRONG{(1)} Duplicate tag file
  49  * @code{.txt}
  50  *      +-----------------------+
  51  *      |' '<fid>\0<frequency>\0|
  52  *      +-----------------------+
  53  * @endcode
  54  *    Duplicate tag file can be referred to as @FILE{D/\<fid\>.html}.
  55  *      
  56  * @par
  57  * @STRONG{(2)} Tag definition
  58  * @code{.txt}
  59  *      +----------------------+
  60  *      |<line number>\0<fid>\0|
  61  *      +----------------------+
  62  * @endcode
  63  *    Tag is referred to as @FILE{S/\<fid\>.html\#\<line number\>}.
  64  */
  65 
  66 /**
  67  * cache_open: open cache file.
  68  */
  69 void
  70 cache_open(void)
  71 {
  72         assoc[GTAGS]  = assoc_open();
  73         assoc[GRTAGS] = assoc_open();
  74         assoc[GSYMS] = symbol ? assoc_open() : NULL;
  75 }
  76 /**
  77  * cache_put: put tag line.
  78  *
  79  *      @param[in]      db      db type
  80  *      @param[in]      tag     tag name
  81  *      @param[in]      line    tag line
  82  *      @param[in]      len
  83  */
  84 void
  85 cache_put(int db, const char *tag, const char *line, int len)
  86 {
  87         if (db >= GTAGLIM)
  88                 die("I don't know such tag file.");
  89         assoc_put_withlen(assoc[db], tag, line, len);
  90 }
  91 /**
  92  * cache_get: get tag line.
  93  *
  94  *      @param[in]      db      db type
  95  *      @param[in]      tag     tag name
  96  *      @return         tag line
  97  */
  98 const char *
  99 cache_get(int db, const char *tag)
 100 {
 101         if (db >= GTAGLIM)
 102                 die("I don't know such tag file.");
 103         return assoc_get(assoc[db], tag);
 104 }
 105 /**
 106  * cache_close: close cache file.
 107  */
 108 void
 109 cache_close(void)
 110 {
 111         int i;
 112 
 113         for (i = GTAGS; i < GTAGLIM; i++) {
 114                 if (assoc[i]) {
 115                         assoc_close(assoc[i]);
 116                         assoc[i] = NULL;
 117                 }
 118         }
 119 }

/* [previous][next][first][last][top][bottom][index][help] */