Example #1
0
/*
	 Parse uri to figure out what function needs to be run,
	 and run that function with parameters 
 */
void parse_uri(int fd, char uri[MAXLINE], int param){
	// check if uri is empty, no function was supplied
	if((strcmp(uri,"/") == 0) || (strcmp(uri,"") == 0)){

		Send(fd,"No function name found.\n");
		Send(fd,"Please add function name at the end of / in url\n");

		return;
	}

	char *uri_args;
	// parse uri
	uri_args = strtok(uri,"/");
	// double check to make sure something was found
	if(strcmp(uri_args,"") == 0){
		Send(fd,"No function name found.");
	}
	else{
		// a function was found, now get the params sent to the 
		// function via json
		// figure out what function needs to be run
		if(strcmp(uri_args,"fibonacci") == 0) {
			fib(fd, param);
		}
		else if(strcmp(uri_args,"fib") == 0) {
			fib(fd, param);
		}
		else if(strcmp(uri_args,"sin") == 0) {
			sin_func(fd, param);
		}
		else if(strcmp(uri_args,"cos") == 0) {
			cos_func(fd, param);
		}
		else if(strcmp(uri_args,"tan") == 0) {
			tan_func(fd, param);
		}

		else {
			Send(fd,uri_args);
			Send(fd," function does not exist yet.\n");
		}
	}

}
Example #2
0
File: data.c Project: amumu/nokuno
static __inline data_t
rand_normal()
{
    static data_t next;
    static int dup = 0;
    data_t t, u;

    if (dup) {
        dup = 0;
        return next;
    }
    else {
        t = sigma*sqrt_func(-2.0*log_func(1.0-rand_regular()));
        u = 2.0*pi*rand_regular();

        dup = 1;
        next = m+t*sin_func(u);
        return m+t*cos_func(u);
    }
}