1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
|
/* hexer.h 8/19/1995
*/
/* Copyright (c) 1995,1996 Sascha Demetrio
* Copyright (c) 2009 Peter Pentchev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* If you modify any part of HEXER and resitribute it, you must add
* a notice to the `README' file and the modified source files containing
* information about the changes you made. I do not want to take
* credit or be blamed for your modifications.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* If you modify any part of HEXER and resitribute it in binary form,
* you must supply a `README' file containing information about the
* changes you made.
* 3. The name of the developer may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* HEXER WAS DEVELOPED BY SASCHA DEMETRIO.
* THIS SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
* THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
* NOT MAKE USE OF THIS WORK.
*
* DISCLAIMER:
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _HEXER_H_
#define _HEXER_H_
#include "config.h"
#include "defs.h"
#include <stdio.h>
#ifdef USE_STDARG
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#if HAVE_ALLOCA
#if NEED_ALLOCA_H
#include <alloca.h>
#endif
#else
char *alloca(size_t);
#endif
#define TIO_MAP 1
#define HE_REFRESH_MAX_PARTS 64
enum map_e { MAP_COMMAND = 1, MAP_VISUAL, MAP_INSERT, MAP_EXH };
struct he_refresh_s {
int flag;
int first[HE_REFRESH_MAX_PARTS];
int last[HE_REFRESH_MAX_PARTS];
int parts;
int message_f;
char message[HE_REFRESH_MAX_PARTS][256];
int messages;
int beep;
};
struct he_s {
Buffer *buffer;
char *buffer_name;
long position;
long screen_offset;
long begin_selection;
long end_selection;
int anchor_selection;
/* `anchor_selection == 0': the position is equal to `end_selection'
* `anchor_selection == 1': the position is equal to `begin_selection'
*/
long insert_position;
int text_mode;
int swapping;
/* `swapping == 0': no swapfile, all changes ar stored in memory.
* `swapping == 1': use the filestream `swapfile' for swapping.
*/
char *swapfile;
/* name of the swapfile */
union he_undo_u {
FILE *swapfile;
/* Filestream of the swapfile.
*/
struct he_command_s *list;
/* The first command in the undo list.
*/
} undo;
struct he_command_s *command;
/* Current command in the undo-list. Used if swapping is turned off.
*/
struct he_refresh_s refresh;
int read_only;
};
extern const struct he_refresh_s NO_REFRESH;
struct he_message_s {
struct he_message_s *next;
char *message;
int beep;
};
extern struct he_message_s *he_messages;
void
#if USE_STDARG
he_message( int beep, char *fmt, ... );
#else
he_message( );
#endif
void
he_refresh_part(struct he_s *hedit, long pos1, long pos2);
void
he_refresh_lines(struct he_s *hedit, int first, int last);
int
he_refresh_check(struct he_s *hedit);
#define he_refresh_all(hedit) ((void)he_refresh_part((hedit), 0, -1))
void
he_refresh_screen(const struct he_s *hedit);
int
he_update_screen(struct he_s *hedit);
struct he_command_s {
struct he_command_s *next_subcommand;
/* Multiple commands may be treatet as a single command, i.e. a relpace
* command is made up by an insert command and a delete command. Such
* a compound command is stored as a list of commands.
*/
struct he_command_s *next_command;
/* The next command in the undo list. This pointer is set only for
* the first command of a compound command. A null-value in the first
* command of a compound command indicates the end of the list.
* NOTE: For all subcommands that are not the first command in a compound
* command, `next_command' has to be set to zero.
*/
struct he_command_s *prev_command;
/* The previous command in the undo list. A null-value in the first
* command of a compound command indicates the beginning of the list.
* For all subcommands that are not the first command in a compound
* command, the value of `prev_command' is ignored.
*/
int type;
/* `type == 0': delete command; `type == 1': insert command.
*/
int again;
/* `again == 1': This command can be preformed again on a diffrent
* position in the file. When the command is repeated with the
* `he_again()' function, the position of every subcommand will be
* changed to the new position, thus the `again' flag should be set
* only if all subcommands perform on the same position in the file.
* `again == 0': This command can't be performed again on a diffrent
* position in the file.
*/
long position;
/* The poisition of the byte of the inserted or deleted data.
*/
long count;
/* The length of the buffer containing the inserted/deleted data.
*/
char *data;
/* A pointer to the inserted/deleted data.
*/
};
/* The format of the swap file is defined as:
* - The string "hexer <version>\n" (without the quotes), where
* <version> is the version number of `hedit'.
* - The full path and name of the file being edited, followed by a newline.
* - 4 zero bytes.
* - A list of commands, terminated by 4 zero bytes.
* Each command is stored as:
* - The number of subcommands stored as big-endian long (4 bytes).
* - One byte indicating if the command may be performed again on a
* diffrent position.
* 0: `again' flag cleared.
* 1: `again' flag set.
* - A list of subcommands.
* - The position of the first byte of the current entry. This allows
* reading backwards through the file.
* Each subcommand is stored as:
* - One byte indicating the type of the command:
* 0: delete command.
* 1: insert command.
* - The position in the file (big-endian long).
* - The number of bytes inserted/deleted (big-endian long).
* - The inserted/deleted data.
*/
void
he_free_command(struct he_command_s *command);
/* Free the memory allocated by command and all the following commands
* in the list.
*/
void
he_compound_comand(struct he_s *hedit, struct he_command_s *command);
void
he_subcommand(struct he_s *hedit,
int type, long position, long count, char *data);
/* Update the undo-list of `hedit' by inserting the given subcommand.
* The command is *not* performed by calling `he_subcommand()'.
* A sequence of subcommands must be terminated by calling
* `he_subcommand(hedit, -1, 0, 0, 0)'.
* NOTE: Iff the position for all subcommands is the same, the `again'
* flag will be set to 1.
*/
long
he_do_command(struct he_s *hedit, struct he_command_s *command);
/* Perform the compound command `command'. The return value is the
* position of the last change made.
*/
/* buffers
*/
struct buffer_s {
struct buffer_s *next;
struct he_s *hedit;
char *path;
char *fullpath;
int loaded_f;
int visited_f;
};
extern const struct buffer_s NO_BUFFER;
extern char *alternate_buffer;
extern struct buffer_s *current_buffer;
extern char *he_pagerprg;
/* exh commands
*/
typedef char *(*exh_fn)(struct he_s *, char *, long, long);
struct exh_cmd_s {
char *cmd_name;
char cmd_char;
exh_fn cmd;
int whole_f;
/* `whole_f == 1': if no range is specified, the whole file is use. */
int expect;
/* `expect == 0': no completer available
* `expect == 1': expects a filename
* `expect == 2`: expects a buffername
* `expect == 3': expects a filename or a buffername
* `expect == 4': expects an option name
*/
};
#define HE_LINE(x) ((long)(x) >> 4)
int
he_open_buffer(char *name, char *path);
int
he_select_buffer(char *name);
int
he_alternate_buffer(void);
int
he_set_buffer_readonly(char *name);
/* Return values:
* -1: no buffer named `name'
* 0: ok
*/
int
he_buffer_readonly(char *name);
/* Return values:
* -1: no buffer named `name'
* 0: buffer is readwrite
* 1: buffer is readonly
*/
int
he_buffer_modified(char *name);
/* Return values:
* -1: no buffer named `name'
* 0: buffer saved
* 1: buffer modified
*/
int
he_close_buffer(char *name);
/* Close the buffer named `name'. If `name == 0', the current buffer
* is closed. The return value is 0 if all goes well, 1 if the named
* buffer doesn't exist and -1 if the `buffer_list' is empty.
*/
void
he_status_message(int verbose);
/* display name and size of the current buffer. if `verbose' is set,
* the current position is also displayed.
*/
void
he_select(struct he_s *hedit, long begin, long end);
int
he_select_buffer_(struct buffer_s *);
void
he_cancel_selection(struct he_s *hedit);
long
he_search(struct he_s *, char *, char *, int, int, int, long,
char **, long *, long *);
void
he_search_command(struct he_s *, char *, int);
char *
he_query_command(char *, char *, int);
int
#if USE_STDARG
he_query_yn( int dfl, char *fmt, ... );
#else
he_query_yn( );
#endif
int
he_mainloop(struct he_s *hedit);
int
hexer(void);
void hexer_init(void);
void hexer_version(void);
#endif
/* end of hexer.h */
/* VIM configuration: (do not delete this line)
*
* vim:bk:nodg:efm=%f\:%l\:%m:hid:icon:
* vim:sw=2:sm:textwidth=79:ul=1024:wrap:
*/
|