void alloc_morphology_grids(void)

{

  static int first_call = TRUE;
  static si32 nbytes_alloc;
  si32 nbytes_needed;

  nbytes_needed = Glob->nx * Glob->ny * sizeof(ui08);
  
  if (first_call) {

    Refl_margin_grid = (ui08 *) umalloc ((ui32) nbytes_needed);
    Morphology_grid = (ui08 *) umalloc ((ui32) nbytes_needed);
    Edm_grid = (ui08 *) umalloc ((ui32) nbytes_needed);
    Eroded_grid = (ui08 *) umalloc ((ui32) nbytes_needed);
    nbytes_alloc = nbytes_needed;

    first_call = FALSE;
    
  } else {

    /*
     * adjust grid allocation as necessary
     */
  
    if (nbytes_needed < nbytes_alloc) {
	
      Refl_margin_grid = (ui08 *) urealloc ((char *) Refl_margin_grid,
					     (ui32) nbytes_needed);
      Morphology_grid = (ui08 *) urealloc ((char *) Morphology_grid,
					     (ui32) nbytes_needed);
      Edm_grid = (ui08 *) urealloc ((char *) Edm_grid,
				      (ui32) nbytes_needed);
      Eroded_grid = (ui08 *) urealloc ((char *) Eroded_grid,
					 (ui32) nbytes_needed);
      
      nbytes_alloc = nbytes_needed;

    } /* if (nbytes_needed < nbytes_alloc) */
    
  } /* if (first_call) */

  /*
   * zero out grids
   */

  memset((void *) Refl_margin_grid, 0, (int) nbytes_alloc);
  memset((void *) Morphology_grid, 0, (int) nbytes_alloc);
  memset((void *) Edm_grid, 0, (int) nbytes_alloc);
  memset((void *) Eroded_grid, 0, (int) nbytes_alloc);

  return;

}
예제 #2
0
static void msg2Buffer(char *msg, uint32_t msgLen, uint32_t taskid,
		       uint8_t type)
{
    RingMsgBuffer_t *rBuf;
    int stype;

    /*
    mlog("%s: msgLen:%u ringBufLast:%u ringBufStart:%u\n", __func__, msgLen,
	    ringBufLast, ringBufStart);
    */

    if (!msgLen) return;

    stype = (type == STDOUT) ?  SLURM_IO_STDOUT : SLURM_IO_STDERR;

    rBuf = &ringBuf[ringBufLast];
    rBuf->taskid = taskid;
    rBuf->type = stype;
    if (rBuf->msgLen < msgLen) {
	rBuf->msg = urealloc(rBuf->msg, msgLen);
    }
    rBuf->msgLen = msgLen;
    memcpy(rBuf->msg, msg, msgLen);

    ringBufLast = (ringBufLast + 1 == RING_BUFFER_LEN) ? 0 : ringBufLast + 1;

    if (ringBufLast == ringBufStart) {
	ringBufStart = (ringBufStart + 1 == RING_BUFFER_LEN) ?
						    0 : ringBufStart + 1;
    }
}
예제 #3
0
tree_vertex_t *alloc_vertices(si32 n_vertices)

{

  static int n_alloc = 0;
  static tree_vertex_t *vertices;
  
  if (n_vertices > n_alloc) {

    if (vertices == NULL) {
      vertices = (tree_vertex_t *)
	umalloc ((ui32) (n_vertices * sizeof(*vertices)));
    } else {
      vertices = (tree_vertex_t *)
	urealloc ((char *) vertices,
		  (ui32) (n_vertices * sizeof(*vertices)));
    }

    n_alloc = n_vertices;

  }

  return (vertices);

}
예제 #4
0
static void *tr_reallochook(void *md, void *ptr, uintptr_t size)
{
    void *hdr;
    struct mdesc *mdp;

    mdp = MD_TO_MDP(md);

    if (ptr == mallwatch)
	tr_break();

    mdp->ufree_hook = old_ufree_hook;
    mdp->umalloc_hook = old_umalloc_hook;
    mdp->urealloc_hook = old_urealloc_hook;
    hdr = (void *) urealloc(md, ptr, size);
    mdp->ufree_hook = tr_freehook;
    mdp->umalloc_hook = tr_mallochook;
    mdp->urealloc_hook = tr_reallochook;
    if (hdr == NULL)
	/* Failed realloc.  */
	fprintf(mallstream, "! %08lx %x\n", (unsigned long) ptr, (int)size);
    else
	fprintf(mallstream, "< %08lx\n> %08lx %x\n", (unsigned long) ptr,
		(unsigned long) hdr, (int)size);

    if (hdr == mallwatch)
	tr_break();

    return hdr;
}
예제 #5
0
static void _alloc_parts(ds_msg_handle_t *handle,
			 int n_parts)
     
