資源描述:
《深入剖析NS2的框架代碼.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、.....................最新資料整理推薦.....................1.??NS2的主函數(shù)main位于tclAppInit.cc文件中
int
main(intargc,char**argv)
{
???Tcl_Main(argc,argv,Tcl_AppInit);
???return0;??????????/*Neededonlytopreventcompilerwarning.*/
}
從這個(gè)main函數(shù)中我們可以看到:整個(gè)NS2的框架其實(shí)完全包含在TCL_Main函數(shù)中。
2.Tcl_Main函數(shù)位于/g
2、eneric/TclMain.c文件中,這個(gè)函數(shù)的代碼如下:(可能比較長(zhǎng))?
void
Tcl_Main(argc,argv,appInitProc)
???intargc;??????????/*Numberofarguments.*/
???char**argv;???????/*Arrayofargumentstrings.*/25.....................最新資料整理推薦.....................
???Tcl_AppInitProc*appInitProc;
????????????/*Applica
3、tion-specificinitialization
????????????*proceduretocallaftermost
????????????*initializationbutbeforestartingto
????????????*executecommands.*/
{
???Tcl_Obj*resultPtr,*argvPtr,*commandPtr=NULL;
???PromptTypeprompt=PROMPT_START;
???intcode,length,tty,exitCode=0;
???Tcl_Chann
4、elinChannel,outChannel,errChannel;
???Tcl_Interp*interp;
???Tcl_DStringappName;
???Tcl_Obj*objPtr;
???Tcl_FindExecutable(argv[0]);?//尋找可執(zhí)行文件ns?作用未知,參數(shù)的值為可執(zhí)行文件ns對(duì)應(yīng)的路徑
25.....................最新資料整理推薦.....................???interp=Tcl_CreateInterp();?//創(chuàng)建OTCL解釋器
???Tcl_InitMe
5、mory(interp);?//配置解釋器
???/*
????*Makecommand-lineargumentsavailableintheTclvariables"argc"
????*and"argv".Ifthefirstargumentdoesn'tstartwitha"-"then
????*stripitoffanduseitasthenameofascriptfiletoprocess.
????*/
???if(TclGetStartupScriptPath()==NULL){
???if((argc>1)&&(argv
6、[1][0]!='-')){
??????TclSetStartupScriptFileName(argv[1]);
??????argc--;
??????argv++;
???}
???25.....................最新資料整理推薦.....................}
???if(TclGetStartupScriptPath()==NULL){
???Tcl_ExternalToUtfDString(NULL,argv[0],-1,&appName);
???}else{
???TclSetStartupScri
7、ptFileName(Tcl_ExternalToUtfDString(NULL,
??????TclGetStartupScriptFileName(),-1,&appName));
???}
???Tcl_SetVar(interp,"argv0",Tcl_DStringValue(&appName),TCL_GLOBAL_ONLY);
???Tcl_DStringFree(&appName);
???argc--;
???argv++;
???objPtr=Tcl_NewIntObj(argc);
???Tcl_IncrRefCount
8、(objPtr);
???Tcl_SetVar2Ex(interp,"argc",NULL,objPtr,25....................