home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libnix-0.8-src.lha / libnix-0.8 / sources / nix_main / __nocommandline.c next >
Encoding:
C/C++ Source or Header  |  1995-03-05  |  1.4 KB  |  63 lines

  1. /*
  2.  * This is a different calling convention for main (actually its _main):
  3.  *
  4.  * int main(char *commandline);
  5.  * void exit(int returncode);
  6.  * 
  7.  */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <exec/memory.h>
  11. #include <dos/dos.h>
  12. #ifdef __GNUC__
  13. #include <inline/exec.h>
  14. #include <inline/dos.h>
  15. #endif
  16. #include <stabs.h>
  17.  
  18. extern char *__argc; /* Defined in startup */
  19. extern char  *__commandline;
  20. extern unsigned long __commandlen;
  21. extern struct WBStartup *_WBenchMsg;
  22.  
  23. /* This guarantees that this module gets linked in.
  24.    If you replace this by an own reference called
  25.    __nocommandline you get no commandline arguments */
  26. ALIAS(__nocommandline,__initcommandline);
  27.  
  28. void __initcommandline(void)
  29. { if(_WBenchMsg==NULL)
  30.   { char *a,**ac;
  31.     unsigned long i;
  32.  
  33.     for(i=256;;i+=256) /* try in steps of 256 bytes */
  34.     { if(!(*(ac=&__argc)=(char *)AllocVec(i+__commandlen+4,MEMF_ANY)))
  35.         exit(20);
  36.       GetProgramName(*ac+1,i); /* Who am I ? */
  37.       if(IoErr()!=ERROR_LINE_TOO_LONG)
  38.         break;
  39.       FreeVec(*ac);
  40.     }
  41.  
  42.     a=*ac;
  43.     *a++='\"';
  44.     while(*a++)
  45.       ;
  46.     a[-1]='\"';
  47.     *a++=' ';
  48.     a[__commandlen]=0;
  49.     CopyMem(__commandline,a,__commandlen);
  50.   }
  51. }
  52.  
  53. void __exitcommandline(void)
  54. { char **ac;
  55.  
  56.   if(*(ac=&__argc)!=NULL)
  57.     FreeVec(*ac);
  58. }
  59.  
  60. /* Add these two functions to the lists */
  61. ADD2INIT(__initcommandline,-40);
  62. ADD2EXIT(__exitcommandline,-40);
  63.