예제 #1
0
static bool ase_file_read_header(FILE *f, ASE_Header *header)
{
  header->pos = ftell(f);

  header->size  = fgetl(f);
  header->magic = fgetw(f);
  if (header->magic != ASE_FILE_MAGIC)
    return false;

  header->frames     = fgetw(f);
  header->width      = fgetw(f);
  header->height     = fgetw(f);
  header->depth      = fgetw(f);
  header->flags      = fgetl(f);
  header->speed      = fgetw(f);
  header->next       = fgetl(f);
  header->frit       = fgetl(f);
  header->transparent_index = fgetc(f);
  header->ignore[0]  = fgetc(f);
  header->ignore[1]  = fgetc(f);
  header->ignore[2]  = fgetc(f);
  header->ncolors    = fgetw(f);
  if (header->ncolors == 0)     // 0 means 256 (old .ase files)
    header->ncolors = 256;

  fseek(f, header->pos+128, SEEK_SET);
  return true;
}
예제 #2
0
float score_game(float *board)
{
    FILE *f = fopen("game.txt", "w");
    int i, j;
    int count = 3;
    fprintf(f, "komi 6.5\n");
    fprintf(f, "boardsize 19\n");
    fprintf(f, "clear_board\n");
    for(j = 0; j < 19; ++j){
        for(i = 0; i < 19; ++i){
            if(board[j*19 + i] == 1) fprintf(f, "play black %c%d\n", 'A'+i+(i>=8), 19-j);
            if(board[j*19 + i] == -1) fprintf(f, "play white %c%d\n", 'A'+i+(i>=8), 19-j);
            if(board[j*19 + i]) ++count;
        }
    }
    fprintf(f, "final_score\n");
    fclose(f);
    FILE *p = popen("./gnugo --mode gtp < game.txt", "r");
    for(i = 0; i < count; ++i){
        free(fgetl(p));
        free(fgetl(p));
    }
    char *l = 0;
    float score = 0;
    char player = 0;
    while((l = fgetl(p))){
        fprintf(stderr, "%s  \t", l);
        int n = sscanf(l, "= %c+%f", &player, &score);
        free(l);
        if (n == 2) break;
    }
    if(player == 'W') score = -score;
    pclose(p);
    return score;
}
예제 #3
0
파일: readfile.c 프로젝트: mingpen/OpenNT
/*  GrabNextPage - get the offset for the next page in the FT->pages [ ] array.
 *                 if there is not enough room in FT->pages [ ], expand it and
 *                 then add the next page.  note that it doesn't update FT->top.
 *
 *  arguments:
 *      hWnd        window message is being displayed in
 *
 *  return value:
 *      TRUE        the next page is present
 *      FALSE       currently at eof
 */
