~mjmendoza/quixie/trunk

« back to all changes in this revision

Viewing changes to src/cls/kse_File.cpp

  • Committer: creek23
  • Date: 2017-09-09 06:35:49 UTC
  • Revision ID: svn-v4:5d579d6f-57a3-4165-9b1e-6dacaf8da75a:quixie:674
first attempt to make it compilable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//translated this 09.22.07@9:01PM by mjmendozaIV
2
 
#include "kageExterns.hpp"
 
2
#include "../../kageExterns.hpp"
3
3
 
4
4
const kseFILE_MAX = 254
5
5
string /*shared*/ kseFILE[kseFILE_MAX];                                                          //contains file content
89
89
        kseFILE[iFileHandler] = kseToken[iMethod].sToken;
90
90
        
91
91
        //use proper slash before checking files
92
 
        sFilePath = Replace(sFilePath, "\", kseSLASH);
 
92
        sFilePath = Replace(sFilePath, "\\", kseSLASH);
93
93
        
94
94
        //im looking for colon because of //C:\//
95
95
        if (InStr(1, sFilePath, kseCOLON) > 0) {
96
96
                //make sure to correct relative path
97
97
                sFilePath = sKonsolPath + kseSLASH + sFilePath;
98
98
        }
99
 
        
100
 
        if (kseToken[iMethod].sToken == kseREAD) {
101
 
                if (Open(sFilePath For Input #iFileHandler) != 0) {
102
 
                        goto ptrErr;
103
 
                }
104
 
        } else if (kseToken[iMethod].sToken = kseWRITE) {
105
 
                Open sFilePath For Output #iFileHandler
106
 
        } else if (kseToken[iMethod].sToken = kseAPPEND) {
107
 
                Open sFilePath For Append #iFileHandler
108
 
        } else if (kseToken[iMethod].sToken = kseRANDOM) {
109
 
                //# idea is to, only OPEN the file when it needs to write
110
 
                kseFILE[iFileHandler) = kseToken[iMethod].sToken + kseFILEDIV + sFilePath + kseFILEDIV + iLen;
111
 
                //Open sFilePath For Random #iFileHandler Len = iLen
112
 
        } else {
113
 
                Engine_Message(KSE_GetErrFileSrc(iMethod) + "(  " + KSE_GetToken(iMethod) + "  ) is not an Access Method; Expecting (  READ/WRITE/APPEND/WREAD  ].", "SYNTAX ERROR AT LINE " + kseToken[iMethod].iLine);
114
 
                Engine_Exit();
115
 
        }
 
99
// [QuixiePP] to be implemented later
 
100
//      if (kseToken[iMethod].sToken == kseREAD) {
 
101
//              if (Open(sFilePath For Input #iFileHandler) != 0) {
 
102
//                      goto ptrErr;
 
103
//              }
 
104
//      } else if (kseToken[iMethod].sToken = kseWRITE) {
 
105
//              Open sFilePath For Output #iFileHandler
 
106
//      } else if (kseToken[iMethod].sToken = kseAPPEND) {
 
107
//              Open sFilePath For Append #iFileHandler
 
108
//      } else if (kseToken[iMethod].sToken = kseRANDOM) {
 
109
//              //# idea is to, only OPEN the file when it needs to write
 
110
//              kseFILE[iFileHandler) = kseToken[iMethod].sToken + kseFILEDIV + sFilePath + kseFILEDIV + iLen;
 
111
//              //Open sFilePath For Random #iFileHandler Len = iLen
 
112
//      } else {
 
113
//              Engine_Message(KSE_GetErrFileSrc(iMethod) + "(  " + KSE_GetToken(iMethod) + "  ) is not an Access Method; Expecting (  READ/WRITE/APPEND/WREAD  ].", "SYNTAX ERROR AT LINE " + kseToken[iMethod].iLine);
 
114
//              Engine_Exit();
 
115
//      }
116
116
        return iIndex;
117
117
ptrErr:
118
118
        if (Err == 1) {
150
150
        }
151
151
        
152
152
        SetNumValue(iHandler, 0, , UNLOCK_IT);
153
 
        
154
 
        Close #iFileHandler
 
153
// [QuixiePP] to be implemented later
 
154
//      Close #iFileHandler
155
155
        
156
156
        kseFILE[iFileHandler) = "";
157
157
        
204
204
                        }
205
205
                }
206
206
                if (FileExists(sSrc)) {
207
 
                        FileCopy(sSrc, sDest)'
 
207
                        std::filesystem::copy(sSrc, sDest);
208
208
                }
209
209
                return iIndex;
210
210
        }
211
211
#endif
212
212
 
 
213
//by harryngh
 
