[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.3

1.3     ! deraadt     1: /*     $OpenBSD: conv.c,v 1.2 1996/06/26 05:34:17 deraadt Exp $        */
1.2       deraadt     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.3     ! deraadt    38: static char rcsid[] = "$OpenBSD: conv.c,v 1.2 1996/06/26 05:34:17 deraadt Exp $";
1.1       deraadt    39: #endif /* not lint */
                     40:
                     41: #include <sys/types.h>
                     42: #include <ctype.h>
1.3     ! deraadt    43: #include <stdio.h>
1.1       deraadt    44: #include "hexdump.h"
                     45:
1.3     ! deraadt    46: void
1.1       deraadt    47: conv_c(pr, p)
                     48:        PR *pr;
                     49:        u_char *p;
                     50: {
                     51:        extern int deprecated;
                     52:        char buf[10], *str;
                     53:
                     54:        switch(*p) {
                     55:        case '\0':
                     56:                str = "\\0";
                     57:                goto strpr;
                     58:        /* case '\a': */
                     59:        case '\007':
                     60:                if (deprecated)         /* od didn't know about \a */
                     61:                        break;
                     62:                str = "\\a";
                     63:                goto strpr;
                     64:        case '\b':
                     65:                str = "\\b";
                     66:                goto strpr;
                     67:        case '\f':
                     68:                str = "\\f";
                     69:                goto strpr;
                     70:        case '\n':
                     71:                str = "\\n";
                     72:                goto strpr;
                     73:        case '\r':
                     74:                str = "\\r";
                     75:                goto strpr;
                     76:        case '\t':
                     77:                str = "\\t";
                     78:                goto strpr;
                     79:        case '\v':
                     80:                if (deprecated)
                     81:                        break;
                     82:                str = "\\v";
                     83:                goto strpr;
                     84:        default:
                     85:                break;
                     86:        }
                     87:        if (isprint(*p)) {
                     88:                *pr->cchar = 'c';
                     89:                (void)printf(pr->fmt, *p);
                     90:        } else {
                     91:                (void)sprintf(str = buf, "%03o", (int)*p);
                     92: strpr:         *pr->cchar = 's';
                     93:                (void)printf(pr->fmt, str);
                     94:        }
                     95: }
                     96:
1.3     ! deraadt    97: void
1.1       deraadt    98: conv_u(pr, p)
                     99:        PR *pr;
                    100:        u_char *p;
                    101: {
                    102:        extern int deprecated;
                    103:        static char *list[] = {
                    104:                "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
                    105:                 "bs",  "ht",  "lf",  "vt",  "ff",  "cr",  "so",  "si",
                    106:                "dle", "dcl", "dc2", "dc3", "dc4", "nak", "syn", "etb",
                    107:                "can",  "em", "sub", "esc",  "fs",  "gs",  "rs",  "us",
                    108:        };
                    109:
                    110:                                                /* od used nl, not lf */
                    111:        if (*p <= 0x1f) {
                    112:                *pr->cchar = 's';
                    113:                if (deprecated && *p == 0x0a)
                    114:                        (void)printf(pr->fmt, "nl");
                    115:                else
                    116:                        (void)printf(pr->fmt, list[*p]);
                    117:        } else if (*p == 0x7f) {
                    118:                *pr->cchar = 's';
                    119:                (void)printf(pr->fmt, "del");
                    120:        } else if (deprecated && *p == 0x20) {  /* od replace space with sp */
                    121:                *pr->cchar = 's';
                    122:                (void)printf(pr->fmt, " sp");
                    123:        } else if (isprint(*p)) {
                    124:                *pr->cchar = 'c';
                    125:                (void)printf(pr->fmt, *p);
                    126:        } else {
                    127:                *pr->cchar = 'x';
                    128:                (void)printf(pr->fmt, (int)*p);
                    129:        }
                    130: }