1: /*
   2:  * Copyright (c) 1989 The Regents of the University of California.
   3:  * All rights reserved.
   4:  *
   5:  * Redistribution and use in source and binary forms are permitted
   6:  * provided that: (1) source distributions retain this entire copyright
   7:  * notice and comment, and (2) distributions including binaries display
   8:  * the following acknowledgement:  ``This product includes software
   9:  * developed by the University of California, Berkeley and its contributors''
  10:  * in the documentation or other materials provided with the distribution
  11:  * and in all advertising materials mentioning features or use of this
  12:  * software. Neither the name of the University nor the names of its
  13:  * contributors may be used to endorse or promote products derived
  14:  * from this software without specific prior written permission.
  15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18:  */
  19: 
  20: #ifndef lint
  21: static char sccsid[] = "@(#)conv.c	5.4 (Berkeley) 6/1/90";
  22: #endif /* not lint */
  23: 
  24: #include <sys/types.h>
  25: #include <ctype.h>
  26: #include "hexdump.h"
  27: 
  28: conv_c(pr, p)
  29:     PR *pr;
  30:     u_char *p;
  31: {
  32:     extern int deprecated;
  33:     char buf[10], *str;
  34: 
  35:     switch(*p) {
  36:     case '\0':
  37:         str = "\\0";
  38:         goto strpr;
  39:     /* case '\a': */
  40:     case '\007':
  41:         if (deprecated)     /* od didn't know about \a */
  42:             break;
  43:         str = "\\a";
  44:         goto strpr;
  45:     case '\b':
  46:         str = "\\b";
  47:         goto strpr;
  48:     case '\f':
  49:         str = "\\f";
  50:         goto strpr;
  51:     case '\n':
  52:         str = "\\n";
  53:         goto strpr;
  54:     case '\r':
  55:         str = "\\r";
  56:         goto strpr;
  57:     case '\t':
  58:         str = "\\t";
  59:         goto strpr;
  60:     case '\v':
  61:         if (deprecated)
  62:             break;
  63:         str = "\\v";
  64:         goto strpr;
  65:     default:
  66:         break;
  67:     }
  68:     if (isprint(*p)) {
  69:         *pr->cchar = 'c';
  70:         (void)printf(pr->fmt, *p);
  71:     } else {
  72:         (void)sprintf(str = buf, "%03o", (int)*p);
  73: strpr:      *pr->cchar = 's';
  74:         (void)printf(pr->fmt, str);
  75:     }
  76: }
  77: 
  78: conv_u(pr, p)
  79:     PR *pr;
  80:     u_char *p;
  81: {
  82:     extern int deprecated;
  83:     static char *list[] = {
  84:         "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
  85:          "bs",  "ht",  "lf",  "vt",  "ff",  "cr",  "so",  "si",
  86:         "dle", "dcl", "dc2", "dc3", "dc4", "nak", "syn", "etb",
  87:         "can",  "em", "sub", "esc",  "fs",  "gs",  "rs",  "us",
  88:     };
  89: 
  90:                         /* od used nl, not lf */
  91:     if (*p <= 0x1f) {
  92:         *pr->cchar = 's';
  93:         if (deprecated && *p == 0x0a)
  94:             (void)printf(pr->fmt, "nl");
  95:         else
  96:             (void)printf(pr->fmt, list[*p]);
  97:     } else if (*p == 0x7f) {
  98:         *pr->cchar = 's';
  99:         (void)printf(pr->fmt, "del");
 100:     } else if (deprecated && *p == 0x20) {  /* od replace space with sp */
 101:         *pr->cchar = 's';
 102:         (void)printf(pr->fmt, " sp");
 103:     } else if (isprint(*p)) {
 104:         *pr->cchar = 'c';
 105:         (void)printf(pr->fmt, *p);
 106:     } else {
 107:         *pr->cchar = 'x';
 108:         (void)printf(pr->fmt, (int)*p);
 109:     }
 110: }

Defined functions

conv_c defined in line 28; used 1 times
conv_u defined in line 78; used 1 times

Defined variables

sccsid defined in line 21; never used
Last modified: 1990-06-02
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1137
Valid CSS Valid XHTML 1.0 Strict