2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3 * Copyright (C) 2004-2007 Kim Woelders
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies of the Software, its documentation and marketing & publicity
14 * materials, and acknowledgment shall be given in the documentation, materials
15 * and software packages that this Software was used.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 static char buf[10240];
30 static int stdin_state;
31 static char *display_name;
33 static Window my_win, comms_win;
36 process_line(char *line)
48 stdin_state_setup(void)
50 stdin_state = fcntl(0, F_GETFL, 0);
51 fcntl(0, F_SETFL, O_NONBLOCK);
55 stdin_state_restore(void)
57 fcntl(0, F_SETFL, stdin_state);
67 while ((ret = read(0, &(buf[j]), 1) > 0))
79 if ((ret < 0) || ((k == 0) && (ret == 0)))
84 main(int argc, char **argv)
98 for (i = 1; i < argc; i++)
104 if (!strcmp(argv[i], "-e"))
112 else if (!strcmp(argv[i], "-ewait"))
118 else if (!strcmp(argv[i], "-display"))
122 display_name = argv[++i];
123 display_name = Estrdup(display_name);
126 else if ((!strcmp(argv[i], "-h")) ||
127 (!strcmp(argv[i], "-help")) || (!strcmp(argv[i], "--help")))
130 ("eesh sends commands to E\n\n"
132 " eesh Command to Send to E then wait for a reply then exit\n"
133 " eesh -ewait \"Command to Send to E then wait for a reply then exit\"\n"
134 " eesh -e \"Command to Send to Enlightenment then exit\"\n\n");
135 printf("Use eesh by itself to enter the \"interactive mode\"\n"
136 " Ctrl-D will exit interactive mode\n"
137 " Use \"help\" from inside interactive mode for further assistance\n");
142 /* Open a connection to the diplay nominated by the DISPLAY variable */
143 /* Or set with the -display option */
144 disp = XOpenDisplay(display_name);
147 Alert("Failed to connect to X server\n");
152 comms_win = CommsFindCommsWindow();
153 my_win = CommsSetup(comms_win);
155 e = ClientCreate(comms_win);
156 me = ClientCreate(my_win);
158 CommsSend(e, "set clientname eesh");
159 CommsSend(e, "set version 0.2");
160 #if 0 /* Speed it up */
161 CommsSend(e, "set author The Rasterman");
162 CommsSend(e, "set email raster@rasterman.com");
163 CommsSend(e, "set web http://www.enlightenment.org");
164 /* CommsSend(e, "set address NONE"); */
165 CommsSend(e, "set info Enlightenment IPC Shell - talk to E direct");
166 /* CommsSend(e, "set pixmap 0"); */
169 if (command == NULL && i < argc)
173 for (; i < argc; i++)
176 command = EREALLOC(char, command, len + l + 2);
179 command[len++] = ' ';
180 strcpy(command + len, argv[i]);
187 /* Non-interactive */
188 CommsSend(e, command);
190 #if 0 /* No - Wait for ack */
199 atexit(stdin_state_restore);
205 while (XPending(disp))
207 XNextEvent(disp, &ev);
211 s = CommsGet(me, &ev);
229 FD_SET(ConnectionNumber(disp), &fd);
231 if (select(ConnectionNumber(disp) + 1, &fd, NULL, NULL, NULL) < 0)
234 if (FD_ISSET(0, &fd))
248 Alert(const char *fmt, ...)
253 vfprintf(stderr, fmt, ap);
259 Estrdup(const char *s)
267 ss = EMALLOC(char, sz + 1);
268 strncpy(ss, s, sz + 1);