Esempio n. 1
0
void get8SVX(int file,ULONG size, struct svx_info *info)
{
  while ((size-=getCk(file, info)) >0)
    ;
  if (size < 0)
    readerror ("Decrepit input in form 8SVX: size incorrect", info);
  if (isodd(size))
    skip1(file);
}
Esempio n. 2
0
void addANNO(char *anote,struct svx_info *info,int len)
{
  static struct anno *cur_anno;        
       
  if (info->anno == NULL)
  {
    if ((info->anno = (struct anno *)AllocMem(sizeof(struct anno),0)) == 0)
      readerror("Out of memory", info);
    
    cur_anno = info->anno;
  }
  else
  {
    if ((cur_anno->next = (struct anno *)AllocMem(sizeof(struct anno),0))
               == 0)
      readerror("Out of memory", info);

    cur_anno = cur_anno->next; 
  }
  cur_anno->text = anote;
  cur_anno->next = NULL;
  cur_anno->len  = len;
}
Esempio n. 3
0
ULONG getCk(int file, struct svx_info *info)
{
  ULONG ckID, ckSize;
  UBYTE *ckData;

  ckID = getID(file);
  printf("");
  ckSize = getID(file);
  if ((ckData = (UBYTE *)AllocMem(ckSize+1,MEMF_CHIP)) == 0)
    readerror("Out of memory: getCk", info);
  else
  {
    read(file,ckData,ckSize);
    ckData [ckSize] = 0;
    IFFRet(ckID,ckData,ckSize,info);
    if (isodd(ckSize))
      skip1(file);
  }
  return ckSize;
}
Esempio n. 4
0
File: main.c Progetto: mariuz/haiku
/*-------------------------------------------------------------------------*/
static int
readfiles (void)

/* Read and analyse all files.
 * If a file can't be read, print a message.
 * Return 0 if all went well, RETURN_WARN if one of the files could not be
 * found, RETURN_ERROR if one of the files could not be read properly.
 */

