示例#1
0
/**
 * configpath: get path of configuration file.
 *
 *	@param[in]	rootdir	Project root directory
 *	@return		path name of the configuration file or NULL
 */
static char *
configpath(const char *rootdir)
{
	STATIC_STRBUF(sb);
	const char *p;

	strbuf_clear(sb);
	/*
	 * at first, check environment variable GTAGSCONF.
	 */
	if (getenv("GTAGSCONF") != NULL)
		strbuf_puts(sb, getenv("GTAGSCONF"));
	/*
	 * if GTAGSCONF not set then check standard config files.
	 */
	else if (rootdir && *rootdir && test("r", makepath(rootdir, "gtags.conf", NULL)))
		strbuf_puts(sb, makepath(rootdir, "gtags.conf", NULL));
	else if ((p = get_home_directory()) && test("r", makepath(p, GTAGSRC, NULL)))
		strbuf_puts(sb, makepath(p, GTAGSRC, NULL));
#ifdef __DJGPP__
	else if ((p = get_home_directory()) && test("r", makepath(p, DOS_GTAGSRC, NULL)))
		strbuf_puts(sb, makepath(p, DOS_GTAGSRC, NULL));
#endif
	else if (test("r", GTAGSCONF))
		strbuf_puts(sb, GTAGSCONF);
	else if (test("r", DEBIANCONF))
		strbuf_puts(sb, DEBIANCONF);
	else if (test("r", makepath(SYSCONFDIR, "gtags.conf", NULL)))
		strbuf_puts(sb, makepath(SYSCONFDIR, "gtags.conf", NULL));
	else
		return NULL;
	return strbuf_value(sb);
}
示例#2
0
/**
 * Load text from file with replacing @CODE{\@PARENT_DIR\@} macro.
 * Macro @CODE{\@PARENT_DIR\@} is replaced with the parent directory
 * of the @FILE{HTML} directory.
 */
static const char *
sed(FILE *ip, int place)
{
    STATIC_STRBUF(sb);
    const char *parent_dir = (place == SUBDIR) ? "../.." : "..";
    int c, start_position = -1;

    strbuf_clear(sb);
    while ((c = fgetc(ip)) != EOF) {
        strbuf_putc(sb, c);
        if (c == '@') {
            int curpos = strbuf_getlen(sb);
            if (start_position == -1) {
                start_position = curpos - 1;
            } else {
                if (!strncmp("@PARENT_DIR@",
                             strbuf_value(sb) + start_position,
                             curpos - start_position))
                {
                    strbuf_setlen(sb, start_position);
                    strbuf_puts(sb, parent_dir);
                    start_position = -1;
                } else {
                    start_position = curpos - 1;
                }
            }
        } else if (!isalpha(c) && c != '_') {
            if (start_position != -1)
                start_position = -1;
        }
    }
    return strbuf_value(sb);
}
示例#3
0
/**
 * args_read: read path From args.
 *
 *	@return		path (@VAR{NULL}: end of argument)
 */
const char *
args_read(void)
{
	const char *p;
	STATIC_STRBUF(sb);

	strbuf_clear(sb);
	switch (type) {
	case ARGS_NOP:
		p = NULL;
		break;
	case ARGS_ARGS:
		p = *argslist++;
		break;
	case ARGS_FILELIST:
		p = strbuf_fgets(sb, ip, STRBUF_NOCRLF);
		break;
	case ARGS_GFIND:
		p = gfind_read(gp);
		break;
	case ARGS_BOTH:
		if (*argslist != NULL)
			p = *argslist++;
		else
			p = strbuf_fgets(sb, ip, STRBUF_NOCRLF);
		break;
	default:
		die("args_read: invalid type.");
	}
	return p;
}
示例#4
0
/**
 * rewrite_string: execute rewrite against string
 *
 *	@param[in]	rewrite object
 *			NULL: just print string
 *	@param[in]	string
 *	@param[in]	offset start point of the rewriting
 *	@param[in]	file descriptor
 */
