Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | ##---------------------------------------------------------------------------## |
2 | ## File: | |
3 | ## $Id: osinit.pl,v 2.6 2001/09/17 16:09:27 ehood Exp $ | |
4 | ## Author: | |
5 | ## Earl Hood mhonarc@mhonarc.org | |
6 | ## Description: | |
7 | ## A library for setting up a script based upon the OS the script | |
8 | ## is running under. The main routine defined is OSinit. See | |
9 | ## the routine for specific information. | |
10 | ##---------------------------------------------------------------------------## | |
11 | ## MHonArc -- Internet mail-to-HTML converter | |
12 | ## Copyright (C) 1995-1999 Earl Hood, mhonarc@mhonarc.org | |
13 | ## | |
14 | ## This program is free software; you can redistribute it and/or modify | |
15 | ## it under the terms of the GNU General Public License as published by | |
16 | ## the Free Software Foundation; either version 2 of the License, or | |
17 | ## (at your option) any later version. | |
18 | ## | |
19 | ## This program is distributed in the hope that it will be useful, | |
20 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | ## GNU General Public License for more details. | |
23 | ## | |
24 | ## You should have received a copy of the GNU General Public License | |
25 | ## along with this program; if not, write to the Free Software | |
26 | ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
27 | ## 02111-1307, USA | |
28 | ##---------------------------------------------------------------------------## | |
29 | ||
30 | package mhonarc; | |
31 | ||
32 | ##---------------------------------------------------------------------------## | |
33 | ## OSinit() checks what operating system we are running on set | |
34 | ## some global variables that can be used by the calling routine. | |
35 | ## All global variables are exported to package main. | |
36 | ## | |
37 | ## Variables set: | |
38 | ## | |
39 | ## $MSDOS => Set to 1 if running under MS-DOS/Windows | |
40 | ## $MACOS => Set to 1 if running under Mac | |
41 | ## $UNIX => Set to 1 if running under Unix | |
42 | ## $VMS => Set to 1 if running under VMS | |
43 | ## $DIRSEP => Directory separator character | |
44 | ## $DIRSEPREX => Directory separator character for use in | |
45 | ## regular expressions. | |
46 | ## $PATHSEP => Recommend path list separator | |
47 | ## $CURDIR => Current working directory | |
48 | ## $PROG => Program name with leading pathname component | |
49 | ## stripped off. | |
50 | ## | |
51 | ## If running under a Mac and the script is a droplet, command-line | |
52 | ## options will be prompted for unless $noOptions argument is | |
53 | ## set to true. | |
54 | ## | |
55 | sub OSinit { | |
56 | my($noOptions) = shift; | |
57 | ||
58 | ## Check what system we are executing under | |
59 | my($tmp); | |
60 | if ($^O =~ /vms/i) { | |
61 | $MSDOS = 0; $MACOS = 0; $UNIX = 0; $VMS = 1; | |
62 | $DIRSEP = '/'; $CURDIR = '.'; | |
63 | $PATHSEP = ':'; | |
64 | ||
65 | } elsif (($^O !~ /cygwin/i) && | |
66 | (($^O =~ /mswin/i) || | |
67 | ($^O =~ /\bdos\b/i) || | |
68 | ($^O =~ /\bos2\b/i) || | |
69 | (($tmp = $ENV{'COMSPEC'}) && | |
70 | ($tmp =~ /^[a-zA-Z]:\\/) && | |
71 | (-e $tmp))) ) { | |
72 | $MSDOS = 1; $MACOS = 0; $UNIX = 0; $VMS = 0; | |
73 | $DIRSEP = '\\'; $CURDIR = '.'; | |
74 | $PATHSEP = ';'; | |
75 | ||
76 | } elsif (defined($MacPerl::Version)) { | |
77 | $MSDOS = 0; $MACOS = 1; $UNIX = 0; $VMS = 0; | |
78 | $DIRSEP = ':'; $CURDIR = ':'; | |
79 | $PATHSEP = ';'; | |
80 | ||
81 | } else { | |
82 | $MSDOS = 0; $MACOS = 0; $UNIX = 1; $VMS = 0; | |
83 | $DIRSEP = '/'; $CURDIR = '.'; | |
84 | $PATHSEP = ':'; | |
85 | } | |
86 | ||
87 | ## Store name of program | |
88 | if ($MSDOS) { | |
89 | $DIRSEPREX = "\\\\\\/"; | |
90 | } else { | |
91 | ($DIRSEPREX = $DIRSEP) =~ s/(\W)/\\$1/g; | |
92 | } | |
93 | ($PROG = $0) =~ s%.*[$DIRSEPREX]%%o; | |
94 | ||
95 | ## Ask for command-line options if script is a Mac droplet | |
96 | ## Code taken from the MacPerl FAQ | |
97 | if (!$noOptions && | |
98 | defined($MacPerl::Version) && | |
99 | ( $MacPerl::Version =~ /Application$/ )) { | |
100 | ||
101 | # we're running from the app | |
102 | local( $cmdLine, @args ); | |
103 | $cmdLine = &MacPerl::Ask( "Enter command line options:" ); | |
104 | require "shellwords.pl"; | |
105 | @args = &shellwords( $cmdLine ); | |
106 | unshift( @ARGV, @args ); | |
107 | } | |
108 | } | |
109 | ||
110 | ##---------------------------------------------------------------------------## | |
111 | ## OSis_absolute_path() returns true if a string is an absolute path | |
112 | ## | |
113 | sub OSis_absolute_path { | |
114 | ||
115 | if ($MSDOS) { | |
116 | return $_[0] =~ /^([a-z]:)?[\\\/]/i; | |
117 | } | |
118 | if ($MACOS) { ## Not sure about Mac | |
119 | return $_[0] =~ /^:/o; | |
120 | } | |
121 | $_[0] =~ m|^/|o; ## Unix (fallback) | |
122 | } | |
123 | ||
124 | ##---------------------------------------------------------------------------## | |
125 | 1; |