Пример #1
0
PatchSet::PatchSet(void)
{
	int i;
	short num_files;
 	OSErr sysErr = noErr;
 	OSErr	myErr;
	Str32	filename;
	CInfoPBRec	cipbr;
	DirInfo		*dpb = (DirInfo *)&cipbr;
	int16		idx = 1;
	int default_patch = 0;
	
	
	HFileInfo	myCPB;
	short	myVRef;	
	long	myDirID;
	char tempname[60];
	
	filenum = 0;
	
	for (i=0; i<MAX_PATCH_NAMES; i++) 
		{
		patches[i] = NULL;
		}

 	sysErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, 
 			&myVRef, &myDirID);

//find dir 		
  	myCPB.ioFDirIndex = 0;
 	myCPB.ioDirID = myDirID;
 	myCPB.ioNamePtr = MONACO_FOLDER;
 	myCPB.ioVRefNum = myVRef;
 	
 	myErr = PBGetCatInfo((CInfoPBPtr)&myCPB, false);
 
 	sysErr = MCO_FILE_OPEN_ERROR;
 	if (myErr == noErr) {
 		if(((myCPB.ioFlAttrib >> 4) & 0x01) == 1) sysErr = 0;
 	}



//find subdir
	if(sysErr == 0){
	  	myCPB.ioFDirIndex = 0;
	 	myCPB.ioNamePtr = MONACO_PATCHES;
	 	myCPB.ioVRefNum = myVRef;
	 	
	 	myErr = PBGetCatInfo((CInfoPBPtr)&myCPB, false);
	 
	 	sysErr = MCO_FILE_OPEN_ERROR;
	 	if (myErr == noErr) {
	 		if(((myCPB.ioFlAttrib >> 4) & 0x01) == 1) sysErr = 0;
	 	}
	}
