Exemple #1
0
static int process_tuple(void * vinstance, wsdata_t* input_data,
                         ws_doutput_t * dout, int type_index) {
     proc_instance_t * proc = (proc_instance_t*)vinstance;

     proc->tuple_cnt++;

     wsdt_tuple_t * tuple = (wsdt_tuple_t *)input_data->data;
     int i;
     wsdt_ts_t * ts= NULL; 
     //search for timestamp
     for (i = 0; i < tuple->len; i++) {
          if (tuple->member[i]->dtype == dtype_ts) {
               ts = tuple->member[i]->data;
               break;
          }
     } 
     FILE * fp;
     if (!ts) {
          fp = get_fp(proc, 0, input_data);
     }
     else {
          fp = get_fp(proc, ts->sec, input_data);
     }

     if (!fp) {
          return 0;
     }
     local_print_tuple(proc, input_data, fp);

     return 0;
}
void set_proposal_fee(proposal_info_type *info) {
    int ret_code;
    fp_number value;
    
    
    while (1) {
    
		print_str("Enter the % fee/profit: ");
	
		ret_code=get_fp(&value);
	
		if (ret_code < 0) {
	    
	    	print_str("\nInvalid number entered\n");
	    	continue;
	    
		}

		if (value < 0 || value > 1500)  {

			print_str("\nInvalid fee entered.  Valid range is 0-15\n");
			continue;
		}

		info->fee = value;
		return;
    }
}
Exemple #3
0
/**
 * The b vector is given in the file with format
 *
 * b_1
 * ...
 * b_n
 *
 * The pointer to dim is either NULL or refers to some best guess of the dimensions of the array;
 *	get_b() will set dim to the actual size as a side-effect.
 */
