MySQL config loading (was Arcane Realms Snippets)

From: Artovil (artovil@arcanerealms.org)
Date: 03/10/02


I hope this is ok?  No bad code or anything... It's getting late, so send
flames to /dev/null, any constructive comments are more than welcome.  I
hope someone can use this...

Uhm, I now realized that this is using the file functions from the ascii
file package.  Shouldn't be too hard to adapt it to a mud without, or?

Regards,
/Torgny

The config file should look like this:
--8<-----------
host: localhost
db  : YOUR_DB
user: YOUR_USER
pass: YOUR_PASS
--8<-----------

Here's the function, put it in db.c and prototype it:
--8<-----------
void load_sql_settings(void) {
        FBFILE *fl;
        char line[MAX_INPUT_LENGTH + 1], tag[6];

        if(!(fl = fbopen(LIB_ETC"mysql", FB_READ))) {
                extended_mudlog(BRF, SYSL_SQL, TRUE, "SYSERR: Couldn't open MySQL
settings.");
                exit(1);
        }

        while(fbgetline(fl, line)) {
                tag_argument(line, tag);

                if(!strcmp(tag, "host"))
                        mysql_host = str_dup(line);
                else if(!strcmp(tag, "db  "))
                        mysql_db = str_dup(line);
                else if(!strcmp(tag, "user"))
                        mysql_usr = str_dup(line);
                else if(!strcmp(tag, "pass"))
                        mysql_pwd = str_dup(line);
                else {
                        extended_mudlog(BRF, SYSL_SQL, TRUE, "SYSERR: Unknown option %s in MySQL
settings.", line);
                        exit(1);
                }
        }

        fbclose(fl);

}
--8<-----------
You also need to stick these in the top of db.c:

extern char *mysql_host;
extern char *mysql_db;
extern char *mysql_usr;
extern char *mysql_pwd;

Then, in comm.c:
char *mysql_host;
char *mysql_db;
char *mysql_usr;
char *mysql_pwd;

And further down in int main(), above if (scheck):
--8<-----------
        load_sql_settings();
        init_mysql(mysql_db);
--8<-----------

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT