home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl502b.zip / lib / Config.pm < prev    next >
Text File  |  1996-02-26  |  14KB  |  672 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.002 or die sprintf
  8.     "Perl lib version (5.002) doesn't match executable version (%.3f)\n", $];
  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. ## This file was produced by running the Configure script. It holds all the
  15. ## definitions figured out by Configure. Should you modify one of these values,
  16. ## do not forget to propagate your changes by running "Configure -der". You may
  17. ## instead choose to run each of the .SH files by yourself, or "Configure -S".
  18. ##
  19. #
  20. ## Configuration time: Tue Feb 20 13:47:28 CUT 1996
  21. ## Configured by: ak
  22. ## Target system: OS/2 2.11 - EMX 0.9
  23.  
  24. my $config_sh = <<'!END!';
  25. archlibexp='c:/usr/lib/perl5/os2'
  26. archname='os2'
  27. cc='gcc'
  28. ccflags='-Zomf'
  29. cppflags='-DDOSISH -DOS2=2 -DEMBED -I. -Ios2'
  30. dlsrc='dl_os2.xs'
  31. dynamic_ext='Fcntl GDBM_File SDBM_File POSIX Socket OS2::UPM OS2::REXX OS2::FTP'
  32. extensions='Fcntl GDBM_File SDBM_File POSIX Socket OS2::UPM OS2::REXX OS2::FTP'
  33. installarchlib='c:/usr/perl5/os2'
  34. installprivlib='c:/usr/perl5'
  35. libpth=''
  36. libs=''
  37. osname='OS/2'
  38. osvers='3.0'
  39. prefix='c:/usr'
  40. privlibexp='c:/usr/perl'
  41. sharpbang='extproc '
  42. shsharp='true'
  43. sig_name='ZERO HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM USR1 USR2 CHLD 19 20 BREAK'
  44. so='dll'
  45. startsh='extproc ksh'
  46. static_ext=' '
  47. Author=''
  48. CONFIG='true'
  49. Date='$Date'
  50. Header=''
  51. Id='$Id'
  52. Locker=''
  53. Log='$Log'
  54. Mcc='Mcc'
  55. PATCHLEVEL='2'
  56. RCSfile='$RCSfile'
  57. Revision='$Revision'
  58. Source=''
  59. State=''
  60. afs='false'
  61. alignbytes='8'
  62. aphostname=''
  63. ar='ar'
  64. archlib='c:/usr/lib/perl5/os2'
  65. archobjs=''
  66. awk='awk'
  67. baserev='5.0'
  68. bash=''
  69. bin='c:/usr/binp'
  70. binexp='c:/usr/binp'
  71. bison='bison'
  72. byacc=''
  73. byteorder='1234'
  74. c='\c'
  75. castflags='0'
  76. cat='cat'
  77. cccdlflags='-Zdll'
  78. ccdlflags=''
  79. cf_by='ak'
  80. cf_email='ak@ananke.s.bawue.de'
  81. cf_time='Tue Feb 20 13:47:28 CET 1996'
  82. chgrp=''
  83. chmod=''
  84. chown=''
  85. clocktype='clock_t'
  86. comm='comm'
  87. compress='compress'
  88. contains='grep'
  89. cp='cp'
  90. cpio='cpio'
  91. cpp='cpp'
  92. cpp_stuff='42'
  93. cpplast=''
  94. cppminus=''
  95. cpprun='cpp'
  96. cppstdin='cpp'
  97. cryptlib=''
  98. csh=''
  99. d_Gconvert='gcvt((x),(n),(b))'
  100. d_access='define'
  101. d_alarm='define'
  102. d_archlib='define'
  103. d_attribut='define'
  104. d_bcmp='define'
  105. d_bcopy='define'
  106. d_bsd='undef'
  107. d_bsdpgrp='undef'
  108. d_bzero='define'
  109. d_casti32='define'
  110. d_castneg='define'
  111. d_charvspr='define'
  112. d_chown='undef'
  113. d_chroot='undef'
  114. d_chsize='define'
  115. d_closedir='define'
  116. d_const='define'
  117. d_crypt='define'
  118. d_csh='undef'
  119. d_cuserid='define'
  120. d_dbl_dig='define'
  121. d_difftime='define'
  122. d_dirnamlen='define'
  123. d_dlerror='undef'
  124. d_dlopen='undef'
  125. d_dlsymun='undef'
  126. d_dosuid='undef'
  127. d_dup2='define'
  128. d_eofnblk='define'
  129. d_fchmod='undef'
  130. d_fchown='undef'
  131. d_fcntl='define'
  132. d_fd_macros='define'
  133. d_fd_set='define'
  134. d_fds_bits='define'
  135. d_fgetpos='define'
  136. d_flexfnam='define'
  137. d_flock='define'
  138. d_fork='undef'
  139. d_fpathconf='define'
  140. d_fsetpos='define'
  141. d_getgrps='undef'
  142. d_gethent='define'
  143. d_gethname='undef'
  144. d_getlogin='undef'
  145. d_getpgrp2='undef'
  146. d_getpgrp='undef'
  147. d_getppid='define'
  148. d_getprior='define'
  149. d_htonl='define'
  150. d_index='undef'
  151. d_isascii='define'
  152. d_killpg='undef'
  153. d_link='undef'
  154. d_locconv='define'
  155. d_lockf='undef'
  156. d_lstat='undef'
  157. d_mblen='define'
  158. d_mbstowcs='define'
  159. d_mbtowc='define'
  160. d_memcmp='define'
  161. d_memcpy='define'
  162. d_memmove='define'
  163. d_memset='define'
  164. d_mkdir='define'
  165. d_mkfifo='undef'
  166. d_mktime='define'
  167. d_msg='undef'
  168. d_msgctl='undef'
  169. d_msgget='undef'
  170. d_msgrcv='undef'
  171. d_msgsnd='undef'
  172. d_mymalloc='define'
  173. d_nice='undef'
  174. d_oldarchlib='undef'
  175. d_oldsock='undef'
  176. d_open3='undef'
  177. d_pathconf='define'
  178. d_pause='define'
  179. d_phostname='undef'
  180. d_pipe='define'
  181. d_poll='undef'
  182. d_portable='define'
  183. d_pwage='undef'
  184. d_pwchange='undef'
  185. d_pwclass='undef'
  186. d_pwcomment='undef'
  187. d_pwexpire='undef'
  188. d_pwquota='undef'
  189. d_readdir='define'
  190. d_readlink='undef'
  191. d_rename='define'
  192. d_rewinddir='define'
  193. d_rmdir='define'
  194. d_safebcpy='undef'
  195. d_safemcpy='undef'
  196. d_seekdir='define'
  197. d_select='define'
  198. d_sem='undef'
  199. d_semctl='undef'
  200. d_semget='undef'
  201. d_semop='undef'
  202. d_setegid='undef'
  203. d_seteuid='undef'
  204. d_setlinebuf='undef'
  205. d_setlocale='define'
  206. d_setpgid='undef'
  207. d_setpgrp2='undef'
  208. d_setpgrp='undef'
  209. d_setprior='define'
  210. d_setregid='undef'
  211. d_setresgid='undef'
  212. d_setresuid='undef'
  213. d_setreuid='undef'
  214. d_setrgid='undef'
  215. d_setruid='undef'
  216. d_setsid='undef'
  217. d_shm='undef'
  218. d_shmat='undef'
  219. d_shmatprototype='undef'
  220. d_shmctl='undef'
  221. d_shmdt='undef'
  222. d_shmget='undef'
  223. d_shrplib='undef'
  224. d_sigaction='define'
  225. d_sigintrp=''
  226. d_sigvec='define'
  227. d_sigvectr='undef'
  228. d_socket='define'
  229. d_sockpair='undef'
  230. d_statblks='undef'
  231. d_stdio_cnt_lval='define'
  232. d_stdio_ptr_lval='define'
  233. d_stdiobase='define'
  234. d_stdstdio='define'
  235. d_strchr='define'
  236. d_strcoll='define'
  237. d_strctcpy='define'
  238. d_strerrm='strerror(e)'
  239. d_strerror='define'
  240. d_strxfrm='define'
  241. d_suidsafe='undef'
  242. d_symlink='undef'
  243. d_syscall='undef'
  244. d_sysconf='define'
  245. d_sysernlst=''
  246. d_syserrlst='define'
  247. d_system='define'
  248. d_tcgetpgrp='define'
  249. d_tcsetpgrp='define'
  250. d_telldir='define'
  251. d_time='define'
  252. d_times='define'
  253. d_truncate='define'
  254. d_tzname='define'
  255. d_umask='define'
  256. d_uname='define'
  257. d_unlnkallvers='define'
  258. d_vfork='undef'
  259. d_vms='undef'
  260. d_void_closedir='define'
  261. d_voidsig='define'
  262. d_voidtty=''
  263. d_volatile='define'
  264. d_vprintf='define'
  265. d_wait4='undef'
  266. d_waitpid='define'
  267. d_wcstombs='define'
  268. d_wctomb='define'
  269. d_xenix='undef'
  270. date='date'
  271. db_hashtype='int'
  272. db_prefixtype='int'
  273. defvoidused='15'
  274. direntrytype='struct dirent'
  275. dlext='dll'
  276. eagain='EAGAIN'
  277. echo='echo'
  278. egrep='egrep'
  279. emacs=''
  280. eunicefix=':'
  281. exe_ext=''
  282. expr='expr'
  283. find='find'
  284. firstmakefile='makefile'
  285. flex=''
  286. fpostype='fpos_t'
  287. freetype='void'
  288. full_csh=''
  289. full_sed='sed'
  290. gcc=''
  291. gccversion=''
  292. gidtype='gid_t'
  293. glibpth='c:/usr/lib/emx h:/emx/lib'
  294. grep='grep'
  295. groupcat=''
  296. groupstype='gid_t'
  297. h_fcntl='true'
  298. h_sysfile='true'
  299. hint='recommended'
  300. hostcat=''
  301. huge=''
  302. i_bsdioctl=''
  303. i_db='undef'
  304. i_dbm='define'
  305. i_dirent='define'
  306. i_dld='undef'
  307. i_dlfcn='undef'
  308. i_fcntl='define'
  309. i_float='define'
  310. i_gdbm='define'
  311. i_grp='undef'
  312. i_limits='define'
  313. i_locale='define'
  314. i_malloc='define'
  315. i_math='define'
  316. i_memory='undef'
  317. i_ndbm='undef'
  318. i_neterrno='undef'
  319. i_niin='define'
  320. i_pwd='undef'
  321. i_rpcsvcdbm='undef'
  322. i_sgtty='undef'
  323. i_stdarg='define'
  324. i_stddef='define'
  325. i_stdlib='define'
  326. i_string='define'
  327. i_sysdir='define'
  328. i_sysfile='define'
  329. i_sysfilio='undef'
  330. i_sysin='undef'
  331. i_sysioctl='define'
  332. i_sysndir='undef'
  333. i_sysparam='define'
  334. i_sysselct='define'
  335. i_syssockio=''
  336. i_sysstat='define'
  337. i_systime='define'
  338. i_systimek='undef'
  339. i_systimes='define'
  340. i_systypes='define'
  341. i_sysun='undef'
  342. i_termio='undef'
  343. i_termios='define'
  344. i_time='define'
  345. i_unistd='define'
  346. i_utime='define'
  347. i_varargs='undef'
  348. i_varhdr='stdarg.h'
  349. i_vfork='undef'
  350. incpath=''
  351. inews=''
  352. installbin='c:/usr/binp'
  353. installman1dir=''
  354. installman3dir=''
  355. installscript='c:/usr/binp'
  356. installsitearch='c:/usr/perl5'
  357. installsitelib='c:/usr/perl'
  358. intsize='4'
  359. known_extensions='DB_File Fcntl FileHandle GDBM_File NDBM_File ODBM_File POSIX SDBM_File Safe Socket UPM REXXCALL'
  360. ksh='ksh'
  361. large=''
  362. ld='gcc'
  363. lddlflags='-Zdll'
  364. ldflags='-Zomf'
  365. less='pg'
  366. lib_ext='.lib'
  367. libc=''
  368. libswanted=''
  369. line='line'
  370. lint=''
  371. lkflags=''
  372. ln=''
  373. lns=''
  374. locincpth=''
  375. loclibpth=''
  376. lp=''
  377. lpr=''
  378. ls='ls'
  379. lseektype='off_t'
  380. mail=''
  381. mailx=''
  382. make=''
  383. mallocobj='malloc.obj'
  384. mallocsrc='malloc.c'
  385. malloctype='void *'
  386. man1dir=''
  387. man1direxp=''
  388. man1ext=''
  389. man3dir=''
  390. man3direxp=''
  391. man3ext=''
  392. medium=''
  393. mips=''
  394. mips_type=''
  395. mkdir='mkdir'
  396. models='none'
  397. modetype='mode_t'
  398. more='pg'
  399. mv=''
  400. myarchname='OS/2 3.0'
  401. mydomain='.s.bawue.de'
  402. myhostname='ananke'
  403. myuname='OS/2 3.0 - EMX 0.9b'
  404. n=''
  405. nm_opt='-p'
  406. nroff='nroff'
  407. o_nonblock='O_NONBLOCK'
  408. obj_ext='.obj'
  409. oldarchlib=''
  410. oldarchlibexp=''
  411. optimize='-O2'
  412. orderlib='false'
  413. package='perl5'
  414. pager='pg'
  415. passcat=''
  416. patchlevel='2'
  417. path_sep=';'
  418. perl='perl'
  419. perladmin='ak@ananke.s.bawue.de'
  420. perlpath='c:/usr/bin/perl'
  421. pg='pg'
  422. phostname='hostname'
  423. plibpth=''
  424. pmake=''
  425. pr=''
  426. prefixexp='c:/usr'
  427. privlib='c:/usr/perl'
  428. prototype='define'
  429. randbits='15'
  430. ranlib=':'
  431. rd_nodata='-1'
  432. rm='rm'
  433. rmail=''
  434. runnm='true'
  435. scriptdir='c:/usr/binp'
  436. scriptdirexp='c:/usr/bin'
  437. sed='sed'
  438. selecttype='int *'
  439. sendmail=''
  440. sh=''
  441. shar=''
  442. shmattype='char *'
  443. shrpdir='none'
  444. sig_num='0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 '
  445. signal_t='void'
  446. sitearch='c:/usr/perl/os'
  447. sitearchexp='c:/usr/perl5/os2'
  448. sitelib='c:/usr/perl'
  449. sitelibexp='c:/usr/perl'
  450. sizetype='size_t'
  451. sleep='sleep'
  452. smail=''
  453. small=''
  454. sockethdr=''
  455. socketlib=''
  456. sort='sort'
  457. spackage='Perl5'
  458. spitshell='cat'
  459. split=''
  460. ssizetype='ssize_t'
  461. startperl='extproc perl -S'
  462. stdchar='unsigned char'
  463. stdio_base='(fp)->_buffer'
  464. stdio_bufsiz='((fp)->_rcount + (fp)->_ptr - (fp)->_buffer)'
  465. stdio_cnt='((fp)->_rcount)'
  466. stdio_ptr='((fp)->_ptr)'
  467. strings='/usr/include/string.h'
  468. submit=''
  469. sysman=''
  470. tail='tail'
  471. tar=''
  472. tbl=''
  473. test=''
  474. timeincl=''
  475. timetype='time_t'
  476. touch='touch'
  477. tr=''
  478. troff=''
  479. uidtype='uid_t'
  480. uname='uname'
  481. uniq=''
  482. usedl='define'
  483. usemymalloc='y'
  484. usenm='true'
  485. useposix='true'
  486. usesafe='true'
  487. usevfork='false'
  488. usrinc='c:/usr/inc'
  489. uuname=''
  490. vi=''
  491. voidflags='15'
  492. xlibpth=''
  493. zcat=''
  494. !END!
  495.  
  496. my $summary = <<'!END!';
  497. Summary of my $package ($baserev patchlevel $PATCHLEVEL) configuration:
  498.   Platform:
  499.     osname=$osname, osver=$osvers, archname=$archname
  500.     uname='$myuname'
  501.     hint=$hint, useposix=$useposix 
  502.   Compiler:
  503.     cc='$cc', optimize='$optimize', gccversion=$gccversion
  504.     cppflags='$cppflags'
  505.     ccflags ='$ccflags'
  506.     stdchar='$stdchar', d_stdstdio=$d_stdstdio, usevfork=$usevfork
  507.     voidflags=$voidflags, castflags=$castflags, d_casti32=$d_casti32, d_castneg=$d_castneg
  508.     intsize=$intsize, alignbytes=$alignbytes, usemymalloc=$usemymalloc, randbits=$randbits
  509.   Linker and Libraries:
  510.     ld='$ld', ldflags ='$ldflags'
  511.     libpth=$libpth
  512.     libs=$libs
  513.     libc=$libc, so=$so
  514.   Dynamic Linking:
  515.     dlsrc=$dlsrc, dlext=$dlext, d_dlsymun=$d_dlsymun, ccdlflags='$ccdlflags'
  516.     cccdlflags='$cccdlflags', lddlflags='$lddlflags'
  517.  
  518. !END!
  519. my $summary_expanded = 0;
  520.  
  521. sub myconfig {
  522.     return $summary if $summary_expanded;
  523.     $summary =~ s/\$(\w+)/$Config{$1}/ge;
  524.     $summary_expanded = 1;
  525.     $summary;
  526. }
  527.  
  528. tie %Config, Config;
  529. sub TIEHASH { bless {} }
  530. sub FETCH { 
  531.     # check for cached value (which maybe undef so we use exists not defined)
  532.     return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]});
  533.  
  534.     my($value); # search for the item in the big $config_sh string
  535.     return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m);
  536.  
  537.     $value = undef if $value eq 'undef'; # So we can say "if $Config{'foo'}".
  538.     $_[0]->{$_[1]} = $value; # cache it
  539.     return $value;
  540. }
  541.  
  542. my $prevpos = 0;
  543.  
  544. sub FIRSTKEY {
  545.     $prevpos = 0;
  546.     my($key) = $config_sh =~ m/^(.*?)=/;
  547.     $key;
  548. }
  549.  
  550. sub NEXTKEY {
  551.     my $pos = index($config_sh, "\n", $prevpos) + 1;
  552.     my $len = index($config_sh, "=", $pos) - $pos;
  553.     $prevpos = $pos;
  554.     $len > 0 ? substr($config_sh, $pos, $len) : undef;
  555. }
  556.  
  557. sub EXISTS { 
  558.      exists($_[0]->{$_[1]})  or  $config_sh =~ m/^$_[1]=/m; 
  559. }
  560.  
  561. sub STORE  { die "\%Config::Config is read-only\n" }
  562. sub DELETE { &STORE }
  563. sub CLEAR  { &STORE }
  564.  
  565.  
  566. sub config_sh {
  567.     $config_sh
  568. }
  569. sub config_vars {
  570.     foreach(@_){
  571.     my $v=(exists $Config{$_}) ? $Config{$_} : 'UNKNOWN';
  572.     $v='undef' unless defined $v;
  573.     print "$_='$v';\n";
  574.     }
  575. }
  576.  
  577. 1;
  578. __END__
  579.  
  580. =head1 NAME
  581.  
  582. Config - access Perl configuration information
  583.  
  584. =head1 SYNOPSIS
  585.  
  586.     use Config;
  587.     if ($Config{'cc'} =~ /gcc/) {
  588.     print "built by gcc\n";
  589.     } 
  590.  
  591.     use Config qw(myconfig config_sh config_vars);
  592.  
  593.     print myconfig();
  594.  
  595.     print config_sh();
  596.  
  597.     config_vars(qw(osname archname));
  598.  
  599.  
  600. =head1 DESCRIPTION
  601.  
  602. The Config module contains all the information that was available to
  603. the C<Configure> program at Perl build time (over 900 values).
  604.  
  605. Shell variables from the F<config.sh> file (written by Configure) are
  606. stored in the readonly-variable C<%Config>, indexed by their names.
  607.  
  608. Values stored in config.sh as 'undef' are returned as undefined
  609. values.  The perl C<exists> function can be used to check is a
  610. named variable exists.
  611.  
  612. =over 4
  613.  
  614. =item myconfig()
  615.  
  616. Returns a textual summary of the major perl configuration values.
  617. See also C<-V> in L<perlrun/Switches>.
  618.  
  619. =item config_sh()
  620.  
  621. Returns the entire perl configuration information in the form of the
  622. original config.sh shell variable assignment script.
  623.  
  624. =item config_vars(@names)
  625.  
  626. Prints to STDOUT the values of the named configuration variable. Each is
  627. printed on a separate line in the form:
  628.  
  629.   name='value';
  630.  
  631. Names which are unknown are output as C<name='UNKNOWN';>.
  632. See also C<-V:name> in L<perlrun/Switches>.
  633.  
  634. =back
  635.  
  636. =head1 EXAMPLE
  637.  
  638. Here's a more sophisticated example of using %Config:
  639.  
  640.     use Config;
  641.  
  642.     defined $Config{sig_name} || die "No sigs?";
  643.     foreach $name (split(' ', $Config{sig_name})) {
  644.     $signo{$name} = $i;
  645.     $signame[$i] = $name;
  646.     $i++;
  647.     }   
  648.  
  649.     print "signal #17 = $signame[17]\n";
  650.     if ($signo{ALRM}) { 
  651.     print "SIGALRM is $signo{ALRM}\n";
  652.     }   
  653.  
  654. =head1 WARNING
  655.  
  656. Because this information is not stored within the perl executable
  657. itself it is possible (but unlikely) that the information does not
  658. relate to the actual perl binary which is being used to access it.
  659.  
  660. The Config module is installed into the architecture and version
  661. specific library directory ($Config{installarchlib}) and it checks the
  662. perl version number when loaded.
  663.  
  664. =head1 NOTE
  665.  
  666. This module contains a good example of how to use tie to implement a
  667. cache and an example of how to make a tied variable readonly to those
  668. outside of it.
  669.  
  670. =cut
  671.  
  672.