Mac OS 7-9 - C编程

7

我很好奇在Mac OS System 7到OS 9上有多少依赖标准Unix功能的C特性能够使用。我没有在该平台上进行过开发,但我知道它没有命令行,也没有标准流可以工作。没有命令行,那么是否有命令行参数?环境变量呢?

我尝试寻找经典的Mac OS编程指南,但是它们非常难找。


1
在68kMLA论坛上有许多活跃的经典Mac OS程序员。我相信他们能够帮助您获取MPW和其他工具。 - Coxy
2个回答

14

首先,C语言没有任何与Unix有关的特性。C语言可以在Windows上和8位微控制器上顺利运行。

至于经典的Mac OS,有两个主要的编程环境:Metrowerks CodeWarrior和苹果的MPW。

  1. CodeWarrior came with a library called SIOUX which opened up a window and provided simple I/O. Any printf statements would print to this window. There's no piping or sockets, but that's not part of the C standard anyway (pipes are a part of POSIX). Using SIOUX, you could port a simple program to Mac OS as long as it stuck to portable C.

  2. Apple's MPW was the other option. MPW provided a command line, a bunch of command-line programs (compilers for C, C++, Pascal, assembly), and dialog box "shells" for generating command line arguments to the programs. You could even use pipes, set environment variables, et cetera.

    There were, however, some major differences in functionality between Unix and MPW. MPW had a great interface, but you could not run two command line programs simultaneously, not even in the very trivial case where one is suspended to run the other. This meant that the "make" program couldn't run the compiler. Instead, "make" generated a shell script which would run the compiler. You'd typically have some kind of keyboard shortcut that would run "make" and then run the resulting output as a shell script.

    Now, this seems to imply that pipes wouldn't work, but I think pipes were just syntactic sugar for working with temporary files.

    Xcode has no MPW heritage, as far as I know. Xcode derives from Project Builder which was developed at NeXT, and NeXT was always Unix. Apple ported some of the old MPW command-line tools to OS X, but not many. The big one is Rez (and DeRez). Since they're shipped with the latest Xcode, I guess somebody is probably still using them. The Rez headers are still around, to get a blast from the past check out:

    find /System/Library/Frameworks -name '*.r'
    
似乎苹果已经把他们的开发网站上早于10.6的所有内容都清除了,这有点可惜。不久前,你还能在苹果网站上找到旧的Carbon文档,包括所有的“Inside Macintosh”系列。你以前也可以从苹果的FTP站点免费下载MPW,我仍然有这些下载文件,但我不知道现在是否仍然可以下载。
请注意,除非你已经成功运行Sheep Shaver,否则你需要10.4(或更早版本)和一台PowerPC电脑才能尝试玩弄它。
有趣的是,MPW的C编译器可以产生一些有趣的错误消息。
a typedef name was a complete surprise to me at this point in your program
You can't modify a constant, float upstream, win an argument with the IRS, or satisfy this compiler ...And the lord said, 'lo, there shall only be case or default labels inside a switch statement'
type in (cast) must be scalar; ANSI 3.3.4; page 39, lines 10-11 (我知道你不在乎,我只是想烦你)
Call me paranoid but finding '/*' inside this comment makes me suspicious
Symbol table full - fatal heap error; please go buy a RAM upgrade from your local Apple dealer Too many errors on one line (make fewer)
This label is the target of a goto from outside of the block containing this label AND this block has an automatic variable with an initializer AND your window wasn't wide enough to read this whole error message we already did this function

你可以将一个简单的程序移植到OS X上 - 不,它在发布10(X)之前不叫做OS X。 - asveikau
@asveikau:实际上,这是真的——CodeWarrior也可以在OS X上运行。但那是一个打字错误。 - Dietrich Epp
"C在Windows上运行得很好" - 我为此大笑了:D - user529758

4

THINK C/Symantec C也有一个标准的I/O窗口,使得移植命令行程序相对容易。通过对话框输入程序参数。

但是,最好的方法是使用MPW - Macintosh程序员工作坊。这是MacOS的一个非常好的命令行环境,拥有优秀的编辑器、可编写脚本、各种“工具”以及许多有用的GUI方面(因此它真正像Mac一样)。

多年来,这可以从苹果的开发者网站免费下载。看起来链接现在可能已经消失了,但我相信可以在网上找到副本,只需稍微搜索即可。(尝试搜索MPW-GM.img.bin或mpw-gm_images。)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接