ARPDAS_QNX6 1.0
|
00001 #include <limits.h> 00002 #include <stdio.h> 00003 #include <string.h> 00004 #include <errno.h> 00005 #include "tm.h" 00006 00007 static FILE *open_path( const char *path, const char *fname ) { 00008 char filename[PATH_MAX]; 00009 FILE *tmd; 00010 if ( snprintf( filename, PATH_MAX, "%s/%s", path, fname ) 00011 >= PATH_MAX ) 00012 nl_error( 3, "Pathname overflow for file '%s'", fname ); 00013 tmd = fopen( filename, "r" ); 00014 return tmd; 00015 } 00016 00017 void load_tmdac( const char *path ) { 00018 FILE *dacfile; 00019 if ( path == NULL || path[0] == '\0' ) path = "."; 00020 dacfile = open_path( path, "tm.dac" ); 00021 if ( dacfile == NULL ) { 00022 char version[40]; 00023 char dacpath[80]; 00024 FILE *ver; 00025 00026 version[0] = '\0'; 00027 ver = open_path( path, "VERSION" ); 00028 if ( ver != NULL ) { 00029 int len; 00030 if ( fgets( version, 40, ver ) == NULL ) 00031 nl_error(3,"Error reading VERSION: %s", 00032 strerror(errno)); 00033 len = strlen(version); 00034 while ( len > 0 && isspace(version[len-1]) ) 00035 version[--len] = '\0'; 00036 if ( len == 0 ) 00037 nl_error( 1, "VERSION was empty: assuming 1.0" ); 00038 } else { 00039 nl_error( 1, "VERSION not found: assuming 1.0" ); 00040 } 00041 if ( version[0] == '\0' ) strcpy( version, "1.0" ); 00042 snprintf( dacpath, 80, "bin/%s/tm.dac" ); 00043 dacfile = open_path( path, dacpath ); 00044 } 00045 if ( dacfile == NULL ) nl_error( 3, "Unable to locate tm.dac" ); 00046 if ( fread(&tm_info.tm, sizeof(tm_dac_t), 1, dacfile) != 1 ) 00047 nl_error( 3, "Error reading tm.dac" ); 00048 fclose(dacfile); 00049 tm_info.nrowminf = tmi(nbminf)/tmi(nbrow); 00050 }