Пример #1
0
static void test_string_ends_with() {
	CU_ASSERT_TRUE(string_ends_with("MiArchivo.txt", "txt"));
	CU_ASSERT_TRUE(string_ends_with("MiArchivo.txt", "MiArchivo.txt"));
	CU_ASSERT_FALSE(string_ends_with("MiArchivo.doc", "txt"));
	CU_ASSERT_FALSE(string_ends_with("MiDoc", "txt"));
	CU_ASSERT_FALSE(string_ends_with("", "txt"));
}
Пример #2
0
static int check_is_unit_filename(const char *filename)
{
    return string_ends_with(filename, ".target") ||
           string_ends_with(filename, ".service") ||
           string_ends_with(filename, ".interface") ||
           string_ends_with(filename, ".route") ||
           string_ends_with(filename, ".mount");
}
Пример #3
0
static enum FileType get_file_type(const char * file) {
  if (string_ends_with(file, ".js")) {
    return FILE_TYPE_JS;
  }
  else if (string_ends_with(file, ".html") || string_ends_with(file, ".htm")) {
    return FILE_TYPE_HTML;
  }
  else {
    return FILE_TYPE_OTHER;
  }
}
Пример #4
0
void string_remove_suffix(caValue* s, const char* str)
{
    if (!string_ends_with(s, str))
        return;

    string_resize(s, string_length(s) - strlen(str));
}
Пример #5
0
 static ConfigFileFormat detect_file_format(const string& filename)
 {
     if (string_ends_with(filename, ".ini"))
     {
         return CONFIG_FORMAT_INI;
     }
     else if (string_ends_with(filename, ".xml"))
     {
         return CONFIG_FORMAT_XML;
     }
     else if (string_ends_with(filename, ".json"))
     {
         return CONFIG_FORMAT_JSON;
     }
     else
     {
         return CONFIG_FORMAT_INFO;
     }
 }
