Skip to content

Commit 69fb8b9

Browse files
committed
- copied options.cpp, options.h from OpenModelica/mosh
to here to get rid of the dependency - small update to read_write.c git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@3661 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent d44e65e commit 69fb8b9

File tree

4 files changed

+126
-7
lines changed

4 files changed

+126
-7
lines changed

c_runtime/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ AR = ar -ru
99
UNAME := $(shell uname -m)
1010
CMDFPUFLAGS := `case ${UNAME} in i[3456]86) echo "-msse2 -mfpmath=sse";; x86_64) echo "-msse2 -mfpmath=sse";; *) echo "";; esac`
1111
FPUFLAGS := ${CMDFPUFLAGS}
12-
CFLAGS = -Wall -O3 ${FPUFLAGS} -fexceptions -ansi -pedantic -I$(top_builddir)/mosh/src/ $(EXTRA_CFLAGS)
12+
CFLAGS = -Wall -O3 ${FPUFLAGS} -fexceptions -ansi -pedantic -I. $(EXTRA_CFLAGS)
1313
CPPFLAGS = $(CFLAGS)
1414
FFLAGS = -O -fexceptions
1515
# P.A: before, g77 had -O3 or -O2 but that caused a bug in DDASRT, giving infinite loop.
@@ -25,7 +25,7 @@ biglag.o ddassl.o dogleg.o fdjac1.o hybrj.o newuoa.o qrfac.o trsapp.o
2525
daux.o dlamch.o dpmpar.o hybrd.o lsame.o newuob.o r1mpyq.o update.o $(EXTRA_OBJS)
2626

2727
SIMOBJS = $(FOBJS) simulation_runtime.o simulation_init.o simulation_input.o simulation_events.o \
28-
solver_dasrt.o solver_euler.o simulation_result.o tables.o ../mosh/src/options.o dgesv_aux.o meta_modelica.o $(EXTRA_SIMOBJS)
28+
solver_dasrt.o solver_euler.o simulation_result.o tables.o options.o dgesv_aux.o meta_modelica.o $(EXTRA_SIMOBJS)
2929

3030
HFILES = blaswrap.h f2c.h integer_array.h memory_pool.h modelica_string.h \
3131
base_array.h inline.h real_array.h string_array.h boolean_array.h \

c_runtime/options.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* This file is part of OpenModelica.
3+
*
4+
* Copyright (c) 1998-2008, Linköpings University,
5+
* Department of Computer and Information Science,
6+
* SE-58183 Linköping, Sweden.
7+
*
8+
* All rights reserved.
9+
*
10+
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THIS OSMC PUBLIC
11+
* LICENSE (OSMC-PL). ANY USE, REPRODUCTION OR DISTRIBUTION OF
12+
* THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THE OSMC
13+
* PUBLIC LICENSE.
14+
*
15+
* The OpenModelica software and the Open Source Modelica
16+
* Consortium (OSMC) Public License (OSMC-PL) are obtained
17+
* from Linköpings University, either from the above address,
18+
* from the URL: http://www.ida.liu.se/projects/OpenModelica
19+
* and in the OpenModelica distribution.
20+
*
21+
* This program is distributed WITHOUT ANY WARRANTY; without
22+
* even the implied warranty of MERCHANTABILITY or FITNESS
23+
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
24+
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
25+
* OF OSMC-PL.
26+
*
27+
* See the full OSMC Public License conditions for more details.
28+
*
29+
*/
30+
31+
#include "options.h"
32+
33+
#include <string>
34+
35+
using namespace std;
36+
37+
bool flagSet(char *option, int argc, char** argv)
38+
{
39+
for (int i=0; i<argc;i++) {
40+
if (("-"+string(option))==string(argv[i])) return true;
41+
}
42+
return false;
43+
}
44+
/* returns the value of a flag on the form -flagname=value
45+
*/
46+
const string* getOption(const char *option, int argc, char **argv)
47+
{
48+
for (int i=0; i<argc;i++) {
49+
string tmpStr=string(argv[i]);
50+
if (("-"+string(option))==(tmpStr.substr(0,tmpStr.find("=")))) {
51+
string str=string(argv[i]);
52+
return new string(str.substr(str.find("=")+1));
53+
}
54+
}
55+
return NULL;
56+
}
57+
/* returns the value of a flag on the form -flagname value */
58+
const string* getFlagValue(const char *option, int argc, char **argv)
59+
{
60+
for (int i=0; i<argc;i++) {
61+
string tmpStr=string(argv[i]);
62+
if (("-"+string(option))==string(argv[i])) {
63+
if (argc >= i+1) {
64+
return new string(argv[i+1]);
65+
}
66+
}
67+
}
68+
return NULL;
69+
}

