Commit 062d6998 authored by Ian Lance Taylor's avatar Ian Lance Taylor

Add support for a -I option. -I DIR searches for packages in

DIR.

R=ken,rsc
DELTA=49  (41 added, 2 deleted, 6 changed)
OCL=26057
CL=26092
parent d27e9f52
...@@ -455,6 +455,13 @@ struct Dlist ...@@ -455,6 +455,13 @@ struct Dlist
Type* field; Type* field;
}; };
typedef struct Idir Idir;
struct Idir
{
Idir* link;
char* dir;
};
EXTERN Dlist dotlist[10]; // size is max depth of embeddeds EXTERN Dlist dotlist[10]; // size is max depth of embeddeds
EXTERN Io curio; EXTERN Io curio;
...@@ -482,6 +489,7 @@ EXTERN int tptr; // either TPTR32 or TPTR64 ...@@ -482,6 +489,7 @@ EXTERN int tptr; // either TPTR32 or TPTR64
extern char* sysimport; extern char* sysimport;
extern char* unsafeimport; extern char* unsafeimport;
EXTERN char* filename; // name to uniqify names EXTERN char* filename; // name to uniqify names
EXTERN Idir* idirs;
EXTERN Type* types[NTYPE]; EXTERN Type* types[NTYPE];
EXTERN uchar simtype[NTYPE]; EXTERN uchar simtype[NTYPE];
...@@ -552,6 +560,7 @@ int yyparse(void); ...@@ -552,6 +560,7 @@ int yyparse(void);
*/ */
int mainlex(int, char*[]); int mainlex(int, char*[]);
void setfilename(char*); void setfilename(char*);
void addidir(char*);
void importfile(Val*); void importfile(Val*);
void cannedimports(char*, char*); void cannedimports(char*, char*);
void unimportfile(); void unimportfile();
......
...@@ -35,6 +35,10 @@ mainlex(int argc, char *argv[]) ...@@ -35,6 +35,10 @@ mainlex(int argc, char *argv[])
case 'k': case 'k':
package = ARGF(); package = ARGF();
break; break;
case 'I':
addidir(ARGF());
break;
} ARGEND } ARGEND
if(argc != 1) if(argc != 1)
...@@ -109,6 +113,7 @@ mainlex(int argc, char *argv[]) ...@@ -109,6 +113,7 @@ mainlex(int argc, char *argv[])
usage: usage:
print("flags:\n"); print("flags:\n");
print(" -I DIR search for packages in DIR\n");
print(" -d print declarations\n"); print(" -d print declarations\n");
print(" -f print stack frame structure\n"); print(" -f print stack frame structure\n");
print(" -k name specify package name\n"); print(" -k name specify package name\n");
...@@ -175,15 +180,29 @@ skiptopkgdef(Biobuf *b) ...@@ -175,15 +180,29 @@ skiptopkgdef(Biobuf *b)
return 1; return 1;
} }
void
addidir(char* dir)
{
Idir** pp;
if(dir == nil)
return;
for(pp = &idirs; *pp != nil; pp = &(*pp)->link)
;
*pp = mal(sizeof(Idir));
(*pp)->link = nil;
(*pp)->dir = dir;
}
int int
findpkg(String *name) findpkg(String *name)
{ {
static char* goroot; static char* goroot;
Idir* p;
if(goroot == nil) { if(goroot == nil) {
goroot = getenv("GOROOT"); goroot = getenv("GOROOT");
if(goroot == nil)
return 0;
} }
// BOTCH need to get .6 from backend // BOTCH need to get .6 from backend
...@@ -191,18 +210,29 @@ findpkg(String *name) ...@@ -191,18 +210,29 @@ findpkg(String *name)
// try .a before .6. important for building libraries: // try .a before .6. important for building libraries:
// if there is an array.6 in the array.a library, // if there is an array.6 in the array.a library,
// want to find all of array.a, not just array.6. // want to find all of array.a, not just array.6.
for(p = idirs; p != nil; p = p->link) {
snprint(namebuf, sizeof(namebuf), "%s/%Z.a", p->dir, name);
if(access(namebuf, 0) >= 0)
return 1;
snprint(namebuf, sizeof(namebuf), "%s/%Z.6", p->dir, name);
if(access(namebuf, 0) >= 0)
return 1;
}
snprint(namebuf, sizeof(namebuf), "%Z.a", name); snprint(namebuf, sizeof(namebuf), "%Z.a", name);
if(access(namebuf, 0) >= 0) if(access(namebuf, 0) >= 0)
return 1; return 1;
snprint(namebuf, sizeof(namebuf), "%Z.6", name); snprint(namebuf, sizeof(namebuf), "%Z.6", name);
if(access(namebuf, 0) >= 0) if(access(namebuf, 0) >= 0)
return 1; return 1;
snprint(namebuf, sizeof(namebuf), "%s/pkg/%Z.a", goroot, name); if(goroot != nil) {
if(access(namebuf, 0) >= 0) snprint(namebuf, sizeof(namebuf), "%s/pkg/%Z.a", goroot, name);
return 1; if(access(namebuf, 0) >= 0)
snprint(namebuf, sizeof(namebuf), "%s/pkg/%Z.6", goroot, name); return 1;
if(access(namebuf, 0) >= 0) snprint(namebuf, sizeof(namebuf), "%s/pkg/%Z.6", goroot, name);
return 1; if(access(namebuf, 0) >= 0)
return 1;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment