Home | Develop | Download | Contact
testpdsfilesfunc4.c

Programa para el testeo de algunas funciones de la biblioteca <pds/pdsfilesfunc.h> .

Autor
Fernando Pujaico Rivera

Este programa solo hace una prueba simple de las funciones que hice mas al tun tun.

# Compilation command
gcc -o testpdsfilesfunc4 testpdsfilesfunc4.c -lpdsdatafunc

# Test command
./testpdsfilesfunc4


/*
* testpdsfilesfunc4.c
*
* Copyright 2017 Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#include <stdio.h> //printf
#include <stdlib.h> //EXIT_SUCCESS
#include <pds/pdsdatafunc.h>
char *func(const char *data)
{
char *rep=NULL;
rep=(char*)calloc(32,1);
sprintf(rep,"tango");
return rep;
}
int main(int argc, char* argv[])
{
char *DATA=NULL;
int d;
char FILE_INPUT[] ="filedata.metadata";
char FILE_OUTPUT1[]="filedata.out1.metadata";
char FILE_OUTPUT2[]="filedata.out2.metadata";
PdsCellString *CELL=NULL;
printf("\n");
// Getting in an int data in the file, relative to "TIME=".
d=pds_get_filedata_int(FILE_INPUT," TIME= ");
// Print the data.
printf("%d\n",d);
printf("\n\n");
// Comaparing the data in the file, relative to "WORKING=".
d=pds_get_filedata_strcmp(FILE_INPUT," WORKING= ","TRUE");
// Print the data.
printf("%d\n",d);
printf("\n\n");
// Getting in a string the data in the file, relative to "genre=".
DATA=pds_get_filedata_string(FILE_INPUT," GENRE= ");
// Print the string data.
if(DATA!=NULL) printf("%s\n",DATA);
// Release de string memory.
free(DATA);
printf("\n\n");
// Getting in a cell string separated by "," the data in the file,
// relative to "GENRE=".
CELL=pds_get_filedata_cell_string(FILE_INPUT," GENRE= ",",");
// Print the cell string data.
if(CELL!=NULL) pds_cell_string_all_printf(CELL);
// Release de cell string memory.
printf("\n\n");
// Replace all occurrences of the text between "=" and "," with the result
// of proccess the text with the function "func".
pds_file_content_replacement(FILE_OUTPUT1,FILE_INPUT,"=",",",func);
// Print the content of a file.
pds_cat(FILE_OUTPUT1);
printf("\n\n");
// Replace all occurrences of the text "sertanejo" with the "salsa em linha" text.
pds_file_pattern_replacement(FILE_OUTPUT2,FILE_INPUT,"sertanejo","salsa em linha");
// Print the content of a file.
pds_cat(FILE_OUTPUT2);
printf("\n");
// Optional
remove(FILE_OUTPUT1);
remove(FILE_OUTPUT2);
return EXIT_SUCCESS;
}

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed