TweetFollow Us on Twitter

Jun 99 Tips

Volume Number: 15 (1999)
Issue Number: 6
Column Tag: Tips & Tidbits

Jun 99 Tips

by Jeff Clites, online@mactech.com

Conversion from Intel Byte Order

Intel microprocessors store integer data in a different way than the PowerPC does. The PowerPC (operating under the Mac OS) stores the bytes in big endian order, from the most significant to the least significant, while the Intel processor uses the opposite byte order (little endian).

When you are using a Macintosh but have to read a file created on a computer with an Intel processor, or when you have to write a file for later use on an Intel machine, this difference is something you have to worry about. You can use the following routines to convert shorts and longs back and forth between the two byte orders.

#define MotorolaToIntelLong IntelToMotorolaLong
#define MotorolaToIntelShort IntelToMotorolaShort
/* Prototypes */
unsigned long IntelToMotorolaLong (unsigned long original);
unsigned short IntelToMotorolaShort 
							(unsigned short original);
/* Intel to Motorola bytes order */
/* Little endian to big endian   */
unsigned long IntelToMotorolaLong (unsigned long original)
{
	unsigned long converted;
	char *b;
	converted = 0L;
	if (original == 0) return converted;
	b = (char*)&converted;
	*b++ = (char)(original);
	*b++ = (char)(original >> 8);
	*b++ = (char)(original >> 16);
	*b++ = (char)(original >> 24);
	return converted;
}

/* Intel to Motorola bytes order */
/* Little endian to big endian   */
unsigned short IntelToMotorolaShort 
							(unsigned short original)
{
	unsigned short converted;
	char *b;
	converted = 0;
	if (original == 0) return converted;
	b = (char *)&converted;
	*b++ = (char)(original);
	*b++ = (char)(original >> 8);
	return converted;
}

Marco Bambini
marco@spiderlink.it

C++ File Streams and FSSpecs

When using ANSI C and C++ file routines, Macintosh programmers run into the unfortunate snag that these routines assume that files are properly identified by path names, but under the Mac OS they are specified through an FSSpec data structure. Of course, it is possible to obtain the full path to a file given its FSSpec, but this isn't really a solution, because on the Macintosh full path names don't uniquely identify files (for instance, if the user has more than one mounted disk with the same name).

Fortunately, Metrowerks has provided FSp_fopen, which works like C's fopen except that it uses FSSpecs instead of paths. To similarly obtain a C++ file stream you have to do a little more work, but the following example from Metrowerks' MWRon <MWRon@metrowerks.com> demonstrates how to do it with minimal fuss.

#include <iostream>
#include <fstream>
#include <SIOUX.h>
#include <unistd.h>
#include <cstring>
using namespace std;
int GetStream(FSSpec &fs, ifstream &in);
void Initialize(void);
const int PSIZE = 256;
char AppPathName[PSIZE];
char FilePathName[PSIZE];
int main()
{
	// initialize your managers
	Initialize();
	SIOUXSettings.initializeTB = FALSE;
	ifstream in;  // input file
	strcpy(AppPathName , "");		// safety
	strcpy(FilePathName , "");	// safety
	const short kNilFilterProc = nil;	// use dialog to open file
	StandardFileReply  reply;
	short numTypes = 0;
	SFTypeList typeList;
	FSSpec fs;
 	StandardGetFile( kNilFilterProc, numTypes, typeList, &reply);
	fs = reply.sfFile;
 	if(GetStream(fs, in)) exit(1); // stream failed to open
 	strcat(FilePathName, p2cstr(fs.name) );
 	c2pstr((char *)fs.name); 
	// see where we are at now
	cout << "The folder holding the executable is \n" 
 		<< getcwd(AppPathName, PSIZE) << endl;
 	cout << "The opened file's full name is \n" 
 		<< FilePathName << endl;
  	
	return 0;
}
 
