示例#1
0
/************** Output Routines ***************/
void
dumpall(struct application *ap, int depth)
{
    int	i;
    union radrec r;

    if ( depth > numreflect ) {
	bu_log( "dumpall: %d reflections!\n", depth );
    }

    /* Firing record */
    /*printf( "Ray [%d %d], depth = %d\n", ap->a_x, ap->a_y, depth );*/

    memset((char *)&r, 0, sizeof(r));

    /*XXX*/
    r.f.head[0] = 'f'; r.f.head[1] = 'i';
    r.f.head[2] = 'r'; r.f.head[3] = 'e';

    /*
     * Make sure there's enough space in
     * the physical record.
     */
    i = 1 + depth;
    if ( depth < numreflect )
	i++;	/* escape */
    if ( precindex + i > 256 )
	writephysrec( outfp );

    r.f.irf = i-1;			/* num recs in ray, not counting fire */
    r.f.ox = ap->a_ray.r_pt[0];	/* ray origin */
    r.f.oy = ap->a_ray.r_pt[1];
    r.f.oz = ap->a_ray.r_pt[2];
    r.f.h = (ap->a_x - width/2) * viewsize/width;
    r.f.v = (ap->a_y - height/2) * viewsize/height;
    r.f.ih = ap->a_x + 1;		/* Radsim counts from 1 */
    r.f.iv = ap->a_y + 1;
    writerec( &r, outfp );

    for ( i = 0; i < depth; i++ ) {
	dumpray( &rayinfo[i] );
    }

    if ( depth == numreflect )
	return;			/* no escape */

    /* Escape record */
    memset((char *)&r, 0, sizeof(r));

    /*XXX*/
    r.e.head[0] = 'e'; r.e.head[1] = 's';
    r.e.head[2] = 'c'; r.e.head[3] = 'p';

    r.e.sight = -3;			/* XXX line of sight for escape? */
    r.e.dx = rayinfo[depth-1].spec[0];	/* escape direction */
    r.e.dy = rayinfo[depth-1].spec[1];
    r.e.dz = rayinfo[depth-1].spec[2];
    writerec( &r, outfp );
}
示例#2
0
文件: tree.c 项目: ProfessorX/CIS501
void writerec(FILE* fp, node_t* root){
    if(root->split >= 0){
        fprintf(fp,"%d %g ",root->split, root->threshold);
        writerec(fp,root->left);
        writerec(fp,root->right);
    }
    else{
        fprintf(fp,"%d %g %g ",root->split, root->pos, root->neg);
    }
}
示例#3
0
/*
 * Write a header record to the dump tape.
 */
void
writeheader(ino_t ino)
{
	int32_t sum, cnt, *lp;

	if (rsync_friendly >= 2) {
		/* don't track changes to access time */
		spcl.c_atime = spcl.c_mtime;
		spcl.c_atimensec = spcl.c_mtimensec;
	}
	spcl.c_inumber = ino;
	spcl.c_magic = FS_UFS2_MAGIC;
	spcl.c_checksum = 0;
	lp = (int32_t *)&spcl;
	sum = 0;
	cnt = sizeof(union u_spcl) / (4 * sizeof(int32_t));
	while (--cnt >= 0) {
		sum += *lp++;
		sum += *lp++;
		sum += *lp++;
		sum += *lp++;
	}
	spcl.c_checksum = CHECKSUM - sum;
	writerec((char *)&spcl, 1);
}
示例#4
0
int main()
{
	struct stud stu[10];
	readrec(stu);
	writerec(stu);
	return 0;
}
示例#5
0
int main(void)
{
	int n=10;
	struct student stu[10];
	readrec( stu,n);
	writerec( stu,n);
	return 0;
}
示例#6
0
int main(int argc, char *argv[])
{
	link head;
	head = readrec(head, 10);
	writerec(head);
	free(head);
	return 0;
}
示例#7
0
/* beginning of a frame */
void
view_2init(struct application *ap)
{
    extern double azimuth, elevation;
    vect_t temp, aimpt;
    union radrec r;

    if ( numreflect > MAXREFLECT ) {
	bu_log("Warning: maxreflect too large (%d), using %d\n",
	       numreflect, MAXREFLECT );
	numreflect = MAXREFLECT;
    }

    bu_log( "Ray Spacing: %f rays/cm\n", 10.0*(width/viewsize) );

    /* Header Record */
    memset((char *)&r, 0, sizeof(r));

    /*XXX*/
    r.h.head[0] = 'h'; r.h.head[1] = 'e';
    r.h.head[2] = 'a'; r.h.head[3] = 'd';

    r.h.id = 1;
    r.h.iview = 1;
    r.h.miview = - r.h.iview;
    VSET( temp, 0.0, 0.0, -1.414 );	/* Point we are looking at */
    MAT4X3PNT( aimpt, view2model, temp );
    r.h.cx = aimpt[0];		/* aimpoint */
    r.h.cy = aimpt[1];
    r.h.cz = aimpt[2];
    r.h.back = 1.414*viewsize/2.0;	/* backoff */
    r.h.e = elevation;
    r.h.a = azimuth;
    r.h.vert = viewsize;
    r.h.horz = viewsize;
    r.h.nvert = height;
    r.h.nhorz = width;
    r.h.maxrfl = numreflect;

    writerec( &r, outfp );

    /* XXX - write extra header records */
    memset((char *)&r, 0, sizeof(r));
    writerec( &r, outfp );
    writerec( &r, outfp );
}
示例#8
0
int main(int argc, char *argv[])
{
	struct stud arr[N];	

	readrec(arr);
	writerec(arr);

	return 0;
}
示例#9
0
int main(void)
{
	stu st[STULEN];
//	printf("%d\n", sizeof(st));
	writerec(st, sizeof(st)/sizeof(st[0]));
	readrec(st, sizeof(st)/sizeof(st[0]));

	return 0;
}
示例#10
0
/*
 * Dump a map to the tape.
 */
