[BACK]Return to dc.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / dc

Annotation of src/usr.bin/dc/dc.c, Revision 1.1

1.1     ! otto        1: /*     $OpenBSD$       */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
        !             5:  *
        !             6:  * Permission to use, copy, modify, and distribute this software for any
        !             7:  * purpose with or without fee is hereby granted, provided that the above
        !             8:  * copyright notice and this permission notice appear in all copies.
        !             9:  *
        !            10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            17:  */
        !            18:
        !            19: #ifndef lint
        !            20: static const char rcsid[] = "$OpenBSD$";
        !            21: #endif /* not lint */
        !            22:
        !            23: #include <err.h>
        !            24: #include <stdlib.h>
        !            25: #include <string.h>
        !            26:
        !            27: #include "extern.h"
        !            28:
        !            29: static __dead void     usage(void);
        !            30:
        !            31: extern char            *__progname;
        !            32:
        !            33: static __dead void
        !            34: usage(void)
        !            35: {
        !            36:        fprintf(stderr, "usage: %s [file]\n", __progname);
        !            37:        exit(1);
        !            38: }
        !            39:
        !            40: int
        !            41: main(int argc, char *argv[])
        !            42: {
        !            43:        FILE            *file;
        !            44:        struct source   src;
        !            45:
        !            46:        if (argc > 2)
        !            47:                usage();
        !            48:
        !            49:
        !            50:        init_bmachine();
        !            51:        setlinebuf(stdout);
        !            52:        setlinebuf(stderr);
        !            53:        if (argc == 2 && strcmp(argv[1], "-") != 0) {
        !            54:                file = fopen(argv[1], "r");
        !            55:                if (file == NULL)
        !            56:                        err(1, "cannot open file %s", argv[1]);
        !            57:                src_setstream(&src, file);
        !            58:                reset_bmachine(&src);
        !            59:                eval();
        !            60:                fclose(file);
        !            61:        }
        !            62:        /*
        !            63:         * BSD dc and Solaris dc continue with stdin after processing
        !            64:         * the file given as the argument.
        !            65:         */
        !            66:        src_setstream(&src, stdin);
        !            67:        reset_bmachine(&src);
        !            68:        eval();
        !            69:
        !            70:        return 0;
        !            71: }