Exemplo n.º 1
0
// ****************************************************************
// * The main function puts everything together so that the shell *
// * can work.													  *
// ****************************************************************
int main(int argc, char **argv, char **envp) 
{
	int fd, i;
	char c;
	char *input_str = calloc(BUFFERSIZE, sizeof(char*));
	char *cmd = calloc(BUFFERSIZE, sizeof(char*));

	// ignore the standard interrupt signal (ctrl+c)
	signal(SIGINT, SIG_IGN);
	// assign interrupt signal (ctrl+c) to the signal handler function
	signal(SIGINT, sig_hdlr);

	// prepare screen and fetch necessary data
	initilize(envp);

	// main loop might be stopped by typing 'quit', 'exit' or by pressing 'ctrl+d'
	while(strcmp(input_str, QUIT_CMD) != 0 && strcmp(input_str, EXIT_CMD) != 0 && c != EOF) {
		// get input
		c = getchar();
		// this switch-case statement read and prepare the input string
		switch(c) {
			case NEWLINE_SYMBOL:
				// if no command is inserted, just print the prompt again
				if(input_str[0] != NULL_SYMBOL) {
					// erase cmd variable
					memset(cmd, 0, BUFFERSIZE);
					// parse the command line
					cmd = prepare_inputs(input_str);
					// special case: change directory call
					if(strncmp(cmd, CD, 2) == 0) {
						cd(inputs[1]);
					// all other command calls
					} else {
						get_cmd_pth(cmd);
						cmd_exec(cmd, envp);
					}
					free_arr(inputs);
				}
				// print the prompt again after hitting enter
				print_prompt();
				memset(input_str, 0, BUFFERSIZE);
				break;
			default:
				// prepare the input string
				strncat(input_str, &c, 1);
				break;
		}
	}

	// free allocated memories
	free(cmd);
	free(input_str);
	free_arr(paths);

	// print new line if 'ctrl+d' is pressed
	if(c == EOF) printf(NEWLINE_STR);

	// end of main
	return 0;
}
	/*
	 * Based on pre-processor data, matrix structure is created and data transferred
	 */
	void GeomData::initilize(pMesh theMesh, const std::set<int> &setOfDomain, int FVM){
		// number of domains stay the same no matter how many adaptations happen
		int i = 0;
		int ndom = (int)setOfDomain.size();
		int *domainList = new int[ndom];
		for(set<int>::iterator iter = setOfDomain.begin(); iter!=setOfDomain.end(); iter++){
			domainList[i++] =  *iter;
		}
		setNumDomains(ndom);
		setDomainList(domainList);
		delete[] domainList; domainList = 0;

//		if (theMesh->getDim()==2){
//			numElem = M_numFaces(theMesh);
//			elemtype = 3;
//		}
//		else{
//			numElem = M_numRegions(theMesh);
//			elemtype = 4;
//		}

		// FVM:
		// CASE 1: classical edge based Finite Volume Formulation
		// CASE 2: modified  CASE 1 (highly heterogeneous porous media)
		if (FVM==1){
			initilize(theMesh);				//every new mesh adaptation, mesh data structure changes
		}
	}
