1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
|
/* Copyright INRIA/ENPC */
#include <stdio.h>
#include "../dld/dld.h"
#if defined(__STDC__)
extern void getpro_(char *,long int);
extern char * dld_strerror(int code);
#else
extern void getpro_();
extern char * dld_strerror();
#endif
/*************************************
* New version : link entry names
* from new shared lib created with
* files.
*************************************/
static int lastlink={0};
void SciLink(iflag,rhs,ilib,files,en_names,strf)
int iflag,*ilib,*rhs;
char *files[],*en_names[],*strf;
{
char enamebuf[MAXNAME];
int i,ii,err=0;
if ( iflag != 0 )
{
*ilib=-3; /* aout link : First argument can't be a number */
return;
}
if ( *rhs <=1 )
{
*ilib=-6; /* aout link, expecting more than one argument */
return;
}
if ( *rhs >= 2 && en_names[1] != (char *) 0 )
{
*ilib=-4;/* aout link : en_names must be of size 1 */
return;
}
/**
if ( files[1] != (char *) 0 )
{
*ilib=-5; / *aout link : files must be of size 1 * /
return;
}
**/
if ( NEpoints != 0 && strcmp(en_names[0],EP[NEpoints-1].name) == 0)
{
ii= NEpoints-1;
}
else
{
ii= NEpoints;
NEpoints++;
if ( NEpoints == ENTRYMAX )
{
*ilib=-2; /* You can't link more functions maxentry reached n*/
}
}
if ( strf[0] == 'f' )
Underscores(1,en_names[0],enamebuf);
else
Underscores(0,en_names[0],enamebuf);
if ( files[1] != (char *) 0 )
C2F(dynload1)(&ii,enamebuf,files,&err);
else
C2F(dynload)(&ii,enamebuf,files[0],&err);
if ( err == 0 )
{
strncpy(EP[ii].name,en_names[0],MAXNAME);
EP[ii].Nshared = ii;
hd[ii].ok = OK;
Nshared = NEpoints;
*ilib= ii;
}
else
{
if ( NEpoints != 0) NEpoints--;
*ilib=-2;
}
}
/**************************************
* return 1 if link accepts multiple file iin one call
* or 0 elsewhere
*************************************/
int LinkStatus()
{
return(0);
}
/**************************************
* Unlink a shared lib
*************************************/
void C2F(isciulink)(i)
integer *i;
{
sciprint("aout link : No unlink up to now \r\n");
}
#define DLDLINK
int dyninit_()
{
static int err=0;
static int initialised=0;
/* required initialization. */
if (!initialised)
{
char prog[200];
getpro_(prog,sizeof(prog)-1);
/*sciprint("Link Initialisation");*/
err = dld_init (dld_find_executable(prog));
/*sciprint(" %s\n",dld_find_executable(prog));*/
if(!err)
initialised=1;
else {
sciprint("dld_init error %s\n",dld_strerror(err));
}
};
return err;
}
/* print out all the undefined symbols */
void list_undefined ()
{
char **list = dld_list_undefined_sym ();
if (list)
{
register int i;
sciprint("There are a total of %d undefined symbols:\n",
dld_undefined_sym_count);
for (i = 0; i < dld_undefined_sym_count; i++)
sciprint("%d: %s\n", i+1, list[i]);
}
else
sciprint("No undefined symbols\n");
}
#define MAXCHAR 256
#if defined(__STDC__)
int C2F(dynload)(int *ii,char ename1[],char loaded_files[],int *err)
#else
int dynload_(ii,ename1,loaded_files,err)
int *ii;char ename1[],loaded_files[];int *err;
#endif
{
function func;
char current_object_file[MAXCHAR];
int i,j;
char current_char;
#ifdef DEBUG
sciprint("ename1 [%s]\r\n",ename1);
sciprint("lastlink %d, entry=%d\n",lastlink,*ii);
#endif
sciprint("linking \"%s\" defined in \"%s\"\n", ename1,loaded_files);
*err = 0;
if ( (*err = dyninit_())) return; /* Error on init */
/* on scane et on charge the objects files */
/* unloading if necessary */
i = 0;j=0;
while (1){
current_char = loaded_files[i];
if((current_char == ' ') || (current_char == '\0') || (i == strlen(loaded_files)))
{
current_object_file[j] = '\0';
if(strlen(current_object_file)>0){
/** if this file was previously linked i must unlink it **/
if ( *ii <= lastlink && lastlink != 0 )
{
dld_unlink_by_file (current_object_file,1);
#ifdef DEBUG
sciprint("unloading : \"%s\"\r\n",current_object_file);
#endif
};
};
j = -1;
if(loaded_files[i] == '\0') break;
}
else
{
current_object_file[j] = loaded_files[i];
}
i++;j++;
if ( j > MAXCHAR )
{
*err=1 ;
sciprint("filename too long");
};
};
/* loading */
i = 0;j=0;
while (1){
current_char = loaded_files[i];
if((current_char == ' ') || (current_char == '\0') || (i == strlen(loaded_files)))
{
current_object_file[j] = '\0';
if(strlen(current_object_file)>0){
#ifdef DEBUG
sciprint("loading : \"%s\"\r\n",current_object_file);
#endif
*err = dld_link (current_object_file);
if(*err){
sciprint("problem when loading : \"%s\"\n",current_object_file);
sciprint("dld_link error %s \n",dld_strerror (*err));
*err=99;
return;
};
};
j = -1;
if(loaded_files[i] == '\0') break;
}
else
{
current_object_file[j] = loaded_files[i];
}
i++;j++;
if ( j > MAXCHAR )
{
*err=1 ;
sciprint("filename too long");
};
};
/* grap the entry point for function "ename" */
if (dld_function_executable_p (ename1))
{
func = (function) dld_get_func (ename1);
if ( func == (function) 0)
{
sciprint("error when finding \"%s\" in \"%s\"\n",ename1,loaded_files);
sciprint("dld_get_func error %s\n",dld_strerror (*err));
*err=1;
return;
};
#ifdef DEBUG
sciprint("procedure numero %d \"%s\" located in \"%s\"\r\n",*ii,ename1,loaded_files);
#endif
EP[*ii].epoint = func;
lastlink=lastlink+1;
}
else
{
sciprint("error [%s] not executable \n",ename1);
list_undefined ();
*err=1;
};
};
#if defined(__STDC__)
int C2F(dynload1)(int *ii,char ename1[],char *loaded_files[],int *err)
#else
int dynload_(ii,ename1,loaded_files,err)
int *ii;char ename1[], *loaded_files[];int *err;
#endif
{
function func;
int i,j;
#ifdef DEBUG
sciprint("ename1 [%s]\r\n",ename1);
sciprint("lastlink %d, entry=%d\n",lastlink,*ii);
#endif
sciprint("linking \"%s\" defined in ",ename1);
i=0;
while ( loaded_files[i] != NULL)
{
sciprint("\"%s\" ", loaded_files[i]); i++;
}
sciprint("\r\n");
*err = 0;
if ( (*err = dyninit_())) return; /* Error on init */
/* scaning and loading objects files */
/* unloading if necessary */
i = 0;
while (loaded_files[i] != NULL )
{
if(strlen(loaded_files[i])>0)
{
/** if this file was previously linked i must unlink it **/
if ( *ii <= lastlink && lastlink != 0 )
{
dld_unlink_by_file (loaded_files[i],1);
#ifdef DEBUG
sciprint("unloading : \"%s\"\r\n",loaded_files[i]);
#endif
}
}
i++;
}
/* loading */
i = 0;
while (loaded_files[i] != NULL)
{
if(strlen(loaded_files[i])>0){
#ifdef DEBUG
sciprint("loading : \"%s\"\r\n",loaded_files[i]);
#endif
*err = dld_link (loaded_files[i]);
if(*err){
sciprint("problem when loading : \"%s\"\n",loaded_files[i]);
sciprint("dld_link error %s \n",dld_strerror (*err));
*err=99;
return;
}
}
i++;
}
/* grap the entry point for function "ename" */
if (dld_function_executable_p (ename1))
{
func = (function) dld_get_func (ename1);
if ( func == (function) 0)
{
sciprint("error when finding \"%s\" in \"%s\",... \n",ename1,loaded_files[0]);
sciprint("dld_get_func error %s\n",dld_strerror (*err));
*err=1;
return;
};
#ifdef DEBUG
sciprint("procedure numero %d \"%s\" located in \"%s\" .... \r\n",*ii,ename1,loaded_files[0]);
#endif
EP[*ii].epoint = func;
lastlink=lastlink+1;
}
else
{
sciprint("error [%s] not executable \n",ename1);
list_undefined ();
*err=1;
};
};
|