~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/cull/example1.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 * 
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
/* \begin{verbatim} */
 
33
 
 
34
#define MAINPROGRAM
 
35
#define __SGE_GDI_LIBRARY_HOME_OBJECT_FILE__
 
36
 
 
37
#include <stdio.h>
 
38
#include <stdlib.h>
 
39
 
 
40
/* REMOTE MONITORING SUPPORT ? */
 
41
/* #define SGE_COMPILE_DEBUG */
 
42
#include "sgermon.h"
 
43
 
 
44
/* THIS ARE ALL PUBLIC LIST LIB HEADERS, YOU'LL NEED IT */
 
45
#include "cull.h"
 
46
 
 
47
/* include cull_whereP.h for WhereArg mechanism, example 7 */
 
48
#include "cull_whereP.h"
 
49
 
 
50
/* THIS ARE THE LIST STRUCTURE DEFINITIONS AND THE NAMESPACES */
 
51
#include "example1.h"
 
52
 
 
53
#include "sge_stdio.h"
 
54
 
 
55
/* DIRECTORY CONTAINING DATA FILES */
 
56
#define DATA_DIR "./"
 
57
 
 
58
/* CREATE SOME LISTS ( HOST, QUEUE, OWNER ) */
 
59
 
 
60
lList *buildHostList(void)
 
61
{
 
62
 
 
63
   lList *hostlist;
 
64
   lListElem *element;
 
65
 
 
66
   hostlist = lCreateList("hostlist", HostT);
 
67
 
 
68
   /*
 
69
      Now we create elements, change their initial 
 
70
      values and append them to the list.  
 
71
    */
 
72
   element = lCreateElem(HostT);
 
73
   lSetHost(element, H_hostname, "balin");
 
74
   lSetString(element, H_arch, "sun4");
 
75
   lSetString(element, H_os, "SunOS 4.1.2");
 
76
   lSetUlong(element, H_memsize, 16);
 
77
   lAppendElem(hostlist, element);
 
78
 
 
79
   element = lCreateElem(HostT);
 
80
   lSetHost(element, H_hostname, "balin");
 
81
   lSetString(element, H_arch, "sun4");
 
82
   lSetString(element, H_os, "SunOS 4.1.2");
 
83
   lSetUlong(element, H_memsize, 24);
 
84
   lAppendElem(hostlist, element);
 
85
 
 
86
   element = lCreateElem(HostT);
 
87
   lSetHost(element, H_hostname, "legolas");
 
88
   lSetString(element, H_arch, "alpha");
 
89
   lSetString(element, H_os, "OSF/1 3.02");
 
90
   lSetUlong(element, H_memsize, 64);
 
91
   lAppendElem(hostlist, element);
 
92
 
 
93
   element = lCreateElem(HostT);
 
94
   lSetHost(element, H_hostname, "bilbo");
 
95
   lSetString(element, H_arch, "sgi");
 
96
   lSetString(element, H_os, "IRIX 4");
 
97
   lSetUlong(element, H_memsize, 16);
 
98
   lAppendElem(hostlist, element);
 
99
 
 
100
   element = lCreateElem(HostT);
 
101
   lSetHost(element, H_hostname, "sam");
 
102
   lSetString(element, H_arch, "i386");
 
103
   lSetString(element, H_os, "Linux");
 
104
   lSetUlong(element, H_memsize, 128);
 
105
   lAppendElem(hostlist, element);
 
106
 
 
107
   return hostlist;
 
108
}
 
109
 
 
110
lList *buildQueueList(void)
 
111
{
 
112
   lList *queuelist = NULL;
 
113
   lListElem *element;
 
114
 
 
115
   queuelist = lCreateList("queuelist", QueueT);
 
116
 
 
117
   /*
 
118
      Now we create elements, change their initial 
 
119
      values and append them to the list.  
 
120
    */
 
121
   element = lCreateElem(QueueT);
 
122
   lSetString(element, Q_name, "balin.q");
 
123
   lSetHost(element, Q_hostname, "balin");
 
124
   lSetInt(element, Q_load, 2);
 
125
   /*
 
126
      The member Q_ownerlist is initialized with NULL, 
 
127
      no changes are needed right now.
 
128
    */
 
129
   lAppendElem(queuelist, element);
 
130
 
 
131
   element = lCreateElem(QueueT);
 
132
   lSetString(element, Q_name, "durin.q");
 
133
   lSetHost(element, Q_hostname, "durin");
 
134
   lSetInt(element, Q_load, 7);
 
135
   lAppendElem(queuelist, element);
 
136
 
 
137
   element = lCreateElem(QueueT);
 
138
   lSetString(element, Q_name, "gloin.q");
 
139
   lSetHost(element, Q_hostname, "gloin");
 
140
   lSetInt(element, Q_load, 23);
 
141
   lAppendElem(queuelist, element);
 
142
 
 
143
   element = lCreateElem(QueueT);
 
144
   lSetString(element, Q_name, "legolas.q");
 
145
   lSetHost(element, Q_hostname, "legolas");
 
146
   lSetInt(element, Q_load, 4);
 
147
   lAppendElem(queuelist, element);
 
148
 
 
149
   return queuelist;
 
150
}
 
