| 18 |
|
|
| 19 |
|
#include <signal.h> |
| 20 |
|
|
| 21 |
+ |
#include <setjmp.h> |
| 22 |
+ |
|
| 23 |
|
#include <ctype.h> |
| 24 |
|
|
| 25 |
|
VIEW ourview = STDVIEW; /* viewing parameters */ |
| 47 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
| 48 |
|
|
| 49 |
|
int greyscale = 0; /* map colors to brightness? */ |
| 50 |
< |
char *devname = "X"; /* output device name */ |
| 50 |
> |
char *devname = dev_default; /* output device name */ |
| 51 |
|
|
| 52 |
|
struct driver *dev = NULL; /* driver functions */ |
| 53 |
|
|
| 57 |
|
RECT pframe; /* current frame boundaries */ |
| 58 |
|
int pdepth; /* image depth in current frame */ |
| 59 |
|
|
| 60 |
+ |
static jmp_buf mainloop; /* longjmp back to main loop */ |
| 61 |
+ |
static char *reserve_mem = NULL; /* pre-allocated reserve memory */ |
| 62 |
+ |
|
| 63 |
+ |
#define RESERVE_AMT 8192 /* amount of memory to reserve */ |
| 64 |
+ |
|
| 65 |
|
#define CTRL(c) ('c'-'@') |
| 66 |
|
|
| 67 |
|
|
| 120 |
|
|
| 121 |
|
devopen(devname); /* open device */ |
| 122 |
|
newimage(); /* set up image */ |
| 123 |
< |
|
| 123 |
> |
setjmp(mainloop); |
| 124 |
|
for ( ; ; ) { /* quit in command() */ |
| 125 |
|
while (hresolu <= 1<<pdepth && |
| 126 |
|
vresolu <= 1<<pdepth) |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
+ |
memreserve() /* fill memory reserves */ |
| 148 |
+ |
{ |
| 149 |
+ |
if (reserve_mem != NULL) |
| 150 |
+ |
return; /* got some already */ |
| 151 |
+ |
reserve_mem = malloc(RESERVE_AMT); |
| 152 |
+ |
} |
| 153 |
+ |
|
| 154 |
+ |
|
| 155 |
+ |
memerror(detail) /* try and rescue a memory error */ |
| 156 |
+ |
char *detail; |
| 157 |
+ |
{ |
| 158 |
+ |
if (reserve_mem == NULL) { |
| 159 |
+ |
sprintf(errmsg, "out of memory %s", detail); |
| 160 |
+ |
error(SYSTEM, errmsg); |
| 161 |
+ |
} |
| 162 |
+ |
free(reserve_mem); |
| 163 |
+ |
reserve_mem = NULL; |
| 164 |
+ |
do |
| 165 |
+ |
command("out of memory: "); |
| 166 |
+ |
while (reserve_mem == NULL); |
| 167 |
+ |
longjmp(mainloop, 1); |
| 168 |
+ |
} |
| 169 |
+ |
|
| 170 |
+ |
|
| 171 |
|
command(prompt) /* get/execute command */ |
| 172 |
|
char *prompt; |
| 173 |
|
{ |
| 176 |
|
char inpbuf[256]; |
| 177 |
|
char *args; |
| 178 |
|
again: |
| 179 |
< |
(*dev->comout)(prompt); /* get command + arguments */ |
| 149 |
< |
(*dev->comin)(inpbuf); |
| 179 |
> |
(*dev->comin)(inpbuf, prompt); /* get command + arguments */ |
| 180 |
|
for (args = inpbuf; *args && *args != ' '; args++) |
| 181 |
|
; |
| 182 |
|
if (*args) *args++ = '\0'; |
| 299 |
|
xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu; |
| 300 |
|
ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu; |
| 301 |
|
rl = (RECT *)malloc(xsiz*sizeof(RECT)); |
| 302 |
+ |
if (rl == NULL) |
| 303 |
+ |
memerror("in rsample"); |
| 304 |
|
pl = (PNODE **)malloc(xsiz*sizeof(PNODE *)); |
| 305 |
< |
if (rl == NULL || pl == NULL) |
| 306 |
< |
error(SYSTEM, "out of memory in rsample"); |
| 305 |
> |
if (pl == NULL) |
| 306 |
> |
memerror("in rsample"); |
| 307 |
|
/* |
| 308 |
|
* Initialize the bottom row. |
| 309 |
|
*/ |
| 390 |
|
if (p->kid == NULL) { /* subdivide */ |
| 391 |
|
|
| 392 |
|
if ((p->kid = newptree()) == NULL) |
| 393 |
< |
error(SYSTEM, "out of memory in refine"); |
| 393 |
> |
memerror("in refine"); |
| 394 |
|
/* |
| 395 |
|
* The following paint order can leave a black pixel |
| 396 |
|
* when redraw() is called in (*dev->paintr)(). |