{
  int i;
  ds_msg_part_t *part;

  if (n_parts > handle->n_parts_alloc) {

    /* alloc parts */

    handle->parts = (ds_msg_part_t *)
      urealloc(handle->parts, n_parts * sizeof(ds_msg_part_t));

    /* initialize new parts */

    for (i = handle->n_parts_alloc; i < n_parts; i++) {
      part = handle->parts + i;
      part->type = -1;
      part->length = 0;
      part->padded_length = 0;
      part->buf = NULL;
      part->n_buf_alloc = 0;
      if (handle->mem_model == DS_MSG_COPY_MEM) {
	part->buf_is_local = 1;
      } else {
	part->buf_is_local = 0;
      }
    } /* i */
    
    handle->n_parts_alloc = n_parts;

  }

}
예제 #6
0
static void _alloc_part_buf(ds_msg_part_t *part)
     
{
  assert(part->buf_is_local);
  if ((part->length > part->n_buf_alloc) ||
      (part->length < part->n_buf_alloc/2)) {
    part->buf = (ui08 *) urealloc(part->buf, part->length);
    part->n_buf_alloc = part->length;
  }
}
예제 #7
0
static void _alloc_assembled_msg(ds_msg_handle_t *handle)
     
{
  if (handle->length_assembled > handle->n_assembled_alloc) {
    handle->assembled_msg =
      (ui08 *) urealloc(handle->assembled_msg, handle->length_assembled);
    handle->n_assembled_alloc = handle->length_assembled;
  }
  memset(handle->assembled_msg, 0, handle->length_assembled);
}
예제 #8
0
/**
 * Reallocate umalloc()-based data buffer
 *
 * @v xferbuf		Data transfer buffer
 * @v len		New length (or zero to free buffer)
 * @ret rc		Return status code
 */
static int xferbuf_umalloc_realloc ( struct xfer_buffer *xferbuf, size_t len ) {
	userptr_t *udata = xferbuf->data;
	userptr_t new_udata;

	new_udata = urealloc ( *udata, len );
	if ( ! new_udata )
		return -ENOSPC;
	*udata = new_udata;
	return 0;
}
예제 #9
0
void * MDV_recalloc(void * ptr_to_mem, int number_of_mem, int size_of_mem)
{ 
  if (ptr_to_mem == NULL) {
    ptr_to_mem = ucalloc(number_of_mem, size_of_mem);
  }
  else {
    ptr_to_mem = urealloc(ptr_to_mem, number_of_mem*size_of_mem);
    memset(ptr_to_mem, 0, number_of_mem*size_of_mem);
  }
  return(ptr_to_mem);
}
static void alloc_complex_nums(si32 n_complex_needed)

