TweetFollow Us on Twitter

Dec 93 Tips, Tidbits
Volume Number:9
Issue Number:12
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: Accelerating MPW's Startup Sequence

This trick is described in the Examples folder that comes with MPW. But in talking to other users, I was surprised to find few people know about it, and even fewer use it.

When MPW is launched, it executes a script named “Startup,” which sets up environment variables, aliases, custom menus, and so forth. This can take from several seconds to over a minute.

It is easy to optimize this startup sequence. After launching MPW normally, copy the following lines into the MPW Worksheet window. Then highlight them as a block and press Enter:

/* 1 */

   Rename "{MPW}"Startup "{MPW}"Startup.Old
   Begin
      Set
      Export
      Alias
      AddMenu
   End > "{MPW}"Startup

This creates an optimized Startup script that will typically execute two to ten times faster than the original. The initial “Rename” command saves the original Startup script, so you can revert to it if you decide you don’t like the results. But if you do “before and after” timings, I think you’ll be happy with the speed improvement.

There are a couple of caveats though. First, the optimized Startup script is not organized and commented the same way the original is. If you frequently change your MPW configuration, you might find the optimized script harder to read and edit. Or you might find it to be easier; the point is that it is different.

Second, if you have UserStartup files that are often modified (such as UserStartup•RunMenu, described in MacTech Magazine, October, 1993), you may wish to add a line to the end of the optimized Startup script to forcibly execute the UserStartup commands. With UserStartup•RunMenu as an example, here’s what the command would look like:

        Execute "{PrefsFolder}"UserStartup•RunMenu

In doing this, you will cause some startup commands to be executed more than once (since some commands from the UserStartup will appear in the optimized Startup script as well). As a final “tweak,” you should then edit the optimized Startup script to delete any commands which will be carried out by forcibly executed UserStartup scripts.

- Lee David Rimar, Absoft Corporation

Strings that go both ways

When writing programs in C on the Macintosh, one thing that we need to deal with is the two possible formats of strings: C-style and Pascal-style. To save the repeated conversion time between the two formats, I sometimes use a format I call the two-in-one format that has both at once.

The C-style string uses a terminating zero character (null) at the end of the string to mark it’s length. The Pascal-style string uses a length byte as the first byte of the string (see figure). Both are allocated by allocating the space for the maximum number of characters the string will hold plus one for either the length byte or the termination byte. My two-in-one format uses both a length byte as it’s first byte and the zero byte as it’s last. To allocate this, take the data size and add two for both the Pascal-style length byte and the C-style terminator. The illustration shows how the length byte, string data, and terminator are laid out.

To use this as a Pascal string, simply use it normally. To use it as a C string, pass the string address as string + 1. Of course, if the size of the string is changed, then either the length byte or the terminator will need to adjusted. If you use calls that treat it as a C string, then the length byte will need adjusting. If you use Pascal-style calls, the terminator will need adjusting. The adjusting isn’t always as hard as you might think.

The following code fragment illustrates using the two-in-one string format:

/* 2 */

Str255  stringOne;
char  stringTwo[50];

...
/*   #1 Toolbox call uses Pascal-style string. */
GetIText (dialogItemHandle, stringOne);
stringOne[stringOne[0] + 1] = ’\0’;     // Add term. byte
...
/*   #2 Uses C-style string and returns the num. of characters. */
stringTwo[0] = sprintf (stringTwo + 1, “foobar”);
...
/*   #3 Two-in-one style, notice the length plus two. */
BlockMove (stringOne, stringTwo, stringOne[0] + 2);

In #1, the toolbox call returns a Pascal-style string, so, for the two-in-one format we’ve got to add the terminator. We know that stringOne[0] is the length byte and we know that stringOne[length] is the last byte of data in the string. So, the length plus one is the terminator byte.

In #2, we’re using the string as a C-style string. Notice that the C-style string starts at an offset of one, this avoids the Pascal-style length byte. Fortunately, sprintf returns the number of bytes (characters) written if there’s no error so we can use it to adjust the length byte. Other C library calls like printf, scanf and their derivatives also return the number of characters processed.

In #3, we’re using the Toolbox call BlockMove() to copy a two-in-one format string. Since the length is the length of the data, we’ve got to add two to allow for the length byte and the terminator byte.

I’ve found that judicious use of this string format can save a lot of conversion in string-heavy programs.

- Malcolm Teas

Step-step