{
    int           rc;       /* Return value */
    Node        * pNode;    /* Node of the file under examination */
    int           srcRead;  /* Number of source files read */
    const char  * pName;    /* Includefile name returned by reader */

    rc = 0;
    srcRead = 0;

    while (NULL != (pNode = nodes_todo()) )
    {
        int bSystem; /* TRUE if it's a <> include */

        if (pNode->flags & NODE_NOTFND)
            continue;

        if (!reader_open(pNode->pName))
        {
            rc = readerror(pNode, rc, FALSE);
            continue;
        } /* If (can't open pNode->pName) */

        if (bVerbose)
        {
            printf(" reading %-65s\r", pNode->pName); fflush(stdout);
        }

        while (NULL != (pName = reader_get(&bSystem)) )
        {
            int    index;    /* index into aIncl[] */
            Node * pChild;   /* Node of included file, NULL if not found */
            Node * pChFirst; /* First 'direct' child node */

            for (index = -1, pChild = NULL, pChFirst = NULL
                ; !pChild && index < iInclSize
                ; index++)
            {
                char aName[FILENAME_MAX+1];
                char * pCName;  /* aName[] cleaned up */
                char * pCBase;  /* Namepart in *pCName */

                /* Don't look for system includes in non-system directories. */
                if (index >= 0 && bSplitPath && bSystem && !aIncl[index].bSysPath)
                    continue;

                aName[FILENAME_MAX] = '\0';

                if (index < 0)
                {
                    /* Special case: look directly for the filename.
                     * If bSplitPath is given, or if the filename is absolute,
                     * use it unchanged. Else, use the path of the including
                     * file as anchor.
                     */

                    if (bSplitPath || '/' == *pName)
                        strcpy(aName, pName);
                    else
                    {
                        size_t oFilename;

                        oFilename = (unsigned)(pNode->pBase - pNode->pName);
                        strncpy(aName, pNode->pName, oFilename);
                        strcpy(aName+oFilename, pName);
                    }
                }
                else
                {
                    /* Standard case: build the pathname from the include
                     * pathname.
                     */

                    strcpy(aName, aIncl[index].pPath);
                    strcat(aName, pName);
                }

                /* Cleanup the filename and check if it is listed in
                 * the tree
                 */
                pCName = util_getpath(aName, &pCBase);
                if (!pCName)
                {
                    if (bVerbose)
                        printf("%-78s\r", "");
                    reader_close();
                    exit_nomem(" (readfiles: 1. util_getpath)");
                }

                pChild = nodes_findadd(pCName, TRUE);

                if (pChild->flags & NODE_NEW)
                {
                    /* New file: check if it exists and set up the
                     * node properly
                     */

                    struct stat aStat;

                    pChild->pName = pCName;
                    pChild->pBase = pCBase;

                    if (index >= 0)
                    {
                        pChild->pPath = util_getpath(pName, NULL);
                        pChild->iInclude = index;
                    }
                    else if (pNode->iInclude < 0 || pNode->flags & NODE_SOURCE)
                    {
                        pChild->pPath = util_getpath(pCName, NULL);
                        pChild->iInclude = -1;
                    }
                    else
                    {
                        strcpy(aName, pNode->pPath);
                        strcat(aName, pName);
                        pChild->pPath = util_getpath(aName, NULL);
                        pChild->iInclude = pNode->iInclude;
                    }
                    if (!pChild->pPath)
                    {
                        if (bVerbose)
                            printf("%-78s\r", "");
                        reader_close();
                        exit_nomem(" (readfiles: 2. util_getpath)");
                    }

                    pChild->flags = (short)(bSystem ? NODE_SYSTEM : 0);

                    /* It's ok to not find <>-includes - they just don't have
                     * to appear in the output then.
                     */
                    if (stat(pCName, &aStat))
                        pChild->flags |= NODE_NOTFND | (bSystem ? NODE_IGNORE : 0);
                }

                /* The pChFirst is needed if the include can't be found
                 * so we can keep track from where it is included.
                 */
                if (index < 0)
                    pChFirst = pChild;

                /* Test if the file for pChild exists.
                 */
                if (pChild->flags & NODE_NOTFND)
                {
                    /* Make sure that the file is listed in the warnings
                     * if appropriate.
                     */
                    if (index >= 0)
                        pChild->flags |= NODE_IGNORE;
                    else if ((pChild->flags & NODE_IGNORE) && !bSystem)
                        pChild->flags ^= NODE_IGNORE;
                    pChild = NULL;
                }
                
                /* For absolute pNames, only index -1 is tried */
                if ('/' == *pName)
                    break;
            } /* for (index = -1..iInclSize) */

            assert(pChFirst != NULL);

            if (pChild ? nodes_depend(pChild, pNode) 
                       : nodes_depend(pChFirst, pNode))
            {
                if (bVerbose)
                    printf("%-78s\r", "");
                reader_close();
                exit_nomem(" (readfiles: nodes_depend)");
            }
        } /* while(get pName from file */

        if (bVerbose)
            printf("%-78s\r", "");
        if (!reader_eof() || reader_close())
        {
            perror(aPgmName);
            printf("%s: Error reading '%s'\n", aPgmName, pNode->pName);
            rc = RETURN_ERROR;
        }
        else if (pNode->flags & NODE_SOURCE)
        {
            srcRead++;
        }
    } /* while (nodes_todo()) */

    if (!srcRead)
    {
        printf("%s: No source file read.\n", aPgmName);
        rc = RETURN_ERROR;
    }

    /* Walk tree and print all include files not found */
    nodes_initwalk();
    while (rc != RETURN_ERROR && NULL != (pNode = nodes_inorder()) )
    {
        if ((pNode->flags & (NODE_NOTFND|NODE_IGNORE)) == NODE_NOTFND)
        {
            if (pNode->pUsers)
                rc = readerror(pNode, rc, TRUE);
            else
                pNode->flags |= NODE_IGNORE;
        }
    }

    if (bVerbose)
        fflush(stdout);

    return rc;
}
Esempio n. 5
0
int main(int argc, char **argv) {
    char buf[nbuf],buf2[512],buf3[512],buf4[512];
    FILE *inp,*out;
    int i,j,k,natoms,nx,ny,nz,nx1,ny1,nz1,counter;

    if(argc!=3) {
	fprintf(stderr, "usage: %s in.cube out.cube\n", argv[0]);
	return 1;
    }
    
    inp = fopen(argv[1], "r");
    if(!inp) {
	fprintf(stderr, "cannot open cube input file %s for reading.\n", argv[1]);
	return 2;
    }

    out = fopen(argv[2], "w");
    if(!out) {
	fprintf(stderr, "cannot open cube output file %s for writing.\n", argv[2]);
	return 3;
    }
    
    for(i=0;i<3;i++) {
	if(!fgets(buf, nbuf, inp)) readerror(argv[1]);
	fputs(buf, out);
    }

    sscanf(buf, "%d", &natoms);
    
    if(!fgets(buf, nbuf, inp)) readerror(argv[1]);
    sscanf(buf, "%d%512s%512s%512s", &nx, buf2, buf3, buf4);
    fprintf(out, " %d %s %s %s\n", nx-1, buf2, buf3, buf4);
    
    if(!fgets(buf, nbuf, inp)) readerror(argv[1]);
    sscanf(buf, "%d%512s%512s%512s", &ny, buf2, buf3, buf4);
    fprintf(out, " %d %s %s %s\n", ny-1, buf2, buf3, buf4);
    
    if(!fgets(buf, nbuf, inp)) readerror(argv[1]);
    sscanf(buf, "%d%512s%512s%512s", &nz, buf2, buf3, buf4);
    fprintf(out, " %d %s %s %s\n", nz-1, buf2, buf3, buf4);

    for(i=0;i<natoms;i++) {
	if(!fgets(buf, nbuf, inp)) readerror(argv[1]);
	fputs(buf, out);
    }
    
    counter = 0;
    nx1 = nx-1;
    ny1 = ny-1;
    nz1 = nz-1;
    for(i=0;i<nx;i++) {
	for(j=0;j<ny;j++) {
	    for(k=0;k<nz;k++) {
		fscanf(inp, "%512s", buf2);
		if(i!=nx1 && j!=ny1 && k!= nz1) {
		    fprintf(out, " %s", buf2);
		}
		counter++;
		if(counter==6) {
		    fputs("\n", out);
		    counter = 0;
		}
	    }
	    if(counter!=0) {
		fputs("\n", out);
		counter = 0;
	    }
	}
    }

    fclose(out);
    fclose(inp);
    
    return 0;
}
Esempio n. 6
0
int StatUtil::read_data(char* filename)
{
	unsigned long missings = 0;
	double t;

	std::ifstream ifs(filename);
	if( !ifs ) {
		std::cerr << "データファイルが読めません" << std::endl;
		return 999;
	}
	
	std::string buf, strrow, strcol;
	char *rest;
	
	getline(ifs, buf);
	std::istringstream stream(buf);
	getline(stream, strrow, ',' );
	getline(stream, strcol);
	rows = atoi(strrow.c_str());
	cols = atoi(strcol.c_str());
	if (rows <= 0 || rows > INT_MAX || cols <= 0 || cols > INT_MAX) {
		std::cerr << "行数・列数が読めません" << std::endl;
		return 999;
	}
	Matrix tmp(rows, cols);
	
	std::string str;
	int r = 0;
	int c = 0;
	int err = 0;
	while( getline( ifs, str ) ){
		std::string token;
		std::stringstream ss, ss2;
		std::istringstream stream( str );
		c = 0;
 
		while( getline( stream, token, ',' ) ) {
		
			if (err) {  
				tmp(r, c)= READERROR;
				c++;
				continue;  
			}
			t = strtod(token.c_str(), &rest);
			if (errno == 0 && *rest == '\0' && fabs(t) <= 0.97E+37) {
				tmp(r, c) = t;
			} else if (readerror(t)){
				tmp(r, c) = READERROR;
				std::cerr << "読込みエラー" << r + 1 << "," << c + 1 << std::endl;
				err = 2;
			} else {
				tmp(r, c) = MISSING;
				missings++;
			}
			c++;
			if (c > cols) {
				std::cerr << (r + 1) << "行目は列数オーバーです" << std::endl;
				break;
			}
		}
		if (c < cols) {
			std::cerr << (r + 1) << "行目は列数不足" << std::endl;
			for (int i = c; i < cols; i++) {
				tmp(r, i) = READERROR;
				missings++;
			}
		}
		r++;
		if (r > rows) {
			std::cerr <<  "行数オーバーです" << std::endl;
			break;
		}
	}
	if (r < rows) {
		std::cerr <<  "行数不足" << std::endl;
		for (int i = r; i < rows; i++) {
			for (int j = 0; j < cols; j++) {
				tmp(i, j) = READERROR;
				missings++;
			}
		}
	}
	
	mat = tmp;
	std::cerr <<  "読込み終了 (欠測値 " << missings << " 個)" << std::endl;
	return err | (missings != 0);
}
Esempio n. 7
0
static void
readunits(const char *userfile)
{
	FILE *unitfile;
	char line[80], *lineptr;
	int len, linenum, i, isdup;

	unitcount = 0;
	linenum = 0;

	if (userfile) {
		unitfile = fopen(userfile, "rt");
		if (!unitfile)
			err(1, "Unable to open units file '%s'", userfile);
	}
	else {
		unitfile = fopen(UNITSFILE, "rt");
		if (!unitfile) {
			char *direc, *env;
			char filename[1000];
			char separator[2];

			env = getenv("PATH");
			if (env) {
				if (strchr(env, ';'))
					strlcpy(separator, ";",
					    sizeof(separator));
				else
					strlcpy(separator, ":",
					    sizeof(separator));
				direc = strtok(env, separator);
				while (direc) {
					strlcpy(filename, "", sizeof(filename));
					strlcat(filename, direc,
					    sizeof(filename));
					strlcat(filename, "/",
					    sizeof(filename));
					strlcat(filename, UNITSFILE,
					    sizeof(filename));
					unitfile = fopen(filename, "rt");
					if (unitfile)
						break;
					direc = strtok(NULL, separator);
				}
			}
			if (!unitfile)
				errx(1, "Can't find units file '%s'",
				    UNITSFILE);
		}
	}
	while (!feof(unitfile)) {
		if (!fgets(line, 79, unitfile))
			break;
		linenum++;
		lineptr = line;
		if (*lineptr == '/')
			continue;
		lineptr += strspn(lineptr, " \n\t");
		len = strcspn(lineptr, " \n\t");
		lineptr[len] = 0;
		if (!strlen(lineptr))
			continue;
		if (lineptr[strlen(lineptr) - 1] == '-') { /* it's a prefix */
			if (prefixcount == MAXPREFIXES) {
				mywarnx(
			"Memory for prefixes exceeded in line %d",
					linenum);
				continue;
			}
			lineptr[strlen(lineptr) - 1] = 0;
			for (isdup = 0, i = 0; i < prefixcount; i++) {
				if (!strcmp(prefixtable[i].prefixname,
				    lineptr)) {
					isdup = 1;
					break;
				}
			}
			if (isdup) {
				mywarnx(
			"Redefinition of prefix '%s' on line %d ignored",
				    lineptr, linenum);
				continue;
			}
			prefixtable[prefixcount].prefixname = dupstr(lineptr);
			lineptr += len + 1;
			if (!strlen(lineptr)) {
				readerror(linenum);
				continue;
			}
			lineptr += strspn(lineptr, " \n\t");
			len = strcspn(lineptr, "\n\t");
			lineptr[len] = 0;
			prefixtable[prefixcount++].prefixval = dupstr(lineptr);
		}
		else {		/* it's not a prefix */
			if (unitcount == MAXUNITS) {
				mywarnx("Memory for units exceeded in line %d",
				    linenum);
				continue;
			}
			for (isdup = 0, i = 0; i < unitcount; i++) {
				if (!strcmp(unittable[i].uname, lineptr)) {
					isdup = 1;
					break;
				}
			}
			if (isdup) {
				mywarnx(
				"Redefinition of unit '%s' on line %d ignored",
				    lineptr, linenum);
				continue;
			}
			unittable[unitcount].uname = dupstr(lineptr);
			lineptr += len + 1;
			lineptr += strspn(lineptr, " \n\t");
			if (!strlen(lineptr)) {
				readerror(linenum);
				continue;
			}
			len = strcspn(lineptr, "\n\t");
			lineptr[len] = 0;
			unittable[unitcount++].uval = dupstr(lineptr);
		}
	}
	fclose(unitfile);
}
Esempio n. 8
0
/*
 * Perform a read to flush the buffer.
 */
