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

mkconfig.c
Go to the documentation of this file.
00001 #include <string.h>
00002 #include <stdlib.h>
00003 #include <stdio.h>
00004 
00005 #ifndef max
00006 #define max(a, b) ((a) > (b) ? (a) : (b))
00007 #endif
00008 
00009 int
00010 write_if_change(char* outbuf, char* filename)
00011 {
00012   FILE* out;
00013   unsigned int end;
00014   char* cmpbuf;
00015   unsigned int stat;
00016 
00017   out = fopen(filename, "rb");
00018   if (out == NULL)
00019     {
00020       out = fopen(filename, "wb");
00021       if (out == NULL)
00022     {
00023       fprintf(stderr, "Unable to create output file\n");
00024       return(1);
00025     }
00026       fputs(outbuf, out);
00027       fclose(out);
00028       return(0);
00029     }
00030 
00031   fseek(out, 0, SEEK_END);
00032   end = ftell(out);
00033   cmpbuf = malloc(end);
00034   if (cmpbuf == NULL)
00035     {
00036       fprintf(stderr, "Out of memory\n");
00037       fclose(out);
00038       return(1);
00039     }
00040 
00041   fseek(out, 0, SEEK_SET);
00042   stat = fread(cmpbuf, 1, end, out);
00043   if (stat != end)
00044     {
00045       fprintf(stderr, "Failed to read data\n");
00046       fclose(out);
00047       free(cmpbuf);
00048       return(1);
00049     }
00050   if (end == strlen(outbuf) && memcmp(cmpbuf, outbuf, end) == 0)
00051     {
00052       fclose(out);
00053       free(cmpbuf);
00054       return(0);
00055     }
00056 
00057   fclose(out);
00058   free(cmpbuf);
00059   out = fopen(filename, "wb");
00060   if (out == NULL)
00061     {
00062       fprintf(stderr, "Unable to create output file\n");
00063       return(1);
00064     }
00065 
00066   stat = fwrite(outbuf, 1, strlen(outbuf), out);
00067   if (strlen(outbuf) != stat)
00068     {
00069       fprintf(stderr, "Unable to write output file\n");
00070       fclose(out);
00071       return(1);
00072     }
00073   fclose(out);
00074   return(0);
00075 }
00076 
00077 int
00078 main(int argc, char* argv[])
00079 {
00080   int include_tests;
00081   unsigned int i;
00082   char* outbuf;
00083   char* s;
00084   char config[512];
00085 
00086   if (argc == 1)
00087     {
00088       fprintf(stderr, "Not enough arguments\n");
00089       return(1);
00090     }
00091 
00092   outbuf = malloc(256 * 1024);
00093   if (outbuf == NULL)
00094     {
00095       fprintf(stderr, "Out of memory 1\n");
00096       return(1);
00097     }
00098 
00099   s = outbuf;
00100   s = s + sprintf(s, "/* Automatically generated, ");
00101   s = s + sprintf(s, "Edit the Makefile to change configuration */\n");
00102   s = s + sprintf(s, "#ifndef __INCLUDE_CONFIG_H\n");
00103   s = s + sprintf(s, "#define __INCLUDE_CONFIG_H\n");
00104   strcpy(config, "");
00105   include_tests = 0;
00106   for (i = 2; i < argc; i++)
00107     {
00108       if (strcmp(argv[i], "REGTESTS") == 0)
00109         {
00110           include_tests = 1;
00111         }
00112       else
00113         {
00114           s = s + sprintf(s, "#ifndef %s\n", argv[i]);
00115           s = s + sprintf(s, "#define %s\n", argv[i]);
00116           s = s + sprintf(s, "#endif /* %s */\n", argv[i]);
00117         }
00118       strcat(config, argv[i]);
00119       if (i != (argc - 1))
00120     {
00121       strcat(config, " ");
00122     }
00123     }
00124   if (include_tests)
00125     {
00126       s = s + sprintf(s, "#ifndef __ASM__\n");
00127       s = s + sprintf(s, "extern void PrepareTests();\n");
00128       s = s + sprintf(s, "#define PREPARE_TESTS PrepareTests();\n");
00129       s = s + sprintf(s, "#endif /* __ASM__ */\n");
00130     }
00131   else
00132     {
00133       s = s + sprintf(s, "#define PREPARE_TESTS\n");
00134     }
00135   s = s + sprintf(s, "#define CONFIG \"%s\"\n", config);
00136   s = s + sprintf(s, "#endif /* __INCLUDE_CONFIG_H */\n");
00137 
00138   return(write_if_change(outbuf, argv[1]));
00139 }

Generated on Sat May 26 2012 04:36: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.