{

  if (n_complex_needed > N_complex_alloc) {
    if (Complex_nums == NULL) {
      Complex_nums = (si32 *) umalloc (n_complex_needed * sizeof(si32));
      Storm1_nums = (si32 *) umalloc (n_complex_needed * sizeof(si32));
    } else {
      Complex_nums = (si32 *) urealloc
	((char *) Complex_nums, n_complex_needed * sizeof(si32));
      Storm1_nums = (si32 *) urealloc
	((char *) Storm1_nums, n_complex_needed * sizeof(si32));
    }
    N_complex_alloc = n_complex_needed;
  }
  
  return;

}
예제 #11
0
파일: buffers.c 프로젝트: bobrippling/uvi
int buffers_add(const char *fname)
{
	int i;

	if((i = buffers_find(fname)) != -1)
		return i;

	i = count++;
	fnames        = urealloc(fnames, (count + 1) * sizeof *fnames);
	fnames[i]     = new_old_buf(fname);
	fnames[count] = NULL;

	return i;
}
예제 #12
0
파일: glob.c 프로젝트: bobrippling/ush
void glob_expand_argv(char ***pargv)
{
	char **argv;
	unsigned int i;
	unsigned int len;

	argv = *pargv;
	len = null_array_len(argv);

	for(i = 0; i < len; i++){
		wordexp_t exp = { 0 };
		int ret;

		ret = ush_wordexp(argv[i], &exp, 0);

		switch(ret){
			case 0:
			if(exp.we_wordc){
				unsigned int j;

				len += exp.we_wordc - 1;
				argv = urealloc(argv, (len+1) * sizeof(*argv));

				/*
				 * move from argv[i + 1] to argv[i + 1 + exp.we_wordc - 1]
				 */
				memmove(&argv[i + exp.we_wordc], &argv[i + 1], sizeof(*argv));

				for(j = 0; j < exp.we_wordc; j++)
					argv[i + j] = ustrdup(exp.we_wordv[j]);

				i += exp.we_wordc - 1; /* skip over inserted entries */
			}
			break;

			case WRDE_BADCHAR: /* Illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, } */
			case WRDE_BADVAL:  /* An undefined shell variable was referenced, and the WRDE_UNDEF flag told us to consider this an error */
			case WRDE_CMDSUB:  /* Command substitution occurred, and the WRDE_NOCMD flag told us to consider this an error */
			case WRDE_NOSPACE: /* ENOMEM */
			case WRDE_SYNTAX:  /* Shell syntax error, such as unbalanced parentheses or unmatched quotes */
				break;
		}

		wordfree(&exp);
	}

	*pargv = argv;
}
예제 #13
0
파일: ex5.c 프로젝트: ZhaoXiyu/UMJI-VG101
void resizeSet(uset* set,int newsize){
	int oldsize=set->card*set->type;//calculate old used mem
	int t=oldsize%(MCHNK*set->type);//calculate the used mem in the last chunk
	oldsize=oldsize-t+MCHNK*set->type;
	//calculate the mem allocated by calculating (orignal size-t+chunksize)
	t=newsize%(MCHNK*set->type);
	newsize=newsize-t+MCHNK*set->type;
	//calculate the new memory required to be allocated;
	//printf("Resizing from %d to %d.\n",oldsize,newsize);
	if(oldsize!=newsize){//if newsize is not equal to old size.
		set->elem=urealloc(set->elem,newsize);//resize memory!
		
		//mempeek(set->elem,newsize);
	}
	return;
}
예제 #14
0
char *ustrprintf(const char *fmt, ...)
{
	va_list l;
	char *buf = NULL;
	int len = 8, ret;

	do{
		len *= 2;
		buf = urealloc(buf, len);
		va_start(l, fmt);
		ret = vsnprintf(buf, len, fmt, l);
		va_end(l);
	}while(ret >= len);

	return buf;
}
예제 #15
0
static char *in_line(FILE *f)
{
    char *s = NULL;
    size_t n = 0;
    int ch;

    while((ch = fgetc(f)) != EOF) {
        s = urealloc(s, ++n + 1);
        s[n-1] = ch;
        if(ch == '\n')
            break;
    }
    if(s)
        s[n] = '\0';

    return s;
}
예제 #16
0
void alloc_vertex_index(si32 max_index)

{
  static si32 n_alloc = 0;
  
  if (max_index > n_alloc) {
    if (Index == NULL) {
      Index = (si32 *) umalloc
	((ui32) (max_index * sizeof(*Index)));
    } else {
      Index = (si32 *) urealloc
	((char *) Index,
	 (ui32) (max_index * sizeof(*Index)));
    }
  }

  return;

}
예제 #17
0
파일: io.c 프로젝트: bobrippling/uvi
char *fline(FILE *f, int *eol)
{
	int c, pos, len;
	char *line;

	if(feof(f) || ferror(f))
		return NULL;

	pos = 0;
	len = 10;
	line = umalloc(len);

	do{
		errno = 0;
		if((c = fgetc(f)) == EOF){
			if(errno == EINTR)
				continue;
			if(pos){
				if(eol)
					*eol = 0;
				return line;
			}
			free(line);
			return NULL;
		}

		line[pos++] = c;
		if(pos == len){
			len *= 2;
			line = urealloc(line, len);
			line[pos] = '\0';
		}

		if(c == '\n'){
			line[pos-1] = '\0';
			if(eol)
				*eol = 1;
			return line;
		}
	}while(1);
}
예제 #18
0
파일: complete.c 프로젝트: bobrippling/ush
static void complete_to(char *to, int len_so_far, int to_len,
		char **bptr, unsigned int *sizptr, unsigned int *idxptr,
		char appendchar)
{
	char *buffer = *bptr;

	if(*sizptr <= strlen(*bptr) + strlen(to))
		buffer = *bptr = urealloc(buffer, *sizptr = strlen(to) + strlen(*bptr) + 1);

	strncpy(buffer + *idxptr, to + len_so_far, to_len - len_so_far);
	fwrite(to + len_so_far, sizeof(char), to_len - len_so_far, stdout);

	*idxptr += to_len - len_so_far;
	if(appendchar){
		putchar(appendchar);

		buffer[*idxptr] = appendchar;
		++*idxptr;
	}
	buffer[*idxptr] = '\0';
}
예제 #19
0
static int push_vertex(tree_vertex_t *v)
{
  void *ptr;
  if (Top < Max_stack - 1) {
    Stack[Top++] = v;
    return(0);
  } else {
    /* try to realloc */
    Max_stack += STACK_INCR;
    ptr = urealloc((char *) Stack, Max_stack * sizeof(*Stack));
    Stack = ptr;
    if (ptr == NULL) {
      printf("vertex stack overflow -- out of memory\n");
      clear_vertex_stack();
      return(-1);
    } else {
      Stack[Top++] = v;
      return(0);
    }
  }
}
예제 #20
0
파일: umalloc_test.c 프로젝트: 3a9LL/panda
void umalloc_test ( void ) {
	struct memory_map memmap;
	userptr_t bob;
	userptr_t fred;

	printf ( "Before allocation:\n" );
	get_memmap ( &memmap );

	bob = umalloc ( 1234 );
	bob = urealloc ( bob, 12345 );
	fred = umalloc ( 999 );

	printf ( "After allocation:\n" );
	get_memmap ( &memmap );

	ufree ( bob );
	ufree ( fred );

	printf ( "After freeing:\n" );
	get_memmap ( &memmap );
}
예제 #21
0
int load_scan_times(storm_file_handle_t *s_handle,
		    date_time_t **scan_times_p)

