Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / dtinfogen / infolib / etc / StyleValidate.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: StyleValidate.cc /main/2 1996/07/18 16:18:13 drk $ */
24 #include <stdio.h>
25 #include <iostream.h>
26 #include <stream.h>
27 #include <unistd.h>
28 #include <sys/wait.h>
29
30 #include "DataBase.h"
31 #include "StyleValidate.h"
32
33 //---------------------------------------------------------------------
34 int 
35 validate_stylesheet( const char *buf, int buf_size, enum RENDERER_ENGINE_T t )
36 {
37
38   char *styleFile = form( "/usr/tmp/style_sheet.%d", getpid() );
39   
40   FILE *fp = fopen( styleFile, "w" );
41   if ( !fp ) {
42     throw( PosixError(1, "Unable to open style_sheet\n") );
43   }
44
45   fwrite( (char *)buf, buf_size, 1, fp );
46   fclose( fp );
47
48   char* renderer = 0;
49
50   switch ( t ) {
51     case ONLINE:
52      renderer = "online";
53      break;
54     case PRINT:
55      renderer = "hardcopy";
56      break;
57     default:
58      throw( PosixError(1, "Unknown renderer engine\n") );
59   }
60
61   char *cmd = form("validator %s %s", renderer, styleFile);
62   int status = system(cmd);
63   int exit_status = WEXITSTATUS(status);
64
65   unlink( styleFile );
66
67   return (exit_status);
68   
69 }
70