File: main.cc

package info (click to toggle)
glbsp 2.24-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,220 kB
  • sloc: cpp: 10,762; ansic: 6,953; makefile: 121; sh: 14
file content (232 lines) | stat: -rw-r--r-- 5,885 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//------------------------------------------------------------------------
// MAIN : Unix/FLTK Main program
//------------------------------------------------------------------------
//
//  GL-Friendly Node Builder (C) 2000-2007 Andrew Apted
//
//  Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//------------------------------------------------------------------------

// this includes everything we need
#include "local.h"


#define MY_TITLE  ("glBSP Node Builder " GLBSP_VER)


// Node building info

nodebuildinfo_t guix_info;

volatile nodebuildcomms_t guix_comms;

const nodebuildfuncs_t guix_funcs =
{
  GUI_FatalError,
  GUI_PrintMsg,
  GUI_Ticker,

  GUI_DisplayOpen,
  GUI_DisplaySetTitle,
  GUI_DisplaySetBar,
  GUI_DisplaySetBarLimit,
  GUI_DisplaySetBarText,
  GUI_DisplayClose
};


// GUI-specific Globals

guix_preferences_t guix_prefs;

const guix_preferences_t default_guiprefs =
{
#ifdef WIN32
  40,  20,     // win_x, win_y
#else
  40,  50,
#endif
  550, 520,    // win_w, win_h;

  120, 200,    // progress_x, progress_y
  90, 200,     // dialog_x, dialog_y
  80, 100,     // other_x, other_y

  20, 50,      // manual_x, manual_y
  610, 520,    // manual_w, manual_h
  0,           // manual_page

  TRUE,        // overwrite_warn
  TRUE,        // same_file_warn
  TRUE,        // lack_ext_warn
  NULL         // save_log_file
};


/* ----- user information ----------------------------- */


static void ShowTitle(void)
{
  GUI_PrintMsg(
    "\n"
    "**** GLBSP Node Builder " GLBSP_VER " (C) 2007 Andrew Apted ****\n\n"
  );
}

static void ShowInfo(void)
{
  GUI_PrintMsg(
    "This GL node builder was originally based on BSP 2.3, which was\n"
    "created from the basic theory stated in DEU5 (OBJECTS.C)\n"
    "\n"
    "Credits should go to :-\n"
    "  Andy Baker & Marc Pullen   for their invaluable help\n"
    "  Janis Legzdinsh            for fixing up Hexen support\n"
    "  Colin Reed & Lee Killough  for creating the original BSP\n"
    "  Matt Fell                  for the Doom Specs\n"
    "  Raphael Quinet             for DEU and the original idea\n"
    "  ... and everyone who helped with the original BSP.\n"
    "\n"
    "This program is free software, under the terms of the GNU General\n"
    "Public License, and comes with ABSOLUTELY NO WARRANTY.  See the\n"
    "accompanying documentation for more details.\n"
    "\n"
    "Note: glBSPX is the GUI (graphical user interface) version.\n"
    "Try plain \"glbsp\" if you want the command-line version.\n"
  );
}


void MainSetDefaults(void)
{
  // this is more messy than it was in C
  memcpy((nodebuildinfo_t  *) &guix_info,  &default_buildinfo,  
      sizeof(guix_info));

  memcpy((nodebuildcomms_t *) &guix_comms, &default_buildcomms, 
      sizeof(guix_comms));

  memcpy((guix_preferences_t *) &guix_prefs, &default_guiprefs,
      sizeof(guix_prefs));

  // set default filename for saving the log
  guix_prefs.save_log_file = GlbspStrDup("glbsp.log");
}


/* ----- main program ----------------------------- */



int main(int argc, char **argv)
{
  if (argc > 1 &&
      (strcmp(argv[1], "/?") == 0 || strcmp(argv[1], "-h") == 0 ||
       strcmp(argv[1], "-help") == 0 || strcmp(argv[1], "--help") == 0 ||
       strcmp(argv[1], "-HELP") == 0 || strcmp(argv[1], "--HELP") == 0))
  {
    ShowTitle();
    ShowInfo();
    exit(1);
  }

  int first_arg = 1;

#ifdef MACOSX
  if (first_arg < argc && (strncmp(argv[first_arg], "-psn", 4) == 0))
    first_arg++;
#endif

  // set defaults, also initializes the nodebuildxxxx stuff
  MainSetDefaults();

  // read persistent data
  CookieSetPath(argv[0]);

  cookie_status_t cookie_ret = CookieReadAll();

  // handle drag and drop: a single non-option argument
  //
  // NOTE: there is no support for giving options to glBSPX via the
  // command line.  Plain 'glbsp' should be used if this is desired.
  // The difficult here lies in possible conflicts between given
  // options and those already set from within the GUI.  Plus we may
  // want to handle a drag-n-drop of multiple files later on.
  //
  boolean_g unused_args = FALSE;

  if (first_arg < argc && argv[first_arg][0] != '-')
  {
    GlbspFree(guix_info.input_file);
    GlbspFree(guix_info.output_file);

    guix_info.input_file = GlbspStrDup(argv[first_arg]);

    // guess an output name too
    
    guix_info.output_file = GlbspStrDup(
        HelperGuessOutput(guix_info.input_file));
 
    first_arg++;
  }

  if (first_arg < argc)
    unused_args = TRUE;


  // load icons for file chooser
  Fl_File_Icon::load_system_icons();

  guix_win = new Guix_MainWin(MY_TITLE);
   
  DialogLoadImages();

  ShowTitle();

  switch (cookie_ret)
  {
    case COOKIE_E_OK:
      break;

    case COOKIE_E_NO_FILE:
      guix_win->text_box->AddMsg(
          "** Missing INI file -- Using defaults **\n\n", FL_RED, TRUE);
      break;

    case COOKIE_E_PARSE_ERRORS:
    case COOKIE_E_CHECK_ERRORS:
      guix_win->text_box->AddMsg(
          "** Warning: Errors found in INI file **\n\n", FL_RED, TRUE);
      break;
  }

  if (unused_args)
    guix_win->text_box->AddMsg(
        "** Warning: Ignoring extra arguments to glBSPX **\n\n", FL_RED, TRUE);

  // run the GUI until the user quits
  while (! guix_win->want_quit)
    Fl::wait();

  delete guix_win;
  guix_win = NULL;

  CookieWriteAll();

  DialogFreeImages();

  return 0;
}