In the process of porting my MPW C program to CodeWarrior; I'm no...

Posted 2025-04-13 | Back to blog index

In the process of porting my MPW C program to CodeWarrior; I'm now past the easy part of "need to fix missing header files and rename old toolbox calls" and into the need-to-read-a-book parts of "C doesn't have a concept of booleans so what does this compiler expect" and how to make pointers to functions work kind of stuff...

A macos 9 screenshot of CodeWarrior showing the incomprehensible compile errors

Update on 2025-04-15:

Yay, I successfully got it to build under CodeWarrior!

A screenshot of AIRConfig showing a “Changes successfully written” dialog

Files seem to work fine but it doesn't like the HTTP parsing code - loading a URL results in this error (that it can't find the end of the HTTP headers)

A dialog that says “Could not load URL -998” and the code that defines the error -998 being code that looks for two newlines

An excuse to try out the CodeWarrior debugger! This thing looks awesome!

From this I can see that the problem seems to be that the request isn't being built/sent properly and the server is sending a 400 Bad Request error, which is why it can't find a result and fails.

Metrowerks CodeWarror debugger stopped on the return -998 line, showing the httpDataPtr variable containing HTTP 400 Bad Request

And it's fixed!

The problem was due to MPW having a backwards interpretation of \n and \r that I was using, and CodeWarrior uses the standard one! They even have an option in the compiler settings to use the MPW mode.

CodeWarrior C language settings dialog with ballon help showing an option to use MPW conventions for \n and \r AIRConfig screenshot showing it successfully loading a list from the Internet

I did a quick web search to see if anyone had discussed the history of this MPW feature, but instead found a Stack Overflow thread with everyone confidently incorrecting each other that it's impossible and never happened, so those are the "facts" your LLMs are going to be trained on.

If anyone is curious to see the changes required: https://github.com/kalleboo/AIRConfig/commit/ba921ee84efb666de5f5599cb9fda966dc2044f6

In the end this is what I had to do:

- Remove all the Mac Toolbox header includes, CodeWarrior does it automagically

- Remove the jank “include all C files directly in the main file" method I used to avoid having to learn MPW Make. CW projects are automatic

- Add missing function prototypes (that MPW didn't need) and externs that I now need when it's not all one postprocessed file

- Fix that \r and \n are reversed in MPW

- Rename old "short" Toolbox calls to newer "long" ones… (1/2)

- Add missing define for geneva font family ID

- Remove MPW-specific boilerplate (_DataInit, QDGlobals)

- Ditch Rez file in favor of a ResEdit file

The Boolean and function pointer stuff I thought I had problems with in the first post were red herrings to other problems with my function prototypes/externs and how I was putting them in header files. Both Booleans and function pointers work exactly the same as in MPW!

(2/2)

I need to start tracking these changes in Projector/SourceServer instead of git 🤔

I've never even tried Projector before, checking the web I'm not finding any information on how it works, does it just work with regular volumes and lock files? It doesn't sound like it has any kind of central server.

Update on 2025-04-16:

I am now controlling my versions like it's 1997!

I'm using the CWProjector plugin for CodeWarrior to connect to MPW SourceServer, working against a Projector project on an AppleShare share, so I can work from either my PowerMac G4 or my PowerBook G3 depending on where I want to work!

A screenshot of CodeWarrior on MacOS 9, showing the version control menu with Checkout selected A screenshot of CodeWarrior on MacOS 9, with a checked out code file showing in the Finder with a checked out label, and the change history in a comment in the header of the file The check-in comment window in CodeWarrior on MacOS 9 The check-in progress window in CodeWarrior on MacOS 9

For files that are not checked out, SourceServer adds a "ckid" resource that software can look at to check if they should allow you to edit the file or not - CodeWarrior offers to automatically check it out for you, and even ResEdit is smart enough to show a warning! I've definitely never seen that ResEdit dialog before!

A dialog in CodeWarrior telling you the file is read only and asking if you want to Check it out ResEdit dialog saying This file is checked out read-only from an MPW project, do you want to edit it anyway?

Here's a video showing the whole workflow!

Back to blog index