--- ray/src/util/rpiece.c 1993/01/21 17:46:31 2.15 +++ ray/src/util/rpiece.c 1993/05/04 09:30:27 2.20 @@ -1,4 +1,4 @@ -/* Copyright (c) 1992 Regents of the University of California */ +/* Copyright (c) 1993 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -10,6 +10,19 @@ static char SCCSid[] = "$SunId$ LBL"; #include "standard.h" #include + +#ifndef F_SETLKW + +main(argc, argv) +int argc; +char *argv[]; +{ + fprintf(stderr, "%s: no NFS lock manager on this machine\n", argv[0]); + exit(1); +} + +#else + #include #include "color.h" #include "view.h" @@ -26,7 +39,15 @@ static char SCCSid[] = "$SunId$ LBL"; #define MAXFORK 0 #endif #endif - + /* protection from SYSV signals(!) */ +#if defined(sgi) || defined(hpux) +#define guard_io() sighold(SIGALRM) +#define unguard() sigrelse(SIGALRM) +#endif +#ifndef guard_io +#define guard_io() 0 +#define unguard() 0 +#endif /* rpict command */ char *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", "-pa", "1"}; int rpargc = 9; @@ -245,7 +266,7 @@ int *xp, *yp; return(0); } } - sprintf(buf, "%d %d\n%d %d\n", hmult, vmult, *xp, *yp); + sprintf(buf, "%4d %4d\n%4d %4d\n", hmult, vmult, *xp, *yp); lseek(syncfd, 0L, 0); /* write new position */ write(syncfd, buf, strlen(buf)); fls.l_type = F_UNLCK; /* release sync file */ @@ -315,10 +336,6 @@ rpiece() /* render picture piece by piece */ putc('\n', torp); fflush(torp); /* assigns piece to rpict */ putpiece(xorg, yorg); /* place piece in output */ - if (verbose) { /* notify caller */ - printf("%d %d done\n", xorg, yorg); - fflush(stdout); - } } } @@ -338,19 +355,24 @@ int xpos, ypos; exit(cleanup(1)); } /* check header from rpict */ + guard_io(); getheader(fromrp, NULL, NULL); if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) { fprintf(stderr, "%s: resolution mismatch from %s\n", progname, rpargv[0]); exit(cleanup(1)); } + unguard(); /* load new piece into buffer */ - for (y = 0; y < vr; y++) + for (y = 0; y < vr; y++) { + guard_io(); if (freadcolrs(pbuf+y*hr, hr, fromrp) < 0) { fprintf(stderr, "%s: read error from %s\n", progname, rpargv[0]); exit(cleanup(1)); } + unguard(); + } #if MAXFORK /* fork so we don't slow rpict down */ if ((pid = fork()) > 0) { @@ -365,16 +387,17 @@ int xpos, ypos; #else pid = -1; /* no forking */ #endif - fls.l_len = (long)vres*hmult*hres*sizeof(COLR); - fls.l_start = scanorig + (vmult-1-ypos)*fls.l_len; + fls.l_start = scanorig + + ((long)(vmult-1-ypos)*vres*hmult+xpos)*hres*sizeof(COLR); #if NFS + fls.l_len = ((long)(vres-1)*hmult+1)*hres*sizeof(COLR); /* lock file section so NFS doesn't mess up */ fls.l_whence = 0; fls.l_type = F_WRLCK; fcntl(outfd, F_SETLKW, &fls); #endif /* write new piece to file */ - if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1) + if (lseek(outfd, fls.l_start, 0) == -1) goto seekerr; if (hmult == 1) { if (writebuf(outfd, (char *)pbuf, @@ -390,7 +413,11 @@ int xpos, ypos; 1) == -1) goto seekerr; } - if (pid == -1) { /* fork failed */ + if (verbose) { /* notify caller */ + printf("%d %d done\n", xpos, ypos); + fflush(stdout); + } + if (pid == -1) { /* didn't fork or fork failed */ #if NFS fls.l_type = F_UNLCK; /* release lock */ fcntl(outfd, F_SETLKW, &fls); @@ -405,3 +432,5 @@ writerr: fprintf(stderr, "%s: write error on file \"%s\"\n", progname, outfile); _exit(1); } + +#endif