static paralist * get_init(projCtx ctx, paralist **start, paralist *next, char *name) { char fname[MAX_PATH_FILENAME+ID_TAG_MAX+3], *opt; FILE *fid; paralist *init_items = NULL; const paralist *orig_next = next; (void)strncpy(fname, name, MAX_PATH_FILENAME + ID_TAG_MAX + 1); /* ** Search for file/key pair in cache */ init_items = pj_search_initcache( name ); if( init_items != NULL ) { next->next = init_items; while( next->next != NULL ) next = next->next; return next; } /* ** Otherwise we try to open the file and search for it. */ if ((opt = strrchr(fname, ':')) != NULL) *opt++ = '\0'; else { pj_ctx_set_errno(ctx,-3); return NULL; } if ( (fid = pj_open_lib(ctx,fname, "rt")) != NULL) next = get_opt(ctx, start, fid, opt, next); else return NULL; (void)fclose(fid); if (errno == 25) errno = 0; /* unknown problem with some sys errno<-25 */ /* ** If we seem to have gotten a result, insert it into the ** init file cache. */ if( next != NULL && next != orig_next ) pj_insert_initcache( name, orig_next->next ); return next; }
static paralist *get_init(PJ_CONTEXT *ctx, char *key) { /************************************************************************* Expand key from buffer or (if not in buffer) from init file *************************************************************************/ char *xkey, *definition; paralist *init_items = 0; /* support "init=file:section", "+init=file:section", and "file:section" format */ xkey = strstr (key, "init="); if (0==xkey) xkey = key; else xkey += 5; pj_log (ctx, PJ_LOG_TRACE, "get_init: searching cache for key: [%s]", xkey); /* Is file/key pair already in cache? */ init_items = pj_search_initcache (xkey); if (init_items) return init_items; /* If not, we must read it from file */ pj_log (ctx, PJ_LOG_TRACE, "get_init: searching on in init files for [%s]", xkey); definition = get_init_string (ctx, xkey); if (0==definition) return 0; init_items = string_to_paralist (ctx, definition); if (init_items) pj_log (ctx, PJ_LOG_TRACE, "get_init: got [%s], paralist[0,1]: [%s,%s]", definition, init_items->param, init_items->next ? init_items->next->param : "(empty)"); pj_dealloc (definition); if (0==init_items) return 0; /* We found it in file - now insert into the cache, before returning */ pj_insert_initcache (xkey, init_items); return init_items; }