#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

#define TASMP ""
#define VER "1.0"



void main(int argc, char *argv[])
{int i=0, name_f=0, run=0, debug=0, com=0;
 char name[30], cmd[100];
 FILE *F;


 if(argc > 1) {

  printf("Try to compile: %s\n", argv[1]);

  for(i=0; i <= argc; i++)
  {
   //printf("argv[i]:%s argv[i][0]:%c\n",argv[i], argv[i][0]);
   if(argv[i][0] == '/')
   {
    if(argv[i][1] == '?' || argv[i][1] == 'h') {
     printf("Compile helper v"VER"\n /h|? - help\n /d - run debuger\n /r - run\n /t - com file\n");
     return; }
    if(argv[i][1] == 'd') {
     debug = 1;
    }
    if(argv[i][1] == 'r') {
     run = 1;
    }
    if(argv[i][1] == 't') {
     com = 1;
    }
   }
  }

  for(i=0; i < strlen(argv[1]) && i < 30; i++)
  {
   if(argv[1][i] == '.')
   {
    name_f=1;
    name[i] = '\0';
    break;

   }

   name[i]=argv[1][i];
  }

  sprintf(cmd, TASMP"TASM.EXE /l /zi %s.asm", name);
  system(cmd);
  if(com == 0)
   sprintf(cmd, TASMP"TLINK.EXE /v /l /m %s.obj", name);
  else
   sprintf(cmd, TASMP"TLINK.EXE /t /v /l /m %s.obj", name);
  
  system(cmd);



  if(debug == 1) {
   if(com == 0)
    sprintf(cmd, TASMP"TD.EXE %s.exe", name);
   else
    sprintf(cmd, TASMP"TD.EXE %s.com", name);
   system(cmd);
  }
  else if(run == 1) {
   if(com == 0)
    sprintf(cmd, TASMP"%s.exe", name);
   else
    sprintf(cmd, TASMP"%s.com", name);
   system(cmd);
  }
 }
 return;
}