UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
checklib.cpp
Go to the documentation of this file.
1 
6 /*
7 All original material Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 Copyright (C) 1997-2001 Id Software, Inc.
10 
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 
20 See the GNU General Public License for more details.
21 
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 
26 */
27 
28 
29 #include "checklib.h"
30 #include "../ufo2map.h"
31 #include "../../../shared/entitiesdef.h"
32 #include "../bsp.h"
33 #include "check.h"
34 
49 void Check_Printf (verbosityLevel_t msgVerbLevel, bool change,
50  int entnum, int brushnum, const char* format, ...)
51 {
52  static verbosityLevel_t lastMsgVerbLevel = VERB_NORMAL;
53  static bool firstSuccessfulPrint = true;
54  static bool startOfLine = true;
55  const bool containsNewline = strchr(format, '\n') != nullptr;
56 
57  /* some checking/fix functions are called when ufo2map is compiling
58  * then the check/fix functions should be quiet */
59  if (!(config.performMapCheck || config.fixMap))
60  return;
61 
62  if (entnum == NUM_SAME)
63  msgVerbLevel = lastMsgVerbLevel;
64 
65  lastMsgVerbLevel = msgVerbLevel;
66 
67  if (AbortPrint(msgVerbLevel))
68  return;
69 
70  /* output prefixed with " " is only a warning, should not be
71  * be displayed in fix mode. may be sent here in several function calls.
72  * skip everything from start of line " " to \n */
73  if (config.fixMap) {
74  static int skippingCheckLine = 0;
75  /* skip warning output sent in single call */
76  if (!skippingCheckLine && startOfLine && !change && containsNewline)
77  return;
78 
79  /* enter multi-call skip mode */
80  if (!skippingCheckLine && startOfLine && !change) {
81  skippingCheckLine = 1;
82  return;
83  }
84 
85  /* leave multi-call skip mode */
86  if (skippingCheckLine && containsNewline) {
87  skippingCheckLine = 0;
88  return;
89  }
90 
91  /* middle of multi-call skip mode */
92  if (skippingCheckLine)
93  return;
94  }
95 
96  if (firstSuccessfulPrint && config.verbosity == VERB_MAPNAME) {
97  PrintMapName();
98  firstSuccessfulPrint = false;
99  }
100 
101  {
102  char out_buffer1[4096];
103  {
104  va_list argptr;
105 
106  va_start(argptr, format);
107  Q_vsnprintf(out_buffer1, sizeof(out_buffer1), format, argptr);
108  va_end(argptr);
109  }
110 
111  if (startOfLine) {
112  const char* prefix;
113  prefix = change ? "* " : " ";
114  prefix = (brushnum == NUM_NONE && entnum == NUM_NONE) ? "//" : prefix;
115 
116  printf("%sent:%i brush:%i - %s", prefix, entnum, brushnum, out_buffer1);
117  } else {
118  printf("%s", out_buffer1);
119  }
120  }
121 
122  /* ensure next call gets brushnum and entnum printed if this is the end of the previous*/
123  startOfLine = containsNewline ? true : false;
124 }
125 
126 
132 {
133  char* entitiesUfoBuf;
134 
135  /* only do this once, may be called by different
136  * check functions, depending on command-line */
137  if (numEntityDefs)
138  return;
139 
140  if (FS_LoadFile("ufos/entities.ufo", (byte**)&entitiesUfoBuf) == -1)
141  Sys_Error("CheckEntities: Unable to read entities.ufo");
142 
143  if (ED_Parse((const char*)entitiesUfoBuf) == ED_ERROR)
144  Sys_Error("Error while parsing entities.ufo: %s", ED_GetLastError());
145 
146  /* info has been copied to new malloc'd space in ED_Parse */
147  Mem_Free(entitiesUfoBuf);
148 }
149 
153 void Check_Free (void)
154 {
155  int i;
156 
157  ED_Free();
158 
159  for (i = 0; i < nummapbrushes; i++) {
160  mapbrush_t* iBrush = &mapbrushes[i];
161  if (iBrush->numNear) {
162  assert(iBrush->nearBrushes);
163  Mem_Free(iBrush->nearBrushes);
164  iBrush->numNear = 0;
165  iBrush->nearBrushes = nullptr;
166  }
167  }
168 
169  for (i = 0; i < numCompositeSides; i++) {
171  if (cs->numMembers) {
172  assert(cs->memberSides);
173  Mem_Free(cs->memberSides);
174  cs->numMembers = 0;
175  cs->memberSides = nullptr;
176  }
177  }
178 }
Performs check on a loaded mapfile, and makes changes that can be saved back to the source map...
Performs check on a loaded mapfile, and makes changes that can be saved back to the source map...
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
Definition: shared.cpp:535
void Sys_Error(const char *error,...)
Definition: g_main.cpp:421
int numNear
Definition: map.h:90
void Check_InitEntityDefs(void)
Definition: checklib.cpp:131
int numCompositeSides
Definition: check.cpp:38
#define NUM_SAME
Definition: checklib.h:34
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Definition: files.cpp:384
int nummapbrushes
Definition: map.cpp:35
verbosityLevel_t
verbosity levels for use in calls to Verb_Printf and on the command line -v ...
Definition: shared.h:40
#define NUM_NONE
Definition: checklib.h:32
mapbrush_t mapbrushes[MAX_MAP_BRUSHES]
Definition: map.cpp:34
void ED_Free(void)
int numEntityDefs
Definition: entitiesdef.cpp:45
void Check_Printf(verbosityLevel_t msgVerbLevel, bool change, int entnum, int brushnum, const char *format,...)
decides wether to proceed with output based on verbosity and ufo2map's mode: check/fix/compile ...
Definition: checklib.cpp:49
int ED_Parse(const char *data_p)
void PrintMapName(void)
print name in concise form for lower verbosity levels. verbosity check done before calling this funct...
Definition: ufo2map.cpp:532
static config_t config
Definition: test_all.cpp:43
struct side_s ** memberSides
Definition: check.h:33
compositeSide_t compositeSides[MAX_MAP_SIDES/2]
Definition: check.cpp:37
const char * ED_GetLastError(void)
QGL_EXTERN GLint i
Definition: r_gl.h:113
struct mapbrush_s ** nearBrushes
Definition: map.h:89
void Check_Free(void)
free the mapbrush_t::nearBrushes, compositeSides and entitiesdef.h stuff.
Definition: checklib.cpp:153
int numMembers
Definition: check.h:34
Definition: map.h:75
#define Mem_Free(ptr)
Definition: mem.h:35
bool AbortPrint(const verbosityLevel_t importance)
return nonzero if printing should be aborted based on the command line verbosity level and the import...
Definition: ufo2map.cpp:189
uint8_t byte
Definition: ufotypes.h:34
#define ED_ERROR
Definition: entitiesdef.h:32
void format(__printf__, 1, 2)))