TweetFollow Us on Twitter

Jun 93 Tidbits
Volume Number:9
Issue Number:6
Column Tag:Tips & Tidbits

Tips & Tidbits

By Neil Ticktin, Editor-in-Chief

This column is your opportunity to spread the word about little bits of information that you find out about. These tidbits can be programming related or they can be user tips that are particularly useful to programmers.

MacTech Magazine will pay $25 for every tip used, and $50 for the Tip of the Month. Or you can take your award in orders or subscriptions.

To submit a tip, send in a letter to the magazine. E-mail is our preferred method, but feel free to send something via the US Mail. See page two for all addresses. If you do send snail mail, enclose a printed copy and a disk copy of the letter so that it does not have to be retyped.

Tip of the month

Ira Ruben has written a useful code disassembler for ResEdit. However, it has drawbacks - in particular, it’s not very intelligent about handling data interspersed with the code (such as embedded string literals). Also, you can’t invoke it on just any resource type: if you come across a new type of code-containing resource (such as those “AINI” resources that System 7 uses), you have to modify ResEdit to be able to disassemble the new resource type.

MacsBug has much nicer disassembly facilities, and you can dump out different bits of memory using different formats if you choose. Wouldn’t it be nice if you could use these facilities on resources you were examining with ResEdit? Well, you can!

First of all, open the resource you want to examine with ResEdit. Make sure the resource is open for editing in a window (using any available editor - even the hex editor). Now, hold down the mouse button over ResEdit’s menu bar (an unused portion is best), and with your other hand, hit the interrupt button (or keyboard interrupt sequence) to get into MacsBug. Once you’re in MacsBug, you can let go of the mouse button.

Check the CurApName on the left of MacsBug’s display, to make sure you’re in ResEdit (it will be in the middle of calling MenuSelect). Now type

hd AINI

(replace “AINI” with whatever the type of the resource is that you want to examine). You will get a list of all resources of that type in the current heap zone, along with their starting addresses, lengths, resource IDs and names, and the refnum of the file they come from. Look for the one with the right ID or name. If you want to make sure you’ve got the right one, you can also use the command

file <refnum>

(replacing “<refnum>” with whatever the file refnum is for that resource) to make sure that the resource comes from the right file. Now you’re free to use commands like il and dm to examine bits of that resource.

If you’re making patches to code, you can use MacsBug’s dh command to check that you’ve got the right instruction words before making the modifications. Also, if you make any changes to a resource in ResEdit’s hex editor, you can go into MacsBug and disassemble that resource, and examine the effects of your changes immediately, before you save them.

- Lawrence D’Oliveiro

University of Waikato

Hamilton, New Zealand

MPW as a “Real” Language

I though that I would write in on “How MPW scripts can perform tasks that might otherwise require you to code in a "real" computer language”. In the past few years, I've had to answer many users' questions on MPW, and I've accumulated a supply of interesting scripts and techniques. As an example, I could have answered Mike Scanlin's March Programmers' Challenge (count unique words) with this script:

Evaluate 
`Begin ; 
  Catenate 
  `GetFilename -t TEXT -b Count -m "UNIQUE WORD COUNT"` ; 
  Echo ; 
 End | 
Translate "A-Z ,." a-zn | 
Sort -unique | 
Count -l` - 1

Obviously, this entry doesn’t qualify because it is not in C, but it is yet another demonstration of MPW's power.

- Lee D. Rimar, Absoft

Source and Line info

After reading the tip of the month in the May issue, I thought others might like to see what I use for debug formatting. It has the same benefits as the DebugFStr routine (i.e., formatted output), but adds automatic source file and line number information to the debug output. Using the routine is identical to using printf, except it is now called dprintf. The dprintf routine itself is actually a macro that invokes one routine to store the caller's file name and line number, then calls the actual output routine.

To use dprintf, include dprintf.h in any files that use it, and make sure you've added ANSI or ANSI-small to your project. Call it anywhere just like you'd call printf.

/*-------- dprintf.h ---------*/

#define dprintf  dprintf_setup(__FILE__,__LINE__), dprintf_output

extern int dprintf_setup(const char *file, int line);
extern int dprintf_output(const char *fmt, ...);

/*-------- dprintf.c ---------*/

#include <stdarg.h>
#include <stdio.h>
#include "dprintf.h"

static int d_line;
static char d_file[32];

int
dprintf_setup(const char *file, int line)
{
 d_line = line;
 strncpy(d_file, file, sizeof(d_file));
 d_file[sizeof(d_file)-1] = 0;
 return 0;
}