c_runtime/options.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This file is part of OpenModelica.
3+
*
4+
* Copyright (c) 1998-2008, Linköpings University,
5+
* Department of Computer and Information Science,
6+
* SE-58183 Linköping, Sweden.
7+
*
8+
* All rights reserved.
9+
*
10+
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THIS OSMC PUBLIC
11+
* LICENSE (OSMC-PL). ANY USE, REPRODUCTION OR DISTRIBUTION OF
12+
* THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THE OSMC
13+
* PUBLIC LICENSE.
14+
*
15+
* The OpenModelica software and the Open Source Modelica
16+
* Consortium (OSMC) Public License (OSMC-PL) are obtained
17+
* from Linköpings University, either from the above address,
18+
* from the URL: http://www.ida.liu.se/projects/OpenModelica
19+
* and in the OpenModelica distribution.
20+
*
21+
* This program is distributed WITHOUT ANY WARRANTY; without
22+
* even the implied warranty of MERCHANTABILITY or FITNESS
23+
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
24+
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
25+
* OF OSMC-PL.
26+
*
27+
* See the full OSMC Public License conditions for more details.
28+
*
29+
*/
30+
31+
#ifndef _MYOPTIONS
32+
#define _MYOPTIONS
33+
34+
#include <string>
35+
#include <algorithm>
36+
37+
/* -f */
38+
bool flagSet(char*, int, char**);
39+
40+
/* -f=value */
41+
const std::string * getOption(const char*, int, char **);
42+
43+
/* -f value */
44+
const std::string* getFlagValue(const char *, int , char **);
45+
46+
#endif

c_runtime/read_write.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ void free_type_description(type_description *desc)
107107
case TYPE_DESC_RECORD: {
108108
size_t i;
109109
type_description *e = desc->data.record.element;
110-
char **n = desc->data.record.name;
111-
for (i = 0; i < desc->data.record.elements; ++i, ++e, ++n) {
112-
free(*n);
113-
free_type_description(e);
110+
/* char **n = desc->data.record.name; */
111+
for (i = 0; i < desc->data.record.elements; i++, e++) {
112+
free(desc->data.record.name[i]);
113+
free_type_description(e);
114114
}
115115
if (desc->data.record.elements > 0) {
116116
free(desc->data.record.element);
@@ -516,7 +516,11 @@ type_description *add_modelica_record_member(type_description *desc,
516516
* (desc->data.record.elements + 1));
517517
elem = desc->data.record.element + desc->data.record.elements;
518518
desc->data.record.name[desc->data.record.elements] = malloc(nlen + 1);
519-
memcpy(desc->data.record.name[desc->data.record.elements], name, nlen + 1);
519+
memcpy(desc->data.record.name[desc->data.record.elements], name, nlen + 1);
520+
/*
521+
* strdup is not ansi!
522+
* desc->data.record.name[desc->data.record.elements] = strdup(name);
523+
*/
520524
++desc->data.record.elements;
521525
init_type_description(elem);
522526
return elem;

0 commit comments

Comments
 (0)