예제 #1
0
int		get_next_person(int fd, person_t **new_person)
{
	char	*temp;
	int		eof_flag;

	*new_person = (person_t*)malloc(sizeof(person_t));
	//read and validate NAME
	get_next_value(fd, &((**new_person).name));
	if (!name_valid((**new_person).name))
		return (INVALID_NAME);
	printf("mkay");
	return (0);	//read and validate SURENAME
	get_next_value(fd, &((**new_person).surename));
	if (!surename_valid((**new_person).surename))
		return (INVALID_SURENAME);
	//read and validate EMAIL
	get_next_value(fd, &((**new_person).email));
	if (!email_valid((**new_person).email))
		return (INVALID_EMAIL);
	//read and validate MARK
	get_next_value(fd, &temp);
	if (!mark_valid(temp))
		return (INVALID_MARK);
	(**new_person).mark = atof(temp);
	//read and validate COUNTY
	eof_flag = get_next_value(fd, &((**new_person).county));
	if (!county_valid((**new_person).name))
		return (INVALID_COUNTY);
	if (eof_flag == END_OF_FILE)
		return (END_OF_FILE);
	return (1);
}
예제 #2
0
ssize_t cir_dm6446_read(struct file *file, char __user *buff,
		size_t size, loff_t *loff)
{
	u16 value;
	ssize_t retval = 0;
	int err;

	if (size < sizeof(u16)) {
		printk(KERN_ERR "Invalid size requested for read\n");
		return -EINVAL;
	}

	while (size >= sizeof(u16)) {

		err = get_next_value(&value);
		if (err < 0)
			return err;
		if (err == 1)
			break;

		if (copy_to_user(buff, &value, sizeof(value)) != 0)
			return -EFAULT;

		buff += sizeof(u16);
		size -= sizeof(u16);
		*loff += sizeof(u16);
		retval += sizeof(u16);

	}

	return retval;
}
예제 #3
0
int get_vector(codebook *b,FILE *in,int start, int n,float *a){
  int i;
  const static_codebook *c=b->c;

  while(1){

    if(v_sofar==n || get_line_value(in,a)){
      reset_next_value();
      if(get_next_value(in,a))
	break;
      for(i=0;i<start;i++){
	sequence_base=*a;
	get_line_value(in,a);
      }
    }

    for(i=1;i<c->dim;i++)
      if(get_line_value(in,a+i))
	break;
    
    if(i==c->dim){
      float temp=a[c->dim-1];
      for(i=0;i<c->dim;i++)a[i]-=sequence_base;
      if(c->q_sequencep)sequence_base=temp;
      v_sofar++;
      return(0);
    }
    sequence_base=0.f;
  }

  return(-1);
}
예제 #4
0
static int getline(FILE *in,float *vec,int begin,int n){
  int i,next=0;

  reset_next_value();
  if(get_next_value(in,vec))return(0);
  if(begin){
    for(i=1;i<begin;i++)
      get_line_value(in,vec);
    next=0;
  }else{
    next=1;
  }

  for(i=next;i<n;i++)
    if(get_line_value(in,vec+i)){
      fprintf(stderr,"ran out of columns in input data\n");
      exit(1);
    }
  
  return(1);
}
예제 #5
0
static int getval(FILE *in,int begin,int n,int group,int max){
  float v;
  int i;
  long val=0;

  if(nsofar>=n || get_line_value(in,&v)){
    reset_next_value();
    nsofar=0;
    if(get_next_value(in,&v))
      return(-1);
    for(i=1;i<=begin;i++)
      get_line_value(in,&v);
  }

  val=(int)v;
  nsofar++;

  for(i=1;i<group;i++,nsofar++)
    if(nsofar>=n || get_line_value(in,&v))
      return(getval(in,begin,n,group,max));
    else
      val = val*max+(int)v;
  return(val);
}
예제 #6
0
codebook *codebook_load(char *filename){
  codebook *b=_ogg_calloc(1,sizeof(codebook));
  static_codebook *c=(static_codebook *)(b->c=_ogg_calloc(1,sizeof(static_codebook)));
  encode_aux_nearestmatch *a=NULL;
  encode_aux_threshmatch *t=NULL;
  encode_aux_pigeonhole *p=NULL;
  int quant_to_read=0;
  FILE *in=fopen(filename,"r");
  char *line;
  long i;

  if(in==NULL){
    fprintf(stderr,"Couldn't open codebook %s\n",filename);
    exit(1);
  }

  /* find the codebook struct */
  find_seek_to(in,"static static_codebook ");

  /* get the major important values */
  line=get_line(in);
  if(sscanf(line,"%ld, %ld,",
	    &(c->dim),&(c->entries))!=2){
    fprintf(stderr,"1: syntax in %s in line:\t %s",filename,line);
    exit(1);
  }
  line=get_line(in);
  line=get_line(in);
  if(sscanf(line,"%d, %ld, %ld, %d, %d,",
	    &(c->maptype),&(c->q_min),&(c->q_delta),&(c->q_quant),
	    &(c->q_sequencep))!=5){
    fprintf(stderr,"1: syntax in %s in line:\t %s",filename,line);
    exit(1);
  }
  
  /* find the auxiliary encode struct[s] (if any) */
  if(find_seek_to(in,"static encode_aux_nearestmatch _vq_aux")){
    /* how big? */
    c->nearest_tree=a=_ogg_calloc(1,sizeof(encode_aux_nearestmatch));
    line=get_line(in);
    line=get_line(in);
    line=get_line(in);
    line=get_line(in);
    line=get_line(in);
    if(sscanf(line,"%ld, %ld",&(a->aux),&(a->alloc))!=2){
      fprintf(stderr,"2: syntax in %s in line:\t %s",filename,line);
      exit(1);
    }

    /* load ptr0 */
    find_seek_to(in,"static long _vq_ptr0");
    reset_next_value();
    a->ptr0=_ogg_malloc(sizeof(long)*a->aux);
    for(i=0;i<a->aux;i++)
      if(get_next_ivalue(in,a->ptr0+i)){
	fprintf(stderr,"out of data while reading codebook %s\n",filename);
	exit(1);
      }
    
    /* load ptr1 */
    find_seek_to(in,"static long _vq_ptr1");
    reset_next_value();
    a->ptr1=_ogg_malloc(sizeof(long)*a->aux);
    for(i=0;i<a->aux;i++)
      if(get_next_ivalue(in,a->ptr1+i)){
	fprintf(stderr,"out of data while reading codebook %s\n",filename);
	exit(1);
    }
    
    
    /* load p */
    find_seek_to(in,"static long _vq_p_");
    reset_next_value();
    a->p=_ogg_malloc(sizeof(long)*a->aux);
    for(i=0;i<a->aux;i++)
      if(get_next_ivalue(in,a->p+i)){
	fprintf(stderr,"out of data while reading codebook %s\n",filename);
	exit(1);
      }
    
    /* load q */
    find_seek_to(in,"static long _vq_q_");
    reset_next_value();
    a->q=_ogg_malloc(sizeof(long)*a->aux);
    for(i=0;i<a->aux;i++)
      if(get_next_ivalue(in,a->q+i)){
	fprintf(stderr,"out of data while reading codebook %s\n",filename);
	exit(1);
      }    
  }
  
  if(find_seek_to(in,"static encode_aux_threshmatch _vq_aux")){
    /* how big? */
    c->thresh_tree=t=_ogg_calloc(1,sizeof(encode_aux_threshmatch));
    line=get_line(in);
    line=get_line(in);
    line=get_line(in);
    if(sscanf(line,"%d",&(t->quantvals))!=1){
      fprintf(stderr,"3: syntax in %s in line:\t %s",filename,line);
      exit(1);
    }
    line=get_line(in);
    if(sscanf(line,"%d",&(t->threshvals))!=1){
      fprintf(stderr,"4: syntax in %s in line:\t %s",filename,line);
      exit(1);
    }
    /* load quantthresh */
    find_seek_to(in,"static float _vq_quantthresh_");
    reset_next_value();
    t->quantthresh=_ogg_malloc(sizeof(float)*t->threshvals);
    for(i=0;i<t->threshvals-1;i++)
      if(get_next_value(in,t->quantthresh+i)){
	fprintf(stderr,"out of data 1 while reading codebook %s\n",filename);
	exit(1);
      }    
    /* load quantmap */
    find_seek_to(in,"static long _vq_quantmap_");
    reset_next_value();
    t->quantmap=_ogg_malloc(sizeof(long)*t->threshvals);
    for(i=0;i<t->threshvals;i++)
      if(get_next_ivalue(in,t->quantmap+i)){
	fprintf(stderr,"out of data 2 while reading codebook %s\n",filename);
	exit(1);
      }    
  }
    
  if(find_seek_to(in,"static encode_aux_pigeonhole _vq_aux")){
    int pigeons=1,i;
    /* how big? */
    c->pigeon_tree=p=_ogg_calloc(1,sizeof(encode_aux_pigeonhole));
    line=get_line(in);
    if(sscanf(line,"%f, %f, %d, %d",&(p->min),&(p->del),
	      &(p->mapentries),&(p->quantvals))!=4){
      fprintf(stderr,"5: syntax in %s in line:\t %s",filename,line);
      exit(1);
    }
    line=get_line(in);
    line=get_line(in);
    if(sscanf(line,"%ld",&(p->fittotal))!=1){
      fprintf(stderr,"6: syntax in %s in line:\t %s",filename,line);
      exit(1);
    }
    /* load pigeonmap */
    find_seek_to(in,"static long _vq_pigeonmap_");
    reset_next_value();
    p->pigeonmap=_ogg_malloc(sizeof(long)*p->mapentries);
    for(i=0;i<p->mapentries;i++)
      if(get_next_ivalue(in,p->pigeonmap+i)){
	fprintf(stderr,"out of data (pigeonmap) while reading codebook %s\n",filename);
	exit(1);
      }    
    /* load fitlist */
    find_seek_to(in,"static long _vq_fitlist_");
    reset_next_value();
    p->fitlist=_ogg_malloc(sizeof(long)*p->fittotal);
    for(i=0;i<p->fittotal;i++)
      if(get_next_ivalue(in,p->fitlist+i)){
	fprintf(stderr,"out of data (fitlist) while reading codebook %s\n",filename);
	exit(1);
      }    
    /* load fitmap */
    find_seek_to(in,"static long _vq_fitmap_");
    reset_next_value();
    for(i=0;i<c->dim;i++)pigeons*=p->quantvals;
    p->fitmap=_ogg_malloc(sizeof(long)*pigeons);
    for(i=0;i<pigeons;i++)
      if(get_next_ivalue(in,p->fitmap+i)){
	fprintf(stderr,"out of data (fitmap) while reading codebook %s\n",filename);
	exit(1);
      }    
 
    /* load fitlength */
    find_seek_to(in,"static long _vq_fitlength_");
    reset_next_value();
    p->fitlength=_ogg_malloc(sizeof(long)*pigeons);
    for(i=0;i<pigeons;i++)
      if(get_next_ivalue(in,p->fitlength+i)){
	fprintf(stderr,"out of data (fitlength) while reading codebook %s\n",filename);
	exit(1);
      }    
  }

  switch(c->maptype){
  case 0:
    quant_to_read=0;
    break;
  case 1:
    quant_to_read=_book_maptype1_quantvals(c);
    break;
  case 2:
    quant_to_read=c->entries*c->dim;
    break;
  }
    
  /* load the quantized entries */
  find_seek_to(in,"static long _vq_quantlist_");
  reset_next_value();
  c->quantlist=_ogg_malloc(sizeof(long)*quant_to_read);
  for(i=0;i<quant_to_read;i++)
    if(get_next_ivalue(in,c->quantlist+i)){
      fprintf(stderr,"out of data while reading codebook %s\n",filename);
      exit(1);
    }
  
  /* load the lengthlist */
  find_seek_to(in,"_lengthlist");
  reset_next_value();
  c->lengthlist=_ogg_malloc(sizeof(long)*c->entries);
  for(i=0;i<c->entries;i++)
    if(get_next_ivalue(in,c->lengthlist+i)){
      fprintf(stderr,"out of data while reading codebook %s\n",filename);
      exit(1);
    }

  /* got it all */
  fclose(in);
  
  vorbis_book_init_encode(b,c);

  return(b);
}
예제 #7
0
int get_next_ivalue(FILE *in,long *ivalue){
  float value;
  int ret=get_next_value(in,&value);
  *ivalue=value;
  return(ret);
}
예제 #8
0
				enum_class( const std::string &name )
					: enum_class( get_next_value(), name ) {
				}
