Beispiel #1
0
ts::uint32 gui_filterbar_c::gm_handler(gmsg<ISOGM_CHANGED_SETTINGS>&ch)
{
    if (ch.pass == 0 && CFG_LANGUAGE == ch.sp)
    {
        if (option1)
        {
            show_options(false);
            show_options(true);
        }
        getengine().redraw();
    }

    return 0;
}
Beispiel #2
0
int main(int argc,char **argv)
{
  long i;
  char stdi=0;
  double min,max,maxmax;

  if (scan_help(argc,argv))
    show_options(argv[0]);
  
  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif

  infile=search_datafile(argc,argv,NULL,verbosity);
  if (infile == NULL)
    stdi=1;

  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".rec");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
      strcpy(outfile,"stdin.rec");
    }
  }
  if (!stdo)
    test_outfile(outfile);

  if (columns == NULL)
    series=(double**)get_multi_series(infile,&length,exclude,&dim,"",dimset,
                                      verbosity);
  else
    series=(double**)get_multi_series(infile,&length,exclude,&dim,columns,
                                      dimset,verbosity);

  maxmax=0.0;
  for (i=0;i<dim;i++) {
    rescale_data(series[i],length,&min,&max);
    if (max > maxmax)
      maxmax=max;
  }

  if (epsset)
    eps /= maxmax;

  check_alloc(list=(long*)malloc(sizeof(long)*length));
  check_alloc(box=(long**)malloc(sizeof(long*)*BOX));
  for (i=0;i<BOX;i++)
    check_alloc(box[i]=(long*)malloc(sizeof(long)*BOX));

  make_multi_box(series,box,list,length,BOX,dim,embed,delay,eps);
  lfind_neighbors();

  return 0;
}
Beispiel #3
0
//--------------------------------------------------------------------------
static bool idaapi menu_options_cb(void *ud)
{
  DECLARE_GI_VAR;
  if ( show_options() )
    gi->refresh();
  return true;
}
Beispiel #4
0
int main(int argc,char **argv)
{
  char stdi=0;
  unsigned int i,j;
  double rms,*av;

  if (scan_help(argc,argv))
    show_options(argv[0]);

  scan_options(argc,argv);

#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif

  infile=search_datafile(argc,argv,NULL,verbosity);
  if (infile == NULL)
    stdi=1;

  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".pca");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
      strcpy(outfile,"stdin.pca");
    }
  }
  if (!stout)
    test_outfile(outfile);

  if (column == NULL)
    series=(double**)get_multi_series(infile,&LENGTH,exclude,&DIM,"",dimset,
                                      verbosity);
  else
    series=(double**)get_multi_series(infile,&LENGTH,exclude,&DIM,column,
                                      dimset,verbosity);
  dimemb=DIM*EMB;
  if (!projection_set)
    LDIM=dimemb;
  else {
    if (LDIM < 1) LDIM=1;
    if (LDIM > dimemb) LDIM=dimemb;
  }

  check_alloc(av=(double*)malloc(sizeof(double)*DIM));
  for (j=0;j<DIM;j++) {
    av[j]=rms=0.0;
    variance(series[j],LENGTH,&av[j],&rms);
    for (i=0;i<LENGTH;i++)
      series[j][i] -= av[j];
  }
  make_pca(av);

  return 0;
}
int main(int argc, char * argv[])
{   char * in = 0;
    char * out = 0;
    {   char * s;
        int i = 1;
        while(1) {
            if (i >= argc) break;
            s = argv[i++];
            if (s[0] == '-') {
                if (eq(s, "-output") || eq(s, "-o")) {
                    if (i >= argc) {
                        fprintf(stderr, "%s requires an argument\n", s);
                        exit(1);
                    }
                    out = argv[i++];
                } else if (eq(s, "-help") || eq(s, "-h")) {
                    show_options(0);
                } else {
                    fprintf(stderr, "%s unknown\n", s);
                    show_options(1);
                }
            }
            else in = s;
        }
    }

    /* initialise the stemming process: */

    {
        struct SN_env * z = H_create_env();
        FILE * f_in;
        FILE * f_out;
        f_in = in == 0 ? stdin : fopen(in, "r");
        if (f_in == 0) {
            fprintf(stderr, "file %s not found\n", in); exit(1);
        }
        f_out = out == 0 ? stdout : fopen(out, "w");
        if (f_out == 0) {
            fprintf(stderr, "file %s cannot be opened\n", out); exit(1);
        }
        stem_file(z, f_in, f_out);
        H_close_env(z);
    }

    return 0;
}
Beispiel #6
0
int main(int argc, char* argv[]) {
  int i;
  for(i = 0; i < argc; i++) {
    printf("argv[%d] %s\n", i, argv[i]);
  }
  init_options(argc, argv);
  show_options();
  return 0;
}
Beispiel #7
0
void Client::show_options_menu() {
    if (!get_stack_count()) {
        old_player_name = player_config.get_player_name();
        old_player_skin = player_config.get_player_skin();
        show_options();
        if (me) {
            me->state.client_server_state.key_states = 0;
        }
    }
}
Beispiel #8
0
void CLI::start(int option) {
    if (option >= 0) {
        apply_option(option);
    } else {
        while (option != QUIT) {
            show_options();
            option = get_user_option();
            apply_option(option);
        }
    }
}
Beispiel #9
0
int
main (int argc, char *argv[])
{
	QFile      *bspfile;
	bsp_t      *bsp;
	image_t    *image;

	/* Enough args? */
	if (argc < 3) {
		show_help ();
		return 1;
	}

	/* Setup options */
	def_options (&options);
	get_options (&options, argc, argv);
	show_options (&options);

	bspfile = Qopen (options.bspf_name, "rbz");
	if (bspfile == NULL) {
		fprintf (stderr, "Error opening bsp file %s.\n", options.bspf_name);
		return 1;
	}
	bsp = LoadBSPFile (bspfile, Qfilesize (bspfile));
	Qclose (bspfile);

	image = render_map (bsp);
	BSP_Free (bsp);

	/* Write image */

	switch (options.outf_type) {
		case 0:
			write_pcx (image);
			break;
		case 1:
			write_png (image);
			break;
	}

	printf ("File written to %s.\n", options.outf_name);

	/* Close, done! */

	free (image->image);
	free (image);

	return 0;
}
Beispiel #10
0
static void select_game(char *emu, char *game)
{

	unsigned long ExKey;

	/* No Selected game */
	strcpy(game,"builtinn");

	/* Clean screen */
	pnd_video_flip();

	/* Wait until user selects a game */
	while(1)
	{
		game_list_view(&last_game_selected);
		pnd_video_flip();

		if( (pnd_joystick_read(0)&0x8c0ff55)) 
			pnd_timer_delay(100); 
		while(!(ExKey=pnd_joystick_read(0)&0x8c0ff55))
		{ 
			if ((ExKey & PND_L) && (ExKey & PND_R)) { pnd_exit(); }
		}

		if (ExKey & PND_UP) last_game_selected--;
		if (ExKey & PND_DOWN) last_game_selected++;
		if (ExKey & PND_L || ExKey & PND_LEFT) last_game_selected-=21;
		if (ExKey & PND_R || ExKey & PND_RIGHT) last_game_selected+=21;
		if ((ExKey & PND_L) && (ExKey & PND_R)) pnd_exit();

		if ((ExKey & PND_A) || (ExKey & PND_B) || (ExKey & PND_START))
		{
			/* Select the game */
			game_list_select(last_game_selected, game, emu);

			/* Emulation Options */
			if(show_options(game))
			{
				break;
			}
		}
	}
}
static void select_game(char *emu, char *game)
{

	unsigned long ExKey;

	/* No Selected game */
	strcpy(game,"builtinn");

	/* Clean screen */
	wiz_video_flip();

	/* Wait until user selects a game */
	while(1)
	{
		game_list_view(&last_game_selected);
		wiz_video_flip();

		if( (wiz_joystick_read(0)&0xFF0FC0)) 
			wiz_timer_delay(100000); 
		while(!(ExKey=wiz_joystick_read(0)&0xFF0FC0))
		{ 
			if ((ExKey & WIZ_L) && (ExKey & WIZ_R)) { wiz_exit(); }
		}

		if (ExKey & WIZ_UP) last_game_selected--;
		if (ExKey & WIZ_DOWN) last_game_selected++;
		if (ExKey & WIZ_L) last_game_selected-=21;
		if (ExKey & WIZ_R) last_game_selected+=21;
		if ((ExKey & WIZ_L) && (ExKey & WIZ_R)) wiz_exit();

		if ((ExKey & WIZ_A) || (ExKey & WIZ_B) || (ExKey & WIZ_MENU))
		{
			/* Select the game */
			game_list_select(last_game_selected, game, emu);

			/* Emulation Options */
			if(show_options(game))
			{
				break;
			}
		}
	}
}
Beispiel #12
0
static void
nest_options(const uint8_t *data, uint_t olen, char *prefix, char *title)
{
	char *str, *oldnest, *oldprefix;

	if (olen <= 0)
		return;
	oldprefix = prot_prefix;
	oldnest = prot_nest_prefix;
	str = malloc(strlen(prot_nest_prefix) + strlen(prot_prefix) + 1);
	if (str == NULL) {
		prot_nest_prefix = prot_prefix;
	} else {
		(void) sprintf(str, "%s%s", prot_nest_prefix, prot_prefix);
		prot_nest_prefix = str;
	}
	show_header(prefix, title, 0);
	show_options(data, olen);
	free(str);
	prot_prefix = oldprefix;
	prot_nest_prefix = oldnest;
}
Beispiel #13
0
int main(int argc,char** argv)
{
  char stdi=0;
  unsigned long i,j;
  double av=0.0,*sigmax;
  FILE *fout;

  if (scan_help(argc,argv))
    show_options(argv[0]);

  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif

  if (!justcreate) {
    infile=search_datafile(argc,argv,NULL,verbosity);
    if (infile == NULL)
      stdi=1;
  }
  else
    stdi=1;

  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".noi");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
      strcpy(outfile,"stdin.noi");
    }
  }
  if (!stout)
    test_outfile(outfile);

  if (!justcreate) {
    if (column == NULL)
      array=(double**)get_multi_series(infile,&length,exclude,&dim,"",dimset,
				       verbosity);
    else
      array=(double**)get_multi_series(infile,&length,exclude,&dim,column,
				       dimset,verbosity);
  }
  else {
    check_alloc(array=(double**)malloc(sizeof(double*)*dim));
    for (i=0;i<dim;i++) {
      check_alloc(array[i]=(double*)malloc(sizeof(double)*length));
      for (j=0;j<length;j++)
	array[i][j]=0.0;
    }
  }

  check_alloc(sigmax=(double*)malloc(sizeof(double)*dim));

  if (!absolute) {
    for (j=0;j<dim;j++)
      variance(array[j],length,&av,&sigmax[j]);
  }

  rnd_init(iseed);

  for (i=0;i<10000;i++) rnd_1279();

  for (j=0;j<dim;j++) {
    if (!cgaussian)
      equidistri(sigmax[j],j);
    else
      gauss(sigmax[j],j);
  }

  if (!stout) {
    fout=fopen(outfile,"w");
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Opened %s for writing\n",outfile);
    for (i=0;i<length;i++) {
      for (j=0;j<dim-1;j++)
	fprintf(fout,"%e ",array[j][i]);
      fprintf(fout,"%e\n",array[dim-1][i]);
    }
    fclose(fout);
  }
  else {
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Writing to stdout\n");
    for (i=0;i<length;i++) {
      for (j=0;j<dim-1;j++)
	fprintf(stdout,"%e ",array[j][i]);
      fprintf(stdout,"%e\n",array[dim-1][i]);
    }
  }

  for (i=0;i<dim;i++)
    free(array[i]);
  free(array);
  free(sigmax);
  if (outfile != NULL)
    free(outfile);
  if (infile != NULL)
    free(infile);
  if (column != NULL)
    free(column);

  return 0;
}
static void select_game(char *emu, char *game)
{

	unsigned long ExKey;

	/* No Selected game */
	strcpy(game,"builtinn");

	/* Clean screen */
	gp2x_video_flip();


	while(ExKey=gp2x_joystick_read(0)&0x8c0ff55){
		gp2x_video_flip();
		gp2x_timer_delay(1);
	};

	/* Wait until user selects a game */
	while(1)
	{
		game_list_view(&last_game_selected);
		gp2x_video_flip();

		gp2x_timer_delay(100);
       	ExKey=gp2x_joystick_read(0);

		if (ExKey & GP2X_UP) last_game_selected--;
		else if (ExKey & GP2X_DOWN) last_game_selected++;
		else if ((ExKey & GP2X_L) || ExKey & GP2X_LEFT) last_game_selected-=21;
		else if ((ExKey & GP2X_R) || ExKey & GP2X_RIGHT) last_game_selected+=21;
		//if ((ExKey & GP2X_L) && (ExKey & GP2X_R)) gp2x_exit();

		if (((ExKey & GP2X_A) || (ExKey & GP2X_B) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START)) && game_num_avail!=0)
		{
			/* Select the game */
			game_list_select(last_game_selected, game, emu);

			/* Emulation Options */
			//defaults!

			m4all_video_aspect=0;
			m4all_video_rotate=0;
			m4all_video_sync=0;
			m4all_frameskip=-1;
			m4all_cheat=0;
            m4all_waysStick = 8;

			m4all_sound = 4;
			m4all_video_depth=16;

			if(m4all_HiSpecs)
			{
				m4all_clock_cpu= 100;
				m4all_clock_sound= 100;
				m4all_buttons=2;
				m4all_sound=12;
			}
			else
			{
				m4all_clock_cpu= 80;
				m4all_clock_sound= 80;
				m4all_buttons=2;
			}

			if(show_options(game))
			{
				break;
			}
		}

	}
}
Beispiel #15
0
int main(int argc,char **argv)
{
  char stdi=0;
  double *pm;
  long i,j;
  FILE *file;
  double **mat,**inverse,*vec,**coeff,**diff,avpm;
  
  if (scan_help(argc,argv))
    show_options(argv[0]);
  
  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif

  infile=search_datafile(argc,argv,NULL,verbosity);
  if (infile == NULL)
    stdi=1;

  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+4,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".ar");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)9,(size_t)1));
      strcpy(outfile,"stdin.ar");
    }
  }
  if (!stdo)
    test_outfile(outfile);

  if (column == NULL)
    series=(double**)get_multi_series(infile,&length,exclude,&dim,"",dimset,
				      verbosity);
  else
    series=(double**)get_multi_series(infile,&length,exclude,&dim,column,
				      dimset,verbosity);

  check_alloc(my_average=(double*)malloc(sizeof(double)*dim));
  set_averages_to_zero();

  if (poles >= length) {
    fprintf(stderr,"It makes no sense to have more poles than data! Exiting\n");
    exit(AR_MODEL_TOO_MANY_POLES);
  }
  
  
  check_alloc(vec=(double*)malloc(sizeof(double)*poles*dim));
  check_alloc(mat=(double**)malloc(sizeof(double*)*poles*dim));
  for (i=0;i<poles*dim;i++)
    check_alloc(mat[i]=(double*)malloc(sizeof(double)*poles*dim));

  check_alloc(coeff=(double**)malloc(sizeof(double*)*dim));
  inverse=build_matrix(mat);
  for (i=0;i<dim;i++) {
    build_vector(vec,i);
    coeff[i]=multiply_matrix_vector(inverse,vec);
  }

  check_alloc(diff=(double**)malloc(sizeof(double*)*dim));
  for (i=0;i<dim;i++)
    check_alloc(diff[i]=(double*)malloc(sizeof(double)*length));

  pm=make_residuals(diff,coeff);
  
  if (stdo) {
    avpm=pm[0]*pm[0];
    for (i=1;i<dim;i++)
      avpm += pm[i]*pm[i];
    avpm=sqrt(avpm/dim);
    printf("#average forcast error= %e\n",avpm);
    printf("#individual forecast errors: ");
    for (i=0;i<dim;i++)
      printf("%e ",pm[i]);
    printf("\n");
    for (i=0;i<dim*poles;i++) {
      printf("# ");
      for (j=0;j<dim;j++)
	printf("%e ",coeff[j][i]);
      printf("\n");
    }
    if (!run_model || (verbosity&VER_USR1)) {
      for (i=poles;i<length;i++) {
	if (run_model)
	  printf("#");
	for (j=0;j<dim;j++)
	  if (verbosity&VER_USR2)
	    printf("%e %e ",series[j][i]+my_average[j],diff[j][i]);
	  else
	    printf("%e ",diff[j][i]);
	printf("\n");
      }
    }
    if (run_model && (ilength > 0))
      iterate_model(coeff,pm,NULL);
  }
  else {
    file=fopen(outfile,"w");
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Opened %s for output\n",outfile);
    avpm=pm[0]*pm[0];
    for (i=1;i<dim;i++)
      avpm += pm[i]*pm[i];
    avpm=sqrt(avpm/dim);
    fprintf(file,"#average forcast error= %e\n",avpm);
    fprintf(file,"#individual forecast errors: ");
    for (i=0;i<dim;i++)
      fprintf(file,"%e ",pm[i]);
    fprintf(file,"\n");
    for (i=0;i<dim*poles;i++) {
      fprintf(file,"# ");
      for (j=0;j<dim;j++)
	fprintf(file,"%e ",coeff[j][i]);
      fprintf(file,"\n");
    }
    if (!run_model || (verbosity&VER_USR1)) {
      for (i=poles;i<length;i++) {
	if (run_model)
	  fprintf(file,"#");
	for (j=0;j<dim;j++)
	  if (verbosity&VER_USR2)
	    fprintf(file,"%e %e ",series[j][i]+my_average[j],diff[j][i]);
	  else
	    fprintf(file,"%e ",diff[j][i]);
	fprintf(file,"\n");
      }
    }
    if (run_model && (ilength > 0))
      iterate_model(coeff,pm,file);
    fclose(file);
  }

  if (outfile != NULL)
    free(outfile);
  if (infile != NULL)
    free(infile);
  free(vec);
  for (i=0;i<poles*dim;i++) {
    free(mat[i]);
    free(inverse[i]);
  }
  free(mat);
  free(inverse);
  for (i=0;i<dim;i++) {
    free(coeff[i]);
    free(diff[i]);
  }
  free(coeff);
  free(diff);
  free(pm);

  return 0;
}
Beispiel #16
0
int main(int argc,char **argv)
{
  char stdi=0,*done,alldone;
  int i;
  long n;
  long maxlength;
  double min,max;
  FILE *file;
  
  if (scan_help(argc,argv))
    show_options(argv[0]);

  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif

  infile=search_datafile(argc,argv,&column,verbosity);
  if (infile == NULL)
    stdi=1;

  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".ros");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
      strcpy(outfile,"stdin.ros");
    }
  }
  test_outfile(outfile);

  series=(double*)get_series(infile,&length,exclude,column,verbosity);
  rescale_data(series,length,&min,&max);

  if (epsset)
    eps0 /= max;

  check_alloc(list=(long*)malloc(length*sizeof(long)));
  check_alloc(lyap=(double*)malloc((steps+1)*sizeof(double)));
  check_alloc(found=(long*)malloc((steps+1)*sizeof(long)));
  check_alloc(done=(char*)malloc(length));

  for (i=0;i<=steps;i++) {
    lyap[i]=0.0;
    found[i]=0;
  }
  for (i=0;i<length;i++)
    done[i]=0;
  
  maxlength=length-delay*(dim-1)-steps-1-mindist;
  alldone=0;
  file=fopen(outfile,"w");
  if (verbosity&VER_INPUT)
    fprintf(stderr,"Opened %s for writing\n",outfile);
  for (eps=eps0;!alldone;eps*=1.1) {
    epsinv=1.0/eps;
    put_in_boxes();
    alldone=1;
    for (n=0;n<=maxlength;n++) {
      if (!done[n])
	done[n]=make_iterate(n);
      alldone &= done[n];
    }
    if (verbosity&VER_USR1)
      fprintf(stderr,"epsilon: %e already found: %ld\n",eps*max,found[0]);
  } 
  for (i=0;i<=steps;i++)
    if (found[i])
      fprintf(file,"%d %e\n",i,lyap[i]/found[i]/2.0);
  fclose(file);

  return 0;
}
Beispiel #17
0
static void
show_help(void)
{
    const tw_optdef **group = all_groups;
    unsigned cnt = 0;

    fprintf(stderr, "usage: %s [options] [-- [args]]\n", program);
    fputc('\n', stderr);

    for (; *group; group++)
    {
        const tw_optdef *def = *group;
        for (; def->type; def++)
        {
            int pos = 0;

            if (def->type == TWOPTTYPE_GROUP)
            {
                if (cnt)
                    fputc('\n', stderr);
                fprintf(stderr, "%s:\n", def->help);
                cnt++;
                continue;
            }

            pos += fprintf(stderr, "  --%s", def->name);
            switch (def->type)
            {
            case TWOPTTYPE_ULONG:
            case TWOPTTYPE_UINT:
                pos += fprintf(stderr, "=n");
                break;

            case TWOPTTYPE_STIME:
                pos += fprintf(stderr, "=ts");
                break;

            case TWOPTTYPE_CHAR:
                pos += fprintf(stderr, "=str");
                break;

            default:
                break;
            }

            if (def->help)
            {
                int col = 22;
                int pad = col - pos;
                if (pad > 0)
                    fprintf(stderr, "%*s", col - pos, "");
                else {
                    fputc('\n', stderr);
                    fprintf(stderr, "%*s", col, "");
                }
                fputs("  ", stderr);
                fputs(def->help, stderr);
            }

            if (def->value)
            {
                switch (def->type)
                {
                case TWOPTTYPE_ULONG:
                    fprintf(stderr, " (default %lu)", *((unsigned long*)def->value));
                    break;

                case TWOPTTYPE_UINT:
                    fprintf(stderr, " (default %u)", *((unsigned int*)def->value));
                    break;

                case TWOPTTYPE_STIME:
                    fprintf(stderr, " (default %.2f)", *((tw_stime*)def->value));
                    break;

                case TWOPTTYPE_CHAR:
                    fprintf(stderr, " (default %s)", (char *) def->value);
                    break;

                default:
                    break;
                }
            }

            fputc('\n', stderr);
            cnt++;
        }
    }

    show_options();
}
Beispiel #18
0
int
main(int argc, char **argv)
{
    time_t cur_time;
    pthread_t signal_thread;
    pthread_t reader_thread;
    pthread_t ipc_thread;
    QUEUE_T *p_queue = create_queue(MAX_QUEUE);
    BUFSZ   *bufptr;
    decoder *decoder = NULL;
    splitter *splitter = NULL;
    static thread_data tdata;
    decoder_options dopt = {
        4,  /* round */
        0,  /* strip */
        0   /* emm */
    };
    tdata.dopt = &dopt;
    tdata.lnb = 0;
    tdata.tfd = -1;

    int result;
    int option_index;
    struct option long_options[] = {
#ifdef HAVE_LIBARIB25
        { "b25",       0, NULL, 'b'},
        { "B25",       0, NULL, 'b'},
        { "round",     1, NULL, 'r'},
        { "strip",     0, NULL, 's'},
        { "emm",       0, NULL, 'm'},
        { "EMM",       0, NULL, 'm'},
#endif
        { "LNB",       1, NULL, 'n'},
        { "lnb",       1, NULL, 'n'},
        { "udp",       0, NULL, 'u'},
        { "addr",      1, NULL, 'a'},
        { "port",      1, NULL, 'p'},
        { "http",      1, NULL, 'H'},
        { "dev",       1, NULL, 'd'},
        { "help",      0, NULL, 'h'},
        { "version",   0, NULL, 'v'},
        { "sid",       1, NULL, 'i'},
        { "tsid",      1, NULL, 't'},
        { "lch",       0, NULL, 'c'},
        {0, 0, NULL, 0} /* terminate */
    };

    boolean use_b25 = FALSE;
    boolean use_udp = FALSE;
    boolean use_http = FALSE;
    boolean fileless = FALSE;
    boolean use_stdout = FALSE;
    boolean use_splitter = FALSE;
    boolean use_lch = FALSE;
    char *host_to = NULL;
    int port_to = 1234;
    int port_http = 12345;
    sock_data *sockdata = NULL;
    int dev_num = 0;
    int val;
    char *voltage[] = {"0V", "11V", "15V"};
    char *sid_list = NULL;
    unsigned int tsid = 0;
	int connected_socket, listening_socket;
	unsigned int len;
	char *channel, *pch = NULL;

    while((result = getopt_long(argc, argv, "br:smn:ua:H:p:d:hvitcl:",
                                long_options, &option_index)) != -1) {
        switch(result) {
        case 'b':
            use_b25 = TRUE;
            fprintf(stderr, "using B25...¥n");
            break;
        case 's':
            dopt.strip = TRUE;
            fprintf(stderr, "enable B25 strip¥n");
            break;
        case 'm':
            dopt.emm = TRUE;
            fprintf(stderr, "enable B25 emm processing¥n");
            break;
        case 'u':
            use_udp = TRUE;
            host_to = "localhost";
            fprintf(stderr, "enable UDP broadcasting¥n");
            break;
        case 'H':
            use_http = TRUE;
            port_http = atoi(optarg);
            fprintf(stderr, "creating a http daemon¥n");
            break;
        case 'h':
            fprintf(stderr, "¥n");
            show_usage(argv[0]);
            fprintf(stderr, "¥n");
            show_options();
            fprintf(stderr, "¥n");
            exit(0);
            break;
        case 'v':
            fprintf(stderr, "%s %s¥n", argv[0], version);
            fprintf(stderr, "recorder command for DVB tuner.¥n");
            exit(0);
            break;
        /* following options require argument */
        case 'n':
            val = atoi(optarg);
            switch(val) {
            case 11:
                tdata.lnb = 1;
                break;
            case 15:
                tdata.lnb = 2;
                break;
            default:
                tdata.lnb = 0;
                break;
            }
            fprintf(stderr, "LNB = %s¥n", voltage[tdata.lnb]);
            break;
        case 'r':
            dopt.round = atoi(optarg);
            fprintf(stderr, "set round %d¥n", dopt.round);
            break;
        case 'a':
            use_udp = TRUE;
            host_to = optarg;
            fprintf(stderr, "UDP destination address: %s¥n", host_to);
            break;
        case 'p':
            port_to = atoi(optarg);
            fprintf(stderr, "UDP port: %d¥n", port_to);
            break;
        case 'd':
            dev_num = atoi(optarg);
            fprintf(stderr, "using device: /dev/dvb/adapter%d¥n", dev_num);
            break;
        case 'i':
            use_splitter = TRUE;
            sid_list = optarg;
            break;
        case 't':
            tsid = atoi(optarg);
            if(strlen(optarg) > 2){
                if((optarg[0] == '0') && ((optarg[1] == 'X') ||(optarg[1] == 'x'))){
                    sscanf(optarg+2, "%x", &tsid);
                }
            }
            fprintf(stderr, "tsid = 0x%x¥n", tsid);
            break;
	case 'c':
	    use_lch = TRUE;
	    break;
        }
    }

if(use_http){	// http-server add-
	fprintf(stderr, "run as a daemon..¥n");
	if(daemon(1,1)){
		perror("failed to start");
		return 1;
	}
	fprintf(stderr, "pid = %d¥n", getpid());

	struct sockaddr_in sin;
	int ret;
	int sock_optval = 1;
		
	listening_socket = socket(AF_INET, SOCK_STREAM, 0);
	if ( listening_socket == -1 ){
		perror("socket");
		return 1;
	}
		
	if ( setsockopt(listening_socket, SOL_SOCKET, SO_REUSEADDR,
			&sock_optval, sizeof(sock_optval)) == -1 ){
		perror("setsockopt");
		return 1;
	}
		
	sin.sin_family = AF_INET;
	sin.sin_port = htons(port_http);
	sin.sin_addr.s_addr = htonl(INADDR_ANY);

		
	if ( bind(listening_socket, (struct sockaddr *)&sin, sizeof(sin)) < 0 ){
		perror("bind");
		return 1;
	}
		
	ret = listen(listening_socket, SOMAXCONN);
	if ( ret == -1 ){
		perror("listen");
		return 1;
	}
	fprintf(stderr,"listening at port %d¥n", port_http);
	//set rectime to the infinite
	if(parse_time("-",&tdata.recsec) != 0){
		return 1;
	}
	if(tdata.recsec == -1)
		tdata.indefinite = TRUE;
}else{	// -http-server add
    if(argc - optind < 3) {
        if(argc - optind == 2 && use_udp) {
            fprintf(stderr, "Fileless UDP broadcasting¥n");
            fileless = TRUE;
            tdata.wfd = -1;
        }
        else {
            fprintf(stderr, "Some required parameters are missing!¥n");
            fprintf(stderr, "Try '%s --help' for more information.¥n", argv[0]);
            return 1;
        }
    }

    fprintf(stderr, "pid = %d¥n", getpid());

    if(use_lch){
        set_lch(argv[optind], &pch, &sid_list, &tsid);
        if(sid_list) use_splitter = TRUE;
        fprintf(stderr, "tsid = 0x%x¥n", tsid);
    }
    if(pch == NULL) pch = argv[optind];

    /* tune */
    if(tune(pch, &tdata, dev_num, tsid) != 0)
        return 1;

    /* set recsec */
    if(parse_time(argv[optind + 1], &tdata.recsec) != 0) // no other thread --yaz
        return 1;

    if(tdata.recsec == -1)
        tdata.indefinite = TRUE;

    /* open output file */
    char *destfile = argv[optind + 2];
    if(destfile && !strcmp("-", destfile)) {
        use_stdout = TRUE;
        tdata.wfd = 1; /* stdout */
    }
    else {
        if(!fileless) {
            int status;
            char *path = strdup(argv[optind + 2]);
            char *dir = dirname(path);
            status = mkpath(dir, 0777);
            if(status == -1)
                perror("mkpath");
            free(path);

            tdata.wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666);
            if(tdata.wfd < 0) {
                fprintf(stderr, "Cannot open output file: %s¥n",
                        argv[optind + 2]);
                return 1;
            }
        }
    }
}	// http-server add

    /* initialize decoder */
    if(use_b25) {
        decoder = b25_startup(&dopt);
        if(!decoder) {
            fprintf(stderr, "Cannot start b25 decoder¥n");
            fprintf(stderr, "Fall back to encrypted recording¥n");
            use_b25 = FALSE;
        }
    }

