Skip to content

Commit

Permalink
Use the impact package listing in getAvailableLibraries
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23700 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Dec 8, 2014
1 parent 337c485 commit 7b223d6
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Compiler/Script/CevalScript.mo
Expand Up @@ -917,7 +917,7 @@ algorithm
Option<list<tuple<Integer, Integer, BackendDAE.Equation>>> jac;
Values.Value ret_val,simValue,value,v,cvar,cvar2,v1,v2,v3;
Absyn.ComponentRef cr,cr_1;
Integer size,resI,i,i1,i2,i3,n,curveStyle,numberOfIntervals;
Integer size,resI,i,i1,i2,i3,n,curveStyle,numberOfIntervals, status;
Option<Integer> fmiContext, fmiInstance, fmiModelVariablesInstance; /* void* implementation: DO NOT UNBOX THE POINTER AS THAT MIGHT CHANGE IT. Just treat this as an opaque type. */
Integer fmiLogLevel;
list<Integer> is;
Expand Down Expand Up @@ -2625,6 +2625,10 @@ algorithm
files = List.flatten(List.map(mps, System.moFiles));
dirs = List.flatten(List.map(mps, System.subDirectories));
files = List.map(List.map1(listAppend(files,dirs), System.strtok, ". "), List.first);
(str, status) = System.popen("impact search '' | perl -pe 's/\\e\\[?.*?[\\@-~]//g' | grep '[^ :]*:' | cut -d: -f1 2>&1");
if 0==status then
files = listAppend(files, System.strtok(str,"\n"));
end if;
files = List.sort(files,Util.strcmpBool);
files = List.sortedUnique(files, stringEqual);
v = ValuesUtil.makeArray(List.map(files, ValuesUtil.makeString));
Expand Down
7 changes: 7 additions & 0 deletions Compiler/Util/System.mo
Expand Up @@ -309,6 +309,13 @@ public function systemCall
external "C" outInteger=SystemImpl__systemCall(command,outFile) annotation(Library = "omcruntime");
end systemCall;

public function popen "Run the command and return the stdout as a string"
input String command;
output String contents;
output Integer status;
external "C" contents=System_popen(OpenModelica.threadData(), command, status) annotation(Library = "omcruntime");
end popen;

public function systemCallParallel
input list<String> inStrings;
input Integer numThreads;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/runtime/Makefile.common
Expand Up @@ -42,9 +42,9 @@ omc_communication_impl.o: omc_communication.h
Corba_omc.o: omc_communication.h corbaimpl.cpp
Dynload_omc.o: systemimpl.h errorext.h ../OpenModelicaBootstrappingHeader.h $(SimRuntimeCDir)/read_write.h $(SimRuntimeCDir)/memory_pool.h Dynload.cpp $(RML_COMPAT)
Database_omc.o: Database.c Database_omc.c
Print_omc.o : printimpl.c
Print_omc.o : printimpl.c printimpl.h
Error_omc.o : errorext.cpp ErrorMessage.hpp ../OpenModelicaBootstrappingHeader.h
System_omc.o : System_omc.c systemimpl.c config.h errorext.h $(configUnix) $(RML_COMPAT)
System_omc.o : System_omc.c systemimpl.c config.h errorext.h printimpl.h $(configUnix) $(RML_COMPAT)
Lapack_omc.o : lapackimpl.c config.h $(configUnix) $(RML_COMPAT)
IOStreamExt_omc.o : IOStreamExt.c
Settings_omc.o : settingsimpl.c config.h $(configUnix)
Expand Down
1 change: 1 addition & 0 deletions Compiler/runtime/Print_omc.c
Expand Up @@ -30,6 +30,7 @@

#include <stdio.h>
#include <stdlib.h>
#include "printimpl.h"
#include "meta_modelica.h"

#include "printimpl.c"
Expand Down
46 changes: 46 additions & 0 deletions Compiler/runtime/printimpl.h
@@ -0,0 +1,46 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THIS OSMC PUBLIC
* LICENSE (OSMC-PL). ANY USE, REPRODUCTION OR DISTRIBUTION OF
* THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THE OSMC
* PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/

#include "meta_modelica.h"

extern int Print_saveAndClearBuf(threadData_t *threadData);
extern void Print_restoreBuf(threadData_t *threadData, int handle);
extern void Print_printErrorBuf(threadData_t *threadData, const char* str);
extern void Print_printBuf(threadData_t *threadData, const char* str);
extern int Print_hasBufNewLineAtEnd(threadData_t *threadData);
extern int Print_getBufLength(threadData_t *threadData);
extern const char* Print_getString(threadData_t *threadData);
extern const char* Print_getErrorString(threadData_t *threadData);
extern void Print_clearErrorBuf(threadData_t *threadData);
extern void Print_clearBuf(threadData_t *threadData);
extern void Print_printBufSpace(threadData_t *threadData,int numSpace);
extern void Print_printBufNewLine(threadData_t *threadData);
extern void Print_writeBuf(threadData_t *threadData,const char* filename);
extern void Print_writeBufConvertLines(threadData_t *threadData,const char* filename);
41 changes: 41 additions & 0 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -59,6 +59,7 @@ extern "C" {
#include "config.h"
#include "errorext.h"
#include "settingsimpl.h"
#include "printimpl.h"
#include "f2c.h"

#if defined(_MSC_VER) /* no iconv for VS! */
Expand Down Expand Up @@ -613,6 +614,46 @@ int SystemImpl__systemCall(const char* str, const char* outFile)
return ret_val;
}

char* System_popen(threadData_t *threadData, const char* command, int *status)
{
int ret_val = -1;
const int debug = 0;
if (debug) {
fprintf(stderr, "System.popen: %s\n", command); fflush(NULL);
}

#if defined(__MINGW32__) || defined(_MSC_VER)
*status = 1;
return "Windows does not have popen";
#else
FILE *pipe = popen(command, "r");
if (pipe == NULL) {
*status = 1;
return "popen returned NULL";
}
long handle = Print_saveAndClearBuf(threadData);
char buf[4096];
while (fgets(buf, 4096, pipe) != NULL){
Print_printBuf(threadData, buf);
}

if (debug) {
fprintf(stderr, "System.pipe: returned\n"); fflush(NULL);
}

ret_val = pclose(pipe);
char *res = GC_strdup(Print_getString(threadData));
Print_restoreBuf(threadData, handle);
return res;

if (debug) {
fprintf(stderr, "System.systemCall: returned value: %d\n", ret_val); fflush(NULL);
}

return ret_val;
#endif
}

#ifdef WITH_HWLOC
#include <hwloc.h>
#endif
Expand Down

0 comments on commit 7b223d6

Please sign in to comment.