Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 208 lines (179 sloc) 5.334 kb
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
1 /* elvdump.c */
2 /* Copyright 1995 by Steve Kirkendall */
3
4
5 /* This file contains a replacement for elvis' main() function. The resulting
6 * program will test each component of elvis.
7 */
8
9 #include "elvis.h"
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
10 #ifdef FEATURE_RCSID
11 char id_elvdump[] = "$Id: elvdump.c,v 1.11 2003/10/17 17:41:23 steve Exp $";
12 #endif
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
13
14 #ifdef FEATURE_COMPLETE
15 # error You must #undef FEATURE_COMPLETE in config.h to compile this program
16 #endif
17
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
18 extern void dump(char *bufname, ELVBOOL useronly);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
19
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
20 /* support for elvis' ctype macros */
21 #ifdef ELVCT_DIGIT
22 CHAR elvct_class[256] = {
23 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
24 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
25 ELVCT_DIGIT,ELVCT_DIGIT,ELVCT_DIGIT,ELVCT_DIGIT,ELVCT_DIGIT,
26 ELVCT_DIGIT,ELVCT_DIGIT,ELVCT_DIGIT,ELVCT_DIGIT,ELVCT_DIGIT,
27 0,0,0,0,0,0,0,
28 ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,
29 ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,
30 ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,
31 ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,
32 ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,ELVCT_UPPER,
33 ELVCT_UPPER,
34 0,0,0,0,0,0,
35 ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,
36 ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,
37 ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,
38 ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,
39 ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,ELVCT_LOWER,
40 ELVCT_LOWER
41 };
42 #endif
43
44 static GUI nogui;
45 GUI *chosengui = &nogui;
46 GUI *gui = &nogui;
47
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
48 ELVBOOL guipoll(ELVBOOL reset)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
49 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
50 return ElvFalse;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
51 }
52
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
53 void msg(MSGIMP imp, char *format, ...)
54 {
55 fprintf(stderr, "%s\n", format);
56 }
57
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
58 CHAR *msgtranslate(char *msg)
59 {
60 return toCHAR(msg);
61 }
62
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
63 ELVBOOL calcnumber(CHAR *arg)
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
64 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
65 return ElvFalse;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
66 }
67
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
68 ELVBOOL calctrue(CHAR *arg)
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
69 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
70 return ElvFalse;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
71 }
72
73 WINDOW windefault;
74 WINDOW winofbuf(WINDOW window, BUFFER buffer)
75 {
76 return windefault;
77 }
78
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
79 void bufreplace(MARK from, MARK to, CHAR *newp, long newlen)
80 {
81 }
82
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
83 void dump(char *bufname, ELVBOOL useronly)
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
84 {
85 BLK *super;
86 BLK *bufinfo;
87 BLK *blklist;
88 BLK *chars;
89 BLKNO blkno, next;
90 int i, j;
91
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
92 sesopen(ElvTrue);
93 seslock(0, ElvFalse, SES_SUPER);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
94 super = sesblk(0);
95 for (i = 0; i < SES_MAXSUPER; i++)
96 {
97 /* skip empty buffer slots */
98 if (!super->super.buf[i])
99 {
100 continue;
101 }
102
103 /* read the bufinfo block */
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
104 sesalloc(super->super.buf[i], SES_BUFINFO);
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
105 seslock(super->super.buf[i], ElvFalse, SES_BUFINFO);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
106 bufinfo = sesblk(super->super.buf[i]);
107
108 /* skip if "-u" and this isn't a user buffer */
109 if (useronly && !strncmp(bufinfo->bufinfo.name, "Elvis ", 6))
110 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
111 sesunlock(super->super.buf[i], ElvFalse);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
112 continue;
113 }
114
115 /* output buffer name, unless we're supposed to list contents */
116 if (!bufname)
117 printf("%6d bufinfo, bufname=\"%s\", changes=%ld\n",
118 super->super.buf[i],
119 bufinfo->bufinfo.name,
120 bufinfo->bufinfo.changes);
121
122 /* if "-u" and we don't have a buffer name, then we're done */
123 if (useronly && !bufname)
124 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
125 sesunlock(super->super.buf[i], ElvFalse);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
126 continue;
127 }
128
129 /* for each blklist block... */
130 for (blkno = bufinfo->bufinfo.first; blkno; blkno = next)
131 {
132 if (!bufname) printf("%6d blklist for #%d\n", blkno, super->super.buf[i]);
133
134 /* read the blklist block */
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
135 sesalloc(blkno, SES_BLKLIST);
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
136 seslock(blkno, ElvFalse, SES_BLKLIST);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
137 blklist = sesblk(blkno);
138
139 /* for each chars block... */
140 for (j = 0; j < SES_MAXBLKLIST && blklist->blklist.blk[j].blkno; j++)
141 {
142 if (!bufname) printf("%6d chars #%d[%d], chars=%d, lines=%d\n",
143 blklist->blklist.blk[j].blkno,
144 blkno,
145 j,
146 blklist->blklist.blk[j].nchars,
147 blklist->blklist.blk[j].nlines);
148 if (bufname && !strcmp(bufname, bufinfo->bufinfo.name))
149 {
150 /* read the chars block & output its contents */
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
151 sesalloc(blklist->blklist.blk[j].blkno, SES_CHARS);
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
152 seslock(blklist->blklist.blk[j].blkno, ElvFalse, SES_CHARS);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
153 chars = sesblk(blklist->blklist.blk[j].blkno);
154 fwrite(chars->chars.chars, blklist->blklist.blk[j].nchars, sizeof(CHAR), stdout);
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
155 sesunlock(blklist->blklist.blk[j].blkno, ElvFalse);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
156 }
157 }
158
159 /* release the blklist block */
160 next = blklist->blklist.next;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
161 sesunlock(blkno, ElvFalse);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
162 }
163
164 /* release the bufinfo block */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
165 sesunlock(super->super.buf[i], ElvFalse);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
166 }
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
167 sesunlock(0, ElvFalse);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
168 sesclose();
169 }
170
171 int main(int argc, char **argv)
172 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
173 ELVBOOL useronly = ElvFalse;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
174
175 optglobinit();
176 if (argc >= 2 && !strcmp(argv[1], "-u"))
177 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
178 useronly = ElvTrue;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
179 argv++;
180 argc--;
181 }
182 if (argc == 1)
183 dump(NULL, useronly);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
184 else if (argc == 2 && argv[1][0] != '-')
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
185 {
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
186 o_session = toCHAR(argv[1]);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
187 dump(NULL, useronly);
188 }
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
189 else if (argc == 3 && argv[1][0] != '-')
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
190 {
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
191 o_session = toCHAR(argv[1]);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
192 dump(argv[2], useronly);
193 }
194 else
195 {
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
196 printf("Usage: elvdump [-u] [session [buffer]]\n");
197 printf("When invoked with a session file name and a buffer name, elvdump\n");
198 printf("will write the text of all versions of that buffer to stdout.\n");
199 printf("When invoked with just a session file name, it will describe\n");
200 printf("the block usage for each buffer in the file (or, with -h, only\n");
201 printf("the user buffers). When invoked with no arguments, it will\n");
202 printf("open an anonymous session file and describe its block usage.\n");
203
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
204 exit(1);
205 }
206 exit(0);
207 }
Something went wrong with that request. Please try again.