214
bool FileExists(string fileName) {
 
215
    std::ifstream infile(fileName);
 
216
    return infile.good();
 
217
}
 
218
 
213
219
private int FileWrite(long &iIndex) {
214
220
        string sWrite;
215
221
        int iHandler;
239
245
                iIndex = LookFor(kseCLOSE_PAREN, "File Handler", iIndex); //look for       )
240
246
        }
241
247
        //EXECUTE SCRIPT =============================================================
242
 
        if (Left(kseFILE[iFileHandler), Len(kseRANDOM)) == kseRANDOM) {
243
 
                vector<string> sFileInfo;
244
 
                int iExcess;
245
 
                string sContent;
246
 
                string sPrevText;
247
 
                int iLen;
248
 
                
249
 
                Split(kseFILE[iFileHandler), kseFILEDIV, sFileInfo);
250
 
                iLen = CInt(sFileInfo[2]);
251
 
                
252
 
                //get data
253
 
                if (Dir(sFileInfo[1]) != "") {
254
 
                        Open sFileInfo[1] For Input #iFileHandler
255
 
                                iExcess = LOF(iFileHandler) % iLen;
256
 
                                if (LOF(iFileHandler) >= iExcess) {
257
 
                                        sContent = Input(LOF(iFileHandler) - iExcess, iFileHandler);
258
 
                                }
259
 
                        Close #iFileHandler
260
 
                }
261
 
                //process data
262
 
                if (Len(sWrite) >= iLen) {
263
 
                        sWrite = Left(sWrite, iLen);
264
 
                } else {
265
 
                        sWrite = sWrite + String(CLng(iLen - Int(Len(sWrite))), " ");
266
 
                }
267
 
                if (iPtr != 0) {
268
 
                        sPrevText = Mid(sContent, (iLen * (iPtr - 1)) + 1, iLen);
269
 
                        sContent = Replace(sContent, sPrevText, sWrite);
270
 
                } else {
271
 
                        sContent += sWrite;
272
 
                }
273
 
                //save data
274
 
                open sFileInfo[1] For Output #iFileHandler
275
 
                        Print #iFileHandler, sContent
276
 
                close #iFileHandler
277
 
        } else {
278
 
                Print #iFileHandler, sWrite
279
 
        }
 
248
// [QuixiePP] to be implemented later
 
249
//      if (Left(kseFILE[iFileHandler), Len(kseRANDOM)) == kseRANDOM) {
 
250
//              vector<string> sFileInfo;
 
251
//              int iExcess;
 
252
//              string sContent;
 
253
//              string sPrevText;
 
254
//              int iLen;
 
255
//              
 
256
//              Split(kseFILE[iFileHandler), kseFILEDIV, sFileInfo);
 
257
//              iLen = CInt(sFileInfo[2]);
 
258
//              
 
259
//              //get data
 
260
//              if (Dir(sFileInfo[1]) != "") {
 
261
//                      std::ifstream ifsFileWrite;
 
262
//                      ifsFileWrite.open(sFileInfo[1], ios::in | ios::binary);
 
263
//                              iExcess = LOF(iFileHandler) % iLen;
 
264
//                              if (LOF(iFileHandler) >= iExcess) {
 
265
//                                      sContent = Input(LOF(iFileHandler) - iExcess, iFileHandler);
 
266
//                              }
 
267
//                      ifsFileWrite.cloese();
 
268
//              }
 
269
//              //process data
 
270
//              if (Len(sWrite) >= iLen) {
 
271
//                      sWrite = Left(sWrite, iLen);
 
272
//              } else {
 
273
//                      sWrite = sWrite + String(CLng(iLen - Int(Len(sWrite))), " ");
 
274
//              }
 
275
//              if (iPtr != 0) {
 
276
//                      sPrevText = Mid(sContent, (iLen * (iPtr - 1)) + 1, iLen);
 
277
//                      sContent = Replace(sContent, sPrevText, sWrite);
 
278
//              } else {
 
279
//                      sContent += sWrite;
 
280
//              }
 
281
//              //save data
 
282
//              open sFileInfo[1] For Output #iFileHandler
 
283
//                      Print #iFileHandler, sContent
 
284
//              close #iFileHandler
 
285
//      } else {
 
286
//              Print #iFileHandler, sWrite
 
287
//      }
280
288
        
281
289
        return iIndex;
282
290
ptrErr:
318
326
                iIndex = LookFor(kseCLOSE_PAREN, "File Handler", iIndex); //look for       )
319
327
        }
320
328
        //EXECUTE SCRIPT =============================================================
