Beispiel #1
0
static int glob_tostring(lua_State *L) {
	struct _fileglob* glob = *(struct _fileglob**)(lua_touserdata(L, 1));
	fileglob_uint64 filetime;
	char buffer[100];
	int top;
	if (!glob) {
		lua_pushstring(L, "[glob object]: done");
		return 1;
	}

	top = lua_gettop(L);
	lua_pushstring(L, "[glob object]: filename = \"");
	lua_pushstring(L, fileglob_FileName(glob));
	lua_pushstring(L, "\"");
	sprintf(buffer, ", creation_time = %lld", fileglob_CreationTime(glob));
	lua_pushstring(L, buffer);
	sprintf(buffer, ", access_time = %lld", fileglob_AccessTime(glob));
	lua_pushstring(L, buffer);
	sprintf(buffer, ", write_time = %lld", fileglob_WriteTime(glob));
	lua_pushstring(L, buffer);
	filetime = fileglob_CreationFILETIME(glob);
	sprintf(buffer, ", creation_FILETIME = { %u, %u }", (unsigned int)(filetime & 0xffffffff), (unsigned int)(filetime >> 32));
	lua_pushstring(L, buffer);
	filetime = fileglob_AccessFILETIME(glob);
	sprintf(buffer, ", access_FILETIME = { %u, %u }", (unsigned int)(filetime & 0xffffffff), (unsigned int)(filetime >> 32));
	lua_pushstring(L, buffer);
	filetime = fileglob_WriteFILETIME(glob);
	sprintf(buffer, ", write_FILETIME = { %u, %u }", (unsigned int)(filetime & 0xffffffff), (unsigned int)(filetime >> 32));
	lua_pushstring(L, buffer);
	sprintf(buffer, ", size = %lld", fileglob_FileSize(glob));
	lua_pushstring(L, buffer);
	sprintf(buffer, ", is_directory = %s", fileglob_IsDirectory(glob) ? "true" : "false");
	lua_pushstring(L, buffer);
	sprintf(buffer, ", is_link = %s", fileglob_IsLink(glob) ? "true" : "false");
	lua_pushstring(L, buffer);
	sprintf(buffer, ", is_readonly = %s", fileglob_IsReadOnly(glob)? "true" : "false");
	lua_pushstring(L, buffer);
	sprintf(buffer, ", number_of_links = %lld", fileglob_NumberOfLinks(glob));
	lua_pushstring(L, buffer);
	lua_concat(L, lua_gettop(L) - top);
	return 1;
}
Beispiel #2
0
static int glob_index_size_helper(lua_State* L, struct _fileglob* glob) {
	lua_pushnumber(L, (lua_Number)ui64ToDouble(fileglob_FileSize(glob)));
	return 1;
}
Beispiel #3
0
int main (int argc, char **argv) {
	int i, argn;
	int verbose = 0;

	if (argc == 1)
		Usage();

	for (argn = 1; argn < argc; ++argn) {
		char* arg = argv[argn];
		if (arg[0] != '-')
			break; // Filenames from here on.

		if (strcmp(arg, "-?") == 0) {
			Usage();
		}

		if (strcmp(arg, "-v") == 0) {
			verbose = 1;
		}

		if (strcmp(arg, "-vv") == 0) {
			verbose = 2;
		}
	}

	for (; argn < argc; ++argn) {
		fileglob* glob;
		char path[1000];
		char* startPath = path;
		strcpy(path, argv[argn]);
		if (*startPath == '\''  &&  startPath[strlen(startPath) - 1] == '\'') {
			startPath++;
			startPath[strlen(startPath) - 1] = 0;
		}
		glob = fileglob_Create(startPath);
        
		for (i = 1; i < argn; ++i) {
			char* arg = argv[i];

			if (strcmp(arg, "-e") == 0) {
				++i;
				fileglob_AddExclusivePattern(glob, argv[i]);
			}
			else if (strcmp(arg, "-i") == 0) {
				i++;
				fileglob_AddIgnorePattern(glob, argv[i]);
			}
		}

		while (fileglob_Next(glob)) {
			const char* filename = fileglob_FileName(glob);
			if (verbose) {
				fileglob_uint64 creationTime = fileglob_CreationTime(glob);
				fileglob_uint64 accessTime = fileglob_AccessTime(glob);
				fileglob_uint64 writeTime = fileglob_WriteTime(glob);
				fileglob_uint64 creationFILETIME = fileglob_CreationFILETIME(glob);
				fileglob_uint64 accessFILETIME = fileglob_AccessFILETIME(glob);
				fileglob_uint64 writeFILETIME = fileglob_WriteFILETIME(glob);
				fileglob_uint64 fileSize = fileglob_FileSize(glob);
				int isDirectory = fileglob_IsDirectory(glob);
				int isLink = fileglob_IsLink(glob);
				int isReadOnly = fileglob_IsReadOnly(glob);
				const char* permissions = fileglob_Permissions(glob);
				if (verbose == 1) {
					printf("%s - creationTime=%llu, accessTime=%llu, writeTime=%llu, creationFILETIME=%llu, accessFILETIME=%llu, writeFILETIME=%llu, fileSize=%llu, isDirectory=%s, isLink=%s, isReadOnly=%s, permissions=%s\n",
							filename, creationTime, accessTime, writeTime, creationFILETIME, accessFILETIME, writeFILETIME, fileSize, isDirectory ? "true" : "false", isLink ? "true" : "false", isReadOnly ? "true" : "false", permissions);
				} else {
					fileglob_uint64 numberOfLinks = fileglob_NumberOfLinks(glob);
					printf("%s - creationTime=%lld, accessTime=%lld, writeTime=%lld, creationFILETIME=%lld, accessFILETIME=%lld, writeFILETIME=%lld, fileSize=%lld, isDirectory=%s, isLink=%s, isReadOnly=%s, permissions=%s, numberOfLinks=%lld\n",
							filename, creationTime, accessTime, writeTime, creationFILETIME, accessFILETIME, writeFILETIME, fileSize, isDirectory ? "true" : "false", isLink ? "true" : "false", isReadOnly ? "true" : "false", permissions, numberOfLinks);
				}
			} else {
				printf("%s\n", filename);
			}
		}

		fileglob_Destroy(glob);
	}

	return EXIT_SUCCESS;
}