Beispiel #1
0
int main(int argc, char *argv[])
{
	int c;
	char *hostname, *ethername;
	int do_temp, do_pub;
	int a_flag, d_flag, n_flag, s_flag, S_flag;
	char *I_arg;

	(progname=strrchr(argv[0],'/')) ? progname++ : (progname=argv[0]);

	a_flag= d_flag= n_flag= s_flag= S_flag= 0;
	I_arg= NULL;
	while(c= getopt(argc, argv, "adnsS?I:"), c != -1)
	{
		switch(c)
		{
		case '?':	usage();
		case 'a':	a_flag= 1; break;
		case 'd':	d_flag= 1; break;
		case 'n':	n_flag= 1; break;
		case 's':	s_flag= 1; break;
		case 'S':	S_flag= 1; break;
		case 'I':	I_arg= optarg; break;
		default:	fatal("getopt failed: '%c'", c);
		}
	}

	hostname= NULL;		/* lint */
	ethername= NULL;	/* lint */
	do_temp= do_pub= 0;	/* lint */

	if (n_flag + d_flag + s_flag + S_flag > 1)
		usage();
	if (s_flag || S_flag)
	{
		if (optind >= argc) usage();
		hostname= argv[optind++];

		if (optind >= argc) usage();
		ethername= argv[optind++];

		do_temp= do_pub= 0;
		while (optind < argc) 
		{
			if (strcasecmp(argv[optind], "temp") == 0)
			{
				do_temp= 1;
				optind++;
				continue;
			}
			if (strcasecmp(argv[optind], "pub") == 0)
			{
				do_pub= 1;
				optind++;
				continue;
			}
			usage();
		}
	}
	else if (d_flag)
	{
		if (!a_flag)
		{
			if (optind >= argc)
				usage();
			hostname= argv[optind++];
			if (optind != argc)
				usage();
		}
	}
	else if (a_flag)
	{
		if (optind != argc)
			usage();
		do_setuid= 1;
	}
	else
	{
		if (optind >= argc)
			usage();
		hostname= argv[optind++];
		if (optind != argc)
			usage();
		do_setuid= 1;
	}

	do_open(I_arg);
	if (d_flag)
	{
		if (a_flag)
			delete_all();
		else
			delete(hostname);
	}
	else if (s_flag || S_flag)
		do_set(hostname, ethername, do_temp, do_pub, S_flag);
	else if (a_flag)
		show_all(n_flag);
	else
		show_one(hostname, n_flag);
	exit(0);
}
SDLGraphicsVertexes::~SDLGraphicsVertexes()
{
    delete_all(mList);
}
Beispiel #3
0
Action::~Action()
{
    delete_all(mAnimations);
}
ImageVertexes::~ImageVertexes()
{
    delete_all(sdl);
    sdl.clear();
}
Beispiel #5
0
StaticTableModel::~StaticTableModel()
{
    delete_all(mTableModel);
}
Beispiel #6
0
StaticTableModel::~StaticTableModel()
{
    delete_all(mTableModel);
    mTableModel.clear();
}
Beispiel #7
0
void CharServerHandler::handleMessage(Net::MessageIn &msg)
{
    switch (msg.getId())
    {
            case SMSG_CHAR_LOGIN:
            {
                msg.skip(2);  // Length word
                msg.skip(20); // Unused

                delete_all(mCharacters);
                mCharacters.clear();

                // Derive number of characters from message length
                const int count = (msg.getLength() - 24) / 106;

                for (int i = 0; i < count; ++i)
                {
                    Net::Character *character = new Net::Character;
                    readPlayerData(msg, character);
                    mCharacters.push_back(character);
                    logger->log("CharServer: Player: %s (%d)",
                                character->dummy->getName().c_str(), character->slot);
                }

                Client::setState(STATE_CHAR_SELECT);
            }
            break;

        case SMSG_CHAR_LOGIN_ERROR:
            switch (msg.readInt8())
            {
                case 0:
                    errorMessage = _("Access denied. Most likely, there are "
                                     "too many players on this server.");
                    break;
                case 1:
                    errorMessage = _("Cannot use this ID.");
                    break;
                default:
                    errorMessage = _("Unknown char-server failure.");
                    break;
            }
            Client::setState(STATE_ERROR);
            break;

        case SMSG_CHAR_CREATE_SUCCEEDED:
            {
                Net::Character *character = new Net::Character;
                readPlayerData(msg, character);
                mCharacters.push_back(character);

                updateCharSelectDialog();

                // Close the character create dialog
                if (mCharCreateDialog)
                {
                    mCharCreateDialog->scheduleDelete();
                    mCharCreateDialog = 0;
                }
            }
            break;

        case SMSG_CHAR_CREATE_FAILED:
            new OkDialog(_("Error"), _("Failed to create character. Most "
                                       "likely the name is already taken."));
            if (mCharCreateDialog)
                mCharCreateDialog->unlock();
            break;

        case SMSG_CHAR_DELETE_SUCCEEDED:
            delete mSelectedCharacter;
            mCharacters.remove(mSelectedCharacter);
            mSelectedCharacter = 0;
            updateCharSelectDialog();
            unlockCharSelectDialog();
            new OkDialog(_("Info"), _("Character deleted."));
            break;

        case SMSG_CHAR_DELETE_FAILED:
            unlockCharSelectDialog();
            new OkDialog(_("Error"), _("Failed to delete character."));
            break;

        case SMSG_CHAR_MAP_INFO:
        {
            msg.skip(4); // CharID, must be the same as local_player->charID
            GameHandler *gh = static_cast<GameHandler*>(Net::getGameHandler());
            gh->setMap(msg.readString(16));
            mapServer.hostname = ipToString(msg.readInt32());
            mapServer.port = msg.readInt16();

            local_player = mSelectedCharacter->dummy;
            PlayerInfo::setBackend(mSelectedCharacter->data);

            // Prevent the selected local player from being deleted
            mSelectedCharacter->dummy = 0;

            delete_all(mCharacters);
            mCharacters.clear();
            updateCharSelectDialog();

            mNetwork->disconnect();
            Client::setState(STATE_CONNECT_GAME);
        }
        break;

        case SMSG_CHANGE_MAP_SERVER:
        {
            GameHandler *gh = static_cast<GameHandler*>(Net::getGameHandler());
            gh->setMap(msg.readString(16));
            int x = msg.readInt16();
            int y = msg.readInt16();
            mapServer.hostname = ipToString(msg.readInt32());
            mapServer.port = msg.readInt16();

            mNetwork->disconnect();
            Client::setState(STATE_CHANGE_MAP);
            Map *map = local_player->getMap();
            const int tileWidth = map->getTileWidth();
            const int tileHeight = map->getTileHeight();
            local_player->setPosition(Vector(x * tileWidth + tileWidth / 2,
                                            y * tileHeight + tileHeight / 2));
            local_player->setMap(0);
        }
        break;
    }
}
Beispiel #8
0
void FloorItemManager::clear()
{
    delete_all(mFloorItems);
    mFloorItems.clear();
}
void CharServerHandler::handleMessage(Net::MessageIn &msg)
{
    switch (msg.getId())
    {
        case SMSG_CHAR_LOGIN:
            processCharLogin(msg);
            break;

        case SMSG_CHAR_LOGIN_ERROR:
            processCharLoginError(msg);
            break;

        case SMSG_CHAR_CREATE_SUCCEEDED:
            processCharCreate(msg, false);
            break;

        case SMSG_CHAR_CREATE_SUCCEEDED2:
            processCharCreate(msg, true);
            break;

        case SMSG_CHAR_CREATE_FAILED:
            processCharCreateFailed(msg);
            break;

        case SMSG_CHAR_DELETE_SUCCEEDED:
            processCharDelete(msg);
            break;

        case SMSG_CHAR_DELETE_FAILED:
            processCharDeleteFailed(msg);
            break;

        case SMSG_CHAR_MAP_INFO:
        {
//            msg.skip(4); // CharID, must be the same as player_node->charID
            PlayerInfo::setCharId(msg.readInt32());
            GameHandler *gh = static_cast<GameHandler*>(Net::getGameHandler());
            gh->setMap(msg.readString(16));
            if (config.getBoolValue("usePersistentIP"))
            {
                msg.readInt32();
                mapServer.hostname = Client::getServerName();
            }
            else
            {
                mapServer.hostname = ipToString(msg.readInt32());
            }
            mapServer.port = msg.readInt16();

            // Prevent the selected local player from being deleted
            player_node = mSelectedCharacter->dummy;
            PlayerInfo::setBackend(mSelectedCharacter->data);

            mSelectedCharacter->dummy = nullptr;

            delete_all(mCharacters);
            mCharacters.clear();
            updateCharSelectDialog();

            if (mNetwork)
                mNetwork->disconnect();
            Client::setState(STATE_CONNECT_GAME);
        }
        break;

        case SMSG_CHANGE_MAP_SERVER:
        {
            GameHandler *gh = static_cast<GameHandler*>(Net::getGameHandler());
            if (!gh || !mNetwork)
                return;
            gh->setMap(msg.readString(16));
            int x = msg.readInt16();
            int y = msg.readInt16();
            mapServer.hostname = ipToString(msg.readInt32());
            mapServer.port = msg.readInt16();

            mNetwork->disconnect();
            Client::setState(STATE_CHANGE_MAP);
            if (player_node)
            {
                player_node->setTileCoords(x, y);
                player_node->setMap(nullptr);
            }
        }
        break;

        default:
            break;
    }
}
Beispiel #10
0
void LoginHandler::clearWorlds()
{
    delete_all(LoginRecv::mWorlds);
    LoginRecv::mWorlds.clear();
}
Beispiel #11
0
LoginHandler::~LoginHandler()
{
    delete_all(LoginRecv::mWorlds);
}
Beispiel #12
0
Order::~Order(){
  delete_all( parameters );
}
Beispiel #13
0
ChannelManager::~ChannelManager()
{
    delete_all(mChannels);
    mChannels.clear();
}
Beispiel #14
0
void Matcher::reset_occurrences()
{
    delete_all(_occ);
    _occ.clear();
}
Beispiel #15
0
Labels::~Labels()
{
	delete_all();
}
Beispiel #16
0
int main(){

    /*
    // Linked list de un arreglo de 10 elementos

    struct node_t arr[10];
    printf("PREV: %x %x %x \n", &arr[0], &arr[1], &arr[2]);

    int i;
    for(i=0; i<10; i++){
        arr[i].next = &arr[i+1];
        printf("addr %d :  0x%p == 0x%p \n", i, &arr[i], arr[i].next);
    } // Hasta ahora el arr[9].next tiene basura


    */


    int menu;
    do{
        printf("Menu:\n");
        printf("1) Create Linked List\n");
        printf("2) Display\n");
        printf("3) Select Node\n");
        printf("4) Insert Node\n");
        printf("5) Remove Node\n");
        printf("6) Delete All Nodes\n");
        printf("0) Exit\n");
        printf("> ");
        scanf("%d", &menu);

        // 1) Create Linked List
        if(menu == 1){
            printf(" create \n");
            create_list();
        }
        // 2) Display
        else if(menu == 2){
            printf(" display \n");
            if(display_list()){ // if it returns a 1, it failed.
                printf("Error: List is empty \n");
            }
        }
        // 3) Select Node
        else if(menu == 3){
            printf(" sel \n");
            int selection;
            printf("Select Node [0:N-1]: ");
            scanf("%d", &selection);
            select_node(selection);

        }
        // 4) Insert Node
        else if(menu == 4){
            printf(" insert \n");
            int selection;
            printf("Insert Node [0:N-1]: ");
            scanf("%d", &selection);
            struct node_t *insert  = (struct node_t*)malloc( sizeof(struct node_t) );
            printf("Dato a insertar: ");
            scanf("%d", &(*insert).data );

            insert_node(selection, insert);
        }

        // 5) Remove Node
        else if(menu == 5){
            printf(" remove \n");
            int selection;
            printf("Remove Node [0:N-1]: ");
            scanf("%d", &selection);
            remove_node(selection);
        }

        // 6) Delete All Nodes
        else if(menu == 6){
            printf(" del all \n");
            delete_all();
        }

    } while(menu != 0);



    /*
    (*ptr_aux).data = (int)N;
    printf("%d", (*ptr_aux).data);
    */


  /*
  // Linked list con selector

    int N;
    struct node_t *head  = (struct node_t*)malloc( sizeof(struct node_t) );
    printf("Dame N: ");
    scanf("%d", &N);

    struct node_t *ptr_aux = head;

    printf("size of struct %d \n", sizeof(struct node_t) );
    printf("head: %p aux: %p \n", head, ptr_aux);


    int i;
    for(i=0; i<N; i++){
        printf("Dato: ");
        scanf("%d", &(*ptr_aux).data );

        printf("Addr: %p  , Data: %d , ", ptr_aux, (int)(*ptr_aux).data);

        (*ptr_aux).next = (struct node_t*)malloc(sizeof(struct node_t));

        printf("Next: %x\n", (*ptr_aux).next );
        ptr_aux = (*ptr_aux).next;
    }

    int sel=0;
    do{
        ptr_aux = head;
        printf("Selecciona un dato por posicion [0:N-1]: ");
        scanf("%d", &sel);

        int j;
        for(j=0; j<N; j++){

            if(j == sel){
                printf("Dato que buscas: %d, addr %p \n ", (int)(*ptr_aux).data, ptr_aux);
                j=N;

            }
            ptr_aux = (*ptr_aux).next;
        }
    }while(sel < N && sel >= 0);

*/
    printf("head: %p \n", head);
    return 0;
}
Beispiel #17
0
void CharServerHandler::clear() const
{
    delete_all(mCharacters);
    mCharacters.clear();
}
Beispiel #18
0
int main(int argc, char **argv) {
	setlocale(LC_ALL, ""); // Comment-out on non-Posix systems
	clock_t time_start = clock();
	time_t time_t_start;
	time(&time_t_start);
	argv_0_basename = basename(argv[0]);
	get_usage_string(usage, USAGE_LEN); // This is a big scary string, so build it elsewhere

	//printf("sizeof(cmd_args)=%zd\n", sizeof(cmd_args));
	parse_cmd_args(argc, argv, usage, &cmd_args);

	if (cmd_args.class_algo == EXCHANGE || cmd_args.class_algo == EXCHANGE_BROWN)
		memusage += sizeof(float) * ENTROPY_TERMS_MAX; // We'll build the precomputed entropy terms after reporting memusage

	struct_model_metadata global_metadata;

	// The list of unique words should always include <s>, unknown word, and </s>
	map_update_count(&word_map, UNKNOWN_WORD, 0, 0); // Should always be first
	map_update_count(&word_map, "<s>", 0, 1);
	map_update_count(&word_map, "</s>", 0, 2);

	// Open input
	FILE *in_train_file = stdin;
	if (in_train_file_string)
		in_train_file = fopen(in_train_file_string, "r");
	if (in_train_file == NULL) {
		fprintf(stderr, "%s: Error: Unable to open input file  %s\n", argv_0_basename, in_train_file_string); fflush(stderr);
		exit(15);
	}

	// Process input sentences
	size_t input_memusage = 0;
	const struct_model_metadata input_model_metadata = process_input(cmd_args, in_train_file, &word_map, &initial_bigram_map, &input_memusage);
	memusage += input_memusage;
	fclose(in_train_file);

	clock_t time_input_processed = clock();
	if (cmd_args.verbose >= -1)
		fprintf(stderr, "%s: Corpus processed in %'.2f CPU secs. %'lu lines, %'u types, %'lu tokens, current memusage: %'.1fMB\n", argv_0_basename, (double)(time_input_processed - time_start)/CLOCKS_PER_SEC, input_model_metadata.line_count, input_model_metadata.type_count, input_model_metadata.token_count, (double)memusage / 1048576); fflush(stderr);

	global_metadata.token_count = input_model_metadata.token_count;
	global_metadata.type_count  = map_count(&word_map);

	// Filter out infrequent words, reassign word_id's, and build a mapping from old word_id's to new word_id's
	sort_by_count(&word_map);
	word_id_t * restrict word_id_remap = calloc(sizeof(word_id_t), input_model_metadata.type_count);
	get_ids(&word_map, word_id_remap);
	word_id_t number_of_deleted_words = filter_infrequent_words(cmd_args, &global_metadata, &word_map, word_id_remap);

	// Get list of unique words
	char * * restrict word_list = (char **)malloc(sizeof(char*) * global_metadata.type_count);
	memusage += sizeof(char*) * global_metadata.type_count;
	reassign_word_ids(&word_map, word_list, word_id_remap);
	get_keys(&word_map, word_list);
	sort_by_id(&word_map);


	// Check or set number of classes
	if (cmd_args.num_classes >= global_metadata.type_count) { // User manually set number of classes is too low
		fprintf(stderr, "%s: Error: Number of classes (%u) is not less than vocabulary size (%u).  Decrease the value of --classes\n", argv_0_basename, cmd_args.num_classes, global_metadata.type_count); fflush(stderr);
		exit(3);
	} else if (cmd_args.num_classes == 0) { // User did not manually set number of classes at all
		cmd_args.num_classes = (wclass_t) (sqrt(global_metadata.type_count) * 1.2);
	}

	// Build array of word_counts
	word_count_t * restrict word_counts = malloc(sizeof(word_count_t) * global_metadata.type_count);
	memusage += sizeof(word_count_t) * global_metadata.type_count;
	build_word_count_array(&word_map, word_list, word_counts, global_metadata.type_count);

	// Initialize clusters, and possibly read-in external class file
	wclass_t * restrict word2class = malloc(sizeof(wclass_t) * global_metadata.type_count);
	memusage += sizeof(wclass_t) * global_metadata.type_count;
	init_clusters(cmd_args, global_metadata.type_count, word2class, word_counts, word_list);
	if (initial_class_file != NULL)
		import_class_file(&word_map, word2class, initial_class_file, cmd_args.num_classes); // Overwrite subset of word mappings, from user-provided initial_class_file

	// Remap word_id's in initial_bigram_map
	remap_and_rev_bigram_map(&initial_bigram_map, &new_bigram_map, &new_bigram_map_rev, word_id_remap, map_find_id(&word_map, UNKNOWN_WORD, -1));
	global_metadata.start_sent_id = map_find_id(&word_map, "<s>", -1);; // need this for tallying emission probs
	global_metadata.end_sent_id   = map_find_id(&word_map, "</s>", -1);; // need this for tallying emission probs
	global_metadata.line_count    = map_find_count(&word_map, "</s>"); // Used for calculating perplexity

	if (global_metadata.line_count == 0) {
		fprintf(stderr, "%s: Warning: Number of lines is 0.  Include <s> and </s> in your ngram counts, or perplexity values will be unreliable.\n", argv_0_basename); fflush(stderr);
	}

	//printf("init_bigram_map hash_count=%u\n", HASH_COUNT(initial_bigram_map)); fflush(stdout);
	//printf("new_bigram_map hash_count=%u\n", HASH_COUNT(new_bigram_map)); fflush(stdout);
	free(word_id_remap);
	memusage -= sizeof(word_id_t) * input_model_metadata.type_count;
	delete_all(&word_map); // static
	delete_all_bigram(&initial_bigram_map); // static
	memusage -= input_memusage;

	// Initialize and set word bigram listing
	clock_t time_bigram_start = clock();
	size_t bigram_memusage = 0; size_t bigram_rev_memusage = 0;
	struct_word_bigram_entry * restrict word_bigrams = NULL;
	struct_word_bigram_entry * restrict word_bigrams_rev = NULL;

	if (cmd_args.verbose >= -1)
		fprintf(stderr, "%s: Word bigram listing ... ", argv_0_basename); fflush(stderr);

	#pragma omp parallel sections // Both bigram listing and reverse bigram listing can be done in parallel
	{
		#pragma omp section
		{
			//sort_bigrams(&new_bigram_map); // speeds things up later
			word_bigrams = calloc(global_metadata.type_count, sizeof(struct_word_bigram_entry));
			memusage += sizeof(struct_word_bigram_entry) * global_metadata.type_count;
			bigram_memusage = set_bigram_counts(word_bigrams, new_bigram_map);
			// Copy entries in word_counts to struct_word_bigram_entry.headword_count since that struct entry is already loaded when clustering
			for (word_id_t word = 0; word < global_metadata.type_count; word++)
				word_bigrams[word].headword_count = word_counts[word];
		}

		// Initialize and set *reverse* word bigram listing
		#pragma omp section
		{
			if (cmd_args.rev_alternate) { // Don't bother building this if it won't be used
				//sort_bigrams(&new_bigram_map_rev); // speeds things up later
				word_bigrams_rev = calloc(global_metadata.type_count, sizeof(struct_word_bigram_entry));
				memusage += sizeof(struct_word_bigram_entry) * global_metadata.type_count;
				bigram_rev_memusage = set_bigram_counts(word_bigrams_rev, new_bigram_map_rev);
				// Copy entries in word_counts to struct_word_bigram_entry.headword_count since that struct entry is already loaded when clustering
				for (word_id_t word = 0; word < global_metadata.type_count; word++)
					word_bigrams_rev[word].headword_count = word_counts[word];
			}
		}
	}

	delete_all_bigram(&new_bigram_map);
	delete_all_bigram(&new_bigram_map_rev);
	memusage += bigram_memusage + bigram_rev_memusage;
	clock_t time_bigram_end = clock();
	if (cmd_args.verbose >= -1)
		fprintf(stderr, "in %'.2f CPU secs.  Bigram memusage: %'.1f MB\n", (double)(time_bigram_end - time_bigram_start)/CLOCKS_PER_SEC, (bigram_memusage + bigram_rev_memusage)/(double)1048576); fflush(stderr);

	//print_word_bigrams(global_metadata, word_bigrams, word_list);

	// Build <v,c> counts, which consists of a word followed by a given class
	word_class_count_t * restrict word_class_counts = calloc(1 + cmd_args.num_classes * global_metadata.type_count , sizeof(word_class_count_t));
	if (word_class_counts == NULL) {
		fprintf(stderr,  "%s: Error: Unable to allocate enough memory for <v,c>.  %'.1f MB needed.  Maybe increase --min-count\n", argv_0_basename, ((cmd_args.num_classes * global_metadata.type_count * sizeof(word_class_count_t)) / (double)1048576 )); fflush(stderr);
		exit(13);
	}
	memusage += cmd_args.num_classes * global_metadata.type_count * sizeof(word_class_count_t);
	fprintf(stderr, "%s: Allocating %'.1f MB for word_class_counts: num_classes=%u x type_count=%u x sizeof(w-cl-count_t)=%zu\n", argv_0_basename, (double)(cmd_args.num_classes * global_metadata.type_count * sizeof(word_class_count_t)) / 1048576 , cmd_args.num_classes, global_metadata.type_count, sizeof(word_class_count_t)); fflush(stderr);
	build_word_class_counts(cmd_args, word_class_counts, word2class, word_bigrams, global_metadata.type_count/*, word_list*/);
	//print_word_class_counts(cmd_args, global_metadata, word_class_counts);

	// Build reverse: <c,v> counts: class followed by word.  This and the normal one are both pretty fast, so no need to parallelize this
	word_class_count_t * restrict word_class_rev_counts = NULL;
	if (cmd_args.rev_alternate) { // Don't bother building this if it won't be used
		word_class_rev_counts = calloc(1 + cmd_args.num_classes * global_metadata.type_count , sizeof(word_class_count_t));
		if (word_class_rev_counts == NULL) {
			fprintf(stderr,  "%s: Warning: Unable to allocate enough memory for <v,c>.  %'.1f MB needed.  Falling back to --rev-alternate 0\n", argv_0_basename, ((cmd_args.num_classes * global_metadata.type_count * sizeof(word_class_count_t)) / (double)1048576 )); fflush(stderr);
			cmd_args.rev_alternate = 0;
		} else {
			memusage += cmd_args.num_classes * global_metadata.type_count * sizeof(word_class_count_t);
			fprintf(stderr, "%s: Allocating %'.1f MB for word_class_rev_counts: num_classes=%u x type_count=%u x sizeof(w-cl-count_t)=%zu\n", argv_0_basename, (double)(cmd_args.num_classes * global_metadata.type_count * sizeof(word_class_count_t)) / 1048576 , cmd_args.num_classes, global_metadata.type_count, sizeof(word_class_count_t)); fflush(stderr);
			build_word_class_counts(cmd_args, word_class_rev_counts, word2class, word_bigrams_rev, global_metadata.type_count/*, word_list*/);
		}

	}

	// Calculate memusage for count_arrays
	for (unsigned char i = 1; i <= cmd_args.max_array; i++) {
		memusage += 2 * (powi(cmd_args.num_classes, i) * sizeof(wclass_count_t));
		//printf("11 memusage += %zu (now=%zu) count_arrays\n", 2 * (powi(cmd_args.num_classes, i) * sizeof(wclass_count_t)), memusage); fflush(stdout);
	}

	clock_t time_model_built = clock();
	if (cmd_args.verbose >= -1)
		fprintf(stderr, "%s: Finished loading %'lu tokens and %'u types (%'u filtered) from %'lu lines in %'.2f CPU secs\n", argv_0_basename, global_metadata.token_count, global_metadata.type_count, number_of_deleted_words, global_metadata.line_count, (double)(time_model_built - time_start)/CLOCKS_PER_SEC); fflush(stderr);
	if (cmd_args.verbose >= -1)
		fprintf(stderr, "%s: Approximate memory usage at clustering: %'.1fMB\n", argv_0_basename, (double)memusage / 1048576); fflush(stderr);

	cluster(cmd_args, global_metadata, word_counts, word_list, word2class, word_bigrams, word_bigrams_rev, word_class_counts, word_class_rev_counts);

	// Now print the final word2class mapping
	if (cmd_args.verbose >= 0) {
		FILE *out_file = stdout;
		if (out_file_string)
			out_file = fopen(out_file_string, "w");
		if (out_file == NULL) {
			fprintf(stderr, "%s: Error: Unable to open output file  %s\n", argv_0_basename, out_file_string); fflush(stderr);
			exit(16);
		}
		if (cmd_args.class_algo == EXCHANGE && (!cmd_args.print_word_vectors)) {
			print_words_and_classes(out_file, global_metadata.type_count, word_list, word_counts, word2class, (int)cmd_args.class_offset, cmd_args.print_freqs);
		} else if (cmd_args.class_algo == EXCHANGE && cmd_args.print_word_vectors) {
			print_words_and_vectors(out_file, cmd_args, global_metadata, word_list, word2class, word_bigrams, word_bigrams_rev, word_class_counts, word_class_rev_counts);
		}
		fclose(out_file);
	}

	clock_t time_clustered = clock();
	time_t time_t_end;
	time(&time_t_end);
	double time_secs_total = difftime(time_t_end, time_t_start);
	if (cmd_args.verbose >= -1)
		fprintf(stderr, "%s: Finished clustering in %'.2f CPU seconds.  Total wall clock time was about %lim %lis\n", argv_0_basename, (double)(time_clustered - time_model_built)/CLOCKS_PER_SEC, (long)time_secs_total/60, ((long)time_secs_total % 60)  );

	free(word2class);
	free(word_bigrams);
	free(word_list);
	free(word_counts);
	exit(0);
}
Beispiel #19
0
Setup::~Setup()
{
    delete_all(mTabs);
}
void SkillDialog::loadSkills(const std::string &file)
{
    // TODO: mTabs->clear();
    while (mTabs->getSelectedTabIndex() != -1)
    {
        mTabs->removeTabWithIndex(mTabs->getSelectedTabIndex());
    }

    for (SkillMap::iterator it = mSkills.begin(); it != mSkills.end();  it++)
    {
        delete (*it).second->display;
    }
    delete_all(mSkills);
    mSkills.clear();

    if (file.length() == 0)
        return;

    XML::Document doc(file);
    xmlNodePtr root = doc.rootNode();

    if (!root || !xmlStrEqual(root->name, BAD_CAST "skills"))
    {
        logger->log("Error loading skills file: %s", file.c_str());
        return;
    }

    int setCount = 0;
    std::string setName;
    ScrollArea *scroll;
    VertContainer *container;

    for_each_xml_child_node(set, root)
    {
        if (xmlStrEqual(set->name, BAD_CAST "set"))
        {
            setCount++;
            setName = XML::getProperty(set, "name", strprintf(_("Skill Set %d"), setCount));

            container = new VertContainer(32);
            container->setOpaque(false);
            scroll = new ScrollArea(container);
            scroll->setOpaque(false);
            scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
            scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);

            mTabs->addTab(setName, scroll);
            for_each_xml_child_node(node, set)
            {
                if (xmlStrEqual(node->name, BAD_CAST "skill"))
                {
                    int id = atoi(XML::getProperty(node, "id", "-1").c_str());
                    std::string name = XML::getProperty(node, "name", strprintf(_("Skill %d"), id));
                    std::string icon = XML::getProperty(node, "icon", "");

                    SkillInfo *skill = new SkillInfo;
                    skill->id = id;
                    skill->name = name;
                    skill->icon = icon;
                    skill->modifiable = 0;
                    skill->display = new SkillEntry(skill);

                    container->add(skill->display);

                    mSkills[id] = skill;
                }
            }
        }
    }
