Beispiel #1
0
int print_dir_tree (char *path)
{
//	static int a;
	printf("path = %s\n");
	DIR *dir;
	struct dirent *entry;
	dir = opendir(path);
	int len;
	if(dir == 0)
	{
		return -1;
	}
	while((entry = readdir(dir)))
	{

		printf ( "%s\n", entry->d_name );
		if ( strcmp (path, "/") == 0 )
			printf ("/%s D_TYPE = %d\n", entry->d_name, entry->d_type);
		else
			printf ("%s/%s D_TYPE = %d\n", path, entry->d_name, entry->d_type);

		if(entry->d_type == DT_DIR)
		{
			if (strcmp (entry->d_name, ".") != 0 && strcmp (entry->d_name, "..") != 0)
			{
				char *newpath = NULL;
				newpath = (char *)  malloc ( sizeof ( char ) * ( strlen (entry->d_name) + strlen (path) + 2 ) );
				if ( strcmp (path, "/") == 0 )
					sprintf ( newpath, "/%s", entry->d_name );
				else
					sprintf ( newpath, "%s/%s", path, entry->d_name );
				print_dir_tree (newpath);
				free (newpath);
			}
		}
	}
	closedir(dir);
	return 0;
}
int docs_to_xml (char * path, int doc_type)
{
	int i = 0;
	SingleList_t tFileList, *pFileList=&tFileList, tFileTypeFilter, *pFileTypeFilter = &tFileTypeFilter;
	int xml_fd;
	char *ext = NULL;
	initList( pFileList );
	setFileTypeFilter ( pFileTypeFilter );

#ifndef OLD_ZRT
	if ( strcmp ( getext_( path ), "zip") == 0 )
	{
		get_file_list_inzip ( path , pFileList );
	}
	else
#endif
	print_dir_tree (path);
	get_file_list ( path, pFileList, pFileTypeFilter );

	printf ( "list of indexed docs\n" );
	for ( i = 0; i < pFileList->count; i++)
		printf ( "%s\n", pFileList->list[i] );

///////////////////////

	xml_fd = open_xml_( XML_PATH ); //FIXME const
	for ( i = 0; i < pFileList->count; i++)
	{
		add_doc_to_xml ( xml_fd, pFileList->list[i], doc_type );
	}
	close_xml_( xml_fd );
///////////////////////

	freeList( pFileList );
	freeList( pFileTypeFilter );
	return 0;
}