|
|
1.1 root 1: static char *sccsid = "@(#)cmdline.c 2.6";
2:
3: #include <stdio.h>
4: #include "cdb.h"
5:
6: extern char *gets();
7:
8: FILE *vfpRecord, *vfpPlayback; /* not every file has <stdio.h> */
9: export int vcStepPlayback;
10: export FLAGT vfRecord;
11:
12: #define chEOF 04 /* a ^D */
13: #define cbSbCmd 200 /* max command length */
14: #define cbSbQuery 20 /* max query (Yes/No) length */
15:
16: /* this file contains the routines that read the commnad line from the TTY and
17: * maintain the record & playback files.
18: * TkNext(), in tk.c, the tokenizer, is what most routines call to actually get
19: * something from the current command line.
20: */
21:
22:
23: /* N E X T C M D */
24:
25: local void NextCmd(sbCmd, cbCmd, sbPrompt)
26: char *sbCmd, *sbPrompt;
27: int cbCmd;
28: {
29: FLAGT fDoit;
30: char *sbT, *sbT2;
31: char sbQuery[cbSbQuery];
32:
33: if (sbPrompt != sbNil AND *sbPrompt != chNull)
34: printf(sbPrompt);
35: while (vfpPlayback != NULL) {
36: sbT = fgets(sbCmd, cbCmd, vfpPlayback);
37: if ((sbT2 = strrchr(sbCmd, '\n')) != NULL)
38: *sbT2 = chNull; /* step on new-line */
39: if ((vcStepPlayback == 0)
40: OR (--vcStepPlayback > 0)) {
41: if (sbT != sbNil)
42: printf("%s\n", sbCmd);
43: }
44: else { /* we are doing playback stepping */
45: if (sbT != sbNil) {
46: printf("%s (<cr>, <#>, C, Q, S or ?): ", sbT);
47: fDoit = false;
48: while (!fDoit) {
49: gets(sbQuery);
50: fDoit = true;
51: switch (*sbQuery) {
52: case 'Q':
53: fclose(vfpPlayback);
54: sbT = sbNil;
55: if ((sbPrompt != sbNil)
56: AND (*sbPrompt != chNull))
57: printf(sbPrompt);
58: /* and fall through */
59: case 'S':
60: vcStepPlayback = 1;
61: goto contMainLoop;
62: break;
63: case 'C':
64: vcStepPlayback = 0;
65: break;
66: case chNull:
67: vcStepPlayback = 1;
68: break;
69: case '?':
70: printf("<cr> executes THIS command line,\n");
71: printf("<#> does that number of command lines,\n");
72: printf("S skips this command,\n");
73: printf("Q quits playback mode,\n");
74: printf("C continues until the end of ALL playback files.\n");
75: fDoit = false;
76: break;
77: case '0':
78: case '1':
79: case '2':
80: case '3':
81: case '4':
82: case '5':
83: case '6':
84: case '7':
85: case '8':
86: case '9':
87: vcStepPlayback = atoi(sbQuery);
88: break;
89: default:
90: fDoit = false;
91: } /* switch */
92: } /* while */
93: } /* if */
94: } /* if */
95: if (sbT != sbNil) {
96: return;
97: }
98: else {
99: fclose(vfpPlayback);
100: vfpPlayback = NULL;
101: /* and fall into `from the TTY code ' */
102: } /* if */
103: break;
104: contMainLoop:
105: ;
106: } /* while */
107:
108: /* there is no playback file, read from terminal */
109: sbT = gets(sbCmd);
110: if (sbT == sbNil) {
111: sbCmd[0] = chNull;
112: }
113: else if (*sbT == chNull) {
114: sbT[0] = '~';
115: sbT[1] = chNull;
116: } /* if */
117: } /* NextCmd */
118:
119:
120: /* R E C O R D C M D */
121:
122: local void RecordCmd(sbCmd)
123: char *sbCmd;
124: {
125: if ( vfRecord
126: AND (vfpRecord != NULL)
127: AND (*sbCmd != '!')
128: AND (*sbCmd != '>')
129: AND (*sbCmd != '<') ) {
130: fprintf(vfpRecord, "%s\n", sbCmd); /* make a recording */
131: } /* if */
132: } /* RecordCmd */
133:
134:
135: /* Y E S N O */
136:
137: export int YesNo(sbPrompt)
138: char *sbPrompt;
139: {
140: char sbAnswer[cbSbQuery];
141:
142: NextCmd(sbAnswer, cbSbQuery, sbPrompt);
143: RecordCmd(sbAnswer);
144: return(sbAnswer[0] == 'y' OR sbAnswer[0] == 'Y');
145: } /* YesNo */
146:
147:
148: /* S E T P L A Y B A C K */
149:
150: local void SetPlayback(sbPlayback, fSinglestep)
151: char *sbPlayback;
152: FLAGT fSinglestep;
153: {
154: FILE *fpTemp;
155:
156: if (vfpPlayback != NULL)
157: fclose(vfpPlayback);
158: if ((sbPlayback == sbNil) OR (*sbPlayback == chNull))
159: UError("No playback name specified");
160: if ((fpTemp = fopen(sbPlayback, "r")) == NULL)
161: UError("Can't open %s as playback file", sbPlayback);
162: printf("Playing back from %s\n", sbPlayback);
163: vfpPlayback = fpTemp;
164: vcStepPlayback = (fSinglestep) ? 1 : 0;
165: } /* SetPlayback */
166:
167:
168: /* S E T R E C O R D */
169:
170: local void SetRecord(sbRecord)
171: char *sbRecord;
172: {
173: FILE *fpTemp;
174:
175: if (vfpRecord != NULL) {
176: printf("Closing record file\n");
177: fclose(vfpRecord);
178: vfRecord = false;
179: vfpRecord = NULL;
180: } /* if */
181: if ((sbRecord == sbNil) OR (*sbRecord == chNull))
182: return;
183: if ((fpTemp = fopen(sbRecord, "w+")) == NULL)
184: UError("Can't open %s as record file", sbRecord);
185: vfRecord = true;
186: vfpRecord = fpTemp;
187: printf("Recording is ON, going to %s\n", sbRecord);
188: } /* SetRecord */
189:
190:
191: /* S T A T E R E C O R D */
192:
193: local void StateRecord(fOn)
194: FLAGT fOn;
195: {
196: vfRecord = fOn;
197: printf("Recording is %s\n", (vfRecord) ? "ON" : "OFF");
198: if ((vfRecord)
199: AND (vfpRecord == NULL))
200: UError("WARNING: no record file is open");
201: } /* StateRecord */
202:
203:
204: /* S H O W S T A T E */
205:
206: local void ShowState()
207: {
208: printf("Debugging %s, %d files %d procedures\n",
209: vsbSymfile, vifdMac-3, vipdMac-1);
210: if (vfnCore != fnNil)
211: printf("Core file is %s\n", vsbCorefile);
212: else
213: printf("No core file\n");
214: if (vpid != pidNil)
215: printf("There is an active child process, #%d\n", vpid);
216: else
217: printf("No active child process\n");
218: if (viadMac == 0)
219: printf("No assertions.\n");
220: else if (vas == asSuspended)
221: printf("Assertions are suspended.\n");
222: else
223: printf("%d assertions are active.\n", viadMac);
224: StateRecord(vfRecord);
225: printf("Searches are %scase sensitive\n",
226: (vcaseMod!=0) ? "NOT " : "");
227: } /* ShowState */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.