Beispiel #21
0
int make_daemon ()
{
    FILE *fp= NULL;
    FILE *fp_pid= NULL;
    pid_t process_id = 0;
    pid_t sid = 0;
    process_id = fork();
    if (process_id < 0) {
        printf("fork failed!\n");
        // Return failure in exit status
        exit(1);
    }
    // PARENT PROCESS. Need to kill it.
    if (process_id > 0) {

        // Should moved to better place
        fp_pid = fopen ("/tmp/clepsydrad.pid", "w+");
        fprintf (fp_pid, "%d\n", process_id);
        fflush(fp_pid);
        fclose (fp_pid);

        printf("process_id of daemon process %d \n", process_id);
        // return success in exit status
        exit(0);
    }

    umask(0);
    sid = setsid();
    if(sid < 0)  {
        exit(1);
    }

    // Change the current working directory to root.
    chdir("/tmp");

    // Close stdin. stdout and stderr
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);

    fp = fopen ("/tmp/clepsydrad.log", "w+");

    char *p = NULL;
    int countToDie = 0;
    while (1)
    {
       //Dont block context switches, let the process sleep for some time
       sleep(1);
       // Temp code to cleanly die this process
       countToDie ++;
       if (countToDie > 15 )  {
           break;
       } else {
           // int pm = checkPamUser ();
           //fprintf(fp, " pam user check ... %d\n",  pm);
           int loggedC = getLoggedusers (fp);
           fprintf(fp, " pam cnt of logged users... %d\n",  loggedC);
           fflush(fp);
       }
       // Implement and call some function that does core work for this daemon.
    }
    fflush(fp);
    fprintf(fp, " First user in list is .. [%s] \n", getUserName (0));
    fprintf(fp, " pam check status  .. [%d] \n", checkPamUser(getUserName (0)));
    fprintf(fp, "list contains [%d] count of items...\n", list_count());
    delete_all (); // delete list
    fprintf(fp, "Quit clepsydrad, bye !...\n");
    fclose(fp);

    // remove pid file
    remove ("/tmp/clepsydrad.pid");
    return (0);

}
Beispiel #22
0
void LoginHandler::clearWorlds()
{
    delete_all(mWorlds);
    mWorlds.clear();
}
Beispiel #23
0
ImageSet::~ImageSet()
{
    delete_all(mImages);
}
Beispiel #24
0
LoginHandler::~LoginHandler()
{
    delete_all(mWorlds);
}
void GraphicsVertexes::clearSDL()
{
    delete_all(sdl[mPtr].mList);
    sdl[mPtr].mList.clear();
}
Beispiel #26
0
void GuiTable::uninstallActionListeners()
{
    delete_all(mActionListeners);
    mActionListeners.clear();
}
Beispiel #27
0
void ShopItems::clear()
{
    delete_all(mShopItems);
    mShopItems.clear();
}
Beispiel #28
0
SpellManager::~SpellManager()
{
    delete_all(mSpells);
    mSpells.clear();
    mSpellsVector.clear();
}
Beispiel #29
0
int main(){
int nr=3, em=0, stack_nr=0, i;
	struct node root, *temp;
	char let, what,no; 
	double number;
	void *v;
	double p;
	struct stack m_stack; 
	
	m_stack.next=NULL;
	m_stack.value=NULL; 
	root.next=NULL;
	root.father=NULL;
	root.name=NULL;
	root.prev=NULL;
print_help();
	
	while(1){
		scanf("%c", &let);
		if(let=='A'){
			em=0;
			scanf("%c%c", &no, &what);
			if(what=='I'){
				scanf("%d %d",&nr, &em);
				add(&root, what, nr, em, 0);
			}
			if(what=='D'){
				scanf("%lf %d",&number, &em);
				add(&root, what, &number, em, 0);			
			}
			if(what=='S'){
				scanf("%d", &stack_nr);
				add(&root, what, &m_stack, 1, stack_nr);
			}
			if(what=='C'){
					char *mes=(char*)malloc(sizeof(char)*20);
					scanf("%s", mes);
					scanf("%d", &em);
					add(&root, what, mes, em, 0);
			}
		} else if(let=='D'){
			em=0;
			scanf("%c%c", &no, &what);
			if(what=='I'){
				scanf("%d %d",&nr, &em);
				delete_all(&root, what, nr, em, 0);
			}
			if(what=='D'){
				scanf("%lf %d",&number, &em);
				delete_all(&root, what, &number, em, 0);			
			}
			if(what=='S'){
				scanf("%d", &stack_nr);
				delete_all(&root, what, &m_stack, 1, stack_nr);
			}
			if(what=='C'){
					char *mes=(char*)malloc(sizeof(char)*20);
					scanf("%s", mes);
					scanf("%d", &em);
					delete_all(&root, what, mes, em, 0);
					free(mes);
			}
			
		} else if(let=='P'){
			scanf("%c%c",&no, &what);
			if(what=='I'){
				scanf("%d",&nr);
				temp=prev(&root, what, nr,0);
				if(temp!=NULL)
				print_node(*temp);
			}
			if(what=='D'){
				scanf("%lf",&number);
				temp=prev(&root, what, &number,0);	
				if(temp!=NULL)
				print_node(*temp);
			}
			if(what=='S'){
				scanf("%d", &stack_nr);
				temp=prev(&root, what, 1,stack_nr);
				if(temp!=NULL)
				print_node(*temp);
			}
			if(what=='C'){
					char *mes=(char*)malloc(sizeof(char)*20);
					scanf("%s", mes);
					temp=prev(&root,what, mes,0);
					if(temp!=NULL)
					print_node(*temp);
					free(mes);
			}
		} else if(let=='N'){
			scanf("%c%c",&no, &what);
			if(what=='I'){
				scanf("%d",&nr);
				temp=next(&root, what, nr,0);
				if(temp!=NULL)
				print_node(*temp);
			}
			if(what=='D'){
				scanf("%lf",&number);
				temp=next(&root, what, &number,0);
				if(temp!=NULL)
				print_node(*temp);
			}
			if(what=='S'){
				scanf("%d", &stack_nr);
				temp=next(&root, what, 1,stack_nr);
				if(temp!=NULL)
				print_node(*temp);
			}
			if(what=='C'){
					char *mes=(char*)malloc(sizeof(char)*20);
					scanf("%s", mes);
					temp=next(&root,what, mes,0);
					if(temp!=NULL)
					print_node(*temp);
					free(mes);
			}
			printf("next");
		} else if(let=='B'){
			scanf_s("%d%d%d",&nr, &em, &stack_nr);
			for(i=0; i<em; i++)
				stack_push(&root, nr, stack_nr);
		} else if(let=='C'){
			scanf_s("%d%d", &em, &stack_nr);
			for(i=0; i<em; i++)
				stack_pop(&root, stack_nr);
		} else if(let=='S'){
			print_all(root);
			printf("\n");
		} else if(let=='H'){
			print_help();
		} else if(let=='Q'){
			break;
		}	
	}
	return 0;
}
Beispiel #30
0
Lista::~Lista() {
#ifdef DEBUG
	printf("Elimina lista\n");
#endif
	delete_all(_first);
}