예제 #9
0
				enum_class()
					: enum_class( get_next_value(), EMPTY_NAME ) {
				}
예제 #10
0
파일: main.c 프로젝트: eazygoin67/PpmViewer
int main( int argc, char **argv )
{
	// Check Command Args
	if ( argc < 2 )
	{
		fprintf( stderr, "Error: Please pass input file\n" );
		return 1;
	}

	// Initialise SDL
	if ( SDL_Init( SDL_INIT_VIDEO ) != 0 )
	{
		fprintf( stderr, "Error: Unable to Initialise SDL:\n%s\n", SDL_GetError() );
		return 1;
	}

	// Open Input File
	FILE *file = fopen( argv[1], "rb" );
	if ( file == NULL )
	{
		fprintf( stderr, "Error: Unable to open Input File:\n%s\n", argv[1] );
		return 1;
	}

	// Read Input File to Memory
	fseek( file, 0, SEEK_END );
	size_t file_size = ftell( file );
	fseek( file, 0, SEEK_SET );
	char *input = (char *)malloc( file_size+1 );
	if ( input == NULL )
	{
		fprintf( stderr, "Error: Unable to allocate memory for input: %u bytes\n", file_size+1 );
		return 1;
	}
	fread( input, file_size, 1, file );
	input[file_size] = '\0';
	fclose( file );

	// Declare Iterator and Value for File Data
	char *at = input;
	char val_string[16];
	bool read_result;

	// Check For ASCII Format
	read_result = get_next_word( &at, val_string, 15 );
	if ( !read_result || 
		 ( strcmp(val_string, "P3") != 0 && 
		   strcmp(val_string, "p3") != 0 ) )
	{
		fprintf( stderr, "Error: Format is not in ascii - cannot read!\n" );
		return 1;
	}

	// Create Window
	long s_width = 0;
	long s_height = 0;
	get_next_value( &at, &s_width );
	read_result = get_next_value( &at, &s_height );
	if ( !read_result )
	{
		fprintf( stderr, "Error: Invalid Input; Could not Read Size\n:" );
		return 1;
	}
	if ( s_width < DISPLAY_MIN_WIDTH || s_height < DISPLAY_MIN_HEIGHT )
	{
		fprintf( stderr, "Error: Image too small - min width/height = (%d,%d)\n",
				 DISPLAY_MIN_WIDTH, DISPLAY_MIN_HEIGHT );
		return 1;
	}
	if ( s_width > DISPLAY_MAX_WIDTH || s_height > DISPLAY_MAX_HEIGHT )
	{
		fprintf( stderr, "Error: Image too large - man width/height = (%d,%d)\n",
				 DISPLAY_MAX_WIDTH, DISPLAY_MAX_HEIGHT );
		return 1;
	}
	SDL_Window *window = SDL_CreateWindow(  "PPM Viewer", 
											128, 128, 
											s_width, s_height,
											SDL_WINDOW_OPENGL );
	if ( window == NULL )
	{
		fprintf( stderr, "Error: Could not create SDL Window!\n" );
		return 1;
	}

	// Create OpenGL Context from SDL
	SDL_GLContext context = SDL_GL_CreateContext( window );
	if ( context == 0 )
	{
		fprintf( stderr, "Error: Unable to create GL context for SDL\n" );
		return 1;
	}

	// Read Max Color Value
	long max_color = 255;
	read_result = get_next_value( &at, &max_color );
	if ( !read_result )
	{
		fprintf( stderr, "Error: Could not read max color value" );
		return 1;
	}

	// Init OpenGL
	glClearColor( 1.0f, 1.0f, 1.0f, 0.0f );
	glMatrixMode( GL_PROJECTION );
	gluOrtho2D( 0.0, (GLdouble)s_width, (GLdouble)s_height, 0.0 );

	// Clear Screen
	glClear( GL_COLOR_BUFFER_BIT );

	// Remember this iterator location
	// We will need to reset to it, if we
	// need to redraw the image
	char *pixel_read_start = at;

	// Loop through each RGB triplet and put a
	// pixel on the screen
	long pixel_count = s_width * s_height;
	long pixel_read = 0;
	long r, g, b;
	while( pixel_read < pixel_count )
	{
		if ( !get_next_value(&at, &r) )
			break;
		if ( !get_next_value(&at, &g) )
			break;
		if ( !get_next_value(&at, &b) )
			break;

		r = clampl( r, 0, max_color );
		g = clampl( g, 0, max_color );
		b = clampl( b, 0, max_color );

		glColor3f( (GLfloat)(r)/(GLfloat)(max_color),
				   (GLfloat)(g)/(GLfloat)(max_color),
				   (GLfloat)(b)/(GLfloat)(max_color) );

		put_pixel( pixel_read % s_width, pixel_read / s_width );

		++pixel_read;
	} 

	// Swap Bit Buffer
	SDL_GL_SwapWindow( window );

	// Main Loop 
	bool running = true;
	while( running )
	{
		SDL_Event event;
		while ( SDL_PollEvent( &event ) )
		{
			if ( event.type == SDL_WINDOWEVENT )
			{
				switch( event.window.event )
				{
					// Close Window
					case SDL_WINDOWEVENT_CLOSE: {
						running = false;
					} break;

					// Restored Focus
					case SDL_WINDOWEVENT_RESTORED: {

						// We need to Refresh the Screen

						// Clear the Screen
						glClear( GL_COLOR_BUFFER_BIT );

						// Reset our string iterator to the start
						// of where our pixels are read
						at = pixel_read_start;

						// Loop through each RGB triplet and put a
						// pixel on the screen
						pixel_read = 0;
						while( pixel_read < pixel_count )
						{
							if ( !get_next_value(&at, &r) )
								break;
							if ( !get_next_value(&at, &g) )
								break;
							if ( !get_next_value(&at, &b) )
								break;

							r = clampl( r, 0, max_color );
							g = clampl( g, 0, max_color );
							b = clampl( b, 0, max_color );

							glColor3f( (GLfloat)(r)/(GLfloat)(max_color),
									   (GLfloat)(g)/(GLfloat)(max_color),
									   (GLfloat)(b)/(GLfloat)(max_color) );

							put_pixel( pixel_read % s_width, pixel_read / s_width );

							++pixel_read;
						}

						// Swap Bit Buffer
						SDL_GL_SwapWindow( window );
					} break;
				}
			}
		}
	}

	// NOTE(troy): Our other resources have not been cleared, but for this small
	//			program it should be okay. The OS will clean up the memory, and the 
	//			program will close faster because of it.

	// Free File Memory
	free( input );

	// Return Success
	return 0;
}