FLAG PASCAL INTERNAL GrabNextPage ( HW hWnd )
{
    FLAG flag = FALSE;
    PLONG   newPages;
    LONG    newPos;
    CHAR    line [ MAXLINELEN ];
    INT     cGetChar = TWINWIDTH ( hWnd ) + 1;

    if ( fSkipToLine ( hWnd, PAGETOLINE (FT->cPages) - 1 ) ) {
        fgetl ( line, cGetChar, FT->fhRead );
        newPos = ftell ( FT->fhRead );
        if ( fgetl ( line, cGetChar, FT->fhRead ) ) {
            if ( FT->cPages + 1 == FT->cPageMax ) {
                FT->cPageMax += PAGEGROW;
                newPages = ( PLONG ) ZMalloc ( FT->cPageMax *
                    sizeof ( *newPages ) );
                Move ( ( LPBYTE ) FT->pages, ( LPBYTE )newPages,
                    FT->cPageMax * sizeof ( *newPages ) );
                ZMfree ( FT->pages );
                FT->pages = newPages;
                }
            fseek ( FT->fhRead, newPos, 0 );
            FT->pages [ FT->cPages++ ] = newPos;
            flag = TRUE;
            }
        }
    return flag;
}
예제 #4
0
static void clean_buffer(void)
{
	char line[LINE_BUFFER_SIZE];
	unsigned int current, *last;

	if (use_to_unique_but_not_add) {
		if (fseek(use_to_unique_but_not_add, 0, SEEK_SET) < 0) pexit("fseek");
		while (fgetl(line, sizeof(line), use_to_unique_but_not_add)) {
			if (cut_len) line[cut_len] = 0;
			last = &buffer.hash[line_hash(line)];
#if ARCH_LITTLE_ENDIAN && !ARCH_INT_GT_32
			current = *last;
#else
			current = get_int(last);
#endif
			while (current != ENTRY_END_HASH) {
				if (current != ENTRY_DUPE && !strcmp(line, &buffer.data[current + 4])) {
					put_int(last, get_data(current));
					put_data(current, ENTRY_DUPE);
					break;
				}
				last = (unsigned int *)&buffer.data[current];
				current = get_int(last);
			}
		}
	}

	if (do_not_unique_against_self)
	  return;

	if (fseek(output, 0, SEEK_SET) < 0) pexit("fseek");

	while (fgetl(line, sizeof(line), output)) {
		if (cut_len) line[cut_len] = 0;
		last = &buffer.hash[line_hash(line)];
#if ARCH_LITTLE_ENDIAN && !ARCH_INT_GT_32
		current = *last;
#else
		current = get_int(last);
#endif
		while (current != ENTRY_END_HASH && current != ENTRY_DUPE) {
			if (!strcmp(line, &buffer.data[current + 4])) {
				put_int(last, get_data(current));
				put_data(current, ENTRY_DUPE);
				break;
			}
			last = (unsigned int *)&buffer.data[current];
			current = get_int(last);
		}
	}

	if (ferror(output)) pexit("fgets");

/* Workaround a Solaris stdio bug */
	if (fseek(output, 0, SEEK_END) < 0) pexit("fseek");
}
예제 #5
0
/*---------------------------------------------------------------*/
LABEL   *LabelReadFile(char *labelfile) {
  LABEL  *area ;
  char   *fname, line[STRLEN], *cp;
  FILE   *fp ;
  int    vno, nlines ;
  float  x, y, z, stat ;

  fname = labelfile;

  area = (LABEL *)calloc(1, sizeof(LABEL)) ;
  if (!area)
    ErrorExit(ERROR_NOMEMORY,"%s: could not allocate LABEL struct.",Progname);

  /* read in the file */
  fp = fopen(fname, "r") ;
  if (!fp)
    ErrorReturn(NULL, (ERROR_NOFILE, "%s: could not open label file %s",
                       Progname, fname)) ;

  cp = fgetl(line, 199, fp) ;
  if (!cp)
    ErrorReturn(NULL,
                (ERROR_BADFILE, "%s: empty label file %s", Progname, fname)) ;
  if (!sscanf(cp, "%d", &area->n_points))
    ErrorReturn(NULL,
                (ERROR_BADFILE, "%s: could not scan # of lines from %s",
                 Progname, fname)) ;
  area->max_points = area->n_points ;
  area->lv = (LABEL_VERTEX *)calloc(area->n_points, sizeof(LABEL_VERTEX)) ;
  if (!area->lv)
    ErrorExit(ERROR_NOMEMORY,
              "%s: LabelRead(%s) could not allocate %d-sized vector",
              Progname, labelfile, sizeof(LV)*area->n_points) ;
  nlines = 0 ;
  while ((cp = fgetl(line, 199, fp)) != NULL) {
    if (sscanf(cp, "%d %f %f %f %f", &vno, &x, &y, &z, &stat) != 5)
      ErrorReturn(NULL, (ERROR_BADFILE, "%s: could not parse %dth line in %s",
                         Progname, area->n_points, fname)) ;
    area->lv[nlines].x = x ;
    area->lv[nlines].y = y ;
    area->lv[nlines].z = z ;
    area->lv[nlines].stat = stat ;
    area->lv[nlines].vno = vno ;
    nlines++ ;
  }

  fclose(fp) ;
  if (!nlines)
    ErrorReturn(NULL,
                (ERROR_BADFILE,
                 "%s: no data in label file %s", Progname, fname));
  return(area) ;
}
예제 #6
0
파일: rforest.c 프로젝트: vgurev/freesurfer
RANDOM_FOREST *
RFreadFrom(FILE *fp)
{
  RF     *rf ;
  int    nfeatures, nclasses, ntrees, max_depth, ntraining, nsteps, c, n, f ;
  char   line[MAX_LINE_LEN], *cp, *class_names[MAX_CLASSES] ;
  double feature_fraction ;

  cp = fgetl(line, MAX_LINE_LEN, fp) ;
  sscanf(cp, "%d %d %d %d %d %d %lf", 
         &nfeatures, &nclasses, &ntrees, &max_depth, &ntraining,&nsteps, &feature_fraction) ;
  for (c = 0 ; c < nclasses ; c++)
  {
    cp = fgetl(line, MAX_LINE_LEN, fp) ;
    class_names[c] = (char *)calloc(strlen(cp)+1, sizeof(char)) ;
    strcpy(class_names[c], cp) ;
  }
  rf = RFalloc(ntrees, nfeatures, nclasses, max_depth, class_names, nsteps) ;
  rf->feature_fraction = feature_fraction ;
  rf->ntraining = ntraining ;

  rf->feature_min = (double *)calloc(rf->nfeatures, sizeof(rf->feature_min[0])) ;
  if (rf->feature_min == NULL)
    ErrorExit(ERROR_NOMEMORY, "RFalloc(%d, %d, %d, %d): could not allocate fmin",
              ntrees,nfeatures,nclasses, max_depth) ;
  rf->feature_max = (double *)calloc(rf->nfeatures, sizeof(rf->feature_max[0])) ;
  if (rf->feature_max == NULL)
    ErrorExit(ERROR_NOMEMORY, "RFalloc(%d, %d, %d, %d): could not allocate fmax",
              ntrees,nfeatures,nclasses, max_depth) ;
  for (f = 0 ; f < rf->nfeatures ; f++)
  {
    cp = fgetl(line, MAX_LINE_LEN, fp) ;
    sscanf(cp, "%lf %lf\n", &rf->feature_min[f], &rf->feature_max[f]) ;
  }
  cp = fgetl(line, MAX_LINE_LEN, fp) ;  // should be FEATURE NAMES
  rf->feature_names = (char **)calloc(rf->nfeatures, sizeof(char *)) ;
  if (rf->feature_names == NULL)
    ErrorExit(ERROR_NOMEMORY, "RFreadFrom: could not allocate feature name array") ;
  for (f = 0 ; f < rf->nfeatures ; f++)
  {
    cp = fgetl(line, MAX_LINE_LEN, fp) ;  
    rf->feature_names[f] = (char *)calloc(strlen(cp)+1, sizeof(char)) ;
    if (rf->feature_names[f] == NULL)
      ErrorExit(ERROR_NOMEMORY, "RFreadFrom: could not allocate %d-len feature name array [%d]", strlen(cp)+1, f) ;
    strcpy(rf->feature_names[f], cp) ;
  }

  for (n = 0 ; n < rf->ntrees ; n++)
    rfReadTree(rf, &rf->trees[n], fp) ;
  for (c = 0 ; c < nclasses ; c++)
    free(class_names[c]) ;
  return(rf) ;
}
예제 #7
0
static int
translate_indices_to_annotations(MRI_SURFACE *mris, char *translation_fname) {
  char   fname[STRLEN], *cp, line[STRLEN], name[STRLEN], **names ;
  FILE   *fp ;
  int    nlines, i, vno, *r, *g, *b, *indices ;
  VERTEX *v ;

  cp = getenv("FREESURFER_HOME") ;
  if (!cp)
    ErrorExit(ERROR_BADPARM,
              "%s: FREESURFER_HOME not defined in environment", Progname) ;
  sprintf(fname, "%s/%s", cp, translation_fname) ;
  fp = fopen(fname, "r") ;
  if (!fp)
    ErrorExit(ERROR_NOFILE,
              "%s: could not read translation file %s", Progname, fname) ;

  nlines = 0 ;
  cp = fgetl(line, STRLEN-1, fp) ;
  while (cp != NULL) {
    nlines++ ;
    cp = fgetl(line, STRLEN-1, fp) ;
  }
  printf("%d lines found in file\n", nlines) ;
  rewind(fp) ;

  r = (int *)calloc(nlines, sizeof(int)) ;
  g = (int *)calloc(nlines, sizeof(int)) ;
  b = (int *)calloc(nlines, sizeof(int)) ;
  indices = (int *)calloc(nlines, sizeof(int)) ;
  names = (char **)calloc(nlines, sizeof(char *)) ;
  if (!r || !g || !b || !indices || !names)
    ErrorExit(ERROR_NOMEMORY, "%s: could not allocate %d-len internal buffers",
              Progname, nlines) ;

  for (i = 0 ; i < nlines ; i++) {
    cp = fgetl(line, STRLEN-1, fp) ;
    sscanf(cp, "%d %s %d %d %d %*d",
           &indices[i], name, &r[i], &g[i], &b[i]) ;
    names[i] = (char *)calloc(strlen(name)+1, sizeof(char)) ;
    strcpy(names[i], name) ;
    printf("parsing parcellation unit %s...\n", name) ;
  }
  fclose(fp) ;

  for (vno = 0 ; vno < mris->nvertices ; vno++) {
    v = &mris->vertices[vno] ;
    if (v->ripflag)
      continue ;
  }
  return(NO_ERROR) ;
}
예제 #8
0
LTA *ltaReadFileEx(const char *fname)
{
  FILE             *fp;
  LINEAR_TRANSFORM *lt ;
  int              i, nxforms, type ;
  char             line[STRLEN], *cp ;
  LTA              *lta ;

  fp = fopen(fname,"r");
  if (fp==NULL)
    ErrorReturn(NULL,
                (ERROR_BADFILE, "ltaReadFile(%s): can't open file",fname));
  cp = fgetl(line, 199, fp) ;
  if (cp == NULL)
  {
    fclose(fp) ;
    ErrorReturn(NULL, (ERROR_BADFILE, "ltaReadFile(%s): can't read data",fname));
  }
  sscanf(cp, "type      = %d\n", &type) ;
  cp = fgetl(line, 199, fp) ;
  sscanf(cp, "nxforms   = %d\n", &nxforms) ;
  lta = LTAalloc(nxforms, NULL) ;
  lta->type = type ;
  for (i = 0 ; i < lta->num_xforms ; i++)
  {
    lt = &lta->xforms[i] ;
    fscanf(fp, "mean      = %f %f %f\n", &lt->x0, &lt->y0, &lt->z0) ;
    fscanf(fp, "sigma     = %f\n", &lt->sigma) ;
    MatrixAsciiReadFrom(fp, lt->m_L) ;
  }
  // oh, well this is the added part
  for (i=0; i < lta->num_xforms; i++)
  {
    if (fgets(line, 199, fp))
    {
      if (strncmp(line, "src volume info", 15)==0)
      {
        char *p;
        readVolGeom(fp, &lta->xforms[i].src);
        p = fgets(line, 199, fp);
        if (strncmp(line, "dst volume info", 15)==0)
          readVolGeom(fp, &lta->xforms[i].dst);
      }
    }
  }
  fclose(fp) ;
  return(lta) ;
}
예제 #9
0
파일: readfile.c 프로젝트: mingpen/OpenNT
/*  LineToCont - move to the given position in the file, grab the line and put
 *               it in the correct line of hWnd->pContent
 *
 *  arguments:
 *      hWnd        window of interest
 *      lineNum     line to fetch
 *
 *  return value:
 *      none
 */
