home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / test.hel < prev    next >
Text File  |  1993-07-23  |  3KB  |  126 lines

  1. // This file tests the installation of the GNU C++ compiler system.
  2. // In order for this file to be compiled successfully, the compiler
  3. // driver (g++) must have execute paths to the preprocessor (cpp+)
  4. // and the compiler (c++), as well as the loader (ld++) and the
  5. // special run-time library (crt0+.o).  In addition, the library
  6. // gnulib+ is needed to provide functions such as "_builtin_new"
  7. // and "_builtin_delete".
  8.  
  9. #include "test0.h"
  10. #include <a.out.h>
  11. #include <sys/file.h>
  12.  
  13.  
  14. class tfile
  15. {
  16. public:
  17.   char tname[L_tmpnam];
  18.   static char *orig_name;
  19.   char *this_name;
  20.   exec header;
  21.  
  22.   tfile (char*);
  23.   ~tfile ();
  24.   void* load ();
  25. };
  26.  
  27. tfile::tfile (char *p)
  28. {
  29.   int fd;
  30.  
  31.   strcpy (tname, "hack.XXXXXX");
  32.   mktemp (tname);
  33.   this_name = new char[strlen (p) + 1];
  34.   strcpy (this_name, p);
  35.  
  36.   if ((fd = open (this_name, 2, 0)) < 0)
  37.     {
  38.       fprintf (stderr, "Unable to open file %s\n", p);
  39.       exit (1);
  40.     }
  41.   if (read (fd, (void*) &header, sizeof (header)) <= 0)
  42.     {
  43.       fprintf (stderr, "Error in reading file %s\n", p);
  44.     }
  45.   close (fd);
  46. }
  47.  
  48. tfile::~tfile ()
  49. {
  50.   unlink (tname);
  51. }
  52.  
  53. void *tfile::load ()
  54. {
  55.   int size = header.a_text + header.a_data;
  56. #ifndef PAGSIZ
  57.   int pagsiz = getpagesize();
  58. #else
  59.   int pagsiz = PAGSIZ;
  60. #endif
  61.  
  62.   if (size < (pagsiz))
  63.     size = (pagsiz);
  64.  
  65.   int init_fn = (int) new short[size];
  66.  
  67.   init_fn += pagsiz-1;
  68.   init_fn &= ~(pagsiz-1);
  69.  
  70.   fprintf (stderr, "\n ... timing incremental load...\n");
  71.  
  72.   char command[512], *cmd = command;
  73.   sprintf (cmd, "time %s -C -N -A %s -T %x %s %s -o %s",
  74.        LDXX, orig_name, init_fn, CRT1X, this_name, tname);
  75.  
  76.   if (system (cmd))
  77.     {
  78.       fprintf (stderr, "Error in linking file bye\n");
  79.       delete this;
  80.       exit (1);
  81.     }
  82.  
  83.   int fd = open (tname, 2, 0);
  84.   if (lseek (fd, sizeof (header), L_SET) < 0)
  85.     {
  86.       perror ("Error in temp file seek\n");
  87.       delete this;
  88.       exit (1);
  89.     }
  90.  
  91.   read (fd, (char*) init_fn, size);
  92.   close (fd);
  93.  
  94.   fprintf (stderr, "load symbol-table at address 0x%x\n", init_fn);
  95.  
  96.   return (void *)init_fn;
  97. }
  98.  
  99. ifile in ("/dev/tty");
  100. ofile out ("/dev/tty");
  101.  
  102. main (int, char *argv[])
  103. {
  104.   char buf[4096];
  105.  
  106.   out << "Enter file to link: (test.bye or test.bye2 or test.shell)\n";
  107.   in >> buf;
  108.   out << "Hello! linking `" << buf << "'...\n";
  109.   
  110.   tfile::orig_name = argv[0];
  111.  
  112.   tfile temp (buf);
  113.   register void (*init_fn)() = temp.load ();
  114.   fprintf (stderr, "\n if execution now aborts, your crt1+.o is bad\n");
  115.   (*init_fn) ();
  116.  
  117.   out << "Enter another file to link: ";
  118.   in >> buf;
  119.   out << "Hello! linking `" << buf << "'...\n";
  120.   
  121.   tfile temp2 (buf);
  122.   init_fn = temp2.load ();
  123.   (*init_fn)();
  124.  
  125. }
  126.