Main Page | Data Structures | Directories | File List | Data Fields | Globals

fileutil.h File Reference

Go to the source code of this file.

Defines

#define LC_PATH_MAX   4096

Functions

void gunzip_file (char *f1, char *f2)
int file_exists (char *filename)
int directory_exists (char *dir)
char * load_graphic (char *s)
void undosify_string (char *s)
void load_lincityrc (void)
void save_lincityrc (void)
void debug_printf (char *fmt,...)

Variables

char * lc_save_dir
char * lc_temp_file
int lc_save_dir_len
char colour_pal_file [LC_PATH_MAX]
char opening_pic [LC_PATH_MAX]
char graphic_path [LC_PATH_MAX]
char fontfile [LC_PATH_MAX]
char opening_path [LC_PATH_MAX]
char help_path [LC_PATH_MAX]
char message_path [LC_PATH_MAX]
char lc_textdomain_directory [LC_PATH_MAX]
char lincityrc_file [LC_PATH_MAX]
char given_scene [LC_PATH_MAX]


Define Documentation

#define LC_PATH_MAX   4096
 

Definition at line 22 of file fileutil.h.


Function Documentation

void debug_printf char *  fmt,
  ...
 

int directory_exists char *  dir  ) 
 

Definition at line 241 of file fileutil.c.

00242 {
00243 #if defined (WIN32)
00244     if (_chdir (dir) == -1) {
00245         _chdir (LIBDIR);                /* go back... */
00246         return 0;
00247     }
00248     _chdir (LIBDIR);            /* go back... */
00249 #else /* UNIX */
00250     DIR *dp;
00251     if ((dp = opendir (dir)) == NULL) {
00252         return 0;
00253     }
00254     closedir (dp);
00255 #endif
00256     return 1;
00257 }

int file_exists char *  filename  ) 
 

Definition at line 260 of file fileutil.c.

00261 {
00262     FILE* fp;
00263     fp = fopen (filename,"rb");
00264     if (fp == NULL) {
00265         return 0;
00266     }
00267     fclose (fp);
00268     return 1;
00269 }

void gunzip_file char *  f1,
char *  f2
 

Definition at line 181 of file fileutil.c.

00182 {
00183   int ret_value = execute_command ("gzip -c -d", f1, ">", f2);
00184   if (ret_value != 0)
00185     {
00186       /* GCS FIX:  Need to make do_error into var_args fn? */
00187       printf ("Tried to gzip -c -d %s > %s\n", f1, f2);
00188       do_error ("Can't gunzip requested file");
00189     }
00190 }

char* load_graphic char *  s  ) 
 

Definition at line 644 of file fileutil.c.

00645 {
00646     int x,l;
00647     char ss[LC_PATH_MAX],*graphic;
00648     FILE *inf;
00649     strcpy(ss,graphic_path);
00650     strcat(ss,s);
00651     if ((inf=fopen(ss,"rb"))==NULL)
00652     {
00653         strcat(ss," -- UNABLE TO LOAD");
00654         do_error(ss);
00655     }
00656     fseek(inf,0L,SEEK_END);
00657     l=ftell(inf);
00658     fseek(inf,0L,SEEK_SET);
00659     graphic=(char *)malloc(l);
00660     for (x=0;x<l;x++)
00661         *(graphic+x)=fgetc(inf);
00662     fclose(inf);
00663     return(graphic);
00664 }

void load_lincityrc void   ) 
 

Definition at line 667 of file fileutil.c.

00668 {
00669     FILE *fp;
00670     int arg;
00671     char buf[128];
00672 
00673     if ((fp = fopen (lincityrc_file, "r")) == 0) {
00674         save_lincityrc();
00675         return;
00676     }
00677     while (fgets (buf,128,fp)) {
00678         if (sscanf(buf,"overwrite_transport=%d",&arg)==1) {
00679             overwrite_transport_flag = !!arg;
00680             continue;
00681         }
00682         if (sscanf(buf,"no_init_help=%d",&arg)==1) {
00683             /* Careful here ... */
00684             no_init_help = !!arg;
00685             continue;
00686         }
00687         if (sscanf(buf,"skip_splash_screen=%d",&arg)==1) {
00688             skip_splash_screen = !!arg;
00689             continue;
00690         }
00691         if (sscanf(buf,"suppress_firsttime_module_help=%d",&arg)==1) {
00692             suppress_firsttime_module_help = !!arg;
00693             continue;
00694         }
00695         if (sscanf(buf,"suppress_popups=%d",&arg)==1) {
00696             suppress_popups = !!arg;
00697             continue;
00698         }
00699         if (sscanf(buf,"time_multiplex_stats=%d",&arg)==1) {
00700             time_multiplex_stats = !!arg;
00701             continue;
00702         }
00703         if (sscanf(buf,"x_confine_pointer=%d",&arg)==1) {
00704             confine_flag = !!arg;
00705             continue;
00706         }
00707     }
00708     fclose (fp);
00709 }

