Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!udel!haven!ni.umd.edu!ni.umd.edu!zben From: zben@ni.umd.edu (Ben Cranston) Newsgroups: comp.sys.mac.programmer Subject: Re: AppParmHandle useage? Summary: Sample code to build args block enclosed Message-ID: <1991Mar22.175427.22105@ni.umd.edu> Date: 22 Mar 91 17:54:27 GMT References: <40417@cup.portal.com> Sender: usenet@ni.umd.edu (USENET News System) Organization: University of Maryland at College Park Lines: 143 Nntp-Posting-Host: ni.umd.edu /* Head of argument buffer handle in low memory. * Variable body follows. */ typedef struct { short int Mess; /* Open or print */ short int ArgC; /* Number of args */ } AppHead; ... GetAppParms(appname,&refn,&arghandle); ... StartArgs(arghandle,appOpen); AddArg(arghandle,docname); AddArg(arghandle,docname); ... /* ARGUMENTS * * Begin generation of argument list for launched program. */ StartArgs(Handle arghandle,short mess) { char diags[256],enbuf[256]; SetHandleSize(arghandle,sizeof(AppHead)); if (noErr != MemError() ) { NumToString(MemError(),enbuf); GetIndString(diags,EBLOCK,ESHAND); DoAlert(diags,enbuf); ExitToShell(); } else { ( (AppHead *) *arghandle )->Mess = mess; ( (AppHead *) *arghandle )->ArgC = 0; } } /* Add document to argument list. */ AddArg(Handle arghandle,char *path) { OSErr errcode; short refnum; FInfo finfo; AppFile af; char diags[256],enbuf[256]; if (0 != (refnum=GetWD(path,af.fName)) ) { if (noErr != (errcode=GetFInfo(af.fName,refnum,&finfo)) ) { if (fnfErr == errcode) { GetIndString(diags,EBLOCK,ENOFIL); DoAlert(diags,af.fName); } else { NumToString(errcode,enbuf); GetIndString(diags,EBLOCK,EFINFO); DoAlert(diags,enbuf); } } else { af.vRefNum = refnum; af.fType = finfo.fdType; af.versNum = 0; if (noErr != (errcode=PtrAndHand((Ptr)&af,arghandle,af.fName[0]+9)) ) { NumToString(errcode,enbuf); GetIndString(diags,EBLOCK,ECATAG); DoAlert(diags,enbuf); } else { ( (AppHead *) *arghandle )->ArgC++; } } } } /* SUBROUTINES * * Split the path string into directory and filename. * Open a working directory on the directory portion. * Return the working directory and filename portion to caller. */ short GetWD(char *path,char *fname) { short len, idx, refnum; char dname[256],diags[256]; OSErr errcode; WDPBRec WDPB; refnum = 0; for (len=idx=path[0]; (idx>0)&&(path[idx]!=':'); idx--) ; if (0 == idx) { GetIndString(diags,EBLOCK,EQUALF); DoAlert(diags,path); } else { dname[0] = idx; BlockMove(&path[1],&dname[1],idx); fname[0] = len-idx; BlockMove(&path[idx+1],&fname[1],len-idx); WDPB.ioNamePtr = dname; WDPB.ioVRefNum = 0; WDPB.ioWDProcID = 'ERIK'; WDPB.ioWDDirID = 0; if (noErr == (errcode=PBOpenWD(&WDPB,false)) ) { refnum = WDPB.ioVRefNum; } else if ( (fnfErr==errcode) || (dirNFErr==errcode) ) { GetIndString(diags,EBLOCK,ENODIR); DoAlert(diags,dname); } else if (nsvErr == errcode) { GetIndString(diags,EBLOCK,ENOVOL); DoAlert(diags,dname); } else { NumToString(errcode,dname); GetIndString(diags,EBLOCK,EOPNWD); DoAlert(diags,dname); } } return(refnum); } /* Tell the user about a problem. * Give her a choice to continue or abort. */ DoAlert(char *diag, char *data) { ParamText(nil,nil,diag,data); if (1 == StopAlert(LALERT,nil) ) ExitToShell(); } /* GetIndString but only on current resource file. */ Get1IndString(char *thestring, short listid, short index) { if (nil == Get1Resource('STR#',listid)) *thestring = 0; else GetIndString(thestring,listid,index); }