VOID PASCAL INTERNAL LineToCont ( HW hWnd, INT lineNum )
{
    INT width = TWINWIDTH ( hWnd );
    CHAR        line [ MAXLINELEN ];
    INT ContentLine;

    if ( ( lineNum > FT->llof ) && ( FT->llof != -1 ) )
        return;

    if ( fSkipToLine ( hWnd, lineNum ) ) {
        /* +1 for the trailing null char */
        if ( fgetl ( line, width + 1, FT->fhRead ) ) {
            FT->cur++;
            if ( LINETOPAGE (FT->cur) >= FT->cPages && !GrabNextPage ( hWnd ) )
                FT->llof = FT->cur;
            }
        else
            FT->llof = FT->cur;
        if ( !strcmpis ( strEOH, line ) )
            *line = 0;
        }
    SpacePad ( line, MAXLINELEN - 1 );
    ContentLine = lineNum - FT->top;
    if ( ( ContentLine >= 0 ) && ( ContentLine <= TWINHEIGHT ( hWnd ) - 1 ) )
        Move ( ( LPSTR ) line, ( LPSTR ) hWnd->pContent +
            ( ContentLine *  width * sizeof ( CHAR ) ), width );
    return;
}
예제 #10
0
파일: classifier.c 프로젝트: imaami/darknet
list *read_data_cfg(char *filename)
{
    FILE *file = fopen(filename, "r");
    if(file == 0) file_error(filename);
    char *line;
    int nu = 0;
    list *options = make_list();
    while((line=fgetl(file)) != 0){
        ++ nu;
        strip(line);
        switch(line[0]){
            case '\0':
            case '#':
            case ';':
                free(line);
                break;
            default:
                if(!read_option(line, options)){
                    fprintf(stderr, "Config file error line %d, could parse: %s\n", nu, line);
                    free(line);
                }
                break;
        }
    }
    fclose(file);
    return options;
}
예제 #11
0
SEQUENCE readOneSequence(OPTIONS options){
  SEQUENCE SEQ;
  char inchar;

  /* input sequence name */
  SEQ.name=fgetl(options.fin);
  SEQ.name.string[--SEQ.name.length]='\0'; /* chop */
  SEQ.orf.string=NULL;
  
  if (options.verbose>=1) fprintf(options.fout,"# session %s\n", SEQ.name.string);

  /* read sequence */
  inchar=fgetc(options.fin);
  SEQ.sequence=instanceString();
  for(SEQ.sequence.length=0; inchar!=EOF;){
    /*if (('a'<=inchar && inchar<='z') || ('A'<=inchar && inchar<='Z')) {*/
    if (isalpha(inchar)) {
      if(SEQ.sequence.length + 10 > SEQ.sequence.buffer){
	SEQ.sequence.buffer = (SEQ.sequence.length + MAXLETTER)*sizeof(char);
	SEQ.sequence.string 
	  = (char*)realloc(SEQ.sequence.string, SEQ.sequence.buffer);
	if(SEQ.sequence.string == NULL){
	  fprintf(stderr, "Memory err occurred on line %d\n", __LINE__);
	  exit(1);
	}
      }
      SEQ.sequence.string[SEQ.sequence.length]   = inchar;
      SEQ.sequence.string[SEQ.sequence.length+1] = '\0';
      SEQ.sequence.length++;
    }
    inchar=fgetc(options.fin);
    if (inchar=='>') break;
  }
  return SEQ;
}
예제 #12
0
void cfg_init(char *name, int allow_missing)
{
	FILE *file;
	char line[LINE_BUFFER_SIZE];
	int number;

	if (cfg_database && !cfg_recursion) return;

	cfg_name = str_alloc_copy(path_expand(name));
	file = fopen(cfg_name, "r");
	if (!file) {
		cfg_name = str_alloc_copy(path_expand_ex(name));
		file = fopen(cfg_name, "r");
		if (!file) {
			if (allow_missing && errno == ENOENT) return;
			pexit("fopen: %s", cfg_name);
		}
	}

	number = 0;
	while (fgetl(line, sizeof(line), file))
	if (cfg_process_line(line, ++number)) cfg_error(cfg_name, number);

	if (ferror(file)) pexit("fgets");

	if (fclose(file)) pexit("fclose");
}
예제 #13
0
파일: gflib.c 프로젝트: idaohang/GLFGPSSim
char *batchprocfile(char name[], char *parser())
{
 FILE *unit;
 char *ptr;
 level = -1;
 batchlevel = level;
 unit = fopen(name,"r");
 if (unit == NULL)
    return "? Unable to open input file";
 level = 0;
 batchlevel = level;
 while (TRUE)
   {
    if (level == 0)
      {
       ptr = fgetl(unit,procbuffer,255);
       if (ptr == NULL)
          break;
      }
    ptr = batch_____proc(procbuffer,parser);
    if (level < 0)
       return ptr;
   }
 while (level > 0)
   {
    fclose(procfile[level]);
    level--;
   }
 fclose(unit);
 level = -1;
 batchlevel = level;
 procbuffer[0] = 0;
 return parser(procbuffer);
}
예제 #14
0
list *read_cfg(char *filename)
{
    FILE *file = fopen(filename, "r");
    if(file == 0) file_error(filename);
    char *line;
    int nu = 0;
    list *sections = make_list();
    section *current = 0;
    while((line=fgetl(file)) != 0){
        ++ nu;
        strip(line);
        switch(line[0]){
            case '[':
                current = malloc(sizeof(section));
                list_insert(sections, current);
                current->options = make_list();
                current->type = line;
                break;
            case '\0':
            case '#':
            case ';':
                free(line);
                break;
            default:
                if(!read_option(line, current->options)){
                    fprintf(stderr, "Config file error line %d, could parse: %s\n", nu, line);
                    free(line);
                }
                break;
        }
    }
    fclose(file);
    return sections;
}
예제 #15
0
static void ase_file_read_frame_header(FILE *f, ASE_FrameHeader *frame_header)
{
  frame_header->size = fgetl(f);
  frame_header->magic = fgetw(f);
  frame_header->chunks = fgetw(f);
  frame_header->duration = fgetw(f);
  ase_file_read_padding(f, 6);
}
예제 #16
0
파일: cshr.c 프로젝트: ec429/harris
int main(void)
{
	struct hist_record rec;
	char *line;
	char outbuf[80];
	int rc;

	while(!feof(stdin))
	{
		line = fgetl(stdin);
		if (!line)
		{
			fprintf(stderr, "Unexpected EOF\n");
			return 3;
		}
		if (!strncmp(line, "History:", 8))
		{
			free(line);
			break;
		}
	}

	while(!feof(stdin))
	{
		line = fgetl(stdin);
		if (!line) break;
		rc = parse_event(&rec, line);
		if (rc)
		{
			fprintf(stderr, "Error %d in line: %s\n", rc, line);
			free(line);
			return rc;
		}
		free(line);
		if (rec.type == HT_MISC)
		{
			if (rec.misc.type == ME_CASH)
			{
				writedate(rec.date, outbuf);
				printf("%s CA %d %d\n", outbuf, rec.misc.cash.delta, rec.misc.cash.current);
			}
		}
	}
	return 0;
}
예제 #17
0
파일: tree.c 프로젝트: Darzu/darknet
tree *read_tree(char *filename)
{
    tree t = {0};
    FILE *fp = fopen(filename, "r");

    char *line;
    int last_parent = -1;
    int group_size = 0;
    int groups = 0;
    int n = 0;
    while((line=fgetl(fp)) != 0){
        char *id = calloc(256, sizeof(char));
        int parent = -1;
        sscanf(line, "%s %d", id, &parent);
        t.parent = realloc(t.parent, (n+1)*sizeof(int));
        t.parent[n] = parent;

        t.child = realloc(t.child, (n+1)*sizeof(int));
        t.child[n] = -1;

        t.name = realloc(t.name, (n+1)*sizeof(char *));
        t.name[n] = id;
        if(parent != last_parent){
            ++groups;
            t.group_offset = realloc(t.group_offset, groups * sizeof(int));
            t.group_offset[groups - 1] = n - group_size;
            t.group_size = realloc(t.group_size, groups * sizeof(int));
            t.group_size[groups - 1] = group_size;
            group_size = 0;
            last_parent = parent;
        }
        t.group = realloc(t.group, (n+1)*sizeof(int));
        t.group[n] = groups;
        if (parent >= 0) {
            t.child[parent] = groups;
        }
        ++n;
        ++group_size;
    }
    ++groups;
    t.group_offset = realloc(t.group_offset, groups * sizeof(int));
    t.group_offset[groups - 1] = n - group_size;
    t.group_size = realloc(t.group_size, groups * sizeof(int));
    t.group_size[groups - 1] = group_size;
    t.n = n;
    t.groups = groups;
    t.leaf = calloc(n, sizeof(int));
    int i;
    for(i = 0; i < n; ++i) t.leaf[i] = 1;
    for(i = 0; i < n; ++i) if(t.parent[i] >= 0) t.leaf[t.parent[i]] = 0;

    fclose(fp);
    tree *tree_ptr = calloc(1, sizeof(tree));
    *tree_ptr = t;
    //error(0);
    return tree_ptr;
}
예제 #18
0
파일: io.cpp 프로젝트: nbcin/POLDER
string File::operator*() const
{
    char* line = nullptr;
    if (fgetl(line, _file))
    {
        return string(line);
    }
    return string("");
}
예제 #19
0
파일: cut.c 프로젝트: jarn0x/Escape
static void handleFile(FILE *f,char *delim,int first,int last) {
	char line[MAX_LINE_LEN];
	while(fgetl(line,sizeof(line),f)) {
		printFields(line,delim,first,last);
		if(ferror(stdout)) {
			printe("Write failed");
			break;
		}
	}
}
예제 #20
0
파일: rforest.c 프로젝트: vgurev/freesurfer
static int
rfReadNode(RANDOM_FOREST *rf, NODE *node, FILE *fp)
{
  int   c, leaf ;
  char  line[MAX_LINE_LEN], *cp ;

  cp = fgetl(line, MAX_LINE_LEN, fp) ;
  sscanf(cp, "NODE %d %d %d %lf\n", &leaf, &node->depth, &node->feature, &node->thresh) ;
  cp = fgetl(line, MAX_LINE_LEN, fp) ;
  cp = strtok(line, " ") ;
  for (node->total_counts = 0, c = 0 ; c < rf->nclasses ; c++)
  {
    if (cp == NULL)
      ErrorExit(ERROR_BADFILE, "could not read class counts") ;
    sscanf(cp, "%d ", &node->class_counts[c]) ;
    cp = strtok(NULL, " ") ;
    node->total_counts += node->class_counts[c] ;
  }

  node->training_set = (int *)calloc(node->total_counts, sizeof(node->training_set[0])) ;
#if 0
  cp = fgetl(line, MAX_LINE_LEN, fp) ;
  cp = strtok(line, " ") ;
  for (n = 0 ; n < node->total_counts ; n++)
  {
    if (cp == NULL)
      ErrorExit(ERROR_BADFILE, "could not read training set") ;
    sscanf(cp, "%d ", &node->training_set[n]) ;
    cp = strtok(NULL, " ") ;
  }
#endif
  cp = fgetl(line, MAX_LINE_LEN, fp) ;  // NODE: END line
  if (leaf == 0)  // read the next pair of nodes
  {
    node->left = rfAllocateNode(node->total_counts, node->depth+1, rf->nclasses) ;
    node->right = rfAllocateNode(node->total_counts, node->depth+1, rf->nclasses) ;
    rfReadNode(rf, node->left, fp) ;
    rfReadNode(rf, node->right, fp) ;
  }
  return(NO_ERROR) ;
}
예제 #21
0
static int
lpafFillEntries(LP_ANSWER_FILE *lpaf, char *fname, int entryno)
{
  int  nentries, type, i, num ;
  char buf[100], *base_name, line[200], *cp ;
  FILE *fp ;

  nentries = FileNumberOfEntries(fname) ;
  type = FileType(fname) ;
  base_name = FileFullName(fname) ;

  for (i = 0 ; i < nentries ; i++)
  {
    switch (type)
    {
    case LIST_FILE:
      fp = fopen(base_name, "rb") ;
      if (!fp)
        ErrorReturn(0, (ERROR_NO_FILE, "lpafFillEntries: could not open %s\n",
                        base_name)) ;
      cp = fgetl(line, 199, fp) ;
      nentries = 0 ;
      while (cp)
      {
        sscanf(cp, "%s", buf) ;
        num = lpafFillEntries(lpaf, buf, entryno+nentries) ;
        nentries += num ;
        cp = fgetl(line, 199, fp) ;
      }
      fclose(fp) ;
      break ;
    default:
      sprintf(buf, "%s#%d", base_name, i) ;
      lpaf->filelist[entryno+i] = (char *)calloc(strlen(buf)+1, sizeof(char));
      strcpy(lpaf->filelist[entryno+i], buf) ;
      break ;
    }
  }
  return(nentries) ;
}
예제 #22
0
static MAYBE_INLINE int skip_lines(unsigned long n, char *line)
{
	if (n) {
		line_number += n;

		do {
			if (!fgetl(line, LINE_BUFFER_SIZE, word_file))
				return 1;
		} while (--n);
	}

	return 0;
}
예제 #23
0
파일: rforest.c 프로젝트: vgurev/freesurfer
static int 
rfReadTree(RANDOM_FOREST *rf, TREE *tree, FILE *fp)
{
  int   f ;
  char  line[MAX_LINE_LEN], *cp ;

  cp = fgetl(line, MAX_LINE_LEN, fp) ;
  sscanf(cp, "TREE %d %d %d\n", &tree->depth, &tree->nleaves, &tree->nfeatures) ;
  tree->feature_list = (int *)calloc(tree->nfeatures, sizeof(tree->feature_list[0]));
  if (tree->feature_list == NULL)
    ErrorExit(ERROR_NOMEMORY, "rfReadTree: could not allocate feature list  (%d)",
	      tree->nfeatures) ;
  for (f = 0 ; f < tree->nfeatures ; f++)
  {
    cp = fgetl(line, MAX_LINE_LEN, fp) ;
    sscanf(cp, "%d", &tree->feature_list[f]) ;
  }

  rfReadNode(rf, &tree->root, fp) ;
  cp = fgetl(line, MAX_LINE_LEN, fp) ;   // TREE: END line
  rfFindLeaves(tree) ;
  return(NO_ERROR) ;
}
예제 #24
0
파일: utils.c 프로젝트: whcsteam/darknet
int *read_map(char *filename)
{
    int n = 0;
    int *map = 0;
    char *str;
    FILE *file = fopen(filename, "r");
    if(!file) file_error(filename);
    while((str=fgetl(file))){
        ++n;
        map = realloc(map, n*sizeof(int));
        map[n-1] = atoi(str);
    }
    return map;
}
예제 #25
0
파일: gflib.c 프로젝트: idaohang/GLFGPSSim
static char *batch_____proc(char strg[], char *parser())
{
 char *ptr;
 while (level > 0)
   {
    if (fgetl(procfile[level],procbuffer,255) != NULL)
       break;
    else
      {
       fclose(procfile[level]);
       level--;
       batchlevel = level;
       if (level == 0)
          return "";
      }
   }
 if (level == 0)
   {
    strncpy(procbuffer,strg,255);
    procbuffer[255] = 0;
   }
 batchlevel = level;
 ptr = parser(procbuffer);
 if (*ptr != 0)
   {
    if (*ptr == '?')    /* ? in first column indicates quit request */
      {
       while (level > 0)
         {
          fclose(procfile[level]);
          level--;
         }
       level = -1;
       batchlevel = level;
       return ptr;
      }
    /* else is assumed to be #INCLUDE filename */
    level++;
    if (level > 10)
       level = 10;
    else
      {
       procfile[level] = fopen(ptr,"r");
       if (procfile[level] == NULL)
          level--;
      }
   }
 batchlevel = level;
 return ptr;
}
예제 #26
0
static void read_file(char *name, void (*process_line)(char *line))
{
    FILE *file;
    char line[LINE_BUFFER_SIZE];

    if (!(file = fopen(name, "r")))
        pexit("fopen: %s", name);

    while (fgetl(line, sizeof(line), file))
        process_line(line);

    if (ferror(file)) pexit("fgets");

    if (fclose(file)) pexit("fclose");
}
예제 #27
0
void vec_char_rnn(char *cfgfile, char *weightfile, char *seed)
{
    char *base = basecfg(cfgfile);
    fprintf(stderr, "%s\n", base);

    network net = parse_network_cfg(cfgfile);
    if(weightfile){
        load_weights(&net, weightfile);
    }
    int inputs = get_network_input_size(net);

    int c;
    int seed_len = strlen(seed);
    float *input = calloc(inputs, sizeof(float));
    int i;
    char *line;
    while((line=fgetl(stdin)) != 0){
        reset_rnn_state(net, 0);
        for(i = 0; i < seed_len; ++i){
            c = seed[i];
            input[(int)c] = 1;
            network_predict(net, input);
            input[(int)c] = 0;
        }
        strip(line);
        int str_len = strlen(line);
        for(i = 0; i < str_len; ++i){
            c = line[i];
            input[(int)c] = 1;
            network_predict(net, input);
            input[(int)c] = 0;
        }
        c = ' ';
        input[(int)c] = 1;
        network_predict(net, input);
        input[(int)c] = 0;

        layer l = net.layers[0];
        #ifdef GPU
        cuda_pull_array(l.output_gpu, l.output, l.outputs);
        #endif
        printf("%s", line);
        for(i = 0; i < l.outputs; ++i){
            printf(",%g", l.output[i]);
        }
        printf("\n");
    }
}
예제 #28
0
파일: main.c 프로젝트: heroinlin/OpencvTest
list *get_paths(char *filename)
{
	list *lines = NULL;  //add by frisch // list *lines;
	char *path;
	FILE *file = fopen(filename, "r");
	if (!file)
	{
		fprintf(stderr, "Couldn't open file: %s\n", filename);
		exit(0);
	}
	lines = make_list();
	while ((path = fgetl(file))){
		list_insert(lines, path);
	}
	fclose(file);
	return lines;
}
예제 #29
0
파일: hlfmt.c 프로젝트: ghostyguo/hashcat
u32 hlfmt_detect (hashcat_ctx_t *hashcat_ctx, FILE *fp, u32 max_check)
{
  const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;

  // Exception: those formats are wrongly detected as HLFMT_SHADOW, prevent it

  if (hashconfig->hash_mode == 5300) return HLFMT_HASHCAT;
  if (hashconfig->hash_mode == 5400) return HLFMT_HASHCAT;

  u32 *formats_cnt = (u32 *) hccalloc (HLFMTS_CNT, sizeof (u32));

  u32 num_check = 0;

  char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);

  while (!feof (fp))
  {
    const size_t line_len = fgetl (fp, line_buf);

    if (line_len == 0) continue;

    if (hlfmt_detect_pwdump (hashcat_ctx, line_buf, line_len)) formats_cnt[HLFMT_PWDUMP]++;
    if (hlfmt_detect_passwd (hashcat_ctx, line_buf, line_len)) formats_cnt[HLFMT_PASSWD]++;
    if (hlfmt_detect_shadow (hashcat_ctx, line_buf, line_len)) formats_cnt[HLFMT_SHADOW]++;

    if (num_check == max_check) break;

    num_check++;
  }

  hcfree (line_buf);

  u32 hashlist_format = HLFMT_HASHCAT;

  for (u32 i = 1; i < HLFMTS_CNT; i++)
  {
    if (formats_cnt[i - 1] >= formats_cnt[i]) continue;

    hashlist_format = i;
  }

  free (formats_cnt);

  return hashlist_format;
}
예제 #30
0
NAMELIST *read_all(FILE *fin){
  char *seqname=NULL, *seqname2;
  fpos_t position;
  int fileend=1;
  long list_size=MAXLETTER, i=0, length;
  NAMELIST *list;

  list=(NAMELIST *)malloc(list_size*sizeof(NAMELIST));

  fseeko(fin,0,SEEK_SET);
  fgetpos(fin, &position);
  while((seqname=fgetl(fin,&fileend))==NULL || fileend!=0){
    if (seqname[0]=='>'){
      if(i+2>list_size){
  list_size+=MAXLETTER;
	list=(NAMELIST *)realloc(list,list_size*sizeof(NAMELIST));
      }

      /* delete return and white space */
      for(length=strlen(seqname); length >= 0 && isspace(seqname[length]); length--);
      seqname[length+1]='\0';
      length--;

      /*length=strlen(seqname);*/
      /*fprintf(stderr, "seqname: %s//\n", seqname);*/
      seqname2=(char*)malloc(sizeof(char)*(length+2));
      strcpy(seqname2, seqname+1);
      list[i].name=seqname2;
      list[i].fposition=position;
      list[i].from=1;
      list[i].to=length;
      i++;
      list[i].name=NULL;
      /*if(i>1000) break;*/
    }
    if(seqname != NULL) { 
      free(seqname);
      seqname=NULL;
    }
    fgetpos(fin, &position);
  }
  return list;
}