| 30 |
|
#include <ctype.h> |
| 31 |
|
|
| 32 |
|
#include "tiff.h" /* for int32 */ |
| 33 |
+ |
#include "paths.h" /* for fixargv0() */ |
| 34 |
|
#include "rtio.h" |
| 35 |
+ |
#include "color.h" |
| 36 |
|
#include "resolu.h" |
| 37 |
|
|
| 38 |
|
#define MAXLINE 2048 |
| 59 |
|
{ |
| 60 |
|
fputs(HDRSTR, fp); |
| 61 |
|
fputs(s, fp); |
| 62 |
< |
putc('\n', fp); |
| 62 |
> |
fputc('\n', fp); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
void |
| 166 |
< |
printargs( /* print arguments to a file */ |
| 166 |
> |
printargs( /* print command arguments to a file */ |
| 167 |
|
int ac, |
| 168 |
|
char **av, |
| 169 |
|
FILE *fp |
| 170 |
|
) |
| 171 |
|
{ |
| 172 |
< |
while (ac-- > 0) { |
| 173 |
< |
fputword(*av++, fp); |
| 174 |
< |
fputc(ac ? ' ' : '\n', fp); |
| 172 |
> |
if (ac <= 0) |
| 173 |
> |
return; |
| 174 |
> |
if (progname == NULL) |
| 175 |
> |
fixargv0(av[0]); /* sets global progname */ |
| 176 |
> |
|
| 177 |
> |
if (progname >= av[0] && progname - av[0] < strlen(av[0])) |
| 178 |
> |
fputword(progname, fp); |
| 179 |
> |
else |
| 180 |
> |
fputword(av[0], fp); |
| 181 |
> |
while (--ac > 0) { |
| 182 |
> |
fputc(' ', fp); |
| 183 |
> |
fputword(*++av, fp); |
| 184 |
|
} |
| 185 |
+ |
fputc('\n', fp); |
| 186 |
|
} |
| 187 |
|
|
| 188 |
|
|
| 194 |
|
{ |
| 195 |
|
const char *cp = FMTSTR; |
| 196 |
|
char *r = fmt; |
| 197 |
< |
|
| 197 |
> |
/* check against format string */ |
| 198 |
|
while (*cp) if (*cp++ != *s++) return(0); |
| 199 |
|
while (isspace(*s)) s++; |
| 200 |
|
if (!*s) return(0); |
| 201 |
< |
if (r == NULL) return(1); |
| 202 |
< |
do |
| 201 |
> |
if (r == NULL) /* just checking if format? */ |
| 202 |
> |
return(1); |
| 203 |
> |
do /* copy format ID */ |
| 204 |
|
*r++ = *s++; |
| 205 |
< |
while (*s && !isspace(*s) && r-fmt < MAXFMTLEN-1); |
| 206 |
< |
*r = '\0'; |
| 205 |
> |
while (*s && r-fmt < MAXFMTLEN-1); |
| 206 |
> |
|
| 207 |
> |
do /* remove trailing white space */ |
| 208 |
> |
*r-- = '\0'; |
| 209 |
> |
while (r > fmt && isspace(*r)); |
| 210 |
> |
|
| 211 |
|
return(1); |
| 212 |
|
} |
| 213 |
|
|
| 218 |
|
FILE *fp |
| 219 |
|
) |
| 220 |
|
{ |
| 221 |
+ |
int align = 0; |
| 222 |
+ |
|
| 223 |
|
fputs(FMTSTR, fp); |
| 224 |
|
fputs(s, fp); |
| 225 |
< |
putc('\n', fp); |
| 225 |
> |
/* pad to align binary type for mmap() */ |
| 226 |
> |
if (globmatch(PICFMT, s)) |
| 227 |
> |
align = 0; /* not needed for picture data */ |
| 228 |
> |
else if (!strncmp("float", s, 5)) |
| 229 |
> |
align = sizeof(float); |
| 230 |
> |
else if (!strncmp("double", s, 6)) |
| 231 |
> |
align = sizeof(double); |
| 232 |
> |
else if (!strncmp("16-bit", s, 6)) |
| 233 |
> |
align = 2; |
| 234 |
> |
else if (!strncmp("32-bit", s, 6)) |
| 235 |
> |
align = 4; |
| 236 |
> |
else if (!strncmp("64-bit", s, 6)) |
| 237 |
> |
align = 8; |
| 238 |
> |
if (align) { |
| 239 |
> |
long pos = ftell(fp); |
| 240 |
> |
if (pos >= 0) { |
| 241 |
> |
pos = (pos + 2) % align; |
| 242 |
> |
if (pos) align -= pos; |
| 243 |
> |
else align = 0; |
| 244 |
> |
} else |
| 245 |
> |
align = 0; |
| 246 |
> |
} |
| 247 |
> |
while (align-- > 0) |
| 248 |
> |
putc(' ', fp); |
| 249 |
> |
fputc('\n', fp); |
| 250 |
|
} |
| 251 |
|
|
| 252 |
|
|
| 268 |
|
{ |
| 269 |
|
const char *be = BIGEND; |
| 270 |
|
|
| 271 |
< |
while (*s & (*be != '=') && *s++ == *be) |
| 271 |
> |
while ((*s != '\0') & (*be != '=') && *s++ == *be) |
| 272 |
|
++be; |
| 273 |
|
if (*be != '=') |
| 274 |
|
return(-1); /* irrelevant */ |
| 342 |
|
struct check *scp = (struct check *)cp; |
| 343 |
|
|
| 344 |
|
if (!formatval(scp->fs, s) && scp->fp != NULL) |
| 345 |
< |
fputs(s, scp->fp); |
| 345 |
> |
return(fputs(s, scp->fp)); |
| 346 |
|
|
| 347 |
|
return(0); |
| 348 |
|
} |
| 371 |
|
while (*s++); |
| 372 |
|
return(0); |
| 373 |
|
case '[': /* character set */ |
| 374 |
< |
setmatch = *s == *++p; |
| 374 |
> |
setmatch = (*s == *++p); |
| 375 |
|
if (!*p) |
| 376 |
|
return(0); |
| 377 |
|
while (*++p != ']') { |
| 378 |
|
if (!*p) |
| 379 |
|
return(0); |
| 380 |
|
if (*p == '-') { |
| 381 |
< |
setmatch += (p[-1] <= *s && *s <= p[1]); |
| 381 |
> |
setmatch += (p[-1] <= *s) & (*s <= p[1]); |
| 382 |
|
if (!*++p) |
| 383 |
|
break; |
| 384 |
|
} else |
| 389 |
|
s++; |
| 390 |
|
break; |
| 391 |
|
case '\\': /* literal next */ |
| 392 |
< |
p++; |
| 392 |
> |
if (!*++p) |
| 393 |
> |
return(0); |
| 394 |
|
/* fall through */ |
| 395 |
|
default: /* normal character */ |
| 396 |
|
if (*p != *s) |