home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / Config.pm < prev    next >
Text File  |  1998-04-17  |  12KB  |  648 lines

  1. package Config;
  2. use Exporter ();
  3. @ISA = (Exporter);
  4. @EXPORT = qw(%Config);
  5. @EXPORT_OK = qw(myconfig config_sh config_vars);
  6.  
  7. $] == 5.004
  8.   or die "Perl lib version (5.004) doesn't match executable version ($])";
  9.  
  10. # This file was created by configpm when Perl was built. Any changes
  11. # made to this file will be lost the next time perl is built.
  12.  
  13. ##
  14. ## Manually created configuration file for Macintii
  15. ## Configuration time:    18Jun97
  16. ## Configured by:     Matthias Neeracher <neeri@iis.ee.ethz.ch>
  17. ## Target system:     Apple Macintosh
  18. #
  19.  
  20. my $config_sh = <<'!END!';
  21. extensions='DB_File DynaLoader Fcntl NDBM_File POSIX IO Socket Opcode Safe'
  22. static_ext='DynaLoader'
  23. osname='MacOS'
  24. osvers='7.5'
  25. archlibexp=''
  26. archname=''
  27. installarchlib=''
  28. cc='C'
  29. ccflags=''
  30. cppflags=''
  31. dlsrc=''
  32. libpth=''
  33. libs=''
  34. prefix=''
  35. installprivlib=''
  36. privlibexp=''
  37. sig_name=''
  38. so=''
  39. sharpbang=''
  40. shsharp=''
  41. startsh=''
  42. Author='neeri'
  43. CONFIG='true'
  44. Date=''
  45. Header=''
  46. Id=''
  47. Locker=''
  48. Log=''
  49. Mcc='C'
  50. PATCHLEVEL='0'
  51. RCSfile=''
  52. Revision=''
  53. Source=''
  54. State=''
  55. afs=''
  56. alignbytes=''
  57. aphostname=''
  58. archlib=''
  59. awk='gawk'
  60. bash=''
  61. bin=''
  62. binexp=''
  63. bison='bison'
  64. byacc='byacc'
  65. byteorder='4321'
  66. c=''
  67. castflags='0'
  68. cat='Catenate'
  69. cccdlflags=''
  70. ccdlflags=''
  71. cf_by=''
  72. cf_time=''
  73. chgrp=''
  74. chmod=''
  75. chown=''
  76. clocktype='clock_t'
  77. compress='Stuffit'
  78. contains=''
  79. cp='Duplicate'
  80. cpio=''
  81. cpp='C -e'
  82. cpp_stuff=''
  83. cpplast=''
  84. cppminus=''
  85. cpprun=''
  86. cppstdin=''
  87. cryptlib=''
  88. csh=''
  89. d_Gconvert='undef'
  90. d_access='undef'
  91. d_alarm='undef'
  92. d_archlib='undef'
  93. d_attrib='undef'
  94. d_bcmp='define'
  95. d_bcopy='define'
  96. d_bsdpgrp='undef'
  97. d_bzero='define'
  98. d_casti32='32'
  99. d_castneg='define'
  100. d_charsprf='undef'
  101. d_charvspr='undef'
  102. d_chown='undef'
  103. d_chroot='undef'
  104. d_chsize='undef'
  105. d_closedir='define'
  106. d_const='define'
  107. d_crypt='undef'
  108. d_csh='undef'
  109. d_cuserid='undef'
  110. d_dbl_dig='define'
  111. d_difftime='define'
  112. d_dirnamlen='define'
  113. d_dlerror='undef'
  114. d_dlopen='undef'
  115. d_dlsymun='undef'
  116. d_dosuid='undef'
  117. d_drem='undef'
  118. d_dup2='2'
  119. d_eunice='undef'
  120. d_fchmod='define'
  121. d_fchown='undef'
  122. d_fcntl='define'
  123. d_fd_macros='define'
  124. d_fd_set='define'
  125. d_fds_bits='define'
  126. d_fgetpos='define'
  127. d_flexfnam='define'
  128. d_flock='undef'
  129. d_fmod='define'
  130. d_fork='undef'
  131. d_fpathconf='undef'
  132. d_fsetpos='define'
  133. d_getgrps='undef'
  134. d_gethent='undef'
  135. d_gethname='define'
  136. d_getlogin='undef'
  137. d_getpgrp2='undef'
  138. d_getpgrp='undef'
  139. d_getppid='undef'
  140. d_getprior='undef'
  141. d_group='undef'
  142. d_htonl='define'
  143. d_index='undef'
  144. d_isascii='define'
  145. d_killpg='undef'
  146. d_link='undef'
  147. d_linuxstd='undef'
  148. d_locconv='undef'
  149. d_lockf='undef'
  150. d_lstat='define'
  151. d_mblen='undef'
  152. d_mbstowcs='define'
  153. d_mbtowc='define'
  154. d_memcmp='define'
  155. d_memcpy='define'
  156. d_memmove='define'
  157. d_memset='define'
  158. d_mkdir='define'
  159. d_mkfifo='undef'
  160. d_mktime='define'
  161. d_msg='undef'
  162. d_msgctl='undef'
  163. d_msgget='undef'
  164. d_msgrcv='undef'
  165. d_msgsnd='undef'
  166. d_mymalloc='undef'
  167. d_nice='undef'
  168. d_oldsock='undef'
  169. d_open3='3'
  170. d_passwd='undef'
  171. d_pathconf='undef'
  172. d_pause='undef'
  173. d_phostname='undef'
  174. d_pipe='undef'
  175. d_portable='undef'
  176. d_pwage='undef'
  177. d_pwchange='undef'
  178. d_pwclass='undef'
  179. d_pwcomment='undef'
  180. d_pwexpire='undef'
  181. d_pwquota='undef'
  182. d_readdir='define'
  183. d_readlink='define'
  184. d_rename='define'
  185. d_rewinddir='define'
  186. d_rmdir='define'
  187. d_safebcpy='define'
  188. d_safemcpy='undef'
  189. d_seekdir='define'
  190. d_select='define'
  191. d_sem='undef'
  192. d_semctl='undef'
  193. d_semget='undef'
  194. d_semop='undef'
  195. d_setegid='undef'
  196. d_seteuid='undef'
  197. d_setlinebuf='undef'
  198. d_setlocale='undef'
  199. d_setpgid='undef'
  200. d_setpgrp2='2'
  201. d_setpgrp='undef'
  202. d_setprior='undef'
  203. d_setregid='undef'
  204. d_setresgid='undef'
  205. d_setresuid='undef'
  206. d_setreuid='undef'
  207. d_setrgid='undef'
  208. d_setruid='undef'
  209. d_setsid='undef'
  210. d_shm='undef'
  211. d_shmat='undef'
  212. d_shmatprototype='undef'
  213. d_shmctl='undef'
  214. d_shmdt='undef'
  215. d_shmget='undef'
  216. d_socket='define'
  217. d_sockpair='undef'
  218. d_statblks='undef'
  219. d_stdstdio='define'
  220. d_strchr='define'
  221. d_strcoll='undef'
  222. d_strctcpy='undef'
  223. d_strerrm='undef'
  224. d_strerror='define'
  225. d_strtod='define'
  226. d_strtol='define'
  227. d_strtoul='define'
  228. d_strxfrm='define'
  229. d_suidsafe='undef'
  230. d_symlink='define'
  231. d_syscall='undef'
  232. d_sysconf='undef'
  233. d_sysernlst='undef'
  234. d_syserrlst='undef'
  235. d_system='undef'
  236. d_tcgetpgrp='undef'
  237. d_tcsetpgrp='undef'
  238. d_telldir='define'
  239. d_time='define'
  240. d_times='define'
  241. d_truncate='undef'
  242. d_tzname='undef'
  243. d_umask='define'
  244. d_uname='undef'
  245. d_vfork='undef'
  246. d_void_closedir='undef'
  247. d_voidsig='undef'
  248. d_voidtty='undef'
  249. d_volatile='define'
  250. d_vprintf='define'
  251. d_wait4='undef'
  252. d_waitpid='undef'
  253. d_wcstombs='define'
  254. d_wctomb='define'
  255. d_xenix='undef'
  256. date='Date'
  257. defvoidused=''
  258. direntrytype='dirent'
  259. dlext=''
  260. dont_use_nlink='define'
  261. echo='Echo'
  262. egrep='egrep'
  263. emacs='$emacs'
  264. eunicefix=':'
  265. expr='Evaluate'
  266. find=''
  267. flex='flex'
  268. fpostype='fpos_t'
  269. gcc='gcc'
  270. gccversion=''
  271. gidtype=''
  272. glibpth=''
  273. grep='grep'
  274. groupcat=''
  275. groupstype=''
  276. h_fcntl='true'
  277. h_sysfile='false'
  278. hint=''
  279. hostcat=''
  280. huge=''
  281. i_bsdioctl=''
  282. i_db='define'
  283. i_dbm='define'
  284. i_dirent='define'
  285. i_dld=''
  286. i_dlfcn=''
  287. i_fcntl='define'
  288. i_float='define'
  289. i_gdbm='undef'
  290. i_grp='undef'
  291. i_limits='define'
  292. i_malloc='undef'
  293. i_math='define'
  294. i_memory='define'
  295. i_ndbm='define'
  296. i_neterrno='undef'
  297. i_niin='undef'
  298. i_pwd='undef'
  299. i_sgtty=''
  300. i_stdarg='define'
  301. i_stddef='define'
  302. i_stdlib='define'
  303. i_string='define'
  304. i_sysdir='undef'
  305. i_sysfile='undef'
  306. i_sysfilio=''
  307. i_sysin='define'
  308. i_sysioctl='define'
  309. i_sysndir=''
  310. i_sysparam=''
  311. i_sysselct=''
  312. i_syssockio=''
  313. i_systime='define'
  314. i_systimek=''
  315. i_systimes=''
  316. i_termio=''
  317. i_termios=''
  318. i_time='define'
  319. i_unistd='define'
  320. i_utime=''
  321. i_varargs=''
  322. i_varhdr='stdarg.h'
  323. i_vfork=''
  324. incpath=''
  325. inews=''
  326. installbin=''
  327. installmansrc=''
  328. installscript=''
  329. intsize='32'
  330. known_extensions='DB_File DynaLoader Fcntl NDBM_File POSIX IO Socket Opcode Safe'
  331. ksh=''
  332. large=''
  333. lddlflags=''
  334. ldflags=''
  335. less=''
  336. libc=''
  337. libswanted=''
  338. line='line'
  339. lint=''
  340. lkflags=''
  341. ln=''
  342. lns=''
  343. lp=''
  344. lpr='Print'
  345. ls='Directory'
  346. lseektype=''
  347. mail=''
  348. mailx=''
  349. make='BuildProgram'
  350. mallocobj=''
  351. mallocsrc=''
  352. malloctype=''
  353. manext=''
  354. mansrc=''
  355. mansrcexp=''
  356. medium=''
  357. mips=''
  358. mips_type=''
  359. mkdir='NewFolder'
  360. models=''
  361. modetype=''
  362. more=''
  363. mv='Move'
  364. mydomain=''
  365. myhostname=''
  366. myuname=''
  367. n=''
  368. nm_opt=''
  369. nroff=''
  370. optimize=''
  371. orderlib=''
  372. package=''
  373. passcat=''
  374. path_sep=','
  375. perl='Perl'
  376. pg=''
  377. phostname=''
  378. plibpth=''
  379. pmake=''
  380. pr=''
  381. privlib=''
  382. prototype=''
  383. randbits=''
  384. ranlib=''
  385. rm='Delete'
  386. rmail=''
  387. runnm=''
  388. scriptdir=''
  389. scriptdirexp=''
  390. sed='sed'
  391. selecttype=''
  392. sendmail=''
  393. sh=''
  394. shar=''
  395. shmattype=''
  396. signal_t='signal_t'
  397. sizetype=''
  398. sleep=''
  399. smail=''
  400. small=''
  401. sockethdr=''
  402. socketlib=''
  403. sort='Sort'
  404. spackage=''
  405. spitshell=''
  406. split=''
  407. ssizetype=''
  408. startperl='Perl -Sx "{0}" {"Parameters"}; Exit {Status}\n#!perl'
  409. stdchar=''
  410. strings='define'
  411. submit=''
  412. sysman=''
  413. tail=''
  414. tar=''
  415. tbl=''
  416. test=''
  417. timeincl='time.h'
  418. timetype='time_t'
  419. touch='SetFile -m .'
  420. tr=''
  421. troff=''
  422. uidtype=''
  423. uname=''
  424. uniq=''
  425. usedl=''
  426. usemymalloc=''
  427. usenm=''
  428. useposix='true'
  429. usevfork=''
  430. usrinc=''
  431. uuname=''
  432. vi=''
  433. voidflags=''
  434. xlibpth=''
  435. yacc=''
  436. yaccflags=''
  437. zcat=''
  438. !END!
  439.  
  440. my $summary = <<'!END!';
  441. Summary of my $package ($baserev patchlevel $PATCHLEVEL subversion $SUBVERSION) configuration:
  442.   Platform:
  443.     osname=$osname, osvers=$osvers, archname=$archname
  444.     uname='$myuname'
  445.     hint=$hint, useposix=$useposix, d_sigaction=$d_sigaction
  446.     bincompat3=$bincompat3 useperlio=$useperlio d_sfio=$d_sfio
  447.   Compiler:
  448.     cc='$cc', optimize='$optimize', gccversion=$gccversion
  449.     cppflags='$cppflags'
  450.     ccflags ='$ccflags'
  451.     stdchar='$stdchar', d_stdstdio=$d_stdstdio, usevfork=$usevfork
  452.     voidflags=$voidflags, castflags=$castflags, d_casti32=$d_casti32, d_castneg=$d_castneg
  453.     intsize=$intsize, alignbytes=$alignbytes, usemymalloc=$usemymalloc, randbits=$randbits
  454.   Linker and Libraries:
  455.     ld='$ld', ldflags ='$ldflags'
  456.     libpth=$libpth
  457.     libs=$libs
  458.     libc=$libc, so=$so
  459.     useshrplib=$useshrplib, libperl=$libperl
  460.   Dynamic Linking:
  461.     dlsrc=$dlsrc, dlext=$dlext, d_dlsymun=$d_dlsymun, ccdlflags='$ccdlflags'
  462.     cccdlflags='$cccdlflags', lddlflags='$lddlflags'
  463.  
  464. !END!
  465. my $summary_expanded = 0;
  466.  
  467. sub myconfig {
  468.     return $summary if $summary_expanded;
  469.     $summary =~ s/\$(\w+)/$Config{$1}/ge;
  470.     $summary_expanded = 1;
  471.     $summary;
  472. }
  473.  
  474. sub FETCH { 
  475.     # check for cached value (which may be undef so we use exists not defined)
  476.     return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]});
  477.  
  478.     # Search for it in the big string 
  479.     my($value, $start, $marker);
  480.     $marker = "$_[1]='";
  481.     # return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m);
  482.     $start = index($config_sh, "\n$marker");
  483.     return undef if ( ($start == -1) &&  # in case it's first 
  484.         (substr($config_sh, 0, length($marker)) ne $marker) );
  485.     if ($start == -1) { $start = length($marker) } 
  486.         else { $start += length($marker) + 1 }
  487.     $value = substr($config_sh, $start, 
  488.         index($config_sh, qq('\n), $start) - $start);
  489.  
  490.     $value = undef if $value eq 'undef'; # So we can say "if $Config{'foo'}".
  491.     $value =~ s/\\n/\n/g if defined $value;         # macintosh
  492.     $_[0]->{$_[1]} = $value; # cache it
  493.     return $value;
  494. }
  495.  
  496. my $prevpos = 0;
  497.  
  498. sub FIRSTKEY {
  499.     $prevpos = 0;
  500.     # my($key) = $config_sh =~ m/^(.*?)=/;
  501.     substr($config_sh, 0, index($config_sh, '=') );
  502.     # $key;
  503. }
  504.  
  505. sub NEXTKEY {
  506.     my $pos = index($config_sh, qq('\n), $prevpos) + 2;
  507.     my $len = index($config_sh, "=", $pos) - $pos;
  508.     $prevpos = $pos;
  509.     $len > 0 ? substr($config_sh, $pos, $len) : undef;
  510. }
  511.  
  512. sub EXISTS { 
  513.     # exists($_[0]->{$_[1]})  or  $config_sh =~ m/^$_[1]=/m;
  514.     exists($_[0]->{$_[1]}) or
  515.     index($config_sh, "\n$_[1]='") != -1 or
  516.     substr($config_sh, 0, length($_[1])+2) eq "$_[1]='";
  517. }
  518.  
  519. sub STORE  { die "\%Config::Config is read-only\n" }
  520. sub DELETE { &STORE }
  521. sub CLEAR  { &STORE }
  522.  
  523.  
  524. sub config_sh {
  525.     $config_sh
  526. }
  527.  
  528. sub config_re {
  529.     my $re = shift;
  530.     my @matches = ($config_sh =~ /^$re=.*\n/mg);
  531.     @matches ? (print @matches) : print "$re: not found\n";
  532. }
  533.  
  534. sub config_vars {
  535.     foreach(@_){
  536.     config_re($_), next if /\W/;
  537.     my $v=(exists $Config{$_}) ? $Config{$_} : 'UNKNOWN';
  538.     $v='undef' unless defined $v;
  539.     print "$_='$v';\n";
  540.     }
  541. }
  542.  
  543. sub TIEHASH { bless {} }
  544.  
  545. tie %Config, 'Config';
  546.  
  547. 1;
  548. __END__
  549.  
  550. =head1 NAME
  551.  
  552. Config - access Perl configuration information
  553.  
  554. =head1 SYNOPSIS
  555.  
  556.     use Config;
  557.     if ($Config{'cc'} =~ /gcc/) {
  558.     print "built by gcc\n";
  559.     } 
  560.  
  561.     use Config qw(myconfig config_sh config_vars);
  562.  
  563.     print myconfig();
  564.  
  565.     print config_sh();
  566.  
  567.     config_vars(qw(osname archname));
  568.  
  569.  
  570. =head1 DESCRIPTION
  571.  
  572. The Config module contains all the information that was available to
  573. the C<Configure> program at Perl build time (over 900 values).
  574.  
  575. Shell variables from the F<config.sh> file (written by Configure) are
  576. stored in the readonly-variable C<%Config>, indexed by their names.
  577.  
  578. Values stored in config.sh as 'undef' are returned as undefined
  579. values.  The perl C<exists> function can be used to check if a
  580. named variable exists.
  581.  
  582. =over 4
  583.  
  584. =item myconfig()
  585.  
  586. Returns a textual summary of the major perl configuration values.
  587. See also C<-V> in L<perlrun/Switches>.
  588.  
  589. =item config_sh()
  590.  
  591. Returns the entire perl configuration information in the form of the
  592. original config.sh shell variable assignment script.
  593.  
  594. =item config_vars(@names)
  595.  
  596. Prints to STDOUT the values of the named configuration variable. Each is
  597. printed on a separate line in the form:
  598.  
  599.   name='value';
  600.  
  601. Names which are unknown are output as C<name='UNKNOWN';>.
  602. See also C<-V:name> in L<perlrun/Switches>.
  603.  
  604. =back
  605.  
  606. =head1 EXAMPLE
  607.  
  608. Here's a more sophisticated example of using %Config:
  609.  
  610.     use Config;
  611.     use strict;
  612.  
  613.     my %sig_num;
  614.     my @sig_name;
  615.     unless($Config{sig_name} && $Config{sig_num}) {
  616.     die "No sigs?";
  617.     } else {
  618.     my @names = split ' ', $Config{sig_name};
  619.     @sig_num{@names} = split ' ', $Config{sig_num};
  620.     foreach (@names) {
  621.         $sig_name[$sig_num{$_}] ||= $_;
  622.     }   
  623.     }
  624.  
  625.     print "signal #17 = $sig_name[17]\n";
  626.     if ($sig_num{ALRM}) { 
  627.     print "SIGALRM is $sig_num{ALRM}\n";
  628.     }   
  629.  
  630. =head1 WARNING
  631.  
  632. Because this information is not stored within the perl executable
  633. itself it is possible (but unlikely) that the information does not
  634. relate to the actual perl binary which is being used to access it.
  635.  
  636. The Config module is installed into the architecture and version
  637. specific library directory ($Config{installarchlib}) and it checks the
  638. perl version number when loaded.
  639.  
  640. =head1 NOTE
  641.  
  642. This module contains a good example of how to use tie to implement a
  643. cache and an example of how to make a tied variable readonly to those
  644. outside of it.
  645.  
  646. =cut
  647.  
  648.