
/*
**      $Application name : EnterEnv $
**      $Revision : 1.2 $
**      $Release : 1.02 $
**      $Date : 92/10/30 $
**
**
**
**      (C) Copyright 1992 David Scrève
**          All Rights Reserved
*/

/* this software was compiled with SAS/C 5.10b Compiler. */
/* to Recompile this C source code, you need the include V37 or higher */
/* Contact the Commodore Amiga Technical Support for more information */

#include <stdio.h>
#include "dos/dos.h"

struct FileHandle *my_Handle;
struct Library *DosBase,*OpenLibrary();

void DOAction(ArgVector,ArgNumber)
char **ArgVector;
int ArgNumber;
{
 char my_text[256];
 char EnvValue[256]=" ";
 LONG Resultat;

 strcpy(my_text,"env:");
 strcat(my_text,*ArgVector);
 if (DosBase=(struct Library *)OpenLibrary("dos.library",37L))
     {
      my_Handle=(struct FileHandle *)Open(&my_text[0],MODE_NEWFILE);
      if (my_Handle!=NULL)
          {
           if (ArgNumber==3)
               {
                ArgVector++;
                printf("\n%s",*ArgVector);
               }
           gets(&EnvValue[0]);
           Resultat=Write(my_Handle,&EnvValue[0],strlen(EnvValue));
           if (Resultat==-1)
                printf("\nUne Erreur d'écriture s'est produite.\n");
           Close(my_Handle);
          }
        else
          printf("\nImpossible d'ouvrir le fichier.\n");
       CloseLibrary(DosBase);
      }
    else
     printf("\n La Dos.library Version 37 m'est vitale. Je meurs...\n");
}

void WriteMessage()
{
 printf("\nEnterEnv Release 1.02 By David Scrève. CopyRight © 1992");
 printf("\nAll Rights Reserved.\n");
 printf("\nThis Software is freely distributable with the complete package.\n");
 printf("\nSyntax : EnterEnv <Name of the Env Variable> [<Text message>]\n\n");
}


main(argc,argv)
int argc;
char **argv;
{
 argv++;
 if (argc==1 || (argc==2 && ((**argv)=='h' || (**argv)=='H' || (**argv)=='?')))
      WriteMessage();
     else
      DOAction(argv,argc);
}
