~ubuntu-branches/ubuntu/precise/torque/precise-updates

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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
/*
*         OpenPBS (Portable Batch System) v2.3 Software License
*
* Copyright (c) 1999-2000 Veridian Information Solutions, Inc.
* All rights reserved.
*
* ---------------------------------------------------------------------------
* For a license to use or redistribute the OpenPBS software under conditions
* other than those described below, or to purchase support for this software,
* please contact Veridian Systems, PBS Products Department ("Licensor") at:
*
*    www.OpenPBS.org  +1 650 967-4675                  sales@OpenPBS.org
*                        877 902-4PBS (US toll-free)
* ---------------------------------------------------------------------------
*
* This license covers use of the OpenPBS v2.3 software (the "Software") at
* your site or location, and, for certain users, redistribution of the
* Software to other sites and locations.  Use and redistribution of
* OpenPBS v2.3 in source and binary forms, with or without modification,
* are permitted provided that all of the following conditions are met.
* After December 31, 2001, only conditions 3-6 must be met:
*
* 1. Commercial and/or non-commercial use of the Software is permitted
*    provided a current software registration is on file at www.OpenPBS.org.
*    If use of this software contributes to a publication, product, or
*    service, proper attribution must be given; see www.OpenPBS.org/credit.html
*
* 2. Redistribution in any form is only permitted for non-commercial,
*    non-profit purposes.  There can be no charge for the Software or any
*    software incorporating the Software.  Further, there can be no
*    expectation of revenue generated as a consequence of redistributing
*    the Software.
*
* 3. Any Redistribution of source code must retain the above copyright notice
*    and the acknowledgment contained in paragraph 6, this list of conditions
*    and the disclaimer contained in paragraph 7.
*
* 4. Any Redistribution in binary form must reproduce the above copyright
*    notice and the acknowledgment contained in paragraph 6, this list of
*    conditions and the disclaimer contained in paragraph 7 in the
*    documentation and/or other materials provided with the distribution.
*
* 5. Redistributions in any form must be accompanied by information on how to
*    obtain complete source code for the OpenPBS software and any
*    modifications and/or additions to the OpenPBS software.  The source code
*    must either be included in the distribution or be available for no more
*    than the cost of distribution plus a nominal fee, and all modifications
*    and additions to the Software must be freely redistributable by any party
*    (including Licensor) without restriction.
*
* 6. All advertising materials mentioning features or use of the Software must
*    display the following acknowledgment:
*
*     "This product includes software developed by NASA Ames Research Center,
*     Lawrence Livermore National Laboratory, and Veridian Information
*     Solutions, Inc.
*     Visit www.OpenPBS.org for OpenPBS software support,
*     products, and information."
*
* 7. DISCLAIMER OF WARRANTY
*
* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT
* ARE EXPRESSLY DISCLAIMED.
*
* IN NO EVENT SHALL VERIDIAN CORPORATION, ITS AFFILIATED COMPANIES, OR THE
* U.S. GOVERNMENT OR ANY OF ITS AGENCIES BE LIABLE FOR ANY DIRECT OR INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 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.
*
* This license will be governed by the laws of the Commonwealth of Virginia,
* without reference to its choice of law rules.
*/

#include <pbs_config.h>   /* the master config generated by configure */

#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE 1
#endif  /* _POSIX_SOURCE */

#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <string.h>
#include <setjmp.h>
#include <stdlib.h>

#include "List.h"

static char ident[] = "@(#) $RCSfile$ $Revision: 2367 $";
/* Global variables */
FILE *ListFpOut;

/* File Scope Variables */
static char * ListErrors[] =
  {
  "0 no such error msg",
  "1 illegal operation on empty List",
  "2 nxp = NULL",
  "3 lexem ptr = NULL",
  "4 NodeNew error got returned NULL",
  "5 node not in List",
  "6 lexem not in List",
  "7 fname *main* not in List -- it should be",
  ""
  };

static int ListMaxErrors = 9;

static char *ListName = "List";

static int ListDF = 0;


void
ListPutDF(int df)
  {
  ListCondPrint("ListPutDF");

  ListDF = df;
  }


void
ListCondPrint(char *str)
  {
  if (ListFpOut == NULL)
    ListErr(7);

  if (ListDF == 1)
    {
    fprintf(ListFpOut, "%s\t", ListName);
    fprintf(ListFpOut, "%s\n", str);
    }
  }

