| 16 | 
  | 
 | 
| 17 | 
  | 
#include "color.h" | 
| 18 | 
  | 
 | 
| 19 | 
+ | 
#include  "resolu.h" | 
| 20 | 
+ | 
 | 
| 21 | 
  | 
#include "calcomp.h" | 
| 22 | 
  | 
 | 
| 23 | 
  | 
#define MAXINP          32              /* maximum number of input files */ | 
| 24 | 
  | 
#define WINSIZ          9               /* scanline window size */ | 
| 25 | 
  | 
#define MIDSCN          4               /* current scan position */ | 
| 26 | 
  | 
 | 
| 25 | 
– | 
#define BRT             (-1)            /* special index for brightness */ | 
| 26 | 
– | 
 | 
| 27 | 
  | 
struct { | 
| 28 | 
< | 
        char    *name;          /* file name */ | 
| 28 | 
> | 
        char    *name;          /* file or command name */ | 
| 29 | 
  | 
        FILE    *fp;            /* stream pointer */ | 
| 30 | 
  | 
        COLOR   *scan[WINSIZ];  /* input scanline window */ | 
| 31 | 
  | 
        COLOR   coef;           /* coefficient */ | 
| 34 | 
  | 
 | 
| 35 | 
  | 
int     nfiles;                         /* number of input files */ | 
| 36 | 
  | 
 | 
| 37 | 
< | 
char    *vcolin[3] = {"ri", "gi", "bi"}; | 
| 38 | 
< | 
char    *vcolout[3] = {"ro", "go", "bo"}; | 
| 37 | 
> | 
char    vcolin[3][4] = {"ri", "gi", "bi"}; | 
| 38 | 
> | 
char    vcolout[3][4] = {"ro", "go", "bo"}; | 
| 39 | 
  | 
char    vbrtin[] = "li"; | 
| 40 | 
  | 
char    vbrtout[] = "lo"; | 
| 41 | 
< | 
char    *vcolexp[3] = {"re", "ge", "be"}; | 
| 41 | 
> | 
char    vcolexp[3][4] = {"re", "ge", "be"}; | 
| 42 | 
  | 
char    vbrtexp[] = "le"; | 
| 43 | 
  | 
 | 
| 44 | 
< | 
#define vnfiles         "nfiles" | 
| 45 | 
< | 
#define vxres           "xres" | 
| 46 | 
< | 
#define vyres           "yres" | 
| 47 | 
< | 
#define vxpos           "x" | 
| 48 | 
< | 
#define vypos           "y" | 
| 44 | 
> | 
char    vnfiles[] = "nfiles"; | 
| 45 | 
> | 
char    vxmax[] = "xmax"; | 
| 46 | 
> | 
char    vymax[] = "ymax"; | 
| 47 | 
> | 
char    vxres[] = "xres"; | 
| 48 | 
> | 
char    vyres[] = "yres"; | 
| 49 | 
> | 
char    vxpos[] = "x"; | 
| 50 | 
> | 
char    vypos[] = "y"; | 
| 51 | 
  | 
 | 
| 52 | 
  | 
int     nowarn = 0;                     /* no warning messages? */ | 
| 53 | 
  | 
 | 
| 54 | 
< | 
int     original = 0;                   /* origninal values? */ | 
| 54 | 
> | 
int     xmax = 0, ymax = 0;             /* input resolution */ | 
| 55 | 
  | 
 | 
| 56 | 
< | 
int     xres=0, yres=0;                 /* picture resolution */ | 
| 56 | 
> | 
int     xscan, yscan;                   /* input position */ | 
| 57 | 
  | 
 | 
| 58 | 
< | 
int     xpos, ypos;                     /* picture position */ | 
| 58 | 
> | 
int     xres, yres;                     /* output resolution */ | 
| 59 | 
  | 
 | 
| 60 | 
+ | 
int     xpos, ypos;                     /* output position */ | 
| 61 | 
+ | 
 | 
| 62 | 
  | 
int     wrongformat = 0; | 
| 63 | 
  | 
 | 
| 64 | 
+ | 
FILE    *popen(); | 
| 65 | 
  | 
 | 
| 66 | 
+ | 
 | 
| 67 | 
  | 
main(argc, argv) | 
| 68 | 
  | 
int     argc; | 
| 69 | 
  | 
char    *argv[]; | 
| 70 | 
  | 
{ | 
| 71 | 
+ | 
        int     original; | 
| 72 | 
  | 
        double  f; | 
| 73 | 
  | 
        int     a, i; | 
| 74 | 
  | 
                                                /* scan options */ | 
| 76 | 
  | 
                if (argv[a][0] == '-') | 
| 77 | 
  | 
                        switch (argv[a][1]) { | 
| 78 | 
  | 
                        case 'x': | 
| 72 | 
– | 
                                xres = atoi(argv[++a]); | 
| 73 | 
– | 
                                continue; | 
| 79 | 
  | 
                        case 'y': | 
| 80 | 
< | 
                                yres = atoi(argv[++a]); | 
| 80 | 
> | 
                                a++; | 
| 81 | 
  | 
                                continue; | 
| 82 | 
  | 
                        case 'w': | 
| 83 | 
  | 
                                nowarn = !nowarn; | 
| 95 | 
  | 
                setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); | 
| 96 | 
  | 
        } | 
| 97 | 
  | 
        nfiles = 0; | 
| 98 | 
+ | 
        original = 0; | 
| 99 | 
  | 
        for ( ; a < argc; a++) { | 
| 100 | 
  | 
                if (nfiles >= MAXINP) { | 
| 101 | 
  | 
                        eputs(argv[0]); | 
| 110 | 
  | 
                                break; | 
| 111 | 
  | 
                        case 'o': | 
| 112 | 
  | 
                                original++; | 
| 113 | 
< | 
                                break; | 
| 113 | 
> | 
                                continue; | 
| 114 | 
  | 
                        case 's': | 
| 115 | 
  | 
                                f = atof(argv[++a]); | 
| 116 | 
  | 
                                scalecolor(input[nfiles].coef, f); | 
| 124 | 
  | 
                                goto usage; | 
| 125 | 
  | 
                        } | 
| 126 | 
  | 
                else { | 
| 127 | 
< | 
                        input[nfiles].name = argv[a]; | 
| 128 | 
< | 
                        input[nfiles].fp = fopen(argv[a], "r"); | 
| 127 | 
> | 
                        if (argv[a][0] == '!') { | 
| 128 | 
> | 
                                input[nfiles].name = "<Command>"; | 
| 129 | 
> | 
                                input[nfiles].fp = popen(argv[a]+1, "r"); | 
| 130 | 
> | 
                        } else { | 
| 131 | 
> | 
                                input[nfiles].name = argv[a]; | 
| 132 | 
> | 
                                input[nfiles].fp = fopen(argv[a], "r"); | 
| 133 | 
> | 
                        } | 
| 134 | 
  | 
                        if (input[nfiles].fp == NULL) { | 
| 135 | 
  | 
                                perror(argv[a]); | 
| 136 | 
  | 
                                quit(1); | 
| 137 | 
  | 
                        } | 
| 138 | 
  | 
                } | 
| 139 | 
  | 
                checkfile(); | 
| 140 | 
< | 
                original = 0; | 
| 140 | 
> | 
                if (original) { | 
| 141 | 
> | 
                        colval(input[nfiles].coef,RED) /= | 
| 142 | 
> | 
                                        colval(input[nfiles].expos,RED); | 
| 143 | 
> | 
                        colval(input[nfiles].coef,GRN) /= | 
| 144 | 
> | 
                                        colval(input[nfiles].expos,GRN); | 
| 145 | 
> | 
                        colval(input[nfiles].coef,BLU) /= | 
| 146 | 
> | 
                                        colval(input[nfiles].expos,BLU); | 
| 147 | 
> | 
                } | 
| 148 | 
  | 
                nfiles++; | 
| 149 | 
+ | 
                original = 0; | 
| 150 | 
  | 
        } | 
| 151 | 
< | 
        init();                         /* set constant expressions */ | 
| 151 | 
> | 
        init();                         /* set constants */ | 
| 152 | 
  | 
                                        /* go back and get expressions */ | 
| 153 | 
  | 
        for (a = 1; a < argc; a++) { | 
| 154 | 
  | 
                if (argv[a][0] == '-') | 
| 155 | 
  | 
                        switch (argv[a][1]) { | 
| 156 | 
  | 
                        case 'x': | 
| 157 | 
+ | 
                                varset(vxres, ':', eval(argv[++a])); | 
| 158 | 
+ | 
                                continue; | 
| 159 | 
  | 
                        case 'y': | 
| 160 | 
< | 
                                a++; | 
| 160 | 
> | 
                                varset(vyres, ':', eval(argv[++a])); | 
| 161 | 
  | 
                                continue; | 
| 162 | 
  | 
                        case 'w': | 
| 163 | 
  | 
                                continue; | 
| 170 | 
  | 
                        } | 
| 171 | 
  | 
                break; | 
| 172 | 
  | 
        } | 
| 173 | 
+ | 
                                                /* set/get output resolution */ | 
| 174 | 
+ | 
        if (!vardefined(vxres)) | 
| 175 | 
+ | 
                varset(vxres, ':', (double)xmax); | 
| 176 | 
+ | 
        if (!vardefined(vyres)) | 
| 177 | 
+ | 
                varset(vyres, ':', (double)ymax); | 
| 178 | 
+ | 
        xres = varvalue(vxres) + .5; | 
| 179 | 
+ | 
        yres = varvalue(vyres) + .5; | 
| 180 | 
+ | 
        if (xres <= 0 || yres <= 0) { | 
| 181 | 
+ | 
                eputs(argv[0]); | 
| 182 | 
+ | 
                eputs(": illegal output resolution\n"); | 
| 183 | 
+ | 
                quit(1); | 
| 184 | 
+ | 
        } | 
| 185 | 
  | 
                                                /* complete header */ | 
| 186 | 
  | 
        printargs(argc, argv, stdout); | 
| 187 | 
  | 
        fputformat(COLRFMT, stdout); | 
| 188 | 
  | 
        putchar('\n'); | 
| 189 | 
< | 
        fputresolu(YMAJOR|YDECR, xres, yres, stdout); | 
| 189 | 
> | 
        fprtresolu(xres, yres, stdout); | 
| 190 | 
  | 
                                                /* combine pictures */ | 
| 191 | 
  | 
        combine(); | 
| 192 | 
  | 
        quit(0); | 
| 194 | 
  | 
        eputs("Usage: "); | 
| 195 | 
  | 
        eputs(argv[0]); | 
| 196 | 
  | 
        eputs( | 
| 197 | 
< | 
" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); | 
| 197 | 
> | 
" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); | 
| 198 | 
  | 
        quit(1); | 
| 199 | 
  | 
} | 
| 200 | 
  | 
 | 
| 214 | 
  | 
        if (isexpos(s)) {                       /* exposure */ | 
| 215 | 
  | 
                d = exposval(s); | 
| 216 | 
  | 
                scalecolor(input[nfiles].expos, d); | 
| 184 | 
– | 
                if (original) | 
| 185 | 
– | 
                        scalecolor(input[nfiles].coef, 1.0/d); | 
| 217 | 
  | 
        } else if (iscolcor(s)) {               /* color correction */ | 
| 218 | 
  | 
                colcorval(ctmp, s); | 
| 219 | 
  | 
                multcolor(input[nfiles].expos, ctmp); | 
| 189 | 
– | 
                if (original) { | 
| 190 | 
– | 
                        colval(input[nfiles].coef,RED) /= colval(ctmp,RED); | 
| 191 | 
– | 
                        colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN); | 
| 192 | 
– | 
                        colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU); | 
| 193 | 
– | 
                } | 
