Skip to content

Commit

Permalink
added trim to System.rml
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1866 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x02lucpo committed Jul 29, 2005
1 parent 1ff50f6 commit fd95e79
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 8 deletions.
9 changes: 7 additions & 2 deletions Compiler/Ceval.rml
Expand Up @@ -1124,11 +1124,16 @@ end
*)
System.path_delimiter => pd &
System.read_env("OPENMODELICAHOME") => omhome &
Util.string_append_list([omhome, pd, "Compiler", pd, "scripts", pd, "Compile ", makefilename," > output.log 2>&1"]) => s_call &
Util.string_append_list(["\"",omhome, pd, "Compiler",
pd, "scripts", pd, "Compile ",
makefilename," > output.log 2>&1",
"\""]) => s_call &
(*> output.log 2>&1 = redirect stderr to stdout and put it in output.log *)

System.system_call(s_call) => 0 &
Util.string_append_list([".", pd, cname_str, " -m ",method_str," >> output.log 2>&1"]) => sim_call &
Util.string_append_list(["\"",".", pd, cname_str, " -m ",
method_str," >> output.log 2>&1",
"\""]) => sim_call &
System.system_call(sim_call) => _ &
Util.string_append_list([cname_str,"_res.plt"]) => result_file &
let simValue = Values.RECORD(Absyn.IDENT("SimulationResult"),[Values.STRING(result_file)],["resultFile"]) &
Expand Down
10 changes: 6 additions & 4 deletions Compiler/ClassLoader.rml
Expand Up @@ -215,16 +215,18 @@ end
**)
relation load_class_from_mp: (Absyn.Ident, string) => Absyn.Program =

rule System.path_delimiter => pd &
rule System.trim(mp'," \"\t") => mp &
System.path_delimiter => pd &
string_append(class,".mo") => classfile &
Util.string_append_list([mp,pd,classfile])=> classfile' &
exist_regular_file(classfile') &
print "parsing " & print classfile' & print "\n" &
Parser.parse(classfile') => p
---------------------------
load_class_from_mp(class,mp) => p
load_class_from_mp(class,mp') => p

rule System.path_delimiter => pd &
rule System.trim(mp'," \"\t") => mp &
System.path_delimiter => pd &
Util.string_append_list([mp,pd,class]) => dirfile &
Util.string_append_list([dirfile, pd, "package.mo"]) => packfile &
exist_directory_file dirfile &
Expand All @@ -233,7 +235,7 @@ relation load_class_from_mp: (Absyn.Ident, string) => Absyn.Program =
load_complete_package_from_mp(class,mp,Absyn.TOP,
Absyn.PROGRAM([],Absyn.TOP)) => p
--------------------------------------
load_class_from_mp(class,mp) => p
load_class_from_mp(class,mp') => p

rule print "load_class_from_mp failed\n"
--------------------
Expand Down
2 changes: 2 additions & 0 deletions Compiler/System.rml
Expand Up @@ -123,6 +123,8 @@ with "Values.rml"

relation remove_first_and_last_char: (string) => string

relation trim: (string,string) => string

relation strcmp: (string,string) => int

relation toupper: (string) => string
Expand Down
2 changes: 2 additions & 0 deletions Compiler/Util.rml
Expand Up @@ -1267,6 +1267,8 @@ relation string_replace_char2 : (char list, char, char) => char list =

end




(** relation string_split_at_char
** Takes a string and a char and split the string at the char
Expand Down
55 changes: 55 additions & 0 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -44,6 +44,7 @@ void reallocdirents(struct dirent ***entries,
*entries = newentries;
}


/*
* compar function is ignored
*/
Expand Down Expand Up @@ -186,6 +187,60 @@ RML_BEGIN_LABEL(System__remove_5ffirst_5fand_5flast_5fchar)
}
RML_END_LABEL

int str_contain_char( const char* chars, const char chr)
{
int length_of_chars = strlen(chars);
int i;
for(i = 0; i < length_of_chars; i++)
{
if(chr == chars[i])
return 1;
}
return 0;
}


/* this removes chars in second from the beginning and end of the first
string and returns it */
RML_BEGIN_LABEL(System__trim)
{
char *str = RML_STRINGDATA(rmlA0);
char *chars_to_be_removed = RML_STRINGDATA(rmlA1);
int length=strlen(str);
char *res = malloc(length+1);
int i;
int start_pos = 0;
int end_pos = length - 1;
if(length > 1)
{
strncpy(res,str,length);
for(i=0; i < length; i++ )
{

if(str_contain_char(chars_to_be_removed,res[start_pos]))
start_pos++;
if(str_contain_char(chars_to_be_removed,res[end_pos]))
end_pos--;
}


res[length] = '\0';
}
if(start_pos < end_pos)
{
res[end_pos+1] = '\0';
rmlA0 = (void*) mk_scon(&res[start_pos]);
} else {
rmlA0 = (void*) mk_scon("");
}

free(res);


RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__strcmp)
{
char *str = RML_STRINGDATA(rmlA0);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/scripts/Compile.bat
@@ -1,7 +1,7 @@
@echo off
set GCC_EXEC_PREFIX=
set OLDPATH=%PATH%
pushd "%OPENMODELICAHOME%\MinGW\bin"
pushd "%OPENMODELICAHOME%\bin\MinGW\bin"
set PATH=%CD%
popd
mingw32-make -f %1 >nul
Expand Down
2 changes: 1 addition & 1 deletion Compiler/scripts/doPlot.bat
@@ -1,6 +1,6 @@
@echo off
if defined PTII goto runplot
set PTII=%OPENMODELICAHOME%\ptplot.jar
set PTII=%OPENMODELICAHOME%\bin\ptplot.jar
:runplot
start javaw -classpath "%PTII%" ptolemy.plot.plotml.EditablePlotMLApplication %1

56 changes: 56 additions & 0 deletions Compiler/winruntime/systemimpl.c
Expand Up @@ -62,6 +62,7 @@ void set_cflags(char *str)
memcpy(cflags,str,strlen(str)+1);
}


void System_5finit(void)
{
char* path;
Expand Down Expand Up @@ -173,6 +174,61 @@ RML_BEGIN_LABEL(System__remove_5ffirst_5fand_5flast_5fchar)
}
RML_END_LABEL

int str_contain_char( const char* chars, const char chr)
{
int length_of_chars = strlen(chars);
int i;
for(i = 0; i < length_of_chars; i++)
{
if(chr == chars[i])
return 1;
}
return 0;
}


/* this removes chars in second from the beginning and end of the first
string and returns it */
RML_BEGIN_LABEL(System__trim)
{
char *str = RML_STRINGDATA(rmlA0);
char *chars_to_be_removed = RML_STRINGDATA(rmlA1);
int length=strlen(str);
char *res = malloc(length+1);
int i;
int start_pos = 0;
int end_pos = length - 1;
if(length > 1)
{
strncpy(res,str,length);
for(i=0; i < length; i++ )
{

if(str_contain_char(chars_to_be_removed,res[start_pos]))
start_pos++;
if(str_contain_char(chars_to_be_removed,res[end_pos]))
end_pos--;
}


res[length] = '\0';
}
if(start_pos < end_pos)
{
res[end_pos+1] = '\0';
rmlA0 = (void*) mk_scon(&res[start_pos]);
} else {
rmlA0 = (void*) mk_scon("");
}

free(res);


RML_TAILCALLK(rmlSC);
}
RML_END_LABEL


RML_BEGIN_LABEL(System__strcmp)
{
char *str = RML_STRINGDATA(rmlA0);
Expand Down

0 comments on commit fd95e79

Please sign in to comment.