ReactOS 0.4.16-dev-2104-gb84fa49
mkconfig.c File Reference
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Include dependency graph for mkconfig.c:

Go to the source code of this file.

Macros

#define max(a, b)   ((a) > (b) ? (a) : (b))
 

Functions

int write_if_change (char *outbuf, char *filename)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ max

#define max (   a,
  b 
)    ((a) > (b) ? (a) : (b))

Definition at line 6 of file mkconfig.c.

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)

Definition at line 78 of file mkconfig.c.

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
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
int WINAPIV fprintf(FILE *file, const char *format,...)
Definition: file.c:5549
#define stderr
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
GLdouble s
Definition: gl.h:2039
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
int write_if_change(char *outbuf, char *filename)
Definition: mkconfig.c:10
#define sprintf
Definition: sprintf.c:45
#define argv
Definition: mplay32.c:18
strcat
Definition: string.h:92
strcpy
Definition: string.h:131

◆ write_if_change()

int write_if_change ( char outbuf,
char filename 
)

Definition at line 10 of file mkconfig.c.

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}
#define stat
Definition: acwin.h:99
#define SEEK_END
Definition: cabinet.c:29
#define free
Definition: debug_ros.c:5
__msvcrt_long CDECL ftell(FILE *file)
Definition: file.c:4740
int CDECL fclose(FILE *file)
Definition: file.c:3757
int CDECL fseek(FILE *file, __msvcrt_long offset, int whence)
Definition: file.c:1610
size_t CDECL fread(void *ptr, size_t size, size_t nmemb, FILE *file)
Definition: file.c:4406
int CDECL fputs(const char *s, FILE *file)
Definition: file.c:4769
FILE *CDECL fopen(const char *path, const char *mode)
Definition: file.c:4310
size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file)
Definition: file.c:4129
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
GLuint GLuint end
Definition: gl.h:1545
const char * filename
Definition: ioapi.h:137
#define SEEK_SET
Definition: jmemansi.c:26
Definition: stat.h:66
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383

Referenced by main().