Exemplo n.º 3
0
main()
{
    initilize();

    while(1)
    {
        int id;

		// Read line from user, and get the function id from it
        GetLine();
        id = FindCommand();

        switch(id)
        {
            case 0:
                mkdir(pathname);
                break;
            case 1:
                rmdir(pathname);
                break;
            case 2:
                cd(pathname);
                break;
            case 3:
                ls();
                break;
            case 4:
                pwd();
                break;
            case 5:
                creat(pathname);
                break;
            case 6:
                rm(pathname);
                break;
            case 7:
                save();
                break;
            case 8:
                reload();
                break;
            case 9:
                menu();
                break;
            case 10:
                quit();
                break;
            default:
                printf("Command not recognized! Please try again.\n\n");
                break;
        }
    }




	return 0;
}
Exemplo n.º 4
0
Client::Client(unsigned id,unsigned usr_id, unsigned n){
	this->id = id;	this->usr_id = usr_id;	this->n = n;
	RecvCorrectCount=RecvIncorrectCount=SendCount = 0;
	initilize(conf_path);
	if (! SocketUtil::create_udp_socket(mysocket))
		print_debugInformation("创建client socket错误");
	isdebug = true;
	MUTEX_INIT(mutex_sendto);
	MUTEX_INIT(mutex_print);
}
Exemplo n.º 5
0
LoadBalancer::LoadBalancer(){
	logger = new Logger(log_path);   //日志类初始化
	ClientRecvCorrectCount=ClientRecvIncorrectCount=ClientSendCount = 0;
	ServerRecvCorrectCount=ServerRecvIncorrectCount=ServerSendCount = 0;
	initilize(conf_path);
	initilize_socket();
	MUTEX_INIT(mutex_sendto);
	MUTEX_INIT(mutex_print);
	
}
Exemplo n.º 6
0
void Controller::setup(Vec2f pos, Vec2f size)
{
    gotNewValue = true;
    controllerIsActive = false;
    mPos = pos;
    mSize = size;
    mBounding = Rectf(mPos,mPos+mSize);
    mFont.getNames();
    mFont = Font( "Helvetica", 14 );
    mTextBox = TextBox().color(Color(0,0,0)).font(mFont).size( Vec2i( 200, TextBox::GROW ) );
    initilize();
}
Exemplo n.º 7
0
int main()
{
	char command[128] = { 0 };
	clock_t flag = clock(), flagNow, flagDiff;
	
	srand((unsigned int)time(NULL));

	newMatrix(&map, HEIGHT, WIDTH);
	newMatrix(&rendered, HEIGHT, WIDTH);

	sprintf(command, "mode con:cols=%d lines=%d", 2 * WIDTH + 5, 4+HEIGHT);
	system(command);
	SetConsoleOutputCP(949);

	initilize();
	eventInitilize();

	for (;;)
	{
		do {
			flagNow = clock();
			flagDiff = ((flagNow - flag) * 1000 / CLOCKS_PER_SEC) % 10000;
			if (flagDiff > timeInterval)
			{
				eventLoop();
				flag = flagNow;
			}
		} while (!kbhit());
		eventKeyPress(getKeyInput());

		switch (state)
		{
			case INIT:
				eventGameInit();
				render(&rendered, &map);
				if(autoState)
					state = GAME;
				break;
			case GAME:
				break;
			case DEAD:
				eventGameOver();
				if(autoState)
					state = INIT;
				break;
			default:
				break;
		}
	}

}
Exemplo n.º 8
0
int main(int argc, char *argv[]) {

    GameState *state = allocate_game_state();
    get_configuration(state->config);
    initilize(state);

    DEBUG("tile size is %li\n", sizeof(Tile));
    char msg1[] = "Welcome to Kookoolegit! You are in an infinitely long "
                  "non-orientable space.  Good luck!";
    add_message(msg1);
    render_messages(&state->config->message_window);
    calculate_visible_tiles(state->map, state->map->at_location);
    state->status_message = get_player_status();
    state->need_to_redraw = 1;
    INFO("entering main loop\n");
    while (state->is_running) {
        /* This blocks, waiting for the next user input */
        INFO("******************************\n");
        DEBUG("Getting command\n");
        enum CommandCode cmd;
        cmd = get_command();
        process_command(state, cmd);
        DEBUG("state is %d\n", state->state);
        DEBUG("Redraw flag is %d\n", state->need_to_redraw);
        if (state->need_to_redraw == 1) {
            clear();
            render_messages(&state->config->message_window);
            render_map_window(state->map, state->map_graphics_state,
                              &state->config->map_window);
            render_look_message(state->status_message,
                                &state->config->status_window);
            state->need_to_redraw = 0;
            flip();
        }
    }

    cleanup(state);

    return 0;
}
Exemplo n.º 9
0
/*!
 * A generic fourth-order Runge-Kutta numerical integration engine for second 
 * order differential equations.
 * 
 * Second Derivative (eg, acceleration) = secondDeriv
 * First Derivative (eg, velocity)      = firstDeriv
 * Function (eg, position               = function
 *
 * initial values   = *_n
 * next guess       = *_n1
 *
 * One Eulers step:
 * secondDeriv = ::get from program::
 * firstDeriv_n1 = firstDeriv_n + secondDeriv*timestep
 * function_n1 = function_n + firstDeriv*timestep
 *
 * rk4firstDeriv = Guesses for the first Derivitive
 * rk4secondDeriv = Guesses for the second Derivitve
 *
 * You are not expected to understand this.
 */
state rk4(state r, float h)
{
    int i;
    double average;
    double t = r.met;
    
    // Prime the pump
    initilize(r);
     
    /* First Steps */
    evalSecondDeriv(r, t);                  //Begining
    
    for (i = 0; i < DOF; i++)
    {
        rk4firstDeriv[0][i] = firstDeriv_n[i];      //Using initial values
        rk4secondDeriv[0][i] = secondDeriv[i];
    }    
    
    /* Second Steps */
    r = updateState(r, 0, 0.5*h);           //Midpoint
    evalFirstDeriv(r, t + 0.5*h);           //Midpoint
    evalSecondDeriv(r, t + 0.5*h);          //Midpoint

    for (i = 0; i < DOF; i++)
    {
        rk4firstDeriv[1][i] = firstDeriv[i];
        rk4secondDeriv[1][i] = secondDeriv[i];
    }


    /* Third Steps */
    r = updateState(r, 1, 0.5*h);           //Midpoint
    evalFirstDeriv(r, t + 0.5*h);           //Midpoint
    evalSecondDeriv(r, t + 0.5*h);          //Midpoint

    for (i = 0; i < DOF; i++)
    {
        rk4firstDeriv[2][i] = firstDeriv[i];
        rk4secondDeriv[2][i] = secondDeriv[i];
    }


    /* Fourth Steps */
    r = updateState(r, 2, h);               //Endpoint
    evalFirstDeriv(r, t + h);               //Endpoint
    evalSecondDeriv(r, t + h);              //Endpoint
    
    for (i = 0; i < DOF; i++)
    {
        rk4firstDeriv[3][i] = firstDeriv[i];
        rk4secondDeriv[3][i] = secondDeriv[i];
    }
    
    
    /* Add it up */
    for (i = 0; i < DOF; i++)
    {
        average = rk4firstDeriv[0][i] 
                + 2*rk4firstDeriv[1][i] 
                + 2*rk4firstDeriv[2][i]
                + rk4firstDeriv[3][i];
                
        function_n1[i] = function_n[i] + (h*average)/6.0;
        
        
        average = rk4secondDeriv[0][i] 
                + 2*rk4secondDeriv[1][i] 
                + 2*rk4secondDeriv[2][i]
                + rk4secondDeriv[3][i];
                
        firstDeriv_n1[i] = firstDeriv_n[i] + (h*average)/6.0;
    }
    
    /* Update State */
    r = setFirstDeriv(r, firstDeriv_n1);
    r = setFunction(r, function_n1);
    r.a = LinearAcceleration(r, t + h);

    return r;
}
Exemplo n.º 10
0
	Bot()
	{
		initilize();
	}