-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPKPCFILE.cpp
226 lines (203 loc) · 6.36 KB
/
PKPCFILE.cpp
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
#include "PKIN.H"
#include "PKINDLOG.h"
#include <direct.h>
/****openscriptin()**********************************************************/
int openscriptin(void)
{
int ireturn;
ireturn = getfilename("dummy", 3); /*3 for scriptin*/
if (ireturn)
{
/*if a previous file is open, close it*/
if(fpscriptin != NULL) fclose(fpscriptin);
if ((fpscriptin = fopen(ScriptinStr,"r")) == NULL)
{
sprintf(alertstr,"Prekin failed to open file: \n%s"
,ScriptinStr);
DoReportDialog();
ireturn = 0;
}
else /* file opened, read header from it */
{
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()_________________________________________________________*/
/****getnewfile()************************************************************/
int getnewfile(char namestrs[256],int nfile)
{
int iflag;
int ireturn = 0;
IOerr = 1;
/* Begins with no file and this flag set for no legitimate file*/
while(IOerr == 1)
{
while(IOerr == 1) iflag = getfilename(namestrs,nfile);
if(iflag == 0) return(0);
/* e.g. invoked cancel instead of file name choice */
IOerr = 1;
openafile(namestrs,nfile); /*PKINFILE.C*/
if(IOerr)
{
sprintf(alertstr,"Error trying to open file %s",namestrs);
DoReportDialog();
ireturn = 1; /* try again */
}
else
{
SetPrekinCaption(); /* set caption to include current filename */
ireturn = 2;
}
}
return(ireturn);
}
/*___getnewfile()___________________________________________________________*/
/*ref: Microsoft Windows Guide to Programming, 1990, for file IO stuff*/
/****getfilename()***Specific for PCWindows**********************************/
int getfilename(char namestrs[256], int nfile)
{
char *cpslash;
OPENFILENAME ofn;
char szFile[256],szFileTitle[256];
UINT i, cbString;
char chReplace;
char szFilter[256];
int ireturn;
if (*szDirName == '\0') _getcwd(szDirName,sizeof(szDirName));
szFile[0] = '\0';
if(nfile==1) strcpy(szFilter,"pdb (*.*)|*.*|");
if(nfile==3) strcpy(szFilter,"script (*.*)|*.*|");
if(nfile==4) strcpy(szFilter,"AA library (*.*)|*.*|");
cbString = strlen(szFilter);
chReplace = szFilter[cbString-1];
for (i = 0; szFilter[i] != '\0'; i++)
{
if (szFilter[i] == chReplace) szFilter[i] = '\0';
}
memset(&ofn,0,sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = PrekinWindow;
ofn.lpstrFilter = szFilter;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof(szFileTitle);
ofn.lpstrInitialDir = szDirName;
if(nfile==1) ofn.lpstrTitle = "PDB File Open";
if(nfile==3) ofn.lpstrTitle = "Script File Open";
if(nfile==4) ofn.lpstrTitle = "AA Library File Open";
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if (GetOpenFileName(&ofn)) /*this must be a system call! */
{
lstrcpy(szDirName,ofn.lpstrFile);
if ((cpslash = strrchr(szDirName,'\\')) != NULL) *cpslash = '\0';
/*c*/ if(nfile==1) lstrcpy(namestrs,ofn.lpstrFile);
if(nfile==3) lstrcpy(ScriptinStr,ofn.lpstrFile);
if(nfile==4) lstrcpy(namestrs,ofn.lpstrFile);
/* store file name to be opened later */
ireturn = 1;
}
else
{
ireturn = 0;
}
IOerr = 0;
return(ireturn);
}
/*___getfilename()__________________________________________________________*/
/****getoutfilename()***Specific for PCWindows****************************/
int getoutfilename(char OutfileStr[256], int nfile)
{
char *cpslash;
OPENFILENAME ofn;
char szFile[256],szFileTitle[256];
UINT i, cbString;
char chReplace;
char szFilter[256];
int ireturn;
if (*szDirName == '\0') _getcwd(szDirName,sizeof(szDirName));
szFile[0] = '\0';
if(nfile==1) strcpy(szFilter,"kin (*.kin)|*.kin|");
if(nfile==2) strcpy(szFilter,"script (*.*)|*.*|");
cbString = strlen(szFilter);
chReplace = szFilter[cbString-1];
for (i = 0; szFilter[i] != '\0'; i++)
{
if (szFilter[i] == chReplace) szFilter[i] = '\0';
}
memset(&ofn,0,sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = PrekinWindow;
ofn.lpstrFilter = szFilter;
ofn.nFilterIndex = 1;
sprintf(szFile,"%s",OutfileStr);
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
sprintf(szFileTitle,"%s",OutfileStr);
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof(szFileTitle);
ofn.lpstrInitialDir = szDirName;
if(nfile==1) ofn.lpstrTitle = "Kinemage Save As";
if(nfile==2) ofn.lpstrTitle = "Script File Save As";
ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
if (GetSaveFileName(&ofn)) /*this must be a system call! */
{
lstrcpy(szDirName,ofn.lpstrFile);
if ((cpslash = strrchr(szDirName,'\\')) != NULL) *cpslash = '\0';
/*c*/ strcpy(OutfileStr,ofn.lpstrFile );
/* store file name to be opened later */
ireturn = 1;
}
else
{
ireturn = 0;
}
IOerr = 0;
return(ireturn);
}
/*___getoutfilename()____________________________________________________*/
/****openhelpout()**********************************************************/
int openhelpout(void)
{
int ireturn;
ireturn = getfilename("dummy", 5); /*5 for helpout*/
if (ireturn)
{
/*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, read header from it */
{
Lhelpoutopen = 1;
ireturn = 1;
}
}
else
{
ireturn = 0; /*canceled file select procedure*/
Lhelpoutopen = 0; /*failed*/
}
return(ireturn);
}
/*___openhelpout()_________________________________________________________*/