int ListIsEmpty(L)
List L;
  {
  ListCondPrint("ListIsEmpty");

  return(L == NULL);
  }

void ListPrint(L)
List L;
  {
  if (ListFpOut == NULL)
    ListErr(7);

  fprintf(ListFpOut, "ListPrint\n");

  if (L == NULL)
    {
    fprintf(ListFpOut, "\nend of list\n");
    return;
    }
  else
    {
    NodePrint(L);
    ListPrint(L->rptr);
    }
  }


List ListInsertFront(L, nxp)
List  L;
Np  nxp;
  {
  ListCondPrint("ListInsertFront");

  /*L can be NULL to insert to empty list*/

  if (nxp == NULL) ListErr(2);

  nxp->rptr = L;

  return(nxp);
  }


void ListParamLink(funNp, parNp)
Np  funNp;
Np  parNp;
  {
  Np paramPt;
  ListCondPrint("ListParamLink");

  /*L cannot be NULL */

  if (funNp == NULL) ListErr(2);

  if (parNp == NULL) ListErr(2);

  /*insert the param immed after FunNp-- insert end so that parameters */
  /* are listed in order */
  /*
   parNp->funDescr.paramPtr = funNp->funDescr.paramPtr;
   funNp->funDescr.paramPtr = parNp;
  */
  paramPt = funNp->funDescr.paramPtr;

  if (paramPt == NULL)
    funNp->funDescr.paramPtr = parNp;
  else
    {
    while (paramPt->funDescr.paramPtr != NULL)
      {
      paramPt = paramPt->funDescr.paramPtr;
      }

    paramPt->funDescr.paramPtr = parNp;
    }

  parNp->funDescr.paramPtr = NULL;



  }

List ListInsertSortedN(L, nxp)
List  L;
Np  nxp;
  {
  ListCondPrint("ListInsertSortedN");

  /*L can be NULL to insert to empty list*/

  if (nxp == NULL) ListErr(2);

  if (L == NULL)
    {
    L = nxp;
    return(L);
    }
  else
    {
    /*increasing order*/
    if (strcmp(nxp->lexeme, L->lexeme) < 0)
      {
      /*insert here*/
      nxp->rptr = L;
      L = nxp;
      return(L);
      }
    else
      {
      L->rptr = ListInsertSortedN(L->rptr, nxp);
      return(L);

      }
    }
  }


List ListInsertSortedD(L, lexem, typ, lineDe, leve, funFla)
List  L;
char  *lexem;
int  typ;
int  lineDe;
int  leve;
int  funFla;
  {
  Np nxp;

  ListCondPrint("ListInsertSortedD");

  if (lexem == NULL)
    ListErr(3);

  /*L can be NULL to insert to empty list*/

  nxp = NodeNew(lexem, typ, lineDe, leve, funFla);

  if (nxp == NULL)
    ListErr(4);

  return(ListInsertSortedN(L, nxp));
  }

int ListIsMember(L, nxp)
List  L;
Np  nxp;
  {
  int s;

  ListCondPrint("ListIsMember");

  if (nxp == NULL)
    ListErr(2);

  if (L == NULL)
    {
    return(0);
    }
  else
    {
    if (nxp == L)
      {
      return(1);
      }
    else
      {
      s = ListIsMember(L->rptr, nxp);
      return(s);
      }
    }
  }


Np ListGetLast(L)
List L;
  {
  Np last;

  ListCondPrint("ListGetLast");

  if (L == NULL)
    ListErr(1);

  if (L->rptr == NULL)
    {
    return(L);
    }
  else
    {
    last = ListGetLast(L->rptr);
    return(last);
    }
  }


Np ListGetSucc(L, nxp)
List  L;
Np  nxp;
  {
  ListCondPrint("ListGetSucc");

  if (L == NULL)
    ListErr(1);

  if (nxp == NULL)
    ListErr(2);

  if (ListIsMember(L, nxp) == 1)
    return(nxp->rptr);
  else
    ListErr(5);

  /*never get here -- keep compiler happy*/
  return(NULL);

  }


List ListDeleteNode(L, nxp)
List  L;
Np  nxp;
  {
  ListCondPrint("ListDeleteNode");

  if (L == NULL)
    ListErr(1);

  if (nxp == NULL)
    ListErr(2);

  if (ListIsMember(L, nxp) == 0)
    ListErr(5); /*nxp not in list*/

  if (nxp == L) /*delete head of sublist*/
    {
    /*delete here*/
    L = L->rptr;
    free(nxp);
    return(L); /*returning adjsted rptr of pred*/
    }
  else
    {
    L->rptr = ListDeleteNode(L->rptr, nxp);
    return(L);
    }
  }


