예제 #1
0
static int parse_fb_params(char *params, int *flags, const char **fb)
{
    char *param;

    if (!params)
        return 0;

    do {
        param = params;
        params = next_param(params);

        if (!strcasecmp(param, "no_shadow")) {
            *flags &= ~GP_FB_SHADOW;
            GP_DEBUG(1, "Shadow framebuffer disabled");
            continue;
        }

        if (!strcasecmp(param, "new_console")) {
            *flags |= GP_FB_ALLOC_CON;
            GP_DEBUG(1, "Console allocation enabled");
            continue;
        }

        *fb = param;

        if (strncmp(*fb, "/dev/", 5))
            GP_WARN("Console dev set to '%s', are you sure?", *fb);

        GP_DEBUG(1, "Framebuffer console set to '%s'", *fb);

    } while (params);

    return 0;
}
예제 #2
0
void dd (header *hd)
{	header *st=hd,*hd1,*result;
	int c1,c2,i,j,r;
	double *m1,*m2,*mr;
	complex *mc1,*mc2,*mcr,hc1,hc2;
	interval *mi1,*mi2,*mir,hi1,hi2;
	hd1=next_param(st);
	equal_params_2(&hd,&hd1); if (error) return;
	getmatrix(hd,&r,&c1,&m1); if (r!=1) wrong_arg();
	getmatrix(hd1,&r,&c2,&m2); if (r!=1) wrong_arg();
	if (c1!=c2) wrong_arg();
	if (iscomplex(hd)) /* complex values */
	{	mc1=(complex *)m1; mc2=(complex *)m2;
		result=new_cmatrix(1,c1,""); if (error) return;
		mcr=(complex *)matrixof(result);
		memmove((char *)mcr,(char *)mc2,c1*sizeof(complex));
		for (i=1; i<c1; i++)
		{	for (j=c1-1; j>=i; j--)
			{	if (mc1[j][0]==mc1[j-i][0] &&
					mc1[j][1]==mc1[j-i][1]) wrong_arg();
				c_sub(mcr[j],mcr[j-1],hc1);
				c_sub(mc1[j],mc1[j-i],hc2);
				c_div(hc1,hc2,mcr[j]);
			}
		}
	}
	else if (isinterval(hd)) /* complex values */
	{	mi1=(complex *)m1; mi2=(complex *)m2;
		result=new_imatrix(1,c1,""); if (error) return;
		mir=(interval *)matrixof(result);
		memmove((char *)mir,(char *)mi2,c1*sizeof(interval));
		for (i=1; i<c1; i++)
		{	for (j=c1-1; j>=i; j--)
			{	i_sub(mir[j],mir[j-1],hi1);
				if (hi1[0]<=0 && hi1[1]>=0)
				{	output("Interval points coincide\n");
					error=1; return;
				}
				i_sub(mi1[j],mi1[j-i],hi2);
				i_div(hi1,hi2,mir[j]);
			}
		}
	}
	else if (isreal(hd))
	{	result=new_matrix(1,c1,""); if (error) return;
		mr=matrixof(result);
		memmove((char *)mr,(char *)m2,c1*sizeof(double));
		for (i=1; i<c1; i++)
		{	for (j=c1-1; j>=i; j--)
			{	if (m1[j]==m1[j-i]) wrong_arg();
				mr[j]=(mr[j]-mr[j-1])/(m1[j]-m1[j-i]);
			}
		}	
	}
	else wrong_arg();
	moveresult(st,result);
}
예제 #3
0
void polymult (header *hd)
{	header *st=hd,*hd1,*result;
	int c,c1,c2,i,r,j,k;
	double *m1,*m2,*mr,x;
	complex *mc1,*mc2,*mcr,xc,hc;
	interval *mi1,*mi2,*mir,xi,hi;
	hd1=next_param(st);
	equal_params_2(&hd,&hd1); if (error) return;
	getmatrix(hd,&r,&c1,&m1); if (r!=1) wrong_arg();
	getmatrix(hd1,&r,&c2,&m2); if (r!=1) wrong_arg();
	if ((LONG)c1+c2-1>INT_MAX) wrong_arg();
	c=c1+c2-1;
	if (iscomplex(hd))
	{	mc1=(complex *)m1; mc2=(complex *)m2;
		result=new_cmatrix(1,c,""); if (error) return;
		mcr=(complex *)matrixof(result);
		c_copy(xc,*mc1); mc1++;
		for (i=0; i<c2; i++) c_mult(xc,mc2[i],mcr[i]);
		for (j=1; j<c1; j++)
		{	c_copy(xc,*mc1); mc1++;
			for (k=j,i=0; i<c2-1; i++,k++)
			{	c_mult(xc,mc2[i],hc);
				c_add(hc,mcr[k],mcr[k]);
			}
			c_mult(xc,mc2[i],mcr[k]);
		}
	}
	else if (isinterval(hd))
	{	mi1=(interval *)m1; mi2=(interval *)m2;
		result=new_imatrix(1,c,""); if (error) return;
		mir=(interval *)matrixof(result);
		i_copy(xi,*mi1); mi1++;
		for (i=0; i<c2; i++) i_mult(xi,mi2[i],mir[i]);
		for (j=1; j<c1; j++)
		{	i_copy(xi,*mi1); mi1++;
			for (k=j,i=0; i<c2-1; i++,k++)
			{	i_mult(xi,mi2[i],hi);
				c_add(hi,mir[k],mir[k]);
			}
			c_mult(xi,mi2[i],mir[k]);
		}
	}
	else if (isreal(hd))
	{	result=new_matrix(1,c,""); if (error) return;
		mr=matrixof(result);
		x=*m1++;
		for (i=0; i<c2; i++) mr[i]=x*m2[i];
		for (j=1; j<c1; j++)
		{	x=*m1++;
			for (k=j,i=0; i<c2-1; i++,k++) mr[k]+=x*m2[i];
			mr[k]=x*m2[i];
		}
	}
	else wrong_arg();
	moveresult(st,result);
}
예제 #4
0
static int parse_x11_params(char *params, GP_Size *w, GP_Size *h,
                            enum GP_BackendX11Flags *flags)
{
    char *param;

