home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / nasm20b / nasm_src / nasm.c < prev    next >
C/C++ Source or Header  |  1993-01-19  |  5KB  |  209 lines

  1. #include "defines.h"
  2. #include OSBIND
  3. #include <stdio.h>
  4. #include <string.h>
  5. #define __BIG_GENERATOR__   1
  6. #include "code.h"
  7.  
  8. lword    __lx;
  9. word     __x;
  10.  
  11. #if OS == TOS
  12. static char _usage[] =
  13. "Usage: nasm [-{brqstvwx}][-a xx][-e #][-o binary][-h includedir] <source>\n";
  14. #else
  15. static char _usage[] =
  16. "Usage: nasm [-{brqsvwx}][-a xx][-e #][-o binary][-h includedir] <source>\n";
  17. #endif
  18.  
  19. void           *nmalloc();
  20. char           *getenv(), 
  21.                *mend_together();
  22.  
  23. void           finalshit(){}
  24. void           h_print(){}
  25. int            maxerrors = 1,
  26.                tok_remain,
  27.                tossable,
  28.                wherewasit;
  29.  
  30. static char   infile[ 256],
  31.               outfile[ 256],
  32.               buffer[ 400],
  33.               path[ 128];
  34.  
  35.  
  36.  
  37. main( argc, argv, envp)
  38. char  *argv[];
  39. char  **envp;
  40. {
  41.    char  *p, *q;
  42.    int   i = 0;
  43.  
  44.    nwarning("This program is only rudimentary at best. USE NASM65");
  45.    while( ++i < argc)
  46.    {
  47.       if( *argv[i] == '-')
  48.          switch( Xtolower( argv[i][1]))
  49.          {
  50.             case 'o' :
  51.             case 'a' :
  52.             case 'd' :  /* maybe we should use the env. as well */
  53.             case 'e' :
  54.             case 'h' :
  55.                ++i;
  56.  
  57.             case 'b' :
  58. #if OS == TOS
  59. # if WITHNOISY
  60.             case 'n' :
  61. # endif
  62.             case 't' :
  63. #endif            
  64.             case 'q' :
  65.             case 'r' :
  66.             case 's' :
  67.             case ':' :
  68.             case 'v' :
  69.             case 'w' :
  70.             case 'x' :
  71.                break;
  72.  
  73.             default  :
  74.                goto usage;
  75.          }
  76.       else
  77.       {
  78.          if( infile[0])
  79.             goto usage;
  80.          wherewasit = i;
  81.          strcpy( infile, argv[i]);
  82.       }
  83.    }
  84.    if( ! infile[0])
  85.       goto usage;
  86.  
  87.    if( ! (p = getenv( "CPP")))
  88.    {
  89.       if( ! (p = getenv( "BINDIR")))
  90.          nferror("Don't know where to find \"cpp\"");
  91.       strcpy( path, p);
  92.       if( p[ (i = (int) strlen( p)) - 1] != '\\')
  93.       {
  94.          path[ i++] = '\\';
  95.          path[ i]   = 0;
  96.       }
  97. #if OS == TOS
  98.       strcat( p = path, "cpp.ttp");
  99. #else
  100.       strcat( p = path, "cpp");
  101. #endif      
  102.    }
  103.  
  104.    if( ! (q = getenv( "INC65")))
  105.       q = "\\include";
  106.  
  107.    strcpy( outfile, infile);
  108.    complete( outfile, ".i", 1);
  109. #if OS == UNIX || AMIGA
  110.    sprintf( buffer, "%s -o=%s -I%s %s", p, outfile, q, infile);
  111.    if( i = execve( p, buffer, *envp))
  112.       exit( 1);
  113. #else
  114.    sprintf( buffer, "-o=%s -I%s %s", outfile, q, infile);
  115.    if( i = exec( p, buffer, *envp))
  116.       exit( 1);
  117. #endif
  118.  
  119.  
  120.  
  121.    if( ! (p = getenv( "NASM65")))
  122.    {
  123.       if( ! (p = getenv( "BINDIR")))
  124.          nferror("Don't know where to find \"nasm65\"");
  125.       strcpy( path, p);
  126.       if( p[ (i = (int) strlen( p)) - 1] != '\\')
  127.       {
  128.          path[ i++] = '\\';
  129.          path[ i]   = 0;
  130.       }
  131. #if OS == TOS
  132.       strcat( p = path, "nasm65.ttp");
  133. #else
  134.       strcat( p = path, "nasm65");
  135. #endif      
  136.    }
  137. #if OS == TOS
  138.    i = exec( p, mend_together( p, argc, argv), *envp);
  139. #else
  140.    i = execve( p, mend_together( p, argc, argv), *envp);
  141. #endif
  142.    unlink( outfile);
  143.    return( i);
  144.  
  145. usage:
  146.    fputs( _usage, ESTREAM);
  147.    fputs( "\
  148. \t-x           : list unresolved references\n\
  149. \t-w           : write output file anyway (W.T.F.)\n\
  150. \t-h <path>    : \"system\" include file directory\n\
  151. \t-o <file>    : output file specifier\n\
  152. \t-r           : create runnable binary file\n\
  153. \t-e <digit>   : set maximal number of errors before aborting\n\
  154. \t-s           : show calling of macros and include files\n\
  155. \t-d <l>[=<v>] : defines label <l>. optionally assigns <v> as value to it\n\
  156. \t-a <value>   : alignment value (1->even 255->page)\n\
  157. \t-q           : quiet flag\n\
  158. \t-b           : optimize small segments\n", ESTREAM);
  159. #if OS == TOS
  160.    fputs( "\
  161. \t-t           : wait for keypress before exit\n\
  162. \t-n           : noisy tokens\n", ESTREAM);
  163. #endif
  164.    return( 1);
  165. }
  166.  
  167.  
  168.  
  169. char  *mend_together( program, argc, argv)
  170. char  *program;
  171. int   argc;
  172. char  *argv[];
  173. {
  174.    char     *p;
  175.    int      i;
  176.    size_t   len;
  177.  
  178. #if OS == UNIX
  179.    len = strlen( program);
  180. #else
  181.    len = 0;
  182. #endif
  183.    for( i = 1; i < argc; i++)
  184.       if( i == wherewasit)
  185.          len += strlen( outfile);
  186.       else
  187.          len += strlen( argv[ i]);
  188.  
  189.    len += strlen( outfile) + 1 + 2 + argc + 2;
  190.    p = nmalloc( len);
  191. #if OS == UNIX
  192.    strcpy( p, program);
  193. #else
  194.    *p = 0;
  195. #endif
  196.    for( i = 1; i < argc; i++)
  197.    {
  198.       if( i > 1)
  199.          strcat( p, " ");
  200.       if( i == wherewasit)
  201.          strcat( p, outfile);
  202.       else
  203.          strcat( p, argv[ i]);
  204.    }
  205.    strcat( p, " -_ ");
  206.    strcat( p, infile);
  207.    return( p);
  208. }
  209.