Example #1
0
void	read_stdin(t_lemin *l)
{
	int				i;
	char			*line;
	char			*prev;

	i = 0;
	line = NULL;
	prev = NULL;
	l->listrooms = NULL;
	l->listtubes = NULL;
	while (get_next_line(0, &line))
	{
		if (line[0] != '#')
		{
			check_stdin(l, line, prev, i);
			i++;
		}
		prev = line;
	}
	link_rooms(l);
	define_rooms_weight(l);
	handle_stdout(l);
	lemin_loop(l);
}
Example #2
0
static int conf_askvalue(struct symbol *sym, const char *def)
{
    enum symbol_type type = sym_get_type(sym);

    if (!sym_has_value(sym))
        printf(_("(NEW) "));

    line[0] = '\n';
    line[1] = 0;

    if (!sym_is_changable(sym)) {
        printf("%s\n", def);
        line[0] = '\n';
        line[1] = 0;
        return 0;
    }

    switch (input_mode) {
    case ask_new:
    case ask_silent:
        if (sym_has_value(sym)) {
            printf("%s\n", def);
            return 0;
        }
        check_stdin();
    case ask_all:
        fflush(stdout);
        if (NULL == fgets(line, 128, stdin)) {  //BRCM: check ret val to fix compiler warning
            printf("fgets failed, exiting\n");
            exit(2);
        }
        if (feof(stdin)) {
            printf("\nEOF on std input -- exiting\n");
            exit(2);
        }
        return 1;
    default:
        break;
    }

    switch (type) {
    case S_INT:
    case S_HEX:
    case S_STRING:
        printf("%s\n", def);
        return 1;
    default:
        ;
    }
    printf("%s", line);
    return 1;
}
Example #3
0
static int conf_askvalue(struct symbol *sym, const char *def)
{
	enum symbol_type type = sym_get_type(sym);

	if (!sym_has_value(sym))
		printf(_("(NEW) "));

	line[0] = '\n';
	line[1] = 0;

	if (!sym_is_changable(sym)) {
		printf("%s\n", def);
		line[0] = '\n';
		line[1] = 0;
		return 0;
	}

	switch (input_mode) {
	case oldconfig:
	case silentoldconfig:
		if (sym_has_value(sym)) {
			printf("%s\n", def);
			return 0;
		}
		check_stdin();
		/* fall through */
	case oldaskconfig:
		fflush(stdout);
		xfgets(line, 128, stdin);
		if (!tty_stdio)
			printf("\n");
		return 1;
	default:
		break;
	}

	switch (type) {
	case S_INT:
	case S_HEX:
	case S_STRING:
		printf("%s\n", def);
		return 1;
	default:
		;
	}
	printf("%s", line);
	return 1;
}
Example #4
0
static int conf_askvalue(struct symbol *sym, const char *def)
{
	char *ret;
	enum symbol_type type = sym_get_type(sym);

	if (!sym_has_value(sym))
		printf("(NEW) ");

	line[0] = '\n';
	line[1] = 0;

	if (!sym_is_changable(sym)) {
		printf("%s\n", def);
		line[0] = '\n';
		line[1] = 0;
		return 0;
	}

	switch (input_mode) {
	case ask_new:
	case ask_silent:
		if (sym_has_value(sym)) {
			printf("%s\n", def);
			return 0;
		}
		check_stdin();
	case ask_all:
		fflush(stdout);
		ret = fgets(line, 128, stdin);
		(void)ret;
		return 1;
	default:
		break;
	}

	switch (type) {
	case S_INT:
	case S_HEX:
	case S_STRING:
		printf("%s\n", def);
		return 1;
	default:
		;
	}
	printf("%s", line);
	return 1;
}
static int conf_choice(struct menu *menu)
{
	struct symbol *sym, *def_sym;
	struct menu *child;
	bool is_new;

	sym = menu->sym;
	is_new = !sym_has_value(sym);
	if (sym_is_changable(sym)) {
		conf_sym(menu);
		sym_calc_value(sym);
		switch (sym_get_tristate_value(sym)) {
		case no:
			return 1;
		case mod:
			return 0;
		case yes:
			break;
		}
	} else {
		switch (sym_get_tristate_value(sym)) {
		case no:
			return 1;
		case mod:
			printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
			return 0;
		case yes:
			break;
		}
	}

	while (1) {
		int cnt, def;

		printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
		def_sym = sym_get_choice_value(sym);
		cnt = def = 0;
		line[0] = 0;
		for (child = menu->list; child; child = child->next) {
			if (!menu_is_visible(child))
				continue;
			if (!child->sym) {
				printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
				continue;
			}
			cnt++;
			if (child->sym == def_sym) {
				def = cnt;
				printf("%*c", indent, '>');
			} else
				printf("%*c", indent, ' ');
			printf(" %d. %s", cnt, _(menu_get_prompt(child)));
			if (child->sym->name)
				printf(" (%s)", child->sym->name);
			if (!sym_has_value(child->sym))
				printf(_(" (NEW)"));
			printf("\n");
		}
		printf(_("%*schoice"), indent - 1, "");
		if (cnt == 1) {
			printf("[1]: 1\n");
			goto conf_childs;
		}
		printf("[1-%d", cnt);
		if (menu_has_help(menu))
			printf("?");
		printf("]: ");
		switch (input_mode) {
		case oldconfig:
		case silentoldconfig:
			if (!is_new) {
				cnt = def;
				printf("%d\n", cnt);
				break;
			}
			check_stdin();
			/* fall through */
		case oldaskconfig:
			fflush(stdout);
			xfgets(line, 128, stdin);
			strip(line);
			if (line[0] == '?') {
				print_help(menu);
				continue;
			}
			if (!line[0])
				cnt = def;
			else if (isdigit(line[0]))
				cnt = atoi(line);
			else
				continue;
			break;
		default:
			break;
		}

	conf_childs:
		for (child = menu->list; child; child = child->next) {
			if (!child->sym || !menu_is_visible(child))
				continue;
			if (!--cnt)
				break;
		}
		if (!child)
			continue;
		if (line[0] && line[strlen(line) - 1] == '?') {
			print_help(child);
			continue;
		}
		sym_set_choice_value(sym, child->sym);
		for (child = child->list; child; child = child->next) {
			indent += 2;
			conf(child);
			indent -= 2;
		}
		return 1;
	}
}
Example #6
0
static void conf_askvalue(struct symbol *sym, const char *def)
{
	enum symbol_type type = sym_get_type(sym);
	tristate val;

	if (!sym_has_value(sym))
		printf("(NEW) ");

	line[0] = '\n';
	line[1] = 0;

	if (!sym_is_changable(sym)) {
		printf("%s\n", def);
		line[0] = '\n';
		line[1] = 0;
		return;
	}

	switch (input_mode) {
	case set_no:
	case set_mod:
	case set_yes:
	case set_random:
		if (sym_has_value(sym)) {
			printf("%s\n", def);
			return;
		}
		break;
	case ask_new:
	case ask_silent:
		if (sym_has_value(sym)) {
			printf("%s\n", def);
			return;
		}
		check_stdin();
	case ask_all:
		fflush(stdout);
		fgets(line, 128, stdin);
		return;
	case set_default:
		printf("%s\n", def);
		return;
	default:
		break;
	}

	switch (type) {
	case S_INT:
	case S_HEX:
	case S_STRING:
		printf("%s\n", def);
		return;
	default:
		;
	}
	switch (input_mode) {
	case set_yes:
		if (sym_tristate_within_range(sym, yes)) {
			line[0] = 'y';
			line[1] = '\n';
			line[2] = 0;
			break;
		}
	case set_mod:
		if (type == S_TRISTATE) {
			if (sym_tristate_within_range(sym, mod)) {
				line[0] = 'm';
				line[1] = '\n';
				line[2] = 0;
				break;
			}
		} else {
			if (sym_tristate_within_range(sym, yes)) {
				line[0] = 'y';
				line[1] = '\n';
				line[2] = 0;
				break;
			}
		}
	case set_no:
		if (sym_tristate_within_range(sym, no)) {
			line[0] = 'n';
			line[1] = '\n';
			line[2] = 0;
			break;
		}
	case set_random:
		do {
			val = (tristate)(random() % 3);
		} while (!sym_tristate_within_range(sym, val));
		switch (val) {
		case no: line[0] = 'n'; break;
		case mod: line[0] = 'm'; break;
		case yes: line[0] = 'y'; break;
		}
		line[1] = '\n';
		line[2] = 0;
		break;
	default:
		break;
	}
	printf("%s", line);
}
Example #7
0
static int conf_choice(struct menu *menu)
{
	struct symbol *sym, *def_sym;
	struct menu *child;
	int type;
	bool is_new;

	sym = menu->sym;
	type = sym_get_type(sym);
	is_new = !sym_has_value(sym);
	if (sym_is_changable(sym)) {
		conf_sym(menu);
		sym_calc_value(sym);
		switch (sym_get_tristate_value(sym)) {
		case no:
			return 1;
		case mod:
			return 0;
		case yes:
			break;
		}
	} else {
		switch (sym_get_tristate_value(sym)) {
		case no:
			return 1;
		case mod:
			printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
			return 0;
		case yes:
			break;
		}
	}

	while (1) {
		int cnt, def;

		printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
		def_sym = sym_get_choice_value(sym);
		cnt = def = 0;
		line[0] = 0;
		for (child = menu->list; child; child = child->next) {
			if (!menu_is_visible(child))
				continue;
			if (!child->sym) {
				printf("%*c %s\n", indent, '*', menu_get_prompt(child));
				continue;
			}
			cnt++;
			if (child->sym == def_sym) {
				def = cnt;
				printf("%*c", indent, '>');
			} else
				printf("%*c", indent, ' ');
			printf(" %d. %s", cnt, menu_get_prompt(child));
			if (child->sym->name)
				printf(" (%s)", child->sym->name);
			if (!sym_has_value(child->sym))
				printf(" (NEW)");
			printf("\n");
		}
		printf("%*schoice", indent - 1, "");
		if (cnt == 1) {
			printf("[1]: 1\n");
			goto conf_childs;
		}
		printf("[1-%d", cnt);
		if (sym->help)
			printf("?");
		printf("]: ");
		switch (input_mode) {
		case ask_new:
		case ask_silent:
			if (!is_new) {
				cnt = def;
				printf("%d\n", cnt);
				break;
			}
			check_stdin();
		case ask_all:
			fflush(stdout);
			fgets(line, 128, stdin);
			strip(line);
			if (line[0] == '?') {
				printf("\n%s\n", menu->sym->help ?
					menu->sym->help : nohelp_text);
				continue;
			}
			if (!line[0])
				cnt = def;
			else if (isdigit(line[0]))
				cnt = atoi(line);
			else
				continue;
			break;
		case set_random:
			def = (random() % cnt) + 1;
		case set_default:
		case set_yes:
		case set_mod:
		case set_no:
			cnt = def;
			printf("%d\n", cnt);
			break;
		}

	conf_childs:
		for (child = menu->list; child; child = child->next) {
			if (!child->sym || !menu_is_visible(child))
				continue;
			if (!--cnt)
				break;
		}
		if (!child)
			continue;
		if (line[strlen(line) - 1] == '?') {
			printf("\n%s\n", child->sym->help ?
				child->sym->help : nohelp_text);
			continue;
		}
		sym_set_choice_value(sym, child->sym);
		if (child->list) {
			indent += 2;
			conf(child->list);
			indent -= 2;
		}
		return 1;
	}
}
Example #8
0
int main(int argc, char **argv)
{
    /* setup up space to pass stuff around in */
    control *c;
    if ((c = malloc(sizeof(control))) == NULL) {
        check_errors("Control structure: Not allocated enough memory", __LINE__);
     }
    
    timeseries *ts;
    if ((ts = malloc(sizeof(timeseries))) == NULL) {
        check_errors("Timeseries structure: Not allocated enough memory", __LINE__);
     }
    
    meta *m;
    if ((m = malloc(sizeof(meta))) == NULL) {
        check_errors("Meta structure: Not allocated enough memory", __LINE__);
     }
    
    output_options *o;
    if ((o = malloc(sizeof(output_options))) == NULL) {
        check_errors("Output_options structure: Not allocated enough memory", __LINE__);
     }
    
    /* setup initial junk */
    setup_initial_conditions(c, ts, o);
    
    /* send sweep along the command line */
    clparse(argc, argv, c, ts, o);
    
    /* check the input file is on the stdin? */
    check_stdin(__LINE__);
    
    /* read data in from stdin */
    read_input_file(argv, c, ts, o);
    
    /* setup space for working arrays and other misc stuff */
    allocate_working_environment(c, ts);
    
    /* calculate lomb periodgram for raw time-series */
    spectrum_wrapper(c, ts, ts->x, ts->y, ts->frq, ts->gxx);
    
    /* Calculate red noise bias and correct periodgram 
        - need to generate a seed ONCE */
    srand (time(NULL));
    rednoise_bias_wrapper(c, ts, o);
    
    /* dump out what you need */
    print_outputs(c, ts, o);
    
    /* tidy up */
    free_array_double(ts->gxx);
    free_array_double(ts->frq);
    free_array_double(ts->red);
    free_array_double(ts->grr);
    free_array_double(ts->grrsum);
    free_array_double(ts->gredth);
    free_array_double(ts->corr);
    free_array_double(ts->gxxc);
    free_array_double(ts->grravg);
    free_array_double(ts->x);
    free_array_double(ts->y);  
    free(c);
    free(ts);
    free(m);
    free(o);
    
    return (0);
}
Example #9
0
File: glfw.c Project: plops/glfw
// Main program. Open a window. Continuously read commands from the
// command line interface and draw frames with 60Hz onto the
// screen. Commands for multiple frames can be cached within a ring
// buffer, so that a consistent frame rate can be maintained even if
// the control program doesn't respond within 16ms. The control
// program is written in Common Lisp and a 16ms time granularity cannot
// always be maintained, due to the time a garbage collection may
// take.
int
main(int argc,char**argv)
{
  
  // make sure frame rate update cycle is phase locked to vertical
  // refresh of screen. On Nvidia hardware this can be done by setting
  // the following environment variable.
  setenv("__GL_SYNC_TO_VBLANK","1",1); 
  
  if(!glfwInit())
    exit(EXIT_FAILURE);
  int width=1280,height=1024;

  if(argc==3){
    width=atoi(argv[1]);
    height=atoi(argv[2]);
  }
   
  if(!glfwOpenWindow(width,height,8,8,8,
		     0,0,0,
		     GLFW_WINDOW
		     )){
    glfwTerminate();
    exit(EXIT_FAILURE);
  }
  printf("lcos started %dx%d\n",width,height);
  fflush(stdout);

  glfwSetWindowTitle("LCoS");
  //glfwSetWindowPos(-8,-31);

  // use glfw method to sync to vertical refresh
  glfwSwapInterval(1);

  glfwSetKeyCallback(keyhandler);
  init_matrix();
  
  glMatrixMode(GL_PROJECTION);
  glOrtho(0,1280,1024,0,-1,1);
  glMatrixMode(GL_MODELVIEW);
  
  while(running){
    while(check_stdin()>0){
      char*s=malloc(CMDLEN);
      char*line=fgets(s,CMDLEN,stdin);
      if(line!=s)
	printf("fgets error\n");
      parse_line(line);
    }
    
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadMatrixf(m);
    
    frame_count++;
    
    // run all commands which have been stored in the queue
    while(!emptyp()){
      char*cmd=pop();
      if(0==strncmp(cmd,"swap",4)){
	struct timeval tv;
	gettimeofday(&tv,0);
	printf("q swap frame-count=%d sec=%lu usec=%lu\n",
	       frame_count,tv.tv_sec,tv.tv_usec);
	free(cmd);
	goto nextframe;
      }
      parse_line(cmd);
      printf("q cread=%5d cwrite=%5d cmd=%s\n",circread,circwrite,cmd);
      fflush(stdout);
      free(cmd);
    }
  nextframe:
    if(show_calibration_stripes){
      float v = 100+20*(frame_count%10);
      glRectf(v,0,v+2,400);    
    }
    
    glfwSleep(1./72);
    glfwSwapBuffers();
  }
  
  glfwCloseWindow();

  glfwTerminate();
  exit(EXIT_SUCCESS);
}
Example #10
0
int	main(int ac, char **av)
{
	check_stdin(ac, av);
}
Example #11
0
static int conf_choice(struct menu *menu)
{
    struct symbol *sym, *def_sym;
    struct menu *child;
    // int type; backported future linux patch to 2.6.30 to fix gcc4.6 compiler warning
    bool is_new;

    sym = menu->sym;
    // type = sym_get_type(sym); see backported comment above
    is_new = !sym_has_value(sym);
    if (sym_is_changable(sym)) {
        conf_sym(menu);
        sym_calc_value(sym);
        switch (sym_get_tristate_value(sym)) {
        case no:
            return 1;
        case mod:
            return 0;
        case yes:
            break;
        }
    } else {
        switch (sym_get_tristate_value(sym)) {
        case no:
            return 1;
        case mod:
            printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
            return 0;
        case yes:
            break;
        }
    }

    while (1) {
        int cnt, def;

        printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
        def_sym = sym_get_choice_value(sym);
        cnt = def = 0;
        line[0] = 0;
        for (child = menu->list; child; child = child->next) {
            if (!menu_is_visible(child))
                continue;
            if (!child->sym) {
                printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
                continue;
            }
            cnt++;
            if (child->sym == def_sym) {
                def = cnt;
                printf("%*c", indent, '>');
            } else
                printf("%*c", indent, ' ');
            printf(" %d. %s", cnt, _(menu_get_prompt(child)));
            if (child->sym->name)
                printf(" (%s)", child->sym->name);
            if (!sym_has_value(child->sym))
                printf(_(" (NEW)"));
            printf("\n");
        }
        printf(_("%*schoice"), indent - 1, "");
        if (cnt == 1) {
            printf("[1]: 1\n");
            goto conf_childs;
        }
        printf("[1-%d", cnt);
        if (menu_has_help(menu))
            printf("?");
        printf("]: ");
        switch (input_mode) {
        case ask_new:
        case ask_silent:
            if (!is_new) {
                cnt = def;
                printf("%d\n", cnt);
                break;
            }
            check_stdin();
        case ask_all:
            fflush(stdout);
            if (NULL == fgets(line, 128, stdin)) { //BRCM: check ret val to fix compiler warning
                printf("fgets failed, exiting\n");
                exit(2);
            }
            strip(line);
            if (line[0] == '?') {
                printf("\n%s\n", get_help(menu));
                continue;
            }
            if (!line[0])
                cnt = def;
            else if (isdigit(line[0]))
                cnt = atoi(line);
            else
                continue;
            break;
        default:
            break;
        }

conf_childs:
        for (child = menu->list; child; child = child->next) {
            if (!child->sym || !menu_is_visible(child))
                continue;
            if (!--cnt)
                break;
        }
        if (!child)
            continue;
        if (line[strlen(line) - 1] == '?') {
            printf("\n%s\n", get_help(child));
            continue;
        }
        sym_set_choice_value(sym, child->sym);
        for (child = child->list; child; child = child->next) {
            indent += 2;
            conf(child);
            indent -= 2;
        }
        return 1;
    }
}