void save_lincityrc void   ) 
 

Definition at line 712 of file fileutil.c.

00713 {
00714     FILE *fp;
00715 
00716     if ((fp = fopen (lincityrc_file, "w")) == 0) {
00717         return;
00718     }
00719 
00720     fprintf (fp, 
00721         "# Set this if you want to be able to overwrite one\n"
00722         "# kind of transport with another.\n"
00723         "overwrite_transport=%d\n\n",
00724         overwrite_transport_flag);
00725     fprintf (fp, 
00726         "# Set this if you don't want the opening help screen.\n"
00727         "no_init_help=%d\n\n",
00728         no_init_help
00729         );
00730     fprintf (fp,
00731         "# Set this if you don't want the opening splash screen.\n"
00732         "skip_splash_screen=%d\n\n",
00733         skip_splash_screen
00734         );
00735     fprintf (fp,
00736         "# Set this if you don't want help the first time you\n"
00737         "# click to place an item.\n"
00738         "suppress_firsttime_module_help=%d\n\n", 
00739         suppress_firsttime_module_help
00740         );
00741     fprintf (fp,
00742         "# Set this if don't want modal dialog boxes which you\n"
00743         "# are required to click OK.  Instead, report the dialog\n"
00744         "# box information to the message area.\n"
00745         "suppress_popups=%d\n\n",
00746         suppress_popups
00747         );
00748     fprintf (fp,
00749         "# Set this if want the different statistic windows to cycle\n"
00750         "# through the right panel.\n"
00751         "time_multiplex_stats=%d\n\n",
00752         time_multiplex_stats
00753         );
00754     fprintf (fp,
00755         "# (X Windows only) Set this if you want to confine the pointer\n"
00756         "# to within the window.\n"
00757         "x_confine_pointer=%d\n\n",
00758         confine_flag
00759         );
00760 
00761     fclose (fp);
00762 }

void undosify_string char *  s  ) 
 

Definition at line 765 of file fileutil.c.

00766 {
00767     /* Convert '\r\n' to '\n' in string */
00768     char prev_char = 0;
00769     char *p = s, *q = s;
00770     while (*p) {
00771         if (*p != '\r') {
00772             if (prev_char == '\r' && *p != '\n') {
00773                 *q++ = '\n';
00774             }
00775             *q++ = *p;
00776         }
00777         prev_char = *p;
00778         p++;
00779     }
00780     if (prev_char == '\r') {
00781         *q++ = '\n';
00782     }
00783     *q = '\0';
00784 }


Variable Documentation

char colour_pal_file[LC_PATH_MAX]
 

Definition at line 109 of file fileutil.c.

char fontfile[LC_PATH_MAX]
 

Definition at line 112 of file fileutil.c.

char given_scene[LC_PATH_MAX]
 

Definition at line 108 of file fileutil.c.

char graphic_path[LC_PATH_MAX]
 

Definition at line 111 of file fileutil.c.

char help_path[LC_PATH_MAX]
 

Definition at line 114 of file fileutil.c.

char* lc_save_dir
 

Definition at line 104 of file fileutil.c.

int lc_save_dir_len
 

Definition at line 105 of file fileutil.c.

char* lc_temp_file
 

Definition at line 98 of file main.c.

char lc_textdomain_directory[LC_PATH_MAX]
 

Definition at line 116 of file fileutil.c.

char lincityrc_file[LC_PATH_MAX]
 

Definition at line 117 of file fileutil.c.

char message_path[LC_PATH_MAX]
 

Definition at line 115 of file fileutil.c.

char opening_path[LC_PATH_MAX]
 

Definition at line 113 of file fileutil.c.

char opening_pic[LC_PATH_MAX]
 

Definition at line 110 of file fileutil.c.


Generated on Sun Dec 26 11:23:28 2004 for lincity by  doxygen 1.3.9.1