/[ascend]/trunk/base/generic/compiler/importhandler.c
ViewVC logotype

Contents of /trunk/base/generic/compiler/importhandler.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 862 - (show annotations) (download) (as text)
Tue Sep 26 13:47:27 2006 UTC (13 years, 10 months ago) by johnpye
File MIME type: text/x-csrc
File size: 5550 byte(s)
Some work on the IMPORT handler functionality. Mostly just placeholders at this stage.
1 /* ASCEND modelling environment
2 Copyright (C) 2006 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 *//**
19 @file
20 Handle the Import Handler library, which is a hash table of additional
21 handlers for external scripts in the IMPORT statement.
22 *//*
23 by John Pye
24 Created Sept 26, 2006
25 */
26
27 #include <utilities/ascConfig.h>
28 #include <utilities/config.h>
29 #include <utilities/error.h>
30 #include "importhandler.h"
31
32 /*
33 Maximum number of importhandlers possible in one session. Hard to imagine
34 that you would want more than this.
35 */
36 #define IMPORTHANDLER_MAX 10
37
38 /**
39 List of import handlers currently in effect. @TODO this shouldn't be a global,
40 but unfortunately such globals are 'The ASCEND Way'.
41 */
42 struct ImportHandler **importhandler_library=NULL;
43
44 ASC_DLLSPEC(int) importhandler_add(struct ImportHandler *handler){
45 int i;
46 if(handler==NULL){
47 ERROR_REPORTER_HERE(ASC_PROG_ERR,"Handler is NULL");
48 return 2;
49 }
50 if(importhandler_library == NULL){
51 importhandler_createlibrary();
52 }
53 for(i=0; i< IMPORTHANDLER_MAX; ++i){
54 if(importhandler_library[i] == NULL)break;
55 if(importhandler_library[i]->name == handler->name){
56 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Handler already loaded");
57 return 0;
58 }
59 }
60 if(i==IMPORTHANDLER_MAX){
61 ERROR_REPORTER_HERE(ASC_PROG_ERR,"Too many import handlers register (IMPORTHANDLER_MAX=%d)",IMPORTHANDLER_MAX);
62 return 1;
63 }
64 importhandler_library[i] = handler;
65 return 0;
66 }
67
68 /* Function to attempt import of an external script
69 @param partialname Name of the external script (without extension), relative to PATH.
70 @param defaultpath Default value of file search PATH. Is trumped by value of pathenvvar if present in environment.
71 @param pathenvvar Environment variable containing the user's preferred file search path value.
72 @return 0 on success
73 */
74 int importhandler_attemptimport(const char *partialname,const char *defaultpath, const char *pathenvvar){
75 ERROR_REPORTER_HERE(ASC_PROG_ERR,"%s not implemented",__FUNCTION__);
76 return 1;
77 }
78
79 /*------------------------------------------------------------------------------
80 DEFAULT IMPORT HANDLER FOR DLL/SO FILES
81 */
82
83 /**
84 Create a filename for an external library (DLL/SO) based on a
85 partial filename.
86
87 @param partialname The partial filename (eg 'mylib')
88 @return Complete filename (eg 'libmylib.so' or 'mylib.dlll', etc)
89 */
90 char *importhandler_extlib_filename(const char *partialname){
91 char *buffer;
92 buffer = ASC_NEW_ARRAY(char,PATH_MAX);
93
94 #if defined(ASC_SHLIBSUFFIX) && defined(ASC_SHLIBPREFIX)
95 /*
96 this is the preferred operation: SCons reports what the local system
97 uses as its shared library file extension.
98 */
99 snprintf(buffer,PATH_MAX,"%s%s%s",ASC_SHLIBPREFIX,s1,ASC_SHLIBSUFFIX);
100 #else
101 /**
102 @DEPRECATED
103
104 If we don't have ASC_SHLIB-SUFFIX and -PREFIX then we can do some
105 system-specific stuff here, but it's not as general.
106 */
107 # ifdef __WIN32__
108 snprintf(buffer,PATH_MAX,"%s.dll",partialname1);
109 # elif defined(linux)
110 snprintf(buffer,PATH_MAX,"lib%s.so",partialname); /* changed from .o to .so -- JP */
111 # elif defined(sun) || defined(solaris)
112 snprintf(buffer,PATH_MAX,"%s.so.1.0",partialname);
113 # elif defined(__hpux)
114 snprintf(buffer,PATH_MAX,"%s.sl",partialname);
115 # elif defined(_SGI_SOURCE)
116 snprintf(buffer,PATH_MAX,"%s.so",partialname);
117 # else
118 # error "Unknown system type (please define ASC_SHLIBSUFFIX and ASC_SHLIBPREFIX)"
119 # endif
120 #endif
121
122 return buffer;
123 }
124
125 /**
126 Perform the actual importing of an external DLL/SO in to ASCEND. Can assume
127 that the file exists and is readable.
128
129 @param fp Location of DLL/SO file
130 @return 0 on success
131 */
132 int importhandler_extlib_import(struct FilePath *fp,void *user_data){
133 return 1;
134 }
135
136 /*------------------------------------------------------------------------------
137 LIST-BASED FUNCTIONS related to IMPORT handler 'library'
138 */
139
140 int importhandler_createlibrary(){
141 int i;
142 if(importhandler_library!=NULL){
143 ERROR_REPORTER_HERE(ASC_PROG_ERR,"Already created");
144 return 1;
145 };
146 importhandler_library=ASC_NEW_ARRAY(struct ImportHandler *,IMPORTHANDLER_MAX);
147 for(i=0; i < IMPORTHANDLER_MAX; ++i){
148 importhandler_library[i] = NULL;
149 }
150 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"ImportHandler library created");
151 return 0;
152 }
153
154 int importhandler_remove(const char *name){
155 ERROR_REPORTER_HERE(ASC_PROG_ERR,"%s not implemented",__FUNCTION__);
156 return 1;
157 }
158
159 struct ImportHandler *importhandler_lookup(const char *name){
160 ERROR_REPORTER_HERE(ASC_PROG_ERR,"%s not implemented",__FUNCTION__);
161 return NULL;
162 }
163
164 int importhandler_destroylibrary(){
165 ERROR_REPORTER_HERE(ASC_PROG_ERR,"%s not implemented",__FUNCTION__);
166 CONSOLE_DEBUG("NOT IMPLEMENTED");
167 return 1;
168 }
169
170
171 int importhandler_printlibrary(FILE *fp){
172 CONSOLE_DEBUG("NOT IMPLEMENTED");
173 return 1;
174 }
175
176 int importhandler_printhandler(FILE *fp, struct ImportHandler *handler){
177 ERROR_REPORTER_HERE(ASC_PROG_ERR,"%s not implemented",__FUNCTION__);
178 CONSOLE_DEBUG("NOT IMPLEMENTED");
179 return 1;
180 }
181
182

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22