예제 #1
0
파일: editor.cpp 프로젝트: Fomka/ufo2000
/**
 * Sets correct value ranges in GUI controls 
 * after the user changes information related to skins
 */
static void fixup_unit_info()
{
    if (sol_dialog[D_RACE].d1 == 0) {
        armour_names     = armour_names_human;
        appearance_names = appearance_names_human;
    } else if (sol_dialog[D_RACE].d1 == (SKIN_NUMBER - 4)) { //LAWYER:  This really should be a little more visible - adding more units needs this number changed
        armour_names     = armour_names_chameleon;
        init_chameleon_appearances();
    } else {
        armour_names     = armour_names_alien;
        appearance_names = appearance_names_alien;
    }
    if (sol_dialog[D_ARMOUR].d1 >= get_list_size(armour_names))
        sol_dialog[D_ARMOUR].d1 = 0;
    if (sol_dialog[D_APPEARANCE].d1 >= get_list_size(appearance_names))
        sol_dialog[D_APPEARANCE].d1 = 0;

    DIALOG *d;
    d = &sol_dialog[D_RACE];
    d->w = text_length(font, race_names[d->d1]) + 6;
    d->dp = (void *)race_names[d->d1];
    d = &sol_dialog[D_APPEARANCE];
    d->w = text_length(font, appearance_names[d->d1]) + 6;
    d->dp = (void *)appearance_names[d->d1];
    d = &sol_dialog[D_ARMOUR];
    d->w = text_length(font, armour_names[d->d1]) + 6;
    d->dp = (void *)armour_names[d->d1];
}
예제 #2
0
void debugger_interpreter_stopped()
{
  int nof_elements;
  uint32_t **elements;
  int i;

  close(newsockfd);
  close(sockfd);

  if (pcs != NULL)
  {
    nof_elements = get_list_size(pcs);
    elements = (uint32_t**)delete_list_and_get_ptrs(pcs);
    for (i=0; i<nof_elements; i++)
      free(elements[i]);
  }

  if (breakpoints != NULL)
  {
    nof_elements = get_list_size(breakpoints);
    elements = (uint32_t**)delete_list_and_get_ptrs(breakpoints);
    for (i=0; i<nof_elements; i++)
      free(elements[i]);
  }
}
예제 #3
0
// help get a list of positions from variable
int get_pos_from_var(list_t *vars, char *var_name, int **pos)
{
  variable_t *pos_var = find_variable(vars, var_name);
  int num_pos = 0;
  if (pos_var->is_id) {
    // dealing with row id, assign directly
    num_pos = get_list_size(pos_var->ids);
    *pos = calloc(num_pos, sizeof(int));
    memcpy(*pos, pos_var->ids->data, sizeof(int) * num_pos);
  } else {
    // now we need to convert from bit vector
    num_pos = get_bv_count(pos_var->bv);
    *pos = calloc(num_pos, sizeof(int));
    // go through the whole bit vector to get the values
    // TODO: should be a better strategy than this!
    uint32_t size = get_bv_size(pos_var->bv);
    uint32_t itr = 0;
    for (uint32_t u=0; u < size; u++) {
      if (is_marked(pos_var->bv, u)) {
        (*pos)[itr] = u;
        itr ++;
      }
    }
    debug("Itr ended at %d\n", itr);
    dbg_assert(itr == num_pos);
  }

  return num_pos;
}
예제 #4
0
파일: hmdp.c 프로젝트: ablochha/Resume
// Sends the HMDP response '302'
// @param connectionfd the socket descriptor of the client
// @param response_list the list of files for the client to upload
void response_302(int connectionfd, csv_record *response_list) {
    
    char *response;                         // The '302' message
    char *list_size;                        // The size of the body of the message
    
    int length;                             // The length of the message
    
    asprintf(&list_size, "%d", get_list_size(response_list));
    
    add_status(&response, STATUS_302);      //  |----------------------|
    add_message(&response, MESSAGE_302);    //  |302 Files requested\n |
    add_key(&response, KEY_LENGTH);         //  |----------------------|
    add_value(&response, list_size);        //  |Length:value\n\n      |
    delimit_header(&response);              //  |----------------------|
    add_body(&response, response_list);     //  |Body:                 |
                                            //  |----------------------|
    length = strlen(response);
    
    // Check to see if the message sent successfully
    if (send_all(connectionfd, response, &length) == -1) {
        
        syslog(LOG_ERR, "Only sent %d bytes\n", length);
        
    } //end if
    
    free(list_size);
    free(response);
    
    list_size = NULL;
    response = NULL;
    
} //end response_302
예제 #5
0
파일: hmdp.c 프로젝트: ablochha/Resume
// Sends the HMDP request 'List'
// @param sockfd the socket descriptor of the server
// @param token the token used for verification
// @param list the list of files found in the clients hooli directory
void request_list(int sockfd, char *token, csv_record *list) {
    
    char *request;                          // The 'List' message
    char *list_size;                        // The size of the list of files and checksums
    
    int length;                             // The length of the 'List' message
    
    asprintf(&list_size, "%d", get_list_size(list));
    
    add_command(&request, COMMAND_LIST);    //  |-----------------|
    add_key(&request, KEY_TOKEN);           //  |List\n           |
    add_value(&request, token);             //  |-----------------|
    add_key(&request, KEY_LENGTH);          //  |Token:value\n    |
    add_value(&request, list_size);         //  |-----------------|
    delimit_header(&request);               //  |Length:value\n\n |
    add_body(&request, list);               //  |-----------------|
                                            //  |Body:            |
                                            //  |-----------------|
    length = strlen(request);
    
    // Check to see if the message sent successfully
    if (send_all(sockfd, request, &length) == -1) {
        
        syslog(LOG_ERR, "Only sent %d bytes\n", length);
        
    } //end if
    
    free(list_size);
    free(request);
    
    list_size = NULL;
    request = NULL;
    
} //end request_list
예제 #6
0
파일: list.c 프로젝트: mycoy/NCSU_CSC501OS
int is_l_elem_exist(list_elem le_t, list l_t){
	_list * l = NULL;
	_list_elem * le = NULL, * lp=NULL;
	void * to_find_data=NULL;
	int i, size, found=0;

	if(le_t==NULL || l_t==NULL){
#ifdef LIST_DEBUG
		printf("list_elem or list is NULL\n");
#endif
		return 0;
	}

    l = (_list*)l_t;
    le = (_list_elem*)le_t;
    to_find_data = le->data;

    size = get_list_size(l_t);
    lp = l->l_head;
    for(i=0; i< size; i++){
    	if( lp->data==to_find_data ){ /* if found */
    		found=1;
    		break;
    	}
    	lp = lp->next;
    }
    return found;
}
예제 #7
0
파일: snapshot.c 프로젝트: kolyshkin/ploop
static int get_snapshot_count(struct ploop_disk_images_data *di)
{
	int n;
	char **images;

	images = make_images_list(di, di->top_guid, 1);
	if (images == NULL)
		return -1;
	n = get_list_size(images);
	ploop_free_array(images);

	return n;
}
예제 #8
0
center::center(std::string filename, std::string key){
	isrun = true;

	boost::shared_ptr<config::config> _config = boost::make_shared<config::config>(filename);
	if (_config == nullptr){
		throw std::exception(("cannot find config file" + filename).c_str());
	}


	auto center_config = _config->get_value_dict("center");
	if (center_config == 0){
		throw std::exception("cannot find center config");
	} else{
		try{
			center_addr.first = center_config->get_value_string("ip");
			center_addr.second = (short)center_config->get_value_int("port");
		} catch(...){
			throw std::exception("center config field error");
		}
	}

	servernum = 0;

	_service = juggle::create_service();
	_process = boost::make_shared<juggle::process>();
	_channelservice = boost::make_shared<achieve::channelservice>();

	_svrsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);

	auto key_config = _config->get_value_dict("key");
	if (key_config == 0){
		throw std::exception("cannot find this config");
	} else{
		auto set = boost::make_shared<std::vector<std::pair<std::string, short> > >();
		auto dict = _config->get_value_dict("blacklist");
		for (size_t i = 0; i < dict->get_list_size(); i++){
			auto e = dict->get_list_dict(i);
			auto ip = e->get_value_string("ip");
			auto port = (short)e->get_value_int("port");
			set->push_back(std::make_pair(ip, port));
		}
		_writeacceptor = boost::make_shared<acceptor::writeacceptor>(key_config->get_value_string("ip"), key_config->get_value_int("port"), set, _channelservice, _svrsessioncontainer);
	}
	_timerservice = timer::timerservice::createinstance();

	_module = boost::make_shared<module::center>(_process);
	_module->sigregister_db.connect(boost::bind(&center::register_db, this, _1, _2));
	_module->sigregister_gate.connect(boost::bind(&center::register_gate, this, _1, _2));
	_module->sigregister_routing.connect(boost::bind(&center::register_routing, this, _1, _2));
	_module->sigregister_logic.connect(boost::bind(&center::register_logic, this, _1, _2));
}
예제 #9
0
파일: list.c 프로젝트: mycoy/NCSU_CSC501OS
list_elem del_l_elem(list_elem le_t, list l_t){
	_list * l = NULL;
	_list_elem * le = NULL, * lp1=NULL, * lp2=NULL, * to_del=NULL;
	void * to_find_data=NULL;
	int i, size, found=0;

	if(le_t==NULL || l_t==NULL){
#ifdef LIST_DEBUG
		printf("list_elem or list is NULL\n");
#endif
		return 0;
	}

    l = (_list*)l_t;
    le = (_list_elem*)le_t;
    to_find_data = le->data;

    size = get_list_size(l_t);
    lp1 = l->l_head;
    for(i=0; i< size; i++){
    	if(lp1->data == to_find_data){ /* if found */
    		to_del=lp1;
    		if(lp1==l->l_head){ /* if to_del is the head */
    			if(l->elem_number==1){ /* if only one elem in the list */
    				l->l_head = l->l_tail = NULL;
    			}else{
    				l->l_head = l->l_head->next;
    			}
    			break;
    		} else if(lp1==l->l_tail){
    			l->l_tail = lp2;
    			break;
    		}else{
    			lp2->next = lp1->next;
    			break;
    		}
    	}
    	lp2=lp1;
    	lp1 = lp1->next;
    } /* end for */

    if(to_del!=NULL){
    	to_del->next = NULL; /* cut relation with the list */
    	l->elem_number--;
    }

    return (list_elem)to_del;
}
예제 #10
0
// Adds a body to a HMDP message
// @param buffer the message so far
// @param list the linked list to be added
void add_body(char **buffer, csv_record *list) {
    
    char *previous = malloc(strlen(*buffer) + NULL_BYTE_SIZE);
    char *list_string = to_string(list);
    int newsize = strlen(*buffer) + get_list_size(list);
    
    strcpy(previous, *buffer);
    *buffer = realloc(*buffer, newsize + NULL_BYTE_SIZE);
    
    strcpy(*buffer, previous);
    strcat(*buffer, list_string);
    
    free(list_string);
    free(previous);
    
    list_string = NULL;
    previous = NULL;
    
} //end add_body
예제 #11
0
writeacceptor::writeacceptor(boost::shared_ptr<config::config> _config, boost::shared_ptr<achieve::channelservice> _chservice, boost::shared_ptr<achieve::sessioncontainer> _sc){
	acp = boost::make_shared<achieve::acceptor>(_chservice, _sc);
	
	auto ip = _config->get_value_string("ip");
	auto port = (short)_config->get_value_int("port");
	
	acp->init((char*)ip.c_str(), port);

	auto set = boost::make_shared<std::vector<std::pair<std::string, short> > >();
	auto dict = _config->get_value_dict("writelist");
	for (size_t i = 0; i < dict->get_list_size(); i++){
		auto e = dict->get_list_dict(i);
		auto ip = e->get_list_string(0);
		auto port = (short)e->get_list_int(1);
		set->push_back(std::make_pair(ip, port));
	}

	epfitle = boost::make_shared<fitle::fitle<std::pair<std::string, short> > >();

	epfitle->setfitle(
		[set](std::pair<std::string, short> ep){
			for(auto e : *set){
				if (ep.first == e.first){
					if (e.second == 0){
						return false;
					}else if (e.second == ep.second){
						return false;
					}
				}else{
					return false;
				}
			}
			return true;
		}
	);

	acp->set_fitle(epfitle);
}
예제 #12
0
gate::gate(std::string filename, std::string key){
	isrun = true;

	boost::shared_ptr<config::config> _config = boost::make_shared<config::config>(filename);

	auto center_config = _config->get_value_dict("center");
	if (center_config == 0){
		throw std::exception("cannot find center config");
	} else{
		try{
			center_addr.first = center_config->get_value_string("ip");
			center_addr.second = (short)center_config->get_value_int("port");
		} catch(...){
			throw std::exception("center config field error");
		}
	}

	auto routing_config = _config->get_value_dict("routing");
	if (routing_config == 0){
		throw std::exception("cannot find routing config");
	} else{
		try{
			auto size = routing_config->get_list_size();
			routing_server.resize(size);
			for (uint32_t i = 0; i < size; i++){
				auto cfig = routing_config->get_list_dict(i);
				routing_server[cfig->get_value_int("serial ")].first.first = cfig->get_value_string("ip");
				routing_server[cfig->get_value_int("serial ")].first.second = cfig->get_value_int("port");
				routing_server[cfig->get_value_int("serial ")].second = nullptr;
			}
		} catch (...){
			throw std::exception("routing config field error");
		}
	}

	_service = juggle::create_service();
	
	_channelservice = boost::make_shared<achieve::channelservice>();
	_rpcproxy = boost::make_shared<rpcproxy>(boost::bind(&gate::get_channel, this, _1, _2));

	_usersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _rpcproxy);
	_usersessioncontainer->sigdisconn.connect(boost::bind(&gate::user_disconn, this, _1));
	
	_process = boost::make_shared<juggle::process>();

	_logicsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_logicsessioncontainer->sigconn.connect(boost::bind(&gate::on_logic_conn, this, _1));
	_logicsessioncontainer->sigdisconn.connect(boost::bind(&gate::logic_disconn, this, _1));

	auto gate_config = _config->get_value_dict("key");
	if (gate_config == 0){
		throw std::exception("cannot find this config");
	} else{
		auto set = boost::make_shared<std::vector<std::pair<std::string, short> > >();
		auto dict = _config->get_value_dict("blacklist");
		for (size_t i = 0; i < dict->get_list_size(); i++){
			auto e = dict->get_list_dict(i);
			auto ip = e->get_value_string("ip");
			auto port = (short)e->get_value_int("port");
			set->push_back(std::make_pair(ip, port));
		}
		_blackacceptor = boost::make_shared<acceptor::blackacceptor>(gate_config->get_value_string("ip"), gate_config->get_value_int("port"), set, _channelservice, _usersessioncontainer);
		
		auto writeset = boost::make_shared<std::vector<std::pair<std::string, short> > >();
		auto writedict = _config->get_value_dict("writelist");
		for (size_t i = 0; i < dict->get_list_size(); i++){
			auto e = writedict->get_list_dict(i);
			auto ip = e->get_value_string("ip");
			auto port = (short)e->get_value_int("port");
			writeset->push_back(std::make_pair(ip, port));
		}
		_writeacceptor = boost::make_shared<acceptor::writeacceptor>(gate_config->get_value_string("clusterip"), gate_config->get_value_int("clusterport"), writeset, _channelservice, _logicsessioncontainer);
	}

	_timerservice = timer::timerservice::createinstance();
	_module = boost::make_shared<module::gate>(_process);

	_routingsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_routingconnector = boost::make_shared<connector::connector>(_channelservice, _routingsessioncontainer);

	_centersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_centerconnector = boost::make_shared<connector::connector>(_channelservice, _centersessioncontainer);
}
예제 #13
0
파일: tool.c 프로젝트: bugou/test
void print_key2(redis_instance* inst, char* key, size_t len)
{
    long long size = 0;
    int flag = get_key_type(inst, key, len);
    long long pttl = get_key_pttl(inst, key, len);
    printf("{key:%s, type:%s, pttl:%lldms, db:%lu,",
            key, type_name[flag], pttl, inst->db);
    switch (flag) {
        case KSTRING: {
            redisReply* kv = (redisReply*)redisCommand(inst->cxt, "get %b", key, len);
            assert(kv != nil);
            assert(kv->type == REDIS_REPLY_STRING);
            assert(kv->len != 0);
            pline(" value:%s}", kv->str);
            freeReplyObject(kv);
        }
        break;

        case KHASH: {
            size = get_hashtable_size(inst, key, len);
            printf(" size:%lld", size);
            if (size) {
                printf(",\n  kvs:[");
                print_hashtable2(inst, key, len);
                pline("\b \n  ]");
            }
            pline("}");
        }
        break;

        case KLIST: {
            size = get_list_size(inst, key, len);
            printf(" size:%lld", size);
            if (size) {
                printf(",\n  values:[");
                print_list(inst, key, len);
                pline("\b \n  ]");
            }
            pline("}");
        }
        break;

        case KSET: {
            size = get_set_size(inst, key, len);
            printf(" size:%lld", size);
            if (size) {
                printf(",\n  values:[");
                print_set2(inst, key, len);
                pline("\b \n  ]");
            }
            pline("}");
        }
        break;

        case KSSET: {
            size = get_sset_size(inst, key, len);
            printf(" size:%lld", size);
            if (size) {
                printf(",\n  values:[");
                print_sset2(inst, key, len);
                pline("\b \n  ]");
            }
            pline("}");
        }
        break;

        case KNONE: {
            FATAL("none type of key:%s", key);
        }
        break;

        case KUNKOWN: {
            FATAL("unknown type of key:%s", key);
        }
    }
}
예제 #14
0
파일: parse.hpp 프로젝트: e42s/libbert
std::vector<value> parse(Range &r, parse_flag_t flags, unsigned n = ~0) {
    std::vector<value> ret;
    for(; n != 0; --n) {
        type_t const t = get_type(r);
        switch(t) {
        case SMALL_INTEGER_EXT:
            ret.push_back(value(t, get_small_integer(r)));
            break;
        case INTEGER_EXT:
            ret.push_back(value(t, get_integer(r)));
            break;
        case FLOAT_EXT:
            ret.push_back(value(t, get_float(r)));
            break;
        case ATOM_EXT:
            ret.push_back(value(t, get_atom(r)));
            break;
        case SMALL_TUPLE_EXT: {
            if(flags & parse_complex) {
                // TODO
            }
            byte_t const size = get_small_tuple_size(r);
            ret.push_back(value(t, parse(r, flags, size)));
        }
        break;
        case LARGE_TUPLE_EXT: {
            if(flags & parse_complex) {
                // TODO
            }
            boost::uint32_t const size = get_large_tuple_size(r);
            ret.push_back(value(t, parse(r, flags, size)));
        }
        break;
        case NIL_EXT:
            ret.push_back(value());
            break;
        case STRING_EXT:
            ret.push_back(value(t, get_string(r)));
            break;
        case LIST_EXT: {
            // TODO handle Tail!
            boost::uint32_t const size = get_list_size(r);
            /* not optimal: collecting into a vector and then constructing a list
               from that */
            std::vector<value> tmp = parse(r, flags, size);
            ret.push_back(value(t, std::list<value>(tmp.begin(), tmp.end())));
        }
        break;
        case BINARY_EXT:
            ret.push_back(value(t, get_binary(r)));
            break;
#ifndef LIBBERT_NO_EXTENSION
        case X_NEW_FLOAT_EXT:
            ret.push_back(value(FLOAT_EXT, x_get_new_float(r)));
            break;
#endif
        default:
            throw bert_exception("unknown type");
        };
    }
    return ret;
}
예제 #15
0
gate::gate(std::string filename, std::string key){
	isrun = true;

	boost::shared_ptr<config::config> _config = boost::make_shared<config::config>(filename);

	auto center_config = _config->get_value_dict("center");
	if (center_config == 0){
		throw std::exception("cannot find center config");
	} else{
		try{
			center_addr.first = center_config->get_value_string("ip");
			center_addr.second = (short)center_config->get_value_int("port");
		} catch(...){
			throw std::exception("center config field error");
		}
	}

	auto routing_config = _config->get_value_dict("routing");
	if (routing_config == 0){
		throw std::exception("cannot find routing config");
	} else{
		try{
			auto size = routing_config->get_list_size();
			routing_server.resize(size);
			for (uint32_t i = 0; i < size; i++){
				auto cfig = routing_config->get_list_dict(i);
				routing_server[cfig->get_value_int("serial ")].first.first = cfig->get_value_string("ip");
				routing_server[cfig->get_value_int("serial ")].first.second = cfig->get_value_int("port");
				routing_server[cfig->get_value_int("serial ")].second = nullptr;
			}
		} catch (...){
			throw std::exception("routing config field error");
		}
	}

	_service = juggle::create_service();
	
	_channelservice = boost::make_shared<achieve::channelservice>();
	_rpcproxy = boost::make_shared<rpcproxy>(boost::bind(&gate::get_channel, this, _1, _2));
	_usersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _rpcproxy);
	
	_usersessioncontainer->sigdisconn.connect(boost::bind(&gate::user_disconn, this, _1));

	auto gate_config = _config->get_value_dict("key");
	if (gate_config == 0){
		throw std::exception("cannot find this config");
	} else{
		_blackacceptor = boost::make_shared<acceptor::blackacceptor>(gate_config, _channelservice, _usersessioncontainer);
	}

	_timerservice = timer::timerservice::createinstance();

	_process = boost::make_shared<juggle::process>();

	_module = boost::make_shared<module::gate>(_process);
	_module->sigregister_logic.connect(boost::bind(&gate::add_logic, this, _1, _2));

	_logicsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_logicconnector = boost::make_shared<connector::connector>(_channelservice, _logicsessioncontainer);

	_routingsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_routingconnector = boost::make_shared<connector::connector>(_channelservice, _routingsessioncontainer);

	_centersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_centerconnector = boost::make_shared<connector::connector>(_channelservice, _centersessioncontainer);
}
예제 #16
0
void debugger_story_has_been_loaded()
{
  size_t index, len;
  uint32_t *element;
  char prefix_string[] = { FIZMO_COMMAND_PREFIX, 0 };
  int flags;

  //add_breakpoint(0x200d0);
  story_has_been_loaded = true;

  if (pcs != NULL)
  {
    len = get_list_size(pcs);
    breakpoints = create_list();
    for (index=0; index<len; index++)
    {
      element = (uint32_t*)get_list_element(pcs, index);
      // TODO: Verify breakpoints.
      add_list_element(breakpoints, z_mem + *element);
      free(element);
    }
    delete_list(pcs);
    pcs = NULL;
  }

  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) 
    exit(-1);
  bzero((char *) &serv_addr, sizeof(struct sockaddr_in));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(DEBUGGER_PORT);
  inet_pton(AF_INET, DEBUGGER_IP_ADDRESS, &serv_addr.sin_addr.s_addr);
  if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) 
    exit(-1);
  listen(sockfd,5);
  clilen = sizeof(cli_addr);

  streams_latin1_output("\nPlease connect to ");
  streams_latin1_output(DEBUGGER_IP_ADDRESS);
  sprintf(buffer, ":%d", DEBUGGER_PORT);
  streams_latin1_output(buffer);
  streams_latin1_output(" to start.\n");

  while (newsockfd < 0) 
  {
    if ((newsockfd = accept(sockfd, 
          (struct sockaddr *) &cli_addr, 
          &clilen)) >= 0)
      break;
    if (errno != EINTR) 
    {
      perror("accept");
      exit(-1);
    }
  }

  flags = fcntl(newsockfd, F_GETFL, 0);
  fcntl(newsockfd, F_SETFL, flags | O_NONBLOCK);

  debugger_output(newsockfd, "\nFizmo debugger, libfizmo version ");
  debugger_output(newsockfd, LIBFIZMO_VERSION);
  debugger_output(newsockfd, ".\n");
  debugger_output(newsockfd, "Enter \"");
  debugger_output(newsockfd, prefix_string);
  debugger_output(newsockfd, "debug\" as story input to start debugging.\n\n");
}
예제 #17
0
파일: i18n.c 프로젝트: erkyrath/fizmo
static locale_module *parse_locale_file(z_ucs *module_name,
                                        char* locale_dir_name, char* module_name_utf8)
{
    char *filename;
    z_file *in;
    z_ucs *locale_data;
    locale_module *result;
    char in_char;
    long nof_zucs_chars;
    z_ucs input;
    z_ucs *linestart;
    list *lines;

    TRACE_LOG("locale_dir_name: \"%s\".\n", locale_dir_name);
    TRACE_LOG("module_name_utf8: \"%s\".\n", module_name_utf8);

    // open-resource:
    if ((filename
            = malloc(strlen(locale_dir_name) + strlen(module_name_utf8) + 2))
            == NULL)
    {
        // exit-point:
        TRACE_LOG("malloc() returned NULL.\n");
        return NULL;
    }

    TRACE_LOG("locale_dir_name: \"%s\".\n", locale_dir_name);
    TRACE_LOG("module_name_utf8: \"%s\".\n", module_name_utf8);

    strcpy(filename, locale_dir_name);
    strcat(filename, "/");
    strcat(filename, module_name_utf8);

    TRACE_LOG("Parsing locale file \"%s\".\n", filename);

    // open-resource:
    if ((in = fsi->openfile(filename, FILETYPE_DATA, FILEACCESS_READ))
            == NULL)
    {
        // exit-point:
        TRACE_LOG("openfile(\"%s\") returned NULL.\n", filename);
        free(filename);
        return NULL;
    }

    nof_zucs_chars = 0;
    while ((parse_utf8_char_from_file(in)) != UEOF)
        nof_zucs_chars++;
    nof_zucs_chars++; // Add space for terminating zero (yes, really required).

    if (fsi->setfilepos(in, 0, SEEK_SET) == -1)
    {
        // exit-point:
        TRACE_LOG("setfilepos() returned -1.\n");
        fsi->closefile(in);
        free(filename);
        return NULL;
    }

    TRACE_LOG("Allocating space for %ld z_ucs chars.\n", nof_zucs_chars);

    // open-resource:
    if ((locale_data = malloc(nof_zucs_chars * sizeof(z_ucs))) == NULL)
    {
        // exit-point:
        TRACE_LOG("malloc(%ld) returned NULL.\n", nof_zucs_chars * sizeof(z_ucs));
        fsi->closefile(in);
        free(filename);
        return NULL;
    }

    TRACE_LOG("Locale data at %p, ends at %p.\n",
              locale_data, locale_data+nof_zucs_chars);

    // open-resource:
    if ((result = malloc(sizeof(locale_module))) == NULL)
    {
        // exit-point:
        free(locale_data);
        fsi->closefile(in);
        free(filename);
        return NULL;
    }

    TRACE_LOG("New module at %p.\n", result);

    result->locale_data = locale_data;
    TRACE_LOG("Locale data starts at %p.\n", locale_data);

    /* --- */

    // open-resource:
    lines = create_list();
    //printf("new list created: %p\n", lines);

    in_char = fsi->getchar(in);
    while (in_char != EOF)
    {
        linestart = locale_data;

        // Found a new line.
        fsi->ungetchar(in_char, in);

        for (;;)
        {
            input = input_char(in);

            if (input == Z_UCS_BACKSLASH)
            {
                //*locale_data++ = input;

                input = input_char(in);

                if (input == Z_UCS_BACKSLASH)
                {
                    *locale_data++ = Z_UCS_BACKSLASH;
                }
                else if (input == 'n')
                {
                    *locale_data++ = Z_UCS_NEWLINE;
                }
                else if (input == '{')
                {
                    *locale_data++ = Z_UCS_BACKSLASH;
                    *locale_data++ = (z_ucs)'{';

                    input = input_char(in);

                    if ((input < 0x30) && (input > 0x39))
                    {
                        fprintf(stderr, "Variable number expected.\n");
                        exit(EXIT_FAILURE);
                    }

                    *locale_data++ = input;

                    input = input_char(in);

                    if (
                        (input != (z_ucs)'s')
                        &&
                        (input != (z_ucs)'d')
                        &&
                        (input != (z_ucs)'x')
                        &&
                        (input != (z_ucs)'z')
                    )
                    {
                        fprintf(stderr, "Invalid parameter type.\n");
                        exit(EXIT_FAILURE);
                    }

                    *locale_data++ = input;

                    input = input_char(in);

                    if (input != (z_ucs)'}')
                    {
                        fprintf(stderr, "Expected '}'.\n");
                        exit(EXIT_FAILURE);
                    }

                    *locale_data++ = (z_ucs)'}';
                }
                else
                {
                    fprintf(stderr, "Undefined control sequence \\%c.\n",(char)input);
                    exit(EXIT_FAILURE);
                }
            }
            else if (input == Z_UCS_NEWLINE)
            {
                *locale_data++ = 0;
                TRACE_LOG("New line at %p.\n", linestart);
                add_list_element(lines, (void*)linestart);

                //TRACE_LOG_Z_UCS(linestart);

                break;
            }
            else
            {
                // Here we've found some "normal" output.
                *locale_data++ = (z_ucs)input;
            }
        }

        //messages_processed++;
        in_char = fsi->getchar(in);
    }

    *locale_data = 0;
    TRACE_LOG("Wirte last byte at %p.\n", locale_data);

    /* --- */

    TRACE_LOG("Read %d lines.\n", get_list_size(lines));

    // close-resource(l), open-resource(result->messages):
    result->nof_messages = get_list_size(lines);
    result->messages = (z_ucs**)delete_list_and_get_ptrs(lines);

    TRACE_LOG("Messages at %p.\n", result->messages);

    TRACE_LOG("First msg at %p.\n", result->messages[0]);

    if ((result->module_name = malloc(sizeof(z_ucs) * (z_ucs_len(module_name)+1)))
            == NULL)
    {
        // exit-point:
        free(result->messages);
        free(result);
        free(locale_data);
        fsi->closefile(in);
        free(filename);
        return NULL;
    }

    z_ucs_cpy(result->module_name, module_name);

    // close-resource:
    fsi->closefile(in);

    // close-resource:
    free(filename);

    TRACE_LOG("Returning new module at %p.\n", result);

    return result;
}