[BACK]Return to term_ascii.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/term_ascii.c, Revision 1.1

1.1     ! kristaps    1: /*     $Id: term.c,v 1.145 2010/06/08 13:22:37 kristaps Exp $ */
        !             2: /*
        !             3:  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
        !             4:  *
        !             5:  * Permission to use, copy, modify, and distribute this software for any
        !             6:  * purpose with or without fee is hereby granted, provided that the above
        !             7:  * copyright notice and this permission notice appear in all copies.
        !             8:  *
        !             9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            16:  */
        !            17: #ifdef HAVE_CONFIG_H
        !            18: #include "config.h"
        !            19: #endif
        !            20:
        !            21: #include <sys/types.h>
        !            22:
        !            23: #include <assert.h>
        !            24: #include <stdint.h>
        !            25: #include <stdio.h>
        !            26: #include <stdlib.h>
        !            27:
        !            28: #include "out.h"
        !            29: #include "term.h"
        !            30: #include "main.h"
        !            31:
        !            32: static void              ascii_endline(struct termp *);
        !            33: static void              ascii_letter(struct termp *, char);
        !            34: static void              ascii_begin(struct termp *);
        !            35: static void              ascii_advance(struct termp *, size_t);
        !            36: static void              ascii_end(struct termp *);
        !            37:
        !            38:
        !            39: void *
        !            40: ascii_alloc(char *outopts)
        !            41: {
        !            42:        struct termp    *p;
        !            43:        const char      *toks[2];
        !            44:        char            *v;
        !            45:
        !            46:        if (NULL == (p = term_alloc(TERMENC_ASCII)))
        !            47:                return(NULL);
        !            48:
        !            49:        p->type = TERMTYPE_CHAR;
        !            50:        p->letter = ascii_letter;
        !            51:        p->begin = ascii_begin;
        !            52:        p->end = ascii_end;
        !            53:        p->endline = ascii_endline;
        !            54:        p->advance = ascii_advance;
        !            55:
        !            56:        toks[0] = "width";
        !            57:        toks[1] = NULL;
        !            58:
        !            59:        while (outopts && *outopts)
        !            60:                switch (getsubopt(&outopts, UNCONST(toks), &v)) {
        !            61:                case (0):
        !            62:                        p->defrmargin = (size_t)atoi(v);
        !            63:                        break;
        !            64:                default:
        !            65:                        break;
        !            66:                }
        !            67:
        !            68:        /* Enforce a lower boundary. */
        !            69:        if (p->defrmargin < 58)
        !            70:                p->defrmargin = 58;
        !            71:
        !            72:        return(p);
        !            73: }
        !            74:
        !            75:
        !            76: void
        !            77: ascii_free(void *arg)
        !            78: {
        !            79:
        !            80:        term_free((struct termp *)arg);
        !            81: }
        !            82:
        !            83:
        !            84: /* ARGSUSED */
        !            85: static void
        !            86: ascii_letter(struct termp *p, char c)
        !            87: {
        !            88:
        !            89:        /* Just push onto the screen. */
        !            90:        putchar(c);
        !            91: }
        !            92:
        !            93:
        !            94: static void
        !            95: ascii_begin(struct termp *p)
        !            96: {
        !            97:
        !            98:        (*p->headf)(p, p->argf);
        !            99: }
        !           100:
        !           101:
        !           102: static void
        !           103: ascii_end(struct termp *p)
        !           104: {
        !           105:
        !           106:        (*p->footf)(p, p->argf);
        !           107: }
        !           108:
        !           109:
        !           110: /* ARGSUSED */
        !           111: static void
        !           112: ascii_endline(struct termp *p)
        !           113: {
        !           114:
        !           115:        putchar('\n');
        !           116: }
        !           117:
        !           118:
        !           119: /* ARGSUSED */
        !           120: static void
        !           121: ascii_advance(struct termp *p, size_t len)
        !           122: {
        !           123:        size_t          i;
        !           124:
        !           125:        /* Just print whitespace on the terminal. */
        !           126:        for (i = 0; i < len; i++)
        !           127:                putchar(' ');
        !           128: }

CVSweb