Example #1
0
/*==================================================
 * load_configs -- Load global config file(s)
 * returns FALSE if error, with message in pmsg
 *================================================*/
static BOOLEAN
load_configs (STRING configfile, STRING * pmsg)
{
    INT rtn=0;
    STRING str=0;
    char cfg_name[MAXPATHLEN];

    /* TODO: Should read a system-wide config file */

    if (!configfile)
        configfile = getenv("LLCONFIGFILE");

    *pmsg = NULL;


    if (configfile && configfile[0]) {

        rtn = load_global_options(configfile, pmsg);
        if (rtn == -1) return FALSE;

    } else {

        /* No config file specified, so load config_file(s) from
           the standard places */

        /* look for global config file */
        llstrncpy(cfg_name, global_conf_path, sizeof(cfg_name), 0);
        llstrapps(cfg_name, sizeof(cfg_name), 0, "/lifelines.conf");
        rtn = load_global_options(cfg_name, pmsg);
        if (rtn == -1) return FALSE;

        /* look for one in user's home directory */
        /* TODO: Shouldn't Win32 use getenv("USERPROFILE") ? */
        llstrncpy(cfg_name, getenv("HOME") , sizeof(cfg_name), 0);
        /*llstrappc(cfg_name, sizeof(cfg_name), '/');*/
        llstrapps(cfg_name, sizeof(cfg_name), 0, "/" LINES_CONFIG_FILE);

        rtn = load_global_options(cfg_name, pmsg);
        if (rtn == -1) return FALSE;

        rtn = load_global_options(LINES_CONFIG_FILE, pmsg);
        if (rtn == -1) return FALSE;
    }

    /* allow chaining to one more config file
     * if one was defined for the database
     */
    str = getlloptstr("LLCONFIGFILE", NULL);
    if (str && str[0]) {
        rtn = load_global_options(str, pmsg);
        if (rtn == -1) return FALSE;
    }
    return TRUE;
}
Example #2
0
/*============================================
 * expand_special_fname_chars -- Replace ~ with home
 *==========================================*/
BOOLEAN
expand_special_fname_chars (STRING buffer, INT buflen, INT utf8)
{
	char * sep=0;
	if (buffer[0]=='~') {
		if (is_dir_sep(buffer[1])) {
			STRING home = get_home();
			if (home && home[0]) {
				STRING tmp;
				if ((INT)strlen(home) + 1 + (INT)strlen(buffer) > buflen) {
					return FALSE;
				}
				tmp = strsave(buffer);
				buffer[0] = 0;
				llstrapps(buffer, buflen, utf8, home);
				llstrapps(buffer, buflen, utf8, tmp+1);
				strfree(&tmp);
				return TRUE;
			}
		}
		/* check for ~name/... and resolve the ~name */
		if ((sep = strchr(buffer,LLCHRDIRSEPARATOR))) {
			STRING username = strsave(buffer+1);
			STRING homedir;
			username[sep-buffer+1] = 0;
			homedir = get_user_homedir(username);
			strfree(&username);
			if (homedir) {
				STRING tmp=0;
				if ((INT)strlen(homedir) + 1 + (INT)strlen(sep+1) > buflen) {
					return FALSE;
				}
				tmp = strsave(sep+1);
				buffer[0] = 0;
				llstrapps(buffer, buflen, utf8, homedir);
				llstrapps(buffer, buflen, utf8, tmp+(sep-buffer+1));
				strfree(&tmp);
				return TRUE;
			}
		}
	}
	return TRUE;
}
Example #3
0
/*====================================================
 * disp_pvalue -- Display details of specified pvalue
 *  Drilldown in variable debugger
 *  This is primarily to display contents of container values
 *  val:   [IN]  value to display
 *==================================================*/
