2013-02-08 09:35:17 -08:00
|
|
|
//Compile with:
|
|
|
|
//gcc -o eio_file_ls eio_file_ls.c `pkg-config --cflags --libs ecore eio`
|
2012-12-05 10:10:43 -08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <Eio.h>
|
|
|
|
#include <Ecore.h>
|
|
|
|
|
|
|
|
static Eina_Bool
|
2014-02-28 04:32:04 -08:00
|
|
|
_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *file)
|
2012-12-05 10:10:43 -08:00
|
|
|
{
|
|
|
|
char *last_slash = strrchr(file, '/');
|
|
|
|
|
|
|
|
//Check if it is a hidden file
|
|
|
|
if (last_slash != NULL && strlen(last_slash) > 1 && last_slash[1] == '.')
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-02-28 04:32:04 -08:00
|
|
|
_main_cb(void *data, Eio_File *handler EINA_UNUSED, const char *file)
|
2012-12-05 10:10:43 -08:00
|
|
|
{
|
|
|
|
int *number_of_listed_files = (int *)data;
|
|
|
|
|
|
|
|
fprintf(stdout, "Processing file:%s\n", file);
|
|
|
|
|
|
|
|
(*number_of_listed_files)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-02-28 04:32:04 -08:00
|
|
|
_done_cb(void *data, Eio_File *handler EINA_UNUSED)
|
2012-12-05 10:10:43 -08:00
|
|
|
{
|
|
|
|
int *number_of_listed_files = (int *)data;
|
|
|
|
|
|
|
|
fprintf(stdout, "Number of listed files:%d\n" \
|
|
|
|
"ls operation is done, quitting.\n", *number_of_listed_files);
|
|
|
|
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-02-28 04:32:04 -08:00
|
|
|
_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int error)
|
2012-12-05 10:10:43 -08:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Something wrong has happend:%s\n", strerror(error));
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int number_of_listed_files = 0;
|
|
|
|
|
|
|
|
ecore_init();
|
|
|
|
eio_init();
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "You must pass a path to execute the command.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
eio_file_ls(argv[1], _filter_cb, _main_cb, _done_cb, _error_cb,
|
|
|
|
&number_of_listed_files);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
|
|
|
eio_shutdown();
|
|
|
|
ecore_shutdown();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|