-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPKMCMAIN.c
356 lines (305 loc) · 11.3 KB
/
PKMCMAIN.c
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*3456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678*/
/***PREKINMACmain.c**********************************************************/
#define EXTERN
/* that is, EXTERN is blank, so prekin.h will do initial declarations */
#include "PKIN.h" /* #include "prekin.h" */
#include "PKINMENU.h"
#include "PKINDLOG.h"
#include <SIOUX.h> /*980701*/
long theclockcount(void);
/***** main ****************************************************************/
void main()
{
int j;
/*Ltestprint = TRUE;*/ /*test option, compile as TRUE to invoke,*/
Ltestprint = 0; /* as FALSE for distribution, can also set in Kludges */
Lerr =0;
mainsetup(); /*____INIT.c*/
/*Lnewfile will be set by AppleEvent if launched with a file name*/
/*beginning event loop to get starting conditions sorted out*/
for(j=1 ; j<10 ; j++)
{
HandleEvent(); /*which might pick up a HandleAEOpenDoc() event*/
}
/*#define FAKECOMMANDLINE*/
#ifdef FAKECOMMANDLINE
sprintf(word,"6PFK.pdb 6PFK.mut.kin -scope -show \"sc,hy\" -mutate 35 tyr -chainid b -append");
/*sprintf(word,"-quiet -ribbon -colornc -chainid AB -onegroup -notext 6PFK.pdb 1atest.kin");*/
/*sprintf(word,"-quiet -show \"mc,at,ct,cb[off],lb(green)[off]\" -nosubgroupmasters -chainid _A -model \"_,6,10\" -bval -bcol -colorscale \"green,10.5,red,20,cyan\" -halfbonds -onegroup -notext 6PFK.pdb 1atest.kin");*/
/*sprintf(word,"-quiet -show \"ca,cb,lb(green)[off]\" -chainid _A -model \"6,10\" -bval -bcol -halfbonds -onegroup -notext 1OMNm6.sup 1atest.kin");*/
/*sprintf(word,"-quiet -show \"ca,cb,lb(green)[off]\" -chainid AB -bval -bcol -halfbonds -onegroup -notext 6PFK.pdb 1atest.kin");*/
/*sprintf(word,"-quiet -show \"ca,cb,lb(green)[off]\" -chainid B -bval -bcol -halfbonds -allbuttons -notext 1cruAH 1atest.kin");*/
/*sprintf(word,"-out 1ahelp.kin -quiet -help");*/
if(Ltestprint)
{
pkintextinsert(word);
adjusttext(0); /*1st call 0 to set up, match CRLFs, quick reset of text*/
}
dissectcommandline(word); /*PKININIT*/
#endif /*FAKECOMMANDLINE*/
/*if(Lbegin)*/
beginnings(); /*HandleAEOpenDoc() sets Lbegin=0 */
/*final endless event loop: program ends sitting here */
/* so messages can be read*/
for (;;)
{/*beginning & final endless event loop*/ /*990402*/
mainlooprouter(); /*PKININIT, common router*/
if(Lerr) break;
if(Lquiet==0) /*i.e. NOT quiet so allow online info and control*/
HandleEvent(); /*____MAIN.c*/
}/*beginning & final endless event loop*/
}
/*___main()_________________________________________________________________*/
/****HandleEvent()***********************************************************/
/* The main event dispatcher. This routine called
* repeatedly by the event-controlled loops, (it handles only one event).
*/
void HandleEvent()
{
int ok;
EventRecord theEvent;
WindowPtr theWindow, oldPort;
OSErr myErr;
Boolean SIOUXDidEvent; /*980701*/
HiliteMenu(0); /*m*/
if(Lappleevents == 0) SystemTask(); /*m*/
/* Handle desk accessories, use with GetNextEvent() */
TEIdle(textText);
if(Lappleevents==0) ok = GetNextEvent( everyEvent, &theEvent); /*m*/
else ok = WaitNextEvent(everyEvent, &theEvent, 0xFFFF, nil); /*m*/
if(ok)/*980701*/
{
SIOUXDidEvent = SIOUXHandleOneEvent(&theEvent);
}
if(ok && !SIOUXDidEvent)/*980701*/
{/*ok*/
switch (theEvent.what)
{/*switch*/
case osEvt: /*980915 operating system event*/
switch ((theEvent.message >> 24) & 0x00FF)
{/*osEvt switch*/
case suspendResumeMessage:
if((theEvent.message & resumeFlag) == 0)
{/*osEvt to suspend PREKIN*/
HiliteControl(vtextScroll,255);
}
else
{/*osEvt to resume PREKIN*/
HiliteControl(vtextScroll,0);
}
break;
case mouseMovedMessage:
;
break;
}/*osEvt switch*/
break;
case kHighLevelEvent:
if(Lappleevents)
{
myErr = AEProcessAppleEvent( (EventRecord *)&theEvent );
/*handlers in PKMCFILE.C*/
/*HandleAEOpenDoc(),HandleAEQuitApp(),HandleAEIgnore()*/
#ifdef TRIAL971223
{
sprintf(alertstr,"PREKIN high level event:theEvent.message== %ld, myErr %d"
,theEvent.message,myErr);
DoReportDialog();
}
#endif /*TRIAL971223*/
}
break;
case mouseDown:
/*.*/ HandleMouseDown(&theEvent);
break;
case keyDown:
charin = (theEvent.message & charCodeMask);
if ((theEvent.modifiers & cmdKey) != 0)
{
/*P*/ AdjustMenus();
/*P*/ HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
}
else if (charin != 0) /* meaningful text key */
{
/*m*/ if (FrontWindow() == textWindow)
/* i.e. textWindow is selected */
{
/*m*/ TEKey( charin, textText); /* echo */
/*I*/ textstringin();
}
}
break;
case updateEvt:
/*m*/ GetPort(&oldPort);
/*m*/ SetPort(theWindow = (WindowPtr)theEvent.message);
/*m*/ BeginUpdate(theWindow);
/*m*/ InvalRect(&theWindow->portRect);
/*tell window manager window is broken*/
if (theWindow == textWindow)
{
/*.*/ settextScrollBar();
/*.*/ gettextTextarea();
/*.*/ settextTextarea();
/*m*/ TEActivate(textText);
/*m*/ TEUpdate(&textdRect,textText);
/*m*/ ValidRect(&textWindow->portRect);
/*tell window manager window is ok*/
}
/*m*/ EndUpdate(theWindow);
/*m*/ SetPort(oldPort);
break;
case activateEvt:
theWindow = (WindowPtr)theEvent.message;
/*m*/ GetPort(&oldPort);
/*m*/ SetPort(theWindow = (WindowPtr)theEvent.message);
/*m*/ BeginUpdate(theWindow);
/*m*/ InvalRect(&theWindow->portRect);
/*tell window manager window is broken*/
/*.*/ if (theWindow == textWindow) settextScrollBar();
/*m*/ EndUpdate(theWindow);
/*m*/ SetPort(oldPort);
break;
}
}
}
/*___HandleEvent()__________________________________________________________*/
/****HandleMouseDown()*******************************************************/
void HandleMouseDown(EventRecord *theEvent) /*Take care of mouseDown events.*/
{
WindowPtr theWindow, oldPort;
int windowCode;
long growResult;
Rect limitRect;
SetRect(&limitRect, 80, 80,
screenBits.bounds.right - screenBits.bounds.left -4,
screenBits.bounds.bottom - screenBits.bounds.top -24);
/*m*/ windowCode = FindWindow (theEvent->where, &theWindow);
switch (windowCode)
{
case inSysWindow:
/*m*/ SystemClick (theEvent, theWindow);
break;
case inMenuBar:
/*P*/ AdjustMenus();
/*P*/ HandleMenu(MenuSelect(theEvent->where));
break;
case inDrag:
/*m*/ DragWindow(theWindow, theEvent->where, &dragRect);
break;
case inContent:
{
if (theWindow != FrontWindow())
/*m*/ SelectWindow(theWindow);
else
{
if (theWindow == textWindow)
{
/*m*/ SetPort(textWindow);
/*.*/ DotextContentClick( theEvent->where );
}
}
}
break;
case inGoAway:
/*m*/ if (TrackGoAway(theWindow, theEvent->where))
{
/*m*/ HideWindow(theWindow);
/*P*/ AdjustMenus();
}
break;
case inGrow:
{
if (theWindow == textWindow )
{
/*m*/ GetPort(&oldPort);
/*m*/ SetPort(textWindow);
/*m*/ growResult = GrowWindow(textWindow
, theEvent->where, &limitRect);
/*m*/ SizeWindow(textWindow,LoWord(growResult)
,HiWord(growResult),0xff);
/*m*/ InvalRect(&textWindow->portRect);
/*.*/ settextScrollBar();
/*.*/ gettextTextarea();
/*.*/ settextTextarea();
/*m*/ SetPort(oldPort);
}
}
break;
}
}
/*___HandleMouseDown()______________________________________________________*/
/****cursorstandard()*******************************************************/
void cursorstandard()
{
InitCursor(); /*m*/
}
/*___cursorstandard()______________________________________________________*/
/****cursorshowwait()******************************************************/
void cursorshowwait()
{
SetCursor(*waitcursor); /*m*/
}
/*___cursorshowwait()_____________________________________________________*/
/*3456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678*/
/****HandleloopEvent()*******************************************************/
/* Minor event dispatcher, esp. for aborting endless runs. Called */
/* repeatedly by the processing loop, (it handles only one event). */
int HandleloopEvent()
{
int ok,ireturn;
EventRecord theEvent;
long charCode;
ireturn = 0;
if(Lappleevents==0) ok = GetNextEvent( everyEvent, &theEvent); /*m*/
else ok = WaitNextEvent(everyEvent, &theEvent, 0, nil); /*m*/
if(ok)
{/*ok*/
switch (theEvent.what)
{/*switch*/
case keyDown:
charin = (theEvent.message & charCodeMask);
if ((theEvent.modifiers & cmdKey) != 0)
{
; /*ignore*/
}
else if (charin != 0) /* meaningful text key */
{
charCode = BitAnd(theEvent.message, charCodeMask);
if(charCode==46) /* . */ /* ascii code */
{
ireturn = 1;
}
}
break;
}/*switch*/
}/*ok*/
return(ireturn);
}
/*___HandleloopEvent()______________________________________________________*/
/****getkeydownstate()*******************************************************/
int getkeydownstate()
{
int ireturn;
ireturn = 0;
if( HandleloopEvent() ) ireturn = 1;
return(ireturn);
}
/*___getkeydownstate()______________________________________________________*/
/****waste()*******************************************************************/
void waste(long nsec)
{
long ticksatstart; /*timing in ticks = 1/60 sec:*/
int j;
ticksatstart = theclockcount(); /*from last startup, good for ~1 year*/
while( (theclockcount() - ticksatstart) < 60*nsec)
{
for(j=-32000; j<32000; j++)
;/*waste a little time*/
}
}
/*___waste()__________________________________________________________________*/
/****theclockcount()*****************************/
long theclockcount()
{
return( TickCount() );
}
/*___theclockcount()____________________________*/