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