Skip to content

Commit

Permalink
[#433,irods/irods#8122] Use more C++ in ienv, ierror, ipwd
Browse files Browse the repository at this point in the history
  • Loading branch information
SwooshyCueb authored and alanking committed Jan 30, 2025
1 parent a971eb0 commit 1fae6c0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
32 changes: 12 additions & 20 deletions src/ienv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@
#include <irods/rodsClient.h>
#include <irods/parseCommandLine.h>

#include <cstdlib>
#include <iostream>

void usage();

int
main( int argc, char **argv ) {
signal( SIGPIPE, SIG_IGN );

char* optStr = "h";
rodsArguments_t myRodsArgs;
int status = parseCmdLineOpt( argc, argv, optStr, 0, &myRodsArgs );

int status = parseCmdLineOpt(argc, argv, "h", 0, &myRodsArgs);

if ( status < 0 ) {
printf( "Use -h for help\n" );
exit( 1 );
std::cout << "Use -h for help" << std::endl;
std::exit(1);
}

if ( myRodsArgs.help == True ) {
usage();
exit( 0 );
std::exit(0);
}

rodsLog( LOG_NOTICE, "Release Version = %s, API Version = %s",
Expand All @@ -34,28 +37,17 @@ main( int argc, char **argv ) {

if ( status < 0 ) {
rodsLogError( LOG_ERROR, status, "main: getRodsEnv error. " );
exit( 1 );
std::exit(1);
}

return 0;
}

void
usage() {
char *msgs[] = {
"Usage: ienv [-h]",
"Display current irods environment. Equivalent to iinit -l.",
"Options are:",
" -h this help",
""
};
int i;
for ( i = 0;; i++ ) {
if ( strlen( msgs[i] ) == 0 ) {
break;
}
printf( "%s\n", msgs[i] );
}
std::cout << "Displays current irods environment. Equivalent to iinit -l.\n"
<< "Usage: ienv [-h]\n"
<< " -h this help" << std::endl;
printReleaseInfo( "ienv" );
}

Expand Down
25 changes: 15 additions & 10 deletions src/ierror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <irods/parseCommandLine.h>
#include <irods/rcMisc.h>

#include <cstdlib>
#include <cstring>
#include <iostream>

void usage( char *prog );

int
Expand All @@ -13,34 +17,35 @@ main( int argc, char **argv ) {
signal( SIGPIPE, SIG_IGN );

if ( argc != 2 ) {
printf( "Use -h for help\n" );
std::cout << "Use -h for help" << std::endl;
return 1;
}

if ( strcmp( argv[1], "-h" ) == 0 ) {
if (std::strcmp(argv[1], "-h") == 0) {
usage( argv[0] );
return 0;
}

int errorCode = atoi( argv[1] );
int errorCode = std::atoi(argv[1]);

if ( errorCode > 0 ) {
errorCode = -errorCode;
}

char *mySubErrName = NULL;
const char *myErrName = rodsErrorName( errorCode, &mySubErrName );
printf( "irods error: %d %s %s\n",
errorCode, myErrName, mySubErrName );
free( mySubErrName );

std::cout << "irods error: " << errorCode << ' ' << myErrName << ' ' << mySubErrName << std::endl;

std::free(mySubErrName);
return 0;
}


void usage( char *prog ) {
printf( "Converts an irods error code to text.\n" );
printf( "Usage: %s [-vVh] errorNumber\n", prog );
printf( "The errorNumber can be preceeded with minus sign (-) or not\n" );
printf( " -h this help\n" );
std::cout << "Converts an irods error code to text.\n"
<< "Usage: " << prog << " [-vVh] errorNumber\n"
<< "The errorNumber can be preceded with minus sign (-) or not\n"
<< " -h this help" << std::endl;
printReleaseInfo( "ierror" );
}
25 changes: 13 additions & 12 deletions src/ipwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <irods/rodsPath.h>

#include <cstdlib>
#include <iostream>

void usage( char *prog );

Expand All @@ -20,35 +21,35 @@ main( int argc, char **argv ) {

status = parseCmdLineOpt( argc, argv, "vVh", 0, &myRodsArgs );
if ( status ) {
printf( "Use -h for help\n" );
exit( 1 );
std::cout << "Use -h for help" << std::endl;
std::exit(1);
}

if ( myRodsArgs.help == True ) {
usage( argv[0] );
exit( 0 );
std::exit(0);
}

status = getRodsEnv( &myEnv );
if ( status != 0 ) {
printf( "Failed with error %d\n", status );
exit( 2 );
std::cout << "Failed with error " << status << std::endl;
std::exit(2);
}

auto* path = escape_path(myEnv.rodsCwd);

printf("%s\n", path);
std::cout << path << std::endl;

std::free(path);

exit( 0 );
std::exit(0);
}

void usage( char *prog ) {
printf( "Shows your iRODS Current Working Directory.\n" );
printf( "Usage: %s [-vVh]\n", prog );
printf( " -v verbose\n" );
printf( " -V very verbose\n" );
printf( " -h this help\n" );
std::cout << "Shows your iRODS Current Working Directory.\n"
<< "Usage: " << prog << " [-vVh]\n"
<< " -v verbose\n"
<< " -V very verbose\n"
<< " -h this help" << std::endl;
printReleaseInfo( "ipwd" );
}

0 comments on commit 1fae6c0

Please sign in to comment.