a99  V32.6
allegro Windows Hauptprogramm
 Alle Klassen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
aiefunc2.cpp
gehe zur Dokumentation dieser Datei
1 // aiefunc2.cpp : Elementarfunktionen Teil 2
2 // 1991 / 1995-05-23 /2011 Alles interne Routinen
3 // Copyright 2011 Universitätsbibliothek Braunschweig, more see bottom
4 
5 
6 #include "includes.h" // einige Konventionen
7 #include "ai-const.h" // allg. Konstanten
8 #include "aisetup.h" // allg. Einstellungen
9 #include "aistruc.h" // Strukturen
10 #include "aiglobal.h" // glob. Variablen
11 #include "aierrors.h" // Fehlernummern
12 #include "aideclar.h" // Funktionsdeklarationen
13 
14 
15 #ifdef WIN32 // ve:$$970120
16 #include "process.h"
17 #include <sys\locking.h> // ---- MICROSOFT ----
18 #include <share.h>
19 #include <sys\stat.h> // From Borland
20 #endif
21 
22 
23 #ifdef WIN32
24 #include <io.h>
25 #endif
26 
27 
28 // Fehlermeldung setzen
30 {
31  return(aiG_fhln = err_no);
32 }
33 
34 // Positioniere innerhalb der Datei (Hilfsfunk. f. read/write)
35 
36 SHORT aifpos(aiDATEI *ainmb, PTRL airecnum)
37 {
38  if (lseek(ainmb->fdsc,ainmb->cafp = airecnum,0) < 0L)
39  return(FHLSEEK);
40  else
41  return(FHLNUL);
42 }
43 
44 
45 // read-write a block of data from/to a file
46 // Anzahl bloclen Bytes aus Datei lesen oder in Datei schreiben
47 
48 SHORT airw(SHORT opcod, aiDATEI *ainmb, RECNR airecnum,CHAR *blocadr, unsigned int bloclen)
49 {
50  if (aifpos(ainmb,airecnum))
51  return(aierro(FHLSEEK));
52  if (!bloclen)
53  bloclen = ainmb->kresrv;
54  if (opcod == aiREAD)
55  {
56  if ((unsigned int)read(ainmb->fdsc,blocadr,bloclen) != bloclen)
57  {
58  ainmb->cafp = -1L;
59  return(aierro(FHLREAD));
60  }
61  }
62  else
63  {
64  if ((unsigned int)write(ainmb->fdsc,blocadr,bloclen) != bloclen)
65  {
66  ainmb->cafp = -1L;
67  return(aierro(FHLWRITE));
68  }
69  }
70  ainmb->cafp += bloclen;
71  return(FHLNUL);
72 }
73 
74 
75 // Datei schliessen
76 
77 SHORT ai_fclose(aiDATEI *ainmb, SHORT clmode)
78 {
79  if (!(ainmb->fmod & aiPERM))
80  aiG_virtf--;
81 
82  return((SHORT) close(ainmb->fdsc));
83 }
84 
85 // Datei loeschen
86 
87 SHORT ai_delt(CHAR *filnam)
88 {
89  if (remove((char*)filnam))
90  return(aiG_fhln = FHLFDLT);
91  else
92  return(FHLNUL);
93 }
94 
95 
96 CHAR *aispace(unsigned int numobj, unsigned int sizobj)
97 {
98 
99  if (sizobj == 0 || numobj == 0)
100  {
101  numobj = 1;
102  sizobj = 1; // to avoid false NULL return
103  }
104 
105  return((CHAR *)calloc(numobj,sizobj));
106 }
107 
108 // ------------------------------------------------------------
109 
110 void airels(CHAR *objptr)
111 {
112  if (objptr != (CHAR*)NULL)
113  free(objptr);
114 }
115 
116 
117 // ------------------------------------------
118 // Einen Block kopieren. Kein Stop bei Byte 0
119 
120 
121 #ifndef aicopy
122 void aicopy(CHAR *dp, CHAR *sp, uSHORT n)
123 {
124  while (n-- != 0)
125  *dp++ = *sp++;
126 }
127 #endif
128 
129 
130 extern SHORT aiG_fhln;
131 
132 
133 
134 // --------------
135 // Harter Abbruch
136 
137 void aiAbort(SHORT err_no)
138 
139 {
140  printf("\nInterner Indexfehler Nr %d.",err_no);
141  exit(0);
142 }
143 
144 
145 #ifdef HITOLO
146 
147 void ai_flip(CHAR *tp, SHORT wrdcnt)
148 {
149  CHAR ch;
150 
151  while (wrdcnt-- > 0)
152  {
153  ch = *tp++;
154  *(tp - 1) = *tp;
155  *tp++ = ch;
156  }
157 }
158 
159 #endif
160 
161 void ai_exchg(CHAR *tp,SHORT len)
162 {
163  CHAR *hp;
164  CHAR ch;
165 
166  hp = tp + len - 1;
167  while (tp < hp)
168  {
169  ch = *tp;
170  *tp++ = *hp;
171  *hp-- = ch;
172  }
173 }
174 
175 /*
176  Copyright 2011 Universitätsbibliothek Braunschweig
177 
178  Licensed under the Apache License, Version 2.0 (the "License");
179  you may not use this file except in compliance with the License.
180  You may obtain a copy of the License at
181 
182  http://www.apache.org/licenses/LICENSE-2.0
183 
184  Unless required by applicable law or agreed to in writing, software
185  distributed under the License is distributed on an "AS IS" BASIS,
186  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
187  See the License for the specific language governing permissions and
188  limitations under the License.
189 */
190