Tue Aug 18 00:42:33 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
[citadel.git] / citadel / config.c
1 /*
2  * This function reads the citadel.config file.  It should be called at
3  * the beginning of EVERY Citadel program.
4  */
5
6 #include "sysdep.h"
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <errno.h>
11 #include <string.h>
12 #include <limits.h>
13 #include "citadel.h"
14 #include "config.h"
15
16 struct config config;
17 char bbs_home_directory[PATH_MAX];
18 int home_specified = 0;
19
20 void get_config(void) {
21         FILE *cfp;
22
23         if (chdir( home_specified ? bbs_home_directory : BBSDIR ) != 0) {
24                 fprintf(stderr, "Cannot start.\nThere is no Citadel installation in %s\n%s\n",
25                         (home_specified ? bbs_home_directory : BBSDIR),
26                         strerror(errno));
27                 exit(errno);
28                 }
29         cfp=fopen("citadel.config","r");
30         if (cfp==NULL) {
31                 fprintf(stderr, "Cannot start.\n");
32                 fprintf(stderr, "There is no citadel.config in %s\n%s\n",
33                         (home_specified ? bbs_home_directory : BBSDIR),
34                         strerror(errno));
35                 exit(errno);
36                 }
37         fread((char *)&config,sizeof(struct config),1,cfp);
38         fclose(cfp);
39         if ( (config.c_setup_level / 10) != (REV_LEVEL/10) ) {
40                 fprintf(stderr, "config: Your data files are out of date.  ");
41                 fprintf(stderr, "Run setup to update them.\n");
42                 fprintf(stderr,
43                         "        This program requires level %d.%02d\n",
44                                 (REV_LEVEL / 100), (REV_LEVEL % 100) );
45                 fprintf(stderr,
46                         "        Data files are currently at %d.%02d\n",
47                                 (config.c_setup_level / 100),
48                                 (config.c_setup_level % 100) );
49                 exit(1);
50                 }
51         }