Vous êtes sur la page 1sur 81

/*

* %W% %E%
*
* Copyright (c) 2006, 2008, Oracle and/or its affiliates !ll rights reser"ed
O#!C$E %#O%#&E'!#(/CO)*&+E)'&!$
,se is s-./ect to license ter0s
+1s212sf
1sfa21fs21
'his si
/*
* %W% %E%
*
* Copyright (c) 2006, 2008, Oracle and/or its affiliates !ll rights reser"ed
* O#!C$E %#O%#&E'!#(/CO)*&+E)'&!$ ,se is s-./ect to license ter0s
*/
/*
* 3hared so-rce for 4/a"a4 co00and line tool
*
* &f 5!6!7!#83 is defined, then acts as a la-ncher for applications *or
* instance, the 5+9 co00and line tools s-ch as /a"ac and /a"adoc (see
* 0a2efiles for 0ore details) are .-ilt :ith this progra0 !ny arg-0ents
* prefi;ed :ith 4<54 :ill .e passed directly to the 4/a"a4 co00and
*/
/*
* One /o. of the la-ncher is to re0o"e co00and line options :hich the
* "0 does not -nderstand and :ill not process 'hese options incl-de
* options :hich select :hich style of "0 is r-n (eg <client and
* <ser"er) as :ell as options :hich select the data 0odel to -se
* !dditionally, for tools :hich in"o2e an -nderlying "0 =<5<foo=
* options are t-rned into =<foo= options to the "0 'his option
* filtering is handled in a n-0.er of places in the la-ncher, so0e of
* it in 0achine<dependent code &n this file, the f-nction
* Chec256>'ype re0o"es "0 style options and 'ranslate!pplication!rgs
* re0o"es =<5= prefi;es On -ni; platfor0s, the
* CreateE;ec-tionEn"iron0ent f-nction fro0 the -ni; /a"a70dc file
* processes and re0o"es <d?n@ options Ao:e"er, in case
* CreateE;ec-tionEn"iron0ent does not need to e;ec .eca-se
* $+7$&B#!#(7%!'A is set accepta.ly and the data 0odel does not need
* to .e changed, %arse!rg-0ents :ill screen o-t the red-ndant <d?n@
* options and pre"ent the0 fro0 .eing passed to the "01 this is done
* .y -sing the 0achine<dependent call
* #e0o"a.le>achine+ependentOption
*/
Cincl-de ?stdioh@
Cincl-de ?stdli.h@
Cincl-de ?stringh@
Cincl-de ?/nih@
Cincl-de ?/"0h@
Cincl-de =/a"ah=
Cincl-de =0anifest7infoh=
Cincl-de ="ersion7co0ph=
Cincl-de =:ildcardh=
Cincl-de =splashscreenh=
Cifndef *,$$76E#3&O)
Cdefine *,$$76E#3&O) 5+97>!5O#76E#3&O) == 5+97>&)O#76E#3&O)
Cendif
/*
* 'he follo:ing en"iron0ent "aria.le is -sed to infl-ence the .eha"ior
* of the /re e;ec4d thro-gh the 3elect6ersion ro-tine 'he co00and line
* options :hich specify the "ersion are not passed to the e;ec4d "ersion,
* .eca-se that /re 0ay .e an older "ersion :hich :o-ldn4t recogniDe the0
* 'his en"iron0ent "aria.le is 2no:n to this (and later) "ersion and ser"es
* to s-ppress the "ersion selection code 'his is not only for efficiency,
* .-t also for correctness, since any co00and line options ha"e .een
* re0o"ed :hich :o-ld ca-se any "al-e fo-nd in the 0anifest to .e -sed
* 'his :o-ld .e incorrect .eca-se the co00and line options are defined
* to ta2e precedence
*
* 'he "al-e associated :ith this en"iron0ent "aria.le is the >ainClass
* na0e fro0 :ithin the e;ec-ta.le /ar file (if any) 'his is strictly a
* perfor0ance enhance0ent to a"oid re<reading the /ar file 0anifest
*
* ! )O'E 'O +E6E$O%E#3E *or perfor0ance reasons it is i0portant that
* the progra0 i0age re0ain relati"ely s0all -ntil after 3elect6ersion
* CreateE;ec-tionEn"iron0ent ha"e finished their possi.ly rec-rsi"e
* processing Watch e"erything, .-t resist all te0ptations to -se 5a"a
* interfaces
*/
Cdefine E)67E)'#( =75!6!76E#3&O)73E'=
Cdefine 3%$!3A7*&$E7E)67E)'#( =75!6!73%$!3A7*&$E=
Cdefine 3%$!3A75!#7E)67E)'#( =75!6!73%$!3A75!#=
static /.oolean print6ersion F 5)&7*!$3E1 /* print and e;it */
static /.oolean sho:6ersion F 5)&7*!$3E1 /* print .-t contin-e */
static char *progna0e1
/.oolean 7la-ncher7de.-g F 5)&7*!$3E1
/*
* Entries for splash screen en"iron0ent "aria.les
* p-ten" is perfor0ed in 3elect6ersion We need
* the0 in 0e0ory -ntil ,nsetEn", so they are 0ade static
* glo.al instead of a-to local
*/
static char* splash7file7entry F ),$$1
static char* splash7/ar7entry F ),$$1
/*
* $ist of 6> options to .e specified :hen the 6> is created
*/
static 5a"a6>Option *options1
static int n-0Options, 0a;Options1
/*
* %rototypes for f-nctions internal to la-ncher
*/
static "oid 3etClass%ath(const char *s)1
static "oid 3elect6ersion(int argc, char **arg", char **0ain7class)1
static /.oolean %arse!rg-0ents(int *pargc, char ***parg", char **p/arfile,
char **pclassna0e, int *pret, const char */"0path)1
static /.oolean &nitialiDe56>(5a"a6> **p"0, 5)&En" **pen",
&n"ocation*-nctions *ifn)1
static /string )e:%latfor03tring(5)&En" *en", char *s)1
static /o./ect!rray )e:%latfor03tring!rray(5)&En" *en", char **str", int strc)1
static /class $oadClass(5)&En" *en", char *na0e)1
static /string 8et>ainClass)a0e(5)&En" *en", char */arna0e)1
static "oid 3et5a"aCo00and$ine%rop(char* classna0e, char* /arfile, int argc, char** arg")1
static "oid 3et5a"a$a-ncher%rop("oid)1
Cifdef 5!6!7!#83
static "oid 'ranslate!pplication!rgs(int *pargc, char ***parg")1
static /.oolean !dd!pplicationOptions("oid)1
Cendif
static "oid %rint5a"a6ersion(5)&En" *en")1
static "oid %rint,sage("oid)1
static /int %rintG,sage(const char */"0path)1
static "oid 3et%aths(int argc, char **arg")1
/* >a;i0-0 s-pported entries fro0 /"0cfg */
Cdefine &)&'7>!G79)OW)76>3 H0
/* 6al-es for "0descflag */
Cdefine 6>7,)9)OW) <H
Cdefine 6>79)OW) 0
Cdefine 6>7!$&!3E+7'O H
Cdefine 6>7W!#) 2
Cdefine 6>7E##O# I
Cdefine 6>7&*73E#6E#7C$!33 J
Cdefine 6>7&8)O#E K
str-ct "0desc L
char *na0e1
int flag1
char *alias1
char *ser"er7class1
M1
static str-ct "0desc *2no:n6>s F ),$$1
static int 2no:n6>sCo-nt F 01
static int 2no:n6>s$i0it F 01
static "oid 8ro:9no:n6>s()1
static int 9no:n6>&nde;(const char* na0e)1
static "oid *ree9no:n6>s()1
static "oid 3ho:3plash3creen()1
/.oolean 3er"erClass>achine()1
/* flag :hich if set s-ppresses error 0essages fro0 the la-ncher */
static int noE;itError>essage F 01
/*
* #-nning 5a"a code in pri0ordial thread ca-sed 0any pro.le0s We :ill
* create a ne: thread to in"o2e 56> 3ee 6IH6HNO for 0ore infor0ation
*/
static /long thread3tac23iDe F 01 /* stac2 siDe of the ne: thread */
int 5)&C!$$ 5a"a>ain("oid * args)1 /* entry point */
str-ct 5a"a>ain!rgs L
int argc1
char ** arg"1
char * /arfile1
char * classna0e1
&n"ocation*-nctions ifn1
M1
/*
* Entry point
*/
int
0ain(int argc, char ** arg")
L
char */arfile F 01
char *classna0e F 01
char *s F 01
char *0ain7class F ),$$1
int ret1
&n"ocation*-nctions ifn1
/long start, end1
char /repathP>!G%!'A$E)Q, /"0pathP>!G%!'A$E)Q1
char ** original7arg" F arg"1
if (geten"(=75!6!7$!,)CAE#7+EB,8=) RF 0) L
7la-ncher7de.-g F 5)&7'#,E1
printf(=<<<<75!6!7$!,)CAE#7+EB,8<<<<Sn=)1
M
/*
* >a2e s-re the specified "ersion of the 5#E is r-nning
*
* 'here are three things to note a.o-t the 3elect6ersion() ro-tineE
* H) &f the "ersion r-nning isn4t correct, this ro-tine doesn4t
* ret-rn (either the correct "ersion has .een e;ec4d or an error
* :as iss-ed)
* 2) !rgc and !rg" in this scope are *not* altered .y this ro-tine
* &t is the responsi.ility of s-.seT-ent code to ignore the
* arg-0ents handled .y this ro-tine
* I) !s a side<effect, the "aria.le =0ain7class= is g-aranteed to
* .e set (if it sho-ld e"er .e set) 'his isn4t e;actly the
* poster child for str-ct-red progra00ing, .-t it is a s0all
* price to pay for not processing a /ar file operand t:ice
* ()oteE 'his side effect has .een disa.led 3ee co00ent on
* .-gid K0I026K .elo:)
*/
3elect6ersion(argc, arg", U0ain7class)1
/* copy original arg" */
L
int i1
original7arg" F (char**)5$&7>e0!lloc(siDeof(char*)*(argcVH))1
for(i F 01 i ? argcVH1 iVV)
original7arg"PiQ F arg"PiQ1
M
CreateE;ec-tionEn"iron0ent(Uargc, Uarg",
/repath, siDeof(/repath),
/"0path, siDeof(/"0path),
original7arg")1
ifnCreate5a"a6> F 01
ifn8et+efa-lt5a"a6>&nit!rgs F 01
if (7la-ncher7de.-g)
start F Co-nter8et()1
if (R$oad5a"a6>(/"0path, Uifn)) L
e;it(6)1
M
if (7la-ncher7de.-g) L
end F Co-nter8et()1
printf(=%ld 0icro seconds to $oad5a"a6>Sn=,
(long)(/int)Co-nter2>icros(end<start))1
M
Cifdef 5!6!7!#83 /* /a"ac, /ar and friends */
progna0e F =/a"a=1
Celse /* /a"a, old/a"a, /a"a: and friends */
Cifdef %#O8)!>E
progna0e F %#O8)!>E1
Celse
progna0e F *arg"1
if ((s F strrchr(progna0e, *&$E73E%!#!'O#)) RF 0) L
progna0e F s V H1
M
Cendif /* %#O8)!>E */
Cendif /* 5!6!7!#83 */
VVarg"1
<<argc1
Cifdef 5!6!7!#83
/* %reprocess :rapper arg-0ents */
'ranslate!pplication!rgs(Uargc, Uarg")1
if (R!dd!pplicationOptions()) L
e;it(H)1
M
Cendif
/* 3et defa-lt C$!33%!'A */
if ((s F geten"(=C$!33%!'A=)) FF 0) L
s F ==1
M
Cifndef 5!6!7!#83
3etClass%ath(s)1
Cendif
/*
* %arse co00and line options1 if the ret-rn "al-e of
* %arse!rg-0ents is false, the progra0 sho-ld e;it
*/
if (R%arse!rg-0ents(Uargc, Uarg", U/arfile, Uclassna0e, Uret, /"0path)) L
e;it(ret)1
M
/* O"erride class path if </ar flag :as specified */
if (/arfile RF 0) L
3etClass%ath(/arfile)1
M
/* set the <+s-n/a"aco00and pse-do property */
3et5a"aCo00and$ine%rop(classna0e, /arfile, argc, arg")1
/* 3et the <+s-n/a"ala-ncher pse-do property */
3et5a"a$a-ncher%rop()1
/* set the <+s-n/a"ala-ncher* platfor0 properties */
3et5a"a$a-ncher%latfor0%rops()1
/* 3ho: the splash screen if needed */
3ho:3plash3creen()1
/*
* +one :ith all co00and line processing and potential re<e;ecs so
* clean -p the en"iron0ent
*/
("oid),nsetEn"(E)67E)'#()1
("oid),nsetEn"(3%$!3A7*&$E7E)67E)'#()1
("oid),nsetEn"(3%$!3A75!#7E)67E)'#()1
5$&7>e0*ree(splash7/ar7entry)1
5$&7>e0*ree(splash7file7entry)1
/*
* &f -ser doesn4t specify stac2 siDe, chec2 if 6> has a preference
* )ote that Aot3pot no longer s-pports 5)&76E#3&O)7H7H .-t it :ill
* ret-rn its defa-lt stac2 siDe thro-gh the init args str-ct-re
*/
if (thread3tac23iDe FF 0) L
str-ct 5+9H7H&nit!rgs argsH7H1
0e0set(("oid*)UargsH7H, 0, siDeof(argsH7H))1
argsH7H"ersion F 5)&76E#3&O)7H7H1
ifn8et+efa-lt5a"a6>&nit!rgs(UargsH7H)1 /* ignore ret-rn "al-e */
if (argsH7H/a"a3tac23iDe @ 0) L
thread3tac23iDe F argsH7H/a"a3tac23iDe1
M
M
L /* Create a ne: thread to create 56> and in"o2e 0ain 0ethod */
str-ct 5a"a>ain!rgs args1
argsargc F argc1
argsarg" F arg"1
args/arfile F /arfile1
argsclassna0e F classna0e1
argsifn F ifn1
ret-rn Contin-e&n)e:'hread(5a"a>ain, thread3tac23iDe, ("oid*)Uargs)1
M
M
int 5)&C!$$
5a"a>ain("oid * 7args)
L
str-ct 5a"a>ain!rgs *args F (str-ct 5a"a>ain!rgs *)7args1
int argc F args<@argc1
char **arg" F args<@arg"1
char */arfile F args<@/arfile1
char *classna0e F args<@classna0e1
&n"ocation*-nctions ifn F args<@ifn1
5a"a6> *"0 F 01
5)&En" *en" F 01
/string 0ainClass)a0e1
/class 0ainClass1
/0ethod&+ 0ain&+1
/o./ect!rray 0ain!rgs1
int ret F 01
/long start, end1
/*
* Error 0essage to print or display1 .y defa-lt the 0essage :ill
* only .e displayed in a :indo:
*/
char * 0essage F =*atal e;ception occ-rred %rogra0 :ill e;it=1
/.oolean 0essage+est F 5)&7*!$3E1
/* &nitialiDe the "irt-al 0achine */
if (7la-ncher7de.-g)
start F Co-nter8et()1
if (R&nitialiDe56>(U"0, Uen", Uifn)) L
#eportError>essage(=Co-ld not create the 5a"a "irt-al 0achine=,
5)&7'#,E)1
e;it(H)1
M
if (print6ersion WW sho:6ersion) L
%rint5a"a6ersion(en")1
if ((*en")<@E;ceptionOcc-rred(en")) L
#eportE;ception+escription(en")1
goto lea"e1
M
if (print6ersion) L
ret F 01
0essage F ),$$1
goto lea"e1
M
if (sho:6ersion) L
fprintf(stderr, =Sn=)1
M
M
/* &f the -ser specified neither a class na0e nor a 5!# file */
if (/arfile FF 0 UU classna0e FF 0) L
%rint,sage()1
0essage F ),$$1
goto lea"e1
M
*ree9no:n6>s()1 /* after last possi.le %rint,sage() */
if (7la-ncher7de.-g) L
end F Co-nter8et()1
printf(=%ld 0icro seconds to &nitialiDe56>Sn=,
(long)(/int)Co-nter2>icros(end<start))1
M
/* !t this stage, argc/arg" ha"e the applications4 arg-0ents */
if (7la-ncher7de.-g) L
int i F 01
printf(=>ain<Class is 4%s4Sn=, classna0e X classna0e E ==)1
printf(=!pps4 argc is %dSn=, argc)1
for (1 i ? argc1 iVV) L
printf(= arg"P%2dQ F 4%s4Sn=, i, arg"PiQ)1
M
M
ret F H1
/*
* 8et the application4s 0ain class
*
* 3ee .-gid K0I026K 'he >ain<Class na0e has already .een parsed
* fro0 the 0anifest, .-t not parsed properly for ,'*<8 s-pport
* Aence the code here ignores the "al-e pre"io-sly e;tracted and
* -ses the pre<e;isting code to ree;tract the "al-e 'his is
* possi.ly an end of release cycle e;pedient Ao:e"er, it has
* also .een disco"ered that passing so0e character sets thro-gh
* the en"iron0ent has =strange= .eha"ior on so0e "ariants of
* Windo:s Aence, 0ay.e the 0anifest parsing code local to the
* la-ncher sho-ld ne"er .e enhanced
*
* Aence, f-t-re :or2 sho-ld eitherE
* H) Correct the local parsing code and "erify that the
* >ain<Class attri.-te gets properly passed thro-gh
* all en"iron0ents,
* 2) #e0o"e the "estages of 0aintaining 0ain7class thro-gh
* the en"iron0ent (and re0o"e these co00ents)
*/
if (/arfile RF 0) L
0ainClass)a0e F 8et>ainClass)a0e(en", /arfile)1
if ((*en")<@E;ceptionOcc-rred(en")) L
#eportE;ception+escription(en")1
goto lea"e1
M
if (0ainClass)a0e FF ),$$) L
const char * for0at F =*ailed to load >ain<Class 0anifest =
=attri.-te fro0Sn%s=1
0essage F (char*)5$&7>e0!lloc((strlen(for0at) V strlen(/arfile)) *
siDeof(char))1
sprintf(0essage, for0at, /arfile)1
0essage+est F 5)&7'#,E1
goto lea"e1
M
classna0e F (char *)(*en")<@8et3tring,'*Chars(en", 0ainClass)a0e, 0)1
if (classna0e FF ),$$) L
#eportE;ception+escription(en")1
goto lea"e1
M
0ainClass F $oadClass(en", classna0e)1
if(0ainClass FF ),$$) L /* e;ception occ-red */
const char * for0at F =Co-ld not find the 0ain classE %s %rogra0 :ill e;it=1
#eportE;ception+escription(en")1
0essage F (char *)5$&7>e0!lloc((strlen(for0at) V
strlen(classna0e)) * siDeof(char) )1
0essage+est F 5)&7'#,E1
sprintf(0essage, for0at, classna0e)1
goto lea"e1
M
(*en")<@#elease3tring,'*Chars(en", 0ainClass)a0e, classna0e)1
M else L
0ainClass)a0e F )e:%latfor03tring(en", classna0e)1
if (0ainClass)a0e FF ),$$) L
const char * for0at F =*ailed to load >ain ClassE %s=1
0essage F (char *)5$&7>e0!lloc((strlen(for0at) V strlen(classna0e)) *
siDeof(char) )1
sprintf(0essage, for0at, classna0e)1
0essage+est F 5)&7'#,E1
goto lea"e1
M
classna0e F (char *)(*en")<@8et3tring,'*Chars(en", 0ainClass)a0e, 0)1
if (classna0e FF ),$$) L
#eportE;ception+escription(en")1
goto lea"e1
M
0ainClass F $oadClass(en", classna0e)1
if(0ainClass FF ),$$) L /* e;ception occ-red */
const char * for0at F =Co-ld not find the 0ain classE %s %rogra0 :ill e;it=1
#eportE;ception+escription(en")1
0essage F (char *)5$&7>e0!lloc((strlen(for0at) V
strlen(classna0e)) * siDeof(char) )1
0essage+est F 5)&7'#,E1
sprintf(0essage, for0at, classna0e)1
goto lea"e1
M
(*en")<@#elease3tring,'*Chars(en", 0ainClass)a0e, classna0e)1
M
/* 8et the application4s 0ain 0ethod */
0ain&+ F (*en")<@8et3tatic>ethod&+(en", 0ainClass, =0ain=,
=(P$/a"a/lang/3tring1)6=)1
if (0ain&+ FF ),$$) L
if ((*en")<@E;ceptionOcc-rred(en")) L
#eportE;ception+escription(en")1
M else L
0essage F =)o 0ain 0ethod fo-nd in specified class=1
0essage+est F 5)&7'#,E1
M
goto lea"e1
M
L /* >a2e s-re the 0ain 0ethod is p-.lic */
/int 0ods1
/0ethod&+ 0id1
/o./ect o./ F (*en")<@'o#eflected>ethod(en", 0ainClass,
0ain&+, 5)&7'#,E)1
if( o./ FF ),$$) L /* e;ception occ-rred */
#eportE;ception+escription(en")1
goto lea"e1
M
0id F
(*en")<@8et>ethod&+(en",
(*en")<@8etO./ectClass(en", o./),
=get>odifiers=, =()&=)1
if ((*en")<@E;ceptionOcc-rred(en")) L
#eportE;ception+escription(en")1
goto lea"e1
M
0ods F (*en")<@Call&nt>ethod(en", o./, 0id)1
if ((0ods U H) FF 0) L /* if (R>odifieris%-.lic(0ods)) */
0essage F =>ain 0ethod not p-.lic=1
0essage+est F 5)&7'#,E1
goto lea"e1
M
M
/* B-ild arg-0ent array */
0ain!rgs F )e:%latfor03tring!rray(en", arg", argc)1
if (0ain!rgs FF ),$$) L
#eportE;ception+escription(en")1
goto lea"e1
M
/* &n"o2e 0ain 0ethod */
(*en")<@Call3tatic6oid>ethod(en", 0ainClass, 0ain&+, 0ain!rgs)1
/*
* 'he la-ncher4s e;it code (in the a.sence of calls to
* 3yste0e;it) :ill .e non<Dero if 0ain thre: an e;ception
*/
ret F (*en")<@E;ceptionOcc-rred(en") FF ),$$ X 0 E H1
/*
* +etach the 0ain thread so that it appears to ha"e ended :hen
* the application4s 0ain 0ethod e;its 'his :ill in"o2e the
* -nca-ght e;ception handler 0achinery if 0ain thre: an
* e;ception !n -nca-ght e;ception handler cannot change the
* la-ncher4s ret-rn code e;cept .y calling 3yste0e;it
*/
if ((*"0)<@+etachC-rrent'hread("0) RF 0) L
0essage F =Co-ld not detach 0ain thread=1
0essage+est F 5)&7'#,E1
ret F H1
goto lea"e1
M
0essage F ),$$1
lea"eE
/*
* Wait for all non<dae0on threads to end, then destroy the 6>
* 'his :ill act-ally create a tri"ial ne: 5a"a :aiter thread
* na0ed =+estroy5a"a6>=, .-t this :ill .e seen as a different
* thread fro0 the one that e;ec-ted 0ain, e"en tho-gh they are
* the sa0e C thread 'his allo:s 0ain'hread/oin() and
* 0ain'hreadis!li"e() to :or2 as e;pected
*/
(*"0)<@+estroy5a"a6>("0)1
if(0essage RF ),$$ UU RnoE;itError>essage)
#eportError>essage(0essage, 0essage+est)1
ret-rn ret1
M
/*
* Chec2s the co00and line options to find :hich 56> type :as
* specified &f no co00and line option :as gi"en for the 56> type,
* the defa-lt type is -sed 'he en"iron0ent "aria.le
* 5+97!$'E#)!'E76> and the co00and line option <GGalt/"0F are also
* chec2ed as :ays of specifying :hich 56> type to in"o2e
*/
char *
Chec25"0'ype(int *pargc, char ***arg", /.oolean spec-lati"e) L
int i, argi1
int argc1
char **ne:!rg"1
int ne:!rg"&d; F 01
int is6>'ype1
int /"0id; F <H1
char */"0type F geten"(=5+97!$'E#)!'E76>=)1
argc F *pargc1
/* 'o 0a2e things si0pler :e al:ays copy the arg" array */
ne:!rg" F 5$&7>e0!lloc((argc V H) * siDeof(char *))1
/* 'he progra0 na0e is al:ays present */
ne:!rg"Pne:!rg"&d;VVQ F (*arg")P0Q1
for (argi F H1 argi ? argc1 argiVV) L
char *arg F (*arg")PargiQ1
is6>'ype F 01
Cifdef 5!6!7!#83
if (argP0Q RF 4<4) L
ne:!rg"Pne:!rg"&d;VVQ F arg1
contin-e1
M
Celse
if (strc0p(arg, =<classpath=) FF 0 WW
strc0p(arg, =<cp=) FF 0) L
ne:!rg"Pne:!rg"&d;VVQ F arg1
argiVV1
if (argi ? argc) L
ne:!rg"Pne:!rg"&d;VVQ F (*arg")PargiQ1
M
contin-e1
M
if (argP0Q RF 4<4) .rea21
Cendif
/* +id the -ser pass an e;plicit 6> typeX */
i F 9no:n6>&nde;(arg)1
if (i @F 0) L
/"0type F 2no:n6>sP/"0id; F iQna0e V H1 /* s2ip the < */
is6>'ype F H1
*pargc F *pargc < H1
M
/* +id the -ser specify an =alternate= 6>X */
else if (strnc0p(arg, =<GGalt/"0F=, H0) FF 0 WW strnc0p(arg, =<5<GGalt/"0F=, H2) FF 0) L
is6>'ype F H1
/"0type F argV((argPHQFF4G4)X H0 E H2)1
/"0id; F <H1
M
if (Ris6>'ype) L
ne:!rg"Pne:!rg"&d;VVQ F arg1
M
M
/*
* *inish copying the arg-0ents if :e a.orted the a.o"e loop
* )O'E that if :e a.orted "ia =.rea2= then :e did )O' copy the
* last arg-0ent a.o"e, and in addition argi :ill .e less than
* argc
*/
:hile (argi ? argc) L
ne:!rg"Pne:!rg"&d;VVQ F (*arg")PargiQ1
argiVV1
M
/* arg" is n-ll<ter0inated */
ne:!rg"Pne:!rg"&d;Q F 01
/* Copy .ac2 arg" */
*arg" F ne:!rg"1
*pargc F ne:!rg"&d;1
/* -se the defa-lt 6> type if not specified (no alias processing) */
if (/"0type FF ),$$) L
char* res-lt F 2no:n6>sP0Qna0eVH1
/* ,se a different 6> type if :e are on a ser"er class 0achineX */
if ((2no:n6>sP0Qflag FF 6>7&*73E#6E#7C$!33) UU
(3er"erClass>achine() FF 5)&7'#,E)) L
res-lt F 2no:n6>sP0Qser"er7classVH1
M
if (7la-ncher7de.-g) L
printf(=+efa-lt 6>E %sSn=, res-lt)1
M
ret-rn res-lt1
M
/* if -sing an alternate 6>, no alias processing */
if (/"0id; ? 0)
ret-rn /"0type1
/* #esol"e aliases first */
L
int loopCo-nt F 01
:hile (2no:n6>sP/"0id;Qflag FF 6>7!$&!3E+7'O) L
int ne;t&d; F 9no:n6>&nde;(2no:n6>sP/"0id;Qalias)1
if (loopCo-nt @ 2no:n6>sCo-nt) L
if (Rspec-lati"e) L
#eportError>essage(=ErrorE Corr-pt /"0cfg file1 cycle in alias list=,
5)&7'#,E)1
e;it(H)1
M else L
ret-rn =E##O#=1
/* .rea21 */
M
M
if (ne;t&d; ? 0) L
if (Rspec-lati"e) L
#eportError>essage2(=ErrorE ,na.le to resol"e 6> alias %s=,
2no:n6>sP/"0id;Qalias, 5)&7'#,E)1
e;it(H)1
M else L
ret-rn =E##O#=1
M
M
/"0id; F ne;t&d;1
/"0type F 2no:n6>sP/"0id;Qna0eVH1
loopCo-ntVV1
M
M
s:itch (2no:n6>sP/"0id;Qflag) L
case 6>7W!#)E
if (Rspec-lati"e) L
fprintf(stderr, =WarningE %s 6> not s-pported1 %s 6> :ill .e -sedSn=,
/"0type, 2no:n6>sP0Qna0e V H)1
M
/* fall thro-gh */
case 6>7&8)O#EE
/"0type F 2no:n6>sP/"0id;F0Qna0e V H1
/* fall thro-gh */
case 6>79)OW)E
.rea21
case 6>7E##O#E
if (Rspec-lati"e) L
#eportError>essage2(=ErrorE %s 6> not s-pported=, /"0type, 5)&7'#,E)1
e;it(H)1
M else L
ret-rn =E##O#=1
M
M
ret-rn /"0type1
M
C define 9B (H02J,$)
C define >B (H02J,$ * 9B)
C define 8B (H02J,$ * >B)
/* copied fro0 Aot3pot f-nction =ato0ll()= */
static int
parse7stac27siDe(const char *s, /long *res-lt) L
/long n F 01
int args7read F sscanf(s, /long7for0at7specifier(), Un)1
if (args7read RF H) L
ret-rn 01
M
:hile (*s RF 4S04 UU *s @F 404 UU *s ?F 4N4) L
sVV1
M
// JO0KKJ0E illegal if 0ore characters are fo-nd after the first non<digit
if (strlen(s) @ H) L
ret-rn 01
M
s:itch (*s) L
case 4'4E case 4t4E
*res-lt F n * 8B * 9B1
ret-rn H1
case 484E case 4g4E
*res-lt F n * 8B1
ret-rn H1
case 4>4E case 404E
*res-lt F n * >B1
ret-rn H1
case 494E case 424E
*res-lt F n * 9B1
ret-rn H1
case 4S04E
*res-lt F n1
ret-rn H1
defa-ltE
/* Create 56> :ith defa-lt stac2 and let 6> handle 0alfor0ed <Gss string*/
ret-rn 01
M
M
/*
* !dds a ne: 6> option :ith the gi"en gi"en na0e and "al-e
*/
"oid
!ddOption(char *str, "oid *info)
L
/*
* E;pand options array if needed to acco00odate at least one 0ore
* 6> option
*/
if (n-0Options @F 0a;Options) L
if (options FF 0) L
0a;Options F J1
options F 5$&7>e0!lloc(0a;Options * siDeof(5a"a6>Option))1
M else L
5a"a6>Option *t0p1
0a;Options *F 21
t0p F 5$&7>e0!lloc(0a;Options * siDeof(5a"a6>Option))1
0e0cpy(t0p, options, n-0Options * siDeof(5a"a6>Option))1
5$&7>e0*ree(options)1
options F t0p1
M
M
optionsPn-0OptionsQoption3tring F str1
optionsPn-0OptionsVVQe;tra&nfo F info1
if (strnc0p(str, =<Gss=, J) FF 0) L
/long t0p1
if (parse7stac27siDe(str V J, Ut0p)) L
thread3tac23iDe F t0p1
M
M
M
static "oid
3etClass%ath(const char *s)
L
char *def1
s F 5$&7WildcardE;pandClasspath(s)1
def F 5$&7>e0!lloc(strlen(s) V J0)1
sprintf(def, =<+/a"aclasspathF%s=, s)1
!ddOption(def, ),$$)1
M
/*
* 'he 3elect6ersion() ro-tine ens-res that an appropriate "ersion of
* the 5#E is r-nning 'he specification for the appropriate "ersion
* is o.tained fro0 either the 0anifest of a /ar file (preferred) or
* fro0 co00and line options
* 'he ro-tine also parses splash screen co00and line options and
* passes on their "al-es in pri"ate en"iron0ent "aria.les
*/
static "oid
3elect6ersion(int argc, char **arg", char **0ain7class)
L
char *arg1
char **ne:7arg"1
char **ne:7argp1
char *operand1
char *"ersion F ),$$1
char */re F ),$$1
int /arflag F 01
int headlessflag F 01
int restrict7search F <H1 /* <H i0plies not 2no:n */
0anifest7info info1
char en"7entryP>!G)!>E$E) V 2JQ F E)67E)'#( =F=1
char *splash7file7na0e F ),$$1
char *splash7/ar7na0e F ),$$1
char *en"7in1
int res1
/*
* &f the "ersion has already .een selected, set *0ain7class
* :ith the "al-e passed thro-gh the en"iron0ent (if any) and
* si0ply ret-rn
*/
if ((en"7in F geten"(E)67E)'#()) RF ),$$) L
if (*en"7in RF 4S04)
*0ain7class F 5$&73tring+-p(en"7in)1
ret-rn1
M
/*
* 3can thro-gh the arg-0ents for options rele"ant to 0-ltiple 5#E
* s-pport *or reference, the co00and line synta; is defined asE
*
* 3()O%3&3
* /a"a PoptionsQ class Parg-0entQ
*
* /a"a PoptionsQ </ar file/ar Parg-0entQ
*
* !s the scan is perfor0ed, 0a2e a copy of the arg-0ent list :ith
* the "ersion specification options (ne: to HK) re0o"ed, so that
* a "ersion less than HK can .e e;ec4d
*
* )ote that d-e to the synta; of the nati"e Windo:s interface
* Create%rocess(), processing si0ilar to the follo:ing e;ists in
* the Windo:s platfor0 specific ro-tine E;ec5#E (in /a"a70dc)
* Changes here sho-ld .e reprod-ced there
*/
ne:7arg" F 5$&7>e0!lloc((argc V H) * siDeof(char*))1
ne:7arg"P0Q F arg"P0Q1
ne:7argp F Une:7arg"PHQ1
argc<<1
arg"VV1
:hile ((arg F *arg") RF 0 UU *arg FF 4<4) L
if (strnc0p(arg, =<"ersionE=, N) FF 0) L
"ersion F arg V N1
M else if (strc0p(arg, =</re<restrict<search=) FF 0) L
restrict7search F H1
M else if (strc0p(arg, =<no</re<restrict<search=) FF 0) L
restrict7search F 01
M else L
if (strc0p(arg, =</ar=) FF 0)
/arflag F H1
/* deal :ith =-nfort-nate= classpath synta; */
if ((strc0p(arg, =<classpath=) FF 0 WW strc0p(arg, =<cp=) FF 0) UU
(argc @F 2)) L
*ne:7argpVV F arg1
argc<<1
arg"VV1
arg F *arg"1
M

/*
* Chec2ing for headless tool2it option in the so0e :ay as !W' doesE
* =tr-e= 0eans tr-e and any other "al-e 0eans false
*/
if (strc0p(arg, =<+/a"aa:theadlessFtr-e=) FF 0) L
headlessflag F H1
M else if (strnc0p(arg, =<+/a"aa:theadlessF=, 20) FF 0) L
headlessflag F 01
M else if (strnc0p(arg, =<splashE=, 8) FF 0) L
splash7file7na0e F argV81
M
*ne:7argpVV F arg1
M
argc<<1
arg"VV1
M
if (argc ?F 0) L /* )o operandX %ossi.ly legit :ith <Pf-llQ"ersion */
operand F ),$$1
M else L
argc<<1
*ne:7argpVV F operand F *arg"VV1
M
:hile (argc<< @ 0) /* Copy o"er Parg-0entQ */
*ne:7argpVV F *arg"VV1
*ne:7argp F ),$$1
/*
* &f there is a /ar file, read the 0anifest &f the /arfile can4t .e
* read, the 0anifest can4t .e read fro0 the /ar file, or the 0anifest
* is corr-pt, iss-e the appropriate error 0essages and e;it
*
* E"en if there isn4t a /ar file, constr-ct a 0anifest7info str-ct-re
* containing the co00and line infor0ation &t4s a con"enient :ay to carry
* this data aro-nd
*/
if (/arflag UU operand) L
if ((res F 5$&7%arse>anifest(operand, Uinfo)) RF 0) L
if (res FF <H)
#eportError>essage2(=,na.le to access /arfile %s=,
operand, 5)&7'#,E)1
else
#eportError>essage2(=&n"alid or corr-pt /arfile %s=,
operand, 5)&7'#,E)1
e;it(H)1
M

/*
* Co00and line splash screen option sho-ld ha"e precedence
* o"er the 0anifest, so the 0anifest data is -sed only if
* splash7file7na0e has not .een initialiDed a.o"e d-ring co00and
* line parsing
*/
if (Rheadlessflag UU Rsplash7file7na0e UU infosplashscreen7i0age7file7na0e) L
splash7file7na0e F infosplashscreen7i0age7file7na0e1
splash7/ar7na0e F operand1
M
M else L
info0anifest7"ersion F ),$$1
info0ain7class F ),$$1
info/re7"ersion F ),$$1
info/re7restrict7search F 01
M

/*
* %assing on splash screen info in en"iron0ent "aria.les
*/
if (splash7file7na0e UU Rheadlessflag) L
char* splash7file7entry F 5$&7>e0!lloc(strlen(3%$!3A7*&$E7E)67E)'#( =F=)
Vstrlen(splash7file7na0e)VH)1
strcpy(splash7file7entry, 3%$!3A7*&$E7E)67E)'#( =F=)1
strcat(splash7file7entry, splash7file7na0e)1
p-ten"(splash7file7entry)1
M
if (splash7/ar7na0e UU Rheadlessflag) L
char* splash7/ar7entry F 5$&7>e0!lloc(strlen(3%$!3A75!#7E)67E)'#( =F=)
Vstrlen(splash7/ar7na0e)VH)1
strcpy(splash7/ar7entry, 3%$!3A75!#7E)67E)'#( =F=)1
strcat(splash7/ar7entry, splash7/ar7na0e)1
p-ten"(splash7/ar7entry)1
M
/*
* 'he 5#E<6ersion and 5#E<#estrict<3earch "al-es (if any) fro0 the
* 0anifest are o"er:ritten .y any specified on the co00and line
*/
if ("ersion RF ),$$)
info/re7"ersion F "ersion1
if (restrict7search RF <H)
info/re7restrict7search F restrict7search1
/*
* =6alid= ret-rns (other than -nreco"era.le errors) follo: 3et
* 0ain7class as a side<effect of this ro-tine
*/
if (info0ain7class RF ),$$)
*0ain7class F 5$&73tring+-p(info0ain7class)1
/*
* &f no "ersion selection infor0ation is fo-nd either on the co00and
* line or in the 0anifest, si0ply ret-rn
*/
if (info/re7"ersion FF ),$$) L
5$&7*ree>anifest()1
5$&7>e0*ree(ne:7arg")1
ret-rn1
M
/*
* Chec2 for correct synta; of the "ersion specification (53# K6)
*/
if (R5$&76alid6ersion3tring(info/re7"ersion)) L
#eportError>essage2(=3ynta; error in "ersion specification S=%sS==,
info/re7"ersion, 5)&7'#,E)1
e;it(H)1
M
/*
* *ind the appropriate 56> on the syste0 5-st to .e as forgi"ing as
* possi.le, if the standard algorith0s don4t locate an appropriate
* /re, chec2 to see if the one r-nning :ill satisfy the reT-ire0ents
* 'his can happen on syste0s :hich ha"en4t .een set<-p for 0-ltiple
* 5#E s-pport
*/
/re F $ocate5#E(Uinfo)1
if (7la-ncher7de.-g)
printf(=5#E<6ersion F %s, 5#E<#estrict<3earch F %s 3elected F %sSn=,
(info/re7"ersionXinfo/re7"ersionE=n-ll=),
(info/re7restrict7searchX=tr-e=E=false=), (/reX/reE=n-ll=))1
if (/re FF ),$$) L
if (5$&7!ccepta.le#elease(*,$$76E#3&O), info/re7"ersion)) L
5$&7*ree>anifest()1
5$&7>e0*ree(ne:7arg")1
ret-rn1
M else L
#eportError>essage2(
=,na.le to locate 5#E 0eeting specification S=%sS==,
info/re7"ersion, 5)&7'#,E)1
e;it(H)1
M
M
/*
* &f &40 not the chosen one, e;ec the chosen one #et-rning fro0
* E;ec5#E indicates that & a0 indeed the chosen one
*
* 'he pri"ate en"iron0ent "aria.le 75!6!76E#3&O)73E' is -sed to
* pre"ent the chosen one fro0 re<reading the 0anifest file and
* -sing the "al-es fo-nd :ithin to o"erride the (potential) co00and
* line flags stripped fro0 arg" (.eca-se the target 0ay not
* -nderstand the0) %assing the >ainClass "al-e is an opti0iDation
* to a"oid locating, e;panding and parsing the 0anifest e;tra
* ti0es
*/
if (info0ain7class RF ),$$) L
if (strlen(info0ain7class) ?F >!G)!>E$E)) L
("oid)strcat(en"7entry, info0ain7class)1
M else L
#eportError>essage(=ErrorE 0ain<classE attri.-te e;ceeds syste0 li0itsSn=, 5)&7'#,E)1
e;it(H)1
M
M
("oid)p-ten"(en"7entry)1
E;ec5#E(/re, ne:7arg")1
5$&7*ree>anifest()1
5$&7>e0*ree(ne:7arg")1
ret-rn1
M
/*
* %arses co00and line arg-0ents #et-rns 5)&7*!$3E if la-ncher
* sho-ld e;it :itho-t starting "0 (eg certain "ersion and -sage
* options)1 ret-rns 5)&7'#,E if "0 needs to .e started to process
* gi"en options *pret (the la-ncher process ret-rn "al-e) is set to
* 0 for a nor0al e;it
*/
static /.oolean
%arse!rg-0ents(int *pargc, char ***parg", char **p/arfile,
char **pclassna0e, int *pret, const char */"0path)
L
int argc F *pargc1
char **arg" F *parg"1
/.oolean /arflag F 5)&7*!$3E1
char *arg1
*pret F H1
:hile ((arg F *arg") RF 0 UU *arg FF 4<4) L
arg"VV1 <<argc1
if (strc0p(arg, =<classpath=) FF 0 WW strc0p(arg, =<cp=) FF 0) L
if (argc ? H) L
#eportError>essage2(=%s reT-ires class path specification=,
arg, 5)&7'#,E)1
%rint,sage()1
ret-rn 5)&7*!$3E1
M
3etClass%ath(*arg")1
arg"VV1 <<argc1
M else if (strc0p(arg, =</ar=) FF 0) L
/arflag F 5)&7'#,E1
M else if (strc0p(arg, =<help=) FF 0 WW
strc0p(arg, =<h=) FF 0 WW
strc0p(arg, =<X=) FF 0) L
%rint,sage()1
*pret F 01
ret-rn 5)&7*!$3E1
M else if (strc0p(arg, =<"ersion=) FF 0) L
print6ersion F 5)&7'#,E1
ret-rn 5)&7'#,E1
M else if (strc0p(arg, =<sho:"ersion=) FF 0) L
sho:6ersion F 5)&7'#,E1
M else if (strc0p(arg, =<G=) FF 0) L
*pret F %rintG,sage(/"0path)1
ret-rn 5)&7*!$3E1
/*
* 'he follo:ing case pro"ide .ac2:ard co0pati.ility :ith old<style
* co00and line options
*/
M else if (strc0p(arg, =<f-ll"ersion=) FF 0) L
fprintf(stderr, =%s f-ll "ersion S=%sS=Sn=, progna0e,
*,$$76E#3&O))1
*pret F 01
ret-rn 5)&7*!$3E1
M else if (strc0p(arg, =<"er.osegc=) FF 0) L
!ddOption(=<"er.oseEgc=, ),$$)1
M else if (strc0p(arg, =<t=) FF 0) L
!ddOption(=<Gt=, ),$$)1
M else if (strc0p(arg, =<t0=) FF 0) L
!ddOption(=<Gt0=, ),$$)1
M else if (strc0p(arg, =<de.-g=) FF 0) L
!ddOption(=<Gde.-g=, ),$$)1
M else if (strc0p(arg, =<noclassgc=) FF 0) L
!ddOption(=<Gnoclassgc=, ),$$)1
M else if (strc0p(arg, =<Gf-t-re=) FF 0) L
!ddOption(=<G"erifyEall=, ),$$)1
M else if (strc0p(arg, =<"erify=) FF 0) L
!ddOption(=<G"erifyEall=, ),$$)1
M else if (strc0p(arg, =<"erifyre0ote=) FF 0) L
!ddOption(=<G"erifyEre0ote=, ),$$)1
M else if (strc0p(arg, =<no"erify=) FF 0) L
!ddOption(=<G"erifyEnone=, ),$$)1
M else if (strc0p(arg, =<GGs-ppressE;it>essage=) FF 0) L
noE;itError>essage F H1
M else if (strnc0p(arg, =<prof=, K) FF 0) L
char *p F arg V K1
char *t0p F 5$&7>e0!lloc(strlen(arg) V K0)1
if (*p) L
sprintf(t0p, =<Gr-nhprofEcp-Fold,fileF%s=, p V H)1
M else L
sprintf(t0p, =<Gr-nhprofEcp-Fold,fileF/a"aprof=)1
M
!ddOption(t0p, ),$$)1
M else if (strnc0p(arg, =<ss=, I) FF 0 WW
strnc0p(arg, =<oss=, J) FF 0 WW
strnc0p(arg, =<0s=, I) FF 0 WW
strnc0p(arg, =<0;=, I) FF 0) L
char *t0p F 5$&7>e0!lloc(strlen(arg) V 6)1
sprintf(t0p, =<G%s=, arg V H)1 /* s2ip 4<4 */
!ddOption(t0p, ),$$)1
M else if (strc0p(arg, =<chec2so-rce=) FF 0 WW
strc0p(arg, =<cs=) FF 0 WW
strc0p(arg, =<noasyncgc=) FF 0) L
/* )o longer s-pported */
fprintf(stderr,
=WarningE %s option is no longer s-pportedSn=,
arg)1
M else if (strnc0p(arg, =<"ersionE=, N) FF 0 WW
strc0p(arg, =<no</re<restrict<search=) FF 0 WW
strc0p(arg, =</re<restrict<search=) FF 0 WW
strnc0p(arg, =<splashE=, 8) FF 0) L
1 /* &gnore 0achine independent options already handled */
M else if (#e0o"a.le>achine+ependentOption(arg) ) L
1 /* +o not pass option to "0 */
M
else L
!ddOption(arg, ),$$)1
M
M
if (<<argc @F 0) L
if (/arflag) L
*p/arfile F *arg"VV1
*pclassna0e F 01
M else L
*p/arfile F 01
*pclassna0e F *arg"VV1
M
*pargc F argc1
*parg" F arg"1
M
ret-rn 5)&7'#,E1
M
/*
* &nitialiDes the 5a"a 6irt-al >achine !lso frees options array :hen
* finished
*/
static /.oolean
&nitialiDe56>(5a"a6> **p"0, 5)&En" **pen", &n"ocation*-nctions *ifn)
L
5a"a6>&nit!rgs args1
/int r1
0e0set(Uargs, 0, siDeof(args))1
args"ersion F 5)&76E#3&O)7H721
argsnOptions F n-0Options1
argsoptions F options1
argsignore,nrecogniDed F 5)&7*!$3E1
if (7la-ncher7de.-g) L
int i F 01
printf(=5a"a6> argsESn =)1
printf(="ersion 0;%08l;, =, (long)args"ersion)1
printf(=ignore,nrecogniDed is %s, =,
argsignore,nrecogniDed X =5)&7'#,E= E =5)&7*!$3E=)1
printf(=nOptions is %ldSn=, (long)argsnOptions)1
for (i F 01 i ? n-0Options1 iVV)
printf(= optionP%2dQ F 4%s4Sn=,
i, argsoptionsPiQoption3tring)1
M
r F ifn<@Create5a"a6>(p"0, ("oid **)pen", Uargs)1
5$&7>e0*ree(options)1
ret-rn r FF 5)&7O91
M
Cdefine ),$$7CAEC90(e) if ((e) FF 0) ret-rn 0
Cdefine ),$$7CAEC9(e) if ((e) FF 0) ret-rn
static /string platfor0Encoding F ),$$1
static /string get%latfor0Encoding(5)&En" *en") L
if (platfor0Encoding FF ),$$) L
/string propna0e F (*en")<@)e:3tring,'*(en", =s-n/n-encoding=)1
if (propna0e) L
/class cls1
/0ethod&+ 0id1
),$$7CAEC90 (cls F (*en")<@*indClass(en", =/a"a/lang/3yste0=))1
),$$7CAEC90 (0id F (*en")<@8et3tatic>ethod&+(
en", cls,
=get%roperty=,
=($/a"a/lang/3tring1)$/a"a/lang/3tring1=))1
platfor0Encoding F (*en")<@Call3taticO./ect>ethod (
en", cls, 0id, propna0e)1
M
M
ret-rn platfor0Encoding1
M
static /.oolean isEncoding3-pported(5)&En" *en", /string enc) L
/class cls1
/0ethod&+ 0id1
),$$7CAEC90 (cls F (*en")<@*indClass(en", =/a"a/nio/charset/Charset=))1
),$$7CAEC90 (0id F (*en")<@8et3tatic>ethod&+(
en", cls,
=is3-pported=,
=($/a"a/lang/3tring1)Y=))1
ret-rn (*en")<@Call3taticBoolean>ethod(en", cls, 0id, enc)1
M
/*
* #et-rns a ne: 5a"a string o./ect for the specified platfor0 string
*/
static /string
)e:%latfor03tring(5)&En" *en", char *s)
L
int len F (int)strlen(s)1
/class cls1
/0ethod&+ 0id1
/.yte!rray ary1
/string enc1
if (s FF ),$$)
ret-rn 01
enc F get%latfor0Encoding(en")1
ary F (*en")<@)e:Byte!rray(en", len)1
if (ary RF 0) L
/string str F 01
(*en")<@3etByte!rray#egion(en", ary, 0, len, (/.yte *)s)1
if (R(*en")<@E;ceptionOcc-rred(en")) L
if (isEncoding3-pported(en", enc) FF 5)&7'#,E) L
),$$7CAEC90(cls F (*en")<@*indClass(en", =/a"a/lang/3tring=))1
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en", cls, =?init@=,
=(PB$/a"a/lang/3tring1)6=))1
str F (*en")<@)e:O./ect(en", cls, 0id, ary, enc)1
M else L
/*&f the encoding specified in s-n/n-encoding is not
endorsed .y =Charsetis3-pported= :e ha"e to fall .ac2
to -se 3tring(.ytePQ) e;plicitly here :itho-t specifying
the encoding na0e, in :hich the 3tringCoding class :ill
pic2-p the iso<88KN<H as the fall.ac2 con"erter for -s
*/
),$$7CAEC90(cls F (*en")<@*indClass(en", =/a"a/lang/3tring=))1
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en", cls, =?init@=,
=(PB)6=))1
str F (*en")<@)e:O./ect(en", cls, 0id, ary)1
M
(*en")<@+elete$ocal#ef(en", ary)1
ret-rn str1
M
M
ret-rn 01
M
/*
* #et-rns a ne: array of 5a"a string o./ects for the specified
* array of platfor0 strings
*/
static /o./ect!rray
)e:%latfor03tring!rray(5)&En" *en", char **str", int strc)
L
/array cls1
/array ary1
int i1
),$$7CAEC90(cls F (*en")<@*indClass(en", =/a"a/lang/3tring=))1
),$$7CAEC90(ary F (*en")<@)e:O./ect!rray(en", strc, cls, 0))1
for (i F 01 i ? strc1 iVV) L
/string str F )e:%latfor03tring(en", *str"VV)1
),$$7CAEC90(str)1
(*en")<@3etO./ect!rrayEle0ent(en", ary, i, str)1
(*en")<@+elete$ocal#ef(en", str)1
M
ret-rn ary1
M
/*
* $oads a class, con"ert the 44 to 4/4
*/
static /class
$oadClass(5)&En" *en", char *na0e)
L
char *.-f F 5$&7>e0!lloc(strlen(na0e) V H)1
char *s F .-f, *t F na0e, c1
/class cls1
/long start, end1
if (7la-ncher7de.-g)
start F Co-nter8et()1
do L
c F *tVV1
*sVV F (c FF 44) X 4/4 E c1
M :hile (c RF 4S04)1
cls F (*en")<@*indClass(en", .-f)1
5$&7>e0*ree(.-f)1
if (7la-ncher7de.-g) L
end F Co-nter8et()1
printf(=%ld 0icro seconds to load 0ain classSn=,
(long)(/int)Co-nter2>icros(end<start))1
printf(=<<<<75!6!7$!,)CAE#7+EB,8<<<<Sn=)1
M
ret-rn cls1
M
/*
* #et-rns the 0ain class na0e for the specified /ar file
*/
static /string
8et>ainClass)a0e(5)&En" *en", char */arna0e)
L
Cdefine >!&)7C$!33 =>ain<Class=
/class cls1
/0ethod&+ 0id1
/o./ect /ar, 0an, attr1
/string str, res-lt F 01
),$$7CAEC90(cls F (*en")<@*indClass(en", =/a"a/-til//ar/5ar*ile=))1
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en", cls, =?init@=,
=($/a"a/lang/3tring1)6=))1
),$$7CAEC90(str F )e:%latfor03tring(en", /arna0e))1
),$$7CAEC90(/ar F (*en")<@)e:O./ect(en", cls, 0id, str))1
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en", cls, =get>anifest=,
=()$/a"a/-til//ar/>anifest1=))1
0an F (*en")<@CallO./ect>ethod(en", /ar, 0id)1
if (0an RF 0) L
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en",
(*en")<@8etO./ectClass(en", 0an),
=get>ain!ttri.-tes=,
=()$/a"a/-til//ar/!ttri.-tes1=))1
attr F (*en")<@CallO./ect>ethod(en", 0an, 0id)1
if (attr RF 0) L
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en",
(*en")<@8etO./ectClass(en", attr),
=get6al-e=,
=($/a"a/lang/3tring1)$/a"a/lang/3tring1=))1
),$$7CAEC90(str F )e:%latfor03tring(en", >!&)7C$!33))1
res-lt F (*en")<@CallO./ect>ethod(en", attr, 0id, str)1
M
M
ret-rn res-lt1
M
Cifdef 5!6!7!#83
static char */a"a7argsPQ F 5!6!7!#831
static char *app7classpathPQ F !%%7C$!33%!'A1
/*
* *or tools, con"ert co00and line args th-sE
* /a"ac <cp fooEfoo/=*= <5<0sI20
* /a"a <0sI20 <cp 5$&7WildcardE;pandClasspath(fooEfoo/=*=)
*/
static "oid
'ranslate!pplication!rgs(int *pargc, char ***parg")
L
const int ),>7!#83 F (siDeof(/a"a7args) / siDeof(char *))1
int argc F *pargc1
char **arg" F *parg"1
int nargc F argc V ),>7!#831
char **narg" F 5$&7>e0!lloc((nargc V H) * siDeof(char *))1
int i1
*pargc F nargc1
*parg" F narg"1
/* Copy the 6> arg-0ents (ie prefi;ed :ith <5) */
for (i F 01 i ? ),>7!#831 iVV) L
char *arg F /a"a7argsPiQ1
if (argP0Q FF 4<4 UU argPHQ FF 454) L
*narg"VV F arg V 21
M
M
for (i F 01 i ? argc1 iVV) L
char *arg F arg"PiQ1
if (argP0Q FF 4<4 UU argPHQ FF 454) L
if (argP2Q FF 4S04) L
#eportError>essage(=ErrorE the <5 option sho-ld not .e =
=follo:ed .y a space=, 5)&7'#,E)1
e;it(H)1
M
*narg"VV F arg V 21
M
M
/* Copy the rest of the arg-0ents */
for (i F 01 i ? ),>7!#831 iVV) L
char *arg F /a"a7argsPiQ1
if (argP0Q RF 4<4 WW argPHQ RF 454) L
*narg"VV F arg1
M
M
for (i F 01 i ? argc1 iVV) L
char *arg F arg"PiQ1
if (argP0Q FF 4<4) L
if (argPHQ FF 454)
contin-e1
Cifdef EG%!)+7C$!33%!'A7W&$+C!#+3
if (argPHQ FF 4c4
UU (strc0p(arg, =<cp=) FF 0 WW
strc0p(arg, =<classpath=) FF 0)
UU i ? argc < H) L
*narg"VV F arg1
*narg"VV F (char *) 5$&7WildcardE;pandClasspath(arg"PiVHQ)1
iVV1
contin-e1
M
Cendif
M
*narg"VV F arg1
M
*narg" F 01
M
/*
* *or o-r tools, :e try to add I 6> optionsE
* <+en"classpathF?en"cp@
* <+applicationho0eF?appho0e@
* <+/a"aclasspathF?appcp@
* ?en"cp@ is the -ser4s setting of C$!33%!'A << for instance the -ser
* tells /a"ac :here to find .inary classes thro-gh this en"iron0ent
* "aria.le )otice that -sers :ill .e a.le to co0pile against o-r
* tools classes (s-ntools/a"ac>ain) only if they e;plicitly add
* tools/ar to C$!33%!'A
* ?appho0e@ is the directory :here the application is installed
* ?appcp@ is the classpath to :here o-r apps4 classfiles are
*/
static /.oolean
!dd!pplicationOptions()
L
const int ),>7!%%7C$!33%!'A F (siDeof(app7classpath) / siDeof(char *))1
char *en"cp, *appcp, *appho0e1
char ho0eP>!G%!'A$E)Q1 /* application ho0e */
char separatorPQ F L %!'A73E%!#!'O#, 4S04 M1
int siDe, i1
int strlenAo0e1
L
const char *s F geten"(=C$!33%!'A=)1
if (s) L
s F (char *) 5$&7WildcardE;pandClasspath(s)1
/* J0 for <+en"classpathF */
en"cp F (char *)5$&7>e0!lloc(strlen(s) V J0)1
sprintf(en"cp, =<+en"classpathF%s=, s)1
!ddOption(en"cp, ),$$)1
M
M
if (R8et!pplicationAo0e(ho0e, siDeof(ho0e))) L
#eportError>essage(=Can4t deter0ine application ho0e=, 5)&7'#,E)1
ret-rn 5)&7*!$3E1
M
/* J0 for 4<+applicationho0eF4 */
appho0e F (char *)5$&7>e0!lloc(strlen(ho0e) V J0)1
sprintf(appho0e, =<+applicationho0eF%s=, ho0e)1
!ddOption(appho0e, ),$$)1
/* Ao: .ig is the application4s classpathX */
siDe F J01 /* J0E =<+/a"aclasspathF= */
strlenAo0e F (int)strlen(ho0e)1
for (i F 01 i ? ),>7!%%7C$!33%!'A1 iVV) L
siDe VF strlenAo0e V (int)strlen(app7classpathPiQ) V H1 /* HE separator */
M
appcp F (char *)5$&7>e0!lloc(siDe V H)1
strcpy(appcp, =<+/a"aclasspathF=)1
for (i F 01 i ? ),>7!%%7C$!33%!'A1 iVV) L
strcat(appcp, ho0e)1 /* cESprogra0 filesS0yapp */
strcat(appcp, app7classpathPiQ)1 /* Sli.S0yapp/ar */
strcat(appcp, separator)1 /* 1 */
M
appcpPstrlen(appcp)<HQ F 4S041 /* re0o"e trailing path separator */
!ddOption(appcp, ),$$)1
ret-rn 5)&7'#,E1
M
Cendif /* 5!6!7!#83 */
/*
* in/ect the <+s-n/a"aco00and pse-do property into the args str-ct-re
* this pse-do property is -sed in the Aot3pot 6> to e;pose the
* 5a"a class na0e and arg-0ents to the 0ain 0ethod to the 6> 'he
* Aot3pot 6> -ses this pse-do property to store the 5a"a class na0e
* (or /ar file na0e) and the arg-0ents to the class4s 0ain 0ethod
* to the instr-0entation 0e0ory region 'he s-n/a"aco00and pse-do
* property is not e;ported .y Aot3pot to the 5a"a layer
*/
"oid
3et5a"aCo00and$ine%rop(char *classna0e, char */arfile,
int argc, char **arg")
L
int i F 01
siDe7t len F 01
char* /a"aCo00and F ),$$1
char* dash+str F =<+s-n/a"aco00andF=1
if (classna0e FF ),$$ UU /arfile FF ),$$) L
/* -ne;pected, one of these sho-ld .e set /-st ret-rn :itho-t
* setting the property
*/
ret-rn1
M
/* if the class na0e is not set, then -se the /arfile na0e */
if (classna0e FF ),$$) L
classna0e F /arfile1
M
/* deter0ine the a0o-nt of 0e0ory to allocate ass-0ing
* the indi"id-al co0ponents :ill .e space separated
*/
len F strlen(classna0e)1
for (i F 01 i ? argc1 iVV) L
len VF strlen(arg"PiQ) V H1
M
/* allocate the 0e0ory */
/a"aCo00and F (char*) 5$&7>e0!lloc(len V strlen(dash+str) V H)1
/* .-ild the <+ string */
*/a"aCo00and F 4S041
strcat(/a"aCo00and, dash+str)1
strcat(/a"aCo00and, classna0e)1
for (i F 01 i ? argc1 iVV) L
/* the co0ponents of the string are space separated &n
* the case of e0.edded :hite space, the relationship of
* the :hite space separated co0ponents to their tr-e
* positional arg-0ents :ill .e a0.ig-o-s 'his iss-e 0ay
* .e addressed in a f-t-re release
*/
strcat(/a"aCo00and, = =)1
strcat(/a"aCo00and, arg"PiQ)1
M
!ddOption(/a"aCo00and, ),$$)1
M
/*
* 56> :o-ld li2e to 2no: if it4s created .y a standard 3-n la-ncher, or .y
* -ser nati"e application, the follo:ing property indicates the for0er
*/
"oid 3et5a"a$a-ncher%rop() L
!ddOption(=<+s-n/a"ala-ncherF3,)73'!)+!#+=, ),$$)1
M
/*
* %rints the "ersion infor0ation fro0 the /a"a"ersion and other properties
*/
static "oid
%rint5a"a6ersion(5)&En" *en")
L
/class "er1
/0ethod&+ print1
),$$7CAEC9("er F (*en")<@*indClass(en", =s-n/0isc/6ersion=))1
),$$7CAEC9(print F (*en")<@8et3tatic>ethod&+(en", "er, =print=, =()6=))1
(*en")<@Call3tatic6oid>ethod(en", "er, print)1
M
/*
* %rints defa-lt -sage 0essage
*/
static "oid
%rint,sage("oid)
L
int i1
fprintf(stdo-t,
=,sageE %s P<optionsQ class PargsQSn=
= (to e;ec-te a class)Sn=
= or %s P<optionsQ </ar /arfile PargsQSn=
= (to e;ec-te a /ar file)Sn=
=Sn=
=:here options incl-deESn=,
progna0e,
progna0e)1
%rint>achine+ependentOptions()1
if ((2no:n6>sP0Qflag FF 6>79)OW)) WW
(2no:n6>sP0Qflag FF 6>7&*73E#6E#7C$!33)) L
fprintf(stdo-t, = %sSt to select the S=%sS= 6>Sn=,
2no:n6>sP0Qna0e, 2no:n6>sP0Qna0eVH)1
M
for (iFH1 i?2no:n6>sCo-nt1 iVV) L
if (2no:n6>sPiQflag FF 6>79)OW))
fprintf(stdo-t, = %sSt to select the S=%sS= 6>Sn=,
2no:n6>sPiQna0e, 2no:n6>sPiQna0eVH)1
M
for (iFH1 i?2no:n6>sCo-nt1 iVV) L
if (2no:n6>sPiQflag FF 6>7!$&!3E+7'O)
fprintf(stdo-t, = %sSt is a synony0 for =
=the S=%sS= 6> PdeprecatedQSn=,
2no:n6>sPiQna0e, 2no:n6>sPiQaliasVH)1
M
/* 'he first 2no:n 6> is the defa-lt */
L
const char* defa-lt6> F 2no:n6>sP0Qna0eVH1
const char* p-nct-ation F ==1
const char* reason F ==1
if ((2no:n6>sP0Qflag FF 6>7&*73E#6E#7C$!33) UU
(3er"erClass>achine() FF 5)&7'#,E)) L
defa-lt6> F 2no:n6>sP0Qser"er7classVH1
p-nct-ation F =, =1
reason F =.eca-se yo- are r-nning on a ser"er<class 0achineSn=1
M
fprintf(stdo-t, = 'he defa-lt 6> is %s%sSn=,
defa-lt6>, p-nct-ation)1
fprintf(stdo-t, = %sSn=,
reason)1
M
fprintf(stdo-t,
= <cp ?class search path of directories and Dip//ar files@Sn=
= <classpath ?class search path of directories and Dip//ar files@Sn=
= ! %c separated list of directories, 5!# archi"es,Sn=
= and Y&% archi"es to search for class filesSn=
= <+?na0e@F?"al-e@Sn=
= set a syste0 propertySn=
= <"er.osePEclassWgcW/niQSn=
= ena.le "er.ose o-tp-tSn=
= <"ersion print prod-ct "ersion and e;itSn=
= <"ersionE?"al-e@Sn=
= reT-ire the specified "ersion to r-nSn=
= <sho:"ersion print prod-ct "ersion and contin-eSn=
= </re<restrict<search W </re<no<restrict<searchSn=
= incl-de/e;cl-de -ser pri"ate 5#Es in the "ersion searchSn=
= <X <help print this help 0essageSn=
= <G print help on non<standard optionsSn=
= <eaPE?pac2agena0e@WE?classna0e@QSn=
= <ena.leassertionsPE?pac2agena0e@WE?classna0e@QSn=
= ena.le assertionsSn=
= <daPE?pac2agena0e@WE?classna0e@QSn=
= <disa.leassertionsPE?pac2agena0e@WE?classna0e@QSn=
= disa.le assertionsSn=
= <esa W <ena.lesyste0assertionsSn=
= ena.le syste0 assertionsSn=
= <dsa W <disa.lesyste0assertionsSn=
= disa.le syste0 assertionsSn=
= <agentli.E?li.na0e@PF?options@QSn=
= load nati"e agent li.rary ?li.na0e@, eg <agentli.EhprofSn=
= see also, <agentli.E/d:pFhelp and <agentli.EhprofFhelpSn=
= <agentpathE?pathna0e@PF?options@QSn=
= load nati"e agent li.rary .y f-ll pathna0eSn=
= </a"aagentE?/arpath@PF?options@QSn=
= load 5a"a progra00ing lang-age agent, see /a"alanginstr-0entSn=
= <splashE?i0agepath@Sn=
= sho: splash screen :ith specified i0ageSn=
,%!'A73E%!#!'O#)1
M
/*
* %rint -sage 0essage for <G options
*/
static /int
%rintG,sage(const char */"0path)
L
/*
! I2 .it c-shion to pre"ent .-ffer o"err-n, noting that
fopen(IC) 0ay fail if the .-ffer e;ceeds >!G%!'A$E)
*/
char pathP>!G%!'A$E)VI2Q1
char .-fPH28Q1
siDe7t n1
*&$E *fp1
static const char G-sage7t;tPQ F =/G-saget;t=1
strcpy(path, /"0path)1
/* )ote the *&$E73E%!#!'O# is platfor0 dependent */
strcpy(strrchr(path, *&$E73E%!#!'O#), G-sage7t;t)1
fp F fopen(path, =r=)1
if (fp FF 0) L
fprintf(stderr, =Can4t open %sSn=, path)1
ret-rn H1
M
:hile ((n F fread(.-f, H, siDeof(.-f), fp)) RF 0) L
f:rite(.-f, H, n, stdo-t)1
M
fclose(fp)1
ret-rn 01
M
/*
* #ead the /"0cfg file and fill the 2no:n56>sPQ array
*
* 'he f-nctionality of the /"0cfg file is s-./ect to change :itho-t
* notice and the 0echanis0 :ill .e re0o"ed in the f-t-re
*
* 'he le;ical str-ct-re of the /"0cfg file is as follo:sE
*
* /"0cfg EF L "0$ine M
* "0$ine EF 2no:n$ine
* W alias$ine
* W :arn$ine
* W ignore$ine
* W error$ine
* W predicate$ine
* W co00ent$ine
* 2no:n$ine EF flag =9)OW)= EO$
* :arn$ine EF flag =W!#)= EO$
* ignore$ine EF flag =&8)O#E= EO$
* error$ine EF flag =E##O#= EO$
* alias$ine EF flag =!$&!3E+7'O= flag EO$
* predicate$ine EF flag =&*73E#6E#7C$!33= flag EO$
* co00ent$ine EF =C= te;t EO$
* flag EF =<= identifier
*
* 'he se0antics are that :hen so0eone specifies a flag on the co00and lineE
* < if the flag appears on a 2no:n$ine, then the identifier is -sed as
* the na0e of the directory holding the 56> li.rary (the na0e of the 56>)
* < if the flag appears as the first flag on an alias$ine, the identifier
* of the second flag is -sed as the na0e of the 56>
* < if the flag appears on a :arn$ine, the identifier is -sed as the
* na0e of the 56>, .-t a :arning is generated
* < if the flag appears on an ignore$ine, the identifier is recogniDed as the
* na0e of a 56>, .-t the identifier is ignored and the defa-lt "0 -sed
* < if the flag appears on an error$ine, an error is generated
* < if the flag appears as the first flag on a predicate$ine, and
* the 0achine on :hich yo- are r-nning passes the predicate indicated,
* then the identifier of the second flag is -sed as the na0e of the 56>,
* other:ise the identifier of the first flag is -sed as the na0e of the 56>
* &f no flag is gi"en on the co00and line, the first "0$ine of the /"0cfg
* file deter0ines the na0e of the 56>
* %redicate$ines are only interpreted on first "0$ine of a /"0cfg file,
* since they only 0a2e sense if so0eone hasn4t specified the na0e of the
* 56> on the co00and line
*
* 'he intent of the /"0cfg file is to allo: se"eral 56> li.raries to
* .e installed in different s-.directories of a single 5#E installation,
* for space<sa"ings and con"enience in testing
* 'he intent is e;plicitly not to pro"ide a f-ll aliasing or predicate
* 0echanis0
*/
/int
#ead9no:n6>s(const char */repath, char * arch, /.oolean spec-lati"e)
L
*&$E */"0Cfg1
char /"0Cfg)a0eP>!G%!'A$E)V20Q1
char lineP>!G%!'A$E)V20Q1
int cnt F 01
int lineno F 01
/long start, end1
int "0'ype1
char *t0p%tr1
char *alt6>)a0e F ),$$1
char *ser"erClass6>)a0e F ),$$1
static char *:hite3pace F = St=1
if (7la-ncher7de.-g) L
start F Co-nter8et()1
M
strcpy(/"0Cfg)a0e, /repath)1
strcat(/"0Cfg)a0e, *&$E3E% =li.= *&$E3E%)1
strcat(/"0Cfg)a0e, arch)1
strcat(/"0Cfg)a0e, *&$E3E% =/"0cfg=)1

/"0Cfg F fopen(/"0Cfg)a0e, =r=)1
if (/"0Cfg FF ),$$) L
if (Rspec-lati"e) L
#eportError>essage2(=ErrorE co-ld not open Z%s4=, /"0Cfg)a0e,
5)&7'#,E)1
e;it(H)1
M else L
ret-rn <H1
M
M
:hile (fgets(line, siDeof(line), /"0Cfg) RF ),$$) L
"0'ype F 6>7,)9)OW)1
linenoVV1
if (lineP0Q FF 4C4)
contin-e1
if (lineP0Q RF 4<4) L
fprintf(stderr, =WarningE no leading < on line %d of Z%s4Sn=,
lineno, /"0Cfg)a0e)1
M
if (cnt @F 2no:n6>s$i0it) L
8ro:9no:n6>s(cnt)1
M
linePstrlen(line)<HQ F 4S041 /* re0o"e trailing ne:line */
t0p%tr F line V strcspn(line, :hite3pace)1
if (*t0p%tr FF 0) L
fprintf(stderr, =WarningE 0issing 6> type on line %d of Z%s4Sn=,
lineno, /"0Cfg)a0e)1
M else L
/* )-ll<ter0inate this string for 5$&73tring+-p .elo: */
*t0p%trVV F 01
t0p%tr VF strspn(t0p%tr, :hite3pace)1
if (*t0p%tr FF 0) L
fprintf(stderr, =WarningE 0issing 6> type on line %d of Z%s4Sn=,
lineno, /"0Cfg)a0e)1
M else L
if (Rstrnc0p(t0p%tr, =9)OW)=, strlen(=9)OW)=))) L
"0'ype F 6>79)OW)1
M else if (Rstrnc0p(t0p%tr, =!$&!3E+7'O=, strlen(=!$&!3E+7'O=))) L
t0p%tr VF strcspn(t0p%tr, :hite3pace)1
if (*t0p%tr RF 0) L
t0p%tr VF strspn(t0p%tr, :hite3pace)1
M
if (*t0p%tr FF 0) L
fprintf(stderr, =WarningE 0issing 6> alias on line %d of Z%s4Sn=,
lineno, /"0Cfg)a0e)1
M else L
/* )-ll ter0inate alt6>)a0e */
alt6>)a0e F t0p%tr1
t0p%tr VF strcspn(t0p%tr, :hite3pace)1
*t0p%tr F 01
"0'ype F 6>7!$&!3E+7'O1
M
M else if (Rstrnc0p(t0p%tr, =W!#)=, strlen(=W!#)=))) L
"0'ype F 6>7W!#)1
M else if (Rstrnc0p(t0p%tr, =&8)O#E=, strlen(=&8)O#E=))) L
"0'ype F 6>7&8)O#E1
M else if (Rstrnc0p(t0p%tr, =E##O#=, strlen(=E##O#=))) L
"0'ype F 6>7E##O#1
M else if (Rstrnc0p(t0p%tr,
=&*73E#6E#7C$!33=,
strlen(=&*73E#6E#7C$!33=))) L
t0p%tr VF strcspn(t0p%tr, :hite3pace)1
if (*t0p%tr RF 0) L
t0p%tr VF strspn(t0p%tr, :hite3pace)1
M
if (*t0p%tr FF 0) L
fprintf(stderr, =WarningE 0issing ser"er class 6> on line %d of Z%s4Sn=,
lineno, /"0Cfg)a0e)1
M else L
/* )-ll ter0inate ser"er class 6> na0e */
ser"erClass6>)a0e F t0p%tr1
t0p%tr VF strcspn(t0p%tr, :hite3pace)1
*t0p%tr F 01
"0'ype F 6>7&*73E#6E#7C$!331
M
M else L
fprintf(stderr, =WarningE -n2no:n 6> type on line %d of Z%s4Sn=,
lineno, U/"0Cfg)a0eP0Q)1
"0'ype F 6>79)OW)1
M
M
M
if (7la-ncher7de.-g)
printf(=/"0cfgP%dQ F <@%s?<Sn=, cnt, line)1
if ("0'ype RF 6>7,)9)OW)) L
2no:n6>sPcntQna0e F 5$&73tring+-p(line)1
2no:n6>sPcntQflag F "0'ype1
s:itch ("0'ype) L
defa-ltE
.rea21
case 6>7!$&!3E+7'OE
2no:n6>sPcntQalias F 5$&73tring+-p(alt6>)a0e)1
if (7la-ncher7de.-g) L
printf(= na0eE %s "0'ypeE %s aliasE %sSn=,
2no:n6>sPcntQna0e, =6>7!$&!3E+7'O=, 2no:n6>sPcntQalias)1
M
.rea21
case 6>7&*73E#6E#7C$!33E
2no:n6>sPcntQser"er7class F 5$&73tring+-p(ser"erClass6>)a0e)1
if (7la-ncher7de.-g) L
printf(= na0eE %s "0'ypeE %s ser"er7classE %sSn=,
2no:n6>sPcntQna0e, =6>7&*73E#6E#7C$!33=, 2no:n6>sPcntQser"er7class)1
M
.rea21
M
cntVV1
M
M
fclose(/"0Cfg)1
2no:n6>sCo-nt F cnt1
if (7la-ncher7de.-g) L
end F Co-nter8et()1
printf(=%ld 0icro seconds to parse /"0cfgSn=,
(long)(/int)Co-nter2>icros(end<start))1
M
ret-rn cnt1
M
static "oid
8ro:9no:n6>s(int 0ini0-0)
L
str-ct "0desc* ne:9no:n6>s1
int ne:>a;1
ne:>a; F (2no:n6>s$i0it FF 0 X &)&'7>!G79)OW)76>3 E (2 * 2no:n6>s$i0it))1
if (ne:>a; ?F 0ini0-0) L
ne:>a; F 0ini0-01
M
ne:9no:n6>s F (str-ct "0desc*) 5$&7>e0!lloc(ne:>a; * siDeof(str-ct "0desc))1
if (2no:n6>s RF ),$$) L
0e0cpy(ne:9no:n6>s, 2no:n6>s, 2no:n6>s$i0it * siDeof(str-ct "0desc))1
M
5$&7>e0*ree(2no:n6>s)1
2no:n6>s F ne:9no:n6>s1
2no:n6>s$i0it F ne:>a;1
M
/* #et-rns inde; of 6> or <H if not fo-nd */
static int
9no:n6>&nde;(const char* na0e)
L
int i1
if (strnc0p(na0e, =<5=, 2) FF 0) na0e VF 21
for (i F 01 i ? 2no:n6>sCo-nt1 iVV) L
if (Rstrc0p(na0e, 2no:n6>sPiQna0e)) L
ret-rn i1
M
M
ret-rn <H1
M
static "oid
*ree9no:n6>s()
L
int i1
for (i F 01 i ? 2no:n6>sCo-nt1 iVV) L
5$&7>e0*ree(2no:n6>sPiQna0e)1
2no:n6>sPiQna0e F ),$$1
M
5$&7>e0*ree(2no:n6>s)1
M
/*
* +isplays the splash screen according to the /ar file na0e
* and i0age file na0es stored in en"iron0ent "aria.les
*/
static "oid
3ho:3plash3creen()
L
const char */ar7na0e F geten"(3%$!3A75!#7E)67E)'#()1
const char *file7na0e F geten"(3%$!3A7*&$E7E)67E)'#()1
int data7siDe1
"oid *i0age7data1
if (/ar7na0e) L
i0age7data F 5$&75ar,npac2*ile(/ar7na0e, file7na0e, Udata7siDe)1
if (i0age7data) L
+o3plash&nit()1
+o3plash$oad>e0ory(i0age7data, data7siDe)1
5$&7>e0*ree(i0age7data)1
M
M else if (file7na0e) L
+o3plash&nit()1
+o3plash$oad*ile(file7na0e)1
M else L
ret-rn1
M
+o3plash3et*ile5ar)a0e(file7na0e, /ar7na0e)1
M
*/
/*
* 3hared so-rce for 4/a"a4 co00and line tool
*
* &f 5!6!7!#83 is defined, then acts as a la-ncher for applications *or
* instance, the 5+9 co00and line tools s-ch as /a"ac and /a"adoc (see
* 0a2efiles for 0ore details) are .-ilt :ith this progra0 !ny arg-0ents
* prefi;ed :ith 4<54 :ill .e passed directly to the 4/a"a4 co00and
*/
/*
* One /o. of the la-ncher is to re0o"e co00and line options :hich the
* "0 does not -nderstand and :ill not process 'hese options incl-de
* options :hich select :hich style of "0 is r-n (eg <client and
* <ser"er) as :ell as options :hich select the data 0odel to -se
* !dditionally, for tools :hich in"o2e an -nderlying "0 =<5<foo=
* options are t-rned into =<foo= options to the "0 'his option
* filtering is handled in a n-0.er of places in the la-ncher, so0e of
* it in 0achine<dependent code &n this file, the f-nction
* Chec256>'ype re0o"es "0 style options and 'ranslate!pplication!rgs
* re0o"es =<5= prefi;es On -ni; platfor0s, the
* CreateE;ec-tionEn"iron0ent f-nction fro0 the -ni; /a"a70dc file
* processes and re0o"es <d?n@ options Ao:e"er, in case
* CreateE;ec-tionEn"iron0ent does not need to e;ec .eca-se
* $+7$&B#!#(7%!'A is set accepta.ly and the data 0odel does not need
* to .e changed, %arse!rg-0ents :ill screen o-t the red-ndant <d?n@
* options and pre"ent the0 fro0 .eing passed to the "01 this is done
* .y -sing the 0achine<dependent call
* #e0o"a.le>achine+ependentOption
*/
Cincl-de ?stdioh@
Cincl-de ?stdli.h@
Cincl-de ?stringh@
Cincl-de ?/nih@
Cincl-de ?/"0h@
Cincl-de =/a"ah=
Cincl-de =0anifest7infoh=
Cincl-de ="ersion7co0ph=
Cincl-de =:ildcardh=
Cincl-de =splashscreenh=
Cifndef *,$$76E#3&O)
Cdefine *,$$76E#3&O) 5+97>!5O#76E#3&O) == 5+97>&)O#76E#3&O)
Cendif
/*
* 'he follo:ing en"iron0ent "aria.le is -sed to infl-ence the .eha"ior
* of the /re e;ec4d thro-gh the 3elect6ersion ro-tine 'he co00and line
* options :hich specify the "ersion are not passed to the e;ec4d "ersion,
* .eca-se that /re 0ay .e an older "ersion :hich :o-ldn4t recogniDe the0
* 'his en"iron0ent "aria.le is 2no:n to this (and later) "ersion and ser"es
* to s-ppress the "ersion selection code 'his is not only for efficiency,
* .-t also for correctness, since any co00and line options ha"e .een
* re0o"ed :hich :o-ld ca-se any "al-e fo-nd in the 0anifest to .e -sed
* 'his :o-ld .e incorrect .eca-se the co00and line options are defined
* to ta2e precedence
*
* 'he "al-e associated :ith this en"iron0ent "aria.le is the >ainClass
* na0e fro0 :ithin the e;ec-ta.le /ar file (if any) 'his is strictly a
* perfor0ance enhance0ent to a"oid re<reading the /ar file 0anifest
*
* ! )O'E 'O +E6E$O%E#3E *or perfor0ance reasons it is i0portant that
* the progra0 i0age re0ain relati"ely s0all -ntil after 3elect6ersion
* CreateE;ec-tionEn"iron0ent ha"e finished their possi.ly rec-rsi"e
* processing Watch e"erything, .-t resist all te0ptations to -se 5a"a
* interfaces
*/
Cdefine E)67E)'#( =75!6!76E#3&O)73E'=
Cdefine 3%$!3A7*&$E7E)67E)'#( =75!6!73%$!3A7*&$E=
Cdefine 3%$!3A75!#7E)67E)'#( =75!6!73%$!3A75!#=
static /.oolean print6ersion F 5)&7*!$3E1 /* print and e;it */
static /.oolean sho:6ersion F 5)&7*!$3E1 /* print .-t contin-e */
static char *progna0e1
/.oolean 7la-ncher7de.-g F 5)&7*!$3E1
/*
* Entries for splash screen en"iron0ent "aria.les
* p-ten" is perfor0ed in 3elect6ersion We need
* the0 in 0e0ory -ntil ,nsetEn", so they are 0ade static
* glo.al instead of a-to local
*/
static char* splash7file7entry F ),$$1
static char* splash7/ar7entry F ),$$1
/*
* $ist of 6> options to .e specified :hen the 6> is created
*/
static 5a"a6>Option *options1
static int n-0Options, 0a;Options1
/*
* %rototypes for f-nctions internal to la-ncher
*/
static "oid 3etClass%ath(const char *s)1
static "oid 3elect6ersion(int argc, char **arg", char **0ain7class)1
static /.oolean %arse!rg-0ents(int *pargc, char ***parg", char **p/arfile,
char **pclassna0e, int *pret, const char */"0path)1
static /.oolean &nitialiDe56>(5a"a6> **p"0, 5)&En" **pen",
&n"ocation*-nctions *ifn)1
static /string )e:%latfor03tring(5)&En" *en", char *s)1
static /o./ect!rray )e:%latfor03tring!rray(5)&En" *en", char **str", int strc)1
static /class $oadClass(5)&En" *en", char *na0e)1
static /string 8et>ainClass)a0e(5)&En" *en", char */arna0e)1
static "oid 3et5a"aCo00and$ine%rop(char* classna0e, char* /arfile, int argc, char** arg")1
static "oid 3et5a"a$a-ncher%rop("oid)1
Cifdef 5!6!7!#83
static "oid 'ranslate!pplication!rgs(int *pargc, char ***parg")1
static /.oolean !dd!pplicationOptions("oid)1
Cendif
static "oid %rint5a"a6ersion(5)&En" *en")1
static "oid %rint,sage("oid)1
static /int %rintG,sage(const char */"0path)1
static "oid 3et%aths(int argc, char **arg")1
/* >a;i0-0 s-pported entries fro0 /"0cfg */
Cdefine &)&'7>!G79)OW)76>3 H0
/* 6al-es for "0descflag */
Cdefine 6>7,)9)OW) <H
Cdefine 6>79)OW) 0
Cdefine 6>7!$&!3E+7'O H
Cdefine 6>7W!#) 2
Cdefine 6>7E##O# I
Cdefine 6>7&*73E#6E#7C$!33 J
Cdefine 6>7&8)O#E K
str-ct "0desc L
char *na0e1
int flag1
char *alias1
char *ser"er7class1
M1
static str-ct "0desc *2no:n6>s F ),$$1
static int 2no:n6>sCo-nt F 01
static int 2no:n6>s$i0it F 01
static "oid 8ro:9no:n6>s()1
static int 9no:n6>&nde;(const char* na0e)1
static "oid *ree9no:n6>s()1
static "oid 3ho:3plash3creen()1
/.oolean 3er"erClass>achine()1
/* flag :hich if set s-ppresses error 0essages fro0 the la-ncher */
static int noE;itError>essage F 01
/*
* #-nning 5a"a code in pri0ordial thread ca-sed 0any pro.le0s We :ill
* create a ne: thread to in"o2e 56> 3ee 6IH6HNO for 0ore infor0ation
*/
static /long thread3tac23iDe F 01 /* stac2 siDe of the ne: thread */
int 5)&C!$$ 5a"a>ain("oid * args)1 /* entry point */
str-ct 5a"a>ain!rgs L
int argc1
char ** arg"1
char * /arfile1
char * classna0e1
&n"ocation*-nctions ifn1
M1
/*
* Entry point
*/
int
0ain(int argc, char ** arg")
L
char */arfile F 01
char *classna0e F 01
char *s F 01
char *0ain7class F ),$$1
int ret1
&n"ocation*-nctions ifn1
/long start, end1
char /repathP>!G%!'A$E)Q, /"0pathP>!G%!'A$E)Q1
char ** original7arg" F arg"1
if (geten"(=75!6!7$!,)CAE#7+EB,8=) RF 0) L
7la-ncher7de.-g F 5)&7'#,E1
printf(=<<<<75!6!7$!,)CAE#7+EB,8<<<<Sn=)1
M
/*
* >a2e s-re the specified "ersion of the 5#E is r-nning
*
* 'here are three things to note a.o-t the 3elect6ersion() ro-tineE
* H) &f the "ersion r-nning isn4t correct, this ro-tine doesn4t
* ret-rn (either the correct "ersion has .een e;ec4d or an error
* :as iss-ed)
* 2) !rgc and !rg" in this scope are *not* altered .y this ro-tine
* &t is the responsi.ility of s-.seT-ent code to ignore the
* arg-0ents handled .y this ro-tine
* I) !s a side<effect, the "aria.le =0ain7class= is g-aranteed to
* .e set (if it sho-ld e"er .e set) 'his isn4t e;actly the
* poster child for str-ct-red progra00ing, .-t it is a s0all
* price to pay for not processing a /ar file operand t:ice
* ()oteE 'his side effect has .een disa.led 3ee co00ent on
* .-gid K0I026K .elo:)
*/
3elect6ersion(argc, arg", U0ain7class)1
/* copy original arg" */
L
int i1
original7arg" F (char**)5$&7>e0!lloc(siDeof(char*)*(argcVH))1
for(i F 01 i ? argcVH1 iVV)
original7arg"PiQ F arg"PiQ1
M
CreateE;ec-tionEn"iron0ent(Uargc, Uarg",
/repath, siDeof(/repath),
/"0path, siDeof(/"0path),
original7arg")1
ifnCreate5a"a6> F 01
ifn8et+efa-lt5a"a6>&nit!rgs F 01
if (7la-ncher7de.-g)
start F Co-nter8et()1
if (R$oad5a"a6>(/"0path, Uifn)) L
e;it(6)1
M
if (7la-ncher7de.-g) L
end F Co-nter8et()1
printf(=%ld 0icro seconds to $oad5a"a6>Sn=,
(long)(/int)Co-nter2>icros(end<start))1
M
Cifdef 5!6!7!#83 /* /a"ac, /ar and friends */
progna0e F =/a"a=1
Celse /* /a"a, old/a"a, /a"a: and friends */
Cifdef %#O8)!>E
progna0e F %#O8)!>E1
Celse
progna0e F *arg"1
if ((s F strrchr(progna0e, *&$E73E%!#!'O#)) RF 0) L
progna0e F s V H1
M
Cendif /* %#O8)!>E */
Cendif /* 5!6!7!#83 */
VVarg"1
<<argc1
Cifdef 5!6!7!#83
/* %reprocess :rapper arg-0ents */
'ranslate!pplication!rgs(Uargc, Uarg")1
if (R!dd!pplicationOptions()) L
e;it(H)1
M
Cendif
/* 3et defa-lt C$!33%!'A */
if ((s F geten"(=C$!33%!'A=)) FF 0) L
s F ==1
M
Cifndef 5!6!7!#83
3etClass%ath(s)1
Cendif
/*
* %arse co00and line options1 if the ret-rn "al-e of
* %arse!rg-0ents is false, the progra0 sho-ld e;it
*/
if (R%arse!rg-0ents(Uargc, Uarg", U/arfile, Uclassna0e, Uret, /"0path)) L
e;it(ret)1
M
/* O"erride class path if </ar flag :as specified */
if (/arfile RF 0) L
3etClass%ath(/arfile)1
M
/* set the <+s-n/a"aco00and pse-do property */
3et5a"aCo00and$ine%rop(classna0e, /arfile, argc, arg")1
/* 3et the <+s-n/a"ala-ncher pse-do property */
3et5a"a$a-ncher%rop()1
/* set the <+s-n/a"ala-ncher* platfor0 properties */
3et5a"a$a-ncher%latfor0%rops()1
/* 3ho: the splash screen if needed */
3ho:3plash3creen()1
/*
* +one :ith all co00and line processing and potential re<e;ecs so
* clean -p the en"iron0ent
*/
("oid),nsetEn"(E)67E)'#()1
("oid),nsetEn"(3%$!3A7*&$E7E)67E)'#()1
("oid),nsetEn"(3%$!3A75!#7E)67E)'#()1
5$&7>e0*ree(splash7/ar7entry)1
5$&7>e0*ree(splash7file7entry)1
/*
* &f -ser doesn4t specify stac2 siDe, chec2 if 6> has a preference
* )ote that Aot3pot no longer s-pports 5)&76E#3&O)7H7H .-t it :ill
* ret-rn its defa-lt stac2 siDe thro-gh the init args str-ct-re
*/
if (thread3tac23iDe FF 0) L
str-ct 5+9H7H&nit!rgs argsH7H1
0e0set(("oid*)UargsH7H, 0, siDeof(argsH7H))1
argsH7H"ersion F 5)&76E#3&O)7H7H1
ifn8et+efa-lt5a"a6>&nit!rgs(UargsH7H)1 /* ignore ret-rn "al-e */
if (argsH7H/a"a3tac23iDe @ 0) L
thread3tac23iDe F argsH7H/a"a3tac23iDe1
M
M
L /* Create a ne: thread to create 56> and in"o2e 0ain 0ethod */
str-ct 5a"a>ain!rgs args1
argsargc F argc1
argsarg" F arg"1
args/arfile F /arfile1
argsclassna0e F classna0e1
argsifn F ifn1
ret-rn Contin-e&n)e:'hread(5a"a>ain, thread3tac23iDe, ("oid*)Uargs)1
M
M
int 5)&C!$$
5a"a>ain("oid * 7args)
L
str-ct 5a"a>ain!rgs *args F (str-ct 5a"a>ain!rgs *)7args1
int argc F args<@argc1
char **arg" F args<@arg"1
char */arfile F args<@/arfile1
char *classna0e F args<@classna0e1
&n"ocation*-nctions ifn F args<@ifn1
5a"a6> *"0 F 01
5)&En" *en" F 01
/string 0ainClass)a0e1
/class 0ainClass1
/0ethod&+ 0ain&+1
/o./ect!rray 0ain!rgs1
int ret F 01
/long start, end1
/*
* Error 0essage to print or display1 .y defa-lt the 0essage :ill
* only .e displayed in a :indo:
*/
char * 0essage F =*atal e;ception occ-rred %rogra0 :ill e;it=1
/.oolean 0essage+est F 5)&7*!$3E1
/* &nitialiDe the "irt-al 0achine */
if (7la-ncher7de.-g)
start F Co-nter8et()1
if (R&nitialiDe56>(U"0, Uen", Uifn)) L
#eportError>essage(=Co-ld not create the 5a"a "irt-al 0achine=,
5)&7'#,E)1
e;it(H)1
M
if (print6ersion WW sho:6ersion) L
%rint5a"a6ersion(en")1
if ((*en")<@E;ceptionOcc-rred(en")) L
#eportE;ception+escription(en")1
goto lea"e1
M
if (print6ersion) L
ret F 01
0essage F ),$$1
goto lea"e1
M
if (sho:6ersion) L
fprintf(stderr, =Sn=)1
M
M
/* &f the -ser specified neither a class na0e nor a 5!# file */
if (/arfile FF 0 UU classna0e FF 0) L
%rint,sage()1
0essage F ),$$1
goto lea"e1
M
*ree9no:n6>s()1 /* after last possi.le %rint,sage() */
if (7la-ncher7de.-g) L
end F Co-nter8et()1
printf(=%ld 0icro seconds to &nitialiDe56>Sn=,
(long)(/int)Co-nter2>icros(end<start))1
M
/* !t this stage, argc/arg" ha"e the applications4 arg-0ents */
if (7la-ncher7de.-g) L
int i F 01
printf(=>ain<Class is 4%s4Sn=, classna0e X classna0e E ==)1
printf(=!pps4 argc is %dSn=, argc)1
for (1 i ? argc1 iVV) L
printf(= arg"P%2dQ F 4%s4Sn=, i, arg"PiQ)1
M
M
ret F H1
/*
* 8et the application4s 0ain class
*
* 3ee .-gid K0I026K 'he >ain<Class na0e has already .een parsed
* fro0 the 0anifest, .-t not parsed properly for ,'*<8 s-pport
* Aence the code here ignores the "al-e pre"io-sly e;tracted and
* -ses the pre<e;isting code to ree;tract the "al-e 'his is
* possi.ly an end of release cycle e;pedient Ao:e"er, it has
* also .een disco"ered that passing so0e character sets thro-gh
* the en"iron0ent has =strange= .eha"ior on so0e "ariants of
* Windo:s Aence, 0ay.e the 0anifest parsing code local to the
* la-ncher sho-ld ne"er .e enhanced
*
* Aence, f-t-re :or2 sho-ld eitherE
* H) Correct the local parsing code and "erify that the
* >ain<Class attri.-te gets properly passed thro-gh
* all en"iron0ents,
* 2) #e0o"e the "estages of 0aintaining 0ain7class thro-gh
* the en"iron0ent (and re0o"e these co00ents)
*/
if (/arfile RF 0) L
0ainClass)a0e F 8et>ainClass)a0e(en", /arfile)1
if ((*en")<@E;ceptionOcc-rred(en")) L
#eportE;ception+escription(en")1
goto lea"e1
M
if (0ainClass)a0e FF ),$$) L
const char * for0at F =*ailed to load >ain<Class 0anifest =
=attri.-te fro0Sn%s=1
0essage F (char*)5$&7>e0!lloc((strlen(for0at) V strlen(/arfile)) *
siDeof(char))1
sprintf(0essage, for0at, /arfile)1
0essage+est F 5)&7'#,E1
goto lea"e1
M
classna0e F (char *)(*en")<@8et3tring,'*Chars(en", 0ainClass)a0e, 0)1
if (classna0e FF ),$$) L
#eportE;ception+escription(en")1
goto lea"e1
M
0ainClass F $oadClass(en", classna0e)1
if(0ainClass FF ),$$) L /* e;ception occ-red */
const char * for0at F =Co-ld not find the 0ain classE %s %rogra0 :ill e;it=1
#eportE;ception+escription(en")1
0essage F (char *)5$&7>e0!lloc((strlen(for0at) V
strlen(classna0e)) * siDeof(char) )1
0essage+est F 5)&7'#,E1
sprintf(0essage, for0at, classna0e)1
goto lea"e1
M
(*en")<@#elease3tring,'*Chars(en", 0ainClass)a0e, classna0e)1
M else L
0ainClass)a0e F )e:%latfor03tring(en", classna0e)1
if (0ainClass)a0e FF ),$$) L
const char * for0at F =*ailed to load >ain ClassE %s=1
0essage F (char *)5$&7>e0!lloc((strlen(for0at) V strlen(classna0e)) *
siDeof(char) )1
sprintf(0essage, for0at, classna0e)1
0essage+est F 5)&7'#,E1
goto lea"e1
M
classna0e F (char *)(*en")<@8et3tring,'*Chars(en", 0ainClass)a0e, 0)1
if (classna0e FF ),$$) L
#eportE;ception+escription(en")1
goto lea"e1
M
0ainClass F $oadClass(en", classna0e)1
if(0ainClass FF ),$$) L /* e;ception occ-red */
const char * for0at F =Co-ld not find the 0ain classE %s %rogra0 :ill e;it=1
#eportE;ception+escription(en")1
0essage F (char *)5$&7>e0!lloc((strlen(for0at) V
strlen(classna0e)) * siDeof(char) )1
0essage+est F 5)&7'#,E1
sprintf(0essage, for0at, classna0e)1
goto lea"e1
M
(*en")<@#elease3tring,'*Chars(en", 0ainClass)a0e, classna0e)1
M
/* 8et the application4s 0ain 0ethod */
0ain&+ F (*en")<@8et3tatic>ethod&+(en", 0ainClass, =0ain=,
=(P$/a"a/lang/3tring1)6=)1
if (0ain&+ FF ),$$) L
if ((*en")<@E;ceptionOcc-rred(en")) L
#eportE;ception+escription(en")1
M else L
0essage F =)o 0ain 0ethod fo-nd in specified class=1
0essage+est F 5)&7'#,E1
M
goto lea"e1
M
L /* >a2e s-re the 0ain 0ethod is p-.lic */
/int 0ods1
/0ethod&+ 0id1
/o./ect o./ F (*en")<@'o#eflected>ethod(en", 0ainClass,
0ain&+, 5)&7'#,E)1
if( o./ FF ),$$) L /* e;ception occ-rred */
#eportE;ception+escription(en")1
goto lea"e1
M
0id F
(*en")<@8et>ethod&+(en",
(*en")<@8etO./ectClass(en", o./),
=get>odifiers=, =()&=)1
if ((*en")<@E;ceptionOcc-rred(en")) L
#eportE;ception+escription(en")1
goto lea"e1
M
0ods F (*en")<@Call&nt>ethod(en", o./, 0id)1
if ((0ods U H) FF 0) L /* if (R>odifieris%-.lic(0ods)) */
0essage F =>ain 0ethod not p-.lic=1
0essage+est F 5)&7'#,E1
goto lea"e1
M
M
/* B-ild arg-0ent array */
0ain!rgs F )e:%latfor03tring!rray(en", arg", argc)1
if (0ain!rgs FF ),$$) L
#eportE;ception+escription(en")1
goto lea"e1
M
/* &n"o2e 0ain 0ethod */
(*en")<@Call3tatic6oid>ethod(en", 0ainClass, 0ain&+, 0ain!rgs)1
/*
* 'he la-ncher4s e;it code (in the a.sence of calls to
* 3yste0e;it) :ill .e non<Dero if 0ain thre: an e;ception
*/
ret F (*en")<@E;ceptionOcc-rred(en") FF ),$$ X 0 E H1
/*
* +etach the 0ain thread so that it appears to ha"e ended :hen
* the application4s 0ain 0ethod e;its 'his :ill in"o2e the
* -nca-ght e;ception handler 0achinery if 0ain thre: an
* e;ception !n -nca-ght e;ception handler cannot change the
* la-ncher4s ret-rn code e;cept .y calling 3yste0e;it
*/
if ((*"0)<@+etachC-rrent'hread("0) RF 0) L
0essage F =Co-ld not detach 0ain thread=1
0essage+est F 5)&7'#,E1
ret F H1
goto lea"e1
M
0essage F ),$$1
lea"eE
/*
* Wait for all non<dae0on threads to end, then destroy the 6>
* 'his :ill act-ally create a tri"ial ne: 5a"a :aiter thread
* na0ed =+estroy5a"a6>=, .-t this :ill .e seen as a different
* thread fro0 the one that e;ec-ted 0ain, e"en tho-gh they are
* the sa0e C thread 'his allo:s 0ain'hread/oin() and
* 0ain'hreadis!li"e() to :or2 as e;pected
*/
(*"0)<@+estroy5a"a6>("0)1
if(0essage RF ),$$ UU RnoE;itError>essage)
#eportError>essage(0essage, 0essage+est)1
ret-rn ret1
M
/*
* Chec2s the co00and line options to find :hich 56> type :as
* specified &f no co00and line option :as gi"en for the 56> type,
* the defa-lt type is -sed 'he en"iron0ent "aria.le
* 5+97!$'E#)!'E76> and the co00and line option <GGalt/"0F are also
* chec2ed as :ays of specifying :hich 56> type to in"o2e
*/
char *
Chec25"0'ype(int *pargc, char ***arg", /.oolean spec-lati"e) L
int i, argi1
int argc1
char **ne:!rg"1
int ne:!rg"&d; F 01
int is6>'ype1
int /"0id; F <H1
char */"0type F geten"(=5+97!$'E#)!'E76>=)1
argc F *pargc1
/* 'o 0a2e things si0pler :e al:ays copy the arg" array */
ne:!rg" F 5$&7>e0!lloc((argc V H) * siDeof(char *))1
/* 'he progra0 na0e is al:ays present */
ne:!rg"Pne:!rg"&d;VVQ F (*arg")P0Q1
for (argi F H1 argi ? argc1 argiVV) L
char *arg F (*arg")PargiQ1
is6>'ype F 01
Cifdef 5!6!7!#83
if (argP0Q RF 4<4) L
ne:!rg"Pne:!rg"&d;VVQ F arg1
contin-e1
M
Celse
if (strc0p(arg, =<classpath=) FF 0 WW
strc0p(arg, =<cp=) FF 0) L
ne:!rg"Pne:!rg"&d;VVQ F arg1
argiVV1
if (argi ? argc) L
ne:!rg"Pne:!rg"&d;VVQ F (*arg")PargiQ1
M
contin-e1
M
if (argP0Q RF 4<4) .rea21
Cendif
/* +id the -ser pass an e;plicit 6> typeX */
i F 9no:n6>&nde;(arg)1
if (i @F 0) L
/"0type F 2no:n6>sP/"0id; F iQna0e V H1 /* s2ip the < */
is6>'ype F H1
*pargc F *pargc < H1
M
/* +id the -ser specify an =alternate= 6>X */
else if (strnc0p(arg, =<GGalt/"0F=, H0) FF 0 WW strnc0p(arg, =<5<GGalt/"0F=, H2) FF 0) L
is6>'ype F H1
/"0type F argV((argPHQFF4G4)X H0 E H2)1
/"0id; F <H1
M
if (Ris6>'ype) L
ne:!rg"Pne:!rg"&d;VVQ F arg1
M
M
/*
* *inish copying the arg-0ents if :e a.orted the a.o"e loop
* )O'E that if :e a.orted "ia =.rea2= then :e did )O' copy the
* last arg-0ent a.o"e, and in addition argi :ill .e less than
* argc
*/
:hile (argi ? argc) L
ne:!rg"Pne:!rg"&d;VVQ F (*arg")PargiQ1
argiVV1
M
/* arg" is n-ll<ter0inated */
ne:!rg"Pne:!rg"&d;Q F 01
/* Copy .ac2 arg" */
*arg" F ne:!rg"1
*pargc F ne:!rg"&d;1
/* -se the defa-lt 6> type if not specified (no alias processing) */
if (/"0type FF ),$$) L
char* res-lt F 2no:n6>sP0Qna0eVH1
/* ,se a different 6> type if :e are on a ser"er class 0achineX */
if ((2no:n6>sP0Qflag FF 6>7&*73E#6E#7C$!33) UU
(3er"erClass>achine() FF 5)&7'#,E)) L
res-lt F 2no:n6>sP0Qser"er7classVH1
M
if (7la-ncher7de.-g) L
printf(=+efa-lt 6>E %sSn=, res-lt)1
M
ret-rn res-lt1
M
/* if -sing an alternate 6>, no alias processing */
if (/"0id; ? 0)
ret-rn /"0type1
/* #esol"e aliases first */
L
int loopCo-nt F 01
:hile (2no:n6>sP/"0id;Qflag FF 6>7!$&!3E+7'O) L
int ne;t&d; F 9no:n6>&nde;(2no:n6>sP/"0id;Qalias)1
if (loopCo-nt @ 2no:n6>sCo-nt) L
if (Rspec-lati"e) L
#eportError>essage(=ErrorE Corr-pt /"0cfg file1 cycle in alias list=,
5)&7'#,E)1
e;it(H)1
M else L
ret-rn =E##O#=1
/* .rea21 */
M
M
if (ne;t&d; ? 0) L
if (Rspec-lati"e) L
#eportError>essage2(=ErrorE ,na.le to resol"e 6> alias %s=,
2no:n6>sP/"0id;Qalias, 5)&7'#,E)1
e;it(H)1
M else L
ret-rn =E##O#=1
M
M
/"0id; F ne;t&d;1
/"0type F 2no:n6>sP/"0id;Qna0eVH1
loopCo-ntVV1
M
M
s:itch (2no:n6>sP/"0id;Qflag) L
case 6>7W!#)E
if (Rspec-lati"e) L
fprintf(stderr, =WarningE %s 6> not s-pported1 %s 6> :ill .e -sedSn=,
/"0type, 2no:n6>sP0Qna0e V H)1
M
/* fall thro-gh */
case 6>7&8)O#EE
/"0type F 2no:n6>sP/"0id;F0Qna0e V H1
/* fall thro-gh */
case 6>79)OW)E
.rea21
case 6>7E##O#E
if (Rspec-lati"e) L
#eportError>essage2(=ErrorE %s 6> not s-pported=, /"0type, 5)&7'#,E)1
e;it(H)1
M else L
ret-rn =E##O#=1
M
M
ret-rn /"0type1
M
C define 9B (H02J,$)
C define >B (H02J,$ * 9B)
C define 8B (H02J,$ * >B)
/* copied fro0 Aot3pot f-nction =ato0ll()= */
static int
parse7stac27siDe(const char *s, /long *res-lt) L
/long n F 01
int args7read F sscanf(s, /long7for0at7specifier(), Un)1
if (args7read RF H) L
ret-rn 01
M
:hile (*s RF 4S04 UU *s @F 404 UU *s ?F 4N4) L
sVV1
M
// JO0KKJ0E illegal if 0ore characters are fo-nd after the first non<digit
if (strlen(s) @ H) L
ret-rn 01
M
s:itch (*s) L
case 4'4E case 4t4E
*res-lt F n * 8B * 9B1
ret-rn H1
case 484E case 4g4E
*res-lt F n * 8B1
ret-rn H1
case 4>4E case 404E
*res-lt F n * >B1
ret-rn H1
case 494E case 424E
*res-lt F n * 9B1
ret-rn H1
case 4S04E
*res-lt F n1
ret-rn H1
defa-ltE
/* Create 56> :ith defa-lt stac2 and let 6> handle 0alfor0ed <Gss string*/
ret-rn 01
M
M
/*
* !dds a ne: 6> option :ith the gi"en gi"en na0e and "al-e
*/
"oid
!ddOption(char *str, "oid *info)
L
/*
* E;pand options array if needed to acco00odate at least one 0ore
* 6> option
*/
if (n-0Options @F 0a;Options) L
if (options FF 0) L
0a;Options F J1
options F 5$&7>e0!lloc(0a;Options * siDeof(5a"a6>Option))1
M else L
5a"a6>Option *t0p1
0a;Options *F 21
t0p F 5$&7>e0!lloc(0a;Options * siDeof(5a"a6>Option))1
0e0cpy(t0p, options, n-0Options * siDeof(5a"a6>Option))1
5$&7>e0*ree(options)1
options F t0p1
M
M
optionsPn-0OptionsQoption3tring F str1
optionsPn-0OptionsVVQe;tra&nfo F info1
if (strnc0p(str, =<Gss=, J) FF 0) L
/long t0p1
if (parse7stac27siDe(str V J, Ut0p)) L
thread3tac23iDe F t0p1
M
M
M
static "oid
3etClass%ath(const char *s)
L
char *def1
s F 5$&7WildcardE;pandClasspath(s)1
def F 5$&7>e0!lloc(strlen(s) V J0)1
sprintf(def, =<+/a"aclasspathF%s=, s)1
!ddOption(def, ),$$)1
M
/*
* 'he 3elect6ersion() ro-tine ens-res that an appropriate "ersion of
* the 5#E is r-nning 'he specification for the appropriate "ersion
* is o.tained fro0 either the 0anifest of a /ar file (preferred) or
* fro0 co00and line options
* 'he ro-tine also parses splash screen co00and line options and
* passes on their "al-es in pri"ate en"iron0ent "aria.les
*/
static "oid
3elect6ersion(int argc, char **arg", char **0ain7class)
L
char *arg1
char **ne:7arg"1
char **ne:7argp1
char *operand1
char *"ersion F ),$$1
char */re F ),$$1
int /arflag F 01
int headlessflag F 01
int restrict7search F <H1 /* <H i0plies not 2no:n */
0anifest7info info1
char en"7entryP>!G)!>E$E) V 2JQ F E)67E)'#( =F=1
char *splash7file7na0e F ),$$1
char *splash7/ar7na0e F ),$$1
char *en"7in1
int res1
/*
* &f the "ersion has already .een selected, set *0ain7class
* :ith the "al-e passed thro-gh the en"iron0ent (if any) and
* si0ply ret-rn
*/
if ((en"7in F geten"(E)67E)'#()) RF ),$$) L
if (*en"7in RF 4S04)
*0ain7class F 5$&73tring+-p(en"7in)1
ret-rn1
M
/*
* 3can thro-gh the arg-0ents for options rele"ant to 0-ltiple 5#E
* s-pport *or reference, the co00and line synta; is defined asE
*
* 3()O%3&3
* /a"a PoptionsQ class Parg-0entQ
*
* /a"a PoptionsQ </ar file/ar Parg-0entQ
*
* !s the scan is perfor0ed, 0a2e a copy of the arg-0ent list :ith
* the "ersion specification options (ne: to HK) re0o"ed, so that
* a "ersion less than HK can .e e;ec4d
*
* )ote that d-e to the synta; of the nati"e Windo:s interface
* Create%rocess(), processing si0ilar to the follo:ing e;ists in
* the Windo:s platfor0 specific ro-tine E;ec5#E (in /a"a70dc)
* Changes here sho-ld .e reprod-ced there
*/
ne:7arg" F 5$&7>e0!lloc((argc V H) * siDeof(char*))1
ne:7arg"P0Q F arg"P0Q1
ne:7argp F Une:7arg"PHQ1
argc<<1
arg"VV1
:hile ((arg F *arg") RF 0 UU *arg FF 4<4) L
if (strnc0p(arg, =<"ersionE=, N) FF 0) L
"ersion F arg V N1
M else if (strc0p(arg, =</re<restrict<search=) FF 0) L
restrict7search F H1
M else if (strc0p(arg, =<no</re<restrict<search=) FF 0) L
restrict7search F 01
M else L
if (strc0p(arg, =</ar=) FF 0)
/arflag F H1
/* deal :ith =-nfort-nate= classpath synta; */
if ((strc0p(arg, =<classpath=) FF 0 WW strc0p(arg, =<cp=) FF 0) UU
(argc @F 2)) L
*ne:7argpVV F arg1
argc<<1
arg"VV1
arg F *arg"1
M

/*
* Chec2ing for headless tool2it option in the so0e :ay as !W' doesE
* =tr-e= 0eans tr-e and any other "al-e 0eans false
*/
if (strc0p(arg, =<+/a"aa:theadlessFtr-e=) FF 0) L
headlessflag F H1
M else if (strnc0p(arg, =<+/a"aa:theadlessF=, 20) FF 0) L
headlessflag F 01
M else if (strnc0p(arg, =<splashE=, 8) FF 0) L
splash7file7na0e F argV81
M
*ne:7argpVV F arg1
M
argc<<1
arg"VV1
M
if (argc ?F 0) L /* )o operandX %ossi.ly legit :ith <Pf-llQ"ersion */
operand F ),$$1
M else L
argc<<1
*ne:7argpVV F operand F *arg"VV1
M
:hile (argc<< @ 0) /* Copy o"er Parg-0entQ */
*ne:7argpVV F *arg"VV1
*ne:7argp F ),$$1
/*
* &f there is a /ar file, read the 0anifest &f the /arfile can4t .e
* read, the 0anifest can4t .e read fro0 the /ar file, or the 0anifest
* is corr-pt, iss-e the appropriate error 0essages and e;it
*
* E"en if there isn4t a /ar file, constr-ct a 0anifest7info str-ct-re
* containing the co00and line infor0ation &t4s a con"enient :ay to carry
* this data aro-nd
*/
if (/arflag UU operand) L
if ((res F 5$&7%arse>anifest(operand, Uinfo)) RF 0) L
if (res FF <H)
#eportError>essage2(=,na.le to access /arfile %s=,
operand, 5)&7'#,E)1
else
#eportError>essage2(=&n"alid or corr-pt /arfile %s=,
operand, 5)&7'#,E)1
e;it(H)1
M

/*
* Co00and line splash screen option sho-ld ha"e precedence
* o"er the 0anifest, so the 0anifest data is -sed only if
* splash7file7na0e has not .een initialiDed a.o"e d-ring co00and
* line parsing
*/
if (Rheadlessflag UU Rsplash7file7na0e UU infosplashscreen7i0age7file7na0e) L
splash7file7na0e F infosplashscreen7i0age7file7na0e1
splash7/ar7na0e F operand1
M
M else L
info0anifest7"ersion F ),$$1
info0ain7class F ),$$1
info/re7"ersion F ),$$1
info/re7restrict7search F 01
M

/*
* %assing on splash screen info in en"iron0ent "aria.les
*/
if (splash7file7na0e UU Rheadlessflag) L
char* splash7file7entry F 5$&7>e0!lloc(strlen(3%$!3A7*&$E7E)67E)'#( =F=)
Vstrlen(splash7file7na0e)VH)1
strcpy(splash7file7entry, 3%$!3A7*&$E7E)67E)'#( =F=)1
strcat(splash7file7entry, splash7file7na0e)1
p-ten"(splash7file7entry)1
M
if (splash7/ar7na0e UU Rheadlessflag) L
char* splash7/ar7entry F 5$&7>e0!lloc(strlen(3%$!3A75!#7E)67E)'#( =F=)
Vstrlen(splash7/ar7na0e)VH)1
strcpy(splash7/ar7entry, 3%$!3A75!#7E)67E)'#( =F=)1
strcat(splash7/ar7entry, splash7/ar7na0e)1
p-ten"(splash7/ar7entry)1
M
/*
* 'he 5#E<6ersion and 5#E<#estrict<3earch "al-es (if any) fro0 the
* 0anifest are o"er:ritten .y any specified on the co00and line
*/
if ("ersion RF ),$$)
info/re7"ersion F "ersion1
if (restrict7search RF <H)
info/re7restrict7search F restrict7search1
/*
* =6alid= ret-rns (other than -nreco"era.le errors) follo: 3et
* 0ain7class as a side<effect of this ro-tine
*/
if (info0ain7class RF ),$$)
*0ain7class F 5$&73tring+-p(info0ain7class)1
/*
* &f no "ersion selection infor0ation is fo-nd either on the co00and
* line or in the 0anifest, si0ply ret-rn
*/
if (info/re7"ersion FF ),$$) L
5$&7*ree>anifest()1
5$&7>e0*ree(ne:7arg")1
ret-rn1
M
/*
* Chec2 for correct synta; of the "ersion specification (53# K6)
*/
if (R5$&76alid6ersion3tring(info/re7"ersion)) L
#eportError>essage2(=3ynta; error in "ersion specification S=%sS==,
info/re7"ersion, 5)&7'#,E)1
e;it(H)1
M
/*
* *ind the appropriate 56> on the syste0 5-st to .e as forgi"ing as
* possi.le, if the standard algorith0s don4t locate an appropriate
* /re, chec2 to see if the one r-nning :ill satisfy the reT-ire0ents
* 'his can happen on syste0s :hich ha"en4t .een set<-p for 0-ltiple
* 5#E s-pport
*/
/re F $ocate5#E(Uinfo)1
if (7la-ncher7de.-g)
printf(=5#E<6ersion F %s, 5#E<#estrict<3earch F %s 3elected F %sSn=,
(info/re7"ersionXinfo/re7"ersionE=n-ll=),
(info/re7restrict7searchX=tr-e=E=false=), (/reX/reE=n-ll=))1
if (/re FF ),$$) L
if (5$&7!ccepta.le#elease(*,$$76E#3&O), info/re7"ersion)) L
5$&7*ree>anifest()1
5$&7>e0*ree(ne:7arg")1
ret-rn1
M else L
#eportError>essage2(
=,na.le to locate 5#E 0eeting specification S=%sS==,
info/re7"ersion, 5)&7'#,E)1
e;it(H)1
M
M
/*
* &f &40 not the chosen one, e;ec the chosen one #et-rning fro0
* E;ec5#E indicates that & a0 indeed the chosen one
*
* 'he pri"ate en"iron0ent "aria.le 75!6!76E#3&O)73E' is -sed to
* pre"ent the chosen one fro0 re<reading the 0anifest file and
* -sing the "al-es fo-nd :ithin to o"erride the (potential) co00and
* line flags stripped fro0 arg" (.eca-se the target 0ay not
* -nderstand the0) %assing the >ainClass "al-e is an opti0iDation
* to a"oid locating, e;panding and parsing the 0anifest e;tra
* ti0es
*/
if (info0ain7class RF ),$$) L
if (strlen(info0ain7class) ?F >!G)!>E$E)) L
("oid)strcat(en"7entry, info0ain7class)1
M else L
#eportError>essage(=ErrorE 0ain<classE attri.-te e;ceeds syste0 li0itsSn=, 5)&7'#,E)1
e;it(H)1
M
M
("oid)p-ten"(en"7entry)1
E;ec5#E(/re, ne:7arg")1
5$&7*ree>anifest()1
5$&7>e0*ree(ne:7arg")1
ret-rn1
M
/*
* %arses co00and line arg-0ents #et-rns 5)&7*!$3E if la-ncher
* sho-ld e;it :itho-t starting "0 (eg certain "ersion and -sage
* options)1 ret-rns 5)&7'#,E if "0 needs to .e started to process
* gi"en options *pret (the la-ncher process ret-rn "al-e) is set to
* 0 for a nor0al e;it
*/
static /.oolean
%arse!rg-0ents(int *pargc, char ***parg", char **p/arfile,
char **pclassna0e, int *pret, const char */"0path)
L
int argc F *pargc1
char **arg" F *parg"1
/.oolean /arflag F 5)&7*!$3E1
char *arg1
*pret F H1
:hile ((arg F *arg") RF 0 UU *arg FF 4<4) L
arg"VV1 <<argc1
if (strc0p(arg, =<classpath=) FF 0 WW strc0p(arg, =<cp=) FF 0) L
if (argc ? H) L
#eportError>essage2(=%s reT-ires class path specification=,
arg, 5)&7'#,E)1
%rint,sage()1
ret-rn 5)&7*!$3E1
M
3etClass%ath(*arg")1
arg"VV1 <<argc1
M else if (strc0p(arg, =</ar=) FF 0) L
/arflag F 5)&7'#,E1
M else if (strc0p(arg, =<help=) FF 0 WW
strc0p(arg, =<h=) FF 0 WW
strc0p(arg, =<X=) FF 0) L
%rint,sage()1
*pret F 01
ret-rn 5)&7*!$3E1
M else if (strc0p(arg, =<"ersion=) FF 0) L
print6ersion F 5)&7'#,E1
ret-rn 5)&7'#,E1
M else if (strc0p(arg, =<sho:"ersion=) FF 0) L
sho:6ersion F 5)&7'#,E1
M else if (strc0p(arg, =<G=) FF 0) L
*pret F %rintG,sage(/"0path)1
ret-rn 5)&7*!$3E1
/*
* 'he follo:ing case pro"ide .ac2:ard co0pati.ility :ith old<style
* co00and line options
*/
M else if (strc0p(arg, =<f-ll"ersion=) FF 0) L
fprintf(stderr, =%s f-ll "ersion S=%sS=Sn=, progna0e,
*,$$76E#3&O))1
*pret F 01
ret-rn 5)&7*!$3E1
M else if (strc0p(arg, =<"er.osegc=) FF 0) L
!ddOption(=<"er.oseEgc=, ),$$)1
M else if (strc0p(arg, =<t=) FF 0) L
!ddOption(=<Gt=, ),$$)1
M else if (strc0p(arg, =<t0=) FF 0) L
!ddOption(=<Gt0=, ),$$)1
M else if (strc0p(arg, =<de.-g=) FF 0) L
!ddOption(=<Gde.-g=, ),$$)1
M else if (strc0p(arg, =<noclassgc=) FF 0) L
!ddOption(=<Gnoclassgc=, ),$$)1
M else if (strc0p(arg, =<Gf-t-re=) FF 0) L
!ddOption(=<G"erifyEall=, ),$$)1
M else if (strc0p(arg, =<"erify=) FF 0) L
!ddOption(=<G"erifyEall=, ),$$)1
M else if (strc0p(arg, =<"erifyre0ote=) FF 0) L
!ddOption(=<G"erifyEre0ote=, ),$$)1
M else if (strc0p(arg, =<no"erify=) FF 0) L
!ddOption(=<G"erifyEnone=, ),$$)1
M else if (strc0p(arg, =<GGs-ppressE;it>essage=) FF 0) L
noE;itError>essage F H1
M else if (strnc0p(arg, =<prof=, K) FF 0) L
char *p F arg V K1
char *t0p F 5$&7>e0!lloc(strlen(arg) V K0)1
if (*p) L
sprintf(t0p, =<Gr-nhprofEcp-Fold,fileF%s=, p V H)1
M else L
sprintf(t0p, =<Gr-nhprofEcp-Fold,fileF/a"aprof=)1
M
!ddOption(t0p, ),$$)1
M else if (strnc0p(arg, =<ss=, I) FF 0 WW
strnc0p(arg, =<oss=, J) FF 0 WW
strnc0p(arg, =<0s=, I) FF 0 WW
strnc0p(arg, =<0;=, I) FF 0) L
char *t0p F 5$&7>e0!lloc(strlen(arg) V 6)1
sprintf(t0p, =<G%s=, arg V H)1 /* s2ip 4<4 */
!ddOption(t0p, ),$$)1
M else if (strc0p(arg, =<chec2so-rce=) FF 0 WW
strc0p(arg, =<cs=) FF 0 WW
strc0p(arg, =<noasyncgc=) FF 0) L
/* )o longer s-pported */
fprintf(stderr,
=WarningE %s option is no longer s-pportedSn=,
arg)1
M else if (strnc0p(arg, =<"ersionE=, N) FF 0 WW
strc0p(arg, =<no</re<restrict<search=) FF 0 WW
strc0p(arg, =</re<restrict<search=) FF 0 WW
strnc0p(arg, =<splashE=, 8) FF 0) L
1 /* &gnore 0achine independent options already handled */
M else if (#e0o"a.le>achine+ependentOption(arg) ) L
1 /* +o not pass option to "0 */
M
else L
!ddOption(arg, ),$$)1
M
M
if (<<argc @F 0) L
if (/arflag) L
*p/arfile F *arg"VV1
*pclassna0e F 01
M else L
*p/arfile F 01
*pclassna0e F *arg"VV1
M
*pargc F argc1
*parg" F arg"1
M
ret-rn 5)&7'#,E1
M
/*
* &nitialiDes the 5a"a 6irt-al >achine !lso frees options array :hen
* finished
*/
static /.oolean
&nitialiDe56>(5a"a6> **p"0, 5)&En" **pen", &n"ocation*-nctions *ifn)
L
5a"a6>&nit!rgs args1
/int r1
0e0set(Uargs, 0, siDeof(args))1
args"ersion F 5)&76E#3&O)7H721
argsnOptions F n-0Options1
argsoptions F options1
argsignore,nrecogniDed F 5)&7*!$3E1
if (7la-ncher7de.-g) L
int i F 01
printf(=5a"a6> argsESn =)1
printf(="ersion 0;%08l;, =, (long)args"ersion)1
printf(=ignore,nrecogniDed is %s, =,
argsignore,nrecogniDed X =5)&7'#,E= E =5)&7*!$3E=)1
printf(=nOptions is %ldSn=, (long)argsnOptions)1
for (i F 01 i ? n-0Options1 iVV)
printf(= optionP%2dQ F 4%s4Sn=,
i, argsoptionsPiQoption3tring)1
M
r F ifn<@Create5a"a6>(p"0, ("oid **)pen", Uargs)1
5$&7>e0*ree(options)1
ret-rn r FF 5)&7O91
M
Cdefine ),$$7CAEC90(e) if ((e) FF 0) ret-rn 0
Cdefine ),$$7CAEC9(e) if ((e) FF 0) ret-rn
static /string platfor0Encoding F ),$$1
static /string get%latfor0Encoding(5)&En" *en") L
if (platfor0Encoding FF ),$$) L
/string propna0e F (*en")<@)e:3tring,'*(en", =s-n/n-encoding=)1
if (propna0e) L
/class cls1
/0ethod&+ 0id1
),$$7CAEC90 (cls F (*en")<@*indClass(en", =/a"a/lang/3yste0=))1
),$$7CAEC90 (0id F (*en")<@8et3tatic>ethod&+(
en", cls,
=get%roperty=,
=($/a"a/lang/3tring1)$/a"a/lang/3tring1=))1
platfor0Encoding F (*en")<@Call3taticO./ect>ethod (
en", cls, 0id, propna0e)1
M
M
ret-rn platfor0Encoding1
M
static /.oolean isEncoding3-pported(5)&En" *en", /string enc) L
/class cls1
/0ethod&+ 0id1
),$$7CAEC90 (cls F (*en")<@*indClass(en", =/a"a/nio/charset/Charset=))1
),$$7CAEC90 (0id F (*en")<@8et3tatic>ethod&+(
en", cls,
=is3-pported=,
=($/a"a/lang/3tring1)Y=))1
ret-rn (*en")<@Call3taticBoolean>ethod(en", cls, 0id, enc)1
M
/*
* #et-rns a ne: 5a"a string o./ect for the specified platfor0 string
*/
static /string
)e:%latfor03tring(5)&En" *en", char *s)
L
int len F (int)strlen(s)1
/class cls1
/0ethod&+ 0id1
/.yte!rray ary1
/string enc1
if (s FF ),$$)
ret-rn 01
enc F get%latfor0Encoding(en")1
ary F (*en")<@)e:Byte!rray(en", len)1
if (ary RF 0) L
/string str F 01
(*en")<@3etByte!rray#egion(en", ary, 0, len, (/.yte *)s)1
if (R(*en")<@E;ceptionOcc-rred(en")) L
if (isEncoding3-pported(en", enc) FF 5)&7'#,E) L
),$$7CAEC90(cls F (*en")<@*indClass(en", =/a"a/lang/3tring=))1
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en", cls, =?init@=,
=(PB$/a"a/lang/3tring1)6=))1
str F (*en")<@)e:O./ect(en", cls, 0id, ary, enc)1
M else L
/*&f the encoding specified in s-n/n-encoding is not
endorsed .y =Charsetis3-pported= :e ha"e to fall .ac2
to -se 3tring(.ytePQ) e;plicitly here :itho-t specifying
the encoding na0e, in :hich the 3tringCoding class :ill
pic2-p the iso<88KN<H as the fall.ac2 con"erter for -s
*/
),$$7CAEC90(cls F (*en")<@*indClass(en", =/a"a/lang/3tring=))1
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en", cls, =?init@=,
=(PB)6=))1
str F (*en")<@)e:O./ect(en", cls, 0id, ary)1
M
(*en")<@+elete$ocal#ef(en", ary)1
ret-rn str1
M
M
ret-rn 01
M
/*
* #et-rns a ne: array of 5a"a string o./ects for the specified
* array of platfor0 strings
*/
static /o./ect!rray
)e:%latfor03tring!rray(5)&En" *en", char **str", int strc)
L
/array cls1
/array ary1
int i1
),$$7CAEC90(cls F (*en")<@*indClass(en", =/a"a/lang/3tring=))1
),$$7CAEC90(ary F (*en")<@)e:O./ect!rray(en", strc, cls, 0))1
for (i F 01 i ? strc1 iVV) L
/string str F )e:%latfor03tring(en", *str"VV)1
),$$7CAEC90(str)1
(*en")<@3etO./ect!rrayEle0ent(en", ary, i, str)1
(*en")<@+elete$ocal#ef(en", str)1
M
ret-rn ary1
M
/*
* $oads a class, con"ert the 44 to 4/4
*/
static /class
$oadClass(5)&En" *en", char *na0e)
L
char *.-f F 5$&7>e0!lloc(strlen(na0e) V H)1
char *s F .-f, *t F na0e, c1
/class cls1
/long start, end1
if (7la-ncher7de.-g)
start F Co-nter8et()1
do L
c F *tVV1
*sVV F (c FF 44) X 4/4 E c1
M :hile (c RF 4S04)1
cls F (*en")<@*indClass(en", .-f)1
5$&7>e0*ree(.-f)1
if (7la-ncher7de.-g) L
end F Co-nter8et()1
printf(=%ld 0icro seconds to load 0ain classSn=,
(long)(/int)Co-nter2>icros(end<start))1
printf(=<<<<75!6!7$!,)CAE#7+EB,8<<<<Sn=)1
M
ret-rn cls1
M
/*
* #et-rns the 0ain class na0e for the specified /ar file
*/
static /string
8et>ainClass)a0e(5)&En" *en", char */arna0e)
L
Cdefine >!&)7C$!33 =>ain<Class=
/class cls1
/0ethod&+ 0id1
/o./ect /ar, 0an, attr1
/string str, res-lt F 01
),$$7CAEC90(cls F (*en")<@*indClass(en", =/a"a/-til//ar/5ar*ile=))1
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en", cls, =?init@=,
=($/a"a/lang/3tring1)6=))1
),$$7CAEC90(str F )e:%latfor03tring(en", /arna0e))1
),$$7CAEC90(/ar F (*en")<@)e:O./ect(en", cls, 0id, str))1
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en", cls, =get>anifest=,
=()$/a"a/-til//ar/>anifest1=))1
0an F (*en")<@CallO./ect>ethod(en", /ar, 0id)1
if (0an RF 0) L
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en",
(*en")<@8etO./ectClass(en", 0an),
=get>ain!ttri.-tes=,
=()$/a"a/-til//ar/!ttri.-tes1=))1
attr F (*en")<@CallO./ect>ethod(en", 0an, 0id)1
if (attr RF 0) L
),$$7CAEC90(0id F (*en")<@8et>ethod&+(en",
(*en")<@8etO./ectClass(en", attr),
=get6al-e=,
=($/a"a/lang/3tring1)$/a"a/lang/3tring1=))1
),$$7CAEC90(str F )e:%latfor03tring(en", >!&)7C$!33))1
res-lt F (*en")<@CallO./ect>ethod(en", attr, 0id, str)1
M
M
ret-rn res-lt1
M
Cifdef 5!6!7!#83
static char */a"a7argsPQ F 5!6!7!#831
static char *app7classpathPQ F !%%7C$!33%!'A1
/*
* *or tools, con"ert co00and line args th-sE
* /a"ac <cp fooEfoo/=*= <5<0sI20
* /a"a <0sI20 <cp 5$&7WildcardE;pandClasspath(fooEfoo/=*=)
*/
static "oid
'ranslate!pplication!rgs(int *pargc, char ***parg")
L
const int ),>7!#83 F (siDeof(/a"a7args) / siDeof(char *))1
int argc F *pargc1
char **arg" F *parg"1
int nargc F argc V ),>7!#831
char **narg" F 5$&7>e0!lloc((nargc V H) * siDeof(char *))1
int i1
*pargc F nargc1
*parg" F narg"1
/* Copy the 6> arg-0ents (ie prefi;ed :ith <5) */
for (i F 01 i ? ),>7!#831 iVV) L
char *arg F /a"a7argsPiQ1
if (argP0Q FF 4<4 UU argPHQ FF 454) L
*narg"VV F arg V 21
M
M
for (i F 01 i ? argc1 iVV) L
char *arg F arg"PiQ1
if (argP0Q FF 4<4 UU argPHQ FF 454) L
if (argP2Q FF 4S04) L
#eportError>essage(=ErrorE the <5 option sho-ld not .e =
=follo:ed .y a space=, 5)&7'#,E)1
e;it(H)1
M
*narg"VV F arg V 21
M
M
/* Copy the rest of the arg-0ents */
for (i F 01 i ? ),>7!#831 iVV) L
char *arg F /a"a7argsPiQ1
if (argP0Q RF 4<4 WW argPHQ RF 454) L
*narg"VV F arg1
M
M
for (i F 01 i ? argc1 iVV) L
char *arg F arg"PiQ1
if (argP0Q FF 4<4) L
if (argPHQ FF 454)
contin-e1
Cifdef EG%!)+7C$!33%!'A7W&$+C!#+3
if (argPHQ FF 4c4
UU (strc0p(arg, =<cp=) FF 0 WW
strc0p(arg, =<classpath=) FF 0)
UU i ? argc < H) L
*narg"VV F arg1
*narg"VV F (char *) 5$&7WildcardE;pandClasspath(arg"PiVHQ)1
iVV1
contin-e1
M
Cendif
M
*narg"VV F arg1
M
*narg" F 01
M
/*
* *or o-r tools, :e try to add I 6> optionsE
* <+en"classpathF?en"cp@
* <+applicationho0eF?appho0e@
* <+/a"aclasspathF?appcp@
* ?en"cp@ is the -ser4s setting of C$!33%!'A << for instance the -ser
* tells /a"ac :here to find .inary classes thro-gh this en"iron0ent
* "aria.le )otice that -sers :ill .e a.le to co0pile against o-r
* tools classes (s-ntools/a"ac>ain) only if they e;plicitly add
* tools/ar to C$!33%!'A
* ?appho0e@ is the directory :here the application is installed
* ?appcp@ is the classpath to :here o-r apps4 classfiles are
*/
static /.oolean
!dd!pplicationOptions()
L
const int ),>7!%%7C$!33%!'A F (siDeof(app7classpath) / siDeof(char *))1
char *en"cp, *appcp, *appho0e1
char ho0eP>!G%!'A$E)Q1 /* application ho0e */
char separatorPQ F L %!'A73E%!#!'O#, 4S04 M1
int siDe, i1
int strlenAo0e1
L
const char *s F geten"(=C$!33%!'A=)1
if (s) L
s F (char *) 5$&7WildcardE;pandClasspath(s)1
/* J0 for <+en"classpathF */
en"cp F (char *)5$&7>e0!lloc(strlen(s) V J0)1
sprintf(en"cp, =<+en"classpathF%s=, s)1
!ddOption(en"cp, ),$$)1
M
M
if (R8et!pplicationAo0e(ho0e, siDeof(ho0e))) L
#eportError>essage(=Can4t deter0ine application ho0e=, 5)&7'#,E)1
ret-rn 5)&7*!$3E1
M
/* J0 for 4<+applicationho0eF4 */
appho0e F (char *)5$&7>e0!lloc(strlen(ho0e) V J0)1
sprintf(appho0e, =<+applicationho0eF%s=, ho0e)1
!ddOption(appho0e, ),$$)1
/* Ao: .ig is the application4s classpathX */
siDe F J01 /* J0E =<+/a"aclasspathF= */
strlenAo0e F (int)strlen(ho0e)1
for (i F 01 i ? ),>7!%%7C$!33%!'A1 iVV) L
siDe VF strlenAo0e V (int)strlen(app7classpathPiQ) V H1 /* HE separator */
M
appcp F (char *)5$&7>e0!lloc(siDe V H)1
strcpy(appcp, =<+/a"aclasspathF=)1
for (i F 01 i ? ),>7!%%7C$!33%!'A1 iVV) L
strcat(appcp, ho0e)1 /* cESprogra0 filesS0yapp */
strcat(appcp, app7classpathPiQ)1 /* Sli.S0yapp/ar */
strcat(appcp, separator)1 /* 1 */
M
appcpPstrlen(appcp)<HQ F 4S041 /* re0o"e trailing path separator */
!ddOption(appcp, ),$$)1
ret-rn 5)&7'#,E1
M
Cendif /* 5!6!7!#83 */
/*
* in/ect the <+s-n/a"aco00and pse-do property into the args str-ct-re
* this pse-do property is -sed in the Aot3pot 6> to e;pose the
* 5a"a class na0e and arg-0ents to the 0ain 0ethod to the 6> 'he
* Aot3pot 6> -ses this pse-do property to store the 5a"a class na0e
* (or /ar file na0e) and the arg-0ents to the class4s 0ain 0ethod
* to the instr-0entation 0e0ory region 'he s-n/a"aco00and pse-do
* property is not e;ported .y Aot3pot to the 5a"a layer
*/
"oid
3et5a"aCo00and$ine%rop(char *classna0e, char */arfile,
int argc, char **arg")
L
int i F 01
siDe7t len F 01
char* /a"aCo00and F ),$$1
char* dash+str F =<+s-n/a"aco00andF=1
if (classna0e FF ),$$ UU /arfile FF ),$$) L
/* -ne;pected, one of these sho-ld .e set /-st ret-rn :itho-t
* setting the property
*/
ret-rn1
M
/* if the class na0e is not set, then -se the /arfile na0e */
if (classna0e FF ),$$) L
classna0e F /arfile1
M
/* deter0ine the a0o-nt of 0e0ory to allocate ass-0ing
* the indi"id-al co0ponents :ill .e space separated
*/
len F strlen(classna0e)1
for (i F 01 i ? argc1 iVV) L
len VF strlen(arg"PiQ) V H1
M
/* allocate the 0e0ory */
/a"aCo00and F (char*) 5$&7>e0!lloc(len V strlen(dash+str) V H)1
/* .-ild the <+ string */
*/a"aCo00and F 4S041
strcat(/a"aCo00and, dash+str)1
strcat(/a"aCo00and, classna0e)1
for (i F 01 i ? argc1 iVV) L
/* the co0ponents of the string are space separated &n
* the case of e0.edded :hite space, the relationship of
* the :hite space separated co0ponents to their tr-e
* positional arg-0ents :ill .e a0.ig-o-s 'his iss-e 0ay
* .e addressed in a f-t-re release
*/
strcat(/a"aCo00and, = =)1
strcat(/a"aCo00and, arg"PiQ)1
M
!ddOption(/a"aCo00and, ),$$)1
M
/*
* 56> :o-ld li2e to 2no: if it4s created .y a standard 3-n la-ncher, or .y
* -ser nati"e application, the follo:ing property indicates the for0er
*/
"oid 3et5a"a$a-ncher%rop() L
!ddOption(=<+s-n/a"ala-ncherF3,)73'!)+!#+=, ),$$)1
M
/*
* %rints the "ersion infor0ation fro0 the /a"a"ersion and other properties
*/
static "oid
%rint5a"a6ersion(5)&En" *en")
L
/class "er1
/0ethod&+ print1
),$$7CAEC9("er F (*en")<@*indClass(en", =s-n/0isc/6ersion=))1
),$$7CAEC9(print F (*en")<@8et3tatic>ethod&+(en", "er, =print=, =()6=))1
(*en")<@Call3tatic6oid>ethod(en", "er, print)1
M
/*
* %rints defa-lt -sage 0essage
*/
static "oid
%rint,sage("oid)
L
int i1
fprintf(stdo-t,
=,sageE %s P<optionsQ class PargsQSn=
= (to e;ec-te a class)Sn=
= or %s P<optionsQ </ar /arfile PargsQSn=
= (to e;ec-te a /ar file)Sn=
=Sn=
=:here options incl-deESn=,
progna0e,
progna0e)1
%rint>achine+ependentOptions()1
if ((2no:n6>sP0Qflag FF 6>79)OW)) WW
(2no:n6>sP0Qflag FF 6>7&*73E#6E#7C$!33)) L
fprintf(stdo-t, = %sSt to select the S=%sS= 6>Sn=,
2no:n6>sP0Qna0e, 2no:n6>sP0Qna0eVH)1
M
for (iFH1 i?2no:n6>sCo-nt1 iVV) L
if (2no:n6>sPiQflag FF 6>79)OW))
fprintf(stdo-t, = %sSt to select the S=%sS= 6>Sn=,
2no:n6>sPiQna0e, 2no:n6>sPiQna0eVH)1
M
for (iFH1 i?2no:n6>sCo-nt1 iVV) L
if (2no:n6>sPiQflag FF 6>7!$&!3E+7'O)
fprintf(stdo-t, = %sSt is a synony0 for =
=the S=%sS= 6> PdeprecatedQSn=,
2no:n6>sPiQna0e, 2no:n6>sPiQaliasVH)1
M
/* 'he first 2no:n 6> is the defa-lt */
L
const char* defa-lt6> F 2no:n6>sP0Qna0eVH1
const char* p-nct-ation F ==1
const char* reason F ==1
if ((2no:n6>sP0Qflag FF 6>7&*73E#6E#7C$!33) UU
(3er"erClass>achine() FF 5)&7'#,E)) L
defa-lt6> F 2no:n6>sP0Qser"er7classVH1
p-nct-ation F =, =1
reason F =.eca-se yo- are r-nning on a ser"er<class 0achineSn=1
M
fprintf(stdo-t, = 'he defa-lt 6> is %s%sSn=,
defa-lt6>, p-nct-ation)1
fprintf(stdo-t, = %sSn=,
reason)1
M
fprintf(stdo-t,
= <cp ?class search path of directories and Dip//ar files@Sn=
= <classpath ?class search path of directories and Dip//ar files@Sn=
= ! %c separated list of directories, 5!# archi"es,Sn=
= and Y&% archi"es to search for class filesSn=
= <+?na0e@F?"al-e@Sn=
= set a syste0 propertySn=
= <"er.osePEclassWgcW/niQSn=
= ena.le "er.ose o-tp-tSn=
= <"ersion print prod-ct "ersion and e;itSn=
= <"ersionE?"al-e@Sn=
= reT-ire the specified "ersion to r-nSn=
= <sho:"ersion print prod-ct "ersion and contin-eSn=
= </re<restrict<search W </re<no<restrict<searchSn=
= incl-de/e;cl-de -ser pri"ate 5#Es in the "ersion searchSn=
= <X <help print this help 0essageSn=
= <G print help on non<standard optionsSn=
= <eaPE?pac2agena0e@WE?classna0e@QSn=
= <ena.leassertionsPE?pac2agena0e@WE?classna0e@QSn=
= ena.le assertionsSn=
= <daPE?pac2agena0e@WE?classna0e@QSn=
= <disa.leassertionsPE?pac2agena0e@WE?classna0e@QSn=
= disa.le assertionsSn=
= <esa W <ena.lesyste0assertionsSn=
= ena.le syste0 assertionsSn=
= <dsa W <disa.lesyste0assertionsSn=
= disa.le syste0 assertionsSn=
= <agentli.E?li.na0e@PF?options@QSn=
= load nati"e agent li.rary ?li.na0e@, eg <agentli.EhprofSn=
= see also, <agentli.E/d:pFhelp and <agentli.EhprofFhelpSn=
= <agentpathE?pathna0e@PF?options@QSn=
= load nati"e agent li.rary .y f-ll pathna0eSn=
= </a"aagentE?/arpath@PF?options@QSn=
= load 5a"a progra00ing lang-age agent, see /a"alanginstr-0entSn=
= <splashE?i0agepath@Sn=
= sho: splash screen :ith specified i0ageSn=
,%!'A73E%!#!'O#)1
M
/*
* %rint -sage 0essage for <G options
*/
static /int
%rintG,sage(const char */"0path)
L
/*
! I2 .it c-shion to pre"ent .-ffer o"err-n, noting that
fopen(IC) 0ay fail if the .-ffer e;ceeds >!G%!'A$E)
*/
char pathP>!G%!'A$E)VI2Q1
char .-fPH28Q1
siDe7t n1
*&$E *fp1
static const char G-sage7t;tPQ F =/G-saget;t=1
strcpy(path, /"0path)1
/* )ote the *&$E73E%!#!'O# is platfor0 dependent */
strcpy(strrchr(path, *&$E73E%!#!'O#), G-sage7t;t)1
fp F fopen(path, =r=)1
if (fp FF 0) L
fprintf(stderr, =Can4t open %sSn=, path)1
ret-rn H1
M
:hile ((n F fread(.-f, H, siDeof(.-f), fp)) RF 0) L
f:rite(.-f, H, n, stdo-t)1
M
fclose(fp)1
ret-rn 01
M
/*
* #ead the /"0cfg file and fill the 2no:n56>sPQ array
*
* 'he f-nctionality of the /"0cfg file is s-./ect to change :itho-t
* notice and the 0echanis0 :ill .e re0o"ed in the f-t-re
*
* 'he le;ical str-ct-re of the /"0cfg file is as follo:sE
*
* /"0cfg EF L "0$ine M
* "0$ine EF 2no:n$ine
* W alias$ine
* W :arn$ine
* W ignore$ine
* W error$ine
* W predicate$ine
* W co00ent$ine
* 2no:n$ine EF flag =9)OW)= EO$
* :arn$ine EF flag =W!#)= EO$
* ignore$ine EF flag =&8)O#E= EO$
* error$ine EF flag =E##O#= EO$
* alias$ine EF flag =!$&!3E+7'O= flag EO$
* predicate$ine EF flag =&*73E#6E#7C$!33= flag EO$
* co00ent$ine EF =C= te;t EO$
* flag EF =<= identifier
*
* 'he se0antics are that :hen so0eone specifies a flag on the co00and lineE
* < if the flag appears on a 2no:n$ine, then the identifier is -sed as
* the na0e of the directory holding the 56> li.rary (the na0e of the 56>)
* < if the flag appears as the first flag on an alias$ine, the identifier
* of the second flag is -sed as the na0e of the 56>
* < if the flag appears on a :arn$ine, the identifier is -sed as the
* na0e of the 56>, .-t a :arning is generated
* < if the flag appears on an ignore$ine, the identifier is recogniDed as the
* na0e of a 56>, .-t the identifier is ignored and the defa-lt "0 -sed
* < if the flag appears on an error$ine, an error is generated
* < if the flag appears as the first flag on a predicate$ine, and
* the 0achine on :hich yo- are r-nning passes the predicate indicated,
* then the identifier of the second flag is -sed as the na0e of the 56>,
* other:ise the identifier of the first flag is -sed as the na0e of the 56>
* &f no flag is gi"en on the co00and line, the first "0$ine of the /"0cfg
* file deter0ines the na0e of the 56>
* %redicate$ines are only interpreted on first "0$ine of a /"0cfg file,
* since they only 0a2e sense if so0eone hasn4t specified the na0e of the
* 56> on the co00and line
*
* 'he intent of the /"0cfg file is to allo: se"eral 56> li.raries to
* .e installed in different s-.directories of a single 5#E installation,
* for space<sa"ings and con"enience in testing
* 'he intent is e;plicitly not to pro"ide a f-ll aliasing or predicate
* 0echanis0
*/
/int
#ead9no:n6>s(const char */repath, char * arch, /.oolean spec-lati"e)
L
*&$E */"0Cfg1
char /"0Cfg)a0eP>!G%!'A$E)V20Q1
char lineP>!G%!'A$E)V20Q1
int cnt F 01
int lineno F 01
/long start, end1
int "0'ype1
char *t0p%tr1
char *alt6>)a0e F ),$$1
char *ser"erClass6>)a0e F ),$$1
static char *:hite3pace F = St=1
if (7la-ncher7de.-g) L
start F Co-nter8et()1
M
strcpy(/"0Cfg)a0e, /repath)1
strcat(/"0Cfg)a0e, *&$E3E% =li.= *&$E3E%)1
strcat(/"0Cfg)a0e, arch)1
strcat(/"0Cfg)a0e, *&$E3E% =/"0cfg=)1

/"0Cfg F fopen(/"0Cfg)a0e, =r=)1
if (/"0Cfg FF ),$$) L
if (Rspec-lati"e) L
#eportError>essage2(=ErrorE co-ld not open Z%s4=, /"0Cfg)a0e,
5)&7'#,E)1
e;it(H)1
M else L
ret-rn <H1
M
M
:hile (fgets(line, siDeof(line), /"0Cfg) RF ),$$) L
"0'ype F 6>7,)9)OW)1
linenoVV1
if (lineP0Q FF 4C4)
contin-e1
if (lineP0Q RF 4<4) L
fprintf(stderr, =WarningE no leading < on line %d of Z%s4Sn=,
lineno, /"0Cfg)a0e)1
M
if (cnt @F 2no:n6>s$i0it) L
8ro:9no:n6>s(cnt)1
M
linePstrlen(line)<HQ F 4S041 /* re0o"e trailing ne:line */
t0p%tr F line V strcspn(line, :hite3pace)1
if (*t0p%tr FF 0) L
fprintf(stderr, =WarningE 0issing 6> type on line %d of Z%s4Sn=,
lineno, /"0Cfg)a0e)1
M else L
/* )-ll<ter0inate this string for 5$&73tring+-p .elo: */
*t0p%trVV F 01
t0p%tr VF strspn(t0p%tr, :hite3pace)1
if (*t0p%tr FF 0) L
fprintf(stderr, =WarningE 0issing 6> type on line %d of Z%s4Sn=,
lineno, /"0Cfg)a0e)1
M else L
if (Rstrnc0p(t0p%tr, =9)OW)=, strlen(=9)OW)=))) L
"0'ype F 6>79)OW)1
M else if (Rstrnc0p(t0p%tr, =!$&!3E+7'O=, strlen(=!$&!3E+7'O=))) L
t0p%tr VF strcspn(t0p%tr, :hite3pace)1
if (*t0p%tr RF 0) L
t0p%tr VF strspn(t0p%tr, :hite3pace)1
M
if (*t0p%tr FF 0) L
fprintf(stderr, =WarningE 0issing 6> alias on line %d of Z%s4Sn=,
lineno, /"0Cfg)a0e)1
M else L
/* )-ll ter0inate alt6>)a0e */
alt6>)a0e F t0p%tr1
t0p%tr VF strcspn(t0p%tr, :hite3pace)1
*t0p%tr F 01
"0'ype F 6>7!$&!3E+7'O1
M
M else if (Rstrnc0p(t0p%tr, =W!#)=, strlen(=W!#)=))) L
"0'ype F 6>7W!#)1
M else if (Rstrnc0p(t0p%tr, =&8)O#E=, strlen(=&8)O#E=))) L
"0'ype F 6>7&8)O#E1
M else if (Rstrnc0p(t0p%tr, =E##O#=, strlen(=E##O#=))) L
"0'ype F 6>7E##O#1
M else if (Rstrnc0p(t0p%tr,
=&*73E#6E#7C$!33=,
strlen(=&*73E#6E#7C$!33=))) L
t0p%tr VF strcspn(t0p%tr, :hite3pace)1
if (*t0p%tr RF 0) L
t0p%tr VF strspn(t0p%tr, :hite3pace)1
M
if (*t0p%tr FF 0) L
fprintf(stderr, =WarningE 0issing ser"er class 6> on line %d of Z%s4Sn=,
lineno, /"0Cfg)a0e)1
M else L
/* )-ll ter0inate ser"er class 6> na0e */
ser"erClass6>)a0e F t0p%tr1
t0p%tr VF strcspn(t0p%tr, :hite3pace)1
*t0p%tr F 01
"0'ype F 6>7&*73E#6E#7C$!331
M
M else L
fprintf(stderr, =WarningE -n2no:n 6> type on line %d of Z%s4Sn=,
lineno, U/"0Cfg)a0eP0Q)1
"0'ype F 6>79)OW)1
M
M
M
if (7la-ncher7de.-g)
printf(=/"0cfgP%dQ F <@%s?<Sn=, cnt, line)1
if ("0'ype RF 6>7,)9)OW)) L
2no:n6>sPcntQna0e F 5$&73tring+-p(line)1
2no:n6>sPcntQflag F "0'ype1
s:itch ("0'ype) L
defa-ltE
.rea21
case 6>7!$&!3E+7'OE
2no:n6>sPcntQalias F 5$&73tring+-p(alt6>)a0e)1
if (7la-ncher7de.-g) L
printf(= na0eE %s "0'ypeE %s aliasE %sSn=,
2no:n6>sPcntQna0e, =6>7!$&!3E+7'O=, 2no:n6>sPcntQalias)1
M
.rea21
case 6>7&*73E#6E#7C$!33E
2no:n6>sPcntQser"er7class F 5$&73tring+-p(ser"erClass6>)a0e)1
if (7la-ncher7de.-g) L
printf(= na0eE %s "0'ypeE %s ser"er7classE %sSn=,
2no:n6>sPcntQna0e, =6>7&*73E#6E#7C$!33=, 2no:n6>sPcntQser"er7class)1
M
.rea21
M
cntVV1
M
M
fclose(/"0Cfg)1
2no:n6>sCo-nt F cnt1
if (7la-ncher7de.-g) L
end F Co-nter8et()1
printf(=%ld 0icro seconds to parse /"0cfgSn=,
(long)(/int)Co-nter2>icros(end<start))1
M
ret-rn cnt1
M
static "oid
8ro:9no:n6>s(int 0ini0-0)
L
str-ct "0desc* ne:9no:n6>s1
int ne:>a;1
ne:>a; F (2no:n6>s$i0it FF 0 X &)&'7>!G79)OW)76>3 E (2 * 2no:n6>s$i0it))1
if (ne:>a; ?F 0ini0-0) L
ne:>a; F 0ini0-01
M
ne:9no:n6>s F (str-ct "0desc*) 5$&7>e0!lloc(ne:>a; * siDeof(str-ct "0desc))1
if (2no:n6>s RF ),$$) L
0e0cpy(ne:9no:n6>s, 2no:n6>s, 2no:n6>s$i0it * siDeof(str-ct "0desc))1
M
5$&7>e0*ree(2no:n6>s)1
2no:n6>s F ne:9no:n6>s1
2no:n6>s$i0it F ne:>a;1
M
/* #et-rns inde; of 6> or <H if not fo-nd */
static int
9no:n6>&nde;(const char* na0e)
L
int i1
if (strnc0p(na0e, =<5=, 2) FF 0) na0e VF 21
for (i F 01 i ? 2no:n6>sCo-nt1 iVV) L
if (Rstrc0p(na0e, 2no:n6>sPiQna0e)) L
ret-rn i1
M
M
ret-rn <H1
M
static "oid
*ree9no:n6>s()
L
int i1
for (i F 01 i ? 2no:n6>sCo-nt1 iVV) L
5$&7>e0*ree(2no:n6>sPiQna0e)1
2no:n6>sPiQna0e F ),$$1
M
5$&7>e0*ree(2no:n6>s)1
M
/*
* +isplays the splash screen according to the /ar file na0e
* and i0age file na0es stored in en"iron0ent "aria.les
*/
static "oid
3ho:3plash3creen()
L
const char */ar7na0e F geten"(3%$!3A75!#7E)67E)'#()1
const char *file7na0e F geten"(3%$!3A7*&$E7E)67E)'#()1
int data7siDe1
"oid *i0age7data1
if (/ar7na0e) L
i0age7data F 5$&75ar,npac2*ile(/ar7na0e, file7na0e, Udata7siDe)1
if (i0age7data) L
+o3plash&nit()1
+o3plash$oad>e0ory(i0age7data, data7siDe)1
5$&7>e0*ree(i0age7data)1
M
M else if (file7na0e) L
+o3plash&nit()1
+o3plash$oad*ile(file7na0e)1
M else L
ret-rn1
M
+o3plash3et*ile5ar)a0e(file7na0e, /ar7na0e)1
M

Vous aimerez peut-être aussi