void
dumpmap(const char *map, int type, ufs1_ino_t ino)
{
	int i;
	const char *cp;

	spcl.c_type = type;
	spcl.c_count = howmany(mapsize * sizeof(char), TP_BSIZE);
	writeheader(ino);
	for (i = 0, cp = map; i < spcl.c_count; i++, cp += TP_BSIZE)
		writerec(cp, 0);
}
示例#11
0
int main(void)
{
    struct stud{
        unsigned short id;
        char name[10];
        int s[4];
        double ave;
    }stu[N];
    
    stu[0]->id=100;
    printf("%d\n", stu[0]->id);
#if 0
    readrec(stu);
    writerec(stu);
#endif
    return 0;


}
示例#12
0
/*
 * Write a header record to the dump tape.
 */
void
writeheader(ufs1_ino_t ino)
{
	int32_t sum, cnt, *lp;

	spcl.c_inumber = ino;
	spcl.c_magic = NFS_MAGIC;
	spcl.c_checksum = 0;
	lp = (int32_t *)&spcl;
	sum = 0;
	cnt = sizeof(union u_spcl) / (4 * sizeof(int32_t));
	while (--cnt >= 0) {
		sum += *lp++;
		sum += *lp++;
		sum += *lp++;
		sum += *lp++;
	}
	spcl.c_checksum = CHECKSUM - sum;
	writerec(&spcl, 1);
}
示例#13
0
void
dumpray(struct rayinfo *rp)
{
    union radrec r;

#ifdef DEBUG1
    printf( " visible = %d\n", rp->sight );
    printf( " i = (%f %f %f)\n", rp->ip[0], rp->ip[1], rp->ip[2] );
    printf( " n = (%f %f %f)\n", rp->norm[0], rp->norm[1], rp->norm[2] );
    printf( " p = (%f %f %f)\n", rp->spec[0], rp->spec[1], rp->spec[2] );
#endif

    /* Reflection record */
    memset((char *)&r, 0, sizeof(r));

    /*XXX*/
    r.r.head[0] = 'r'; r.r.head[1] = 'e';
    r.r.head[2] = 'l'; r.r.head[3] = 'f';

    r.r.packedid = 12345;
    r.r.sight = rp->sight;
    r.r.ix = rp->ip[0];		/* intersection */
    r.r.iy = rp->ip[1];
    r.r.iz = rp->ip[2];
    r.r.nx = rp->norm[0];		/* normal */
    r.r.ny = rp->norm[1];
    r.r.nz = rp->norm[2];
    r.r.px = rp->curvature.crv_pdir[0];	/* principle plane */
    r.r.py = rp->curvature.crv_pdir[1];
    r.r.pz = rp->curvature.crv_pdir[2];
    r.r.rc1 = rp->curvature.crv_c1;
    r.r.rc2 = rp->curvature.crv_c2;
    r.r.dfirst = rp->dist;
    r.r.ireg = rp->reg;
    r.r.isol = rp->sol;
    r.r.isurf = rp->surf;

    writerec( &r, outfp );
}
示例#14
0
//main() function
int main(int argc, char *argv[])
{
    student std,std1;

        if(!strcmp(argv[1],"-a")) //'-a(command line argument) is for add a record'
        {
    		    strcpy(std.name,argv[2]);
    		    strcpy(std.usn,argv[3]);
    		    std.db.dd=convert(argv[4]);
    		    std.db.mm=convert(argv[5]);
    		    std.db.yy=convert(argv[6]);
    		 	strcpy(std.adr,argv[7]);
    		 	writerec(std);
        }
        else if(!strcmp(argv[1],"-l"))  //'-l(command line argument) is for list a records'
    	    listrec(std);
    	   		
    	else if(!strcmp(argv[1],"-m")) ////'-m(command line argument) is for modify a particular record' 
    	{
    	        
                strcpy(std1.name,argv[3]);
    		    strcpy(std1.usn,argv[4]);
    		 	std1.db.dd=convert(argv[5]);
    		    std1.db.mm=convert(argv[6]);
    		    std1.db.yy=convert(argv[7]);
    		 	strcpy(std1.adr,argv[8]);
				modifyrec(argv[2],std1);
	    }
    	 else if(!strcmp(argv[1],"-d"))  //'-d(command line argument) is for delete a particular record'

    	    delerec(argv[2]);
    	      
        else if(!strcmp(argv[1],"-s"))  //'-s(command line argument) is for search a  particular record'
    	    Searchrec(argv[2]);
    
    return (0);

}
示例#15
0
/*
 * Dump passes 3 and 4.
 *
 * Dump the contents of an inode to tape.
 */
