2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: CanvasOs.c /main/5 1996/05/09 03:40:38 drk $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 ** Project: Cde Help System
31 ** Description: Utility functions for parsing an SDL volume.
33 ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
35 ** (c) Copyright 1993, 1994 Hewlett-Packard Company
36 ** (c) Copyright 1993, 1994 International Business Machines Corp.
37 ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
38 ** (c) Copyright 1993, 1994 Novell, Inc.
40 ****************************************************************************
41 ************************************<+>*************************************/
54 * Canvas Engine includes
62 #include "CanvasOsI.h"
63 #include "FormatUtilI.h"
68 /******** Private Function Declarations ********/
69 /******** End Private Function Declarations ********/
71 /******************************************************************************
75 *****************************************************************************/
76 /******************************************************************************
80 *****************************************************************************/
81 /******************************************************************************
85 *****************************************************************************/
86 /******************************************************************************
90 *****************************************************************************/
91 /******************************************************************************
93 * Semi Public Functions
95 *****************************************************************************/
96 /*********************************************************************
97 * Function: _DtCvRunInterp
99 * _DtCvRunInterp calls a script and maybe gets data.
101 *********************************************************************/
104 int (*filter_exec)(),
105 _DtCvPointer client_data,
114 int writeBufSize = 0;
115 char *writeBuf = NULL;
119 char readBuf[BUFSIZ];
120 BufFilePtr myBufFile;
123 * ask for permission to run the interperator command.
126 if (filter_exec != NULL && (*filter_exec)(client_data,data,&newData) != 0)
130 * open a temporary file to write the data to.
132 fileName = tempnam(NULL, NULL);
133 if (fileName == NULL)
141 * write the data to file.
145 myFd = open(fileName, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
147 myFd = open(fileName, O_WRONLY | O_CREAT | O_TRUNC);
152 * write the data to the file
154 result = write(myFd, newData, strlen(newData));
159 * change the access permissions so the interpreter can read
162 result = fchmod(myFd, S_IRUSR | S_IRGRP | S_IROTH);
182 * create the system command string with its parameters
184 ptr = (char *) malloc(sizeof(interp) + strlen(fileName) + 1);
192 strcpy (ptr, interp);
194 strcat (ptr, fileName);
196 myFile = popen(ptr, "r");
206 if (!myFile) /* couldn't create execString process */
214 * create a file handler for the pipe.
216 myBufFile = _DtHelpCeCreatePipeBufFile(myFile);
217 if (myBufFile == NULL)
219 (void) pclose(myFile); /* don't check for error, it was popen'd */
226 * read the file the pipe writes to until the pipe finishes.
227 * Create a string from the results
233 result = _DtHelpCeGetNxtBuf(myBufFile, readBuf, &ptr, BUFSIZ);
237 size = strlen(readBuf);
238 if (writeBuf == NULL)
239 writeBuf = (char *) malloc (size + 1);
241 writeBuf = (char *) realloc (writeBuf, writeBufSize + size + 1);
243 if (writeBuf != NULL)
245 writeBuf[writeBufSize] = '\0';
246 strcat(writeBuf, readBuf);
247 writeBufSize += size;
252 } while (result != -1 && !feof(FileStream(myBufFile)));
257 _DtHelpCeBufFileClose (myBufFile, True);
261 if (writeBuf != NULL)
270 * unlink the temporary file and free the memory.
278 *ret_data = writeBuf;
282 } /* End _DtCvRunInterp */