1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
* Copyright (c) 2004 Tama Communications Corporation
*
* This file is part of GNU GLOBAL.
*
* GNU GLOBAL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU GLOBAL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef STDC_HEADERS
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include "global.h"
#include "assoc.h"
#include "htags.h"
#include "path2url.h"
static ASSOC *assoc;
static int nextkey;
/*
* load_gpath: load gpath tag file.
*
* load the contents of GPATH file into the memory.
*/
void
load_gpath(dbpath)
const char *dbpath;
{
DBOP *dbop;
const char *path;
int n;
assoc = assoc_open('a');
nextkey = 0;
dbop = dbop_open(makepath(dbpath, dbname(GPATH), NULL), 0, 0, 0);
if (dbop == NULL)
die("cannot open '%s'.", makepath(dbpath, dbname(GPATH), NULL));
for (path = dbop_first(dbop, "./", NULL, DBOP_PREFIX | DBOP_KEY); path; path = dbop_next(dbop)) {
const char *no = dbop_lastdat(dbop);
path += 2; /* remove './' */
assoc_put(assoc, path, no);
n = atoi(no);
if (n > nextkey)
nextkey = n;
}
dbop_close(dbop);
}
/*
* unload_gpath: load gpath tag file.
*
* load the contents of GPATH file into the memory.
*/
void
unload_gpath(void)
{
assoc_close(assoc);
}
/*
* path2fid: convert the path name into the file id.
*
* i) path path name
* r) id
*/
const char *
path2fid(path)
const char *path;
{
static char number[32];
const char *p;
if (strlen(path) > MAXPATHLEN)
die("path name too long. '%s'", path);
/*
* accept both aaa and ./aaa.
*/
if (*path == '.' && *(path + 1) == '/')
path += 2;
p = assoc_get(assoc, path);
if (!p) {
snprintf(number, sizeof(number), "%d", ++nextkey);
assoc_put(assoc, path, number);
p = number;
}
return p;
}
|