static void
disp_pvalue (PVALUE val)
{
	switch (which_pvalue_type(val)) {
		case PGNODE:
			{
				NODE node = pvalue_to_node(val);
				char buffer[256] = "";
				size_t len = sizeof(buffer);
				STRING str = buffer;
				if (ntag(node)) {
					llstrappf(str, len, uu8, "%s: ", ntag(node));
				}
				if (nval(node)) {
					llstrapps(str, len, uu8, nval(node));
				}
				msg_info(str);
			}
			return;
		case PINDI:
		case PFAM:
		case PSOUR:
		case PEVEN:
		case POTHR:
			{
				RECORD rec = pvalue_to_record(val);
				NODE node = nztop(rec);
				size_t len = 128;
				STRING txt = generic_to_list_string(node, NULL, len, " ", NULL, TRUE);
				msg_info(txt);
			}
			return;
		case PLIST:
			{
				LIST list = pvalue_to_list(val);
				disp_list(list);
			}
			return;
		case PTABLE:
			{
				TABLE tab = pvalue_to_table(val);
				disp_table(tab);
			}
			return;
		case PSET:
			{
				INDISEQ seq = pvalue_to_seq(val);
				disp_seq(seq);
			}
			return;
	}
}
Example #4
0
/*=============================================
 * concat_path -- add file & directory together
 *  dir:  [IN]  directory (may be NULL)
 *  file: [IN]  file (may be NULL)
 *  handles trailing / in dir and/or leading / in file
 *  (see test_concat_path above)
 *  returns no trailing / if file is NULL
 *===========================================*/
STRING
concat_path (CNSTRING dir, CNSTRING file, INT utf8, STRING buffer, INT buflen)
{
	ASSERT(buflen);
	buffer[0] = 0;
	if (dir && dir[0]) {
		llstrapps(buffer, buflen, utf8, dir);
		if (is_dir_sep(buffer[strlen(buffer)-1])) {
			/* dir ends in sep */
			if (!file || !file[0]) {
				/* dir but no file, we don't include trailing slash */
				buffer[strlen(buffer)-1] = 0;
			} else {
				if (is_dir_sep(file[0])) {
					/* file starts in sep */
					llstrapps(buffer, buflen, utf8, &file[1]);
				} else {
					/* file doesn't start in sep */
					llstrapps(buffer, buflen, utf8, file);
				}
			}
		} else {
			/* dir doesn't end in sep */
			if (!file || !file[0]) {
				/* dir but no file, we don't include trailing slash */
			} else {
				if (is_dir_sep(file[0])) {
					/* file starts in sep */
					llstrapps(buffer, buflen, utf8, file);
				} else {
					/* file doesn't start in sep */
					llstrapps(buffer, buflen, utf8, LLSTRDIRSEPARATOR);
					llstrapps(buffer, buflen, utf8, file);
				}
			}
		}
	} else {
		/* no dir, include file exactly as it is */
		if (file && file[0])
			llstrapps(buffer, buflen, utf8, file);
	}

	return buffer;
}
Example #5
0
/*===================================================
 * describe_dberror -- Describe database opening error
 * dberr:  [in] error whose description is sought
 * buffer: [out] buffer for description
 * buflen: [in]  size of buffer
 *=================================================*/
