ucsim-0.2.37-pre3 into cvs
[fw/sdcc] / sim / ucsim / s51.src / cmd51.cc
1 /*
2  * Simulator of microcontrollers (cmd51.cc)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING.  If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
27
28 #include "ddconfig.h"
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include "i_string.h"
33
34 #include "globals.h"
35
36 #include "cmd51cl.h"
37
38
39 /*
40  * Special console for s51 it uses old version of the command interpreter
41  */
42
43 cl_51cons::cl_51cons(char *fin, char *fout, class cl_sim *asim):
44   cl_console(fin, fout, asim)
45 {}
46
47 cl_51cons::cl_51cons(FILE *fin, FILE *fout, class cl_sim *asim):
48   cl_console(fin, fout, asim)
49 {}
50
51 #ifdef SOCKET_AVAIL
52 cl_51cons::cl_51cons(int portnumber, class cl_sim *asim):
53   cl_console(portnumber, asim)
54 {}
55 #endif
56
57 int
58 cl_51cons::proc_input(void)
59 {
60   return(cl_console::proc_input());
61   /*char *cmd= read_line();
62   if (!cmd)
63     return(1);
64   int retval= interpret(cmd);
65   prompt();
66   free(cmd);
67   return(retval);*/
68 }
69
70 bool
71 cl_51cons::interpret(char *cmd)
72 {
73   int i;
74   char *c, *s;
75   bool repeat= FALSE, retval= FALSE;
76   
77   if (*cmd)
78     {
79       c= strdup(cmd);
80       if (last_command)
81         free(last_command);
82       last_command= strdup(cmd);
83     }
84   else
85     if (last_command == NULL)
86       return(FALSE);
87     else
88       {
89         c= strdup(last_command);
90         repeat= TRUE;
91       }
92   i= 0;
93   s= strtok(c, delimiters);
94   while ((cmd_table[i].name != NULL) &&
95          /*(strstr(c, cmd_table[i].name) != c)*/
96          (strcmp(s, cmd_table[i].name) != 0))
97     i++;
98   if (cmd_table[i].name == NULL)
99     {
100       fprintf(sim->cmd_out(), "Unknown command.\n");
101       if (last_command)
102         {
103           free(last_command);
104           last_command= NULL;
105         }
106     }
107   else
108     {
109       if (!repeat)
110         retval= cmd_table[i].func(c, sim->uc, sim);
111       else
112         if (cmd_table[i].can_repeat)
113           retval= cmd_table[i].func(c, sim->uc, sim);
114     }
115   free(c);
116   return(retval);
117 }
118
119 bool
120 cl_51cons::old_command(class cl_cmdline *cmdline)
121 {
122   int i= 0;
123
124   if (cmdline->name == 0 ||
125       *(cmdline->name) == '\0' ||
126       *(cmdline->name) == '\n')
127     return(TRUE);
128   while ((cmd_table[i].name != NULL) &&
129          /*(strstr(c, cmd_table[i].name) != c)*/
130          (strcmp(cmdline->name, cmd_table[i].name) != 0))
131     i++;
132   return(cmd_table[i].name != NULL);
133 }
134
135
136 /*
137  * Special commander for s51 it uses special console
138  */
139
140 cl_51cmd::cl_51cmd(class cl_sim *asim):
141   cl_commander(asim)
142 {}
143
144 class cl_console *
145 cl_51cmd::mk_console(char *fin, char *fout, class cl_sim *asim)
146 {
147   return(new cl_51cons(fin, fout, asim));
148 }
149
150 class cl_console *
151 cl_51cmd::mk_console(FILE *fin, FILE *fout, class cl_sim *asim)
152 {
153   return(new cl_51cons(fin, fout, asim));
154 }
155
156
157 /* End of s51.src/cmd51.cc */