home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / BookmarksFile.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  1.6 KB  |  61 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "BookmarksFile.h"
  20. #include "resgui.h"
  21. #include <LStream.h>
  22.  
  23. #include <algorithm>
  24.  
  25.  
  26. //
  27. // ReadBookmarksFile
  28. //
  29. // Given a file containing a single URL (probably dropped on the Finder), open it and
  30. // create a bookmark entry for it so we can load it.
  31. //
  32. OSErr 
  33. ReadBookmarksFile ( vector<char> & oURL, FSSpec & inSpec )
  34. {
  35.     FInfo info;
  36.     OSErr err = ::FSpGetFInfo (&inSpec, &info);
  37.     if (err != noErr)
  38.         return err;
  39.     
  40.     if (info.fdType != emBookmarkFile)
  41.         return fnfErr;
  42.  
  43.     try {
  44.         LFileStream stream(inSpec);
  45.         stream.OpenDataFork(fsRdPerm);
  46.         Int32 howMuch;
  47.         
  48.         // Read in the URL, which is in the form URL\rTITLE
  49.         howMuch = stream.ReadData(oURL.begin(), oURL.size());
  50.         char* where = find(oURL.begin(), oURL.end(), '\r');
  51.         ThrowIfNil_(where);
  52.         *where = 0;
  53.     }
  54.     catch ( Uint32 inErr )
  55.     {
  56.         return inErr;
  57.     }
  58.     
  59.     return noErr;
  60. }
  61.