while(1){	// http-server add-
	if(use_http){
		struct hostent *peer_host;
		struct sockaddr_in peer_sin;
		pch = NULL;
		sid_list = NULL;

		len = sizeof(peer_sin);

		connected_socket = accept(listening_socket, (struct sockaddr *)&peer_sin, &len);
		if ( connected_socket == -1 ){
			perror("accept");
			return 1;
		}

		peer_host = gethostbyaddr((char *)&peer_sin.sin_addr.s_addr,
				  sizeof(peer_sin.sin_addr), AF_INET);
		if ( peer_host == NULL ){
			fprintf(stderr, "gethostbyname failed¥n");
			return 1;
		}

		fprintf(stderr,"connect from: %s [%s] port %d¥n", peer_host->h_name, inet_ntoa(peer_sin.sin_addr), ntohs(peer_sin.sin_port));

		char buf[256];
		read_line(connected_socket, buf);
		fprintf(stderr,"request command is %s¥n",buf);
		char s0[256],s1[256],s2[256];
		sscanf(buf,"%s%s%s",s0,s1,s2);
		char delim[] = "/";
		channel = strtok(s1,delim);
		char *sidflg = strtok(NULL,delim);
		if(sidflg)
			sid_list = sidflg;
		if(use_lch)
			set_lch(channel, &pch, &sid_list, &tsid);
		if(pch == NULL) pch = channel;
		fprintf(stderr,"channel is %s¥n",channel);

		if(sid_list == NULL){
			use_splitter = FALSE;
			splitter = NULL;
		}else if(!strcmp(sid_list,"all")){
			use_splitter = FALSE;
			splitter = NULL;
		}else{
			use_splitter = TRUE;
		}
	}	// -http-server add

    /* initialize splitter */
    if(use_splitter) {
        splitter = split_startup(sid_list);
        if(splitter->sid_list == NULL) {
            fprintf(stderr, "Cannot start TS splitter¥n");
            return 1;
        }
    }

	if(use_http){	// http-server add-
		char header[100];
		if(use_b25) {
			strcpy(header, "HTTP/1.1 200 OK¥r¥nContent-Type: video/mpeg¥r¥nCache-Control: no-cache¥r¥n¥r¥n");
		}else if(!strcmp(sid_list,"1seg")){
			strcpy(header, "HTTP/1.1 200 OK¥r¥nContent-Type: video/mpeg¥r¥nCache-Control: no-cache¥r¥n¥r¥n");
		}else{
			strcpy(header, "HTTP/1.1 200 OK¥r¥nContent-Type: application/octet-stream¥r¥nCache-Control: no-cache¥r¥n¥r¥n");
		}
		write(connected_socket, header, strlen(header));

		//set write target to http
		tdata.wfd = connected_socket;

		//tune
		if(tune(pch, &tdata, dev_num, tsid) != 0){
			fprintf(stderr, "Tuner cannot start recording¥n");
			continue;
		}
	}else{	// -http-server add
    /* initialize udp connection */
    if(use_udp) {
      sockdata = calloc(1, sizeof(sock_data));
      struct in_addr ia;
      ia.s_addr = inet_addr(host_to);
      if(ia.s_addr == INADDR_NONE) {
            struct hostent *hoste = gethostbyname(host_to);
            if(!hoste) {
                perror("gethostbyname");
                return 1;
            }
            ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]);
        }
        if((sockdata->sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
            perror("socket");
            return 1;
        }

        sockdata->addr.sin_family = AF_INET;
        sockdata->addr.sin_port = htons (port_to);
        sockdata->addr.sin_addr.s_addr = ia.s_addr;

        if(connect(sockdata->sfd, (struct sockaddr *)&sockdata->addr,
                   sizeof(sockdata->addr)) < 0) {
            perror("connect");
            return 1;
        }
    }
	}	// http-server add
    /* prepare thread data */
    tdata.queue = p_queue;
    tdata.decoder = decoder;
    tdata.splitter = splitter;
    tdata.sock_data = sockdata;
    tdata.tune_persistent = FALSE;

    /* spawn signal handler thread */
    init_signal_handlers(&signal_thread, &tdata);

    /* spawn reader thread */
    tdata.signal_thread = signal_thread;
    pthread_create(&reader_thread, NULL, reader_func, &tdata);

    /* spawn ipc thread */
    key_t key;
    key = (key_t)getpid();

    if ((tdata.msqid = msgget(key, IPC_CREAT | 0666)) < 0) {
        perror("msgget");
    }
    pthread_create(&ipc_thread, NULL, mq_recv, &tdata);
    fprintf(stderr, "¥nRecording...¥n");

    time(&tdata.start_time);

    /* read from tuner */
    while(1) {
        if(f_exit)
            break;

        time(&cur_time);
        bufptr = malloc(sizeof(BUFSZ));
        if(!bufptr) {
            f_exit = TRUE;
            break;
        }
        bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE);
        if(bufptr->size <= 0) {
            if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) {
                f_exit = TRUE;
                enqueue(p_queue, NULL);
                break;
            }
            else {
                free(bufptr);
                continue;
            }
        }
        enqueue(p_queue, bufptr);

        /* stop recording */
        time(&cur_time);
        if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) {
            break;
        }
    }

    /* delete message queue*/
    msgctl(tdata.msqid, IPC_RMID, NULL);

    pthread_kill(signal_thread, SIGUSR1);

    /* wait for threads */
    pthread_join(reader_thread, NULL);
    pthread_join(signal_thread, NULL);
    pthread_join(ipc_thread, NULL);

    /* close tuner */
    if(close_tuner(&tdata) != 0)
        return 1;

    /* release queue */
    destroy_queue(p_queue);
	if(use_http){	// http-server add-
		//reset queue
		p_queue = create_queue(MAX_QUEUE);

		/* close http socket */
		close(tdata.wfd);

		fprintf(stderr,"connection closed. still listening at port %d¥n",port_http);
		f_exit = FALSE;
	}else{	// -http-server add
    /* close output file */
	if(!use_stdout){
		fsync(tdata.wfd);
        close(tdata.wfd);
	}

    /* free socket data */
    if(use_udp) {
        close(sockdata->sfd);
        free(sockdata);
    }

    /* release decoder */
    if(!use_http)
    if(use_b25) {
        b25_shutdown(decoder);
    }
	}	// http-server add
    if(use_splitter) {
        split_shutdown(splitter);
    }

	if(!use_http)	// http-server add
    return 0;
}	// http-server add
}
Beispiel #19
0
int main(int argc,char **argv)
{
  char stin=0;
  unsigned long i;
  int j,k;
  unsigned int alldim,maxemb,emb,rundel,delsum,runmdel;
  unsigned int *inddelay;
  FILE *fout;

  if (scan_help(argc,argv))
    show_options(argv[0]);

  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif


  infile=search_datafile(argc,argv,NULL,verbosity);
  if (infile == NULL)
    stin=1;

  if (outfile == NULL) {
    if (!stin) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,1));
      strcpy(outfile,infile);
      strcat(outfile,".del");
    }
    else {
      check_alloc(outfile=(char*)calloc(10,1));
      strcpy(outfile,"stdin.del");
    }
  }
  if (!stdo)
    test_outfile(outfile);

  if (delayset && mdelayset) {
    fprintf(stderr,"-d and -D can't be used simultaneously. Exiting!\n");
    exit(DELAY_INCONS_d_D);
  }

  if (delay < 1) {
    fprintf(stderr,"Delay has to be larger than 0. Exiting!\n");
    exit(DELAY_SMALL_ZERO);
  }

  if (!formatset && (embdim%indim)) {
    fprintf(stderr,"Inconsistent -m and -M. Please set -F\n");
    exit(DELAY_INCONS_m_M);
  }
  if (formatset) {
    create_format_list();
  }
  else {
    check_alloc(formatlist=(unsigned int*)malloc(sizeof(int)*indim));
    for (i=0;i<indim;i++) {
      formatlist[i]=embdim/indim;
    }
  }

  alldim=0;
  for (i=0;i<indim;i++)
    alldim += formatlist[i];

  if (mdelayset) {
    create_delay_list();
  }

  check_alloc(inddelay=(unsigned int*)malloc(sizeof(int)*alldim));

  rundel=0;
  if (!mdelayset) {
    for (i=0;i<indim;i++) {
      delsum=0;
      inddelay[rundel++]=delsum;
      for (j=1;j<formatlist[i];j++) {
	delsum += delay;
	inddelay[rundel++]=delsum;
      }
    }
  }
  else {
    runmdel=0;
    for (i=0;i<indim;i++) {
      delsum=0;
      inddelay[rundel++]=delsum;
      for (j=1;j<formatlist[i];j++) {
	delsum += delaylist[runmdel++];
	inddelay[rundel++]=delsum;
      }
    }
  }

  maxemb=0;
  for (i=0;i<alldim;i++)
    maxemb=(maxemb<inddelay[i])?inddelay[i]:maxemb;

  if (column == NULL) {
    series=get_multi_series(infile,&length,exclude,&indim,"",dimset,verbosity);
  }
  else {
    series=get_multi_series(infile,&length,exclude,&indim,column,dimset,
			    verbosity);
  }

  if (stdo) {
    if (verbosity)
      fprintf(stderr,"Writing to stdout\n");
    for (i=maxemb;i<length;i++) {
      rundel=0;
      for (j=0;j<indim;j++) {
	emb=formatlist[j];
	for (k=0;k<emb;k++)
	  fprintf(stdout,"%e ",series[j][i-inddelay[rundel++]]);
      }
      fprintf(stdout,"\n");
    }
  }
  else {
    fout=fopen(outfile,"w");
    if (verbosity)
      fprintf(stderr,"Opened %s for writing\n",outfile);
    for (i=maxemb;i<length;i++) {
      for (j=0;j<indim;j++) {
	rundel=0;
	emb=formatlist[j];
	for (k=0;k<emb;k++)
	  fprintf(fout,"%e ",series[j][i-inddelay[rundel++]]);
      }
      fprintf(fout,"\n");
    }
    fclose(fout);
  }

  if (formatlist != NULL)
    free(formatlist);
  if (delaylist != NULL)
    free(delaylist);
  free(inddelay);

  return 0;
}
Beispiel #20
0
int main(int argc,char **argv)
{
  char stdi=0,done;
  long i,j,hdim,actfound;
  unsigned long count=1;
  double *swap,*newcast,maxinterval,*min,*interval,dummy,epsilon0;
  FILE *file=NULL;
  
  if (scan_help(argc,argv))
    show_options(argv[0]);
  
  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif
  
  infile=search_datafile(argc,argv,NULL,verbosity);
  if (infile == NULL)
    stdi=1;
  
  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".lzr");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
      strcpy(outfile,"stdin.lzr");
    }
  }
  if (!onscreen)
    test_outfile(outfile);
  
  hdim=(embed-1)*DELAY+1;
  if (column == NULL)
    series=(double**)get_multi_series(infile,&LENGTH,exclude,&dim,"",dimset,
				      verbosity);
  else
    series=(double**)get_multi_series(infile,&LENGTH,exclude,&dim,column,
				      dimset,verbosity);

  dim1=dim-1;

  check_alloc(min=(double*)malloc(sizeof(double)*dim));
  check_alloc(interval=(double*)malloc(sizeof(double)*dim));
  check_alloc(var=(double*)malloc(sizeof(double)*dim));

  maxinterval=0.0;

  for (i=0;i<dim;i++) {
    rescale_data(series[i],LENGTH,&min[i],&interval[i]);
    variance(series[i],LENGTH,&dummy,&var[i]);
    if (interval[i] > maxinterval)
      maxinterval=interval[i];
  }

  if (epsset)
    EPS0 /= maxinterval;
    
  check_alloc(cast=(double**)malloc(sizeof(double*)*hdim));
  for (i=0;i<hdim;i++)
    check_alloc(cast[i]=(double*)malloc(sizeof(double)*dim));
  check_alloc(newcast=(double*)malloc(sizeof(double)*dim));
  check_alloc(newav=(double*)malloc(sizeof(double)*dim));
    
  check_alloc(list=(long*)malloc(sizeof(long)*LENGTH));
  check_alloc(found=(long*)malloc(sizeof(long)*LENGTH));
  check_alloc(abstand=(double*)malloc(sizeof(double)*LENGTH));
  check_alloc(box=(long**)malloc(sizeof(long*)*NMAX));
  for (i=0;i<NMAX;i++)
    check_alloc(box[i]=(long*)malloc(sizeof(long)*NMAX));
  
  check_alloc(vec=(double*)malloc(sizeof(double)*dim));
  check_alloc(hsum=(double*)malloc(sizeof(double)*dim));
  check_alloc(mat=(double**)malloc(sizeof(double*)*dim));
  for (i=0;i<dim;i++) {
    check_alloc(mat[i]=(double*)malloc(sizeof(double)*dim));
  }

  for (j=0;j<dim;j++)
    for (i=0;i<hdim;i++)
      cast[i][j]=series[j][LENGTH-hdim+i];

  indexes=make_multi_index(dim,embed,DELAY);
  
  if (!onscreen) {
    file=fopen(outfile,"w");
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Opened %s for writing\n",outfile);
  }
  else {
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Writing to stdout\n");
  }

  rnd_init(seed);

  epsilon0=EPS0/EPSF;

  if (setnoise) 
    Q /= 100.0;

  for (i=0;i<FLENGTH;i++) {
    done=0;
    if (setsort)
      epsilon= epsilon0/((double)count*EPSF);
    else
      epsilon=epsilon0;
    while (!done) {
      epsilon*=EPSF;
      put_in_boxes();
      actfound=hfind_neighbors();
      if (actfound >= MINN) {
	if (setsort) {
	  epsilon0 += epsilon;
	  count++;
	  sort(actfound);
	  actfound=MINN;
	}
	make_zeroth(actfound,newcast);
	if (onscreen) {
	  for (j=0;j<dim-1;j++)
	    printf("%e ",newcast[j]*interval[j]+min[j]);
	  printf("%e\n",newcast[dim-1]*interval[dim-1]+min[dim-1]);
	  fflush(stdout);
	}
	else {
	  for (j=0;j<dim-1;j++)
	    fprintf(file,"%e ",newcast[j]*interval[j]+min[j]);
	  fprintf(file,"%e\n",newcast[dim-1]*interval[dim-1]+min[dim-1]);
	  fflush(file);
	}
	done=1;
	swap=cast[0];
	for (j=0;j<hdim-1;j++)
	  cast[j]=cast[j+1];
	cast[hdim-1]=swap;
	for (j=0;j<dim;j++)
	  cast[hdim-1][j]=newcast[j];
      }
    }
  }
  if (!onscreen)
    fclose(file);
  
  if (outfile != NULL)
    free(outfile);
  for (i=0;i<dim;i++)
    free(mat[i]);
  free(mat);
  for (i=0;i<hdim;i++)
    free(cast[i]);
  free(cast);
  free(newcast);
  free(found);
  free(list);
  for (i=0;i<NMAX;i++)
    free(box[i]);
  free(box);
  free(vec);
  free(newav);
  for (i=0;i<dim;i++)
    free(series[i]);
  free(series);

  return 0;
}
bool game::opening_screen()
{
    world_generator->set_active_world(NULL);
    // This actually _loads_ what worlds exist.
    world_generator->get_all_worlds();

    WINDOW *w_background = newwin(TERMY, TERMX, 0, 0);
    werase(w_background);
    wrefresh(w_background);

    // main window should also expand to use available display space.
    // expanding to evenly use up half of extra space, for now.
    int extra_w = ((TERMX - FULL_SCREEN_WIDTH) / 2) - 1;
    int extra_h = ((TERMY - FULL_SCREEN_HEIGHT) / 2) - 1;
    extra_w = (extra_w > 0 ? extra_w : 0);
    extra_h = (extra_h > 0 ? extra_h : 0);
    const int total_w = FULL_SCREEN_WIDTH + extra_w;
    const int total_h = FULL_SCREEN_HEIGHT + extra_h;

    // position of window within main display
    const int x0 = (TERMX - total_w) / 2;
    const int y0 = (TERMY - total_h) / 2;

    WINDOW *w_open = newwin(total_h, total_w, y0, x0);

    const int iMenuOffsetX = 2;
    int iMenuOffsetY = total_h - 3;

    std::vector<std::string> vSubItems;
    vSubItems.push_back(pgettext("Main Menu|New Game", "<C>ustom Character"));
    vSubItems.push_back(pgettext("Main Menu|New Game", "<P>reset Character"));
    vSubItems.push_back(pgettext("Main Menu|New Game", "<R>andom Character"));
    vSubItems.push_back(pgettext("Main Menu|New Game", "Play <N>ow!"));

    std::vector<std::string> vWorldSubItems;
    vWorldSubItems.push_back(pgettext("Main Menu|World", "<C>reate World"));
    vWorldSubItems.push_back(pgettext("Main Menu|World", "<D>elete World"));
    vWorldSubItems.push_back(pgettext("Main Menu|World", "<R>eset World"));

    print_menu(w_open, 0, iMenuOffsetX, iMenuOffsetY);

    std::vector<std::string> savegames, templates;
    dirent *dp;
    DIR *dir;

    if (!assure_dir_exist("save")) {
        popup(_("Unable to make save directory. Check permissions."));
        return false;
    }

    dir = opendir("data");
    while ((dp = readdir(dir))) {
        std::string tmp = dp->d_name;
        if (tmp.find(".template") != std::string::npos) {
            templates.push_back(tmp.substr(0, tmp.find(".template")));
        }
    }
    closedir(dir);

    int sel1 = 1, sel2 = 1, sel3 = 1, layer = 1;
    InputEvent input;
    int chInput;
    bool start = false;

    // Load MOTD and store it in a string
    // Only load it once, it shouldn't change for the duration of the application being open
    static std::vector<std::string> motd;
    if (motd.empty()) {
        std::ifstream motd_file;
        motd_file.open("data/motd");
        if (!motd_file.is_open()) {
            motd.push_back(_("No message today."));
        } else {
            while (!motd_file.eof()) {
                std::string tmp;
                getline(motd_file, tmp);
                if (!tmp.length() || tmp[0] != '#') {
                    motd.push_back(tmp);
                }
            }
        }
    }

    // Load Credits and store it in a string
    // Only load it once, it shouldn't change for the duration of the application being open
    static std::vector<std::string> credits;
    if (credits.empty()) {
        std::ifstream credits_file;
        credits_file.open("data/credits");
        if (!credits_file.is_open()) {
            credits.push_back(_("No message today."));
        } else {
            while (!credits_file.eof()) {
                std::string tmp;
                getline(credits_file, tmp);
                if (!tmp.length() || tmp[0] != '#') {
                    credits.push_back(tmp);
                }
            }
        }
    }

    u = player();

    while(!start) {
        print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY, (sel1 == 0 || sel1 == 7) ? false : true);

        if (layer == 1) {
            if (sel1 == 0) { // Print the MOTD.
                for (int i = 0; i < motd.size() && i < 16; i++) {
                    mvwprintz(w_open, i + 6, 8 + extra_w / 2, c_ltred, motd[i].c_str());
                }

                wrefresh(w_open);
                refresh();
            } else if (sel1 == 7) { // Print the Credits.
                for (int i = 0; i < credits.size() && i < 16; i++) {
                    mvwprintz(w_open, i + 6, 8 + extra_w / 2, c_ltred, credits[i].c_str());
                }

                wrefresh(w_open);
                refresh();
            }

            chInput = getch();

            if (chInput == 'm' || chInput == 'M') {
                // MOTD
                sel1 = 0;
                chInput = '\n';
            } else if (chInput == 'n' || chInput == 'N') {
                // New Game
                sel1 = 1;
                chInput = '\n';
            } else if (chInput == 'a' || chInput == 'A') {
                // Load Game
                sel1 = 2;
                chInput = '\n';
            } else if (chInput == 'w' || chInput == 'W') {
                // World
                sel1 = 3;
                chInput = '\n';
            } else if (chInput == 's' || chInput == 'S') {
                // Special Game
                sel1 = 4;
                chInput = '\n';
            } else if (chInput == 'o' || chInput == 'O') {
                // Options
                sel1 = 5;
                chInput = '\n';
            } else if (chInput == 'e' || chInput == 'E' || chInput == '?') {
                // Help
                sel1 = 6;
                chInput = '\n';
            } else if (chInput == 'c' || chInput == 'C') {
                // Credits
                sel1 = 7;
                chInput = '\n';
            } else if (chInput == 'q' || chInput == 'Q' || chInput == KEY_ESCAPE) {
                // Quit
                sel1 = 8;
                chInput = '\n';
            }

            if (chInput == KEY_LEFT || chInput == 'h') {
                if (sel1 > 0) {
                    sel1--;
                } else {
                    sel1 = 8;
                }
            } else if (chInput == KEY_RIGHT || chInput == 'l') {
                if (sel1 < 8) {
                    sel1++;
                } else {
                    sel1 = 0;
                }
            } else if ((chInput == KEY_UP || chInput == 'k' || chInput == '\n') && sel1 > 0 && sel1 != 7) {
                if (sel1 == 5) {
                    show_options();
                } else if (sel1 == 6) {
                    display_help();
                } else if (sel1 == 8) {
                    uquit = QUIT_MENU;
                    delwin(w_open);
                    delwin(w_background);
                    return false;
                } else {
                    sel2 = 0;
                    layer = 2;
                    print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY, (sel1 == 0 || sel1 == 7) ? false : true);
                }
            }
        } else if (layer == 2) {
            if (sel1 == 1) { // New Character
                print_menu_items(w_open, vSubItems, sel2, iMenuOffsetY - 2, iMenuOffsetX);
                wrefresh(w_open);
                refresh();
                chInput = getch();

                if (chInput == 'c' || chInput == 'C') {
                    sel2 = 0;
                    chInput = '\n'  ;
                } else if (chInput == 'p' || chInput == 'P') {
                    sel2 = 1;
                    chInput = '\n';
                } else if (chInput == 'r' || chInput == 'R') {
                    sel2 = 2;
                    chInput = '\n';
                } else if (chInput == 'n' || chInput == 'N') {
                    sel2 = 3;
                    chInput = '\n';
                }

                if (chInput == KEY_LEFT || chInput == 'h') {
                    sel2--;
                    if (sel2 < 0) {
                        sel2 = vSubItems.size() - 1;
                    }
                }
                if (chInput == KEY_RIGHT || chInput == 'l') {
                    sel2++;
                    if (sel2 >= vSubItems.size()) {
                        sel2 = 0;
                    }
                } else if (chInput == KEY_DOWN || chInput == 'j' || chInput == KEY_ESCAPE) {
                    layer = 1;
                    sel1 = 1;
                }
                if (chInput == KEY_UP || chInput == 'k' || chInput == '\n') {
                    if (sel2 == 0 || sel2 == 2 || sel2 == 3) {
                        // First load the mods, this is done by
                        // loading the world.
                        // Pick a world, supressing prompts if it's "play now" mode.
                        WORLDPTR world = world_generator->pick_world( sel2 != 3 );
                        if (world == NULL) {
                            continue;
                        }
                        world_generator->set_active_world(world);
                        setup();
                        if (!u.create((sel2 == 0) ? PLTYPE_CUSTOM :
                                                    ((sel2 == 2) ? PLTYPE_RANDOM : PLTYPE_NOW))) {
                            u = player();
                            continue;
                        }
                        werase(w_background);
                        wrefresh(w_background);

                        MAPBUFFER.load(world->world_name);
                        start_game(world->world_name);
                        start = true;
                    } else if (sel2 == 1) {
                        layer = 3;
                        sel3 = 0;
                    }
                }
            } else if (sel1 == 2) { // Load Character
                if (world_generator->all_worldnames.empty()) {
                    mvwprintz(w_open, iMenuOffsetY - 2, 15 + iMenuOffsetX + extra_w / 2,
                              c_red, _("No Worlds found!"));
                } else {
                    for (int i = 0; i < world_generator->all_worldnames.size(); ++i) {
                      int line = iMenuOffsetY - 2 - i;
                      std::string world_name = world_generator->all_worldnames[i];
                      int savegames_count = world_generator->all_worlds[world_name]->world_saves.size();
                      mvwprintz(w_open, line, 15 + iMenuOffsetX + extra_w / 2,
                                (sel2 == i ? h_white : c_white), "%s (%d)", world_name.c_str(), savegames_count);
                    }
                }
                wrefresh(w_open);
                refresh();
                input = get_input();
                if (world_generator->all_worldnames.empty() && (input == DirectionS || input == Confirm)) {
                    layer = 1;
                } else if (input == DirectionS) {
                    if (sel2 > 0) {
                        sel2--;
                    } else {
                        sel2 = world_generator->all_worldnames.size() - 1;
                    }
                } else if (input == DirectionN) {
                    if (sel2 < world_generator->all_worldnames.size() - 1) {
                        sel2++;
                    } else {
                        sel2 = 0;
                    }
                } else if (input == DirectionW || input == Cancel) {
                    layer = 1;
                }
                if (input == DirectionE || input == Confirm) {
                    if (sel2 >= 0 && sel2 < world_generator->all_worldnames.size()) {
                        layer = 3;
                        sel3 = 0;
                    }
                }
            } else if (sel1 == 3) {  // World Menu
                // Show options for Create, Destroy, Reset worlds.
                // Create world goes directly to Make World screen.
                // Reset and Destroy ask for world to modify.
                // Reset empties world of everything but options, then makes new world within it.
                // Destroy asks for confirmation, then destroys everything in world and then removes world folder.

                // only show reset / destroy world if there is at least one valid world existing!

                int world_subs_to_display = (world_generator->all_worldnames.size() > 0)? vWorldSubItems.size(): 1;
                std::vector<std::string> world_subs;
                int xoffset = 25 + iMenuOffsetX + extra_w / 2;
                int yoffset = iMenuOffsetY - 2;
                int xlen = 0;
                for (int i = 0; i < world_subs_to_display; ++i) {
                    world_subs.push_back(vWorldSubItems[i]);
                    xlen += vWorldSubItems[i].size() + 2; // Open and close brackets added
                }
                xlen += world_subs.size() - 1;
                if (world_subs.size() > 1) {
                    xoffset -= 6;
                }
                print_menu_items(w_open, world_subs, sel2, yoffset, xoffset - (xlen / 4));
                wrefresh(w_open);
                refresh();
                chInput = getch();
                input = get_input(chInput);

                //shortcuts
                if (chInput == 'c' || chInput == 'C') {
                    sel2 = 0;
                    input = Confirm;
                } else if ((chInput == 'd' || chInput == 'D') && (world_subs_to_display > 1)) {
                    sel2 = 1;
                    input = Confirm;
                } else if ((chInput == 'r' || chInput == 'R') && (world_subs_to_display > 1)) {
                    sel2 = 2;
                    input = Confirm;
                }

                if (input == DirectionW) {
                    if (sel2 > 0) {
                        --sel2;
                    } else {
                        sel2 = world_subs_to_display - 1;
                    }
                } else if (input == DirectionE) {
                    if (sel2 < world_subs_to_display - 1) {
                        ++sel2;
                    } else {
                        sel2 = 0;
                    }
                } else if (input == DirectionS || input == Cancel) {
                    layer = 1;
                }

                if (input == DirectionN || input == Confirm) {
                    if (sel2 == 0) { // Create world
                        // Open up world creation screen!
                        if (world_generator->make_new_world()) {
                            return opening_screen();
                        } else {
                            layer = 1;
                        }
                    } else if (sel2 == 1 || sel2 == 2) { // Delete World | Reset World
                        layer = 3;
                        sel3 = 0;
                    }
                }
            } else if (sel1 == 4) { // Special game
                std::vector<std::string> special_names;
                int xoffset = 32 + iMenuOffsetX  + extra_w / 2;
                int yoffset = iMenuOffsetY - 2;
                int xlen = 0;
                for (int i = 1; i < NUM_SPECIAL_GAMES; i++) {
                    std::string spec_name = special_game_name(special_game_id(i));
                    special_names.push_back(spec_name);
                    xlen += spec_name.size() + 2;
                }
                xlen += special_names.size() - 1;
                print_menu_items(w_open, special_names, sel2, yoffset, xoffset - (xlen / 4));

                wrefresh(w_open);
                refresh();
                input = get_input();
                if (input == DirectionW) {
                    if (sel2 > 0) {
                        sel2--;
                    } else {
                        sel2 = NUM_SPECIAL_GAMES - 2;
                    }
                } else if (input == DirectionE) {
                    if (sel2 < NUM_SPECIAL_GAMES - 2) {
                        sel2++;
                    } else {
                        sel2 = 0;
                    }
                } else if (input == DirectionS || input == Cancel) {
                    layer = 1;
                }
                if (input == DirectionN || input == Confirm) {
                    if (sel2 >= 0 && sel2 < NUM_SPECIAL_GAMES - 1) {
                        delete gamemode;
                        gamemode = get_special_game( special_game_id(sel2 + 1) );
                        // check world
                        WORLDPTR world = world_generator->make_new_world(special_game_id(sel2 + 1));
                        if (world == NULL) {
                            continue;
                        }
                        world_generator->set_active_world(world);
                        setup();
                        if (!gamemode->init()) {
                            delete gamemode;
                            gamemode = NULL;
                            u = player();
                            continue;
                        }
                        start = true;
                    }
                }
            }
        } else if (layer == 3) {
            if (sel1 == 2) { // Load Game
                savegames = world_generator->all_worlds[world_generator->all_worldnames[sel2]]->world_saves;
                if (savegames.empty()) {
                    mvwprintz(w_open, iMenuOffsetY - 2, 19 + 19 + iMenuOffsetX + extra_w / 2,
                              c_red, _("No save games found!"));
                } else {
                    for (int i = 0; i < savegames.size(); i++) {
                        int line = iMenuOffsetY - 2 - i;
                        mvwprintz(w_open, line, 19 + 19 + iMenuOffsetX + extra_w / 2,
                                  (sel3 == i ? h_white : c_white),
                                  base64_decode(savegames[i]).c_str());
                    }
                }
                wrefresh(w_open);
                refresh();
                input = get_input();
                if (savegames.size() == 0 && (input == DirectionS || input == Confirm)) {
                    layer = 2;
                } else if (input == DirectionS) {
                    if (sel3 > 0) {
                        sel3--;
                    } else {
                        sel3 = savegames.size() - 1;
                    }
                } else if (input == DirectionN) {
                    if (sel3 < savegames.size() - 1) {
                        sel3++;
                    } else {
                        sel3 = 0;
                    }
                } else if (input == DirectionW || input == Cancel) {
                    layer = 2;
                    sel3 = 0;
                    print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY);
                }
                if (input == DirectionE || input == Confirm) {
                    if (sel3 >= 0 && sel3 < savegames.size()) {
                        werase(w_background);
                        wrefresh(w_background);
                        WORLDPTR world = world_generator->all_worlds[world_generator->all_worldnames[sel2]];
                        world_generator->set_active_world(world);
                        setup();
                        MAPBUFFER.load(world->world_name);

                        load(world->world_name, savegames[sel3]);
                        start = true;
                    }
                }
            } else if (sel1 == 3) { // Show world names
                int i = 0;
                for (std::vector<std::string>::iterator it = world_generator->all_worldnames.begin();
                     it != world_generator->all_worldnames.end(); ++it) {
                    int savegames_count = world_generator->all_worlds[*it]->world_saves.size();
                    int line = iMenuOffsetY - 4 - i;
                    mvwprintz(w_open, line, 26 + iMenuOffsetX + extra_w / 2,
                              (sel3 == i ? h_white : c_white), "%s (%d)", (*it).c_str(), savegames_count);
                    ++i;
                }
                wrefresh(w_open);
                refresh();
                input = get_input();

                if (input == DirectionS) {
                    if (sel3 > 0) {
                        --sel3;
                    } else {
                        sel3 = world_generator->all_worldnames.size() - 1;
                    }
                } else if (input == DirectionN) {
                    if (sel3 < world_generator->all_worldnames.size() - 1) {
                        ++sel3;
                    } else {
                        sel3 = 0;
                    }
                } else if (input == DirectionW || input == Cancel) {
                    layer = 2;

                    print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY);
                }
                if (input == DirectionE || input == Confirm) {
                    if (sel3 >= 0 && sel3 < world_generator->all_worldnames.size()) {
                        bool query_yes = false;
                        bool do_delete = false;
                        if (sel2 == 1) { // Delete World
                            if (query_yn(_("Delete the world and all saves?"))) {
                                query_yes = true;
                                do_delete = true;
                            }
                        } else if (sel2 == 2) { // Reset World
                            if (query_yn(_("Remove all saves and regenerate world?"))) {
                                query_yes = true;
                                do_delete = false;
                            }
                        }

                        if (query_yes) {
                            delete_world(world_generator->all_worldnames[sel3], do_delete);

                            savegames.clear();
                            MAPBUFFER.reset();
                            MAPBUFFER.make_volatile();
                            overmap_buffer.clear();

                            layer = 2;

                            if (do_delete) {
                                // delete world and all contents
                                world_generator->remove_world(world_generator->all_worldnames[sel3]);
                            } else {
                                // clear out everything but worldoptions from this world
                                world_generator->all_worlds[world_generator->all_worldnames[sel3]]->world_saves.clear();
                            }
                            if (world_generator->all_worldnames.size() == 0) {
                                sel2 = 0; // reset to create world selection
                            }
                        } else {
                            // hacky resolution to the issue of persisting world names on the screen
                            return opening_screen();
                        }
                    }
                    print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY);
                }
            } else { // Character Templates
                if (templates.size() == 0) {
                    mvwprintz(w_open, iMenuOffsetY - 4, iMenuOffsetX + 20 + extra_w / 2,
                              c_red, _("No templates found!"));
                } else {
                    for (int i = 0; i < templates.size(); i++) {
                        int line = iMenuOffsetY - 4 - i;
                        mvwprintz(w_open, line, 20 + iMenuOffsetX + extra_w / 2,
                                  (sel3 == i ? h_white : c_white), templates[i].c_str());
                    }
                }
                wrefresh(w_open);
                refresh();
                input = get_input();
                if (input == DirectionS) {
                    if (sel3 > 0) {
                        sel3--;
                    } else {
                        sel3 = templates.size() - 1;
                    }
                } else if (templates.size() == 0 && (input == DirectionN || input == Confirm)) {
                    sel1 = 1;
                    layer = 2;
                    print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY);
                } else if (input == DirectionN) {
                    if (sel3 < templates.size() - 1) {
                        sel3++;
                    } else {
                        sel3 = 0;
                    }
                } else if (input == DirectionW  || input == Cancel || templates.size() == 0) {
                    sel1 = 1;
                    layer = 2;
                    print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY);
                } else if (input == DirectionE || input == Confirm) {
                    WORLDPTR world = world_generator->pick_world();
                    if (world == NULL) {
                        u = player();
                        continue;
                    }
                    world_generator->set_active_world(world);
                    setup();
                    if (!u.create(PLTYPE_TEMPLATE, templates[sel3])) {
                        u = player();
                        continue;
                    }
                    werase(w_background);
                    wrefresh(w_background);
                    MAPBUFFER.load(world_generator->active_world->world_name);
                    start_game(world_generator->active_world->world_name);
                    start = true;
                }
            }
        }
    }
    delwin(w_open);
    delwin(w_background);
    if (start == false) {
        uquit = QUIT_MENU;
    } else {
        refresh_all();
        draw();
    }
    return start;
}
Beispiel #22
0
//--------------------------------------------------------------------------
void idaapi run(int arg)
{
  if ( arg == -1 )
  {
    load_options();
    show_options();
    return;
  }

  func_t *pfn = get_func(get_screen_ea());
  if ( pfn == NULL )
  {
    warning("Please position the cursor in a function first!");
    return;
  }
  load_options();
  qstring title;
  graph_info_t::get_title(pfn->startEA, &title);

  HWND hwnd = NULL;
  TForm *form = create_tform(title.c_str(), &hwnd);
  if ( hwnd != NULL )
  {
    // window is new, but instance is in the list?
    graph_info_t *gi = graph_info_t::find(title.c_str());
    if ( gi != NULL )
    {
      // in that case let us "recycle" the instance
      gi->func_ea = pfn->startEA;
    }
    else
    {
      // we create a new instance
      gi = graph_info_t::create(pfn->startEA);
    }

    if ( gi != NULL )
    {
      // get a unique graph id
      netnode id;
      id.create();

      gi->mark_for_refresh();
      gi->form = form;
      gi->gv = create_graph_viewer(form, id, gr_callback, gi, 0);
      open_tform(form, FORM_MDI|FORM_TAB|FORM_MENU);
      if ( gi->gv != NULL )
      {
        viewer_fit_window(gi->gv);
        viewer_add_menu_item(gi->gv, "Options", menu_options_cb, gi, "O", 0);
        viewer_add_menu_item(gi->gv, "Goto to first node", menu_home_cb, gi, "H", 0);
        viewer_add_menu_item(gi->gv, "Refresh", menu_refresh_cb, gi, "R", 0);
        viewer_add_menu_item(gi->gv, "Search first", menu_searchfirst_cb, gi, "S", 0);
        viewer_add_menu_item(gi->gv, "Search next", menu_searchnext_cb, gi, "N", 0);
      }
      else
      {
        graph_info_t::destroy(gi);
        gi = NULL;
      }
    }
    // failed to creat a graph view?
    if ( gi == NULL )
    {
      warning("Failed to create call graph window!\n");
      return;
    }
  }
  else
  {
    graph_info_t *gi = graph_info_t::find(title.c_str());
    if ( gi != NULL )
    {
      gi->refresh();
      open_tform(gi->form, FORM_MDI|FORM_TAB|FORM_MENU);
    }
  }
}
Beispiel #23
0
int main(int argc,char **argv)
{
  char stdi=0;
  FILE *file=NULL;
  double min,inter=0.0,ind_inter,epsilon,av,ind_var;
  char *nearest,alldone;
  long i;
  unsigned int dim,emb;
  unsigned long donesofar;

  if (scan_help(argc,argv))
    show_options(argv[0]);
  
  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif

  infile=search_datafile(argc,argv,NULL,verbosity);
  if (infile == NULL)
    stdi=1;

  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".fnn");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
      strcpy(outfile,"stdin.fnn");
    }
  }
  if (!stdo)
    test_outfile(outfile);

  if (column == NULL)
    series=(double**)get_multi_series(infile,&length,exclude,&comp,"",dimset,
				      verbosity);
  else
    series=(double**)get_multi_series(infile,&length,exclude,&comp,column,
				      dimset,verbosity);

  for (i=0;i<comp;i++) {
    rescale_data(series[i],length,&min,&ind_inter);
    variance(series[i],length,&av,&ind_var);
    if (i == 0) {
      varianz=ind_var;
      inter=ind_inter;
    }
    else {
      varianz=(varianz>ind_var)?ind_var:varianz;
      inter=(inter<ind_inter)?ind_inter:inter;
    }
  }

  check_alloc(list=(long*)malloc(sizeof(long)*length));
  check_alloc(nearest=(char*)malloc(length));
  check_alloc(box=(long**)malloc(sizeof(long*)*BOX));
  for (i=0;i<BOX;i++)
    check_alloc(box[i]=(long*)malloc(sizeof(long)*BOX));

  if (!stdo) {
    file=fopen(outfile,"w");
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Opened %s for writing\n",outfile);
  }
  else {
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Writing to stdout\n");
  }
  check_alloc(vcomp=(unsigned int*)malloc(sizeof(int)*(maxdim)));
  check_alloc(vemb=(unsigned int*)malloc(sizeof(int)*(maxdim)));
  for (i=0;i<maxdim;i++) {
    if (comp == 1) {
      vcomp[i]=0;
      vemb[i]=i;
    }
    else {
      vcomp[i]=i%comp;
      vemb[i]=(i/comp)*delay;
    }
  }
  for (emb=minemb;emb<=maxemb;emb++) {
    dim=emb*comp-1;
    epsilon=eps0;
    toolarge=0;
    alldone=0;
    donesofar=0;
    aveps=0.0;
    vareps=0.0;
    for (i=0;i<length;i++)
      nearest[i]=0;
    if (verbosity&VER_USR1)
      fprintf(stderr,"Start for dimension=%u\n",dim+1);
    while (!alldone && (epsilon < 2.*varianz/rt)) {
      alldone=1;
      mmb(vcomp[dim],vemb[dim],epsilon);
      for (i=0;i<length-maxemb*delay;i++)
	if (!nearest[i]) {
	  nearest[i]=find_nearest(i,dim,epsilon);
	  alldone &= nearest[i];
	  donesofar += (unsigned long)nearest[i];
	}
      if (verbosity&VER_USR1)
	fprintf(stderr,"Found %lu up to epsilon=%e\n",donesofar,epsilon*inter);
      epsilon*=sqrt(2.0);
      if (!donesofar)
	eps0=epsilon;
    }
    if (donesofar == 0) {
      fprintf(stderr,"Not enough points found!\n");
      exit(FALSE_NEAREST_NOT_ENOUGH_POINTS);
    }
    aveps *= (1./(double)donesofar);
    vareps *= (1./(double)donesofar);
    if (stdo) {
      fprintf(stdout,"%u %e %e %e\n",dim+1,(double)toolarge/(double)donesofar,
	      aveps*inter,sqrt(vareps)*inter);
      fflush(stdout);
    }
    else {
      fprintf(file,"%u %e %e %e\n",dim+1,(double)toolarge/(double)donesofar,
	      aveps*inter,sqrt(vareps)*inter);
      fflush(file);
    }
  }
  if (!stdo)
    fclose(file);

  if (infile != NULL)
    free(infile);
  if (outfile != NULL)
    free(outfile);
  free(series);
  free(list);
  free(nearest);
  for (i=0;i<BOX;i++)
    free(box[i]);
  free(box);

  return 0;
}
Beispiel #24
0
int main(int argc,char **argv)
{
  unsigned int outstrlen=0;
  int i,j,k,n;
  unsigned int offset,wdim=1,alldim;
  unsigned int has_future,*future,**useries,h;
  unsigned long count;
  long *segment;
  char *outstring,*infile,*wcol,*use_array;
  double **series,*sermin,*serinter,**dfuture;
  ptree *root;
  FILE *fout;

  if (scan_help(argc,argv))
    show_options(argv[0]);

  for (i=0;i<argc;i++) {
    outstrlen += strlen(argv[i]);
    outstrlen++;
  }
  check_alloc(outstring=(char*)malloc(sizeof(char)*(outstrlen+8)));
  sprintf(outstring,"#Prog: ");
  offset=7;
  for (i=0;i<argc;i++) {
    sprintf(outstring+offset,"%s ",argv[i]);
    offset += (strlen(argv[i])+1);
  }

  scan_options(argc,argv);
 
  if (!compdimset) 
    compdim=pars.DIM;
  else
    if (compdim > pars.DIM) {
      fprintf(stderr,"-C value larger -m Value.\n");
      exit(LANGEVIN_MAIN_C_TOO_LARGE);
    }

  infile=search_datafile(argc,argv,NULL,VERBOSITY);
  if (infile == NULL) {
    fprintf(stderr,"No input datafile found.\n");
    exit(LANGEVIN_MAIN_NO_INPUTFILE);
  }
  
  if (OUTFILE == NULL) {
    check_alloc(OUTFILE=(char*)calloc(strlen(infile)+5,(size_t)1));
    sprintf(OUTFILE,"%s.pru",infile);
  }
  OUTFILE=test_outfile(OUTFILE);

  if (COLUMN == NULL)
    series=(double**)get_multi_series(infile,&(pars.LENGTH),EXCLUDE,
				      &(pars.DIM),"",dimset,VERBOSITY);
  else
    series=(double**)get_multi_series(infile,&(pars.LENGTH),EXCLUDE,
				      &(pars.DIM),COLUMN,dimset,VERBOSITY);

  check_alloc(sermin=malloc(sizeof(double)*pars.DIM));
  check_alloc(serinter=malloc(sizeof(double)*pars.DIM));
  rescale_data(series,pars,sermin,serinter);

  alldim=pars.DIM;
  pars.DIM=compdim;

  check_alloc(useries=(unsigned int**)malloc(sizeof(int*)*pars.DIM));
  check_alloc(PART=(unsigned int*)malloc(sizeof(int)*pars.DIM));
  if (SPART == NULL)
    for (i=0;i<pars.DIM;i++)
      PART[i]=2;
  else
    set_part(PART,SPART,pars);

  for (i=0;i<pars.DIM;i++) {
    check_alloc(useries[i]=(unsigned int*)malloc(sizeof(int)*pars.LENGTH));
    for (j=0;j<pars.LENGTH;j++) {
      h=(unsigned int)((series[i][j]*(double)PART[i])/serinter[i]);
      useries[i][j]=((h<PART[i])?h:(PART[i]-1));
    }
  }

  check_alloc(future=(unsigned int*)malloc(sizeof(int)*pars.LENGTH));
  if (WHICHFUTURE>0) {
    check_alloc(wcol=(char*)calloc((size_t)10,(size_t)1));
    sprintf(wcol,"%u",WHICHFUTURE);
    dfuture=(double**)get_multi_series(infile,&(pars.LENGTH),EXCLUDE,
				       &wdim,wcol,1,0L);
    for (i=0;i<pars.LENGTH-1;i++) {
      future[i] = (dfuture[0][i]>0.0);
    }
    future[pars.LENGTH-1]=1;
    free(dfuture);
  }
  else {
    for (i=0;i<pars.LENGTH;i++)
      future[i]=1;
  }
  root=make_ptree(PART[0]);

  count=0;
  check_alloc(segment=(long*)malloc(sizeof(long)*pars.LENGTH));
  for (i=0;i<pars.LENGTH;i += ODEPTH) {
    has_future=1;
    for (j=0;j<ODEPTH;j++)
      has_future &= future[i+j];
    if (has_future) {
      fill_tree(root,useries,pars,i,0,DEPTH,PART);
    }
    segment[count++]=i;
  }

  if (scrambleset)
    lscramble(segment,count);

  check_alloc(use_array=(char*)malloc(sizeof(char)*pars.LENGTH));
  for (i=0;i<count;i++) {
    n=segment[i];
    has_future=1;
    for (j=0;j<ODEPTH;j++)
      has_future &= future[n+j];
    if (has_future) {
      h=read_tree(root,useries,pars,n,0,DEPTH);
      if (h <= MAXOUT)
	use_array[i]=1;
      else 
	use_array[i]=0;
    }
    else 
      use_array[i]=2;
  }
  pars.DIM=alldim;

  fout=fopen(OUTFILE,"w");
  fprintf(fout,"%s\n",outstring);
  fprintf(fout,"#Content: ");
  for (i=0;i<pars.DIM;i++)
    fprintf(fout,"x%d ",i+1);
  fprintf(fout,"future time_index\n");
  fflush(fout);

  for (i=0;i<count;i++) {
    n=segment[i];
    if (use_array[i] == 1) {
      for (j=0;j<(ODEPTH-1);j++) {
	for (k=0;k<pars.DIM;k++)
	  fprintf(fout,"%f ",series[k][n+j]+sermin[k]);
	fprintf(fout,"1 %u\n",n+j);
      }
      for (k=0;k<pars.DIM;k++)
	fprintf(fout,"%f ",series[k][n+ODEPTH-1]+sermin[k]);
      if (i<(count-1)) {
	if (segment[i+1] == (n+ODEPTH) && use_array[i+1])
	  fprintf(fout,"1 %u\n",n+ODEPTH-1);
	else 
	  fprintf(fout,"0 %u\n",n+ODEPTH-1);
      }
      else 
	fprintf(fout,"0 %u\n",n+ODEPTH-1);
    }
  }

  fclose(fout);
}
Beispiel #25
0
static void controller_config(void)
{

	unsigned long ExKey=0;
	int selected_option=0;
	int x_Pos = 41;
	int y_Pos = 48;
	int options_count = 18;
	char text[64];
	int i;
	char* options[] = 		{	"FIRE01 Auto    = %s",
						"FIRE02 Auto    = %s",
						"FIRE03 Auto    = %s",
						"FIRE01         = %s",
						"FIRE02         = %s",
						"FIRE03         = %s",
						"FIRE04         = %s",
						"FIRE05         = %s",
						"FIRE06         = %s",
						"FIRE07         = %s",
						"FIRE08         = %s",
						"FIRE09         = %s",
						"FIRE10         = %s",
						"X Sensitivity  = %s",
						"X Reversed     = %s",
						"Y Sensitivity  = %s",
						"Y Reversed     = %s",
						"Back to Default Values"};
	
	while (1)
	{
		/* Draw background image */
		load_bmp_8bpp(gp2x_screen8,gp2xmenu_bmp);
		
		/* Draw the options */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+0,options[0],key_settings->JOY_FIRE1_AUTO?"ON\0":"OFF\0");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+8,options[1],key_settings->JOY_FIRE2_AUTO?"ON\0":"OFF\0");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+16,options[2],key_settings->JOY_FIRE3_AUTO?"ON\0":"OFF\0");
		button_text(key_settings->JOY_FIRE1,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+24,options[3],text);
		button_text(key_settings->JOY_FIRE2,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+32,options[4],text);
		button_text(key_settings->JOY_FIRE3,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,options[5],text);
		button_text(key_settings->JOY_FIRE4,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+48,options[6],text);
		button_text(key_settings->JOY_FIRE5,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+56,options[7],text);
		button_text(key_settings->JOY_FIRE6,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+64,options[8],text);
		button_text(key_settings->JOY_FIRE7,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+72,options[9],text);
		button_text(key_settings->JOY_FIRE8,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,options[10],text);
		button_text(key_settings->JOY_FIRE9,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+88,options[11],text);
		button_text(key_settings->JOY_FIRE10,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+96,options[12],text);
		if (x_sensitivity!=-1)
			sprintf(text,"%d",x_sensitivity);
		else
			strcpy(text,"DEFAULT");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+104,options[13],text);
		if (x_reversed)
			strcpy(text,"ON");
		else
			strcpy(text,"OFF");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+112,options[14],text);
		if (y_sensitivity!=-1)
			sprintf(text,"%d",y_sensitivity);
		else
			strcpy(text,"DEFAULT");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+120,options[15],text);
		if (y_reversed)
			strcpy(text,"ON");
		else
			strcpy(text,"OFF");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+128,options[16],text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+136,options[17]);