{

  static int first_call = TRUE;
  static date_time_t *scan_times;
  int n_scans, iscan;

  n_scans = s_handle->header->n_scans;

  if (first_call == TRUE) {

    scan_times = (date_time_t *) umalloc
      ((ui32) (n_scans * sizeof(date_time_t)));

    first_call = FALSE;

  } else {

    scan_times = (date_time_t *) urealloc
      ((char *) scan_times,
       (ui32) (n_scans * sizeof(date_time_t)));

  }

  for (iscan = 0; iscan < n_scans; iscan++) {

    if (RfReadStormScan(s_handle, iscan, "load_scan_times"))
      tidy_and_exit(-1);

    scan_times[iscan].unix_time = s_handle->scan->time;
    uconvert_from_utime(scan_times + iscan);

  } /* iscan */

  *scan_times_p = scan_times;
  return (n_scans);

}
예제 #22
0
/**
 * Ensure that download buffer is large enough for the specified size
 *
 * @v downloader	Downloader
 * @v len		Required minimum size
 * @ret rc		Return status code
 */
static int downloader_ensure_size ( struct downloader *downloader,
				    size_t len ) {
	userptr_t new_buffer;

	/* If buffer is already large enough, do nothing */
	if ( len <= downloader->image->len )
		return 0;

	DBGC ( downloader, "Downloader %p extending to %zd bytes\n",
	       downloader, len );

	/* Extend buffer */
	new_buffer = urealloc ( downloader->image->data, len );
	if ( ! new_buffer ) {
		DBGC ( downloader, "Downloader %p could not extend buffer to "
		       "%zd bytes\n", downloader, len );
		return -ENOSPC;
	}
	downloader->image->data = new_buffer;
	downloader->image->len = len;

	return 0;
}
예제 #23
0
static void *urealloc_check(void *md, void *ptr, uintptr_t size)
{
    struct hdr *hdr = ((struct hdr *) ptr) - 1;
    struct mdesc *mdp;
    uintptr_t nbytes;

    mdp = MD_TO_MDP(md);
    checkhdr(mdp, hdr);
    mdp->ufree_hook = NULL;
    mdp->umalloc_hook = NULL;
    mdp->urealloc_hook = NULL;
    nbytes = sizeof(struct hdr) + size + 1;
    hdr = (struct hdr *) urealloc(md, (void *) hdr, nbytes);
    mdp->ufree_hook = ufree_check;
    mdp->umalloc_hook = umalloc_check;
    mdp->urealloc_hook = urealloc_check;
    if (hdr != NULL) {
	hdr->size = size;
	hdr++;
	*((char *) hdr + size) = MAGICBYTE;
    }
    return ((void *) hdr);
}
예제 #24
0
static ui08 *init_overlap_grid(ui32 npoints_grid)

{

  static ui32 n_alloc = 0;
  static ui08 *grid_array = NULL;

  ui32 nbytes = npoints_grid * sizeof(ui08);

  if (nbytes > n_alloc) {
    if (grid_array == NULL) {
      grid_array = (ui08 *) umalloc(nbytes);
    } else {
      grid_array = (ui08 *) urealloc((char *) grid_array, nbytes);
    }
    n_alloc = nbytes;
  }

  memset((void *) grid_array, 0, nbytes);
  
  return (grid_array);

}
예제 #25
0
char *splice_line(void)
{
	static int n_nls;
	char *last;
	int join;

	if(n_nls){
		n_nls--;
		return ustrdup("");
	}

	last = NULL;
	join = 0;

	for(;;){
		FILE *f;
		int len;
		char *line;

re_read:
		if(file_stack_idx < 0)
			ICE("file stack idx = 0 on read()");
		f = file_stack[file_stack_idx].file;
		line = fline(f);

		if(!line){
			if(ferror(f))
				die("read():");

			fclose(f);
			if(file_stack_idx > 0){
				free(dirname_pop());
				preproc_pop();
				goto re_read;
			}

			return NULL;
		}

		current_line++;

		if(join){
			join = 0;

			last = urealloc(last, strlen(last) + strlen(line) + 1);
			strcpy(last + strlen(last), line);
			free(line);
			line = last;
		}

		len = strlen(line);
		if(len && line[len - 1] == '\\'){
			line[len - 1] = '\0';
			join = 1;
			last = line;
			n_nls++;
		}else{
			return line;
		}
	}
}
예제 #26
0
void add_proj_runs(storm_file_handle_t *s_handle,
		   storm_file_global_props_t *gprops)

