made names of dynamically varying length

This commit is contained in:
ceriel 1987-03-25 16:24:41 +00:00
parent eeb5148f29
commit 3e694c1b9d
3 changed files with 18 additions and 46 deletions

View file

@ -39,18 +39,6 @@ char **dnames, **pnames; /* Dynamically allocated arrays of strings.
*/ */
STATIC char **newnametab(tablen,namelen)
short tablen,namelen;
{
register char **np, **tab;
tab = (char **) newmap(tablen);
for (np = &tab[1]; np <= &tab[tablen]; np++) {
*np = (char *) newcore(namelen);
}
return tab;
}
STATIC line_p get_ca_lines(lf,p_out) STATIC line_p get_ca_lines(lf,p_out)
FILE *lf; FILE *lf;
@ -140,18 +128,14 @@ STATIC getdnames(dumpd)
*/ */
char str[IDL+1]; char str[IDL+1];
char *s;
int id; int id;
register int i;
dnames = (char **) newnametab(dlength,IDL); dnames = (char **) newmap(dlength);
for (;;) { for (;;) {
if (fscanf(dumpd,"%d %s",&id,str) == EOF) return; if (fscanf(dumpd,"%d %s",&id,str) == EOF) return;
assert(id <= dlength); assert(id <= dlength);
s = dnames[id]; dnames[id] = (char *) newcore(strlen(str)+1);
for (i = 0; i < IDL; i++) { strcpy(dnames[id], str);
*s++ = str[i];
}
} }
} }
@ -163,18 +147,14 @@ STATIC getpnames(dumpp)
*/ */
char str[IDL+1]; char str[IDL+1];
char *s;
int id; int id;
register int i;
pnames = (char **) newnametab(plength,IDL); pnames = (char **) newmap(plength);
for (;;) { for (;;) {
if (fscanf(dumpp,"%d %s",&id,str) == EOF) return; if (fscanf(dumpp,"%d %s",&id,str) == EOF) return;
assert(id <= plength); assert(id <= plength);
s = pnames[id]; pnames[id] = (char *) newcore(strlen(str)+1);
for (i = 0; i < IDL; i++) { strcpy(pnames[id], str);
*s++ = str[i];
}
} }
} }
@ -193,10 +173,10 @@ STATIC bool name_exists(name,endp,endd)
dblock_p d; dblock_p d;
for (p = fproc; p != endp; p = p->p_next) { for (p = fproc; p != endp; p = p->p_next) {
if (strncmp(name,pnames[p->p_id],IDL) == 0) return TRUE; if (strcmp(name,pnames[p->p_id]) == 0) return TRUE;
} }
for (d = fdblock; d != endd; d = d->d_next) { for (d = fdblock; d != endd; d = d->d_next) {
if (strncmp(name,dnames[d->d_id],IDL) == 0) return TRUE; if (strcmp(name,dnames[d->d_id]) == 0) return TRUE;
} }
return FALSE; return FALSE;
} }

View file

@ -18,12 +18,12 @@ typedef struct num *num_p;
struct sym { struct sym {
sym_p sy_next; /* link */ sym_p sy_next; /* link */
char sy_name[IDL]; /* name of the symbol */ char *sy_name; /* name of the symbol */
dblock_p sy_dblock; /* pointer to dblock struct */ dblock_p sy_dblock; /* pointer to dblock struct */
}; };
struct prc { struct prc {
prc_p pr_next; /* link */ prc_p pr_next; /* link */
char pr_name[IDL]; /* name of the procedure */ char *pr_name; /* name of the procedure */
proc_p pr_proc; /* pointer tto proc struct */ proc_p pr_proc; /* pointer tto proc struct */
}; };

View file

