revert between 56095 -> 55830 in arch
[AROS.git] / tools / adflib / adf_env.c
blob79a670e6b72aa33323ecae2217bdbe0c76ffdf42
1 /*
2 * ADF Library
4 * adf_env.c
6 */
8 #include<stdio.h>
9 #include<stdlib.h>
11 #include"adf_defs.h"
12 #include"adf_str.h"
13 #include"adf_nativ.h"
14 #include"adf_env.h"
16 #include"defendian.h"
18 union u{
19 long l;
20 char c[4];
23 ENV_DECLARATION;
25 void rwHeadAccess(SECTNUM physical, SECTNUM logical, BOOL write)
27 /* display the physical sector, the logical block, and if the access is read or write */
29 fprintf(stderr, "phy %ld / log %ld : %c\n", (long)physical, (long)logical, write ? 'W' : 'R');
32 void progressBar(int perCentDone)
34 fprintf(stderr,"%d %% done\n",perCentDone);
37 void Warning(char* msg) {
38 fprintf(stderr,"Warning <%s>\n",msg);
41 void Error(char* msg) {
42 fprintf(stderr,"Error <%s>\n",msg);
43 // exit(1);
46 void Verbose(char* msg) {
47 fprintf(stderr,"Verbose <%s>\n",msg);
50 void Changed(SECTNUM nSect, int changedType)
52 /* switch(changedType) {
53 case ST_FILE:
54 fprintf(stderr,"Notification : sector %ld (FILE)\n",nSect);
55 break;
56 case ST_DIR:
57 fprintf(stderr,"Notification : sector %ld (DIR)\n",nSect);
58 break;
59 case ST_ROOT:
60 fprintf(stderr,"Notification : sector %ld (ROOT)\n",nSect);
61 break;
62 default:
63 fprintf(stderr,"Notification : sector %ld (???)\n",nSect);
65 */}
68 * adfInitEnv
71 void adfEnvInitDefault()
73 // char str[80];
74 union u val;
76 /* internal checking */
78 if (sizeof(UBYTE)!=1)
79 { fprintf(stderr,"Compilation error : sizeof(UBYTE)!=1\n"); exit(1); }
80 if (sizeof(USHORT)!=2)
81 { fprintf(stderr,"Compilation error : sizeof(USHORT)!=2\n"); exit(1); }
82 if (sizeof(ULONG)!=4)
83 { fprintf(stderr,"Compilation error : sizeof(ULONG)!=4\n"); exit(1); }
84 if (sizeof(struct bEntryBlock)!=512)
85 { fprintf(stderr,"Internal error : sizeof(struct bEntryBlock)!=512\n"); exit(1); }
86 if (sizeof(struct bRootBlock)!=512)
87 { fprintf(stderr,"Internal error : sizeof(struct bRootBlock)!=512\n"); exit(1); }
88 if (sizeof(struct bDirBlock)!=512)
89 { fprintf(stderr,"Internal error : sizeof(struct bDirBlock)!=512\n"); exit(1); }
90 if (sizeof(struct bBootBlock)!=1024)
91 { fprintf(stderr,"Internal error : sizeof(struct bBootBlock)!=1024\n"); exit(1); }
92 if (sizeof(struct bFileHeaderBlock)!=512)
93 { fprintf(stderr,"Internal error : sizeof(struct bFileHeaderBlock)!=512\n"); exit(1); }
94 if (sizeof(struct bFileExtBlock)!=512)
95 { fprintf(stderr,"Internal error : sizeof(struct bFileExtBlock)!=512\n"); exit(1); }
96 if (sizeof(struct bOFSDataBlock)!=512)
97 { fprintf(stderr,"Internal error : sizeof(struct bOFSDataBlock)!=512\n"); exit(1); }
98 if (sizeof(struct bBitmapBlock)!=512)
99 { fprintf(stderr,"Internal error : sizeof(struct bBitmapBlock)!=512\n"); exit(1); }
100 if (sizeof(struct bBitmapExtBlock)!=512)
101 { fprintf(stderr,"Internal error : sizeof(struct bBitmapExtBlock)!=512\n"); exit(1); }
102 if (sizeof(struct bLinkBlock)!=512)
103 { fprintf(stderr,"Internal error : sizeof(struct bLinkBlock)!=512\n"); exit(1); }
105 val.l=1L;
106 /* if LITT_ENDIAN not defined : must be BIG endian */
107 #ifndef LITT_ENDIAN
108 if (val.c[3]!=1) /* little endian : LITT_ENDIAN must be defined ! */
109 { fprintf(stderr,"Compilation error : #define LITT_ENDIAN must exist\n"); exit(1); }
110 #else
111 if (val.c[3]==1) /* big endian : LITT_ENDIAN must not be defined ! */
112 { fprintf(stderr,"Compilation error : #define LITT_ENDIAN must not exist\n"); exit(1); }
113 #endif
115 adfEnv.wFct = Warning;
116 adfEnv.eFct = Error;
117 adfEnv.vFct = Verbose;
118 adfEnv.notifyFct = Changed;
119 adfEnv.rwhAccess = rwHeadAccess;
120 adfEnv.progressBar = progressBar;
122 adfEnv.useDirCache = FALSE;
123 adfEnv.useRWAccess = FALSE;
124 adfEnv.useNotify = FALSE;
125 adfEnv.useProgressBar = FALSE;
127 /* sprintf(str,"ADFlib %s (%s)",adfGetVersionNumber(),adfGetVersionDate());
128 (*adfEnv.vFct)(str);
130 adfEnv.nativeFct=(struct nativeFunctions*)malloc(sizeof(struct nativeFunctions));
131 if (!adfEnv.nativeFct) (*adfEnv.wFct)("adfInitDefaultEnv : malloc");
133 adfInitNativeFct();
138 * adfEnvCleanUp
141 void adfEnvCleanUp()
143 free(adfEnv.nativeFct);
148 * adfChgEnvProp
151 void adfChgEnvProp(int prop, void *new)
153 BOOL *newBool;
154 // int *newInt;
156 switch(prop) {
157 case PR_VFCT:
158 adfEnv.vFct = (void(*)(char*))new;
159 break;
160 case PR_WFCT:
161 adfEnv.wFct = (void(*)(char*))new;
162 break;
163 case PR_EFCT:
164 adfEnv.eFct = (void(*)(char*))new;
165 break;
166 case PR_NOTFCT:
167 adfEnv.notifyFct = (void(*)(SECTNUM,int))new;
168 break;
169 case PR_USE_NOTFCT:
170 newBool = (BOOL*)new;
171 adfEnv.useNotify = *newBool;
172 break;
173 case PR_PROGBAR:
174 adfEnv.progressBar = (void(*)(int))new;
175 break;
176 case PR_USE_PROGBAR:
177 newBool = (BOOL*)new;
178 adfEnv.useProgressBar = *newBool;
179 break;
180 case PR_USE_RWACCESS:
181 newBool = (BOOL*)new;
182 adfEnv.useRWAccess = *newBool;
183 break;
184 case PR_RWACCESS:
185 adfEnv.rwhAccess = (void(*)(SECTNUM,SECTNUM,BOOL))new;
186 break;
187 case PR_USEDIRC:
188 newBool = (BOOL*)new;
189 adfEnv.useDirCache = *newBool;
190 break;
195 * adfSetEnv
198 void adfSetEnvFct( void(*eFct)(char*), void(*wFct)(char*), void(*vFct)(char*),
199 void(*notFct)(SECTNUM,int) )
201 if (*eFct!=0)
202 adfEnv.eFct = *eFct;
203 if (*wFct!=0)
204 adfEnv.wFct = *wFct;
205 if (*vFct!=0)
206 adfEnv.vFct = *vFct;
207 if (*notFct!=0)
208 adfEnv.notifyFct = *notFct;
213 * adfGetVersionNumber
216 char* adfGetVersionNumber()
218 return(ADFLIB_VERSION);
223 * adfGetVersionDate
226 char* adfGetVersionDate()
228 return(ADFLIB_DATE);
234 /*##################################################################################*/