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
$116.47
Apple Inc.
+0.16
MSFT
$47.98
Microsoft Corpora
-0.72
GOOG
$537.50
Google Inc.
+2.67

MacTech Search:
Community Search:

Software Updates via MacUpdate

Cobook 3.0.7 - Intelligent address book....
Cobook Contacts is an intuitive, engaging address book. Solve the problem of contact management with Cobook Contacts and its simple interface and powerful syncing and integration possibilities.... Read more
StatsBar 1.9 - Monitor system processes...
StatsBar gives you a comprehensive and detailed analysis of the following areas of your Mac: CPU usage Memory usage Disk usage Network and bandwidth usage Battery power and health (MacBooks only)... Read more
Cyberduck 4.6 - FTP and SFTP browser. (F...
Cyberduck is a robust FTP/FTP-TLS/SFTP browser for the Mac whose lack of visual clutter and cleverly intuitive features make it easy to use. Support for external editors and system technologies such... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
Evernote 6.0.1 - Create searchable notes...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
calibre 2.11 - Complete e-library manage...
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
Herald 5.0.1 - Notification plugin for M...
Note: Versions 2.1.3 (for OS X 10.7), 3.0.6 (for OS X 10.8), and 4.0.8 (for OS X 10.9) are no longer supported by the developer. Herald is a notification plugin for Mail.app, Apple's Mac OS X email... Read more
Firetask 3.7 - Innovative task managemen...
Firetask uniquely combines the advantages of classical priority-and-due-date-based task management with GTD. Stay focused and on top of your commitments - Firetask's "Today" view shows all relevant... Read more
TechTool Pro 7.0.6 - Hard drive and syst...
TechTool Pro is now 7, and this is the most advanced version of the acclaimed Macintosh troubleshooting utility created in its 20-year history. Micromat has redeveloped TechTool Pro 7 to be fully 64... Read more
PhotoDesk 3.0.1 - Instagram client for p...
PhotoDesk lets you view, like, comment, and download Instagram pictures/videos! (NO Uploads! / Image Posting! Instagram forbids that! AND you *need* an *existing* Instagram account). But you can do... Read more

Latest Forum Discussions

See All

Ubisoft Gives Everyone Two New Ways to E...
Ubisoft Gives Everyone Two New Ways to Earn In-Game Stuff for Far Cry 4 Posted by Jessica Fisher on November 21st, 2014 [ permalink ] | Read more »
Golfinity – Tips, Tricks, Strategies, an...
Dig this: Would you like to know what we thought of being an infinite golfer? Check out our Golfinity review! Golfinity offers unlimited ways to test your skills at golf. Here are a few ways to make sure your score doesn’t get too high and your... | Read more »
Dark Hearts, The Sequel to Haunting Meli...
Dark Hearts, The Sequel to Haunting Melissa, is Available Now Posted by Jessica Fisher on November 21st, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Meowza! Toyze Brings Talking Tom to Life...
Meowza! | Read more »
Square Enix Announces New Tactical RPG f...
Square Enix Announces New Tactical RPG for Mobile, Heavenstrike Rivals. Posted by Jessica Fisher on November 21st, 2014 [ permalink ] With their epic stories and gorgeous graphics, | Read more »
Quest for Revenge (Games)
Quest for Revenge 1.0.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0.0 (iTunes) Description: The great Kingdom of the west has fallen. The gods ignore the prayers of the desperate. A dark warlord has extinguished... | Read more »
Threadz is a New Writing Adventure for Y...
Threadz is a New Writing Adventure for You and Your Friends Posted by Jessica Fisher on November 21st, 2014 [ permalink ] In the tradition of round-robin storytelling, | Read more »
SteelSeries Stratus XL Hardware Review
Made by: SteelSeries Price: $59.99 Hardware/iOS Integration Rating: 4 out of 5 stars Usability Rating: 4.5 out of 5 stars Reuse Value Rating: 4.25 out of 5 stars Build Quality Rating: 4.5 out of 5 stars Overall Rating: 4.31 out of 5 stars | Read more »
ACDSee (Photography)
ACDSee 1.0.0 Device: iOS iPhone Category: Photography Price: $1.99, Version: 1.0.0 (iTunes) Description: Capture, perfect, and share your photos with ACDSee. The ACDSee iPhone app combines an innovative camera, a powerful photo... | Read more »
ProTube for YouTube (Entertainment)
ProTube for YouTube 2.0.2 Device: iOS Universal Category: Entertainment Price: $1.99, Version: 2.0.2 (iTunes) Description: ProTube is the ultimate, fully featured YouTube app. With it's highly polished design, ProTube offers ad-free... | Read more »

Price Scanner via MacPrices.net

15″ 2.2GHz Retina MacBook Pro on sale for $17...
 B&H Photo has the 2014 15″ 2.2GHz Retina MacBook Pro on sale today for $1749. Shipping is free, and B&H charges NY sales tax only. B&H will also include free copies of Parallels Desktop... Read more
27-inch 3.5GHz 5K iMac in stock today and on...
 B&H Photo has the new 27″ 3.5GHz 5K iMac in stock today and on sale for $2299 including free shipping plus NY sales tax only. Their price is $200 off MSRP, and it’s the lowest price available... Read more
21-inch 1.4GHz iMac on sale for $979, save $1...
B&H Photo has the new 21″ 1.4GHz iMac on sale for $979.99 including free shipping plus NY sales tax only. Their price is $120 off MSRP. B&H will also include free copies of Parallels Desktop... Read more
13-inch 1.4GHz/256GB MacBook Air on sale for...
B&H Photo has lowered their price on the 13″ 1.4GHz/256GB MacBook Air to $1059.99 including free shipping plus NY sales tax only. Their price is $140 off MSRP, and it’s the lowest price for this... Read more
Save up to $400 with Apple refurbished 2014 1...
The Apple Store has restocked Apple Certified Refurbished 2014 15″ Retina MacBook Pros for up to $400 off the cost of new models. An Apple one-year warranty is included with each model, and shipping... Read more
New 13-inch 1.4GHz MacBook Air on sale for $8...
 Adorama has the 2014 13″ 1.4GHz/128GB MacBook Air on sale for $899.99 including free shipping plus NY & NJ tax only. Their price is $100 off MSRP. B&H Photo has the 13″ 1.4GHz/128GB MacBook... Read more
Apple Expected to Reverse Nine-Month Tablet S...
Apple and Samsung combined accounted for 62 percent of the nearly 36 million branded tablets shipped in 3Q 2014, according to early vendor shipment share estimates from market intelligence firm ABI... Read more
Stratos: 30 Percent of US Smartphone Owners t...
Stratos, Inc., creator of the Bluetooth Connected Card Platform, has announced results from its 2014 Holiday Mobile Payments Survey. The consumer survey found that nearly one out of three (30 percent... Read more
2014 1.4GHz Mac mini on sale for $449, save $...
 B&H Photo has lowered their price on the new 1.4GHz Mac mini to $449.99 including free shipping plus NY tax only. Their price is $50 off MSRP, and it’s the lowest price available for this new... Read more
Check Apple prices on any device with the iTr...
MacPrices is proud to offer readers a free iOS app (iPhones, iPads, & iPod touch) and Android app (Google Play and Amazon App Store) called iTracx, which allows you to glance at today’s lowest... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Solutions Consultant (ASC)- Retail S...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager, *Apple* Financial Services...
**Job Summary** Apple Financial Services (AFS) offers consumers, businesses and educational institutions ways to finance Apple purchases. We work with national and Read more
*Apple* Store Leader Program - College Gradu...
Job Description: Job Summary As an Apple Store Leader Program agent, you can continue your education as you major in the art of leadership at the Apple Store. You'll Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.