misccomponents/emulatorlauncher/perl/eshell.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Eshell Launcher
       
    15 # Depends on the current working directory providing
       
    16 # the drive of the currently used SDK.
       
    17 # 
       
    18 #
       
    19 
       
    20 use Cwd;
       
    21 
       
    22 #
       
    23 # Check the argument(s), if any.
       
    24 #
       
    25 $numArgs = $#ARGV + 1;
       
    26 
       
    27 if($numArgs == 0) 
       
    28 	{
       
    29     	&launchEshell("udeb","winscw");
       
    30     	exit(0);
       
    31 	}
       
    32 
       
    33 if($numArgs > 2) 
       
    34 	{
       
    35     	&printHelp;
       
    36     	die "ERROR: Too many arguments.\n";
       
    37 	}
       
    38 
       
    39 if($numArgs == 1)
       
    40 	{ 
       
    41 	if(lc($ARGV[0]) eq "-rel") 
       
    42 		{
       
    43     		&launchEshell("urel","winscw");
       
    44     		exit(0);
       
    45 		}
       
    46 
       
    47 	if(lc($ARGV[0]) eq "-wins") 
       
    48 		{
       
    49     		&launchEshell("udeb", "wins");
       
    50     		exit(0);
       
    51 		}
       
    52 
       
    53 	if(lc($ARGV[0]) eq "-winscw") 
       
    54 		{
       
    55     		&launchEshell("udeb", "winscw");
       
    56     		exit(0);
       
    57 		}
       
    58 
       
    59 	if(lc($ARGV[0]) eq "-help") 
       
    60 		{
       
    61     		&printHelp;
       
    62     		exit(0);
       
    63 		}
       
    64 	}
       
    65 
       
    66 if ($numArgs == 2)
       
    67 	{
       
    68 	if(lc($ARGV[0]) eq "-rel") 
       
    69 		{
       
    70 		if (lc($ARGV[1]) eq "-wins")
       
    71 			{
       
    72     			&launchEshell("urel","wins");
       
    73     			exit(0);
       
    74 			}
       
    75 
       
    76 		if (lc($ARGV[1]) eq "-winscw")
       
    77 			{
       
    78     			&launchEshell("urel","winscw");
       
    79     			exit(0);
       
    80 			}
       
    81 		}	
       
    82 	
       
    83 	if (lc($ARGV[0]) eq "-winscw")
       
    84 		{
       
    85 		if (lc($ARGV[1] eq "-rel"))
       
    86 			{
       
    87 			&launchEshell("urel","winscw");
       
    88 			exit(0);	
       
    89 			}
       
    90 		}
       
    91 	
       
    92 	if (lc($ARGV[0]) eq "-wins")
       
    93 		{
       
    94 		if (lc($ARGV[1] eq "-rel"))
       
    95 			{
       
    96 			&launchEshell("urel","wins");
       
    97 			exit(0);	
       
    98 			}
       
    99 		}	
       
   100 	}
       
   101 
       
   102 # Error, unknown argument.
       
   103 &printHelp;
       
   104 die "ERROR: Unknown argument " . "\"" . $ARGV[0] . "\".\n";
       
   105 
       
   106 sub launchEshell
       
   107 {
       
   108     my ($type,$win) = @_;
       
   109     $epocroot = &getEpocroot;
       
   110     $drive = &getDrive;
       
   111     $emu = $drive . $epocroot . "epoc32" . "\\" 
       
   112 	. "release\\" . $win . "\\" . $type . "\\" . "eshell.exe";
       
   113     -e $emu ||
       
   114 	die "ERROR: File \"$emu\" not found.\n\n" .
       
   115 	    "The EPOCROOT environment variable does not identify\n" .
       
   116 	    "a valid eshell installation on this drive.\n" . 
       
   117 		"EPOCROOT must be an absolute path to an existing\n" .
       
   118 		    "directory - it should have no drive qualifier and\n" .
       
   119 			"must end with a backslash.\n";
       
   120 
       
   121 	#add the stuff to use the console
       
   122 	$emu.=" -MConsole --";
       
   123 			
       
   124     # If the execute is successful, this never returns.
       
   125     exec($emu) || die "Failed to execute eshell \"$emu\": $!";
       
   126 }
       
   127 
       
   128 sub printHelp
       
   129 {
       
   130     print "Eshell Launcher\n";
       
   131     print "Syntax :\teshell [-rel] [-wins|-winscw] [-help]\n";
       
   132     print "(no options)\tLaunch active winscw debug eshell\n";
       
   133     print "-rel\t\tLaunch active release eshell\n";
       
   134     print "-wins\t\tLaunch active wins eshell\n";
       
   135     print "-winscw\t\tLaunch active winscw eshell\n";
       
   136     print "-help\t\tOutput this help message\n";
       
   137 }
       
   138 
       
   139 #
       
   140 # Determines, validates, and returns EPOCROOT.
       
   141 #
       
   142 sub getEpocroot
       
   143 {
       
   144     my $epocroot = $ENV{EPOCROOT};
       
   145     die "ERROR: Must set the EPOCROOT environment variable.\n"
       
   146 	if (!defined($epocroot));
       
   147     $epocroot =~ s-/-\\-go;	# for those working with UNIX shells
       
   148     die "ERROR: EPOCROOT must be an absolute path, " .
       
   149 	"not containing a drive letter.\n" if ($epocroot !~ /^\\/);
       
   150     die "ERROR: EPOCROOT must not be a UNC path.\n" if ($epocroot =~ /^\\\\/);
       
   151     die "ERROR: EPOCROOT must end with a backslash.\n" if ($epocroot !~ /\\$/);
       
   152     die "ERROR: EPOCROOT must specify an existing directory.\n" 
       
   153 	if (!-d $epocroot);
       
   154     return $epocroot;
       
   155 }
       
   156 
       
   157 #
       
   158 # Determines and returns the current drive, if any.
       
   159 #
       
   160 sub getDrive
       
   161 {
       
   162     my $wd = cwd;
       
   163     if($wd =~ /^([a-zA-Z]:)/) {
       
   164 	$drive = $1;
       
   165     } else {
       
   166 	# Perhaps we're on a machine that has no drives.
       
   167 	$drive = "";
       
   168     }
       
   169     return $drive;
       
   170 }