-cl_console::cl_console(char *fin, char *fout, class cl_app *the_app):
- cl_base()
-{
- FILE *f;
-
- app= the_app;
- in= 0;
- if (fin)
- if (f= fopen(fin, "r"), in= f, !f)
- fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno));
- out= 0;
- if (fout)
- if (f= fopen(fout, "w"), out= f, !f)
- fprintf(stderr, "Can't open `%s': %s\n", fout, strerror(errno));
- prompt= 0;
- flags= CONS_NONE;
- if (in &&
- isatty(fileno(in)))
- flags|= CONS_INTERACTIVE;
- else
- ;//fprintf(stderr, "Warning: non-interactive console\n");
- rout= 0;
- id= 0;
- lines_printed= new cl_ustrings(100, 100, "console_cache");
-}
-
-cl_console::cl_console(FILE *fin, FILE *fout, class cl_app *the_app):
- cl_base()
-{
- app= the_app;
- in = fin;
- out= fout;
- prompt= 0;
- flags= CONS_NONE;
- if (in &&
- isatty(fileno(in)))
- flags|= CONS_INTERACTIVE;
- else
- ;//fprintf(stderr, "Warning: non-interactive console\n");
- rout= 0;
- id= 0;
- lines_printed= new cl_ustrings(100, 100, "console_cache");
-}
-
-/*
- * use the port number supplied to connect to localhost for
- * (by Sandeep)
- */
-
-#ifdef SOCKET_AVAIL
-static int
-connect_to_port(int portnum)
-{
- int sock= socket(AF_INET,SOCK_STREAM,0);
- struct sockaddr_in sin;
-
- sin.sin_family = AF_INET;
- sin.sin_port = htons(portnum);
- sin.sin_addr.s_addr = inet_addr("127.0.0.1");
-
- if (connect(sock, (struct sockaddr *)&sin, sizeof(sin))) {
- fprintf(stderr, "Connect to port %d: %s\n", portnum, strerror(errno));
- return -1;
- }
- return sock;
-}
-
-cl_console::cl_console(int portnumber, class cl_app *the_app)
-{
- int sock= connect_to_port(portnumber);
-
- app= the_app;
- if (!(in= fdopen(sock, "r")))
- fprintf(stderr, "cannot open port for input\n");
- if (!(out= fdopen(sock, "w")))
- fprintf(stderr, "cannot open port for output\n");
- //fprintf(stderr, "init socket done\n");
- id= 0;
- lines_printed= new cl_ustrings(1, 1, "console_cache");
-}
-#endif
-
-class cl_console *
-cl_console::clone_for_exec(char *fin)
-{
- FILE *fi= 0, *fo= 0;
-
- if (!fin)
- return(0);
- if (fi= fopen(fin, "r"), !fi)
- {
- fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno));
- return(0);
- }
- if ((fo= fdopen(dup(fileno(out)), "a")) == 0)
- {
- fclose(fi);
- fprintf(stderr, "Can't re-open output file: %s\n", strerror(errno));
- return(0);
- }
- class cl_console *con= new cl_sub_console(this, fi, fo, app);
- return(con);
-}
-