void Lookup_Test::test_remove_backslash_1() { uint errorc = 0; size_t charc = 0; char *word[][2] = { /// old, new { strdup ("\\"), (char *) "" }, { strdup ("\\a"), (char *) "a" }, { strdup ("\\a\\b\\c"), (char *) "abc" }, { strdup ("\\aa\\bb\\cc"), (char *) "aabbcc" }, }; size_t word_len[][2] = { /// old, new { 1, 1, }, { 2, 1 }, { 6, 3 }, { 9, 6 } }; for (uint idx = 0; idx < 3; idx++) { try { charc = remove_backslash (word[idx][0]); CPPUNIT_ASSERT (charc == word_len[idx][1]); CPPUNIT_ASSERT (Util::strEqu (word[idx][0], word[idx][1])); } CATCH_ERROR_PCHAR; } CPPUNIT_ASSERT (errorc == 0); for (uint idx = 0; idx < 4; idx++) { free (word[idx][0]); } }
int main( int argc, char *argv[] ) { Alias *aliases; char *cmd; int i; char *result; if ( argc > 1 ) { /* The first argument on the command line is usually the name of the file containing the aliases, which we read into memory. If however it is the string "-noalias", then we operate without any alias definitions. */ if ( strcmp( argv[1], "-noalias" ) == 0 ) { aliases = NULL; } else { aliases = read_alias_table( argv[1] ); } // print_aliases( aliases ); /* Gather up all the rest of the args into a single string as they form our command */ cmd = strdup( "" ); for ( i = 2; i < argc; i++ ) { cmd = append_dup_string( cmd, argv[i] ); cmd = append_dup_string( cmd, " " ); } /* If the command is enclosed in double quotes then remove the double quote from both ends. */ cmd = get_string_in_quotes( trim( cmd ) ); // fprintf( stderr, "Command is: %s\n", cmd ); result = dealias_command( cmd, aliases ); /* Any sub commands (contained in back ticks) may themselves contain aliases which need to be expanded. */ result = process_back_ticks( result, aliases ); /* Remove any quotes (") from the string, unless they are escaped with a backslash (\") */ result = remove_quotes( result ); /* Convert any occurence of "\!" into "!". */ result = remove_backslash( result, '!' ); printf( "%s\n", result ); free( result ); free( cmd ); } else { fprintf( stderr, "\nTake a tcsh alias table and a tcsh command and print the command after\n" ); fprintf( stderr, "alias substitution. The alias table can be created from within tcsh by:\n" ); fprintf( stderr, " alias > alias.txt\n\n" ); fprintf( stderr, "usage: %s <alias-table> <cmd args ...>\n", argv[0] ); } return 0; }