]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/helmpot/main.c
This commit was manufactured by cvs2svn to create branch 'start'.
[helm.git] / helm / helmpot / main.c
diff --git a/helm/helmpot/main.c b/helm/helmpot/main.c
new file mode 100644 (file)
index 0000000..f99e2fa
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
+ * 
+ * This file is part of HelmPot, a minimal browser for HELM.
+ * 
+ * HelmPot is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * HelmPot is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with HelmPot; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * 
+ * For details, see the HelmPot World-Wide-Web page,
+ * http://cs.unibo.it/helm/helmview, or send a mail to
+ * <luca.padovani@cs.unibo.it>
+ */
+
+#include <config.h>
+
+#include <glib.h>
+#include <assert.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "defs.h"
+#include "guiGTK.h"
+
+#define BUFFER_SIZE 2048
+
+PRIVATE gchar app_name[64];
+PRIVATE gint sockfd;
+PRIVATE struct sockaddr_in address;
+
+PRIVATE void
+error(const gchar* msg)
+{
+  g_assert(msg != NULL);
+  fprintf(stderr, "%s: fatal error: %s\n", app_name, msg);
+}
+
+#if 0
+PRIVATE void
+print_version()
+{
+  printf("%s - written by Luca Padovani (C) 2000.\n", app_name);
+#ifdef DEBUG
+  printf("Compiled %s %s\n", __DATE__, __TIME__);
+#endif
+  exit(0);
+}
+#endif
+
+PRIVATE gboolean
+timeout(gpointer user_data)
+{
+  static gchar file_name[BUFFER_SIZE];
+
+  if (recv(sockfd, file_name, BUFFER_SIZE, 0) < 0) {
+    if (errno != EAGAIN && errno != EWOULDBLOCK)
+      error("error receving message");
+  } else
+    GUI_load_document(file_name);
+
+  return TRUE;
+}
+
+int
+main(int argc, char *argv[])
+{
+  sprintf(app_name, "HELM Pot (Plug-OuT) v%s", VERSION);
+
+  if (argc != 2) {
+    fprintf(stderr, "%s\n\n", app_name);
+    fprintf(stderr, "Usage: helmpot URL\n");
+    exit(-1);
+  }
+
+  sockfd = socket(PF_INET, SOCK_DGRAM, 0);
+  if (sockfd < 0) error("could not create socket");
+
+  if (inet_aton("127.0.0.1", &address.sin_addr) < 0)
+    error("could not create address");
+  address.sin_port = 8778;
+  address.sin_family = PF_INET;
+
+  if (bind(sockfd, &address, sizeof(address)) < 0) {
+    if (sendto(sockfd, argv[1], strlen(argv[1]), 0, &address, sizeof(address)) < 0) 
+      error("could not send message");
+    sleep(1);
+    exit(0);
+  }
+
+  if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0)
+    error("could not set the socket to non-block mode");
+
+  GUI_init(&argc, &argv, app_name, 500, 600, timeout, 500);
+
+  GUI_load_document(argv[1]);
+
+  GUI_run();
+  GUI_uninit();
+  GUI_unload_document();
+
+  return 0;
+}