home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume22
/
popi
/
part02
< prev
next >
Wrap
Text File
|
1991-08-22
|
50KB
|
2,033 lines
Newsgroups: comp.sources.misc
From: Rich Burridge <richb@Aus.Sun.COM>
Subject: v22i041: popi - The Digital Darkroom, Part02/09
Message-ID: <1991Aug22.152951.15472@sparky.IMD.Sterling.COM>
X-Md4-Signature: cbe43b2ce1a4e1cd1a09acf062ce3c0e
Date: Thu, 22 Aug 1991 15:29:51 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: Rich Burridge <richb@Aus.Sun.COM>
Posting-number: Volume 22, Issue 41
Archive-name: popi/part02
Environment: Xlib, Xview, SunView
Supersedes: popi: Volume 9, Issue 47-55
#! /bin/sh
# 1. Remove everything above the #! /bin/sh line
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh to create the files:
# debug.c
# expr.c
# io.c
# lex.c
# main.c
# polar.c
# This archive created: Wed Aug 21 10:35:49 EST 1991
#
#
export PATH; PATH=/bin:$PATH
#
if [ -f debug.c ]
then
echo shar: will not over-write existing file debug.c
else
echo shar: extracting 'debug.c', 1542 characters
cat > debug.c <<'Funky_Stuff'
/* @(#)debug.c 1.2 90/12/28
*
* Debug routines used by the popi program.
*
* Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
* This version is based on the code in his Prentice Hall book,
* "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
* which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
*
* Permission is given to distribute these extensions, as long as these
* introductory messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors or inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file) then an attempt will be made to fix them.
*/
#include "popi.h"
#ifdef DEBUG
char *LatStrings[] = {
"PLUS",
"MINUS",
"MULT",
"DIV",
"MOD",
"GT",
"LT",
"GE",
"LE",
"EQ",
"NE",
"AND",
"OR",
"XOR",
"BOR",
"BAND",
"X",
"Y",
"UMIN",
"LNOT",
"ASSIGN",
"CRVAL",
"CLVAL",
"PRVAL",
"PLVAL",
"POW",
"ANGLE",
"RADIUS",
"SIN",
"COS",
"ATAN",
"HYPOT",
"ABS",
"LOG",
"SQRT",
"RAND",
"LSHIFT",
"RSHIFT",
"QUEST",
"COLON",
} ;
char *LatStrings1[] = {
"FNAME",
"FNUM",
"INAME",
"INUM",
"NAME",
"NEW",
"SPECIAL",
"VALUE",
"NL",
"AT",
"DOLLAR",
"LPAREN",
"RPAREN",
"LSQUARE",
"RSQUARE",
"LCURLY",
"RCURLY",
"COMMA",
"QUIT",
"OLDSPECIAL",
};
char *
LatString(t)
int t ;
{
if (t < 100) return(LatStrings[t-1]) ;
return(LatStrings1[t-100]) ;
}
#endif /* DEBUG */
Funky_Stuff
len=`wc -c < debug.c`
if [ $len != 1542 ] ; then
echo error: debug.c was $len bytes long, should have been 1542
fi
fi # end of overwriting check
if [ -f expr.c ]
then
echo shar: will not over-write existing file expr.c
else
echo shar: extracting 'expr.c', 14811 characters
cat > expr.c <<'Funky_Stuff'
/* @(#)expr.c 1.3 91/03/25
*
* Parser routines used by the popi program.
*
* Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
* This version is based on the code in his Prentice Hall book,
* "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
* which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
*
* Permission is given to distribute these extensions, as long as these
* introductory messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors or inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file) then an attempt will be made to fix them.
*/
#include <stdio.h>
#include <ctype.h>
#include "popi.h"
#include "lex.h"
int lat ; /* Look ahead token. */
int prs = 0 ;
int RangeCheck = 1 ;
parse_t parsed[MAXTOKENS] ;
/* Prototypes for local functions */
void expr P((void)) ;
void level P((int)) ;
void factor P((void)) ;
void fileref P((int, int)) ;
void expect P((int)) ;
void emit P((int)) ;
void transform P((void)) ;
#define MAX_SAME_PREC 5 /* Max length row of op[], +1 */
static int op[][MAX_SAME_PREC] = {
{ T_POW },
{ '*', }, /* Do mul before div, to avoid int underflow */
{ '/', '%' },
{ '+', '-' },
{ T_LSHIFT, T_RSHIFT },
{ '>', '<', T_GE, T_LE },
{ T_EQ, T_NE },
{ '&' },
{ '^' },
{ '|' },
{ T_AND },
{ T_OR },
} ;
static int op_op[][MAX_SAME_PREC] = {
{ OP_POW },
{ OP_MUL, }, /* Do mul before div, to avoid int underflow */
{ OP_DIV, OP_MOD },
{ OP_PLUS, OP_MINUS },
{ OP_LSHIFT, OP_RSHIFT },
{ OP_GT, OP_LT, OP_GE, OP_LE },
{ OP_EQ, OP_NE },
{ OP_AND },
{ OP_XOR },
{ OP_OR },
{ OP_CAND },
{ OP_COR },
} ;
/* I was using NELS(op) here (see popi.h) but Microsoft Quick C
* gets this wrong (it thinks sizeof *op == sizeof op).
*/
/** #define PREC_LEVELS NELS(op) **/
#define PREC_LEVELS (sizeof op / sizeof (int [MAX_SAME_PREC]))
static void
emit(what)
int what ;
{
DEBUG((Debug, "emit(%d)\n", what)) ;
if (prs >= MAXTOKENS)
{
SPRINTF(ErrBuf, "expression too long") ;
error(ERR_PARSE) ;
}
parsed[prs++] = what ;
}
/* Token is either CLVAL or CRVAL, indicating an lvalue or an rvalue.
* We actually determine if the coordinates are polar or cartesian.
*/
static void
fileref(val, opc)
int val, opc ;
{
DEBUG((Debug, "fileref(val=%d, opc=%d)\n", val, opc)) ;
if (val < 0 || val >= nimages || Images[val].str == (char *) 0)
{
SPRINTF(ErrBuf, "bad file number: %d", val - 1) ;
error(ERR_PARSE) ;
}
DEBUG((Debug, "fileref name='%s'\n", Images[val].str)) ;
emit(OP_VALUE) ;
emit(val) ;
if (lat == '[')
{
/* Cartesian coordinate reference */
lex() ;
expr() ;
expect(',') ;
expr() ;
expect(']') ; /* [x, y] */
emit(opc) ;
return ;
}
if (lat == '{')
{
/* Polar coordinate reference */
lex() ;
expr() ;
expect(',') ;
expr() ;
expect('}') ; /* {r, a} */
emit(opc == OP_CLVAL ? OP_PLVAL : OP_PRVAL) ;
return ;
}
/* Default (no index specified) is [x, y]. */
emit(OP_X) ;
emit(OP_Y) ;
emit(opc) ;
}
/* factor = '(' expr ')'
* | UNARYOP factor
* | FNCALL1 '(' expr ')'
* | FNCALL2 '(' expr ',' expr ')'
*
* UNARYOP = '!'
* | '~'
*
* FNCALL1 = 'sin'
* | 'cos'
* | 'log'
* | 'sqrt'
* | 'abs'
*
* FNCALL2 = 'atan'
*/
static void
factor()
{
int token ;
DEBUG((Debug, "factor() lat='%c'\n", lat)) ;
switch (token = lat)
{
case '(' : lex() ;
expr() ;
expect(')') ;
break ;
case '-' : lex() ;
factor();
if (parsed[prs-2] == OP_VALUE) /* Constant evaluation */
parsed[prs-1] = -parsed[prs-1] ;
else
emit(OP_UMIN) ;
break ;
case '!' : lex() ;
factor() ;
if (parsed[prs-2] == OP_VALUE)
parsed[prs-1] = !parsed[prs-1] ;
else
emit(OP_NOT) ;
break ;
case '~' : lex() ;
factor() ;
if (parsed[prs-2] == OP_XOR)
parsed[prs-1] = ~parsed[prs-1] ;
else
emit(token) ;
break ;
case T_INAME : lex() ;
fileref(lexval, OP_CRVAL) ;
break ;
case '$' : lex() ;
expect(T_VALUE) ;
/* $1 refers to Images[2] */
fileref(lexval-1+2, OP_CRVAL) ;
break ;
case T_VALUE : emit(OP_VALUE) ;
emit(lexval) ;
lex() ;
break ;
case 'r' : MakePolar() ; /* Create polar coordinate lookup tables */
emit(OP_R) ;
lex() ;
break ;
case 'a' : MakePolar() ; /* Create polar coordinate lookup tables */
emit(OP_A) ;
lex() ;
break ;
case 'y' : emit(OP_Y) ;
lex() ;
break ;
case 'x' : emit(OP_X) ;
lex() ;
break ;
case T_RAND : lex() ;
expect('(') ;
expect(')') ;
emit(OP_RAND) ;
break ;
case T_SIN :
case T_COS :
case T_LOG :
case T_SQRT :
case T_ABS : lex() ;
expect('(');
expr() ;
expect(')') ;
if (parsed[prs-2] == OP_VALUE)
{
switch (token)
{
case T_SIN : parsed[prs-1] = (parse_t)
sin((double) DtoR(parsed[prs-1])) ;
break ;
case T_COS : parsed[prs-1] = (parse_t)
cos((double) DtoR(parsed[prs-1])) ;
break ;
case T_LOG : parsed[prs-1] = (parse_t)
log((double) parsed[prs-1]) ;
break ;
case T_SQRT : parsed[prs-1] = (parse_t)
sqrt((double) parsed[prs-1]) ;
break ;
case T_ABS : if (parsed[prs-1] < 0)
parsed[prs-1] = -parsed[prs-1] ;
}
}
else
{
switch (token)
{
case T_SIN : emit(OP_SIN) ;
break ;
case T_COS : emit(OP_COS) ;
break ;
case T_LOG : emit(OP_LOG) ;
break ;
case T_SQRT : emit(OP_SQRT) ;
break ;
case T_ABS : emit(OP_ABS) ;
}
}
break ;
case T_ATAN :
case T_HYPOT : lex() ;
expect('(') ;
expr() ;
expect(',') ;
expr() ;
expect(')') ;
emit(token == T_ATAN? OP_ATAN : OP_HYPOT) ;
break ;
default : SPRINTF(ErrBuf, "expr: syntax error (expected factor)") ;
error(ERR_PARSE) ;
}
}
/* Recursive descent parser for binary operators as specified
* in the op[] array above.
*
* term = factor BINARYOP term
*/
static void
level(nr)
int nr ;
{
int i ;
extern int noerro ;
DEBUG((Debug, "level(%d) lat='%c'\n", nr, lat)) ;
if (nr < 0)
{
factor() ;
return ;
}
level(nr-1) ;
for (i = 0; op[nr][i] != 0 && noerr; i++)
if (lat == op[nr][i])
{
/* LHS of op is already on parse string;
* process RHS and then emit the operator
*/
lex() ;
level(nr) ;
/* Do a little compile-time constant evaluation here
*
* If the parse string looks like this:
* <= prs
* + value (prs - 1) RHS
* ^ VALUE (prs - 2)
* v value (prs - 3) LHS
* - VALUE (prs - 4)
* then instead of emitting the operation, we can evaluate.
*/
if (prs >= 4 && parsed[prs-2] == OP_VALUE && parsed[prs-4] == OP_VALUE)
{
parse_t *dest = &parsed[prs-3] ;
parse_t *src = &parsed[prs-1] ;
DEBUG((Debug, "Optimise: %ld %ld '%c'(%d) ",
*dest, *src, lat, lat)) ;
switch(op[nr][i])
{
case T_POW : *dest = (parse_t)
pow((double) *dest, (double) *src) ;
break ;
case '*' : *dest *= *src ;
break ;
case '/' : if (*src == 0) *dest = Zmax ;
else *dest /= *src ;
break ;
case '%' : if (*src != 0) *dest %= *src ;
break ;
case '+' : *dest += *src ;
break ;
case '-' : *dest -= *src ;
break ;
case T_LSHIFT : *dest <<= *src ;
break ;
case T_RSHIFT : *dest >>= *src ;
break ;
case '>' : *dest = *dest > *src ;
break ;
case '<' : *dest = *dest < *src ;
break ;
case T_GE : *dest = *dest >= *src ;
break ;
case T_LE : *dest = *dest <= *src;
break ;
case T_EQ : *dest = *dest == *src ;
break ;
case T_NE : *dest = *dest != *src ;
break ;
case '&' : *dest &= *src ;
break ;
case '^' : *dest ^= *src ;
break ;
case '|' : *dest |= *src ;
break ;
case T_AND : *dest = *dest && *src ;
break ;
case T_OR : *dest = *dest || *src ;
break ;
default : SPRINTF(ErrBuf,
"Unrecognised token (%d) found during optimisation",
lat) ;
error(ERR_SNARK) ;
}
prs -= 2 ;
DEBUG((Debug, "=> %ld\n", *dest)) ;
}
else emit(op_op[nr][i]) ;
break ;
}
}
#ifndef __MSC__ /* MSC gets scope rules wrong */
static
#endif /* __MSC__ */
void
expr()
{
extern int prs ;
int remem1, remem2 ;
DEBUG((Debug, "expr() lat='%c'\n", lat)) ;
DEBUG((Debug, "levels of precedence: %d\n", PREC_LEVELS)) ;
level(PREC_LEVELS - 1) ;
if (lat == '?')
{
lex() ;
emit(OP_CONDIT) ;
remem1 = prs ;
emit(0) ; /* Actual value filled in below. */
expr() ;
expect(':') ;
emit(OP_COLON) ;
remem2 = prs ;
emit(0) ; /* Actual value filled in below. */
parsed[remem1] = prs-1 ;
expr() ;
parsed[remem2] = prs-1 ;
}
}
void
expect(t)
int t ;
{
DEBUG((Debug, "expect('%c')\n", t)) ;
if (lat == t) lex() ;
else
{
if (t < 127) SPRINTF(ErrBuf, "expected token '%c' (%d)", t, t) ;
else SPRINTF(ErrBuf, "expected token (%d)", t) ;
error(ERR_PARSE) ;
}
}
/* Transform = NEW '[' index ']' '=' expr
* | NEW '=' expr
* | expr
*/
static void
transform()
{
extern int prs ;
DEBUG((Debug, "transform() lat='%c'\n", lat)) ;
prs = 0 ; /* initial length of parse string */
DEBUG((Debug, "lat=%d, NEW=%d, lat!=NEW = %d\n", lat, T_NEW, lat != T_NEW)) ;
if (lat != T_NEW)
{
expr() ;
emit(OP_AT) ;
}
else
{
lex() ;
if (lat == '[')
{
fileref((int)(CurNew - Images), OP_CLVAL) ;
expect('=') ;
expr() ;
emit(OP_ASGN) ;
}
else
{
expect((int) "=") ;
expr() ;
emit(OP_AT) ;
}
}
if (lat != '\n')
{
SPRINTF(ErrBuf,
"syntax error - expected operator or end of expression") ;
error(ERR_PARSE) ;
}
assert(lat == '\n') ;
}
/* Parse = : special
* | '?' help
* | 'q' quit
* | transform transformation expression
*/
void
parse(istr)
FILE *istr ;
{
extern int lat ; /* Look ahead token. */
FILE *SaveInput ; /* Saved previous input stream. */
DEBUG((Debug, "parse()\n")) ;
/* Save and then reset current input stream. */
SaveInput = InputStream;
InputStream = istr;
do
{
DEBUG((Debug, "parse() - top of loop\n")) ;
noerr = TRUE ;
/* Display popi prompt and clear input line. Returns length of popi prompt. */
CharPos = istr ? 0 : disp_prompt() ;
if (LogStr)
{
FPRINTF(LogStr, "-> ") ;
FFLUSH(LogStr) ;
}
lex() ;
switch (lat)
{
/* Keep '#' for backwards compatibility */
case '#' :
case ':' : special() ;
break ;
case '?' : help() ;
Skip() ;
break ;
case 'q' : Quit() ;
/* NOTREACHED */
case EOF :
case '\n' : break ;
default : transform() ;
if (noerr) run() ;
}
assert(lat == '\n' || lat == EOF) ;
}
while (lat != EOF) ;
/* Restore saved previous input stream. */
InputStream = SaveInput ;
}
Funky_Stuff
len=`wc -c < expr.c`
if [ $len != 14811 ] ; then
echo error: expr.c was $len bytes long, should have been 14811
fi
fi # end of overwriting check
if [ -f io.c ]
then
echo shar: will not over-write existing file io.c
else
echo shar: extracting 'io.c', 10951 characters
cat > io.c <<'Funky_Stuff'
/* @(#)io.c 1.7 91/08/20
*
* File handling routines used by the popi program.
*
* Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
* This version is based on the code in his Prentice Hall book,
* "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
* which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
*
* Permission is given to distribute these extensions, as long as these
* introductory messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors or inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file) then an attempt will be made to fix them.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include "popi.h"
#include "libpbm.h"
#if unix || AMIGA
#define RMODE "r"
#define WMODE "w"
#else /* ! (unix || AMIGA) */
#define RMODE "rb"
#define WMODE "wb"
#endif /* unix || AMIGA */
#if defined(unix)
static bool IsPopen = FALSE ;
#endif /* unix */
int nimages = 2 ;
pixel_t ***
ImgAlloc()
{
int color ;
pixel_t ***img ;
pixel_t ***linep ;
pixel_t ***imgend ;
noerr = TRUE ;
img = (pixel_t ***)
LINT_CAST(Emalloc((unsigned)Ysize * sizeof(pixel_t **))) ;
if (img == 0) return((pixel_t ***) 0) ;
imgend = &img[Ysize] ;
for (linep = img; linep != imgend; ++linep)
{
*linep = (pixel_t **)
LINT_CAST(Emalloc((unsigned)colors * sizeof (pixel_t *))) ;
for (color = 0; color < colors; color++)
(*linep)[color] = (pixel_t *)
LINT_CAST(Emalloc((unsigned)Xsize * sizeof (pixel_t))) ;
}
if (!noerr)
{
/* Run out of memory; free what we have allocated */
for (linep = img; linep != imgend; ++linep)
if (*linep)
for (color = 0; color < colors; color++)
{
if ((*linep)[color]) free((char *) (*linep)[color]) ;
free((char *) *linep) ;
}
return((pixel_t ***) 0) ;
}
return(img) ;
}
void
ImgFree(img)
struct SRC *img ;
{
int color, y ;
pixel_t **p ;
free(img->str) ;
img->str = (char *) 0 ;
for (y = 0; y < Ysize; ++y)
{
p = img->pix[y] ;
for (color = 0; color < colors; color++)
free((char *) p[color]) ;
free((char *) p) ;
}
free((char *) img->pix) ;
img->pix = (pixel_t ***) 0 ;
}
void
Efclose(stream)
FILE *stream ;
{
#ifdef unix
if (IsPopen)
{
PCLOSE(stream) ;
IsPopen = FALSE ;
}
else
#endif /* unix */
FCLOSE(stream) ;
}
FILE *
EfopenR(filename)
char *filename ;
{
FILE *istr ;
#if unix
FILE *popen() ;
#endif /* unix */
DEBUG((Debug, "EfopenR(%s)\n", filename)) ;
if ((istr = fopen(filename, RMODE)) != NULL) return(istr) ;
#if unix
if (errno == ENOENT)
{
char buf[MAXPATHLEN] ;
/* First see if the compressed file exists and is readable */
SPRINTF(buf, "%s.Z", filename) ;
if ((istr = fopen(buf, "r")) != NULL)
{
/* OK - it's there */
FCLOSE(istr) ;
SPRINTF(buf, "zcat %s", filename) ;
DEBUG((Debug, "popen(%s)\n", buf)) ;
if ((istr = popen(buf, "r")) != NULL)
{
IsPopen = TRUE ;
return(istr) ;
}
}
}
#endif /* unix */
SPRINTF(ErrBuf, "Can't read file '%s'", filename) ;
error(ERR_SYS) ;
return(NULL) ;
}
FILE *
EfopenW(filename)
char *filename ;
{
FILE *ostr ;
#ifdef unix
FILE *popen() ;
#endif /* unix */
DEBUG((Debug, "EfopenW(%s)\n", filename)) ;
#ifdef unix
if (*filename == '|')
{
++filename ;
if ((ostr = popen(filename, "w")) == NULL)
{
SPRINTF(ErrBuf, "Can't run command '%s'", filename) ;
error(ERR_SYS) ;
}
IsPopen = TRUE ;
return ostr ;
}
#endif /* unix */
if ((ostr = fopen(filename, WMODE)) == NULL)
{
SPRINTF(ErrBuf, "Can't write file '%s'", filename) ;
error(ERR_SYS) ;
}
return(ostr) ;
}
void
do_ioerror(fd, filename, direction, row)
FILE *fd ;
char *filename, *direction ;
int row ;
{
if (ferror(fd))
{
SPRINTF(ErrBuf, "File '%s' %s error on row %d",
filename, direction, row) ;
error(ERR_SYS) ;
FCLOSE(fd) ;
return ;
}
SPRINTF(ErrBuf, "File '%s' insufficient data at row %d", filename, row) ;
error(0) ;
}
void
getpix(filename, imgname)
char *filename ; /* File name */
char *imgname ; /* Image name */
{
FILE *fd ;
struct SRC *img ; /* Pointer into Images */
struct SRC *unused = (struct SRC *) 0 ; /* First unused slot */
char *p, *r, *g, *b ;
char *rem ;
int len ;
int row ;
pixel_t ***linep ;
pixel_t ***imgend ;
int x, mask ;
extern int pm_iserror ;
int format ;
pixval maxval ;
gray *grayrow ;
pixel *pixelrow ;
len = strlen(filename) ;
if (len > 2 && !strncmp(&filename[len-2], ".Z", 2)) filename[len-2] = '\0' ;
if ((fd = EfopenR(filename)) == NULL) return ;
pm_iserror = FALSE ;
ppm_readppminit(fd, &Xsize, &Ysize, &maxval, &format) ;
if (format == PBM_FORMAT || format == RPBM_FORMAT ||
format == PGM_FORMAT || format == RPGM_FORMAT)
{
colors = 1 ;
grayrow = pgm_allocrow(Xsize) ;
}
else if (format == PPM_FORMAT || format == RPPM_FORMAT)
{
colors = 3 ;
pixelrow = ppm_allocrow(Xsize) ;
}
else if (format == OLD_POPI_FORMAT) colors = 1 ;
if (imgname == 0 || *imgname == '\0')
{
imgname = filename ;
/*
* Use the basename of the filename for the image name. If this results in a
* non-valid image name, they'll just have to use the $n equivalent. It's not
* our business to go transforming names.
*/
/* Find last '/' in string */
for (p = rem = imgname; *p; ++p)
if (*p == '/' && p[1] != '\0') rem = p + 1 ;
imgname = rem ;
}
/* See if the named image already exists */
for (img = Images; img != &Images[nimages]; ++img)
{
if (img->str && strcmp(img->str, imgname) == 0) break ;
if (img->pix == (pixel_t ***) 0 && unused == (struct SRC *) 0)
unused = img ;
}
if (img == &Images[nimages])
{
/* Named image doesn't exist. Allocate a new image. */
if (unused == (struct SRC *) 0) img = &Images[nimages++] ;
else img = unused ;
if ((img->pix = ImgAlloc()) == 0 ||
(img->str = (char *)
Emalloc((unsigned int) (strlen(imgname)+1))) == 0)
return ;
STRCPY(img->str, imgname) ;
}
/* Read in the image. */
row = 0 ;
imgend = &img->pix[Ysize] ;
for (linep = img->pix; linep != imgend; ++linep)
{
mask = (signed_io) ? 0x80 : 0x00 ;
if (format == PBM_FORMAT || format == RPBM_FORMAT ||
format == PGM_FORMAT || format == RPGM_FORMAT)
{
pgm_readpgmrow(fd, grayrow, Xsize, maxval, format) ;
if (pm_iserror == TRUE)
{
do_ioerror(fd, filename, "read", row) ;
return ;
}
g = (char *) (*linep)[0] ;
for (x = 0; x < Xsize; x++)
g[x] = (char) (grayrow[x] ^ mask) ;
}
else if (format == PPM_FORMAT || format == RPPM_FORMAT)
{
ppm_readppmrow(fd, pixelrow, Xsize, maxval, format) ;
if (pm_iserror == TRUE)
{
do_ioerror(fd, filename, "read", row) ;
return ;
}
r = (char *) (*linep)[0] ;
g = (char *) (*linep)[1] ;
b = (char *) (*linep)[2] ;
for (x = 0; x < Xsize; x++)
{
r[x] = pixelrow[x].r ^ mask ;
g[x] = pixelrow[x].g ^ mask ;
b[x] = pixelrow[x].b ^ mask ;
}
}
else if (format == OLD_POPI_FORMAT)
{
if (fread((char *) (*linep)[0], 1, Xsize, fd) <= 0)
{
do_ioerror(fd, filename, "read", row) ;
return ;
}
}
row++ ;
}
if (format == PGM_FORMAT || format == RPGM_FORMAT ||
format == PGM_FORMAT || format == RPGM_FORMAT)
pgm_freerow(grayrow) ;
else if (format == PPM_FORMAT || format == RPPM_FORMAT)
ppm_freerow(pixelrow) ;
Efclose(fd) ;
}
void
putpix(into, filename)
struct SRC *into ; /* Work buffer */
char *filename ; /* File name */
{
FILE *fd;
pixel_t ***linep ; /* Pointer to a scanline */
pixel_t ***imgend ; /* Pointer to just after end of image */
int row ;
char *r, *g, *b ;
int x, mask ;
extern int pm_iserror ;
int format ;
pixval maxval ;
gray *grayrow ;
pixel *pixelrow ;
if ((fd = EfopenW(filename)) == NULL) return ;
pm_iserror = FALSE ;
maxval = 255 ;
if (colors == 1)
{
format = RPGM_FORMAT ;
if (oldfmt != TRUE) pgm_writepgminit(fd, Xsize, Ysize, maxval) ;
grayrow = pgm_allocrow(Xsize) ;
}
else if (colors == 3)
{
format = RPPM_FORMAT ;
ppm_writeppminit(fd, Xsize, Ysize, maxval) ;
pixelrow = ppm_allocrow(Xsize) ;
}
/* Write out the image. */
row = 0 ;
imgend = &into->pix[Ysize] ;
for (linep = into->pix; linep != imgend; ++linep)
{
mask = (signed_io) ? 0x80 : 0x00 ;
if (format == RPGM_FORMAT)
{
g = (char *) (*linep)[0] ;
for (x = 0; x < Xsize; x++)
grayrow[x] = g[x] ^ mask ;
pgm_writepgmrow(fd, grayrow, Xsize, maxval) ;
if (pm_iserror == TRUE)
{
do_ioerror(fd, filename, "write", row) ;
return ;
}
}
else if (format == RPPM_FORMAT)
{
r = (char *) (*linep)[0] ;
g = (char *) (*linep)[1] ;
b = (char *) (*linep)[2] ;
for (x = 0; x < Xsize; x++)
{
pixelrow[x].r = r[x] ^ mask ;
pixelrow[x].g = g[x] ^ mask ;
pixelrow[x].b = b[x] ^ mask ;
}
ppm_writeppmrow(fd, pixelrow, Xsize, maxval) ;
if (pm_iserror == TRUE)
{
do_ioerror(fd, filename, "write", row) ;
return ;
}
}
row++ ;
}
if (format == RPGM_FORMAT) pgm_freerow(grayrow) ;
else if (format == RPPM_FORMAT) ppm_freerow(pixelrow) ;
Efclose(fd) ;
}
void
showfiles()
{
struct SRC *img ;
struct SRC *endimages ;
for (img = &Images[2], endimages = &Images[nimages]; img != endimages; ++img)
{
if(img->str)
{
PRINTF("$%d = %s\n", img - Images - 1, img->str) ;
if (LogStr)
FPRINTF(LogStr, "$%d = %s\n", img - Images + 1, img->str) ;
}
}
}
Funky_Stuff
len=`wc -c < io.c`
if [ $len != 10951 ] ; then
echo error: io.c was $len bytes long, should have been 10951
fi
fi # end of overwriting check
if [ -f lex.c ]
then
echo shar: will not over-write existing file lex.c
else
echo shar: extracting 'lex.c', 6952 characters
cat > lex.c <<'Funky_Stuff'
/* @(#)lex.c 1.2 90/12/28
*
* Lexical routines used by the popi program.
*
* Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
* This version is based on the code in his Prentice Hall book,
* "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
* which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
*
* Permission is given to distribute these extensions, as long as these
* introductory messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors or inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file) then an attempt will be made to fix them.
*/
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include "popi.h"
#include "lex.h"
/* Prototypes for local functions */
int Getch P((void)) ;
int getnumber P((int)) ;
int getstring P((int)) ;
int follow P((int, int, int)) ;
int CharPos = 0 ; /* Current character pos on input line */
int OldPos = 0 ; /* Previous character pos on input line */
int TokPos = 0 ; /* Position of the beginning of the current token */
char ErrBuf[256] ;
double lexfract ;
FILE *InputStream = (FILE *) 0 ;
/* One level of character pushback on stdin to avoid disp_ungetc() */
char SaveChar = '\0' ;
static int
Getch()
{
int c ;
if (InputStream == (FILE *) 0)
{
if (SaveChar == '\0') c = disp_getchar() ;
else
{
c = SaveChar;
SaveChar = '\0';
}
}
else c = getc(InputStream) ;
OldPos = CharPos ;
if (c == '\t') CharPos = (CharPos - 1) % 8 + 8 ;
else if (c == '\n') CharPos = 0 ;
else ++CharPos ;
DEBUG((Debug, "Getch() => '%c'\n", c)) ;
if (LogStr && CharPos != OldPos) PUTC(c, LogStr) ;
return(c) ;
}
void
Skip() /* Skip to the end of the line */
{
while (lat != '\n' && lat != EOF)
lat = Getch() ;
lat = '\n' ;
}
void
error(errtype)
int errtype ;
{
DEBUG((Debug, "error: type %d, pos %d msg '%s'\n",
errtype, TokPos, ErrBuf)) ;
if (!noerr) return ; /* Already printed a message */
disp_error(errtype, TokPos) ;
Skip() ;
noerr = FALSE ; /* An error has occurred */
if (LogStr) FPRINTF(LogStr, "Error: %s\n", ErrBuf) ;
}
static int
getnumber(first)
int first ;
{
int c ;
lexval = first - '0' ;
lexfract = 0.0 ;
while (isdigit(c = Getch()))
lexval = 10 * lexval + c - '0' ;
/* Some of the special routines use floating values */
if (c == '.')
{
double div = 10.0 ;
while (isdigit(c = Getch()))
{
lexfract += (c - '0') / div ;
div *= 10.0;
}
}
pushback(c) ;
return(T_VALUE) ;
}
static int
getstring(first)
int first ;
{
int c = first ;
char *str = text ;
struct SRC *img ;
struct SRC *endimages ;
do
{
*str++ = (char) c ;
c = Getch() ;
}
while (isalpha(c) || c == '_' || isdigit(c)) ;
*str = '\0' ;
pushback(c) ;
if (strcmp(text, "new") == 0) return(T_NEW) ;
else if (strcmp(text, "sin") == 0) return(T_SIN) ;
else if (strcmp(text, "cos") == 0) return(T_COS) ;
else if (strcmp(text, "atan") == 0) return(T_ATAN) ;
else if (strcmp(text, "hypot") == 0) return(T_HYPOT) ;
else if (strcmp(text, "abs") == 0) return(T_ABS) ;
else if (strcmp(text, "log") == 0) return(T_LOG) ;
else if (strcmp(text, "sqrt") == 0) return(T_SQRT) ;
else if (strcmp(text, "rand") == 0) return(T_RAND) ;
for (img = Images, endimages = &Images[nimages]; img != endimages; ++img)
{
if (img->str && strcmp(img->str, text) == 0)
{
lexval = (int)(img - Images) ;
return(T_INAME) ;
}
}
if (strlen(text) > 1) return(T_NAME) ;
return(first) ;
}
static int
follow(tok, ifyes, ifno)
int tok, ifyes, ifno ;
{
int c ;
if ((c = Getch()) == tok) return(ifyes) ;
pushback(c) ;
return(ifno) ;
}
void
lex() /* Set the global lookahead token "lat". */
{
DEBUG((Debug, "lex():\n")) ;
do /* Ignore white space */
lat = Getch() ;
while (lat == ' ' || lat == '\t') ;
TokPos = CharPos ;
if (isdigit(lat)) lat = getnumber(lat) ;
else if (isalpha(lat) || lat == '_') lat = getstring(lat) ;
switch (lat)
{
case '*' : lat = follow('*', T_POW, lat) ;
break ;
case '>' : lat = follow('=', T_GE, lat) ;
lat = follow('>', T_RSHIFT, lat) ;
break ;
case '<' : lat = follow('=', T_LE, lat) ;
lat = follow('<', T_LSHIFT, lat) ;
break ;
case '!' : lat = follow('=', T_NE, lat) ;
break ;
case '=' : lat = follow('=', T_EQ, lat) ;
break ;
case '|' : lat = follow('|', T_OR, lat) ;
break ;
case '&' : lat = follow('&', T_AND, lat) ;
break ;
case 'Z' : lat = T_VALUE ;
lexval = Zmax ;
break ;
case 'Y' : lat = T_VALUE ;
lexval = Ysize - 1 ;
break ;
case 'X' : lat = T_VALUE ;
lexval = Xsize - 1 ;
break ;
case 'R' : lat = T_VALUE ;
lexval = (int) hypot(Xsize / 2.0, Ysize / 2.0) ;
break ;
case 'A' : lat = T_VALUE ;
lexval = 360 ;
break ;
case '"' : {
char *str ;
str = text ;
while ((lat = Getch()) != EOF && lat != '\n' && lat != '"')
*str++ = (char) lat ;
*str = '\0' ;
if (lat != '"')
{
SPRINTF(ErrBuf, "Expected matching '\"'") ;
error(ERR_PARSE) ;
return ;
}
}
lat = T_FNAME ;
break ;
case ';' : Skip() ; /* Comment to end of line */
lat = '\n' ;
break ;
case '\\' : /* Special meaning to next character */
switch (lat = Getch())
{
case '\n' : lex() ; /* Ignore newline - get next token */
break ;
/* May be other cases here later. */
}
break ;
default : break ;
}
if (Debug)
{
if (lat < 127 && isprint(lat))
DEBUG((Debug, "lex() => '%c' (%d)\n", lat, lat)) ;
else
DEBUG((Debug, "lex() => (%d)\n", lat)) ;
}
}
void
pushback(c)
int c ;
{
DEBUG((Debug, "pushback('%c')\n", c)) ;
if (InputStream == (FILE *) 0) SaveChar = c ;
else
UNGETC(c, InputStream) ;
CharPos = OldPos ;
}
Funky_Stuff
len=`wc -c < lex.c`
if [ $len != 6952 ] ; then
echo error: lex.c was $len bytes long, should have been 6952
fi
fi # end of overwriting check
if [ -f main.c ]
then
echo shar: will not over-write existing file main.c
else
echo shar: extracting 'main.c', 9932 characters
cat > main.c <<'Funky_Stuff'
/* @(#)main.c 1.6 91/08/20
*
* Main routine and declarations used by the popi program.
*
* Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
* This version is based on the code in his Prentice Hall book,
* "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
* which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
*
* Permission is given to distribute these extensions, as long as these
* introductory messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors or inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file) then an attempt will be made to fix them.
*/
#include <stdio.h>
#include <ctype.h>
#include "popi.h"
#include "patchlevel.h"
/* Prototypes for local functions */
void get_options P((int, char **[])) ;
void Usage P((int)) ;
int main P((int, char **)) ;
struct SRC Images[MAXIMG] ; /* Array of images. */
struct SRC *CurOld ; /* Pointer to "old" image */
struct SRC *CurNew ; /* Pointer to "new" image */
pixel_t Zmax = DEF_ZSIZE - 1 ; /* Max brightness level */
FILE *Debug = NULL ; /* Debugging output stream */
FILE *LogStr = NULL ; /* Logging output stream */
char text[512] ; /* Value of string token */
char *ProgName ; /* Program name (for err messages) */
char *LogFile = "popi.log" ; /* Name of log file */
char geometry[MAXLINE] ; /* X11 geometry information. */
char x11_display[MAXLINE] ; /* X11 display information. */
int noerr = TRUE ;
int lexval ; /* Value of numerical token */
int BOXW ; /* Text box width */
int TXsize ; /* Total width */
int TYsize ; /* Total height */
int Xsize = DEF_X ; /* Image width */
int Ysize = DEF_Y ; /* Image height */
int Zsize = DEF_ZSIZE ; /* No. brightness levels */
int disp_active = 1 ; /* So we can turn off the display */
int colors = 1 ; /* RGB color mode (default off) */
int signed_io = 0 ; /* Signed I/O mode (default off) */
int Truncate = 0 ; /* Truncate assignments instead of wrapping. */
int Verbose = 0 ; /* Be chatty */
int iconic = 0 ; /* Set if the window is in an iconic state. */
int oldfmt = 0 ; /* Set to save images in old format. */
int tcache = 0 ; /* Set to read/write cached trig info. */
#if SEQPAR
int ncpus = 1 ; /* Default is single-tasking */
#endif /* SEQPAR */
static char *UsageMsg[] = {
"\nvalid options:",
" -a[+-] turn auto-display on (off)",
" -c[+-] turn RGB color mode on (off)",
" -D[file] enable debugging trace (default stderr)",
" -d disp specify X11 display",
" -g geom specify X11 geometry",
" -i start window iconically",
" -l[file] log all commands (default ./popi.log)",
" -o save images to disk in old popi format",
" -p# specify number of CPUs (if available)",
" -r[+-] turn range checking on (off)",
" -s[+-] turn signed I/O mode on (off)",
" -t[+-] turn trig caching mode on (off)",
" -V print version number",
" -v[+-] turn verbose mode on (off)",
" -xWidth specify image width (in pixels)",
" -yHeight specify image height (in scanlines)",
" -zDepth specify image depth (in levels)",
(char *) 0
} ;
void
PrStrs(msg)
char *msg[] ;
{
char **p ;
for (p = msg; *p; ++p) FPRINTF(stderr, "%s\n", *p) ;
}
static void
Usage(status)
int status ;
{
FPRINTF(stderr, "Usage: %s [options] [image-files]\n", ProgName) ;
PrStrs(UsageMsg) ;
/* Also need a driver-specific usage message appended. */
exit(status) ;
}
void
version()
{
FPRINTF(stderr, "%s: version 3.1.%1d\n", ProgName, PATCHLEVEL) ;
}
static void
get_options(argc, argvp) /* Read command line options. */
int argc ;
char **argvp[] ;
{
char **argv ;
char **new_argv ;
char **nav ;
argv = *argvp ;
new_argv = (char **)
LINT_CAST(Emalloc((unsigned) ((argc + 1) * sizeof (char *)))) ;
nav = new_argv ;
for (ProgName = *nav++ = *argv++; *argv && **argv == '-'; ++argv)
{
bool ArgRecognised ;
ArgRecognised = TRUE ;
switch (*++*argv)
{
case 'a' : if (*++*argv == '-') /* Auto-display */
disp_active = 0 ;
else
disp_active = 1 ;
break ;
case 'c' : if (*++*argv == '-') /* RGB color mode */
colors = 1 ;
else
colors = 3 ;
break ;
case 'D' : if (*++*argv)
{
if ((Debug = fopen(*argv, "w")) == NULL)
{
SPRINTF(ErrBuf,
"Can't open debug file '%s' - using stderr",
*argv) ;
error(ERR_SYS) ;
Debug = stderr ;
}
}
else Debug = stderr ;
setbuf(Debug, (char *) NULL) ; /**/
break ;
case 'd' : ++argv ; /* X11 display information. */
if (*argv == NULL)
Usage(0) ; /* Print usage message */
/*NOTREACHED*/
STRCPY(x11_display, *argv) ;
break ;
case 'g' : ++argv ; /* X11 geometry information. */
if (*argv == NULL)
Usage(0) ; /* Print usage message */
/*NOTREACHED*/
STRCPY(geometry, *argv) ;
break ;
case 'i' : iconic = 1 ; /* Start window iconically. */
break ;
case 'l' : if (*++*argv) /* Log all commands */
LogFile = *argv ;
OpenLog(&LogStr) ;
break ;
case 'o' : oldfmt = 1 ; /* Save images in old format. */
break ;
case 'p' : /* No. cpus to use in parallel */
/* Still recognise the option on other machines,
* so scripts can use this option portably.
*/
#if SEQPAR
if (*++*argv)
{
ncpus = atoi(*argv) ;
if (ncpus >= cpus_online()) ncpus = cpus_online() - 1 ;
if (ncpus < 0) ncpus = 0 ;
}
else ncpus = cpus_online() - 1 ;
#endif /* SEQPAR */
break ;
case 'r' : if (*++*argv == '-') /* Range checking */
RangeCheck = 0 ;
else
RangeCheck = 1 ;
break ;
case 's' : if (*++*argv == '-') /* Signed I/O mode */
signed_io = 0 ;
else
signed_io = 1 ;
break ;
case 't' : if (*++*argv == '-') /* Trig caching mode */
tcache = 0 ;
else
tcache = 1 ;
break ;
case 'V' : version() ; /* Print version number. */
exit(0) ;
/*NOTREACHED*/
case 'v' : if (*++*argv == '-') /* Verbose */
Verbose = 0 ;
else
++Verbose ;
break ;
case 'x' : Xsize = atoi(++*argv) ;
break ;
case 'y' : Ysize = atoi(++*argv) ;
break ;
case 'z' : Zsize = atoi(++*argv) ;
Zmax = (pixel_t) (Zsize - 1) ;
break ;
case '?' : Usage(0) ; /* Print usage message */
/*NOTREACHED*/
/* Note: no error on default because drivers may interpret other options.
* It's up to them to give an error message if they can.
*/
default : ArgRecognised = FALSE ;
}
if (!ArgRecognised) *nav++ = *argv ;
}
*nav = (char *) 0 ;
CurOld = &Images[0] ;
CurNew = &Images[1] ;
CurOld->pix = ImgAlloc() ;
CurOld->str = "old" ;
CurNew->pix = ImgAlloc() ;
CurNew->str = "new" ;
for (; *argv; ++argv) getpix(*argv, (char *) 0) ;
}
/* We deliberately don't exit on error here.
* The user may have some picture that has taken ages to develop.
* If we run out of memory, they have a chance to save the
* image and exit themselves, which they should do as soon
* as possible.
*/
char *
Emalloc(n)
unsigned int n ;
{
char *try ;
static unsigned long TotalAllocated = 0L ;
if ((try = malloc(n)) == NULL)
{
SPRINTF(ErrBuf,
"Allocate %u bytes failed (total malloc=%ld",
n, TotalAllocated) ;
error(ERR_SYS) ;
}
TotalAllocated += n ;
return(try) ;
}
void
Quit()
{
disp_finish() ;
exit(0) ;
}
main(argc, argv)
int argc ;
char **argv ;
{
get_options(argc, &argv) ; /* read the command line options. */
TXsize = Xsize ;
if (TXsize < TWIDTH) TXsize = TWIDTH ;
TYsize = Ysize+100 ;
BOXW = TXsize-50 ;
disp_init(argc, argv) ;
#if SEQPAR
m_set_procs(ncpus) ;
#endif /* SEQPAR */
parse((FILE *) 0) ;
Quit() ;
return 0 ; /* Shut up warning messages from some compilers */
/*NOTREACHED*/
}
Funky_Stuff
len=`wc -c < main.c`
if [ $len != 9932 ] ; then
echo error: main.c was $len bytes long, should have been 9932
fi
fi # end of overwriting check
if [ -f polar.c ]
then
echo shar: will not over-write existing file polar.c
else
echo shar: extracting 'polar.c', 3529 characters
cat > polar.c <<'Funky_Stuff'
/* @(#)polar.c 1.4 91/08/20
*
* Polar coordinate handling routines used by the popi program.
*
* Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
* This version is based on the code in his Prentice Hall book,
* "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
* which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
*
* Permission is given to distribute these extensions, as long as these
* introductory messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors or inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file) then an attempt will be made to fix them.
*/
#include <fcntl.h>
#include <stdio.h>
#include "popi.h"
short *avals = 0 ;
short *rvals = 0 ;
#ifdef AMIGA
double
hypot(x, y)
double x, y;
{
return(sqrt(x*x + y*y)) ;
}
#endif /* AMIGA */
extern int tcache ;
void
MakePolar()
{
char path[30] ;
short *ap ; /* Pointer to angle array */
short *rp ; /* Pointer into radius array */
short *a1 ; /* Tmp pointer to angle array */
short *r1 ; /* Tmp pointer to radius array */
int fd ;
int n ;
int pct ;
int pctl ;
int size ;
int x ;
int y ;
int xmin ;
int xmax ;
int ymin ;
int ymax ;
double xd;
double yd;
if (avals) return ; /* Previously calculated */
size = Xsize * Ysize * sizeof(short) ;
avals = (short *) LINT_CAST(Emalloc((unsigned) size)) ;
rvals = (short *) LINT_CAST(Emalloc((unsigned) size)) ;
if (tcache)
{
sprintf(path, "/usr/tmp/popi.%d.%d", Xsize, Ysize) ;
if ((fd=open(path, O_RDONLY)) != -1)
{
n = read(fd, avals, size) ;
n += read(fd, rvals, size) ;
close(fd) ;
if (n == 2*size) return ;
}
/* else perror("polar open (read) error") ; */
}
ymax = Ysize / 2 ;
ymin = -(Ysize - 1) / 2 ;
xmin = -Xsize / 2 ;
xmax = (Xsize - 1) / 2 ;
rp = rvals ;
ap = avals ;
FPRINTF(stderr, "Calculating trig tables\n") ;
FFLUSH(stderr) ;
/* +y
* ^
* 2 | 1
* -x <----+----> +x
* 3 | 4
* v
* -y
*/
pctl = -1 ;
for (y = ymax; y >= 0; --y)
{
pct = ((ymax-y) * 100) / ymax ;
if (pct != pctl)
disp_percentdone(pctl=pct) ;
yd = y;
/* Quadrant 2 */
for (x = xmin; x < 0; ++x)
{
xd = x;
*ap++ = (short) (RtoD(atan2(yd, xd)) + 0.5) ;
*rp++ = (short) hypot(yd, xd) ;
}
*ap++ = (y == 0) ? 0 : (short) (RtoD(atan2(yd, xd)) + 0.5) ;
*rp++ = (y == 0) ? 0 : (short) hypot(yd, xd) ;
++x ;
/* Remember location just before the 0 value */
r1 = rp - 2 ;
a1 = ap - 2 ;
/* Quadrant 1 */
for ( ; x <= xmax; ++x)
{
*ap++ = 180 - *a1-- ;
*rp++ = *r1-- ;
}
}
/* Quadrant 3, 4 */
r1 = rp - Xsize - 1 ;
a1 = ap - Xsize - 1 ;
for ( ; y >= ymin; --y)
{
for (x = xmin; x <= xmax; ++x)
{
*rp++ = *r1-- ;
*ap++ = *a1-- + 180 ;
}
}
disp_percentdone(100) ; /* Can rely on '100' to terminate */
if (tcache)
{
if ((fd=open(path, O_WRONLY|O_CREAT, 0777)) != -1)
{
n = write(fd, avals, size) ;
n += write(fd, rvals, size) ;
close(fd) ;
if (n == 2*size) return ;
}
else perror("polar open (write) error") ;
}
}
Funky_Stuff
len=`wc -c < polar.c`
if [ $len != 3529 ] ; then
echo error: polar.c was $len bytes long, should have been 3529
fi
fi # end of overwriting check
exit 0 # Just in case...