321
 
        if (Left(kseFILE[iFileHandler), Len(kseRANDOM)) == kseRANDOM) {
322
 
                vector<string> sFileInfo;
323
 
                int iExcess;
324
 
                string sContent;
325
 
                int iLen;
326
 
                
327
 
                Split(kseFILE[iFileHandler], kseFILEDIV, sFileInfo);
328
 
                iLen = CInt(sFileInfo[2]);
329
 
                
330
 
                //get data
331
 
                if (Dir(sFileInfo[1]) != "") {
332
 
                        if (Open(sFileInfo[1] For Input #iFileHandler) != 0) {
333
 
                                goto ptrErr:
334
 
                        }
335
 
                                iExcess = LOF(iFileHandler) % iLen
336
 
                                if (LOF(iFileHandler) >= iExcess) {
337
 
                                        sContent = Input(LOF(iFileHandler) - iExcess, iFileHandler)
338
 
                                }
339
 
                        close #iFileHandler
340
 
                }
341
 
                //process data
342
 
                if (iPtr == 0) {
343
 
                        Engine_Message(KSE_GetErrFileSrc(iIndex - 2) + "Pointer parameter cannot have a value of (  0  ].", "SYNTAX ERROR AT LINE " + kseToken[iIndex - 2].iLine);
344
 
                        Engine_Exit();
345
 
                } else {
346
 
                        sRead = Mid(sContent, (iLen * (iPtr - 1)) + 1, iLen);
347
 
                }
348
 
        } else {
349
 
                Input #iFileHandler, sRead
350
 
        }
351
 
        
352
 
        if (IsTokenStr(iValHandler)) {
353
 
                SetStrValue(iValHandler, sRead);
354
 
        } else if (IsTokenNum(iValHandler)) {
355
 
                SetNumValue(iValHandler, CDbl(sRead));
356
 
        } else if (IsTokenBool(iValHandler)) {
357
 
                SetBoolValue(iValHandler, CByte(sRead));
358
 
        } else {
359
 
                VarNotDeclared(KSE_GetToken(iIndex), "Variable", iIndex);
360
 
        }
 
329
// [QuixiePP] to be implemented later
 
330
//      if (Left(kseFILE[iFileHandler), Len(kseRANDOM)) == kseRANDOM) {
 
331
//              vector<string> sFileInfo;
 
332
//              int iExcess;
 
333
//              string sContent;
 
334
//              int iLen;
 
335
//              
 
336
//              Split(kseFILE[iFileHandler], kseFILEDIV, sFileInfo);
 
337
//              iLen = CInt(sFileInfo[2]);
 
338
//              
 
339
//              //get data
 
340
//              if (Dir(sFileInfo[1]) != "") {
 
341
//                      if (Open(sFileInfo[1] For Input #iFileHandler) != 0) {
 
342
//                              goto ptrErr:
 
343
//                      }
 
344
//                              iExcess = LOF(iFileHandler) % iLen
 
345
//                              if (LOF(iFileHandler) >= iExcess) {
 
346
//                                      sContent = Input(LOF(iFileHandler) - iExcess, iFileHandler)
 
347
//                              }
 
348
//                      close #iFileHandler
 
349
//              }
 
350
//              //process data
 
351
//              if (iPtr == 0) {
 
352
//                      Engine_Message(KSE_GetErrFileSrc(iIndex - 2) + "Pointer parameter cannot have a value of (  0  ].", "SYNTAX ERROR AT LINE " + kseToken[iIndex - 2].iLine);
 
353
//                      Engine_Exit();
 
354
//              } else {
 
355
//                      sRead = Mid(sContent, (iLen * (iPtr - 1)) + 1, iLen);
 
356
//              }
 
357
//      } else {
 
358
//              Input #iFileHandler, sRead
 
359
//      }
 
360
//      
 
361
//      if (IsTokenStr(iValHandler)) {
 
362
//              SetStrValue(iValHandler, sRead);
 
363
//      } else if (IsTokenNum(iValHandler)) {
 
364
//              SetNumValue(iValHandler, CDbl(sRead));
 
365
//      } else if (IsTokenBool(iValHandler)) {
 
366
//              SetBoolValue(iValHandler, CByte(sRead));
 
367
//      } else {
 
368
//              VarNotDeclared(KSE_GetToken(iIndex), "Variable", iIndex);
 
369
//      }
361
370
        
362
371
        return iIndex;
363
372
ptrErr:
390
399
        //EXECUTE SCRIPT =============================================================
391
400
        !!!On Error GoTo ptrErr
392
401
        
393
 
        if (Left(sDest, 1) = "\") { sDest = Mid(sDest, 2); }
 
402
        if (Left(sDest, 1) = "\\") { sDest = Mid(sDest, 2); }
394
403
        
395
404
        if (InStr(1, sSource, "*") > 0) {
396
405
                Engine_Log("Warning: Copy one file at a time.");