void config_file::parse_key(config_file::value& value, std::string& key, const std::string& strvalue)
{
  value::value_type keytype = config_file::parse_keytype(key);
  value.type_ = keytype;
  
  if(keytype == value::RAW_VALUE){
    value.raw_value_ = strvalue;
  }
  else if(keytype == value::ARRAY){
    size_t index;
    bool ret_val = parse_array(key, index);
    if(index>=value.array_.size())
    {
      value.array_.resize(index + 1);
    }
    parse_key(value.array_[index], key, strvalue);
  }
  else if(keytype == value::RECORD){
    std::string recordname = parse_record_name(key);
    mapi it = value.record_.find(recordname);
    if(it == value.record_.end()){
      config_file::value new_value;
      parse_key(new_value, key, strvalue);
      value.record_.insert(mapt::value_type(recordname, new_value));
    }
    else{
      parse_key(it->second, key, strvalue);
    }
  }
}
Exemple #2
0
/******************************************************************************
 *                                                                            *
 * Function: load_aliases                                                     *
 *                                                                            *
 * Purpose: load aliases from configuration                                   *
 *                                                                            *
 * Parameters: lines - aliase entries from configuration file                 *
 *                                                                            *
 * Comments: calls add_alias() for each entry                                 *
 *                                                                            *
 ******************************************************************************/
