src/gedlib/lloptions.c
/*==========================================
 * load_config_file -- read options in config file
 *  and load into table (f_global)
 * returns 1 for success, 0 for not found, -1 for error (with pmsg)
 *========================================*/
- read options in config file
and load into table (f_global)
returns 1 for success, 0 for not found, -1 for error (with pmsg)
- read options in config file and load into table ( f_global ) returns 1 for success 0 for not found - 1 for error ( with pmsg )
static INT
load_config_file (STRING file, STRING * pmsg, STRING *chain)
{
	FILE * fp = 0;
	STRING ptr, val, key;
	STRING thisdir = dir_from_file(file);
	BOOLEAN failed, noesc;
	char buffer[MAXLINELEN],valbuf[MAXLINELEN];
	INT len;
	fp = fopen(file, LLREADTEXT);
	if (!fp) {
		free(thisdir);
		return 0; 
	}
	f_predef = create_table_str();
	insert_table_str(f_predef, "%thisdir%", thisdir);
	strfree(&thisdir);
	while (fgets(buffer, sizeof(buffer), fp)) {
		noesc = FALSE;
		len = strlen(buffer);
		if (len == 0)
			continue; 
		if (buffer[0] == '#')
			continue; 
		if (!feof(fp) && buffer[len-1] != '\n') {
			break;
		}
		chomp(buffer); 
		for (ptr = buffer; *ptr && *ptr!='='; ptr++)
			;
		if (*ptr != '=' || ptr==buffer)
			continue; 
		*ptr=0; 
		if (ptr[-1] == ':') {
			noesc = TRUE; 
			ptr[-1] = 0;
		}
		ptr++;
		if (noesc)
			llstrncpy(valbuf, ptr, sizeof(valbuf), uu8);
		else
			copy_process(valbuf, ptr);
		expand_variables(valbuf, sizeof(valbuf));
		key = buffer; 
		val = valbuf;
		if (strcmp(key,"LLCONFIGFILE") == 0) {
		    *chain = strsave(val);
		} else {
		    insert_table_str(f_global, key, val);
		}
	}
	failed = !feof(fp);
	fclose(fp);
	if (failed) {
		*pmsg = strsave(_(qSopt2long));
		return -1; 
	}
	free_optable(&f_predef);
	send_notifications();
	return 1; 
}
static INT load_config_file ( STRING file , STRING * pmsg , STRING * chain ) { FILE * fp = 0 ; STRING ptr , val , key ; STRING thisdir = dir_from_file ( file ) ; BOOLEAN failed , noesc ; char buffer [ MAXLINELEN ] , valbuf [ MAXLINELEN ] ; INT len ; fp = fopen ( file , LLREADTEXT ) ; if ( ! fp ) { free ( thisdir ) ; return 0 ; } f_predef = create_table_str ( ) ; insert_table_str ( f_predef , " " , thisdir ) ; strfree ( & thisdir ) ; while ( fgets ( buffer , sizeof ( buffer ) , fp ) ) { noesc = FALSE ; len = strlen ( buffer ) ; if ( len == 0 ) continue ; if ( buffer [ 0 ] == ' ' ) continue ; if ( ! feof ( fp ) && buffer [ len - 1 ] != ' \n ' ) { break ; } chomp ( buffer ) ; for ( ptr = buffer ; * ptr && * ptr != ' ' ; ptr ++ ) ; if ( * ptr != ' ' || ptr == buffer ) continue ; * ptr = 0 ; if ( ptr [ -1 ] == ' ' ) { noesc = TRUE ; ptr [ -1 ] = 0 ; } ptr ++ ; if ( noesc ) llstrncpy ( valbuf , ptr , sizeof ( valbuf ) , uu8 ) ; else copy_process ( valbuf , ptr ) ; expand_variables ( valbuf , sizeof ( valbuf ) ) ; key = buffer ; val = valbuf ; if ( strcmp ( key , " " ) == 0 ) { * chain = strsave ( val ) ; } else { insert_table_str ( f_global , key , val ) ; } } failed = ! feof ( fp ) ; fclose ( fp ) ; if ( failed ) { * pmsg = strsave ( _ ( qSopt2long ) ) ; return -1 ; } free_optable ( & f_predef ) ; send_notifications ( ) ; return 1 ; }
load_config_file -- read options in config file
  and load into table (f_global)
 returns 1 for success, 0 for not found, -1 for error (with pmsg)
load_config_file -- read options in config file and load into table ( f_global ) returns 1 for success 0 for not found - 1 for error ( with pmsg )
/* 0 for not found */ /* read thru config file til done (or error) */ /* ignore blank lines */ /* ignore lines starting with # */ /* bail out if line too long */ /* trim any trailing CR or LF */ /* find =, which separates key from value */ /* ignore lines without = or key */ /* zero-terminate key */ /* := means don't do backslash escapes */ /* ignore any previous value, it will be overwritten */ /* advance over separator to value */ /*
		process the value into valbuf
		this handles escapes (eg, "\n")
		the output (valbuf) is no longer than the input (ptr)
		*/ /* key is in beginning of buffer, we zero-terminated it */ /* LLCONFIGFILE is not entered in table, only used to 
		     * chain to another config file
		     */ /* error is in heap */ /* -1 for error */ /* 1 for ok */