/*

                                   _JNJ`                        
                               .JNMH`                           
                              JMMF`       `;.                   
                            .NMM)          `MN.                 
                            MMM)            (MML                
                           (MMM`             MMML               
                     M  I  D  N  I  G  H  T    C  o  D  E       
                           (NMMF             MHNH               
                            NMML            .MMM                
                             NMML          .NMH                 
                              4MMNL       .#F                   
                               `4HNNL_   `                      
                                   `"""`                        

                          Copyright (C) 2004-2005
       "Ian (Larry) Latter" <ian dot latter at midnightcode dot org>

    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, and mirrored at the Midnight Code web
    site; as at version 2 of the License only.
  
    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
    (version 2) along with this program; if not, write to the Free
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA, or see http://midnightcode.org/gplv2.txt

*/

/* midnightcode-license.c :: Midnight Code license library		*/


#include <stdio.h>
#include <string.h>

#include "midnightcode-colour.h"
#include "midnightcode-license.h"


char midnightcode_license_text_copyright[2][80] = {
  "                          Copyright (C) 2004-2005",
  "       \"Ian (Larry) Latter\" <ian dot latter at midnightcode dot org>"
  };

char midnightcode_license_text_freesoft[4][80] = {
  "    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, and mirrored at the Midnight Code web",
  "    site; as at version 2 of the License only."
  };
  
char midnightcode_license_text_warranty[4][80] = {
  "    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."
  };
  
char midnightcode_license_text_license[5][80] = {
  "    You should have received a copy of the GNU General Public License",
  "    (version 2) along with this program; if not, write to the Free",
  "    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA",
  "    02111-1307 USA, or see http://midnightcode.org/gplv2.txt"
  };


void
midnightcode_license(int padding, int style, int sections) {
  int	element;
  char  pad[81];


  memset(pad, 0, 81);
  if(padding == 0 || padding > 50) {
    padding = 4;
  }
  memset(pad, ' ', padding);

  if(sections < MIDNIGHTCODE_LICENSE_TEXT_NONE ||
     sections > MIDNIGHTCODE_LICENSE_TEXT_ALL) {
    sections = MIDNIGHTCODE_LICENSE_TEXT_ALL;
  }

  if(style != MIDNIGHTCODE_LICENSE_STYLE_ASCII) {
    switch(style) {
      default:
        fprintf(stdout, MIDNIGHTCODE_COLOUR_DK_GREY);
        break;
    }
  }

  if(sections & MIDNIGHTCODE_LICENSE_TEXT_COPYRIGHT) {
    for(element=0; element<2; element++) {
      fprintf(stdout, "%s\n", midnightcode_license_text_copyright[element]);
    }
    fprintf(stdout, "\n");
  }

  if(sections & MIDNIGHTCODE_LICENSE_TEXT_GPLV2) {
    for(element=0; element<4; element++) {
      fprintf(stdout, "%s\n", midnightcode_license_text_freesoft[element]);
    }
    fprintf(stdout, "\n");
  }

  if(sections & MIDNIGHTCODE_LICENSE_TEXT_WARRANTY) {
    for(element=0; element<4; element++) {
      fprintf(stdout, "%s\n", midnightcode_license_text_warranty[element]);
    }
    fprintf(stdout, "\n");
  }

  if(sections & MIDNIGHTCODE_LICENSE_TEXT_GETGPL) {
    for(element=0; element<4; element++) {
      fprintf(stdout, "%s\n", midnightcode_license_text_license[element]);
    }
    fprintf(stdout, "\n");
  }

  if(style != MIDNIGHTCODE_LICENSE_STYLE_ASCII) {
    fprintf(stdout, MIDNIGHTCODE_COLOUR_NORMAL);
  }

  fflush(stdout);

  return;
}


