Add: Function regrex

This commit is contained in:
2025-09-17 09:36:48 +02:00
parent 40e269449c
commit db5f6bd795

View File

@@ -21,7 +21,45 @@
None
Return value :
Ping value as a string or NULL if an error occured
*/
*/ /*Fonction pour compiler et exécuter le regex */
/*@null@*/ int extract_ping_from_line(const char* line, char** ping){
regex_t reg;
regmatch_t pmatch[2];
int start, end, size_ping;
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
return -1;
}
if(regrexec(&reg, line, 2, pmatch, 0) != 0){
regfree(&reg);
return -1;
}
start = (int)pmatch[1].rm_so;
end = (int)pmatch[1].rm_eo;
size_ping = end - start;
*ping = malloc(sizeof(char) * (size_ping + 1));
if( *ping == NULL){
regfree(&reg);
return -1;
}
strncpy(*ping, &line[start], size_ping);
(*ping)[size_ping] = '\0';
regfree(&reg);
return 0;
}
/*@null@*/char* read_ping_from_file(const char)
/*@null@*/char* get_ping_from_temp_log(){
/* Variables */
@@ -123,6 +161,8 @@
return ping;
}
/*
-- write_ping_log --
Desc :