const char *
rewrite_string(REWRITE *rewrite, const char *string, int offset)
{
	STATIC_STRBUF(sb);
	regmatch_t m;

	/* if rewrite object is NULL or does not match, just return the string. */
	if (rewrite == NULL || rewrite->pattern == NULL)
		return string;
	if (regexec(&rewrite->reg, string + offset, 1, &m, 0) != 0)
		return string;
        strbuf_clear(sb);
	strbuf_nputs(sb, string, offset);
	string += offset;
	strbuf_nputs(sb, string, m.rm_so);
	if (rewrite->part[REWRITE_CENTER]) {
		strbuf_puts(sb, rewrite->part[REWRITE_CENTER]);
	} else {
		if (rewrite->part[REWRITE_LEFT])
			strbuf_puts(sb, rewrite->part[REWRITE_LEFT]);
		strbuf_nputs(sb, string + m.rm_so, m.rm_eo - m.rm_so);
		if (rewrite->part[REWRITE_RIGHT])
			strbuf_puts(sb, rewrite->part[REWRITE_RIGHT]);
	}
	strbuf_puts(sb, string + m.rm_eo);
	return (const char *)strbuf_value(sb);
}
示例#5
0
文件: dbop.c 项目: luchachen/global
/**
 * dbop_put_tag: put a tag
 *
 *	@param[in]	dbop	descripter
 *	@param[in]	name	key
 *	@param[in]	data	data
 */
void
dbop_put_tag(DBOP *dbop, const char *name, const char *data)
{
#ifdef USE_SQLITE3
	if (dbop->openflags & DBOP_SQLITE3) {
		int len;
		char fid[MAXFIDLEN], *q = fid;
		const char *p = data;

		/* extract fid */
		while (*p && isdigit(*p))
			*q++ = *p++;
		*q = '\0';
		/* trim line */
		len = strlen(data);
		if (data[len-1] == '\n')
			len--;
		if (data[len-1] == '\r')
			len--;
		if (data[len] == '\r' || data[len] == '\n') {
			STATIC_STRBUF(sb);

			strbuf_clear(sb);
			strbuf_nputs(sb, data, len);
			data = strbuf_value(sb);
		}
		dbop3_put(dbop, name, data, fid);
		return;
	}
#endif
	dbop_put(dbop, name, data);
	return;
}
示例#6
0
/**
 * Generate beginning of generic page
 *
 *	@param[in]	title	title of this page
 *	@param[in]	place	#SUBDIR: this page is in sub directory <br>
 *			#TOPDIR: this page is in the top directory
 *	@param[in]	use_frameset
 *			use frameset document type or not
 *	@param[in]	header_item
 *			item which should be inserted into the header
 */
