2 * Copyright © 2008 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
28 static int s51_port = 0;
29 static char *cpu = "8051";
30 static double freq = 11059200;
31 char *s51_prompt = "> ";
32 struct ccdbg *s51_dbg;
33 int s51_interrupted = 0;
36 static FILE *s51_input;
37 static FILE *s51_output;
42 fprintf(stderr, "You're doing it wrong.\n");
52 main(int argc, char **argv)
56 struct sigvec vec, ovec;
58 while ((opt = getopt(argc, argv, "PVvHhmt:X:c:r:Z:s:S:p:")) != -1) {
64 freq = strtod(optarg, &endptr);
67 if (endptr[0] != '\0') {
68 if (!strcmp(endptr, "k"))
70 else if (!strcmp(endptr, "M") )
80 s51_port = strtol(optarg, &endptr, 0);
81 if (endptr == optarg || strlen(endptr) != 0)
112 struct sockaddr_in in;
114 l = socket(AF_INET, SOCK_STREAM, 0);
119 r = setsockopt(l, SOL_SOCKET, SO_REUSEADDR, &one, sizeof (int));
121 perror("setsockopt");
124 in.sin_family = AF_INET;
125 in.sin_port = htons(s51_port);
126 in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
127 r = bind(l, (struct sockaddr *) &in, sizeof (in));
138 struct sockaddr_in client_addr;
139 socklen_t client_len = sizeof (struct sockaddr_in);
141 s = accept(l, (struct sockaddr *)
142 &client_addr, &client_len);
147 s51_input = fdopen(s, "r");
148 s51_output = fdopen(s, "w");
149 if (!s51_input || !s51_output) {
153 vec.sv_handler = SIG_IGN;
156 sigvec(SIGINT, &vec, &ovec);
158 sigvec(SIGINT, &ovec, NULL);
165 vec.sv_handler = s51_sigint;
168 sigvec(SIGINT, &vec, &ovec);
175 s51_printf(char *format, ...)
179 va_start(ap, format);
180 vfprintf(s51_output, format, ap);
182 vfprintf(stdout, format, ap);
192 #include <readline/readline.h>
193 #include <readline/history.h>
196 s51_read_line(char *line, int len)
199 if (s51_output == stdout && s51_input == stdin && s51_prompt) {
202 r = readline(s51_prompt);
205 strncpy (line, r, len);
211 s51_printf("%s", s51_prompt);
215 ret = fgets(line, len, s51_input) != NULL;
217 printf("> %s", line);
224 s51_check_input(void)
230 input.fd = fileno(s51_input);
231 input.events = POLLIN;
232 r = poll(&input, 1, 0);
235 (void) s51_read_line(line, sizeof (line));