Michael_I_Summers@cup.portal.com (03/22/91)
Does anyone have a code fragment that shows manipulating the Finder Information pointed to via AppParmHandle that they'd be willing to share? I've been working for several days with this and am just not quite getting it. Thanks, Mike
zben@ni.umd.edu (Ben Cranston) (03/23/91)
/* 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); }