21 #include <sys/mount.h> /* for BLKGETSIZE */
24 void LSEEK(int fd
, off_t where
);
25 int LSEEK_(int fd
, off_t where
);
27 /*******************************************************************************/
29 /*******************************************************************************/
30 #define BIGGEST_COPYING (1 * 1024 * 1024)
31 #define BLOCK_SEARCH_SIZE (4 * 1024)
32 #define SECTOR_SIZE ((off_t) 512)
34 #define CTRL(c) ((c) & 0x1F)
36 #define ALT(c) ((c) | 0xa0)
37 #define DIE(M) { fprintf(stderr, M, progName); exit(1); }
38 #define FREE(p) if (p) free(p)
39 #define MIN(a, b) ((a) < (b) ? (a) : (b))
40 #define MAX(a, b) ((a) > (b) ? (a) : (b))
41 #define NORMAL A_NORMAL
42 #define MARKED A_REVERSE
43 #define MODIFIED A_BOLD
44 #define ATTRPRINTW(attr, a) do { if (oldattr != (attr)) attrset(attr), oldattr = (attr); printw a; } while (0)
45 #define MAXATTRPRINTW(attr, a) do { if (oldattr & (~(attr))) attrset(attr & oldattr), oldattr &= (attr); printw a; } while (0)
46 #define PRINTW(a) ATTRPRINTW(NORMAL, a)
48 #define getnstr(str, n) wgetnstr(stdscr, str, n)
52 /*******************************************************************************/
53 /* Configuration parameters */
54 /*******************************************************************************/
55 typedef enum { bySector
, maximized
, LAST
} modeType
;
57 int blocSize
, lineLength
, page
;
60 extern modeParams modes
[LAST
];
65 #define pressAnyKey "(press any key)"
68 /*******************************************************************************/
70 /*******************************************************************************/
71 typedef struct _typePage
{
72 struct _typePage
*next
;
80 /*******************************************************************************/
81 /* Global variables */
82 /*******************************************************************************/
84 extern off_t lastEditedLoc
, biggestLoc
, fileSize
;
85 extern off_t mark_min
, mark_max
, mark_set
;
86 extern off_t base
, oldbase
;
87 extern int normalSpaces
, cursor
, cursorOffset
, hexOrAscii
;
88 extern int cursor
, blocSize
, lineLength
, colsUsed
, page
;
89 extern int isReadOnly
, fd
, nbBytes
, oldcursor
, oldattr
, oldcursorOffset
;
90 extern int sizeCopyBuffer
, *bufferAttr
;
91 extern char *progName
, *fileName
, *baseName
;
92 extern unsigned char *buffer
, *copyBuffer
;
93 extern typePage
*edited
;
95 extern char *lastFindFile
, *lastYankToAFile
, *lastAskHexString
, *lastAskAsciiString
, *lastFillWithStringHexa
, *lastFillWithStringAscii
;
98 /*******************************************************************************/
99 /* Miscellaneous functions declaration */
100 /*******************************************************************************/
101 off_t
getfilesize(void);
102 int key_to_function(int key
);
105 int tryloc(off_t loc
);
109 int computeLineSize(void);
110 int computeCursorXCurrentPos(void);
111 int computeCursorXPos(int cursor
, int hexOrAscii
);
112 void updateMarked(void);
113 int ask_about_save(void);
114 int ask_about_save_and_redisplay(void);
115 void ask_about_save_and_quit(void);
117 void setToChar(int i
, unsigned char c
);
119 /*******************************************************************************/
120 /* Pages handling functions declaration */
121 /*******************************************************************************/
122 void discardEdited(void);
123 void addToEdited(off_t base
, int size
, unsigned char *vals
);
124 void removeFromEdited(off_t base
, int size
);
125 typePage
*newPage(off_t base
, int size
);
126 void freePage(typePage
*page
);
129 /*******************************************************************************/
130 /* Cursor manipulation function declarations */
131 /*******************************************************************************/
132 int move_cursor(off_t delta
);
133 int set_cursor(off_t loc
);
134 int move_base(off_t delta
);
135 int set_base(off_t loc
);
137 /*******************************************************************************/
138 /* Curses functions declaration */
139 /*******************************************************************************/
140 void initCurses(void);
141 void exitCurses(void);
143 void displayLine(int offset
, int max
);
144 void clr_line(int line
);
145 void displayCentered(char *msg
, int line
);
146 void displayOneLineMessage(char *msg
);
147 void displayTwoLineMessage(char *msg1
, char *msg2
);
148 void displayMessageAndWaitForKey(char *msg
);
149 int displayMessageAndGetString(char *msg
, char **last
, char *p
, int p_size
);
150 void ungetstr(char *s
);
151 int get_number(off_t
*i
);
154 /*******************************************************************************/
155 /* Search functions declaration */
156 /*******************************************************************************/
157 void search_forward(void);
158 void search_backward(void);
161 /*******************************************************************************/
162 /* Mark functions declaration */
163 /*******************************************************************************/
164 void markRegion(off_t a
, off_t b
);
165 void unmarkRegion(off_t a
, off_t b
);
166 void markSelectedRegion(void);
167 void unmarkAll(void);
169 void unmarkIt(int i
);
170 void copy_region(void);
172 void yank_to_a_file(void);
173 void fill_with_string(void);
176 /*******************************************************************************/
177 /* Small common functions declaration */
178 /*******************************************************************************/
179 int streq(const char *s1
, const char *s2
);
180 int strbeginswith(const char *a
, const char *prefix
);
181 int myceil(int a
, int b
);
182 off_t
myfloor(off_t a
, off_t b
);
183 int setLowBits(int p
, int val
);
184 int setHighBits(int p
, int val
);
185 char *strconcat3(char *a
, char *b
, char *c
);
186 int hexCharToInt(int c
);
188 char *mymemmem(char *a
, int sizea
, char *b
, int sizeb
);
189 char *mymemrmem(char *a
, int sizea
, char *b
, int sizeb
);
190 int is_file(char *name
);
191 int hexStringToBinString(char *p
, int *l
);
193 #endif /* HEXEDIT_H */