TweetFollow Us on Twitter

Generic C
Volume Number:7
Issue Number:9
Column Tag:Beginning C

Generic C with a Twist

By Kirk Chase, MacTutor Editor

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Introduction

I suppose a good many readers are interested in programming on the Macintosh, but have never done so before. I also suppose that a good many of you are taking computer science classes in school or college. And I also suppose that many of you are forced to do your development work on a Pretty Crummy computer rather than a Macintosh.

Unfortunately, there are a number of reasons why you are forced away from using your development platform of choice.

1. The Mac is a difficult machine to program for. Even if the program is simple.

2. The assistants and code help is all geared for other platforms.

3. Your class load does not permit you the time to develop Mac programs.

Well, there is help. The major C languages supported on the Mac also support generic C programs with little or no modifications. Most of them support all the ANSI standard functions and UNIX functions as they make sense on the Macintosh. Also this article will help you develop generic C programs on the Mac. Since cost is usually a high consideration for students, I will suppose that you are using Symantec’s THINK C for development work. This article will explain some of the techniques of how to create source-portable code and other interesting things you can do with THINK C.

Figure 1: A Generic C Program

Figure 2: A Generic THINK C Program

First: Preprocessors

Since this article is discussing writing source-portable code, C preprocessors are used quite frequently. They can be used for including files, defining and undefining flags, as well as directing conditional compilation. Using C preprocessors wisely will allow you to write one source and compile it on multiple platforms.

Only one preprocessor is automatically defined for you. THINK_C is defined when working with THINK C. You can test for it with the #ifdef or #ifndef preprocessors as well as undefine it with #undef. Unfortunately there is no preprocessor automatically defined when the source debugger option is turned on; this would greatly reduce the mistakes of not defining or undefining a debugger symbol (more later).

With the #if-#endif or #if-#else-#else directives you can section which code will be compiled. Thereby you can write purely generic code and code slightly tweaked for the Macintosh. For example, you would use

* 1 */

#ifdef THINK_C

/* code that is THINK C specific */

#else

/* generic replacement C code */

#endif

One convention that I like in THINK C is the one time header file inclusion. If your header file in named “filename.h”, you can include a preprocessor directive, “#define _H_filename” and the header file will be included only once no matter how many files #include “filename.h”. This keeps things from being multiply defined.

I use the #pragma directives for navigation. There is a shareware product by Max Lyth called, “CMarker”. Once installed a box is added to source code windows. When pressed a list of functions appear as well as points marked in your code like the following: #pragma mark <name to appear> (<name to appear> is displayed). THINK C currently ignores the #pragma directive and CMarker scans for #pragma mark. When a mark or function is selected, the source code will scroll to that place automatically. You can also comment/uncomment blocks of code automatically with CMarker. There are also other commercial and shareware products that can do similar functions.

Floating Down The Standard Streams

The standard streams-stdin, stdout, and stderr-are also supported by THINK C. Upon using a routine that accesses a standard stream, such as printf() or scanf(), THINK C creates a window named “console” that simulates a display of 80 columns by 25 lines. The console window is used by all the standard streams. A menu bar is created, if one is not already provided, with options to quit as well as cut, copy, and paste text. You already have a simple Mac program without any extra work on your part. You may even use the standard streams in Macintosh applications (output only); in this way, printf() could be used like a call to fprintf() to stderr.

Input, through stdin, defaults to line-buffered, echoed input with full editing capabilities. This means that your input is held from the program until you type RETURN or ENTER (these keys are not passed). You can also use the menu commands as well as the DELETE or BACKSPACE key. There are other input modes that allow for un-buffered input. In these un-buffered modes, an EOF is simulated from the keyboard by typing Command-D (not Control-D as the manual states).

Output, through stdout and stderr, go to the emulated console as well. The text automatically flows up and off as the console fills up. You may also create other console related streams which are other windows set up for input and output with calls such as fprintf() and fscanf(). Unfortunately, there is no way to separate the standard streams to go to another console. This would be nice so that stderr could be directed to print its messages to another console and leave the other standard streams to the main console.

You may open up as many console windows as memory will permit. Before opening a console, you may change some of its parameters like window name, columns, and rows by using the global structure, console_options, as described under the section “Options” on page 167 of THINK C’s Standard Libraries Reference Manual.

One point I would like to make is that console_options.title is declared to be a char pointer. This must point to a Pascal style string (one with a preceding length byte and no terminating null character). The Macintosh toolbox is Pascal based so functions that are used by the toolbox must have the pascal keyword in front of them, certain parameters are passed by address even though they seem to be passed by reference, and strings are Pascal style ones.

To convert a C string to a Pascal string or the reverse, simply use

/* 2 */