void	load_aliases(char **lines)
{
	char	**pline, *r, *c;

	for (pline = lines; NULL != *pline; pline++)
	{
		r = *pline;

		if (SUCCEED != parse_key(&r) || ':' != *r)
		{
			zabbix_log(LOG_LEVEL_CRIT, "cannot add alias \"%s\": invalid character at position %ld",
					*pline, (r - *pline) + 1);
			exit(EXIT_FAILURE);
		}

		c = r++;

		if (SUCCEED != parse_key(&r) || '\0' != *r)
		{
			zabbix_log(LOG_LEVEL_CRIT, "cannot add alias \"%s\": invalid character at position %ld",
					*pline, (r - *pline) + 1);
			exit(EXIT_FAILURE);
		}

		*c++ = '\0';

		add_alias(*pline, c);

		*--c = ':';
	}
}
Exemple #3
0
// Lua: ip = wifi.xx.setip()
static int wifi_setip( lua_State* L, uint8_t mode )
{
  struct ip_info pTempIp;
  wifi_get_ip_info(mode, &pTempIp);

  if (!lua_istable(L, 1))
    return luaL_error( L, "wrong arg type" );
  uint32_t ip = parse_key(L, "ip");
  if(ip!=0) 
    pTempIp.ip.addr = ip;

  ip = parse_key(L, "netmask");
  if(ip!=0) 
    pTempIp.netmask.addr = ip;

  ip = parse_key(L, "gateway");
  if(mode==SOFTAP_IF || ip!=0)
    pTempIp.gw.addr = ip;
  
  if(STATION_IF == mode)
  {
    wifi_station_dhcpc_stop();
    lua_pushboolean(L,wifi_set_ip_info(mode, &pTempIp));
  }
  else
  {
    wifi_softap_dhcps_stop();
    lua_pushboolean(L,wifi_set_ip_info(mode, &pTempIp));
    wifi_softap_dhcps_start();
  }

  return 1;  
}
Exemple #4
0
static int	quest_close(t_cmds **cmds, t_shell *shell)
{
	if (ft_strlen((*cmds)->cmd) == 0)
		exit(0);
	parse_key(185, cmds, shell);
	parse_key(DELETE, cmds, shell);
	return (1);
}
bool IniSimpleParser::parse(const char* file_path)
{
	input_file_.open(file_path, ios::in);
	if (input_file_.fail())
		return false;
	settings_pairs_ = map<string, string>();
	string line_content;
	while (input_file_.eof() == false)
	{
		try{
			getline(input_file_, line_content);
		}catch (exception e){
			cout << e.what() << endl;
			input_file_.close();
			return false;
		}
		if (is_content_available(line_content) == false)
			continue;
		int seperator_pos;
		string key = parse_key(line_content, seperator_pos);
		string value = parse_value(line_content, seperator_pos + 1);
		settings_pairs_.insert(pair<string, string>(key, value));
	}
	input_file_.close();
	return true;
}
Exemple #6
0
static int do_append( struct chronos_handle * handle, int argc, char** argv ){
	int key_parsed = 0;
	struct index_key key;

	if( argc > 4 && strncmp("-t", argv[3], 2) == 0 ){
		int rc = parse_key( argv[4], strlen( argv[4] ), & key );
		if( rc == 0 ){
			key_parsed = 1;
		} else {
			bad_key(rc, argv[4]);
			return rc;
		}
	}

	int rc = 0;
	if( key_parsed ){
		rc = chronos_append( handle, & key, 0 );
	} else {
		rc = chronos_append( handle, NULL, 0 );
	}
	if( rc != 0 ){
		if( rc == C_PROVIDED_KEY_NOT_LATEST ){
			fprintf( stderr, "can't insert keys before the last entry.\n");
        } else if ( rc == C_IO_NEEDS_A_PIPE ) {
			fprintf( stderr, "error reading stdin, it must be a pipe!\n");
		} else {
			perror("chronos_append");
		}
		return rc;
	}

	return 0;
}
Exemple #7
0
static int do_get( struct chronos_handle * handle, int argc, char** argv ){
	struct index_key key;
	int rc = parse_key( argv[3], strlen( argv[3] ), & key );
	if( rc != 0 ){
		bad_key(rc, argv[3]);
		return rc;
	}

	struct index_entry entry;

	rc = chronos_find( handle, & key, & entry );
	if( rc != 0 ){
		if( rc != C_NOT_FOUND ){
			perror("chronos_find");
		}
		return rc;
	}

	// output to stdout
	chronos_output( handle, & entry, 1 );
	if( rc != 0 ){
		perror("chronos_output");
		return rc;
	}

	return 0;
}
Exemple #8
0
static bool parse_keys(struct key_chain *chain, const char *keys)
{
	int i = 0;

	clear(chain);
	while (keys[i]) {
		int start;

		while (keys[i] == ' ')
			i++;
		start = i;
		while (keys[i] && keys[i] != ' ')
			i++;
		if (start == i)
			break;

		if (chain->count >= ARRAY_COUNT(chain->keys)) {
			error_msg("Too many keys.");
			return false;
		}
		if (!parse_key(&chain->types[chain->count], &chain->keys[chain->count], keys + start, i - start))
			return false;
		chain->count++;
	}
	if (chain->count == 0) {
		error_msg("Empty key not allowed.");
		return false;
	}
	return true;
}
Exemple #9
0
static int parser_insert_node(Parser *parser, char *key, char *value)
{
	if(!key || !value)
	{
		PRINTF("invalid parameter!\n");
		return -1;
	}
	
	PRINTF("start!\n");
	char *widget_name = NULL;	
	TagType type = TAG_CONTENT;
	int is_ddl = 0;
	int ddl_id = 0;
	TagNode *node = NULL;
	char tmp_key_buf[32] = {0};
	
	memcpy(tmp_key_buf, key, strlen(key));
	parse_key(key, &widget_name, &type, &is_ddl, &ddl_id);
	PRINTF("\nafter parse key\n");
	printf("widget_name(%s) type(%d), is_ddl(%d), ddl_id(%d)\n", widget_name, type, is_ddl, ddl_id);
	node = create_tree_node(type, widget_name, is_ddl, ddl_id, tmp_key_buf);
	printf("after create_tree_node  type(%d), widget_name(%s), is_ddl(%d), ddl_id(%d)\n", node->tag_type, \
			node->tag_name, node->is_ddl, node->ddl_id);

	parser_tree_insert_node(parser, node);

	return 0;
}
Exemple #10
0
static int check_events(void)
{
	struct input_event *iev;
	int ret = 0;
	int rep_config_done = 0;
	int rep_keys_done = 0;

	read_events();

	while (have_events()) {
		iev = next_event();
		switch (iev->type) {
		case EV_REP:
			ret = parse_autorepeat_config(iev);
			rep_config_done = 1;
			break;
		case EV_KEY:
			ret = parse_key(iev);
			rep_keys_done = 1;
			break;
		default:
			tst_resm(TFAIL,
				 "Unexpected event type '0x%04x' received",
				iev->type);
			ret = 0;
			break;
		}

		if (!ret || (rep_config_done && rep_keys_done))
			break;
	}

	return ret;
}
Exemple #11
0
// Lua: ip = wifi.ap.dhcp.config()
static int wifi_ap_dhcp_config( lua_State* L )
{
  if (!lua_istable(L, 1))
    return luaL_error( L, "wrong arg type" );

  struct dhcps_lease lease;
  uint32_t ip;

  ip = parse_key(L, "start");
  if (ip == 0)
    return luaL_error( L, "wrong arg type" );

  lease.start_ip = ip;
  NODE_DBG(IPSTR, IP2STR(&lease.start_ip));
  NODE_DBG("\n");

  // use configured max_connection to determine end
  struct softap_config config;
  wifi_softap_get_config(&config);
  lease.end_ip = lease.start_ip;
  ip4_addr4(&lease.end_ip) += config.max_connection - 1;

  char temp[64];
  c_sprintf(temp, IPSTR, IP2STR(&lease.start_ip));
  lua_pushstring(L, temp);
  c_sprintf(temp, IPSTR, IP2STR(&lease.end_ip));
  lua_pushstring(L, temp);

  // note: DHCP max range = 101 from start_ip to end_ip
  wifi_softap_dhcps_stop();
  wifi_softap_set_dhcps_lease(&lease);
  wifi_softap_dhcps_start();

  return 2;
}
Exemple #12
0
/*==========================================
 * is_key_in_use -- Return TRUE if a live record
 *========================================*/
