Exercici 2: Entrada de dades [40%]
This commit is contained in:
parent
c43a99dca8
commit
19613287e6
48 changed files with 364 additions and 102 deletions
4
Makefile
4
Makefile
|
|
@ -1,12 +1,8 @@
|
||||||
.PHONY: clean All
|
.PHONY: clean All
|
||||||
|
|
||||||
All:
|
All:
|
||||||
@echo "----------Building project:[ UOCContacts - Release ]----------"
|
|
||||||
@cd "UOCContacts" && "$(MAKE)" -f "UOCContacts.mk"
|
|
||||||
@echo "----------Building project:[ UOC20211 - Release ]----------"
|
@echo "----------Building project:[ UOC20211 - Release ]----------"
|
||||||
@"$(MAKE)" -f "UOC20211.mk"
|
@"$(MAKE)" -f "UOC20211.mk"
|
||||||
clean:
|
clean:
|
||||||
@echo "----------Cleaning project:[ UOCContacts - Release ]----------"
|
|
||||||
@cd "UOCContacts" && "$(MAKE)" -f "UOCContacts.mk" clean
|
|
||||||
@echo "----------Cleaning project:[ UOC20211 - Release ]----------"
|
@echo "----------Cleaning project:[ UOC20211 - Release ]----------"
|
||||||
@"$(MAKE)" -f "UOC20211.mk" clean
|
@"$(MAKE)" -f "UOC20211.mk" clean
|
||||||
|
|
|
||||||
11
UOC20211.mk
11
UOC20211.mk
|
|
@ -13,7 +13,7 @@ CurrentFileName :=
|
||||||
CurrentFilePath :=
|
CurrentFilePath :=
|
||||||
CurrentFileFullPath :=
|
CurrentFileFullPath :=
|
||||||
User :=Guillem
|
User :=Guillem
|
||||||
Date :=19/10/21
|
Date :=24/10/21
|
||||||
CodeLitePath :=/home/guillem/.codelite
|
CodeLitePath :=/home/guillem/.codelite
|
||||||
LinkerName :=/usr/bin/g++
|
LinkerName :=/usr/bin/g++
|
||||||
SharedObjectLinkerName :=/usr/bin/g++ -shared -fPIC
|
SharedObjectLinkerName :=/usr/bin/g++ -shared -fPIC
|
||||||
|
|
@ -72,19 +72,12 @@ Objects=$(Objects0)
|
||||||
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
|
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
|
||||||
all: $(OutputFile)
|
all: $(OutputFile)
|
||||||
|
|
||||||
$(OutputFile): $(IntermediateDirectory)/.d ".build-release/UOCContacts" $(Objects)
|
$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
|
||||||
@$(MakeDirCommand) $(@D)
|
@$(MakeDirCommand) $(@D)
|
||||||
@echo "" > $(IntermediateDirectory)/.d
|
@echo "" > $(IntermediateDirectory)/.d
|
||||||
@echo $(Objects0) > $(ObjectsFileList)
|
@echo $(Objects0) > $(ObjectsFileList)
|
||||||
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
|
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
|
||||||
|
|
||||||
".build-release/UOCContacts":
|
|
||||||
@$(MakeDirCommand) ".build-release"
|
|
||||||
@echo stam > ".build-release/UOCContacts"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MakeIntermediateDirs:
|
MakeIntermediateDirs:
|
||||||
@test -d ./bin/Release || $(MakeDirCommand) ./bin/Release
|
@test -d ./bin/Release || $(MakeDirCommand) ./bin/Release
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
./bin/Release/test_src_test.c.o ./bin/Release/test_src_test_suite.c.o ./bin/Release/test_src_test_pr1.c.o ./bin/Release/src_main.c.o
|
./bin/Debug/test_src_test.c.o ./bin/Debug/test_src_test_suite.c.o ./bin/Debug/test_src_test_pr1.c.o ./bin/Debug/src_main.c.o
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ CurrentFileName :=
|
||||||
CurrentFilePath :=
|
CurrentFilePath :=
|
||||||
CurrentFileFullPath :=
|
CurrentFileFullPath :=
|
||||||
User :=Guillem
|
User :=Guillem
|
||||||
Date :=19/10/21
|
Date :=24/10/21
|
||||||
CodeLitePath :=/home/guillem/.codelite
|
CodeLitePath :=/home/guillem/.codelite
|
||||||
LinkerName :=/usr/bin/g++
|
LinkerName :=/usr/bin/g++
|
||||||
SharedObjectLinkerName :=/usr/bin/g++ -shared -fPIC
|
SharedObjectLinkerName :=/usr/bin/g++ -shared -fPIC
|
||||||
|
|
@ -60,7 +60,7 @@ AS := /usr/bin/as
|
||||||
## User defined environment variables
|
## User defined environment variables
|
||||||
##
|
##
|
||||||
CodeLiteDir:=/usr/share/codelite
|
CodeLiteDir:=/usr/share/codelite
|
||||||
Objects0=$(IntermediateDirectory)/src_api.c$(ObjectSuffix) $(IntermediateDirectory)/src_person.c$(ObjectSuffix) $(IntermediateDirectory)/src_csv.c$(ObjectSuffix) $(IntermediateDirectory)/src_date.c$(ObjectSuffix)
|
Objects0=$(IntermediateDirectory)/src_contact.c$(ObjectSuffix) $(IntermediateDirectory)/src_api.c$(ObjectSuffix) $(IntermediateDirectory)/src_person.c$(ObjectSuffix) $(IntermediateDirectory)/src_csv.c$(ObjectSuffix) $(IntermediateDirectory)/src_date.c$(ObjectSuffix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -93,6 +93,12 @@ PreBuild:
|
||||||
##
|
##
|
||||||
## Objects
|
## Objects
|
||||||
##
|
##
|
||||||
|
$(IntermediateDirectory)/src_contact.c$(ObjectSuffix): src/contact.c
|
||||||
|
@$(CC) $(CFLAGS) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/src_contact.c$(ObjectSuffix) -MF$(IntermediateDirectory)/src_contact.c$(DependSuffix) -MM src/contact.c
|
||||||
|
$(CC) $(SourceSwitch) "/dades/git/UOC/PP/PR1/UOC20211/UOCContacts/src/contact.c" $(CFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/src_contact.c$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/src_contact.c$(PreprocessSuffix): src/contact.c
|
||||||
|
$(CC) $(CFLAGS) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/src_contact.c$(PreprocessSuffix) src/contact.c
|
||||||
|
|
||||||
$(IntermediateDirectory)/src_api.c$(ObjectSuffix): src/api.c
|
$(IntermediateDirectory)/src_api.c$(ObjectSuffix): src/api.c
|
||||||
@$(CC) $(CFLAGS) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/src_api.c$(ObjectSuffix) -MF$(IntermediateDirectory)/src_api.c$(DependSuffix) -MM src/api.c
|
@$(CC) $(CFLAGS) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/src_api.c$(ObjectSuffix) -MF$(IntermediateDirectory)/src_api.c$(DependSuffix) -MM src/api.c
|
||||||
$(CC) $(SourceSwitch) "/dades/git/UOC/PP/PR1/UOC20211/UOCContacts/src/api.c" $(CFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/src_api.c$(ObjectSuffix) $(IncludePath)
|
$(CC) $(SourceSwitch) "/dades/git/UOC/PP/PR1/UOC20211/UOCContacts/src/api.c" $(CFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/src_api.c$(ObjectSuffix) $(IncludePath)
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,14 @@
|
||||||
<Description/>
|
<Description/>
|
||||||
<Dependencies/>
|
<Dependencies/>
|
||||||
<VirtualDirectory Name="src">
|
<VirtualDirectory Name="src">
|
||||||
|
<File Name="src/contact.c"/>
|
||||||
<File Name="src/date.c"/>
|
<File Name="src/date.c"/>
|
||||||
<File Name="src/person.c"/>
|
<File Name="src/person.c"/>
|
||||||
<File Name="src/csv.c"/>
|
<File Name="src/csv.c"/>
|
||||||
<File Name="src/api.c"/>
|
<File Name="src/api.c"/>
|
||||||
</VirtualDirectory>
|
</VirtualDirectory>
|
||||||
<VirtualDirectory Name="include">
|
<VirtualDirectory Name="include">
|
||||||
|
<File Name="include/contact.h"/>
|
||||||
<File Name="include/date.h"/>
|
<File Name="include/date.h"/>
|
||||||
<File Name="include/person.h"/>
|
<File Name="include/person.h"/>
|
||||||
<File Name="include/csv.h"/>
|
<File Name="include/csv.h"/>
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
../bin/Release/src_api.c.o ../bin/Release/src_person.c.o ../bin/Release/src_csv.c.o ../bin/Release/src_date.c.o
|
../bin/Debug/src_contact.c.o ../bin/Debug/src_api.c.o ../bin/Debug/src_person.c.o ../bin/Debug/src_csv.c.o ../bin/Debug/src_date.c.o
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "csv.h"
|
#include "csv.h"
|
||||||
|
#include "contact.h"
|
||||||
|
#include "person.h"
|
||||||
|
|
||||||
// Type that stores all the application data
|
// Type that stores all the application data
|
||||||
typedef struct _ApiData {
|
typedef struct _ApiData {
|
||||||
|
|
@ -10,6 +12,9 @@ typedef struct _ApiData {
|
||||||
// Ex PR1 2:
|
// Ex PR1 2:
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
|
||||||
|
tPopulation population;
|
||||||
|
tGeolocationData geolocationData;
|
||||||
|
|
||||||
} tApiData;
|
} tApiData;
|
||||||
|
|
||||||
// Get the API version information
|
// Get the API version information
|
||||||
|
|
|
||||||
89
UOCContacts/include/contact.h
Executable file
89
UOCContacts/include/contact.h
Executable file
|
|
@ -0,0 +1,89 @@
|
||||||
|
#ifndef __CONTACT_H__
|
||||||
|
#define __CONTACT_H__
|
||||||
|
#include "csv.h"
|
||||||
|
#include "date.h"
|
||||||
|
|
||||||
|
// Maximum length of an identity document
|
||||||
|
#define MAX_PERSON_DOCUMENT_LEN 15
|
||||||
|
|
||||||
|
/*typedef struct _tDate {
|
||||||
|
int day;
|
||||||
|
int month;
|
||||||
|
int year;
|
||||||
|
} tDate;*/
|
||||||
|
|
||||||
|
/*typedef struct _tTime {
|
||||||
|
int hour;
|
||||||
|
int minutes;
|
||||||
|
} tTime;*/
|
||||||
|
|
||||||
|
/*typedef struct _tDateTime {
|
||||||
|
tDate date;
|
||||||
|
tTime time;
|
||||||
|
} tDateTime;*/
|
||||||
|
|
||||||
|
|
||||||
|
// Parse a tDateTime from string information
|
||||||
|
void dateTime_parse(tDateTime* dateTime, const char* date, const char* time);
|
||||||
|
|
||||||
|
// Compare two tDateTime structures and return true if they contain the same value or false otherwise.
|
||||||
|
bool dateTime_cmp(tDateTime dateTime1, tDateTime dateTime2);
|
||||||
|
|
||||||
|
// Ex 1: Define data types here...
|
||||||
|
|
||||||
|
///////////////////////////
|
||||||
|
// #define MAX_POSITIONS 100
|
||||||
|
|
||||||
|
typedef struct _tCoordinate {
|
||||||
|
float latitude;
|
||||||
|
float longitude;
|
||||||
|
} tCoordinate;
|
||||||
|
|
||||||
|
typedef struct _tTimePosition {
|
||||||
|
tCoordinate coordinate;
|
||||||
|
tDateTime timestamp;
|
||||||
|
char person[MAX_PERSON_DOCUMENT_LEN];
|
||||||
|
} tTimePosition;
|
||||||
|
|
||||||
|
typedef struct _tGeolocationData {
|
||||||
|
tTimePosition* elems;
|
||||||
|
int count;
|
||||||
|
} tGeolocationData;
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
// Ex 2: Define your methods here ....
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
|
// Initialize the geopositon data
|
||||||
|
void geoData_init(tGeolocationData* data);
|
||||||
|
|
||||||
|
// Parse input from CSVEntry
|
||||||
|
void contact_parse(tTimePosition* data, tCSVEntry entry);
|
||||||
|
|
||||||
|
// Add a new position
|
||||||
|
void geoData_add(tGeolocationData* data, tTimePosition position);
|
||||||
|
|
||||||
|
// Remove the data from a person in a certain time moment
|
||||||
|
void geoData_del(tGeolocationData* data, const char* document, tDateTime time);
|
||||||
|
|
||||||
|
// Print the geoposition data
|
||||||
|
void geoData_print(tGeolocationData data);
|
||||||
|
|
||||||
|
// [AUX METHOD] Return the position of a geoposition entry with provided information. -1 if it does not exist
|
||||||
|
int geoData_find(tGeolocationData data, const char* document, tDateTime time);
|
||||||
|
|
||||||
|
// [AUX METHOD] Copy the data from the source to destination
|
||||||
|
void timePos_cpy(tTimePosition* destination, tTimePosition source);
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
|
||||||
|
// PAC2
|
||||||
|
|
||||||
|
// Clear tGeopositionData structure
|
||||||
|
void geoData_free(tGeolocationData* geoData);
|
||||||
|
////////////////////////////////////////////
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -69,7 +69,64 @@ tApiError api_addDataEntry(tApiData* data, tCSVEntry entry) {
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
// Ex PR1 2
|
// Ex PR1 2
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
return E_NOT_IMPLEMENTED;
|
|
||||||
|
if (data == NULL) {
|
||||||
|
api_initData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Managing PERSON type
|
||||||
|
if (strcmp(csv_getType(&entry), "PERSON") == 0) {
|
||||||
|
|
||||||
|
// Check if numFields is the expected; return INVALID_ENTRY_FORMAT otherwise
|
||||||
|
if (csv_numFields(entry) == 7) {
|
||||||
|
|
||||||
|
tPerson newPerson;
|
||||||
|
person_parse(&newPerson,entry);
|
||||||
|
|
||||||
|
// Check if person already exists; return DUPLICATED_ENTRY otherwise
|
||||||
|
if (population_find(data->population, newPerson.document) == -1) {
|
||||||
|
|
||||||
|
// Add person to population variable inside ApiData
|
||||||
|
population_add(&data->population, newPerson);
|
||||||
|
return E_SUCCESS;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return E_DUPLICATED_ENTRY;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return E_INVALID_ENTRY_FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (strcmp(csv_getType(&entry), "GEOLOCATION") == 0) {
|
||||||
|
|
||||||
|
// Check if numFields is the expected; return INVALID_ENTRY_FORMAT otherwise
|
||||||
|
if (csv_numFields(entry) == 5) {
|
||||||
|
|
||||||
|
//tGeolocationData newGeolocationData;
|
||||||
|
tTimePosition newTimePosition;
|
||||||
|
contact_parse(&newTimePosition, entry);
|
||||||
|
|
||||||
|
// Check if record does not exist yet; return DUPLICATED_ENTRY otherwise
|
||||||
|
if(geoData_find(data->geolocationData, newTimePosition.person, newTimePosition.timestamp) == -1) {
|
||||||
|
|
||||||
|
// Add geolocation info for variable inside ApiData
|
||||||
|
geoData_add(&data->geolocationData, newTimePosition);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return E_DUPLICATED_ENTRY;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return E_INVALID_ENTRY_FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return E_INVALID_ENTRY_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//return E_NOT_IMPLEMENTED;
|
||||||
|
return E_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free all used memory
|
// Free all used memory
|
||||||
|
|
@ -77,7 +134,14 @@ tApiError api_freeData(tApiData* data) {
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
// Ex PR1 2:
|
// Ex PR1 2:
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
return E_NOT_IMPLEMENTED;
|
|
||||||
|
assert(data != NULL);
|
||||||
|
|
||||||
|
population_free(&data->population);
|
||||||
|
geoData_free(&data->geolocationData);
|
||||||
|
|
||||||
|
//return E_NOT_IMPLEMENTED;
|
||||||
|
return E_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the data structure
|
// Initialize the data structure
|
||||||
|
|
@ -86,7 +150,14 @@ tApiError api_initData(tApiData* data) {
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
// Ex PR1 2:
|
// Ex PR1 2:
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
return E_NOT_IMPLEMENTED;
|
|
||||||
|
assert(data != NULL);
|
||||||
|
|
||||||
|
geoData_init(&data->geolocationData);
|
||||||
|
population_init(&data->population);
|
||||||
|
|
||||||
|
//return E_NOT_IMPLEMENTED;
|
||||||
|
return E_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get person data
|
// Get person data
|
||||||
|
|
|
||||||
182
UOCContacts/src/contact.c
Executable file
182
UOCContacts/src/contact.c
Executable file
|
|
@ -0,0 +1,182 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "contact.h"
|
||||||
|
|
||||||
|
// Parse a tDateTime from string information
|
||||||
|
void dateTime_parse(tDateTime* dateTime, const char* date, const char* time) {
|
||||||
|
// Check output data
|
||||||
|
assert(dateTime != NULL);
|
||||||
|
|
||||||
|
// Check input date
|
||||||
|
assert(date != NULL);
|
||||||
|
assert(strlen(date) == 10);
|
||||||
|
|
||||||
|
// Check input time
|
||||||
|
assert(time != NULL);
|
||||||
|
assert(strlen(time) == 5);
|
||||||
|
|
||||||
|
// Parse the input date
|
||||||
|
sscanf(date, "%d/%d/%d", &(dateTime->date.day), &(dateTime->date.month), &(dateTime->date.year));
|
||||||
|
|
||||||
|
// Parse the input time
|
||||||
|
sscanf(time, "%d:%d", &(dateTime->time.hour), &(dateTime->time.minutes));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare two tDateTime structures and return true if they contain the same value or false otherwise.
|
||||||
|
bool dateTime_cmp(tDateTime dateTime1, tDateTime dateTime2) {
|
||||||
|
if (dateTime1.date.day != dateTime2.date.day || dateTime1.date.month != dateTime2.date.month || dateTime1.date.year != dateTime2.date.year) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dateTime1.time.hour == dateTime2.time.hour && dateTime1.time.minutes == dateTime2.time.minutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// EX2: Implement your methods here....
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Initialize the geopositon data
|
||||||
|
void geoData_init(tGeolocationData* data) {
|
||||||
|
// Set the initial number of elements to zero.
|
||||||
|
data->count = 0;
|
||||||
|
data->elems = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse input from CSVEntry
|
||||||
|
void contact_parse(tTimePosition* data, tCSVEntry entry) {
|
||||||
|
char date[11];
|
||||||
|
char time[6];
|
||||||
|
|
||||||
|
// Check input data (Pre-conditions)
|
||||||
|
assert(data != NULL);
|
||||||
|
assert(csv_numFields(entry) == 5);
|
||||||
|
|
||||||
|
// Get the identity document
|
||||||
|
csv_getAsString(entry, 0, data->person, 15);
|
||||||
|
|
||||||
|
// Get the date and time
|
||||||
|
csv_getAsString(entry, 1, date, 11);
|
||||||
|
csv_getAsString(entry, 2, time, 6);
|
||||||
|
dateTime_parse(&(data->timestamp), date, time);
|
||||||
|
|
||||||
|
// Assign the coordinates
|
||||||
|
data->coordinate.latitude = csv_getAsReal(entry, 3);
|
||||||
|
data->coordinate.longitude = csv_getAsReal(entry, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a new position
|
||||||
|
void geoData_add(tGeolocationData* data, tTimePosition position) {
|
||||||
|
// Check input data (Pre-conditions)
|
||||||
|
assert(data != NULL);
|
||||||
|
|
||||||
|
// PAC2 No limit on max positions
|
||||||
|
//assert(data->count < MAX_POSITIONS);
|
||||||
|
|
||||||
|
// Check if an entry with this data already exists
|
||||||
|
if (geoData_find(data[0], position.person, position.timestamp) < 0) {
|
||||||
|
|
||||||
|
// Need to allocate new memory space for new item to be inserted
|
||||||
|
if (data->count == 0) {
|
||||||
|
// Allocate new position if structure is still empty
|
||||||
|
data->elems=(tTimePosition*)malloc(sizeof(tTimePosition));
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Resize vector to allocate new position
|
||||||
|
data->elems = (tTimePosition*)realloc(data->elems, (data->count+1) * sizeof(tTimePosition));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that returned pointer to elems is not NULL
|
||||||
|
if(data->elems == NULL) {
|
||||||
|
printf("Error: Not enough space to allocate tTimePosition entry.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
timePos_cpy(&(data->elems[data->count]), position);
|
||||||
|
data->count ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Remove the data from a person in a certain time moment
|
||||||
|
void geoData_del(tGeolocationData* data, const char* document, tDateTime time) {
|
||||||
|
int pos;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// Find if it exists
|
||||||
|
pos = geoData_find(data[0], document, time);
|
||||||
|
|
||||||
|
if (pos >= 0) {
|
||||||
|
// Shift elements to remove selected
|
||||||
|
for(i = pos; i < data->count-1; i++) {
|
||||||
|
// Copy element on position i+1 to position i
|
||||||
|
timePos_cpy(&(data->elems[i]), data->elems[i+1]);
|
||||||
|
}
|
||||||
|
// Update the number of elements
|
||||||
|
data->count--;
|
||||||
|
|
||||||
|
if (data->count==0) {
|
||||||
|
free(data->elems);
|
||||||
|
data->elems == NULL;
|
||||||
|
} else {
|
||||||
|
data->elems=(tTimePosition*)realloc(data->elems, data->count * sizeof(tTimePosition));
|
||||||
|
|
||||||
|
if (data->elems == NULL) {
|
||||||
|
printf("Error: resize when deleting failed.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print the geoposition data
|
||||||
|
void geoData_print(tGeolocationData data) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < data.count; i++) {
|
||||||
|
// Print position and document
|
||||||
|
printf("%d;%s;", i, data.elems[i].person);
|
||||||
|
// Print date and time
|
||||||
|
printf("%02d/%02d/%04d;%02d:%02d;", data.elems[i].timestamp.date.day, data.elems[i].timestamp.date.month, data.elems[i].timestamp.date.year, data.elems[i].timestamp.time.hour, data.elems[i].timestamp.time.minutes);
|
||||||
|
// Print position
|
||||||
|
printf("%.4f;%.4f\n", data.elems[i].coordinate.latitude, data.elems[i].coordinate.longitude);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// [AUX METHOD] Return the position of a geoposition entry with provided information. -1 if it does not exist
|
||||||
|
int geoData_find(tGeolocationData data, const char* document, tDateTime time) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < data.count; i++) {
|
||||||
|
if(strcmp(data.elems[i].person, document) == 0 && dateTime_cmp(data.elems[i].timestamp, time)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [AUX METHOD] Copy the data from the source to destination
|
||||||
|
void timePos_cpy(tTimePosition* destination, tTimePosition source) {
|
||||||
|
strcpy(destination->person, source.person);
|
||||||
|
destination->coordinate = source.coordinate;
|
||||||
|
destination->timestamp = source.timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////
|
||||||
|
|
||||||
|
// PAC3
|
||||||
|
void geoData_free(tGeolocationData* data) {
|
||||||
|
|
||||||
|
// Check input data
|
||||||
|
assert(data != NULL);
|
||||||
|
|
||||||
|
// Release memory
|
||||||
|
if (data->count > 0) {
|
||||||
|
free(data->elems);
|
||||||
|
data->elems = NULL;
|
||||||
|
data->count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
///////////////////////////////////////////
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
|
|
||||||
Binary file not shown.
|
|
@ -1,6 +0,0 @@
|
||||||
../bin/Debug/src_api.c.o: src/api.c include/csv.h include/api.h \
|
|
||||||
include/error.h include/csv.h
|
|
||||||
include/csv.h:
|
|
||||||
include/api.h:
|
|
||||||
include/error.h:
|
|
||||||
include/csv.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,2 +0,0 @@
|
||||||
../bin/Debug/src_csv.c.o: src/csv.c include/csv.h
|
|
||||||
include/csv.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,2 +0,0 @@
|
||||||
../bin/Debug/src_date.c.o: src/date.c include/date.h
|
|
||||||
include/date.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,8 +0,0 @@
|
||||||
bin/Debug/src_main.c.o: src/main.c test/include/test.h \
|
|
||||||
test/include/test_suite.h UOCContacts/include/api.h \
|
|
||||||
UOCContacts/include/error.h UOCContacts/include/csv.h
|
|
||||||
test/include/test.h:
|
|
||||||
test/include/test_suite.h:
|
|
||||||
UOCContacts/include/api.h:
|
|
||||||
UOCContacts/include/error.h:
|
|
||||||
UOCContacts/include/csv.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,5 +0,0 @@
|
||||||
../bin/Debug/src_person.c.o: src/person.c include/person.h include/csv.h \
|
|
||||||
include/date.h
|
|
||||||
include/person.h:
|
|
||||||
include/csv.h:
|
|
||||||
include/date.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,5 +0,0 @@
|
||||||
bin/Debug/test_src_test.c.o: test/src/test.c test/include/test.h \
|
|
||||||
test/include/test_suite.h test/include/test_pr1.h
|
|
||||||
test/include/test.h:
|
|
||||||
test/include/test_suite.h:
|
|
||||||
test/include/test_pr1.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,9 +0,0 @@
|
||||||
bin/Debug/test_src_test_pr1.c.o: test/src/test_pr1.c \
|
|
||||||
test/include/test_pr1.h test/include/test_suite.h \
|
|
||||||
UOCContacts/include/api.h UOCContacts/include/error.h \
|
|
||||||
UOCContacts/include/csv.h
|
|
||||||
test/include/test_pr1.h:
|
|
||||||
test/include/test_suite.h:
|
|
||||||
UOCContacts/include/api.h:
|
|
||||||
UOCContacts/include/error.h:
|
|
||||||
UOCContacts/include/csv.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,3 +0,0 @@
|
||||||
bin/Debug/test_src_test_suite.c.o: test/src/test_suite.c \
|
|
||||||
test/include/test_suite.h
|
|
||||||
test/include/test_suite.h:
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
|
|
||||||
Binary file not shown.
|
|
@ -1,6 +0,0 @@
|
||||||
../bin/Release/src_api.c.o: src/api.c include/csv.h include/api.h \
|
|
||||||
include/error.h include/csv.h
|
|
||||||
include/csv.h:
|
|
||||||
include/api.h:
|
|
||||||
include/error.h:
|
|
||||||
include/csv.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,2 +0,0 @@
|
||||||
../bin/Release/src_csv.c.o: src/csv.c include/csv.h
|
|
||||||
include/csv.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,2 +0,0 @@
|
||||||
../bin/Release/src_date.c.o: src/date.c include/date.h
|
|
||||||
include/date.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,8 +0,0 @@
|
||||||
bin/Release/src_main.c.o: src/main.c test/include/test.h \
|
|
||||||
test/include/test_suite.h UOCContacts/include/api.h \
|
|
||||||
UOCContacts/include/error.h UOCContacts/include/csv.h
|
|
||||||
test/include/test.h:
|
|
||||||
test/include/test_suite.h:
|
|
||||||
UOCContacts/include/api.h:
|
|
||||||
UOCContacts/include/error.h:
|
|
||||||
UOCContacts/include/csv.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,5 +0,0 @@
|
||||||
../bin/Release/src_person.c.o: src/person.c include/person.h \
|
|
||||||
include/csv.h include/date.h
|
|
||||||
include/person.h:
|
|
||||||
include/csv.h:
|
|
||||||
include/date.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,5 +0,0 @@
|
||||||
bin/Release/test_src_test.c.o: test/src/test.c test/include/test.h \
|
|
||||||
test/include/test_suite.h test/include/test_pr1.h
|
|
||||||
test/include/test.h:
|
|
||||||
test/include/test_suite.h:
|
|
||||||
test/include/test_pr1.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,9 +0,0 @@
|
||||||
bin/Release/test_src_test_pr1.c.o: test/src/test_pr1.c \
|
|
||||||
test/include/test_pr1.h test/include/test_suite.h \
|
|
||||||
UOCContacts/include/api.h UOCContacts/include/error.h \
|
|
||||||
UOCContacts/include/csv.h
|
|
||||||
test/include/test_pr1.h:
|
|
||||||
test/include/test_suite.h:
|
|
||||||
UOCContacts/include/api.h:
|
|
||||||
UOCContacts/include/error.h:
|
|
||||||
UOCContacts/include/csv.h:
|
|
||||||
Binary file not shown.
|
|
@ -1,3 +0,0 @@
|
||||||
bin/Release/test_src_test_suite.c.o: test/src/test_suite.c \
|
|
||||||
test/include/test_suite.h
|
|
||||||
test/include/test_suite.h:
|
|
||||||
BIN
bin/UOC20211
BIN
bin/UOC20211
Binary file not shown.
BIN
bin/UOC20211d
BIN
bin/UOC20211d
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in a new issue