Do at least something for SHDragDrop functions although that isn't the
[wine/multimedia.git] / tools / wpp / wpp.c
blobd4b5465a71f501290b81edcc76d90eccebef4891
1 /*
2 * Exported functions of the Wine preprocessor
4 * Copyrignt 1998 Bertho A. Stultiens
5 * Copyright 2002 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <time.h>
26 #include <stdlib.h>
28 #include "wpp_private.h"
29 #include "wpp.h"
31 static void add_special_defines(void)
33 time_t now = time(NULL);
34 pp_entry_t *ppp;
35 char buf[32];
37 strftime(buf, sizeof(buf), "\"%b %d %Y\"", localtime(&now));
38 pp_add_define( pp_xstrdup("__DATE__"), pp_xstrdup(buf) );
40 strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now));
41 pp_add_define( pp_xstrdup("__TIME__"), pp_xstrdup(buf) );
43 ppp = pp_add_define( pp_xstrdup("__FILE__"), pp_xstrdup("") );
44 ppp->type = def_special;
46 ppp = pp_add_define( pp_xstrdup("__LINE__"), pp_xstrdup("") );
47 ppp->type = def_special;
51 /* add a define to the preprocessor list */
52 void wpp_add_define( const char *name, const char *value )
54 if (!value) value = "";
55 pp_add_define( pp_xstrdup(name), pp_xstrdup(value) );
59 /* add a command-line define of the form NAME=VALUE */
60 void wpp_add_cmdline_define( const char *value )
62 char *str = pp_xstrdup(value);
63 char *p = strchr( str, '=' );
64 if (p) *p++ = 0;
65 else p = "";
66 pp_add_define( str, pp_xstrdup(p) );
70 /* set the various debug flags */
71 void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug )
73 pp_flex_debug = lex_debug;
74 ppdebug = parser_debug;
75 pp_status.debug = msg_debug;
79 /* set the pedantic mode */
80 void wpp_set_pedantic( int on )
82 pp_status.pedantic = on;
86 /* the main preprocessor parsing loop */
87 int wpp_parse( const char *input, FILE *output )
89 int ret;
91 add_special_defines();
93 if (!input) ppin = stdin;
94 else if (!(ppin = fopen(input, "rt")))
96 fprintf(stderr,"Could not open %s\n", input);
97 exit(2);
100 pp_status.input = input;
102 ppout = output;
103 fprintf(ppout, "# 1 \"%s\" 1\n", input ? input : "");
105 ret = ppparse();
107 if (input) fclose(ppin);
108 return ret;
112 /* parse into a temporary file */
113 int wpp_parse_temp( const char *input, const char *output_base, char **output_name )
115 FILE *output;
116 int ret, fd;
117 char *temp_name;
119 if (!output_base || !output_base[0]) output_base = "wpptmp";
121 temp_name = pp_xmalloc( strlen(output_base) + 8 );
122 strcpy( temp_name, output_base );
123 strcat( temp_name, ".XXXXXX" );
125 if((fd = mkstemp( temp_name )) == -1)
127 fprintf(stderr, "Could not generate a temp name from %s\n", temp_name);
128 exit(2);
131 if (!(output = fdopen(fd, "wt")))
133 fprintf(stderr,"Could not open fd %s for writing\n", temp_name);
134 exit(2);
137 *output_name = temp_name;
138 ret = wpp_parse( input, output );
139 fclose( output );
140 return ret;