{

  static Interval *Intervals = NULL;
  static int N_intervals_alloc = 0;
  static Row_hdr *Rowh = NULL;
  static int Nrows_alloc = 0;
  static int Ngrid_alloc = 0;
  static ui08 *Grid = NULL;

  int irun;
  si32 offset;
  si32 min_ix, min_iy, max_ix, max_iy;
  si32 n, nx, ny;
  si32 num_intervals;

  Interval *intvl;
  storm_file_run_t *run;

  if (gprops->n_runs == 0) {
    gprops->n_proj_runs = 0;
    return;
  }

  /*
   * get the limits of the proj area
   */
  
  min_ix = gprops->bounding_min_ix;
  min_iy = gprops->bounding_min_iy;
  max_ix = gprops->bounding_max_ix;
  max_iy = gprops->bounding_max_iy;

  /*
   * compute grid sizes, and set grid params
   */

  nx = max_ix - min_ix + 1;
  ny = max_iy - min_iy + 1;
  n = nx * ny;

  /*
   * check grid memory allocation
   */

  if (n > Ngrid_alloc) {
    if (Grid == NULL) {
      Grid = (ui08 *) umalloc((ui32) (n * sizeof(ui08)));
    } else {
      Grid = (ui08 *) urealloc((char *) Grid,
				 (ui32) (n * sizeof(ui08)));
    }
    Ngrid_alloc = n;
  }

  /*
   * zero out grid for proj area comps
   */

  memset((void *) Grid, 0, (int) n);
  
  /*
   * load up grid with 1's to indicate projected area
   */

  run = s_handle->runs;
  for (irun = 0; irun < gprops->n_runs; irun++, run++) {
    offset = ((run->iy - min_iy) * nx) + (run->ix - min_ix);
    memset((void *) (Grid + offset), 1, (int) run->n);
  }
  
  /*
   * check memory allocation
   */

  EG_alloc_rowh((int) ny, &Nrows_alloc, &Rowh);

  /*
   * get the intervals
   */
  
  num_intervals = EG_find_intervals(ny, nx, Grid,
				    &Intervals, &N_intervals_alloc,
				    Rowh, 1);

  /*
   * alloc for proj runs
   */
  
  gprops->n_proj_runs = num_intervals;

  RfAllocStormProps(s_handle, s_handle->scan->grid.nz,
		    gprops->n_dbz_intervals,
		    gprops->n_runs, gprops->n_proj_runs,
		    "add_proj_runs");

  /*
   * load up the proj runs
   */
  
  run = s_handle->proj_runs;
  intvl = Intervals;
  
  for (irun = 0; irun < gprops->n_proj_runs;
       irun++, run++, intvl++) {
    
    run->ix = intvl->begin + min_ix;
    run->iy = intvl->row_in_plane + min_iy;
    run->iz = 0;
    run->n = intvl->len;

  } /* irun */

  return;

}
예제 #27
0
파일: lex.c 프로젝트: apetrunev/bclite
token_t
get_next_token(void)
{
	int used, len, neg;
	double number, mult;
	int power_temp, power;
	char *id, *string;
	struct symbol *symbol;
	struct keyword *keyword;
	int tmp;

	neg = 0;
	id  = NULL;

	while (TRUE) {
		switch(peek) {
		case 0: 
		case ' ':
		case '\t':
			peek = fgetc(input_file);
			continue;
		case '#':
			skip_comment();
			break;
		default:
			break;
		}

		break;
	}

	switch (lex.token) {
	case TOKEN_ID:
		if (lex.id != NULL) 
			ufree(lex.id);
		break;
	case TOKEN_STRING:	
		if (lex.string != NULL)
			ufree(lex.string);
		break;
	default:
		break;
	}
	
	memset(&lex, 0, sizeof(lex));
	
	if (isalpha(peek) || peek == '_') {
		used = len = 0;
		do {
			if ((used + 1) >= len) {
				len += 64;
				id   = urealloc(id, len);
			}

			id[used++] = peek;
			peek = fgetc(input_file);

		} while (isalnum(peek) || peek == '_');

		id[used++] = 0;
			
		keyword = keyword_table_lookup(id);

		if (keyword != NULL) {
			lex.token = keyword->token;
			ufree(id);
			return lex.token;
		}
		
		lex.id = ustrdup(id);
		lex.token = TOKEN_ID;
		
		ufree(id);	
		return TOKEN_ID;	
	}
	

	switch (peek) {
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
do_number:	
		switch(peek) {
		case '-':
			neg = 1;
		case '+':
			peek = fgetc(input_file);
			break;
		}

		number  = 0.0;
		power_temp = power = 0;

		while (isdigit(peek)) {
			number *= 10;
			number += peek - '0';
			peek = fgetc(input_file); 
		}
		
		if (peek == '.') {
			peek = fgetc(input_file);
			while(isdigit(peek)) {
				number *= 10;
				number += peek - '0';
				peek = fgetc(input_file);
				power_temp--;
			}
		} 
	
		if (peek == 'e' || peek == 'E') {
			int exp_neg = 0;
			
			peek = fgetc(input_file);
			switch(peek) {
			case '-':
				peek = fgetc(input_file);
				exp_neg++;
				break;
			case '+':
				peek = fgetc(input_file);
				break;
			}
			
			while(isdigit(peek)) {
				power *= 10;
				power += peek - '0';
				peek   = fgetc(input_file);
			}
			
			power = (exp_neg) ? -power : power;	
	
		}
		
		power += power_temp;
		power_temp =  (power < 0) ? -power : power;
		
		mult = 10.0;
		while(power_temp) {
			if (power_temp & 0x1) {
				if (power < 0)
					number /= mult;
				else
					number *= mult;	
			}
			mult *= mult;
			power_temp >>= 1;
		}
		
		lex.real  = (neg) ? -number : number;
		lex.token = TOKEN_DOUBLE;

		return TOKEN_DOUBLE;
	case '+':
		peek = 0;
		lex.token = TOKEN_PLUS;
		return TOKEN_PLUS;
	case '-':
		tmp = fgetc(input_file);
		if (isdigit(tmp)) {
			ungetc(tmp, input_file);
			goto do_number;
		}
		peek = 0;
		lex.token = TOKEN_MINUS;
		return TOKEN_MINUS;
	case '*':
		peek = 0;
		lex.token = TOKEN_ASTERIK;
		return TOKEN_ASTERIK;
	case '/':
		peek = 0;
		lex.token = TOKEN_SLASH;
		return TOKEN_SLASH;
	case '(':
		peek = 0;
		lex.token = TOKEN_LPARENTH;
		return TOKEN_LPARENTH;
	case ')':
		peek = 0;
		lex.token = TOKEN_RPARENTH;
		return TOKEN_RPARENTH;
	case ',':
		peek = 0;
		lex.token = TOKEN_COMMA;
		return TOKEN_COMMA;
	case '!':
		peek = fgetc(input_file);
		if (peek == '=') {
			peek = 0;
			lex.token = TOKEN_NE;
			return TOKEN_NE;
		}
		lex.token = TOKEN_NOT;
		return TOKEN_NOT;
	case '&':
		peek = fgetc(input_file);
		if (peek == '&') {
			peek = 0;
			lex.token = TOKEN_AND;
			return TOKEN_AND;
		}
		lex.token = TOKEN_UNKNOWN;
		return TOKEN_UNKNOWN;
	case '|':
		peek = fgetc(input_file);
		if (peek == '|') {
			peek = 0;
			lex.token = TOKEN_OR;
			return TOKEN_OR;
		}
		lex.token = TOKEN_UNKNOWN;
		return TOKEN_UNKNOWN;
	case '=':
		peek = fgetc(input_file);
		if (peek == '=') {
			peek = 0;
			lex.token = TOKEN_EQ;
			return TOKEN_EQ;
		}
		lex.token = TOKEN_EQUALITY;
		return TOKEN_EQUALITY;
	case '>':
		peek = fgetc(input_file);
		if (peek == '=') {
			peek = 0;
			lex.token = TOKEN_GE;
			return TOKEN_GE;
		}
		lex.token = TOKEN_GT;
		return TOKEN_GT;
	case '<':
		peek = fgetc(input_file);
		if (peek == '=') {
			peek = 0;
			lex.token = TOKEN_LE;
			return TOKEN_LE;	
		}
		lex.token = TOKEN_LT;
		return TOKEN_LT;
	case '{':
		peek = 0;
		lex.token = TOKEN_LBRACE;
		return TOKEN_LBRACE;
	case '}':
		peek = 0;
		lex.token = TOKEN_RBRACE;
		return TOKEN_RBRACE;
	case '[':
		peek = 0;
		lex.token = TOKEN_LBRACKET;
		return TOKEN_LBRACKET;
	case ']':
		peek = 0;
		lex.token = TOKEN_RBRACKET;
		return TOKEN_RBRACKET;
	case ';':
		peek = 0;
		lex.token = TOKEN_SEMICOLON;
		return TOKEN_SEMICOLON;	
	case '"':
		string = NULL;
		used = len = 0;
		peek = fgetc(input_file);

		do {
			if (peek == '\n') {
				if (string != NULL)
					ufree(string);

				lex.token = TOKEN_UNKNOWN;
				return TOKEN_UNKNOWN;	
			}
			
			if ((used + 1) >= len) {
				len += 4;
				string = urealloc(string, len);
			}
			
			string[used++] = peek;

			peek = fgetc(input_file);
				
		} while(peek != '"');	
		
		string[used] = '\0';

		peek = 0;
		lex.string = ustrdup(string); 
		lex.token  = TOKEN_STRING;
		ufree(string);
		return TOKEN_STRING;
	case '^':
		peek = 0;
		lex.token = TOKEN_CARET;
		return TOKEN_CARET;	
	case '\n':
		peek = 0;
		lex.token = TOKEN_EOL;
		return TOKEN_EOL;
	case EOF:
		peek = 0;
		lex.token = TOKEN_EOF;
		return TOKEN_EOF;
	}

	peek = 0;
	lex.token = TOKEN_UNKNOWN;
	return TOKEN_UNKNOWN;	
}
예제 #28
0
파일: syntax.c 프로젝트: apetrunev/bclite
static struct ast_node*
process_matrix(void)
{	
	struct ast_node_stub *stub_node;
	struct ast_node **elem;
	struct ast_node *node;	
	int row, col, len;
	int prev_col;
	int i;

	elem = NULL;
	node = NULL;

	row = col = 1;
	len = prev_col = 0;

	while (TRUE) {
		node = or_expr();

		if (node == NULL) {
			error_msg("expr expected");
			sync_stream();
			goto err;
		}		
		
		elem = urealloc(elem, ++len*sizeof(struct ast_node *));
		elem[len - 1] = node;

		switch(current_token) {
		case TOKEN_COMMA:
			consume_token();
			col++;
			continue;
		case TOKEN_SEMICOLON:
			consume_token();
			if (prev_col == 0)
				prev_col = col;
			else if (prev_col != col) {
				error_msg("incompatible column count");
				sync_stream();
				goto err;
			}
			col = 1;
			row++;
			continue;
		case TOKEN_RBRACKET:
			consume_token();
			break;
		default:
			error_msg("syntax error");
			sync_stream();
			goto err;
		} 
		break;							
	}

	if (row == 1 || col == 1)
		node = (struct ast_node *)ast_node_vector(elem, len);
	else
		node = (struct ast_node *) ast_node_matrix(elem, row, col);

	return node;

err:
	if (node != NULL)
		ast_node_unref(node);
	
	if (elem != NULL) 
		for (i = 0; i < len; i++)
			ast_node_unref(elem[i]);

	stub_node = ast_node_stub();

	return AST_NODE(stub_node);	
}
예제 #29
0
static void initialize(double lead_time)