#ifdef PSP
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+152,"Press [] or O to confirm");
#else
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+152,"Press A or B to confirm");
#endif
		/* Show currently selected item */
		gp2x_gamelist_text_out(x_Pos-16,y_Pos+(selected_option*8)," >");

		gp2x_video_flip();
		while(gp2x_joystick_read()&0x8c0ff55) { gp2x_timer_delay(150); }
		while(!(ExKey=gp2x_joystick_read()&0x8c0ff55)) { }

		if(ExKey & GP2X_DOWN){
			selected_option++;
			selected_option = selected_option % options_count;
		}
		else if(ExKey & GP2X_UP){
			selected_option--;
			if(selected_option<0)
				selected_option = options_count - 1;
		}
#ifdef GP2X
		else if(ExKey & GP2X_R || ExKey & GP2X_L){
#else
		else if(ExKey & GP2X_RIGHT || ExKey & GP2X_LEFT){
#endif
			switch(selected_option) {
				
				case 0: key_settings->JOY_FIRE1_AUTO=key_settings->JOY_FIRE1_AUTO?0:1; break;
				case 1: key_settings->JOY_FIRE2_AUTO=key_settings->JOY_FIRE2_AUTO?0:1; break;
				case 2: key_settings->JOY_FIRE3_AUTO=key_settings->JOY_FIRE3_AUTO?0:1; break;
				case 3: key_settings->JOY_FIRE1=button_next((key_settings->JOY_FIRE1),(ExKey&GP2X_R)); break;
				case 4: key_settings->JOY_FIRE2=button_next((key_settings->JOY_FIRE2),(ExKey&GP2X_R)); break;
				case 5: key_settings->JOY_FIRE3=button_next((key_settings->JOY_FIRE3),(ExKey&GP2X_R)); break;
				case 6: key_settings->JOY_FIRE4=button_next((key_settings->JOY_FIRE4),(ExKey&GP2X_R)); break;
				case 7: key_settings->JOY_FIRE5=button_next((key_settings->JOY_FIRE5),(ExKey&GP2X_R)); break;
				case 8: key_settings->JOY_FIRE6=button_next((key_settings->JOY_FIRE6),(ExKey&GP2X_R)); break;
				case 9: key_settings->JOY_FIRE7=button_next((key_settings->JOY_FIRE7),(ExKey&GP2X_R)); break;
				case 10: key_settings->JOY_FIRE8=button_next((key_settings->JOY_FIRE8),(ExKey&GP2X_R)); break;
				case 11: key_settings->JOY_FIRE9=button_next((key_settings->JOY_FIRE9),(ExKey&GP2X_R)); break;
				case 12: key_settings->JOY_FIRE10=button_next((key_settings->JOY_FIRE10),(ExKey&GP2X_R)); break;
				case 13:
					/* X Sensitivity */
#ifdef GP2X
					if (ExKey & GP2X_R) {
#else
					if (ExKey & GP2X_RIGHT) {
#endif
						if (x_sensitivity!=-1) {
							x_sensitivity+=5;
							if (x_sensitivity>255) x_sensitivity=-1;
						} else
							x_sensitivity=0;
					} else {
						if (x_sensitivity!=-1) {
							x_sensitivity-=5;
							if (x_sensitivity<0) x_sensitivity=-1;
						} else
							x_sensitivity=255;
					}
					break;
				case 14:
					/* X Reversed */
					x_reversed=!x_reversed;
					break;
				case 15:
					/* Y Sensitivity */
#ifdef GP2X
					if (ExKey & GP2X_R) {
#else
					if (ExKey & GP2X_RIGHT) {
#endif
						if (y_sensitivity!=-1) {
							y_sensitivity+=5;
							if (y_sensitivity>255) y_sensitivity=-1;
						} else
							y_sensitivity=0;
					} else {
						if (y_sensitivity!=-1) {
							y_sensitivity-=5;
							if (y_sensitivity<0) y_sensitivity=-1;
						} else
							y_sensitivity=255;
					}
					break;
				case 16:
					/* Y Reversed */
					y_reversed=!y_reversed;
					break;
				case 17:
					/* Default Values */
					key_settings->JOY_FIRE1=GP2X_B;
					key_settings->JOY_FIRE2=GP2X_X;
					key_settings->JOY_FIRE3=GP2X_A;
					key_settings->JOY_FIRE4=GP2X_Y;
					key_settings->JOY_FIRE5=GP2X_L;
					key_settings->JOY_FIRE6=GP2X_R;
					key_settings->JOY_FIRE7=GP2X_VOL_UP;
					key_settings->JOY_FIRE8=GP2X_VOL_DOWN;
					key_settings->JOY_FIRE9=GP2X_PUSH;
					key_settings->JOY_FIRE10=GP2X_START;
					key_settings->JOY_FIRE1_AUTO=0;
					key_settings->JOY_FIRE2_AUTO=0;
					key_settings->JOY_FIRE3_AUTO=0;
					x_sensitivity=-1;
					y_sensitivity=-1;
					x_reversed=0;
					y_reversed=0;
					break;
			}
		}
		
		if ((ExKey & GP2X_A) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START)) {
			return;
		}
		else if ((ExKey & GP2X_B) || (ExKey & GP2X_SELECT)){
			return;
		}
	}
}