char *CtoPstr(char *)
char *PtoCstr(char *)

which does the change in place, forever changing the string. You can also create a Pascal string in constants by preceding it with “\p” or “\P”. “\pHello World” will then be the Pascal string “Hello World”. The function printf() even has a directive for printing Pascal strings ( printf(“%#s”, “\pHello World”); ).

While we are on the subject of constants, there are a few character constants recognized by THINK C some of which were not documented in the current manual. They are

‘\n’ - new line
‘\r’ - return, same as new line
‘\a’ - attention, beeps Macintosh or flashes menu bar is sound is off
‘\b’ - backspace
‘\t’ - tab, advances to next tab stop.  You can set this up with console_options.
‘\v’ - vertical tab, goes down one line
‘\f’ - form feed, clears screen.  It works only with the screen and not 
with printing.

The Mac At Your Command

Just because you are programming on the Mac, doesn’t mean you can’t use some Mac calls to make life easier, and this doesn’t necessarily have to be hard or difficult. There are many commands that you can use to gain more control over the standard streams create some console streams of your own. Include the ANSI file and for each file which uses one of the console commands #include <console.h>. Chapter 4 of THINK C’s Standard Libraries Reference Manual explains these functions to you.

The function ccommand() is an important one. By using this one, you get a dialog which can be used for inputing command line argument and redirecting stdin and stdout (stderr can not be redirected). You may also echo a stream to a file by using cecho2file() or echo a stream to a printer by using cecho2printer() (this is undocumented). You may also set up the console to print inverse characters (white on black) which uses the characters generated by the Option key though they do not correspond (Option-A does not produce an inverse “A”. Check an ASCII key code chart). Read chapter 4 of the manual more carefully for a complete description.

Figure 3: THINK C Command Line Dialog

One thing to note, that once you echo a file to a printer, you cannot stop echoing it. In fact you cannot close any streams at all, though you can hide them. What I suggest is that you open a console window specifically for printing and use that to send all you printing to. More later on printing tricks.

Other Macintosh Specific Code

When a standard stream is used, THINK initializes most of the Macintosh managers; so why not use them? You may need to add the MacTraps file to your project if it can’t link the function. Here are a few neat things.

1. Put SysBeep() in your code to beep the Macintosh or flash the menu bar if the sound is off. Just pass it an integer, usually 5, for the duration.

2. The function Button() returns true if the mouse button is pressed. You can put this in a loop to wait until the mouse is pressed before continuing.

3. PC clones have a different font than Macintosh standard fonts. I have included on the source disk a Font/DA Mover file with a PC font called “pcansi”. Include it with your other fonts if you wish to use it.

THINK C will also automatically include resources, such as fonts, with your program if you have a file in the same folder as your project with the same name as the project with the “.rsrc” extension. If, for example, your project is named “myProject.Π” then the resource file for automatic inclusion would be named “myProject.Π.rsrc”. I have also included the PC font in the project’s resource file. The code to use the font for a console/stream window can be found in InitSecondConsole(). This basically entails getting the font number from the name of the font and setting the console’s font to that number. Now you can get all those fancy PC characters!

Debugging On The Macintosh

THINK C comes with an adequate source level debugger as well as a object level debugger or monitor (Macsbug). If either is in use, there are a couple of undocumented calls that you can use to enter them. (I like to take this time to point out how bad the THINK C manuals are. It appears that all the attention was put into documenting the object extensions to version 4.0. Hence the manual is poorly written, organized, and indexed. A better approach would have been to pattern after there THINK Pascal manuals.)

One function call is Debugger(). This will drop you into the source debugger or Macsbug (if the source level debugger is not on). Execution will stop and you will be able to to the code and examine the variables in use.

The other function is DebugStr(). It is exactly like Debugger() except it prints out a string to Macsbug or the source debugger. This string is a Pascal style string.

A word of caution, the two functions above will cause the Macintosh to crash if Macsbug is not installed or you are not running the program with the source debugger on. Therefore you may wish, as I have to add a preprocessor to direct conditional compilation of code for these two functions. Otherwise, BOMB!. Of course now you need to remember to comment/uncomment your #define flag; I wish there was an automatic preprocessor symbol defined.

Check out the function CheckUserAbort() in the source listing. This function polls the keyboard to see if the Option key is down. You could use a test like this in a loop to send a signal (see more later) or drop into the debugger using Debugger() or DebugStr().

I would also like to comment on the THINK C source debugger. I feel that Symantec could have done much better with it. First, an automatically defined flag could exist when the source level debugger option was on. The debugger could remember break points and watch points from program invocation to invocation. The debugger could also display register values (which is a big reason to keep Macsbug installed). In short, I would be happy if Symantec were to take their debugger for THINK Pascal and bring it over to THINK C.

The ANSI assert mechanism is also useful for debugging. You can use asserts to test a condition and print out a message of where that condition failed. The message tells the expression, the file name, and the line number of the statement that failed.

Mixed Signals

THINK C’s default handling interrupt signal is Command-Period and not Control-C. And when you press it, your application simply quits. You can override this rude little behaviour with the signal(), setjmp(), and longjmp() functions.

The first thing you need to do is write a small procedure to call when a signal is generated. There are many limitations as to what this procedure can do so we want to do just a couple things. First, we set a global flag indicating we got a particular signal. Second we call longjmp() with the value of the signal (non-zero).

Next you need to decide on is the location you want to jump to when a signal (any kind) is received and longjmp() is called. You do this with setjmp() which returns zero when first invoked and a non-zero value you return when your call to longjmp(). setjmp() sets up an environment that longjmp() can use for doing abnormal exits. setjmp() must be in a function that has not previously been exited. Therefore a good location for setjmp() is in your main procedure right before your signal handling routine.

Pass to your signal handling function the value returned by setjmp() (which is the signal value passed in the longjmp() or zero). If the value is zero, it means that you are first starting out and you need to set the function that will be called when a particular signal is generated; you do this with signal() passing it the signal value and the address of the routine which sets the flag and jumps to your marker. If a non-zero value is received, it is the signal that was generated; you should reset any flags and reset the signal to call your routine when generated (If you do not, the default behaviour of exiting the program will be re-installed).

This strategy gives you a general purpose signal handler to catch things like Command-Period. You can also create your own signal types besides the standards defined in signal.h, but you will need alter ANSI.

Printing Tricks

Through the function ccommand(), you may redirect stdout to output to a printer. You can also output a console stream to a printer with cecho2printer(). The output is set up for a default of 80 columns (getting about 66 lines to a US Letter sized page). If your printing goes over 80 characters before a new line, the remaining text for that line will be lost. By calling cecho2printer() again and again, you can simulate a form feed (“\f”) on printouts (printing automatically continues on the next page).

You can change the number of columns with console_options, but at 9 point type you can only get a few more. By modifying your ANSI file just a bit, you can get about 125 columns by 25 lines per page. To do this, on a copy of ANSI add the line “PrStylDialog(h);” the function print() in the code segment:

/* 3 */

h = (THPrint) NewHandle(sizeof(TPrint));
 PrintDefault(h);
 if (hPrint) {
 PrJobMerge(hPrint, h);
 DisposHandle(hPrint);
 }
 else {
 InitCursor();

 /* add the following line */
 PrStlDialog(h);

 if (!PrJobDialog(h)) {
 noPrint = 1;
 return;
 }
 }

What this will do is bring up the “Page Setup ” dialog. This will allow you to set the paper size and print orientation. By selecting landscape printing as opposed to portrait printing orientation (wide instead of tall paper) you can simulate more columns.

THINK C’s Profiler

TC has included a tool for collecting statistics. It is called, “The Profiler”. With the Profiler you can track the entries and exits to functions as well as time those procedures. At the end of program execution, timing statistics are printed to stdout, and the program will wait for the user to press the RETURN or ENTER key before quitting, allowing you to view the findings. Its output looks like this

Function Minimum Maximum Average % Entries

InitSecondConsole 434443 434443 434443 11 1

ReadFile 197691 1063707 583191 47 3

SecondConsoleAd 1494920 1494920 1494920 40 1

With this information, you can find out which functions actually get executed and which functions actually take the longest. Then you can fine tune your code or re-work some code to bring down those times.

To add the profiler to your development code (note: you probably don’t want it for your final version.), you need to do three things.

1. Under the Edit menu, select “Options ”. This will bring up a dialog. Select the “Code Generation” button and the select the “Profile” option.

2. Add the profile library as well as the ANSI library found in the folder, “C Libraries”, to your project. Then include <profile.h> to all files who access the Profiler.

3. Finally, add the call InitProfile(nsyms, depth) at the beginning of your main function. This sets up storage for number of functions to track, nsyms, and the maximum recursive depth to track, depth. Symantec recommends a default value of 200 for both parameters.

You may selectively turn on and off the Profiler. It is useful to turn the Profiler off when getting input from the user; User interaction takes more time then normal operations and will therefore throw off your timing statistics. Setting the variable __trace to zero will turn off the printing of function names to stdout when they are entered. Setting the variable __profile to zero will turn off the collection of timing statistics. You must set these variables before you call the routines you want to affect.

You may modify the Profiler in a number of ways. You can set it up so that it gives its statistics in 60ths of a second instead of 1.2766 µsec. You can also modify what to do when you enter a procedure or exit a procedure or when you exit the program.

The Profiler lets you add in a simple way an option to track your functions. You do not need to add print statements at the beginning of a function nor timing code. You can modify the Profiler’s behaviour. However, the Profiler works on a function level basis. Within a function you are left to print out values or flags when logical sections are entered (eg. if, while, for-statements).

Conclusion

The program listing that follows for the program Generic shows a number of techniques for doing generic C programming on the Mac. You can also take advantage of the Mac in a number of ways. With this article and THINK C, you should be able to tackle the generic C programs on the Mac without all the hassles. Then you can use the ideas you’ve learned such as standard streams and signals to help in your own Macintosh development.

Listing:  DebugAids.h

#pragma mark Header
/***************************/
/* DebugAids.h
 Header file for DebugAids.c
 Defines whether debugging is done
 and whether a debugger is installed
 6/5/91 - Created by Kirk Chase */
/***************************/

#pragma mark #defines
#define _H_DebugAids /* THINK C one time header flag */

/* #define PROFILE */ /* Profile options on */
/* #define DEBUG */ /* install debugging features */
/* #define DEBUGGER */ /* install debugger features */
/* #undef THINK_C */ /* uncomment for generic C features */

#ifndef DEBUG
#undef DEBUGGER
#define NDEBUG
#else
#undef NDEBUG
#endif

#ifndef THINK_C
#undef PROFILE
#endif

#pragma mark #includes
#include <setjmp.h>

#pragma mark Prototypes
extern SigHandler(int sig); /* set up jumps and signals */
extern CheckOptionAbort(void); 
 /* checks if cmd-. is down on mac */
extern void UserAbort(int sig); 
 /* forced cmd-. signal if SIGINT is passed */
!codeexampleend!
codeexamplestart
Listing:  DebugAids.c

#pragma mark Header
/***************************/
/* DebugAids.c
 This file contains some generic debugging aids
 6/5/91 - created by Kirk Chase */
/***************************/

#pragma mark #includes
#include <stdio.h>
#include <signal.h>
#include <errno.h>

#include “DebugAids.h” /* needed for turning off assert */

#include <assert.h>


#pragma mark #defines
#ifndef TRUE
#define TRUE (1)
#define FALSE (0)
#endif

#pragma mark Externals
extern jmp_buf env;

#pragma mark Static Globals
static int __userAbort = FALSE;

/* CheckOptionAbort() 
 Routine to look for option key pressed.
 returns TRUE if there was, FALSE if none */
CheckOptionAbort(void)
{
#ifdef THINK_C
KeyMap debugKeys;

GetKeys(&debugKeys);
if (debugKeys.Key[1] & 0x4) {
 SigHandler(SIGINT);
 return(TRUE);
 }

#endif

return(FALSE);
}

/* UserAbort() 
 Routine to set user abort flag.
 jumps to signal handling software sending SIGINT */
void UserAbort(int sig)
{
__userAbort = TRUE;
longjmp(env, SIGINT);
}

/* SigHandler(int sig)
 Sets up signals (sig=0) or handles them (sig=anything) */
SigHandler(int sig)
{
switch (sig) {
 case 0: /* set up signals */
 assert(signal(SIGINT, &UserAbort) != SIG_ERR);
 break;
 case SIGINT: /* User abort, cmd-. */
 signal(SIGINT, &UserAbort);
 __userAbort = FALSE;
 #ifdef DEBUG
 fprintf(stderr,”\n***User Interrupt***\n”);
 #ifdef DEBUGGER
 DebugStr(“\p***User Interrupt***”);
 /* drop into monitor - bomb if none installed */
 #endif
 #endif
 break;
 default: /* unknown signal */
 #ifdef DEBUG
 fprintf(stderr,”\n***Unknown Signal***%d\n”, sig);
 #endif
 break;
 }
}
Listing:  SecondConsole.c

#pragma mark Header
/***************************/
/* SecondConsole.c
 This handles all functions to
 second console
 6/5/91 - Created by Kirk Chase */
/***************************/

#pragma mark #includes
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <console.h>
#include “DebugAids.h”

#pragma mark Globals
#ifdef THINK_C
static FILE *printerConsole = NULL;
#else
static FILE *printerConsole = stdout;
#endif

PrintTestPage(short pageType)
{
short i;

#ifdef THINK_C
cshow(printerConsole);
cecho2printer(printerConsole);
#endif

if (pageType == 1) {
 fprintf(printerConsole, “         1         2         3         4         5         6         7         8\n”);
 fprintf(printerConsole, “12345678901234567890123456789012345678901234567890123456789012345678901234567890\n”); 
/* 80 columns per page */
 /* Actually you can get a little bit more but most            
 terminals actually are set up for 80 columns.
 You might want to add PrStlDialog to console.c 
 thereby modifying ANSI project and experiment
 with simulating printing to wide computer paper by
 printing in landscape mode rather than portrait
 (about 115 columns by 50 rows in my test) */
 for (i = 3; i<67; i++) fprintf(printerConsole,”%d\n”, i);
 return; /* 66 lines per page on LaserWriter */
 }

fprintf(printerConsole,”\t\tTest Page 2\t\tpg. 1\n”);

#ifdef THINK_C
cecho2printer(printerConsole); /* forces page break */
#else
fprintf(printerConsole, “\f”);
#endif

fprintf(printerConsole,”\t\tTest Page 2\t\tpg. 2\n”);
}

void ReadFile(short echo, FILE *con2)
{
char buffer[81];
FILE *inputStream, *copyStream;
short count;

#ifdef THINK_C
cshow(con2); /* bring console to the front */
cgotoxy(1, 1, con2);
ccleos(con2);
#endif

if (!(inputStream = fopen(“Some Text”, “r”))) {
 /* try to open input stream */
 fprintf(stderr, “\n*** Error *** Could not open file \”Some Text\”\n”);
 
 #ifdef THINK_C
 chide(con2);
 #endif
 return;
 }
 
if (echo)
 if(!(copyStream = fopen(“Some Text Copy”, “w”)) ) {
 fprintf(stderr, “\n*** Error *** Could not open file \”Some Text Copy\”\n”);
 #ifdef THINK_C
 chide(con2);
 #endif
 fclose(inputStream);
 return;
 }

while(!feof(inputStream)) {
 /* get input from inputStream, write to console */
 count = fread(buffer, sizeof(char), 80, inputStream);
 fwrite(buffer, sizeof(char), count, copyStream);
 buffer[count] = ‘\0’;
 fprintf(con2, “%s”, buffer);
 }
fprintf(con2, “\n”);
if (echo)
 fclose(copyStream);
fclose(inputStream); /* close input stream */
}

SecondConsoleAd(FILE *con2)
{
#ifdef THINK_C
cshow(con2);
cgotoxy(1,1, con2);
ccleos(con2);

fprintf(con2, “Žƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒø\n”);
fprintf(con2, “  Ansi Style Font  \n”);
fprintf(con2, “¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ\n”);
fprintf(con2, “\n”);
fprintf(con2, “¤þþþþþ¤  =--=ª\n”);
fprintf(con2, “¤ YES ¤  < > \n”);
fprintf(con2, “¤ÐÐÐÐФ »=œ=º\n”);
fprintf(con2, “\n”);

fprintf(con2, “Press mouse button to continue...\n”);
while(!Button());
chide(con2);
#else
fprintf(con2, “>>>> Get A Mac <<<<\n”);
#endif
}

InitSecondConsole(FILE **con2)
{
short fnum;
char consoleName[16]=”\pSecond Console”;
char printerName[16]=”\pPrinter Console”;
char pcFont[256] = “\ppcansi”;

#ifdef THINK_C
console_options.title = consoleName;
console_options.top +=10;
console_options.left +=10;
GetFNum((Str255 *) pcFont, &fnum);
if (fnum)
 console_options.txFont = fnum;
*con2 = fopenc();
cinverse(FALSE, *con2);

console_options.title = printerName;
console_options.txFont = monaco;
console_options.top +=10;
console_options.left +=10;

printerConsole = fopenc();
chide(*con2);
chide(printerConsole);
#else
*con2 = stdout;
#endif
}
Listing:  Generic.c

#pragma mark Header
/***************************/
/* Generic.c
 This program is to demonstrate some
 of the generic features of THINK C
 and some of the THINK C features for
 debugging and console emulation
 History
 6/5/91 - Created by Kirk Chase */
/***************************/

#pragma mark #includes
/* the #pragma directive is ignored by THINK C and is used
 by CMarker by Max Lyth (shareware $20).  CMarker adds a
 box to the window bar that when pressed will display a
 list of all functions and #pragma mark <Name> directives.
 This is useful for quick navigation through a source file.
 You simply select the function or <Name>, and the window
 will scroll to it.  Also you can comment/uncomment blocks
 of code. */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include “DebugAids.h”

#ifdef THINK_C
#include <console.h>
#endif

#ifdef PROFILE
#include <profile.h>
#endif

#pragma mark #defines
#ifndef TRUE
#define TRUE (1)
#define FALSE (0)
#endif

#pragma mark Globals
jmp_buf env;

void PrintMenu(void)
/* prints menu choices */
{
printf(“\n”);
#ifdef THINK_C
printf(“\n\t\t               \n”);
printf(“\t\t™™ MAIN MENU ™™\n”);
printf(“\t\t               \n\n”);

printf(“ÝÃÝ Command Line Args\t\t”);
printf(“Ý¬Ý Beep Macintosh\n”);
printf(“Ý‘Ý Test Interrupt\t\t”);
printf(“Ý¡Ý Advertisement\n”);
printf(“Ý“Ý Read File\t\t\t”);
printf(“Ý Ý Copy File\n”);
printf(“Ý±Ý Test Page 1\t\t\t”);
printf(“Ý¾Ý Test Page 2\n”);

printf(“\nÝ--Ý Quit\n”);
#else
printf(“\n\t\t===============\n”);
printf(“\t\t** MAIN MENU **\n”);
printf(“\t\t===============\n\n”);

printf(“ L) Command Line Args\t\t”);
printf(“ B) Beep Macintosh\n”);
printf(“ T) Test Interrupt\t\t”);
printf(“ A) Advertisement\n”);
printf(“ R) Read File\t\t\t”);
printf(“ C) Copy File\n”);
printf(“ 1) Test Page 1\t\t\t”);
printf(“ 2) Test Page 2\n”);

