1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
/*
* ADF Library
*
* adf_env.c
*
* $Id$
*
* library context and customization code
*
* This file is part of ADFLib.
*
* ADFLib is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ADFLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include<stdio.h>
#include<stdlib.h>
#include"adf_defs.h"
#include"adf_str.h"
#include"adf_nativ.h"
#include"adf_env.h"
#include"Win32/defendian.h"
union u{
int32_t l;
char c[4];
};
ENV_DECLARATION;
void rwHeadAccess(SECTNUM physical, SECTNUM logical, BOOL write)
{
/* display the physical sector, the logical block, and if the access is read or write */
fprintf(stderr, "phy %d / log %d : %c\n", physical, logical, write ? 'W' : 'R');
}
void progressBar(int perCentDone)
{
fprintf(stderr,"%d %% done\n",perCentDone);
}
void Warning(char* msg) {
fprintf(stderr,"Warning <%s>\n",msg);
}
void Error(char* msg) {
fprintf(stderr,"Error <%s>\n",msg);
/* exit(1);*/
}
void Verbose(char* msg) {
fprintf(stderr,"Verbose <%s>\n",msg);
}
void Changed(SECTNUM nSect, int changedType)
{
/* switch(changedType) {
case ST_FILE:
fprintf(stderr,"Notification : sector %d (FILE)\n",nSect);
break;
case ST_DIR:
fprintf(stderr,"Notification : sector %d (DIR)\n",nSect);
break;
case ST_ROOT:
fprintf(stderr,"Notification : sector %d (ROOT)\n",nSect);
break;
default:
fprintf(stderr,"Notification : sector %d (???)\n",nSect);
}
*/}
/*
* adfInitEnv
*
*/
void adfEnvInitDefault()
{
/* char str[80];*/
union u val;
/* internal checking */
if (sizeof(int16_t)!=2)
{ fprintf(stderr,"Compilation error : sizeof(int16_t)!=2\n"); exit(1); }
if (sizeof(int32_t)!=4)
{ fprintf(stderr,"Compilation error : sizeof(int16_t)!=2\n"); exit(1); }
if (sizeof(struct bEntryBlock)!=512)
{ fprintf(stderr,"Internal error : sizeof(struct bEntryBlock)!=512\n"); exit(1); }
if (sizeof(struct bRootBlock)!=512)
{ fprintf(stderr,"Internal error : sizeof(struct bRootBlock)!=512\n"); exit(1); }
if (sizeof(struct bDirBlock)!=512)
{ fprintf(stderr,"Internal error : sizeof(struct bDirBlock)!=512\n"); exit(1); }
if (sizeof(struct bBootBlock)!=1024)
{ fprintf(stderr,"Internal error : sizeof(struct bBootBlock)!=1024\n"); exit(1); }
if (sizeof(struct bFileHeaderBlock)!=512)
{ fprintf(stderr,"Internal error : sizeof(struct bFileHeaderBlock)!=512\n"); exit(1); }
if (sizeof(struct bFileExtBlock)!=512)
{ fprintf(stderr,"Internal error : sizeof(struct bFileExtBlock)!=512\n"); exit(1); }
if (sizeof(struct bOFSDataBlock)!=512)
{ fprintf(stderr,"Internal error : sizeof(struct bOFSDataBlock)!=512\n"); exit(1); }
if (sizeof(struct bBitmapBlock)!=512)
{ fprintf(stderr,"Internal error : sizeof(struct bBitmapBlock)!=512\n"); exit(1); }
if (sizeof(struct bBitmapExtBlock)!=512)
{ fprintf(stderr,"Internal error : sizeof(struct bBitmapExtBlock)!=512\n"); exit(1); }
if (sizeof(struct bLinkBlock)!=512)
{ fprintf(stderr,"Internal error : sizeof(struct bLinkBlock)!=512\n"); exit(1); }
val.l=1L;
/* if LITT_ENDIAN not defined : must be BIG endian */
#ifndef LITT_ENDIAN
if (val.c[3]!=1) /* little endian : LITT_ENDIAN must be defined ! */
{ fprintf(stderr,"Compilation error : #define LITT_ENDIAN must exist\n"); exit(1); }
#else
if (val.c[3]==1) /* big endian : LITT_ENDIAN must not be defined ! */
{ fprintf(stderr,"Compilation error : #define LITT_ENDIAN must not exist\n"); exit(1); }
#endif
adfEnv.wFct = Warning;
adfEnv.eFct = Error;
adfEnv.vFct = Verbose;
adfEnv.notifyFct = Changed;
adfEnv.rwhAccess = rwHeadAccess;
adfEnv.progressBar = progressBar;
adfEnv.useDirCache = FALSE;
adfEnv.useRWAccess = FALSE;
adfEnv.useNotify = FALSE;
adfEnv.useProgressBar = FALSE;
/* sprintf(str,"ADFlib %s (%s)",adfGetVersionNumber(),adfGetVersionDate());
(*adfEnv.vFct)(str);
*/
adfEnv.nativeFct=(struct nativeFunctions*)malloc(sizeof(struct nativeFunctions));
if (!adfEnv.nativeFct) (*adfEnv.wFct)("adfInitDefaultEnv : malloc");
adfInitNativeFct();
}
/*
* adfEnvCleanUp
*
*/
void adfEnvCleanUp()
{
free(adfEnv.nativeFct);
}
/*
* adfChgEnvProp
*
* compilation warnings
* adf_env.c: In function adfChgEnvProp:
* adf_env.c:176: warning: ISO C forbids conversion of object pointer to function pointer type
* adf_env.c:179: warning: ISO C forbids conversion of object pointer to function pointer type
* adf_env.c:182: warning: ISO C forbids conversion of object pointer to function pointer type
* adf_env.c:185: warning: ISO C forbids conversion of object pointer to function pointer type
* adf_env.c:192: warning: ISO C forbids conversion of object pointer to function pointer type
* adf_env.c:203: warning: ISO C forbids conversion of object pointer to function pointer type
*
*/
void adfChgEnvProp(int prop, void *new)
{
BOOL *newBool;
/* int *newInt;*/
switch(prop) {
case PR_VFCT:
adfEnv.vFct = (void(*)(char*))new;
break;
case PR_WFCT:
adfEnv.wFct = (void(*)(char*))new;
break;
case PR_EFCT:
adfEnv.eFct = (void(*)(char*))new;
break;
case PR_NOTFCT:
adfEnv.notifyFct = (void(*)(SECTNUM,int))new;
break;
case PR_USE_NOTFCT:
newBool = (BOOL*)new;
adfEnv.useNotify = *newBool;
break;
case PR_PROGBAR:
adfEnv.progressBar = (void(*)(int))new;
break;
case PR_USE_PROGBAR:
newBool = (BOOL*)new;
adfEnv.useProgressBar = *newBool;
break;
case PR_USE_RWACCESS:
newBool = (BOOL*)new;
adfEnv.useRWAccess = *newBool;
break;
case PR_RWACCESS:
adfEnv.rwhAccess = (void(*)(SECTNUM,SECTNUM,BOOL))new;
break;
case PR_USEDIRC:
newBool = (BOOL*)new;
adfEnv.useDirCache = *newBool;
break;
}
}
/*
* adfSetEnv
*
*/
void adfSetEnvFct( void(*eFct)(char*), void(*wFct)(char*), void(*vFct)(char*),
void(*notFct)(SECTNUM,int) )
{
if (*eFct!=0)
adfEnv.eFct = *eFct;
if (*wFct!=0)
adfEnv.wFct = *wFct;
if (*vFct!=0)
adfEnv.vFct = *vFct;
if (*notFct!=0)
adfEnv.notifyFct = *notFct;
}
/*
* adfGetVersionNumber
*
*/
char* adfGetVersionNumber()
{
return(ADFLIB_VERSION);
}
/*
* adfGetVersionDate
*
*/
char* adfGetVersionDate()
{
return(ADFLIB_DATE);
}
/*##################################################################################*/
|