void
dumpino(struct ufs1_dinode *dp, ufs1_ino_t ino)
{
	int ind_level, cnt;
	fsizeT size;
	char buf[TP_BSIZE];

	if (newtape) {
		newtape = 0;
		dumpmap(dumpinomap, TS_BITS, ino);
	}
	CLRINO(ino, dumpinomap);
	spcl.c_dinode = *dp;
	spcl.c_type = TS_INODE;
	spcl.c_count = 0;
	switch (dp->di_mode & S_IFMT) {

	case 0:
		/*
		 * Freed inode.
		 */
		return;

	case S_IFLNK:
		/*
		 * Check for short symbolic link.
		 */
#ifdef FS_44INODEFMT
		if (dp->di_size > 0 &&
		    dp->di_size < (unsigned)sblock->fs_maxsymlinklen) {
			spcl.c_addr[0] = 1;
			spcl.c_count = 1;
			writeheader(ino);
			memmove(buf, dp->di_shortlink, (u_long)dp->di_size);
			buf[dp->di_size] = '\0';
			writerec(buf, 0);
			return;
		}
#endif
		/* fall through */

	case S_IFDIR:
	case S_IFREG:
		if (dp->di_size > 0)
			break;
		/* fall through */

	case S_IFIFO:
	case S_IFSOCK:
	case S_IFCHR:
	case S_IFBLK:
		writeheader(ino);
		return;

	default:
		msg("Warning: undefined file type 0%o\n", dp->di_mode & IFMT);
		return;
	}
	if (dp->di_size > NDADDR * (unsigned)sblock->fs_bsize)
		cnt = NDADDR * sblock->fs_frag;
	else
		cnt = howmany(dp->di_size, sblock->fs_fsize);
	blksout(&dp->di_db[0], cnt, ino);
	if ((size = dp->di_size - NDADDR * sblock->fs_bsize) <= 0)
		return;
	for (ind_level = 0; ind_level < NIADDR; ind_level++) {
		dmpindir(ino, dp->di_ib[ind_level], ind_level, &size);
		if (size <= 0)
			return;
	}
}
示例#16
0
文件: tree.c 项目: ProfessorX/CIS501
void writeTree(FILE* fp, node_t* t){
    writerec(fp, t);
    fprintf(fp,"\n");
}
示例#17
0
/*
 * Dump passes 3 and 4.
 *
 * Dump the contents of an inode to tape.
 */
