Copyright (C) Kevin Larke 2009-2020

This file is part of libcm.

libcm is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

libcm is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See the GNU General Public License distributed with the libcm package or look here: .


cmTextTemplate : Generate text using templates with replaceable variables.
enum
{
  kOkTtRC = cmOkRC,
  kFileFailTtRC,
  kLHeapFailTtRC,
  kSyntaxErrTtRC,
  kFindFailTtRC,
  kInvalidTypeTtRC,
  kJsonFailTtRC
};

typedef cmHandle_t cmTtH_t;
typedef unsigned   cmTtRC_t;
extern  cmTtH_t    cmTtNullHandle;

// Initialize a template file.
cmTtRC_t cmTextTemplateInitialize( cmCtx_t* ctx, cmTtH_t* hp, const cmChar_t* fn );

// Finalize a template file
cmTtRC_t cmTextTemplateFinalize( cmTtH_t* hp );

// Return true if the template file is intialized.
bool     cmTextTemplateIsValid( cmTtH_t h );

// Set the value of a template variable.
// The node identified by { label,index, label, index ... } must
// be a variable node.  The function will fail if a 'set' or 'text' node
// is identified.
// Set 'value' to NULL to erase a previously set value.
cmTtRC_t cmTextTemplateSetValue( cmTtH_t h, const cmChar_t* value, const cmChar_t* label, unsigned index, ... );

// Create a copy of the sub-tree identified by the variable path
// and insert it as the left sibling of the sub-tree's root.
cmTtRC_t cmTextTemplateRepeat( cmTtH_t h, const cmChar_t* label, unsigned index, ... );

// Write the template file.
cmTtRC_t cmTextTemplateWrite( cmTtH_t h, const cmChar_t* fn );

// Apply a template value JSON file to this template
cmTtRC_t cmTextTemplateApply( cmTtH_t h, const cmChar_t* fn );

// Print an annotated template tree.
void cmTtPrintTree( cmTtH_t h, cmRpt_t* rpt );

cmTtRC_t cmTextTemplateTest( cmCtx_t* ctx, const cmChar_t* fn );