delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/01/21/16:29:50

From: <ams AT ludd DOT luth DOT se>
Message-Id: <200301212129.h0LLTfF25178@speedy.ludd.luth.se>
Subject: stubify calling stubedit
To: DJGPP-WORKERS <djgpp-workers AT delorie DOT com>
Date: Tue, 21 Jan 2003 22:29:41 +0100 (CET)
X-Mailer: ELM [version 2.4ME+ PL78 (25)]
MIME-Version: 1.0
X-MailScanner: Found to be clean
X-MailScanner-SpamScore: ss
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Here's the promised patch to stubify to be able to set stub options by
calling stubedit.

Note that the environmental thing is gone. Could be reintroduce by
someone willing. (Not me, unless somebody can convince me that it's
necessary.)

Note the wonderous versatility of options to pass to stubedit.

You might have opinions on the "=" in"-stubparams=". 
stubparams=minstack=2000m" might look strange.


Right,

						MartinS

Index: djgpp/src/stub/stubify.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/stub/stubify.c,v
retrieving revision 1.7
diff -p -u -r1.7 stubify.c
--- djgpp/src/stub/stubify.c	21 Jan 2003 20:59:29 -0000	1.7
+++ djgpp/src/stub/stubify.c	21 Jan 2003 21:12:24 -0000
@@ -28,6 +29,9 @@
 #define SEEK_SET 0
 #endif
 
+/* Option string that marks what to send to stubedit (stub options). */
+#define STUB_OPTIONS "-stubparams="
+
 const unsigned char stub_bytes[] = {
 #include "stub.h"
 };
@@ -36,6 +40,7 @@ const unsigned char stub_bytes[] = {
 int verbose=0;
 
 char *generate=NULL;
+char *stubparams=NULL;
 
 unsigned long
 get32(unsigned char *ptr)
@@ -49,6 +54,41 @@ get16(unsigned char *ptr)
   return ptr[0] | (ptr[1]<<8);
 }
 
+void stubedit(const char *filename)
+{
+  if( stubparams )
+  {
+    int i;
+    char *stubedit_str = malloc( sizeof("stubedit ")-1
+			   +strlen(filename)
+			   +1 /* space */
+			   +strlen(stubparams)
+			   +1 ); /* For NULL. */
+    if( stubedit_str )
+    {
+      sprintf(stubedit_str, "stubedit %s %s",
+	      filename, stubparams);
+      if (verbose)
+      {
+	v_printf("Running '%s'\n", stubedit_str);
+      }
+      i = system(stubedit_str);
+      if( i )
+      {
+	fprintf(stderr, "%s: call to stubedit failed"
+		"(stubedit exit status was %d)\n", filename, i);
+      }
+      
+      free( stubedit_str );
+    }
+    else
+    {
+      fprintf(stderr, "%s: failed using %s (out of memory)\n", filename, 
+	      STUB_OPTIONS);
+    }
+  }
+}
+
 void coff2exe(char *fname)
 {
   char ifilename[256];
@@ -241,19 +281,22 @@ void coff2exe(char *fname)
     }
   }
 
+  stubedit(ofilename);
 }
 
 void print_help(void)
 {
-  fprintf(stderr, "Usage: stubify [-v] [-g] [%sopt[,opt...] <program>\n"
+  fprintf(stderr, "Usage: stubify [-v] [-g] [%sparam[,param...] <program>\n"
 	  "<program> may be COFF or stubbed .exe, and may be COFF with .exe extension.\n"
 	  "Resulting file will have .exe\n"
 	  "-v -> verbose\n"
 	  "-g -> generate a stub\n"
+	  "%s -> pass param[,param...] to stubedit, commas are converted into spaces\n"
 	  "\nThis program is NOT shareware or public domain.  It is copyrighted.\n"
 	  "It is redistributable but only as part of a complete package.  If you\n"
 	  "have a copy of this program, the place that you got it from is\n"
-	  "responsible for making sure you are able to get its sources as well.\n");
+	  "responsible for making sure you are able to get its sources as well.\n",
+	  STUB_OPTIONS, STUB_OPTIONS );
 }
 
 int main(int argc, char **argv)
@@ -279,6 +322,28 @@ int main(int argc, char **argv)
       argv += 2;
       argc -= 2;
     }
+    else if (! strncmp(argv[1], STUB_OPTIONS, sizeof(STUB_OPTIONS)-1))
+    {
+      int j = 0;
+      i = sizeof(STUB_OPTIONS)-1;
+      stubparams = malloc( strlen(&(argv[1][i])) + 1 );
+      while (argv[1][i])
+      {
+	if (argv[1][i] == ',')
+	{
+	  stubparams[j] = ' ';
+	}
+	else
+	{
+	  stubparams[j] = argv[1][i];
+	}
+	i++;
+	j++;
+      }
+      stubparams[j] = 0;
+      argv++;
+      argc--;
+    }
     else
     {
       fprintf(stderr, "Unknow option: %s\n", argv[1]);
@@ -316,6 +381,7 @@ int main(int argc, char **argv)
 
     write(ofile, stub_bytes, sizeof(stub_bytes));
     close(ofile);
+    stubedit(ofilename);
   }
   else
   {

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019