pdirt/data/
pdirt/data/HELP/
pdirt/data/HELP/0/
pdirt/data/HELP/F/
pdirt/data/HELP/G/
pdirt/data/HELP/H/
pdirt/data/HELP/J/
pdirt/data/HELP/K/
pdirt/data/HELP/O/
pdirt/data/HELP/Q/
pdirt/data/HELP/R/
pdirt/data/HELP/U/
pdirt/data/HELP/V/
pdirt/data/HELP/Y/
pdirt/data/HELP/Z/
pdirt/data/MESSAGES/
pdirt/data/POWERINFO/
pdirt/data/WIZ_ZONES/
pdirt/drv/
pdirt/drv/bin/
pdirt/drv/compiler/converter/
pdirt/drv/compiler/libs/
pdirt/drv/compiler/scripts/
pdirt/drv/include/AberChat/
pdirt/drv/include/InterMud/
pdirt/drv/include/machine/
pdirt/drv/src/InterMud/
pdirt/drv/src/Players/
pdirt/drv/utils/UAFPort/
pdirt/drv/utils/dnsresolv/
pdirt/drv/utils/gdbm/
#include <stdio.h>
#include <ctype.h>

#define NEEDSTRING	1
#define NEEDBOOL	2
#define NEEDNUMBER	3
#define CONFIGHEAD	\
"/****************************************************************************
 ** Automatically generated Header
 ** Use config.example if you want to configure it yourself. Just copy that
 ** one over this and edit it.
 **************************************************************************/
#ifndef CONFIG_H
#define CONFIG_H
"

#define CONFIGTAIL     \
"
/*##########################################################################*
 *# END USER CONFIGURATION
 *# You won't need to change anything below this line, unless you turn into
 *# a professional pdirt user.
 *##########################################################################*/

#define DYRT                           /* We use Dyrt based code, no change */

/*#############################################################################
 *# NEED_RANDOM is needed for machines without a random() function. If you need
 *# this is in the machine configuration (see machines.h and the appropriate
 *# file in the include/machine/ dir
 *############################################################################*/ 

#ifdef NEED_RANDOM
#define SYS_NO_RANDOM
#endif

/*############################################################################*
 *# Some systems, like linux have problems with varargs.. Again it is in the
 *# machine configuration file.
 *############################################################################*/
#ifdef NO_VARARGS
#undef VARGS
#else
#define VARGS
#endif

/******************************************************************************
 ** End of the Configuration file
 ** Check the Makefile to see if the right machine is configured.
 ******************************************************************************/#endif /* Do not enter anything below this line !*/ "

#define INTRO		\
"Welcome to pDirt!

You have chosen one of the latest incarnations of the old Abers as either the
base of your mud, or just to look around. I hope you'll like this base and 
have fun with it!

This program will create a configuration file for you by using the options you
give them. Please fill all fields properly as this is just a very basic 
program which doesnt do much checking. If you're new to the world of abers, or
dont know what you are doing, use the default values when you arent sure.

Enjoy\n\n"


typedef struct _Mapping {
    char *func;
    int  needs;
    char *def;
    char *question;
    char *definevar;
} Mapping;
int  now;