double * get_b(char *filename, int *dim) {
	int n = 0;
	size_t size;

	size = *dim;
	double *b = calloc(size, sizeof(double));

	// Get the file specified.
	FILE *fp = get_fp(filename, "r");

	size_t m = MAX_BUF;
	char *line_buf = calloc(m, sizeof(char));
	double result;

	while(getline(&line_buf, &m, fp) != -1) {
		sscanf(line_buf, "%lf\n", &result);
		if(n >= size) {
			size++;
			b = realloc(b, size * sizeof(double));
		}
		b[n] = result;
		n++;
	}

	*dim = n;
	return(b);
}
Exemple #4
0
static bool file_stdio_fseek(ALLEGRO_FILE *f, int64_t offset,
   int whence)
{
   FILE *fp = get_fp(f);
   int rc;

   switch (whence) {
      case ALLEGRO_SEEK_SET: whence = SEEK_SET; break;
      case ALLEGRO_SEEK_CUR: whence = SEEK_CUR; break;
      case ALLEGRO_SEEK_END: whence = SEEK_END; break;
   }

#ifdef ALLEGRO_HAVE_FSEEKO
   rc = fseeko(fp, offset, whence);
#else
   rc = fseek(fp, offset, whence);
#endif

   if (rc == -1) {
      al_set_errno(errno);
      return false;
   }

   return true;
}
Exemple #5
0
void cigma::TextReader::get_connectivity(const char *loc, int **connectivity, int *nel, int *ndofs)
{
    // XXX: add support for sections (c.f. gmsh format) so we can scan a single file
    // for now, interpret loc argument to be an entirely new file
    FILE *loc_fp = get_fp(loc, fp);
    assert(loc_fp != NULL);
    read_imat(loc_fp, connectivity, nel, ndofs);
}
Exemple #6
0
void cigma::TextReader::get_coordinates(const char *loc, double **coordinates, int *nno, int *nsd)
{
    // XXX: add support for sections (c.f. gmsh format) so we can scan a single file
    // for now, interpret loc argument to be an entirely new file
    FILE *loc_fp = get_fp(loc, fp);
    assert(loc_fp != NULL);
    read_dmat(loc_fp, coordinates, nno, nsd);
}
Exemple #7
0
static int parse_arg(struct app *app, int argc, char **argv)
{
	char **endv = &argv[argc];

	/* read command */
	for (argv++; argv < endv; argv++) {
		if (find_operand(argv, endv, "-x")) {
			app->dn_mecab = *++argv;
		} else if (find_operand(argv, endv, "-m")) {
			app->fn_voice = *++argv;
		} else if (find_operand(argv, endv, "-ot")) {
			app->logfp = get_fp(*++argv, "w");
		} else if (!strcmp(*argv, "-h")) {
			usage();
		} else if (find_operand(argv, endv, "-s")) {
			app->sampling_rate = atoi(*++argv);
		} else if (find_operand(argv, endv, "-p")) {
			app->fperiod = atoi(*++argv);
		} else if (find_operand(argv, endv, "-a")) {
			app->alpha = atof(*++argv);
		} else if (find_operand(argv, endv, "-b")) {
			app->beta = atof(*++argv);
		} else if (find_operand(argv, endv, "-r")) {
			app->speed = atof(*++argv);
		} else if (find_operand(argv, endv, "-fm")) {
			app->half_tone = atof(*++argv);
		} else if (find_operand(argv, endv, "-u")) {
			app->uv_threshold = atof(*++argv);
		} else if (find_operand(argv, endv, "-jm")) {
			app->gv_weight_mgc = atof(*++argv);
		} else if (find_operand(argv, endv, "-jf")) {
			app->gv_weight_lf0 = atof(*++argv);
#ifdef HTS_MELP
		} else if (find_operand(argv, endv, "-jl")) {
			app->gv_weight_lpf = atof(*++argv);
#endif	/* HTS_MELP */
		} else if (find_operand(argv, endv, "-z")) {
			app->audio_buff_size = atoi(*++argv);
		} else if ((*argv)[0] == '-') {
			app_error("Invalid option %s.\n", *argv);
			exit(1);
		} else {
			app->txtfn = *argv;
		}
	}

	/* sanity check */
	if (app->fn_voice == NULL) {
		app_error("HTS void is not specified.\n");
		exit(1);
	} else if (app->dn_mecab == NULL) {
		app_error("dictionary directory is not specified.\n");
		exit(1);
	}

	return 0;
}
Exemple #8
0
static int file_stdio_fungetc(ALLEGRO_FILE *f, int c)
{
   int rc = ungetc(c, get_fp(f));

   if (rc == EOF) {
      al_set_errno(errno);
   }

   return rc;
}
Exemple #9
0
int main(int argc, char **argv)
{
	struct app app;
	FILE *txtfp;
	char buff[MAXBUFLEN];
	int ret = 0;

	if (argc == 1)
		usage();

	/* init */
	memset(&app, 0, sizeof(app));

	app.sampling_rate = 48000;
	app.fperiod = -1;
	app.alpha = -1.0;
	app.beta = -1.0;
	app.half_tone = -1.0;
	app.audio_buff_size = 0;
	app.uv_threshold = -1.0;
	app.gv_weight_mgc = -1.0;
	app.gv_weight_lf0 = -1.0;
#ifdef HTS_MELP
	app.gv_weight_lpf = -1.0;
#endif	/* HTS_MELP */
	app.speed = -1.0;

	parse_arg(&app, argc, argv);

	txtfp = (app.txtfn != NULL) ? get_fp(app.txtfn, "rt") : stdin;

	/* initialize and load */
	if (setup(&app) < 0)
		goto out;

	/* synthesis */
	fgets(buff, MAXBUFLEN - 1, txtfp);
	if (synthesize(&app, buff) < 0) {
		fprintf(stderr, "failed to synthesize.\n");
		ret = 1;
	}

out:
	/* cleanup */
	cleanup(&app);

	/* free */
	if (app.txtfn != NULL)
		fclose(txtfp);
	if (app.logfp != NULL)
		fclose(app.logfp);

	return ret;
}
Exemple #10
0
static bool file_stdio_fflush(ALLEGRO_FILE *f)
{
   FILE *fp = get_fp(f);

   if (fflush(fp) == EOF) {
      al_set_errno(errno);
      return false;
   }

   return true;
}
Exemple #11
0
static size_t file_stdio_fwrite(ALLEGRO_FILE *f, const void *ptr, size_t size)
{
   size_t ret;

   ret = fwrite(ptr, 1, size, get_fp(f));
   if (ret < size) {
      al_set_errno(errno);
   }

   return ret;
}
Exemple #12
0
static size_t file_stdio_fread(ALLEGRO_FILE *f, void *ptr, size_t size)
{
   if (size == 1) {
      /* Optimise common case. */
      int c = fgetc(get_fp(f));
      if (c == EOF) {
         al_set_errno(errno);
         return 0;
      }
      *((char *)ptr) = (char)c;
      return 1;
   }
   else {
      size_t ret = fread(ptr, 1, size, get_fp(f));
      if (ret < size) {
         al_set_errno(errno);
      }
      return ret;
   }
}
Exemple #13
0
/*
 * flush file system buffers by file descriptor.
 */
