OpenCOBOL 1.1pre-rel
fileio.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2002-2009 Keisuke Nishida
00003  * Copyright (C) 2007-2009 Roger While
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public License
00007  * as published by the Free Software Foundation; either version 2.1,
00008  * or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; see the file COPYING.LIB.  If
00017  * not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor
00018  * Boston, MA 02110-1301 USA
00019  */
00020 
00021 #ifndef COB_FILEIO_H
00022 #define COB_FILEIO_H
00023 
00024 #include <libcob/common.h>
00025 
00026 /* File version */
00027 #define COB_FILE_VERSION        0
00028 
00029 #define COB_EQ                  1       /* x == y */
00030 #define COB_LT                  2       /* x <  y */
00031 #define COB_LE                  3       /* x <= y */
00032 #define COB_GT                  4       /* x >  y */
00033 #define COB_GE                  5       /* x >= y */
00034 #define COB_NE                  6       /* x != y */
00035 
00036 #define COB_ASCENDING           0
00037 #define COB_DESCENDING          1
00038 
00039 #define COB_FILE_MODE           0644
00040 
00041 /* Organization */
00042 
00043 #define COB_ORG_SEQUENTIAL      0
00044 #define COB_ORG_LINE_SEQUENTIAL 1
00045 #define COB_ORG_RELATIVE        2
00046 #define COB_ORG_INDEXED         3
00047 #define COB_ORG_SORT            4
00048 #define COB_ORG_MAX             5
00049 
00050 /* Access mode */
00051 
00052 #define COB_ACCESS_SEQUENTIAL   1
00053 #define COB_ACCESS_DYNAMIC      2
00054 #define COB_ACCESS_RANDOM       3
00055 
00056 /* SELECT features */
00057 
00058 #define COB_SELECT_FILE_STATUS  0x01
00059 #define COB_SELECT_EXTERNAL     0x02
00060 #define COB_SELECT_LINAGE       0x04
00061 #define COB_SELECT_SPLITKEY     0x08
00062 
00063 /* Lock mode */
00064 
00065 #define COB_LOCK_EXCLUSIVE      1
00066 #define COB_LOCK_MANUAL         2
00067 #define COB_LOCK_AUTOMATIC      4
00068 #define COB_LOCK_MULTIPLE       8
00069 #define COB_LOCK_MASK           0x7
00070 
00071 /* Open mode */
00072 
00073 #define COB_OPEN_CLOSED         0
00074 #define COB_OPEN_INPUT          1
00075 #define COB_OPEN_OUTPUT         2
00076 #define COB_OPEN_I_O            3
00077 #define COB_OPEN_EXTEND         4
00078 #define COB_OPEN_LOCKED         5
00079 
00080 /* Close options */
00081 
00082 #define COB_CLOSE_NORMAL        0
00083 #define COB_CLOSE_LOCK          1
00084 #define COB_CLOSE_NO_REWIND     2
00085 #define COB_CLOSE_UNIT          3
00086 #define COB_CLOSE_UNIT_REMOVAL  4
00087 
00088 /* Write options */
00089 
00090 #define COB_WRITE_MASK          0x0000ffff
00091 #define COB_WRITE_LINES         0x00010000
00092 #define COB_WRITE_PAGE          0x00020000
00093 #define COB_WRITE_CHANNEL       0x00040000
00094 #define COB_WRITE_AFTER         0x00100000
00095 #define COB_WRITE_BEFORE        0x00200000
00096 #define COB_WRITE_EOP           0x00400000
00097 #define COB_WRITE_LOCK          0x00800000
00098 
00099 /* Read options */
00100 #define COB_READ_NEXT           0x01
00101 #define COB_READ_PREVIOUS       0x02
00102 #define COB_READ_FIRST          0x04
00103 #define COB_READ_LAST           0x08
00104 #define COB_READ_LOCK           0x10
00105 #define COB_READ_NO_LOCK        0x20
00106 #define COB_READ_KEPT_LOCK      0x40
00107 #define COB_READ_WAIT_LOCK      0x80
00108 #define COB_READ_IGNORE_LOCK    0x100
00109 
00110 /* I-O status */
00111 
00112 #define COB_STATUS_00_SUCCESS                   00
00113 #define COB_STATUS_02_SUCCESS_DUPLICATE         02
00114 #define COB_STATUS_04_SUCCESS_INCOMPLETE        04
00115 #define COB_STATUS_05_SUCCESS_OPTIONAL          05
00116 #define COB_STATUS_07_SUCCESS_NO_UNIT           07
00117 #define COB_STATUS_10_END_OF_FILE               10
00118 #define COB_STATUS_14_OUT_OF_KEY_RANGE          14
00119 #define COB_STATUS_21_KEY_INVALID               21
00120 #define COB_STATUS_22_KEY_EXISTS                22
00121 #define COB_STATUS_23_KEY_NOT_EXISTS            23
00122 #define COB_STATUS_30_PERMANENT_ERROR           30
00123 #define COB_STATUS_31_INCONSISTENT_FILENAME     31
00124 #define COB_STATUS_34_BOUNDARY_VIOLATION        34
00125 #define COB_STATUS_35_NOT_EXISTS                35
00126 #define COB_STATUS_37_PERMISSION_DENIED         37
00127 #define COB_STATUS_38_CLOSED_WITH_LOCK          38
00128 #define COB_STATUS_39_CONFLICT_ATTRIBUTE        39
00129 #define COB_STATUS_41_ALREADY_OPEN              41
00130 #define COB_STATUS_42_NOT_OPEN                  42
00131 #define COB_STATUS_43_READ_NOT_DONE             43
00132 #define COB_STATUS_44_RECORD_OVERFLOW           44
00133 #define COB_STATUS_46_READ_ERROR                46
00134 #define COB_STATUS_47_INPUT_DENIED              47
00135 #define COB_STATUS_48_OUTPUT_DENIED             48
00136 #define COB_STATUS_49_I_O_DENIED                49
00137 #define COB_STATUS_51_RECORD_LOCKED             51
00138 #define COB_STATUS_52_EOP                       52
00139 #define COB_STATUS_57_I_O_LINAGE                57
00140 #define COB_STATUS_61_FILE_SHARING              61
00141 #define COB_STATUS_91_NOT_AVAILABLE             91
00142 
00143 /* Special status */
00144 
00145 /* Need some value that does not conflict with errno for OPEN/LINAGE */
00146 #define COB_LINAGE_INVALID      16384
00147 /* Need value that does not conflict with errno 30 (EROFS) for OPEN */
00148 #define COB_NOT_CONFIGURED      32768
00149 
00150 /* File connector */
00151 
00152 struct cob_file_key {
00153         cob_field       *field; /* key field */
00154         int             flag;   /* WITH DUPLICATES (for RELATIVE/INDEXED) */
00155                                 /* ASCENDING/DESCENDING (for SORT) */
00156         size_t          offset; /* Offset of field */
00157 };
00158 
00159 struct linage_struct {
00160         cob_field               *linage;                /* LINAGE */
00161         cob_field               *linage_ctr;            /* LINAGE-COUNTER */
00162         cob_field               *latfoot;               /* LINAGE FOOTING */
00163         cob_field               *lattop;                /* LINAGE AT TOP */
00164         cob_field               *latbot;                /* LINAGE AT BOTTOM */
00165         int                     lin_lines;              /* Current Linage */
00166         int                     lin_foot;               /* Current Footage */
00167         int                     lin_top;                /* Current Top */
00168         int                     lin_bot;                /* Current Bottom */
00169 };
00170 
00171 typedef struct {
00172         const char              *select_name;           /* Name in SELECT */
00173         unsigned char           *file_status;           /* FILE STATUS */
00174         cob_field               *assign;                /* ASSIGN TO */
00175         cob_field               *record;                /* record area */
00176         cob_field               *record_size;           /* record size depending on */
00177         struct cob_file_key     *keys;                  /* RELATIVE/RECORD/SORT keys */
00178         void                    *file;                  /* file specific data pointer */
00179         void                    *linorkeyptr;           /* LINAGE pointer or SPLIT KEY */
00180         const unsigned char     *sort_collating;        /* SORT collating */
00181         void                    *extfh_ptr;             /* For EXTFH usage */
00182         size_t                  record_min;             /* record min size */
00183         size_t                  record_max;             /* record max size */
00184         size_t                  nkeys;                  /* the number of keys */
00185         char                    organization;           /* ORGANIZATION */
00186         char                    access_mode;            /* ACCESS MODE */
00187         char                    lock_mode;              /* LOCKMODE */
00188         char                    open_mode;              /* OPEN MODE */
00189         char                    flag_optional;          /* OPTIONAL */
00190         char                    last_open_mode;         /* open mode given by OPEN */
00191         char                    special;                /* Special file */
00192         char                    flag_nonexistent;       /* nonexistent file */
00193         char                    flag_end_of_file;       /* reached the end of file */
00194         char                    flag_begin_of_file;     /* reached beginning of file */
00195         char                    flag_first_read;        /* first READ after OPEN/START */
00196         char                    flag_read_done;         /* last READ successfully done */
00197         char                    flag_select_features;   /* SELECT features */
00198         char                    flag_needs_nl;          /* LS file needs NL at close */
00199         char                    flag_needs_top;         /* Linage needs top */
00200         char                    file_version;           /* File I/O version */
00201 } cob_file;
00202 
00203 /* File I-O functions */
00204 
00205 /* Struct cob_fileio_funcs
00206         (*open)         (file, filename, mode, sharing);
00207         (*close)        (file, opt);
00208         (*start)        (file, cond, key);
00209         (*read)         (file, key, read_opts);
00210         (*read next)    (file, read_opts);
00211         (*write)        (file, opt);
00212         (*rewrite)      (file, opt);
00213         (*delete)       (file);
00214 */
00215 
00216 struct cob_fileio_funcs {
00217         int     (*open)         (cob_file *, char *, const int, const int);
00218         int     (*close)        (cob_file *, const int);
00219         int     (*start)        (cob_file *, const int, cob_field *);
00220         int     (*read)         (cob_file *, cob_field *, int);
00221         int     (*read_next)    (cob_file *, int);
00222         int     (*write)        (cob_file *, const int);
00223         int     (*rewrite)      (cob_file *, const int);
00224         int     (*fdelete)      (cob_file *);
00225 };
00226 
00227 DLL_EXPIMP extern cob_file      *cob_error_file;
00228 
00229 extern void cob_default_error_handle    (void);
00230 
00231 extern void cob_open            (cob_file *, const int, const int, cob_field *);
00232 extern void cob_close           (cob_file *, const int, cob_field *);
00233 extern void cob_read            (cob_file *, cob_field *, cob_field *, int);
00234 extern void cob_write           (cob_file *, cob_field *, const int, cob_field *);
00235 extern void cob_rewrite         (cob_file *, cob_field *, const int, cob_field *);
00236 extern void cob_delete          (cob_file *, cob_field *);
00237 extern void cob_start           (cob_file *, const int, cob_field *, cob_field *);
00238 
00239 extern void cob_unlock_file     (cob_file *, cob_field *);
00240 extern void cob_commit          (void);
00241 extern void cob_rollback        (void);
00242 
00243 /* System routines */
00244 extern int CBL_OPEN_FILE        (unsigned char *, unsigned char *,
00245                                  unsigned char *, unsigned char *,
00246                                  unsigned char *);
00247 extern int CBL_CREATE_FILE      (unsigned char *, unsigned char *,
00248                                  unsigned char *, unsigned char *,
00249                                  unsigned char *);
00250 extern int CBL_READ_FILE        (unsigned char *, unsigned char *,
00251                                  unsigned char *, unsigned char *,
00252                                  unsigned char *);
00253 extern int CBL_WRITE_FILE       (unsigned char *, unsigned char *,
00254                                  unsigned char *, unsigned char *,
00255                                  unsigned char *);
00256 extern int CBL_CLOSE_FILE       (unsigned char *);
00257 extern int CBL_FLUSH_FILE       (unsigned char *);
00258 extern int CBL_DELETE_FILE      (unsigned char *);
00259 extern int CBL_COPY_FILE        (unsigned char *, unsigned char *);
00260 extern int CBL_CHECK_FILE_EXIST (unsigned char *, unsigned char *);
00261 extern int CBL_RENAME_FILE      (unsigned char *, unsigned char *);
00262 extern int CBL_GET_CURRENT_DIR  (const int, const int, unsigned char *);
00263 extern int CBL_CHANGE_DIR       (unsigned char *);
00264 extern int CBL_CREATE_DIR       (unsigned char *);
00265 extern int CBL_DELETE_DIR       (unsigned char *);
00266 extern int cob_acuw_chdir       (unsigned char *, unsigned char *);
00267 extern int cob_acuw_mkdir       (unsigned char *);
00268 extern int cob_acuw_copyfile    (unsigned char *, unsigned char *, unsigned char *);
00269 extern int cob_acuw_file_info   (unsigned char *, unsigned char *);
00270 extern int cob_acuw_file_delete (unsigned char *, unsigned char *);
00271 
00272 /* SORT */
00273 extern void     cob_file_sort_init      (cob_file *, const int,
00274                                          const unsigned char *,
00275                                          void *, cob_field *);
00276 extern void     cob_file_sort_init_key  (cob_file *, const int,
00277                                          cob_field *, size_t);
00278 extern void     cob_file_sort_close     (cob_file *);
00279 extern void     cob_file_sort_using     (cob_file *, cob_file *);
00280 extern void     cob_file_sort_giving    (cob_file *, const size_t, ...);
00281 extern void     cob_file_release        (cob_file *);
00282 extern void     cob_file_return         (cob_file *);
00283 
00284 #endif /* COB_FILEIO_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines