/* query external help program for s. num < 0 [keyword] or chapter number */ static void external_help(const char *s, int num) { long nbli = term_height()-3, li = 0; char buf[256], *str; const char *opt = "", *ar = "", *cdir = ""; char *t, *help = GP_DATA->help; pariFILE *z; FILE *f; if (!has_ext_help()) pari_err(e_MISC,"no external help program"); t = filter_quotes(s); if (num < 0) opt = "-k"; else if (t[strlen(t)-1] != '@') ar = stack_sprintf("@%d",num); #ifdef _WIN32 if (*help=='@') { const char *basedir = win32_basedir(); help++; cdir = stack_sprintf("%c:& cd %s & ", *basedir, basedir); } #endif str=stack_sprintf("%s%s -fromgp %s %c%s%s%c",cdir,help,opt, SHELL_Q,t,ar,SHELL_Q); z = try_pipe(str,0); f = z->file; pari_free(t); while (fgets(buf, numberof(buf), f)) { if (!strncmp("ugly_kludge_done",buf,16)) break; pari_puts(buf); if (nl_read(buf) && ++li > nbli) { pari_hit_return(); li = 0; } } pari_fclose(z); }
int get_xsockets (int *number, struct x_socket **sockets, int tcp_socket) { int dpy; struct x_socket *s; int n; int i; s = malloc (sizeof(*s) * 5); if (s == NULL) errx (1, "malloc: out of memory"); try_mkdir (X_UNIX_PATH); try_mkdir (X_PIPE_PATH); for(dpy = 4; dpy < 256; ++dpy) { char **path; int tmp = 0; n = 0; for (path = x_sockets; *path; ++path) { tmp = try_socket (&s[n], dpy, *path); if (tmp == -1) { if (errno != ENOTDIR && errno != ENOENT) err(1, "failed to open '%s'", *path); } else if (tmp == 1) { while(--n >= 0) { close (s[n].fd); free (s[n].pathname); } break; } else if (tmp == 0) ++n; } if (tmp == 1) continue; #ifdef MAY_HAVE_X11_PIPES for (path = x_pipes; *path; ++path) { tmp = try_pipe (&s[n], dpy, *path); if (tmp == -1) { if (errno != ENOTDIR && errno != ENOENT && errno != ENOSYS) err(1, "failed to open '%s'", *path); } else if (tmp == 1) { while (--n >= 0) { close (s[n].fd); free (s[n].pathname); } break; } else if (tmp == 0) ++n; } if (tmp == 1) continue; #endif if (tcp_socket) { tmp = try_tcp (&s[n], dpy); if (tmp == -1) err(1, "failed to open tcp stocket"); else if (tmp == 1) { while (--n >= 0) { close (s[n].fd); free (s[n].pathname); } break; } else if (tmp == 0) ++n; } break; } if (dpy == 256) errx (1, "no free x-servers"); for (i = 0; i < n; ++i) if (s[i].flags & LISTENP && listen (s[i].fd, SOMAXCONN) < 0) err (1, "listen %s", s[i].pathname ? s[i].pathname : "tcp"); *number = n; *sockets = s; return dpy; }