ReactOS  0.4.15-dev-1207-g698a8e6
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[] 
)

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

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
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
int write_if_change(char *outbuf, char *filename)
Definition: mkconfig.c:10
#define argv
Definition: mplay32.c:18
#define sprintf(buf, format,...)
Definition: sprintf.c:55
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
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
GLdouble s
Definition: gl.h:2039
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
FILE * stderr
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4

◆ 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 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define free
Definition: debug_ros.c:5
GLuint GLuint end
Definition: gl.h:1545
_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:135
_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_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
#define SEEK_SET
Definition: jmemansi.c:26
static FILE * out
Definition: regtests2xml.c:44
Definition: stat.h:55
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
FILE * stderr
#define SEEK_END
Definition: cabinet.c:27
#define malloc
Definition: debug_ros.c:4
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)

Referenced by main().