Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

wpp.c

Go to the documentation of this file.
00001 /*
00002  * Exported functions of the Wine preprocessor
00003  *
00004  * Copyright 1998 Bertho A. Stultiens
00005  * Copyright 2002 Alexandre Julliard
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00020  */
00021 
00022 #include "config.h"
00023 #include "wine/port.h"
00024 
00025 #include <time.h>
00026 #include <stdlib.h>
00027 
00028 #include "wpp_private.h"
00029 #include "wine/wpp.h"
00030 
00031 int ppy_debug, pp_flex_debug;
00032 
00033 struct define
00034 {
00035     struct define *next;
00036     char          *name;
00037     char          *value;
00038 };
00039 
00040 static struct define *cmdline_defines;
00041 
00042 static void add_cmdline_defines(void)
00043 {
00044     struct define *def;
00045 
00046     for (def = cmdline_defines; def; def = def->next)
00047     {
00048         if (def->value) pp_add_define( def->name, def->value );
00049     }
00050 }
00051 
00052 static void add_special_defines(void)
00053 {
00054     time_t now = time(NULL);
00055     pp_entry_t *ppp;
00056     char buf[32];
00057 
00058     strftime(buf, sizeof(buf), "\"%b %d %Y\"", localtime(&now));
00059     pp_add_define( "__DATE__", buf );
00060 
00061     strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now));
00062     pp_add_define( "__TIME__", buf );
00063 
00064     ppp = pp_add_define( "__FILE__", "" );
00065     if(ppp)
00066         ppp->type = def_special;
00067 
00068     ppp = pp_add_define( "__LINE__", "" );
00069     if(ppp)
00070         ppp->type = def_special;
00071 }
00072 
00073 
00074 /* add a define to the preprocessor list */
00075 int wpp_add_define( const char *name, const char *value )
00076 {
00077     struct define *def;
00078 
00079     if (!value) value = "";
00080 
00081     for (def = cmdline_defines; def; def = def->next)
00082     {
00083         if (!strcmp( def->name, name ))
00084         {
00085             char *new_value = pp_xstrdup(value);
00086             if(!new_value)
00087                 return 1;
00088             free( def->value );
00089             def->value = new_value;
00090 
00091             return 0;
00092         }
00093     }
00094 
00095     def = pp_xmalloc( sizeof(*def) );
00096     if(!def)
00097         return 1;
00098     def->next  = cmdline_defines;
00099     def->name  = pp_xstrdup(name);
00100     if(!def->name)
00101     {
00102         free(def);
00103         return 1;
00104     }
00105     def->value = pp_xstrdup(value);
00106     if(!def->value)
00107     {
00108         free(def->name);
00109         free(def);
00110         return 1;
00111     }
00112     cmdline_defines = def;
00113     return 0;
00114 }
00115 
00116 
00117 /* undefine a previously added definition */
00118 void wpp_del_define( const char *name )
00119 {
00120     struct define *def;
00121 
00122     for (def = cmdline_defines; def; def = def->next)
00123     {
00124         if (!strcmp( def->name, name ))
00125         {
00126             free( def->value );
00127             def->value = NULL;
00128             return;
00129         }
00130     }
00131 }
00132 
00133 
00134 /* add a command-line define of the form NAME=VALUE */
00135 int wpp_add_cmdline_define( const char *value )
00136 {
00137     char *p;
00138     char *str = pp_xstrdup(value);
00139     if(!str)
00140         return 1;
00141     p = strchr( str, '=' );
00142     if (p) *p++ = 0;
00143     wpp_add_define( str, p );
00144     free( str );
00145     return 0;
00146 }
00147 
00148 
00149 /* set the various debug flags */
00150 void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug )
00151 {
00152     pp_flex_debug   = lex_debug;
00153     ppy_debug       = parser_debug;
00154     pp_status.debug = msg_debug;
00155 }
00156 
00157 
00158 /* set the pedantic mode */
00159 void wpp_set_pedantic( int on )
00160 {
00161     pp_status.pedantic = on;
00162 }
00163 
00164 
00165 /* the main preprocessor parsing loop */
00166 int wpp_parse( const char *input, FILE *output )
00167 {
00168     int ret;
00169 
00170     pp_status.input = NULL;
00171     pp_status.line_number = 1;
00172     pp_status.char_number = 1;
00173     pp_status.state = 0;
00174 
00175     ret = pp_push_define_state();
00176     if(ret)
00177         return ret;
00178     add_cmdline_defines();
00179     add_special_defines();
00180 
00181     if (!input) pp_status.file = stdin;
00182     else if (!(pp_status.file = wpp_callbacks->open(input, 1)))
00183     {
00184         ppy_error("Could not open %s\n", input);
00185         pp_pop_define_state();
00186         return 2;
00187     }
00188 
00189     pp_status.input = input;
00190 
00191     ppy_out = output;
00192     pp_writestring("# 1 \"%s\" 1\n", input ? input : "");
00193 
00194     ret = ppy_parse();
00195     /* If there were errors during processing, return an error code */
00196     if (!ret && pp_status.state) ret = pp_status.state;
00197 
00198     if (input) wpp_callbacks->close(pp_status.file);
00199     /* Clean if_stack, it could remain dirty on errors */
00200     while (pp_get_if_depth()) pp_pop_if();
00201     pp_pop_define_state();
00202     return ret;
00203 }
00204 
00205 
00206 void wpp_set_callbacks( const struct wpp_callbacks *callbacks )
00207 {
00208     wpp_callbacks = callbacks;
00209 }

Generated on Thu Feb 9 05:04:45 2012 for ReactOS by doxygen 1.6.3

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.