home *** CD-ROM | disk | FTP | other *** search
/ c't freeware shareware 1997 / CT_SW_97.ISO / mac / Software / entwickl / win95 / pw32i306.exe / lib / config.pm < prev    next >
Text File  |  1997-04-08  |  6KB  |  359 lines

  1. package Config;
  2. require Exporter;
  3. @ISA = (Exporter);
  4. @EXPORT = qw(%Config);
  5. @EXPORT_OK = qw(myconfig config_sh config_vars);
  6.  
  7. $] == 5.00307 or die sprintf
  8.     "Perl lib version (5.00307) doesn't match executable version (%.5f)\n", $];
  9.  
  10.  
  11. #### Hard coded for Win32 - WYT 1995-10-23
  12.  
  13. =head1 NAME
  14.  
  15. Config - access Perl configuration option
  16.  
  17. =head1 SYNOPSIS
  18.  
  19.     use Config;
  20.     if ($Config{'cc'} =~ /gcc/) {
  21.     print "built by gcc\n";
  22.     } 
  23.  
  24. =head1 DESCRIPTION
  25.  
  26. The Config module contains everything that was available to the
  27. C<Configure> program at Perl build time.  Shell variables from
  28. F<config.sh> are stored in the readonly-variable C<%Config>, indexed by
  29. their names.
  30.  
  31. =head1 EXAMPLE
  32.  
  33. Here's a more sophisticated example of using %Config:
  34.  
  35.     use Config;
  36.  
  37.     defined $Config{sig_name} || die "No sigs?";
  38.     foreach $name (split(' ', $Config{sig_name})) {
  39.     $signo{$name} = $i;
  40.     $signame[$i] = $name;
  41.     $i++;
  42.     }   
  43.  
  44.     print "signal #17 = $signame[17]\n";
  45.     if ($signo{ALRM}) { 
  46.     print "SIGALRM is $signo{ALRM}\n";
  47.     }   
  48.  
  49. =head1 NOTE
  50.  
  51. This module contains a good example of how to make a variable
  52. readonly to those outside of it.  
  53.  
  54. =cut
  55.  
  56. $config_sh=<<'!END!OF!CONFIG!';
  57. archlib=''
  58. ccflags=''
  59. cppflags=''
  60. dynamic_ext=''
  61. extensions='Fcntl FileHandle SDBM_File IO Socket'
  62. intsize='4'
  63. libpth=''
  64. osname='MSWin32'
  65. osvers='3.51'
  66. sharpbang=''
  67. shsharp=''
  68. sig_name=''
  69. so='dll'
  70. startsh=''
  71. static_ext=' '
  72. Author=''
  73. CONFIG='true'
  74. Date='$Date'
  75. Header=''
  76. Id='$Id'
  77. Locker=''
  78. Log='$Log'
  79. Mcc='Mcc'
  80. PATCHLEVEL='1'
  81. RCSfile='$RCSfile'
  82. Revision='$Revision'
  83. Source=''
  84. State=''
  85. afs='false'
  86. alignbytes='4'
  87. aphostname=''
  88. archlibexp=
  89. archname='i386-win32'
  90. awk='awk'
  91. baserev='5.0'
  92. bash=''
  93. bin=''
  94. binexp=''
  95. bison=''
  96. byacc='byacc'
  97. byteorder='1234'
  98. c=''
  99. castflags='0'
  100. cat='type'
  101. cc='cl'
  102. cccdlflags=''
  103. ccdlflags=''
  104. cf_by=''
  105. cf_time=''
  106. chgrp=''
  107. chmod=''
  108. chown=''
  109. clocktype=''
  110. comm='comm'
  111. compress=''
  112. contains=''
  113. cp='copy'
  114. cpio=''
  115. cpp='cl /E'
  116. cpp_stuff=''
  117. cpplast=''
  118. cppminus=''
  119. cpprun='cl /E'
  120. cppstdin='cl /E'
  121. cryptlib=''
  122. csh='cmd'
  123. date='date'
  124. db_hashtype='u_int32_t'
  125. db_prefixtype='size_t'
  126. defvoidused='15'
  127. direntrytype='struct dirent'
  128. dlext='pll'
  129. dlsrc='dl_win32.xs'
  130. echo='echo'
  131. egrep=''
  132. emacs=''
  133. eunicefix=':'
  134. expr=''
  135. find=''
  136. flex=''
  137. fpostype='fpos_t'
  138. freetype='void'
  139. full_csh=''
  140. full_sed=''
  141. gcc=''
  142. gccversion=''
  143. gidtype='gid_t'
  144. glibpth=''
  145. grep=''
  146. groupcat=''
  147. groupstype='gid_t'
  148. h_fcntl='false'
  149. h_sysfile=''
  150. hint='recommended'
  151. hostcat=''
  152. huge=''
  153. incpath=''
  154. inews=''
  155. installarchlib=''
  156. installbin=''
  157. installman1dir=''
  158. installman3dir=''
  159. installprivlib=''
  160. installscript=''
  161. installsitelib=''
  162. known_extensions=''
  163. ksh=''
  164. large=''
  165. ld='link32'
  166. lddlflags=''
  167. ldflags=''
  168. less=''
  169. libc=''
  170. libs=''
  171. libswanted=''
  172. line=''
  173. lint=''
  174. lkflags=''
  175. ln=''
  176. lns=''
  177. lp=''
  178. lpr=''
  179. ls='dir'
  180. lseektype='off_t'
  181. mail=''
  182. mailx=''
  183. make='nmake'
  184. mallocobj=''
  185. mallocsrc=''
  186. malloctype='void *'
  187. man1dir=''
  188. man1direxp=''
  189. man1ext=''
  190. man3dir=''
  191. man3direxp=''
  192. man3ext=''
  193. medium=''
  194. mips=''
  195. mips_type=''
  196. mkdir='mkdir'
  197. models='none'
  198. modetype='mode_t'
  199. more=''
  200. mv='rename'
  201. myarchname='i386-win32'
  202. mydomain=''
  203. myhostname=''
  204. myuname=''
  205. n=''
  206. nm_opt=''
  207. nroff=''
  208. optimize=''
  209. orderlib='false'
  210. package='perl5'
  211. passcat=''
  212. patchlevel='7'
  213. perl='perl'
  214. pg=''
  215. phostname='hostname'
  216. plibpth=''
  217. pmake=''
  218. pr=''
  219. prefix=''
  220. prefixexp=''
  221. privlib=''
  222. privlibexp=''
  223. prototype='define'
  224. randbits='15'
  225. ranlib=':'
  226. rm='del'
  227. rmail=''
  228. runnm='true'
  229. scriptdir=''
  230. scriptdirexp=''
  231. sed=''
  232. selecttype='fd_set *'
  233. sendmail=''
  234. sh=''
  235. shar=''
  236. shmattype='char *'
  237. shrpdir='none'
  238. signal_t='void'
  239. sitelib=''
  240. sitelibexp=''
  241. sizetype='size_t'
  242. sleep=''
  243. smail=''
  244. small=''
  245. sockethdr=''
  246. socketlib=''
  247. sort='sort'
  248. spackage='Perl5'
  249. spitshell='type'
  250. split=''
  251. ssizetype='ssize_t'
  252. stdchar='char'
  253. stdio_base='((fp)->_IO_read_base)'
  254. stdio_bufsiz='((fp)->_IO_read_end - (fp)->_IO_read_base)'
  255. stdio_cnt='((fp)->_IO_read_end - (fp)->_IO_read_ptr)'
  256. stdio_ptr='((fp)->_IO_read_ptr)'
  257. strings=''
  258. submit=''
  259. sysman=''
  260. tail=''
  261. tar=''
  262. tbl=''
  263. test='test'
  264. timeincl=''
  265. timetype='time_t'
  266. touch=''
  267. tr=''
  268. troff=''
  269. uidtype='uid_t'
  270. uname=''
  271. uniq=''
  272. usedl='define'
  273. usemymalloc='n'
  274. usenm='false'
  275. useposix='false'
  276. usevfork='false'
  277. usrinc=''
  278. uuname=''
  279. vi=''
  280. voidflags='15'
  281. xlibpth=''
  282. zcat=''
  283. !END!OF!CONFIG!
  284.  
  285.  
  286. tie %Config, Config;
  287. sub TIEHASH { bless {} }
  288. sub FETCH { 
  289.     # check for cached value (which maybe undef so we use exists not defined)
  290.     return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]});
  291.  
  292.     my($value); # search for the item in the big $config_sh string
  293.     return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m);
  294.  
  295.     $value = undef if $value eq 'undef'; # So we can say "if $Config{'foo'}".
  296.     $_[0]->{$_[1]} = $value; # cache it
  297.     return $value;
  298. }
  299.  
  300. sub FIRSTKEY {
  301.     $prevpos = 0;
  302.     my $key;
  303.     ($key) = $config_sh =~ m/^(.*)=/;
  304.     $key;
  305. }
  306.  
  307. sub NEXTKEY {
  308.     my ($pos, $len);
  309.     $pos = $prevpos;
  310.     $pos = index( $config_sh, "\n", $pos) + 1;
  311.     $prevpos = $pos;
  312.     $len = index( $config_sh, "=", $pos) - $pos;
  313.     $len > 0 ? substr( $config_sh, $pos, $len) : undef;
  314. }
  315.  
  316. sub EXISTS{ 
  317.      exists($_[0]->{$_[1]})  or  $config_sh =~ m/^$_[1]=/m; 
  318. }
  319.  
  320. sub readonly { die "\%Config::Config is read-only\n" }
  321.  
  322. sub myconfig {
  323.     my($output);
  324.     
  325.     $output = <<'END';
  326. Summary of my $package (patchlevel $PATCHLEVEL) configuration:
  327.   Platform:
  328.     osname=$osname, osver=$osvers, archname=$archname
  329.     uname='$myuname'
  330.     hint=$hint
  331.   Compiler:
  332.     cc='$cc', optimize='$optimize'
  333.     cppflags='$cppflags'
  334.     ccflags ='$ccflags'
  335.     ldflags ='$ldflags'
  336.     stdchar='$stdchar', d_stdstdio=$d_stdstdio, usevfork=$usevfork
  337.     voidflags=$voidflags, castflags=$castflags, d_casti32=$d_casti32, d_castneg=$d_castneg
  338.     intsize=$intsize, alignbytes=$alignbytes, usemymalloc=$usemymalloc, randbits=$randbits
  339.   Libraries:
  340.     so=$so
  341.     libpth=$libpth
  342.     libs=$libs
  343.     libc=$libc
  344.   Dynamic Linking:
  345.     dlsrc=$dlsrc, dlext=$dlext, d_dlsymun=$d_dlsymun
  346.     cccdlflags='$cccdlflags', ccdlflags='$ccdlflags', lddlflags='$lddlflags'
  347.  
  348. END
  349.     $output =~ s/\$(\w+)/$Config{$1}/ge;
  350.     $output;
  351. }
  352.  
  353. sub STORE { &readonly }
  354. sub DELETE{ &readonly }
  355. sub CLEAR { &readonly }
  356.  
  357.  
  358. 1;
  359.