VisItInit.C 19.8 KB
Newer Older
hrchilds's avatar
hrchilds committed
1
2
/*****************************************************************************
*
brugger's avatar
   
brugger committed
3
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
brugger's avatar
   
brugger committed
5
* LLNL-CODE-400142
hrchilds's avatar
hrchilds committed
6
7
* All rights reserved.
*
brugger's avatar
   
brugger committed
8
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
hrchilds's avatar
hrchilds committed
9
10
11
12
13
14
15
16
17
18
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
brugger's avatar
   
brugger committed
19
20
21
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
hrchilds's avatar
hrchilds committed
22
23
24
25
26
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
brugger's avatar
   
brugger committed
27
28
29
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
hrchilds's avatar
hrchilds committed
30
31
32
33
34
35
36
37
38
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

hrchilds's avatar
hrchilds committed
39
40
41
42
// ************************************************************************* //
//                                    Init.C                                 //
// ************************************************************************* //

43
#include <VisItInit.h>
hrchilds's avatar
hrchilds committed
44
45
46
47
48
49
50
51
52
53
54

#include <stdio.h>
#include <stdlib.h>
#if defined(_WIN32)
#include <process.h>
#include <winsock2.h>
#else
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
#endif
55
#include <new>
56
#include <cstring>
hrchilds's avatar
hrchilds committed
57

58
#include <DebugStreamFull.h>
miller86's avatar
miller86 committed
59
#include <DebugStream.h>
60
#include <InstallationFunctions.h>
hrchilds's avatar
hrchilds committed
61
#include <TimingsManager.h>
62
#include <visit-config.h>
hrchilds's avatar
hrchilds committed
63
64

static void RemovePrependedDirs(const char *, char *); 
hrchilds's avatar
hrchilds committed
65
66
static char executableName[256];
static char componentName[256];
67
68
69
70
71
72
73
static const char *AVTPREP = "avtprep";
static const char *CLI = "cli";
static const char *ENGINE = "engine";
static const char *GUI = "gui";
static const char *LAUNCHER = "launcher";
static const char *MDSERVER = "mdserver";
static const char *VIEWER = "viewer";
hrchilds's avatar
hrchilds committed
74
static const char *const allComponentNames[] = {
75
76
77
78
79
80
81
    AVTPREP,
    CLI,
    ENGINE,
    GUI,
    LAUNCHER,
    MDSERVER,
    VIEWER
hrchilds's avatar
hrchilds committed
82
};
hrchilds's avatar
hrchilds committed
83
84
static ErrorFunction errorFunction = NULL;
static void *errorFunctionArgs = NULL;
85
86
static bool initializeCalled = false;
static bool finalizeCalled = false;
hrchilds's avatar
hrchilds committed
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

// ****************************************************************************
//  Function: striparg
//
//  Purpose:
//      Given an argc and an argv, strip off the arguments from i to i+n.
//
//  Arguments:
//      i           The first argument to strip      (i)
//      n           The number of arguments to strip (i)
//      argc        The number of total arguments    (io)
//      argv        The array of arguments           (io)
//
//  Programmer: Jeremy Meredith
//  Creation:   November 16, 2000
//
//  Modifications:
//    Jeremy Meredith, Fri Feb  1 16:05:05 PST 2002
//    Fixed a bug where it was copying beyond the end of the array.
//
// ****************************************************************************
static void
striparg(int i, int n, int &argc, char *argv[])
{
    for ( ; i+n<argc; i++)
        argv[i] = argv[i+n];

    argc -= n;
}

// ****************************************************************************
//  Function: NewHandler
//
//  Purpose:
//      Called when the component runs out of memory.
//
//  Programmer: Hank Childs
//  Creation:   August 21, 2001
//
//  Modifications:
//
//    Hank Childs, Tue Nov 20 13:07:51 PST 2001
//    Added an abort.
//
// ****************************************************************************
static void
NewHandler(void)
{
    debug1 << "This component has run out of memory." << endl;
    abort();
}

// ****************************************************************************
140
//  Function: VisItInit::Initialize
hrchilds's avatar
hrchilds committed
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
//
//  Purpose:
//      Parse any common commandline arguments (e.g. "-debug N") and do
//      common initialization.
//
//  Arguments:
//      argc        The number of total arguments                       (io)
//      argv        The array of arguments                              (io)
//      r           The rank of this process                            (i)
//      n           The total number of processes                       (i)
//      strip       Whether or not to strip the argument from the list. (i)
//
//  Programmer: Jeremy Meredith
//  Creation:   November 16, 2000
//
//  Modifications:
//    Brad Whitlock, Mon Nov 27 16:25:07 PST 2000
//    I added a new flag that indicates whether or not to strip the argument
//    from the list after processing it.
//
//    Hank Childs, Sat Mar 10 15:35:36 PST 2001
//    Start timings manager too.
//
//    Hank Childs, Mon Aug 13 13:43:21 PDT 2001
//    Remove the directory before the program name to allow debug stream to
//    go to current directory.
//
//    Hank Childs, Tue Aug 21 13:05:28 PDT 2001
//    Registered a new handler.
//
//    Jeremy Meredith, Fri Feb  1 16:05:36 PST 2002
//    Added an 'else' to the if test when checking arguments, and added a
//    '--i' when stripping the arg.
//
//    Brad Whitlock, Thu Mar 14 12:43:34 PDT 2002
//    Made it work on Windows. Added code to initialize sockets.
//
//    Jeremy Meredith, Wed Aug  7 13:17:01 PDT 2002
//    Made it clamp the debug level to 0 through 5.
//
hrchilds's avatar
hrchilds committed
181
182
183
184
185
//    Brad Whitlock, Wed May 21 17:03:56 PST 2003
//    I made it write the command line arguments to the debug logs.
//
//    Brad Whitlock, Wed Jun 18 11:15:22 PDT 2003
//    I made it understand the -timing argument.
hrchilds's avatar
hrchilds committed
186
//
hrchilds's avatar
hrchilds committed
187
188
189
//    Hank Childs, Tue Jun  1 11:47:36 PDT 2004
//    Removed atexit call, since that is buggy with gcc.
//
hrchilds's avatar
hrchilds committed
190
191
192
//    Jeremy Meredith, Tue May 17 11:20:51 PDT 2005
//    Allow disabling of signal handlers.
//
hrchilds's avatar
hrchilds committed
193
194
195
196
//    Mark C. Miller, Wed Aug  2 19:58:44 PDT 2006
//    Added explicit call to SetFilename for TimingsManager. This is to
//    handle cases where TimingsManager may have already been instanced
//    before Initialize is called as in the engine.
197
198
199
200
//
//    Kathleen Bonnell, Wed Aug 22 18:00:57 PDT 2007 
//    On Windows, write timings and log files to User's directory. 
//
cyrush's avatar
cyrush committed
201
202
203
204
//    Cyrus Harrison, Tue Sep  4 10:54:59 PDT 2007
//    If -vtk-debug is specified make sure the debug level is at least 1
//    for the engine
//
hrchilds's avatar
hrchilds committed
205
206
207
//    Hank Childs, Tue Dec 18 15:53:10 PST 2007
//    Add support for -svn_revision.
//
208
209
210
//    Cyrus Harrison, Wed Jan 23 09:23:19 PST 2008
//    Changed set_new_handler to std::set_new_handler b/c of change from 
//    deprecated <new.h> to <new>
211
212
213
214
215
216
//
//    Brad Whitlock, Wed Jun 25 10:42:58 PDT 2008
//    Added check to return early in case this function gets called multiple
//    times as when you include multiple VisIt components in a single
//    executable.
//
217
218
219
220
//    Dave Pugmire, Thu Jan 15 16:35:08 EST 2009
//    Add support for -debug_engine_rank, limiting debug output to the specified
//    rank.
//
221
222
223
//    Brad Whitlock, Fri Apr 10 16:00:55 PDT 2009
//    I added support for reading -dv.
//
224
225
226
//    Mark C. Miller, Tue Apr 21 14:24:18 PDT 2009
//    Added logic to manage buffering of debug logs; an extra 'b' after level.
//
hrchilds's avatar
hrchilds committed
227
228
229
// ****************************************************************************

void
230
VisItInit::Initialize(int &argc, char *argv[], int r, int n, bool strip, bool sigs)
hrchilds's avatar
hrchilds committed
231
{
232
233
234
235
236
    // Return if Initialize has already been called.
    if(initializeCalled)
         return;
    initializeCalled = true;

237
    int i, debuglevel = 0, engineDebugRank=-1;
hrchilds's avatar
hrchilds committed
238
239
240
#if defined(_WIN32)
    bool usePid = true;
#else
hrchilds's avatar
hrchilds committed
241
    bool usePid = false;
hrchilds's avatar
hrchilds committed
242
#endif
243
    bool bufferDebug = false;
244
    bool clobberVlogs = false;
cyrush's avatar
cyrush committed
245
    bool vtk_debug = false;
hrchilds's avatar
hrchilds committed
246
247
    bool enableTimings = false;
    for (i=1; i<argc; i++)
hrchilds's avatar
hrchilds committed
248
    {
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
        if (strcmp("-debug_engine_rank", argv[i]) == 0)
        {
            engineDebugRank = -1;
            if (i+1 < argc && isdigit(*(argv[i+1])))
                engineDebugRank = atoi(argv[i+1]);
            else
                cerr<<"Warning: debug engine rank not specified. Igorning.\n";
            if (engineDebugRank >= n)
            {
                cerr<<"Warning: clamping debug engine rank to "<<n-1<<endl;
                engineDebugRank = n-1;
            }
            else if (engineDebugRank < 0)
            {
                cerr<<"Warning: clamping debug engine rank to 0\n";
                engineDebugRank = 0;
            }
            if(strip)
            {
                striparg(i,2, argc,argv);
                --i;
            }
            else
                ++i;
        }

275
        if (strncmp("-debug",argv[i],6) == 0)
hrchilds's avatar
hrchilds committed
276
        {
277
278
279
280
281
282
283
284
	    if ((strlen(argv[i]) > 7 && IsComponent(&argv[i][7])) ||
	         strlen(argv[i]) == 6)
	    {
                debuglevel = 1;
                if (i+1 < argc && isdigit(*(argv[i+1])))
                   debuglevel = atoi(argv[i+1]);
                else
                   cerr << "Warning: debug level not specified, assuming 1\n";
285

286
287
288
289
290
291
292
293
294
295
                if (debuglevel > 5)
                {
                    cerr << "Warning: clamping debug level to 5\n";
                    debuglevel = 5;
                }
                if (debuglevel < 0)
                {
                    cerr << "Warning: clamping debug level to 0\n";
                    debuglevel = 0;
                }
296
297
298
                if (i+1 < argc && *(argv[i+1]+1) == 'b')
                    bufferDebug = true;

299
300
301
302
303
304
305
306
307
308
309
310
311
312
                if(strip)
                {
                    striparg(i,2, argc,argv);
                    --i;
                }
                else
                {
                    ++i;
                }
	    }
        }
        else if (strcmp("-clobber_vlogs", argv[i]) == 0)
        {
            clobberVlogs = true;
hrchilds's avatar
hrchilds committed
313
314
315
316
317
        }
        else if (strcmp("-pid", argv[i]) == 0)
        {
            usePid = true;
        }
cyrush's avatar
cyrush committed
318
319
320
321
        else if (strcmp("-vtk-debug", argv[i]) == 0)
        {
            vtk_debug = true;
        }
hrchilds's avatar
hrchilds committed
322
323
324
325
326
        else if (strcmp("-timing",  argv[i]) == 0 ||
                 strcmp("-timings", argv[i]) == 0)
        {
            enableTimings = true;
        }
327
328
329
330
        else if (strcmp("-dv",  argv[i]) == 0)
        {
            SetIsDevelopmentVersion(true);
        }
hrchilds's avatar
hrchilds committed
331
332
        else if (strcmp("-svn_revision",  argv[i]) == 0)
        {
333
            if (strcmp(VISIT_SVN_REVISION, "") == 0)
hrchilds's avatar
hrchilds committed
334
335
                cerr << "SVN revision is unknown!" << endl;
            else
336
                cerr << "Built from revision " << VISIT_SVN_REVISION << endl;
hrchilds's avatar
hrchilds committed
337
338
            exit(0);
        }
hrchilds's avatar
hrchilds committed
339
340
341
342
    }

    char progname_wo_dir[256];
    RemovePrependedDirs(argv[0], progname_wo_dir);
hrchilds's avatar
hrchilds committed
343
344
    strcpy(executableName, progname_wo_dir);
    strcpy(componentName, progname_wo_dir);
345
346
347
348
349
350
351
352
#ifdef WIN32
    // On windows, we want timings and log files to go in user's directory,
    // not install directory, because users may not have write permissions.
    const char *home = getenv("VISITUSERHOME");
    std::string homedir;
    if(home != 0)
    {
        homedir = std::string(home);
353
354
        if(homedir[homedir.size() - 1] != VISIT_SLASH_CHAR)
            homedir += VISIT_SLASH_STRING;
355
356
357
358
        homedir += executableName;
        strcpy(progname_wo_dir, homedir.c_str());
    }
#endif
hrchilds's avatar
hrchilds committed
359
360
361
362
363
364
365
366
367
    char progname[256];
    if (n > 1)
    {
        sprintf(progname, "%s.%03d", progname_wo_dir, r);
    }
    else
    {
        strcpy(progname, progname_wo_dir);
    }
368
    
hrchilds's avatar
hrchilds committed
369
370
371
372
373
374
375
376
377
378
379
380
    if (usePid)
    {
#if defined(_WIN32)
        int pid = _getpid();
#else
        int pid = (int) getpid();
#endif
        char progname2[256];
        sprintf(progname2, "%s.%d", progname, pid);
        strcpy(progname, progname2);
    }

cyrush's avatar
cyrush committed
381
382
383
384
385
    // if this is the engine and -vtk-debug is enabled, make sure the
    // debuglevel is at least 1
    if(vtk_debug && strstr(progname,"engine") != NULL  && debuglevel < 1)
        debuglevel = 1;

386
387
388
389
390
391
392
    // If debug rank specified, and we are not rank 'r', then turn off debuging.
    if ((strncmp(progname, ENGINE, strlen(ENGINE)) == 0) &&
        engineDebugRank != -1 && engineDebugRank != r)
    {
        debuglevel = 0;
    }
    
hrchilds's avatar
hrchilds committed
393
394
    // Initialize the debug streams and also add the command line arguments
    // to the debug logs.
miller86's avatar
miller86 committed
395
    DebugStreamFull::Initialize(progname, debuglevel, sigs, clobberVlogs, bufferDebug);
hrchilds's avatar
hrchilds committed
396
397
398
399
    for(i = 0; i < argc; ++i)
        debug1 << argv[i] << " ";
    debug1 << endl;

hrchilds's avatar
hrchilds committed
400
    TimingsManager::Initialize(progname);
hrchilds's avatar
hrchilds committed
401
402
    // In case TimingsManager was already initialized...
    visitTimer->SetFilename(progname);
hrchilds's avatar
hrchilds committed
403
404
    if(enableTimings)
        visitTimer->Enable();
hrchilds's avatar
hrchilds committed
405
406

#if !defined(_WIN32)
407
    std::set_new_handler(NewHandler);
hrchilds's avatar
hrchilds committed
408
409
410
411
412
413
414
415
416
417
418
419
420
#endif

#if defined(_WIN32)
    // Windows specific code
    WORD wVersionRequested;
    WSADATA wsaData;

    // Initiate the use of a Winsock DLL (WS2_32.DLL), necessary for sockets.
    wVersionRequested = MAKEWORD(2,2);
    WSAStartup(wVersionRequested, &wsaData);
#endif
}

hrchilds's avatar
hrchilds committed
421
// ****************************************************************************
422
//  Function: VisItInit::SetComponentName
hrchilds's avatar
hrchilds committed
423
424
425
426
427
428
//
//  Purpose: Sets the name of the component
//
// ****************************************************************************

void
429
VisItInit::SetComponentName(const char *cname)
hrchilds's avatar
hrchilds committed
430
{
431
   size_t len;
hrchilds's avatar
hrchilds committed
432

hrchilds's avatar
hrchilds committed
433
   if (cname != 0 && (len = strlen(cname)) > 0)
hrchilds's avatar
hrchilds committed
434
435
436
437
438
439
440
441
   {
      len = len < sizeof(componentName) ? len : sizeof(componentName) - 1;
      strncpy(componentName, cname, len);
      componentName[len]='\0';
   }
}

// ****************************************************************************
442
//  Function: VisItInit::GetComponentName
hrchilds's avatar
hrchilds committed
443
444
445
446
447
448
449
//
//  Purpose: Gets the name of the component. Defaults to name of the
//  executable of it was not set.
//
// ****************************************************************************

const char *
450
VisItInit::GetComponentName(void)
hrchilds's avatar
hrchilds committed
451
452
453
454
{
   return (const char *) componentName;
}

hrchilds's avatar
hrchilds committed
455
// ****************************************************************************
456
//  Function: VisItInit::ComponentNameToID
hrchilds's avatar
hrchilds committed
457
458
459
460
461
//
//  Purpose: Return integer index of component name in list of all components
//
// ****************************************************************************
const int
462
VisItInit::ComponentNameToID(const char *compName)
hrchilds's avatar
hrchilds committed
463
464
465
466
467
468
469
470
471
472
473
{
    int n = sizeof(allComponentNames) / sizeof(allComponentNames[0]);
    for (int i = 0; i < n; i++)
    {
        if (strcmp(compName, allComponentNames[i]) == 0)
            return i;
    }
    return -1;
}

// ****************************************************************************
474
//  Function: VisItInit::ComponentNameToID
hrchilds's avatar
hrchilds committed
475
476
477
478
479
//
//  Purpose: Return name of component with given index in list of all components
//
// ****************************************************************************
const char*
480
VisItInit::ComponentIDToName(const int id)
hrchilds's avatar
hrchilds committed
481
482
483
484
485
486
487
488
489
{
    int n = sizeof(allComponentNames) / sizeof(allComponentNames[0]);

    if (id >= 0 && id < n)
        return allComponentNames[id];
    else
        return "unknown";
}

hrchilds's avatar
hrchilds committed
490
// ****************************************************************************
491
//  Function: VisItInit::IsComponent
hrchilds's avatar
hrchilds committed
492
493
494
495
496
//
//  Purpose: Tests name of component against name passed as argument 
//
// ****************************************************************************
bool
497
VisItInit::IsComponent(const char *compName)
hrchilds's avatar
hrchilds committed
498
{
499
   if (strcmp(compName, VisItInit::GetComponentName()) == 0)
hrchilds's avatar
hrchilds committed
500
501
502
503
504
       return true;
   else
       return false;
}

hrchilds's avatar
hrchilds committed
505
// ****************************************************************************
506
//  Function: VisItInit::GetExecutableName
hrchilds's avatar
hrchilds committed
507
508
509
510
511
512
//
//  Purpose: Gets the name of the executable 
//
// ****************************************************************************

const char *
513
VisItInit::GetExecutableName(void)
hrchilds's avatar
hrchilds committed
514
515
516
517
{
   return (const char *) executableName;
}

hrchilds's avatar
hrchilds committed
518
// ****************************************************************************
519
//  Function: VisItInit::ComponentRegisterErrorFunction
hrchilds's avatar
hrchilds committed
520
521
522
523
524
525
526
527
528
529
//
//  Purpose:
//      Registers an error function.
//
//  Programmer: Hank Childs
//  Creation:   August 8, 2003
//
// ****************************************************************************

void
530
VisItInit::ComponentRegisterErrorFunction(ErrorFunction ef, void *args)
hrchilds's avatar
hrchilds committed
531
532
533
534
535
536
537
{
    errorFunctionArgs = args;
    errorFunction = ef;
}


// ****************************************************************************
538
//  Function: VisItInit::ComponentIssueError
hrchilds's avatar
hrchilds committed
539
540
541
542
543
544
545
546
547
548
//
//  Purpose:
//      Issues an error message on that component.
//
//  Programmer: Hank Childs
//  Creation:   August 8, 2003
//
// ****************************************************************************

void
549
VisItInit::ComponentIssueError(const char *msg)
hrchilds's avatar
hrchilds committed
550
551
552
553
554
555
556
557
558
559
560
561
562
563
{
    debug1 << "Error issued: " << msg << endl;
    if (errorFunction != NULL)
    {
        errorFunction(errorFunctionArgs, msg);
    }
    else
    {
        debug1 << "Not able to issue error because no function was registered."
               << endl;
    }
}


hrchilds's avatar
hrchilds committed
564
// ****************************************************************************
565
// Method: VisItInit::Finalize
hrchilds's avatar
hrchilds committed
566
567
568
569
570
571
572
573
//
// Purpose: 
//   Calls cleanup functions before the application exits.
//
// Programmer: Brad Whitlock
// Creation:   Tue Mar 19 16:12:37 PST 2002
//
// Modifications:
hrchilds's avatar
hrchilds committed
574
575
576
//   Brad Whitlock, Wed Jun 18 11:14:50 PDT 2003
//   Added code to dump timings.
//
hrchilds's avatar
hrchilds committed
577
578
579
//   Hank Childs, Tue Jun  1 11:47:36 PDT 2004
//   Made the method be associated with the Init namespace.
//
hrchilds's avatar
hrchilds committed
580
581
582
//   Mark C. Miller, Tue Jul 25 18:26:10 PDT 2006
//   Pushed timer dump and finalization down into TimingsManager::Finalize 
//
583
584
585
586
//   Brad Whitlock, Wed Jun 25 10:44:24 PDT 2008
//   Added check to return early if Finalize has already been called, which
//   can happen when multiple VisIt components are part of the same executable.
//
hrchilds's avatar
hrchilds committed
587
588
// ****************************************************************************

hrchilds's avatar
hrchilds committed
589
void
590
VisItInit::Finalize(void)
hrchilds's avatar
hrchilds committed
591
{
592
593
594
595
596
    // Return if Finalize has already been called.
    if(finalizeCalled)
         return;
    finalizeCalled = true;

hrchilds's avatar
hrchilds committed
597
    TimingsManager::Finalize();
hrchilds's avatar
hrchilds committed
598

hrchilds's avatar
hrchilds committed
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
#if defined(_WIN32)
    // Terminates use of the WS2_32.DLL, the Winsock DLL.
    WSACleanup();
#endif
}

// ****************************************************************************
//  Function: RemovePrependedDirs
//
//  Purpose:
//      Removes prepended directories from a program name.
//
//  Arguments:
//      path      The input.  A program name with a path.
//      name      The output.  Only the name at the end.
//
//  Programmer:   Hank Childs
//  Creation:     August 13, 2001
//
618
619
620
621
//  Modifications:
//    Kathleen Bonnell, Wed Aug 22 18:00:57 PDT 2007
//    Use SLASH_CHAR.
//
hrchilds's avatar
hrchilds committed
622
623
624
625
626
627
628
629
630
631
// ****************************************************************************

static void
RemovePrependedDirs(const char *path, char *name)
{
    //
    // Find the last slash by going to the end and working backwards.
    //
    int  len = strlen(path);
    int lastSlash;
632
    for (lastSlash=len ; path[lastSlash]!=VISIT_SLASH_CHAR && lastSlash>=0 ; lastSlash--)
hrchilds's avatar
hrchilds committed
633
634
635
636
637
638
639
640
641
642
643
644
645
646
    {
        continue;
    }

    //
    // Last slash can get to be less than zero if there are no slashes.
    //
    if (lastSlash < 0)
    {
        lastSlash = 0;
    }

    //
    //
647
    if (path[lastSlash] == VISIT_SLASH_CHAR)
hrchilds's avatar
hrchilds committed
648
649
650
651
652
653
654
655
    {
        strcpy(name, path + lastSlash + 1);
    }
    else
    {
        strcpy(name, path + lastSlash);
    }
}