Commit | Line | Data |
---|---|---|
196ba1fc PH |
1 | *** ../simhv38/scp.c 2008-06-01 15:59:14.000000000 +0200 |
2 | --- scp.c 2008-09-19 16:55:57.000000000 +0200 | |
3 | *************** | |
4 | *** 169,188 **** | |
5 | --- 169,192 ---- | |
6 | 13-Apr-95 RMS Added symbolic printouts\r | |
7 | */\r | |
8 | \r | |
9 | /* Macros and data structures */\r | |
10 | \r | |
11 | #include "sim_defs.h"\r | |
12 | #include "sim_rev.h"\r | |
13 | #include <signal.h>\r | |
14 | #include <ctype.h>\r | |
15 | \r | |
16 | + #ifdef HAVE_READLINE\r | |
17 | + #include <sim_readline.h>\r | |
18 | + #endif\r | |
19 | + \r | |
20 | #define EX_D 0 /* deposit */\r | |
21 | #define EX_E 1 /* examine */\r | |
22 | #define EX_I 2 /* interactive */\r | |
23 | #define SCH_OR 0 /* search logicals */\r | |
24 | #define SCH_AND 1\r | |
25 | #define SCH_XOR 2\r | |
26 | #define SCH_E 0 /* search booleans */\r | |
27 | #define SCH_N 1\r | |
28 | #define SCH_G 2\r | |
29 | #define SCH_L 3\r | |
30 | *************** | |
31 | *** 572,591 **** | |
32 | --- 576,599 ---- | |
33 | /* Main command loop */\r | |
34 | \r | |
35 | int main (int argc, char *argv[])\r | |
36 | {\r | |
37 | char cbuf[CBUFSIZE], gbuf[CBUFSIZE], *cptr;\r | |
38 | int32 i, sw;\r | |
39 | t_bool lookswitch;\r | |
40 | t_stat stat;\r | |
41 | CTAB *cmdp;\r | |
42 | \r | |
43 | + #ifdef HAVE_READLINE\r | |
44 | + readline_read_history();\r | |
45 | + #endif\r | |
46 | + \r | |
47 | #if defined (__MWERKS__) && defined (macintosh)\r | |
48 | argc = ccommand (&argv);\r | |
49 | #endif\r | |
50 | \r | |
51 | *cbuf = 0; /* init arg buffer */\r | |
52 | sim_switches = 0; /* init switches */\r | |
53 | lookswitch = TRUE;\r | |
54 | for (i = 1; i < argc; i++) { /* loop thru args */\r | |
55 | if (argv[i] == NULL) continue; /* paranoia */\r | |
56 | if ((*argv[i] == '-') && lookswitch) { /* switch? */\r | |
57 | *************** | |
58 | *** 649,695 **** | |
59 | else if (*argv[0]) { /* sim name arg? */\r | |
60 | char nbuf[PATH_MAX + 7], *np; /* "path.ini" */\r | |
61 | nbuf[0] = '"'; /* starting " */\r | |
62 | strncpy (nbuf + 1, argv[0], PATH_MAX + 1); /* copy sim name */\r | |
63 | if (np = match_ext (nbuf, "EXE")) *np = 0; /* remove .exe */\r | |
64 | strcat (nbuf, ".ini\""); /* add .ini" */\r | |
65 | stat = do_cmd (-1, nbuf); /* proc cmd file */\r | |
66 | }\r | |
67 | \r | |
68 | while (stat != SCPE_EXIT) { /* in case exit */\r | |
69 | ! printf ("sim> "); /* prompt */\r | |
70 | if (cptr = sim_brk_getact (cbuf, CBUFSIZE)) /* pending action? */\r | |
71 | ! printf ("%s\n", cptr); /* echo */\r | |
72 | else if (sim_vm_read != NULL) /* sim routine? */\r | |
73 | cptr = (*sim_vm_read) (cbuf, CBUFSIZE, stdin);\r | |
74 | ! else cptr = read_line (cbuf, CBUFSIZE, stdin); /* read command line */\r | |
75 | ! if (cptr == NULL) continue; /* ignore EOF */\r | |
76 | ! if (*cptr == 0) continue; /* ignore blank */\r | |
77 | if (sim_log) fprintf (sim_log, "sim> %s\n", cptr); /* log cmd */\r | |
78 | cptr = get_glyph (cptr, gbuf, 0); /* get command glyph */\r | |
79 | sim_switches = 0; /* init switches */\r | |
80 | if (cmdp = find_cmd (gbuf)) /* lookup command */\r | |
81 | stat = cmdp->action (cmdp->arg, cptr); /* if found, exec */\r | |
82 | else stat = SCPE_UNK;\r | |
83 | if (stat >= SCPE_BASE) { /* error? */\r | |
84 | printf ("%s\n", scp_error_messages[stat - SCPE_BASE]);\r | |
85 | if (sim_log) fprintf (sim_log, "%s\n",\r | |
86 | scp_error_messages[stat - SCPE_BASE]);\r | |
87 | }\r | |
88 | if (sim_vm_post != NULL) (*sim_vm_post) (TRUE);\r | |
89 | } /* end while */\r | |
90 | \r | |
91 | detach_all (0, TRUE); /* close files */\r | |
92 | sim_set_deboff (0, NULL); /* close debug */\r | |
93 | sim_set_logoff (0, NULL); /* close log */\r | |
94 | sim_set_notelnet (0, NULL); /* close Telnet */\r | |
95 | sim_ttclose (); /* close console */\r | |
96 | return 0;\r | |
97 | }\r | |
98 | \r | |
99 | /* Find command routine */\r | |
100 | \r | |
101 | CTAB *find_cmd (char *gbuf)\r | |
102 | {\r | |
103 | CTAB *cmdp = NULL;\r | |
104 | \r | |
105 | if (sim_vm_cmd) cmdp = find_ctab (sim_vm_cmd, gbuf); /* try ext commands */\r | |
106 | --- 657,720 ---- | |
107 | else if (*argv[0]) { /* sim name arg? */\r | |
108 | char nbuf[PATH_MAX + 7], *np; /* "path.ini" */\r | |
109 | nbuf[0] = '"'; /* starting " */\r | |
110 | strncpy (nbuf + 1, argv[0], PATH_MAX + 1); /* copy sim name */\r | |
111 | if (np = match_ext (nbuf, "EXE")) *np = 0; /* remove .exe */\r | |
112 | strcat (nbuf, ".ini\""); /* add .ini" */\r | |
113 | stat = do_cmd (-1, nbuf); /* proc cmd file */\r | |
114 | }\r | |
115 | \r | |
116 | while (stat != SCPE_EXIT) { /* in case exit */\r | |
117 | ! \r | |
118 | if (cptr = sim_brk_getact (cbuf, CBUFSIZE)) /* pending action? */\r | |
119 | ! printf ("sim> %s\n", cptr); /* echo */\r | |
120 | else if (sim_vm_read != NULL) /* sim routine? */\r | |
121 | cptr = (*sim_vm_read) (cbuf, CBUFSIZE, stdin);\r | |
122 | ! \r | |
123 | ! else\r | |
124 | ! #ifdef HAVE_READLINE\r | |
125 | ! cptr = readline_read_line(cbuf,CBUFSIZE,"sim>");\r | |
126 | ! #else\r | |
127 | ! printf("sim>");\r | |
128 | ! cptr = read_line (cbuf, CBUFSIZE, stdin); /* read command line */\r | |
129 | ! #endif\r | |
130 | ! if (cptr == NULL){ /* ignore EOF */\r | |
131 | ! printf("\r");\r | |
132 | ! continue;\r | |
133 | ! }\r | |
134 | ! if (*cptr == 0) continue; /* ignore blank */\r | |
135 | ! \r | |
136 | if (sim_log) fprintf (sim_log, "sim> %s\n", cptr); /* log cmd */\r | |
137 | cptr = get_glyph (cptr, gbuf, 0); /* get command glyph */\r | |
138 | sim_switches = 0; /* init switches */\r | |
139 | if (cmdp = find_cmd (gbuf)) /* lookup command */\r | |
140 | stat = cmdp->action (cmdp->arg, cptr); /* if found, exec */\r | |
141 | else stat = SCPE_UNK;\r | |
142 | if (stat >= SCPE_BASE) { /* error? */\r | |
143 | printf ("%s\n", scp_error_messages[stat - SCPE_BASE]);\r | |
144 | if (sim_log) fprintf (sim_log, "%s\n",\r | |
145 | scp_error_messages[stat - SCPE_BASE]);\r | |
146 | }\r | |
147 | if (sim_vm_post != NULL) (*sim_vm_post) (TRUE);\r | |
148 | } /* end while */\r | |
149 | \r | |
150 | detach_all (0, TRUE); /* close files */\r | |
151 | sim_set_deboff (0, NULL); /* close debug */\r | |
152 | sim_set_logoff (0, NULL); /* close log */\r | |
153 | sim_set_notelnet (0, NULL); /* close Telnet */\r | |
154 | sim_ttclose (); /* close console */\r | |
155 | + \r | |
156 | + /* Write command history back to file */\r | |
157 | + #ifdef HAVE_READLINE\r | |
158 | + readline_write_history();\r | |
159 | + #endif\r | |
160 | + \r | |
161 | return 0;\r | |
162 | }\r | |
163 | \r | |
164 | /* Find command routine */\r | |
165 | \r | |
166 | CTAB *find_cmd (char *gbuf)\r | |
167 | {\r | |
168 | CTAB *cmdp = NULL;\r | |
169 | \r | |
170 | if (sim_vm_cmd) cmdp = find_ctab (sim_vm_cmd, gbuf); /* try ext commands */\r | |
171 | *************** | |
172 | *** 3068,3091 **** | |
173 | for (tptr = cptr; tptr < (cptr + size); tptr++) { /* remove cr or nl */\r | |
174 | if ((*tptr == '\n') || (*tptr == '\r') ||\r | |
175 | (tptr == (cptr + size - 1))) { /* str max length? */\r | |
176 | *tptr = 0; /* terminate */\r | |
177 | break;\r | |
178 | }\r | |
179 | }\r | |
180 | while (isspace (*cptr)) cptr++; /* trim leading spc */\r | |
181 | if (*cptr == ';') *cptr = 0; /* ignore comment */\r | |
182 | \r | |
183 | - #if defined (HAVE_READLINE)\r | |
184 | - add_history (cptr);\r | |
185 | \r | |
186 | - #endif\r | |
187 | return cptr;\r | |
188 | }\r | |
189 | \r | |
190 | /* get_glyph get next glyph (force upper case)\r | |
191 | get_glyph_nc get next glyph (no conversion)\r | |
192 | get_glyph_gen get next glyph (general case)\r | |
193 | \r | |
194 | Inputs:\r | |
195 | iptr = pointer to input string\r | |
196 | optr = pointer to output string\r | |
197 | --- 3093,3113 ---- |