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

Annotation of src/usr.bin/hexdump/conv.c, Revision 1.2

1.2     ! deraadt     1: /*     $OpenBSD$       */
        !             2:
1.1       deraadt     3: /*
                      4:  * Copyright (c) 1989 The Regents of the University of California.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. All advertising materials mentioning features or use of this software
                     16:  *    must display the following acknowledgement:
                     17:  *     This product includes software developed by the University of
                     18:  *     California, Berkeley and its contributors.
                     19:  * 4. Neither the name of the University nor the names of its contributors
                     20:  *    may be used to endorse or promote products derived from this software
                     21:  *    without specific prior written permission.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     24:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     25:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     26:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     27:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     28:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     29:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     31:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     32:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     33:  * SUCH DAMAGE.
                     34:  */
                     35:
                     36: #ifndef lint
                     37: /*static char sccsid[] = "from: @(#)conv.c     5.4 (Berkeley) 6/1/90";*/
1.2     ! deraadt    38: static char rcsid[] = "$OpenBSD: conv.c,v 1.1.1.1 1995/10/18 08:45:23 deraadt Exp $";
1.1       deraadt    39: #endif /* not lint */
                     40:
                     41: #include <sys/types.h>
                     42: #include <ctype.h>
                     43: #include "hexdump.h"
                     44:
                     45: conv_c(pr, p)
                     46:        PR *pr;
                     47:        u_char *p;
                     48: {
                     49:        extern int deprecated;
                     50:        char buf[10], *str;
                     51:
                     52:        switch(*p) {
                     53:        case '\0':
                     54:                str = "\\0";
                     55:                goto strpr;
                     56:        /* case '\a': */
                     57:        case '\007':
                     58:                if (deprecated)         /* od didn't know about \a */
                     59:                        break;
                     60:                str = "\\a";
                     61:                goto strpr;
                     62:        case '\b':
                     63:                str = "\\b";
                     64:                goto strpr;
                     65:        case '\f':
                     66:                str = "\\f";
                     67:                goto strpr;
                     68:        case '\n':
                     69:                str = "\\n";
                     70:                goto strpr;
                     71:        case '\r':
                     72:                str = "\\r";
                     73:                goto strpr;
                     74:        case '\t':
                     75:                str = "\\t";
                     76:                goto strpr;
                     77:        case '\v':
                     78:                if (deprecated)
                     79:                        break;
                     80:                str = "\\v";
                     81:                goto strpr;
                     82:        default:
                     83:                break;
                     84:        }
                     85:        if (isprint(*p)) {
                     86:                *pr->cchar = 'c';
                     87:                (void)printf(pr->fmt, *p);
                     88:        } else {
                     89:                (void)sprintf(str = buf, "%03o", (int)*p);
                     90: strpr:         *pr->cchar = 's';
                     91:                (void)printf(pr->fmt, str);
                     92:        }
                     93: }
                     94:
                     95: conv_u(pr, p)
                     96:        PR *pr;
                     97:        u_char *p;
                     98: {
                     99:        extern int deprecated;
                    100:        static char *list[] = {
                    101:                "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
                    102:                 "bs",  "ht",  "lf",  "vt",  "ff",  "cr",  "so",  "si",
                    103:                "dle", "dcl", "dc2", "dc3", "dc4", "nak", "syn", "etb",
                    104:                "can",  "em", "sub", "esc",  "fs",  "gs",  "rs",  "us",
                    105:        };
                    106:
                    107:                                                /* od used nl, not lf */
                    108:        if (*p <= 0x1f) {
                    109:                *pr->cchar = 's';
                    110:                if (deprecated && *p == 0x0a)
                    111:                        (void)printf(pr->fmt, "nl");
                    112:                else
                    113:                        (void)printf(pr->fmt, list[*p]);
                    114:        } else if (*p == 0x7f) {
                    115:                *pr->cchar = 's';
                    116:                (void)printf(pr->fmt, "del");
                    117:        } else if (deprecated && *p == 0x20) {  /* od replace space with sp */
                    118:                *pr->cchar = 's';
                    119:                (void)printf(pr->fmt, " sp");
                    120:        } else if (isprint(*p)) {
                    121:                *pr->cchar = 'c';
                    122:                (void)printf(pr->fmt, *p);
                    123:        } else {
                    124:                *pr->cchar = 'x';
                    125:                (void)printf(pr->fmt, (int)*p);
                    126:        }
                    127: }