1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/* e_unix.cpp
*
* Copyright (c) 1997, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
// UNIX specific routines
#include "c_bind.h"
#include "c_config.h"
#include "c_history.h"
#include "i_modelview.h"
#include "i_view.h"
#include "o_buflist.h"
#include "s_util.h"
#ifdef WINNT
#include "e_win32.cpp"
#else
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <sys/wait.h>
int EView::SysShowHelp(ExState &State, const char *word) {
char options[128] = "";
char command[1024];
char file[MAXPATH];
if (State.GetStrParam(this, options, sizeof(options) - 1) == 0)
options[0] = 0;
char wordAsk[64] = "";
if (word == 0) {
if (State.GetStrParam(this, wordAsk, sizeof(wordAsk) - 1) == 0)
if (MView->Win->GetStr("Keyword",
sizeof(wordAsk) - 1, wordAsk, HIST_DEFAULT) == 0)
return 0;
word = wordAsk;
}
snprintf(file, sizeof(file)-1, "/tmp/fte%d-man-%s", getpid(), word);
snprintf(command, sizeof(command)-1, "%s %s %s >'%s' 2>&1", HelpCommand, options, word, file);
/// !!! why is this needed ???
#define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
pid_t pid;
int err, status;
Msg(S_INFO, "Retrieving man page for %s, please wait", word);
if ((pid = fork()) == 0) {
close(1);
SYSCALL(err = open(file, O_CREAT | O_WRONLY | O_APPEND, S_IRWXU));
if (err != -1) {
close(2);
//dup(1); // ignore error output
close(0);
assert(open("/dev/null", O_RDONLY) == 0);
setenv("MAN_KEEP_FORMATTING", "1", 0);
execlp("man", "man", "-7",
#ifndef AIX // current AIX's don't like the -a.
"-a",
#endif
word, NULL);
// execlp("/bin/sh", "sh", "-c", command, NULL);
perror("Can't exec command");
} else
perror("Can't open file");
exit(1);
} else if (pid < 0) {
perror("Can't fork");
return 0;
}
SYSCALL(err = waitpid(pid, &status, 0));
if (err == -1) {
perror("waitpid failed");
return 0;
}
// int rc = system(command);
err = FileLoad(0, file, "CATBS", this);
BFI((EBuffer*)(this->Model), BFI_ReadOnly) = 1;
unlink(file);
if (err == 0){
Msg(S_ERROR, "Error code %d retrieving manpage for %s", err, word);
return 0;
}
return 1;
}
#endif
|