1 *** ../simhv38/scp.c 2008-06-01 15:59:14.000000000 +0200
2 --- scp.c 2008-09-19 16:55:57.000000000 +0200
6 13-Apr-95 RMS Added symbolic printouts
9 /* Macros and data structures */
16 + #ifdef HAVE_READLINE
17 + #include <sim_readline.h>
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 */
26 #define SCH_E 0 /* search booleans */
33 /* Main command loop */
35 int main (int argc, char *argv[])
37 char cbuf[CBUFSIZE], gbuf[CBUFSIZE], *cptr;
43 + #ifdef HAVE_READLINE
44 + readline_read_history();
47 #if defined (__MWERKS__) && defined (macintosh)
48 argc = ccommand (&argv);
51 *cbuf = 0; /* init arg buffer */
52 sim_switches = 0; /* init switches */
54 for (i = 1; i < argc; i++) { /* loop thru args */
55 if (argv[i] == NULL) continue; /* paranoia */
56 if ((*argv[i] == '-') && lookswitch) { /* switch? */
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 */
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 */
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]);
88 if (sim_vm_post != NULL) (*sim_vm_post) (TRUE);
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 */
99 /* Find command routine */
101 CTAB *find_cmd (char *gbuf)
105 if (sim_vm_cmd) cmdp = find_ctab (sim_vm_cmd, gbuf); /* try ext commands */
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 */
116 while (stat != SCPE_EXIT) { /* in case exit */
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);
124 ! #ifdef HAVE_READLINE
125 ! cptr = readline_read_line(cbuf,CBUFSIZE,"sim>");
128 ! cptr = read_line (cbuf, CBUFSIZE, stdin); /* read command line */
130 ! if (cptr == NULL){ /* ignore EOF */
134 ! if (*cptr == 0) continue; /* ignore blank */
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]);
147 if (sim_vm_post != NULL) (*sim_vm_post) (TRUE);
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 */
156 + /* Write command history back to file */
157 + #ifdef HAVE_READLINE
158 + readline_write_history();
164 /* Find command routine */
166 CTAB *find_cmd (char *gbuf)
170 if (sim_vm_cmd) cmdp = find_ctab (sim_vm_cmd, gbuf); /* try ext commands */
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 */
180 while (isspace (*cptr)) cptr++; /* trim leading spc */
181 if (*cptr == ';') *cptr = 0; /* ignore comment */
183 - #if defined (HAVE_READLINE)
184 - add_history (cptr);
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)
195 iptr = pointer to input string
196 optr = pointer to output string