Beispiel #1
0
int
main(int argc, char *argv[])
{
    unsigned short *p, *q;
    unsigned int n;
    unsigned long clip_high, clip_low;
    int idx;

    unsigned short iobuf[BUFLEN];		/* input buffer */

    if (!(progname=strrchr(*argv, '/')))
	progname = *argv;

    if (!get_args(argc, argv) || isatty(fileno(stdin)) || isatty(fileno(stdout))) {
	bu_exit(1, "%s", usage);
    }

    mk_trans_tbl();

    clip_high = clip_low = 0;

    while ((n=fread(iobuf, sizeof(*iobuf), BUFLEN, stdin)) > 0) {
	/* translate */
	for (p=iobuf, q= &iobuf[n]; p < q; ++p) {
	    idx = *p;
	    if (idx < 0)
		idx = 0;
	    else if (idx > 65535)
		idx = 65535;
	    *p = idx;

	    if (mapbuf[*p] > 65535) {
		++clip_high;
		*p = 65535;
	    } else if (mapbuf[*p] < -0) {
		++clip_low;
		*p = 0;
	    } else {
		*p = (unsigned short)mapbuf[*p];
	    }
	}
	/* output */
	if (fwrite(iobuf, sizeof(*iobuf), n, stdout) != n) {
	    bu_exit(-1, "%s: Error writing stdout\n", progname);
	}
    }

    if (clip_high != 0L || clip_low != 0L) {
	fprintf(stderr, "%s: clipped %lu high, %lu low\n", progname, (long unsigned)clip_high, (long unsigned)clip_low);
    }

    return 0;
}
Beispiel #2
0
int main(int argc, char **argv)
{
    register unsigned char	*p, *q;
    register int		tmp;
    int	 		n;
    unsigned long		clip_high, clip_low;

#if defined(_WIN32) && !defined(__CYGWIN__)
    setmode(fileno(stdin), O_BINARY);
    setmode(fileno(stdout), O_BINARY);
    setmode(fileno(stderr), O_BINARY);
#endif

    progname = *argv;

    if ( !get_args( argc, argv ) || isatty((int)fileno(stdin))
	 || isatty((int)fileno(stdout)) ) {
	(void)fputs(usage, stderr);
	bu_exit ( 1, NULL );
    }

    if (char_arith)
	mk_char_trans_tbl();
    else
	mk_trans_tbl();

    clip_high = clip_low = 0L;
    while ( (n=read(0, (void *)ibuf, (unsigned)sizeof(ibuf))) > 0) {
	/* translate */
	for (p = ibuf, q = &ibuf[n]; p < q; ++p) {
	    tmp = mapbuf[*p];
	    if (tmp > 255) { ++clip_high; *p = 255; }
	    else if (tmp < 0) { ++clip_low; *p = 0; }
	    else *p = tmp;
	}
	/* output */
	if (write(1, (void *)ibuf, (unsigned)n) != n) {
	    (void)fprintf(stderr, "%s: Error writing stdout\n",
			  progname);
	    bu_exit (-1, NULL);
	}
    }
    if (n < 0) {
	perror("READ ERROR");
    }

    if ( clip_high != 0 || clip_low != 0 ) {
	(void)fprintf( stderr, "bwmod: clipped %lu high, %lu low\n",
		       clip_high, clip_low );
    }
    return(0);
}