ReactOS 0.4.15-dev-7842-g558ab78
mkconfig.c
Go to the documentation of this file.
1#include <string.h>
2#include <stdlib.h>
3#include <stdio.h>
4
5#ifndef max
6#define max(a, b) ((a) > (b) ? (a) : (b))
7#endif
8
9int
10write_if_change(char* outbuf, char* filename)
11{
12 FILE* out;
13 unsigned int end;
14 char* cmpbuf;
15 unsigned int stat;
16
17 out = fopen(filename, "rb");
18 if (out == NULL)
19 {
20 out = fopen(filename, "wb");
21 if (out == NULL)
22 {
23 fprintf(stderr, "Unable to create output file\n");
24 return(1);
25 }
26 fputs(outbuf, out);
27 fclose(out);
28 return(0);
29 }
30
31 fseek(out, 0, SEEK_END);
32 end = ftell(out);
33 cmpbuf = malloc(end);
34 if (cmpbuf == NULL)
35 {
36 fprintf(stderr, "Out of memory\n");
37 fclose(out);
38 return(1);
39 }
40
41 fseek(out, 0, SEEK_SET);
42 stat = fread(cmpbuf, 1, end, out);
43 if (stat != end)
44 {
45 fprintf(stderr, "Failed to read data\n");
46 fclose(out);
47 free(cmpbuf);
48 return(1);
49 }
50 if (end == strlen(outbuf) && memcmp(cmpbuf, outbuf, end) == 0)
51 {
52 fclose(out);
53 free(cmpbuf);
54 return(0);
55 }
56
57 fclose(out);
58 free(cmpbuf);
59 out = fopen(filename, "wb");
60 if (out == NULL)
61 {
62 fprintf(stderr, "Unable to create output file\n");
63 return(1);
64 }
65
66 stat = fwrite(outbuf, 1, strlen(outbuf), out);
67 if (strlen(outbuf) != stat)
68 {
69 fprintf(stderr, "Unable to write output file\n");
70 fclose(out);
71 return(1);
72 }
73 fclose(out);
74 return(0);
75}
76
77int
78main(int argc, char* argv[])
79{
80 int include_tests;
81 unsigned int i;
82 char* outbuf;
83 char* s;
84 char config[512];
85
86 if (argc == 1)
87 {
88 fprintf(stderr, "Not enough arguments\n");
89 return(1);
90 }
91
92 outbuf = malloc(256 * 1024);
93 if (outbuf == NULL)
94 {
95 fprintf(stderr, "Out of memory 1\n");
96 return(1);
97 }
98
99 s = outbuf;
100 s = s + sprintf(s, "/* Automatically generated, ");
101 s = s + sprintf(s, "Edit the Makefile to change configuration */\n");
102 s = s + sprintf(s, "#ifndef __INCLUDE_CONFIG_H\n");
103 s = s + sprintf(s, "#define __INCLUDE_CONFIG_H\n");
104 strcpy(config, "");
105 include_tests = 0;
106 for (i = 2; i < argc; i++)
107 {
108 if (strcmp(argv[i], "REGTESTS") == 0)
109 {
110 include_tests = 1;
111 }
112 else
113 {
114 s = s + sprintf(s, "#ifndef %s\n", argv[i]);
115 s = s + sprintf(s, "#define %s\n", argv[i]);
116 s = s + sprintf(s, "#endif /* %s */\n", argv[i]);
117 }
118 strcat(config, argv[i]);
119 if (i != (argc - 1))
120 {
121 strcat(config, " ");
122 }
123 }
124 if (include_tests)
125 {
126 s = s + sprintf(s, "#ifndef __ASM__\n");
127 s = s + sprintf(s, "extern void PrepareTests();\n");
128 s = s + sprintf(s, "#define PREPARE_TESTS PrepareTests();\n");
129 s = s + sprintf(s, "#endif /* __ASM__ */\n");
130 }
131 else
132 {
133 s = s + sprintf(s, "#define PREPARE_TESTS\n");
134 }
135 s = s + sprintf(s, "#define CONFIG \"%s\"\n", config);
136 s = s + sprintf(s, "#endif /* __INCLUDE_CONFIG_H */\n");
137
138 return(write_if_change(outbuf, argv[1]));
139}
static int argc
Definition: ServiceArgs.c:12
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define stat
Definition: acwin.h:99
#define SEEK_END
Definition: cabinet.c:29
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
int main()
Definition: test.c:6
GLdouble s
Definition: gl.h:2039
GLuint GLuint end
Definition: gl.h:1545
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
const char * filename
Definition: ioapi.h:137
#define SEEK_SET
Definition: jmemansi.c:26
int write_if_change(char *outbuf, char *filename)
Definition: mkconfig.c:10
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define argv
Definition: mplay32.c:18
static FILE * out
Definition: regtests2xml.c:44
Definition: stat.h:55