ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

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

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  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

gc_to_bin.c
Go to the documentation of this file.
00001 #include "../../grammar/grammar_crt.h"
00002 #include "../../grammar/grammar_crt.c"
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 
00006 static const char *slang_shader_syn =
00007 #include "slang_shader_syn.h"
00008 ;
00009 
00010 static int gc_to_bin (grammar id, const char *in, const char *out)
00011 {
00012     FILE *f;
00013     byte *source, *prod;
00014     unsigned int size, i, line = 0;
00015 
00016     printf ("Precompiling %s\n", in);
00017 
00018     f = fopen (in, "r");
00019     if (f == NULL)
00020         return 1;
00021     fseek (f, 0, SEEK_END);
00022     size = ftell (f);
00023     fseek (f, 0, SEEK_SET);
00024     source = (byte *) grammar_alloc_malloc (size + 1);
00025     source[fread (source, 1, size, f)] = '\0';
00026     fclose (f);
00027 
00028     if (!grammar_fast_check (id, source, &prod, &size, 65536))
00029     {
00030         grammar_alloc_free (source);
00031         return 1;
00032     }
00033 
00034     f = fopen (out, "w");
00035     fprintf (f, "\n");
00036     fprintf (f, "/* DO NOT EDIT - THIS FILE IS AUTOMATICALLY GENERATED FROM THE FOLLOWING FILE: */\n");
00037     fprintf (f, "/* %s */\n", in);
00038     fprintf (f, "\n");
00039     for (i = 0; i < size; i++)
00040     {
00041         unsigned int a;
00042         if (prod[i] < 10)
00043             a = 1;
00044         else if (prod[i] < 100)
00045             a = 2;
00046         else
00047             a = 3;
00048         if (i < size - 1)
00049             a++;
00050         if (line + a >= 100)
00051         {
00052             fprintf (f, "\n");
00053             line = 0;
00054         }
00055         line += a;
00056         fprintf (f, "%d", prod[i]);
00057         if (i < size - 1)
00058             fprintf (f, ",");
00059     }
00060     fprintf (f, "\n");
00061     fclose (f);
00062     grammar_alloc_free (prod);
00063    return 0;
00064 }
00065 
00066 int main (int argc, char *argv[])
00067 {
00068    grammar id;
00069 
00070    id = grammar_load_from_text ((const byte *) slang_shader_syn);
00071    if (id == 0) {
00072       fprintf(stderr, "Error loading grammar from text\n");
00073       return 1;
00074    }
00075    grammar_set_reg8 (id, (const byte *) "parsing_builtin", 1);
00076    grammar_set_reg8 (id, (const byte *) "shader_type", atoi (argv[1]));
00077    if (gc_to_bin (id, argv[2], argv[3])) {
00078       fprintf(stderr, "Error in gc_to_bin %s %s\n", argv[2], argv[3]);
00079       grammar_destroy (id);
00080       return 1;
00081    }
00082    grammar_destroy (id);
00083    return 0;
00084 }
00085 

Generated on Sun May 27 2012 04:20:35 for ReactOS by doxygen 1.7.6.1

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