int GetStream(FSSpec &fs, ifstream &in)
{
	short savedVol;
	OSErr err = 0;

	// get volume of application
	if ( (err = GetVol(0, &savedVol)) != NULL)
		return err;

	// set working volume	
	if ((err = HSetVol(0, fs.vRefNum, fs.parID)) != NULL)
		return err;
	
	// open file 
	in.open(p2cstr(fs.name));
	if(!in) { err = 1; return err;}
	c2pstr((char *)fs.name);
	getcwd(FilePathName, PSIZE);   // get working directory	
	// reset volume of application
	if( (err = SetVol(0, savedVol)) != NULL)
		return err;
	
	return err;
}

void Initialize(void)
{
	/* Initialize all the needed managers. */
	InitGraf(&qd.thePort);
	InitFonts();
	InitWindows();
	InitMenus();
	TEInit();
	InitDialogs(nil);
	InitCursor();
}
 
AAPL
$101.79
Apple Inc.
+0.21
MSFT
$46.68
Microsoft Corpora
+0.16
GOOG
$589.27
Google Inc.
+4.50

MacTech Search:
Community Search:

Software Updates via MacUpdate

iMazing 1.0 - Complete iOS device manage...
iMazing (formerly DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can: Copy music to and... Read more
Xcode 6.0.1 - Integrated development env...
Apple Xcode is Apple Computer's integrated development environment (IDE) for OS X. The full Xcode package is free to ADC members and includes all the tools you need to create, debug, and optimize... Read more
Apple Safari 7.1 - Apple's Web brow...
Apple Safari in OS X Mavericks brings you all-new ways to find and enjoy the best of the web. It works with iCloud to give you a seamless browsing experience across all your devices. It looks out for... Read more
Delivery Status 6.1.2 - Check delivery s...
Delivery Status displays delivery status of packages for a variety of shipment services. Can't wait for your packages to arrive? Don't waste your time checking the site constantly, just open this all... Read more
Mavericks Cache Cleaner 8.0.9 - Clear ca...
Mavericks Cache Cleaner is an award-winning general purpose tool for OS X. MCC makes system maintenance simple with an easy point-and-click interface to many OS X functions. Novice and expert users... Read more
OneNote 15.2.2 - Free digital notebook f...
OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that's too important to forget. Whether you're at... Read more
Apple Configurator 1.6 - Configure and d...
Apple Configurator makes it easy for anyone to mass configure and deploy iPhone, iPad, and iPod touch in a school, business, or institution. Three simple workflows let you prepare new iOS devices... Read more
SpamSieve 2.9.16 - Robust spam filter fo...
SpamSieve is a robust spam filter for major email clients that uses powerful Bayesian spam filtering. SpamSieve understands what your spam looks like in order to block it all, but also learns what... Read more
OS X Server 3.2.1 - For OS X 10.9.5 Mave...
OS X Server is the next generation of Apple's award winning server software. Designed for OS X and iOS devices, OS X Server makes it easy to share files, schedule meetings, synchronize contacts, host... Read more
Apple Security Update 2014-004 - For OS...
Apple Security Update is recommended for all users and improves the security of Mac OS X. For information on the security content of this update, please visit this website: http://support.apple.com/... Read more

Latest Forum Discussions

See All

Down Among the Dead Men (Games)
Down Among the Dead Men 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: Avast! Take to the high seas in a fully interactive piratical tale of broadsides and buccaneers. From author Dave... | Read more »
Sling Adds Chromecast Support Through Sl...
Sling Adds Chromecast Support Through Slingplaye​r Mobile Apps Posted by Jessica Fisher on September 18th, 2014 [ permalink ] | Read more »
How to Completely Delete Your iPhone’s C...
The iPhone 6 is out tomorrow, and plenty of people are excited about it. So much so that they’re planning to – or already have – traded in their old iPhone to go towards it. The thing about trading in hardware is it’s very important to make sure... | Read more »
Dragon Quest I Review
Dragon Quest I Review By Andrew Fisher on September 18th, 2014 Our Rating: :: THINE QUEST AWAITETHUniversal App - Designed for iPhone and iPad Its historical significance aside, Dragon Quest 1 is a fun, campy, difficult, thoroughly... | Read more »
It Came From Canada: Overkill 3
Overkill 3 is like every trope of big modern gaming rolled into one. It’s a sequel to an action-packed military shooter. It’s flashy and scripted and flaunts its sophisticated graphics. And it’s a mobile game with a heavy emphasis on in-app... | Read more »
New Modes and Leader Boards in Update fo...
New Modes and Leader Boards in Update for Rules! Posted by Jessica Fisher on September 18th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
TwistedRun Review
TwistedRun Review By Rob Thomas on September 18th, 2014 Our Rating: :: DON'T TWIST YOUR ANKLE!Universal App - Designed for iPhone and iPad TwistedRun is kind of like running up a giant curly fry into the sky. Or maybe that was just... | Read more »
Scope Review
Scope Review By Jennifer Allen on September 18th, 2014 Our Rating: :: LOCATION AWAREiPhone App - Designed for the iPhone, compatible with the iPad Want to easily find photos from around the world based on their location? Scope is a... | Read more »
HipstaFox Review
HipstaFox Review By Jordan Minor on September 18th, 2014 Our Rating: :: FANTASTIC MR. FOXUniversal App - Designed for iPhone and iPad HipstaFox is a great single that makes players long for the whole album.   | Read more »
Ninja Raft (Games)
Ninja Raft 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: ** Special Launch Price ** "Ninja Raft is definitely the game to play if you’re into Tower Defense games and want to play something... | Read more »

Price Scanner via MacPrices.net

Save up to $300 on the price of a new Mac wit...
Purchase a new Mac or iPad at The Apple Store for Education and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free,... Read more
13-inch 2.8GHz Retina MacBook Pro available f...
B&H Photo has the new 2014 13″ 2.8GHz Retina MacBook Pro on sale for $1699.99 including free shipping plus NY sales tax only. They’ll also include free copies of Parallels Desktop and LoJack for... Read more
16GB iPad Air on sale for $449, save $50
Walmart has the 16GB iPad Air WiFi on sale for $449 on their online store for a limited time. Choose free home shipping or free local store pickup. Their price represents a $50 savings over standard... Read more
13-inch 256GB MacBook Air on sale for $1099,...
B&H Photo has the 2014 13″ 1.4GHz 256GB MacBook Air on sale for $1099.99. Shipping is free, and B&H charges NY sales tax only. Their price is $100 off MSRP. Read more
Toshiba Introduces TransMemory ID High-Speed...
Toshiba’s Digital Products Division (DPD), a division of Toshiba America Information Systems, Inc., today introduced the TransMemory ID USB 3.0 Flash Drive, a simpler storage solution for people who... Read more
New iPads and OS X Yosemite Release Coming Oc...
The DailyDot’s Micah Singleton reports that Apple is planning to hold its next product announcement event on Oct. 21, at which it will unveil the iPad Air 2 and iPad mini 3 and release a final build... Read more
Logitech Bluetooth Multi-Device Cross-Platfor...
Logitech has an enviable track record of making some of the best computer keyboards and mice. At least in my estimation, the best freestanding keyboards I’ve ever used have been Logitech units,... Read more
Roundup of Apple refurbished iPad Airs and iP...
Apple is offering Certified Refurbished iPad Airs for up to $140 off MSRP. Apple’s one-year warranty is included with each model, and shipping is free. Stock tends to come and go with some of these... Read more
Sprint offers 16GB iPad mini for $199.99 with...
Sprint is offering 1st generation 16GB iPad minis for $199.99 with a 2-year service agreement. Standard MSRP for this iPad is $429. Their price is the lowest available for this model. Read more
2.5GHz Mac mini remains on sale for $549, sav...
B&H Photo has the 2.5GHz Mac mini on sale for $549.99 including free shipping. That’s $50 off MSRP, and B&H will also include a free copy of Parallels Desktop software. NY sales tax only. Read more

Jobs Board

Project Manager, *Apple* Financial Services...
**Job Summary** Apple Financial Services (AFS) offers consumers, businesses and educational institutions ways to finance Apple purchases. We work with national and Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.