Пример #2
0
const char *autotype_via_mactype(const char *file) 
{
    OSErr err;
    CInfoPBRec CPB;
    HFileParam hfp;
    char *d, kind[10], buf[MAXPATHLEN];
    short vRef = 0;
    long dirID = 0;
    

    if (!file) return nil;
    strcpy(buf, file);	/* thou shalt not poke thy caller's buffer */
    err = GetPathRef(buf, &vRef, &dirID); /* GetPathRef does c2p */
    c2pstr(buf);
    CPB.hFileInfo.ioNamePtr = buf;
    CPB.hFileInfo.ioDirID = 0;
    CPB.hFileInfo.ioVRefNum = 0;
    CPB.hFileInfo.ioFDirIndex = 0;
    switch (PBGetCatInfo (&CPB, 0)) {
	case noErr: break;
	case fnfErr:
	    CPB.hFileInfo.ioDirID = 0;
	    CPB.hFileInfo.ioVRefNum = vRef; 
	    err = PBGetCatInfo (&CPB, 0);
	    break;
	default:
	    return nil;
    }
    hfp.ioCompletion = nil;
    hfp.ioNamePtr = buf;
    hfp.ioVRefNum = CPB.hFileInfo.ioVRefNum;
    hfp.ioFDirIndex = 0;
    hfp.ioDirID = CPB.hFileInfo.ioDirID;
    if (err = PBHGetFInfo((HParmBlkPtr) &hfp, FALSE)) {
	print(catgets(catalog, CAT_MSGS, 1013, "autotyper:  couldn't read attachment file information"));
	return nil;
    }

    /* creator default is Z-Mail sig */
    d = (char *) kind;
    *((long *)(d)) =  CPB.hFileInfo.ioFlFndrInfo.fdType;
    kind[4] = '/';
    d += 5;
    *((long *)(d)) = CPB.hFileInfo.ioFlFndrInfo.fdCreator;
    kind[9] = 0;
    if (!type_mactypes)
        (void) get_attach_keys(0, (Attach *)0, NULL);
    d = get_type_from_mactype((char *)kind);    
    if (!strcmp(d, kind))
    	d = nil;
    if (!d && hfp.ioFlRLgLen)
	d = "application/mac-binhex40";

    return d;

} /* autotype_via_mactype */
Пример #3
0
long
ischild (long potential_parent_dir, long potential_child_dir, short volume)
{
  CInfoPBRec pb;
  OSErr err;

  if (potential_parent_dir == potential_child_dir)
    return true;		/* for our purposes, any directory is a child of itself */
  pb.dirInfo.ioCompletion = 0;
  pb.dirInfo.ioNamePtr = 0;
  pb.dirInfo.ioVRefNum = volume;
  pb.dirInfo.ioFDirIndex = -1;
  pb.dirInfo.ioDrDirID = potential_child_dir;
  while (pb.dirInfo.ioDrDirID > 1)
    {
      err = PBGetCatInfo (&pb, false);
      if (err != noErr)
	{
	  doerror (err, (StringPtr) "\pPBGetCatInfo");
	  return true;
	}
      if (pb.dirInfo.ioDrParID == potential_parent_dir)
/*-->*/ return true;
      pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
    }
Пример #4
0
void
setoneicon (ControlHandle c)
{
  CInfoPBRec pb;
  item **ih;
  typeinfo *tip;

  ih = (item **) (*c)->contrlData;
  pb.hFileInfo.ioFDirIndex = 0;
  pb.hFileInfo.ioVRefNum = (*ih)->vrefnum;
  pb.hFileInfo.ioDirID = (*ih)->ioparid;
  pb.hFileInfo.ioNamePtr = (*c)->contrlTitle;
  PBGetCatInfo (&pb, false);
  if (pb.hFileInfo.ioFlAttrib & DIRBIT)
    {
      (*ih)->iconfam = &g_foldericonsptr;
      (*ih)->action = OPENDIR;
      (*ih)->size = 0;
      (*ih)->moddate = pb.dirInfo.ioDrMdDat;
    }
  else
    {
      (*ih)->iconfam = gethash (pb.hFileInfo.ioFlFndrInfo.fdType,
				pb.hFileInfo.ioFlFndrInfo.fdCreator);
      tip = gettypeinfo (pb.hFileInfo.ioFlFndrInfo.fdType);
      (*ih)->action = tip->action;
      (*ih)->size = pb.hFileInfo.ioFlLgLen;
      (*ih)->moddate = pb.hFileInfo.ioFlMdDat;
    }
}
Пример #5
0
short file_attr(const char *path) {

#ifdef TARGET_API_MAC_CARBON
	Str255			fname;
	FSSpec			fss;
	FSRef			fsr;
	FSCatalogInfo	fsci;
	short			ret;

	mkstr255(fname, path);
	if ((FSMakeFSSpec(0, 0, fname, &fss) != noErr) ||
		(FSpMakeFSRef(&fss, &fsr) != noErr) ||
		(FSGetCatalogInfo(&fsr, kFSCatInfoNodeFlags, &fsci,
										NULL, NULL, NULL) != noErr)) {
		return(-1);
	}
	if (fsci.nodeFlags & kFSNodeIsDirectoryMask) {
		ret = FILEATTR_DIRECTORY;
	}
	else {
		ret = FILEATTR_ARCHIVE;
	}
	if (fsci.nodeFlags & kFSNodeLockedMask) {
		ret |= FILEATTR_READONLY;
	}
	return(ret);
#else
	Str255		fname;
	FSSpec		fss;
	CInfoPBRec	pb;
	short		ret;

	mkstr255(fname, path);
	FSMakeFSSpec(0, 0, fname, &fss);
	pb.dirInfo.ioNamePtr = fss.name;
	pb.dirInfo.ioVRefNum = fss.vRefNum;
	pb.dirInfo.ioDrDirID = fss.parID;
	if (fss.name[0] == 0) {
		pb.dirInfo.ioFDirIndex = -1;
	}
	else {
		pb.dirInfo.ioFDirIndex = 0;
	}
	if (PBGetCatInfo(&pb, false) != noErr) {
		return(-1);
	}
	if (pb.hFileInfo.ioFlAttrib & ioDirMask) {
		ret = FILEATTR_DIRECTORY;
	}
	else {
		ret = FILEATTR_ARCHIVE;
	}
	if (pb.hFileInfo.ioFlAttrib & 0x01) {
		ret |= FILEATTR_READONLY;
	}
	return(ret);
#endif
}
Пример #6
0
OSErr find_exec_spec(FSSpec *result, FSSpec *myself)
{
  OSErr err;
  CInfoPBRec pbrec;
  short find_position = 0;
  AliasHandle execAlias;
  Boolean aliasChanged;

  // first we try the stored alias.
  
  execAlias = (AliasHandle)GetResource('alis',128);
  
  if (execAlias != NULL) {
    
    err = ResolveAlias(NULL,execAlias,result,&aliasChanged);
  
    if (err == noErr) {
      
      if (aliasChanged) { // need to write it back to disk
        WriteResource((Handle)execAlias);
      }
       	
      return noErr;
    }
  }
    
  // if that doesn't work, drop back and look for the file in the current directory.

  result->vRefNum = myself->vRefNum;
  result->parID = myself->parID;
  
  while (1) {
    pbrec.hFileInfo.ioVRefNum = result->vRefNum;
    pbrec.hFileInfo.ioDirID = result->parID;
    pbrec.hFileInfo.ioFDirIndex = find_position + 1;
    pbrec.hFileInfo.ioNamePtr = result->name;
    if (PBGetCatInfo(&pbrec, 0) || !*result->name)
      break;
    
    find_position++;

    if (pbrec.hFileInfo.ioFlFndrInfo.fdType == 'APPL') {
      if (pbrec.hFileInfo.ioFlFndrInfo.fdCreator == DEST_CREATOR) { 
        // found it!
        Str255 newName = "\pExecutable Location";
        
	if (NewAlias(NULL,result,&execAlias) == noErr) {
	  AddResource((Handle)execAlias,'alis',128,newName);
	  WriteResource((Handle)execAlias);
	} 

	return noErr;
      }
		
    }
  }
Пример #7
0
void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
{
	DirInfo	block;
	Str255	mark = "\p:";
	Str255	directoryName="\p";
	OSErr	err;

	block.ioDrParID = dirID;
	block.ioNamePtr = directoryName;
	do {
			block.ioVRefNum = vRefNum;
			block.ioFDirIndex = -1;
			block.ioDrDirID = block.ioDrParID;
			err = PBGetCatInfo((CInfoPBPtr)&block, FALSE);
			pstrinsert(fullPathName, mark);
			pstrinsert(fullPathName, directoryName);
	} while (block.ioDrDirID != 2);	//note!! 2 is current volume directory
}
Пример #8
0
static int
GetFileReadOnly(
    Tcl_Interp *interp,		/* The interp to report errors with. */
    int objIndex,		/* The index of the attribute. */
    char *fileName,		/* The name of the file. */
    Tcl_Obj **readOnlyPtrPtr)	/* A pointer to return the object with. */
{
    OSErr err;
    FSSpec fileSpec;
    CInfoPBRec paramBlock;
    
    err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec);
    
    if (err == noErr) {
    	if (err == noErr) {
    	    paramBlock.hFileInfo.ioCompletion = NULL;
    	    paramBlock.hFileInfo.ioNamePtr = fileSpec.name;
    	    paramBlock.hFileInfo.ioVRefNum = fileSpec.vRefNum;
    	    paramBlock.hFileInfo.ioFDirIndex = 0;
    	    paramBlock.hFileInfo.ioDirID = fileSpec.parID;
    	    err = PBGetCatInfo(&paramBlock, 0);
    	    if (err == noErr) {
    	    
    	    	/*
    	    	 * For some unknown reason, the Mac does not give
    	    	 * symbols for the bits in the ioFlAttrib field.
    	    	 * 1 -> locked.
    	    	 */
    	    
    	    	*readOnlyPtrPtr = Tcl_NewBooleanObj(
    	    		paramBlock.hFileInfo.ioFlAttrib & 1);
    	    }
    	}
    }
    if (err != noErr) {
    	errno = TclMacOSErrorToPosixError(err);
    	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), 
    		"couldn't get attributes for file \"", fileName, "\": ",
    		Tcl_PosixError(interp), (char *) NULL);
    	return TCL_ERROR;
    }
    return TCL_OK;
}
Пример #9
0
BOOL file_listnext(FLISTH hdl, FLINFO *fli) {

	FLHDL			flhdl;
	Str255			fname;
	unsigned long	dt;

	flhdl = (FLHDL)hdl;
	if ((flhdl == NULL) || (flhdl->eoff)) {
		goto ffn_err;
	}
	fname[0] = 0;
	flhdl->pb.dirInfo.ioNamePtr = fname;
	flhdl->pb.dirInfo.ioDrDirID = flhdl->tagid;
	flhdl->pb.dirInfo.ioFDirIndex = flhdl->index;
	flhdl->pb.dirInfo.ioACUser = 0;
	if (PBGetCatInfo(&flhdl->pb, false) != noErr) {
		flhdl->eoff = TRUE;
		goto ffn_err;
	}
	flhdl->index++;
	if (fli) {
		fli->caps = FLICAPS_SIZE | FLICAPS_ATTR | FLICAPS_DATE | FLICAPS_TIME;
		if (flhdl->pb.hFileInfo.ioFlAttrib & ioDirMask) {
			fli->attr = FILEATTR_DIRECTORY;
			fli->size = 0;
			dt = flhdl->pb.dirInfo.ioDrCrDat;
		}
		else {
			fli->attr = FILEATTR_ARCHIVE;
			fli->size = flhdl->pb.hFileInfo.ioFlLgLen;
			dt = flhdl->pb.hFileInfo.ioFlMdDat;
		}
		if (flhdl->pb.hFileInfo.ioFlAttrib & 0x01) {
			fli->attr |= FILEATTR_READONLY;
		}
		cnvdatetime(dt, &fli->date, &fli->time);
		mkcstr(fli->path, sizeof(fli->path), fname);
	}
	return(SUCCESS);

ffn_err:
	return(FAILURE);
}
Пример #10
0
FLISTH file_list1st(const char *dir, FLINFO *fli) {

	Str255	fname;
	FSSpec	fss;
	FLHDL	ret;

	mkstr255(fname, dir);
	FSMakeFSSpec(0, 0, fname, &fss);
	ret = (FLHDL)_MALLOC(sizeof(_FLHDL), dir);
	if (ret == NULL) {
		goto ff1_err1;
	}
	ret->pb.dirInfo.ioNamePtr = fss.name;
	ret->pb.dirInfo.ioVRefNum = fss.vRefNum;
	ret->pb.dirInfo.ioDrDirID = fss.parID;
	if (fss.name[0] == 0) {
		ret->pb.dirInfo.ioFDirIndex = -1;
	}
	else {
		ret->pb.dirInfo.ioFDirIndex = 0;
	}
	if (PBGetCatInfo(&ret->pb, false) != noErr) {
		goto ff1_err2;
	}
	if (ret->pb.hFileInfo.ioFlAttrib & 0x10) {
		ret->tagid = ret->pb.dirInfo.ioDrDirID;
	}
	else {
		ret->tagid = ret->pb.hFileInfo.ioFlParID;
	}
	ret->eoff = FALSE;
	ret->index = 1;
	if (file_listnext((FLISTH)ret, fli) == SUCCESS) {
		return((FLISTH)ret);
	}

ff1_err2:
	_MFREE(ret);

ff1_err1:
	return(NULL);
}
Пример #11
0
void
getnameandfromdirid (Str255 * sp, LONGINT * fromdirid)
{
  CInfoPBRec cpb;

  if (globalreply.fName[0] == 0)
    {
      cpb.hFileInfo.ioFDirIndex = -1;
      cpb.hFileInfo.ioDirID = globalreply.fType;
      cpb.hFileInfo.ioVRefNum = -SFSaveDisk;
      cpb.hFileInfo.ioNamePtr = *sp;
      PBGetCatInfo (&cpb, false);
      if (sp[0] != 0)
	*fromdirid = cpb.hFileInfo.ioFlParID;
      else
	*fromdirid = CurDirStore;
    }
  else
    {
      *fromdirid = CurDirStore;
      BlockMove (globalreply.fName, *sp, globalreply.fName[0] + 1);
    }
}
Пример #12
0
/*---------------------------------------------------------------------------
 * T_DIR_INFO *osd_opendir( const char *filename )
 *---------------------------------------------------------------------------*/