{

  int i_int;

  /*
   * init forecast times
   */

  N_forecast_intervals = (int) (lead_time /
			    Glob->params.scan_interval + 0.5);

  N_forecast_intervals = MAX(N_forecast_intervals, 1);
  
  if (N_forecast_intervals > N_intervals_alloc) {
    
    N_intervals_alloc = N_forecast_intervals;
    
    if (Interval_contrib_time == NULL) {
      Interval_contrib_time = (double *) umalloc
	((ui32) ((N_intervals_alloc)* sizeof(double)));
    } else {
      Interval_contrib_time = (double *) urealloc
	((char *) Interval_contrib_time,
	 (ui32) ((N_intervals_alloc)* sizeof(double)));
    }
    
    if (Interval_lead_time == NULL) {
      Interval_lead_time = (double *) umalloc
	((ui32) ((N_intervals_alloc)* sizeof(double)));
    } else {
      Interval_lead_time = (double *) urealloc
	((char *) Interval_lead_time,
	 (ui32) ((N_intervals_alloc)* sizeof(double)));
    }
    
  } /* if (N_forecast_intervals < N_intervals_alloc) */

  for (i_int = 0; i_int < N_forecast_intervals; i_int++) {
    Interval_contrib_time[i_int] = Glob->params.scan_interval / 3600.0;
    Interval_lead_time[i_int] =
      (((double) i_int + 1.0) * Glob->params.scan_interval) / 3600.0;
  } /* i_int */

  Interval_contrib_time[N_forecast_intervals - 1] =
    (lead_time -
     ((double) N_forecast_intervals - 1.0) *
     Glob->params.scan_interval) / 3600.0;

  if (Glob->params.debug >= DEBUG_EXTRA) {

    fprintf(stderr, "N_forecast_intervals : %ld\n",
	    (long) N_forecast_intervals);
    
    for (i_int = 0; i_int < N_forecast_intervals; i_int++)
      fprintf(stderr,
	      "Forecast interval #, lead_time, contrib_time : %ld, %g, %g\n",
	      (long) i_int,
	      Interval_lead_time[i_int],
	      Interval_contrib_time[i_int]);
    
  } /* if (Glob->params.debug >= DEBUG_EXTRA) */

}
예제 #30
0
char *DB_encode_url(DB_url_t *url_struct)
{
  static char *routine_name = "DB_encode_url";
  
  static char *url_string = (char *)NULL;
  static int url_string_alloc = 0;
  
  int max_string_len;
  char port_string[BUFSIZ];
  
  /*
   * Check for missing required fields.
   */

  if (url_struct->protocol == (char *)NULL ||
      url_struct->protocol[0] == '\0')
  {
    fprintf(stderr,
	    "ERROR: %s::%s\n", Module_name, routine_name);
    fprintf(stderr,
	    "Protocol field MUST be specified in URL\n");
    
    return((char *)NULL);
  }
  
  if (url_struct->file == (char *)NULL ||
      url_struct->file[0] == '\0')
  {
    fprintf(stderr,
	    "ERROR: %s::%s\n", Module_name, routine_name);
    fprintf(stderr,
	    "File path field MUST be specified in URL\n");
    
    return((char *)NULL);
  }
  
  /*
   * Convert the port number to a string.
   */

  if (url_struct->port <= 0)
    port_string[0] = '\0';
  else
    sprintf(port_string, "%d", url_struct->port);
  
  /*
   * Calculate the required length of the returned string and
   * allocate the space.
   */

  max_string_len = 1;    /* NULL terminator */
  max_string_len += strlen(url_struct->protocol);
  max_string_len += strlen(DB_PROTO_TRANS_DELIM);
  if (url_struct->translator != (char *)NULL)
    max_string_len += strlen(url_struct->translator);
  max_string_len += strlen(DB_TRANS_PARAMS_DELIM);
  if (url_struct->param_file != (char *)NULL)
    max_string_len += strlen(url_struct->param_file);
  max_string_len += strlen(DB_PARAMS_HOST_DELIM);
  if (url_struct->host != (char *)NULL)
    max_string_len += strlen(url_struct->host);
  max_string_len += strlen(DB_HOST_PORT_DELIM);
  max_string_len += strlen(port_string);
  max_string_len += strlen(DB_PORT_FILE_DELIM);
  max_string_len += strlen(url_struct->file);
  if (url_struct->args != (char *)NULL)
  {
    max_string_len += strlen(DB_FILE_ARGS_DELIM);
    max_string_len += strlen(url_struct->args);
  }
  
  if (max_string_len > url_string_alloc)
  {
    url_string_alloc = max_string_len;
    
    if (url_string == (char *)NULL)
      url_string = (char *)umalloc(url_string_alloc);
    else
      url_string = (char *)urealloc(url_string, url_string_alloc);
  }
  
  /*
   * Now construct the string.
   */

  STRcopy(url_string, url_struct->protocol, url_string_alloc);
  STRconcat(url_string, DB_PROTO_TRANS_DELIM, url_string_alloc);
  if (url_struct->translator != (char *)NULL)
    STRconcat(url_string, url_struct->translator, url_string_alloc);
  STRconcat(url_string, DB_TRANS_PARAMS_DELIM, url_string_alloc);
  if (url_struct->param_file != (char *)NULL)
    STRconcat(url_string, url_struct->param_file, url_string_alloc);
  STRconcat(url_string, DB_PARAMS_HOST_DELIM, url_string_alloc);
  if (url_struct->host != (char *)NULL)
    STRconcat(url_string, url_struct->host, url_string_alloc);
  STRconcat(url_string, DB_HOST_PORT_DELIM, url_string_alloc);
  STRconcat(url_string, port_string, url_string_alloc);
  STRconcat(url_string, DB_PORT_FILE_DELIM, url_string_alloc);
  STRconcat(url_string, url_struct->file, url_string_alloc);
  if (url_struct->args != (char *)NULL)
  {
    STRconcat(url_string, DB_FILE_ARGS_DELIM, url_string_alloc);
    STRconcat(url_string, url_struct->args, url_string_alloc);
  }
  
  return(url_string);
}