along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdio.h>
+#include <string.h>
#include <libguile.h>
#include <libgen.h>
#include <readline/readline.h>
#include "gacela_FTGL.h"
+// Generic variables
+int ctrl_c = 0;
+
static int
find_matching_paren (int k)
{
ctrl_c_handler (int signum)
{
printf ("ERROR: User interrupt\nABORT: (signal)\n");
+ ctrl_c = 1;
}
static void
void
gacela_client (char *hostname, int port)
{
- int sockfd;
+ int sockfd, n;
struct hostent *server;
struct sockaddr_in serv_addr;
-
+ char buffer[256];
char *line;
char *history_path;
while (1) {
line = readline ("gacela> ");
+ ctrl_c = 0;
if (!line) break;
if (line && *line)
{
- printf ("%s\n", line);
add_history (line);
+ write (sockfd, "(", 1);
+ n = write (sockfd, line, strlen (line));
+ write (sockfd, ")", 1);
+ if (n < 0)
+ error("ERROR writing to socket");
+
+ bzero (buffer, 256);
+ n = read (sockfd, buffer, sizeof (buffer));
+ while (n == 0) {
+ if (ctrl_c) break;
+ sleep (1);
+ n = read (sockfd, buffer, sizeof (buffer));
+ }
+ if (n < 0)
+ error("ERROR reading from socket");
+ if (ctrl_c)
+ ctrl_c = 0;
+ else
+ printf ("%s\n", buffer);
}
free (line);
}
+ close (sockfd);
write_history (history_path);
free (history_path);
}
load_scheme_files (working_path);
sprintf (start_server, "(start-server %d)", port);
scm_c_eval_string (start_server);
- scm_c_eval_string ("(game-loop)");
}
void
{
char *arg;
int mode = 0; // shell: 1, server: 2, client: 3
- int port = 2;
+ char *host;
+ int port = 0;
int i;
- for (i = 1; i < argc; i++)
+ // Checking arguments
+ for (i = 1; i < argc; i++) {
if (strcmp (argv[i], "--shell-mode") == 0)
mode = 1;
else if (strncmp (argv[i], "--server", 8) == 0) {
- arg = strdup (argv[i]);
- port = 1234;
+ mode = 2;
+ arg = strtok (argv[i], "=");
+ arg = strtok (NULL, "=");
+ if (arg != NULL)
+ port = atoi (arg);
+ }
+ else if (strncmp (argv[i], "--client", 8) == 0) {
+ mode = 3;
+ arg = strtok (argv[i], "=");
+ arg = strtok (NULL, "=");
+ if (arg != NULL) {
+ host = strtok (arg, ":");
+ arg = strtok (NULL, ":");
+ if (arg != NULL)
+ port = atoi (arg);
+ }
+ }
+ }
if (mode == 1)
start_single (dirname (argv[0]));
- else
- printf ("Puerto: %d\n", port);
+ else if (mode == 2 && port != 0)
+ start_server (dirname (argv[0]), port);
+ else if (mode == 3 && port != 0)
+ start_client (host, port);
/*
if (fork () == 0)
start_server ();