-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPKMCFILE.c
290 lines (254 loc) · 9.02 KB
/
PKMCFILE.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
/*3456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678*/
#include "PKIN.h"
#include "PKINDLOG.h"
/****getnewfile()************************************************************/
int getnewfile(char namestrs[256],int nfile)
{
int ilocalflag,ireturn;
static short *imessage, *ninfiles; /*see if launched by a file*/
ilocalflag = 0;
IOerr = 1;
/* Begins with no file and this flag set for no legitimate file*/
while(IOerr == 1)
{
/*m*/ InitCursor();
if(Llaunched && !LAElaunched) /*can be==1 only on first entering program*/
{/*get name of file into global NameStr*/
ilocalflag = 0; /*should not be able to get here under OS later than 6 */
#ifdef SYSTEM6
getnamestroffile(); /*file that launched PREKIN, sys6*/
strcpy(namestrs, (const char *)NameStr);
CtoPstr(namestrs);
ilocalflag = 1;
#endif /*SYSTEM6*/
}
/*.*/ else if(LAElaunched)
{
strcpy(namestrs, (const char *)NameStr);
/*name of file already in global NameStr */
CtoPstr(namestrs);
ilocalflag = 1;
}
else
{
while(IOerr == 1) ilocalflag = getfilename(namestrs,nfile);
/*returns with Pascal type file name in namestrs*/
}
if(ilocalflag == 0) return(0);
/* e.g. invoked cancel instead of file name choice */
Llaunched = 0; /*clear flags so could select file if launch fails*/
LAElaunched = 0;
IOerr = 1;
/*m*/ /*SetCursor(*waitcursor);*/
openafile(namestrs,nfile); /*PKINFILE.C, expects Pascal type name string*/
if(IOerr)
{
/*c*/ sprintf(alertstr,"Error trying to open file %s",namestrs);
/*Ms*/ DoReportDialog();
ireturn = 1; /* try again */
}
else
{
ireturn = 2;
}
}
return(ireturn);
}
/*___getnewfile()___________________________________________________________*/
/****getfilename()***Specific for Macinosh**********************PREKIN*******/
int getfilename(char namestrs[256], int i)
{
Point where;
SFTypeList typeList;
SFReply reply;
int ireturn;
/*
SFReply
good: Boolean;
fType: OSType;
vRefNum: Integer;
version: Integer;
fName: Str63;
*/
if(i==4)
{
sprintf(alertstr,"Now choose a file with coords for %s;"
CRLF"preferably use PREKINAA.LIB",resid[mutoutl]);
DoReportDialog();
}
/*m*/ SetPt( &where, 85, 100 ); /* position of display box on screen */
/* invoke the standard dialog for finding a file */
/*m*/ SFGetFile( where, "\p", NULL,
-1, typeList, /* -1 means display all files */
NULL, &reply );
/*The prompt string seems to go to an off-screen placed text field*/
/*see I-523 of original Inside Macintosh*/
if( reply.good )
{
/* In newer hierarchical directory system,*/
/* reply.vRefNum holds directory number */
/*m*/ SetVol( "\p", reply.vRefNum ); /* change to directory of file */
/*c*/ strcpy(namestrs, (const char *)reply.fName);
/* store file name to be opened later */
ireturn = 1;
}
else
{
ireturn = 0; /*canceled file select procedure*/
}
IOerr = 0;
return(ireturn);
}
/*___getfilename()__________________________________________________________*/
#ifdef SYSTEM6
/****ifilelaunched()****************************/
int ifilelaunched()
{
static short *imessage, *ninfiles;
/*Mac-portable needs these to be static*/
/*see if MAGE was launched by clicking a file on a system 6 machine*/
/*m*/ CountAppFiles(imessage, ninfiles);
return(*ninfiles);
}
/*___ifilelaunched()___________________________*/
/****getnamestroffile()**************************/
void getnamestroffile()
{
AppFile filestart;
/*m*/ GetAppFiles( 1 , &filestart);
/*m*/ ClrAppFiles( 1 );
/*m*/ SetVol( "\p", filestart.vRefNum );
/* change to directory of file */
/*m*/ PtoCstr(filestart.fName);
/*c*/ strcpy(NameStr, (const char *)filestart.fName);
}
/*___getnamestroffile()__________________________*/
#endif /*SYSTEM6*/
/**** ConvertFilename(&fss) from RasMol2.5 Roger Sayle**********************/
/*this is the magic that some how recovers the full path name*/
/*even though the vRefNum and parID return seemingly useless*/
/*static void ConvertFilename(FSSpec *fss) */
void ConvertFilename(FSSpec *fss)
{
register char *src;
register char *dst;
register int i;
char buffer[256];
Str255 dirname;
DirInfo dinfo;
src = buffer;
dinfo.ioDrParID = fss->parID;
dinfo.ioNamePtr = dirname;
do {
dinfo.ioVRefNum = fss->vRefNum;
dinfo.ioFDirIndex = -1;
dinfo.ioDrDirID = dinfo.ioDrParID;
PBGetCatInfo((CInfoPBPtr)&dinfo,0);
*src++ = ':';
for( i=dirname[0]; i; i-- )
*src++ = dirname[i];
} while( dinfo.ioDrDirID != 2 );
/* Reverse the file path! */
dst = NameStr; /*MAGE input file name*/ /*dst = Filename;*/
while( src != buffer )
*dst++ = *(--src);
for( i=1; i<=fss->name[0]; i++ )
*dst++ = fss->name[i];
*dst = '\0'; /* C type ending for string ! */
}
/*___ConvertFilename()_______________________________________________________*/
/*3456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678*/
/****openscriptin()***********************************************************/
int openscriptin(void)
{
Point where;
SFTypeList typeList;
SFReply reply;
int ireturn;
/*m*/ SetPt( &where, 85, 100 ); /* position of display box on screen */
/* invoke the standard dialog for finding a file */
/*m*/ SFGetFile( where, "\p", NULL,
-1, typeList, /* -1 means display all files */
NULL, &reply );
if( reply.good )
{
/* In newer hierarchical directory system,*/
/* reply.vRefNum holds directory number */
/*m*/ SetVol( "\p", reply.vRefNum ); /* change to directory of file */
/*c*/ strcpy(ScriptinStr, (const char *)reply.fName);
/* store file name to be opened later */
/*m*/ PtoCstr((unsigned char *)ScriptinStr);
/* convert input file name from Pascal to C type string */
/*if a previous file is open, close it*/
/*c*/ if(fpscriptin != NULL) fclose(fpscriptin);
/*c*/ if ((fpscriptin = fopen(ScriptinStr,"r")) == NULL)
{
/*c*/ sprintf(alertstr,"Prekin failed to open file: \n%s "
,ScriptinStr);
/*Ms*/ DoReportDialog();
ireturn = 0;
}
else /* file opened, read header from it */
{
/*c*/ fscanf(fpscriptin ,CRLF"Script file opened: %s",temps);
pkintextinsert(temps);
adjusttext(1);
Lscriptin = 1; /*still !! */
Lrangecontrols = 1;
Lstartarange = 1; /*now go through range controls*/
ireturn = 1;
}
}
else
{
ireturn = 0; /*canceled file select procedure*/
Lscriptin = 0; /*failed*/
Lrangecontrols = 0;
Lrangestart = 1;
}
return(ireturn);
}
/*___openscriptin()__________________________________________________________*/
/****openhelpout()***********************************************************/
int openhelpout(void) /*040425*/
{
Point where;
SFTypeList typeList;
SFReply reply;
int ireturn;
SetPt( &where, 85, 100 ); /* position of display box on screen */
/* invoke the standard dialog for finding a file */
SFGetFile( where, "\p", NULL,
-1, typeList, /* -1 means display all files */
NULL, &reply );
if( reply.good )
{
/* In newer hierarchical directory system,*/
/* reply.vRefNum holds directory number */
SetVol( "\p", reply.vRefNum ); /* change to directory of file */
strcpy(helpoutStr, (const char *)reply.fName);
/* store file name to be opened later */
PtoCstr((unsigned char *)helpoutStr);
/* convert input file name from Pascal to C type string */
/*if a previous file is open, close it*/
if(fphelpout != NULL) fclose(fphelpout);
if ((fphelpout = fopen(helpoutStr,"w")) == NULL)
{
sprintf(alertstr,"Prekin failed to open file: \n%s",helpoutStr);
DoReportDialog();
ireturn = 0;
}
else /* file opened */
{
Lhelpoutopen = 1;
ireturn = 1;
}
}
else
{
ireturn = 0; /*canceled file select procedure*/
Lhelpoutopen = 0; /*failed*/
}
return(ireturn);
}
/*___openhelpout()__________________________________________________________*/