#include "srfsh.h"
+int is_from_script = 0;
+
int main( int argc, char* argv[] ) {
/* --------------------------------------------- */
- if( argc < 2 ) {
+ /* see if they have a .srfsh.xml in their home directory */
+ char* home = getenv("HOME");
+ int l = strlen(home) + 36;
+ char fbuf[l];
+ memset(fbuf, 0, l);
+ sprintf(fbuf,"%s/.srfsh.xml",home);
- /* see if they have a .srfsh.xml in their home directory */
- char* home = getenv("HOME");
- int l = strlen(home) + 36;
- char fbuf[l];
- memset(fbuf, 0, l);
- sprintf(fbuf,"%s/.srfsh.xml",home);
+ if(!access(fbuf, R_OK)) {
+ if( ! osrf_system_bootstrap_client(fbuf) )
+ fatal_handler( "Unable to bootstrap client for requests");
+
+ } else {
+ fatal_handler( "No Config file found at %s", fbuf );
+ }
- if(!access(fbuf, R_OK)) {
- if( ! osrf_system_bootstrap_client(fbuf) )
- fatal_handler( "Unable to bootstrap client for requests");
+ if(argc > 1) {
+ /* for now.. the first arg is used as a script file for processing */
+ int f;
+ if( (f = open(argv[1], O_RDONLY)) == -1 )
+ fatal_handler("Unable to open file %s for reading, exiting...", argv[1]);
- } else {
- fatal_handler( "No Config file found at %s and none specified. "
- "\nusage: %s <config_file>", fbuf, argv[0] );
- }
+ if(dup2(f, STDIN_FILENO) == -1)
+ fatal_handler("Unable to duplicate STDIN, exiting...");
- } else {
- if( ! osrf_system_bootstrap_client(argv[1]) )
- fatal_handler( "Unable to bootstrap client for requests");
+ close(f);
+ is_from_script = 1;
}
+
/* --------------------------------------------- */
load_history();
history_file = strdup(fbuf);
if(!access(history_file, W_OK | R_OK )) {
- //set_history_length(999);
history_length = 999;
read_history(history_file);
}
signal(SIGPIPE, SIG_IGN);
- FILE* less = popen( "less -EX", "w");
+ FILE* less;
+ if(!is_from_script) less = popen( "less -EX", "w");
+ else less = stdout;
+
if( less == NULL ) { less = stdout; }
growing_buffer* resp_buffer = buffer_init(4096);