void
describe_dberror (INT dberr, STRING buffer, INT buflen)
{
	STRING b=buffer;
	INT n=buflen, u8=uu8;
	buffer[0]=0;
	if (dberr != BTERR_WRITER)
		llstrncpy(buffer, _("Database error: -- "), buflen, 0);

	switch (dberr) {
	case BTERR_NODB:
		llstrapps(b, n, u8, _("requested database does not exist."));
		break;
	case BTERR_DBBLOCKEDBYFILE:
		llstrapps(b, n, u8, _("db directory is file, not directory."));
		break;
	case BTERR_DBCREATEFAILED:
		llstrapps(b, n, u8, _("creation of new database failed."));
		break;
	case BTERR_DBACCESS:
		llstrapps(b, n, u8, _("error accessing database directory."));
		break;
	case BTERR_NOKEY:
		llstrapps(b, n, u8, _("no keyfile (directory does not appear to be a database)."));
		break;
	case BTERR_INDEX:
		llstrapps(b, n, u8,  _("could not open, read or write an index file."));
		break;
	case BTERR_KFILE:
		llstrapps(b, n, u8,  _("could not open, read or write the key file."));
		break;
	case BTERR_KFILE_ALTERDB:
		llstrapps(b, n, u8,  _("could not open, read or write the key file (to alter database)."));
		break;
	case BTERR_BLOCK:
		llstrapps(b, n, u8,  _("could not open, read or write a block file."));
		break;
	case BTERR_LNGDIR:
		llstrapps(b, n, u8,  _("name of database is too long."));
		break;
	case BTERR_WRITER:
		llstrapps(b, n, u8,  _("The database is already open for writing."));
		break;
	case BTERR_LOCKED:
		llstrapps(b, n, u8,  _("The database is locked (no readwrite access)."));
		break;
	case BTERR_UNLOCKED:
		llstrapps(b, n, u8,  _("The database is unlocked."));
		break;
	case BTERR_ILLEGKF:
		llstrapps(b, n, u8,  _("keyfile is corrupt."));
		break;
	case BTERR_ALIGNKF:
		llstrapps(b, n, u8,  _("keyfile is wrong alignment."));
		break;
	case BTERR_VERKF:
		llstrapps(b, n, u8,  _("keyfile is wrong version."));
		break;
	case BTERR_EXISTS:
		llstrapps(b, n, u8,  _("Existing database found."));
		break;
	case BTERR_READERS:
		llstrappf(b, n, u8
			, _pl("The database is already opened for read access by %d user."
				, "The database is already opened for read access by %d users."
				, rdr_count)
			, rdr_count);
		break;
	case BTERR_BADPROPS:
		llstrapps(b, n, u8,  _("Invalid properties set for new database"));
		break;
	default:
		llstrapps(b, n, u8,  _("Undefined database error -- fix program."));
		break;
	}
}
Example #6
0
static FILE *
ask_for_file_worker (STRING mode,
                     STRING ttl,
                     STRING *pfname,
                     STRING *pfullpath,
                     STRING path,
                     STRING ext,
                     DIRECTION direction)
{
	FILE *fp;
	char prompt[MAXPATHLEN];
	char fname[MAXPATHLEN];
	int elen, flen;
	BOOLEAN rtn;

	make_fname_prompt(prompt, sizeof(prompt), ext);

	if (direction==INPUT)
		rtn = ask_for_input_filename(ttl, path, prompt, fname, sizeof(fname));
	else
		rtn = ask_for_output_filename(ttl, path, prompt, fname, sizeof(fname));
	
	if (pfname) {
		if (fname && fname[0])
			*pfname = strdup(fname);
		else
			*pfname = 0;
	}
	if (pfullpath) *pfullpath = 0; /* 0 indicates we didn't try to open */

	if (!rtn || !fname[0]) return NULL;

	if (!expand_special_fname_chars(fname, sizeof(fname), uu8)) {
		msg_error(_(qSfn2long));
		return NULL;
	}

ask_for_file_try:

	/* try name as given */
	if (ISNULL(path)) {
		/* bare filename was given */
		if ((fp = fopen(fname, mode)) != NULL) {
			if (pfname)
				strupdate(pfname, fname);
			return fp;
		}
	} else {
		/* fully qualified path was given */
		if ((fp = fopenpath(fname, mode, path, ext, uu8, pfullpath)) != NULL) {
			return fp;
		}
	}

	/* try default extension */
	if (ext) {
		elen = strlen(ext);
		flen = strlen(fname);
		if (elen<flen && path_match(fname+flen-elen, ext)) {
			ext = NULL;	/* the file name has the extension already */
		} else {
			/* add extension and go back and retry */
			llstrapps(fname, sizeof(fname), uu8, ext);
			ext = NULL; /* only append extension once! */
			goto ask_for_file_try;
		}
	}

	/* failed to open it, give up */
	msg_error(_(qSnofopn), fname);
	return NULL;
}