link-grammar-5.8.0/link-grammar/dict-file/read-dict.c
/**
 * read_entry() -- read one dictionary entry
 * Starting with the current token, parse one dictionary entry.
 * A single dictionary entry must have one and only one colon in it,
 * and is terminated by a semi-colon.
 * Add these words to the dictionary.
 */
- read one dictionary entry
Starting with the current token, parse one dictionary entry.
A single dictionary entry must have one and only one colon in it,
and is terminated by a semi-colon.
Add these words to the dictionary.
- read one dictionary entry Starting with the current token parse one dictionary entry . A single dictionary entry must have one and only one colon in it and is terminated by a semi - colon . Add these words to the dictionary .
static bool read_entry(Dictionary dict)
{
	Exp *n;
	int i;
	Dict_node *dnx, *dn = NULL;
	while (!is_equal(dict, ':'))
	{
		if (dict->is_special)
		{
			dict_error(dict, "I expected a word but didn\'t get it.");
			goto syntax_error;
		}
		if ((dict->token[0] == '/') && (dict->token[1] != '.'))
		{
			dn = read_word_file(dict, dn, dict->token);
			if (dn == NULL)
			{
				prt_error("Error: Cannot open word file \"%s\".\n", dict->token);
				return false;
			}
		}
		else if (0 == strcmp(dict->token, "#include"))
		{
			bool rc;
			char* instr;
			char* dict_name;
			const char * save_name;
			bool save_is_special;
			const char * save_input;
			const char * save_pin;
			int save_already_got_it;
			int save_line_number;
			size_t skip_slash;
			if (!link_advance(dict)) goto syntax_error;
			skip_slash          = ('/' == dict->token[0]) ? 1 : 0;
			dict_name           = strdupa(dict->token);
			save_name           = dict->name;
			save_is_special     = dict->is_special;
			save_input          = dict->input;
			save_pin            = dict->pin;
			save_already_got_it = dict->already_got_it;
			save_line_number    = dict->line_number;
			instr = get_file_contents(dict_name + skip_slash);
			if (NULL == instr)
			{
				prt_error("Error: While parsing dictionary \"%s\":\n"
				          "\t Line %d: Could not open subdictionary \"%s\"\n",
				          dict->name, dict->line_number-1, dict_name);
				goto syntax_error;
			}
			dict->input = instr;
			dict->pin = dict->input;
			dict->line_number = 1;
			dict->name = dict_name;
			rc = read_dictionary(dict);
			dict->name           = save_name;
			dict->is_special     = save_is_special;
			dict->input          = save_input;
			dict->pin            = save_pin;
			dict->already_got_it = save_already_got_it;
			dict->line_number    = save_line_number;
			free(instr);
			if (!rc) goto syntax_error;
			if (!link_advance(dict)) goto syntax_error;
			if (';' == dict->token[0])
			{
				if (!link_advance(dict)) goto syntax_error;
			}
			return true;
		}
		else
		{
			Dict_node * dn_new = dict_node_new();
			dn_new->left = dn;
			dn_new->right = NULL;
			dn_new->exp = NULL;
			dn = dn_new;
			dn->file = NULL;
			patch_subscript(dict->token);
			dn->string = string_set_add(dict->token, dict->string_set);
		}
		if (!link_advance(dict)) goto syntax_error;
	}
	if (!link_advance(dict))
	{
		goto syntax_error;
	}
	n = make_expression(dict);
	if (n == NULL)
	{
		goto syntax_error;
	}
	if (!is_equal(dict, ';'))
	{
		dict_error(dict, "Expecting \";\" at the end of an entry.");
		goto syntax_error;
	}
	if (dn == NULL)
	{
		dict_error(dict, "Expecting a token before \":\".");
		goto syntax_error;
	}
	i = 0;
	for (dnx = dn; dnx != NULL; dnx = dnx->left)
	{
		dnx->exp = n;
		i++;
	}
	dict->insert_entry(dict, dn, i);
	if (dict->suppress_warning)
	{
		free((void *)dict->suppress_warning);
		dict->suppress_warning = NULL;
	}
	if (!link_advance(dict))
	{
		return false;
	}
	return true;
syntax_error:
	free_insert_list(dn);
	return false;
}
static bool read_entry ( Dictionary dict ) { Exp * n ; int i ; Dict_node * dnx , * dn = NULL ; while ( ! is_equal ( dict , ' ' ) ) { if ( dict -> is_special ) { dict_error ( dict , " \' " ) ; goto syntax_error ; } if ( ( dict -> token [ 0 ] == ' ' ) && ( dict -> token [ 1 ] != ' ' ) ) { dn = read_word_file ( dict , dn , dict -> token ) ; if ( dn == NULL ) { prt_error ( " \" \" \n " , dict -> token ) ; return false ; } } else if ( 0 == strcmp ( dict -> token , " " ) ) { bool rc ; char * instr ; char * dict_name ; const char * save_name ; bool save_is_special ; const char * save_input ; const char * save_pin ; int save_already_got_it ; int save_line_number ; size_t skip_slash ; if ( ! link_advance ( dict ) ) goto syntax_error ; skip_slash = ( ' ' == dict -> token [ 0 ] ) ? 1 : 0 ; dict_name = strdupa ( dict -> token ) ; save_name = dict -> name ; save_is_special = dict -> is_special ; save_input = dict -> input ; save_pin = dict -> pin ; save_already_got_it = dict -> already_got_it ; save_line_number = dict -> line_number ; instr = get_file_contents ( dict_name + skip_slash ) ; if ( NULL == instr ) { prt_error ( " \" \" \n " " \t \" \" \n " , dict -> name , dict -> line_number - 1 , dict_name ) ; goto syntax_error ; } dict -> input = instr ; dict -> pin = dict -> input ; dict -> line_number = 1 ; dict -> name = dict_name ; rc = read_dictionary ( dict ) ; dict -> name = save_name ; dict -> is_special = save_is_special ; dict -> input = save_input ; dict -> pin = save_pin ; dict -> already_got_it = save_already_got_it ; dict -> line_number = save_line_number ; free ( instr ) ; if ( ! rc ) goto syntax_error ; if ( ! link_advance ( dict ) ) goto syntax_error ; if ( ' ' == dict -> token [ 0 ] ) { if ( ! link_advance ( dict ) ) goto syntax_error ; } return true ; } else { Dict_node * dn_new = dict_node_new ( ) ; dn_new -> left = dn ; dn_new -> right = NULL ; dn_new -> exp = NULL ; dn = dn_new ; dn -> file = NULL ; patch_subscript ( dict -> token ) ; dn -> string = string_set_add ( dict -> token , dict -> string_set ) ; } if ( ! link_advance ( dict ) ) goto syntax_error ; } if ( ! link_advance ( dict ) ) { goto syntax_error ; } n = make_expression ( dict ) ; if ( n == NULL ) { goto syntax_error ; } if ( ! is_equal ( dict , ' ' ) ) { dict_error ( dict , " \" \" " ) ; goto syntax_error ; } if ( dn == NULL ) { dict_error ( dict , " \" \" " ) ; goto syntax_error ; } i = 0 ; for ( dnx = dn ; dnx != NULL ; dnx = dnx -> left ) { dnx -> exp = n ; i ++ ; } dict -> insert_entry ( dict , dn , i ) ; if ( dict -> suppress_warning ) { free ( ( void * ) dict -> suppress_warning ) ; dict -> suppress_warning = NULL ; } if ( ! link_advance ( dict ) ) { return false ; } return true ; syntax_error : free_insert_list ( dn ) ; return false ; }
read_entry() -- read one dictionary entry
 Starting with the current token, parse one dictionary entry.
read_entry () -- read one dictionary entry Starting with the current token parse one dictionary entry .
/* If it's a word-file name */ /* However, be careful to reject "/.v" which is the division symbol
		 * used in equations (.v means verb-like) */ /* OK, token contains the filename to read ... */ /* The line number and dict name are used for error reporting */ /* Now read the thing in. */ /* when we return, point to the next entry */ /* If a semicolon follows the include, that's OK... ignore it. */ /* Note: The following patches a dot in regexes appearing in
			 * the affix file... It is corrected later. */ /* Advance to next entry, unless error */ /* pass the : */ /* At this point, dn points to a list of Dict_nodes connected by
	 * their left pointers. These are to be inserted into the dictionary. */ /* pass the ; */ /* Avoid freeing dn, since it is already inserted into the dict. */