1 /* @source ajfileio ***********************************************************
2 **
3 ** AJAX file routines
4 **
5 ** @author Copyright (C) 1999 Peter Rice
6 ** @version $Revision: 1.29 $
7 ** @modified Peter Rice pmr@ebi.ac.uk I/O file functions from ajfile.c
8 ** @modified $Date: 2012/12/07 10:05:36 $ by $Author: rice $
9 ** @@
10 **
11 ** This library is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU Lesser General Public
13 ** License as published by the Free Software Foundation; either
14 ** version 2.1 of the License, or (at your option) any later version.
15 **
16 ** This library is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ** Lesser General Public License for more details.
20 **
21 ** You should have received a copy of the GNU Lesser General Public
22 ** License along with this library; if not, write to the Free Software
23 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 ** MA  02110-1301,  USA.
25 **
26 ******************************************************************************/
27 
28 
29 #include "ajlib.h"
30 
31 #include "ajfileio.h"
32 #include "ajutil.h"
33 #include "ajfile.h"
34 
35 #include <string.h>
36 #include <errno.h>
37 
38 
39 static void   filebuffLineAdd(AjPFilebuff thys, const AjPStr line);
40 
41 
42 
43 
44 /* @filesection ajfile ********************************************************
45 **
46 ** @nam1rule aj Function belongs to the AJAX library.
47 **
48 */
49 
50 
51 
52 
53 /* @datasection [AjPFile] File object *****************************************
54 **
55 ** Function is for manipulating input files and returns or takes at least
56 ** one AjPFile argument.
57 **
58 */
59 
60 
61 
62 
63 /* @section file line read operations
64 **
65 ** @fdata [AjPFile]
66 **
67 ** These functions read data directly from a file using system functions.
68 ** Integer data is by default assumed to be stored as little-endian
69 ** so that binary files with integers are portable across systems
70 **
71 ** @nam2rule Readline
72 ** @nam3rule Trim     Remove trailing newline and linefeed characters
73 ** @nam3rule Append   Append to existing buffer
74 ** @suffix   Pos      Return file position after read
75 **
76 ** @argrule * file [AjPFile] Input file object
77 ** @argrule * Pdest [AjPStr*] Buffer (expanded automatically) for results
78 ** @argrule Pos Ppos [ajlong*] File position after read
79 **
80 ** @valrule * [AjBool] True on success
81 **
82 ** @fcategory input
83 */
84 
85 
86 
87 
88 /* @func ajReadline ***********************************************************
89 **
90 ** Read a line from a file.
91 **
92 ** @param [u] file [AjPFile] Input file.
93 ** @param [w] Pdest [AjPStr*] Buffer to hold the current line.
94 ** @return [AjBool] ajTrue on success.
95 ** @category modify [AjPFile] Reads a record from a file
96 **
97 ** @release 6.0.0
98 ** @@
99 ******************************************************************************/
100 
ajReadline(AjPFile file,AjPStr * Pdest)101 AjBool ajReadline(AjPFile file, AjPStr* Pdest)
102 {
103     ajlong fpos = 0;
104 
105     return ajReadlinePos(file, Pdest, &fpos);
106 }
107 
108 
109 
110 
111 /* @func ajReadlineAppend *****************************************************
112 **
113 ** Reads a record from a file and appends it to the user supplied buffer.
114 **
115 ** @param [u] file [AjPFile] Input file.
116 ** @param [u] Pdest [AjPStr*] Buffer to hold results.
117 ** @return [AjBool] ajTrue on success.
118 **
119 ** @release 6.0.0
120 ** @@
121 ******************************************************************************/
122 
ajReadlineAppend(AjPFile file,AjPStr * Pdest)123 AjBool ajReadlineAppend(AjPFile file, AjPStr* Pdest)
124 {
125     static AjPStr locbuff = 0;
126     AjBool ok;
127 
128     if(!locbuff)
129 	locbuff = ajStrNewRes(512);
130 
131     ok = ajReadline(file, &locbuff);
132 
133     if(ok)
134 	ajStrAppendS(Pdest, locbuff);
135 
136     ajStrDel(&locbuff);
137 
138     return ok;
139 }
140 
141 
142 
143 
144 /* @func ajReadlinePos ********************************************************
145 **
146 ** Reads a line from a file.
147 **
148 ** @param [u] file [AjPFile] Input file.
149 ** @param [w] Pdest [AjPStr*] Buffer to hold the current line.
150 ** @param [w] Ppos [ajlong*] File position before the read.
151 ** @return [AjBool] ajTrue on success.
152 ** @category modify [AjPFile] Reads a record from a file
153 **
154 ** @release 6.0.0
155 ** @@
156 ******************************************************************************/
157 
ajReadlinePos(AjPFile file,AjPStr * Pdest,ajlong * Ppos)158 AjBool ajReadlinePos(AjPFile file, AjPStr* Pdest, ajlong* Ppos)
159 {
160     const char *cp;
161     char *buff;
162     ajint isize;
163     ajint ilen;
164     ajint jlen;
165     ajint ipos;
166 
167     const char* pnewline = NULL;
168 #ifndef __ppc__
169     size_t iread;
170 #endif
171 
172     /*
173     ** delete the output record here
174     ** if simply read, it is a reference counted copy of file->Buff
175     ** so we decrement the reference count, reuse file->Buff (now single use)
176     ** and make a new reference copy at the end
177     ** saving the need for any string free and allocate
178     */
179 
180     MAJSTRDEL(Pdest);
181 
182     if(file->Buffsize)
183     {
184         buff  = MAJSTRGETUNIQUEPTR(&file->Buff);
185     }
186     else
187     {
188         file->Buffsize = ajFileValueBuffsize();
189 
190         if(!file->Buff)
191             ajStrAssignResC(&file->Buff, file->Buffsize, "");
192         else if(file->Buffsize > MAJSTRGETRES(file->Buff))
193             ajStrSetRes(&file->Buff, file->Buffsize);
194 
195         buff = MAJSTRGETPTR(file->Buff);
196     }
197 
198     isize = MAJSTRGETRES(file->Buff);
199     ilen  = 0;
200     ipos  = 0;
201 
202     if(!file->fp)
203 	ajWarn("ajReadlinePos file not found");
204 
205     *Ppos = file->Filepos;
206 
207     while(buff)
208     {
209 	if(file->End)
210 	{
211 	    ajStrAssignClear(Pdest);
212 	    ajDebug("at EOF: File already read to end %F\n", file);
213 
214 	    return ajFalse;
215 	}
216 
217 
218 #ifndef __ppc__
219         if(file->Readblock)
220         {
221             if(file->Blockpos >= file->Blocklen)
222             {
223                 iread = fread(file->Readblock,
224                               1, file->Blocksize,
225                               file->fp);
226 
227                 if(!iread && ferror(file->fp))
228                     ajFatal("fread failed with error:%d '%s'",
229                             ferror(file->fp), strerror(ferror(file->fp)));
230 
231                 file->Blockpos = 0;
232                 file->Blocklen = iread;
233                 file->Readblock[iread] = '\0';
234                 /*ajDebug("++ fread %u Ppos:%Ld\n", iread, *Ppos);*/
235              }
236 
237             if(file->Blockpos < file->Blocklen)
238             {
239 
240                 /* we know we have something in Readblock to process */
241 
242                 pnewline = strchr(&file->Readblock[file->Blockpos], '\n');
243 
244                 if(pnewline)
245                     jlen = pnewline - &file->Readblock[file->Blockpos] + 1;
246                 else
247                     jlen = file->Blocklen - file->Blockpos;
248 
249                 /*ajDebug("ipos:%d jlen:%d pnewline:%p "
250                           "Readblock:%p blockpos:%d blocklen:%d\n",
251                           ipos, jlen, pnewline, file->Readblock,
252                           file->Blockpos, file->Blocklen);*/
253                 memmove(&buff[ipos], &file->Readblock[file->Blockpos], jlen);
254                 buff[ipos+jlen]='\0';
255                 cp = &buff[ipos];
256                 file->Blockpos += jlen;
257             }
258             else
259             {
260                 jlen = 0;
261                 cp = NULL;
262             }
263         }
264         else
265         {
266             cp = fgets(&buff[ipos], isize, file->fp);
267             jlen = strlen(&buff[ipos]);
268         }
269 
270 #else
271 	cp = ajSysFuncFgets(&buff[ipos], isize, file->fp);
272 	jlen = strlen(&buff[ipos]);
273 #endif
274 
275         if(!cp && !ipos)
276 	{
277             file->Filepos += ilen;
278 
279 	    if(feof(file->fp))
280 	    {
281 		file->End = ajTrue;
282 		ajStrAssignClear(Pdest);
283 		ajDebug("EOF ajFileGetsL file %F\n", file);
284 
285 		return ajFalse;
286 	    }
287 	    else
288             {
289 		ajFatal("Error reading from file '%S' ferror:%d %d: %s\n",
290                         ajFileGetNameS(file),
291                         ferror(file->fp),
292                         errno, strerror(errno));
293             }
294 	}
295 
296 	ilen += jlen;
297 
298 	/*
299 	 ** We need to read again if:
300 	 ** We have read the entire buffer
301 	 ** and we don't have a newline at the end
302 	 ** (must be careful about that - we may just have read enough)
303 	 */
304 
305 	if(((file->Readblock && !pnewline) || (jlen == (isize-1))) &&
306 	   (buff[ilen-1] != '\n'))
307 	{
308             MAJSTRSETVALIDLEN(&file->Buff, ilen); /* fix before resizing! */
309 	    ajStrSetResRound(&file->Buff, ilen+file->Buffsize+1);
310 	    /*ajDebug("more to do: jlen: %d ipos: %d isize: %d ilen: %d "
311 		    "Size: %d\n",
312 		    jlen, ipos, isize, ilen, ajStrGetRes(file->Buff));*/
313 	    ipos += jlen;
314 	    buff = MAJSTRGETUNIQUEPTR(&file->Buff);
315 	    isize = MAJSTRGETRES(file->Buff) - ipos;
316 	    /*ajDebug("expand to: ipos: %d isize: %d Size: %d\n",
317               ipos, isize, ajStrGetRes(file>Buff));*/
318 	}
319 	else
320 	{
321             buff = NULL;
322         }
323     }
324 
325     file->Filepos += ilen;
326 
327     MAJSTRSETVALIDLEN(&file->Buff, ilen);
328     if (MAJSTRGETCHARLAST(file->Buff) != '\n')
329     {
330 	/*ajDebug("Appending missing newline to '%S'\n", file->Buff);*/
331 	ajStrAppendK(&file->Buff, '\n');
332     }
333 
334     MAJSTRASSIGNREF(Pdest, file->Buff);
335 
336 /*
337   if(file->Readblock)
338         ajDebug("ajFileGetsL done blocklen:%d blockpos:%d readlen:%u\n",
339                 file->Blocklen, file->Blockpos, ajStrGetLen(file->Buff));
340 */
341     return ajTrue;
342 }
343 
344 
345 
346 
347 /* @func ajReadlineTrim *******************************************************
348 **
349 ** Reads a line from a file and removes any trailing newline.
350 **
351 ** @param [u] file [AjPFile] Input file.
352 ** @param [w] Pdest [AjPStr*] Buffer to hold the current line.
353 ** @return [AjBool] ajTrue on success.
354 ** @category modify [AjPFile] Reads a record from a file and removes
355 **                            newline characters
356 **
357 ** @release 6.0.0
358 ** @@
359 ******************************************************************************/
360 
ajReadlineTrim(AjPFile file,AjPStr * Pdest)361 AjBool ajReadlineTrim(AjPFile file, AjPStr* Pdest)
362 {
363     ajlong fpos=0;
364 
365     return ajReadlineTrimPos(file, Pdest, &fpos);
366 }
367 
368 
369 
370 
371 /* @func ajReadlineTrimPos ****************************************************
372 **
373 ** Reads a line from a file and removes any trailing newline.
374 **
375 ** @param [u] file [AjPFile] Input file.
376 ** @param [w] Pdest [AjPStr*] Buffer to hold the current line.
377 ** @param [w] Ppos [ajlong*] File position before the read.
378 ** @return [AjBool] ajTrue on success.
379 ** @category modify [AjPFile] Reads a record from a file and removes
380 **                            newline characters
381 **
382 ** @release 6.0.0
383 ** @@
384 ******************************************************************************/
385 
ajReadlineTrimPos(AjPFile file,AjPStr * Pdest,ajlong * Ppos)386 AjBool ajReadlineTrimPos(AjPFile file, AjPStr* Pdest, ajlong* Ppos)
387 {
388     AjBool ok;
389 
390     ok = ajReadlinePos(file, Pdest, Ppos);
391 
392     if(!ok)
393 	return ajFalse;
394 
395     MAJSTRDEL(Pdest);
396 
397     /* trim any trailing newline */
398 
399 
400     /*ajDebug("Remove carriage-return characters from PC-style files\n");*/
401     if(MAJSTRGETCHARLAST(file->Buff) == '\n')
402 	ajStrCutEnd(&file->Buff, 1);
403 
404     /* PC files have \r\n Macintosh files have just \r : this fixes both */
405     if(MAJSTRGETCHARLAST(file->Buff) == '\r')
406 	ajStrCutEnd(&file->Buff, 1);
407 
408     MAJSTRASSIGNREF(Pdest, file->Buff);
409 
410     return ajTrue;
411 }
412 
413 
414 
415 
416 /* @section file binary read operations
417 **
418 ** @fdata [AjPFile]
419 **
420 ** These functions read data directly from a file using system functions.
421 ** Integer data is by default assumed to be stored as little-endian
422 ** so that binary files with integers are portable across systems
423 **
424 ** @nam2rule Readbin
425 ** @nam3rule Binary Binary read into a buffer
426 ** @nam3rule Char Binary read of a character string
427 ** @nam4rule CharTrim Trim trailing space from a character string
428 ** @nam3rule Int Binary read of an integer
429 ** @nam3rule Int2 Binary read of a 2 byte integer
430 ** @nam3rule Int4 Binary read of a 4 byte integer
431 ** @nam3rule Int8 Binary read of an 8 byte integer
432 ** @nam3rule Uint Binary read of an unsigned integer
433 ** @nam3rule Uint2 Binary read of a 2 byte unsigned integer
434 ** @nam3rule Uint4 Binary read of a 4 byte unsigned integer
435 ** @nam3rule Uint8 Binary read of an 8 byte unsigned integer
436 ** @nam3rule Str Binary read of a string
437 ** @nam4rule StrTrim Trim trailing space from a string
438 ** @suffix Endian Data in file is big-endian
439 ** @suffix Local Data in file  is in local endian-ness
440 **
441 ** @argrule Readbin file [AjPFile] File object
442 ** @argrule Binary count [size_t] Number of elements to read
443 ** @argrule Binary size [size_t] Size of each element
444 ** @argrule Binary buffer [void*] Buffer for binary read
445 ** @argrule Char size [size_t] Size of each element
446 ** @argrule Char buffer [char*] Buffer for binary read
447 ** @argrule Str size [size_t] Size of each element
448 ** @argrule Str Pstr [AjPStr*] Buffer for binary read
449 **
450 ** @argrule Int Pi [ajint*] Integer value
451 ** @argrule Int2 Pi2 [ajshort*] Integer 2 byte value
452 ** @argrule Int4 Pi4 [ajint*] Integer 4 byte value
453 ** @argrule Int8 Pi8 [ajlong*] Integer 8 byte value
454 ** @argrule Uint Pu [ajuint*] Unsigned integer value
455 ** @argrule Uint2 Pu2 [ajushort*] Unsigned integer 2 byte value
456 ** @argrule Uint4 Pu4 [ajuint*] Unsigned integer 4 byte value
457 ** @argrule Uint8 Pu8 [ajulong*] Unsigned integer 8 byte value
458 **
459 ** @valrule * [size_t] Number of elements read. Zero for failure.
460 **
461 ** @fcategory input
462 **
463 ******************************************************************************/
464 
465 
466 
467 
468 /* @func ajReadbinBinary ******************************************************
469 **
470 ** Binary read from an input file object using the C 'fread' function.
471 **
472 ** @param [u] file [AjPFile] Input file.
473 ** @param [r] count [size_t] Number of elements to read.
474 ** @param [r] size [size_t] Number of bytes per element.
475 ** @param [w] buffer [void*] Buffer for output.
476 ** @return [size_t] Return value from 'fread'
477 **
478 ** @release 6.0.0
479 ** @@
480 ******************************************************************************/
481 
ajReadbinBinary(AjPFile file,size_t count,size_t size,void * buffer)482 size_t ajReadbinBinary(AjPFile file, size_t count,size_t size,
483 		   void* buffer)
484 {
485     return fread(buffer, size, count, file->fp);
486 }
487 
488 
489 
490 
491 /* @func ajReadbinChar ********************************************************
492 **
493 ** Reads a character string from a file
494 **
495 ** @param [u] file [AjPFile] File object.
496 ** @param [r] size[size_t] Number of bytes to read from index file.
497 ** @param [w] buffer[char*] Buffer to read into
498 ** @return [size_t] Number of bytes read.
499 **
500 ** @release 6.0.0
501 ** @@
502 ******************************************************************************/
503 
ajReadbinChar(AjPFile file,size_t size,char * buffer)504 size_t ajReadbinChar(AjPFile file, size_t size,
505                      char* buffer)
506 {
507     size_t ret;
508 
509     ret = fread(buffer, 1, size, file->fp);
510 
511     return ret;
512 }
513 
514 
515 
516 
517 /* @func ajReadbinCharTrim ****************************************************
518 **
519 ** Reads a character string from a file and trims trailing spaces
520 **
521 ** @param [u] file [AjPFile] File object.
522 ** @param [r] size[size_t] Number of bytes to read from index file.
523 ** @param [w] buffer[char*] Buffer to read into
524 ** @return [size_t] Number of bytes read.
525 **
526 ** @release 6.0.0
527 ** @@
528 ******************************************************************************/
529 
ajReadbinCharTrim(AjPFile file,size_t size,char * buffer)530 size_t ajReadbinCharTrim(AjPFile file, size_t size,
531                              char* buffer)
532 {
533     size_t ret;
534     char* sp;
535 
536     ret = fread(buffer, 1, size, file->fp);
537 
538     buffer[size] = '\0';
539     sp = &buffer[strlen(buffer)];
540 
541     while(sp > buffer)
542     {
543         sp--;
544 
545 	if(*sp != ' ')
546 	    break;
547 
548 	*sp = '\0';
549     }
550 
551     return ret;
552 }
553 
554 
555 
556 
557 /* @func ajReadbinInt *********************************************************
558 **
559 ** Binary read of an unsigned integer from an input file object using
560 ** the C 'fread' function. Converts from little-endian.
561 **
562 ** @param [u] file [AjPFile] Input file.
563 ** @param [w] Pi [ajint*] Integer value
564 ** @return [size_t] Number of bytes read.
565 **
566 ** @release 6.0.0
567 ** @@
568 ******************************************************************************/
569 
ajReadbinInt(AjPFile file,ajint * Pi)570 size_t ajReadbinInt(AjPFile file, ajint *Pi)
571 {
572     size_t ret;
573 
574     ret = fread(Pi, 4, 1, file->fp);
575 
576 #ifdef WORDS_BIGENDIAN
577     ajByteRevLen4(Pi);
578 #endif
579 
580     return ret;
581 }
582 
583 
584 
585 
586 /* @func ajReadbinIntEndian ***************************************************
587 **
588 ** Binary read of an unsigned integer from an input file object using
589 ** the C 'fread' function. Converts from big-endian.
590 **
591 ** @param [u] file [AjPFile] Input file.
592 ** @param [w] Pi [ajint*] Integer value
593 ** @return [size_t] Number of bytes read.
594 **
595 ** @release 6.0.0
596 ** @@
597 ******************************************************************************/
598 
ajReadbinIntEndian(AjPFile file,ajint * Pi)599 size_t ajReadbinIntEndian(AjPFile file, ajint *Pi)
600 {
601     size_t ret;
602 
603 
604     ret = fread(Pi, 4, 1, file->fp);
605 
606 #ifndef WORDS_BIGENDIAN
607     ajByteRevLen4(Pi);
608 #endif
609 
610     return ret;
611 }
612 
613 
614 
615 
616 /* @func ajReadbinIntLocal ****************************************************
617 **
618 ** Binary read of an unsigned integer from an input file object using
619 ** the C 'fread' function. No conversion (assumes integer was written
620 ** on the same system).
621 **
622 ** @param [u] file [AjPFile] Input file.
623 ** @param [w] Pi [ajint*] Integer value
624 ** @return [size_t] Number of bytes read.
625 **
626 ** @release 6.0.0
627 ** @@
628 ******************************************************************************/
629 
ajReadbinIntLocal(AjPFile file,ajint * Pi)630 size_t ajReadbinIntLocal(AjPFile file, ajint *Pi)
631 {
632     size_t ret;
633 
634     ret = fread(Pi, 4, 1, file->fp);
635 
636     return ret;
637 }
638 
639 
640 
641 
642 /* @func ajReadbinInt2 ********************************************************
643 **
644 ** Binary read of a 2 byte integer from an input file object using
645 ** the C 'fread' function. Converts from little-endian.
646 **
647 ** @param [u] file [AjPFile] Input file.
648 ** @param [w] Pi2 [ajshort*] Integer value
649 ** @return [size_t] Number of bytes read.
650 **
651 ** @release 6.0.0
652 ** @@
653 ******************************************************************************/
654 
ajReadbinInt2(AjPFile file,ajshort * Pi2)655 size_t ajReadbinInt2(AjPFile file, ajshort *Pi2)
656 {
657     size_t ret;
658 
659     ret = fread(Pi2, 2, 1, file->fp);
660 
661 #ifdef WORDS_BIGENDIAN
662     ajByteRevLen2(Pi2);
663 #endif
664 
665     return ret;
666 }
667 
668 
669 
670 
671 /* @func ajReadbinInt2Endian **************************************************
672 **
673 ** Binary read of an unsigned integer from an input file object using
674 ** the C 'fread' function. Converts from big-endian.
675 **
676 ** @param [u] file [AjPFile] Input file.
677 ** @param [w] Pi2 [ajshort*] Integer value
678 ** @return [size_t] Number of bytes read.
679 **
680 ** @release 6.0.0
681 ** @@
682 ******************************************************************************/
683 
ajReadbinInt2Endian(AjPFile file,ajshort * Pi2)684 size_t ajReadbinInt2Endian(AjPFile file, ajshort *Pi2)
685 {
686     size_t ret;
687 
688     ret = fread(Pi2, 2, 1, file->fp);
689 
690 #ifndef WORDS_BIGENDIAN
691     ajByteRevLen2(Pi2);
692 #endif
693 
694     return ret;
695 }
696 
697 
698 
699 
700 /* @func ajReadbinInt2Local ***************************************************
701 **
702 ** Binary read of an unsigned integer from an input file object using
703 ** the C 'fread' function. No conversion (assumes integer was written
704 ** on the same system).
705 **
706 ** @param [u] file [AjPFile] Input file.
707 ** @param [w] Pi2 [ajshort*] Integer value
708 ** @return [size_t] Number of bytes read.
709 **
710 ** @release 6.0.0
711 ** @@
712 ******************************************************************************/
713 
ajReadbinInt2Local(AjPFile file,ajshort * Pi2)714 size_t ajReadbinInt2Local(AjPFile file, ajshort *Pi2)
715 {
716     size_t ret;
717 
718     ret = fread(Pi2, 2, 1, file->fp);
719 
720     return ret;
721 }
722 
723 
724 
725 
726 /* @func ajReadbinInt4 ********************************************************
727 **
728 ** Binary read of a 4 byte integer from an input file object using
729 ** the C 'fread' function.
730 **
731 ** @param [u] file [AjPFile] Input file.
732 ** @param [w] Pi4 [ajint*] Integer value
733 ** @return [size_t] Number of bytes read.
734 **
735 ** @release 6.0.0
736 ** @@
737 ******************************************************************************/
738 
ajReadbinInt4(AjPFile file,ajint * Pi4)739 size_t ajReadbinInt4(AjPFile file, ajint *Pi4)
740 {
741     size_t ret;
742 
743     ret = fread(Pi4, 4, 1, file->fp);
744 
745 #ifdef WORDS_BIGENDIAN
746     ajByteRevLen4(Pi4);
747 #endif
748 
749     return ret;
750 }
751 
752 
753 
754 
755 /* @func ajReadbinInt4Endian **************************************************
756 **
757 ** Binary read of an unsigned integer from an input file object using
758 ** the C 'fread' function. Converts from big-endian.
759 **
760 ** @param [u] file [AjPFile] Input file.
761 ** @param [w] Pi4 [ajint*] Integer value
762 ** @return [size_t] Number of bytes read.
763 **
764 ** @release 6.0.0
765 ** @@
766 ******************************************************************************/
767 
ajReadbinInt4Endian(AjPFile file,ajint * Pi4)768 size_t ajReadbinInt4Endian(AjPFile file, ajint *Pi4)
769 {
770     size_t ret;
771 
772     ret = fread(Pi4, 4, 1, file->fp);
773 
774 #ifndef WORDS_BIGENDIAN
775     ajByteRevLen4(Pi4);
776 #endif
777 
778     return ret;
779 }
780 
781 
782 
783 
784 /* @func ajReadbinInt4Local ***************************************************
785 **
786 ** Binary read of an unsigned integer from an input file object using
787 ** the C 'fread' function. No conversion (assumes integer was written
788 ** on the same system).
789 **
790 ** @param [u] file [AjPFile] Input file.
791 ** @param [w] Pi4 [ajint*] Integer value
792 ** @return [size_t] Number of bytes read.
793 **
794 ** @release 6.0.0
795 ** @@
796 ******************************************************************************/
797 
ajReadbinInt4Local(AjPFile file,ajint * Pi4)798 size_t ajReadbinInt4Local(AjPFile file, ajint *Pi4)
799 {
800     size_t ret;
801 
802     ret = fread(Pi4, 4, 1, file->fp);
803 
804     return ret;
805 }
806 
807 
808 
809 
810 /* @func ajReadbinInt8 ********************************************************
811 **
812 ** Binary read of an 8 byte integer from an input file object using
813 ** the C 'fread' function. Converts from little-endian.
814 **
815 ** @param [u] file [AjPFile] Input file.
816 ** @param [w] Pi8 [ajlong*] Integer value
817 ** @return [size_t] Number of bytes read.
818 **
819 ** @release 6.0.0
820 ** @@
821 ******************************************************************************/
822 
ajReadbinInt8(AjPFile file,ajlong * Pi8)823 size_t ajReadbinInt8(AjPFile file, ajlong *Pi8)
824 {
825     long ret;
826 
827     ret = fread(Pi8, 8, 1, file->fp);
828 
829 #ifdef WORDS_BIGENDIAN
830     ajByteRevLen8(Pi8);
831 #endif
832 
833     return ret;
834 }
835 
836 
837 
838 
839 /* @func ajReadbinInt8Endian **************************************************
840 **
841 ** Binary read of an unsigned integer from an input file object using
842 ** the C 'fread' function. Converts from big-endian.
843 **
844 ** @param [u] file [AjPFile] Input file.
845 ** @param [w] Pi8 [ajlong*] Integer value
846 ** @return [size_t] Number of bytes read.
847 **
848 ** @release 6.0.0
849 ** @@
850 ******************************************************************************/
851 
ajReadbinInt8Endian(AjPFile file,ajlong * Pi8)852 size_t ajReadbinInt8Endian(AjPFile file, ajlong *Pi8)
853 {
854     size_t ret;
855 
856     ret = fread(Pi8, 8, 1, file->fp);
857 
858 #ifndef WORDS_BIGENDIAN
859     ajByteRevLen8(Pi8);
860 #endif
861 
862     return ret;
863 }
864 
865 
866 
867 
868 /* @func ajReadbinInt8Local ***************************************************
869 **
870 ** Binary read of an unsigned integer from an input file object using
871 ** the C 'fread' function. No conversion (assumes integer was written
872 ** on the same system).
873 **
874 ** @param [u] file [AjPFile] Input file.
875 ** @param [w] Pi8 [ajlong*] Integer value
876 ** @return [size_t] Number of bytes read.
877 **
878 ** @release 6.0.0
879 ** @@
880 ******************************************************************************/
881 
ajReadbinInt8Local(AjPFile file,ajlong * Pi8)882 size_t ajReadbinInt8Local(AjPFile file, ajlong *Pi8)
883 {
884     size_t ret;
885 
886     ret = fread(Pi8, 8, 1, file->fp);
887 
888     return ret;
889 }
890 
891 
892 
893 
894 /* @func ajReadbinStr *********************************************************
895 **
896 ** Reads a string from a file
897 **
898 ** @param [u] file [AjPFile] File object.
899 ** @param [r] size [size_t] Number of bytes to read from index file.
900 ** @param [w] Pstr [AjPStr*] Buffer to read into
901 ** @return [size_t] Number of bytes read.
902 **
903 ** @release 6.5.0
904 ** @@
905 ******************************************************************************/
906 
ajReadbinStr(AjPFile file,size_t size,AjPStr * Pstr)907 size_t ajReadbinStr(AjPFile file, size_t size,
908                     AjPStr* Pstr)
909 {
910     size_t ret;
911     char* cp;
912 
913     ajStrSetRes(Pstr, size+1);
914     cp = ajStrGetuniquePtr(Pstr);
915 
916     ret = fread(cp, 1, size, file->fp);
917     cp[size] = '\0';
918 
919     ajStrSetValid(Pstr);
920 
921     return ret;
922 }
923 
924 
925 
926 
927 /* @func ajReadbinStrTrim *****************************************************
928 **
929 ** Reads a character string from a file and trims trailing spaces
930 **
931 ** @param [u] file [AjPFile] File object.
932 ** @param [r] size [size_t] Number of bytes to read from index file.
933 ** @param [w] Pstr [AjPStr*] Buffer to read into
934 ** @return [size_t] Number of bytes read.
935 **
936 ** @release 6.5.0
937 ** @@
938 ******************************************************************************/
939 
ajReadbinStrTrim(AjPFile file,size_t size,AjPStr * Pstr)940 size_t ajReadbinStrTrim(AjPFile file, size_t size,
941                         AjPStr* Pstr)
942 {
943     size_t ret;
944     char* cp;
945 
946     ajStrSetRes(Pstr, size+1);
947     cp = ajStrGetuniquePtr(Pstr);
948 
949     ret = fread(cp, 1, size, file->fp);
950     cp[size] = '\0';
951 
952     ajStrSetValid(Pstr);
953 
954     ajStrTrimEndC(Pstr, " ");
955 
956     return ret;
957 }
958 
959 
960 
961 
962 /* @func ajReadbinUint ********************************************************
963 **
964 ** Binary read of an unsigned integer from an input file object using
965 ** the C 'fread' function.
966 **
967 ** @param [u] file [AjPFile] Input file.
968 ** @param [w] Pu [ajuint*] Unsigned integer value
969 ** @return [size_t] Number of bytes read.
970 **
971 ** @release 6.0.0
972 ** @@
973 ******************************************************************************/
974 
ajReadbinUint(AjPFile file,ajuint * Pu)975 size_t ajReadbinUint(AjPFile file, ajuint *Pu)
976 {
977     size_t ret;
978 #ifdef WORDS_BIGENDIAN
979     ajint val2;
980 #endif
981 
982     ret = fread(Pu, 4, 1, file->fp);
983 
984 #ifdef WORDS_BIGENDIAN
985     val2 = *Pu;
986     ajByteRevLen4(&val2);
987     *Pu = val2;
988 #endif
989 
990     return ret;
991 }
992 
993 
994 
995 
996 /* @func ajReadbinUintEndian **************************************************
997 **
998 ** Binary read of an unsigned integer from an input file object using
999 ** the C 'fread' function. Converts from big-endian.
1000 **
1001 ** @param [u] file [AjPFile] Input file.
1002 ** @param [w] Pu [ajuint*] Unsigned integer value
1003 ** @return [size_t] Number of bytes read.
1004 **
1005 ** @release 6.0.0
1006 ** @@
1007 ******************************************************************************/
1008 
ajReadbinUintEndian(AjPFile file,ajuint * Pu)1009 size_t ajReadbinUintEndian(AjPFile file, ajuint *Pu)
1010 {
1011     ajuint ret;
1012 #ifndef WORDS_BIGENDIAN
1013     ajint val2;
1014 #endif
1015 
1016     ret = fread(Pu, 4, 1, file->fp);
1017 
1018 #ifndef WORDS_BIGENDIAN
1019     val2 = *Pu;
1020     ajByteRevLen4(&val2);
1021     *Pu = val2;
1022 #endif
1023 
1024     return ret;
1025 }
1026 
1027 
1028 
1029 
1030 /* @func ajReadbinUintLocal ***************************************************
1031 **
1032 ** Binary read of an unsigned integer from an input file object using
1033 ** the C 'fread' function. No conversion (assumes integer was written
1034 ** on the same system).
1035 **
1036 ** @param [u] file [AjPFile] Input file.
1037 ** @param [w] Pu [ajuint*] Unsigned integer value
1038 ** @return [size_t] Number of bytes read.
1039 **
1040 ** @release 6.0.0
1041 ** @@
1042 ******************************************************************************/
1043 
ajReadbinUintLocal(AjPFile file,ajuint * Pu)1044 size_t ajReadbinUintLocal(AjPFile file, ajuint *Pu)
1045 {
1046     ajuint ret;
1047 
1048     ret = fread(Pu, 4, 1, file->fp);
1049 
1050     return ret;
1051 }
1052 
1053 
1054 
1055 
1056 /* @func ajReadbinUint2 *******************************************************
1057 **
1058 ** Binary read of an unsigned integer from an input file object using
1059 ** the C 'fread' function. Converts from little-endian.
1060 **
1061 ** @param [u] file [AjPFile] Input file.
1062 ** @param [w] Pu2 [ajushort*] Unsigned integer value
1063 ** @return [size_t] Number of bytes read.
1064 **
1065 ** @release 6.0.0
1066 ** @@
1067 ******************************************************************************/
1068 
ajReadbinUint2(AjPFile file,ajushort * Pu2)1069 size_t ajReadbinUint2(AjPFile file, ajushort *Pu2)
1070 {
1071     size_t ret;
1072 #ifdef WORDS_BIGENDIAN
1073     ajshort val2;
1074 #endif
1075 
1076     ret = fread(Pu2, 2, 1, file->fp);
1077 
1078 #ifdef WORDS_BIGENDIAN
1079     val2 = *Pu2;
1080     ajByteRevLen2(&val2);
1081     *Pu2 = val2;
1082 #endif
1083 
1084     return ret;
1085 }
1086 
1087 
1088 
1089 
1090 /* @func ajReadbinUint2Endian *************************************************
1091 **
1092 ** Binary read of an unsigned integer from an input file object using
1093 ** the C 'fread' function. Converts from big-endian.
1094 **
1095 ** @param [u] file [AjPFile] Input file.
1096 ** @param [w] Pu2 [ajushort*] Unsigned integer value
1097 ** @return [size_t] Number of bytes read.
1098 **
1099 ** @release 6.0.0
1100 ** @@
1101 ******************************************************************************/
1102 
ajReadbinUint2Endian(AjPFile file,ajushort * Pu2)1103 size_t ajReadbinUint2Endian(AjPFile file, ajushort *Pu2)
1104 {
1105     size_t ret;
1106 #ifndef WORDS_BIGENDIAN
1107     ajshort val2;
1108 #endif
1109 
1110     ret = fread(Pu2, 2, 1, file->fp);
1111 
1112 #ifndef WORDS_BIGENDIAN
1113     val2 = *Pu2;
1114     ajByteRevLen2(&val2);
1115     *Pu2 = val2;
1116 #endif
1117 
1118     return ret;
1119 }
1120 
1121 
1122 
1123 
1124 /* @func ajReadbinUint2Local **************************************************
1125 **
1126 ** Binary read of an unsigned integer from an input file object using
1127 ** the C 'fread' function. No conversion (assumes integer was written
1128 ** on the same system).
1129 **
1130 ** @param [u] file [AjPFile] Input file.
1131 ** @param [w] Pu2 [ajushort*] Unsigned integer value
1132 ** @return [size_t] Number of bytes read.
1133 **
1134 ** @release 6.0.0
1135 ** @@
1136 ******************************************************************************/
1137 
ajReadbinUint2Local(AjPFile file,ajushort * Pu2)1138 size_t ajReadbinUint2Local(AjPFile file, ajushort *Pu2)
1139 {
1140     size_t ret;
1141 
1142     ret = fread(Pu2, 2, 1, file->fp);
1143 
1144     return ret;
1145 }
1146 
1147 
1148 
1149 
1150 /* @func ajReadbinUint4 *******************************************************
1151 **
1152 ** Binary read of an unsigned integer from an input file object using
1153 ** the C 'fread' function. Converts from little-endian.
1154 **
1155 ** @param [u] file [AjPFile] Input file.
1156 ** @param [w] Pu4 [ajuint*] Unsigned integer value
1157 ** @return [size_t] Number of bytes read.
1158 **
1159 ** @release 6.0.0
1160 ** @@
1161 ******************************************************************************/
1162 
ajReadbinUint4(AjPFile file,ajuint * Pu4)1163 size_t ajReadbinUint4(AjPFile file, ajuint *Pu4)
1164 {
1165     size_t ret;
1166 #ifdef WORDS_BIGENDIAN
1167     ajint val2;
1168 #endif
1169 
1170     ret = fread(Pu4, 4, 1, file->fp);
1171 
1172 #ifdef WORDS_BIGENDIAN
1173     val2 = *Pu4;
1174     ajByteRevLen4(&val2);
1175     *Pu4 = val2;
1176 #endif
1177 
1178     return ret;
1179 }
1180 
1181 
1182 
1183 
1184 /* @func ajReadbinUint4Endian *************************************************
1185 **
1186 ** Binary read of an unsigned integer from an input file object using
1187 ** the C 'fread' function. Converts from a big-endian.
1188 **
1189 ** @param [u] file [AjPFile] Input file.
1190 ** @param [w] Pu4 [ajuint*] Unsigned integer value
1191 ** @return [size_t] Number of bytes read.
1192 **
1193 ** @release 6.0.0
1194 ** @@
1195 ******************************************************************************/
1196 
ajReadbinUint4Endian(AjPFile file,ajuint * Pu4)1197 size_t ajReadbinUint4Endian(AjPFile file, ajuint *Pu4)
1198 {
1199     size_t ret;
1200 #ifndef WORDS_BIGENDIAN
1201     ajint val2;
1202 #endif
1203 
1204     ret = fread(Pu4, 4, 1, file->fp);
1205 
1206 #ifndef WORDS_BIGENDIAN
1207     val2 = *Pu4;
1208     ajByteRevLen4(&val2);
1209     *Pu4 = val2;
1210 #endif
1211 
1212     return ret;
1213 }
1214 
1215 
1216 
1217 
1218 /* @func ajReadbinUint4Local **************************************************
1219 **
1220 ** Binary read of an unsigned integer from an input file object using
1221 ** the C 'fread' function. No conversion (assumes integer was written
1222 ** on the same system).
1223 **
1224 ** @param [u] file [AjPFile] Input file.
1225 ** @param [w] Pu4 [ajuint*] Unsigned integer value
1226 ** @return [size_t] Number of bytes read.
1227 **
1228 ** @release 6.0.0
1229 ** @@
1230 ******************************************************************************/
1231 
ajReadbinUint4Local(AjPFile file,ajuint * Pu4)1232 size_t ajReadbinUint4Local(AjPFile file, ajuint *Pu4)
1233 {
1234     size_t ret;
1235 
1236     ret = fread(Pu4, 4, 1, file->fp);
1237 
1238     return ret;
1239 }
1240 
1241 
1242 
1243 
1244 /* @func ajReadbinUint8 *******************************************************
1245 **
1246 ** Binary read of an unsigned integer from an input file object using
1247 ** the C 'fread' function. Converts from little-endian.
1248 **
1249 ** @param [u] file [AjPFile] Input file.
1250 ** @param [w] Pu8 [ajulong*] Unsigned long integer value
1251 ** @return [size_t] Number of bytes read.
1252 **
1253 ** @release 6.0.0
1254 ** @@
1255 ******************************************************************************/
1256 
ajReadbinUint8(AjPFile file,ajulong * Pu8)1257 size_t ajReadbinUint8(AjPFile file, ajulong *Pu8)
1258 {
1259     size_t ret;
1260 #ifdef WORDS_BIGENDIAN
1261     ajlong val2;
1262 #endif
1263 
1264     ret = fread(Pu8, 8, 1, file->fp);
1265 
1266 #ifdef WORDS_BIGENDIAN
1267     val2 = *Pu8;
1268     ajByteRevLen8(&val2);
1269     *Pu8 = val2;
1270 #endif
1271 
1272     return ret;
1273 }
1274 
1275 
1276 
1277 
1278 /* @func ajReadbinUint8Endian *************************************************
1279 **
1280 ** Binary read of an unsigned integer from an input file object using
1281 ** the C 'fread' function. Converts from big-endian.
1282 **
1283 ** @param [u] file [AjPFile] Input file.
1284 ** @param [w] Pu8 [ajulong*] Unsigned long integer value
1285 ** @return [size_t] Number of bytes read.
1286 **
1287 ** @release 6.0.0
1288 ** @@
1289 ******************************************************************************/
1290 
ajReadbinUint8Endian(AjPFile file,ajulong * Pu8)1291 size_t ajReadbinUint8Endian(AjPFile file, ajulong *Pu8)
1292 {
1293     size_t ret;
1294 #ifndef WORDS_BIGENDIAN
1295     ajlong val2;
1296 #endif
1297 
1298     ret = fread(Pu8, 8, 1, file->fp);
1299 
1300 #ifndef WORDS_BIGENDIAN
1301     val2 = (ajlong) *Pu8;
1302     ajByteRevLen8(&val2);
1303     *Pu8 = val2;
1304 #endif
1305 
1306     return ret;
1307 }
1308 
1309 
1310 
1311 
1312 /* @func ajReadbinUint8Local **************************************************
1313 **
1314 ** Binary read of an unsigned integer from an input file object using
1315 ** the C 'fread' function. No conversion (assumes integer was written
1316 ** on the same system).
1317 **
1318 ** @param [u] file [AjPFile] Input file.
1319 ** @param [w] Pu8 [ajulong*] Unsigned long integer value
1320 ** @return [size_t] Number of bytes read.
1321 **
1322 ** @release 6.0.0
1323 ** @@
1324 ******************************************************************************/
1325 
ajReadbinUint8Local(AjPFile file,ajulong * Pu8)1326 size_t ajReadbinUint8Local(AjPFile file, ajulong *Pu8)
1327 {
1328     size_t ret;
1329 
1330     ret = fread(Pu8, 8, 1, file->fp);
1331 
1332     return ret;
1333 }
1334 
1335 
1336 
1337 
1338 /* @datasection [AjPFile] File object *****************************************
1339 **
1340 ** Function is for manipulating files open for output and returns or
1341 ** takes at least one AjSFile argument.
1342 **
1343 */
1344 
1345 
1346 
1347 
1348 /* @section file binary write operations
1349 **
1350 ** @fdata [AjPFile]
1351 **
1352 ** These functions write data directly to a file using system functions
1353 **
1354 ** @nam2rule Writebin Write binary data to a file
1355 ** @nam3rule Binary Binary write from a buffer
1356 ** @nam3rule Byte Write a single byte (character)
1357 ** @nam3rule Char Write a C character string
1358 ** @nam3rule Int Binary read of an integer
1359 ** @nam3rule Int2 Binary read of a 2 byte integer
1360 ** @nam3rule Int4 Binary read of a 4 byte integer
1361 ** @nam3rule Int8 Binary read of an 8 byte integer
1362 ** @nam3rule Uint2 Binary read of a 2 byte unsigned integer
1363 ** @nam3rule Uint4 Binary read of a 4 byte unsigned integer
1364 ** @nam3rule Uint8 Binary read of an 8 byte unsigned integer
1365 ** @nam3rule Newline Write newline character(s)
1366 ** @nam3rule Str Write a string object
1367 **
1368 ** @argrule Writebin file [AjPFile] Output file object
1369 ** @argrule Binary count [size_t] Number of elements to write
1370 ** @argrule Binary size [size_t] Size of each element
1371 ** @argrule Binary buffer [const void*] Buffer for binary write
1372 ** @argrule Byte ch [char] Byte to be written
1373 ** @argrule Char txt [const char*] Character string (length passed separately)
1374 ** @argrule Char len [size_t] Character string length to be written
1375 ** @argrule Int i [ajint] Integer value
1376 ** @argrule Int2 i2 [ajshort] Integer 2 byte value
1377 ** @argrule Int4 i4 [ajint] Integer 4 byte value
1378 ** @argrule Int8 i8 [ajlong] Integer 8 byte value
1379 ** @argrule Uint2 u2 [ajushort] Integer 2 byte unsigned value
1380 ** @argrule Uint4 u4 [ajuint] Integer 4 byte unsigned value
1381 ** @argrule Uint8 u8 [ajulong] Integer 8 byte unsigned value
1382 ** @argrule Uint u [ajuint] Unsigned integer value
1383 ** @argrule Str str [const AjPStr] String (length passed separately)
1384 ** @argrule Str len [size_t] String length to be written
1385 **
1386 ** @valrule * [size_t] Number of elements written
1387 **
1388 ** @fcategory output
1389 **
1390 ******************************************************************************/
1391 
1392 
1393 
1394 
1395 /* @func ajWritebinBinary *****************************************************
1396 **
1397 ** Binary write to an output file object using the C 'fwrite' function.
1398 **
1399 ** @param [u] file [AjPFile] Output file.
1400 ** @param [r] count [size_t] Number of elements to write.
1401 ** @param [r] size [size_t] Number of bytes per element.
1402 ** @param [r] buffer [const void*] Buffer for output.
1403 ** @return [size_t] Return value from 'fwrite'
1404 **
1405 ** @release 6.0.0
1406 ** @@
1407 ******************************************************************************/
1408 
ajWritebinBinary(AjPFile file,size_t count,size_t size,const void * buffer)1409 size_t ajWritebinBinary(AjPFile file, size_t count,
1410 		   size_t size, const void* buffer)
1411 {
1412     return fwrite(buffer, size, count, file->fp);
1413 }
1414 
1415 
1416 
1417 
1418 /* @func ajWritebinByte *******************************************************
1419 **
1420 ** Writes a single byte to a binary file
1421 **
1422 ** @param [u] file [AjPFile] Output file
1423 ** @param [r] ch [char] Character
1424 ** @return [size_t] Return value from fwrite
1425 **
1426 ** @release 6.0.0
1427 ** @@
1428 ******************************************************************************/
1429 
ajWritebinByte(AjPFile file,char ch)1430 size_t ajWritebinByte(AjPFile file, char ch)
1431 {
1432     return fwrite(&ch, 1, 1, file->fp);
1433 }
1434 
1435 
1436 
1437 
1438 /* @func ajWritebinChar *******************************************************
1439 **
1440 ** Writes a text string to a binary file
1441 **
1442 ** @param [u] file [AjPFile] Output file
1443 ** @param [r] txt [const char*] Text string
1444 ** @param [r] len [size_t] Length (padded) to write to the file
1445 ** @return [size_t] Return value from fwrite
1446 **
1447 ** @release 6.0.0
1448 ** @@
1449 ******************************************************************************/
1450 
ajWritebinChar(AjPFile file,const char * txt,size_t len)1451 size_t ajWritebinChar(AjPFile file, const char* txt, size_t len)
1452 {
1453     size_t ret;
1454     size_t i;
1455     size_t j;
1456 
1457     i = strlen(txt) + 1;
1458 
1459     if(i >= len)
1460         return fwrite(txt, len, 1, file->fp);
1461 
1462     ret = fwrite(txt, i, 1, file->fp);
1463 
1464     j = len-i;
1465 
1466     for(i=0;i<j;i++)
1467         fwrite("", 1, 1, file->fp);
1468 
1469     return ret;
1470 }
1471 
1472 
1473 
1474 
1475 /* @func ajWritebinInt2 *******************************************************
1476 **
1477 ** Writes a 2 byte integer to a binary file, with the correct byte orientation
1478 **
1479 ** @param [u] file [AjPFile] Output file
1480 ** @param [r] i2 [ajshort] Integer
1481 ** @return [size_t] Return value from fwrite
1482 **
1483 ** @release 6.0.0
1484 ** @@
1485 ******************************************************************************/
1486 
ajWritebinInt2(AjPFile file,ajshort i2)1487 size_t ajWritebinInt2(AjPFile file, ajshort i2)
1488 {
1489 #ifdef WORDS_BIGENDIAN
1490     short j;
1491 
1492     j = i2;
1493     ajByteRevLen2(&j);
1494 
1495     return fwrite(&j, 2, 1, file->fp);
1496 #else
1497     return fwrite(&i2, 2, 1, file->fp);
1498 #endif
1499 
1500 }
1501 
1502 
1503 
1504 
1505 /* @func ajWritebinInt4 *******************************************************
1506 **
1507 ** Writes a 4 byte integer to a binary file, with the correct byte orientation
1508 **
1509 ** @param [u] file [AjPFile] Output file
1510 ** @param [r] i4 [ajint] Integer
1511 ** @return [size_t] Return value from fwrite
1512 **
1513 ** @release 6.0.0
1514 ** @@
1515 ******************************************************************************/
1516 
ajWritebinInt4(AjPFile file,ajint i4)1517 size_t ajWritebinInt4(AjPFile file, ajint i4)
1518 {
1519 #ifdef WORDS_BIGENDIAN
1520     ajint j;
1521 
1522     j = i4;
1523 
1524     ajByteRevLen4(&j);
1525 
1526     return fwrite(&j, 4, 1, file->fp);
1527 #else
1528     return fwrite(&i4, 4, 1, file->fp);
1529 #endif
1530 }
1531 
1532 
1533 
1534 
1535 /* @func ajWritebinInt8 *******************************************************
1536 **
1537 ** Writes an 8 byte long to a binary file, with the correct byte orientation
1538 **
1539 ** @param [u] file [AjPFile] Output file
1540 ** @param [r] i8 [ajlong] Integer
1541 ** @return [size_t] Return value from fwrite
1542 **
1543 ** @release 6.0.0
1544 ** @@
1545 ******************************************************************************/
1546 
ajWritebinInt8(AjPFile file,ajlong i8)1547 size_t ajWritebinInt8(AjPFile file, ajlong i8)
1548 {
1549 #ifdef WORDS_BIGENDIAN
1550     ajlong j;
1551 
1552     j = i8;
1553 
1554     ajByteRevLen8(&j);
1555 
1556     return fwrite(&j, 8, 1, file->fp);
1557 #else
1558     return fwrite(&i8, 8, 1, file->fp);
1559 #endif
1560 }
1561 
1562 
1563 
1564 
1565 /* @func ajWritebinNewline ****************************************************
1566 **
1567 ** Writes newline character(s) to a file
1568 **
1569 ** @param [u] file [AjPFile] Output file
1570 ** @return [size_t] Return value from fwrite
1571 **
1572 ** @release 6.2.0
1573 ******************************************************************************/
1574 
ajWritebinNewline(AjPFile file)1575 size_t ajWritebinNewline(AjPFile file)
1576 {
1577     size_t ret;
1578 
1579 #ifdef WIN32
1580     /*ret = fwrite("\r\n", 1, 2, file->fp);*/
1581     ret = fwrite("\n", 1, 1, file->fp);
1582 #else
1583     ret = fwrite("\n", 1, 1, file->fp);
1584 #endif
1585 
1586     return ret;
1587 }
1588 
1589 
1590 
1591 
1592 /* @func ajWritebinStr ********************************************************
1593 **
1594 ** Writes a string to a binary file
1595 **
1596 ** @param [u] file [AjPFile] Output file
1597 ** @param [r] str [const AjPStr] String
1598 ** @param [r] len [size_t] Length (padded) to use in the file
1599 ** @return [size_t] Return value from fwrite
1600 **
1601 ** @release 6.0.0
1602 ** @@
1603 ******************************************************************************/
1604 
ajWritebinStr(AjPFile file,const AjPStr str,size_t len)1605 size_t ajWritebinStr(AjPFile file, const AjPStr str, size_t len)
1606 {
1607     size_t ret;
1608     ajuint ilen;
1609     ajuint i;
1610     ajuint j;
1611     ajuint k;
1612 
1613     ilen = 1+ajStrGetLen(str);
1614 
1615     if(ilen >= len)
1616         return fwrite(ajStrGetPtr(str), len, 1, file->fp);
1617 
1618     ret = fwrite(ajStrGetPtr(str), ilen, 1, file->fp);
1619 
1620     j = len - ilen;
1621 
1622     k = 20;
1623 
1624     for(i=0;i<j;i+=20)
1625     {
1626         if((j-i) < 20)
1627             k = j-i;
1628         fwrite("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
1629                k, 1, file->fp);
1630     }
1631 
1632     return ret;
1633 }
1634 
1635 
1636 
1637 
1638 /* @func ajWritebinUint2 ******************************************************
1639 **
1640 ** Writes a 2 byte unsigned integer to a binary file, with the correct
1641 ** byte orientation
1642 **
1643 ** @param [u] file [AjPFile] Output file
1644 ** @param [r] u2 [ajushort] Unsigned integer
1645 ** @return [size_t] Return value from fwrite
1646 **
1647 ** @release 6.0.0
1648 ** @@
1649 ******************************************************************************/
1650 
ajWritebinUint2(AjPFile file,ajushort u2)1651 size_t ajWritebinUint2(AjPFile file, ajushort u2)
1652 {
1653 #ifdef WORDS_BIGENDIAN
1654     unsigned short j;
1655 
1656     j = u2;
1657 
1658     ajByteRevLen2u(&j);
1659 
1660     return fwrite(&j, 2, 1, file->fp);
1661 #else
1662     return fwrite(&u2, 2, 1, file->fp);
1663 #endif
1664 
1665 }
1666 
1667 
1668 
1669 
1670 /* @func ajWritebinUint4 ******************************************************
1671 **
1672 ** Writes a 4 byte unsigned integer to a binary file, with the correct
1673 ** byte orientation
1674 **
1675 ** @param [u] file [AjPFile] Output file
1676 ** @param [r] u4 [ajuint] Unsigned integer
1677 ** @return [size_t] Return value from fwrite
1678 **
1679 ** @release 6.5.0
1680 ** @@
1681 ******************************************************************************/
1682 
ajWritebinUint4(AjPFile file,ajuint u4)1683 size_t ajWritebinUint4(AjPFile file, ajuint u4)
1684 {
1685 #ifdef WORDS_BIGENDIAN
1686     ajuint j;
1687 
1688     j = u4;
1689 
1690     ajByteRevLen4u(&j);
1691 
1692     return fwrite(&j, 4, 1, file->fp);
1693 #else
1694     return fwrite(&u4, 4, 1, file->fp);
1695 #endif
1696 }
1697 
1698 
1699 
1700 
1701 /* @func ajWritebinUint8 ******************************************************
1702 **
1703 ** Writes an 8 byte unsigned long to a binary file, with the correct
1704 ** byte orientation
1705 **
1706 ** @param [u] file [AjPFile] Output file
1707 ** @param [r] u8 [ajulong] Unsigned integer
1708 ** @return [size_t] Return value from fwrite
1709 **
1710 ** @release 6.5.0
1711 ** @@
1712 ******************************************************************************/
1713 
ajWritebinUint8(AjPFile file,ajulong u8)1714 size_t ajWritebinUint8(AjPFile file, ajulong u8)
1715 {
1716 #ifdef WORDS_BIGENDIAN
1717     ajulong j;
1718 
1719     j = u8;
1720 
1721     ajByteRevLen8u(&j);
1722 
1723     return fwrite(&j, 8, 1, file->fp);
1724 #else
1725     return fwrite(&u8, 8, 1, file->fp);
1726 #endif
1727 }
1728 
1729 
1730 
1731 
1732 /* @section file line write operations
1733 **
1734 ** @fdata [AjPFile]
1735 **
1736 ** These functions write data directly to a file using system functions.
1737 ** Integer data is by default assumed to be stored as little-endian
1738 ** so that binary files with integers are portable across systems
1739 **
1740 ** @nam2rule Writeline Write a string to a file
1741 ** @nam3rule Space   Write a string to a file with a leading space
1742 ** @suffix Newline   Write a string to a file with a trailing newline
1743 **
1744 ** @argrule * file [AjPFile] Output file
1745 ** @argrule * line [const AjPStr] Output line with trailing newline
1746 **
1747 ** @valrule * [AjBool] True on success
1748 **
1749 ** @fcategory output
1750 **
1751 ******************************************************************************/
1752 
1753 
1754 
1755 
1756 /* @func ajWriteline **********************************************************
1757 **
1758 ** Writes a string to a file, including any newline characters
1759 **
1760 ** @param [u] file [AjPFile] Output file
1761 ** @param [r] line [const AjPStr] String to be written
1762 ** @return [AjBool] True on success
1763 **
1764 ** @release 6.0.0
1765 ******************************************************************************/
1766 
ajWriteline(AjPFile file,const AjPStr line)1767 AjBool ajWriteline(AjPFile file, const AjPStr line)
1768 {
1769     if(!fwrite(MAJSTRGETPTR(line), MAJSTRGETLEN(line), 1, file->fp))
1770         return ajFalse;
1771 
1772     return ajTrue;
1773 }
1774 
1775 
1776 
1777 
1778 /* @func ajWritelineNewline ***************************************************
1779 **
1780 ** Writes a string to a file, including any newline characters
1781 **
1782 ** @param [u] file [AjPFile] Output file
1783 ** @param [r] line [const AjPStr] String to be written
1784 ** @return [AjBool] True on success
1785 **
1786 ** @release 6.2.0
1787 ******************************************************************************/
1788 
ajWritelineNewline(AjPFile file,const AjPStr line)1789 AjBool ajWritelineNewline(AjPFile file, const AjPStr line)
1790 {
1791     if(!fwrite(MAJSTRGETPTR(line), 1, MAJSTRGETLEN(line), file->fp))
1792         return ajFalse;
1793 
1794 #ifdef WIN32
1795     /*if(!fwrite("\r\n", 1, 2, file->fp))
1796       return ajFalse;*/
1797     if(!fwrite("\n", 1, 1, file->fp))
1798         return ajFalse;
1799 #else
1800     if(!fwrite("\n", 1, 1, file->fp))
1801         return ajFalse;
1802 #endif
1803 
1804     return ajTrue;
1805 }
1806 
1807 
1808 
1809 
1810 /* @func ajWritelineSpace *****************************************************
1811 **
1812 ** Writes a string to a file, with a leading space
1813 **
1814 ** @param [u] file [AjPFile] Output file
1815 ** @param [r] line [const AjPStr] String to be written
1816 ** @return [AjBool] True on success
1817 **
1818 ** @release 6.2.0
1819 ******************************************************************************/
1820 
ajWritelineSpace(AjPFile file,const AjPStr line)1821 AjBool ajWritelineSpace(AjPFile file, const AjPStr line)
1822 {
1823     if(!fwrite(" ", 1, 1, file->fp))
1824         return ajFalse;
1825 
1826     if(!fwrite(MAJSTRGETPTR(line), MAJSTRGETLEN(line), 1, file->fp))
1827         return ajFalse;
1828 
1829     return ajTrue;
1830 }
1831 
1832 
1833 
1834 
1835 /* @datasection [AjPFilebuff] Buffered file object *****************************
1836 **
1837 ** Function is for manipulating buffered input files and returns or
1838 ** takes at least one AjPFilebuff argument.
1839 **
1840 */
1841 
1842 
1843 
1844 
1845 /* @section buffered file line read operations
1846 **
1847 ** @fdata [AjPFilebuff]
1848 **
1849 ** These functions read data directly from a file using system functions.
1850 ** Integer data is by default assumed to be stored as little-endian
1851 ** so that binary files with integers are portable across systems
1852 **
1853 ** @nam2rule Buffread
1854 ** @nam3rule Line     Read next line from buffer
1855 ** @nam4rule Trim     Remove trailing newline and linefeed characters
1856 ** @suffix   Pos      Return file position after read
1857 ** @suffix   Store    Append line to store buffer
1858 **
1859 ** @argrule * buff [AjPFilebuff] Input buffered file object
1860 ** @argrule Line Pdest [AjPStr*] Buffer (expanded automatically) for results
1861 ** @argrule Pos Ppos [ajlong*] File position after read
1862 ** @argrule Store dostore [AjBool] If true, use store buffer
1863 ** @argrule Store Pstore [AjPStr*] Buffer to store text from file
1864 **
1865 ** @valrule * [AjBool] True on success
1866 **
1867 ** @fcategory input
1868 */
1869 
1870 
1871 
1872 
1873 /* @func ajBuffreadLine *******************************************************
1874 **
1875 ** Reads a line from a buffered file. If the buffer has data, reads from the
1876 ** buffer. If the buffer is exhausted, reads from the file. If the file is
1877 ** exhausted, sets end of file and returns. If end of file was already set,
1878 ** looks for another file to open.
1879 **
1880 ** @param [u] buff [AjPFilebuff] Buffered input file.
1881 ** @param [w] Pdest [AjPStr*] Buffer to hold results.
1882 ** @return [AjBool] ajTrue if data was read.
1883 **
1884 ** @release 6.0.0
1885 ** @@
1886 ******************************************************************************/
1887 
ajBuffreadLine(AjPFilebuff buff,AjPStr * Pdest)1888 AjBool ajBuffreadLine(AjPFilebuff buff, AjPStr* Pdest)
1889 {
1890     ajlong fpos = 0;
1891 
1892     return ajBuffreadLinePos(buff, Pdest, &fpos);
1893 }
1894 
1895 
1896 
1897 
1898 /* @func ajBuffreadLinePos ****************************************************
1899 **
1900 ** Reads a line from a buffered file. If the buffer has data, reads from the
1901 ** buffer. If the buffer is exhausted, reads from the file. If the file is
1902 ** exhausted, sets end of file and returns. If end of file was already set,
1903 ** looks for another file to open.
1904 **
1905 ** @param [u] buff [AjPFilebuff] Buffered input file.
1906 ** @param [w] Pdest [AjPStr*] Buffer to hold results.
1907 ** @param [w] Ppos [ajlong*] File position before the read.
1908 ** @return [AjBool] ajTrue if data was read.
1909 **
1910 ** @release 6.0.0
1911 ** @@
1912 ******************************************************************************/
1913 
ajBuffreadLinePos(AjPFilebuff buff,AjPStr * Pdest,ajlong * Ppos)1914 AjBool ajBuffreadLinePos(AjPFilebuff buff, AjPStr* Pdest, ajlong* Ppos)
1915 {
1916     AjBool ok;
1917 
1918     /* read from the buffer if it is not empty */
1919 
1920     *Ppos = 0;
1921 
1922     if(buff->Pos < buff->Size)
1923     {
1924 	ajStrAssignS(Pdest, buff->Curr->Line);
1925 	*Ppos = buff->Curr->Fpos;
1926 	buff->Prev = buff->Curr;
1927 	buff->Curr = buff->Curr->Next;
1928 	buff->Pos++;
1929 
1930 	return ajTrue;
1931     }
1932 
1933     /* file has been closed */
1934     if(!buff->File->Handle)
1935 	return ajFalse;
1936 
1937     /* buffer used up - try reading from the file */
1938 
1939     ok = ajReadlinePos(buff->File, Pdest, &buff->Fpos);
1940 
1941     if(!ok)
1942     {
1943 	if(buff->File->End)
1944 	{
1945 	    if(buff->Size)
1946 	    {
1947 		/* we have data in the buffer - fail */
1948 		ajDebug("End of file - data in buffer - return ajFalse\n");
1949 		return ajFalse;
1950 	    }
1951 	    else
1952 	    {
1953 		/* buffer clear - try another file */
1954 		if(ajFileReopenNext(buff->File))
1955 		{
1956 		    /* OK - read the new file */
1957 		    ok = ajBuffreadLinePos(buff, Pdest, Ppos);
1958 		    ajDebug("End of file - trying next file ok: %B "
1959 			    "fpos: %Ld %Ld\n",
1960 			    ok, *Ppos, buff->Fpos);
1961 
1962 		    return ok;
1963 		}
1964 		else
1965 		{
1966 		    /* no new file, fail again */
1967 		    ajDebug("End of file - no new file to read - "
1968 			    "return ajFalse\n");
1969 
1970 		    return ajFalse;
1971 		}
1972 	    }
1973 	}
1974 	else
1975         {
1976 	    ajWarn("Error reading from file '%S'",
1977 		    ajFileGetNameS(buff->File));
1978             return ajFalse;
1979         }
1980     }
1981 
1982     if(buff->Nobuff)
1983     {
1984 	*Ppos = buff->Fpos;
1985 	/*ajDebug("ajBuffreadLinePos unbuffered fpos: %Ld\n", *Ppos);*/
1986 
1987 	return ajTrue;
1988     }
1989 
1990     filebuffLineAdd(buff, *Pdest);
1991     *Ppos = buff->Fpos;
1992 
1993     return ajTrue;
1994 }
1995 
1996 
1997 
1998 
1999 /* @func ajBuffreadLinePosStore ***********************************************
2000 **
2001 ** Reads a line from a buffered file. Also appends the line to
2002 ** a given string if the append flag is true. A double NULL character
2003 ** is added afterwards. If the buffer has data, reads from the
2004 ** buffer. If the buffer is exhausted, reads from the file. If the file is
2005 ** exhausted, sets end of file and returns. If end of file was already set,
2006 ** looks for another file to open.
2007 **
2008 ** @param [u] buff [AjPFilebuff] Buffered input file.
2009 ** @param [w] Pdest [AjPStr*] Buffer to hold results.
2010 ** @param [w] Ppos [ajlong*] File position before the read.
2011 ** @param [r] dostore [AjBool] append if true
2012 ** @param [w] Pstore [AjPStr*] string to append to
2013 ** @return [AjBool] ajTrue if data was read.
2014 ** @category modify [AjPFilebuff] Reads a line from a buffered file
2015 **                                with append.
2016 **
2017 ** @release 6.0.0
2018 ** @@
2019 ******************************************************************************/
2020 
ajBuffreadLinePosStore(AjPFilebuff buff,AjPStr * Pdest,ajlong * Ppos,AjBool dostore,AjPStr * Pstore)2021 AjBool ajBuffreadLinePosStore(AjPFilebuff buff, AjPStr* Pdest, ajlong* Ppos,
2022                               AjBool dostore, AjPStr *Pstore)
2023 {
2024     AjBool ret;
2025 
2026     ret =  ajBuffreadLinePos(buff, Pdest, Ppos);
2027 
2028     if(dostore && ret)
2029     {
2030 	ajDebug("ajBuffreadLinePosStore:\n%S", *Pdest);
2031 	ajStrAppendS(Pstore,*Pdest);
2032     }
2033 
2034     return ret;
2035 }
2036 
2037 
2038 
2039 
2040 /* @func ajBuffreadLineStore **************************************************
2041 **
2042 ** Reads a line from a buffered file. Also appends the line to
2043 ** a given string if the append flag is true. A double NULL character
2044 ** is added afterwards. If the buffer has data, reads from the
2045 ** buffer. If the buffer is exhausted, reads from the file. If the file is
2046 ** exhausted, sets end of file and returns. If end of file was already set,
2047 ** looks for another file to open.
2048 **
2049 ** @param [u] buff [AjPFilebuff] Buffered input file.
2050 ** @param [w] Pdest [AjPStr*] Buffer to hold results.
2051 ** @param [r] dostore [AjBool] append if true
2052 ** @param [w] Pstore[AjPStr*] string to append to
2053 ** @return [AjBool] ajTrue if data was read.
2054 ** @category modify [AjPFilebuff] Reads a line from a buffered file
2055 **                                with append.
2056 **
2057 ** @release 6.0.0
2058 ** @@
2059 ******************************************************************************/
2060 
ajBuffreadLineStore(AjPFilebuff buff,AjPStr * Pdest,AjBool dostore,AjPStr * Pstore)2061 AjBool ajBuffreadLineStore(AjPFilebuff buff, AjPStr* Pdest,
2062                            AjBool dostore, AjPStr *Pstore)
2063 {
2064     ajlong fpos = 0;
2065     AjBool ret;
2066 
2067     ret =  ajBuffreadLinePos(buff, Pdest, &fpos);
2068 
2069     if(dostore && ret)
2070     {
2071 	ajDebug("ajBuffreadLineStore: '%S'", *Pdest);
2072 	ajStrAppendS(Pstore,*Pdest);
2073     }
2074 
2075     return ret;
2076 }
2077 
2078 
2079 
2080 
2081 /* @func ajBuffreadLineTrim ***************************************************
2082 **
2083 ** Reads a line from a buffered file. If the buffer has data, reads from the
2084 ** buffer. If the buffer is exhausted, reads from the file. If the file is
2085 ** exhausted, sets end of file and returns. If end of file was already set,
2086 ** looks for another file to open.
2087 **
2088 ** @param [u] buff [AjPFilebuff] Buffered input file.
2089 ** @param [w] Pdest [AjPStr*] Buffer to hold results.
2090 ** @return [AjBool] ajTrue if data was read.
2091 ** @category modify [AjPFilebuff] Reads a line from a buffered file.
2092 **
2093 ** @release 6.0.0
2094 ** @@
2095 ******************************************************************************/
2096 
ajBuffreadLineTrim(AjPFilebuff buff,AjPStr * Pdest)2097 AjBool ajBuffreadLineTrim(AjPFilebuff buff, AjPStr* Pdest)
2098 {
2099     AjBool ret;
2100     ajlong fpos = 0;
2101 
2102     ret = ajBuffreadLinePos(buff, Pdest, &fpos);
2103 
2104     /* trim any trailing newline */
2105 
2106     /*ajDebug("Remove carriage-return characters from PC-style files\n");*/
2107     if(ajStrGetCharLast(*Pdest) == '\n')
2108 	ajStrCutEnd(Pdest, 1);
2109 
2110     /* PC files have \r\n Macintosh files have just \r : this fixes both */
2111     if(ajStrGetCharLast(*Pdest) == '\r')
2112 	ajStrCutEnd(Pdest, 1);
2113 
2114     return ret;
2115 }
2116 
2117 
2118 
2119 
2120 /* @funcstatic filebuffLineAdd ************************************************
2121 **
2122 ** Appends a line to a buffer.
2123 **
2124 ** @param [u] buff [AjPFilebuff] File buffer
2125 ** @param [r] line [const AjPStr] Line
2126 ** @return [void]
2127 **
2128 ** @release 6.0.0
2129 ******************************************************************************/
2130 
filebuffLineAdd(AjPFilebuff buff,const AjPStr line)2131 static void filebuffLineAdd(AjPFilebuff buff, const AjPStr line)
2132 {
2133     /* ajDebug("fileBuffLineAdd '%S'\n", line);*/
2134     if(buff->Freelines)
2135     {
2136 	if(!buff->Lines)
2137 	{
2138 	    /* Need to set first line in list */
2139 	    buff->Lines = buff->Freelines;
2140 	}
2141 	else
2142 	    buff->Last->Next = buff->Freelines;
2143 
2144 	buff->Last = buff->Freelines;
2145 	buff->Freelines = buff->Freelines->Next;
2146 
2147 	if(!buff->Freelines)
2148 	{
2149 	    /* Free list now empty */
2150 	    buff->Freelast = NULL;
2151 	}
2152     }
2153     else
2154     {
2155 	/* No Free list, make a new string */
2156 	if(!buff->Lines)
2157 	    buff->Lines = AJNEW0(buff->Last);
2158 	else
2159 	    buff->Last = AJNEW0(buff->Last->Next);
2160     }
2161 
2162     ajStrAssignS(&buff->Last->Line, line);
2163     buff->Prev = buff->Curr;
2164     buff->Curr = buff->Last;
2165     buff->Last->Next = NULL;
2166     buff->Last->Fpos = buff->Fpos;
2167     buff->Pos++;
2168     buff->Size++;
2169 
2170     return;
2171 }
2172 
2173 
2174 
2175 
2176 #ifdef AJ_COMPILE_DEPRECATED_BOOK
2177 #endif
2178 
2179 
2180 
2181 
2182 #ifdef AJ_COMPILE_DEPRECATED
2183 /* @obsolete ajFileGets
2184 ** @rename ajReadline
2185 */
ajFileGets(AjPFile thys,AjPStr * pdest)2186 __deprecated AjBool ajFileGets(AjPFile thys, AjPStr* pdest)
2187 {
2188     return ajReadline(thys, pdest);
2189 }
2190 
2191 
2192 
2193 
2194 /* @obsolete ajFileReadAppend
2195 ** @rename ajReadlineAppend
2196 */
ajFileReadAppend(AjPFile thys,AjPStr * pbuff)2197 __deprecated AjBool ajFileReadAppend(AjPFile thys, AjPStr* pbuff)
2198 {
2199     return ajReadlineAppend(thys, pbuff);
2200 }
2201 
2202 
2203 
2204 
2205 /* @obsolete ajFileGetsL
2206 ** @rename ajReadlinePos
2207 */
ajFileGetsL(AjPFile thys,AjPStr * pdest,ajlong * fpos)2208 __deprecated AjBool ajFileGetsL(AjPFile thys, AjPStr* pdest, ajlong* fpos)
2209 {
2210     return ajReadlinePos(thys, pdest, fpos);
2211 }
2212 
2213 
2214 
2215 
2216 /* @obsolete ajFileGetsTrim
2217 ** @rename ajReadlineTrim
2218 */
ajFileGetsTrim(AjPFile thys,AjPStr * pdest)2219 __deprecated AjBool ajFileGetsTrim(AjPFile thys, AjPStr* pdest)
2220 {
2221     ajlong fpos=0;
2222 
2223     return ajReadlineTrimPos(thys, pdest, &fpos);
2224 }
2225 
2226 
2227 
2228 
2229 /* @obsolete ajFileReadLine
2230 ** @rename ajReadlineTrim
2231 */
ajFileReadLine(AjPFile thys,AjPStr * pdest)2232 __deprecated AjBool ajFileReadLine(AjPFile thys, AjPStr* pdest)
2233 {
2234     ajlong fpos=0;
2235 
2236     return ajReadlineTrimPos(thys, pdest, &fpos);
2237 }
2238 
2239 
2240 
2241 
2242 /* @obsolete ajFileGetsTrimL
2243 ** @rename ajReadlineTrimPos
2244 */
ajFileGetsTrimL(AjPFile thys,AjPStr * pdest,ajlong * fpos)2245 __deprecated AjBool ajFileGetsTrimL(AjPFile thys, AjPStr* pdest, ajlong* fpos)
2246 {
2247     return ajReadlineTrimPos(thys, pdest, fpos);
2248 }
2249 
2250 
2251 
2252 
2253 /* @obsolete ajFileRead
2254 ** @replace ajReadbinBinary (1,2,3,4/4,3,2,1)
2255 */
ajFileRead(void * ptr,size_t element_size,size_t count,AjPFile file)2256 __deprecated size_t ajFileRead(void* ptr, size_t element_size, size_t count,
2257 		  AjPFile file)
2258 {
2259     return ajReadbinBinary(file, count, element_size, ptr);
2260 }
2261 
2262 
2263 
2264 
2265 /* @obsolete ajFileOutHeader
2266 ** @remove Not used
2267 */
ajFileOutHeader(AjPFile file)2268 __deprecated void ajFileOutHeader(AjPFile file)
2269 {
2270     ajFmtPrintF(file, "Standard output header ...\n");
2271 
2272     return;
2273 }
2274 
2275 
2276 
2277 
2278 /* @obsolete ajFileWrite
2279 ** @replace ajWritebinBinary (1,2,3,4/1,4,3,2)
2280 */
ajFileWrite(AjPFile file,const void * ptr,size_t element_size,size_t count)2281 __deprecated size_t ajFileWrite(AjPFile file, const void* ptr,
2282 		   size_t element_size, size_t count)
2283 {
2284     return ajWritebinBinary(file,count,element_size,ptr);
2285 }
2286 
2287 
2288 
2289 
2290 /* @obsolete ajFileWriteByte
2291 ** @rename ajWritebinByte
2292 */
ajFileWriteByte(AjPFile thys,char ch)2293 __deprecated ajint ajFileWriteByte(AjPFile thys, char ch)
2294 {
2295     return ajWritebinByte(thys, ch);
2296 }
2297 
2298 
2299 
2300 
2301 /* @obsolete ajFileWriteInt2
2302 ** @rename ajWritebinInt2
2303 */
ajFileWriteInt2(AjPFile thys,ajshort i)2304 __deprecated ajint ajFileWriteInt2(AjPFile thys, ajshort i)
2305 {
2306     return ajWritebinInt2(thys, i);
2307 }
2308 
2309 
2310 
2311 
2312 /* @obsolete ajFileWriteInt4
2313 ** @rename ajWritebinInt4
2314 */
ajFileWriteInt4(AjPFile thys,ajint i)2315 __deprecated ajint ajFileWriteInt4(AjPFile thys, ajint i)
2316 {
2317     return ajWritebinInt4(thys, i);
2318 }
2319 
2320 
2321 
2322 
2323 /* @obsolete ajFileWriteStr
2324 ** @rename ajWritebinStr
2325 */
ajFileWriteStr(AjPFile thys,const AjPStr str,ajuint len)2326 __deprecated ajint ajFileWriteStr(AjPFile thys, const AjPStr str, ajuint len)
2327 {
2328     return ajWritebinStr(thys, str, len);
2329 }
2330 
2331 
2332 
2333 
2334 /* @obsolete ajFileBuffGet
2335 ** @rename ajBuffreadLine
2336 */
ajFileBuffGet(AjPFilebuff thys,AjPStr * pdest)2337 __deprecated AjBool ajFileBuffGet(AjPFilebuff thys, AjPStr* pdest)
2338 {
2339     return ajBuffreadLine(thys, pdest);
2340 }
2341 
2342 
2343 
2344 
2345 /* @obsolete ajFileBuffGetL
2346 ** @rename ajBuffreadLinePos
2347 */
ajFileBuffGetL(AjPFilebuff buff,AjPStr * pdest,ajlong * fpos)2348 __deprecated AjBool ajFileBuffGetL(AjPFilebuff buff, AjPStr* pdest,
2349                                    ajlong* fpos)
2350 {
2351     return ajBuffreadLinePos(buff, pdest, fpos);
2352 }
2353 
2354 
2355 
2356 
2357 /* @obsolete ajFileBuffGetStoreL
2358 ** @rename ajBuffreadLinePosStore
2359 */
ajFileBuffGetStoreL(AjPFilebuff thys,AjPStr * pdest,ajlong * fpos,AjBool store,AjPStr * astr)2360 __deprecated AjBool ajFileBuffGetStoreL(AjPFilebuff thys, AjPStr* pdest,
2361 			   ajlong* fpos,
2362 			   AjBool store, AjPStr *astr)
2363 {
2364     return ajBuffreadLinePosStore(thys, pdest, fpos, store, astr);
2365 }
2366 
2367 
2368 
2369 
2370 /* @obsolete ajFileBuffGetStore
2371 ** @rename ajBuffreadLineStore
2372 */
ajFileBuffGetStore(AjPFilebuff thys,AjPStr * pdest,AjBool store,AjPStr * astr)2373 __deprecated AjBool ajFileBuffGetStore(AjPFilebuff thys, AjPStr* pdest,
2374 			  AjBool store, AjPStr *astr)
2375 {
2376     return ajBuffreadLineStore(thys, pdest, store, astr);
2377 }
2378 
2379 
2380 
2381 
2382 /* @obsolete ajFileBuffGetTrim
2383 ** @rename ajBuffreadLineTrim
2384 */
ajFileBuffGetTrim(AjPFilebuff thys,AjPStr * pdest)2385 __deprecated AjBool ajFileBuffGetTrim(AjPFilebuff thys, AjPStr* pdest)
2386 {
2387     return ajBuffreadLineTrim(thys, pdest);
2388 }
2389 #endif
2390