@ -116,7 +116,7 @@ dblock_p symlookup(name, status)
* hash values). Try to find 'name' in its * hash values). Try to find 'name' in its
* list. * list.
*/ */
if (strncmp((*spp)->sy_name, name, IDL) == 0) { if (strcmp((*spp)->sy_name, name) == 0) {
/* found */ /* found */
return ((*spp)->sy_dblock); return ((*spp)->sy_dblock);
} else { } else {
@ -129,7 +129,8 @@ dblock_p symlookup(name, status)
*/ */
if (status == IMPORTING) return (dblock_p) 0; if (status == IMPORTING) return (dblock_p) 0;
*spp = sp = newsym(); *spp = sp = newsym();
strncpy(sp->sy_name, name, IDL); sp->sy_name = (char *) newcore(strlen(name)+1);
strcpy(sp->sy_name, name);
dp = sp->sy_dblock = newdblock(); dp = sp->sy_dblock = newdblock();
} }
if (fdblock == (dblock_p) 0) { if (fdblock == (dblock_p) 0) {
@ -202,7 +203,7 @@ proc_p proclookup(name, status)
* hash values). Try to find 'name' in its * hash values). Try to find 'name' in its
* list. * list.
*/ */
if (strncmp((*ppp)->pr_name, name, IDL) == 0) { if (strcmp((*ppp)->pr_name, name) == 0) {
/* found */ /* found */
return ((*ppp)->pr_proc); return ((*ppp)->pr_proc);
} else { } else {
@ -215,7 +216,8 @@ proc_p proclookup(name, status)
*/ */
if (status == IMPORTING) return (proc_p) 0; if (status == IMPORTING) return (proc_p) 0;
*ppp = pp = newprc(); *ppp = pp = newprc();
strncpy(pp->pr_name, name, IDL); pp->pr_name = (char *) newcore(strlen(name)+1);
strcpy(pp->pr_name, name);
dp = pp->pr_proc = newproc(); dp = pp->pr_proc = newproc();
if (fproc == (proc_p) 0) { if (fproc == (proc_p) 0) {
fproc = dp; /* first proc */ fproc = dp; /* first proc */
@ -279,7 +281,6 @@ dump_procnames(hash,n,f)
register prc_p *pp, ph; register prc_p *pp, ph;
proc_p p; proc_p p;
char str[IDL+1];
register int i; register int i;
#define PF_WRITTEN 01 #define PF_WRITTEN 01
@ -292,11 +293,7 @@ dump_procnames(hash,n,f)
p = ph->pr_proc; p = ph->pr_proc;
if ((p->p_flags2 & PF_WRITTEN) == 0) { if ((p->p_flags2 & PF_WRITTEN) == 0) {
/* not been written yet */ /* not been written yet */
for(i = 0; i < IDL; i++) { fprintf(f,"%d %s\n",p->p_id, ph->pr_name);
str[i] = ph->pr_name[i];
}
str[IDL] = '\0';
fprintf(f,"%d %s\n",p->p_id, str);
p->p_flags2 |= PF_WRITTEN; p->p_flags2 |= PF_WRITTEN;
} }
} }
@ -362,7 +359,6 @@ dump_dblocknames(hash,n,f)
register sym_p *sp, sh; register sym_p *sp, sh;
dblock_p d; dblock_p d;
char str[IDL+1];
register int i; register int i;
#define DF_WRITTEN 01 #define DF_WRITTEN 01
@ -375,11 +371,7 @@ dump_dblocknames(hash,n,f)
d = sh->sy_dblock; d = sh->sy_dblock;
if ((d->d_flags2 & DF_WRITTEN) == 0) { if ((d->d_flags2 & DF_WRITTEN) == 0) {
/* not been written yet */ /* not been written yet */
for (i = 0; i < IDL; i++) { fprintf(f,"%d %s\n",d->d_id, sh->sy_name);
str[i] = sh->sy_name[i];
str[IDL] = '\0';
}
fprintf(f,"%d %s\n",d->d_id, str);
d->d_flags2 |= DF_WRITTEN; d->d_flags2 |= DF_WRITTEN;
} }
} }