File: macinit.c

package info (click to toggle)
readseq 1-15
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 780 kB
  • sloc: ansic: 10,165; makefile: 424; sh: 32
file content (302 lines) | stat: -rw-r--r-- 6,799 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
  macinit.c
  -- Macintosh initializations, then call real main

Note: compile this segment as Main for generic 68000 processor, so it won't
 fail on generic mac

*/

#pragma segment Main

#include <Types.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <StdLib.h>

#include <Quickdraw.h>
#include <Memory.h>
#include <OSUtils.h>
#include <ToolUtils.h>
#include <Windows.h>
#include <Palettes.h>
#include  <dialogs.h>
#include  <StandardFile.h>
#include  <Events.h>
//#include <Menus.h>
//#include <Fonts.h>


Boolean StopKey()
{
EventRecord ev;

  if (EventAvail( keyDownMask+autoKeyMask, &ev)) {
    if (  (ev.modifiers & cmdKey)
     && ((char)(ev.message & charCodeMask) == '.') ) {
        SysBeep(1);
      (void) GetNextEvent( keyDownMask+autoKeyMask, &ev);
      return true;
      }
    }
  return false;
}

Boolean cmdKeyIsDown()
{ KeyMap  kmap;
  GetKeys(&kmap);
  return BitTst(kmap, (sizeof(KeyMap)*8) - 55);
}

Boolean shiftKeyIsDown()
{   KeyMap  kmap;
  GetKeys(&kmap);
  return BitTst(kmap, (sizeof(KeyMap)*8) - 56);
}

Boolean capsLockIsDown()
{ KeyMap  kmap;
  GetKeys(&kmap);
  return BitTst(kmap, (sizeof(KeyMap)*8) - 57);
}

Boolean optionKeyIsDown()
{ KeyMap  kmap;
  GetKeys(&kmap);
  return BitTst(kmap, (sizeof(KeyMap)*8) - 58);
}

Boolean MouseButton()
{
  return Button();
}

Boolean Keypress()
{ EventRecord ev;
  return EventAvail( keyDownMask+keyUpMask+autoKeyMask, &ev);
}



char *StdGetFile(
  char*  prompt,
  OSType fileTypes[],
  int    nFileTypes)
{
  Point       wher;       /*where to display dialog*/
  SFReply     reply;      /*reply record*/
  short       len;
  static char filename[80] = "\0";

  wher.h = 80;
  wher.v = 90;
  if (optionKeyIsDown()) nFileTypes=0;

  SFGetFile(wher, prompt, nil, nFileTypes, fileTypes, nil, &reply);

  if (reply.good) {
      len = SetVol(nil, reply.vRefNum);
    len = reply.fName[0];
    strncpy(filename, (char *)(&reply.fName[1]), len);
    filename[len]= '\0';
    return filename;
    }
  else
    return NULL;
}


int readCmdOptions(FILE *cl, char *progname, char ***argv)
/* command line reader for Mac/MPW  -- dgg */
{
#define MAXS  255
#define addarg(sptr)  if (strlen(sptr)>0) { \
  targv = (char **) realloc( targv, (argc+1) * sizeof(char *)); \
  targv[argc] = (char *) malloc(1+strlen(sptr) * sizeof(char)); \
  strcpy( targv[argc], sptr);  \
  argc++; }

  char  *pword, st[MAXS];
  int   argc = 0;
  char  **targv;

  targv = (char **) malloc(1);
  if (progname==NULL) progname = "program";
  addarg( progname);
  fgets( st, MAXS, cl);
  if (!feof(cl) && st!=NULL && *st!=0) {
    pword = strtok( st, "\ \n");
    while (pword!=NULL) {
      addarg( pword);
      pword = strtok( NULL, "\ \n");
      }
    }

  *argv = targv;
  return argc;
}

int ccommand(char ***argv)
{
  int argc;
  char  **targv;

  argc = readCmdOptions(stdin, *argv[0], &targv);
  *argv = targv;
  return argc;
}




extern _DataInit();

//#define VERSION     curSysEnvVers
#define nocolorID   130
#define no68020     133
#define no68881     132
#define no256       134
#define nosys6      135

