mojoshader_preprocessor.c
changeset 951 6ef73d06ecb0
parent 950 dcbf30c07fc9
child 952 7e7d5737f9a6
equal deleted inserted replaced
950:dcbf30c07fc9 951:6ef73d06ecb0
   638     // let the usual preprocessor parser sort these out.
   638     // let the usual preprocessor parser sort these out.
   639     char *define_include = NULL;
   639     char *define_include = NULL;
   640     unsigned int define_include_len = 0;
   640     unsigned int define_include_len = 0;
   641     if ((okay) && (define_count > 0))
   641     if ((okay) && (define_count > 0))
   642     {
   642     {
   643         for (i = 0; i < define_count; i++)
   643         Buffer *predefbuf = buffer_create(256, MallocBridge, FreeBridge, ctx);
   644         {
   644         okay = okay && (predefbuf != NULL);
   645             define_include_len += strlen(defines[i].identifier);
   645         for (i = 0; okay && (i < define_count); i++)
   646             define_include_len += strlen(defines[i].definition);
   646         {
   647             define_include_len += 10;  // "#define<space><space><newline>"
   647             okay = okay && buffer_append_fmt(predefbuf, "#define %s %s\n",
       
   648                                  defines[i].identifier, defines[i].definition);
   648         } // for
   649         } // for
   649         define_include_len++;  // for null terminator.
   650 
   650 
   651         define_include_len = buffer_size(predefbuf);
   651         define_include = (char *) Malloc(ctx, define_include_len);
   652         if (define_include_len > 0)
   652         if (define_include == NULL)
   653         {
   653             okay = 0;
   654             define_include = buffer_flatten(predefbuf);
   654         else
   655             okay = okay && (define_include != NULL);
   655         {
   656         } // if
   656             char *ptr = define_include;
   657         buffer_destroy(predefbuf);
   657             for (i = 0; i < define_count; i++)
       
   658             {
       
   659                 ptr += sprintf(ptr, "#define %s %s\n", defines[i].identifier,
       
   660                                defines[i].definition);
       
   661             } // for
       
   662         } // else
       
   663     } // if
   658     } // if
   664 
   659 
   665     if ((okay) && (!push_source(ctx,fname,source,sourcelen,1,NULL)))
   660     if ((okay) && (!push_source(ctx,fname,source,sourcelen,1,NULL)))
   666         okay = 0;
   661         okay = 0;
   667 
   662 
   668     if ((okay) && (define_include_len > 0))
   663     if ((okay) && (define_include_len > 0))
   669     {
   664     {
   670         assert(define_include != NULL);
   665         assert(define_include != NULL);
   671         okay = push_source(ctx, "<predefined macros>", define_include,
   666         okay = push_source(ctx, "<predefined macros>", define_include,
   672                            define_include_len-1, 1, close_define_include);
   667                            define_include_len, 1, close_define_include);
   673     } // if
   668     } // if
   674 
   669 
   675     if (!okay)
   670     if (!okay)
   676     {
   671     {
   677         preprocessor_end((Preprocessor *) ctx);
   672         preprocessor_end((Preprocessor *) ctx);