int fsync(int fd)
{
	struct file_t * fp;

	if(fd < 0)
		return -1;

	if((fp = get_fp(fd)) == NULL)
		return -1;

	return sys_fsync(fp);
}
Exemple #14
0
/*
 * input and output control
 */
int ioctl(int fd, int cmd, void * arg)
{
	struct file_t * fp;

	if(fd < 0)
		return -1;

	if((fp = get_fp(fd)) == NULL)
		return -1;

	return sys_ioctl(fp, cmd, arg);
}
Exemple #15
0
/*
 * stat a file by file descriptor
 */
int fstat(int fd, struct stat * st)
{
	struct file_t * fp;

	if(fd < 0)
		return -1;

	if((fp = get_fp(fd)) == NULL)
		return -1;

	return sys_fstat(fp, st);
}
Exemple #16
0
/*
 * rewind a directory
 */
int rewinddir(void * dir)
{
	struct dir * pdir;
	struct file_t * fp;

	if(!dir)
		return -1;

	pdir = (struct dir *)dir;
	if((fp = get_fp(pdir->fd)) == NULL)
		return -1;

	return sys_rewinddir(fp);
}
Exemple #17
0
/*
 * seek a offset
 */
loff_t lseek(int fd, loff_t offset, s32_t whence)
{
	struct file_t * fp;
	loff_t org;

	if(fd < 0)
		return -1;

	if((fp = get_fp(fd)) == NULL)
		return -1;

	if(sys_lseek(fp, offset, whence, &org) != 0)
		return -1;

	return org;
}
Exemple #18
0
static int64_t file_stdio_ftell(ALLEGRO_FILE *f)
{
   FILE *fp = get_fp(f);
   int64_t ret;

#ifdef ALLEGRO_HAVE_FTELLO
   ret = ftello(fp);
#else
   ret = ftell(fp);
#endif
   if (ret == -1) {
      al_set_errno(errno);
   }

   return ret;
}
Exemple #19
0
/*
 * read a directory
 */
struct dirent * readdir(void * dir)
{
    struct dir * pdir;
    struct file * fp;

    if(!dir)
        return NULL;

    pdir = (struct dir *)dir;
    if((fp = get_fp(pdir->fd)) == NULL)
        return NULL;

    if(sys_readdir(fp, &pdir->entry) == 0)
        return &pdir->entry;
    return NULL;
}
Exemple #20
0
/*
 * write to file
 */
loff_t write(int fd, void * buf, loff_t len)
{
	struct file_t * fp;
	loff_t bytes;

	if(fd < 0)
		return -1;

	if((fp = get_fp(fd)) == NULL)
		return -1;

	if(sys_write(fp, buf, len, &bytes) != 0)
		return -1;

	return bytes;
}
Exemple #21
0
/*
 * close a file by file descriptor
 */