void
dumpino(union dinode *dp, ino_t ino)
{
	int ind_level, cnt;
	off_t size;
	char buf[TP_BSIZE];

	if (newtape) {
		newtape = 0;
		dumpmap(dumpinomap, TS_BITS, ino);
	}
	CLRINO(ino, dumpinomap);
	if (sblock->fs_magic == FS_UFS1_MAGIC) {
		spcl.c_mode = dp->dp1.di_mode;
		spcl.c_size = dp->dp1.di_size;
		spcl.c_old_atime = (time_t)dp->dp1.di_atime;
		spcl.c_atime = dp->dp1.di_atime;
		spcl.c_atimensec = dp->dp1.di_atimensec;
		spcl.c_old_mtime = (time_t)dp->dp1.di_mtime;
		spcl.c_mtime = dp->dp1.di_mtime;
		spcl.c_mtimensec = dp->dp1.di_mtimensec;
		spcl.c_birthtime = 0;
		spcl.c_birthtimensec = 0;
		spcl.c_rdev = dp->dp1.di_rdev;
		spcl.c_file_flags = dp->dp1.di_flags;
		spcl.c_uid = dp->dp1.di_uid;
		spcl.c_gid = dp->dp1.di_gid;
	} else {
		spcl.c_mode = dp->dp2.di_mode;
		spcl.c_size = dp->dp2.di_size;
		spcl.c_atime = dp->dp2.di_atime;
		spcl.c_atimensec = dp->dp2.di_atimensec;
		spcl.c_mtime = dp->dp2.di_mtime;
		spcl.c_mtimensec = dp->dp2.di_mtimensec;
		spcl.c_birthtime = dp->dp2.di_birthtime;
		spcl.c_birthtimensec = dp->dp2.di_birthnsec;
		spcl.c_rdev = dp->dp2.di_rdev;
		spcl.c_file_flags = dp->dp2.di_flags;
		spcl.c_uid = dp->dp2.di_uid;
		spcl.c_gid = dp->dp2.di_gid;
	}
	spcl.c_type = TS_INODE;
	spcl.c_count = 0;
	switch (DIP(dp, di_mode) & S_IFMT) {

	case 0:
		/*
		 * Freed inode.
		 */
		return;

	case IFLNK:
		/*
		 * Check for short symbolic link.
		 */
		if (DIP(dp, di_size) > 0 &&
#ifdef FS_44INODEFMT
		    (DIP(dp, di_size) < sblock->fs_maxsymlinklen ||
		     (sblock->fs_maxsymlinklen == 0 &&
			 DIP(dp, di_blocks) == 0))) {
#else
		    DIP(dp, di_blocks) == 0) {
#endif
			void *shortlink;

			spcl.c_addr[0] = 1;
			spcl.c_count = 1;
			writeheader(ino);
			if (sblock->fs_magic == FS_UFS1_MAGIC)
				shortlink = dp->dp1.di_shortlink;
			else
				shortlink = dp->dp2.di_shortlink;
			memcpy(buf, shortlink, DIP(dp, di_size));
			buf[DIP(dp, di_size)] = '\0';
			writerec(buf, 0);
			return;
		}
		/* FALLTHROUGH */

	case IFDIR:
	case IFREG:
		if (DIP(dp, di_size) > 0)
			break;
		/* FALLTHROUGH */

	case IFIFO:
	case IFSOCK:
	case IFCHR:
	case IFBLK:
		writeheader(ino);
		return;

	default:
		msg("Warning: undefined file type 0%o\n",
		    DIP(dp, di_mode) & IFMT);
		return;
	}
	if (DIP(dp, di_size) > NDADDR * sblock->fs_bsize)
		cnt = NDADDR * sblock->fs_frag;
	else
		cnt = howmany(DIP(dp, di_size), sblock->fs_fsize);
	if (sblock->fs_magic == FS_UFS1_MAGIC)
		ufs1_blksout(&dp->dp1.di_db[0], cnt, ino);
	else
		ufs2_blksout(&dp->dp2.di_db[0], cnt, ino);
	if ((size = DIP(dp, di_size) - NDADDR * sblock->fs_bsize) <= 0)
		return;
	for (ind_level = 0; ind_level < NIADDR; ind_level++) {
		dmpindir(ino, DIP(dp, di_ib[ind_level]), ind_level, &size);
		if (size <= 0)
			return;
	}
}
示例#18
0
/*
 * Dump passes 3 and 4.
 *
 * Dump the contents of an inode to tape.
 */