| 220 | 
  | 
        } | 
| 221 | 
  | 
                                                /* echo line */ | 
| 222 | 
  | 
        putchar('\t'); | 
| 226 | 
  | 
 | 
| 227 | 
  | 
checkfile()                     /* ready a file */ | 
| 228 | 
  | 
{ | 
| 229 | 
+ | 
        int     xinp, yinp; | 
| 230 | 
  | 
        register int    i; | 
| 231 | 
  | 
                                        /* process header */ | 
| 232 | 
  | 
        fputs(input[nfiles].name, stdout); | 
| 237 | 
  | 
                eputs(": not in Radiance picture format\n"); | 
| 238 | 
  | 
                quit(1); | 
| 239 | 
  | 
        } | 
| 240 | 
< | 
        if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != (YMAJOR|YDECR)) { | 
| 240 | 
> | 
        if (fgetresolu(&xinp, &yinp, input[nfiles].fp) < 0) { | 
| 241 | 
  | 
                eputs(input[nfiles].name); | 
| 242 | 
  | 
                eputs(": bad picture size\n"); | 
| 243 | 
  | 
                quit(1); | 
| 244 | 
  | 
        } | 
| 245 | 
< | 
        if (xres == 0 && yres == 0) { | 
| 246 | 
< | 
                xres = xpos; | 
| 247 | 
< | 
                yres = ypos; | 
| 248 | 
< | 
        } else if (xpos != xres || ypos != yres) { | 
| 245 | 
> | 
        if (xmax == 0 && ymax == 0) { | 
| 246 | 
> | 
                xmax = xinp; | 
| 247 | 
> | 
                ymax = yinp; | 
| 248 | 
> | 
        } else if (xinp != xmax || yinp != ymax) { | 
| 249 | 
  | 
                eputs(input[nfiles].name); | 
| 250 | 
  | 
                eputs(": resolution mismatch\n"); | 
| 251 | 
  | 
                quit(1); | 
| 252 | 
  | 
        } | 
| 253 | 
  | 
                                        /* allocate scanlines */ | 
| 254 | 
  | 
        for (i = 0; i < WINSIZ; i++) | 
| 255 | 
< | 
                input[nfiles].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 255 | 
> | 
                input[nfiles].scan[i] = (COLOR *)emalloc(xmax*sizeof(COLOR)); | 
| 256 | 
  | 
} | 
| 257 | 
  | 
 | 
| 258 | 
  | 
 | 
| 259 | 
< | 
init()                          /* perform final setup */ | 
| 259 | 
> | 
init()                                  /* perform final setup */ | 
| 260 | 
  | 
{ | 
| 261 | 
  | 
        double  l_colin(), l_expos(); | 
| 262 | 
  | 
        register int    i; | 
| 236 | 
– | 
                                                /* prime input */ | 
| 237 | 
– | 
        for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) | 
| 238 | 
– | 
                advance(); | 
| 263 | 
  | 
                                                /* define constants */ | 
| 264 | 
  | 
        varset(vnfiles, ':', (double)nfiles); | 
| 265 | 
< | 
        varset(vxres, ':', (double)xres); | 
| 266 | 
< | 
        varset(vyres, ':', (double)yres); | 
| 265 | 
> | 
        varset(vxmax, ':', (double)xmax); | 
| 266 | 
> | 
        varset(vymax, ':', (double)ymax); | 
| 267 | 
  | 
                                                /* set functions */ | 
| 268 | 
  | 
        for (i = 0; i < 3; i++) { | 
| 269 | 
  | 
                funset(vcolexp[i], 1, ':', l_expos); | 
| 293 | 
  | 
                brtdef = NULL; | 
| 294 | 
  | 
                                                /* allocate scanline */ | 
| 295 | 
  | 
        scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 296 | 
+ | 
                                                /* set input position */ | 
| 297 | 
+ | 
        yscan = ymax+MIDSCN; | 
| 298 | 
  | 
                                                /* combine files */ | 
| 299 | 
  | 
        for (ypos = yres-1; ypos >= 0; ypos--) { | 
| 300 | 
  | 
            advance(); | 
| 301 | 
  | 
            varset(vypos, '=', (double)ypos); | 
| 302 | 
  | 
            for (xpos = 0; xpos < xres; xpos++) { | 
| 303 | 
+ | 
                xscan = (long)xpos*xmax/xres; | 
| 304 | 
  | 
                varset(vxpos, '=', (double)xpos); | 
| 305 | 
  | 
                eclock++; | 
| 306 | 
  | 
                if (brtdef != NULL) { | 
| 315 | 
  | 
                        } else { | 
| 316 | 
  | 
                            d = 0.0; | 
| 317 | 
  | 
                            for (i = 0; i < nfiles; i++) | 
| 318 | 
< | 
                                d += colval(input[i].scan[MIDSCN][xpos],j); | 
| 318 | 
> | 
                                d += colval(input[i].scan[MIDSCN][xscan],j); | 
| 319 | 
  | 
                        } | 
| 320 | 
  | 
                        if (d < 0.0) | 
| 321 | 
  | 
                            d = 0.0; | 
| 332 | 
  | 
} | 
| 333 | 
  | 
 | 
| 334 | 
  | 
 | 
| 335 | 
< | 
advance()                       /* read in next scanline */ | 
| 335 | 
> | 
advance()                       /* read in data for next scanline */ | 
| 336 | 
  | 
{ | 
| 337 | 
+ | 
        extern double  fabs(); | 
| 338 | 
+ | 
        int     ytarget; | 
| 339 | 
  | 
        register COLOR  *st; | 
| 340 | 
  | 
        register int    i, j; | 
| 341 | 
  | 
 | 
| 342 | 
< | 
        for (i = 0; i < nfiles; i++) { | 
| 343 | 
< | 
                st = input[i].scan[WINSIZ-1]; | 
| 344 | 
< | 
                for (j = WINSIZ-1; j > 0; j--)  /* rotate window */ | 
| 345 | 
< | 
                        input[i].scan[j] = input[i].scan[j-1]; | 
| 346 | 
< | 
                input[i].scan[0] = st; | 
| 347 | 
< | 
                if (ypos < MIDSCN)              /* hit bottom */ | 
| 348 | 
< | 
                        continue; | 
| 349 | 
< | 
                if (freadscan(st, xres, input[i].fp) < 0) { | 
| 350 | 
< | 
                        eputs(input[i].name); | 
| 351 | 
< | 
                        eputs(": read error\n"); | 
| 352 | 
< | 
                        quit(1); | 
| 342 | 
> | 
        for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) | 
| 343 | 
> | 
                for (i = 0; i < nfiles; i++) { | 
| 344 | 
> | 
                        st = input[i].scan[WINSIZ-1]; | 
| 345 | 
> | 
                        for (j = WINSIZ-1; j > 0; j--)  /* rotate window */ | 
| 346 | 
> | 
                                input[i].scan[j] = input[i].scan[j-1]; | 
| 347 | 
> | 
                        input[i].scan[0] = st; | 
| 348 | 
> | 
                        if (yscan <= MIDSCN)            /* hit bottom? */ | 
| 349 | 
> | 
                                continue; | 
| 350 | 
> | 
                        if (freadscan(st, xmax, input[i].fp) < 0) {  /* read */ | 
| 351 | 
> | 
                                eputs(input[i].name); | 
| 352 | 
> | 
                                eputs(": read error\n"); | 
| 353 | 
> | 
                                quit(1); | 
| 354 | 
> | 
                        } | 
| 355 | 
> | 
                        if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || | 
| 356 | 
> | 
                                fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || | 
| 357 | 
> | 
                                fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) | 
| 358 | 
> | 
                                for (j = 0; j < xmax; j++)  /* adjust color */ | 
| 359 | 
> | 
                                        multcolor(st[j], input[i].coef); | 
| 360 | 
  | 
                } | 
| 325 | 
– | 
                for (j = 0; j < xres; j++)      /* adjust color */ | 
| 326 | 
– | 
                        multcolor(st[j], input[i].coef); | 
| 327 | 
– | 
        } | 
| 361 | 
  | 
} | 
| 362 | 
  | 
 | 
| 363 | 
  | 
 | 
| 366 | 
  | 
register char   *nam; | 
| 367 | 
  | 
{ | 
| 368 | 
  | 
        register int    fn, n; | 
| 336 | 
– | 
        double  d; | 
| 369 | 
  | 
 | 
| 370 | 
< | 
        d = argument(1); | 
| 371 | 
< | 
        if (d > -.5 && d < .5) | 
| 372 | 
< | 
                return((double)nfiles); | 
| 341 | 
< | 
        fn = d - .5; | 
| 342 | 
< | 
        if (fn < 0 || fn >= nfiles) { | 
| 343 | 
< | 
                errno = EDOM; | 
| 344 | 
< | 
                return(0.0); | 
| 345 | 
< | 
        } | 
| 370 | 
> | 
        fn = argument(1) - .5; | 
| 371 | 
> | 
        if (fn < 0 || fn >= nfiles) | 
| 372 | 
> | 
                return(1.0); | 
| 373 | 
  | 
        if (nam == vbrtexp) | 
| 374 | 
  | 
                return(bright(input[fn].expos)); | 
| 375 | 
  | 
        n = 3; | 
| 403 | 
  | 
                d = argument(2); | 
| 404 | 
  | 
                if (d < 0.0) { | 
| 405 | 
  | 
                        xoff = d-.5; | 
| 406 | 
< | 
                        if (xpos+xoff < 0) | 
| 407 | 
< | 
                                xoff = -xpos; | 
| 406 | 
> | 
                        if (xscan+xoff < 0) | 
| 407 | 
> | 
                                xoff = -xscan; | 
| 408 | 
  | 
                } else { | 
| 409 | 
  | 
                        xoff = d+.5; | 
| 410 | 
< | 
                        if (xpos+xoff >= xres) | 
| 411 | 
< | 
                                xoff = xres-1-xpos; | 
| 410 | 
> | 
                        if (xscan+xoff >= xmax) | 
| 411 | 
> | 
                                xoff = xmax-1-xscan; | 
| 412 | 
  | 
                } | 
| 413 | 
  | 
        } | 
| 414 | 
  | 
        if (n >= 3) { | 
| 417 | 
  | 
                        yoff = d-.5; | 
| 418 | 
  | 
                        if (yoff+MIDSCN < 0) | 
| 419 | 
  | 
                                yoff = -MIDSCN; | 
| 420 | 
< | 
                        if (ypos+yoff < 0) | 
| 421 | 
< | 
                                yoff = -ypos; | 
| 420 | 
> | 
                        if (yscan+yoff < 0) | 
| 421 | 
> | 
                                yoff = -yscan; | 
| 422 | 
  | 
                } else { | 
| 423 | 
  | 
                        yoff = d+.5; | 
| 424 | 
  | 
                        if (yoff+MIDSCN >= WINSIZ) | 
| 425 | 
  | 
                                yoff = WINSIZ-1-MIDSCN; | 
| 426 | 
< | 
                        if (ypos+yoff >= yres) | 
| 427 | 
< | 
                                yoff = yres-1-ypos; | 
| 426 | 
> | 
                        if (yscan+yoff >= ymax) | 
| 427 | 
> | 
                                yoff = ymax-1-yscan; | 
| 428 | 
  | 
                } | 
| 429 | 
  | 
        } | 
| 430 | 
  | 
        if (nam == vbrtin) | 
| 431 | 
< | 
                return(bright(input[fn].scan[MIDSCN+yoff][xpos+xoff])); | 
| 431 | 
> | 
                return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff])); | 
