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

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.