/* 
   Version 1.2							1997/1/10

   cfilebdyos2.c : This file is part of the alliance 3.0 patch for OS/2 & WIN32

   Copyright (C) 1996 Christoph Jaeschke, jaeschke@item.uni-bremen.de

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <process.h>
#include <string.h>
#include <stdlib.h>

#define FULLPATHLENGTH 2048
#define ALL_BIN "ALLIANCE_BIN"
int main (int argc, char *argv[]) {

  int i;
  int rc;
  char *found;
  char *all_bin_path;
  char *newargv[256];
  char nameBuffer[FULLPATHLENGTH]="";
  char *fullpath;

  for (i=0; i<argc+1; i++) {
    newargv[i+1]=argv[i];
#ifdef DEBUG
    printf("argno: %d, argstr: %s\n",i,newargv[i]);
#endif
  }
  found=strstr(strupr(argv[0]),".EXE");
  if (found != NULL) {
#ifdef DEBUG
    printf("with exe\n");
#endif
    strcpy(found,"\0");
  }
#ifdef EXPANDPATH
  all_bin_path = getenv(ALL_BIN);
  if (all_bin_path == NULL) {
#ifdef DEBUG
    printf("Environment Variable %s not set!\n",ALL_BIN);
#endif
    exit(1);
  } else {
    strcpy(nameBuffer, all_bin_path);
    strcat(nameBuffer, EXPANDPATH);
    strcat(nameBuffer, "/");
  }
#endif
  strcat(nameBuffer, EXECNAME);
#ifdef DEBUG
  for (i=0; i<argc+1; i++)
    printf("argno: %d, argstr: %s\n",i,newargv[i]);
#endif
  newargv[0]=EXECSHELL;
  newargv[1]=nameBuffer;
  rc = spawnvp(P_WAIT, EXECSHELL, &newargv[0]);
#ifdef DEBUG
  if (rc != 0)
  	printf("%s.exe : Error occured during execvp(%s, %s...)\n", EXECNAME, EXECSHELL, nameBuffer);
#endif
  return rc;
}