ide_main.c
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Interactive Diagnostic Environment Command Line Interpreter
*
*/
#include <stdio.h>
#include "signal.h"
#include "ide.h"
#include <getopt.h>
int goteof = 0;
extern char yyinbuff[];
extern int yyinlen;
extern int yyinbp;
extern char ide_startup[];
extern int inloop; /* semantic feedback: the parser is inside a loop */
extern int inblock; /* ditto for block {} */
extern int inswitch; /* ditto for switch */
extern int inif; /* ditto for if */
extern int ide_dosource;
char *ide_pstartup = ide_startup;
char *ide_sname;
int ide_cancelstartup;
jmp_buf intr_jump;
void onsigint();
static void (* ide_clean)(void) = 0;
void ide_set_clean(void (* user_clean)(void))
{
ide_clean = user_clean;
}
main(argc,argv)
int argc;
char *argv[];
{
int val;
ide_init();
init_context(argc,argv);
if (argc == 1) {
sigset(SIGINT,onsigint);
if (val = setjmp(intr_jump)) {
/*
* Reset the global optind, in case the test
* used getopt() to parse its option arguments.
*
* We would ordinarily do this when the test exited
* cleanly, but we need to do it here in case the user
* aborted the test with an interrupt (e.g. ctrl-c).
*/
optind = 1;
if ((val == 1) && (ide_clean)) ide_clean();
printf("\n<Stopped>\n");
ide_cancelstartup = 1;
yyinlen = 0;
handle_interrupt();
sigrelse(SIGINT);
}
}
while ( ! goteof )
yyparse();
putchar('\n');
_doexit(0);
}
/*
* Get input from somewhere
*
* ide supports three different types of input:
* 1. From a startup script linked in at compile time
* 2. From the keyboard
* 3. From a remote device via the "source" command
*
*/
int
ide_refill()
{
if ( !ide_cancelstartup && *ide_pstartup ) {
ide_sname = "startup script";
if ( (yyinlen = strlen(ide_pstartup)) >= MAXLINELEN )
strncpy(yyinbuff,ide_pstartup, yyinlen = MAXLINELEN-1 );
else
strcpy( yyinbuff, ide_pstartup );
ide_pstartup += yyinlen;
} else {
if ( !(ide_dosource && (yyinlen = getsfromsource(yyinbuff))) ) {
ide_sname = 0;
if ( inloop || inswitch || inblock || inif ) {
sym_t *psym = findsym("PS2");
if ( psym )
ide_puts(psym->sym_s);
else
ide_puts("> ");
} else {
sym_t *psym = findsym("PS1");
if ( psym )
ide_puts(psym->sym_s);
else
ide_puts("! ");
}
#ifdef __sgi__
if ( ! gets(yyinbuff) )
#else
if ( ! fgets(yyinbuff, MAXLINELEN, stdin) )
#endif
return EOF;
yyinlen = strlen(yyinbuff);
yyinbuff[yyinlen++] = '\n';
}
}
yyinbp = 0;
yyinbuff[yyinlen] = '\0';
return yyinbuff[yyinbp++];
}
void
onsigint()
{
longjmp(intr_jump, 1);
}