/* **********************************************************
 * *                                                        *
 * *  Function call to launch the sigrfopen exe             *
 * *  sigrfopen can either:                                 *
 * *   1. Read and write remote file                        *
 * *   2. Launch remote executables                         *
 * *                                                        *
 * **********************************************************
 * File: libs/config/sigrfopenFunc.c
 *
 *                      COPYRIGHT (c) 2001  BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 *
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */    
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sigtypes.h"
#include "config_lib.h" 
#include "user_lib.h" 


FILE *sigrfopen(const char *hostname_a, const char *path_a, const char *mode_a)
{
   char *bin_ptr;
   char cmd[100];
   FILE *fp = NULL;

   bin_ptr = getenv( "IRIS_BIN" );
   if (!bin_ptr)
   {
      sig_signal_va( USER_NO_ENV, 1, "IRIS_BIN" );
      return fp;        
   } 

   sprintf(cmd,"%ssigrfopen %s '%s' %s", bin_ptr, hostname_a, path_a, mode_a);
   if (!strcmp(mode_a,"r"))
      fp = popen(cmd, "r");
   else if (!strcmp(mode_a,"w"))
      fp = popen(cmd, "w");
   return fp;
}

FILE *sigrcmd(const char *hostname_a, const char *path_a)
{
   char *bin_ptr;
   char cmd[100];
   FILE *fp = NULL;

   bin_ptr = getenv( "IRIS_BIN" );
   if (!bin_ptr)
   {
      sig_signal_va( USER_NO_ENV, 1, "IRIS_BIN" );
      return fp;        
   } 

   sprintf(cmd,"%ssigrfopen %s -c '%s'", bin_ptr, hostname_a, path_a);
   fp = popen(cmd, "r");
   return fp;
}

void sigrclose(FILE *fp_a)
{
   pclose(fp_a);
}


