Debugging Terminal
Volume Number: 12
Issue Number: 10
Column Tag: Communications Toolbox Connections
DebugTerm 
A Poor Man’s Debugging Terminal
By Mark Chally, Covina, California
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
The purpose of this article is to implement a useful C-language debugging tool and to
discuss the basics of Apple’s Macintosh Communications Toolbox, including methods for
using the Connection Manager. In the process, we will also create a base for a more
powerful application that may be presented in a later issue or one that you may develop
on your own.
We will begin by discussing the Communications Toolbox (CTB), what it’s good
for, why you need to know about it, and why you want to read about it here. Next, we
will summarize the use and structure of the CTB.
With a general understanding of the CTB under our belts, we will be ready to
discuss the purpose and use of DebugTerm. Once we know what DebugTerm is expected
to do, we can walk through the code and see how it takes advantage of the CTB. In the
penultimate section, we’ll take DebugTerm for a test spin and see the results of
function calls we make.
Finally, we will discuss problems that may occur when using DebugTerm, and
possible enhancements to it. We will summarize what we have accomplished and
ponder future directions.
The Advent of the Communications Toolbox
Before Apple created the CTB, there were already many ways to connect the
Macintosh to the outside world. Being so easily connected was a fabulous feature. Even
the first Macs had built-in networking, and counting connections to LaserWriters, the
Mac was the world’s most networked personal computer.
However, as the variety of ways to connect the Macintosh increased, so did the
difficulty encountered when implementing programs that connect in various different
ways. Even before the Mac // arrived, it would have been useful to have a single
library which would allow a program to communicate through whatever connection the
user desired, using the same high-level code for each type of connection. The
application programmer would not have needed to be concerned with the intricacies of
any specific connection type. Ideally, it would have been better to avoid having to deal
with the complexities of different brands of modems, too. Making matters worse, the
Mac // came out, with an open architecture through which a user could add internal
modems and multiple serial connections. Apple had a real mess on their hands!
The Macintosh Communications Toolbox Arrives
As Apple mapped the way to System 7, they apparently became aware of the
morass that had grown-and found a gem which was already under development. As the
forward to Inside the Macintosh® Communications Toolbox (Inside CTB) indicates,
“Initially conceived as a better way to engineer MacTerminal 2.0-it enabled
MacTerminal to support new protocols without having to be revised-the
Communications Toolbox has evolved into an integral component of our system
software.”
With the CTB, programmers can now write programs which connect to other
computers using tools for connection, terminal emulation and file transfer protocols
whose intricacies the programmer is not required to know. In theory, with a
well-designed program and tools, a networking protocol that the programmer was
unaware of could be supported, in addition to a slew of modems and file transfer
protocols.
Given such a powerful API (Application Program Interface), communications
features can be uniformly and reliably added to just about any type of application, with
minimal effort. When I learned this, I was eager to begin taking advantage of the CTB.
Obstacles for the Communications Toolbox, or Why read this article?
My enthusiasm for the CTB was tempered by some harsh realities. I found an
early SDK (Software Developer’s Kit) woefully inadequate. It came with only a
smattering of example code and unfinished documentation. Perhaps the current SDK is
more useful. Until now, MacTech had never printed an article on the subject, and I saw none elsewhere. Nor did I find available on-line source code examples satisfactory.
The code that I used to enhance my understanding was inspired by a simple Pascal
program called Surfer, from Apple’s ETO (Essentials•Tools•Objects) mailing. Once
Inside CTB was completed, I used it as documentation, which I highly recommend.
Another topic of confusion was whether or not Apple and vendors would continue
to support the CTB. Since programmers did not receive it warmly, and other parts of
System 7 never really “caught on,” some questioned whether it would become like
PowerTalk and other orphaned technologies. It was pleasing to see that, though there
have been a few problems implementing Open Transport, it seems to support the CTB
seamlessly, which still works fine with the serial port, as well as over networks too.
Modem manufacturers’ responses have been mixed. Some companies such as Global
Village have done a good job, but some others have not. One company’s support
technician seemed peeved to “have to write Apple’s code for them.” Despite a rough
start, the future looks good for the CTB.
If you think you can recognize every program using the CTB, you may be
surprised. There is a very recognizable user interface, but there is also an API which
lets programmers implement the user interface themselves. The CTB is not difficult to
learn to program. Although I am far from a CTB expert, I was able to put together the
code I needed fairly quickly.
What is the Communications Toolbox? Included as an extension to System 6 and built into System 7, the CTB consists of
four managers and a set of utilities. Together, they provide a means to control three
separate aspects of communications: connections, file transfers, and terminal
emulation. Inside CTB has some pretty pictures-most of which are probably not
necessary here. In the interest of clarity, however, here is a representative one:
Figure 1. The Realm of Macintosh
Communications Toobox Influence
Normally, the CTB and the client application do not interact much with the user
or handle the details the managers oversee. That responsibility is handled by
communications tools. Standard tools come with the CTB; users can obtain various
others from third parties, and drop them into their extensions folder to use them with
programs that employ the CTB. There are public domain, shareware, direct mail, and
various other commercially available tools. Others are distributed with their client
applications. The managers provide the API and the utilities handle housekeeping
chores.
The Connection Manager provides an API through which the client application
(your code) can use a connection tool. Each, such as the Serial Tool, Apple Modem Tool
and AppleTalk ADSP Tool, allows the client application to connect through the specific
medium in which the tool specializes. The Serial Tool, for example, is responsible for
transferring data only through the serial ports. The Apple Modem Tool, on the other
hand, has to know about the complexities of modems-which it does with the help of
plug-in modules that manufacturers provide to meet Apple’s specifications. The
AppleTalk ADSP Tool, provides an AppleTalk network connection using the ADSP
protocol. Other connection tools exist, such as an ISDN tool, according to Inside CTB.
The Terminal Manager provides an API through which the client application can
use terminal emulation tools. The TTY Tool behaves as a dumb terminal, as do most
terminal programs in their simplest modes. An additional standard terminal emulation
is the VT102 Tool, which is somewhat more complex. Tools to emulate other standard
terminals, such as IBM 3270, are also available.
The File Transfer Manager provides an API through which the client application
can use file transfer tools. Standard tools include the Text Tool, which sends and
receives text straight through the connection, as archaic text file captures did, and the
XMODEM Tool. There are tools that support other file transfer protocols, such as
YMODEM, ZMODEM, and Kermit.
Users are typically unaware of the structure through which they are
communicating, as Apple apparently intended. In most cases, they only know that they
are using a familiar user interface for connections, file transfers, and terminal
emulation. Programmers should seriously consider allowing the user to have access to
the standard interface, as opposed to the scripted interface described in Inside CTB as
Custom Configuration. Using the scripted interface allows the application to tell the
CTB that it knows what the user needs to see. Aside from being beyond the scope of this