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
}
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »

Price Scanner via MacPrices.net

Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more

Jobs Board

Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.