Skip to content

Commit

Permalink
Console Find_Orb and batch-mode 'fo' now accept a command-line switch…
Browse files Browse the repository at this point in the history
… to redirect output to a specified directory.
  • Loading branch information
Bill-Gray committed Nov 5, 2018
1 parent 1258bba commit 54d4484
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
31 changes: 18 additions & 13 deletions findorb.cpp
Expand Up @@ -2364,6 +2364,13 @@ int main( const int argc, const char **argv)
case 'n':
max_mpc_color_codes = atoi( arg);
break;
case 'O': /* write output files to specified dir */
{
extern const char *output_directory;

output_directory = arg;
}
break;
case 'o': /* obj designation / ephemeris from orbital */
break; /* elems: fall through, handle below */
case 'p':
Expand Down Expand Up @@ -3645,19 +3652,14 @@ int main( const int argc, const char **argv)
add_off_on = (observation_display & DISPLAY_ORBITAL_ELEMENTS);
clear( );
break;
case 'p':
if( element_precision < 15)
{
element_precision++;
update_element_display = 1;
}
break;
case 'P':
if( element_precision > 1)
{
case 'P': /* show one less digit of precision in elements */
case 'p': /* show one more digit of precision in elements */
if( c == 'P' && element_precision > 1)
element_precision--;
update_element_display = 1;
}
else if( c == 'p' && element_precision < 15)
element_precision++;
update_element_display = 1;
sprintf( message_to_user, "%d digits\n", element_precision);
break;
case CTRL( 'P'):
inquire( "Blunder probability: ", tbuff, sizeof( tbuff),
Expand Down Expand Up @@ -4481,7 +4483,10 @@ int main( const int argc, const char **argv)
case 9:
sort_obs_by_code = !sort_obs_by_code;
break;
case ALT_A: case ALT_P:
case ALT_P:
obs[curr_obs].flags ^= OBS_IS_SELECTED;
break;
case ALT_A:
case ALT_R: case ALT_X: case ALT_Y:
case ALT_Z: case '\'':
default:
Expand Down
7 changes: 7 additions & 0 deletions fo.cpp
Expand Up @@ -487,6 +487,13 @@ int main( const int argc, const char **argv)
case 'n':
starting_object = atoi( arg);
break;
case 'O': /* write output files to specified dir */
{
extern const char *output_directory;

output_directory = arg;
}
break;
case 'o': /* obj designation / ephemeris from orbital */
break; /* elems: fall through, handle below */
case 'p':
Expand Down
31 changes: 22 additions & 9 deletions miscell.cpp
Expand Up @@ -35,6 +35,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
int snprintf( char *string, const size_t max_len, const char *format, ...);
#endif

int snprintf_append( char *string, const size_t max_len, /* ephem0.cpp */
const char *format, ...)
#ifdef __GNUC__
__attribute__ (( format( printf, 3, 4)))
#endif
;

/* This function allows one to put the following options in front of
the 'permits' string :
Expand Down Expand Up @@ -98,7 +105,12 @@ void make_config_dir_name( char *oname, const char *iname)
therefore putting some temporary files (ephemerides, elements, etc.)
into the config directory ~/.find_orb. If that's happening, we ought
to put our temporary files elsewhere, in a directories of the form
/tmp/find_orb(process ID). */
/tmp/find_orb(process ID).
We can also deliberately put output files to a desired 'output_directory',
via command-line options. */

const char *output_directory = NULL;

FILE *fopen_ext( const char *filename, const char *permits)
{
Expand All @@ -112,7 +124,7 @@ FILE *fopen_ext( const char *filename, const char *permits)
#ifndef _WIN32
extern bool findorb_already_running;

is_temporary = findorb_already_running;
is_temporary = findorb_already_running || (output_directory != NULL);
#endif
permits++;
}
Expand All @@ -135,16 +147,17 @@ FILE *fopen_ext( const char *filename, const char *permits)
{
char tname[255];
static int process_id = 0;
const bool first_time = (process_id == 0);

if( !process_id)
{
if( first_time)
process_id = getpid( );
snprintf( tname, sizeof( tname),
"/tmp/find_orb%d", process_id);
if( output_directory)
strcpy( tname, output_directory);
else
snprintf( tname, sizeof( tname), "/tmp/find_orb%d", process_id);
if( first_time)
mkdir( tname, 0777);
}
snprintf( tname, sizeof( tname),
"/tmp/find_orb%d/%s", process_id, filename);
snprintf_append( tname, sizeof( tname), "/%s", filename);
rval = fopen( tname, permits);
}
#endif
Expand Down

0 comments on commit 54d4484

Please sign in to comment.