-procfile *procfile_parser(procfile *ff) {
- debug(D_PROCFILE, PF_PREFIX ": Parsing file '%s'", ff->filename);
-
- char *s = ff->data, *e = &ff->data[ff->len], *t = ff->data, quote = 0;
- uint32_t l = 0, w = 0;
- int opened = 0;
-
- ff->lines = pflines_add(ff->lines, w);
- if(unlikely(!ff->lines)) goto cleanup;
-
- while(likely(s < e)) {
- // we are not at the end
-
- switch(ff->separators[(uint8_t)(*s)]) {
- case PF_CHAR_IS_OPEN:
- if(s == t) {
- opened++;
- t = ++s;
- }
- else if(opened) {
- opened++;
- s++;
- }
- else
- s++;
- continue;
-
- case PF_CHAR_IS_CLOSE:
- if(opened) {
- opened--;
-
- if(!opened) {
- *s = '\0';
- ff->words = pfwords_add(ff->words, t);
- if(unlikely(!ff->words)) goto cleanup;
-
- ff->lines->lines[l].words++;
- w++;
-
- t = ++s;
- }
- else
- s++;
- }
- else
- s++;
- continue;
-
- case PF_CHAR_IS_QUOTE:
- if(unlikely(!quote && s == t)) {
- // quote opened at the beginning
- quote = *s;
- t = ++s;
- }
- else if(unlikely(quote && quote == *s)) {
- // quote closed
- quote = 0;
-
- *s = '\0';
- ff->words = pfwords_add(ff->words, t);
- if(unlikely(!ff->words)) goto cleanup;
-
- ff->lines->lines[l].words++;
- w++;
-
- t = ++s;
- }
- else
- s++;
- continue;
-
- case PF_CHAR_IS_SEPARATOR:
- if(unlikely(quote || opened)) {
- // we are inside a quote
- s++;
- continue;
- }
-
- if(unlikely(s == t)) {
- // skip all leading white spaces
- t = ++s;
- continue;
- }
-
- // end of word
- *s = '\0';
-
- ff->words = pfwords_add(ff->words, t);
- if(unlikely(!ff->words)) goto cleanup;
-
- ff->lines->lines[l].words++;
- w++;
-
- t = ++s;
- continue;
-
- case PF_CHAR_IS_NEWLINE:
- // end of line
- *s = '\0';
-
- ff->words = pfwords_add(ff->words, t);
- if(unlikely(!ff->words)) goto cleanup;
-
- ff->lines->lines[l].words++;
- w++;
-
- // debug(D_PROCFILE, PF_PREFIX ": ended line %d with %d words", l, ff->lines->lines[l].words);
-
- ff->lines = pflines_add(ff->lines, w);
- if(unlikely(!ff->lines)) goto cleanup;
- l++;
-
- t = ++s;
- continue;
-
- default:
- s++;
- continue;
- }
- }
-
- if(likely(s > t && t < e)) {
- // the last word
- if(likely(ff->len < ff->size))
- *s = '\0';
- else {
- // we are going to loose the last byte
- ff->data[ff->size - 1] = '\0';
- }
-
- ff->words = pfwords_add(ff->words, t);
- if(unlikely(!ff->words)) goto cleanup;
-
- ff->lines->lines[l].words++;
- w++;
- }
-
- return ff;
-
-cleanup:
- error(PF_PREFIX ": Failed to parse file '%s'", ff->filename);
- procfile_close(ff);
- return NULL;
+static inline void procfile_parser(procfile *ff) {
+ // debug(D_PROCFILE, PF_PREFIX ": Parsing file '%s'", ff->filename);
+
+ register char *s = ff->data, *e = &ff->data[ff->len], *t = ff->data;
+ register char *separators = ff->separators;
+ char quote = 0;
+ size_t l = 0, w = 0, opened = 0;
+
+ ff->lines = pflines_add(ff->lines, w);
+
+ while(likely(s < e)) {
+ // we are not at the end
+
+ switch(separators[(unsigned char)(*s)]) {
+ case PF_CHAR_IS_OPEN:
+ if(s == t) {
+ opened++;
+ t = ++s;
+ }
+ else if(opened) {
+ opened++;
+ s++;
+ }
+ else
+ s++;
+ break;
+
+ case PF_CHAR_IS_CLOSE:
+ if(opened) {
+ opened--;
+
+ if(!opened) {
+ *s = '\0';
+ ff->words = pfwords_add(ff->words, t);
+ ff->lines->lines[l].words++;
+ w++;
+
+ t = ++s;
+ }
+ else
+ s++;
+ }
+ else
+ s++;
+ break;
+
+ case PF_CHAR_IS_QUOTE:
+ if(unlikely(!quote && s == t)) {
+ // quote opened at the beginning
+ quote = *s;
+ t = ++s;
+ }
+ else if(unlikely(quote && quote == *s)) {
+ // quote closed
+ quote = 0;
+
+ *s = '\0';
+ ff->words = pfwords_add(ff->words, t);
+ ff->lines->lines[l].words++;
+ w++;
+
+ t = ++s;
+ }
+ else
+ s++;
+ break;
+
+ case PF_CHAR_IS_SEPARATOR:
+ if(unlikely(quote || opened)) {
+ // we are inside a quote
+ s++;
+ break;
+ }
+
+ if(unlikely(s == t)) {
+ // skip all leading white spaces
+ t = ++s;
+ break;
+ }
+
+ // end of word
+ *s = '\0';
+
+ ff->words = pfwords_add(ff->words, t);
+ ff->lines->lines[l].words++;
+ w++;
+
+ t = ++s;
+ break;
+
+ case PF_CHAR_IS_NEWLINE:
+ // end of line
+ *s = '\0';
+
+ ff->words = pfwords_add(ff->words, t);
+ ff->lines->lines[l].words++;
+ w++;
+
+ // debug(D_PROCFILE, PF_PREFIX ": ended line %d with %d words", l, ff->lines->lines[l].words);
+
+ ff->lines = pflines_add(ff->lines, w);
+ l++;
+
+ t = ++s;
+ break;
+
+ default:
+ s++;
+ break;
+ }
+ }
+
+ if(likely(s > t && t < e)) {
+ // the last word
+ if(likely(ff->len < ff->size))
+ *s = '\0';
+ else {
+ // we are going to loose the last byte
+ ff->data[ff->size - 1] = '\0';
+ }
+
+ ff->words = pfwords_add(ff->words, t);
+ ff->lines->lines[l].words++;
+ }