T_DIR_INFO	*osd_opendir( const char *filename )
{
  char *p;
  short	 i;
  OSErr  err;
  short  vRefNum;
  int    num;
  long   dirID;
  T_DIR_INFO	*dir;
  Str63		temp;
  CInfoPBRec	pbr;

  /* : なら、ルート(トップレベル) とみなす */
  if (strcmp(filename, ":")==0) {
    return openroot();
  }

  /* filenameが無いときも、ルート(トップレベル) とみなす */
  if( filename==NULL || filename[0]=='\0' ) return openroot();


				/* T_DIR_INFO ワークを 1個確保 */
  if( (dir = (T_DIR_INFO *)malloc( sizeof(T_DIR_INFO) ))==NULL ){
    return NULL;
  }

  err = PathToSpec(filename, &vRefNum, &dirID, NULL);
  if (noErr != err) {
    free( dir );
    return NULL;
  }

  /* 項目の数を取得する */
  dir->nr_entry = 2;		/* 最低でも2エントリ (TOPとparent) */
  i = 1;
  pbr.hFileInfo.ioNamePtr = temp;
  pbr.hFileInfo.ioVRefNum = vRefNum;
  do {
    pbr.hFileInfo.ioFDirIndex = i;
    pbr.hFileInfo.ioDirID     = dirID;
    pbr.hFileInfo.ioACUser    = 0;
    err = PBGetCatInfoSync(&pbr);
    if (err == noErr && !(pbr.hFileInfo.ioFlFndrInfo.fdFlags & 0x4000)) {
      dir->nr_entry += 1;
    }
    i++;
  } while (err == noErr);
				/* T_DIR_ENTRY ワークを 項目数分 確保 */
  dir->entry = (T_DIR_ENTRY *)malloc( dir->nr_entry * sizeof(T_DIR_ENTRY) );
  if( dir->entry==NULL ){
    free( dir );
    return NULL;
  }
  for( i=0; i<dir->nr_entry; i++ ) {
    dir->entry[ i ].name = NULL;
  /*dir->entry[ i ].str  = NULL;*/
  }


  dir->cur_entry = 0;

  /* 先頭に <TOP> と <parent> を追加 */

#define	TOP_NAME	":"
#define	TOP_STR		"<< TOP >>"
#define	PAR_NAME	"::"
#define	PAR_STR		"<< parent >>"

  num = 0;
  {
    p = (char *)malloc( sizeof(TOP_NAME) + sizeof(TOP_STR) );
    if( p==NULL ){	/* ↑ファイル名    ↑表示名    */
      dir->nr_entry = num;
      return dir;
    }
    dir->entry[ num ].name = &p[0];
    dir->entry[ num ].str =  &p[sizeof(TOP_NAME)];

    strcpy(dir->entry[ num ].name, TOP_NAME);
    strcpy(dir->entry[ num ].str,  TOP_STR );

    dir->entry[ num ].type = FILE_STAT_DIR;
  }
  num = 1;
  {
    p = (char *)malloc( sizeof(PAR_NAME) + sizeof(PAR_STR) );
    if( p==NULL ){	/* ↑ファイル名    ↑表示名    */
      dir->nr_entry = num;
      return dir;
    }
    dir->entry[ num ].name = &p[0];
    dir->entry[ num ].str =  &p[sizeof(PAR_NAME)];

    strcpy(dir->entry[ num ].name, PAR_NAME );
    strcpy(dir->entry[ num ].str,  PAR_STR  );

    dir->entry[ num ].type = FILE_STAT_DIR;
  }

  /* フォルダ内の項目を追加 */
  i = 1;
  num = 2;
  pbr.hFileInfo.ioNamePtr = temp;
  pbr.hFileInfo.ioVRefNum = vRefNum;
  do {
    pbr.hFileInfo.ioFDirIndex = i;
    pbr.hFileInfo.ioDirID     = dirID;
    pbr.hFileInfo.ioACUser    = 0;
    err = PBGetCatInfo(&pbr, 0);
    if (err == noErr &&		/* ↓ 不可視属性のファイルは除く */
	!(pbr.hFileInfo.ioFlFndrInfo.fdFlags & 0x4000)) {
      temp[temp[0] + 1] = 0;

      p = (char *)malloc( (temp[0] + 1) + (temp[0] + 3) );
      if( p==NULL ){	/* ↑ファイル名    ↑表示名    */
	dir->nr_entry = num;
        break;
      }

      dir->entry[ num ].name = &p[0];
      dir->entry[ num ].str =  &p[(temp[0] + 1)];

      if (pbr.hFileInfo.ioFlAttrib & 16) {
        sprintf(dir->entry[ num ].name, "%s", temp + 1);
        sprintf(dir->entry[ num ].str, "[%s]", temp + 1);
        dir->entry[ num ].type = FILE_STAT_DIR;
      } else {
        sprintf(dir->entry[ num ].name, "%s", temp + 1);
        sprintf(dir->entry[ num ].str,  "%s", temp + 1);
        dir->entry[ num ].type = FILE_STAT_FILE;
      }
      num++;
    }
    i++;
  } while (err == noErr && num < dir->nr_entry);

  dir->nr_entry = num;

  return dir;
}
Пример #13
0
NLM_EXTERN ValNodePtr LIBCALL Nlm_DirCatalog (Nlm_CharPtr pathname)

