Skip to content

Commit

Permalink
Added more functionality
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@735 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
henjo committed Feb 14, 2002
1 parent 563b2d7 commit 3acd52a
Show file tree
Hide file tree
Showing 10 changed files with 672 additions and 276 deletions.
58 changes: 58 additions & 0 deletions mosh/build/Makefile.single
@@ -0,0 +1,58 @@
# -*- Mode: Makefile -*-
#
# TARGET is specified on the command line
# eg.
# >make -f Makefile.single TARGET=algorithm_for1
#

MODEQ=$(MOSHHOME)/../modeq/modeq
CC=gcc

CRTHOME=$(MOSHHOME)/../c_runtime

CFLAGS= -W -Wall -ansi -pedantic-errors -Werror -g -I$(CRTHOME) -I.

LDFLAGS= -L$(CRTHOME) -lm

CDIR = csrc
ODIR = obj
BDIR = .

MOFILES = $(TARGET:=.mo)
TARGETS = $(MOFILES:%.mo=$(BDIR)/%)
OBJS = $(MOFILES:%.mo=$(ODIR)/%.main.o)
GENC = $(MOFILES:%.mo=$(CDIR)/%.c)


all : $(CDIR) $(ODIR) $(BDIR) $(TARGETS)


$(TARGETS) : $(BDIR)/% : $(ODIR)/%.main.o
rm -f $@
gcc -g -o $@ $(LDFLAGS) $< -lc_runtime

$(OBJS) : $(ODIR)/%.main.o : $(CDIR)/%.c $(MOSHHOME)/build/main.c
rm -f $(TARGETS)
@echo compiling $(subst .main.o,,$@)
$(CC) $(CFLAGS) \
-DCFILE_TO_INCLUDE="\"$(subst $(ODIR),$(CDIR),$(subst .main.o,.c,$@))\""\
-DCFUNCTION_TO_CALL="$(subst $(ODIR)/,,$(subst .main.o,,$@))_read_call_write"\
-c -o $@ $(MOSHHOME)/build/main.c

$(GENC) : $(CDIR)/%.c : %.mo
@$(MODEQ) $< +d=codegen > $@

$(CDIR) $(ODIR) $(BDIR) : % :
mkdir $@

.SUFFIXES: .mo


.mo.c:
if not @$(MODEQ) $< +d=codegen > $(<:.mo=.c); then cat $(<:.mo=.c); fi

clean :
rm -f $(TARGETS)
rm -f $(OBJS)
rm -f $(GENC)

23 changes: 23 additions & 0 deletions mosh/build/main.c
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

#include CFILE_TO_INCLUDE



int main(int argc, char** argv)
{

if (argc != 3)
{
fprintf(stderr,"# Incorrrect number of arguments\n");
return 1;
}


CFUNCTION_TO_CALL(argv[1],argv[2]);

return 0;

}
201 changes: 201 additions & 0 deletions mosh/src/builtin_function.cpp
Expand Up @@ -6,6 +6,8 @@
#include <cstdlib>
#include <fstream>

#include <unistd.h>

#include "function_argument.hpp"

builtin_function::builtin_function()
Expand Down Expand Up @@ -78,6 +80,205 @@ value abs_t::do_apply(value args)
return value(true);
}

cd_t::cd_t()
{
}
cd_t::~cd_t()
{
}
value cd_t::do_apply(value args)
{
value ret;
if (args.is_function_argument())
{
function_argument* fnarg = args.get_function_argument();
if (fnarg)
{
if (fnarg->size() == 1)
{
value val = fnarg->begin()->first;
if (val.is_string())
{
std::string path = val.get_string();
if(chdir(path.c_str()))
{
std::cout << "Unable to change directory to \""
<< path.c_str() << "\"\n";
}
char buf[1024];
char *b2;
b2 = getcwd(buf,1024);
if (b2)
{
ret = std::string(buf);
}
else
{
std::cout << "Unable to get current directory\n";
}
}
else
{
std::cout << "Type mismatch. Expected string\n";
}
}
else
{
std::cout << "Incorrect number of arguments. Expected one string\n";
}
}
else
{
std::cout << "Internal error: NULL function_argument\n";
}
}
else
{
std::cout << "Internal error: not function_argument\n";
}
return ret;
}

system_t::system_t()
{
}
system_t::~system_t()
{
}
value system_t::do_apply(value args)
{
value ret;
if (args.is_function_argument())
{
function_argument* fnarg = args.get_function_argument();
if (fnarg)
{
if (fnarg->size() == 1)
{
value val = fnarg->begin()->first;
if (val.is_string())
{
std::string cmd = val.get_string();
ret = system(cmd.c_str());
}
else
{
std::cout << "Type mismatch. Expected string\n";
}
}
else
{
std::cout << "Incorrect number of arguments. Expected one string\n";
}
}
else
{
std::cout << "Internal error: NULL function_argument\n";
}
}
else
{
std::cout << "Internal error: not function_argument\n";
}
return ret;
}


read_t::read_t()
{
}
read_t::~read_t()
{
}
value read_t::do_apply(value args)
{
value ret;
if (args.is_function_argument())
{
function_argument* fnarg = args.get_function_argument();
if (fnarg)
{
if (fnarg->size() == 1)
{
value val = fnarg->begin()->first;
if (val.is_string())
{
std::string path = val.get_string();

ret = read_result_file(path.c_str());

}
else
{
std::cout << "Type mismatch. Expected string\n";
}
}
else
{
std::cout << "Incorrect number of arguments. Expected one string\n";
}
}
else
{
std::cout << "Internal error: NULL function_argument\n";
}
}
else
{
std::cout << "Internal error: not function_argument\n";
}
return ret;
}

write_t::write_t()
{
}
write_t::~write_t()
{
}
value write_t::do_apply(value args)
{
value ret;
if (args.is_function_argument())
{
function_argument* fnarg = args.get_function_argument();
if (fnarg)
{
if (fnarg->size() == 2)
{
function_argument::parameter_iterator it = fnarg->begin();
value val = it->first;
++it;
value file = it->first;
if (file.is_string())
{
std::string path = file.get_string();

ret = write_input_file(val,path.c_str());

}
else
{
std::cout << "Type mismatch. Expected string for second argument\n";
}
}
else
{
std::cout << "Incorrect number of arguments. Expected one value and one string\n";
}
}
else
{
std::cout << "Internal error: NULL function_argument\n";
}
}
else
{
std::cout << "Internal error: not function_argument\n";
}
return ret;
}

bt_div_t::bt_div_t()
{

Expand Down
36 changes: 36 additions & 0 deletions mosh/src/builtin_function.hpp
Expand Up @@ -110,6 +110,42 @@ class integer_t : public builtin_function
value do_apply(value args);
};

class cd_t : public builtin_function
{
public:
cd_t();
virtual ~cd_t();
protected:
value do_apply(value args);
};

class system_t : public builtin_function
{
public:
system_t();
virtual ~system_t();
protected:
value do_apply(value args);
};

class read_t : public builtin_function
{
public:
read_t();
virtual ~read_t();
protected:
value do_apply(value args);
};

class write_t : public builtin_function
{
public:
write_t();
virtual ~write_t();
protected:
value do_apply(value args);
};

template <class Fn>
class unary_fcn : public builtin_function
{
Expand Down

0 comments on commit 3acd52a

Please sign in to comment.