    if (!params)
        return 0;

    do {
        param = params;
        params = next_param(params);

        if (!strcasecmp(param, "use_root")) {
            *flags |= GP_X11_USE_ROOT_WIN;
            GP_DEBUG(1, "X11: Using root window");
            continue;
        }

        if (!strcasecmp(param, "create_root")) {
            *flags |= GP_X11_CREATE_ROOT_WIN;
            GP_DEBUG(1, "X11: Creating root window");
            continue;
        }

        if (!strcasecmp(param, "disable_shm")) {
            *flags |= GP_X11_DISABLE_SHM;
            GP_DEBUG(1, "X11: Disabling SHM");
            continue;
        }

        if (!strcasecmp(param, "fs")) {
            *flags |= GP_X11_FULLSCREEN;
            GP_DEBUG(1, "X11: Enabling fullscreen");
            continue;
        }

        /*
         * Accepts only string with format "intxint" or "intXint"
         */
        int sw, sh;
        unsigned int n;

        if (sscanf(param, "%i%*[xX]%i%n", &sw, &sh, &n) == 2 && n == strlen(param)) {
            *w = sw;
            *h = sh;
            continue;
        }

        GP_WARN("X11: Invalid parameters '%s'", param);
        errno = EINVAL;
        return 1;
    } while (params);