{
#ifdef OS_MAC
  long            dirID;
  OSErr           err;
  short           index;
  unsigned short  num;
  Nlm_Char        path[PATH_MAX];
  CInfoPBRec      pbc;
  HParamBlockRec  pbh;
  short           vRefNum;
#endif
#ifdef OS_UNIX
  Nlm_Uint1       choice;
#ifdef OS_UNIX_DARWIN
  DIR             *dirp;
  struct dirent   *dep;
#else
  Nlm_Char        buf [256];
  Nlm_Char        ch;
  Nlm_Char        cmmd [PATH_MAX + 20];
  FILE            *fp;
  Nlm_CharPtr     ptr;
#endif
#endif
  ValNodePtr      vnp = NULL;

  if (pathname != NULL && pathname [0] != '\0') {
#ifdef OS_MAC
    Nlm_StringNCpy_0 (path, pathname, sizeof (path));
    Nlm_CtoPstr ((Nlm_CharPtr) path);
    Nlm_MemSet ((Nlm_VoidPtr) (&pbh), 0, sizeof (HParamBlockRec));
    pbh.volumeParam.ioNamePtr = (StringPtr) path;
    pbh.volumeParam.ioVolIndex = -1;
    err = PBHGetVInfo (&pbh, FALSE);
    if (err != noErr) return NULL;
    vRefNum = pbh.volumeParam.ioVRefNum;
    Nlm_StringNCpy_0 (path, pathname, sizeof (path));
    Nlm_CtoPstr ((Nlm_CharPtr) path);
    Nlm_MemSet ((Nlm_VoidPtr) (&pbc), 0, sizeof (CInfoPBRec));
    pbc.dirInfo.ioNamePtr = (StringPtr) path;
    pbc.dirInfo.ioVRefNum = vRefNum;
    err = PBGetCatInfo (&pbc, FALSE);
    if (err != noErr) return NULL;
    if (pbc.dirInfo.ioFlAttrib & 16) {
      num = pbc.dirInfo.ioDrNmFls;
      dirID = pbc.dirInfo.ioDrDirID;
      for (index = 1; index <= num; index++) {
        Nlm_MemSet ((Nlm_VoidPtr) (&pbc), 0, sizeof (CInfoPBRec));
        pbc.dirInfo.ioNamePtr = (StringPtr) path;
        pbc.dirInfo.ioVRefNum = vRefNum;
        pbc.dirInfo.ioFDirIndex = index;
        pbc.dirInfo.ioDrDirID = dirID;
        pbc.dirInfo.ioACUser = 0;
        err = PBGetCatInfo (&pbc, FALSE);
        if (err == noErr) {
          Nlm_PtoCstr ((Nlm_CharPtr) path);
          if (pbc.dirInfo.ioFlAttrib & 16) {
            ValNodeCopyStr (&vnp, 1, path);
          } else {
            ValNodeCopyStr (&vnp, 0, path);
          }
        }
      }
    }
#endif
#if defined(WIN32)
    {{
      Nlm_Char x_path[PATH_MAX];
      WIN32_FIND_DATA fData;
      HANDLE hFindFile;
      Nlm_StringNCpy_0(x_path, pathname, sizeof(x_path) - 5);
      Nlm_StringCat(x_path, "\\*.*");
      hFindFile = FindFirstFile(x_path, &fData);
      if (hFindFile == INVALID_HANDLE_VALUE)
        return 0;
      do {
        if (fData.cFileName[0] != '.'  ||
            (fData.cFileName[1] != '.'  &&  fData.cFileName[1] != '\0'))
          ValNodeCopyStr
            (&vnp, (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0,
             fData.cFileName);
      } while ( FindNextFile(hFindFile, &fData) );
      FindClose(hFindFile);
    }}
#endif
#ifdef OS_UNIX
#ifdef OS_UNIX_DARWIN
    dirp = opendir(pathname);
    if (dirp == NULL) return NULL;
    while ((dep = readdir(dirp)) != NULL) {
      /* ignore 'invisible' files. */
      if (dep->d_namlen < 1 || dep->d_name[0] == '.')
        continue;
      if (dep->d_type == DT_DIR) /* directory */
        choice = 1;
      else          /* all other file types. */
        choice = 0;
      ValNodeCopyStr (&vnp, choice, dep->d_name);
    }
    closedir(dirp);
#else
    sprintf (cmmd, "ls -1p %s 2>/dev/null", pathname);
    fp = popen (cmmd, "r");
    if (fp == NULL) return NULL;
    while (Nlm_FileGets (buf, sizeof (buf), fp) != NULL) {
      ptr = buf;
      ch = *ptr;
      while (ch != '\0' && ch != '\n' && ch != '\r') {
        ptr++;
        ch = *ptr;
      }
      *ptr = '\0';
      choice = 0;
      ptr = Nlm_StringChr (buf, '/');
      if (ptr != NULL) {
        *ptr = '\0';
        choice = 1;
      }
      ValNodeCopyStr (&vnp, choice, buf);
    }
    pclose (fp);
#endif
#endif
#ifdef OS_VMS
#endif
  }
  return vnp;
}
Пример #14
0
/*****************************************************************************
*
*   TmpNam()
*
*****************************************************************************/
NLM_EXTERN Nlm_CharPtr LIBCALL Nlm_TmpNam (Nlm_CharPtr s)

{
#ifdef TEMPNAM_AVAIL
    char *filename;
    static Nlm_Char save_filename[PATH_MAX];

    /* emulate tmpnam(), except get the benefits of tempnam()'s ability to */
    /* place the files in another directory specified by the environment   */
    /* variable TMPDIR                                                     */
#ifdef OS_UNIX_DARWIN
    filename = tempnam("/tmp", "ncbi.");
#else
    filename = tempnam(NULL, NULL);
#endif
    if (s == NULL)
    { /* return pointer to static string */
        if (filename != NULL) {
          strcpy ((char *) save_filename, (char *) filename);
          free ((void *) filename);
        } else {
          save_filename [0] = '\0';
        }
        return save_filename;
    } else {
        if (filename != NULL) {
          strcpy ((char *) save_filename, (char *) filename);
          Nlm_StrCpy (s, save_filename);
          free ((void *) filename);
        } else {
          *s = '\0';
        }
        return s;
    }
#else
#ifdef OS_MAC
    static Nlm_Char  directory [PATH_MAX];
    OSErr        err;
    long         gesResponse;
    long         newDirID;
    short        newVRefNum;
    CInfoPBRec   params;
    Nlm_Char     temp [PATH_MAX];
    Nlm_CharPtr  tmp;
    Nlm_Boolean  useTempFolder;
    char * filename;

    useTempFolder = FALSE;
    if (! Gestalt (gestaltFindFolderAttr, &gesResponse) &&
        (gesResponse & (1 << gestaltFindFolderPresent))) {
      err = FindFolder(kOnSystemDisk, kTemporaryFolderType,
                       kCreateFolder, &newVRefNum, &newDirID);
      if (err == noErr) {
        useTempFolder = TRUE;
      }
    }
    filename = tmpnam (NULL);
    if (useTempFolder) {
      temp [0] = '\0';
      params.dirInfo.ioNamePtr = (StringPtr) directory;
      params.dirInfo.ioDrParID = newDirID;
      do {
        params.dirInfo.ioVRefNum = newVRefNum;
        params.dirInfo.ioFDirIndex = -1;
        params.dirInfo.ioDrDirID = params.dirInfo.ioDrParID;
        err = PBGetCatInfo (&params, FALSE);
        Nlm_PtoCstr ((Nlm_CharPtr) directory);
        Nlm_StringCat (directory, DIRDELIMSTR);
        Nlm_StringCat (directory, temp);
        Nlm_StringCpy (temp, directory);
      } while (params.dirInfo.ioDrDirID != fsRtDirID);
      tmp = Nlm_StringMove (directory, temp);
      tmp = Nlm_StringMove (tmp, (Nlm_CharPtr) filename);
      if (s == NULL) {
          return (Nlm_CharPtr) directory;
      } else {
          s [0] = '\0';
          Nlm_StringCpy (s, directory);
          return s;
      }
    } else {
      if (s == NULL) {
          return (Nlm_CharPtr) filename;
      } else {
          s [0] = '\0';
          Nlm_StringCpy (s, filename);
          return s;
      }
    }
#else
    char * filename;

    filename = tmpnam (NULL);
    if (s == NULL) {
        return (Nlm_CharPtr) filename;
    } else {
        s [0] = '\0';
        Nlm_StringCpy (s, filename);
        return s;
    }
#endif
#endif
}
Пример #15
0
char *
get_full_pathname (long dirID, short volID)
{
  FSVolumeInfoParam vol;
  HFSUniStr255 volname;
  CInfoPBRec pb;
  OSErr result;
  Str255 dir;
  char *pathname = NULL;
  char *prov = NULL;
  SInt16 vdefNum; 
  SInt32 dummy;

  pb.dirInfo.ioNamePtr = dir;
  pb.dirInfo.ioVRefNum = volID;
  pb.dirInfo.ioDrParID = dirID;
  pb.dirInfo.ioFDirIndex = -1;

  do
    {
      pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
      result = PBGetCatInfo (&pb, false);
      if (result != noErr)
	return NULL;
      if (pb.dirInfo.ioDrDirID != fsRtDirID)
	{
	  prov = pathname;
	  pathname =
	      (char *) malloc ((pathname ? strlen (pathname) : 0) +
	      (unsigned char) dir[0] + 2);
	  strcpy (pathname, PATH_SEPARATOR);
	  strncat (pathname, (char *) dir + 1, (unsigned char) dir[0]);
	}
#ifdef macintosh
      else
	{
	  prov = pathname;
	  pathname =
	      (char *) malloc ((pathname ? strlen (pathname) : 0) +
	      (unsigned char) dir[0] + 1);
	  pathname[0] = 0;
	  strncat (pathname, (char *) dir + 1, (unsigned char) dir[0]);
	}
#endif

      if (prov)
	{
	  strcat (pathname, prov);
	  free (prov);
         prov = NULL;
	}
    }
  while (pb.dirInfo.ioDrDirID != fsRtDirID);

#ifdef __APPLE__
  /* Get also the volume name */
  FindFolder (kOnSystemDisk, kSystemFolderType, FALSE, &vdefNum, &dummy);
  if(vdefNum != volID)
    {
      vol.ioVRefNum = volID;
      vol.volumeIndex = 0;
      vol.whichInfo = kFSVolInfoNone;
      vol.volumeName = &volname;
      vol.ref = NULL;

      PBGetVolumeInfoSync(&vol);
      if(volname.length)
        {
          wchar_t volwchar[1024];
          char *volutf8 = NULL;

          /* Convert the UniString255 to wchar */
          for(dummy = 0 ; dummy < volname.length ; dummy++)
            volwchar[dummy] = volname.unicode[dummy];
          volwchar[dummy] = L'\0';

          /* Then transform it in UTF8 */
          volutf8 = dm_SQL_WtoU8 (volwchar, SQL_NTS);
          if(volutf8)
            {
              prov = pathname;
              pathname =
                (char*) malloc ((pathname ? strlen (pathname) : 0) +
                volname.length + strlen("/Volumes/") + 2);
              strcpy(pathname, "/Volumes/");
              strcat(pathname, volutf8);
              if(prov)
                {
                  strcat(pathname, prov);
                  free(prov);
                }
              free(volutf8);
            }
        }
    }
#endif

  return pathname;
}
Пример #16
0
/* --------- Local Code --------- */
// static OSErr enumerate_files(
//	struct find_file_pb *param_block, 
//	long directory_id) /* Because it is recursive.. */
bool FileFinder::Enumerate(DirectorySpecifier& Dir)
{
	// Set up the temporary file
	TempFile.FromDirectory(Dir);

	// Kludge to make the FSSpec always available
	FSSpec& temp_file = TempFile.GetSpec();
	
	// Local variable
	short index;

	obj_clear(pb);
	
	pb.hFileInfo.ioVRefNum= Dir.Get_vRefNum();
	pb.hFileInfo.ioNamePtr= temp_file.name;

        // ZZZ addition
        bool KeepGoing = true;
			
	for(Err= noErr, index=1; count<max && Err==noErr && KeepGoing; index++) 
	{
		pb.hFileInfo.ioDirID= Dir.Get_parID();
		pb.hFileInfo.ioFDirIndex= index;

		Err= PBGetCatInfo( &pb, false);
		if(Err == noErr)
		{
			if ((pb.hFileInfo.ioFlAttrib & 16) && (flags & _ff_recurse))
			{
				/* Recurse, if you really want to... */

                                // ZZZ addition: callback on directory change if desired
                                if(directory_change_callback != NULL)
                                        KeepGoing = directory_change_callback(TempFile, true, (flags & _ff_callback_with_catinfo) ? &pb : user_data);

                                if(KeepGoing)
                                {
                                        // Set up volume info
                                        DirectorySpecifier SubDir = Dir;
                                        // Change the directory
                                        SubDir.Set_parID(pb.dirInfo.ioDrDirID);
                                        // Go!
                                        Enumerate(SubDir);
                                        // Reset the temporary file's directory to what's appropriate here
                                        // (it's global to this object)
                                        TempFile.FromDirectory(Dir);

                                        // ZZZ addition: callback on directory change if desired
                                        if(directory_change_callback != NULL)
                                                KeepGoing = directory_change_callback(TempFile, false, (flags & _ff_callback_with_catinfo) ? &pb : user_data);

                                }                                        
				
			} else {
				/* Add.. */
				if(Type==WILDCARD_TYPE || 
				   Type == TempFile.GetType())
				{
					/* Only add if there isn't a callback or it returns true */
					switch(search_type)
					{
						case _fill_buffer:
							if(!callback || callback(TempFile, user_data))
							{
								/* Copy it in.. */
								buffer[count++] = TempFile;
							}
							break;
							
						case _callback_only:
							assert(callback);
                                                                KeepGoing = callback(TempFile, (flags & _ff_callback_with_catinfo) ? &pb : user_data);
							break;
							
						default:
							assert(false);
							break;
					}
				}
			}
		} else {
			/* We ran out of files.. */
		}
	}

	/* If we got a fnfErr, it was because we indexed too far. */	
	if (Err == fnfErr) Err = noErr;
	
	return (Err == noErr);
}
Пример #17
0
P4 (PUBLIC pascal trap, OSErr, FSMakeFSSpec,
    int16, vRefNum, int32, dir_id,
    Str255, file_name, FSSpecPtr, spec)
{
    Str255 local_file_name;
    OSErr retval;
    HParamBlockRec hpb;

    if (!file_name)
        warning_unexpected("!file_name");

    /*
     * Colons make things tricky because they are used both to identify volumes
     * and to delimit directories and sometimes to identify partial paths.  Right
     * now, most of these uses of colon shouldn't cause problems, but there are
     * some issues that need to be checked on a real Mac.  What do all these
     * mean?
     *
     *     dir_id      file_name
     *     310         foo:
     *     310         :foo:
     *     310         foo:bar
     *     310         :foo:bar
     *     310         :foo:bar:
     *
     * what about all those file_names, but with dir_id = 0, dir_id = 1, dir_id = 2
     * and dir_id = a number that isn't a directory id?
     */

    if (pstr_index_after (file_name, ':', 0))
        warning_unexpected ("colon found");

    str255assign (local_file_name, file_name);
    hpb.volumeParam.ioNamePtr = (StringPtr) RM ((Ptr) local_file_name);
    hpb.volumeParam.ioVRefNum = CW (vRefNum);
    if (file_name[0])
        hpb.volumeParam.ioVolIndex = CLC (-1);
    else
        hpb.volumeParam.ioVolIndex = CLC (0);

    retval = PBHGetVInfo (&hpb, FALSE);

    if (retval == noErr)
    {
        CInfoPBRec cpb;

        str255assign (local_file_name, file_name);
        cpb.hFileInfo.ioNamePtr = (StringPtr) RM ((Ptr) local_file_name);
        cpb.hFileInfo.ioVRefNum = CW (vRefNum);
        if (file_name[0])
            cpb.hFileInfo.ioFDirIndex = CWC (0);
        else
            cpb.hFileInfo.ioFDirIndex = CWC (-1);
        cpb.hFileInfo.ioDirID = CL (dir_id);
        retval = PBGetCatInfo (&cpb, FALSE);
        if (retval == noErr)
        {
            spec->vRefNum = hpb.volumeParam.ioVRefNum;
            spec->parID = cpb.hFileInfo.ioFlParID;
            extract_name ((StringPtr) spec->name, MR (cpb.hFileInfo.ioNamePtr));
        }
        else if (retval == fnfErr)
        {
            OSErr err;

            cpb.hFileInfo.ioNamePtr = CLC (0);
            cpb.hFileInfo.ioVRefNum = CW (vRefNum);
            cpb.hFileInfo.ioFDirIndex = CWC (-1);
            cpb.hFileInfo.ioDirID = CL (dir_id);
            err = PBGetCatInfo (&cpb, FALSE);
            if (err == noErr)
            {
                if (cpb.hFileInfo.ioFlAttrib & ATTRIB_ISADIR)
                {
                    spec->vRefNum = hpb.volumeParam.ioVRefNum;
                    spec->parID = CL (dir_id);
                    extract_name ((StringPtr) spec->name, file_name);
                }
                else
                    retval = dupFNErr;
            }
        }
    }
    return retval;
}
Пример #18
0
CWindowPtr
createdirwindow (CInfoPBRec *dir, Rect *r, char **path, short volume)
{
  CWindowPeek wp;
  short i;
  OSErr e;
  Str255 s;
  opendirinfo **infoh;
  ControlHandle c;

  if (executor_p ())
    {
      CInfoPBRec cpb;
      OSErr e2;

      cpb = *dir;
      e2 = unixmount (&cpb);
      if (e2 == noErr)
	volume = cpb.hFileInfo.ioVRefNum;
    }
  tail (*path, s);
  wp = (CWindowPeek) NewPtr (sizeof (CWindowRecord));
  wp = (CWindowPeek) NewCWindow (wp, r, s, false, documentProc, (WindowPtr) 0, true, 0);
  wp->refCon = (long) NewHandle (sizeof (opendirinfo));

  infoh = (opendirinfo **) wp->refCon;
#if 1
/* This handle should be unlocked later, but it isn't for Executor 1.99m */
  HLock ((Handle) infoh);
#endif /* 0 */
  (*infoh)->sortorder = ALPHABETIC;
  (*infoh)->items = (ControlHandle (**)[])
    NewHandle (BANDARRAYSIZE * sizeof (ControlHandle));
  (*infoh)->path = path;
  (*infoh)->iodirid = dir->dirInfo.ioDrDirID;
  (*infoh)->vrefnum = volume;
  (*infoh)->numitems = 0;
  (*infoh)->view = ICONVIEW;

/* NOTE: r is the wrong rectangle, but it gets fixed before it's used. */
  (*infoh)->sbar = NewControl ((WindowPtr) wp, r, (StringPtr) "\p", false, 0, 0, 0,
			       scrollBarProc, 0);
  MoveControl ((*infoh)->sbar, wp->port.portRect.right - SCROLLBARWIDTH, 0);

  dir->hFileInfo.ioNamePtr = s;
  dir->hFileInfo.ioVRefNum = volume;
  e = noErr;
  for (i = 1; e == noErr; i++)
    {
      checkgrowitemarray (i, (*infoh)->items);
      dir->hFileInfo.ioDirID = (*infoh)->iodirid;
      dir->hFileInfo.ioFDirIndex = i;
      e = PBGetCatInfo (dir, false);
      if (e == noErr && !(dir->hFileInfo.ioFlFndrInfo.fdFlags & fInvisible))
	{
	  c = addtolist ((WindowPeek) wp, s, dir->hFileInfo.ioFlParID, volume);
	  if (dir->hFileInfo.ioFlFndrInfo.fdType == 'APPL' ||
	      dir->hFileInfo.ioFlFndrInfo.fdType == 'dfil')
	    hashicons (c);
	}
    }
  setwindowicons (wp);
  straightenwindow ((WindowPtr) wp);
  return (CWindowPtr) wp;
}
Пример #19
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(Public)
 *	Return the default directory name(s) where the profiles
 *	were loaded.  The argument Entries points to the first element in
 *	an array of SpDataBaseEntry structures.  The number of entries in
 *	the array is specified in the location pointed to by numEntries.
 *	The size of the dirName field in each entry in the array is specified 
 *	in the location pointed to by entrySize.  If the dirName field is not
 *	large enough to hold the default directory names the size required 
 *	is returned in the location pointed to by entrySize. 
 *
 * AUTHOR
 * 	Marleen_Clark & doro & M. Biamonte
 *
 * DATE CREATED
 *	October 16, 1995
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileGetDefaultDB(
				KpInt32_t		numEntries,
				KpInt32_t		FileNameSize,
				SpDataBaseEntry_p	Entries)
{
KpInt32_t	numDBs;
SpStatus_t 	spStat = SpStatSuccess;
KpInt32_t	count;
#if defined (KPSGI) || defined(KPSGIALL) || defined (KPSUN)
KpBool_t	DoesExist;
dirStatus	Dstat;
#endif

#if defined (KPMAC)
long		gestaltResponse;
OSErr       theErr;
long        theDirID;
short       theVRefNum;
char		fname[MAX_PATH];
CInfoPBRec	parm; /* parameters for call to ROM */
HFileInfo	*fParm = (HFileInfo *)&parm;
DirInfo		*dParm = (DirInfo *)&parm;
Boolean		async=false, ColorSyncAvailable=false;
short       folderID[3] = {kLocalDomain, kSystemDomain, kUserDomain};
KpInt32_t	i;
#endif
long	macOSVersion = 0;

#if defined (KPWIN32)
KpInt32_t		retVal;
#endif

	numDBs = GetDefaultDBCount();

#if defined (KPMAC)
	Gestalt(gestaltSystemVersion, &macOSVersion);
#endif

	if (macOSVersion >= 0x1000) {	/* Only will be non-zero on Mac */
		if (numEntries <=0)
      		return SpStatBufferTooSmall;
      	count = numDBs;	/* keep number of DBs we know about */
    }
    else {
      	if (numEntries < numDBs)
     		return SpStatBufferTooSmall;
    }

   numDBs = 0;

#if defined (KPSUN)
   if (FileNameSize < 40)  /* Testing against the longer 
                                   of the following two 
                                   directory paths */
      return SpStatBufferTooSmall;

   strcpy(Entries[numDBs].dirName, 
         "/usr/openwin/share/etc/devdata/profiles");
   Dstat = KpFileExists(Entries[numDBs].dirName,
                        &Entries[numDBs].fileProps,
                        &DoesExist);
   if (DoesExist == KPTRUE)
      numDBs++;

   strcpy(Entries[numDBs].dirName,
         "/etc/openwin/devdata/profiles");
   Dstat = KpFileExists(Entries[numDBs].dirName,
                        &Entries[numDBs].fileProps,
                        &DoesExist);
   if (DoesExist == KPTRUE)
      numDBs++;
      
     /* Set filenames of unused DBs to NULL */
   while (numDBs < numEntries)
   	 Entries[numDBs++].dirName[0] = '\0';

#else

#if defined (KPSGI) || defined(KPSGIALL)

   if (FileNameSize < 18)   /* Testing against the string size */
      return SpStatBufferTooSmall;

   strcpy(Entries[0].dirName,
         "/var/cms/profiles");

   Dstat = KpFileExists(Entries[numDBs].dirName, 
                        &Entries[numDBs].fileProps,
                        &DoesExist);
   if (DoesExist == KPTRUE)
      numDBs++;

     /* Set filenames of unused DBs to NULL */
   while (numDBs < numEntries)
   	 Entries[numDBs++].dirName[0] = '\0';

#elif defined (KPMAC)

#if defined (KPMACPPC)
	ColorSyncAvailable =
		((Gestalt(gestaltColorMatchingAttr, &gestaltResponse) == noErr)
			&& (gestaltResponse & (1<<gestaltColorMatchingLibLoaded)));
#else defined (KPMAC68K)
	if (Gestalt(gestaltColorMatchingVersion, &version) == noErr) {
		if (version >= gestaltColorSync20) {
			ColorSyncAvailable = true;
		}
	}
#endif

	if (macOSVersion < 0x1000)
	{
		if (ColorSyncAvailable == true) {
			theErr = CMGetColorSyncFolderSpec ( kOnSystemDisk, kDontCreateFolder,
   										&theVRefNum, &theDirID);
   		} else {
   			theErr = colorSyncNotInstalled;
   		}

		if (theErr == noErr) {
			strcpy(Entries[0].dirName, "");
			Entries[0].fileProps.dirID   = theDirID;
			Entries[0].fileProps.vRefNum = theVRefNum;
			numDBs++;
		} else {
			theErr = FindFolder(kOnSystemDisk, kPreferencesFolderType,
                       				kDontCreateFolder, &theVRefNum, &theDirID);


			if (theErr == noErr) {
				/* Get the folder name */
				GetIndString((StringPtr)fname, COLORSYNCSTR, 1);
				if (fname[0] == 0) { /* test for empty pascal string */
					return SpStatFileNotFound;
				}
				if (fname[0] > (unsigned long)FileNameSize) {
					return SpStatBufferTooSmall;
				}
				fParm->ioCompletion = nil;
				fParm->ioVRefNum    = theVRefNum;
				fParm->ioDirID      = theDirID;
				fParm->ioFDirIndex  = 0;
				fParm->ioNamePtr    = (StringPtr)fname;
				theErr = PBGetCatInfo(&parm,async);

				if (theErr == noErr) {
					strcpy(Entries[0].dirName, "");
					Entries[0].fileProps.dirID   = dParm->ioDrDirID;
					Entries[0].fileProps.vRefNum = fParm->ioVRefNum;
					numDBs++;
				} else {
					return SpStatFileNotFound;
				}
			} else {
				return SpStatFileNotFound;
			}
		}
	}
	else
	{	/* OS X Implementation */
		/* First find profiles folder */
			for (i = 0; (i < numEntries) && (i < count); i++)
			{
			
				theErr = FindFolder(folderID[i], kColorSyncProfilesFolderType,
                       				kCreateFolder, &theVRefNum, &theDirID);
				if (theErr == noErr) {
					strcpy(Entries[i].dirName, "");
					Entries[i].fileProps.dirID   = theDirID;
					Entries[i].fileProps.vRefNum = theVRefNum;
					numDBs++;
				} else {
					spStat =  SpStatFileNotFound;
				}
            }
    }
   
     /* Set filenames and Props of unused DBs to NULL */
	while (numDBs < numEntries) {
		Entries[numDBs].dirName[0] = '\0';
		Entries[numDBs].fileProps.dirID   = 0;
		Entries[numDBs++].fileProps.vRefNum = 0;   	
	} 

#elif defined (KPWIN32)

	retVal = GetWinDefaultDB (Entries[0].dirName, FileNameSize);
	if (retVal == SpStatSuccess) {
		numDBs++;
	}
	else {
		return retVal;
	}
	
     /* Set filenames of unused DBs to NULL */
   while (numDBs < numEntries)
   	 Entries[numDBs++].dirName[0] = '\0';
#else

   return SpStatFileNotFound;

#endif

#endif
   return spStat;
}