ARB
macinit.c
Go to the documentation of this file.
1 /*
2  macinit.c
3  -- Macintosh initializations, then call real main
4 
5 Note: compile this segment as Main for generic 68000 processor, so it won't
6  fail on generic mac
7 
8 */
9 
10 #pragma segment Main
11 
12 #include <Types.h>
13 #include <stdio.h>
14 #include <ctype.h>
15 #include <string.h>
16 #include <StdLib.h>
17 
18 #include <Quickdraw.h>
19 #include <Memory.h>
20 #include <OSUtils.h>
21 #include <ToolUtils.h>
22 #include <Windows.h>
23 #include <Palettes.h>
24 #include <dialogs.h>
25 #include <StandardFile.h>
26 #include <Events.h>
27 //#include <Menus.h>
28 //#include <Fonts.h>
29 
30 
32 {
33 EventRecord ev;
34 
35  if (EventAvail( keyDownMask+autoKeyMask, &ev)) {
36  if ( (ev.modifiers & cmdKey)
37  && ((char)(ev.message & charCodeMask) == '.') ) {
38  SysBeep(1);
39  (void) GetNextEvent( keyDownMask+autoKeyMask, &ev);
40  return true;
41  }
42  }
43  return false;
44 }
45 
47 { KeyMap kmap;
48  GetKeys(&kmap);
49  return BitTst(kmap, (sizeof(KeyMap)*8) - 55);
50 }
51 
53 { KeyMap kmap;
54  GetKeys(&kmap);
55  return BitTst(kmap, (sizeof(KeyMap)*8) - 56);
56 }
57 
59 { KeyMap kmap;
60  GetKeys(&kmap);
61  return BitTst(kmap, (sizeof(KeyMap)*8) - 57);
62 }
63 
65 { KeyMap kmap;
66  GetKeys(&kmap);
67  return BitTst(kmap, (sizeof(KeyMap)*8) - 58);
68 }
69 
71 {
72  return Button();
73 }
74 
76 { EventRecord ev;
77  return EventAvail( keyDownMask+keyUpMask+autoKeyMask, &ev);
78 }
79 
80 
81 
82 char *StdGetFile(
83  char* prompt,
84  OSType fileTypes[],
85  int nFileTypes)
86 {
87  Point wher; /*where to display dialog*/
88  SFReply reply; /*reply record*/
89  short len;
90  static char filename[80] = "\0";
91 
92  wher.h = 80;
93  wher.v = 90;
94  if (optionKeyIsDown()) nFileTypes=0;
95 
96  SFGetFile(wher, prompt, nil, nFileTypes, fileTypes, nil, &reply);
97 
98  if (reply.good) {
99  len = SetVol(nil, reply.vRefNum);
100  len = reply.fName[0];
101  strncpy(filename, (char *)(&reply.fName[1]), len);
102  filename[len]= '\0';
103  return filename;
104  }
105  else
106  return NULL;
107 }
108 
109 
110 int readCmdOptions(FILE *cl, char *progname, char ***argv)
111 /* command line reader for Mac/MPW -- dgg */
112 {
113 #define MAXS 255
114 #define addarg(sptr) if (strlen(sptr)>0) { \
115  targv = (char **) realloc( targv, (argc+1) * sizeof(char *)); \
116  targv[argc] = (char *) malloc(1+strlen(sptr) * sizeof(char)); \
117  strcpy( targv[argc], sptr); \
118  argc++; }
119 
120  char *pword, st[MAXS];
121  int argc = 0;
122  char **targv;
123 
124  targv = (char **) malloc(1);
125  if (progname==NULL) progname = "program";
126  addarg( progname);
127  fgets( st, MAXS, cl);
128  if (!feof(cl) && st!=NULL && *st!=0) {
129  pword = strtok( st, "\ \n");
130  while (pword!=NULL) {
131  addarg( pword);
132  pword = strtok( NULL, "\ \n");
133  }
134  }
135 
136  *argv = targv;
137  return argc;
138 }
139 
140 int ccommand(char ***argv)
141 {
142  int argc;
143  char **targv;
144 
145  argc = readCmdOptions(stdin, *argv[0], &targv);
146  *argv = targv;
147  return argc;
148 }
149 
150 
151 
152 
153 extern _DataInit();
154 
155 //#define VERSION curSysEnvVers
156 #define nocolorID 130
157 #define no68020 133
158 #define no68881 132
159 #define no256 134
160 #define nosys6 135
161 
162 void MacInit()
163 {
164 SysEnvRec theWorld;
165 OSErr OSys;
166 DialogPtr crashDia;
167 long tick;
168 
169  UnloadSeg(_DataInit);
170 
171  InitGraf((Ptr)&qd.thePort);
172  //InitFonts();
173  InitWindows();
174  //InitMenus();
175  //TEInit();
176  InitDialogs(nil);
177  InitCursor();
178 
179 /*______________________________________________________*/
180 /* If not right Machine then stop */
181 /*______________________________________________________*/
182  OSys = SysEnvirons( curSysEnvVers,&theWorld);
183 
184  /*if(!theWorld.hasColorQD) {
185  crashDia = GetNewDialog (nocolorID, nil, (WindowPtr) -1);
186  DrawDialog (crashDia);
187  Delay (300, &tick);
188  ExitToShell();
189  }*/
190  /*if(theWorld.processor < env68020) {
191  crashDia = GetNewDialog (no68020, nil, (WindowPtr) -1);
192  DrawDialog (crashDia);
193  Delay (300, &tick);
194  ExitToShell();
195  }*/
196  /*if(!theWorld.hasFPU) {
197  crashDia = GetNewDialog (no68881, nil, (WindowPtr) -1);
198  DrawDialog (crashDia);
199  Delay (300, &tick);
200  ExitToShell();
201  }
202  if(theWorld.systemVersion < 0x0600) {
203  crashDia = GetNewDialog (nosys6, nil, (WindowPtr) -1);
204  DrawDialog (crashDia);
205  Delay (300, &tick);
206  ExitToShell();
207  }*/
208 
209 #ifdef UnDeFineD
210 /*______________________________________________________*/
211 /* Set Rects */
212 /*______________________________________________________*/
213  screenRect = qd.screenBits.bounds;
214  offLeft = 0;
215  offTop = 0;
216  offRight = screenRect.right;
217  offBottom = screenRect.bottom;
218  SetRect(&BaseRect, 40, 60, 472, 282);
219  tempRgn = GetGrayRgn();
220  HLock ((Handle) tempRgn);
221  TotalRect = (**tempRgn).rgnBBox;
222  SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40,
223  (**tempRgn).rgnBBox.bottom - 40);
224  HUnlock ((Handle) tempRgn);
225 
226 /*______________________________________________________*/
227 /* Open Window & set Palette & Picture */
228 /*______________________________________________________*/
229  theGDevice = GetMainDevice();
230  HLock ((Handle) theGDevice);
231  mycolors = (**(**theGDevice).gdPMap).pmTable;
232  numcolor = (**(**theGDevice).gdPMap).pixelSize;
233  HUnlock((Handle) theGDevice);
234  switch (numcolor) {
235  case 1:
236  numcolor = 2;
237  break;
238  case 2:
239  numcolor = 4;
240  break;
241  case 4:
242  numcolor = 16;
243  break;
244  case 8:
245  numcolor = 256;
246  break;
247  }
248 
249  myWindow = NewCWindow(nil, &BaseRect, "", true, zoomDocProc,
250  (WindowPtr) -1, true, 150);
251  SetPort((WindowPtr) myWindow);
252  DrawGrowIcon (myWindow);
253 
254  srcPalette = NewPalette (numcolor, mycolors, pmCourteous, 0);
255  SetPalette ((WindowPtr) myWindow, srcPalette, true);
256 
257 /*______________________________________________________*/
258 /* Set menus */
259 /*______________________________________________________*/
260  mymenu0 = GetMenu(appleID);
261  AddResMenu(mymenu0, 'DRVR');
262  InsertMenu(mymenu0,0);
263  mymenu1 = newmenu(129,"File");
264  appendmenu(mymenu1,"Start;Quit");
265  InsertMenu(mymenu1,0);
266  mymenu2 = newmenu(130,"Edit");
267  InsertMenu(mymenu2,0);
268  DrawMenuBar();
269 
270 /*______________________________________________________*/
271 /* Init variables */
272 /*______________________________________________________*/
273  DoneFlag = false;
274  yieldTime = 0;
275  return;
276 #endif
277 
278 }
279 
280 
281 
282 
283 main(int argc, char *argv[])
284 {
285  Boolean loop = true;
286  char **myargv;
287  int myargc;
288 
289  /* MacInit(); -- SIOW library handles this */
290  do {
291  fprintf(stderr,"\nEnter command line for %s [cmd-Q to quit]\n", argv[0]);
292  fprintf(stderr,"-> %s ",argv[0]);
293  myargv = argv;
294  myargc = ccommand(&myargv);
295 
296  siow_main(myargc, myargv);
297  fflush(stdout);
298 
299  } while (true);
300  exit(0);
301 }
302 
int readCmdOptions(FILE *cl, char *progname, char ***argv)
Definition: macinit.c:110
main(int argc, char *argv[])
Definition: macinit.c:283
Boolean optionKeyIsDown()
Definition: macinit.c:64
#define addarg(sptr)
int ccommand(char ***argv)
Definition: macinit.c:140
Boolean shiftKeyIsDown()
Definition: macinit.c:52
fflush(stdout)
Boolean Keypress()
Definition: macinit.c:75
void MacInit()
Definition: macinit.c:162
Boolean capsLockIsDown()
Definition: macinit.c:58
Boolean MouseButton()
Definition: macinit.c:70
#define MAXS
_DataInit()
Boolean cmdKeyIsDown()
Definition: macinit.c:46
Boolean StopKey()
Definition: macinit.c:31
char * StdGetFile(char *prompt, OSType fileTypes[], int nFileTypes)
Definition: macinit.c:82