    return 0;
}
예제 #5
0
파일: elma.cpp 프로젝트: edeproject/svn
int main(int argc, char** argv) {
	const char* config_file = NULL;
	bool test_mode = false;
	bool daemon_mode = false;

	if(argc > 1) {
		const char* a;
		for(int i = 1; i < argc; i++) {
			a = argv[i];
			if(CHECK_ARGV(a, "-h", "--help")) {
				help();
				return 0;
			} else if(CHECK_ARGV(a, "-c", "--config")) {
				config_file = next_param(i, argv, argc);
				if(!config_file) {
					puts("Missing configuration filename");
					return 1;
				}
				i++;
			} else if(CHECK_ARGV(a, "-d", "--daemon")) {
				daemon_mode = true;
			} else if(CHECK_ARGV(a, "-t", "--test")) {
				test_mode = true;
			} else {
				printf("Unknown parameter '%s'. Run 'elma -h' for options\n", a);
				return 1;
			}
		}
	}

	ElmaService* service = ElmaService::instance();

	if(!service->load_config()) {
		puts("Unable to load config file");
		return 1;
	}

	if(!service->load_theme()) {
		puts("Unable to load theme file");
		return 1;
	}

	service->display_window();

	return 0;
}
예제 #6
0
void polyadd (header *hd)
{	header *st=hd,*hd1,*result;
	int c,c1,c2,i,r;
	double *m1,*m2,*mr;
	complex *mc1,*mc2,*mcr;
	interval *mi1,*mi2,*mir;
	hd1=next_param(st);
	equal_params_2(&hd,&hd1); if (error) return;
	getmatrix(hd,&r,&c1,&m1); if (r!=1) wrong_arg();
	getmatrix(hd1,&r,&c2,&m2); if (r!=1) wrong_arg();
	c=max(c1,c2);
	if (iscomplex(hd)) /* complex values */
	{	mc1=(complex *)m1; mc2=(complex *)m2;
		result=new_cmatrix(1,c,""); if (error) return;
		mcr=(complex *)matrixof(result);
		for (i=0; i<c; i++)
		{	if (i>=c1) { c_copy(*mcr,*mc2); mcr++; mc2++; }
			else if (i>=c2) { c_copy(*mcr,*mc1); mcr++; mc1++; }
			else { c_add(*mc1,*mc2,*mcr); mc1++; mc2++; mcr++; }
		}
	}
	else if (isinterval(hd))
	{	mi1=(interval *)m1; mi2=(interval *)m2;
		result=new_imatrix(1,c,""); if (error) return;
		mir=(interval *)matrixof(result);
		for (i=0; i<c; i++)
		{	if (i>=c1) { i_copy(*mir,*mi2); mir++; mi2++; }
			else if (i>=c2) { i_copy(*mir,*mi1); mir++; mi1++; }
			else { i_add(*mi1,*mi2,*mir); mi1++; mi2++; mir++; }
		}
	}
	else if (isreal(hd))
	{	result=new_matrix(1,c,""); if (error) return;
		mr=matrixof(result);
		for (i=0; i<c; i++)
		{	if (i>=c1) { *mr++ = *m2++; }
			else if (i>=c2) { *mr++ = *m1++; }
			else { *mr++ = *m1++ + *m2++; }
		}
	}
	else wrong_arg();
	moveresult(st,result);
}
예제 #7
0
void polydd (header *hd)
{	header *st=hd,*hd1,*result;
	int c1,c2,i,j,r;
	double *m1,*m2,*mr,x;
	complex *mc1,*mc2,*mcr,hc,xc;
	hd1=next_param(st);
	equal_params_2(&hd,&hd1); if (error) return;
	getmatrix(hd,&r,&c1,&m1); if (r!=1) wrong_arg();
	getmatrix(hd1,&r,&c2,&m2); if (r!=1) wrong_arg();
	if (c1!=c2) wrong_arg();
	if (iscomplex(hd)) /* complex values */
	{	mc1=(complex *)m1; mc2=(complex *)m2;
		result=new_cmatrix(1,c1,""); if (error) return;
		mcr=(complex *)matrixof(result);
		c_copy(mcr[c1-1],mc2[c1-1]);
		for (i=c1-2; i>=0; i--)
		{	c_copy(xc,mc1[i]);
			c_mult(xc,mcr[i+1],hc);
			c_sub(mc2[i],hc,mcr[i]);
			for (j=i+1; j<c1-1; j++) 
			{	c_mult(xc,mcr[j+1],hc);
				c_sub(mcr[j],hc,mcr[j]);
			}
		}
	}
	else
	{	result=new_matrix(1,c1,""); if (error) return;
		mr=matrixof(result);
		mr[c1-1]=m2[c1-1];
		for (i=c1-2; i>=0; i--)
		{	x=m1[i];
			mr[i]=m2[i]-x*mr[i+1];
			for (j=i+1; j<c1-1; j++) mr[j]=mr[j]-x*mr[j+1];
		}
	}
	moveresult(st,result);
}
예제 #8
0
파일: evoke.cpp 프로젝트: edeproject/svn
int main(int argc, char** argv) {
	const char* config_file = NULL;
	const char* pid_file    = NULL;
	const char* log_file    = NULL;

	bool do_startup     = false;
	bool do_foreground  = false;

	if(argc > 1) {
		const char* a;
		for(int i = 1; i < argc; i++) {
			a = argv[i];
			if(CHECK_ARGV(a, "-h", "--help")) {
				help();
				return 0;
			} else if(CHECK_ARGV(a, "-c", "--config")) {
				config_file = next_param(i, argv, argc);
				if(!config_file) {
					puts("Missing configuration filename");
					return 1;
				}
				i++;
			} else if(CHECK_ARGV(a, "-p", "--pid")) {
				pid_file = next_param(i, argv, argc);
				if(!pid_file) {
					puts("Missing pid filename");
					return 1;
				}
				i++;
			} else if(CHECK_ARGV(a, "-l", "--log")) {
				log_file = next_param(i, argv, argc);
				if(!log_file) {
					puts("Missing log filename");
					return 1;
				}
				i++;
			} 
			else if(CHECK_ARGV(a, "-s", "--startup"))
				do_startup = true;
			else if(CHECK_ARGV(a, "-f", "--foreground"))
				do_foreground = true;
			else {
				printf("Unknown parameter '%s'. Run '"APPNAME" -h' for options\n", a);
				return 1;
			}
		}
	}
	
	// make sure X11 is running before fork
	fl_open_display();

	// start service
	if(!do_foreground) {
		int x;
		if((x = fork()) > 0)
			exit(0);
		else if(x == -1) {
			printf("Fatal: fork failed !\n");
			return 1;
		}
	}

	EvokeService* service = EvokeService::instance();

	if(!service->setup_logging(log_file)) {
		printf("Can't open %s for logging. Please choose some writeable place\n", log_file);
		return 1;
	}

	EVOKE_LOG("= "APPNAME" started =\n");

	if(!pid_file)
		pid_file = DEFAULT_PID;

	if(!service->setup_pid(pid_file)) {
		EVOKE_LOG("Either another "APPNAME" instance is running or can't create pid file. Please correct this\n");
		EVOKE_LOG("= "APPNAME" abrupted shutdown =\n");
		return 1;
	}

	if(!config_file)
		config_file = CONFIG_FILE; // TODO: XDG paths

	if(!service->setup_config(config_file, do_startup)) {
		EVOKE_LOG("Unable to read correctly %s. Please check it is correct config file\n");
		EVOKE_LOG("= "APPNAME" abrupted shutdown =\n");
		return 1;
	}

	service->setup_atoms(fl_display);

	signal(SIGINT, quit_signal);
	signal(SIGTERM, quit_signal);
	signal(SIGKILL, quit_signal);

	running = true;

	XSelectInput(fl_display, RootWindow(fl_display, fl_screen), PropertyChangeMask | StructureNotifyMask | ClientMessage);

	/*
	 * Register event listener and run in infinite loop. Loop will be
	 * interrupted from one of the received signals.
	 *
	 * I choose to use fltk for this since wait() will nicely pool events
	 * and pass expecting ones to xmessage_handler(). Other (non-fltk) solution would
	 * be to manually pool events via select() and that code could be very messy.
	 * So stick with the simplicity :)
	 */
	Fl::add_handler(xmessage_handler);
	while(running)
		Fl::wait(FOREVER);

	EVOKE_LOG("= "APPNAME" nice shutdown =\n");
	return 0;
}
예제 #9
0
파일: lexer.c 프로젝트: 16candles/16cc
// Takes the first expression from a string.
// Pass null to take the next expression out of the string.
c16_expr *get_expr(char *str){
    char *in = (str) ? str : NULL;
    c16_expr *ret = malloc(sizeof(c16_expr));
    char *tok;
    static const char* const bin_ops[][2] = { { "and",   "&&" },
                                              { "or",    "||" },
                                              { "xand",  "!&" },
                                              { "xor",   "!|" },
                                              { "lshift","<<" },
                                              { "rshift",">>" },
                                              { "add",   "+"  },
                                              { "sub",   "-"  },
                                              { "mul",   "*"  },
                                              { "div",   "/"  },
                                              { "mod",   "%"  },
                                              { "min",   ""   },
                                              { "max",   ""   } };
    static const char* const un_ops[][2] =  { { "inv",   "~"  },
                                              { "inc",   "++" },
                                              { "dec",   "--" },
                                              { "set",   "="  },
                                              { "swap",  "\\\\" },
                                              { "gt",    ">"  },
                                              { "lt",    "<"  },
                                              { "gte",   ">=" },
                                              { "lte",   "<=" },
                                              { "eq",    "==" },
                                              { "neq",   "!=" } };
    static const char* const nrp_ops[][2] = { { "push",  ":"  },
                                              { "write", ""   },
                                              { "pop",   "$"  },
                                              { "peek",  "@"  },
                                              { "read",  ""   } };
    static const char* const fr_ops[][2] =  { { "flush", "#"  },
                                              { "halt",  ""   },
                                              { "nop",   ""   } };
    static const char* const jmp_ops[][2] = { { "jmp",   "=>" },
                                              { "jmpt",  "->" },
                                              { "jmpf",  "<-" } };
    int n;
    ret->is_valid = true;
    tok = strtok(in," \n");
    if (!tok){
        ret->op       = OP_TERM;
        ret->param_1  = no_param;
        ret->param_2  = no_param;
        ret->param_3  = no_param;
        ret->str_data = NULL;
        return ret;
    }
    if (tok[0] == '@' && strlen(tok) > 1){
        ret->op       = OP_LABEL;
        ret->param_1  = no_param;
        ret->param_2  = no_param;
        ret->param_3  = no_param;
        ret->str_data = &tok[1];
        v_msgf("Adding label to expr list: '%s'\n",tok);
        return ret;
    }
    if (!strcmp(tok,"mset") || !strcmp(tok,":=")){
        ret->op = OP_MSET_;
        ret->param_1  = next_param();
        ret->param_2  = next_param();
        ret->param_3  = no_param;
        ret->str_data = NULL;
        specialize_expr(ret);
        return ret;
    }
    for (n = 0;n < 13;n++){
        if (!strcmp(tok,bin_ops[n][0])
            || !strcmp(tok,bin_ops[n][1])){
            ret->op       = parse_opcode(tok);
            ret->param_1  = next_param();
            ret->param_2  = next_param();
            ret->param_3  = next_param();
            ret->str_data = NULL;
            specialize_expr(ret);
            return ret;
        }
    }
    for (n = 0;n < 11;n++){
        if (!strcmp(tok,un_ops[n][0])
            || !strcmp(tok,un_ops[n][1])){
            ret->op       = parse_opcode(tok);
            ret->param_1  = next_param();
            ret->param_2  = next_param();
            ret->param_3  = no_param;
            ret->str_data = NULL;
            specialize_expr(ret);
            return ret;
        }
    }
    for (n = 0;n < 5;n++){
        if (!strcmp(tok,nrp_ops[n][0])
            || !strcmp(tok,nrp_ops[n][1])){
            ret->op       = parse_opcode(tok);
            ret->param_1  = next_param();
            ret->param_2  = no_param;
            ret->param_3  = no_param;
            ret->str_data = NULL;
            specialize_expr(ret);
            return ret;
        }
    }
    for (n = 0;n < 3;n++){
        if (!strcmp(tok,fr_ops[n][0])
            || !strcmp(tok,fr_ops[n][1])){
            ret->op       = parse_opcode(tok);
            ret->param_1  = no_param;
            ret->param_2  = no_param;
            ret->param_3  = no_param;
            ret->str_data = NULL;
            specialize_expr(ret);
            return ret;
        }
    }
    for (n = 0;n < 3;n++){
        if (!strcmp(tok,jmp_ops[n][0])
            || !strcmp(tok,jmp_ops[n][1])){
            ret->op            = parse_opcode(tok);
            ret->param_1       = malloc(sizeof(c16_param));
            ret->param_1->type = WORDLIT_PARAM;
            ret->param_1->data = 0;
            ret->param_2       = no_param;
            ret->param_3       = no_param;
            ret->str_data      = strdup(strtok(NULL," \n"));
            return ret;
        }
    }
    v_msgf("Read an unreckognized token: '%s'\n",tok);
    no_param = malloc(sizeof(c16_param));
    no_param->type = NO_PARAM;
    no_param->str  = NULL;
    ret->op        = OP_INVALID;
    ret->param_1   = no_param;
    ret->param_2   = no_param;
    ret->param_3   = no_param;
    ret->str_data  = strdup(tok);
    specialize_expr(ret);
    return ret;
}
예제 #10
0
void polydiv (header *hd)
{	header *st=hd,*hd1,*result,*rest;
	int c1,c2,i,r,j;
	double *m1,*m2,*mr,*mh,x,l;
	complex *mc1,*mc2,*mcr,*mch,xc,lc,hc;
	interval *mi1,*mi2,*mir,*mih,xi,li,hi;
	hd1=next_param(st);
	equal_params_2(&hd,&hd1); if (error) return;
	getmatrix(hd,&r,&c1,&m1); if (r!=1) wrong_arg();
	getmatrix(hd1,&r,&c2,&m2); if (r!=1) wrong_arg();
	if (c1<c2)
	{	result=new_real(0.0,"");
		rest=(header *)newram;
		moveresult(rest,hd1);
	}
	else if (iscomplex(hd))
	{	mc1=(complex *)m1; mc2=(complex *)m2;
		result=new_cmatrix(1,c1-c2+1,""); if (error) return;
		mcr=(complex *)matrixof(result);
		rest=new_cmatrix(1,c2,""); if (error) return;
		mch=(complex *)newram;
		if (!freeram(c1*sizeof(complex)))
		{	output("Out of memory!\n"); error=190; return;
		}
		memmove((char *)mch,(char *)mc1,c1*sizeof(complex));
		c_copy(lc,mc2[c2-1]);
		if (lc[0]==0.0 && lc[1]==0.0) wrong_arg();
		for (i=c1-c2; i>=0; i--)
		{	c_div(mch[c2+i-1],lc,xc); c_copy(mcr[i],xc);
			for(j=0; j<c2; j++)
			{	c_mult(mc2[j],xc,hc);
				c_sub(mch[i+j],hc,mch[i+j]);
			}
		}
		memmove((char *)matrixof(rest),(char *)mch,c2*sizeof(complex));
	}
	else if (isinterval(hd))
	{	mi1=(interval *)m1; mi2=(interval *)m2;
		result=new_imatrix(1,c1-c2+1,""); if (error) return;
		mir=(interval *)matrixof(result);
		rest=new_imatrix(1,c2,""); if (error) return;
		mih=(complex *)newram;
		if (!freeram(c1*sizeof(complex)))
		{	output("Out of memory!\n"); error=190; return;
		}
		memmove((char *)mih,(char *)mi1,c1*sizeof(interval));
		i_copy(li,mi2[c2-1]);
		if (li[0]<=0.0 && li[1]>=0.0) wrong_arg();
		for (i=c1-c2; i>=0; i--)
		{	i_div(mih[c2+i-1],li,xi); c_copy(mir[i],xi);
			for(j=0; j<c2; j++)
			{	i_mult(mi2[j],xi,hi);
				i_sub(mih[i+j],hi,mih[i+j]);
			}
		}
		memmove((char *)matrixof(rest),(char *)mih,c2*sizeof(interval));
	}
	else if (isreal(hd))
	{	result=new_matrix(1,c1-c2+1,""); if (error) return;
		mr=matrixof(result);
		rest=new_matrix(1,c2,""); if (error) return;
		mh=(double *)newram;
		if (!freeram(c1*sizeof(double)))
		{	output("Out of memory!\n"); error=190; return;
		}
		memmove((char *)mh,(char *)m1,c1*sizeof(double));
		l=m2[c2-1];
		if (l==0.0) wrong_arg();
		for (i=c1-c2; i>=0; i--)
		{	x=mh[c2+i-1]/l; mr[i]=x;
			for(j=0; j<c2; j++) mh[i+j]-=m2[j]*x;
		}
		memmove((char *)matrixof(rest),(char *)mh,c2*sizeof(double));
	}
	else wrong_arg();
	moveresult(st,result);
	moveresult(nextof(st),rest);
}
예제 #11
0
bool resample_init(char *opt) {
	char *recipe = NULL, *flags = NULL;
	char *atten = NULL;
	char *precision = NULL, *passband_end = NULL, *stopband_begin = NULL, *phase_response = NULL;

	if (!load_soxr()) {
		LOG_WARN("resampling disabled");
		return false;
	}

	if (opt) {
		recipe = next_param(opt, ':');
		flags = next_param(NULL, ':');
		atten = next_param(NULL, ':');
		precision = next_param(NULL, ':');
		passband_end = next_param(NULL, ':');
		stopband_begin = next_param(NULL, ':');
		phase_response = next_param(NULL, ':');
	}

	// default to HQ (20 bit) if not user specified
	r->q_recipe = SOXR_HQ;
	r->q_flags = 0;
	// default to 1db of attenuation if not user specified
	r->scale = pow(10, -1.0 / 20);
	// override recipe derived values with user specified values
	r->q_precision = 0;
	r->q_passband_end = 0;
	r->q_stopband_begin = 0;
	r->q_phase_response = -1;

	if (recipe && recipe[0] != '\0') {
		if (strchr(recipe, 'v')) r->q_recipe = SOXR_VHQ;
		if (strchr(recipe, 'h')) r->q_recipe = SOXR_HQ;
		if (strchr(recipe, 'm')) r->q_recipe = SOXR_MQ;
		if (strchr(recipe, 'l')) r->q_recipe = SOXR_LQ;
		if (strchr(recipe, 'q')) r->q_recipe = SOXR_QQ;
		if (strchr(recipe, 'L')) r->q_recipe |= SOXR_LINEAR_PHASE;
		if (strchr(recipe, 'I')) r->q_recipe |= SOXR_INTERMEDIATE_PHASE;
		if (strchr(recipe, 'M')) r->q_recipe |= SOXR_MINIMUM_PHASE;
		if (strchr(recipe, 's')) r->q_recipe |= SOXR_STEEP_FILTER;
		// X = async resampling to max_rate
		if (strchr(recipe, 'X')) r->max_rate = true;
	}

	if (flags) {
		r->q_flags = strtoul(flags, 0, 16);
	}

	if (atten) {
		double scale = pow(10, -atof(atten) / 20);
		if (scale > 0 && scale <= 1.0) {
			r->scale = scale;
		}
	}

	if (precision) {
		r->q_precision = atof(precision);
	}

	if (passband_end) {
		r->q_passband_end = atof(passband_end) / 100;
	}

	if (stopband_begin) {
		r->q_stopband_begin = atof(stopband_begin) / 100;
	}

	if (phase_response) {
		r->q_phase_response = atof(phase_response);
	}

	LOG_INFO("resampling %s recipe: 0x%02x, flags: 0x%02x, scale: %03.2f, precision: %03.1f, passband_end: %03.5f, stopband_begin: %03.5f, phase_response: %03.1f",
			r->max_rate ? "async" : "sync",
			r->q_recipe, r->q_flags, r->scale, r->q_precision, r->q_passband_end, r->q_stopband_begin, r->q_phase_response);

	return true;
}
예제 #12
0
static int process(struct cmd_line_options* cmd_line_options)
{
  int result = EXIT_FAILURE;
  uint32_t entries;
  struct state state;
  param_t *par;
  CSPSA_Handle_t handle;
  char idstr[BUFSIZ];
  int i;
  int cspsa_written = 0;

  memset(&state, 0, sizeof(state));

  if (cmd_line_options->debug) {
    printf(PROGRAM ": Processing %s (only stuff below", cmd_line_options->inpath);
    for (i = 0; i < cmd_line_options->subpaths; i++)
      printf(" %s", cmd_line_options->subpath[i]);
    printf("), writing to %s.\n", cmd_line_options->area);
  }

  result = init_cspsa(cmd_line_options->area, &handle);
  if (result != EXIT_SUCCESS)
    goto error_exit;

  /* unit id 0 is reserved for the number of entries */
  state.entries = 1;

  /* create entries in a linked list for each file
   * or directory in the input directory tree */
  if (cmd_line_options->subpaths)
  {
    for (i = 0; i < cmd_line_options->subpaths; i++)
    {
      result |= process_dirtree(cmd_line_options, cmd_line_options->inpath, "/",
					cmd_line_options->subpath[i], &state);
    }
  }
  else
  {
    result = process_dirtree(cmd_line_options, cmd_line_options->inpath, "/",
					NULL, &state);
  }

  if (result != EXIT_SUCCESS)
  {
    fprintf(stderr, ERRORSTR_INTERNAL, __LINE__);
    goto error_exit;
  }

  /* Create small header */
  result = create_id(PROGRAM, STRINGIFY(VERSION), idstr, BUFSIZ);
  if (result != EXIT_SUCCESS)
  {
    fprintf(stderr, ERRORSTR_INTERNAL, __LINE__);
    goto error_exit;
  }

  /* Wipe key 0, we have no parameter entries in CSPSA yet */
  entries = 0;
  cspsa_written = 1;
  result = emit_parameter_to_cspsa(cmd_line_options, &handle, 0,
				sizeof (entries), (unsigned char *) &entries);
  if (result != EXIT_SUCCESS)
  {
    fprintf(stderr, ERRORSTR_INTERNAL, __LINE__);
    goto error_exit;
  }

  /* Make sure key 0 hits storage */
  result = flush_cspsa(&handle);
  if (result != EXIT_SUCCESS)
  {
    fprintf(stderr, ERRORSTR_INTERNAL, __LINE__);
    goto error_exit;
  }

  /* Write header */
  result = emit_parameter_to_cspsa(cmd_line_options, &handle, MAX_FILES + 1,
				strlen(idstr) + 1, (unsigned char *) idstr);
  if (result != EXIT_SUCCESS)
  {
    fprintf(stderr, ERRORSTR_INTERNAL, __LINE__);
    goto error_exit;
  }

  /* Dump the stuff, par points to head of linked list */
  par = state.par;
  while (par != NULL)
  {
    result = emit_parameter_to_cspsa(cmd_line_options, &handle, par->key,
							par->size, par->data);
    if (result != EXIT_SUCCESS)
      goto error_exit;
    par = next_param(par);
  }

  /* Make sure the parameters hit storage before key 0 */
  result = flush_cspsa(&handle);
  if (result != EXIT_SUCCESS)
  {
    fprintf(stderr, ERRORSTR_INTERNAL, __LINE__);
    goto error_exit;
  }

  /* a unit id 0 output the number of files+dirs */
  entries = state.entries - 1;
  result = emit_parameter_to_cspsa(cmd_line_options, &handle, 0,
				sizeof (entries), (unsigned char *) &entries);

  printf(PROGRAM ": Read %d entries from %s, wrote to %s\n", entries,
			cmd_line_options->inpath, cmd_line_options->area);

error_exit:

  if (state.par)
    free_param(state.par);
  result |= exit_cspsa(&handle);

  if (result != EXIT_SUCCESS)
  {
    if (cspsa_written)
      fprintf(stderr, ERRORSTR PROGRAM ": WARNING: CSPSA was most likely modified!\n");
    else
      fprintf(stderr, ERRORSTR PROGRAM ": CSPSA was NOT modified.\n");
  }

  return result;
}
예제 #13
0
static int parse_sdl_params(char *params, GP_Size *w, GP_Size *h,
                            GP_Size *bpp, uint8_t *flags)
{
    char *param;

    if (!params)
        return 0;

    do {
        param = params;
        params = next_param(params);

        if (!strcasecmp(param, "FS")) {
            *flags |= GP_SDL_FULLSCREEN;
            GP_DEBUG(1, "SDL fullscreen enabled");
            continue;
        }

        if (!strcmp(param, "8")) {
            *bpp = 8;
            GP_DEBUG(1, "SDL depth set to 8");
            continue;
        }

        if (!strcmp(param, "16")) {
            *bpp = 16;
            GP_DEBUG(1, "SDL depth set to 16");
            continue;
        }

        if (!strcmp(param, "24")) {
            *bpp = 24;
            GP_DEBUG(1, "SDL depth set to 24");
            continue;
        }

        if (!strcmp(param, "32")) {
            *bpp = 32;
            GP_DEBUG(1, "SDL depth set to 32");
            continue;
        }

        /*
         * Accepts only string with format "intxint" or "intXint"
         */
        int sw, sh;
        unsigned int n;

        if (sscanf(param, "%i%*[xX]%i%n", &sw, &sh, &n) == 2 && n == strlen(param)) {
            *w = sw;
            *h = sh;
            continue;
        }

        GP_WARN("SDL: Invalid parameters '%s'", param);
        errno = EINVAL;
        return 1;
    } while (params);

    return 0;
}
예제 #14
0
int main(int argc, char **argv) {
    const char *title, *txt;
    int         opt = OPT_NONE;
    int         ret = EDE_DIALOG_ERROR_RET;
    int         nbuttons = 0;

    MessageBoxType     mtype = MSGBOX_PLAIN;
    MessageBoxIconType itype = MSGBOX_ICON_TYPE_INFO;

    title = txt = NULL;

    if(argc <= 1) {
        help();
        return EDE_DIALOG_ERROR_RET;
    }

    for(int i = 1; i < argc; i++) {
        if(CHECK_ARGV(argv[i], "-h", "--help")) {
            help();
            return EDE_DIALOG_ERROR_RET;
        }

        /* optional flags */
        if(CHECK_ARGV_LONG(argv[i], "--title")) {
            title = next_param(i, argv, argc);
            if(!title) {
                puts("'title' option requires a parameter");
                return EDE_DIALOG_ERROR_RET;
            }

            i++;
            continue;
        }

        /* mandatory flags */
        if(CHECK_ARGV_LONG(argv[i], "--yesno")) {
            itype = MSGBOX_ICON_TYPE_QUESTION;
            opt = OPT_YESNO;
        } else if(CHECK_ARGV_LONG(argv[i], "--yesnocancel")) {
            itype = MSGBOX_ICON_TYPE_QUESTION;
            opt = OPT_YESNOCANCEL;
        } else if(CHECK_ARGV_LONG(argv[i], "--error")) {
            itype = MSGBOX_ICON_TYPE_ALERT;
            opt = OPT_ERROR;
        } else if(CHECK_ARGV_LONG(argv[i], "--sorry")) {
            itype = MSGBOX_ICON_TYPE_ALERT;
            opt = OPT_SORRY;
        } else if(CHECK_ARGV_LONG(argv[i], "--msgbox")) {
            opt = OPT_MSGBOX;
            /* for else do nothing; use default values */
        } else if(CHECK_ARGV_LONG(argv[i], "--inputbox")) {
            itype = MSGBOX_ICON_TYPE_INPUT;
            mtype = MSGBOX_INPUT;
            opt   = OPT_INPUTBOX;
        } else if(CHECK_ARGV_LONG(argv[i], "--password")) {
            itype = MSGBOX_ICON_TYPE_PASSWORD;
            mtype = MSGBOX_INPUT_SECRET;
            opt   = OPT_PASSWORD;
        } else {
            printf("Unknown '%s' parameter\n", argv[i]);
            return EDE_DIALOG_ERROR_RET;
        }

        /* every above option requres additional parameter */
        txt = next_param(i, argv, argc);
        if(!txt) {
            printf("'%s' option requires a parameter\n", argv[i]);
            return EDE_DIALOG_ERROR_RET;
        }

        /* skip parameter */
        i++;
    }

    if(opt == OPT_NONE) {
        puts("Missing one of the flags that will describe the dialog. Run program with '--help' for the details");
        return EDE_DIALOG_ERROR_RET;
    }

    EDE_APPLICATION("ede-dialog");

    /*
     * Use a trick to load icon theme and colors using xsettings stuff. edelib::Window will load them
     * and fill static FLTK values; every further window will use those values, including our will use them
     *
     * TODO: this hack needs appropriate solution in edelib.
     */
    EdelibWindow *win = new EdelibWindow(-100, -100, 0, 0);
    win->show();
    Fl::wait(0.2);
    win->hide();

    mbox = new MessageBox(mtype);
    mbox->set_icon_from_type(itype);
    mbox->set_text(txt);
    mbox->label(title);

    /* determine buttons */
    switch(opt) {
    case OPT_YESNO:
        mbox->add_button(_("&No"));
        mbox->add_button(_("&Yes"));
        nbuttons = 2;
        break;
    case OPT_YESNOCANCEL:
        mbox->add_button(_("&Cancel"));
        mbox->add_button(_("&No"));
        mbox->add_button(_("&Yes"));
        nbuttons = 3;
        break;
    case OPT_ERROR:
    case OPT_MSGBOX:
    case OPT_SORRY:
        mbox->add_button(_("&Close"));
        nbuttons = 1;
        break;
    case OPT_INPUTBOX:
    case OPT_PASSWORD:
        mbox->add_button(_("&Cancel"));
        mbox->add_button(_("&OK"));
        nbuttons = 2;
        break;
    }

    ret = mbox->run();

    /* check box type and 'Cancel' wasn't present */
    if((opt == OPT_INPUTBOX || opt == OPT_PASSWORD) && ret != 0)
        printf("%s\n", mbox->get_input());

    /*
     * Now emulate kdialog return values; e.g. 'OK' will be 0 and 'Cancel' will be 1 if two buttons
     * are exists. Because MessageBox already do this in reversed way, here value is just re-reversed again if
     * we have more that one button.
     */
    if(nbuttons > 1) {
        /* xor-ing with 2 is different so button number can't be decreased */
        if(nbuttons == 3) {
            ret ^= nbuttons;
            ret -= 1;
        } else {
            ret ^= (nbuttons - 1);
        }
    }

    return ret;
}