this avoids problems people have run into with
multiple closures in the same package.
when preparing filename, only cut off .go, not .anything.
this fixes a bug tgs ran into with foo.pb.go and foo.go
in the same package.
also turn bad identifier chars from filename into
underscores: a-b.pb.go => a_b_pb
R=ken
OCL=27050
CL=27050
// declare function.
vargen++;
- snprint(namebuf, sizeof(namebuf), "_f%.3ld", vargen);
+ snprint(namebuf, sizeof(namebuf), "_f%.3ld·%s", vargen, filename);
f = newname(lookup(namebuf));
addvar(f, ft, PFUNC);
f->funcdepth = 0;
setfilename(char *file)
{
char *p;
+ int c;
p = strrchr(file, '/');
if(p != nil)
file = p+1;
strncpy(namebuf, file, sizeof(namebuf));
- p = strchr(namebuf, '.');
- if(p != nil)
+ p = strrchr(namebuf, '.');
+ if(p != nil && strcmp(p, ".go") == 0)
*p = 0;
filename = strdup(namebuf);
+
+ // turn invalid identifier chars into _
+ for(p=filename; *p; p++) {
+ c = *p & 0xFF;
+ if(c < 0x80 && !isalpha(c) && !isdigit(c) && c != '_')
+ *p = '_';
+ }
}
int