]> arthur.barton.de Git - netdata.git/blobdiff - src/procfile.h
dns_query_time plugin: replace "." with "_" in dimensions
[netdata.git] / src / procfile.h
index 5e00b25842613e205aba7052647965d6c17694cf..98765697f59ea07dc735a4e6e7a1bdf44a31705c 100644 (file)
@@ -30,8 +30,8 @@
 // An array of words
 
 typedef struct {
-    uint32_t len;   // used entries
-    uint32_t size;  // capacity
+    size_t len;     // used entries
+    size_t size;    // capacity
     char *words[];  // array of pointers
 } pfwords;
 
@@ -40,15 +40,15 @@ typedef struct {
 // An array of lines
 
 typedef struct {
-    uint32_t words;     // how many words this line has
-    uint32_t first;     // the id of the first word of this line
-                // in the words array
+    size_t words;   // how many words this line has
+    size_t first;   // the id of the first word of this line
+                    // in the words array
 } ffline;
 
 typedef struct {
-    uint32_t len;       // used entries
-    uint32_t size;      // capacity
-    ffline lines[];     // array of lines
+    size_t len;     // used entries
+    size_t size;    // capacity
+    ffline lines[]; // array of lines
 } pflines;
 
 
@@ -58,16 +58,26 @@ typedef struct {
 #define PROCFILE_FLAG_DEFAULT             0x00000000
 #define PROCFILE_FLAG_NO_ERROR_ON_FILE_IO 0x00000001
 
+typedef enum procfile_separator {
+    PF_CHAR_IS_SEPARATOR,
+    PF_CHAR_IS_NEWLINE,
+    PF_CHAR_IS_WORD,
+    PF_CHAR_IS_QUOTE,
+    PF_CHAR_IS_OPEN,
+    PF_CHAR_IS_CLOSE
+} PF_CHAR_TYPE;
+
 typedef struct {
-    char filename[FILENAME_MAX + 1];
+    char filename[FILENAME_MAX + 1]; // not populated until profile_filename() is called
+
     uint32_t flags;
-    int fd;         // the file desriptor
-    size_t len;     // the bytes we have placed into data
-    size_t size;        // the bytes we have allocated for data
+    int fd;               // the file desriptor
+    size_t len;           // the bytes we have placed into data
+    size_t size;          // the bytes we have allocated for data
     pflines *lines;
     pfwords *words;
-    char separators[256];
-    char data[];        // allocated buffer to keep file contents
+    PF_CHAR_TYPE separators[256];
+    char data[];          // allocated buffer to keep file contents
 } procfile;
 
 // close the proc file and free all related memory
@@ -89,6 +99,8 @@ extern void procfile_print(procfile *ff);
 extern void procfile_set_quotes(procfile *ff, const char *quotes);
 extern void procfile_set_open_close(procfile *ff, const char *open, const char *close);
 
+extern char *procfile_filename(procfile *ff);
+
 // ----------------------------------------------------------------------------
 
 // set this to 1, to have procfile adapt its initial buffer allocation to the max allocation used so far