Dbi_index * alias_init (const char *project, const char *index) { const char *aname; if (NULL == index) index = ""; #if 0 if (*index) error (NULL, "per-index aliases are not yet implemented"); ++initialized; if (initialized > 1) return; #endif aname = se_file(project, index, "aliases.dbh"); if (xaccess(aname,R_OK,0)) return NULL; aname = se_dir(project, index); aliases_dip = dbi_open ("aliases", aname); /* don't care if it's NULL */ return aliases_dip; }
static int openfname(Hdr *hp, char *fname, int dir, int mode) { int fd; fd = -1; cleanname(fname); switch (hp->linkflag) { case LF_LINK: case LF_SYMLINK1: case LF_SYMLINK2: fprint(2, "%s: can't make (sym)link %s\n", argv0, fname); break; case LF_FIFO: fprint(2, "%s: can't make fifo %s\n", argv0, fname); break; default: if (!keepexisting || access(fname, AEXIST) < 0) { int rw = (dir? OREAD: OWRITE); fd = create(fname, rw, mode); if (fd < 0) { mkpdirs(fname); fd = create(fname, rw, mode); } if (fd < 0 && (!dir || xaccess(fname, AEXIST) < 0)) cantcreate(fname, mode); } if (fd >= 0 && verbose) fprint(2, "%s\n", fname); break; } return fd; }
void se_vids_init(const char *index) { const char *vids = se_file (se_curr_project, (l2&&!gdf_flag) ? "cat" : index, "vid.dat"); if (!xaccess(vids, R_OK, 0)) vp = vid_load_data(vids); else vp = NULL; }
void se_pcre_init(const char *project, const char *index) { static int initialized = 0; static char *iproject = NULL, *iindex = NULL; FILE *fp; static char glist_fname[_MAX_PATH]; if (!project || !*project) project = "cdli"; if (initialized && !strcmp(iproject,project) && !strcmp(iindex,index)) return; if (iproject) free(iproject); if (iindex) free(iindex); iproject = strdup(project); iindex = strdup(index); initialized = 1; strcpy(glist_fname, se_file(project, index, "key.lst")); xaccess (glist_fname, R_OK, TRUE); glist_buf_len = fsize_t (glist_fname, NULL); glist_buf = malloc(glist_buf_len+3); *glist_buf = '\n'; fp = xfopen (glist_fname, "rb"); xfread (glist_fname, TRUE, &glist_buf[1], 1, glist_buf_len, fp); xfclose (glist_fname, fp); ++glist_buf_len; glist_buf[glist_buf_len++] = '\n'; glist_buf[glist_buf_len++] = '\0'; for (glist_begin = glist_buf+1; '#' == *glist_begin; ++glist_begin) { while ('\n' != *glist_begin) ++glist_begin; } glist_len = glist_buf_len - (glist_begin - glist_buf); }
/*#define PADDED_GRAPHEME_LEN 32*/ void alias_index_aliases (const char *project,const char *index) { const char *alias_fn, *alias_dir; FILE *alias_fp; Dbi_index *alias_dip; Uchar padded_grapheme[PADDED_GRAPHEME_LEN], head_grapheme[PADDED_GRAPHEME_LEN]; Uchar *s, *t; int last_grapheme_len = PADDED_GRAPHEME_LEN; int line_num = 0; int hg_len = 0; alias_fn = strdup(se_file(project, index, "aliases")); alias_dir = se_dir(project,index); if (xaccess(alias_fn,W_OK|R_OK,0)) { if (verbose) mwarning(NULL,"no aliases file %s; proceeding without aliasing",alias_fn); return; } alias_fp = xfopen (alias_fn, "r"); alias_dip = dbi_create ("aliases", alias_dir, 1024, 1, DBI_BALK); dbi_set_cache (alias_dip, 32); while (NULL != (s = getline (alias_fp))) { if ('#' == *s) continue; if (!isspace(*s)) { memset (head_grapheme, '\0', last_grapheme_len); t = head_grapheme; while (*s && !isspace(*s)) { if (t - head_grapheme == PADDED_GRAPHEME_LEN) { *t = '\0'; error (ewfile(alias_fn, line_num), "%s...: grapheme too long (max %d chars)", head_grapheme, PADDED_GRAPHEME_LEN-1); } *t++ = *s++; } *t++ = '\0'; hg_len = t - head_grapheme; while (*s && isspace(*s)) ++s; } else { do ++s; while (*s && isspace(*s)); } while (*s) { t = padded_grapheme; while (*s && !isspace(*s)) { if (t - padded_grapheme == PADDED_GRAPHEME_LEN) { *t = '\0'; error (ewfile(alias_fn, line_num), "%s...: grapheme too long (max %d chars)",padded_grapheme,PADDED_GRAPHEME_LEN-1); } *t++ = *s++; } *t = '\0'; last_grapheme_len = t - padded_grapheme; if (DBI_BALK == dbi_add (alias_dip, padded_grapheme, head_grapheme, hg_len)) mwarning (NULL, "duplicate grapheme alias %s -> %s", padded_grapheme, head_grapheme); while (*s && isspace(*s)) ++s; } } dbi_flush (alias_dip); xfclose (alias_fn, alias_fp); }