List ListDelete(L)
List L;
  {
  List t;

  ListCondPrint("ListDelete");

  if (L == NULL)
    {
    return(NULL);
    }
  else
    {
    t = L->rptr;
    free(L);
    return(ListDelete(t));
    }
  }


List ListDeleteLevel(L, leve)
List  L;
int  leve;
  {
  List t;

  ListCondPrint("ListDeleteLevel");
  /*level is block -- cannot be discontinuos in SymTab*/

  if (L == NULL)
    return(NULL);

  if (L->level == leve)
    {
    t = L->rptr;
    free(L);
    return(ListDeleteLevel(t, leve));
    }
  else
    {
    /*got out of the block*/
    return(L);
    }
  }


Np ListFindNodeByLexeme(L, lexem)
List  L;
char  *lexem;
  {
  Np foundp;

  ListCondPrint("ListFindNodeByLexeme");

  if (L == NULL)
    return(NULL);

  if (lexem == NULL)
    ListErr(3);

  if (strcmp(L->lexeme, lexem) == 0)
    {
    return(L);
    }
  else
    {
    foundp = ListFindNodeByLexeme(L->rptr, lexem);
    }

  return(foundp); /*NULL means not found*/
  }


Np ListFindFunProtoByLexemeInProg(L, lexem)
List  L;
char  *lexem;
  {
  Np foundp;

  ListCondPrint("ListFindFunProtoByLexemeInProg");

  if (L == NULL)
    return(NULL);

  if (lexem == NULL)
    ListErr(3);

  while (L != NULL)
    {
    if ((strcmp(L->lexeme, "main") == 0))
      break;

    L = L->rptr;
    }

  if (L == NULL)
    ListErr(7);

  foundp = ListFindNodeByLexeme(L, lexem);

  return(foundp);

  }


Np ListFindNodeByLexemeInLevel(L, lexem, leve)
List  L;
char  *lexem;
int  leve;
  {
  Np foundp;

  ListCondPrint("ListFindNodeByLexemeInLevel");

  if (L == NULL)
    return(NULL);

  if (lexem == NULL)
    ListErr(3);

  /* This is no longer true since we can have */
  /* global variable declarations appearing */
  /* before functions that can contain local */
  /* variables in a different level */
  /*
   if (NodeGetLevel(L) != leve)
    return(NULL);
  */
  /*block cannot discontinuous*/

  if (strcmp(L->lexeme, lexem) == 0 && \
      NodeGetLevel(L) == leve)
    {
    return(L);
    }
  else
    {
    foundp = ListFindNodeByLexemeInLevel(L->rptr, lexem, leve);
    return(foundp); /*NULL means not found*/
    }
  }

Np ListFindNodeByLexemeInLine(L, lexem, line)
List  L;
char  *lexem;
int  line;
  {
  Np foundp;

  ListCondPrint("ListFindNodeByLexemeInLine");

  if (L == NULL)
    return(NULL);

  if (lexem == NULL)
    ListErr(3);

  if (strcmp(NodeGetLexeme(L), lexem) == 0 && NodeGetLineDef(L) == line)
    {
    return(L);
    }
  else
    {
    foundp = ListFindNodeByLexemeInLine(L->rptr, lexem, line);
    return(foundp); /*NULL means not found*/
    }
  }

/* Same as ListFindNodeByLexemeInLine except that it does "strpbrk" instead of
   doing "strcmp". */
Np ListMatchNodeByLexemeInLine(L, lexem, line)
List  L;
char  *lexem;
int  line;
  {
  Np foundp;

  ListCondPrint("ListMatchNodeByLexemeInLine");

  if (L == NULL)
    return(NULL);

  if (lexem == NULL)
    ListErr(3);

  if (strpbrk(NodeGetLexeme(L), lexem) != NULL && \
      NodeGetLineDef(L) == line)
    {
    return(L);
    }
  else
    {
    foundp = ListMatchNodeByLexemeInLine(L->rptr, lexem, line);
    return(foundp); /*NULL means not found*/
    }
  }

