|
|
1.1 root 1: /*
2: * static char ID_frs[] = "@(#)pass1.c 1.5 4/6/84";
3: */
4:
5: /* program to remove duplicate structures and unions */
6: /* 2 pass process; 1st pass makes comparisons 2nd pass compresses,
7: * reading complete object file and redirecting pointers
8: */
9:
10: #include <stdio.h>
11: #include "sdp.h"
12: #include "sdp1.h"
13: #include <signal.h>
14: #include "filehdr.h"
15: #include "syms.h"
16: #include "storclass.h"
17: #include "ldfcn.h"
18: #include "tagitem.h"
19:
20: #define YES 1
21: #define NO 0
22: #define HASHSIZE 521
23: #define nmcmp(a,b) !strcmp((a),(b))
24:
25:
26: static int sdp_call = 0; /* indicate if sdpinit called */
27: static char sdpname[sizeof(TMPDIR)+20] = "";
28: static char buf[sizeof(sdpname)*2 + 20 ];
29: static int call = 0;
30: char tagname[sizeof(TMPDIR)+20] = "";
31: static char buf2[sizeof(tagname) * 2 + 20];
32:
33: /* TAGITEM is a chain containing information needed in
34: * comparing various tags. there are as many tagitems as there
35: * are union and structure
36: */
37: ITEMID hashtab[HASHSIZE];
38:
39:
40:
41:
42: ldclose(),
43: ldfhread(),
44: ldohseek(),
45: ldtbread(),
46: ldtbseek();
47:
48: ITEMID ti_head,
49: ti_end;
50: TAGITEM *p;
51:
52:
53: LDFILE *input;
54:
55: /* variable representing total # of entries removed */
56:
57:
58: long delsum = 0;
59: int sbrk();
60: #define ulimit(a) 1000000L
61: long szecnt = 0;
62: struct SPACE *TAGSPACE;
63: struct ENVIRON *ENV;
64: struct SPACE *SYMSPACE;
65: int pagesize=512; /* the size of a page for sdp */
66: int framsz=4096; /* the size of a frame for sdp */
67: long reserved; /* the size of core excluded from sdp */
68: long allocated; /* amount of core used for sdp */
69: int framect;
70:
71: char *str_table; /* all names are copied to here for storage */
72: char *str_next; /* next available location in str_table */
73: char *str_top; /* last location in str_table */
74:
75: /* main opens object file and reads header info
76: */
77:
78: int
79: frstpass(argv)
80:
81: char *argv;
82: {
83: extern char *malloc();
84: extern char *keep_name();
85: SYMENT symbuf;
86: AUXENT auxbuf;
87: extern long tag_sum;
88: extern int vflag;
89: extern int pflag;
90: long nthis, nnext;
91: int aux;
92:
93: ti_head = 0L;
94: if ( (input = ldopen(argv, NULL)) == NULL) {
95: fprintf(stderr, "unable to open %s \n",argv);
96: return(NO);
97: }
98: if (!(ISCOFF(HEADER(input).f_magic))) {
99: fprintf(stderr, "%s has incorrect magic number\n", argv);
100: return(NO);
101: }
102:
103: if ( ldtbseek(input) == FAILURE) {
104: if ( pflag > 0)
105: fprintf(stderr, "could not find symbol table\n");
106: return(FAILURE);
107: }
108: nnext = 0;
109: /* call subroutine to initialize SDP for symtab and Tag */
110: allocated = ulimit(3) - sbrk(0);
111: allocated = (allocated > 1048576) ? 1048576 : allocated;
112: reserved = ((reserved = allocated/10) > 8192) ? reserved : 8192;
113: framect =(allocated - reserved) / framsz;
114: if (framect < 2)
115: {
116: fprintf(stderr,"Insufficient core for sdp\n");
117: return(NO);
118: }
119: free(malloc((unsigned) framect*(unsigned) framsz));
120: if ((ENV=sdp_house(framect,framsz,NULL)) == NULL)
121: {
122: return(NO);
123: }
124: if (syminit() && taginit() == NO)
125: return(NO);
126: /*
127: * get initial string table set up
128: */
129: if (init_strings() == FAILURE)
130: return (FAILURE);
131: while( nnext < HEADER(input).f_nsyms) {
132: nthis = nnext;
133: if ( ldtbread(input, nthis, &symbuf) == FAILURE){
134: if ( vflag > 0)
135: fprintf(stderr,"cannot read symbol with index %d\n", nthis);
136: return(NO);
137: }
138: if ( symbuf.n_numaux == 0)
139: nnext = nthis + 1;
140: else {
141: nnext = nthis + symbuf.n_numaux + 1;
142: for ( aux = 0; aux < symbuf.n_numaux; aux++)
143: if ( fread(&auxbuf, AUXESZ, 1, IOPTR(input)) < 1) {
144: if ( vflag > 0)
145: fprintf(stderr, "unable to read auxiliary entry\n");
146: return(NO);
147: }
148: }
149:
150: /* after reading an entry check to see if it is a tag */
151: if (symbuf.n_sclass== C_STRTAG || symbuf.n_sclass == C_UNTAG) {
152: if ( symbuf.n_numaux != 0)
153: nnext = auxbuf.x_sym.x_fcnary.x_fcn.x_endndx;
154:
155: if ((symbuf.n_nptr = keep_name(input, &symbuf)) == NULL)
156: return (FAILURE);
157: /* call subroutine to store all entries of tag */
158: if ( tagstor(symbuf, auxbuf, nthis) == NO)
159: return(NO);
160: tag_sum++;
161: }
162: } /* end of while loop */
163:
164: /* at end of loop all symbol table entries have been read and compared
165: */
166:
167: if ( nnext != HEADER(input).f_nsyms ) {
168: if ( vflag > 0)
169: fprintf(stderr, "error in indexing symbol table\n");
170: return(NO);
171: }
172:
173: ldclose(input);
174:
175: return (SUCCESS);
176: }
177:
178: /*eject*/
179:
180: /* function tagstor saves all tag entry info so comparison can be done */
181:
182: int
183: tagstor(symbuf, auxbuf, nthis)
184:
185: SYMENT symbuf;
186: AUXENT auxbuf;
187: long nthis;
188: {
189:
190: extern long tag_sum;
191: extern int vflag;
192:
193: extern ITEMID compar();
194:
195: TAGITEM *px, *p_comp;
196: SYMENT *storbuf;
197: SYMENTRY *symbl;
198: ITEMID id,
199: id2,
200: realval;
201: long last, ncur;
202: SYMENTRY *sym;
203: AUXENT *ax;
204: int hashval;
205: int aux_flag = 0;
206:
207:
208: last = auxbuf.x_sym.x_fcnary.x_fcn.x_endndx;
209: szecnt += (long)((last-nthis)*sizeof(SYMENT));
210: id = sdp_allot(TAGSPACE, sizeof(TAGITEM));
211: p = (TAGITEM *) sdp_use(TAGSPACE,id,RNLY);
212: szecnt += (long)(sizeof(TAGITEM));
213: p->oldloc = nthis;
214: p->nentrys = (unsigned)((long)last - (long)nthis);
215: p->tmpsym = (SYMENT *) calloc( p->nentrys, sizeof(SYMENT) );
216: storbuf = p->tmpsym;
217:
218: /* initially ptr to next tagitem is NULL; also, dupl. ptr. is NULL */
219:
220: p->next_ti = 0L;
221: p->p_realtag = 0L;
222: p->newloc = 0;
223:
224: /* ti_head = 1st data structure in chain */
225: if(ti_head == 0L){
226: ti_head = id;
227: ti_end = id;
228: }
229: else{
230:
231: /* not the first tag found */
232: px = (TAGITEM *) sdp_use(TAGSPACE,ti_end,WRTN);
233:
234: /* attach new tag to chain */
235:
236: px->next_ti = id;
237: sdp_unuse(TAGSPACE,ti_end,WRTN);
238: ti_end = id;
239: }
240:
241: /*
242: * In addition to ordered list, create hash table access
243: * for speed
244: */
245:
246: hashval = hash(symbuf.n_nptr);
247: p->next_col = hashtab[hashval]; /* may be 0L */
248: hashtab[hashval] = id;
249:
250: /* copy tag into allocated area of symbol */
251:
252: *(p->tmpsym) = symbuf;
253: ++(p->tmpsym);
254: *(AUXENT *)(p->tmpsym) = auxbuf;
255:
256: /* proceed to read all members and .eos */
257:
258: for ( ncur = nthis+symbuf.n_numaux+1; ncur < last; ncur++) {
259: ++(p->tmpsym);
260: if( ldtbread( input, ncur, &symbuf) == FAILURE) {
261: if ( vflag > 0)
262: fprintf(stderr, "unable to read symbol at index %ld\n", ncur);
263: return(NO);
264: }
265: /*
266: * Check to see if this is an aux or not. Only save the
267: * name when it is not. Assume that the first entry is a
268: * non-aux entry and keep track from there.
269: */
270: if (aux_flag == 0)
271: {
272: if ((symbuf.n_nptr = keep_name(input, &symbuf)) == NULL)
273: return (FAILURE);
274: aux_flag = symbuf.n_numaux;
275: }
276: else
277: aux_flag--;
278: *(p->tmpsym) = symbuf;
279: }
280:
281: p->tmpsym = storbuf;
282: p_comp = p;
283:
284: /* compare for duplicate tags */
285:
286: p->newloc = p->oldloc - delsum;
287: if(( realval = compar(p_comp)) != 0L) {
288: cfree(storbuf);
289: p->tmpsym = NULL;
290: p->tagbuf = 0L;
291: delsum = delsum + (p->nentrys) - 1;
292: p->p_realtag = realval;
293: sdp_unuse(TAGSPACE,id, RNLY);
294: return(SUCCESS);
295: }
296:
297: /*
298: * store symbol table info permanently in SDP
299: */
300:
301: p->tmpsym = storbuf;
302: p->tagbuf = sdp_allot(SYMSPACE,sizeof(SYMENTRY));
303: symbl = (SYMENTRY *) sdp_use(SYMSPACE,p->tagbuf,WRTN);
304: symbl->symbuf = *(p->tmpsym);
305: symbl->auxbuf = sdp_allot(SYMSPACE,sizeof(AUXENT));
306: ax = (AUXENT *) sdp_use(SYMSPACE,symbl->auxbuf,WRTN);
307: ++(p->tmpsym);
308: *ax = *((AUXENT *)p->tmpsym);
309: sdp_unuse(SYMSPACE,symbl->auxbuf, WRTN);
310: id2 = p->tagbuf;
311: for ( ncur = nthis+2; ncur < last; ncur++) {
312: symbl->nxtsym = sdp_allot(SYMSPACE,sizeof(SYMENTRY));
313: sym = (SYMENTRY *) sdp_use(SYMSPACE,symbl->nxtsym,WRTN);
314: sym->symbuf = *(++(p->tmpsym));
315: if ( sym->symbuf.n_numaux != 0) {
316: ncur += (long) sym->symbuf.n_numaux;
317: sym->auxbuf = sdp_allot(SYMSPACE,sizeof(AUXENT));
318: ax = (AUXENT *) sdp_use(SYMSPACE,sym->auxbuf,WRTN);
319: *ax = *((AUXENT *) ++(p->tmpsym));
320: sdp_unuse(SYMSPACE,sym->auxbuf, WRTN);
321: }
322: sdp_unuse(SYMSPACE,id2, WRTN);
323: id2 = symbl->nxtsym;
324: symbl = sym;
325: }
326:
327: sdp_unuse(SYMSPACE,id2, WRTN);
328: sdp_unuse(TAGSPACE,id, RNLY);
329: cfree(storbuf);
330: p->tmpsym = NULL;
331: return(SUCCESS);
332: }
333:
334:
335: /*eject*/
336:
337: /* function to compare requires last tag read in and compares it against
338: * all others
339: */
340:
341: ITEMID
342: compar(p_test)
343: TAGITEM *p_test;
344: {
345: TAGITEM *p_real;
346: ITEMID tmpid;
347:
348: for ( tmpid = p_test->next_col; tmpid != 0L; tmpid = p_real->next_col) {
349: p_real = (TAGITEM *) sdp_use(TAGSPACE,tmpid,RNLY);
350: if( pair(p_real, p_test)==YES) {
351: sdp_unuse(TAGSPACE,tmpid, RNLY);
352: return(tmpid);
353: } else {
354: sdp_unuse(TAGSPACE,tmpid, RNLY);
355: }
356: }
357: return(0L);
358: }
359: /*eject*/
360: /* the function pair, does actual comparison of 2 given data structures */
361:
362:
363: int
364: pair(preal, ptest)
365: TAGITEM *preal, *ptest;
366: {
367:
368: SYMENTRY *ptr1;
369: SYMENT *ptr2;
370: AUXENT *aux1, *aux2;
371: int i,
372: aux;
373:
374: ITEMID id;
375:
376: /* pair takes the elements of 2 different data structures and compares each
377: * element. if any element varies, the 2 are different and function returns
378: * zero to calling routine. */
379: /* if all elements are equal, the function returns one */
380:
381: aux1 = aux2 = NULL;
382:
383: if( preal->nentrys != ptest->nentrys)
384: return(NO);
385: if( preal->p_realtag == ptest->p_realtag && preal->p_realtag != 0L)
386: return(YES);
387: if( preal->p_realtag != 0L || ptest->p_realtag != 0L)
388: return(NO);
389:
390: id = preal->tagbuf;
391: ptr1 = (SYMENTRY *)sdp_use(SYMSPACE,id,RNLY);
392: ptr2 = ptest->tmpsym;
393:
394: /* ptr1 & ptr2 point to symbol table infor. stored. Compare tagname
395: * and auxentry of each tag.
396: */
397:
398: if( nmcmp(ptr1->symbuf.n_nptr, ptr2->n_nptr) == NO)
399: if( gen(ptr1->symbuf.n_nptr) == NO || gen(ptr2->n_nptr) == NO)
400: goto failure;
401: if( ptr1->symbuf.n_scnum != ptr2->n_scnum)
402: goto failure;
403: if( ptr1->symbuf.n_value != ptr2->n_value)
404: goto failure;
405: if( ptr1->symbuf.n_sclass != ptr2->n_sclass)
406: goto failure;
407: if( ptr1->symbuf.n_type != ptr2->n_type)
408: goto failure;
409: if( ptr1->symbuf.n_numaux != ptr2->n_numaux)
410: goto failure;
411: /* tag names matched, now test the aux. entry for respective tags
412: */
413: if( ptr1->symbuf.n_numaux != 0) {
414: aux1 = (AUXENT *) sdp_use(SYMSPACE,ptr1->auxbuf,RNLY);
415: aux2 = (AUXENT *) ++(ptest->tmpsym);
416:
417: if (aux1->x_sym.x_misc.x_lnsz.x_size != aux2->x_sym.x_misc.x_lnsz.x_size)
418: goto failure;
419: sdp_unuse(SYMSPACE,ptr1->auxbuf, RNLY);
420: aux1 = aux2 = NULL;
421: }
422: aux = ptr1->symbuf.n_numaux;
423:
424: sdp_unuse(SYMSPACE,id, RNLY);
425: id = ptr1->nxtsym;
426: ptr1 = (SYMENTRY *)sdp_use(SYMSPACE,id,RNLY);
427: ptr2 = ++(ptest->tmpsym);
428:
429: for ( i=0; i < preal->nentrys - (aux + 3); i++) {
430: if( memcom(ptr1, ptr2, ptest, preal) == NO)
431: goto failure;
432: if( ptr1->symbuf.n_numaux != 0) {
433: i += ptr1->symbuf.n_numaux;
434: ++(ptest->tmpsym);
435: }
436: sdp_unuse(SYMSPACE,id, RNLY);
437: id = ptr1->nxtsym;
438: ptr1 = (SYMENTRY *)sdp_use(SYMSPACE,id,RNLY);
439: ptr2 = ++(ptest->tmpsym);
440: }
441:
442: /* all members are equal; compare .eos and auxentry */
443:
444: if( ptr1->symbuf.n_sclass != C_EOS && ptr2->n_sclass != C_EOS)
445: goto failure;
446: if( ptr1->symbuf.n_value != ptr2->n_value)
447: goto failure;
448:
449: if( ptr1->symbuf.n_numaux != ptr2->n_numaux)
450: goto failure;
451:
452: if( ptr1->symbuf.n_numaux != 0) {
453: for ( i = 0; i < ptr1->symbuf.n_numaux; i++) {
454: aux1 = (AUXENT *) sdp_use(SYMSPACE,ptr1->auxbuf,RNLY);
455: aux2 = (AUXENT *) ++(ptest->tmpsym);
456: if(aux1->x_sym.x_misc.x_lnsz.x_size != aux2->x_sym.x_misc.x_lnsz.x_size)
457: goto failure;
458: sdp_unuse(SYMSPACE,ptr1->auxbuf, RNLY);
459: aux1 = aux2 = NULL;
460: }
461: }
462:
463: sdp_unuse(SYMSPACE,id, RNLY);
464: return(YES);
465:
466: failure:
467: sdp_unuse(SYMSPACE,id, RNLY);
468: if ( aux1 != NULL ) {
469: sdp_unuse(SYMSPACE,ptr1->auxbuf, RNLY);
470: }
471: return(NO);
472: }
473:
474:
475: /* memcom compares corresponding members of structures
476: */
477:
478: int
479: memcom(ptr1, ptr2, ptest, preal)
480:
481: SYMENTRY *ptr1;
482: SYMENT *ptr2;
483: TAGITEM *ptest, *preal;
484: {
485:
486: AUXENT *aux1, *aux2;
487:
488: if(nmcmp(ptr1->symbuf.n_nptr, ptr2->n_nptr) == NO)
489: return(NO);
490: if(ptr1->symbuf.n_value != ptr2->n_value)
491: return(NO);
492: if(ptr1->symbuf.n_scnum != ptr2->n_scnum)
493: return(NO);
494: if(ptr1->symbuf.n_type != ptr2->n_type)
495: return(NO);
496: if(ptr1->symbuf.n_sclass != ptr2->n_sclass)
497: return(NO);
498: if(ptr1->symbuf.n_numaux != ptr2->n_numaux)
499: return(NO);
500: if (ptr1->symbuf.n_numaux != 0) {
501: if(BTYPE(ptr1->symbuf.n_type) == T_STRUCT || BTYPE(ptr1->symbuf.n_type) == T_UNION || ISARY(ptr1->symbuf.n_type) ) {
502: aux1 = (AUXENT *) sdp_use(SYMSPACE,ptr1->auxbuf,RNLY);
503: aux2 = (AUXENT *) ++ptr2;
504: if(aux1->x_sym.x_misc.x_lnsz.x_size != aux2->x_sym.x_misc.x_lnsz.x_size) {
505: sdp_unuse(SYMSPACE,ptr1->auxbuf, RNLY);
506: return(NO);
507: }
508: if ( auxcom(ptr1, aux1, aux2, ptest, preal)==NO){
509: sdp_unuse(SYMSPACE,ptr1->auxbuf, RNLY);
510: return(NO);
511: }
512: sdp_unuse(SYMSPACE,ptr1->auxbuf, RNLY);
513: }
514: }
515: return(YES);
516: }
517:
518:
519: /*eject*/
520: /* gen checks to see if symbol name is compiler generated
521: */
522:
523:
524: int
525: gen(px)
526:
527: char *px;
528: {
529:
530: int pos = 1;
531:
532: if(*px != '.')
533: return(0);
534: px++;
535: pos++;
536: while(*px >= '0' && *px <= '9') {
537: px++;
538: pos++;
539: }
540: if(pos== 1 || pos > 5)
541: return(0);
542: if(*px != 'f' || *(px+1) != 'a' || *(px+2) != 'k' || *(px+3) != 'e')
543: return(0);
544: return(1);
545: }
546:
547:
548: /*eject*/
549: /* auxcom compares corresponding aux.entries for members being tested */
550:
551: auxcom(ptr1, aux1, aux2, ptest, preal)
552:
553: SYMENTRY *ptr1;
554: AUXENT *aux1, *aux2;
555: TAGITEM *ptest, *preal;
556: {
557: SYMENTRY *check1, *check2;
558: SYMENT *check2x;
559: int useid;
560: ITEMID axid,axid2, tmpid, tmpid2;
561:
562: useid = 0;
563:
564: if(BTYPE(ptr1->symbuf.n_type) == T_STRUCT || BTYPE(ptr1->symbuf.n_type) == T_UNION) {
565: if(aux1->x_sym.x_tagndx ==preal->oldloc && aux2->x_sym.x_tagndx == ptest->oldloc)
566: return(YES);
567: if(aux1->x_sym.x_tagndx ==preal->oldloc) {
568: axid = preal->tagbuf;
569: check1 = (SYMENTRY *)sdp_use(SYMSPACE,axid,WRTN);
570: } else {
571: axid = ti_head;
572: for (preal = (TAGITEM *)sdp_use(TAGSPACE,axid,WRTN); preal->next_ti != 0L; preal = (TAGITEM *)sdp_use(TAGSPACE,axid,WRTN)) {
573: if(preal->oldloc == aux1->x_sym.x_tagndx) {
574: if (preal->tagbuf == 0L) {
575: axid2 = preal->p_realtag;
576: sdp_unuse(TAGSPACE,axid, WRTN);
577: axid = axid2;
578: preal = (TAGITEM *) sdp_use(TAGSPACE,axid,WRTN);
579: }
580: sdp_unuse (TAGSPACE,axid, WRTN);
581: axid = preal->tagbuf;
582: check1 = (SYMENTRY *)sdp_use(SYMSPACE,axid,WRTN);
583: break;
584: } else {
585: axid2 = preal->next_ti;
586: sdp_unuse (TAGSPACE,axid, WRTN);
587: axid = axid2;
588: }
589: }
590: }
591: /* At this point axid is locked and check1 points to something resonable */
592: if ( aux2->x_sym.x_tagndx == ptest->oldloc) {
593: check2x = ptest->tmpsym;
594: } else {
595: useid = 1;
596: tmpid = ti_head;
597: for (ptest = (TAGITEM *)sdp_use(TAGSPACE,tmpid,WRTN); ptest->next_ti != 0L; ptest = (TAGITEM *)sdp_use(TAGSPACE,tmpid,WRTN)) {
598: if(ptest->oldloc == aux2->x_sym.x_tagndx) {
599: if(ptest->tagbuf == 0L) {
600: tmpid2 = ptest->p_realtag;
601: sdp_unuse(TAGSPACE,tmpid, WRTN);
602: tmpid = tmpid2;
603: ptest = (TAGITEM *) sdp_use(TAGSPACE,tmpid,WRTN);
604: }
605: sdp_unuse (TAGSPACE,tmpid, WRTN);
606: tmpid = ptest->tagbuf;
607: check2 = (SYMENTRY *)sdp_use(SYMSPACE,tmpid,WRTN);
608: break;
609: } else {
610: tmpid2 = ptest->next_ti;
611: sdp_unuse (TAGSPACE,tmpid, WRTN);
612: tmpid = tmpid2;
613: }
614: }
615: }
616: if (useid) {
617: if( check1 == check2) {
618:
619: sdp_unuse (SYMSPACE,axid, WRTN);
620: sdp_unuse(SYMSPACE,tmpid, WRTN);
621: return(YES);
622: }
623: if(nmcmp(check1->symbuf.n_nptr, check2->symbuf.n_nptr)==NO)
624: if(gen(check1->symbuf.n_nptr) == 0 && gen(check2->symbuf.n_nptr) == 0) {
625: sdp_unuse(SYMSPACE,axid, WRTN);
626: sdp_unuse(SYMSPACE,tmpid, WRTN);
627: return(NO);
628: }
629: if(check1->symbuf.n_value != check2->symbuf.n_value) {
630: sdp_unuse(SYMSPACE,axid, WRTN);
631: sdp_unuse(SYMSPACE,tmpid, WRTN);
632: return(NO);
633: }
634: if(check1->symbuf.n_type != check2->symbuf.n_type) {
635: sdp_unuse(SYMSPACE,axid,WRTN);
636: sdp_unuse(SYMSPACE,tmpid, WRTN);
637: return(NO);
638: }
639: if(check1->symbuf.n_sclass != check2->symbuf.n_sclass) {
640: sdp_unuse(SYMSPACE,axid, WRTN);
641: sdp_unuse(SYMSPACE,tmpid, WRTN);
642: return(NO);
643: }
644:
645: if(check1->symbuf.n_numaux != check2->symbuf.n_numaux) {
646: sdp_unuse(SYMSPACE,axid, WRTN);
647: sdp_unuse(SYMSPACE,tmpid, WRTN);
648: return(NO);
649: }
650: sdp_unuse(SYMSPACE,axid, WRTN);
651: sdp_unuse(SYMSPACE,tmpid, WRTN);
652: return(YES);
653: } /* if useid */
654:
655: /*
656: * comparing SDP with internal storage
657: */
658: if(nmcmp(check1->symbuf.n_nptr, check2x->n_nptr)==NO)
659: if(gen(check1->symbuf.n_nptr) == 0 && gen(check2x->n_nptr) == 0) {
660: sdp_unuse(SYMSPACE,axid, WRTN);
661: return(NO);
662: }
663: if(check1->symbuf.n_value != check2x->n_value) {
664: sdp_unuse(SYMSPACE,axid, WRTN);
665: return(NO);
666: }
667: if(check1->symbuf.n_type != check2x->n_type) {
668: sdp_unuse(SYMSPACE,axid,WRTN);
669: return(NO);
670: }
671: if(check1->symbuf.n_sclass != check2x->n_sclass) {
672: sdp_unuse(SYMSPACE,axid, WRTN);
673: return(NO);
674: }
675:
676: if(check1->symbuf.n_numaux != check2x->n_numaux) {
677: sdp_unuse(SYMSPACE,axid, WRTN);
678: return(NO);
679: }
680: sdp_unuse(SYMSPACE,axid, WRTN);
681: return(YES);
682:
683: } /* if BTYPE */
684: return(YES);
685: }
686:
687: int
688: syminit()
689: {
690: extern int sprintf();
691: extern int mktemp();
692: extern int fork();
693:
694: if (sdp_call==2) {
695: fprintf(stderr,"Attemp to re-initialize SDP\n");
696: return(NO);
697: }
698: sdp_call++;
699: sprintf(sdpname, "%s/%s", TMPDIR, "symXXXX");
700: mktemp(sdpname);
701: if ((sdp_generate(sdpname,pagesize,NULL,0777)) == SDPERROR)
702: {
703: return(NO);
704: }
705:
706: if ((SYMSPACE = sdp_connect(sdpname,ENV,NULL,WRTN)) == NULL)
707: {
708: fprintf(stderr,"Failed to initialize SDP symbol space");
709: return(NO);
710: }
711: else
712: {
713: sdp_call++;
714: sdp_allot(SYMSPACE,4); /* so itemid never 0L */
715: return(YES);
716: }
717: }
718:
719:
720: int
721: symfini()
722: {
723:
724:
725: /* Ignore BREAK, HANGUP and QUIT signals, to insure cleanup is finished
726: */
727: /*
728: signal(SIGINT, SIG_IGN);
729: signal(SIGQUIT, SIG_IGN);
730:
731: */
732: if (sdp_call==2) {
733: sdp_call--;
734: if (sdp_disconnect(SYMSPACE) == SDPERROR)
735: {
736: fprintf(stderr,"Failed to close SDP");
737: return(NO);
738: }
739: if (sdp_destroy(sdpname,NULL) == SDPERROR)
740: {
741: fprintf(stderr,"Failed to close SDP");
742: return(NO);
743: }
744: }
745: if (sdp_call != 1) {
746: return(YES);
747: }
748: sdp_call--;
749:
750: return(YES);
751: }
752:
753: int
754: taginit()
755: {
756:
757: extern int sprintf(),
758: mktemp();
759:
760:
761: if (call) {
762: fprintf(stderr,"Attempt to re-init SDP for Tag");
763: return(NO);
764: }
765:
766: sprintf(tagname, "%s/%s", TMPDIR, "tgXXXX");
767: mktemp(tagname);
768:
769: call++;
770:
771: if ((sdp_generate(tagname,pagesize,NULL,0777)) == SDPERROR)
772: {
773: return(NO);
774: }
775:
776: if ((TAGSPACE = sdp_connect(tagname,ENV,NULL,WRTN)) == NULL)
777: {
778: fprintf(stderr,"Failed to initialize SDP Tag space");
779: return(NO);
780: }
781: else
782: {
783: sdp_allot(TAGSPACE,4); /* so that itemid never 0L */
784: call++;
785: return(YES);
786: }
787: }
788:
789: int
790: tagfini()
791: {
792:
793: /*
794: signal(SIGINT, SIG_IGN);
795: signal(SIGQUIT, SIG_IGN);
796: */
797:
798: if (call==2) {
799: call--;
800: if (sdp_disconnect(TAGSPACE) == SDPERROR)
801: {
802: fprintf(stderr,"Failed to close SDP for tag");
803: return(NO);
804: }
805: if (sdp_destroy(tagname,NULL) == SDPERROR)
806: {
807: fprintf(stderr,"Failed to close SDP for TAG");
808: return(NO);
809: }
810: }
811:
812: if (call != 1)
813: return(YES);
814: call--;
815: return(YES);
816: }
817: hash(name)
818: register char *name;
819: {
820:
821: /*
822: * Compute hash value for a symbol name
823: */
824:
825: register unsigned hashval;
826: register int symlenth;
827: int tmp; /* VAX CC BUG KLUDGE */
828:
829: hashval = symlenth = 0;
830: while( (*name != '\0') && (symlenth < 8) ) {
831: hashval = hashval*13 + *name++;
832: symlenth++;
833: }
834:
835: /*
836: * Because of a bug in the current VAX compiler, the following
837: * line has temporarily been replaced by the KLUDGE following
838: * this comment. The define of abs() is also added above
839: *
840: * return( (int) (hashval % HASHSIZE) );
841: */
842:
843: tmp = (int) hashval;
844: tmp = abs(tmp);
845: return ( tmp % HASHSIZE );
846: }
847:
848: int
849: init_strings()
850: {
851: extern char *malloc();
852:
853: if ((str_table = malloc((unsigned)(BUFSIZ * 10))) == NULL)
854: {
855: fprintf(stderr, "Insufficient memory for string table\n");
856: return (FAILURE);
857: }
858: str_next = str_table;
859: str_top = str_table + BUFSIZ * 10;
860: return (SUCCESS);
861: }
862:
863: char *
864: keep_name(f, symptr) /* place name into permanent string table */
865: LDFILE *f;
866: SYMENT *symptr;
867: {
868: register char *p, *s;
869: register int i, j;
870: extern char *ldgetname();
871: extern char *realloc();
872:
873: if ((p = ldgetname(f, symptr)) == NULL)
874: {
875: fprintf(stderr, "Name retrieval error\n");
876: return (NULL);
877: }
878: i = strlen(p) + 1;
879: if (str_next + i >= str_top)
880: {
881: str_top += BUFSIZ * 5;
882: s = str_table;
883: str_table = realloc(s, (unsigned)(str_top - s));
884: if (str_table == NULL)
885: {
886: fprintf(stderr,
887: "Insufficient memory to grow string table\n");
888: return (NULL);
889: }
890: j = str_table - s;
891: str_next += j;
892: str_top += j;
893: }
894: (void)strcpy(str_next, p);
895: s = str_next;
896: str_next += i;
897: return (s);
898: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.