| 1 | /* ---------------------------------------------------------------- EASYFC.H */ |
|---|
| 2 | |
|---|
| 3 | /* ----------------------------------------------------------------- defines */ |
|---|
| 4 | #ifndef BOOLEAN |
|---|
| 5 | #define BOOLEAN int |
|---|
| 6 | #endif |
|---|
| 7 | |
|---|
| 8 | #ifndef TRUE |
|---|
| 9 | #define TRUE 1 |
|---|
| 10 | #endif |
|---|
| 11 | |
|---|
| 12 | #ifndef FALSE |
|---|
| 13 | #define FALSE 0 |
|---|
| 14 | #endif |
|---|
| 15 | |
|---|
| 16 | #ifndef O_TEXT |
|---|
| 17 | #define O_TEXT 0 |
|---|
| 18 | #endif |
|---|
| 19 | |
|---|
| 20 | #ifndef O_BINARY |
|---|
| 21 | #define O_BINARY 0 |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | /* File access modes used with open() and fcntl() */ |
|---|
| 25 | /* Copy of fcntl.h */ |
|---|
| 26 | #ifndef O_RDONLY |
|---|
| 27 | #define O_RDONLY 0000000 /* Open for reading only */ |
|---|
| 28 | #endif |
|---|
| 29 | #ifndef O_WRONLY |
|---|
| 30 | #define O_WRONLY 0000001 /* Open for writing only */ |
|---|
| 31 | #endif |
|---|
| 32 | #ifndef O_RDWR |
|---|
| 33 | #define O_RDWR 0000002 /* Open for reading or writing */ |
|---|
| 34 | #endif |
|---|
| 35 | #ifndef O_ACCMODE |
|---|
| 36 | #define O_ACCMODE 0000003 /* Mask for file access modes */ |
|---|
| 37 | #endif |
|---|
| 38 | |
|---|
| 39 | #ifndef O_DENYNONE |
|---|
| 40 | #define O_DENYNONE 0 |
|---|
| 41 | #endif |
|---|
| 42 | |
|---|
| 43 | #ifndef KBYTE |
|---|
| 44 | #define KBYTE 1024L |
|---|
| 45 | #endif |
|---|
| 46 | |
|---|
| 47 | #ifndef EFC_ERROR_INFO_MAX |
|---|
| 48 | #define EFC_ERROR_INFO_MAX 60 |
|---|
| 49 | #endif |
|---|
| 50 | /* ------------------------------------------------------------- enumaration */ |
|---|
| 51 | typedef enum { |
|---|
| 52 | FILE_ERROR_EMPTY, |
|---|
| 53 | FILE_ERROR_SIZE, |
|---|
| 54 | FILE_ERROR_OPEN, |
|---|
| 55 | FILE_ERROR_ALLOC, |
|---|
| 56 | FILE_ERROR_READ, |
|---|
| 57 | FILE_ERROR_LIST_QTT |
|---|
| 58 | } EFC_FILE_ERROR_LIST; /* file error */ |
|---|
| 59 | |
|---|
| 60 | typedef enum { |
|---|
| 61 | COPYFILE_ERROR_OK, |
|---|
| 62 | COPYFILE_ERROR_IN_OPEN, |
|---|
| 63 | COPYFILE_ERROR_OUT_OPEN, |
|---|
| 64 | COPYFILE_ERROR_LIST_QTT |
|---|
| 65 | } COPYFILE_ERROR; /* file copy error */ |
|---|
| 66 | |
|---|
| 67 | typedef enum { |
|---|
| 68 | NUMBERLIST_ERROR_OK, |
|---|
| 69 | NUMBERLIST_ERROR_ALLOC, |
|---|
| 70 | NUMBERLIST_ERROR_LIST_QTT |
|---|
| 71 | } EFC_NUMBERLIST_ERROR_LIST; /* number list error */ |
|---|
| 72 | /* --------------------------------------------------------------- structure */ |
|---|
| 73 | typedef struct { |
|---|
| 74 | int code; |
|---|
| 75 | char info[EFC_ERROR_INFO_MAX+1]; |
|---|
| 76 | } EFC_ERROR; /* error */ |
|---|
| 77 | |
|---|
| 78 | typedef struct { |
|---|
| 79 | char *text; |
|---|
| 80 | } EFC_LINE; |
|---|
| 81 | |
|---|
| 82 | typedef struct { |
|---|
| 83 | long qtt; |
|---|
| 84 | EFC_LINE *list; |
|---|
| 85 | } EFC_SPLIT_LINES; |
|---|
| 86 | |
|---|
| 87 | typedef struct { |
|---|
| 88 | long qtt; |
|---|
| 89 | long *list; |
|---|
| 90 | } EFC_NUMBER_LIST; |
|---|
| 91 | /* --------------------------------------------------------------- prototype */ |
|---|
| 92 | int efc_error (EFC_ERROR *err, |
|---|
| 93 | int error_code, |
|---|
| 94 | char *error_info); |
|---|
| 95 | long efc_filesize (int handle); |
|---|
| 96 | char *efc_filecontent (char *read_file, |
|---|
| 97 | long *qttbytes); |
|---|
| 98 | void *efc_free (void *buff); |
|---|
| 99 | void *efc_new (long mem_size); |
|---|
| 100 | long efc_split_lines (EFC_SPLIT_LINES *split_lines, |
|---|
| 101 | char *text); |
|---|
| 102 | long efc_split_lines_char (EFC_SPLIT_LINES *split_lines, |
|---|
| 103 | char *text, |
|---|
| 104 | char char_sep); |
|---|
| 105 | void efc_split_lines_free (EFC_SPLIT_LINES *split_lines); |
|---|
| 106 | long efc_numberList (EFC_ERROR *err, |
|---|
| 107 | EFC_NUMBER_LIST *numberList, |
|---|
| 108 | char *text); |
|---|
| 109 | void efc_numberListFree (EFC_NUMBER_LIST *numberList); |
|---|
| 110 | char *efc_std_filecontent (EFC_ERROR *err, |
|---|
| 111 | char *file_name); |
|---|
| 112 | char *efc_strrepl (char *old, |
|---|
| 113 | char *from); |
|---|
| 114 | char *efc_trim_right (char *buff); |
|---|
| 115 | COPYFILE_ERROR efc_copyFile(unsigned char *fileNameIn, |
|---|
| 116 | unsigned char *fileNameOut); |
|---|