static void dipswitches_config(void)
{
	struct InputPort *inp=NULL;					/* input ports */
	int i;								/* Index into the input ports */
	int x_Pos;							/* Position X in the screen to print */
	int y_Pos;							/* Position Y in the screen to print */
	int index=0;							/* Index into the dipswitches to modify */
	int num_items;							/* Total number of dipswitches */
	const char *name;						/* Name of the dipswitch */
	unsigned long ExKey=0;						/* Key status */
	unsigned short *value_change;					/* Pointer of the value to be changed */
	int value_count;						/* Number of values */
	unsigned short value_range[32];					/* Different values */
	unsigned short value;						/* Current value*/
	unsigned short value_count_m;					/* Fire values count */

	/* Get input ports of the selected game */
	index=0;
	for (i=0;i<game_num;i++) {
		if (game_avail[i]==1) {
			if(index==last_game_selected) {
				inp=drivers[i]->input_ports;
			}
			index++;
		}
	}
	if (!inp) return;

	i=0;
	index=0;
	while(1)
	{
		/* Draw background image */
		load_bmp_8bpp(gp2x_screen8,gp2xmenu_bmp);
	
		i=0;
		x_Pos=41;
		y_Pos=48;
		num_items=0;

		/* Show currently selected item */
		gp2x_gamelist_text_out(x_Pos-16,y_Pos+(index*8)," >");

		/* Show Dipswitches configuration */	
		while (inp[i].type!= IPT_END)
		{
			/* Dipswitch Name */
			if ( (inp[i].type & ~IPF_MASK) == IPT_DIPSWITCH_NAME && inp[i].name!=0 && (inp[i].type & IPF_UNUSED) == 0 ) {
				name=inp[i].name;
				value=inp[i].default_value;
				if (index==num_items) {
					value_change = &(inp[i].default_value);
					value_count=0;
					value_count_m=1;
				} else
					value_count_m=0;
			}
			/* Cheat Name */
			if ( (inp[i].type & ~IPF_MASK) == (IPT_DIPSWITCH_NAME | IPF_CHEAT) && inp[i].name!=0 && (inp[i].type & IPF_UNUSED) == 0 ) {
				name=inp[i].name;
				value=inp[i].default_value;
				if (index==num_items) {
					value_change = &(inp[i].default_value);
					value_count=0;
					value_count_m=1;
				} else
					value_count_m=0;
			}
			/* Dipswitch Setting */
			if ((inp[i].type & ~IPF_MASK) == IPT_DIPSWITCH_SETTING) {
				if (value_count_m) {
					value_range[value_count]=inp[i].default_value;
					value_count++;
				}
				if (value==inp[i].default_value) {
					/* printf("%s: %s\n",name,inp[i].name); */
					gp2x_gamelist_text_out_fmt(x_Pos,y_Pos,"%s: %s",name,inp[i].name);
					y_Pos+=8;
					num_items++;
				}
			}
			i++;			
		}	

#ifdef PSP
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+8,"Press [] or O to confirm");
#else
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+8,"Press A or B to confirm");
#endif
	
		gp2x_video_flip();

		while(gp2x_joystick_read()&0x8c0ff55) { gp2x_timer_delay(150); }
		while(!(ExKey=gp2x_joystick_read()&0x8c0ff55)) { }
		if(ExKey & GP2X_DOWN){
			index++;
			index = index % num_items;
		}
		else if(ExKey & GP2X_UP){
			index--;
			if(index<0)
				index = num_items - 1;
		}