void MacInit()
{
SysEnvRec   theWorld;
OSErr       OSys;
DialogPtr   crashDia;
long        tick;

    UnloadSeg(_DataInit);

    InitGraf((Ptr)&qd.thePort);
    //InitFonts();
    InitWindows();
    //InitMenus();
    //TEInit();
    InitDialogs(nil);
    InitCursor();

/*______________________________________________________*/
/*            If not right Machine then stop            */
/*______________________________________________________*/
  OSys = SysEnvirons( curSysEnvVers,&theWorld);

  /*if(!theWorld.hasColorQD) {
    crashDia = GetNewDialog (nocolorID, nil, (WindowPtr) -1);
    DrawDialog (crashDia);
    Delay (300, &tick);
    ExitToShell();
    }*/
  /*if(theWorld.processor < env68020) {
    crashDia = GetNewDialog (no68020, nil, (WindowPtr) -1);
    DrawDialog (crashDia);
    Delay (300, &tick);
    ExitToShell();
    }*/
  /*if(!theWorld.hasFPU) {
    crashDia = GetNewDialog (no68881, nil, (WindowPtr) -1);
    DrawDialog (crashDia);
    Delay (300, &tick);
    ExitToShell();
    }
  if(theWorld.systemVersion < 0x0600) {
    crashDia = GetNewDialog (nosys6, nil, (WindowPtr) -1);
    DrawDialog (crashDia);
    Delay (300, &tick);
    ExitToShell();
    }*/

#ifdef UnDeFineD
/*______________________________________________________*/
/*                     Set Rects                        */
/*______________________________________________________*/
  screenRect = qd.screenBits.bounds;
  offLeft = 0;
  offTop = 0;
  offRight = screenRect.right;
  offBottom = screenRect.bottom;
  SetRect(&BaseRect, 40, 60, 472, 282);
  tempRgn = GetGrayRgn();
  HLock ((Handle) tempRgn);
  TotalRect = (**tempRgn).rgnBBox;
  SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40,
        (**tempRgn).rgnBBox.bottom - 40);
  HUnlock ((Handle) tempRgn);

/*______________________________________________________*/
/*        Open Window & set Palette & Picture           */
/*______________________________________________________*/
  theGDevice = GetMainDevice();
  HLock ((Handle) theGDevice);
  mycolors = (**(**theGDevice).gdPMap).pmTable;
  numcolor = (**(**theGDevice).gdPMap).pixelSize;
  HUnlock((Handle) theGDevice);
  switch (numcolor) {
    case 1:
      numcolor = 2;
      break;
    case 2:
      numcolor = 4;
      break;
    case 4:
      numcolor = 16;
      break;
    case 8:
      numcolor = 256;
      break;
    }

  myWindow = NewCWindow(nil, &BaseRect, "", true, zoomDocProc,
              (WindowPtr) -1, true, 150);
  SetPort((WindowPtr) myWindow);
  DrawGrowIcon (myWindow);

  srcPalette = NewPalette (numcolor, mycolors, pmCourteous, 0);
  SetPalette ((WindowPtr) myWindow, srcPalette, true);

/*______________________________________________________*/
/*                    Set menus                         */
/*______________________________________________________*/
  mymenu0 = GetMenu(appleID);
  AddResMenu(mymenu0, 'DRVR');
  InsertMenu(mymenu0,0);
  mymenu1 = newmenu(129,"File");
  appendmenu(mymenu1,"Start;Quit");
  InsertMenu(mymenu1,0);
  mymenu2 = newmenu(130,"Edit");
  InsertMenu(mymenu2,0);
  DrawMenuBar();

/*______________________________________________________*/
/*                  Init variables                      */
/*______________________________________________________*/
  DoneFlag = false;
  yieldTime = 0;
  return;
#endif

}




main(int argc, char *argv[])
{
  Boolean loop = true;
  char **myargv;
  int   myargc;

  /* MacInit();  -- SIOW library handles this */
  do {
    fprintf(stderr,"\nEnter command line for %s [cmd-Q to quit]\n", argv[0]);
    fprintf(stderr,"-> %s ",argv[0]);
    myargv = argv;
    myargc = ccommand(&myargv);

    siow_main(myargc, myargv);
    fflush(stdout);

    } while (true);
  exit(0);
}