|
|
1.1 root 1: /* For debugging, read ASCII numbers on stdin, write them in
2: * compressed and expanded form on stdout. Numbers without
3: * a decimal point are taken to be unsigned integers.
4: */
5:
6: #include <stdio.h>
7:
8: char *
9: nonbln(s)
10: char *s;
11: {
12: char c;
13: if (s)
14: for(; c = *s; s++)
15: if (c > ' ') return s;
16: return 0;
17: }
18:
19: char *
20: nextbln(s)
21: char *s;
22: {
23: while(*s > ' ') s++;
24: return s;
25: }
26:
27: char *
28: Alloc(n)
29: int n;
30: {
31: extern char *malloc();
32: register char *rv;
33: rv = malloc(n);
34: if (!rv) {
35: fprintf(stderr, "malloc(%d) failure!\n", n);
36: exit(1);
37: }
38: return rv;
39: }
40:
41: fatal(msg)
42: char *msg;
43: {
44: fprintf(stderr, "*** %s ***\n", msg);
45: exit(1);
46: }
47:
48: static char *memlast;
49:
50: char *
51: mem(n)
52: int n;
53: {
54: static char buf[512];
55: if (n > sizeof(buf)) {
56: fprintf(stderr, "mem(%d) failure!\n", n);
57: exit(1);
58: }
59: memlast = buf+n;
60: memset(buf, '?', n);
61: return buf;
62: }
63:
64: main()
65: {
66: char buf[1024], c, *s, *s1, *z;
67: extern char *cds();
68:
69: while(s = fgets(buf,sizeof(buf),stdin)) {
70: while(s = nonbln(s)) {
71: s1 = nextbln(s);
72: c = *s1;
73: *s1 = 0;
74: z = cds(s,0);
75: *memlast = '?';
76: printf("%s --> %s (len %d)\n",
77: s, z, strlen(z));
78: if (memlast[-1])
79: printf("expected memlast[-1] = 0, but got %c\n",
80: memlast[-1]);
81: if (z[0] != '-' && z[-1] != '-')
82: printf("z[0] = %c, z[-1] = %c, and neither is -\n",
83: z[0],z[-1]);
84: *s1 = c;
85: s = s1;
86: }
87: }
88: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.