151
 
 
152
lList *buildOwnerListA(void)
 
153
{
 
154
   lList *ownerlist = NULL;
 
155
   lListElem *owner;
 
156
 
 
157
   ownerlist = lCreateList("ownerlistA", OwnerT);
 
158
 
 
159
   owner = lCreateElem(OwnerT);
 
160
   lSetString(owner, O_owner, "Anton");
 
161
   lSetString(owner, O_group, "Tennis");
 
162
   lAppendElem(ownerlist, owner);
 
163
 
 
164
   owner = lCreateElem(OwnerT);
 
165
   lSetString(owner, O_owner, "Berta");
 
166
   lSetString(owner, O_group, "Basketball");
 
167
   lAppendElem(ownerlist, owner);
 
168
 
 
169
   return ownerlist;
 
170
}
 
171
 
 
172
lList *buildOwnerListB(void)
 
173
{
 
174
   lList *ownerlist = NULL;
 
175
   lListElem *owner;
 
176
 
 
177
   ownerlist = lCreateList("ownerlistB", OwnerT);
 
178
 
 
179
   owner = lCreateElem(OwnerT);
 
180
   lSetString(owner, O_owner, "Christian");
 
181
   lSetString(owner, O_group, "Tennis");
 
182
   lAppendElem(ownerlist, owner);
 
183
 
 
184
   return ownerlist;
 
185
}
 
186
 
 
187
lList *buildOwnerListC(void)
 
188
{
 
189
   lList *ownerlist = NULL;
 
190
   lListElem *owner;
 
191
 
 
192
   ownerlist = lCreateList("ownerlistC", OwnerT);
 
193
 
 
194
   owner = lCreateElem(OwnerT);
 
195
   lSetString(owner, O_owner, "Anton");
 
196
   lSetString(owner, O_group, "Golf");
 
197
   lAppendElem(ownerlist, owner);
 
198
 
 
199
   return ownerlist;
 
200
}
 
201
 
 
202
void usage(void)
 
203
{
 
204
   printf("example1 0\t Scenario: JOIN\n");
 
205
   printf("example1 1\t Scenario: SELECT\n");
 
206
   printf("example1 2\t Scenario: SELECTDESTROY\n");
 
207
   printf("example1 3\t Scenario: SORT\n");
 
208
   printf("example1 4\t Scenario: SELECTSUB\n");
 
209
   printf("example1 5\t Scenario: JOINSUB\n");
 
210
   printf("example1 6\t Scenario: CHANGE\n");
 
211
   printf("example1 7\t Scenario: UNDUMP\n");
 
212
   printf("example1 8\t Scenario: WHERE\n");
 
213
   printf("example1 9\t Scenario: lNm2Str/lStr2Nm\n");
 
214
   printf("example1 10\t Scenario: BITMASK\n");
 
215
   printf("example1 11\t Scenario: SPLIT\n");
 
216
   printf("example1 12\t Scenario: UNIQ\n");
 
217
   printf("example1 13\t Scenario: COPYENUM\n");
 
218
   printf("example1 14\t Scenario: REFERENCE\n");
 
219
 
 
220
   exit(-1);
 
221
}
 
222
 
 
223
/* for this monster see proto.h */
 
224
int main(int argc, char *argv[])
 