#ifdef GP2X
		else if(ExKey & GP2X_R || ExKey & GP2X_L){
#else
		else if(ExKey & GP2X_RIGHT || ExKey & GP2X_LEFT){
#endif
			/* Modify dipswitch */
			for(i=0;i<value_count;i++) {
				if (value_range[i]==*value_change) break;	
			}
			if (i==value_count-1)
				*value_change=value_range[0];
			if (i<value_count-1)
				*value_change=value_range[i+1];
		}

		if ((ExKey & GP2X_A) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START)) {
			return;
		}
		else if ((ExKey & GP2X_B) || (ExKey & GP2X_SELECT)){
			return;
		}
	}
}

#ifdef PSP
#define SAVEDATASTRUCTURE "gp2x_freq=%d;gp2x_frameskip=%d;gp2x_frameskip_auto=%d;gp2x_clock_cpu=%d;gp2x_sound_enable=%d;gp2x_clock_sound=%d;key_setting=%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%d,%d,%d,%d;gp2x_double_buffer=%d;gp2x_rotate=%d;gp2x_vsync=%d;gp2x_autofire=%d,%d,%d;\0"
#else
#define SAVEDATASTRUCTURE "gp2x_freq=%d;gp3x_frameskip=%d;gp2x_frameskip_auto=%d;gp2x_clock_cpu=%d;gp2x_sound_enable=%d;gp2x_clock_sound=%d;key_setting=%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%d,%d,%d,%d;gp2x_double_buffer=%d;gp2x_rotate=%d;gp2x_vsync=%d;gp2x_autofire=%d,%d,%d;\0"
#endif
#define SAVEDATAFILEDEF	"%scfg/mame.cfg\0"
#define SAVEDATAFILECFG "%scfg/%s.cfg\0"
/*static*/ int show_options(char *game)
{
	unsigned long ExKey=0;
	int selected_option=0;
	int x_Pos = 41;
	int y_Pos = 58;
#ifdef PSP
	int options_count = 10;
#else
	int options_count = 9;
#endif
	char text[256];
	FILE *f;

	/* Load Configuration Files */
	gp2x_save_config = 0;
#ifdef PSP
  strcpy(gp2x_path_mame,"");
#endif
	sprintf(text,SAVEDATAFILEDEF, gp2x_path_mame);
	f=fopen(text,"r");
	if (f) {
		fscanf(f,SAVEDATASTRUCTURE,
		&gp2x_freq,&gp2x_frameskip,&gp2x_frameskip_auto,&gp2x_clock_cpu,&gp2x_sound_enable,&gp2x_clock_sound,
		&(key_settings->JOY_FIRE1),&(key_settings->JOY_FIRE2),&(key_settings->JOY_FIRE3),&(key_settings->JOY_FIRE4),
		&(key_settings->JOY_FIRE5),&(key_settings->JOY_FIRE6),&(key_settings->JOY_FIRE7),&(key_settings->JOY_FIRE8),
		&(key_settings->JOY_FIRE9),&(key_settings->JOY_FIRE10),&x_sensitivity,&x_reversed,&y_sensitivity,&y_reversed,
		&gp2x_double_buffer,&gp2x_vsync,&(key_settings->JOY_FIRE1_AUTO),&(key_settings->JOY_FIRE2_AUTO),&(key_settings->JOY_FIRE3_AUTO));
		fclose(f);
	}
	sprintf(text,SAVEDATAFILECFG, gp2x_path_mame, game);
	f=fopen(text,"r");
	if (f) {
		fscanf(f,SAVEDATASTRUCTURE,
		&gp2x_freq,&gp2x_frameskip,&gp2x_frameskip_auto,&gp2x_clock_cpu,&gp2x_sound_enable,&gp2x_clock_sound,
		&(key_settings->JOY_FIRE1),&(key_settings->JOY_FIRE2),&(key_settings->JOY_FIRE3),&(key_settings->JOY_FIRE4),
		&(key_settings->JOY_FIRE5),&(key_settings->JOY_FIRE6),&(key_settings->JOY_FIRE7),&(key_settings->JOY_FIRE8),
		&(key_settings->JOY_FIRE9),&(key_settings->JOY_FIRE10),&x_sensitivity,&x_reversed,&y_sensitivity,&y_reversed,
		&gp2x_double_buffer,&gp2x_vsync,&(key_settings->JOY_FIRE1_AUTO),&(key_settings->JOY_FIRE2_AUTO),&(key_settings->JOY_FIRE3_AUTO));
		fclose(f);
	}


	while(1)
	{
		/* Draw background image */
		load_bmp_8bpp(gp2x_screen8,gp2xmenu_bmp);

		/* Draw the options */
		gp2x_gamelist_text_out(x_Pos,y_Pos,"Selected Game:\0");
		fast_memcpy (text,game_list_description(last_game_selected),33);
		text[32]='\0';
		gp2x_gamelist_text_out(x_Pos,y_Pos+10,text);
		/*gp2x_gamelist_text_out(x_Pos,y_Pos+10,game_list_description(last_game_selected));*/

#ifdef GP2X
		/* GP2X Clock*/
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30, "GP2X Clock    %d MHz", gp2x_freq);
		
		/* Frame-Skip */
		if(gp2x_frameskip_auto && gp2x_frameskip!=0) {
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    %s %d %s","<=",gp2x_frameskip, "(Auto-skip)");
		}
		else{
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    %s %d %s","=",gp2x_frameskip,"");
		}
#else
#ifdef PSP
		switch (gp2x_rotate)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","Fixed"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","Fixed DIV2"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","SW Scaled"); break;
			default: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","SW Streched"); break;
		}
		/* Frame-Skip */
		if(gp2x_frameskip_auto && gp2x_frameskip!=0) {
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    %s %d %s","<=",gp2x_frameskip, "(Auto-skip)");
		}
		else{
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    %s %d %s","=",gp2x_frameskip,"");
		}
