-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleCmd_Avail.c
1436 lines (1251 loc) · 38.8 KB
/
ModuleCmd_Avail.c
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****
** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: Modulate_Avail.c **
** First Edition: 1991/10/23 **
** **
** Authors: John Furlan, [email protected] **
** Jens Hamisch, [email protected] **
** R.K. Owen, <[email protected]> or <[email protected]> **
** **
** Description: This module command prints out the modulefiles that **
** are available in the directories listed in the **
** MODULEPATH environment variable. **
** **
** Exports: ModuleCmd_Avail **
** print_aligned_files **
** check_dir **
** get_dir **
** dirlst_to_list **
** delete_dirlst **
** delete_cache_list **
** **
** Notes: **
** **
** ************************************************************************ **
****/
/** ** Copyright *********************************************************** **
** **
** Copyright 1991-1994 by John L. Furlan. **
** see LICENSE.GPL, which must be provided, for details **
** **
** ************************************************************************ **/
static char Id[] = "@(#)$Id$";
static void *UseId[] = { &UseId, Id };
/** ************************************************************************ **/
/** HEADERS **/
/** ************************************************************************ **/
#include <time.h>
#include <sys/ioctl.h>
#include "modules_def.h"
#if defined HAVE_STRCOLL && defined HAVE_LOCALE_H && defined HAVE_SETLOCALE
# include <locale.h>
#endif
/** ************************************************************************ **/
/** LOCAL DATATYPES **/
/** ************************************************************************ **/
/**
** Structure for a linked list that stores directories to be listed.
**/
typedef struct _subdir_node {
fi_ent* sd_dir;
struct _subdir_node* sd_next;
} sd_node;
/** ************************************************************************ **/
/** CONSTANTS **/
/** ************************************************************************ **/
/**
** I tried having a test for isgraph() in the configuration file,
** but it fails on AIX. This is the best I could come up with...
**/
#if !defined(isgraph) && defined(_P) && defined(_N)
# define isgraph(c) ((_ctype_+1)[c]&(_P|_U|_L|_N))
#endif
#define DIREST 50
/** ************************************************************************ **/
/** MACROS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** LOCAL DATA **/
/** ************************************************************************ **/
static char buffer[MOD_BUFSIZE];
static char buf[ LINELENGTH];
static char module_name[] = __FILE__;
static char short_format[] = "%s";
static char short_format_part[] = "%s/%s";
static char short_format_full[] = "%s/%s(%s)";
static char long_format[] = "%-39.39s %-10.10s %17s\n";
char long_header[] = "\
- Package -----------------------------+- Versions -+- Last mod. ------\n";
/**
** Terse file list buffer
**/
#define FILE_LIST_SEGM_SIZE 100
static char _file_list_buffer[ 200];
static char **_file_list_ptr = (char **) NULL;
static int _file_list_cnt = 0;
static int _file_list_wr_ndx = 0;
static int _file_list_rd_ndx = 0;
/** ************************************************************************ **/
/** PROTOTYPES **/
/** ************************************************************************ **/
static int print_dir( Tcl_Interp*, char*, char*);
static void print_spaced_file( char*, int, int, int);
static char *mkdirnm( char*, char*);
static int fi_ent_cmp( const void*, const void*);
static void _init_file_list(void);
static void _add_file_list( char *name);
static char *_get_file_list(void);
static char *_pick_file_list( int ndx);
static void print_terse_files( int terminal_width, int len, char *header,
int numbered);
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: ModuleCmd_Avail **
** **
** Description: Execution of the 'module avail' command **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: Tcl_Interp *interp Current Tcl Interpr. **
** char *argv[] Arguments to the **
** command **
** **
** Result: int TCL_OK Successful operation **
** TCL_ERROR Any failure **
** **
** Attached Globals: g_specified_module The module name from the **
** command line. **
** **
** ************************************************************************ **
++++*/
int ModuleCmd_Avail(
Tcl_Interp * interp,
int argc,
char *argv[]
) {
char **dirname;
int Result = -TCL_ERROR;
#if defined HAVE_STRCOLL && defined HAVE_SETLOCALE
/**
** define the collation order using the locale
**/
(void) setlocale(LC_COLLATE,"");
#endif
/**
** Load the MODULEPATH and split it into a list of paths. Complain
** if no list to output ...
**/
if (!ModulePathVec || !uvec_number(ModulePathVec)) {
ErrorLogger(ERR_MODULE_PATH, LOC, NULL);
Result = TCL_ERROR;
goto unwind0;
}
/**
** If we're given a full-path, then we'll just check that directory.
** Otherwise, we'll check every directory in MODULESPATH.
**/
if (argc > 0 && **argv == *psep) {
while (argc--) {
/**
** Set the name of the module specified on the command line
**/
g_specified_module = *argv;
if (!check_dir(*argv)) {
if (OK != ErrorLogger(ERR_PARAM, LOC, NULL)) {
Result = TCL_ERROR;
/** --- EXIT PROCEDURE (FAILURE) --> **/
}
} else {
print_dir(interp, *argv, NULL);
}
argv++;
}
} else {
/**
** We're not given a full path. Tokenize the module path string and
** print the contents of each directory specified (if it exists ;-)
**/
if (sw_format & SW_LONG)
fprintf(stderr,"%s", _(long_header));
/**
** If a module category is specified check whether it is part
** of the directory we're scanning at the moment.
**/
if (argc > 0) { /* show sub directory */
while (argc--) {
/**
** Set the name of the module specified on the command line
**/
g_specified_module = *argv;
dirname = ModulePath;
while (dirname && *dirname) {
/**
** Print the category
**/
if (check_dir(*dirname))
print_dir(interp,*dirname,*argv);
dirname++;
}
argv++;
}
/**
** Otherwise, if there's no category given, descend the current
** directory and print its contents.
**/
} else {
dirname = ModulePath;
while (dirname && *dirname) {
if (check_dir(*dirname))
print_dir(interp, *dirname, NULL);
dirname++;
}
} /** argc **/
} /** if( no full path name given) **/
/**
** Free up what has been allocated and exit from this procedure
**/
/* if got here via this path ... it must have been OK */
if (Result < 0)
Result = TCL_OK;
unwind0:
/* if Result is negative here ... must have been an unwind */
if (Result < 0)
Result = -Result;
success0:
return (Result); /** --- EXIT PROCEDURE (FAILURE/SUCCESS) --> **/
} /** End of 'ModuleCmd_Avail' **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: check_dir **
** **
** Description: Open and close the passed directory in order to check**
** if it does exist and is readable **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: char *dirname Name of the directory to be **
** checked **
** **
** Result: int 0 Not a directory or unreadable **
** 1 OK **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
++++*/
int check_dir( char *dirname)
{
DIR* dirp;
if( !(dirp = opendir( dirname)))
return( 0);
if( -1 == closedir( dirp))
if( OK != ErrorLogger( ERR_CLOSEDIR, LOC, dirname, NULL))
return( 0);
return( 1);
} /** End of 'check_dir' **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: print_dir **
** **
** Description: Print all files beyond the passed directory **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: char *dir Directory to be scanned **
** char *module A selcted module name or NULL**
** **
** Result: int TCL_OK Successful operation **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
++++*/
static int print_dir(
Tcl_Interp * interp,
char *dir,
char *module
) {
fi_ent *dirlst_head = NULL;
/** Directory list base pointer **/
int count = 0, /** Number of elements in the top **/
/** level directory list **/
tcount = 0, /** Total number of files to print **/
start = 0,
dirlen;
char **cache_list = NULL;
char *selection, *s;
/**
** Print the directory name
**/
if ((sw_format & (SW_PARSE | SW_TERSE | SW_LONG))
&& !(sw_format & (SW_HUMAN | SW_LIST))) {
fprintf(stderr, "%s:\n", dir);
}
if (dir)
dirlen = strlen(dir) + 1;
else
dirlen = 0;
/**
** If the is a module selection given, build the whole selected path
**/
if (module) {
if (dir) {
if (!(selection = stringer(NULL, 0,
dir, psep, module, NULL))) {
ErrorLogger(ERR_STRING, LOC, NULL);
goto unwind0; /** ---- EXIT (FAILURE) ---> **/
}
} else
selection = module;
} else
selection = (char *)NULL;
if (!cache_list) {
/**
** Normal reading of the files
**/
if (!(dirlst_head = get_dir(dir, NULL, &count, &tcount)))
if (OK != ErrorLogger(ERR_READDIR, LOC, dir, NULL))
goto unwind1;
if (!(cache_list =
(char **)module_malloc(tcount * sizeof(char **))))
if (OK != ErrorLogger(ERR_ALLOC, LOC, NULL))
goto unwind1;
(void)memset(cache_list, 0, tcount * sizeof(char **));
start = 0;
dirlst_to_list(cache_list, dirlst_head, count, &start, dir,
selection);
}
/**
** In case of any selection, we have to force all .modulrc's and .versions
** on the path
**/
if (dir) {
s = dir;
while (s) {
if ((s = strchr(s, *psep)))
*s = '\0';
else
break;
SourceRC(interp, dir, modulerc_file, Mod_Load);
SourceVers(interp, dir, module, Mod_Load);
if (s)
*s++ = *psep;
}
/**
** Finally source the rc files in the directory itself
**/
SourceRC(interp, dir, modulerc_file, Mod_Load);
SourceVers(interp, dir, module, Mod_Load);
}
if (dir && selection)
null_free((void *)&selection);
/**
** Print and remove the cache list
**/
delete_dirlst(dirlst_head, count);
print_aligned_files(interp, dir, dir, cache_list, tcount,
(sw_format & SW_LIST ? 1 : -1));
delete_cache_list(cache_list, start);
if (sw_format & SW_LONG)
fprintf(stderr, "\n");
return (TCL_OK); /** ------- EXIT (SUCCESS) --------> **/
unwind1:
if (dir && selection)
null_free((void *)&selection);
unwind0:
return (TCL_ERROR); /** ------- EXIT (FAILURE) --------> **/
} /** End of 'print_dir' **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: get_dir **
** **
** Description: Read in the passed directory and save every interes- **
** ting item in the directory list **
** skipping known version control directories **
** unless they contain module 'dot' files **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: char *dir Directory to be read **
** char *prefix Directory prefix (path) **
** int *listcount Buffer to store the number of**
** elements in the current **
** directory list **
** int *total_count Buffer for the total number **
** of files read **
** **
** Result: fi_ent* NULL Failure **
** else Directory list base pointer **
** *listcount Number of elements in the **
** top level directory list **
** *total_count Total number of files read **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
++++*/
fi_ent *get_dir( char *dir,
char *prefix,
int *listcount,
int *total_count)
{
struct dirent *dp; /** Directory read pointer **/
DIR *dirptr; /** Directory handle **/
fi_ent *dirlst_head, /** Directory list pointers. Head, **/
*dirlst_cur, /** current **/
*dirlst_last; /** and last **/
char *dirname; /** Expanded directory path name **/
char *tmp;
int count = 0;
/**
** Open the desired directiory
**/
if( !(dirptr = opendir( dir))) {
#if 0
/* if you can't open a directory ... is that really an error? */
if( OK != ErrorLogger( ERR_OPENDIR, LOC, dir, NULL))
#endif
return( NULL); /** ----------- EXIT (FAILURE) ------------> **/
}
/**
** Allocate memory for reading in the directory
**/
if(!(dirlst_cur = dirlst_head = (fi_ent*) module_calloc( DIREST,
sizeof( fi_ent)))) {
if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL)) {
if( -1 == closedir( dirptr))
ErrorLogger( ERR_CLOSEDIR, LOC, dir, NULL);
goto unwind0;
}
}
dirlst_last = dirlst_head + DIREST;
/**
** Read in the contents of the directory. Ignore dotfiles
** and version directories.
**/
for( count = 0, dp = readdir( dirptr); dp != NULL; dp = readdir( dirptr)) {
if( *dp->d_name == '.') continue;
/**
** Conditionally double up the space allocated for reading the direc-
** tory
**/
if(dirlst_cur == dirlst_last) {
if(!(dirlst_head = (fi_ent*) module_realloc(
(char*) dirlst_head, (count<<1) * sizeof( fi_ent))))
if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
goto unwind0;
dirlst_cur = dirlst_head + count;
dirlst_last = dirlst_head + (count<<1);
}
/**
** Build the complete path name and get information about the file
**/
if( !( dirname = mkdirnm( dir, dp->d_name)))
if( OK != ErrorLogger( ERR_DIRNAME, LOC, NULL)) {
if( -1 == closedir( dirptr))
ErrorLogger( ERR_CLOSEDIR, LOC, dir, NULL);
goto unwind1;
}
if( stat( dirname, &(dirlst_cur->fi_stats)) < 0)
if( OK != ErrorLogger( ERR_DIRNOTFOUND, LOC, dirname, NULL)) {
if( -1 == closedir( dirptr))
ErrorLogger( ERR_CLOSEDIR, LOC, dir, NULL);
goto unwind1;
}
/**
** If it is a directory, recursively delve into it ..
**/
if(dirlst_cur->fi_stats.st_mode & S_IFDIR) {
char* np;
char* ndir;
int tmpcount = 0;
/**
** Build the new base points for the recursion
**/
if( !( tmp = mkdirnm( prefix, dp->d_name))) {
if( OK != ErrorLogger( ERR_DIRNAME, LOC, NULL)) {
if( -1 == closedir( dirptr))
ErrorLogger( ERR_CLOSEDIR, LOC, dir, NULL);
goto unwind1;
}
} else {
if(!(np = stringer(NULL,0, tmp, NULL)))
if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
goto unwind1;
}
if( !( tmp = mkdirnm( dir, dp->d_name))) {
if( OK != ErrorLogger( ERR_DIRNAME, LOC, NULL)) {
if( -1 == closedir( dirptr))
ErrorLogger( ERR_CLOSEDIR, LOC, dir, NULL);
goto unwind1;
}
} else {
if(!(ndir = stringer(NULL,0, tmp, NULL)))
if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
goto unwind1;
}
/**
** What if it's a known version control directory
** check if it has a .version file
**/
if(uvec_find(mhash_keys_uvec(skipdirs),dp->d_name,
UVEC_ASCEND) >= 0) {
int found_dot = 0;
if(!stringer(buffer, MOD_BUFSIZE, tmp,psep,version_file,NULL))
if( OK != ErrorLogger( ERR_STRING, LOC, NULL))
goto unwind1;
if(is_("file",buffer))
found_dot++;
if(!stringer(buffer, MOD_BUFSIZE, tmp,psep,modulerc_file,NULL))
if( OK != ErrorLogger( ERR_STRING, LOC, NULL))
goto unwind1;
if(is_("file",buffer))
found_dot++;
if (!found_dot)
continue; /* does not have a module dot file */
}
/**
** The recursion itself ...
**/
dirlst_cur->fi_subdir = get_dir( ndir,np,&dirlst_cur->fi_listcount,
&tmpcount);
/**
** Add the number of real modulefiles (i.e. not subdirs and
** not non-modulefiles) to our total number of modulefiles
** contained in the structure.
**/
*total_count += tmpcount;
/**
** This means that it's an empty directory so the prefix is
** never used
**/
if( !dirlst_cur->fi_listcount)
null_free((void *) &np);
null_free((void *) &ndir);
/**
** if it is not a directory check the magic cookie of the file. Only
** files with the modules magic cookie will be accepted. Also tem-
** porary files are to be ignored.
**/
} else if( dp->d_name[NLENGTH(dp)-1] == '~' ||
!check_magic( dirname, MODULES_MAGIC_COOKIE,
MODULES_MAGIC_COOKIE_LENGTH)) {
continue;
} else {
dirlst_cur->fi_subdir = NULL;
}
/**
** Put the name of the file on the directory list
**/
dirlst_cur->fi_prefix = prefix;
if(!(dirlst_cur->fi_name = stringer(NULL,0, dp->d_name, NULL)))
if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
goto unwind1;
/**
** Count even the number of elements in the current list as the
** total number of elements read in so far.
** Increment the list index to be prepared for the next entry.
**/
count++;
(*total_count)++;
dirlst_cur++;
} /** for **/
/**
** Now sort alphabetically what has been read
**/
if( count > 1)
qsort( dirlst_head, count, sizeof(fi_ent), fi_ent_cmp);
/**
** Close the directory, set up return values
**/
if( -1 == closedir( dirptr))
if( OK != ErrorLogger( ERR_CLOSEDIR, LOC, dir, NULL))
goto unwind1;
*listcount = count;
return( dirlst_head); /** ----------- EXIT (SUCCESS) ------------> **/
unwind1:
null_free((void *) &dirlst_cur);
unwind0:
return( NULL); /** ----------- EXIT (FAILURE) ------------> **/
} /** End of 'get_dir' **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: dirlst_to_list **
** **
** Description: Transform the passed nested directory list into a **
** flat list of strings **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: char **list List to be created **
** fi_ent *dirlst_head Head of the directory list **
** to be transformed **
** int count Number of elements in the **
** directory list **
** int *beginning Index of the element in List **
** to start appending the file- **
** names at. **
** char *path prepend pathname to list **
** char *module A search pattern **
** **
** Result: - **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
++++*/
void dirlst_to_list( char **list,
fi_ent *dirlst_head,
int count,
int *beginning,
char *path,
char *module)
{
fi_ent *dirlst_cur;
int i;
char *ptr;
int mlen;
int (*str_comp) (const char *, const char *, size_t);
/**
** If there's any selection given, figure out its length
**/
if( module)
mlen = strlen( module);
/**
** string comparaison ignore case?
** based on sw_icase value
**/
if (sw_icase) str_comp = &strncasecmp;
else str_comp = &strncmp;
/**
** Put all files in the directory list at the end of the passed list
** of character arrays
**/
for( i=0, dirlst_cur=dirlst_head;
i<count && dirlst_cur;
i++, dirlst_cur++) {
if( dirlst_cur->fi_prefix) {
if( path) {
if(!stringer(buf, MOD_BUFSIZE, path,psep,
dirlst_cur->fi_prefix,psep, dirlst_cur->fi_name, NULL))
return;
} else {
if(!stringer(buf, MOD_BUFSIZE, dirlst_cur->fi_prefix,psep,
dirlst_cur->fi_name, NULL))
return;
}
ptr = buf;
} else {
if( path) {
if(!stringer(buf, MOD_BUFSIZE, path,psep,
dirlst_cur->fi_name, NULL))
return;
ptr = buf;
} else
ptr = dirlst_cur->fi_name;
}
/**
** Check whether this is part of the selected modules ...
**/
if( !module || !str_comp( module, buf, mlen)) {
/**
** Put this guy on the list
**/
if(!(list[(*beginning)++] = stringer(NULL,0, ptr, NULL))) {
if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL)) {
while( i--)
null_free((void *) list + (--(*beginning)));
return; /** ------- EXIT (FAILURE) --------> **/
}
}
}
/**
** recursively descend to subdirectories
**/
if( dirlst_cur->fi_subdir)
dirlst_to_list( list, dirlst_cur->fi_subdir,
dirlst_cur->fi_listcount, beginning, path, module);
} /** for **/
} /** end of 'dirlst_to_list' **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: delete_dirlst **
** **
** Description: Delete an entire directory list including all sub- **
** directory lists **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: fi_ent *dirlst_head Head of the list to be re- **
** moved **
** **
** Result: - **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
++++*/
void delete_dirlst( fi_ent *dirlst_head,
int count)
{
fi_ent *dirlst_cur;
int i;
if( !dirlst_head)
return;
/**
** Free all filenames stored in the list
**/
for( i=0, dirlst_cur=dirlst_head;
i<count && dirlst_cur;
i++, dirlst_cur++) {
null_free((void *) &(dirlst_cur->fi_name));
/**
** Recursivle decend to subdirectories
**/
if( dirlst_cur->fi_subdir)
delete_dirlst( dirlst_cur->fi_subdir, dirlst_cur->fi_listcount);
} /** for **/
/**
** Remove the entire list
**/
if( dirlst_head->fi_prefix)
null_free((void *) &(dirlst_head->fi_prefix));
null_free((void *) &dirlst_head);
} /** End of 'delete_dirlst' **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: delete_cache_list **
** **
** Description: Remove an entire list of allocated strings and free **
** up the used memory **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: char **list List of filenames to be print**
** int tcount Size ofd the list in elements**
** **
** Result: - **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
++++*/
void delete_cache_list( char **list,
int tcount)
{
int i;
for( i=0; i<tcount; i++)
null_free((void *) (list + i));
null_free((void *)&list);
} /** End of 'delete_cache_list' **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: print_aligned_files **
** **
** Description: Print out the filenames passed in a sorted array **
** column by column taking care of the order being re- **
** flected to the single columns **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: char **list List of filenames to print **
** char *path common path **
** char *header List header **
** int tcount Size of the list in elements **
** int numbered Controls printing of numbers **
** set to -1 for none **
** **
** Result: - **
** **
** Attached Globals: g_current_module The module which is handled **
** by the current command **
** **
** ************************************************************************ **
++++*/
void print_aligned_files(
Tcl_Interp * interp,
char *path,
char *header,
char **list,
int tcount,
int numbered
) {
struct stat stats;
struct tm *tm;
char *symbols, *module, *release;
char buffer[20];
char modulefile[MOD_BUFSIZE];
char modulename[MOD_BUFSIZE];
char *timestr;
char *s;
int t;
int terminal_width = 80;
int maxlen = 0;
/**
** In case of terse, human output we need to obtain the size of
** the tty
**/
if (sw_format & (SW_HUMAN | SW_LONG)) {
struct winsize window_size;
int fd_err = fileno(stderr);
if (isatty(fd_err))
if (ioctl(fd_err, TIOCGWINSZ, &window_size) != -1)
terminal_width = (window_size.ws_col == 0) ?
80 : window_size.ws_col;
}
if (!path) {
/**
** For listing loaded modules ...
** Load the MODULEPATH and split it into a list of paths.
**/
if (!uvec_number(ModulePathVec))
if (OK != ErrorLogger(ERR_MODULE_PATH, LOC, NULL))
return;
}
/**
** Scan all entries of the passed list
**/
_init_file_list();
while (list && tcount-- && *list) {
/**
** find module[/version] in filename
**/
if ((g_current_module = s = strrchr(*list, *psep))) {
*s = 0;
g_current_module++;
if (TCL_ERROR ==
Locate_ModuleFile(interp, g_current_module,
modulename, modulefile)) {
g_current_module = strrchr(*list, *psep);
g_current_module++;
}
*s = *psep;
}
if (!stat(*list, &stats)) {
/**
** If the file is a directory, try to source the .modulerc
** file and skip to the next file
**/
if (S_ISDIR(stats.st_mode)) {
SourceRC(interp,*list,modulerc_file,Mod_Load);
SourceVers(interp, *list, g_current_module,
Mod_Load);
g_current_module = (char *)NULL;
list++;
continue;
}
/**
** For listing loaded modules ...
**/
if (!path) {
size_t pathlen, maxPrefixLength = 0;
char **dirname = ModulePath;
/**
** try to find the longest prefix from the module path
**/
while (dirname && *dirname) {
pathlen = strlen(*dirname);
if (!strncmp(*list,*dirname,pathlen)
&& (pathlen > maxPrefixLength)) {
/* partial match */
maxPrefixLength = pathlen;
}
dirname++;
}
/**
** Skip over *psep
**/
if (maxPrefixLength > 0)
maxPrefixLength += 1;
module = stringer(NULL, 0,