void
dumpino(union dinode *dp, ino_t ino)
{
	int ind_level, cnt, last, added;
	off_t size;
	char buf[TP_BSIZE];

	if (newtape) {
		newtape = 0;
		dumpmap(dumpinomap, TS_BITS, ino);
	}
	CLRINO(ino, dumpinomap);
	/*
	 * Zero out the size of a snapshot so that it will be dumped
	 * as a zero length file.
	 */
	if ((DIP(dp, di_flags) & SF_SNAPSHOT) != 0) {
		DIP_SET(dp, di_size, 0);
		DIP_SET(dp, di_flags, DIP(dp, di_flags) & ~SF_SNAPSHOT);
	}
	if (sblock->fs_magic == FS_UFS1_MAGIC) {
		spcl.c_mode = dp->dp1.di_mode;
		spcl.c_size = dp->dp1.di_size;
		spcl.c_extsize = 0;
		spcl.c_atime = _time32_to_time(dp->dp1.di_atime);
		spcl.c_atimensec = dp->dp1.di_atimensec;
		spcl.c_mtime = _time32_to_time(dp->dp1.di_mtime);
		spcl.c_mtimensec = dp->dp1.di_mtimensec;
		spcl.c_birthtime = 0;
		spcl.c_birthtimensec = 0;
		spcl.c_rdev = dp->dp1.di_rdev;
		spcl.c_file_flags = dp->dp1.di_flags;
		spcl.c_uid = dp->dp1.di_uid;
		spcl.c_gid = dp->dp1.di_gid;
	} else {
		spcl.c_mode = dp->dp2.di_mode;
		spcl.c_size = dp->dp2.di_size;
		spcl.c_extsize = dp->dp2.di_extsize;
		spcl.c_atime = _time64_to_time(dp->dp2.di_atime);
		spcl.c_atimensec = dp->dp2.di_atimensec;
		spcl.c_mtime = _time64_to_time(dp->dp2.di_mtime);
		spcl.c_mtimensec = dp->dp2.di_mtimensec;
		spcl.c_birthtime = _time64_to_time(dp->dp2.di_birthtime);
		spcl.c_birthtimensec = dp->dp2.di_birthnsec;
		spcl.c_rdev = dp->dp2.di_rdev;
		spcl.c_file_flags = dp->dp2.di_flags;
		spcl.c_uid = dp->dp2.di_uid;
		spcl.c_gid = dp->dp2.di_gid;
	}
	spcl.c_type = TS_INODE;
	spcl.c_count = 0;
	switch (DIP(dp, di_mode) & S_IFMT) {

	case 0:
		/*
		 * Freed inode.
		 */
		return;

	case S_IFLNK:
		/*
		 * Check for short symbolic link.
		 */
		if (DIP(dp, di_size) > 0 &&
		    DIP(dp, di_size) < sblock->fs_maxsymlinklen) {
			spcl.c_addr[0] = 1;
			spcl.c_count = 1;
			added = appendextdata(dp);
			writeheader(ino);
			if (sblock->fs_magic == FS_UFS1_MAGIC)
				memmove(buf, (caddr_t)dp->dp1.di_db,
				    (u_long)DIP(dp, di_size));
			else
				memmove(buf, (caddr_t)dp->dp2.di_db,
				    (u_long)DIP(dp, di_size));
			buf[DIP(dp, di_size)] = '\0';
			writerec(buf, 0);
			writeextdata(dp, ino, added);
			return;
		}
		/* FALLTHROUGH */

	case S_IFDIR:
	case S_IFREG:
		if (DIP(dp, di_size) > 0)
			break;
		/* FALLTHROUGH */

	case S_IFIFO:
	case S_IFSOCK:
	case S_IFCHR:
	case S_IFBLK:
		added = appendextdata(dp);
		writeheader(ino);
		writeextdata(dp, ino, added);
		return;

	default:
		msg("Warning: undefined file type 0%o\n",
		    DIP(dp, di_mode) & IFMT);
		return;
	}
	if (DIP(dp, di_size) > NDADDR * sblock->fs_bsize) {
		cnt = NDADDR * sblock->fs_frag;
		last = 0;
	} else {
		cnt = howmany(DIP(dp, di_size), sblock->fs_fsize);
		last = 1;
	}
	if (sblock->fs_magic == FS_UFS1_MAGIC)
		ufs1_blksout(&dp->dp1.di_db[0], cnt, ino);
	else
		ufs2_blksout(dp, &dp->dp2.di_db[0], cnt, ino, last);
	if ((size = DIP(dp, di_size) - NDADDR * sblock->fs_bsize) <= 0)
		return;
	for (ind_level = 0; ind_level < NIADDR; ind_level++) {
		dmpindir(dp, ino, DIP(dp, di_ib[ind_level]), ind_level, &size);
		if (size <= 0)
			return;
	}
}