| 432 | 
  | 
        n = 3; | 
| 433 | 
  | 
        while (n--) | 
| 434 | 
  | 
            if (nam == vcolin[n]) | 
| 435 | 
< | 
                return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],n)); | 
| 435 | 
> | 
                return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); | 
| 436 | 
  | 
        eputs("Bad call to l_colin()!\n"); | 
| 437 | 
  | 
        quit(1); | 
| 438 | 
  | 
} | 
| 453 | 
  | 
} | 
| 454 | 
  | 
 | 
| 455 | 
  | 
 | 
| 456 | 
+ | 
#ifdef  NIX | 
| 457 | 
+ | 
 | 
| 458 | 
  | 
quit(code) | 
| 459 | 
< | 
int     code; | 
| 459 | 
> | 
int  code; | 
| 460 | 
  | 
{ | 
| 461 | 
  | 
        exit(code); | 
| 462 | 
  | 
} | 
| 463 | 
+ | 
 | 
| 464 | 
+ | 
#else | 
| 465 | 
+ | 
 | 
| 466 | 
+ | 
#include  <signal.h> | 
| 467 | 
+ | 
 | 
| 468 | 
+ | 
quit(code)              /* exit gracefully */ | 
| 469 | 
+ | 
int  code; | 
| 470 | 
+ | 
{ | 
| 471 | 
+ | 
        int  status; | 
| 472 | 
+ | 
 | 
| 473 | 
+ | 
        if (code) {             /* abnormal exit -- kill children */ | 
| 474 | 
+ | 
                signal(SIGPIPE, SIG_IGN); | 
| 475 | 
+ | 
                kill(0, SIGPIPE); | 
| 476 | 
+ | 
        } | 
| 477 | 
+ | 
                                /* reap any children */ | 
| 478 | 
+ | 
        while (wait(&status) != -1) | 
| 479 | 
+ | 
                if (code == 0) | 
| 480 | 
+ | 
                        code = status>>8 & 0xff; | 
| 481 | 
+ | 
        exit(code); | 
| 482 | 
+ | 
} | 
| 483 | 
+ | 
 | 
| 484 | 
+ | 
#endif |