static const char *
gen_page_generic_begin(const char *title, int place, int use_frameset, const char *header_item)
{
    STATIC_STRBUF(sb);
    const char *dir = NULL;

    switch (place) {
    case TOPDIR:
        dir = "";
        break;
    case SUBDIR:
        dir = "../";
        break;
    case CGIDIR:
        dir = "$basedir/";	/* decided by the CGI script */
        break;
    }
    strbuf_clear(sb);
    if (enable_xhtml) {
        /*
         * Since some browser cannot treat "<?xml...>", we don't
         * write the declaration as long as XHTML1.1 is not required.
         */
        if (strict_xhtml) {
            strbuf_puts_nl(sb, "<?xml version='1.0' encoding='ISO-8859-1'?>");
            strbuf_sprintf(sb, "<?xml-stylesheet type='text/css' href='%sstyle.css'?>\n", dir);
        }
        /*
         * If the --frame option are specified then we take
         * 'XHTML 1.0 Frameset' for index.html
         * and 'XHTML 1.0 Transitional' for other files,
         * else if the config variable 'xhtml_version' is
         * set to '1.1' then we take 'XHTML 1.1',
         * else 'XHTML 1.0 Transitional'.
         */
        if (use_frameset)
            strbuf_puts_nl(sb, "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Frameset//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd'>");
        else if (!Fflag && strict_xhtml)
            strbuf_puts_nl(sb, "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>");
        else
            strbuf_puts_nl(sb, "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
    }
    strbuf_puts_nl(sb, html_begin);
    strbuf_puts_nl(sb, html_head_begin);
    strbuf_puts(sb, html_title_begin);
    strbuf_puts(sb, title);
    strbuf_puts_nl(sb, html_title_end);
    strbuf_sprintf(sb, "<meta name='robots' content='noindex,nofollow'%s>\n", empty_element);
    strbuf_sprintf(sb, "<meta name='generator' content='GLOBAL-%s'%s>\n", get_version(), empty_element);
    if (enable_xhtml) {
        strbuf_sprintf(sb, "<meta http-equiv='Content-Style-Type' content='text/css'%s>\n", empty_element);
        strbuf_sprintf(sb, "<link rel='stylesheet' type='text/css' href='%sstyle.css'%s>\n", dir, empty_element);
    }
    if (header_item)
        strbuf_puts(sb, header_item);		/* internal use */
    if (html_header)
        strbuf_puts(sb, html_header);		/* --html-header=file */
    strbuf_puts(sb, html_head_end);
    return strbuf_value(sb);
}
示例#7
0
/**
 * print directory name.
 *
 *	@param[in]	level	0,1,2...
 *	@param[in]	path	path of the directory
 *	@param[in]	count	number of files in this directory
 */
static const char *
print_directory_name(int level, const char *path, int count)
{
	STATIC_STRBUF(sb);
	char tips[80];

	if (count > 1)
		snprintf(tips, sizeof(tips), "%d files", count);
	else
		snprintf(tips, sizeof(tips), "%d file", count);
	path = removedotslash(path);
	strbuf_clear(sb);
	if (table_flist)
		strbuf_puts(sb, fitem_begin);
	else if (!no_order_list)
		strbuf_puts(sb, item_begin);
	strbuf_puts(sb, gen_href_begin_with_title(level == 0 ? "files" : NULL,
			path2fid(path), HTML, NULL, tips));
	if (Iflag) {
		strbuf_puts(sb, gen_image(level == 0 ? CURRENT : PARENT, dir_icon, appendslash(path)));
		strbuf_puts(sb, quote_space);
	}
	strbuf_sprintf(sb, "%s/%s", lastpart(path), gen_href_end());
	if (table_flist)
		strbuf_puts(sb, fitem_end);
	else if (!no_order_list)
		strbuf_puts(sb, item_end);
	else
		strbuf_puts(sb, br);
	strbuf_putc(sb, '\n');
	return (const char *)strbuf_value(sb);
}
示例#8
0
/**
 * Generate list begin tag.
 */
const char *
gen_list_begin(void)
{
    STATIC_STRBUF(sb);

    if (strbuf_empty(sb)) {
        strbuf_clear(sb);
        if (table_list) {
            if (enable_xhtml) {
                strbuf_sprintf(sb, "%s\n%s%s%s%s",
                               table_begin,
                               "<tr><th class='tag'>tag</th>",
                               "<th class='line'>line</th>",
                               "<th class='file'>file</th>",
                               "<th class='code'>source code</th></tr>");
            } else {
                strbuf_sprintf(sb, "%s\n%s%s%s%s",
                               table_begin,
                               "<tr><th nowrap='nowrap' align='left'>tag</th>",
                               "<th nowrap='nowrap' align='right'>line</th>",
                               "<th nowrap='nowrap' align='center'>file</th>",
                               "<th nowrap='nowrap' align='left'>source code</th></tr>");
            }
        } else {
            strbuf_puts(sb, verbatim_begin);
        }
    }
    return strbuf_value(sb);
}
示例#9
0
/*
 * gpath_put: put path name
 *
 *	i)	path	path name
 *	i)	type	path type
 *			GPATH_SOURCE: source file
 *			GPATH_OTHER: other file
 */
void
gpath_put(const char *path, int type)
{
	char fid[MAXFIDLEN];
	STATIC_STRBUF(sb);

	assert(opened > 0);
	if (_mode == 1 && created)
		return;
	if (dbop_get(dbop, path) != NULL)
		return;
	/*
	 * generate new file id for the path.
	 */
	snprintf(fid, sizeof(fid), "%d", _nextkey++);
	/*
	 * path => fid mapping.
	 */
	strbuf_clear(sb);
	strbuf_puts0(sb, fid);
	if (type == GPATH_OTHER)
		strbuf_puts0(sb, "o");
	dbop_put_withlen(dbop, path, strbuf_value(sb), strbuf_getlen(sb));
	/*
	 * fid => path mapping.
	 */
	strbuf_clear(sb);
	strbuf_puts0(sb, path);
	if (type == GPATH_OTHER)
		strbuf_puts0(sb, "o");
	dbop_put_withlen(dbop, fid, strbuf_value(sb), strbuf_getlen(sb));
}
示例#10
0
/**
 * gpath_put: put path name
 *
 *	@param[in]	path	path name
 *	@param[in]	type	path type
 *			GPATH_SOURCE: source file,
 *			GPATH_OTHER: other file
 */
const char *
gpath_put(const char *path, int type)
{
	static char sfid[MAXFIDLEN];
	STATIC_STRBUF(sb);

	assert(opened > 0);
	if (_mode == 1 && created)
		return "";
	if (dbop_get(dbop, path) != NULL)
		return "";
	/*
	 * generate new file id for the path.
	 */
	snprintf(sfid, sizeof(sfid), "%d", _nextkey++);
	/*
	 * path => fid mapping.
	 */
	strbuf_clear(sb);
	strbuf_puts(sb, sfid);
	dbop_put_path(dbop, path, strbuf_value(sb), type == GPATH_OTHER ? "o" : NULL);
	/*
	 * fid => path mapping.
	 */
	strbuf_clear(sb);
	strbuf_puts(sb, path);
	dbop_put_path(dbop, sfid, strbuf_value(sb), type == GPATH_OTHER ? "o" : NULL);
	return (const char *)sfid;
}
示例#11
0
/**
 * Generate upper directory.
 *
 * Just returns the parent path of @a dir. (Adds @FILE{../} to it).
 */
const char *
upperdir(const char *dir)
{
    STATIC_STRBUF(sb);

    strbuf_clear(sb);
    strbuf_sprintf(sb, "../%s", dir);
    return strbuf_value(sb);
}
示例#12
0
/**
 * Generate beginning of frameset (@CODE{\<frameset\>})
 *
 *	@param[in]	contents	target
 */
const char *
gen_frameset_begin(const char *contents)
{
    STATIC_STRBUF(sb);

    strbuf_clear(sb);
    strbuf_sprintf(sb, "<frameset %s>", contents);
    return strbuf_value(sb);
}
示例#13
0
/**
 * Generate beginning of frame (@CODE{\<frame\>})
 *
 *	@param[in]	name	target (value for @CODE{name} and @CODE{id} attributes)
 *	@param[in]	src	value for @CODE{src} attribute
 */
const char *
gen_frame(const char *name, const char *src)
{
    STATIC_STRBUF(sb);

    strbuf_clear(sb);
    strbuf_sprintf(sb, "<frame name='%s' id='%s' src='%s'%s>", name, name, src, empty_element);
    return strbuf_value(sb);
}
示例#14
0
/**
 * append @CODE{'/'} after the path name
 *
 *	@param[in]	path	path name
 *	@return		appended path name
 *
 *	@note Doesn't check if ends with a @CODE{'/'} already.
 *
 * @par Examples:
 * @code
 * appendslash("a")	=> "a/"
 * @endcode
 */
static const char *
appendslash(const char *path)
{
	STATIC_STRBUF(sb);

	strbuf_clear(sb);
	strbuf_puts(sb, path);
	strbuf_putc(sb, '/');
	return strbuf_value(sb);
}
示例#15
0
/*
 * makesearchpart: make search part
 *
 *	@param[in]	target	$target
 *	@return		html
 */
static char *
makesearchpart(const char *target)
{
	STATIC_STRBUF(sb);

	strbuf_clear(sb);
	strbuf_puts(sb, header_begin);
	if (Fflag)
		strbuf_puts(sb, gen_href_begin(NULL, "search", normal_suffix, NULL));
	strbuf_puts(sb, "SEARCH");
	if (Fflag)
		strbuf_puts(sb, gen_href_end());
	strbuf_puts_nl(sb, header_end);
	if (!target) {
		strbuf_puts(sb, "Please input object name and select [Search]. POSIX's regular expression is allowed.");
		strbuf_puts_nl(sb, br);
	}
	strbuf_puts_nl(sb, gen_form_begin(target));
	strbuf_puts_nl(sb, gen_input("pattern", NULL, NULL));
	strbuf_puts_nl(sb, gen_input(NULL, "Search", "submit"));
	strbuf_puts(sb, gen_input(NULL, "Reset", "reset"));
	strbuf_puts_nl(sb, br);
	strbuf_puts(sb, gen_input_radio("type", "definition", 1, "Retrieve the definition place of the specified symbol."));
	strbuf_puts_nl(sb, target ? "Def" : "Definition");
	strbuf_puts(sb, gen_input_radio("type", "reference", 0, "Retrieve the reference place of the specified symbol."));
	strbuf_puts_nl(sb, target ? "Ref" : "Reference");
	strbuf_puts(sb, gen_input_radio("type", "symbol", 0, "Retrieve the place of the specified symbol is used."));
	strbuf_puts_nl(sb, target ? "Sym" : "Other symbol");
	strbuf_puts(sb, gen_input_radio("type", "path", 0, "Look for path name which matches to the specified pattern."));
	strbuf_puts_nl(sb, target ? "Path" : "Path name");
	if (enable_grep) {
		strbuf_puts(sb, gen_input_radio("type", "grep", 0, "Retrieve lines which matches to the specified pattern."));
		strbuf_puts_nl(sb, target ? "Grep" : "Grep pattern");
	}
	if (enable_idutils && test("f", makepath(dbpath, "ID", NULL))) {
		strbuf_puts(sb, gen_input_radio("type", "idutils", 0, "Retrieve lines which matches to the specified pattern using idutils(1)."));
		strbuf_puts_nl(sb, target ? "Id" : "Id pattern");
	}
	strbuf_puts_nl(sb, br);
	strbuf_puts(sb, gen_input_checkbox("icase", NULL, "Ignore case distinctions in the pattern."));
	strbuf_puts_nl(sb, target ? "Icase" : "Ignore case");
	if (other_files) {
		strbuf_puts(sb, gen_input_checkbox("other", NULL, "Files other than the source code are also retrieved."));
		strbuf_puts_nl(sb, target ? "Other" : "Other files");
	}
	if (other_files && !target) {
		strbuf_puts_nl(sb, br);
		strbuf_puts(sb, "('Other files' is effective only to 'Path name'");
		if (enable_grep)
			strbuf_puts(sb, " and 'Grep pattern'");
		strbuf_puts_nl(sb, ".)");
	}
	strbuf_puts_nl(sb, gen_form_end());
	return strbuf_value(sb);
}
示例#16
0
/**
 * print file name.
 *
 *	@param[in]	level	0,1,2...
 *	@param[in]	path	path of the file
 */
static const char *
print_file_name(int level, const char *path)
{
	STATIC_STRBUF(sb);
	char *target = (Fflag) ? "mains" : "_top";
	int size = filesize(path);
	char tips[80];

	message(" [%d] adding %s", ++src_count, removedotslash(path));
	/*
	 * We assume the file which has one of the following suffixes
	 * as a candidate of include file.
	 *
	 * C: .h
	 * C++: .hxx, .hpp, .H, .hh
	 * PHP: .inc.php
	 */
	if (regexec(&is_include_file, path, 0, 0, 0) == 0)
		put_inc(lastpart(path), path, src_count);
	strbuf_clear(sb);
	if (table_flist)
		strbuf_puts(sb, fitem_begin);
	else if (!no_order_list)
		strbuf_puts(sb, item_begin);
	if (size > 1)
		snprintf(tips, sizeof(tips), "%s bytes", insert_comma(size));
	else
		snprintf(tips, sizeof(tips), "%s byte", insert_comma(size));
	strbuf_puts(sb, gen_href_begin_with_title_target(level == 0 ? SRCS: upperdir(SRCS),
			path2fid(path), HTML, NULL, tips, target));
	if (Iflag) {
		const char *lang, *suffix, *text_icon;

		if ((suffix = locatestring(path, ".", MATCH_LAST)) != NULL
		    && (lang = decide_lang(suffix)) != NULL
		    && (strcmp(lang, "c") == 0 || strcmp(lang, "cpp") == 0
		       || strcmp(lang, "yacc") == 0))
			text_icon = c_icon;
		else
			text_icon = file_icon;
		strbuf_puts(sb, gen_image(level == 0 ? CURRENT : PARENT, text_icon, removedotslash(path)));
		strbuf_puts(sb, quote_space);
	}
	strbuf_puts(sb, full_path ? removedotslash(path) : lastpart(path));
	strbuf_puts(sb, gen_href_end());
	if (table_flist)
		strbuf_puts(sb, fitem_end);
	else if (!no_order_list)
		strbuf_puts(sb, item_end);
	else
		strbuf_puts(sb, br);
	strbuf_putc(sb, '\n');
	return (const char *)strbuf_value(sb);
}
示例#17
0
/*
 * Read line with a prompt.
 *
 * This is part of cscope protocol.
 */
static char *
get_line(void)
{
	STATIC_STRBUF(sb);

	/* Prompt */
	fputs(">> ", stdout);
	fflush(stdout);
	if (strbuf_fgets(sb, stdin, STRBUF_NOCRLF) == NULL)
		return NULL;
	return strbuf_value(sb);
}
示例#18
0
/**
 * Generate beginning of form (@CODE{\<form\>})
 *
 *	@param[in]	target	target attribute or @VAR{NULL} for no target.
 */
const char *
gen_form_begin(const char *target)
{
    STATIC_STRBUF(sb);

    strbuf_clear(sb);
    strbuf_sprintf(sb, "<form method='get' action='%s'", fix_attr_value(action));
    if (Fflag && target)
        strbuf_sprintf(sb, " target='%s'", fix_attr_value(target));
    strbuf_puts(sb, ">");
    return strbuf_value(sb);
}
示例#19
0
文件: dbop.c 项目: luchachen/global
char *
dbop3_quote(char *string) {
	STATIC_STRBUF(sb);
	char *p;

	strbuf_clear(sb);
	for (p = string; *p; p++) {
		if (*p == '\'')
			strbuf_putc(sb, '\'');
		strbuf_putc(sb, *p);
	}
	return strbuf_value(sb);
}
示例#20
0
文件: char.c 项目: GimXu/global
/**
 * quote string.
 *
 *  Non-alphanumeric characters are quoted/escaped.
 *
 *	Examples:
 *	'a:a,a' => 'a\:a\,a'
 */
const char *
quote_string(const char *s)
{
	STATIC_STRBUF(sb);

	strbuf_clear(sb);
	for (; *s; s++) {
		if (!isalnum((unsigned char)*s))
			strbuf_putc(sb, '\\');
		strbuf_putc(sb, *s);
	}
	return strbuf_value(sb);
}
示例#21
0
文件: char.c 项目: GimXu/global
/**
 * quote characters in the string.
 *
 *	Examples:
 *	quote_char('a:a,a', :) => 'a\:a,a'
 */
const char *
quote_chars(const char *s, unsigned int c)
{
	STATIC_STRBUF(sb);

	strbuf_clear(sb);
	for (; *s; s++) {
		if ((unsigned char)*s == c)
			strbuf_putc(sb, '\\');
		strbuf_putc(sb, *s);
	}
	return strbuf_value(sb);
}
示例#22
0
/*
 * Update tag files.
 */
static void
update(void)
{
	STATIC_STRBUF(command);

	strbuf_clear(command);
	strbuf_sprintf(command, "%s -u", global_path);
	if (vflag) {
		strbuf_putc(command, 'v');
		fprintf(stderr, "gscope: %s\n", strbuf_value(command));
	}
	system(strbuf_value(command));
}
示例#23
0
文件: dbop.c 项目: luchachen/global
void
dbop3_close(DBOP *dbop) {
	int rc;
	char *errmsg = 0;

	rc = sqlite3_exec(dbop->db3, "end transaction", NULL, NULL, &errmsg);
       	if (rc != SQLITE_OK)
		die("end transaction error: %s", errmsg);
	/*
	 * create index
	 */
	if (dbop->mode == 1 && dbop->openflags & DBOP_DUP) {
		STATIC_STRBUF(sql);

		strbuf_clear(sql);
		strbuf_puts(sql, "create index key_i on ");
		strbuf_puts(sql, dbop->tblname);
		strbuf_puts(sql, "(key)");
		rc = sqlite3_exec(dbop->db3, strbuf_value(sql), NULL, NULL, &errmsg);
		if (rc != SQLITE_OK)
			die("create index error: %s", errmsg);
		strbuf_clear(sql);
		strbuf_puts(sql, "create index fid_i on ");
		strbuf_puts(sql, dbop->tblname);
		strbuf_puts(sql, "(extra)");
		rc = sqlite3_exec(dbop->db3, strbuf_value(sql), NULL, NULL, &errmsg);
		if (rc != SQLITE_OK)
			die("create index error: %s", errmsg);
	}
	if (dbop->stmt) {
		rc = sqlite3_finalize(dbop->stmt);
		if (rc != SQLITE_OK)
			die("sqlite3_finalize failed. (rc = %d)", rc);
		dbop->stmt = NULL;
	}
	if (dbop->stmt_put3) {
		rc = sqlite3_finalize(dbop->stmt_put3);
		if (rc != SQLITE_OK)
			die("dbop3_finalize failed. (rc = %d)", rc);
		dbop->stmt_put3 = NULL;
	}
	rc = sqlite3_close(dbop->db3);
	if (rc != SQLITE_OK)
		die("sqlite3_close failed. (rc = %d)", rc);
	dbop->db3 = NULL;
	if (dbop->tblname)
		free((void *)dbop->tblname);
	strbuf_close(dbop->sb);
	free(dbop);
}
示例#24
0
/*
 * uncompress source line.
 *
 *	i)	in	compressed string
 *	i)	name	replaced string
 *	r)		uncompressed string
 */
char *
uncompress(const char *in, const char *name)
{
	STATIC_STRBUF(sb);
	const char *p;
	int i;

	strbuf_clear(sb);
	for (p = in;  *p; p++) {
		if (*p == '@') {
			int spaces = 0;

			switch (*++p) {
			case '@':
				strbuf_putc(sb, '@');
				break;
			case 'n':
				strbuf_puts(sb, name);
				break;
			case '{':	/* } */
				for (p++; *p && isdigit((unsigned char)*p); p++)
					spaces = spaces * 10 + *p - '0';
				break;
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				spaces = *p - '0';
				break;
			default:
				if (*p < 'a' || *p > 'z')
					die("Abbrev character must be a lower alphabetic character. (%c)", *p);
				i = *p - 'a';
				if (ab2name[i].name)
					strbuf_puts(sb, ab2name[i].name);
				break;
                        }
			strbuf_nputc(sb, ' ', spaces);
                } else {
			strbuf_putc(sb, *p);
		}
	}
	return strbuf_value(sb);
}
示例#25
0
/**
 * Generate image tag (@CODE{\<img\>})
 *
 *	@param[in]	where	Where is the icon directory? <br>
 *			#CURRENT: current directory <br>
 *			#PARENT: parent directory
 *	@param[in]	file	icon file without suffix.
 *	@param[in]	alt	alt string (the @CODE{alt} attribute is always added)
 *
 *	@note Images are assumed to be in the @FILE{icons} or @FILE{../icons} directory, only.
 */
const char *
gen_image(int where, const char *file, const char *alt)
{
    STATIC_STRBUF(sb);
    const char *dir = (where == PARENT) ? "../icons" : "icons";

    strbuf_clear(sb);
    if (enable_xhtml)
        strbuf_sprintf(sb, "<img class='icon' src='%s/%s.%s' alt='[%s]'%s>",
                       dir, file, icon_suffix, fix_attr_value(alt), empty_element);
    else
        strbuf_sprintf(sb, "<img src='%s/%s.%s' alt='[%s]' %s%s>",
                       dir, file, icon_suffix, fix_attr_value(alt), icon_spec, empty_element);
    return strbuf_value(sb);
}
示例#26
0
文件: strmake.c 项目: GimXu/global
/**
 * strmake: make string from original string with limit character.
 *
 *	@param[in]	p	original string.
 *	@param[in]	lim	limitter
 *	@return		result string
 *
 * Usage:
 *	strmake("aaa:bbb", ":/=")	=> "aaa"
 *
 * [Note] The result string area is function local. So, following call
 *	 to this function may destroy the area.
 */
const char *
strmake(const char *p, const char *lim)
{
	STATIC_STRBUF(sb);
	const char *c;

	strbuf_clear(sb);
	for (; *p; p++) {
		for (c = lim; *c; c++)
			if (*p == *c)
				goto end;
		strbuf_putc(sb,*p);
	}
end:
	return strbuf_value(sb);
}
示例#27
0
/*
 * get pattern which match to #include lines.
 *
 *	i)	arg	include file name
 *	r)		pattern which match to #include lines
 */
static char *
include_pattern(const char *arg)
{
#if defined(_WIN32)
#define INCLUDE "^[ \t]*#[ \t]*include[ \t].*[\\\"\"</\\]%s[\\\"\">]"
#elif defined(__DJGPP__)
#define INCLUDE "^[ \t]*#[ \t]*include[ \t].*[\"</\\]%s[\">]"
#else
#define INCLUDE "^[ \t]*#[ \t]*include[ \t].*[\"</]%s[\">]"
#endif
	STATIC_STRBUF(pat);

	strbuf_clear(pat);
	strbuf_sprintf(pat, INCLUDE, quote_string(arg));
	return strbuf_value(pat);
}
示例#28
0
/**
 * Check and fix an attribute's value; convert all @c ' (single quote) characters
 * into @CODE{\&\#39;} within it.
 */
static const char *
fix_attr_value(const char *value)
{
    STATIC_STRBUF(sb);
    char c;
    const char *cptr;

    strbuf_clear(sb);
    cptr = value;

    while((c = *cptr) != '\0') {
        if(c == ATTR_DELIM)
            strbuf_puts(sb, "&#39;");
        else
            strbuf_putc(sb, c);
        ++cptr;
    }
    return strbuf_value(sb);
}
示例#29
0
/**
 * Generate name tag (@CODE{\<a name='xxx'\>}).
 *
 * Uses attribute @CODE{'id'}, if is @NAME{XHTML}.
 */
const char *
gen_name_string(const char *name)
{
    STATIC_STRBUF(sb);

    strbuf_clear(sb);
    if (enable_xhtml) {
        /*
         * Since some browser cannot understand "<a id='xxx' />",
         * we put both of 'id=' and 'name=' as long as XHTML1.1
         * is not required. XHTML1.1 prohibit 'name='.
         */
        if (strict_xhtml)
            strbuf_sprintf(sb, "<a id='%s'></a>", name);
        else
            strbuf_sprintf(sb, "<a id='%s' name='%s'></a>", name, name);
    } else {
        strbuf_sprintf(sb, "<a name='%s'></a>", name);
    }
    return strbuf_value(sb);
}
示例#30
0
/**
 * Generate anchor begin tag (@CODE{\<a href='dir/file.suffix\#key'\>}).
 * (complete format)
 *
 *	@param[in]	dir	directory
 *	@param[in]	file	file
 *	@param[in]	suffix	suffix (file extension e.g. @CODE{'.txt'}). A @CODE{'.'} (dot) will be added.
 *	@param[in]	key	key
 *	@param[in]	title	@CODE{title='xxx'} attribute; if @VAR{NULL}, doesn't add it.
 *	@param[in]	target	@CODE{target='xxx'} attribute; if @VAR{NULL}, doesn't add it.
 *	@return		generated anchor tag
 *
 *	@note @a dir, @a file, @a suffix, @a key, @a target and @a title may be @VAR{NULL}.
 *	@note Single quote (@CODE{'}) characters are used with the attribute values.
 */
const char *
gen_href_begin_with_title_target(const char *dir, const char *file, const char *suffix, const char *key, const char *title, const char *target)
{
    STATIC_STRBUF(sb);

    strbuf_clear(sb);
    /*
     * Construct URL.
     * href='dir/file.suffix#key'
     */
    strbuf_puts(sb, "<a href='");
    if (file) {
        if (dir) {
            strbuf_puts(sb, dir);
            strbuf_putc(sb, '/');
        }
        strbuf_puts(sb, file);
        if (suffix) {
            strbuf_putc(sb, '.');
            strbuf_puts(sb, suffix);
        }
    }
    if (key) {
        strbuf_putc(sb, '#');
        /*
         * If the key starts with a digit, it assumed line number.
         * XHTML 1.1 profibits number as an anchor.
         */
        if (isdigit(*key))
            strbuf_putc(sb, 'L');
        strbuf_puts(sb, key);
    }
    strbuf_putc(sb, '\'');
    if (Fflag && target)
        strbuf_sprintf(sb, " target='%s'", fix_attr_value(target));
    if (title)
        strbuf_sprintf(sb, " title='%s'", fix_attr_value(title));
    strbuf_putc(sb, '>');
    return strbuf_value(sb);
}