In Think Pascal, the option key allows you to “step-step” through the code. Hold down the option key and pull down the RUN menu. You will see the step-step option. Step-step walks through your source code one line at a time, stepping into functions and procedures. It’s like a guided tour through your own program. Hold down the option key and browse through the Think Pascal menus. You may be surprised how much the option key modifies in the menus.

- Lillian Thompson, Reno, Nevada

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

FotoMagico 5.6.12 - Powerful slideshow c...
FotoMagico lets you create professional slideshows from your photos and music with just a few, simple mouse clicks. It sports a very clean and intuitive yet powerful user interface. High image... Read more
OmniGraffle Pro 7.12.1 - Create diagrams...
OmniGraffle Pro helps you draw beautiful diagrams, family trees, flow charts, org charts, layouts, and (mathematically speaking) any other directed or non-directed graphs. We've had people use... Read more
beaTunes 5.2.1 - Organize your music col...
beaTunes is a full-featured music player and organizational tool for music collections. How well organized is your music library? Are your artists always spelled the same way? Any R.E.M. vs REM?... Read more
HandBrake 1.3.0 - Versatile video encode...
HandBrake is a tool for converting video from nearly any format to a selection of modern, widely supported codecs. Features Supported Sources VIDEO_TS folder, DVD image or real DVD (unencrypted... Read more
Macs Fan Control 1.5.1.6 - Monitor and c...
Macs Fan Control allows you to monitor and control almost any aspect of your computer's fans, with support for controlling fan speed, temperature sensors pane, menu-bar icon, and autostart with... Read more
TunnelBear 3.9.3 - Subscription-based pr...
TunnelBear is a subscription-based virtual private network (VPN) service and companion app, enabling you to browse the internet privately and securely. Features Browse privately - Secure your data... Read more
calibre 4.3.0 - Complete e-book library...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital librarian... Read more
Lyn 1.13 - Lightweight image browser and...
Lyn is a fast, lightweight image browser and viewer designed for photographers, graphic artists, and Web designers. Featuring an extremely versatile and aesthetically pleasing interface, it delivers... Read more
Visual Studio Code 1.40.0 - Cross-platfo...
Visual Studio Code provides developers with a new choice of developer tool that combines the simplicity and streamlined experience of a code editor with the best of what developers need for their... Read more
OmniGraffle 7.12.1 - Create diagrams, fl...
OmniGraffle helps you draw beautiful diagrams, family trees, flow charts, org charts, layouts, and (mathematically speaking) any other directed or non-directed graphs. We've had people use Graffle to... Read more

Latest Forum Discussions

See All

The House of Da Vinci 2 gets a new gamep...
The House of Da Vinci launched all the way back in 2017. Now, developer Blue Brain Games is gearing up to deliver a second dose of The Room-inspired puzzling. Some fresh details have now emerged, alongside the game's first official trailer. [Read... | Read more »
Shoot 'em up action awaits in Battl...
BattleBrew Productions has just introduced another entry into its award winning, barrelpunk inspired, BattleSky Brigade series. Whilst its previous title BattleSky Brigade TapTap provided fans with idle town building gameplay, this time the... | Read more »
Arcade classic R-Type Dimensions EX blas...
If you're a long time fan of shmups and have been looking for something to play lately, Tozai Games may have just released an ideal game for you on iOS. R-Type Dimensions EX brings the first R-Type and its sequel to iOS devices. [Read more] | Read more »
Intense VR first-person shooter Colonicl...
Our latest VR obsession is Colonicle, an intense VR FPS, recently released on Oculus and Google Play, courtesy of From Fake Eyes and Goboogie Games. It's a pulse-pounding multiplayer shooter which should appeal to genre fanatics and newcomers alike... | Read more »
PUBG Mobile's incoming update bring...
PUGB Mobile's newest Royale Pass season they're calling Fury of the Wasteland arrives tomorrow and with it comes a fair chunk of new content to the game. We'll be seeing a new map, weapon and even a companion system. [Read more] | Read more »
PSA: Download Bastion for free, but wait...
There hasn’t been much news from Supergiant Games on mobile lately regarding new games, but there’s something going on with their first game. Bastion released on the App Store in 2012, and back then it was published by Warner Bros. This Warner... | Read more »
Apple Arcade: Ranked - 51+ [Updated 11.5...
This is Part 2 of our Apple Arcade Ranking list. To see part 1, go here. 51. Patterned [Read more] | Read more »
NABOKI is a blissful puzzler from acclai...
Acclaimed developer Rainbow Train's latest game, NABOKI, is set to launch for iOS, Android, and Steam on November 13th. It's a blissful puzzler all about taking levels apart in interesting, inventive ways. [Read more] | Read more »
A Case of Distrust is a narrative-driven...
A Case of Distrust a narrative-focused mystery game that's set in the roaring 20s. In it, you play as a detective with one of the most private eye sounding names ever – Phyllis Cadence Malone. You'll follow her journey in San Francisco as she... | Read more »
Brown Dust’s October update offers playe...
October is turning out to be a productive month for the Neowiz team, and a fantastic month to be a Brown Dust player. First, there was a crossover event with the popular manga That Time I Got Reincarnated as a Slime. Then, there was the addition of... | Read more »

Price Scanner via MacPrices.net

Score a 37% discount on Apple Smart Keyboards...
Amazon has Apple Smart Keyboards for current-generation 10″ iPad Airs and previous-generation 10″ iPad Pros on sale today for $99.99 shipped. That’s a 37% discount over Apple’s regular MSRP of $159... Read more
Apple has refurbished 2019 13″ 1.4GHz MacBook...
Apple has a full line of Certified Refurbished 2019 13″ 1.4GHz 4-Core Touch Bar MacBook Pros available starting at $1099 and up to $230 off MSRP. Apple’s one-year warranty is included, shipping is... Read more
2019 13″ 1.4GHz 4-Core MacBook Pros on sale f...
Amazon has new 2019 13″ 1.4GHz 4-Core Touch Bar MacBook Pros on sale for $150-$200 off Apple’s MSRP. These are the same MacBook Pros sold by Apple in its retail and online stores: – 2019 13″ 1.4GHz/... Read more
11″ 64GB Gray WiFi iPad Pro on sale for $674,...
Amazon has the 11″ 64GB Gray WiFi iPad Pro on sale today for $674 shipped. Their price is $125 off MSRP for this iPad, and it’s the lowest price available for the 64GB model from any Apple reseller. Read more
2019 15″ MacBook Pros available for up to $42...
Apple has a full line of 2019 15″ 6-Core and 8-Core Touch Bar MacBook Pros, Certified Refurbished, available for up to $420 off the cost of new models. Each model features a new outer case, shipping... Read more
2019 15″ MacBook Pros on sale this week for $...
Apple resellers B&H Photo and Amazon are offering the new 2019 15″ MacBook Pros for up to $300 off Apple’s MSRP including free shipping. These are the same MacBook Pros sold by Apple in its... Read more
Sunday Sale: AirPods with Wireless Charging C...
B&H Photo has Apple AirPods with Wireless Charging Case on sale for $159.99 through 11:59pm ET on November 11th. Their price is $40 off Apple’s MSRP, and it’s the lowest price available for these... Read more
Details of Sams Club November 9th one day App...
Through midnight Saturday night (November 9th), Sams Club online has several Apple products on sale as part of their One Day sales event. Choose free shipping or free local store pickup (if available... Read more
Sprint is offering the 64GB Apple iPhone 11 f...
Sprint has the new 64GB iPhone 11 available for $15 per month for new lines. That’s about 50% off their standard monthly lease of $29.17. Over is valid until November 24, 2019. The fine print: “Lease... Read more
New Sprint November iPhone deal: Lease one iP...
Switch to Sprint and purchase an Apple iPhone 11, 11 Pro, or 11 Pro Max, and get a second 64GB iPhone 11 for free. Requires 2 new lines or 1 upgrade-eligible line and 1 new line. Offer is valid from... Read more

Jobs Board

*Apple* Mobility Pro - Best Buy (United Stat...
**746087BR** **Job Title:** Apple Mobility Pro **Job Category:** Store Associates **Store NUmber or Department:** 000319-Harlem & Irving-Store **Job Description:** Read more
Best Buy *Apple* Computing Master - Best Bu...
**743392BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Store Associates **Store NUmber or Department:** 001171-Southglenn-Store **Job Read more
Best Buy *Apple* Computing Master - Best Bu...
**746015BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Store NUmber or Department:** 000372-Federal Way-Store **Job Description:** Read more
*Apple* Mobility Pro - Best Buy (United Stat...
**744658BR** **Job Title:** Apple Mobility Pro **Job Category:** Store Associates **Store NUmber or Department:** 000586-South Hills-Store **Job Description:** At Read more
Best Buy *Apple* Computing Master - Best Bu...
**741552BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Store NUmber or Department:** 000277-Metcalf-Store **Job Description:** **What Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.