Пример #6
0
char* depurarSentencia(char* sentencia){

		int i = strlen(sentencia);
		while (string_ends_with(sentencia, "\n")) {
			i--;
			sentencia = string_substring_until(sentencia, i);
		}
		return sentencia;

}
Пример #7
0
bool test_file_directory_current_path (Test *test)
{
	char *path;

	TITLE ();
	CATCH (!string_ends_with ((path = directory_current_path ()), "/project.m/app.test.lib.core"));
	string_destroy (path);
	CATCH (!file_path_is_valid ((path = directory_current_path ())));
	string_destroy (path);
	PASS ();
}
Пример #8
0
struct processor *processor_soffice_search(void *context,
                                               const char *filename)
{
    struct processor_soffice *p;

    p = NULL;

    if (string_ends_with(filename, ".odg.pdf")) {
        p = talloc(context, struct processor_soffice);
        p->p.name = talloc_reference(p, p_name);
        p->p.process = &process;
    }
Пример #9
0
BOOL is_always_skipped(char* filename)
{
    int   i;

    char *skip;

    for (i = 0; g_global_skip_list[i] != 0; i++) {
        skip = g_global_skip_list[i];
        if (string_ends_with(filename, skip)) {
            return TRUE;
        }
    }
    return FALSE;
}
Пример #10
0
struct processor *processor_svgtex_search(void *context, const char *filename)
{
    struct processor_svgtex *p;

    p = NULL;

    if (string_ends_with(filename, ".svgtex.stex"))
        p = talloc(context, struct processor_svgtex);

    if (p != NULL) {
        p->p.name = talloc_reference(p, p_name);
        p->p.process = &process;
    }

    return (struct processor *)p;
}
Пример #11
0
struct processor *processor_pdfcrop_search(void *context,
                                           const char *filename)
{
    struct processor_pdfcrop *p;

    p = NULL;

    if (string_ends_with(filename, ".uncrop.pdf.pdf"))
        p = talloc(context, struct processor_pdfcrop);

    if (p != NULL) {
        p->p.name = talloc_reference(p, p_name);
        p->p.process = &process;
    }

    return (struct processor *)p;
}
Пример #12
0
void find_dll_for_script(Branch* branch, caValue* resultOut)
{
    String* filename = (String*) branch_get_source_filename(branch);

    if (!is_string(filename)) {
        set_name(resultOut, name_Failure);
        return;
    }

    String dllFilename;
    copy(filename, &dllFilename);

    if (string_ends_with(&dllFilename, ".ca"))
        string_resize(&dllFilename, -3);

    //string_append(&dllFilename, DLL_SUFFIX);
    swap(&dllFilename, resultOut);
}
Пример #13
0
Language Manager::detectLanguage(std::string path, std::string& content) {
    
    for (Language& lang : langs) {
        for (std::string& ext : lang.extensions) {
            std::string dot_ext = std::string(".") + ext;
            if (string_ends_with(path, dot_ext))
                return lang;
        }
    }
    
    for (Language& lang : langs) {
        if (lang.name == path) {
            return lang;
        }
    }
    
    return Language();
}
Пример #14
0
// ----------------------------------------------------------------
static char * test_starts_or_ends_with() {

	mu_assert_lf(string_starts_with("abcde", ""));
	mu_assert_lf(string_starts_with("abcde", "a"));
	mu_assert_lf(string_starts_with("abcde", "abcd"));
	mu_assert_lf(string_starts_with("abcde", "abcde"));
	mu_assert_lf(!string_starts_with("abcde", "abcdef"));

	mu_assert_lf(string_ends_with("abcde", "", NULL));
	mu_assert_lf(string_ends_with("abcde", "e", NULL));
	mu_assert_lf(string_ends_with("abcde", "de", NULL));
	mu_assert_lf(string_ends_with("abcde", "abcde", NULL));
	mu_assert_lf(!string_ends_with("abcde", "0abcde", NULL));
	int len = -1;
	mu_assert_lf(!string_ends_with("abcde", "0abcde", &len));
	mu_assert_lf(len == 5);

	return 0;
}
Пример #15
0
/** Reads the command received and excecutes the corrisponding process sending it it's arguments and 
also responds to special characters.*/
int process_input(const char * input, int tty_number) { 

	int  piped = 0;
	char file_call_buffer[1024];
	char stdout_call_buffer[128];
	char stdin_call_buffer[128];
	
	int stdout_file = 0;
	int stdin_file = 0;
	int read_ptr = 0;
	int stdin = 0;
	int stdout = 0;
	do {
		int i = 0;
		int write_i = 0;
		for(; i < 128; ++i) {
			stdout_call_buffer[i] = 0;
			stdin_call_buffer[i]  = 0;
		}

		for(i = 0; i < 1024; ++i)	{
			file_call_buffer[i] = 0;
		}
		i = read_ptr;
		
		char * file_call;

		
		int valid_input = 0;
		char * current_buffer = file_call_buffer;
		for(; input[i] && input[i] != '|'; ++i) {
			if(strlen(current_buffer) > 0 ) {
				if(input[i] == '>') {
					current_buffer = stdout_call_buffer;
					valid_input = 0;
					write_i = 0;
					stdout_file = 1;

					continue;
				} else if (input[i] == '<') { 
					current_buffer = stdin_call_buffer;
					valid_input = 0;
					write_i = 0;
					stdin_file = 1;
					continue;
				}
			} else {
				if (input[i] == '>' || input[i] == '<') {
					return 0;
				}
			}
			valid_input = input[i] != ' ';
			if(!(write_i == 0 && !valid_input)) {
				current_buffer[write_i++] = input[i];
			}
		}
		if(i == 0 && input[i] == '|') {
			return 0;
		}
		piped = (input[i] == '|') && !stdin_file && !stdout_file; 
		i++;
		
		if(piped)
		{
			read_ptr = i;
		}
		
		int n = 0;
		char** strs = split_string(file_call_buffer, ' ', &n);
		
		
		int pid = pcreate(strs[0], n, strs);
		
		if(pid != -1)
		{
			if(stdout_file) {
				int _stdout = open(stdout_call_buffer, O_WR | O_NEW);
				if(_stdout >= 0)
				{
					pdup2(pid, _stdout, STDOUT);
 				} else {
					printf("TTY: file %s could not be opened for output, invalid perms?\n", stdout_call_buffer);
				}
			}
			
			if(stdin_file) {
				int _stdin = open(stdin_call_buffer, O_RD);
				if(_stdin >= 0)
				{
					pdup2(pid, _stdin, STDIN);
				} else {
					printf("TTY: file %s could not be opened for input, invalid perms?\n", stdin_call_buffer);
				}

			}
			
			// For pipe
			if(stdin)	{
				pdup2(pid, stdin, STDIN);
			}
			char cad[20];
			if(piped)
			{
				cad[0] = '.';
				itoa(pid, cad + 1);
				stdout = mkfifo(cad, 0600);
				pdup2(pid,stdout,STDOUT);
				stdin = stdout;
				stdout = 0;
			}
			
			prun(pid);
			if(!string_ends_with(file_call_buffer, '&') && !piped) {
				waitpid(pid);
				rm(cad);
			}
		}
	} while(piped);
	return 1;
}
Пример #16
0
void test_string() {
  constexpr size_t NUM_STRINGS = 1024;

  std::vector<std::string> strings(NUM_STRINGS);
  std::vector<grnxx::String> refs(NUM_STRINGS);
  std::vector<grnxx::String> bodies(NUM_STRINGS);
  for (size_t i = 0; i < NUM_STRINGS; ++i) {
    std::stringstream stream;
    stream << i;
    strings[i] = stream.str();
    refs[i] = grnxx::String(strings[i].data(), strings[i].size());
    assert(refs[i].is_reference());
    bodies[i].assign(refs[i]);
    assert(bodies[i].is_instance());
  }

  for (size_t i = 0; i < NUM_STRINGS; ++i) {
    assert(bodies[i].size() == static_cast<size_t>(strings[i].size()));
    for (size_t j = 0; j < bodies[i].size(); ++j) {
      assert(bodies[i][j] == strings[i][j]);
    }

    for (size_t j = 0; j < NUM_STRINGS; ++j) {
      assert((bodies[i] == bodies[j]) == (strings[i] == strings[j]));
      assert((bodies[i] != bodies[j]) == (strings[i] != strings[j]));
      assert((bodies[i] < bodies[j]) == (strings[i] < strings[j]));
      assert((bodies[i] > bodies[j]) == (strings[i] > strings[j]));
      assert((bodies[i] <= bodies[j]) == (strings[i] <= strings[j]));
      assert((bodies[i] >= bodies[j]) == (strings[i] >= strings[j]));

      assert((bodies[i] == refs[j]) == (strings[i] == strings[j]));
      assert((bodies[i] != refs[j]) == (strings[i] != strings[j]));
      assert((bodies[i] < refs[j]) == (strings[i] < strings[j]));
      assert((bodies[i] > refs[j]) == (strings[i] > strings[j]));
      assert((bodies[i] <= refs[j]) == (strings[i] <= strings[j]));
      assert((bodies[i] >= refs[j]) == (strings[i] >= strings[j]));

      assert((bodies[i] == strings[j].c_str()) == (strings[i] == strings[j]));
      assert((bodies[i] != strings[j].c_str()) == (strings[i] != strings[j]));
      assert((bodies[i] < strings[j].c_str()) == (strings[i] < strings[j]));
      assert((bodies[i] > strings[j].c_str()) == (strings[i] > strings[j]));
      assert((bodies[i] <= strings[j].c_str()) == (strings[i] <= strings[j]));
      assert((bodies[i] >= strings[j].c_str()) == (strings[i] >= strings[j]));

      assert((refs[i] == bodies[j]) == (strings[i] == strings[j]));
      assert((refs[i] != bodies[j]) == (strings[i] != strings[j]));
      assert((refs[i] < bodies[j]) == (strings[i] < strings[j]));
      assert((refs[i] > bodies[j]) == (strings[i] > strings[j]));
      assert((refs[i] <= bodies[j]) == (strings[i] <= strings[j]));
      assert((refs[i] >= bodies[j]) == (strings[i] >= strings[j]));

      assert((strings[i].c_str() == bodies[j]) == (strings[i] == strings[j]));
      assert((strings[i].c_str() != bodies[j]) == (strings[i] != strings[j]));
      assert((strings[i].c_str() < bodies[j]) == (strings[i] < strings[j]));
      assert((strings[i].c_str() > bodies[j]) == (strings[i] > strings[j]));
      assert((strings[i].c_str() <= bodies[j]) == (strings[i] <= strings[j]));
      assert((strings[i].c_str() >= bodies[j]) == (strings[i] >= strings[j]));

      assert(bodies[i].starts_with(bodies[j]) ==
             string_starts_with(strings[i], strings[j]));
      assert(bodies[i].starts_with(strings[j].c_str()) ==
             string_starts_with(strings[i], strings[j]));
      assert(bodies[i].ends_with(bodies[j]) ==
             string_ends_with(strings[i], strings[j]));
      assert(bodies[i].ends_with(strings[j].c_str()) ==
             string_ends_with(strings[i], strings[j]));
    }
  }

  for (size_t i = 0; i < NUM_STRINGS; ++i) {
    std::stringstream stream;
    stream << (i / 2.0);
    std::string extra_string = stream.str();
    strings[i].append(extra_string);
    bodies[i].append(extra_string.data(), extra_string.size());
    assert(bodies[i] == grnxx::String(strings[i].data(), strings[i].size()));
  }

  for (size_t i = 0; i < NUM_STRINGS; ++i) {
    strings[i].append(strings[i]);
    bodies[i].append(bodies[i]);
    assert(std::string(bodies[i].data(), bodies[i].size()) == strings[i]);
  }
}
Пример #17
0
void String__ends_with(caStack* stack)
{
    set_bool(circa_output(stack, 0), string_ends_with(circa_input(stack, 0), as_cstring(circa_input(stack, 1))));
}
Пример #18
0
void config_load( const char* name, hash_t filter_section, bool built_in, bool overwrite )
{
	/*lint --e{838} Safety null assign all pointers for all preprocessor paths */
	/*lint --e{750} Unused macros in some paths */
#define NUM_SEARCH_PATHS 10
#define ANDROID_ASSET_PATH_INDEX 5
	char* sub_exe_path = 0;
	char* exe_parent_path = 0;
	char* exe_processed_path = 0;
	char* abs_exe_parent_path = 0;
	char* abs_exe_processed_path = 0;
	char* bundle_path = 0;
	char* home_dir = 0;
	char* cmdline_path = 0;
	char* cwd_config_path = 0;
	const char* paths[NUM_SEARCH_PATHS];
#if !FOUNDATION_PLATFORM_FAMILY_MOBILE
	const char* const* cmd_line;
	int icl, clsize;
#endif
	int start_path, i, j;

	const char buildsuffix[4][9] = { "/debug", "/release", "/profile", "/deploy" };
	const char platformsuffix[7][14] = { "/win32", "/win64", "/osx", "/ios", "/android", "/raspberrypi", "/unknown" };
	const char binsuffix[1][5] = { "/bin" };

	FOUNDATION_ASSERT( name );

	sub_exe_path = path_merge( environment_executable_directory(), "config" );
	exe_parent_path = path_merge( environment_executable_directory(), "../config" );
	abs_exe_parent_path = path_make_absolute( exe_parent_path );

	exe_processed_path = string_clone( environment_executable_directory() );
	for( i = 0; i < 4; ++i )
	{
		if( string_ends_with( exe_processed_path, buildsuffix[i] ) )
		{
			exe_processed_path[ string_length( exe_processed_path ) - string_length( buildsuffix[i] ) ] = 0;
			break;
		}
	}
	for( i = 0; i < 7; ++i )
	{
		if( string_ends_with( exe_processed_path, platformsuffix[i] ) )
		{
			exe_processed_path[ string_length( exe_processed_path ) - string_length( platformsuffix[i] ) ] = 0;
			break;
		}
	}
	for( i = 0; i < 1; ++i )
	{
		if( string_ends_with( exe_processed_path, binsuffix[i] ) )
		{
			exe_processed_path[ string_length( exe_processed_path ) - string_length( binsuffix[i] ) ] = 0;
			break;
		}
	}
	exe_processed_path = path_append( exe_processed_path, "config" );
	abs_exe_processed_path = path_make_absolute( exe_processed_path );
	
	paths[0] = environment_executable_directory();
	paths[1] = sub_exe_path;
	paths[2] = abs_exe_parent_path;
	paths[3] = abs_exe_processed_path;

#if FOUNDATION_PLATFORM_FAMILY_DESKTOP && !BUILD_DEPLOY
	paths[4] = environment_initial_working_directory();
#else
	paths[4] = 0;
#endif

#if FOUNDATION_PLATFORM_APPLE
	bundle_path = path_merge( environment_executable_directory(), "../Resources/config" );
	paths[5] = bundle_path;
#elif FOUNDATION_PLATFORM_ANDROID
	paths[5] = "/config";
#else
	paths[5] = 0;
#endif

#if FOUNDATION_PLATFORM_FAMILY_DESKTOP
	paths[6] = environment_current_working_directory();
#else
	paths[6] = 0;
#endif

	paths[7] = 0;
	paths[8] = 0;

	string_deallocate( exe_parent_path );
	string_deallocate( exe_processed_path );

#if FOUNDATION_PLATFORM_FAMILY_DESKTOP
	cwd_config_path = path_merge( environment_current_working_directory(), "config" );
	paths[7] = cwd_config_path;

	cmd_line = environment_command_line();
	/*lint -e{850} We modify loop var to skip extra arg */
	for( icl = 0, clsize = array_size( cmd_line ); icl < clsize; ++icl )
	{
		/*lint -e{613} array_size( cmd_line ) in loop condition does the null pointer guard */
		if( string_equal_substr( cmd_line[icl], "--configdir", 11 ) )
		{
			if( string_equal_substr( cmd_line[icl], "--configdir=", 12 ) )
			{
				paths[8] = cmdline_path = string_substr( cmd_line[icl], 12, STRING_NPOS );
			}
			else if( icl < ( clsize - 1 ) )
			{
				paths[8] = cmdline_path = string_clone( cmd_line[++icl] );
			}
		}
	}
#endif
	
	start_path = 0;
	if( !built_in )
	{
#if FOUNDATION_PLATFORM_WINDOWS
		home_dir = path_merge( environment_home_directory(), environment_application()->config_dir );
#elif FOUNDATION_PLATFORM_LINUX || FOUNDATION_PLATFORM_MACOSX
		home_dir = path_prepend( string_concat( ".", environment_application()->config_dir ), environment_home_directory() );
#endif
		if( home_dir )
			paths[9] = home_dir;
		start_path = 9;
	}
	else
	{
		paths[9] = 0;
	}

	for( i = start_path; i < NUM_SEARCH_PATHS; ++i )
	{
		char* filename;
		stream_t* istream;
		bool path_already_searched = false;

		if( !paths[i] )
			continue;

		for( j = start_path; j < i; ++j )
		{
			if( paths[j] && string_equal( paths[j], paths[i] ) )
			{
				path_already_searched = true;
				break;
			}
		}
		if( path_already_searched )
			continue;
		
		//TODO: Support loading configs from virtual file system (i.e in zip/other packages)
		filename = string_append( path_merge( paths[i], name ), ".ini" );
		istream = 0;
#if FOUNDATION_PLATFORM_ANDROID
		if( i == ANDROID_ASSET_PATH_INDEX )
			istream = asset_stream_open( filename, STREAM_IN );
		else
#endif
		istream = stream_open( filename, STREAM_IN );
		if( istream )
		{
			config_parse( istream, filter_section, overwrite );
			stream_deallocate( istream );
		}
		string_deallocate( filename );

		if( built_in )
		{
			const char* FOUNDATION_PLATFORM_name =
#if FOUNDATION_PLATFORM_WINDOWS
				"windows";
#elif FOUNDATION_PLATFORM_LINUX_RASPBERRYPI
				"raspberrypi";
#elif FOUNDATION_PLATFORM_LINUX
				"linux";
#elif FOUNDATION_PLATFORM_MACOSX
				"osx";
#elif FOUNDATION_PLATFORM_IOS
				"ios";
#elif FOUNDATION_PLATFORM_ANDROID
				"android";
#else
#  error Insert platform name
				"unknown";
#endif
			filename = string_append( path_append( path_merge( paths[i], FOUNDATION_PLATFORM_name ), name ), ".ini" );
#if FOUNDATION_PLATFORM_ANDROID
			if( i == ANDROID_ASSET_PATH_INDEX )
				istream = asset_stream_open( filename, STREAM_IN );
			else
#endif
			istream = stream_open( filename, STREAM_IN );
			if( istream )
			{
				config_parse( istream, filter_section, overwrite );
				stream_deallocate( istream );
			}
			string_deallocate( filename );
		}
	}

	string_deallocate( home_dir );
	string_deallocate( cmdline_path );
	string_deallocate( sub_exe_path );
	string_deallocate( abs_exe_processed_path );
	string_deallocate( abs_exe_parent_path );
	string_deallocate( bundle_path );
	string_deallocate( cwd_config_path );
}
Пример #19
0
int string_ends_with_string(String* source, String* suffix) {
	return string_ends_with(source, suffix->string);
}