225
{
 
226
   static char trala[] = "Doedel";
 
227
   enum {
 
228
      JOIN, SELECT, SELECTDESTROY, SORT, SELECTSUB, JOINSUB, CHANGE,
 
229
      UNDUMP, WHEREARGS, NM2STR, BITMASK, SPLIT, UNIQ, COPYENUM, REFERENCE
 
230
   };
 
231
   int scene, i = 0;
 
232
   const char *cp;
 
233
 
 
234
   lList *hostlist = NULL, *queuelist = NULL, *joinedlist = NULL, *joinedsublist = NULL,
 
235
    *selectedlist = NULL, *ownerlist[3];
 
236
   lList *unchained = NULL;
 
237
 
 
238
   FILE *fp;
 
239
 
 
240
   lListElem *element;
 
241
 
 
242
   lCondition *where = NULL, *subwhere = NULL;
 
243
   lCondition *where2 = NULL;
 
244
 
 
245
   lEnumeration *what = NULL;
 
246
   lEnumeration *what2 = NULL;
 
247
 
 
248
   lEnumeration *allHostFields = NULL, *allQueueFields = NULL, *allOwnerFields = NULL;
 
249
 
 
250
   /* monitoring macros */
 
251
   DENTER_MAIN(TOP_LAYER, "example1");
 
252
 
 
253
   /* WHICH SCENARIO SHALL I USE ? */
 
254
   if (argc != 2)
 
255
      usage();
 
256
   sscanf(argv[1], "%d", &scene);
 
257
 
 
258
   /* INITIALIZE FIELDID TO FIELDNAME STRING CONVERSION */
 
259
   lInit(nmv);                  /* nmv is the lNameSpace array address */
 
260
   /* see example1.h                      */
 
261
 
 
262
   /* 
 
263
      the what structures are typespecific,
 
264
      even if we want all fields
 
265
    */
 
266
   allHostFields = lWhat("%T(ALL)", HostT);
 
267
   allQueueFields = lWhat("%T(ALL)", QueueT);
 
268
   allOwnerFields = lWhat("%T(ALL)", OwnerT);
 
269
 
 
270
   printf("\n\n\n");
 
271
 
 
272
   switch (scene) {
 
273
      /* 
 
274
         JOIN TWO LISTS CONNECTED BY A COMMON JOINFIELD TO A NEW 
 
275
         LIST CONTAINING INFORMATION OF BOTH ORIGINAL LISTS
 
276
       */
 
277
   case JOIN:
 
278
 
 
279
      /* build a host- and a queuelist and write them to stdout */
 
280
      hostlist = buildHostList();
 
281
      printf("\n\nHOSTLIST\n\n");
 
282
      lWriteListTo(hostlist, stdout);
 
283
 
 
284
      queuelist = buildQueueList();
 
285
      printf("\n\nQUEUELIST\n\n");
 
286
      lWriteListTo(queuelist, stdout);
 
287
 
 
288
      /*
 
289
         The lJoin() function gets normally two conditions and 
 
290
         two field enumerations to select the list elements and
 
291
         the fields which will appear in the resulting list.  
 
292
         If we set a condition to NULL, this means that all elements 
 
293
         fulfilling the joincondition (here: H_hostname == Q_hostname) 
 
294
         are returned.  
 
295
         With 'allHostFields' and 'allQueueFields' we get every field
 
296
         of both lists (Normally you keep only one of the join fields
 
297
         i.e. either Q_hostname or H_hostname)
 
298
       */
 
299
 
 
300
      joinedlist = lJoin("joinedList", H_hostname, hostlist, NULL, allHostFields, Q_hostname,
 
301
                         queuelist, NULL, allQueueFields);
 
302
 
 
303
      /* print the result */
 
304
      printf("\n\nJOINED LIST\ncommon fields are "
 
305
             "H_hostname and Q_hostname\n\n");
 
306
      lWriteListTo(joinedlist, stdout);
 
307
 
 
308
      /* here we open a dump file to write the result to disk */
 
309
      if (!(fp = fopen(DATA_DIR "dump.dmp", "w"))) {
 
310
         printf("unable to open dump.dmp for write access\n");
 
311
         break;
 
312
      }
 
313
      if (lDumpList(fp, joinedlist, 0) == EOF) {
 
314
         printf("unable to dump into dump.dmp\n");
 
315
         break;
 
316
      }
 
317
      FCLOSE(fp);
 
318
 
 
319
      break;
 
320
 
 
321
   case SELECT:
 
322
      /*
 
323
         WITH THE lSelect FUNCTION WE CAN EXTRACT THOSE
 
324
         ELEMENTS OF A LIST THAT FULFILL A CERTAIN
 
325
         CONDITION. THE CONDITION IS SPECIFIED IN A
 
326
         where STRUCTURE AND HANDED OVER TO lSelect.
 
327
       */
 
328
 
 
329
      /* build a queuelist and write it to stdout */
 
330
      queuelist = buildQueueList();
 
331
      printf("\n\nQUEUELIST\n\n");
 
332
      lWriteListTo(queuelist, stdout);
 
333
 
 
334
      /*
 
335
         The where structure chooses certain rows and the 
 
336
         what structure certain columns, if we speak in terms of 
 
337
         databases.
 
338
         The where structure is build by the lWhere function and the 
 
339
         what structure by the lWhat function.
 
340
         With lWhat you select the fields to be kept in the
 
341
         list elements. 
 
342
         The syntax is explained in the manpages lWhere(3),lWhat(3).
 
343
         In the following example the where structure states:
 
344
         Get The elements from the queuelist that do not
 
345
         fulfill the condition (Q_load < 12 and Q_Hostname != durin).
 
346
         In the what structure we select the fields Q_load, Q_name,
 
347
         Q_hostname from a list element of type QueueT.
 
348
       */
 
349
      where = lWhere("%T(!(%I < %d && %I != %s)) ", QueueT,
 
350
                     Q_load, 12, Q_hostname, "durin");
 
351
      what = lWhat(" %T( %I %I %I )", QueueT, Q_load, Q_name, Q_hostname);
 
352
 
 
353
      selectedlist = lSelect("selectedlist", queuelist, where, what);
 
354
 
 
355
      /* release memory */
 
356
      lFreeWhere(&where);
 
357
      lFreeWhat(&what);
 
358
 
 
359
      /* Show the result */
 
360
      printf("\n\nREDUCED SELECTED QUEUELIST\n"
 
361
             "only the fields Q_load, Q_name"
 
362
             "and Q_hostname are selected\n"
 
363
             "condition for selection is NOT(Q_load < 12 && "
 
364
             "Q_hostname != \"durin\")\n\n");
 
365
      lWriteListTo(selectedlist, stdout);
 
366
 
 
367
      break;
 
368
 
 
369
   case SELECTDESTROY:
 
370
      /*
 
371
         WITH THE lSelect FUNCTION WE CAN EXTRACT THOSE
 
372
         ELEMENTS OF A LIST THAT FULFILL A CERTAIN
 
373
         CONDITION. THE CONDITION IS SPECIFIED IN A
 
374
         where STRUCTURE AND HANDED OVER TO lSelect.
 
375
       */
 
376
 
 
377
      /* build a queuelist and write it to stdout */
 
378
      queuelist = buildQueueList();
 
379
      printf("\n\nQUEUELIST\n\n");
 
380
      lWriteListTo(queuelist, stdout);
 
381
 
 
382
      where = lWhere("%T(!(%I < %d && %I != %s)) ", QueueT,
 
383
                     Q_load, 12, Q_hostname, "durin");
 
384
 
 
385
      if ((queuelist = lSelectDestroy(queuelist, where)))
 
386
         printf("there is a list\n");
 
387
 
 
388
      /* release memory */
 
389
      lFreeWhere(&where);
 
390
 
 
391
      /* Show the result */
 
392
      printf("\n\nREDUCED QUEUELIST\n"
 
393
             "all fields\n"
 
394
             "condition for selection is NOT(Q_load < 12 && "
 
395
             "Q_hostname != \"durin\")\n\n");
 
396
      lWriteListTo(queuelist, stdout);
 
397
 
 
398
      break;
 
399
 
 
400
   case SORT:
 
401
      /*
 
402
         THE lSort FUNCTION ALLOWS THE SORTING OF A LIST
 
403
       */
 
404
 
 
405
      /* create the list and write it to stdout */
 
406
      hostlist = buildHostList();
 
407
      printf("\n\nHOSTLIST\n\n");
 
408
      lWriteListTo(hostlist, stdout);
 
409
 
 
410
      /* 
 
411
         Show the changed list ordered by H_memsize  (- = descending) 
 
412
         After sorting the unsorted list no longer exists.
 
413
         The lSortOrder formatstring specifies the keyfields as in lWhat 
 
414
         or lWhere with a minus/plus sign for ascending/descending sort 
 
415
         order appended.
 
416
         The leftmost sort criterion is the most important.
 
417
         The following ones are weighted from left to right.
 
418
       */
 
419
      lPSortList(hostlist, "%I+%I-", H_hostname, H_memsize);
 
420
 
 
421
      printf("\n\nHOSTLIST SORTED ASCENDING BY %s, DESCENDING BY %s\n\n",
 
422
             lNm2Str(H_hostname), lNm2Str(H_memsize));
 
423
      lWriteListTo(hostlist, stdout);
 
424
 
 
425
      break;
 
426
 
 
427
   case SELECTSUB:
 
428
      /*
 
429
         SELECT SPECIFYING CRITERIA FOR A SUBLIST
 
430
       */
 
431
 
 
432
      /* build and write the lists */
 
433
      ownerlist[0] = buildOwnerListA();
 
434
      ownerlist[1] = buildOwnerListB();
 
435
      ownerlist[2] = buildOwnerListC();
 
436
      /* Write the three ownerlists */
 
437
      for (i = 0; i < 3; i++) {
 
438
         printf("OWNERLIST %c\n", 'A' + i);
 
439
         lWriteListTo(ownerlist[i], stdout);
 
440
      }
 
441
 
 
442
      queuelist = buildQueueList();
 
443
      printf("\n\nORIGINAL QUEUELIST WITHOUT OWNERLISTS\n\n");
 
444
      lWriteListTo(queuelist, stdout);
 
445
      /* 
 
446
         Change the queuelist.ownerlist field where 
 
447
         Q_hostname == "gloin"  (first matching element only)
 
448
       */
 
449
      where = lWhere("%T(%I == %s)", QueueT, Q_hostname, "gloin");
 
450
      element = lFindFirst(queuelist, where);
 
451
      lSetList(element, Q_ownerlist, lCopyList("ownerlist0",
 
452
                                               ownerlist[0]));
 
453
      lFreeWhere(&where);
 
454
 
 
455
      /* 
 
456
         Change the queuelist.ownerlist field where 
 
457
         Q_hostname == "legolas" (first matching element only)
 
458
       */
 
459
      where = lWhere("%T(%I == %s)", QueueT, Q_hostname, "legolas");
 
460
      element = lFindFirst(queuelist, where);
 
461
      lSetList(element, Q_ownerlist, lCopyList("ownerlist1",
 
462
                                               ownerlist[1]));
 
463
      lFreeWhere(&where);
 
464
 
 
465
      /* 
 
466
         Change the queuelist.ownerlist field where 
 
467
         Q_hostname == "durin" (first matching element only)
 
468
       */
 
469
      where = lWhere("%T(%I == %s)", QueueT, Q_hostname, "durin");
 
470
      element = lFindFirst(queuelist, where);
 
471
      lSetList(element, Q_ownerlist, lCopyList("ownerlist2",
 
472
                                               ownerlist[2]));
 
473
      lFreeWhere(&where);
 
474
 
 
475
      printf("\n\nQUEUELIST WITH OWNERLISTS\n\n");
 
476
      lWriteListTo(queuelist, stdout);
 
477
      /* 
 
478
         Select the elements which contain in the owner sublist 
 
479
         owner "Anton" 
 
480
       */
 
481
      /*
 
482
         where = lWhere("%T(!(%I == %s) || %I != %s && %I -> %T(%I == %s))",
 
483
         QueueT, Q_hostname, "legolas", Q_hostname, "gloin",
 
484
         Q_ownerlist, OwnerT, O_owner, "Anton");
 
485
       */
 
486
      where = lWhere("%T( %I -> %T(%I == %s))",
 
487
                     QueueT, Q_ownerlist, OwnerT, O_owner, "Anton");
 
488
      what = lWhat("%T(ALL)", QueueT);
 
489
 
 
490
      selectedlist = lSelect("selectedlist", queuelist, where, what);
 
491
 
 
492
      printf("\n\nQUEUELIST ELEMENTS WHERE:\n");
 
493
      lWriteWhereTo(where, stdout);
 
494
      printf("\n\n");
 
495
      lWriteListTo(selectedlist, stdout);
 
496
 
 
497
      /* release memory */
 
498
      lFreeWhere(&where);
 
499
      lFreeWhat(&what);
 
500
 
 
501
      /* dump the resulting list to file */
 
502
      if (!(fp = fopen(DATA_DIR "dump.dmp", "w"))) {
 
503
         printf("unable to open dump.dmp for write access\n");
 
504
         break;
 
505
      }
 
506
      if (lDumpList(fp, selectedlist, 0) == EOF) {
 
507
         printf("unable to dump into dump.dmp\n");
 
508
         break;
 
509
      }
 
510
      FCLOSE(fp);
 
511
 
 
512
      break;
 
513
 
 
514
   case JOINSUB:
 
515
      /*
 
516
         JOIN A LIST WITH ONE OF ITS SUBLISTS, THIS GENERATES
 
517
         ADDITIONAL ELEMENTS IN THE MAIN LIST BUT THE SUBLIST
 
518
         CAN BE REMOVED. SO THE DEPTH OF A LIST STRUCTURE IS 
 
519
         REDUCED.
 
520
         CONDITIONS CAN BE SPECIFIED FOR THE MAIN AND THE 
 
521
         SUBLIST.
 
522
       */
 
523
 
 
524
      /* build the lists and write them */
 
525
      ownerlist[0] = buildOwnerListA();
 
526
      ownerlist[1] = buildOwnerListB();
 
527
      ownerlist[2] = buildOwnerListC();
 
528
      /* Write the three ownerlists */
 
529
      for (i = 0; i < 3; i++) {
 
530
         printf("OWNERLIST %c\n", 'A' + i);
 
531
         lWriteListTo(ownerlist[i], stdout);
 
532
      }
 
533
      queuelist = buildQueueList();
 
534
      printf("\n\nORIGINAL QUEUELIST WITHOUT OWNERLISTS\n\n");
 
535
      lWriteListTo(queuelist, stdout);
 
536
      /* 
 
537
         Change the queuelist.ownerlist field where 
 
538
         Q_hostname == "gloin" 
 
539
       */
 
540
      where = lWhere("%T(%I == %s)", QueueT, Q_hostname, "gloin");
 
541
      element = lFindFirst(queuelist, where);
 
542
      lSetList(element, Q_ownerlist, lCopyList("ownerlist0",
 
543
                                               ownerlist[0]));
 
544
      lFreeWhere(&where);
 
545
      /* 
 
546
         Change the queuelist.ownerlist field where 
 
547
         Q_hostname == "legolas" 
 
548
       */
 
549
      where = lWhere("%T(%I == %s)", QueueT, Q_hostname, "legolas");
 
550
      element = lFindFirst(queuelist, where);
 
551
      lSetList(element, Q_ownerlist, lCopyList("ownerlist1",
 
552
                                               ownerlist[1]));
 
553
      lFreeWhere(&where);
 
554
      /*
 
555
         Change the queuelist.ownerlist field where 
 
556
         Q_hostname == "durin" 
 
557
       */
 
558
      where = lWhere("%T(%I == %s)", QueueT, Q_hostname, "durin");
 
559
      element = lFindFirst(queuelist, where);
 
560
      lSetList(element, Q_ownerlist, lCopyList("ownerlist2",
 
561
                                               ownerlist[2]));
 
562
      lFreeWhere(&where);
 
563
 
 
564
      /* 
 
565
         Select the elements which contain in the ownerlist 
 
566
         owner "Anton" 
 
567
       */
 
568
      printf("\n\nQUEUELIST WITH OWNERLISTS\n\n");
 
569
      lWriteListTo(queuelist, stdout);
 
570
 
 
571
      if (!(where = lWhere("%T(%I->%T(%I == %s))", QueueT, Q_ownerlist,
 
572
                           OwnerT, O_owner, "Anton"))) {
 
573
         printf("lWhere failure\n");
 
574
         exit(-1);
 
575
      }
 
576
      if (!(subwhere = lWhere("%T(%I == %s)", OwnerT, O_owner, "Anton"))) {
 
577
         printf("lWhere failure\n");
 
578
         exit(-1);
 
579
      }
 
580
      /* Q_ownerlist is removed, so we have a flat list */
 
581
      if (!(what = lWhat("%T( %I %I %I )", QueueT, Q_name, Q_hostname, Q_load))) {
 
582
         printf("lWhat failure\n");
 
583
         exit(-1);
 
584
      }
 
585
 
 
586
      joinedsublist = lJoinSublist("joinedsublist", Q_ownerlist,
 
587
                                   queuelist, where, what,
 
588
                                   OwnerT, subwhere, allOwnerFields);
 
589
 
 
590
      printf("\n\nQUEUELIST JOINED WITH SUBLIST OWNERLIST\n");
 
591
      printf("\n");
 
592
      printf("\n\n");
 
593
      lWriteListTo(joinedsublist, stdout);
 
594
 
 
595
      /* release memory */
 
596
      lFreeWhere(&where);
 
597
      lFreeWhere(&subwhere);
 
598
      lFreeWhat(&what);
 
599
 
 
600
      break;
 
601
 
 
602
   case CHANGE:
 
603
      /*
 
604
         CHANGE THE VALUES OF LIST ELEMENT FIELDS
 
605
       */
 
606
 
 
607
      /* build lists and show them */
 
608
      hostlist = buildHostList();
 
609
      printf("\n\nHOSTLIST\n\n");
 
610
      lWriteListTo(hostlist, stdout);
 
611
 
 
612
      if (!(where = lWhere("%T( %I == %s )", HostT, H_os,
 
613
                           "SunOS 4.1.2"))) {
 
614
         printf("lWhere failure\n");
 
615
         exit(-1);
 
616
      }
 
617
 
 
618
      /* Change every element containing H_os = 'SunOS 4.1.2' */
 
619
      for_each_where(element, hostlist, where)
 
620
         lSetString(element, H_os, "SunOS 4.2.1");
 
621
      /* free memory */
 
622
      lFreeWhere(&where);
 
623
 
 
624
      /* show result */
 
625
      printf("\n\nCHANGED HOSTLIST\n"
 
626
             "H_os changed from SunOS 4.1.2 to SunOS 4.2.1\n\n");
 
627
      lWriteListTo(hostlist, stdout);
 
628
 
 
629
      break;
 
630
 
 
631
   case UNDUMP:
 
632
      /*
 
633
         GET A DUMPED LIST FROM DISK BACK INTO MEMORY
 
634
         IT IS POSSIBLE TO SPECIFY A NEW DESCRIPTOR,
 
635
         IF THE DIFFERENCES ARE NOT ACCEPTABLE THE 
 
636
         FUNCTION FAILS OTHERWISE WARNINGS ARE DISPLAYED
 
637
       */
 
638
      /* open dump file and read information */
 
639
      fp = fopen(DATA_DIR "dump.dmp", "r");
 
640
      joinedlist = lUndumpList(fp, NULL, NULL /*QueueT */ );
 
641
      FCLOSE(fp);
 
642
 
 
643
      /* show the undumped list */
 
644
      lWriteListTo(joinedlist, stdout);
 
645
 
 
646
      break;
 
647
 
 
648
   case WHEREARGS:
 
649
 
 
650
      /* build a queuelist and write it to stdout */
 
651
      queuelist = buildQueueList();
 
652
      /* build the lists and write them */
 
653
      ownerlist[0] = buildOwnerListA();
 
654
      ownerlist[1] = buildOwnerListB();
 
655
      ownerlist[2] = buildOwnerListC();
 
656
      /* 
 
657
         Change the queuelist.ownerlist field where 
 
658
         Q_hostname == "gloin" 
 
659
       */
 
660
      where = lWhere("%T(%I == %s)", QueueT, Q_hostname, "gloin");
 
661
      element = lFindFirst(queuelist, where);
 
662
      lSetList(element, Q_ownerlist, lCopyList("ownerlist0",
 
663
                                               ownerlist[0]));
 
664
      lFreeWhere(&where);
 
665
      /* 
 
666
         Change the queuelist.ownerlist field where 
 
667
         Q_hostname == "legolas" 
 
668
       */
 
669
      where = lWhere("%T(%I == %s)", QueueT, Q_hostname, "legolas");
 
670
      element = lFindFirst(queuelist, where);
 
671
      lSetList(element, Q_ownerlist, lCopyList("ownerlist1",
 
672
                                               ownerlist[1]));
 
673
      lFreeWhere(&where);
 
674
      /*
 
675
         Change the queuelist.ownerlist field where 
 
676
         Q_hostname == "durin" 
 
677
       */
 
678
      where = lWhere("%T(%I == %s)", QueueT, Q_hostname, "durin");
 
679
      element = lFindFirst(queuelist, where);
 
680
      lSetList(element, Q_ownerlist, lCopyList("ownerlist2",
 
681
                                               ownerlist[2]));
 
682
      lFreeWhere(&where);
 
683
 
 
684
      /* 
 
685
         Select the elements which contain in the ownerlist 
 
686
         owner "Anton" 
 
687
       */
 
688
      printf("\n\nQUEUELIST WITH OWNERLISTS\n\n");
 
689
      lWriteListTo(queuelist, stdout);
 
690
      where = lWhere("%T(%I -> %T(%I == %s)) ", QueueT, Q_ownerlist, OwnerT, 
 
691
                     O_owner, "Anton");
 
692
      what = lWhat(" %T( %I %I %I %I)", QueueT, Q_load, Q_name, Q_hostname,
 
693
                   Q_ownerlist);
 
694
 
 
695
      selectedlist = lSelect("selectedlist", queuelist, where, what);
 
696
 
 
697
      /* release memory */
 
698
      lFreeWhere(&where);
 
699
      lFreeWhat(&what);
 
700
 
 
701
      /* Show the result */
 
702
      printf("SELECTED LIST\n\n");
 
703
      lWriteListTo(selectedlist, stdout);
 
704
 
 
705
      break;
 
706
 
 
707
   case NM2STR:
 
708
 
 
709
      cp = lNm2Str(Q_name);
 
710
      printf("Worked ok cp = %s, Q_name %d == lStr2Nm %d\n",
 
711
             cp, Q_name, lStr2Nm(cp));
 
712
      i = lStr2Nm("Q_complexname");
 
713
      printf("Nr.: %d Name: %s\n", i, lNm2Str(i));
 
714
      break;
 
715
 
 
716
   case BITMASK:
 
717
      queuelist = buildQueueList();
 
718
      i = 0;
 
719
      for_each(element, queuelist) {
 
720
         i++;
 
721
         if (i % 2)
 
722
            lSetUlong(element, Q_status, 3);
 
723
         if (i == 3)
 
724
            lSetUlong(element, Q_status, 5);
 
725
      }
 
726
      where = lWhere("%T(!(%I m= %u))", QueueT,
 
727
                     Q_status, 3);
 
728
      what = lWhat(" %T( %I %I %I %I %I)", QueueT, Q_load, Q_status, Q_name, Q_hostname, 
 
729
                   Q_ownerlist);
 
730
      selectedlist = lSelect("selectedlist", queuelist, where, what);
 
731
 
 
732
      /* release memory */
 
733
      lFreeWhere(&where);
 
734
      lFreeWhat(&what);
 
735
 
 
736
      /* Show the result */
 
737
      lWriteListTo(queuelist, stdout);
 
738
      printf("BITMASK LIST\n\n");
 
739
      lWriteListTo(selectedlist, stdout);
 
740
 
 
741
      break;
 
742
 
 
743
   case SPLIT:
 
744
      queuelist = buildQueueList();
 
745
      where = lWhere("%T(!(%I < %d && %I != %s)) ", QueueT, Q_load, 12, Q_hostname, "durin");
 
746
 
 
747
      printf("Condition is:\n");
 
748
      printf("Vor Split\n");
 
749
      lWriteListTo(queuelist, stdout);
 
750
 
 
751
      if (lSplit(&queuelist, &unchained, "Unchained", where) == -1) {
 
752
         printf("lSplit failed\n");
 
753
      }
 
754
      lFreeWhere(&where);
 
755
 
 
756
      printf("Nach Split\n");
 
757
      lWriteListTo(queuelist, stdout);
 
758
      lWriteListTo(unchained, stdout);
 
759
 
 
760
      break;
 
761
 
 
762
   case UNIQ:
 
763
      hostlist = buildHostList();
 
764
      lWriteListTo(hostlist, stdout);
 
765
      lUniqHost(hostlist, H_hostname);
 
766
      lWriteListTo(hostlist, stdout);
 
767
      break;
 
768
 
 
769
   case COPYENUM:
 
770
      queuelist = buildQueueList();
 
771
      where = lWhere("%T(!(%I < %d && %I != %s)) ", QueueT, Q_load, 12, Q_hostname, "durin");
 
772
 
 
773
      what = lWhat("%T(%I %I)", QueueT, Q_hostname, Q_load);
 
774
 
 
775
      printf("Condition is:\n");
 
776
      lWriteWhereTo(where, stdout);
 
777
      printf("Condition copied is:\n");
 
778
      where2 = lCopyWhere(where);
 
779
      lWriteWhereTo(where2, stdout);
 
780
      lFreeWhere(&where2);
 
781
      lFreeWhere(&where);
 
782
      printf("Condition is:\n");
 
783
      lWriteWhereTo(where, stdout);
 
784
      printf("Condition copied is:\n");
 
785
      where2 = lCopyWhere(where);
 
786
      lWriteWhereTo(where2, stdout);
 
787
 
 
788
      printf("Enumeration is:\n");
 
789
      lWriteWhatTo(what, stdout);
 
790
      printf("Enumeration copied is:\n");
 
791
      what2 = lCopyWhat(what);
 
792
      lWriteWhatTo(what2, stdout);
 
793
      lFreeWhat(&what2);
 
794
      lFreeWhat(&what);
 
795
      what = lWhat("%T(ALL)", QueueT);
 
796
      printf("Enumeration is:\n");
 
797
      lWriteWhatTo(what, stdout);
 
798
      printf("Enumeration copied is:\n");
 
799
      what2 = lCopyWhat(what);
 
800
      lWriteWhatTo(what2, stdout);
 
801
 
 
802
      break;
 
803
   
 
804
   case REFERENCE:
 
805
      queuelist = buildQueueList();
 
806
      i = 0;
 
807
      for_each(element, queuelist) {
 
808
         lSetRef(element, Q_ref, &trala[i++]);         
 
809
      }
 
810
      lWriteListTo(queuelist, stdout);
 
811
      lFreeList(&queuelist);
 
812
      break;
 
813
      
 
814
 
 
815
   default:
 
816
      printf("Not allowed\n");
 
817
   }
 
818
 
 
819
   /* clean the house */
 
820
   if (hostlist)
 
821
      lFreeList(&hostlist);
 
822
   if (queuelist)
 
823
      lFreeList(&queuelist);
 
824
   if (joinedlist)
 
825
      lFreeList(&joinedlist);
 
826
   if (selectedlist)
 
827
      lFreeList(&selectedlist);
 
828
 
 
829
   if (allHostFields)
 
830
      lFreeWhat(&allHostFields);
 
831
   if (allQueueFields)
 
832
      lFreeWhat(&allQueueFields);
 
833
   if (allOwnerFields)
 
834
      lFreeWhat(&allOwnerFields);
 
835
 
 
836
   DCLOSE;
 
837
   return 0;
 
838
FCLOSE_ERROR:
 
839
   DCLOSE;
 
840
   return 0;
 
841
}
 
842
 
 
843
/* \end{verbatim} */