/* * 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)); }
/** * 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; }
static void cleanup(varnam *handle) { strbuf_clear(handle->internal->output); strbuf_clear(handle->internal->rtl_output); handle->internal->last_token_available = 0; handle->internal->last_rtl_token_available = 0; }
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); }
/** * 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; }
/** * 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; }
/** * 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); }
/** * 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); }
void dbop3_update(DBOP *dbop, const char *key, const char *dat) { int rc; char *errmsg = 0; STRBUF *sql = strbuf_open_tempbuf(); strbuf_sprintf(sql, "update %s set dat = '%s' where key = '%s'", dbop->tblname, dbop3_quote((char *)dat), key); rc = sqlite3_exec(dbop->db3, strbuf_value(sql), NULL, NULL, &errmsg); if (rc != SQLITE_OK) { sqlite3_close(dbop->db3); die("dbop3_update failed: %s", errmsg); } if (sqlite3_changes(dbop->db3) == 0) { strbuf_clear(sql); strbuf_sprintf(sql, "insert into %s values ('%s', '%s', NULL)", dbop->tblname, key, dbop3_quote((char *)dat)); rc = sqlite3_exec(dbop->db3, strbuf_value(sql), NULL, NULL, &errmsg); if (rc != SQLITE_OK) { sqlite3_close(dbop->db3); die("dbop3_updated failed: %s", errmsg); } } strbuf_release_tempbuf(sql); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * * @param widget * @param msg */ void cwt_msgbox_set_msg(CWT_WIDGET_PTR widget, const CWT_CHAR* msg) { if( msg ) { CWT_WIDGET_PTR label; const CWT_CHAR *ptr = msg; StringBufferPtr sb; sb = strbuf_new_defaults(); while( *ptr ) { if( *ptr == '\n' ) { label = cwt_new_widget(0, CWT_WT_LABEL, widget); cwt_label_set_text(label, strbuf_cstr(sb)); strbuf_clear(sb); } else { strbuf_append_char(sb, *ptr); } ptr++; } if( strbuf_size(sb) > 0 ) { label = cwt_new_widget(0, CWT_WT_LABEL, widget); cwt_label_set_text(label, strbuf_cstr(sb)); } strbuf_delete(sb); widget->need_layout = TRUE; } }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/* * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
int prepare_commands(struct run_event_state *state, const char *dump_dir_name, const char *event ) { free_commands(state); state->children_count = 0; strbuf_clear(state->command_output); GList *rule_list = load_rule_list(NULL, CONF_DIR"/report_event.conf", /*recursion_depth:*/ 0); state->rule_list = rule_list; return rule_list != NULL; }
END_TEST START_TEST (varnam_export_full) { int rc, pcnt, wcnt, i; float filecnt; strbuf* f; strbuf* error; f = strbuf_init (20); pcnt = execute_query_int (varnam_instance->internal->known_words, "select count(*) from patterns_content;"); wcnt = execute_query_int (varnam_instance->internal->known_words, "select count(*) from words;"); rc = varnam_export_words (varnam_instance, 2, "output/", VARNAM_EXPORT_FULL, NULL); assert_success (rc); filecnt = pcnt / 2; for (i = 0; i < (int) ceil (filecnt); i++) { strbuf_clear (f); strbuf_addf (f, "output/%d.patterns.txt", i); if (!file_exist (strbuf_to_s (f))) { error = strbuf_init (10); strbuf_addf (error, "Failed to find file: %s\n", strbuf_to_s (f)); ck_abort_msg (strbuf_to_s (error)); } } filecnt = wcnt / 2; for (i = 0; i < (int) ceil (filecnt); i++) { strbuf_clear (f); strbuf_addf (f, "output/%d.words.txt", i); if (!file_exist (strbuf_to_s (f))) { error = strbuf_init (10); strbuf_addf (error, "Failed to find file: %s\n", strbuf_to_s (f)); ck_abort_msg (strbuf_to_s (error)); } } strbuf_destroy (f); }
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); }
/** * 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); }
/* * 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)); }
static int tokenize(varnam *handle, const char *input, struct strbuf *string) { const char *text, *remaining; int matchpos = 0, counter = 0; struct varnam_internal *vi; struct strbuf *lookup; struct token *temp = NULL, *last = NULL; vi = handle->internal; lookup = vi->lookup; text = input; while( *text != '\0' ) { strbuf_addc( lookup, *text ); ++counter; temp = find_token( handle, lookup->buffer ); if (temp) { last = temp; matchpos = counter; if( last->children <= 0 ) break; } else if( !can_find_token( handle, last, lookup->buffer )) { break; } ++text; } if (last) { resolve_token(handle, last, string); remaining = input + matchpos; set_last_token (handle, last); } else { if(lookup->buffer[0] != '_') strbuf_addc( string, lookup->buffer[0] ); remaining = input + 1; set_last_token (handle, NULL); } strbuf_clear (lookup); if( strlen( remaining ) > 0 ) return tokenize( handle, remaining, string ); return VARNAM_SUCCESS; }
/* * 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); }
/** * 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); }