int close(int fd)
{
	struct file_t * fp;
	int err;

	if(fd < 0)
		return -1;

	if((fp = get_fp(fd)) == NULL)
		return -1;

	if((err = sys_close(fp)) != 0)
		return err;

	fd_free(fd);
	return 0;
}
int shell(int ac, char **av, char **env)
{
  int running;
  int status;
  int ret_val;
  char **argv;
  char **paths_array;
  char *abs_path;

  ac = ac;
  av = av;
  running = 1;
  status = 1;
  ret_val = 0;

  while (running) {
      print_prompt();
      argv = get_argv();

      /* if no builtins were invoked */
      if (builtins(argv, env, &running, &ret_val) == 0) {
	paths_array = get_patharr(env);
	abs_path = get_fp(argv[0], paths_array);
	if (abs_path == NULL) {
	  print_string(argv[0]);
	  print_string(": command not found\n");
	} else {
	  free(argv[0]);
	  argv[0] = abs_path;
	  create_subshell(argv, env, &status);
	}
	printf("the 'status' of the last executed process is %i\n", status);

	/* free paths_array after executing command */
	free_2Darr(paths_array);
      }

      /* free argv pointer and strings inside */
      free_2Darr(argv);
    }
  return ret_val;

  /* return any values for success? or error? */
}
Exemple #23
0
/*
 * close a directory
 */
int closedir(void * dir)
{
    struct file * fp;
    struct dir * pdir;
    int err;

    if(!dir)
        return -1;

    pdir = (struct dir *)dir;
    if((fp = get_fp(pdir->fd)) == NULL)
        return -1;

    if((err = sys_closedir(fp)) != 0)
        return err;

    fd_free(pdir->fd);
    free(dir);

    return 0;
}
Exemple #24
0
static void default_sched_hook(struct dtask *from, struct dtask *to)
{
    uint8_t *ptr_stack;

    /* update sched history */
    journal_task_switch(from, to);

    /* check stack overflow: if task is dead, we don't check it */
    if(from->state != TASK_STATE_DEAD)
    {
        ptr_stack = (uint8_t *)from->stack_base;

        if(*ptr_stack != TASK_STACK_INIT_CHAR)
        {
            kprintf("error: task %s stack overflow!!\n", from->name);
            dump_call_stack(get_fp(), MEMLOW, MEMHIGH);
            panic("stack overflow\n");
        }
    }

    /* update consumed time for from task */


}
Exemple #25
0
static void file_stdio_fclose(ALLEGRO_FILE *f)
{
   fclose(get_fp(f));
   _AL_FREE(f);
}
Exemple #26
0
void cigma::TextReader::get_dataset(const char *loc, double **data, int *num, int *dim)
{
    FILE *loc_fp = get_fp(loc, fp);
    assert(loc_fp != NULL);
    read_dmat(loc_fp, data, num, dim);
}
Exemple #27
0
/**
 * Write the x vector to the output file.
 */
