X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fhelmpot%2Fmain.c;fp=helm%2Fhelmpot%2Fmain.c;h=f99e2fa3b64eaedf4e5b24eff168c5e43f500f3b;hb=d70d5de1ec9ccc86c9df45036245af34c37575ea;hp=0000000000000000000000000000000000000000;hpb=99d60351f793983bb7633334ea59e95feb36c72c;p=helm.git diff --git a/helm/helmpot/main.c b/helm/helmpot/main.c new file mode 100644 index 000000000..f99e2fa3b --- /dev/null +++ b/helm/helmpot/main.c @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2000, Luca Padovani . + * + * 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 + * + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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; +}