//
// aegis - project change supervisor
// Copyright (C) 2008, 2012 Peter Miller
//
// This program 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.
//
// This program 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.
//
// You should have received a copy of the GNU General Public License along
// with this program. If not, see .
//
#include
#include
#include
#include
generator::~generator()
{
}
generator::generator(const nstring &filename) :
ip(indent::create(filename))
{
this_file_is_generated();
}
void
generator::this_file_is_generated()
{
/*
* DO NOT insert a timestamp in the generated files, it needlessly
* changes the fingerprint. This, in turn, causes cook to cook
* too much, compiling several hundred files which do not need to
* be compiled.
*/
printf
(
"//\n"
"// This file is generated by %s.\n"
"//\n",
progname_get()
);
}
nstring
generator::base_name(const nstring &s)
{
const char *cp = strrchr(s.c_str(), '/');
if (cp)
++cp;
else
cp = s.c_str();
char buffer[256];
strendcpy(buffer, cp, buffer + sizeof(buffer));
char *bp = strrchr(buffer, '.');
if (bp)
*bp = 0;
for (bp = buffer; *bp; ++bp)
{
if (!isalnum((unsigned char)*bp))
*bp = '_';
}
return buffer;
}
void
generator::printf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
void
generator::vprintf(const char *fmt, va_list ap)
{
ip->vprintf(fmt, ap);
}
void
generator::wrap_and_print(const nstring &text)
{
ip->wrap_and_print("", text);
}
void
generator::wrap_and_print(const nstring &prefix, const nstring &text)
{
ip->wrap_and_print(prefix, text);
}
void
generator::include_once(const nstring &filename)
{
ip->include_once(filename);
}
nstring
generator::calculate_include_file_name(const nstring &code_file_name)
{
nstring name = code_file_name.downcase();
if (name.ends_with(".cpp"))
return (code_file_name.substr(0, code_file_name.size() - 3) + "h");
if (name.ends_with(".cc"))
return (code_file_name.substr(0, code_file_name.size() - 2) + "h");
if (name.ends_with(".c"))
return (code_file_name.substr(0, code_file_name.size() - 1) + "h");
return (code_file_name + ".h");
}
// vim: set ts=8 sw=4 et :