#else
		switch (gp2x_rotate)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","Fixed"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","Fixed DIV2"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","SW Scaled"); break;
			default: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","HW Scaled"); break;
		}
		if (gp2x_frameskip_auto)
		{
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    Auto");
			gp2x_frameskip=-1;
		}
		else
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    = %d",gp2x_frameskip);
#endif
#endif

		/* Video Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Clock   %d%%",gp2x_clock_cpu);

		/* Video Sync */
#ifdef GP2X
		if (gp2x_double_buffer && gp2x_vsync==1)
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    VSync+DblBuf");
		else if (gp2x_double_buffer && gp2x_vsync==0)
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    DblBuf");
		else if (!gp2x_double_buffer && gp2x_vsync==1)
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    VSync");
		else if (gp2x_vsync==-1)
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    Off");
		else
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    Normal");
#else
		if (gp2x_vsync)
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    On");
		else
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    Off");

#endif
		/* Sound */
		switch(gp2x_sound_enable)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound OFF"); break;
#ifdef GP2X
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON (15 KHz)"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON (22 KHz)"); break;
			case 3: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON (33 KHz)"); break;
			case 4: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON (44 KHz)"); break;
			case 5: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON (11 KHz)"); break;
#else
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Emulated but OFF"); break;
			case 3: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Accurate and ON"); break;
#ifdef PSP
			case 4: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","44k 16v"); break;
			case 5: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","44k 8v"); break;
			case 6: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","44k 4v"); break;
			case 7: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","33k 16v"); break;
			case 8: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","33k 8v"); break;
			case 9: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","33k 4v"); break;
#endif
#endif
		}

		/* Audio Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Audio Clock   %d%%",gp2x_clock_sound);

		/* Controller Configuration */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+90,"Controller Configuration");

		/* Controller Configuration */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+100,"Dipswitches Configuration");

		/* Save Configuration */
		switch(gp2x_save_config) {
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+110,"No Save Configuration"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+110,"Save Configuration"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+110,"Save as Default"); break;
		}
#ifdef PSP
		/* PSP Clock*/
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+120, "PSP Clock     %d MHz", gp2x_freq);
		gp2x_gamelist_text_out(x_Pos,y_Pos+130,"Press [] to confirm, X return\0");
#else
		gp2x_gamelist_text_out(x_Pos,y_Pos+130,"Press B to confirm, X to return\0");
#endif

		/* Show currently selected item */
		gp2x_gamelist_text_out(x_Pos-16,y_Pos+(selected_option*10)+30," >");

		gp2x_video_flip();
		while(gp2x_joystick_read()&0x8c0ff55) { gp2x_timer_delay(150); }
		while(!(ExKey=gp2x_joystick_read()&0x8c0ff55)) { }
		if(ExKey & GP2X_DOWN){
			selected_option++;
			selected_option = selected_option % options_count;
		}
		else if(ExKey & GP2X_UP){
			selected_option--;
			if(selected_option<0)
				selected_option = options_count - 1;
		}
