ReactOS  0.4.10-dev-7-g0d308f4
util.h File Reference
#include <stdio.h>
#include "cmd.h"
#include "options.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define log(outFile, fmt,...)
 
#define esclog(outFile, fmt,...)
 
#define clilog(outFile, fmt,...)
 
#define l2l_dbg(level,...)
 

Functions

int file_exists (char *name)
 
int mkPath (char *path, int isDir)
 
charbasename (char *path)
 
const chargetFmt (const char *a)
 
long my_atoi (const char *a)
 
int isOffset (const char *a)
 
int copy_file (char *src, char *dst)
 
int set_LogFile (FILE **plogFile)
 

Macro Definition Documentation

#define clilog (   outFile,
  fmt,
  ... 
)
Value:
{ \
esclog(outFile, fmt, ##__VA_ARGS__) \
log(outFile, fmt, ##__VA_ARGS__); \
}
#define esclog(outFile, fmt,...)
Definition: util.h:22
if(!(yy_init))
Definition: macro.lex.yy.c:717
int opt_cli
Definition: options.c:31
Definition: dsound.c:943
#define log(outFile, fmt,...)
Definition: util.h:15

Definition at line 27 of file util.h.

Referenced by regscan(), and stat_print().

#define esclog (   outFile,
  fmt,
  ... 
)
Value:
{ \
log(outFile, KDBG_ESC_RESP fmt, ##__VA_ARGS__); \
}
#define KDBG_ESC_RESP
Definition: cmd.h:15
Definition: dsound.c:943
#define log(outFile, fmt,...)
Definition: util.h:15

Definition at line 22 of file util.h.

Referenced by handle_address_cmd(), handle_escape_cmd(), handle_switch(), handle_switch_pstr(), and handle_switch_str().

#define l2l_dbg (   level,
  ... 
)
Value:
{ \
fprintf(stderr, ##__VA_ARGS__); \
}
GLint level
Definition: gl.h:1546
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
if(!(yy_init))
Definition: macro.lex.yy.c:717
int opt_verbose
Definition: options.c:25
FILE * stderr

Definition at line 35 of file util.h.

Referenced by cache_entry_create(), check_directory(), copy_file(), create_cache(), get_ImageBase(), get_sectionheader(), getRevision(), getTBRevision(), log_file(), main(), match_mod(), optionInit(), optionParse(), process_data(), process_file(), read_cache(), regscan(), set_LogFile(), sources_entry_create(), translate_file(), unpack_iso(), and updateSvnlog().

#define log (   outFile,
  fmt,
  ... 
)
Value:
{ \
fprintf(outFile, fmt, ##__VA_ARGS__); \
fprintf(logFile, fmt, ##__VA_ARGS__); \
}
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
char logFile[_MAX_PATH]
Definition: tftpd.cpp:38
if(!(yy_init))
Definition: macro.lex.yy.c:717
Definition: dsound.c:943

Definition at line 15 of file util.h.

Referenced by __ieee754_log(), _CIlog(), acosh(), asinh(), atanh(), check_entropy(), check_no_duplicates(), DoOpenFile(), DSOUND_AmpFactorToVolPan(), Global_Log(), handle_escape_cmd(), CMathTest::import_checks(), log_file(), log_rev_check(), log_state(), logf(), logSource(), lzx_init_static(), make_conv16to8_table(), Math_log(), Number_toString(), pres_log(), print_glsl_info_log(), rpn_ln(), ValarrayTest::transcendentals(), translate_files(), and translate_line().

Function Documentation

char* basename ( char path)

Definition at line 110 of file util.c.

111 {
112  char *base;
113 
114  base = strrchr(path, PATH_CHAR);
115  if (base)
116  return ++base;
117  return path;
118 }
GLsizei const GLchar ** path
Definition: glext.h:7234
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
#define PATH_CHAR
Definition: rmkdir.c:17
Definition: services.c:325
int copy_file ( char src,
char dst 
)

Definition at line 163 of file util.c.

164 {
165  char Line[LINESIZE];
166 
167  sprintf(Line, CP_FMT, src, dst);
168  l2l_dbg(2, "Executing: %s\n", Line);
169  remove(dst);
170  if (file_exists(dst))
171  {
172  l2l_dbg(0, "Cannot remove dst %s before copy\n", dst);
173  return 1;
174  }
175  if (system(Line) < 0)
176  {
177  l2l_dbg(0, "Cannot copy %s to %s\n", src, dst);
178  l2l_dbg(1, "Failed to execute: '%s'\n", Line);
179  return 2;
180  }
181 
182  if (!file_exists(dst))
183  {
184  l2l_dbg(0, "Dst %s does not exist after copy\n", dst);
185  return 2;
186  }
187  return 0;
188 }
int file_exists(char *name)
Definition: util.c:52
#define sprintf(buf, format,...)
Definition: sprintf.c:55
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
#define l2l_dbg(level,...)
Definition: util.h:35
int __cdecl system(_In_opt_z_ const char *_Command)
Definition: ncftp.h:79
#define CP_FMT
Definition: config.h:20
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define LINESIZE
Definition: chargen.c:18
int file_exists ( char name)

Definition at line 52 of file util.c.

Referenced by copy_file().

53 {
54  FILE *f;
55 
56  f = fopen(name, "r");
57  if (!f)
58  return 0;
59  fclose(f);
60  return 1;
61 }
_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)
#define f
Definition: ke_i.h:83
Definition: name.c:36
const char* getFmt ( const char a)

Definition at line 121 of file util.c.

Referenced by isOffset(), and my_atoi().

122 {
123  const char *fmt = "%x";
124 
125  if (*a == '0')
126  {
127  switch (*++a)
128  {
129  case 'x':
130  fmt = "%x";
131  ++a;
132  break;
133  case 'd':
134  fmt = "%d";
135  ++a;
136  break;
137  default:
138  fmt = "%o";
139  break;
140  }
141  }
142  return fmt;
143 }
const char * fmt
Definition: wsprintf.c:30
#define a
Definition: ke_i.h:78
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
Definition: dsound.c:943
int isOffset ( const char a)

Definition at line 154 of file util.c.

Referenced by main().

155 {
156  int i = 0;
157  if (strchr(a, '.'))
158  return 0;
159  return sscanf(a, getFmt(a), &i);
160 }
const char * getFmt(const char *a)
Definition: util.c:121
GLenum GLclampf GLint i
Definition: glfuncs.h:14
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
char * strchr(const char *String, int ch)
Definition: utclib.c:501
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
int mkPath ( char path,
int  isDir 
)

Definition at line 68 of file util.c.

Referenced by mkPath().

69 {
70  char *s;
71  int res = 0;
72 
73  if (isDir)
74  {
75  res = MKDIR(path);
76  if (!res || (res == -1 && errno == EEXIST))
77  return 0;
78  }
79  // create parent dir
80  if ((s = strrchr(path, PATH_CHAR)))
81  {
82  *s = '\0';
83  res = mkPath(path, 1);
84  *s = PATH_CHAR;
85  }
86 
87  if (!res && isDir)
88  res = MKDIR(path);
89 
90  return res;
91 }
int mkPath(char *path, int isDir)
Definition: util.c:68
int errno
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define EEXIST
Definition: acclib.h:88
#define MKDIR(d)
Definition: compat.h:23
GLdouble s
Definition: gl.h:2039
#define PATH_CHAR
Definition: rmkdir.c:17
Definition: services.c:325
GLuint res
Definition: glext.h:9613
long my_atoi ( const char a)

Definition at line 146 of file util.c.

Referenced by main().

147 {
148  int i = 0;
149  sscanf(a, getFmt(a), &i);
150  return i;
151 }
const char * getFmt(const char *a)
Definition: util.c:121
GLenum GLclampf GLint i
Definition: glfuncs.h:14
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
int set_LogFile ( FILE **  plogFile)

Definition at line 19 of file util.c.

Referenced by handle_escape_cmd(), and main().

20 {
21  if (*opt_logFile)
22  {
23  if (*plogFile)
24  fclose(*plogFile);
25  *plogFile = NULL;
26 
27  if (strcmp(opt_logFile,"none") == 0)
28  return 0; //just close
29 
30  *plogFile = fopen(opt_logFile, opt_mod ? opt_mod : "a");
31  if (*plogFile)
32  {
33  // disable buffering so fflush is not needed
34  if (!opt_buffered)
35  {
36  l2l_dbg(1, "Disabling log buffering on %s\n", opt_logFile);
37  setbuf(*plogFile, NULL);
38  }
39  else
40  l2l_dbg(1, "Enabling log buffering on %s\n", opt_logFile);
41  }
42  else
43  {
44  l2l_dbg(0, "Could not open logfile %s (%s)\n", opt_logFile, strerror(errno));
45  return 2;
46  }
47  }
48  return 0;
49 }
int opt_buffered
Definition: options.c:21
int errno
char opt_logFile[PATH_MAX]
Definition: options.c:43
const char * strerror(int err)
Definition: compat_str.c:23
char * opt_mod
Definition: options.c:44
#define l2l_dbg(level,...)
Definition: util.h:35
smooth NULL
Definition: ftsmooth.c:416
_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)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
_CRTIMP void __cdecl setbuf(_Inout_ FILE *_File, _Inout_updates_opt_(BUFSIZ) _Post_readable_size_(0) char *_Buffer)