home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / cputt-2.3 / part01 / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-05  |  1.5 KB  |  57 lines

  1. #include     <stdio.h>
  2. #include     <nlist.h>
  3. #include     <sys/file.h>
  4. #include     <sys/user.h>
  5. #include     <kvm.h>
  6.  
  7. #include     "cputt.h"
  8.  
  9. /*
  10.    INIT - Gets symbol table values for symbols in Symbollist.
  11. */
  12.  
  13. void
  14. init()
  15. {
  16.      register struct nlist   *np;
  17.      register struct symbol  *s;
  18.      register struct nlist   *np0;
  19.      char                    *getcore();
  20.  
  21.      /* find length of the list of desired symbols */
  22.      for (s = Symbollist; s->s_kname; s++);
  23.  
  24.      /* allocate core for nlist array */
  25.      np0 = (struct nlist*)getcore((s-Symbollist+1)*sizeof(struct nlist));
  26.  
  27.      /* initialize nlist array */
  28.      for (s = Symbollist,np = np0; s->s_kname; s++,np++)
  29.      {
  30.           np->n_name = s->s_kname;
  31.           np[1].n_name = (char*)0;
  32.           np->n_value = 0;
  33.      }
  34.  
  35.      /* read symbols from symbol table into nlist array */
  36.      if (kvm_nlist(Flkvm,np0) == -1)
  37.      {
  38.           fprintf(stderr,"sps - Can't read symbol file \n");
  39.           sysperror();
  40.      }
  41.  
  42.      /* derive system info from nlist and store in Symbollist */
  43.      for (s = Symbollist,np = np0; s->s_kname; s++,np++)
  44.      {                                       
  45.           if (!np->n_value)             
  46.           {
  47.               fprintf( stderr, "sps - Can't find symbol %s in %s", np->n_name);
  48.               *s->s_info = (caddr_t)0;
  49.               continue;
  50.           }
  51.  
  52.           /* Using the obtained address, read the value into Symbollist */
  53.           (void)getkmem((long)np->n_value, (char*)s->s_info, sizeof(caddr_t));
  54.      }
  55.      free((char*)np0);
  56. }
  57.