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