Minor cosmetic fixes to core_io
This commit is contained in:
parent
fc7503113a
commit
f16cef85db
|
@ -15,12 +15,10 @@
|
|||
* a source (stdin) to a destination (stdout) using an Efl.Io.Copier.
|
||||
*/
|
||||
|
||||
Eo *_copier = NULL;
|
||||
|
||||
static void
|
||||
_io_write(const char *filename)
|
||||
{
|
||||
Eina_Slice content = EINA_SLICE_STR("1. Some dummy content\n2. \n3. With more...\n");
|
||||
Eina_Slice content = EINA_SLICE_STR("### This is a sample string for the file io test ###");
|
||||
Efl_Io_File *file;
|
||||
|
||||
file = efl_add(EFL_IO_FILE_CLASS, NULL,
|
||||
|
@ -32,12 +30,16 @@ _io_write(const char *filename)
|
|||
if (!file)
|
||||
return;
|
||||
|
||||
printf("Loaded file %s for read on fd %d\n", filename, efl_io_reader_fd_get(file));
|
||||
printf(" Opened file %s for writing on fd %d\n", filename, efl_io_reader_fd_get(file));
|
||||
|
||||
if (efl_io_writer_write(file, &content, NULL) != EINA_ERROR_NO_ERROR)
|
||||
fprintf(stderr, "Failed to write test file\n");
|
||||
fprintf(stderr, " Failed to write test file\n");
|
||||
else
|
||||
printf("Wrote content to file\n");
|
||||
{
|
||||
char *string = eina_slice_strdup(content);
|
||||
printf(" Wrote content: %s\n", string);
|
||||
free(string);
|
||||
}
|
||||
|
||||
efl_del(file);
|
||||
}
|
||||
|
@ -55,14 +57,14 @@ _io_read(const char *filename)
|
|||
if (!file)
|
||||
return;
|
||||
|
||||
printf("Loaded file %s for write on fd %d\n", filename, efl_io_reader_fd_get(file));
|
||||
printf(" Opened file %s for reading on fd %d\n", filename, efl_io_reader_fd_get(file));
|
||||
|
||||
if (efl_io_reader_read(file, &content) != EINA_ERROR_NO_ERROR)
|
||||
fprintf(stderr, "Failed to read test file\n");
|
||||
fprintf(stderr, " Failed to read test file\n");
|
||||
else
|
||||
{
|
||||
char *string = eina_rw_slice_strdup(content);
|
||||
printf("Read content from file: %s\n", string);
|
||||
printf(" Read content: %s\n", string);
|
||||
free(string);
|
||||
}
|
||||
|
||||
|
@ -74,16 +76,17 @@ _io_test()
|
|||
{
|
||||
const char *filename = "/tmp/efl_core_io_test.tmp";
|
||||
|
||||
_io_write(filename);
|
||||
_io_read(filename);
|
||||
printf("TEST 1: Efl.Io.File\n");
|
||||
_io_write(filename);
|
||||
_io_read(filename);
|
||||
|
||||
eina_file_unlink(filename);
|
||||
eina_file_unlink(filename);
|
||||
}
|
||||
|
||||
static void
|
||||
_copier_done(void *data EINA_UNUSED, const Efl_Event *event)
|
||||
{
|
||||
fprintf(stderr, "INFO: %s done\n", efl_name_get(event->object));
|
||||
fprintf(stderr, " %s done\n", efl_name_get(event->object));
|
||||
|
||||
efl_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -93,7 +96,7 @@ _copier_error(void *data EINA_UNUSED, const Efl_Event *event)
|
|||
{
|
||||
const Eina_Error *perr = event->info;
|
||||
|
||||
fprintf(stderr, "INFO: %s error: #%d '%s'\n",
|
||||
fprintf(stderr, " %s error: #%d '%s'\n",
|
||||
efl_name_get(event->object), *perr, eina_error_msg_get(*perr));
|
||||
|
||||
efl_exit(EXIT_FAILURE);
|
||||
|
@ -107,24 +110,26 @@ static void
|
|||
_copier_test(Efl_Loop *loop)
|
||||
{
|
||||
Eo *input, *output;
|
||||
Eo *copier = NULL;
|
||||
|
||||
printf("TEST 2: Efl.Io.Copier\n");
|
||||
// set up our objects to copy, use stdin and stdout
|
||||
input = efl_add(EFL_IO_STDIN_CLASS, loop);
|
||||
output = efl_add(EFL_IO_STDOUT_CLASS, loop);
|
||||
|
||||
// copier: set up a copy from input to output
|
||||
_copier = efl_add(EFL_IO_COPIER_CLASS, loop,
|
||||
efl_name_set(efl_added, "Copier"),
|
||||
efl_io_copier_source_set(efl_added, input),
|
||||
efl_io_copier_destination_set(efl_added, output),
|
||||
efl_event_callback_array_add(efl_added, copier_cbs(), NULL));
|
||||
if (!_copier)
|
||||
copier = efl_add(EFL_IO_COPIER_CLASS, loop,
|
||||
efl_name_set(efl_added, "Copier"),
|
||||
efl_io_copier_source_set(efl_added, input),
|
||||
efl_io_copier_destination_set(efl_added, output),
|
||||
efl_event_callback_array_add(efl_added, copier_cbs(), NULL));
|
||||
if (!copier)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not create Efl_Io_Copier\n");
|
||||
fprintf(stderr, " ERROR: could not create Efl_Io_Copier\n");
|
||||
efl_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Type something here and press enter, it will be copied to stdout...\n");
|
||||
printf(" Type something here and press enter, it will be copied to stdout...\n");
|
||||
printf(" (press Ctrl-D to exit)\n");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue