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
$97.67
Apple Inc.
+0.64
MSFT
$44.50
Microsoft Corpora
+0.10
GOOG
$589.02
Google Inc.
-4.33

MacTech Search:
Community Search:

Software Updates via MacUpdate

Vienna 3.0.0 RC 2 :be5265e: - RSS and At...
Vienna is a freeware and Open-Source RSS/Atom newsreader with article storage and management via a SQLite database, written in Objective-C and Cocoa, for the OS X operating system. It provides... Read more
VLC Media Player 2.1.5 - Popular multime...
VLC Media Player is a highly portable multimedia player for various audio and video formats (MPEG-1, MPEG-2, MPEG-4, DivX, MP3, OGG, ...) as well as DVDs, VCDs, and various streaming protocols. It... Read more
Default Folder X 4.6.7 - Enhances Open a...
Default Folder X attaches a toolbar to the right side of the Open and Save dialogs in any OS X-native application. The toolbar gives you fast access to various folders and commands. You just click... Read more
TinkerTool 5.3 - Expanded preference set...
TinkerTool is an application that gives you access to additional preference settings Apple has built into Mac OS X. This allows to activate hidden features in the operating system and in some of the... Read more
Audio Hijack Pro 2.11.0 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Intermission 1.1.1 - Pause and rewind li...
Intermission allows you to pause and rewind live audio from any application on your Mac. Intermission will buffer up to 3 hours of audio, allowing users to skip through any assortment of audio... Read more
Autopano Giga 3.6 - Stitch multiple imag...
Autopano Giga allows you to stitch 2, 20, or 2,000 images. Version 3.0 integrates impressive new features that will definitely make you adopt Autopano Pro or Autopano Giga: Choose between 9... Read more
Airfoil 4.8.7 - Send audio from any app...
Airfoil allows you to send any audio to AirPort Express units, Apple TVs, and even other Macs and PCs, all in sync! It's your audio - everywhere. With Airfoil you can take audio from any... Read more
Microsoft Remote Desktop 8.0.8 - Connect...
With Microsoft Remote Desktop, you can connect to a remote PC and your work resources from almost anywhere. Experience the power of Windows with RemoteFX in a Remote Desktop client designed to help... Read more
xACT 2.30 - Audio compression toolkit. (...
xACT stands for X Aaudio Compression Toolkit, an application that encodes and decodes FLAC, SHN, Monkey’s Audio, TTA, Wavpack, and Apple Lossless files. It also can encode these formats to MP3, AAC... Read more

Latest Forum Discussions

See All

This Week at 148Apps: July 21-25, 2014
Another Week of Expert App Reviews   At 148Apps, we help you sort through the great ocean of apps to find the ones we think you’ll like and the ones you’ll need. Our top picks become Editor’s Choice, our stamp of approval for apps with that little... | Read more »
Reddme for iPhone - The Reddit Client (...
Reddme for iPhone - The Reddit Client 1.0 Device: iOS iPhone Category: News Price: $.99, Version: 1.0 (iTunes) Description: Reddme for iPhone is an iOS 7-optimized Reddit client that offers a refreshing new way to experience Reddit... | Read more »
Jacob Jones and the Bigfoot Mystery : Ep...
Jacob Jones and the Bigfoot Mystery : Episode 2 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Jacob Jones is back in Episode 2 of one of Apples 'Best of 2013' games and an App Store... | Read more »
New Trailer For Outcast Odyssey, A New K...
New Trailer For Outcast Odyssey, A New Kind of Card Battler Posted by Jennifer Allen on July 25th, 2014 [ permalink ] Out this Fall is a new kind of card battle game: Outcast Odyssey. | Read more »
Hay Day – Tip, Tricks, Strategies, and C...
Recently got into Supercell’s other huge hit, Hay Day and could do with some advice on what to do? We’ve got you covered with some helpful trips and tricks to bear in mind! Ticking Along One of the key things to keep in mind while building up that... | Read more »
Monster Head Review
Monster Head Review By Nadia Oxford on July 25th, 2014 Our Rating: :: FEEDING TIMEUniversal App - Designed for iPhone and iPad Racking up a high score with Monster Head is trickier than it first appears. The appeal wears out fairly... | Read more »
Garfield: Survival of the Fattest Coming...
Garfield: Survival of the Fattest Coming to iOS this Fall Posted by Jennifer Allen on July 25th, 2014 [ permalink ] Who loves lasagna? Me. Also everyone’s favorite grumpy fat cat, Garfield. | Read more »
Happy Flock Review
Happy Flock Review By Andrew Fisher on July 25th, 2014 Our Rating: :: HERD IT ALL BEFOREUniversal App - Designed for iPhone and iPad Underneath the gloss of Happy Flock’s visuals is a game of very little substance. It’s cute, but... | Read more »
Square Register Updates Adds Offline Pay...
Square Register Updates Adds Offline Payments Posted by Ellis Spice on July 25th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Looking For Group – Hearthstone’s Curse...
For the first time since its release (which has thankfully been a much shorter window for iPad players than their PC counterparts), Blizzard’s wildly successful Hearthstone: Heroes of Warcraft CCG is sporting some brand new content: the single... | Read more »

Price Scanner via MacPrices.net

Record Mac Shipments In Q2/14 Confound Analys...
A Seeking Alpha Trefis commentary notes that Apple’s fiscal Q3 2014 results released July 22, beat market predictions on earnings, although revenues were slightly lower than anticipated. Apple’s Mac’... Read more
Intel To Launch Core M Silicon For Use In Not...
Digitimes’ Monica Chen and Joseph Tsai, report that Intel will launch 14nm-based Core M series processors specifically for use in fanless notebook/tablet 2-in-1 models in Q4 2014, with many models to... Read more
Apple’s 2014 Back to School promotion: $100 g...
 Apple’s 2014 Back to School promotion includes a free $100 App Store Gift Card with the purchase of any new Mac (Mac mini excluded), or a $50 Gift Card with the purchase of an iPad or iPhone,... Read more
iMacs on sale for $150 off MSRP, $250 off for...
Best Buy has iMacs on sale for up to $160 off MSRP for a limited time. Choose free home shipping or free instant local store pickup (if available). Prices are valid for online orders only, in-store... Read more
Mac minis on sale for $100 off MSRP, starting...
Best Buy has Mac minis on sale for $100 off MSRP. Choose free shipping or free instant local store pickup. Prices are for online orders only, in-store prices may vary: 2.5GHz Mac mini: $499.99 2.3GHz... Read more
Global Tablet Market Grows 11% in Q2/14 Notwi...
Worldwide tablet sales grew 11.0 percent year over year in the second quarter of 2014, with shipments reaching 49.3 million units according to preliminary data from the International Data Corporation... Read more
New iPhone 6 Models to Have Staggered Release...
Digitimes’ Cage Chao and Steve Shen report that according to unnamed sources in Apple’s upstream iPhone supply chain, the new 5.5-inch iPhone will be released several months later than the new 4.7-... Read more
New iOS App Helps People Feel Good About thei...
Mobile shoppers looking for big savings at their favorite stores can turn to the Goodshop app, a new iOS app with the latest coupons and deals at more than 5,000 online stores. In addition to being a... Read more
Save on 5th generation refurbished iPod touch...
The Apple Store has Apple Certified Refurbished 5th generation iPod touches available starting at $149. Apple’s one-year warranty is included with each model, and shipping is free. Many, but not all... Read more
What Should Apple’s Next MacBook Priority Be;...
Stabley Times’ Phil Moore says that after expanding its iMac lineup with a new low end model, Apple’s next Mac hardware decision will be how it wants to approach expanding its MacBook lineup as well... 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
WW Sales Program Manager, *Apple* Online St...
**Job Summary** Imagine what you could do here. At Apple , great ideas have a way of becoming great products, services, and customer experiences very quickly. Bring Read more
Lead Software Engineer, *Apple* Online Stor...
**Job Summary** Imagine what you could do here. At Apple , great ideas have a way of becoming great products, services, and customer experiences very quickly. Bring Read more
Manager, *Apple* Fullfillment Operation (AF...
…cross-functional teams to drive the highest level of program management quality for Apple . You will help plan launch strategy and demand generation programs with Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.