forked from menault/TD2_DEV51_Qualite_Algo
Add: Function regrex
This commit is contained in:
@@ -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(®, line, 2, pmatch, 0) != 0){
|
||||
regfree(®);
|
||||
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(®);
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(*ping, &line[start], size_ping);
|
||||
(*ping)[size_ping] = '\0';
|
||||
|
||||
regfree(®);
|
||||
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 :
|
||||
|
Reference in New Issue
Block a user