printf(“\n Q) Quit\n”);
#endif
}

char GetChoice(void)
/* gets menu choices */
{
char command;
char commandSet[10] = “QBTRCLA12\0”;
#ifdef PROFILE
 _profile = FALSE;
 _trace = FALSE;
#endif
printf(“\n”);

#ifdef THINK_C
csetmode(C_CBREAK, stdin);
printf(“æææ “);
#else
printf(“>>> “);
#endif

scanf(“%c”, &command);
command = toupper(command);
while (!strchr(commandSet, command)) {
 /* loop til command is valid */
 printf(“\nType in one of the following letters <%s>\n”, commandSet);
 
 #ifdef THINK_C
 printf(“\næææ “);
 #else
 printf(“>>> “);
 #endif
 scanf(“%c”, &command);
 command = toupper(command);
 }
printf(“\n”);

#ifdef THINK_C
csetmode(C_ECHO, stdin);
#endif
#ifdef PROFILE
 _profile = TRUE;
 _trace = TRUE;
#endif
return (command);
}

void TestInterrupt(void)
/* continous loop until cmd-. is pressed */
{
while (!CheckOptionAbort())
 printf(“Type COMMAND-. to stop!\n”);
}

main(int argc, char **argv)
{
/* main entry point */
short i, theSignal;
char com;
FILE *con2=NULL;

/* set up */
#ifdef PROFILE
InitProfile(200, 200);
_profile = TRUE;
_trace = TRUE;
#endif

#ifdef THINK_C
/* Should go up all the time unless using other environment */
argc = ccommand(&argv);
cinverse(TRUE, stdout);
ccleos(stdout);
printf(“You are using THINK C\n”);
#else
printf(“You are using a PC\n”);
#endif

#ifdef DEBUG
printf(“Debug options are on\n”);
#else
printf(“Debug options are off\n”);
#endif

#ifdef DEBUGGER
printf(“Debugger options are on\n”);
#else
printf(“No Debugger\n”);
#endif

printf(“\n”);
/* set up second console */
InitSecondConsole(&con2);

do { /* main loop */
 /* turn off Profiler for input loop */
 /* if left on for input then timing stats would be off since input is 
always SLOW in comparison with other operations */
 #ifdef PROFILE
 _profile = FALSE;
 _trace = FALSE;
 #endif
 
 theSignal = setjmp(env); /* set up jump point */
 SigHandler(theSignal); /* do signal handler */
 
 PrintMenu();
 com = GetChoice();
 
 /* turn Profiler back on */
 #ifdef PROFILE
 _profile = TRUE;
 _trace = TRUE;
 #endif
 
 switch (com) { /* handle command */
 case ‘B’:
 printf(“\a”); /* ‘\a’ rings bell/beeps Macintosh */
 /* you could have used SysBeep(x) where x
 is an integer.  SysBeep(5) is a nice value */
 /* menu bar will flash if sound is turned off */
 break;
 case ‘T’:
 #ifdef PROFILE
 _profile = FALSE; /* cmd-. messes up profiler */
 _trace = FALSE;
 #endif
 
 TestInterrupt(); /* test cmd-. */
 
 #ifdef PROFILE
 _profile = TRUE;
 _trace = TRUE;
 #endif
 
 break;
 case ‘R’:
 ReadFile(FALSE, con2); /* read a file */
 break;
 case ‘C’:
 ReadFile(TRUE, con2); /* copy a file */
 break;
 case ‘L’: /* list command line arguements */
 printf(“ #\tArguement\n==\t=========\n”);
 for (i=0; i<argc; i++)
 printf(“%d\t%s \n”, i, argv[i]);
 
 #ifdef THINK_C
 printf(“\nPress mouse button to continue...\n\n”);
 while(!Button()); /* loop until button */
 #endif
 break;
 case ‘A’:
 SecondConsoleAd(con2); /* advertisement */
 break;
 case ‘1’: /* print columns/rows per page */
 case ‘2’: /* print two pages with forced page break */
 PrintTestPage((short) com - ‘0’);
 break;
 }
 } while (com != ‘Q’);

#ifdef PROFILE
#ifdef THINK_C
cecho2file(“Profiler Report”, TRUE, stdout); /* output */
#endif
printf(“***** Profile Report *****\n”);
printf(“%s\n”, ctime(NULL));
 /* Profiler will generate it’s output automatically */
#endif
}
 
AAPL
$93.94
Apple Inc.
-0.49
MSFT
$44.84
Microsoft Corpora
+0.15
GOOG
$589.47
Google Inc.
-5.61

MacTech Search:
Community Search:

Software Updates via MacUpdate

OS X Yosemite 10.10 DP4 - Developer Prev...
Note: This is a Developer Preview. You must be a registered Apple Mac Developer to download this update. OS X Yosemite is Apple's newest operating system for Mac. An elegant design that feels... Read more
FinderPop 2.5.6 - Classic Mac utility, n...
FinderPop is a Universal preference pane that extends OS X's contextual menus using a FinderPop Items folder much as the Apple Menu Items folder used to do for the Apple menu. It has other features... Read more
SpiderOak 5.1.7 - Secure cloud backup, s...
SpiderOak is a multi-platform secure online backup, storage, access, and sharing solution engineered for the consumer and small businesses. You must first sign up to use SpiderOak. Running natively... Read more
Espionage 3.6 - Simple, state of the art...
Espionage offers state-of-the-art encryption and plausible deniability for your confidential data. Sometimes, encrypting your data isn't enough to protect it. That's why Espionage 3 goes beyond data... Read more
calibre 1.45.0 - Complete e-library mana...
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... Read more
iFFmpeg 4.3.1 - Convert multimedia files...
iFFmpeg is a graphical front-end for FFmpeg, a command-line tool used to convert multimedia files between formats. The command line instructions can be very hard to master/understand, so iFFmpeg does... Read more
Chromium 36.0.1985.125 - Fast and stable...
Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all Internet users to experience the web. FreeSMUG-Free OpenSource Mac User Group build is... Read more
pwSafe 3.0 - Secure password management...
pwSafe provides simple and secure password management across devices and computers. pwSafe uses iCloud to keep your password databases backed-up and synced between Macs and iOS devices. It is... Read more
Day One 1.9.6 - Maintain a daily journal...
Day One is the easiest and best-looking way to use a journal / diary / text-logging application for the Mac. Day One is well designed and extremely focused to encourage you to write more through... Read more
Google Chrome 36.0.1985.125 - Modern and...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more

Latest Forum Discussions

See All

HELMUT Review
HELMUT Review By Andrew Fisher on July 21st, 2014 Our Rating: :: TRUNDLE SIMULATOR 2014Universal App - Designed for iPhone and iPad HELMUT is a fun, fleeting time-sink that offers a momentary distraction and nothing else.   | Read more »
Walkr Review
Walkr Review By Jennifer Allen on July 21st, 2014 Our Rating: :: ORIGINAL WALKINGiPhone App - Designed for the iPhone, compatible with the iPad Walking is a bit more exciting thanks to this planet building/discovering sim reliant... | Read more »
Zombie Commando Review
Zombie Commando Review By Jennifer Allen on July 21st, 2014 Our Rating: :: MINDLESS SLAUGHTERUniversal App - Designed for iPhone and iPad Briefly fun but ultimately forgettable, Zombie Commando will scratch an itch then be... | Read more »
Swords & Poker Adventures Review
Swords & Poker Adventures Review By Jennifer Allen on July 21st, 2014 Our Rating: :: SOULLESS POKER PLAYUniversal App - Designed for iPhone and iPad Swords & Poker Adventures is a mishmash of Poker and RPGing, but it lacks... | Read more »
Warhammer 40,000: The Horus Heresy: Drop...
Warhammer 40,000: The Horus Heresy: Drop Assault Coming Soon to iOS Posted by Jennifer Allen on July 21st, 2014 [ permalink ] Coming soon to iOS will be an all-new Warhammer 40,000 tactical strategy game by the name of The Horus Heresy: Drop As | Read more »
A Life Worth Dying For Review
A Life Worth Dying For Review By Jordan Minor on July 21st, 2014 Our Rating: :: A BEAUTIFUL MINDUniversal App - Designed for iPhone and iPad A Life Worth Dying For is a fascinating portrait of a serious subject.   | Read more »
Zombie Puzzle Panic Review
Zombie Puzzle Panic Review By Jordan Minor on July 21st, 2014 Our Rating: :: THE MATCHING DEADUniversal App - Designed for iPhone and iPad Zombie Puzzle Panic puts some pretty neat undead twists on Match-3 puzzling.   | Read more »
This Week at 148Apps: July 14-18, 2014
Expert App Reviewers   So little time and so very many apps. What’s a poor iPhone/iPad lover to do? Fortunately, 148Apps is here to give you the rundown on the latest and greatest releases. And we even have a tremendous back catalog of reviews; just... | Read more »
Fallen Lords Review
Fallen Lords Review By Andrew Fisher on July 18th, 2014 Our Rating: :: FALLS SHORTiPad Only App - Designed for the iPad Fallen Lords is a decent game, but its similarity and inferiority compared to Ghost Stories makes it ultimately... | Read more »
Real Boxing’s New Combo Update is a Knoc...
Real Boxing’s New Combo Update is a Knockout Posted by Blake Grundman on July 18th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »

Price Scanner via MacPrices.net

Twelve South HiRise For MacBook – Height-Adju...
If you use your MacBook as a workhorse desktop substitute, as many of us do, a laptop stand combined with an external keyboard and pointing device are pretty much obligatory if you want to avoid... Read more
Why The Mac Was Not Included In The Apple/IBM...
TUAW’s Yoni Heisler cites Fredrick Paul of Network World whoi blogged last week that the Mac’s conspicuous absence from Apple and IBM’s landmark partnership agreement represents a huge squandered... Read more
Save $100 on 13-inch Retina MacBook Pros, plu...
Adorama has 13″ Retina MacBook Pros on sale for $100 off MSRP. Shipping is free, and Adorama charges sales tax in NY & NJ only: - 13″ 2.4GHz/128GB MacBook Pro with Retina Display: $1199 - 13″ 2.... Read more
Blurr it 2.3 for iOS – Quickly Blurs Selected...
Hyderabad, India based TouchLabs has announced a new update of Blurr it 2.3, their photography app for iOS users. Blurr it allows you to blur part of the image to hide potentially sensitive or... Read more
MacBook Airs on sale for $100 off MSRP, start...
Best Buy has the new 2014 MacBook Airs on sale for up to $100 off MSRP on their online store. Choose free home shipping or free local store pickup (if available). Prices valid for online orders only... Read more
Amazon Announces Kindle Unlimited: Unlimited...
Amazon.com has introduced Kindle Unlimited — a new subscription service which allows customers to freely read as much as they want from over 600,000 Kindle books, and listen as much as they want to... Read more
New Linksys Wireless Range Extenders Boost Wi...
Linksys has announced its new lineup of Linksys Wi-Fi Range Extenders. Consumers often experience a weak wireless signal in some parts of their house or apartment caused by blocking elements such as... Read more
MacBook Airs available starting at $719
The Apple Store has Apple Certified Refurbished 2013 & 2012 MacBook Airs in stock today starting at $719. An Apple one-year warranty is included with each MacBook, and shipping is free: 2013... Read more
Get the best deals on iPad minis with Apple r...
The Apple Store has Certified Refurbished 2nd generation iPad minis with Retina Displays available for up to $130 off the cost of new models, starting at $339. Apple’s one-year warranty is included... Read more
Best Buy’s College Student Deals: $100 off Ma...
Take an additional $100 off all MacBooks and iMacs, $50 off iPad Airs and iPad minis, at Best Buy Online with their College Students Deals Savings, valid through July 25th. Anyone with a valid .EDU... Read more

Jobs Board

*Apple* Computer Technician - Fairfield Coun...
Company DescriptionWe are an Apple Authorized Sales and Service Provider. We have been selling and servicing Apple computers in the Fairfield County area for over 20 Read more
*Apple* Computer Technician - Fairfield Coun...
Company DescriptionWe are an Apple Authorized Sales and Service Provider. We have been selling and servicing Apple computers in the Fairfield County area for over 20 Read more
Mac Expert - *Apple* Online Store Mexico -...
…MUST be fluent in English and Spanish to be considered for this position At Apple , we believe that hard work, a fun environment, creativity and innovation fuel the Read more
*Apple* Computer Technician - Fairfield Coun...
Company DescriptionWe are an Apple Authorized Sales and Service Provider. We have been selling and servicing Apple computers in the Fairfield County area for over 20 Read more
Mac Expert - *Apple* Online Store - Apple (...
**Job Summary** At Apple , we believe that hard work, a fun environment, creativity and innovation fuel the ultimate customer experience. We believe each customer Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.