a3893022e1a44f898ec19e7e1043472685057582 kent Fri Jan 30 14:07:05 2015 -0800 Implementing a raNextTagValWithIndent function. diff --git src/lib/ra.c src/lib/ra.c index efabdf3..03b4478 100644 --- src/lib/ra.c +++ src/lib/ra.c @@ -31,70 +31,85 @@ if (tag[0] == 0 || tag[0] == '#') { if (dy) { dyStringAppend(dy, line); dyStringAppendC(dy, '\n'); } } else break; } lineFileReuse(lf); return TRUE; } -boolean raNextTagVal(struct lineFile *lf, char **retTag, char **retVal, struct dyString *dyRecord) +boolean raNextTagValWithIndent(struct lineFile *lf, char **retTag, char **retVal, struct dyString *dy, + int *retIndent) // Read next line. Return FALSE at end of file or blank line. Otherwise fill in -// *retTag and *retVal and return TRUE. If dy parameter is non-null, then the text parsed -// gets appended to dy. Continuation lines in RA file will be joined to produce tag and val, -// but dy will be filled with the unedited multiple lines containing the continuation chars. +// *retTag and *retVal and *retIndent and return TRUE. If dy parameter is non-null, then +// the text parsed gets appended to dy. Continuation lines in RA file will be joined to produce +// tag and val, but dy will be filled with the unedited multiple lines containing the continuation chars. // NOTE: retTag & retVal, if returned, point to static mem which will be overwritten on next call! { *retTag = NULL; *retVal = NULL; char *line, *raw = NULL; int lineLen,rawLen; // Don't bother with raw if it isn't used. char **pRaw = NULL; int *pRawLen = NULL; -if (dyRecord != NULL) +if (dy != NULL) { pRaw = &raw; pRawLen = &rawLen; } while (lineFileNextFull(lf, &line, &lineLen, pRaw, pRawLen)) // Joins continuation lines { char *clippedText = skipLeadingSpaces(line); if (*clippedText == 0) { - if (dyRecord) + if (dy) lineFileReuse(lf); // Just so don't loose leading space in dy. return FALSE; } + if (retIndent != NULL) + { + int indentLevel = 0; + char *s = line; + while (s < clippedText) + { + char c = *s++; + if (c == '\t') + indentLevel = ((indentLevel+8) & 0xfffffff8); + else + indentLevel += 1; + } + *retIndent = indentLevel; + } // Append whatever line was read from file. - if (dyRecord) + if (dy) { if (raw != NULL) - dyStringAppendN(dyRecord, raw, rawLen); + dyStringAppendN(dy, raw, rawLen); else - dyStringAppendN(dyRecord, line, lineLen); - dyStringAppendC(dyRecord,'\n'); + dyStringAppendN(dy, line, lineLen); + dyStringAppendC(dy,'\n'); } // Skip comments if (*clippedText == '#') { if (startsWith("#EOF", clippedText)) return FALSE; else continue; } *retTag = nextWord(&line); *retVal = trimSpaces(line); return TRUE; } return FALSE;