BOOLEAN
is_key_in_use (CNSTRING key)
{
	DELETESET set=0;
	INT keynum=0;
	char ktype=0;
	CNSTRING barekey=0;
	BOOLEAN result=FALSE;

	if (!parse_key(key, &ktype, &keynum)) {
		char msg[512];
		snprintf(msg, sizeof(msg)/sizeof(msg[0]), "Bad key passed to is_key_in_use: %s", key);
		FATAL2(msg);
	}

	set = get_deleteset_from_type(ktype);

	ASSERT(keynum>0);
	
	result = xref_isvalid_impl(set, keynum);

	strfree((STRING *)&barekey);
	
	return result;
}
Exemple #13
0
bool add_keys_from_file(const char *key_file)
{
    int size;
    FILE *fd = fopen(key_file, "r");
    if(fd == NULL)
    {
        if(g_debug)
            perror("cannot open key file");
        return false;
    }
    fseek(fd, 0, SEEK_END);
    size = ftell(fd);
    fseek(fd, 0, SEEK_SET);
    char *buf = xmalloc(size + 1);
    if(fread(buf, 1, size, fd) != (size_t)size)
    {
        if(g_debug)
            perror("Cannot read key file");
        fclose(fd);
        return false;
    }
    buf[size] = 0;
    fclose(fd);

    if(g_debug)
        printf("Parsing key file '%s'...\n", key_file);
    char *p = buf;
    while(1)
    {
        struct crypto_key_t k;
        /* parse key */
        if(!parse_key(&p, &k))
        {
            if(g_debug)
                printf("invalid key file\n");
            return false;
        }
        if(g_debug)
        {
            printf("Add key: ");
            print_key(&k, true);
        }
        add_keys(&k, 1);
        /* request at least one space character before next key, or end of file */
        if(*p != 0 && !isspace(*p))
        {
            if(g_debug)
                printf("invalid key file\n");
            return false;
        }
        /* skip whitespace */
        while(isspace(*p))
            p++;
        if(*p == 0)
            break;
    }
    free(buf);
    return true;
}
Exemple #14
0
static void exec_release(const char* args, context_t* ctx, debug_t* dbg)
{
    joypad_key_t key = parse_key(args);

    (void)dbg;

    if (key != KEY_INVALID) {
        printf("Released %s\n", args);
        joypad_release(ctx, key);
    }
}
Exemple #15
0
#include "assert.h"
#include "stdlib.h"
#include "stdio.h"
#include "allegro.h"
#include "string.h"
#include "ctype.h"
//#include "memory.h"
#include "trace.h"
#include "strparse.h"
#ifndef EXPERIMENTAL_NOTE_TRACK
#include "allegrord.h"
#endif /* EXPERIMENTAL_NOTE_TRACK */
#define streql(s1, s2) (strcmp(s1, s2) == 0)
#define field_max 80


//Note that this is an #ifdef, not an #ifndef
#ifdef EXPERIMENTAL_NOTE_TRACK

class Alg_reader {
public:
    FILE *file;
    int line_no;
    String_parse line_parser;
    bool line_parser_flag;
    char field[field_max];
    bool error_flag;
    Alg_seq_ptr seq;
    double tsnum;
    double tsden;

    Alg_reader(FILE *a_file, Alg_seq_ptr new_seq);
    void readline();
    Alg_parameters_ptr process_attributes(Alg_parameters_ptr attributes, double time);
    bool parse();
    long parse_chan(char *field);
    long parse_int(char *field);
    int find_real_in(char *field, int n);
    double parse_real(char *field);
    void parse_error(char *field, long offset, char *message);
    double parse_dur(char *field, double base);
    double parse_after_dur(double dur, char *field, int n, double base);
    double parse_loud(char *field);
    long parse_key(char *field);
    double parse_pitch(char *field);
    long parse_after_key(int key, char *field, int n);
    long find_int_in(char *field, int n);
    bool parse_attribute(char *field, Alg_parameter_ptr parm);
    bool parse_val(Alg_parameter_ptr param, char *s, int i);
    bool check_type(char type_char, Alg_parameter_ptr param);
};

#endif /* EXPERIMENTAL_NOTE_TRACK */

void subseq(char *result, char *source, int from, int to)
{
    memcpy(result, source + from, to - from);
    result[to - from] = 0;
}

