remove line-end witespace noise
[rofl0r-hexedit0r.git] / hexedit.h
blob823972f68717908ea52aa0f9e89290b96ff2549c
1 #ifndef HEXEDIT_H
2 #define HEXEDIT_H
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include <curses.h>
13 #include <ctype.h>
14 #include <signal.h>
15 #include <sys/wait.h>
16 #include <errno.h>
17 #if HAVE_SYS_MOUNT_H
18 #include <sys/mount.h> /* for BLKGETSIZE */
19 #endif
21 void LSEEK(int fd, off_t where);
22 int LSEEK_(int fd, off_t where);
24 /*******************************************************************************/
25 /* Macros */
26 /*******************************************************************************/
27 #define BIGGEST_COPYING (1 * 1024 * 1024)
28 #define BLOCK_SEARCH_SIZE (4 * 1024)
29 #define SECTOR_SIZE ((off_t) 512)
30 #ifndef CTRL
31 #define CTRL(c) ((c) & 0x1F)
32 #endif
33 #define ALT(c) ((c) | 0xa0)
34 #define DIE(M) { fprintf(stderr, M, progName); exit(1); }
35 #define FREE(p) if (p) free(p)
36 #define MIN(a, b) ((a) < (b) ? (a) : (b))
37 #define MAX(a, b) ((a) > (b) ? (a) : (b))
38 #define NORMAL A_NORMAL
39 #define MARKED A_REVERSE
40 #define MODIFIED A_BOLD
41 #define ATTRPRINTW(attr, a) do { if (oldattr != (attr)) attrset(attr), oldattr = (attr); printw a; } while (0)
42 #define MAXATTRPRINTW(attr, a) do { if (oldattr & (~(attr))) attrset(attr & oldattr), oldattr &= (attr); printw a; } while (0)
43 #define PRINTW(a) ATTRPRINTW(NORMAL, a)
44 #ifndef getnstr
45 #define getnstr(str, n) wgetnstr(stdscr, str, n)
46 #endif
49 /*******************************************************************************/
50 /* Configuration parameters */
51 /*******************************************************************************/
52 typedef enum { bySector, maximized, LAST } modeType;
53 typedef struct {
54 int blocSize, lineLength, page;
55 } modeParams;
57 extern modeParams modes[LAST];
58 extern modeType mode;
59 extern int colored;
60 extern char *usage;
62 #define pressAnyKey "(press any key)"
65 /*******************************************************************************/
66 /* Pages handling */
67 /*******************************************************************************/
68 typedef struct _typePage {
69 struct _typePage *next;
71 off_t base;
72 int size;
73 unsigned char *vals;
74 } typePage;
77 /*******************************************************************************/
78 /* Global variables */
79 /*******************************************************************************/
81 extern off_t lastEditedLoc, biggestLoc, fileSize;
82 extern off_t mark_min, mark_max, mark_set;
83 extern off_t base, oldbase;
84 extern int normalSpaces, cursor, cursorOffset, hexOrAscii;
85 extern int cursor, blocSize, lineLength, colsUsed, page;
86 extern int isReadOnly, fd, nbBytes, oldcursor, oldattr, oldcursorOffset;
87 extern int sizeCopyBuffer, *bufferAttr;
88 extern char *progName, *fileName, *baseName;
89 extern unsigned char *buffer, *copyBuffer;
90 extern typePage *edited;
92 extern char *lastFindFile, *lastYankToAFile, *lastAskHexString, *lastAskAsciiString, *lastFillWithStringHexa, *lastFillWithStringAscii;
95 /*******************************************************************************/
96 /* Miscellaneous functions declaration */
97 /*******************************************************************************/
98 off_t getfilesize(void);
99 int key_to_function(int key);
100 void init(void);
101 void quit(void);
102 int tryloc(off_t loc);
103 void openFile(void);
104 void readFile(void);
105 int findFile(void);
106 int computeLineSize(void);
107 int computeCursorXCurrentPos(void);
108 int computeCursorXPos(int cursor, int hexOrAscii);
109 void updateMarked(void);
110 int ask_about_save(void);
111 int ask_about_save_and_redisplay(void);
112 void ask_about_save_and_quit(void);
113 int setTo(int c);
114 void setToChar(int i, unsigned char c);
116 /*******************************************************************************/
117 /* Pages handling functions declaration */
118 /*******************************************************************************/
119 void discardEdited(void);
120 void addToEdited(off_t base, int size, unsigned char *vals);
121 void removeFromEdited(off_t base, int size);
122 typePage *newPage(off_t base, int size);
123 void freePage(typePage *page);
126 /*******************************************************************************/
127 /* Cursor manipulation function declarations */
128 /*******************************************************************************/
129 int move_cursor(off_t delta);
130 int set_cursor(off_t loc);
131 int move_base(off_t delta);
132 int set_base(off_t loc);
134 /*******************************************************************************/
135 /* Curses functions declaration */
136 /*******************************************************************************/
137 void initCurses(void);
138 void exitCurses(void);
139 void display(void);
140 void displayLine(int offset, int max);
141 void clr_line(int line);
142 void displayCentered(char *msg, int line);
143 void displayOneLineMessage(char *msg);
144 void displayTwoLineMessage(char *msg1, char *msg2);
145 void displayMessageAndWaitForKey(char *msg);
146 int displayMessageAndGetString(char *msg, char **last, char *p, int p_size);
147 void ungetstr(char *s);
148 int get_number(off_t *i);
151 /*******************************************************************************/
152 /* Search functions declaration */
153 /*******************************************************************************/
154 void search_forward(void);
155 void search_backward(void);
158 /*******************************************************************************/
159 /* Mark functions declaration */
160 /*******************************************************************************/
161 void markRegion(off_t a, off_t b);
162 void unmarkRegion(off_t a, off_t b);
163 void markSelectedRegion(void);
164 void unmarkAll(void);
165 void markIt(int i);
166 void unmarkIt(int i);
167 void copy_region(void);
168 void yank(void);
169 void yank_to_a_file(void);
170 void fill_with_string(void);
173 /*******************************************************************************/
174 /* Small common functions declaration */
175 /*******************************************************************************/
176 int streq(const char *s1, const char *s2);
177 int strbeginswith(const char *a, const char *prefix);
178 int myceil(int a, int b);
179 off_t myfloor(off_t a, off_t b);
180 int setLowBits(int p, int val);
181 int setHighBits(int p, int val);
182 char *strconcat3(char *a, char *b, char *c);
183 int hexCharToInt(int c);
184 int not(int b);
185 #ifndef HAVE_MEMMEM
186 char *mymemmem(char *a, size_t sizea, char *b, size_t sizeb);
187 #else
188 #define mymemmem(a,b,c,d) memmem(a,b,c,d)
189 #endif
190 #ifndef HAVE_MEMRMEM
191 char *mymemrmem(char *a, size_t sizea, char *b, size_t sizeb);
192 #else
193 #define mymemrmem(a,b,c,d) memrmem(a,b,c,d)
194 #endif
195 int is_file(char *name);
196 int hexStringToBinString(char *p, size_t *l);
198 #endif /* HEXEDIT_H */