Mapping config[] = {
  { "Mudname",	 NEEDSTRING,	"pDirt",	"Please specify your mudname", "MUDNAME" },
  { "MudCol",    NEEDSTRING,    "&+YpDirt",     "Please enter a coloured mudname", "COL_MUDNAME" },
  { "Prompt",    NEEDSTRING,    "> ",           "Please enter the default prompt", "DEFAULT_PROMPT" },
  { "GLobal",    NEEDNUMBER,    "2000",         "Please enter the mobile count limit (use default)", "GLOBAL_MAX_MOBS" },
  { "Global",    NEEDNUMBER,    "5000",         "Please enter the location count limit (use default)", "GLOBAL_MAX_LOCS" },
  { "Global",    NEEDNUMBER,    "3000",         "Please enter the object count limit (use default)", "GLOBAL_MAX_OBJS" },   
  { "Port",	 NEEDNUMBER,	"6715",		"On what port should the mud run", "PORT" },
  { "MasterUser",NEEDSTRING,	NULL,		"Please give the name of the master User", "MASTERUSER"},
  { "Unveil",	 NEEDSTRING,	"dummy",	"Give a password for the Master User account", "UNVEILPASSWD" },
  { "Users",     NEEDNUMBER,    "40",           "Give the player limit for your mud", "MAX_USERS" },
  { "Reboot",    NEEDBOOL,      "Y",            "Do you want to use reboot/update recovery?", "REBOOT" },
  { "Parse",     NEEDBOOL,      "Y",            "Do you want to use a 'smart' parser?", "FIND_SECOND" },
  { "Group",     NEEDBOOL,      "Y",            "Do you want to use the party grouping system" , "GROUP" },
  { "Stealing",  NEEDBOOL,      "N",            "Do you want players to be able to steal from eachother", "ALLOW_PL_STEAL" },
  { "Reset",     NEEDNUMBER,    "1800",		"How long until the reset stone can be hit again (in seconds)", "RESET_TIME" },
  { "Reset2",    NEEDNUMBER,    "600",          "How long can someone be idle and prevent a reset (in seconds)", "RESET_IDLE" },
  { "Idle",      NEEDBOOL,      "Y",            "Do you want to check for idle players", "CHECK_IDLE" },
  { "Idle2",     NEEDNUMBER,    "1800",         "How long can someone be idle before being transported (in seconds", "MAX_IDLE" },
  { "Pages",     NEEDNUMBER,    "24",           "How much lines are there on a screen (use default)", "LINES" },
  { "Qdone",     NEEDBOOL,      "N",            "Show quests in 2 columns (if no then it will show in 3)", "TWOCOLUMNS" },
  { "UAF",       NEEDBOOL,      "Y",            "Use safe userfile access (recommended)", "SAFE_USERFILE" },
  { "Corpse",    NEEDBOOL,      "Y",            "Should deaths leave corpses", "LEAVE_CORPSES" },
  { "Backup",    NEEDBOOL,      "Y",            "Do you want to use the auto player file backup option", "UAF_BACKUP" },
  { "Intermud",  NEEDBOOL,      "N",            "Do you want to connect to Intermud (read info)", "INTERMUD" },
  { "AberChat",  NEEDBOOL,      "N",            "Do you want to connect to Aberchat (read info)", "ABERCHAT" },
  { "Linkdead",  NEEDNUMBER,    "360",          "How long will you sustain a linkdead connection (in seconds)", "KEEP_LINKDEAD" },

  { "Logging",   0,		NULL,		":==========================================================================", "" },
  { "Log",       NEEDBOOL,      "Y",            "Log Resets", "LOG_RESET" }, 
  { "Log",       NEEDBOOL,      "N",            "Log Deaths", "LOG_SLAIN" }, 
  { "Log",       NEEDBOOL,      "Y",            "Log Exorcises", "LOG_EXORCISE" }, 
  { "Log",       NEEDBOOL,      "Y",            "Log Resurrections", "LOG_RESURRECT" },
  { "Log",       NEEDBOOL,      "Y",            "Log Aliassing", "LOG_ALIAS" }, 
  { "Log",       NEEDBOOL,      "Y",            "Log Touting (timeout command)", "LOG_TOUT" }, 
  { "Log",       NEEDBOOL,      "N",            "Log Player Stealing", "LOG_STEAL" },
  { "Log",       NEEDBOOL,      "Y",            "Log Snooping", "LOG_SNOOP" },
  { "Log",       NEEDBOOL,      "Y",            "Log personal heals", "LOG_HEAL" },
  { "Log",       NEEDBOOL,      "Y",            "Log zaps", "LOG_ZAP" },
  { "Log",       NEEDBOOL,      "Y",            "Log War/Peace Commands", "LOG_WAR" }, 
  { "Log",       NEEDBOOL,      "Y",            "Log Set command", "LOG_SET" }, 
  { "Log",       NEEDBOOL,      "N",            "Log Pager Errors (never seen any)", "LOG_PAGEERROR" }, 
  { "Log",       NEEDBOOL,      "Y",            "Log Events Changes", "LOG_EVENTS" }, 
  { "Log",       NEEDBOOL,      "N",            "Log Closing hours of the mud", "LOG_CHOURS" }, 
  { "Log",       NEEDBOOL,      "Y",            "Log Bans/Locks", "LOG_BAN" }, 
  { "Log",       NEEDBOOL,      "Y",            "Log Host lookup errors", "LOG_HOSTERR" }, 
  { "Log",       NEEDBOOL,      "Y",            "Log Healalls", "LOG_HEALALL" }, 
  { "Log",       NEEDBOOL,      "N",            "Log Intermud events", "LOG_INTERMUD" }, 
  { "Log",       NEEDBOOL,      "N",            "Log Defrob/Refrob (fluid immortality)", "LOG_DEFROB" }, 
  { "Log",       NEEDBOOL,      "N",            "Log Clone (Clone system)", "LOG_CLONE" }, 
  { "Log2",      NEEDBOOL,      "N",            "Log Store (Clone system)", "LOG_STORE" },
  { "Log3",      NEEDBOOL,      "N",            "Log Load (Clone system)",  "LOG_LOAD" }, 
  { NULL,	 0,		NULL,		NULL, NULL}
};
    
char *getstring()
{   static char buffer[512];
    char   *s = NULL; 
    int    i;

    while (s == NULL)
    {  s = fgets(buffer,511,stdin);

      if (s == NULL || *s == '\n' || *s == '\0')
      {   if (config[now].def == NULL)
          {   printf("%s: ",config[now].question);
              s = NULL;
          }
          else
             return config[now].def;
      }
   }
   i = strlen(s);

   while (s[i] == '\n' || s[i] == '\0' || s[i] == '\r')
        s[i--] = '\0';
   return s;
}

int testyesno(char *str)
{   if (*str == 'y' || *str == 'Y')
       return 1;

    return 0;
}

int getyesno()
{   char *yn;

    yn = getstring();
    return testyesno(yn);
}

int getnum()
{   char *str;

    str = getstring();

    return atoi(str);
}

void make_config()
{   int  i;
    FILE *fp;
    char  *str;
    int   num;

    fp = fopen("include/config.h","w");
    fprintf(fp,"%s\n\n",CONFIGHEAD);

    for (i=0; config[i].func != NULL; i++)
    {   printf("%s",config[i].question);
        if (config[i].def != NULL)
           printf(" [%s]",config[i].def);
        printf(": ");
    
        now = i;    
        switch (config[i].needs) {
        case NEEDSTRING:  
		str = getstring(); 
        	fprintf(fp,"#define %s\t\t\"%s\"\n",config[i].definevar,str);
		break;
        case NEEDNUMBER:    
		num = getnum(); 
        	fprintf(fp,"#define %s\t\t%d\n",config[i].definevar,num);
		break;
        case NEEDBOOL:  
		num = getyesno(); 
                if (num)
        	   fprintf(fp,"#define %s\n",config[i].definevar);
                else
        	   fprintf(fp,"#undef  %s\n",config[i].definevar);
		break;
        default:
               printf("\n");
               fprintf(fp,"\n");
        }
    }
    fprintf(fp,"\n\n%s\n",CONFIGTAIL);
    fclose(fp);
}

int main()
{  printf(INTRO);
   make_config();
}