Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / October 2004



Tip: Looking for answers? Try searching our database.

Overview of string conversions?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
r5 - 27 Oct 2004 21:53 GMT
Is there a well-contained overview of the string objects
and methods associated with FSSpec and Str255?  I am having
a terrible time just trying to find out how to convert
a char * to an FSSpec.  It appears that some string services from
the past are no longer supported (e.g. NativePathNameToFSSpec
or c2pstr).  Thanks.

#include <Carbon/Carbon.h>
#include <CoreServices/CoreServices.h>

int main()
{
 FSSpec fss;
 char *text = "/tmp/junk.txt";
 Str255 name;
 c2pstr(strcpy((char*)name, text));   /// <-- SEE ERROR [1]
 OSErr err = FSMakeFSSpec (0, 0, name, &fss);
 return 0;
}

[1] 14: implicit declaration of function `int c2pstr(...)'
Eric VERGNAUD - 27 Oct 2004 21:59 GMT
dans l'article r5ahhj-F988A5.15530527102004@newssvr11-ext.news.prodigy.com,
r5 à r5ahhj@r5ahhj.bounceme.net a écrit le 27/10/04 22:53 :

> Is there a well-contained overview of the string objects
> and methods associated with FSSpec and Str255?  I am having
[quoted text clipped - 17 lines]
>
> [1] 14: implicit declaration of function `int c2pstr(...)'

If you're using unix-style paths, you'd better switch to FSRef api. FSSpecs
expect locale dependant pascal strings, while FSRefs work with UTF-8. Also
FSSpecs are imited in name size, and you might encounter mangled names whan
they describe a file object with a long name.

The only big problem with FSRefs is that you cannot have a FSRef pointing to
an inexistant file object.

Eric
r5 - 27 Oct 2004 22:59 GMT
> If you're using unix-style paths, you'd better switch to FSRef api. FSSpecs

Is there an equivalent to CreateMovieFile() which accepts FSRef
objects?  Thanks.
r5 - 27 Oct 2004 23:36 GMT
Thanks for the help.  I found something that works:

{
 FSSpec fss;
 FSRef ref;

 char *text = "/tmp/junk.txt";

 //
 // Easy way to force existence of the file to be created.
 //
 ofstream ostrm(text);
 ostrm.close();

 OSStatus status = FSPathMakeRef((const UInt8 *) text, &ref, NULL);

 OSErr err = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL,
                              &fss, NULL);
}
Eric Albert - 28 Oct 2004 04:31 GMT
In article
<r5ahhj-762BFE.17365027102004@newssvr30-ext.news.prodigy.com>,

> Thanks for the help.  I found something that works:
>
[quoted text clipped - 15 lines]
>                                &fss, NULL);
> }

Good, because that's the right way to do it. :)  (Well, as long as you
check the return value of FSPathMakeRef.)

-Eric

Signature

Eric Albert         ejalbert@cs.stanford.edu
http://outofcheese.org/

Miro Jurisic - 27 Oct 2004 22:28 GMT
> Is there a well-contained overview of the string objects
> and methods associated with FSSpec and Str255?  I am having
> a terrible time just trying to find out how to convert
> a char * to an FSSpec.  It appears that some string services from
> the past are no longer supported (e.g. NativePathNameToFSSpec
> or c2pstr).  Thanks.

It depends on what's in the char*. Where did it come from?

meeroh

Signature

If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist>

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.