void set_x(double *x, int dim, char *filename) {
	FILE *fp = get_fp(filename, "w");
	for(int row = 0; row < dim; row++) {
		fprintf(fp, "%f\n", x[row]);
	}
}
Exemple #28
0
static bool file_stdio_ferror(ALLEGRO_FILE *f)
{
   return ferror(get_fp(f));
}
Exemple #29
0
int arop(int count, int op) {
float32 f1, f2, f3, f4;
int	i;
int	fp;
char	*mode;
int	add=0;
int	sub=0;
int	mul=0;
int	div=0;
int	oper;
int	err;
int	err_count=0;

if(!quiet) printf("\nGenerating %0d Arithmetic test vectors ...\n",count);

if(append)	mode = "a";
else		mode = "w";
if(ofile==0)	ofile = "ar.hex";

fp = fopen(ofile,mode);
if(fp == 0) {
	printf("ERROR: Could not create file '%s'.\n",ofile);
	return(-1);
   }

if(!quiet) {
	if(op & 0x1)	printf("Add OP\n");
	if(op & 0x2)	printf("Sub OP\n");
	if(op & 0x4)	printf("Mul OP\n");
	if(op & 0x8)	printf("Div OP\n");
   }

if(op & 0x1)	add=1;
if(op & 0x2)	sub=1;
if(op & 0x4)	mul=1;
if(op & 0x8)	div=1;

f1 = get_pat(0);	// Initialize pattern generator ...

for(i=0;i<count;i++) {

	err = 0;

	if(pat>0) {
		f1 = get_pat(1);
		f2 = get_pat(2);
	   } else {
		f1 = get_fp();
		f2 = get_fp();
	   }


	if(rall)	float_rounding_mode = (rand() % 4);


	oper = -1;
	while(oper == -1) {
	float_exception_flags = 0;	// Reset Exceptions

		if( (rand() % 4)==3 & div) {
			oper = 8;
			f3 = float32_div( f1, f2);
			float_exception_flags = 0;	// Reset Exceptions
			f3 = float32_div( f1, f2);

			//*( (float *) &f4 ) = *( (float *) &f1 ) / *( (float *) &f2 );
			//if( f4 != f3) {
			//	err = 1;
			//	printf("FP Div Error: %x - %x: System: %x Lib: %x\n",f1, f2, f4, f3);
			//   }
		   }

		if( (rand() % 4)==2 & mul) {
			oper = 4;
			f3 = float32_mul( f1, f2);
			float_exception_flags = 0;	// Reset Exceptions
			f3 = float32_mul( f1, f2);

			//*( (float *) &f4 ) = *( (float *) &f1 ) * *( (float *) &f2 );
			//if( f4 != f3) {
			//	err = 1;
			//	printf("FP Mul Error: %x - %x: System: %x Lib: %x\n",f1, f2, f4, f3);
			//   }
		   }

		if( (rand() % 4)==1 & sub) {
			oper = 2;
			f3 = float32_sub( f1, f2);
			float_exception_flags = 0;	// Reset Exceptions
			f3 = float32_sub( f1, f2);

			//*( (float *) &f4 ) = *( (float *) &f1 ) - *( (float *) &f2 );
			//if( f4 != f3) {
			//	err = 1;
			//	printf("FP Sub Error: %x - %x: System: %x Lib: %x\n",f1, f2, f4, f3);
			//   }
		   }

		if( (rand() % 4)==0 & add) {
			oper = 1;
			f3 = float32_add( f1, f2);
			float_exception_flags = 0;	// Reset Exceptions
			f3 = float32_add( f1, f2);

			//*( (float *) &f4 ) = *( (float *) &f1 ) + *( (float *) &f2 );
			//if( f4 != f3) {
			//	err = 1;
			//	printf("FP Add Error: %x - %x: System: %x Lib: %x\n",f1, f2, f4, f3);
			//   }
		   }

	   }

	if(err)		err_count++;

	if(!err) {

		//if(float_exception_flags != 0)
		//	printf("Exceptions: %x\n",float_exception_flags);
	
	
		if(verb)	printf("rmode: %01x, except: %02x, oper: %01x opa: %08x, opb: %08x res: %08x\n", float_rounding_mode, float_exception_flags, oper, f1, f2, f3);
		fprintf(fp,"%01x%02x%01x%08x%08x%08x\n", float_rounding_mode, float_exception_flags, oper, f1, f2, f3);
	   }
	else {
		printf("\t Vecor mismatch between library and system calculations. This Vector\n");
		printf("\t will not be placed in to vector file ...\n");
	}

   }


close(fp);

if(!quiet) {
	printf("Found %d errors\n",err_count);
	printf("Wrote %d vectors from total %d specified.\n", (count-err_count), count);
	
	printf("\n ... f2i done.\n");
   }
return(0);
}
Exemple #30
0
	const Binfile & Binfile::write(const void * req, uint size) const
	{
		fwrite(req, size, 1, get_fp());
		return *this;
	}