/*
 * File automatically generated by
 * gengen 1.0 by Lorenzo Bettini 
 * http://www.gnu.org/software/gengen
 */

#ifndef GENSTRINGFUN_GEN_CLASS_H
#define GENSTRINGFUN_GEN_CLASS_H

#include <string>
#include <iostream>

using std::string;
using std::ostream;

class genstringfun_gen_class
{
 protected:

 public:
  genstringfun_gen_class()
  {
  }
  

  void generate_genstringfun(ostream &stream, unsigned int indent = 0)
  {
    string indent_str (indent, ' ');
    indent = 0;
  
    stream << "\n";
    stream << indent_str;
    stream << "static void";
    stream << "\n";
    stream << indent_str;
    stream << "generate_string(const char *s, FILE *stream, unsigned int indent)";
    stream << "\n";
    stream << indent_str;
    stream << "{";
    stream << "\n";
    stream << indent_str;
    stream << "  const char *sub = s;";
    stream << "\n";
    stream << indent_str;
    stream << "  char *indent_str;";
    stream << "\n";
    stream << indent_str;
    stream << "  unsigned int i;";
    stream << "\n";
    stream << indent_str;
    stream << "\n";
    stream << indent_str;
    stream << "  if (!indent || strchr (s, '\\n') == 0)";
    stream << "\n";
    stream << indent_str;
    stream << "    {";
    stream << "\n";
    stream << indent_str;
    stream << "      fprintf (stream, \"%s\", s);";
    stream << "\n";
    stream << indent_str;
    stream << "      return;";
    stream << "\n";
    stream << indent_str;
    stream << "    }";
    stream << "\n";
    stream << indent_str;
    stream << "\n";
    stream << indent_str;
    stream << "  indent_str = (char *) malloc (indent + 1);";
    stream << "\n";
    stream << indent_str;
    stream << "  for (i = 0; i < indent; ++i)";
    stream << "\n";
    stream << indent_str;
    stream << "    indent_str[i] = ' ';";
    stream << "\n";
    stream << indent_str;
    stream << "  indent_str[indent] = '\\0';";
    stream << "\n";
    stream << indent_str;
    stream << "\n";
    stream << indent_str;
    stream << "  while ( (sub=strchr (s, '\\n')) != 0 )";
    stream << "\n";
    stream << indent_str;
    stream << "    {";
    stream << "\n";
    stream << indent_str;
    stream << "      fwrite (s, sizeof(char), (sub-s)+1, stream);";
    stream << "\n";
    stream << indent_str;
    stream << "      s = sub+1;";
    stream << "\n";
    stream << indent_str;
    stream << "      if (s[0])";
    stream << "\n";
    stream << indent_str;
    stream << "        fprintf (stream, \"%s\", indent_str);";
    stream << "\n";
    stream << indent_str;
    stream << "    }";
    stream << "\n";
    stream << indent_str;
    stream << "  if (s[0])";
    stream << "\n";
    stream << indent_str;
    stream << "    fwrite (s, sizeof(char), strlen (s), stream);";
    stream << "\n";
    stream << indent_str;
    stream << "\n";
    stream << indent_str;
    stream << "  free (indent_str);";
    stream << "\n";
    stream << indent_str;
    stream << "}";
    stream << "\n";
    stream << indent_str;
    stream << "\n";
    stream << indent_str;
  }
};

#endif // GENSTRINGFUN_GEN_CLASS_H