void fl_read( void )
{
        int             err;            /* Result from system call */
        int             left;           /* Bytes left */
        char           *more;           /* Pointer to next byte to read */

        /*
         * Clear the count of errors.  This only applies to a single call to
         * fl_read.  We leave read_error_flag alone; it is only turned off by
         * higher level software.
         */
        r_error_count = 0;                      /* Clear error count */

        /*
         * If we are about to wipe out a record that somebody needs to keep, copy
         * it out to a holding area and adjust somebody's pointer to it.
         */
        if (save_rec &&
                *save_rec >= ar_record &&
                *save_rec < ar_last)
        {
                record_save_area = **save_rec;
                *save_rec = &record_save_area;
        }
error_loop:
#if defined(MSDOS) && !defined(__NO_PHYS__)
        if (f_phys)
                err = physread(ar_block->charptr, blocksize);
        else
#endif
                err = read(archive, ar_block->charptr, blocksize);
        if (err == blocksize)
                return;
        if (err < 0)
        {
                readerror();
                goto error_loop;                /* Try again */
        }

        more = ar_block->charptr + err;
        left = blocksize - err;

#ifndef MSDOS
        if (baserec != 0)       /* multi-volume support on read -- JER */
        {
                uprintf(ftty,"\ntar: End of volume.  Change volumes and press [Enter]: ");
                while (ugetc(ftty) != '\n') ;
                lseek(archive, 0L, 0);
                goto error_loop_2;
        }
#endif

again:
        if (0 == (((unsigned) left) % RECORDSIZE))
        {
                /* FIXME, for size=0, multi vol support */
                /* On the first block, warn about the problem */
                if (!f_reblock && baserec == 0 && f_verbose)
                {
                        annorec(stderr, tar);
                        fprintf(stderr, "Blocksize = %d records\n",
                                err / RECORDSIZE);
                }
                ar_last = ar_block + ((unsigned) (blocksize - left)) / RECORDSIZE;
                return;
        }
        if (f_reblock)
        {

                /*
                 * User warned us about this.  Fix up.
                 */
                if (left > 0)
                {
        error_loop_2:
#if defined(MSDOS) && !defined(__NO_PHYS__)
                        if (f_phys)
                                err = physread(more, left);
                        else
#endif
                                err = read(archive, more, left);
                        if (err < 0)
                        {
                                readerror();
                                goto error_loop_2;              /* Try again */
                        }
                        if (err == 0)
                        {
                                annorec(stderr, tar);
                                fprintf(stderr,
                                        "%s: eof not on block boundary, strange...\n",
                                        ar_file);
                                exit(EX_BADARCH);
                        }
                        left -= err;
                        more += err;
                        goto again;
                }
        }
        else
        {
                annorec(stderr, tar);
                fprintf(stderr, "%s: read %d bytes, strange...\n",
                        ar_file, err);
                exit(EX_BADARCH);
        }
}