summaryrefslogtreecommitdiff
path: root/app/wlib/gtklib/osxhelp.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/wlib/gtklib/osxhelp.c')
-rw-r--r--app/wlib/gtklib/osxhelp.c167
1 files changed, 84 insertions, 83 deletions
diff --git a/app/wlib/gtklib/osxhelp.c b/app/wlib/gtklib/osxhelp.c
index 2fed375..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>
@@ -51,15 +51,15 @@ extern wBool_t CheckHelpTopicExists(const char *);
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);
}