diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-11-14 19:35:45 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-11-14 19:35:45 +0100 |
commit | df5520aa2dae5b3ce7abf8733dcdd152898af163 (patch) | |
tree | 00d3047bfb14f682bfb5a21010c731ed649bfed7 /app/wlib/gtklib/osxhelp.c | |
parent | df247efec654e512242e4f4f1b0212034f9e01fe (diff) | |
parent | ec3c0f6f6e7153fa797dc57a0e95779cbc63a23b (diff) |
Merge branch 'release/debian/1_5.3.0GA-1'HEADdebian/1_5.3.0GA-1master
Diffstat (limited to 'app/wlib/gtklib/osxhelp.c')
-rw-r--r-- | app/wlib/gtklib/osxhelp.c | 169 |
1 files changed, 85 insertions, 84 deletions
diff --git a/app/wlib/gtklib/osxhelp.c b/app/wlib/gtklib/osxhelp.c index 4ec1f5e..b508961 100644 --- a/app/wlib/gtklib/osxhelp.c +++ b/app/wlib/gtklib/osxhelp.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -28,7 +28,6 @@ #include <errno.h> #include <fcntl.h> -#include "misc.h" #include "gtkint.h" #include "i18n.h" @@ -40,6 +39,7 @@ static pid_t pidOfChild; static int handleOfPipe; extern char *wExecutableName; +extern wBool_t CheckHelpTopicExists(const char *); /** * Create the fully qualified filename for the help helper @@ -51,15 +51,15 @@ extern char *wExecutableName; static char *ChildProgramFile(char *parentProgram) { - char *startOfFilename; - char *childProgram; + char *startOfFilename; + char *childProgram; - childProgram = malloc(strlen(parentProgram)+ sizeof(HELPERPROGRAM) + 1); - strcpy(childProgram, parentProgram); - startOfFilename = strrchr(childProgram, '/'); - strcpy(startOfFilename + 1, HELPERPROGRAM); + childProgram = malloc(strlen(parentProgram)+ sizeof(HELPERPROGRAM) + 1); + strcpy(childProgram, parentProgram); + startOfFilename = strrchr(childProgram, '/'); + strcpy(startOfFilename + 1, HELPERPROGRAM); - return (childProgram); + return (childProgram); } @@ -71,92 +71,93 @@ char *ChildProgramFile(char *parentProgram) void wHelp(const char * topic) { - pid_t newPid; - int status; - const char html[] = ".html"; - static char *directory; /**< base directory for HTML files */ - char * htmlFile; - - struct { - int length; - char *page; - } buffer; - - if (!CheckHelpTopicExists(topic)) return; - - // check whether child already exists - if (pidOfChild != 0) { - if (waitpid(pidOfChild, &status, WNOHANG) < 0) { - // child exited -> clean up - close(handleOfPipe); - unlink(HELPCOMMANDPIPE); - handleOfPipe = 0; - pidOfChild = 0; // child exited - } - } - - // (re)start child - if (pidOfChild == 0) { - unlink(HELPCOMMANDPIPE); - int rc = mkfifo(HELPCOMMANDPIPE, 0666); - newPid = fork(); /* New process starts here */ - - if (newPid > 0) { - pidOfChild = newPid; - } else if (newPid == 0) { + pid_t newPid; + int status; + const char html[] = ".html"; + static char *directory; /**< base directory for HTML files */ + char * htmlFile; + + struct { + int length; + char *page; + } buffer; + + if (!CheckHelpTopicExists(topic)) { return; } + + // check whether child already exists + if (pidOfChild != 0) { + if (waitpid(pidOfChild, &status, WNOHANG) < 0) { + // child exited -> clean up + close(handleOfPipe); + unlink(HELPCOMMANDPIPE); + handleOfPipe = 0; + pidOfChild = 0; // child exited + } + } + + // (re)start child + if (pidOfChild == 0) { + unlink(HELPCOMMANDPIPE); + int rc = mkfifo(HELPCOMMANDPIPE, 0666); + newPid = fork(); /* New process starts here */ + + if (newPid > 0) { + pidOfChild = newPid; + } else if (newPid == 0) { char *child = ChildProgramFile(wExecutableName); - - if (execlp(child, child, NULL) < 0) { /* never normally returns */ - exit(8); - } - - free(child); - } else { /* -1 signifies fork failure */ - pidOfChild = 0; - return; - } - } - - buffer.page = malloc(sizeof(int)+strlen(topic) + strlen(html) + 1); - - if (!buffer.page) { - return; - } - - strcpy(buffer.page, topic); - strcat(buffer.page, html); - buffer.length = strlen(buffer.page); - - if (buffer.length>255) { - printf("Help Topic too long %s", buffer.page); - return; - } - - if (!handleOfPipe) { + + if (execlp(child, child, NULL) < 0) { /* never normally returns */ + exit(8); + } + + free(child); + } else { /* -1 signifies fork failure */ + pidOfChild = 0; + return; + } + } + + buffer.page = malloc(sizeof(int)+strlen(topic) + strlen(html) + 1); + + if (!buffer.page) { + return; + } + + strcpy(buffer.page, topic); + strcat(buffer.page, html); + buffer.length = strlen(buffer.page); + + if (buffer.length>255) { + printf("Help Topic too long %s", buffer.page); + return; + } + + if (!handleOfPipe) { handleOfPipe = open(HELPCOMMANDPIPE, O_WRONLY); if (handleOfPipe < 0) { - if (pidOfChild) - kill(pidOfChild, SIGKILL); /* tidy up on next call */ + if (pidOfChild) { + kill(pidOfChild, SIGKILL); /* tidy up on next call */ + } handleOfPipe = 0; return; } } - int written = 0; - int towrite = sizeof(int); + int written = 0; + int towrite = sizeof(int); - while (written < towrite){ - written += write(handleOfPipe, &buffer.length, sizeof(int)); - } - written =0; - towrite = strlen(buffer.page); - while (written < towrite){ - written += write(handleOfPipe, buffer.page+written, towrite-written); - } + while (written < towrite) { + written += write(handleOfPipe, &buffer.length, sizeof(int)); + } + written =0; + towrite = strlen(buffer.page); + while (written < towrite) { + written += write(handleOfPipe, buffer.page+written, towrite-written); + } - fsync(handleOfPipe); + fsync(handleOfPipe); - free(buffer.page); + free(buffer.page); } |