home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / xfitsvew.zip / XFITSview / textfile.h < prev    next >
C/C++ Source or Header  |  1995-12-19  |  4KB  |  86 lines

  1. /*  header file for TextFile (Unix/Xwindow) utilities */ 
  2. /*-----------------------------------------------------------------------
  3. *  Copyright (C) 1996
  4. *  Associated Universities, Inc. Washington DC, USA.
  5. *  This program is free software; you can redistribute it and/or
  6. *  modify it under the terms of the GNU General Public License as
  7. *  published by the Free Software Foundation; either version 2 of
  8. *  the License, or (at your option) any later version.
  9. *
  10. *  This program is distributed in the hope that it will be useful,
  11. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. *  GNU General Public License for more details.
  14. *-----------------------------------------------------------------------*/
  15.   
  16. #include <stdio.h>
  17.  
  18. #ifndef TEXTFILE_H 
  19. #define TEXTFILE_H 
  20. #define TEXTBUFFER_SIZE 4096  /* I/O buffer size */
  21.  
  22. /* argument is actually TextFilePtr */
  23. typedef void (*TextFileProc)(XPointer);
  24.  
  25. typedef struct {
  26. Widget w;                  /* Widget to attach Dialog boxes to */
  27. long InBuffer;             /* The number of characters in Buffer */ 
  28. long BufferPos;            /* Next character position in Buffer */
  29. TextFileProc OKfunc;       /* function to be called to process TextFile */
  30. TextFileProc CancelFunc;   /* function to be called if select file canceled
  31.                   or fails*/
  32. char *FileName;            /* file name */
  33. char *directory;           /* file directory */
  34. unsigned char Buffer[TEXTBUFFER_SIZE];/* I/O buffer */
  35. FILE *file;                /* file pointer for write */
  36. int  hFile;                /* file index for read */
  37. int  Good;                 /* file properly selected */
  38. int  HitEOF;               /* if 1 then read an EOF else 0 */
  39. int  State;                /* State=0=> not open, 1=> read, 2=write */
  40. int  FileType;             /* File type 0=unknown, 1=text, 2=FITS, 3=DOStext*/
  41. int  isGzip;               /* if true file is gzip compressed */
  42. int  chkGzip;              /* if true check for gzip compression next buffer */
  43. } TextFileInfo, *TextFilePtr;
  44.  
  45. /* Public file functions */ 
  46.  
  47. /* create/initialize TextFileInfo structure                               */
  48. /* w is a Widget for dialog boxes to be attached to                       */
  49. /* if non null filename and directory filled in                           */
  50. TextFilePtr TextFileMake (Widget w, char* filename, char* directory);
  51.  
  52. /* delete TextFileInfo structure                                          */
  53. /* if non null filename and directory filled in                           */
  54. void TextFileKill (TextFilePtr TFilePtr);
  55.  
  56. /* get file specification, fill in TextFileInfo, call specified function  */
  57. /* inout = 1 => input; 2=> output                                         */
  58. /* TFilePtr->Good indicated if file selected func called                  */
  59. void TextFileFind (int inout, TextFilePtr TFilePtr, TextFileProc OKfunc,
  60.            TextFileProc CancelFunc);
  61.   
  62. /* open text file                                                         */ 
  63. /* inout = 1 => input; 2=> output                                         */
  64. /* returns 1 if successful                                                */
  65. int TextFileOpen (TextFilePtr TFilePtr, int inout);
  66.   
  67. /* close file specified by TFilePtr                                       */ 
  68. /* returns 1 if successful                                                */ 
  69. int TextFileClose(TextFilePtr TFilePtr); 
  70.   
  71. /* Read a line of text from a file                                        */ 
  72. /* returns 1 if OK, 0 if failed, -1 -> HitEOF                             */ 
  73. /* maxchar is the maximum number of characters allowed in line            */
  74. int TextFileRead(TextFilePtr TFilePtr, char* line, int maxchar); 
  75.   
  76. /* Write a line of text to a file                                         */ 
  77. /* returns 1 if OK, 0 if failed                                           */ 
  78. int TextFileWrite(TextFilePtr TFilePtr, char* line); 
  79.   
  80. #endif /* TEXTFILE_H */ 
  81.   
  82.   
  83.   
  84.   
  85.   
  86.