#ifndef EXPERIMENTAL_NOTE_TRACK
double Allegro_reader::parse_pitch(char *field)
#else /* EXPERIMENTAL_NOTE_TRACK */
double Alg_reader::parse_pitch(char *field)
#endif /* EXPERIMENTAL_NOTE_TRACK */
{
    if (isdigit(field[1])) {
        char real_string[80];
        int last = find_real_in(field, 1);
        subseq(real_string, field, 1, last);
        return atof(real_string);
    } else {
        return (double) parse_key(field);
    }
}
int main(void) {
	size_t i;

	for(i = 0; i < sizeof(keys) / sizeof(struct key); i++) {
		int res = parse_key(keys[i].text, keys[i].formatted, keys[i].valid);
		if(res != EXIT_SUCCESS) {
			return res;
		}
	}

	return EXIT_SUCCESS;
}
Exemple #17
0
static int	parse_key_three(size_t key, t_cmds **cmd, t_shell *shell)
{
	if (key == 344)
	{
		while ((*cmd)->pointer > 0 && (*cmd)->cmd[(*cmd)->pointer] == ' ')
			parse_key(186, cmd, shell);
		while ((*cmd)->pointer > 0 && (*cmd)->cmd[(*cmd)->pointer] != ' ')
			parse_key(186, cmd, shell);
	}
	else if (key == 343)
	{
		while ((*cmd)->pointer < (int)ft_strlen((*cmd)->cmd)
			&& (*cmd)->cmd[(*cmd)->pointer] != ' ')
			parse_key(185, cmd, shell);
		while ((*cmd)->pointer < (int)ft_strlen((*cmd)->cmd)
			&& (*cmd)->cmd[(*cmd)->pointer] == ' ')
			parse_key(185, cmd, shell);
	}
	else
		return (parse_key_four(-1, key, cmd, shell));
	return (1);
}
Exemple #18
0
/* pair = key ':' value */
static int parse_pair(struct frozen *f) {
  int current_path_len;
  const char *tok;
  skip_whitespaces(f);
  tok = f->cur;
  TRY(parse_key(f));
  current_path_len =
      append_to_path(f, *tok == '"' ? tok + 1 : tok,
                     *tok == '"' ? f->cur - tok - 2 : f->cur - tok);
  TRY(test_and_skip(f, ':'));
  TRY(parse_value(f));
  truncate_path(f, current_path_len);
  return 0;
}
Exemple #19
0
/*
 * Read keyfile and look for lines starting with keywords "up, down, left,
 * right, stop, pause & exit". When found, send the rest of the string to
 * parse_key(). If invalid keyword found, or parse_key() returns true,
 * report syntax error to stderr and return to caller.
 * Return values:
 * 0: Success
 * 1: Can't open file
 * 2: Syntax error
 */
int setkeys(char* path) {
    FILE *file;
    char line[MAXLINE];
    char keyword[MAXLINE];
    char value[MAXLINE];
    int matches;
    int error_flag = 0;
    int i;

    /* Open file for reading */
    if ( ! (file = fopen(path, "r")) ) {
            return 1;
    }
    
    /* Read lines from file */
    while (fgets(line, MAXLINE, file) != NULL) {
        if (line[0] == '#') {
            continue;
        }
        
        /* Ket keyword and value from line */
        matches = sscanf(line, "%s%s", keyword, value);
        if (matches == EOF) {
            continue;
        }

        /* Compare word from line with valid keywords. On syntax error, report
         * error and return 1 to caller. */
        error_flag = 1; /* Murphy's law */
        for (i = 0; i < KEYWORDS_COUNT; i++) {
            if (strcmp(keyword, kw[i].keyword) == 0) {
                error_flag = 0;
                if (parse_key(value, kw[i].global) != 0) {
                    error_flag = 1;
                }
                break;
            }
        }
        if (error_flag) {
            error(0, 0, "Keyfile syntax error -- %s", path);
            return 2;
        }
    }
    /* Whole file read with no errors */
    return 0;
}
Exemple #20
0
static	void	snew_key_from_str (uc *string, char *what)
{
	int	i;
	int	meta;
	int	old_display;
	uc	chr;

	old_display = window_display;
	window_display = 0;
	if ((meta = parse_key(string, &chr)) == -1)
		return;
	window_display = old_display;

	if (lookup_function(what, &i) == 1)
		new_key(meta, chr, i, 0, NULL);

	return;
}
Exemple #21
0
int main()
{
  setup();
  sidebar *sb = create_sidebar();
  setup_sidebar_items(sb);
  content_pane *cp = create_content_pane();
  setup_content_items(cp);
  wrapper *wp = create_wrapper(cp, sb);
  print_wrapper(wp);

  int x, y;
  getmaxyx(stdscr, x, y);
  mvprintw(20, 21, "x: %d y: %d", x, y);

  parse_key(wp);
  tear_down();
  return 0;
}
Exemple #22
0
/*===================================================
 * addxref_impl -- Mark key free (accepts string key, any type)
 *  key:    [IN]  key to delete (add to free set)
 *  silent: [IN]  if FALSE, ASSERT if record is already free
 *=================================================*/
