| 31 | } |
| 32 | |
| 33 | int main( const int argc, const char* const argv[] ) |
| 34 | { |
| 35 | const char* in_file_name= ""; |
| 36 | const char* out_file_name= ""; |
| 37 | |
| 38 | for( int i= 1; i < argc; i++ ) |
| 39 | { |
| 40 | const char* const arg= argv[i]; |
| 41 | if( std::strcmp( arg, "-i" ) == 0 ) |
| 42 | { |
| 43 | if( i < argc - 1 ) |
| 44 | in_file_name= argv[ i + 1 ]; |
| 45 | else |
| 46 | std::cout << "Error, expected file name, after -i" << std::endl; |
| 47 | } |
| 48 | else if( std::strcmp( arg, "-o" ) == 0 ) |
| 49 | { |
| 50 | if( i < argc - 1 ) |
| 51 | out_file_name= argv[ i + 1 ]; |
| 52 | else |
| 53 | std::cout << "Error, expected file name, after -o" << std::endl; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if( std::strlen( in_file_name ) == 0 ) |
| 58 | { |
| 59 | std::cout << "Error, no input file" << std::endl; |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | char out_file_name_buffer[ 1024 ]; |
| 64 | if( std::strlen( out_file_name ) == 0 ) |
| 65 | { |
| 66 | const int in_file_name_len= std::strlen( in_file_name ); |
| 67 | int i= in_file_name_len; |
| 68 | |
| 69 | while( i >= 0 && in_file_name[i] != '.' ) |
| 70 | i--; |
| 71 | |
| 72 | if( i >= 0 ) |
| 73 | { |
| 74 | std::memcpy( out_file_name_buffer, in_file_name, i + 1 ); |
| 75 | std::memcpy( out_file_name_buffer + i + 1, "tga", 4 ); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | std::memcpy( out_file_name_buffer, in_file_name, in_file_name_len ); |
| 80 | std::memcpy( out_file_name_buffer + in_file_name_len, ".tga", 5 ); |
| 81 | } |
| 82 | |
| 83 | out_file_name= out_file_name_buffer; |
| 84 | } |
| 85 | |
| 86 | std::FILE* file= std::fopen( in_file_name, "rb" ); |
| 87 | if( file == nullptr ) |
| 88 | { |
| 89 | std::cout << "Could not read file \"" << in_file_name << "\"" << std::endl; |
| 90 | return -1; |
nothing calls this directly
no test coverage detected