/* Gets the node that is before the node containing "lexem" inserted at */
/* "line". */
/* NOTE: If the returned np contains the "lexem" and "line", then it */
/*       means it has no before node (i.e. the head of the list. */
Np ListFindNodeBeforeLexemeInLine(L, lexem, line)
List  L;
char  *lexem;
int  line;
  {
  Np foundp;

  ListCondPrint("ListFindNodeBeforeLexemeInLine");

  if (L == NULL)
    return(NULL);

  if (lexem == NULL)
    ListErr(3);

  /* If current node itself matches the lexem and line */
  if (strcmp(NodeGetLexeme(L), lexem) == 0 && NodeGetLineDef(L) == line)
    {
    return(L);
    }

  if (L->rptr == NULL)
    return(NULL);

  if (strcmp(NodeGetLexeme(L->rptr), lexem) == 0 && NodeGetLineDef(L->rptr) == line)
    {
    return(L);
    }
  else
    {
    foundp = ListFindNodeBeforeLexemeInLine(L->rptr, lexem, line);
    return(foundp); /*NULL means not found*/
    }
  }

/* Similar to ListFindNodeBeforeLexemeInLine except instead of doing a "strcmp",
   a "strpbrk" is done. */
Np ListMatchNodeBeforeLexemeInLine(L, lexem, line)
List  L;
char  *lexem;
int  line;
  {
  Np foundp;

  ListCondPrint("ListFindNodeBeforeLexemeInLine");

  if (L == NULL)
    return(NULL);

  if (lexem == NULL)
    ListErr(3);

  /* If current node itself matches the lexem and line */
  if (ListDF == 1)
    printf("Matching %s with %s and linedef: %d with %d\n",
           NodeGetLexeme(L), lexem, NodeGetLineDef(L), line);

  if (strpbrk(NodeGetLexeme(L), lexem) != NULL && NodeGetLineDef(L) == line)
    {
    return(L);
    }

  if (L->rptr == NULL)
    return(NULL);

  if (ListDF == 1)
    printf("Matching %s with %s and linedef: %d with %d\n",
           NodeGetLexeme(L), lexem, NodeGetLineDef(L), line);

  if (strpbrk(NodeGetLexeme(L->rptr), lexem) != NULL && NodeGetLineDef(L->rptr) == line)
    {
    return(L);
    }
  else
    {
    foundp = ListMatchNodeBeforeLexemeInLine(L->rptr, lexem, line);
    return(foundp); /*NULL means not found*/
    }
  }


/* Similar to ListFindNodeByLexemeInLevel except instead of doing a "strcmp" on */
/* the lexemes, the supplied "compare_func" is used instead. */
Np ListFindNodeByLexemeAndTypeInLevel(L, lexem, leve, type, compare_func)
List  L;
char  *lexem;
int  leve;
int type;
int (*compare_func)();
  {
  Np foundp;

  ListCondPrint("ListFindNodeByLexemeInLevel2");

  if (L == NULL)
    return(NULL);

  if (lexem == NULL)
    ListErr(3);

  /* No longer true */
  /*
   if (NodeGetLevel(L) != leve)
    return(NULL);
  */
  /*block cannot discontinuous*/

  if ((NodeGetType(L) == type) && (compare_func(L->lexeme, lexem) == 0) && \
      NodeGetLevel(L) == leve)
    {
    return(L);
    }
  else
    {
    foundp = ListFindNodeByLexemeAndTypeInLevel(L->rptr, lexem, leve, type, compare_func);
    return(foundp); /*NULL means not found*/
    }
  }

Np ListFindAnyNodeInLevelOfType(L, leve, type)
List  L;
int  leve;
int type;
  {
  Np foundp;

  ListCondPrint("ListFindAnyNodeInLevelOfType");

  if (L == NULL)
    return(NULL);

  /* No longer true */
  /*
   if (NodeGetLevel(L) != leve)
    return(NULL);
  */
  /*block cannot discontinuous*/

  if (NodeGetType(L) == type && \
      NodeGetLevel(L) == leve)
    {
    return(L);
    }
  else
    {
    foundp = ListFindAnyNodeInLevelOfType(L->rptr, leve, type);
    return(foundp); /*NULL means not found*/
    }
  }


void
ListErr(int e)
  {
  if (ListFpOut == NULL)
    ListErr(7);

  fprintf(ListFpOut, "ListErr\n");

  if (e >= ListMaxErrors)
    e = 0;

  fprintf(ListFpOut, "rs: %s\n", ListErrors[e]);

  exit(1);
  }