static BOOLEAN
addxref_impl (CNSTRING key, DUPS dups)
{
	char ktype=0;
	INT keynum=0;
	if (!parse_key(key, &ktype, &keynum)) {
		char msg[512];
		snprintf(msg, sizeof(msg)/sizeof(msg[0]), "Bad key passed to addxref_impl: %s", key);
		FATAL2(msg);
	}
	switch(ktype) {
	case 'I': return addixref_impl(keynum, dups);
	case 'F': return addfxref_impl(keynum, dups);
	case 'S': return addsxref_impl(keynum, dups);
	case 'E': return addexref_impl(keynum, dups);
	case 'X': return addxxref_impl(keynum, dups);
	default: ASSERT(0); return FALSE;
	}
}
Exemple #23
0
static bool parse_key(unsigned char *type, unsigned int *key, const char *str, int len)
{
	unsigned char ch;
	int i;

	if (len == 1) {
		*type = KEY_NORMAL;
		*key = str[0];
		return true;
	}
	if (buf_str_case_equal(str, len, "sp") || buf_str_case_equal(str, len, "space")) {
		*type = KEY_NORMAL;
		*key = ' ';
		return true;
	}
	ch = toupper(str[1]);
	if (str[0] == '^' && len == 2) {
		if (ch >= 0x40 && ch < 0x60) {
			*type = KEY_NORMAL;
			*key = ch - 0x40;
			return true;
		}
		if (ch == '?') {
			*type = KEY_NORMAL;
			*key = 0x7f;
			return true;
		}
	}
	if (toupper(str[0]) == 'M' && str[1] == '-' && parse_key(type, key, str + 2, len - 2)) {
		*type = KEY_META;
		return true;
	}
	for (i = 0; i < NR_SKEYS; i++) {
		if (buf_str_case_equal(str, len, special_names[i])) {
			*type = KEY_SPECIAL;
			*key = i;
			return true;
		}
	}
	error_msg("Invalid key %s", str);
	return false;
}
Exemple #24
0
void run_command_unbind(char *argstr) /* {{{ */
{
	/**
	 * unbind a key
	 * syntax - mode key
	 */
	char *modestr = NULL, *keystr = NULL, *keyname = NULL;
	prog_mode mode;
	int ret = 0;

	/* parse args */
	if (argstr != NULL)
		ret = sscanf(argstr, "%ms %m[^\n]", &modestr, &keystr);
	if (ret != 2)
	{
		statusbar_message(cfg.statusbar_timeout, "syntax: unbind <mode> <key>");
		tnc_fprintf(logfp, LOG_ERROR, "syntax: unbind <mode> <key> [%d](%s)", ret, argstr);
		goto cleanup;
	}

	/* parse mode */
	if (str_eq(modestr, "pager"))
		mode = MODE_PAGER;
	else if (str_eq(modestr, "tasklist"))
		mode = MODE_TASKLIST;
	else
		mode = MODE_ANY;

	int key = parse_key(keystr);

	remove_keybinds(key, mode);
	keyname = name_key(key);
	statusbar_message(cfg.statusbar_timeout, "key unbound: %s (%d)", keyname, key);
	goto cleanup;

cleanup:
	free(keyname);
	free(modestr);
	free(keystr);
	return;
} /* }}} */
Exemple #25
0
static grub_video_color_t
parse_color (char *name, grub_uint32_t *fill)
{
  int fg, bg;
  char *p, *n;

  n = grub_menu_next_field (name, ',');
  if (n)
    *fill = parse_key (n);

  if (*name == '#')
    {
      grub_uint32_t rgb;

      rgb = grub_strtoul (name + 1, &name, 16);
      if (grub_menu_region_get_current ()->map_rgb)
	{
	  grub_menu_restore_field (n, ',');
	  return grub_menu_region_get_current ()->map_rgb (rgb >> 16, rgb >> 8,
							   rgb);
	}
Exemple #26
0
	void parse_object(const char* json, JsonObject& object)
	{
		CE_ASSERT_NOT_NULL(json);

		if (*json == '{')
		{
			json = skip_spaces(++json);

			if (*json == '}')
				return;

			while (*json)
			{
				const char* key_begin = *json == '"' ? (json + 1) : json;

				TempAllocator256 ta;
				DynamicString key(ta);
				json = parse_key(json, key);

				FixedString fs_key(key_begin, key.length());

				json = skip_spaces(json);
				json = next(json, (*json == '=') ? '=' : ':');
				json = skip_spaces(json);

				map::set(object, fs_key, json);

				json = skip_value(json);
				json = skip_spaces(json);

				if (*json == '}')
					return;

				json = skip_spaces(json);
			}
		}

		CE_FATAL("Bad object");
	}
Exemple #27
0
	static void parse_root_object(const char* json, JsonObject& object)
	{
		CE_ENSURE(NULL != json);

		while (*json)
		{
			const char* key_begin = *json == '"' ? (json + 1) : json;

			TempAllocator256 ta;
			DynamicString key(ta);
			json = parse_key(json, key);

			FixedString fs_key(key_begin, key.length());

			json = skip_spaces(json);
			json = next(json, (*json == '=') ? '=' : ':');
			json = skip_spaces(json);

			map::set(object._map, fs_key, json);

			json = skip_value(json);
			json = skip_spaces(json);
		}
	}
Exemple #28
0
// pair = key ':' value
static int parse_pair(struct frozen *f) {
  TRY(parse_key(f));
  TRY(test_and_skip(f, ':'));
  TRY(parse_value(f));
  return 0;
}
Exemple #29
0
gboolean module_feedkey(int kv, int kvstate)
{
  int lkv = tolower(kv);
  int shift_m=(kvstate&ShiftMask) > 0;
//  printf("%x %c  %d\n", kv, kv, shift_m);

  if (kvstate & ControlMask)
    return FALSE;
  if (kvstate & (Mod1Mask|Mod4Mask|Mod5Mask))
    return FALSE;

  if (kv==XK_Shift_L||kv==XK_Shift_R) {
    key_press_time = gmf.mf_current_time();
  }

  if (!gmf.mf_tsin_pho_mode())
    return 0;

  gboolean b_is_empty = is_empty();

  switch (kv) {
    case XK_F7:
      if (is_empty())
        return FALSE;
      state = STATE_ROMANJI;
      if (state_hira_kata != STATE_kata)
        state_hira_kata = STATE_kata;
      else
        state_hira_kata = STATE_hira;
      disp_input();
      return TRUE;
    case XK_F8:
      if (is_empty())
        return FALSE;
      state = STATE_ROMANJI;
      if (state_hira_kata != STATE_half_kata)
        state_hira_kata = STATE_half_kata;
      else
        state_hira_kata = STATE_hira;
      disp_input();
      return TRUE;
    case XK_F11:
      system("kasumi &");
      return TRUE;
    case XK_F12:
      system("kasumi -a &");
      return TRUE;
    case XK_Up:
      if (b_is_empty)
        return FALSE;
      if (state==STATE_SELECT) {
        int N = page_N();
        gmf.mf_tss->pho_menu_idx--;
        if (gmf.mf_tss->pho_menu_idx < 0)
          gmf.mf_tss->pho_menu_idx = N - 1;
        disp_select();
      }
      return TRUE;
    case XK_Down:
      if (b_is_empty)
        return FALSE;
      if (state==STATE_CONVERT) {
        state = STATE_SELECT;
        gmf.mf_tss->sel_pho = TRUE;
  //      puts("STATE_SELECT");
        disp_select();
      } else
      if (state==STATE_SELECT) {
        int N = page_N();
        gmf.mf_tss->pho_menu_idx=(gmf.mf_tss->pho_menu_idx+1)% N;
        disp_select();
      }
      return TRUE;
    case XK_Return:
      if (b_is_empty)
        return FALSE;
      if (state==STATE_SELECT) {
        if (select_idx(gmf.mf_tss->pho_menu_idx))
          goto send;
        return TRUE;
      }
send:
      return module_flush_input();
    case XK_Escape:
        if (state==STATE_SELECT) {
          state = STATE_CONVERT;
          gmf.mf_tss->sel_pho = FALSE;
          gmf.mf_clear_sele();
        }
        else
        if (state==STATE_CONVERT)
          goto rom;
      return FALSE;
    case XK_BackSpace:
      if (b_is_empty) {
        state_hira_kata = STATE_hira;
        return FALSE;
      }

      gmf.mf_hide_selections_win();

      if (state&(STATE_CONVERT|STATE_SELECT)) {
rom:
//        puts("romanji");
        state = STATE_ROMANJI;
        cursor = jpN;
        segN = 0;
        disp_input();
        return TRUE;
      }

//      puts("back");
      if (keysN) {
        keysN--;
        keys[keysN]=0;
      }
      else
      if (jpN && cursor) {
        delete_jpstr(cursor-1);
        cursor--;
      } else
        return FALSE;
      disp_input();
      auto_hide();
      return TRUE;
    case XK_Delete:
      if (b_is_empty)
        return FALSE;
      if (state&STATE_ROMANJI) {
        if (keysN)
          return TRUE;
        delete_jpstr(cursor);
        disp_input();
      }
      auto_hide();
      return TRUE;
    case XK_Left:
      if (b_is_empty)
        return FALSE;
      if (state&STATE_ROMANJI) {
        if (keysN)
          keysN = 0;
        else {
          if (cursor)
            cursor--;
        }
        disp_input();
      } else
      if (state&STATE_CONVERT) {
        if (shift_m) {
          anthy_resize_segment(ac, cursor, -1);
          load_seg();
        } else {
          if (cursor)
            cursor--;
        }
        disp_convert();
      }
      return TRUE;
    case XK_Right:
      if (b_is_empty)
        return FALSE;
      if (state&STATE_ROMANJI) {
        if (cursor < jpN)
          cursor++;
        disp_input();
      } else
      if (state&STATE_CONVERT) {
        if (shift_m) {
          anthy_resize_segment(ac, cursor, 1);
          load_seg();
        } else {
          if (cursor < segN-1)
            cursor++;
        }
        disp_convert();
      }
      return TRUE;
    case XK_Home:
      if (b_is_empty)
        return FALSE;
      cursor = 0;
      if (state&STATE_ROMANJI) {
        disp_input();
      } else
      if (state&STATE_CONVERT) {
        disp_convert();
      }
      return TRUE;
    case XK_End:
      if (b_is_empty)
        return FALSE;
      if (state&STATE_ROMANJI) {
        cursor = jpN;
        disp_input();
      } else
      if (state&STATE_CONVERT) {
        cursor = segN-1;
        disp_convert();
      }
      return TRUE;
    case XK_Prior:
      if (state!=STATE_SELECT)
        return FALSE;
      prev_page();
      return TRUE;
    case XK_Next:
      if (state!=STATE_SELECT)
        return FALSE;
      next_page();
      return TRUE;
    case ' ':
      if (b_is_empty)
        return FALSE;
      goto lab1;
    default:
      if (state==STATE_SELECT) {
        char *pp;
        if ((pp=strchr(*gmf.mf_pho_selkey, lkv))) {
          int c=pp-*gmf.mf_pho_selkey;
          if (select_idx(c))
            goto send;
        }
        return TRUE;
      }
  }

//  printf("kv %d\n", kv);
  if (!is_legal_char(kv))
    return FALSE;

  kv = lkv;

  if (state==STATE_CONVERT && kv!=' ') {
    send_seg();
    state = STATE_ROMANJI;
  }

lab1:
  if (state==STATE_ROMANJI) {
    if (keysN < MAX_KEYS)
      keys[keysN++]=kv;

    keys[keysN]=0;
    parse_key();
    disp_input();
  }

  module_show_win();

  if (kv==' ') {
    if (state==STATE_ROMANJI) {
      char tt[512];
      clear_seg_label();
      merge_jp(tt, TRUE);
//      dbg("tt %s %d\n", tt, strlen(tt));
      anthy_set_string(ac, tt);
      load_seg();
    } else
    if (state==STATE_CONVERT) {
      state = STATE_SELECT;
      gmf.mf_tss->sel_pho = TRUE;
//      puts("STATE_SELECT");
      disp_select();
    } else
    if (state==STATE_SELECT) {
      next_page();
    }
  }

  return TRUE;
}
Exemple #30
0
Fichier : xkey.c Projet : 8l/ted
LoadTedrc(char *tedname, int depth, int kdefmapno)
{
FILE *fp;
char ss[8192],ibuf[2048],*tt,*uu,*vv,*ww,*xx;
int len,i,j,lno;
int hdef[128];
extern int X_inited;
KEYDEF *kdef=kdefmap[kdefmapno];
int kdefno=kdefno_m[kdefmapno];

if ((fp=init_tedrc_fname(tedname, depth))==NULL)
	return 1;

if (kdefno && !depth) {
	for(j=0;j<kdefno;j++) free(kdef[j].cmd);
	if (!kdefmapno) free_lang();
	free(kdef);
	kdefmap[kdefmapno]=NULL;
	if (kdefmapno) {
		free(mode_str_m[kdefmapno]);
		mode_str_m[kdefmapno]=NULL;
	}
	kdef=NULL;
}
#if	0
printf("-- %d %d %s\n",depth, kdefmapno, ftedrc);
#endif
if (kdef==NULL) {
	MAX_KEY_DEF=280;
	if ((kdef=mmalloc(sizeof(KEYDEF)*MAX_KEY_DEF,"LoadTedrc"))==NULL)
		exit(1);
	kdefmap[kdefmapno]=kdef;
	kdefno_m[kdefmapno]=kdefno=0;
}


if (!depth) qsort(kmap,kname_no,sizeof(KEYMAP),qcmpxk);
tedrcfname=tedname;
lno=0;
while (!feof(fp)) {
	int next_l;

	ss[0]=0;
	next_l=0;
	for(;;) {
		lno++;
		len=mfgets(ibuf,sizeof(ibuf),fp);
		if (!len) {
			next_l=1;
			break;
		}
		if (ibuf[len-1]=='\n') ibuf[--len]=0;
		if (!len) {
			next_l=1;
			break;
		}
		while (len && (ibuf[len-1]==' '||ibuf[len-1]==9)) len--;
		if (!len) {
			next_l=1;
			break;
		}
		if (ibuf[len-1]=='\\') {
			ibuf[len-1]=0;
			strcat(ss,ibuf);
		} else {
			strcat(ss,ibuf);
			break;
		}
	}
	if (next_l) continue;

	tt=skip_spc(ss);
	uu=to_spc(tt);
	vv=skip_spc(uu);
	*uu=0;
	if (tt[0]=='#')	continue;
	if (!strcmp(tt,"d")) {
		ww=to_spc(vv);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		kdef[kdefno].klen=parse_key(tedname, lno,vv,ww,kdef[kdefno].kcode);
		if ((i=kcode_exist(kdefno,kdef,kdefno))<kdefno)
			free(kdef[i].cmd);
		xx=skip_spc(ww);
		kdef[i].cmd=strdup(parse_Cstr(tedname, lno,xx,&uu));
		kdef[i].type=0;
		if (i==kdefno) incr_kdefno(&kdef,kdefmapno,&kdefno);
		continue;
	} else
	if (!strcmp(tt,"f")) {
		ww=to_spc(vv);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		kdef[kdefno].klen=parse_key(tedname, lno,vv,ww,kdef[kdefno].kcode);
		if ((i=kcode_exist(kdefno,kdef,kdefno))<kdefno)
			free(kdef[i].cmd);
		xx=skip_spc(ww);
		if (parse_stmt(tedname, lno,xx,&kdef[i].cmd,&kdef[i].type)) {
			if (i==kdefno) incr_kdefno(&kdef,kdefmapno,&kdefno);
		}
		continue;
	}
	if (kdefmapno)
		lper(tedname,lno,"%s for LoadKeyDefInto can accept 'f' and 'd' command only", tedname);
	if (!strcmp(tt,"s")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		*ww=0;
		for(i=0;i<sizeof(locolor)/sizeof(locolor[0]);i++)
			if (!strcmp(vv,locolor[i].cname)) break;
		if (i==sizeof(locolor)/sizeof(locolor[0]))
			lper(tedname,lno,"Unknown Def color %s",vv);
		ww=to_spc(xx);
		*ww=0;
		strcpy(locolor[i].caddr,xx);
	} else
	if (!strcmp(tt,"set")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		tt=to_spc(xx);
		if (!(*ww)) lper(tedname,lno,"argument expected");
		*ww=0;
		for(i=0;i<sizeof(sets)/sizeof(sets[0]);i++)
		if (!strcmp(sets[i].sname,vv)) break;
		if (i==sizeof(sets)/sizeof(sets[0]))
			lper2(tedname,lno,"Unknown set %s",vv);
		else {
		  *tt=0;
		  *(sets[i].saddr)=atoi(xx);
		}
	} else
	if (!strcmp(tt,"lang") && !depth) {
		extern char DirectCommentChars[];
		int keywcnt=3,LangIdx,ColIdx,AllocN=32,kwidx, MaxKeywordLen=0;
		char *ff;
		KW *kw;

		if (depth)
			p_err("cannot define 'lang' in include %s", tedname);


		tt=parse_Cstr(tedname, lno,vv,&uu);
		i=strlen(tt)+2;
		if ((vv=mmalloc(i,"LoadTedrc"))==NULL) exit(1);
		if ((kw=mmalloc(AllocN*sizeof(KW),"LoadTedrc 2"))==NULL) exit(1);

		LangExt[LangN]=strcat(strcpy(vv,tt)," ");
		kw[0].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		uu=skip_spc(uu);
		DirectCommentChars[LangN]=*uu;
		kw[1].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		kw[2].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		for(;;) {
			if (!*uu) break;
			strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
			strcpy(pc_color[ColorCnt].bg_str,getstr(vv,&uu));
			uu=skip_spc(uu);
			ww=tt=parse_Cstr(tedname, lno,uu,&vv);
			uu=vv;
			xx=tt+strlen(tt);
			for(;;) {
				char *pstr;

				tt=to_spc(ww);
				vv=skip_spc(tt);
				*(tt)=0;
				if (pstr=strchr(ww,'(')) {
					kw[keywcnt].arg=strdup(pstr);
					*pstr=0;
				} else kw[keywcnt].arg=0;
				kw[keywcnt].keyword=strdup(ww);
				if (strlen(ww) > MaxKeywordLen) MaxKeywordLen=strlen(ww);
				kw[keywcnt].coloridx=ColorCnt;
#if	0
				printf("%d %d   %d %s\n",LangN,keywcnt, ColorCnt,
				kw[keywcnt].keyword);
#endif
				keywcnt++;
				if (keywcnt+3>=AllocN) {
					AllocN+=32;
					if ((kw=mrealloc(kw,AllocN*sizeof(KW),"LoadTedrc 3"))==NULL) exit(1);
				}
				ww=vv;
				if (ww==xx) break;
			}
			ColorCnt++;
		}
		qsort(kw+3,keywcnt-3,sizeof(KW), kwcmp);
		LangKw[LangN]=kw;
		LangMaxKeywordLen[LangN]=MaxKeywordLen;
		LangKwN[LangN++]=keywcnt;
		if (LangN>=MaxLang) {
			error("Too many languages defined");
			error("Remove unused language in tedrc or modify ted.h and recompile");
			exit(1);
		}
	} else
	if (!strcmp(tt,"include")) {
		if (depth > 10) {
			error("include too many level ??");
			continue;
		}
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		*ww=0;
		LoadTedrc(vv,depth+1,kdefmapno);
		tedrcfname=tedname;
	} else
	if (!strcmp(tt,"filebrowser")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		init_reg_exp(vv);
	} else
	if (!strcmp(tt,"fontlist")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		setFontList(vv);
	} else
	if (!strcmp(tt,"LoadKeyDefInto")) {
		int no;
		char mstr[16], *p;
		tt=parse_Cstr(tedname, lno,vv,&uu);
		if (!(*tt)) lper(tedname,lno,"file name expected");
		ww=skip_spc(uu);
		if (!*ww) lper(tedname,lno,"Bind number expected");
		no=*ww-'0';
		if (no<=0 || no>=4)
			lper(tedname,lno,"Bind number must be less than 4 and greater than 0");
		if ((p=strchr(tt,'.'))==NULL) {
			mode_str_m[no]="      ";
		} else {
			p++;
			if (! *p)
				mode_str_m[no]=strdup("      ");
			else
				mode_str_m[no]=strdup(p);
		}
		LoadTedrc(tt,0,no);
	}
}
fclose(fp);

if (!depth) {
kdefno=kdefno_m[kdefmapno];
qsort(kdef,kdefno,sizeof(kdef[0]),qcmp);
bzero(hdef,sizeof(hdef));
bzero(kdefhash[kdefmapno],128*sizeof(int));
for(i=0;i<kdefno;i++) {
	j=KEYHASH(kdef[i].kcode[0]);
	if (hdef[j]) continue;
	hdef[j]=1;
	kdefhash[kdefmapno][j]=i;
}
kdefhash[kdefmapno][127]=kdefno;
for(i=126;i>=0;i--)
if (!hdef[i]) kdefhash[kdefmapno][i]=kdefhash[kdefmapno][i+1];
ReLoadTed=1;
if (X_inited) alloc_pc_colors();
}
return 0;
}