00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #pragma segment Main
00011
00012 #include <Types.h>
00013 #include <stdio.h>
00014 #include <ctype.h>
00015 #include <string.h>
00016 #include <StdLib.h>
00017
00018 #include <Quickdraw.h>
00019 #include <Memory.h>
00020 #include <OSUtils.h>
00021 #include <ToolUtils.h>
00022 #include <Windows.h>
00023 #include <Palettes.h>
00024 #include <dialogs.h>
00025 #include <StandardFile.h>
00026 #include <Events.h>
00027
00028
00029
00030
00031 Boolean StopKey()
00032 {
00033 EventRecord ev;
00034
00035 if (EventAvail( keyDownMask+autoKeyMask, &ev)) {
00036 if ( (ev.modifiers & cmdKey)
00037 && ((char)(ev.message & charCodeMask) == '.') ) {
00038 SysBeep(1);
00039 (void) GetNextEvent( keyDownMask+autoKeyMask, &ev);
00040 return true;
00041 }
00042 }
00043 return false;
00044 }
00045
00046 Boolean cmdKeyIsDown()
00047 { KeyMap kmap;
00048 GetKeys(&kmap);
00049 return BitTst(kmap, (sizeof(KeyMap)*8) - 55);
00050 }
00051
00052 Boolean shiftKeyIsDown()
00053 { KeyMap kmap;
00054 GetKeys(&kmap);
00055 return BitTst(kmap, (sizeof(KeyMap)*8) - 56);
00056 }
00057
00058 Boolean capsLockIsDown()
00059 { KeyMap kmap;
00060 GetKeys(&kmap);
00061 return BitTst(kmap, (sizeof(KeyMap)*8) - 57);
00062 }
00063
00064 Boolean optionKeyIsDown()
00065 { KeyMap kmap;
00066 GetKeys(&kmap);
00067 return BitTst(kmap, (sizeof(KeyMap)*8) - 58);
00068 }
00069
00070 Boolean MouseButton()
00071 {
00072 return Button();
00073 }
00074
00075 Boolean Keypress()
00076 { EventRecord ev;
00077 return EventAvail( keyDownMask+keyUpMask+autoKeyMask, &ev);
00078 }
00079
00080
00081
00082 char *StdGetFile(
00083 char* prompt,
00084 OSType fileTypes[],
00085 int nFileTypes)
00086 {
00087 Point wher;
00088 SFReply reply;
00089 short len;
00090 static char filename[80] = "\0";
00091
00092 wher.h = 80;
00093 wher.v = 90;
00094 if (optionKeyIsDown()) nFileTypes=0;
00095
00096 SFGetFile(wher, prompt, nil, nFileTypes, fileTypes, nil, &reply);
00097
00098 if (reply.good) {
00099 len = SetVol(nil, reply.vRefNum);
00100 len = reply.fName[0];
00101 strncpy(filename, (char *)(&reply.fName[1]), len);
00102 filename[len]= '\0';
00103 return filename;
00104 }
00105 else
00106 return NULL;
00107 }
00108
00109
00110 int readCmdOptions(FILE *cl, char *progname, char ***argv)
00111
00112 {
00113 #define MAXS 255
00114 #define addarg(sptr) if (strlen(sptr)>0) { \
00115 targv = (char **) realloc( targv, (argc+1) * sizeof(char *)); \
00116 targv[argc] = (char *) malloc(1+strlen(sptr) * sizeof(char)); \
00117 strcpy( targv[argc], sptr); \
00118 argc++; }
00119
00120 char *pword, st[MAXS];
00121 int argc = 0;
00122 char **targv;
00123
00124 targv = (char **) malloc(1);
00125 if (progname==NULL) progname = "program";
00126 addarg( progname);
00127 fgets( st, MAXS, cl);
00128 if (!feof(cl) && st!=NULL && *st!=0) {
00129 pword = strtok( st, "\ \n");
00130 while (pword!=NULL) {
00131 addarg( pword);
00132 pword = strtok( NULL, "\ \n");
00133 }
00134 }
00135
00136 *argv = targv;
00137 return argc;
00138 }
00139
00140 int ccommand(char ***argv)
00141 {
00142 int argc;
00143 char **targv;
00144
00145 argc = readCmdOptions(stdin, *argv[0], &targv);
00146 *argv = targv;
00147 return argc;
00148 }
00149
00150
00151
00152
00153 extern _DataInit();
00154
00155
00156 #define nocolorID 130
00157 #define no68020 133
00158 #define no68881 132
00159 #define no256 134
00160 #define nosys6 135
00161
00162 void MacInit()
00163 {
00164 SysEnvRec theWorld;
00165 OSErr OSys;
00166 DialogPtr crashDia;
00167 long tick;
00168
00169 UnloadSeg(_DataInit);
00170
00171 InitGraf((Ptr)&qd.thePort);
00172
00173 InitWindows();
00174
00175
00176 InitDialogs(nil);
00177 InitCursor();
00178
00179
00180
00181
00182 OSys = SysEnvirons( curSysEnvVers,&theWorld);
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 #ifdef UnDeFineD
00210
00211
00212
00213 screenRect = qd.screenBits.bounds;
00214 offLeft = 0;
00215 offTop = 0;
00216 offRight = screenRect.right;
00217 offBottom = screenRect.bottom;
00218 SetRect(&BaseRect, 40, 60, 472, 282);
00219 tempRgn = GetGrayRgn();
00220 HLock ((Handle) tempRgn);
00221 TotalRect = (**tempRgn).rgnBBox;
00222 SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40,
00223 (**tempRgn).rgnBBox.bottom - 40);
00224 HUnlock ((Handle) tempRgn);
00225
00226
00227
00228
00229 theGDevice = GetMainDevice();
00230 HLock ((Handle) theGDevice);
00231 mycolors = (**(**theGDevice).gdPMap).pmTable;
00232 numcolor = (**(**theGDevice).gdPMap).pixelSize;
00233 HUnlock((Handle) theGDevice);
00234 switch (numcolor) {
00235 case 1:
00236 numcolor = 2;
00237 break;
00238 case 2:
00239 numcolor = 4;
00240 break;
00241 case 4:
00242 numcolor = 16;
00243 break;
00244 case 8:
00245 numcolor = 256;
00246 break;
00247 }
00248
00249 myWindow = NewCWindow(nil, &BaseRect, "", true, zoomDocProc,
00250 (WindowPtr) -1, true, 150);
00251 SetPort((WindowPtr) myWindow);
00252 DrawGrowIcon (myWindow);
00253
00254 srcPalette = NewPalette (numcolor, mycolors, pmCourteous, 0);
00255 SetPalette ((WindowPtr) myWindow, srcPalette, true);
00256
00257
00258
00259
00260 mymenu0 = GetMenu(appleID);
00261 AddResMenu(mymenu0, 'DRVR');
00262 InsertMenu(mymenu0,0);
00263 mymenu1 = newmenu(129,"File");
00264 appendmenu(mymenu1,"Start;Quit");
00265 InsertMenu(mymenu1,0);
00266 mymenu2 = newmenu(130,"Edit");
00267 InsertMenu(mymenu2,0);
00268 DrawMenuBar();
00269
00270
00271
00272
00273 DoneFlag = false;
00274 yieldTime = 0;
00275 return;
00276 #endif
00277
00278 }
00279
00280
00281
00282
00283 main(int argc, char *argv[])
00284 {
00285 Boolean loop = true;
00286 char **myargv;
00287 int myargc;
00288
00289
00290 do {
00291 fprintf(stderr,"\nEnter command line for %s [cmd-Q to quit]\n", argv[0]);
00292 fprintf(stderr,"-> %s ",argv[0]);
00293 myargv = argv;
00294 myargc = ccommand(&myargv);
00295
00296 siow_main(myargc, myargv);
00297 fflush(stdout);
00298
00299 } while (true);
00300 exit(0);
00301 }
00302