#ifdef GP2X
		else if(ExKey & GP2X_R || ExKey & GP2X_L){
#else
		else if(ExKey & GP2X_RIGHT || ExKey & GP2X_LEFT){
#endif
			switch(selected_option) {
			case 0:
#ifdef GP2X
				/* GP2X Clock */
				if(ExKey & GP2X_R){
					switch (gp2x_freq) {
						case  66: gp2x_freq=75;break;
						case  75: gp2x_freq=80;break;
						case  80: gp2x_freq=100;break;
						case 100: gp2x_freq=120;break;
						case 120: gp2x_freq=133;break;
						case 133: gp2x_freq=150;break;
						case 150: gp2x_freq=166;break;
						case 166: gp2x_freq=180;break;
						case 180: gp2x_freq=200;break;
						case 200: gp2x_freq=225;break;
						case 225: gp2x_freq=233;break;
						case 233: gp2x_freq=245;break;
						case 245: gp2x_freq=250;break;
						case 250: gp2x_freq=255;break;
						case 255: gp2x_freq=260;break;
						case 260: gp2x_freq=265;break;
						case 265: gp2x_freq=266;break;
						case 266: gp2x_freq=270;break;
						case 270: gp2x_freq=275;break;
						case 275: gp2x_freq=280;break;
						case 280: gp2x_freq=285;break;
						case 285: gp2x_freq=290;break;
						case 290: gp2x_freq=295;break;
						case 295: gp2x_freq=300;break;
						case 300: gp2x_freq=66;break;
					}
				} else {
					switch (gp2x_freq) {
						case  66: gp2x_freq=300;break;
						case  75: gp2x_freq=66;break;
						case  80: gp2x_freq=75;break;
						case 100: gp2x_freq=80;break;
						case 120: gp2x_freq=100;break;
						case 133: gp2x_freq=120;break;
						case 150: gp2x_freq=133;break;
						case 166: gp2x_freq=150;break;
						case 180: gp2x_freq=166;break;
						case 200: gp2x_freq=180;break;
						case 225: gp2x_freq=200;break;
						case 233: gp2x_freq=225;break;
						case 245: gp2x_freq=233;break;
						case 250: gp2x_freq=245;break;
						case 255: gp2x_freq=250;break;
						case 260: gp2x_freq=255;break;
						case 265: gp2x_freq=260;break;
						case 266: gp2x_freq=265;break;
						case 270: gp2x_freq=266;break;
						case 275: gp2x_freq=270;break;
						case 280: gp2x_freq=275;break;
						case 285: gp2x_freq=280;break;
						case 290: gp2x_freq=285;break;
						case 295: gp2x_freq=290;break;
						case 300: gp2x_freq=295;break;
					}
				}
#else
				if (ExKey & GP2X_RIGHT)
					gp2x_rotate++;
				else
				if (ExKey & GP2X_LEFT)
					gp2x_rotate--;
				if (gp2x_rotate<0)
					gp2x_rotate=3;
				else if (gp2x_rotate>3)
					gp2x_rotate=0;
#ifdef DREAMCAST
				if (gp2x_rotate==3)
					gp2x_vsync=1;
#endif

#endif
				break;
			case 1:
				/* "Frame-Skip" */
#ifdef GP2X
				if(ExKey & GP2X_R){
#else
				if(ExKey & GP2X_RIGHT){
#endif
					gp2x_frameskip ++;
					if (!gp2x_frameskip)
						gp2x_frameskip_auto=0;
					else
					if (gp2x_frameskip > 5) {
#ifdef GP2X
						gp2x_frameskip = 0;
						gp2x_frameskip_auto=!gp2x_frameskip_auto; 
#else
#ifdef PSP
						gp2x_frameskip = 0;
						gp2x_frameskip_auto=!gp2x_frameskip_auto;
#else
						gp2x_frameskip = -1;
						gp2x_frameskip_auto = 1;
#endif
#endif
					}
				}
				else{
					gp2x_frameskip--;
#ifdef GP2X
					if (gp2x_frameskip < 0){
						gp2x_frameskip = 5;
						gp2x_frameskip_auto=!gp2x_frameskip_auto; 
					}
#else
#ifdef PSP
					if (gp2x_frameskip < 0){
						gp2x_frameskip = 5;
						gp2x_frameskip_auto=!gp2x_frameskip_auto;
					}
#else
					if (gp2x_frameskip==-1)
						gp2x_frameskip_auto=1;
					else if (gp2x_frameskip<-1)
					{
						gp2x_frameskip = 5;
						gp2x_frameskip_auto = 0;
					}
#endif
#endif
				}
				break;
			case 2:
				/* "Video Clock" */
#ifdef GP2X
				if(ExKey & GP2X_R){
#else
				if(ExKey & GP2X_RIGHT){
#endif
					gp2x_clock_cpu += 10; /* Add 10% */
					if (gp2x_clock_cpu > 200) /* 200% is the max */
						gp2x_clock_cpu = 200;
				}
				else{
					gp2x_clock_cpu -= 10; /* Subtract 10% */
					if (gp2x_clock_cpu < 10) /* 10% is the min */
						gp2x_clock_cpu = 10;
				}
				break;
			case 3:
				/* Video Sync */
#ifdef GP2X
				if (!gp2x_double_buffer && gp2x_vsync==0)
				{ gp2x_double_buffer=0; gp2x_vsync=-1; }
				else if (!gp2x_double_buffer && gp2x_vsync==-1)
				{ gp2x_double_buffer=1; gp2x_vsync=0; }
				else if (gp2x_double_buffer && gp2x_vsync==0)
				{ gp2x_double_buffer=0; gp2x_vsync=1; }
				else if (!gp2x_double_buffer && gp2x_vsync==1)				
				{ gp2x_double_buffer=1; gp2x_vsync=1; }	
				else 
				{ gp2x_double_buffer=0; gp2x_vsync=0; }	
#else
				gp2x_vsync=(gp2x_vsync+1)&1;
#endif
				break;

			case 4:
#ifndef NOSOUND
				/* "Sound" */
#ifdef GP2X
				if(ExKey & GP2X_R){
#else
				if(ExKey & GP2X_RIGHT){
#endif
					gp2x_sound_enable++;
#ifdef PSP
					if (gp2x_sound_enable>9)
#else
#ifdef GP2X
					if (gp2x_sound_enable>5)
#else
					if (gp2x_sound_enable>3)
#endif
#endif
						gp2x_sound_enable=0;
				}
				else {
					gp2x_sound_enable--;
					if (gp2x_sound_enable<0)
#ifdef PSP
						gp2x_sound_enable=9;
#else
#ifdef GP2X
						gp2x_sound_enable=5;
#else
						gp2x_sound_enable=3;
#endif
#endif
				}
#endif
				break;
			case 5:
				/* "Audio Clock" */
#ifdef GP2X
				if(ExKey & GP2X_R){
#else
				if(ExKey & GP2X_RIGHT){
#endif
					gp2x_clock_sound += 10; /* Add 10% */
					if (gp2x_clock_sound > 200) /* 200% is the max */
						gp2x_clock_sound = 200;
				}
				else{
					gp2x_clock_sound -= 10; /* Subtract 10% */
					if (gp2x_clock_sound < 10) /* 10% is the min */
						gp2x_clock_sound = 10;
				}
				break;
			case 6:
				/* Controller Configuration */
				controller_config();
				break;
			case 7:
				/* Dipswitches Configuration */
				dipswitches_config();
				break;
			case 8:
				/* Save Configuration */
#ifdef GP2X
				if(ExKey & GP2X_R){
#else
				if(ExKey & GP2X_RIGHT){
#endif
					gp2x_save_config += 1;
					if (gp2x_save_config > 2)
						gp2x_save_config = 0;
				}
				else{
					gp2x_save_config -= 1;
					if (gp2x_save_config < 0)
						gp2x_save_config = 2;
				}
				break;
#ifdef PSP
			case 9:
				/* PSP Clock */
				if(ExKey & GP2X_RIGHT){
					switch (gp2x_freq) {
						case 133: gp2x_freq=166;break;
						case 166: gp2x_freq=200;break;
						case 200: gp2x_freq=222;break;
						case 222: gp2x_freq=266;break;
						case 266: gp2x_freq=300;break;
						case 300: gp2x_freq=333;break;
						case 333: gp2x_freq=133;break;
					}
				} else {
					switch (gp2x_freq) {
						case 133: gp2x_freq=333;break;
						case 166: gp2x_freq=133;break;
						case 200: gp2x_freq=166;break;
						case 222: gp2x_freq=200;break;
						case 266: gp2x_freq=222;break;
						case 300: gp2x_freq=266;break;
						case 333: gp2x_freq=300;break;
					}
				}
				break;
#endif
			}
		}
#ifndef GP2X
		if ((ExKey & GP2X_A) || (ExKey & GP2X_START)) {
#else
		if ((ExKey & GP2X_A) || (ExKey & GP2X_B) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START)) {
#endif

			/* Save Configuration Files */
			if (gp2x_save_config>1) {
				sprintf(text,SAVEDATAFILEDEF, gp2x_path_mame);
				f=fopen(text,"w");
				if (f) {
					fprintf(f,SAVEDATASTRUCTURE,
					gp2x_freq,gp2x_frameskip,gp2x_frameskip_auto,gp2x_clock_cpu,gp2x_sound_enable,gp2x_clock_sound,
					(key_settings->JOY_FIRE1),(key_settings->JOY_FIRE2),(key_settings->JOY_FIRE3),(key_settings->JOY_FIRE4),
					(key_settings->JOY_FIRE5),(key_settings->JOY_FIRE6),(key_settings->JOY_FIRE7),(key_settings->JOY_FIRE8),
					(key_settings->JOY_FIRE9),(key_settings->JOY_FIRE10),x_sensitivity,x_reversed,y_sensitivity,y_reversed,
					gp2x_double_buffer,gp2x_vsync,(key_settings->JOY_FIRE1_AUTO),(key_settings->JOY_FIRE2_AUTO),(key_settings->JOY_FIRE3_AUTO));
					fclose(f);
#ifdef GP2X
					sync();
#endif
				}
			}
			if (gp2x_save_config>0) {
				sprintf(text,SAVEDATAFILECFG, gp2x_path_mame, game);
				f=fopen(text,"w");
				if (f) {
					fprintf(f,SAVEDATASTRUCTURE,
					gp2x_freq,gp2x_frameskip,gp2x_frameskip_auto,gp2x_clock_cpu,gp2x_sound_enable,gp2x_clock_sound,
					(key_settings->JOY_FIRE1),(key_settings->JOY_FIRE2),(key_settings->JOY_FIRE3),(key_settings->JOY_FIRE4),
					(key_settings->JOY_FIRE5),(key_settings->JOY_FIRE6),(key_settings->JOY_FIRE7),(key_settings->JOY_FIRE8),
					(key_settings->JOY_FIRE9),(key_settings->JOY_FIRE10),x_sensitivity,x_reversed,y_sensitivity,y_reversed,
					gp2x_rotate,gp2x_vsync,(key_settings->JOY_FIRE1_AUTO),(key_settings->JOY_FIRE2_AUTO),(key_settings->JOY_FIRE3_AUTO));
					fclose(f);
#ifdef GP2X
					sync();
#endif
				}
			}

			/* Selected game will be run */
			return 1;
		}
#ifndef GP2X
		else if ((ExKey & GP2X_X) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_SELECT)){
#else
		else if ((ExKey & GP2X_X) || (ExKey & GP2X_Y) || (ExKey & GP2X_SELECT)){
#endif
			/* Return To Menu */
			return 0;
		}
	}
}

void select_game(char *game) {

	unsigned long ExKey;
	int c;

	/* No Selected game */
	strcpy(game,"builtinn");

	/* Clean screen */
	gp2x_video_flip();

	/* enable extra PSP-2000 memory */
#ifdef PSP_2K
	psp2k_mem_init();
#endif
	/* Wait until no key pressed */
	while(gp2x_joystick_read()&0x8c0ff55) 
		gp2x_timer_delay(100);

	/* Available games? */
	if(game_num_avail==0) {
		gp2x_mame_palette();
		gp2x_text_out( 35, 110, "ERROR: NO AVAILABLE GAMES FOUND" );
		gp2x_video_flip();
		while(1) { if (gp2x_joystick_read()&GP2X_A) exit(0);}
	}

#ifdef PSP
	SetGP2XClock(133);
#else
	SetGP2XClock(66);
#endif

	/* Wait until user selects a game */
	while(1) {
		game_list_view(&last_game_selected);
		gp2x_video_flip();

#ifdef GP2X
		if( (gp2x_joystick_read()&0x8c0ff55)) 
			gp2x_timer_delay(100); 
		while(!(ExKey=gp2x_joystick_read()&0x8c0ff55)) { if ((ExKey & GP2X_L) && (ExKey & GP2X_R)) exit(0); }
#else
		if( (gp2x_joystick_read()&0x8c0ff55)) 
			gp2x_timer_delay(100); 
		while(!(ExKey=gp2x_joystick_read()&0x8c0ff55))
			gp2x_timer_delay(100); 
#endif

		if (ExKey & GP2X_UP) last_game_selected--;
		if (ExKey & GP2X_DOWN) last_game_selected++;
		if (ExKey & GP2X_L) last_game_selected-=21;
		if (ExKey & GP2X_R) last_game_selected+=21;
		if ((ExKey & GP2X_L) && (ExKey & GP2X_R)) exit(0);

		/* If Button A is pressed, or a rom name was passed to this application */
#ifndef GP2X
		{
#ifdef DREAMCAST
			static int parasalir=0;
			if (ExKey & GP2X_PUSH)
				parasalir++;
			else
				parasalir=0;
			if (parasalir>8)
				gp2x_deinit();
#else
			if (ExKey & GP2X_PUSH)
				gp2x_deinit();
#endif
		}
		if ((ExKey & GP2X_A) || (ExKey & GP2X_START))
#else
		if ((ExKey & GP2X_A) || (ExKey & GP2X_B) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START))
#endif
		{
			/* Select the game */
			game_list_select(last_game_selected, game);

			/* Emulation Options */
			if(show_options(game))
			{
				/* break out of the while(1) loop */
				break;
			}
		}
	}
	SetGP2XClock(gp2x_freq);
}
Beispiel #26
0
int main( int argc, char* args[] )
{
    //Quit flag
    bool quit = false;
    //Initialize
    if( init() == false )
    {
        return 1;
    }

    //Load the files
    if( load_files() == false )
    {
        return 1;
    }

    //Apply the background
    show_screen();
    //While the user hasn't quit
    while( quit == false )
    {
      if( Mix_PlayingMusic() == 0 )
	{
	  //Play the music
	  if( Mix_PlayMusic( music, -1 ) == -1 )
	    {
	      return 1;
	    }
	}
        //While there's events to handle
      while( SDL_PollEvent( &event ) )
	{
	  if(event.type==SDL_KEYDOWN)
	    {
	      if(event.key.keysym.sym==SDLK_w)
		{
		  Mix_PlayChannel(-1,jump,0);
		  if(arrowPos==2 && screenNum==0) // main menu is showing
		    {
		      arrowPos=0;
		    }
		  else if((arrowPos==1 || arrowPos==2 || arrowPos==3)&&screenNum==1) // options is showing
		    {
		      if(arrowPos==3)
			{
			  arrowPos-=2;
			}
		      else
			{
			  arrowPos=0;
			}
		    }
		  else
		    {
		      arrowPos=arrowPos;
		    }
		}
	      else if(event.key.keysym.sym==SDLK_d)
		{
		  Mix_PlayChannel(-1,fire,0);
		  if(arrowPos==0 && screenNum==0)
		    {
		      arrowPos=1;
		    }
		  else if(arrowPos==1 && screenNum==1)
		    {
		      arrowPos=2;
		    }
		  else
		    {
		      arrowPos=arrowPos;
		    }
		}
	      else if(event.key.keysym.sym==SDLK_a)
		{
		  if(arrowPos==1 && screenNum==0)
		    {
		      arrowPos=0;
		    }
		  else if(arrowPos==2 && screenNum==1)
		    {
		      arrowPos=1;
		    }
		  else
		    {
		      arrowPos=arrowPos;
		    }
		}
	      else if(event.key.keysym.sym==SDLK_s)
		{
		  if((arrowPos==0 || arrowPos==1) && screenNum==0)
		    {
		      arrowPos=2;
		    }
		  else if(arrowPos<3 && screenNum==1)
		    {
		      if(arrowPos==0)
			{
			  arrowPos++;
			}
		      else
			{
			  arrowPos=3;
			}
		    }
		  else
		    {
		      arrowPos=arrowPos;
		    }
		}
	      else if(event.key.keysym.sym==SDLK_e)
		{
		  if((arrowPos==0 || arrowPos==1) && screenNum==0)
		    {
		      screenNum=2;
		      quit=true;
		    }
		  else if(arrowPos==2 && screenNum==0)
		    {
		      arrowPos=0;
		      screenNum=1;
		    }	  
		  else if(arrowPos==3 && screenNum==1)
		    {
		      screenNum=0;
		      arrowPos=0;
		    }
		}

	    }
	  if(screenNum==0)
	    {
	      show_screen();
	    }
	  else if(screenNum==1)
	    {
	      show_options();
	    }
	  else
	    {
	      show_loading();
	    }
	}
      //If the user has Xed out the window
      if( event.type == SDL_QUIT )
	{
	  //Quit the program
	  quit = true;
	}
    }
    SDL_Delay(500);
    //Free surfaces, fonts and sounds
    //then quit SDL_mixer, SDL_ttf and SDL
    clean_up();

    return 0;
}
int avs_parse_tree (AVSTree *avstree, AVSContainer *curcontainer)
{
        AVSElement *element = NULL;
        char namedelem[30];
        int isnamed;
        char *next_section = NULL;
        int marker;

        if (curcontainer == NULL)
                return -1;

        while (avstree->cur < (avstree->data + avstree->datasize)) {

                element = NULL;

                marker = AVS_SERIALIZE_GET_INT (AVS_TREE_GET_CURRENT_POINTER (avstree));
                AVS_SERIALIZE_SKIP_INT (AVS_TREE_GET_CURRENT_POINTER (avstree));

                /* Named preset section */
                isnamed = FALSE;
                if (marker > 0xff) {
                        printf ("Marker > 0xff, named APE %x\n", marker);

                        strncpy (namedelem, AVS_TREE_GET_CURRENT_POINTER (avstree), 30);

                        AVS_SERIALIZE_SKIP_LENGTH (avstree->cur, 32);
                        isnamed = TRUE;
                        marker = AVS_ELEMENT_TYPE_APE;

                        printf("avstree->cur %s\n", avstree->cur);
                }
                // FIXME: In some files next_section doesn't point to the correct location.
                // Check the location of the section's size data. For now I've commented the
                // line at the bottom of this function where avstree->cur is assigned next_section.
                // This may not work for every file, but it works with the few I've checked.
                next_section = AVS_SERIALIZE_GET_NEXT_SECTION (AVS_TREE_GET_CURRENT_POINTER (avstree));
                avstree->cur_section_length = next_section - avstree->cur;

                AVS_SERIALIZE_SKIP_INT (AVS_TREE_GET_CURRENT_POINTER (avstree));

                printf (":: 0x%x marker! %d\n", marker, marker);

                /* FIXME: Use a table lookup here instead of giant function */
                switch (marker) {
                    case AVS_ELEMENT_TYPE_RENDER_SIMPLESPECTRUM:

                    break;

                    case AVS_ELEMENT_TYPE_MISC_COMMENT:
                            element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_MISC_COMMENT,
                                                "text", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                                                NULL);

                    break;

                    case AVS_ELEMENT_TYPE_MISC_RENDERSTATE:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_MISC_RENDERSTATE,
                            "newmode", AVS_SERIALIZE_ENTRY_TYPE_INT,
                            NULL);
                    break;
            
                    case AVS_ELEMENT_TYPE_MISC_BPM:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_MISC_BPM,
                            "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                            "arbitrary", AVS_SERIALIZE_ENTRY_TYPE_INT,
                            "skip", AVS_SERIALIZE_ENTRY_TYPE_INT,
                            "invert", AVS_SERIALIZE_ENTRY_TYPE_INT,
                            "arbVal", AVS_SERIALIZE_ENTRY_TYPE_INT,
                            "skipVal", AVS_SERIALIZE_ENTRY_TYPE_INT,
                            "skipfirst", AVS_SERIALIZE_ENTRY_TYPE_INT,
                            NULL);
                    break;

            
                case AVS_ELEMENT_TYPE_MISC_STACK:
                    element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_MISC_STACK,
                        "dir", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "which", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "blend", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "adjblend_val", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        NULL);
                break;
            
                case AVS_ELEMENT_TYPE_RENDER_RING:
                    element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_RENDER_RING,
                        "source and place", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "palette", AVS_SERIALIZE_ENTRY_TYPE_PALETTE,
                        "size", AVS_SERIALIZE_ENTRY_TYPE_BYTE,
                        "type", AVS_SERIALIZE_ENTRY_TYPE_BYTE,
                        NULL);

                break;

                case AVS_ELEMENT_TYPE_RENDER_SUPERSCOPE:
                    element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_RENDER_SUPERSCOPE,
                        "empty", AVS_SERIALIZE_ENTRY_TYPE_BYTE,
                        "point", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                        "frame", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                        "beat", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                        "init", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                        "channel source", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "palette", AVS_SERIALIZE_ENTRY_TYPE_PALETTE,
                        "draw type", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        NULL);

                break;

                case AVS_ELEMENT_TYPE_TRANS_DMOVE:
                    element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_DMOVE,
                        "empty", AVS_SERIALIZE_ENTRY_TYPE_BYTE,
                        "point", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                        "frame", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                        "beat", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                        "init", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                        "subpixel", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "rectcoords", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "xres", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "yres", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "blend", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "wrap", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "buffern", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "nomove", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        NULL);
                break;

                case AVS_ELEMENT_TYPE_RENDER_CLEARSCREEN:
                    element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_RENDER_CLEARSCREEN,
                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "color", AVS_SERIALIZE_ENTRY_TYPE_COLOR,
                        "clear type", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "clear 5050", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "first", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        NULL);

                break;

                case AVS_ELEMENT_TYPE_RENDER_BASSSPIN:
                    element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_RENDER_BASSSPIN,
                        "chan enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        "left color", AVS_SERIALIZE_ENTRY_TYPE_COLOR,
                        "right color", AVS_SERIALIZE_ENTRY_TYPE_COLOR,
                        "draw type", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        NULL);
                break;

                case AVS_ELEMENT_TYPE_TRANS_FASTBRIGHT:
                    element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_FASTBRIGHT,
                            "brightness type", AVS_SERIALIZE_ENTRY_TYPE_INT,
                            NULL);

                break;

                case AVS_ELEMENT_TYPE_TRANS_INVERT:
                    element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_INVERT,
                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                        NULL);

                break;

                case AVS_ELEMENT_TYPE_TRANS_BLUR:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_BLUR,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "roundmode",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_MOVEMENT:
                        element = AVS_ELEMENT (avs_parse_trans_movement (avstree));

                        break;

                case AVS_ELEMENT_TYPE_TRANS_ONETONE:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_ONETONE,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "color",  AVS_SERIALIZE_ENTRY_TYPE_COLOR,
                                        "blend",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "blendavg",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "invert",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_GRAIN:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_GRAIN,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "blend",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "blendavg",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "smax",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "staticgrain",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_MIRROR:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_MIRROR,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "mode",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "onbeat",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "smooth",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "slower",  AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_SCATTER:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_SCATTER,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_FADEOUT:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_FADEOUT,
                                        "fadelen", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "color", AVS_SERIALIZE_ENTRY_TYPE_COLOR,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_MOSAIC:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_MOSAIC,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "quality", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "quality2", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "blend", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "blendavg", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "onbeat", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "frame duration", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_WATER:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_BRIGHTNESS,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_WATERBUMP:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_WATERBUMP,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "density", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "depth", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "random prop", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "drop position x", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "drop position y", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "drop radius", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "method", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_BRIGHTNESS:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_BRIGHTNESS,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "blend", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "blendavg", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "redp", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "greenp", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "bleup", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "dissoc", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "color", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "exclude", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "distance", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_BUMPMAP:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_BUMPMAP,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "onbeat", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "frame duration", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "depth", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "depth 2", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "blend", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "blendavg", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "code1", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                                        "code2", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                                        "code3", AVS_SERIALIZE_ENTRY_TYPE_STRING,
                                        "showlight", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "invert", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "oldstyle", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "buffern", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_TRANS_NFRAMECLEAR:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_NFRAMECLEAR,
                                        "color", AVS_SERIALIZE_ENTRY_TYPE_COLOR,
                                        "blend", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "n frame", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_RENDER_PARTICLE:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_RENDER_PARTICLE,
                                        "enabled", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "color", AVS_SERIALIZE_ENTRY_TYPE_COLOR,
                                        "maxdist", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "size", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "size2", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "blend", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_RENDER_OSCSTARS:
                        element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_RENDER_OSCSTARS,
                                        "effect", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "palette", AVS_SERIALIZE_ENTRY_TYPE_PALETTE,
                                        "size", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        "rotate", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                        NULL);

                        break;

                case AVS_ELEMENT_TYPE_APE:

                        printf ("APE NAME: %s\n", namedelem);

                        element = NULL;
                        if (strcmp (namedelem, "Multiplier") == 0) {
                                element = avs_parse_element_non_complex (avstree, AVS_ELEMENT_TYPE_TRANS_MULTIPLIER,
                                                "multiply", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                                NULL);
                        } else if (strcmp (namedelem, "Channel Shift") == 0) {
                                element = avs_parse_element_non_complex (avstree,
                                                AVS_ELEMENT_TYPE_TRANS_CHANNELSHIFT,
                                                "shift", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                                "onbeat", AVS_SERIALIZE_ENTRY_TYPE_INT,
                                                NULL);
                        } else {
                                printf ("Unhandled named entry: %s position: %x\n",
                                                namedelem, avstree->cur - avstree->data);
                        }

                        break;

                default:
                        printf ("Unhandled type: %x position: %x\n", *avstree->cur, avstree->cur - avstree->data);

                        return -1;

                        break;
                }

                if (element != NULL) {
                        visual_list_add (curcontainer->members, element);

                        show_options (element);
                }


                avstree->cur = next_section;
        }

        return 0;
}
Beispiel #28
0
int main(int argc,char **argv)
{
  char stdi=0;
  FILE *file;
  double min,max;
  double av,varianz;
  long i,n;
    
  if (scan_help(argc,argv))
    show_options(argv[0]);

  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif

  infile=search_datafile(argc,argv,NULL,verbosity);
  if (infile == NULL)
    stdi=1;

  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".res");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
      strcpy(outfile,"stdin.res");
    }
  }
  if (!stdo)
    test_outfile(outfile);

  if (xmin >= xmax) {
    fprintf(stderr,"Choosing the minimum larger or equal the maximum\n"
	    "makes no sense. Exiting!\n");
    exit(RESCALE__WRONG_INTERVAL);
  }

  if (column == NULL)
    series=(double**)get_multi_series(infile,&length,exclude,&dim,"",dimset,
				      verbosity);
  else
    series=(double**)get_multi_series(infile,&length,exclude,&dim,column,
				      dimset,verbosity);

  for (n=0;n<dim;n++) {
    variance(series[n],length,&av,&varianz);
    if (ddof!=0)
      varianz *= sqrt((double) length/(length-ddof));
    
    if (set_av)
      for (i=0;i<length;i++)
	series[n][i] -= av;

    if (set_var)
      for (i=0;i<length;i++)
	series[n][i] /= varianz;
  
    if (!set_var && !set_av) {
      rescale_data(series[n],length,&min,&max);
      for (i=0;i<length;i++)
	series[n][i]=series[n][i]*(xmax-xmin)+xmin;
    }
  }

  if (stdo) {
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Writing to stdout\n");
    for (i=0;i<length;i++) {
      fprintf(stdout,"%e",series[0][i]);
      for (n=1;n<dim;n++)
	fprintf(stdout," %e",series[n][i]);
      fprintf(stdout,"\n");
    }
  }
  else {
    file=fopen(outfile,"w");
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Opened %s for writing\n",outfile);
    for (i=0;i<length;i++) {
      fprintf(file,"%e",series[0][i]);
      for (n=1;n<dim;n++)
	fprintf(file," %e",series[n][i]);
      fprintf(file,"\n");
    }
    fclose(file);
  }

  return 0;
}
Beispiel #29
0
PRIVATE void 
talk ()
{
  char *line;
  char *machine;
  int connection;
  int code;
  int value;
  access *Data;
  unsigned short port;

  Data = (access *) space (sizeof (access));

  printf ("enter machine to connect to (return if same as caller)\n");
  line = get_line (stdin);
  if (*line == '\0')
    {
      machine = NULL;
      free (line);
    }
  else
      machine = line;

  printf ("enter port number (return if 5000)\n");
  line = get_line (stdin);
  if (*line == '\0')
      port = 5000;
  else
      sscanf (line, "%u", port);
  free (line);

  while (TRUE)
    {
      if ((connection = DialServer (machine, port)) > 0)
	{
	  system ("clear");
	  while (CheckForData (connection, Data, sizeof (access)) <= 0);
	  show_options (Data);

	  line = get_line (stdin);
	  if (*line == '\0')
	    {
	      Send (connection, Data, sizeof (access));
	      free (line);
	    }
	  else if (*line == '\\')
	    {
	      Data->ctrl = -1;
	      if ((connection = DialServer (machine, port)) > 0)
		Send (connection, Data, sizeof (access));
	      HangUp (connection);
	      free (line);
	      free (machine);
	      exit (0);
	    }
	  else
	    {
	      sscanf (line, "%d %d", &code, &value);

	      switch (code)
		{
		case 0:
		  if (value == 2)
		    {
		      printf ("re-read parameters? (y/n) [y]\n");
		      line = get_line (stdin);
		      if (!(*line == 'y' || *line == '\0'))
			{
			  free (line);
			  Data->ctrl = 1;
			  break;
			}
		      printf ("input filename [alchemy.inp]\n");
		      line = get_line (stdin);
		      if (*line == '\0')
			strcpy (Data->message, "alchemy.inp");
		      else
			strcpy (Data->message, line);
		      free (line);
		    }
		  Data->ctrl = value;
		  break;
		  
		case 1:
		  Data->show = value;
		  break;
		  
		default:
		  printf ("no such parameter\n");
		  break;
		}
	      free (line);

	      Send (connection, Data, sizeof (access));
	    }
	}
    }
}
Beispiel #30
0
int main(int argc,char **argv)
{
  char stdi=0,done;
  long i,j,hdim,actfound;
  double maxinterval,*swap,*newcast;
  FILE *file=NULL;
  
  if (scan_help(argc,argv))
    show_options(argv[0]);
  
  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif
  
  infile=search_datafile(argc,argv,NULL,verbosity);
  if (infile == NULL)
    stdi=1;
  
  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+6,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".cast");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)11,(size_t)1));
      strcpy(outfile,"stdin.cast");
    }
  }
  if (!onscreen)
    test_outfile(outfile);
  
  hdim=(embed-1)*DELAY+1;
  if (column == NULL)
    series=(double**)get_multi_series(infile,&LENGTH,exclude,&dim,"",dimset,
				      verbosity);
  else
    series=(double**)get_multi_series(infile,&LENGTH,exclude,&dim,column,
				      dimset,verbosity);
  check_alloc(min=(double*)malloc(sizeof(double)*dim));
  check_alloc(interval=(double*)malloc(sizeof(double)*dim));
  dim1=dim-1;
  maxinterval=0.0;
  for (i=0;i<dim;i++) {
    rescale_data(series[i],LENGTH,&min[i],&interval[i]);
    if (interval[i] > maxinterval)
      maxinterval=interval[i];
  }
  
  check_alloc(cast=(double**)malloc(sizeof(double*)*hdim));
  for (i=0;i<hdim;i++)
    check_alloc(cast[i]=(double*)malloc(sizeof(double)*dim));
  check_alloc(newcast=(double*)malloc(sizeof(double)*dim));
    
  check_alloc(list=(long*)malloc(sizeof(long)*LENGTH));
  check_alloc(found=(long*)malloc(sizeof(long)*LENGTH));
  check_alloc(box=(long**)malloc(sizeof(long*)*NMAX));
  for (i=0;i<NMAX;i++)
    check_alloc(box[i]=(long*)malloc(sizeof(long)*NMAX));
  
  check_alloc(localav=(double*)malloc(sizeof(double)*dim*embed));
  check_alloc(foreav=(double*)malloc(sizeof(double)*dim));
  check_alloc(vec=(double*)malloc(sizeof(double)*dim*embed));
  check_alloc(mat=(double**)malloc(sizeof(double*)*dim*embed));
  for (i=0;i<dim*embed;i++)
    check_alloc(mat[i]=(double*)malloc(sizeof(double)*dim*embed));

  if (epsset)
    EPS0 /= maxinterval;

  for (j=0;j<dim;j++)
    for (i=0;i<hdim;i++)
      cast[i][j]=series[j][LENGTH-hdim+i];
  
  if (!onscreen) {
    file=fopen(outfile,"w");
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Opened %s for writing\n",outfile);
  }
  else {
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Writing to stdout\n");
  }

  for (i=0;i<FLENGTH;i++) {
    done=0;
    epsilon=EPS0/EPSF;
    while (!done) {
      epsilon*=EPSF;
      put_in_boxes();
      actfound=hfind_neighbors();
      if (actfound >= MINN) {
	if (!do_zeroth)
	  make_fit(actfound,newcast);
	else
	  make_zeroth(actfound,newcast);
	if (onscreen) {
	  for (j=0;j<dim-1;j++)
	    printf("%e ",newcast[j]*interval[j]+min[j]);
	  printf("%e\n",newcast[dim-1]*interval[dim-1]+min[dim-1]);
	  fflush(stdout);
	}
	else {
	  for (j=0;j<dim-1;j++)
	    fprintf(file,"%e ",newcast[j]*interval[j]+min[j]);
	  fprintf(file,"%e\n",newcast[dim-1]*interval[dim-1]+min[dim-1]);
	  fflush(file);
	}
	done=1;
	for (j=0;j<dim;j++) {
	  if ((newcast[j] > 2.0) || (newcast[j] < -1.0)) {
	    fprintf(stderr,"Forecast failed. Escaping data region!\n");
	    exit(NSTEP__ESCAPE_REGION);
	  }
	}

	swap=cast[0];
	for (j=0;j<hdim-1;j++)
	  cast[j]=cast[j+1];
	cast[hdim-1]=swap;
	for (j=0;j<dim;j++)
	  cast[hdim-1][j]=newcast[j];
      }
    }
  }
  if (!onscreen)
    fclose(file);
  
  if (outfile != NULL)
    free(outfile);
  for (i=0;i<embed*dim;i++)
    free(mat[i]);
  free(mat);
  for (i=0;i<hdim;i++)
    free(cast[i]);
  free(cast);
  free(newcast);
  free(found);
  free(list);
  for (i=0;i<NMAX;i++)
    free(box[i]);
  free(box);
  free(vec);
  free(localav);
  free(foreav);
  free(min);
  free(interval);
  for (i=0;i<dim;i++)
    free(series[i]);
  free(series);

  return 0;
}