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>
59
#include <InstallationFunctions.h>
hrchilds's avatar
hrchilds committed
60
#include <TimingsManager.h>
61
#include <visit-config.h>
hrchilds's avatar
hrchilds committed
62
63

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

// ****************************************************************************
//  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();
}

// ****************************************************************************
139
//  Function: VisItInit::Initialize
hrchilds's avatar
hrchilds committed
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
//
//  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
180
181
182
183
184
//    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
185
//
hrchilds's avatar
hrchilds committed
186
187
188
//    Hank Childs, Tue Jun  1 11:47:36 PDT 2004
//    Removed atexit call, since that is buggy with gcc.
//
hrchilds's avatar
hrchilds committed
189
190
191
//    Jeremy Meredith, Tue May 17 11:20:51 PDT 2005
//    Allow disabling of signal handlers.
//
hrchilds's avatar
hrchilds committed
192
193
194
195
//    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.
196
197
198
199
//
//    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
200
201
202
203
//    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
204
205
206
//    Hank Childs, Tue Dec 18 15:53:10 PST 2007
//    Add support for -svn_revision.
//
207
208
209
//    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>
210
211
212
213
214
215
//
//    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.
//
216
217
218
219
//    Dave Pugmire, Thu Jan 15 16:35:08 EST 2009
//    Add support for -debug_engine_rank, limiting debug output to the specified
//    rank.
//
220
221
222
//    Brad Whitlock, Fri Apr 10 16:00:55 PDT 2009
//    I added support for reading -dv.
//
223
224
225
//    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
226
227
228
// ****************************************************************************

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

236
    int i, debuglevel = 0, engineDebugRank=-1;
hrchilds's avatar
hrchilds committed
237
238
239
#if defined(_WIN32)
    bool usePid = true;
#else
hrchilds's avatar
hrchilds committed
240
    bool usePid = false;
hrchilds's avatar
hrchilds committed
241
#endif
242
    bool bufferDebug = false;
243
    bool clobberVlogs = false;
cyrush's avatar
cyrush committed
244
    bool vtk_debug = false;
hrchilds's avatar
hrchilds committed
245
246
    bool enableTimings = false;
    for (i=1; i<argc; i++)
hrchilds's avatar
hrchilds committed
247
    {
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
        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;
        }

274
        if (strncmp("-debug",argv[i],6) == 0)
hrchilds's avatar
hrchilds committed
275
        {
276
277
278
279
280
281
282
283
	    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";
284

285
286
287
288
289
290
291
292
293
294
                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;
                }
295
296
297
                if (i+1 < argc && *(argv[i+1]+1) == 'b')
                    bufferDebug = true;

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

    char progname_wo_dir[256];
    RemovePrependedDirs(argv[0], progname_wo_dir);
hrchilds's avatar
hrchilds committed
342
343
    strcpy(executableName, progname_wo_dir);
    strcpy(componentName, progname_wo_dir);
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#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);
        if(homedir[homedir.size() - 1] != SLASH_CHAR)
            homedir += SLASH_STRING;
        homedir += executableName;
        strcpy(progname_wo_dir, homedir.c_str());
    }
#endif
hrchilds's avatar
hrchilds committed
358
359
360
361
362
363
364
365
366
    char progname[256];
    if (n > 1)
    {
        sprintf(progname, "%s.%03d", progname_wo_dir, r);
    }
    else
    {
        strcpy(progname, progname_wo_dir);
    }
367
    
hrchilds's avatar
hrchilds committed
368
369
370
371
372
373
374
375
376
377
378
379
    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
380
381
382
383
384
    // 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;

385
386
387
388
389
390
391
    // 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
392
393
    // Initialize the debug streams and also add the command line arguments
    // to the debug logs.
394
    DebugStream::Initialize(progname, debuglevel, sigs, clobberVlogs, bufferDebug);
hrchilds's avatar
hrchilds committed
395
396
397
398
    for(i = 0; i < argc; ++i)
        debug1 << argv[i] << " ";
    debug1 << endl;

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

#if !defined(_WIN32)
406
    std::set_new_handler(NewHandler);
hrchilds's avatar
hrchilds committed
407
408
409
410
411
412
413
414
415
416
417
418
419
#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
420
// ****************************************************************************
421
//  Function: VisItInit::SetComponentName
hrchilds's avatar
hrchilds committed
422
423
424
425
426
427
//
//  Purpose: Sets the name of the component
//
// ****************************************************************************

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

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

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

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

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

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

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

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

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

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

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

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


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

void
548
VisItInit::ComponentIssueError(const char *msg)
hrchilds's avatar
hrchilds committed
549
550
551
552
553
554
555
556
557
558
559
560
561
562
{
    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
563
// ****************************************************************************
564
// Method: VisItInit::Finalize
hrchilds's avatar
hrchilds committed
565
566
567
568
569
570
571
572
//
// 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
573
574
575
//   Brad Whitlock, Wed Jun 18 11:14:50 PDT 2003
//   Added code to dump timings.
//
hrchilds's avatar
hrchilds committed
576
577
578
//   Hank Childs, Tue Jun  1 11:47:36 PDT 2004
//   Made the method be associated with the Init namespace.
//
hrchilds's avatar
hrchilds committed
579
580
581
//   Mark C. Miller, Tue Jul 25 18:26:10 PDT 2006
//   Pushed timer dump and finalization down into TimingsManager::Finalize 
//
582
583
584
585
//   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
586
587
// ****************************************************************************

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

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

hrchilds's avatar
hrchilds committed
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
#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
//
617
618
619
620
//  Modifications:
//    Kathleen Bonnell, Wed Aug 22 18:00:57 PDT 2007
//    Use SLASH_CHAR.
//
hrchilds's avatar
hrchilds committed
621
622
623
624
625
626
627
628
629
630
// ****************************************************************************

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;
631
    for (lastSlash=len ; path[lastSlash]!=SLASH_CHAR && lastSlash>=0 ; lastSlash--)
hrchilds's avatar
hrchilds committed
632
633
634
635
636
637
638
639
640
641
642
643
644
645
    {
        continue;
    }

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

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