Beispiel #1
0
static ASTPtr generateCCs(std::vector<ConsistentContent>* ccs, const char* format, const char*** wordSourcesPtr, const LengthFunc** lengthFuncsPtr, va_list args) {
  ccs->clear();
  std::string evaluatedFormat;
  vsprintf(&evaluatedFormat, format, args);
  const char* f_begin = evaluatedFormat.c_str();
  const char* f_at = f_begin;
  ASTPtr root;
  try {
    //printf("\n\n%s\n", format);

    root = parseFormat(&f_at, wordSourcesPtr, lengthFuncsPtr);
    root->convertLLSharesToLength();
    root->computeStartEndCols(0, root->getFixedLength());

    std::vector<FillerPtr> topFillersStack, bottomFillersStack;
    root->flatten(root, root, ccs, true, &topFillersStack, &bottomFillersStack);
    //root->print();
    //printf("\n");

    for (ConsistentContent& cc : *ccs) {
      cc.generateCCLines();
    }

    root->computeNumContentLines();
    root->computeNumTotalLines(true);
    root->computeBlockVerticalFillersShares();

    //printf("\n");
    for (ConsistentContent& cc : *ccs) {
      /*printf("\n");
      cc.print();
      printf("\n");
      printf("content: %d  fixed: %d  total: %d\n", cc.srcAst->numContentLines, cc.srcAst->numFixedLines, cc.srcAst->numTotalLines);*/
      cc.generateLinesChars(root->numTotalLines);
    }
    //printf("\n\n");

  } catch (DSLException& e) {
    fprintf(stderr, "%s\n", f_begin);
    for (int i = 0; i < e.f_at - f_begin; ++i) {
      fputc(' ', stderr);
    }
    fprintf(stderr, "^\n");
    fprintf(stderr, "Error at %d: %s\n", e.f_at - f_begin, e.what());
    
    return ASTPtr();
  }

  return root;
}
Beispiel #2
0
static ASTPtr parseFormat(const char** fptr, const char*** wordSourcesPtr, const LengthFunc** lengthFuncsPtr) {
  parseWhitespaces(fptr);
  // Will insert all root content as children into a super-root Block.
  Block* rootsParentBlock = new Block(*fptr, LiteralLength(0, false));
  ASTPtr rootsParent(rootsParentBlock);
  while (**fptr != '\0') {
    if (**fptr == '\'' || std::isdigit(**fptr)) {
      ASTPtr root = parseSpecifiedLengthContent(fptr, wordSourcesPtr, lengthFuncsPtr);
      int rootLength = root->getFixedLength();
      if (rootLength == UNKNOWN_COL) {
        throw DSLException(root->f_at, "Root content must be fixed-length.");
      }
      rootsParentBlock->addChild(std::move(root));
      rootsParentBlock->length.value += rootLength;
    } else {
      throw DSLException(*fptr, "Expected ' or digit.");
    }
  }
  return rootsParent;
}