Exemplo n.º 1
0
/**
 * Checks one or more of the standard script search locations to locate the
 * specified file. If found, returns the discovered path to the script on
 * the top of the Lua stack.
 */
int premake_test_file(lua_State* L, const char* filename, int searchMask)
{
	if (searchMask & TEST_LOCAL) {
		if (do_isfile(filename)) {
			lua_pushcfunction(L, path_getabsolute);
			lua_pushstring(L, filename);
			lua_call(L, 1, 1);
			return OKAY;
		}
	}

	if (scripts_path && (searchMask & TEST_SCRIPTS)) {
		if (do_locate(L, filename, scripts_path)) return OKAY;
	}

	if (searchMask & TEST_PATH) {
		const char* path = getenv("PREMAKE_PATH");
		if (path && do_locate(L, filename, path)) return OKAY;
	}

	#if !defined(PREMAKE_NO_BUILTIN_SCRIPTS)
	if ((searchMask & TEST_EMBEDDED) != 0) {
		/* Try to locate a record matching the filename */
		if (premake_find_embedded_script(filename) != NULL) {
			lua_pushstring(L, "$/");
			lua_pushstring(L, filename);
			lua_concat(L, 2);
			return OKAY;
		}
	}
	#endif

	return !OKAY;
}
Exemplo n.º 2
0
/**
 * Checks one or more of the standard script search locations to locate the
 * specified file. If found, returns the discovered path to the script on
 * the top of the Lua stack.
 */
int premake_test_file(lua_State* L, const char* filename, int searchMask)
{
	int i;

	if (searchMask & TEST_LOCAL) {
		if (do_isfile(filename)) {
			lua_pushcfunction(L, path_getabsolute);
			lua_pushstring(L, filename);
			lua_call(L, 1, 1);
			return OKAY;
		}
	}

	if (scripts_path && (searchMask & TEST_SCRIPTS)) {
		if (do_locate(L, filename, scripts_path)) return OKAY;
	}

	if (searchMask & TEST_PATH) {
		const char* path = getenv("PREMAKE_PATH");
		if (path && do_locate(L, filename, path)) return OKAY;
	}

	if ((searchMask & TEST_EMBEDDED) != 0) {
		/* Try to locate a record matching the filename */
		for (i = 0; builtin_scripts_index[i] != NULL; ++i) {
			if (strcmp(builtin_scripts_index[i], filename) == 0) {
				lua_pushstring(L, "$/");
				lua_pushstring(L, filename);
				lua_concat(L, 2);
				return OKAY;
			}
		}
	}

	return !OKAY;
}
Exemplo n.º 3
0
int os_locate(lua_State* L)
{
	const char* path;
	int i;
	int nArgs = lua_gettop(L);

	/* Fetch premake.path */
	lua_getglobal(L, "premake");
	lua_getfield(L, -1, "path");
	path = lua_tostring(L, -1);

	for (i = 1; i <= nArgs; ++i) {
		const char* name = lua_tostring(L, i);

		/* Direct path to file? Return as absolute path */
		if (do_isfile(name)) {
			lua_pushcfunction(L, path_getabsolute);
			lua_pushvalue(L, i);
			lua_call(L, 1, 1);
			return 1;
		}

		/* do_locate(arg[i], premake.path) */
		if (do_locate(L, name, path)) {
			return 1;
		}

		/* embedded in the executable? */
		if (premake_find_embedded_script(name)) {
			lua_pushstring(L, "$/");
			lua_pushvalue(L, i);
			lua_concat(L, 2);
			return 1;
		}
	}

	return 0;
}
Exemplo n.º 4
0
/* Fm-Index Search MAIN */
int main(int argc, char *argv[]) {

	char * program_name = argv[0];
	char * filename, * extfilename = NULL;
	void *index;
	uchar * pattern;
	ulong nchars, position = 0;
	int unbuild, count, locate, extract, display, error;

	nchars = 10;	
	count = locate = extract = unbuild = display = 0;
	
	int next_option;
	const char* short_options = "hlce:s:d:n:";
	const struct option long_options[] = {
		{"help" , 		0,	NULL, 	'h'},
		{"locate",		0,	NULL,	'l'},
		{"count",		0,	NULL,	'c'},
		{"extract",		1,	NULL,	'e'},
		{"display",		1,	NULL,	's'},
		{"unbuild",		1,	NULL,	'd'},
		{"numchars",	1,	NULL,	'n'},
		{NULL,			0,	NULL,	0}
	 };
 
 	if(argc<3) print_usage(program_name);
	
		do { 
		next_option = getopt_long(argc, argv, short_options,
								  long_options, NULL);
		
		switch (next_option) {
			    
			case 'l': /* report position */
         		locate = 1; 
				break;
			
			case 's': /* display len chars sourronding each occ */
         		display = 1;
			    nchars = (ulong) atol(optarg); 
				break;
			
			case 'd': /* unbuild */
         		unbuild = 1;
			    extfilename = (char *) optarg;
				break;
			
	  		case 'e': /* extract */
		 		extract = 1;
				position = (ulong) atol(optarg); 
    	 		break;
			
			case 'c': /* count */
		 		count = 1;
    	 		break;
			
	  		case 'n': /* numchars for extract function */
				extract = 1;
		 		nchars = (ulong) atol(optarg); 
	  	 		break;

			case '?': /* The user specified an invalid option. */
        		fprintf(stderr,"Unknown option.\n");
        		print_usage(program_name);
				break;	
			
			case -1: /* Done with options. */
				break;
			
			default: 
				print_usage(program_name);
    	}
	}
	while (next_option != -1);
	
	if (optind == argc)  {	
		  	fprintf(stderr,"You must supply a pattern and a .fmi filename\n\n");
			print_usage(program_name);
     		exit(1);
    }
	
	/* priorita' extract display locate count */
	if(!(extract || unbuild)) /* pattern */ 
		pattern = (uchar *) argv[optind++];
	else pattern = NULL;
		
	if (optind == argc)  {	
		  	fprintf(stderr,"You must supply a pattern and a .fmi filename\n\n");
			print_usage(program_name);
     		exit(1);
    }
			
	filename = argv[optind];
	
	error = load_index (filename, &index);
	IFERROR (error);

	if (unbuild==1) 
		do_unbuild(index, extfilename);
	if (extract==1) 
		do_extract(index, position, nchars);
	if (display==1) 
		do_display(index, pattern, nchars);
	if (locate==1) 
		do_locate(index, pattern);
	
	do_count(index, pattern);
	exit(0);
}