|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /*
25: * Standard buffer dump/compare library.
26: */
27:
28: #import <bsd/sys/types.h>
29: #import <bsd/libc.h>
30: #import "buflib.h"
31:
32: int buf_comp(int size, u_char *wbuf, u_char *rbuf)
33: {
34: /* verify wbuf == rbuf for size bytes */
35:
36: register int i;
37: char inch;
38: int bufad;
39: u_char *bp;
40:
41: for(i=0; i<size; i++) {
42: if(wbuf[i] != rbuf[i]) {
43: printf("***DATA ERROR***\n");
44: printf("byte %XH\n",i);
45: printf("Expected data = %02XH Received = %02XH\n",
46: wbuf[i],rbuf[i]);
47: while(1) {
48: printf("More (m), buffer dump (d), quit (q))? ");
49: inch = getchar();
50: getchar();
51: switch(inch) {
52: case 'q':
53: return(1);
54: case 'm':
55: goto next_int;
56: case 'd':
57: printf("Which buffer (r/w)? ");
58: inch = getchar();
59: getchar();
60: switch(inch) {
61: case 'r':
62: bp = rbuf;
63: break;
64: case 'w':
65: bp = wbuf;
66: break;
67: default:
68: printf("Huh??\n");
69: continue;
70: }
71: printf("Enter buffer address: ");
72: bufad = get_num(0, 16);
73: dump_buf((u_char *)&bp[bufad], size);
74: break;
75: }
76: }
77: next_int:
78: continue;
79: }
80: }
81: return(0);
82: } /* buf_comp() */
83:
84: int get_num(int deflt,
85: int base) /* HEX or DEC, user can override with 'x' or
86: * '0x' */
87: {
88: char x_bad=0;
89: int digit;
90: char inch;
91: int first_char=1;
92: int result;
93:
94: /*
95: * returns new number, if a legal one entered, else 'deflt'.
96: * Radix assumes to be 'base'; can be overridden by leading
97: * '0x'.
98: */
99:
100: result = 0;
101: while(1) {
102: inch = getchar();
103: if(inch == '\n') {
104: if(first_char) {
105: result = deflt;
106: return(result);
107: }
108: else
109: return(result);
110: }
111: first_char = 0;
112: if(inch == 'x') {
113: if(x_bad)
114: goto nullret;
115: else {
116: base = HEX;
117: x_bad++;
118: }
119: }
120: else {
121: if((inch >= '0') && (inch <= '9'))
122: digit = inch - '0';
123: else {
124: inch |= 0x20; /* make lower case */
125: if((inch >= 'a') && (inch <= 'f')) {
126: if(base != HEX) /* hex OK? */
127: goto nullret;
128: }
129: else
130: goto nullret; /* illegal char */
131: digit = (inch - 'a') + 10;
132: }
133: if(digit>0)
134: x_bad++;
135: result *= base;
136: result += digit;
137: }
138: }
139:
140: nullret:
141: while(getchar() != '\n')
142: ;
143: return(deflt);
144:
145: } /* get_num() */
146:
147:
148: void dump_buf(u_char *buf, int size) {
149:
150: int i;
151: char c[100];
152:
153: printf("\n");
154: for(i=0; i<size; i++) {
155: if((i>0) && (i%0x100 == 0)) {
156: printf("\n...More? (y/anything) ");
157: gets(c);
158: if(c[0] != 'y')
159: return;
160: }
161: if(i%0x10 == 0)
162: printf("\n %03X: ",i);
163: else if(i%8 == 0)
164: printf(" ");
165: printf("%02X ",buf[i]);
166: }
167: printf("\n");
168: } /* dump_buf() */
169:
170: /*
171: * Get default values from environment (first choice) or specified default.
172: */
173: void get_default(char *name,
174: u_int *value,
175: u_int deflt)
176: {
177: char *ep;
178:
179: ep = getenv(name);
180: if(ep)
181: *value = atoi(ep);
182: else
183: *value = deflt;
184: }
185:
186:
187: void get_default_t(char *name,
188: char **value,
189: char *deflt)
190: {
191: char *ep;
192:
193: ep = getenv(name);
194: if(ep)
195: *value = ep;
196: else
197: *value = deflt;
198: }
199:
200:
201:
202:
203:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.