1 /* ELLE - Copyright 1982, 1985, 1987 by Ken Harrenstien, SRI International
2 * This software is quasi-public; it may be used freely with
3 * like software, but may NOT be sold or made part of licensed
4 * products without permission of the author.
6 /* EEDIAG - Error diagnostics and testing routines
13 /* EFUN: "Debug Mode" */
14 /* With no arg, toggles self-checking on and off.
15 * With arg of 4 (^U), enters special debug/diagnostics mode.
20 { extern int (*vfy_vec
)(); /* In E_MAIN.C */
23 if(ch
< 0) /* Internal call? */
31 if(vfy_vec
) vfy_vec
= 0; /* Toggle current value */
32 else vfy_vec
= (int (*)())vfy_data
;
33 say(vfy_vec
? "Self-checking on" : "Self-checking off");
37 vfy_data(flag
) /* Flag = 0 for quiet check */
40 register char *res
, *mess
;
41 char *sbe_mvfy(), *sbe_sbvfy(), *sbe_svfy();
43 if(res
= sbe_mvfy(0)) mess
= "Mem mgt";
44 else if(res
= sbe_sbvfy(cur_buf
,0)) mess
= "SBBUF";
45 else if(res
= sbe_svfy(0)) mess
= "SD list";
46 else return(0); /* Success */
49 { int ostate
= clean_exit();
50 printf("\n%s error: %s !!!\n",mess
,res
);
52 if(ostate
> 0) set_tty();
54 return(res
); /* Error seen */
57 extern char *asklin();
58 extern int sbx_nfl
,sbm_nfl
;
63 V - Verify Mem & SD lists\n\
66 B - Current buffer SB\n\
69 DL - SD Logical lists\n\
70 DP - SD Physical lists\n\
71 C n - Compact; 0-7=sbx_comp(n), 8=SM freelist, 9=SD freelist.\n\
72 W - Window printout\n\
73 X n - Xercise randomly (GC every n)\n\
74 Z n - like X but with notes\n";
87 asklin(cp
= linbuf
); /* Read a line of input */
91 writez(1,diaghelp
); /* Too long for printf */
94 f_pshinf(); /* Invoke inferior subshell */
95 clean_exit(); /* Restore normal modes */
100 case 'B': /* Print current SBBUF */
104 case 'C': /* C n - Compact */
105 c
= atoi(&linbuf
[1]);
107 sbm_ngc(); /* GC the SM nodes */
108 #if 0 /* This doesn't work, dangerous to invoke. */
110 sbm_xngc(&sbx_nfl
,sizeof(struct sdblk
),
117 case 'D': /* Print all SD blocks in mem order */
120 case 0: /* D - all SDs in mem order */
123 case 'F': /* DF - SD freelist */
126 case 'L': /* DL - SD logical list */
129 case 'P': /* DP - SD physical list */
138 case 0: /* M - all mem alloc info */
141 case 'F': /* MF - mem freelist */
147 case 'V': /* Verify */
149 printf(" Failed: %s\n",cp
);
150 else printf(" OK\n");
152 case 'W': /* Print out current window */
155 case 'X': /* Xercise */
156 c
= atoi(&linbuf
[1]);
157 vfy_exer(0, c
? c
: 100);
159 case 'Z': /* Zercise */
160 c
= atoi(&linbuf
[1]);
161 vfy_exer(1, c
? c
: 100);
164 } /* End of switch */
166 printf("?? Type ? for help\n");
171 /* VFY_EXER - a "random" editor exerciser. It creates a buffer,
172 * fills it with some patterned stuff, and then edits it
173 * pseudo-randomly in ways which retain the basic pattern.
174 * Frequent GC's and self-checks are done, and execution
175 * halted either when an error is seen or when typein is detected.
177 char *xer_strs
[] = {
178 "throne", "too", "sky", "fore", "fingers", "sex", "stone",
179 "010", "nazgul", "base"
184 int pf
; /* Nonzero to print notes as we go */
185 int gcfrq
; /* Frequency of GC invocation (# passes per GC) */
186 { register int i
, k
, c
;
188 char *res
, linbuf
[100];
190 struct buffer
*bfp
, *make_buf();
192 /* Clean out kill buffer first */
193 for(i
= 0; i
< KILL_LEN
; ++i
)
194 kill_push((SBSTR
*)0);
196 bfp
= make_buf("**EXORCISE**");
202 ed_sins(xer_strs
[i
%10]);
205 if(pf
) printf("Bufflen: %ld\n", e_blen());
207 /* Buffer now has stuff in it, start hacking. */
209 srand(1); /* Start random seed */
211 { if(tinwait() && (*asklin(linbuf
)))
212 { printf("Typein stop.\n");
216 printf(" Pass %ld",npass
);
217 if(npass
%gcfrq
== 0) /* Time to do a GC? */
219 i
= rand(); /* Level between 0-4 */
220 i
= (i
< 0 ? -i
: i
) % 5;
221 printf(" - GC lev %d\n", i
);
226 k
= (i
= rand())%1024;
227 if (i
&020000) k
= -k
;
228 e_igoff(k
); /* Move randomly */
229 e_gobol(); /* Get stuff to flush */
235 if(pf
) printf(" Kill %ld/ %d;", lbeg
, k
);
237 if(res
= vfy_data(0))
238 { printf("XERR after kill: %s\n",res
);
241 k
= (i
= rand())%2048;
246 if(pf
) printf(" Yank %ld;", e_dot());
247 f_unkill(); /* Yank back */
248 if(res
= vfy_data(0))
249 { printf("XERR after yank: %s\n",res
);
253 for(i
= rand()%4; i
>= 0; --i
)
254 { if(pf
) printf(" Pop;");
255 f_unkpop(); /* Do meta-Y */
256 if(res
= vfy_data(0))
257 { printf("XERR after pop: %s\n",res
);
261 if(rand()&07) /* Slowly add stuff */
262 { if(pf
) printf(" Add");
264 ed_sins(xer_strs
[rand()%10]);
266 if(res
= vfy_data(0))
267 { printf("XERR after ins: %s\n",res
);
273 /* Okay, done with this pass edits, run through the
274 * file to ensure pattern is still there
277 while((c
= e_getc()) != EOF
)
278 if(c
== LF
&& (c
= e_getc()) != EOF
)
284 { printf("XERR in pattern!\n");
289 /* User typein or error, stop. */
292 printf("Loop count = %ld\n",npass
);
295 /* DB_PRWIND(win) - Print out stuff about given window
298 register struct window
*w
;
299 { register struct scr_line
*s
;
301 char tstr
[MAXLINE
+MAXCHAR
];
304 printf("cur_dot/ %ld cur_buf/ %o cur_win/ %o\n",
305 cur_dot
, cur_buf
, cur_win
);
307 printf("Window %o:\n", w
);
308 printf(" next/ %o\n", w
->w_next
);
309 printf(" buf / %o\n", w
->w_buf
);
310 printf(" redp/ %o\n", w
->w_redp
);
312 printf(" topldot/ %ld\n", w
->w_topldot
);
313 printf(" dot / %ld\n", w
->w_dot
);
314 printf(" bmod/ %ld\n", w
->w_bmod
);
315 printf(" emod/ %ld\n", w
->w_emod
);
316 printf(" oldz/ %ld\n", w
->w_oldz
);
318 printf(" pos / %d\n", w
->w_pos
);
319 printf(" ht / %d\n", w
->w_ht
);
321 # Flags Boff Len ! Cols Line\n");
322 for(i
= w
->w_pos
; i
< w
->w_pos
+ w
->w_ht
; ++i
)
324 printf("%2d %-5.5s %6ld %3d %1d %4d ",
325 i
, db_scflgs(s
->sl_flg
), s
->sl_boff
, s
->sl_len
,
326 s
->sl_cont
, s
->sl_col
);
327 strncpy(tstr
, s
->sl_line
, MAXLINE
);
329 printf("%-40.40s\n", tstr
);
331 { printf("%26d ", s
->sl_ncol
);
332 strncpy(tstr
, s
->sl_nlin
, MAXLINE
);
333 tstr
[s
->sl_ncol
] = 0;
334 printf("%-40.40s\n", tstr
);
342 { static char retstr
[10];
346 if(flags
&SL_MOD
) *cp
++ = 'M';
347 if(flags
&SL_EOL
) *cp
++ = 'E';