Skip to content

Commit 2e8d853

Browse files
author
Peter Aronsson
committed
-Added System.removeFile() that uses remove() from stdio.h
git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/MathCoreOSMC@3998 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent acb4f6a commit 2e8d853

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

Compiler/System.mo

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,18 @@ end groupDelimiter;
383383

384384
public function regularFileExists
385385
input String inString;
386-
output Integer outInteger;
386+
output Integer outInteger "returns 0 if file exists";
387387

388388
external "C" ;
389389
end regularFileExists;
390390

391+
public function removeFile "Removes a file, returns 0 if suceeds, implemented using remove() in stdio.h"
392+
input String fileName;
393+
output Integer res;
394+
395+
external "C";
396+
end removeFile;
397+
391398
public function getPackageFileNames
392399
input String inString1;
393400
input String inString2;

Compiler/runtime/systemimpl.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,15 +1514,15 @@ RML_BEGIN_LABEL(System__getPackageFileNames)
15141514
void *res;
15151515
WIN32_FIND_DATA FileData;
15161516
HANDLE sh;
1517-
1518-
sprintf(strSearch,"%s\\*\0",dir);
1517+
1518+
sprintf(strSearch,"%s\\*\0",dir);
15191519
sh = FindFirstFile(strSearch, &FileData);
1520-
1520+
15211521
if (sh == INVALID_HANDLE_VALUE) {
15221522
printf(" invalid\n");
15231523
}
15241524
else {
1525-
if ((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
1525+
if ((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
15261526
sprintf(tmpSearchString,"%s\\%s\\%s",dir,FileData.cFileName,fileName);
15271527
if(fileExistsLocal(tmpSearchString)==0){
15281528
if(strlen(FileData.cFileName)+current>mallocSize){
@@ -1625,6 +1625,19 @@ RML_BEGIN_LABEL(System__regularFileExists)
16251625
}
16261626
RML_END_LABEL
16271627

1628+
RML_BEGIN_LABEL(System__removeFile)
1629+
{
1630+
char* str = RML_STRINGDATA(rmlA0);
1631+
int ret_val;
1632+
ret_val = remove(str);
1633+
1634+
rmlA0 = (void*) mk_icon(ret_val);
1635+
1636+
RML_TAILCALLK(rmlSC);
1637+
}
1638+
RML_END_LABEL
1639+
1640+
16281641
#ifdef WIN32
16291642
RML_BEGIN_LABEL(System__platform)
16301643
{
@@ -3240,7 +3253,7 @@ RML_BEGIN_LABEL(System__getVariableNames)
32403253
}
32413254
RML_END_LABEL
32423255

3243-
#if 0
3256+
#if 0
32443257
void* read_one_value_from_file(FILE* file, type_description* desc)
32453258
{
32463259
void *res=NULL;
@@ -3611,6 +3624,19 @@ RML_BEGIN_LABEL(System__regularFileExists)
36113624
}
36123625
RML_END_LABEL
36133626

3627+
RML_BEGIN_LABEL(System__removeFile)
3628+
{
3629+
char* str = RML_STRINGDATA(rmlA0);
3630+
int ret_val;
3631+
ret_val = remove(str);
3632+
3633+
rmlA0 = (void*) mk_icon(ret_val);
3634+
3635+
RML_TAILCALLK(rmlSC);
3636+
}
3637+
RML_END_LABEL
3638+
3639+
36143640
#ifdef WIN32
36153641
RML_BEGIN_LABEL(System__platform)
36163642
{

0 commit comments

Comments
 (0)