int
dprintf_output(const char *fmt, ...)
{
 va_list ap;
 Str255 buf;
 
 sprintf(buf, "%s %d: ", d_file, d_line);
 va_start(ap, fmt);
 vsprintf(buf + strlen(buf), fmt, ap);
 va_end(ap);
 CtoPstr(buf);
 DebugStr(buf);
 return 0;
}

- Mark Nagel

Irvine, CA

System 7 FindFolder

There is a neat little function in System 7 called FindFolder(). It lets you find important system folders with little effort. I used it to find the preferences folder into which I placed my own folder. This worked fine under MacOS. I had a nice little combination of FindFolder(), FSOpen() and Create() calls. The problem begins with the A/UX way of seeing directories. These are more like Unix than Apple folders.

A/UX preferences folder = /mac/sys/System Folder/Preferences
Mac preferences folder = System Folder:Preferences

The A/UX path as presented is what FindFolder() returns. Unfortunately this does not work as a path for older Mac function calls. All the PB, PBH and other pre-System 7 calls do not understand this. to use this format directly you need to do either a) or b):

a) Use the FSSpec type of calls everywhere, which works very well after you get used to them; or b) Convert all your paths to the following:

A/UX FindFolder() gives:

/mac/sys/System Folder/Preferences

You need:

/:mac:sys:System Folder:Preferences

The key here being the '/:' at the beginning.

- CHUS-FAMUS

[Remember to keep them cards and letters coming. The more entries, the better the entries. - Ed.]

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »
Play Together teams up with Sanrio to br...
I was quite surprised to learn that the massive social network game Play Together had never collaborated with the globally popular Sanrio IP, it seems like the perfect team. Well, this glaring omission has now been rectified, as that instantly... | Read more »
Dark and Darker Mobile gets a new teaser...
Bluehole Studio and KRAFTON have released a new teaser trailer for their upcoming loot extravaganza Dark and Darker Mobile. Alongside this look into the underside of treasure hunting, we have received a few pieces of information about gameplay... | Read more »
DOFUS Touch relaunches on the global sta...
After being a big part of a lot of gamers - or at the very least my - school years with Dofus and Wakfu, Ankama sort of shied away from the global stage a bit before staging a big comeback with Waven last year. Now, the France-based developers are... | Read more »

Price Scanner via MacPrices.net

Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more
B&H has 16-inch MacBook Pros on sale for...
Apple 16″ MacBook Pros with M3 Pro and M3 Max CPUs are in stock and on sale today for $200-$300 off MSRP at B&H Photo. Their prices are among the lowest currently available for these models. B... Read more
Updated Mac Desktop Price Trackers
Our Apple award-winning Mac desktop price trackers are the best place to look for the lowest prices and latest sales on all the latest computers. Scan our price trackers for the latest information on... Read more
9th-generation iPads on sale for $80 off MSRP...
Best Buy has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80 off MSRP on their online store for a limited time. Prices start at only $249. Sale prices for online orders only, in-store prices... Read more
15-inch M3 MacBook Airs on sale for $100 off...
Best Buy has Apple 15″ MacBook Airs with M3 CPUs on sale for $100 off MSRP on their online store. Prices valid for online orders only, in-store prices may vary. Order online and choose free shipping... Read more
24-inch M3 iMacs now on sale for $150 off MSR...
Amazon is now offering a $150 discount on Apple’s new M3-powered 24″ iMacs. Prices start at $1149 for models with 8GB of RAM and 256GB of storage: – 24″ M3 iMac/8-core GPU/8GB/256GB: $1149.99, $150... Read more
15-inch M3 MacBook Airs now on sale for $150...
Amazon is now offering a $150 discount on Apple’s new M3-powered 15″ MacBook Airs. Prices start at $1149 for models with 8GB of RAM and 256GB of storage: – 15″ M3 MacBook Air/8GB/256GB: $1149.99, $... Read more
The latest Apple Education discounts on MacBo...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take up to $300 off the purchase of a new MacBook... Read more

Jobs Board

Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Retail Assistant Manager- *Apple* Blossom Ma...
Retail Assistant Manager- APPLE BLOSSOM MALL Brand: Bath & Body Works Location: Winchester, VA, US Location Type: On-site Job ID: 04225 Job Area: Store: Management Read more
Housekeeper, *Apple* Valley Village - Cassi...
Apple Valley Village Health Care Center, a senior care campus, is hiring a Part-Time Housekeeper to join our team! We will train you for this position! In this role, Read more
Sonographer - *Apple* Hill Imaging Center -...
Sonographer - Apple Hill Imaging Center - Evenings Location: York Hospital, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now See Read more
Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.