remove another useless file
[rofl0r-hexedit0r.git] / hexedit.c
blobf339edbb1561b1251948253ed6171bb7c71c16e0
1 /* hexedit -- Hexadecimal Editor for Binary Files
2 Copyright (C) 1998 Pixel (Pascal Rigaux)
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
17 #include "hexedit.h"
20 /*******************************************************************************/
21 /* Global variables */
22 /*******************************************************************************/
23 INT lastEditedLoc, biggestLoc, fileSize;
24 INT mark_min, mark_max, mark_set;
25 INT base, oldbase;
26 int normalSpaces, cursor, cursorOffset, hexOrAscii;
27 int cursor, blocSize, lineLength, colsUsed, page;
28 int isReadOnly, fd, nbBytes, oldcursor, oldattr, oldcursorOffset;
29 int sizeCopyBuffer, *bufferAttr;
30 char *progName, *fileName, *baseName;
31 unsigned char *buffer, *copyBuffer;
32 typePage *edited;
34 char *lastFindFile = NULL, *lastYankToAFile = NULL, *lastAskHexString = NULL, *lastAskAsciiString = NULL, *lastFillWithStringHexa = NULL, *lastFillWithStringAscii = NULL;
37 modeParams modes[LAST] = {
38 { 8, 16, 256 },
39 { 4, 0, 0 },
41 modeType mode = maximized;
42 int colored = FALSE;
44 char * usage = "usage: %s [-s | --sector] [-m | --maximize]"
45 " [--nocolor] [-h | --help] filename\n";
48 /*******************************************************************************/
49 /* main */
50 /*******************************************************************************/
51 int main(int argc, char **argv)
53 progName = basename(argv[0]);
54 argv++; argc--;
55 colored = TRUE;
57 for (; argc > 0; argv++, argc--)
59 if (streq(*argv, "-s") || streq(*argv, "--sector"))
60 mode = bySector;
61 else if (streq(*argv, "-m") || streq(*argv, "--maximize"))
62 mode = maximized;
63 else if (streq(*argv, "--nocolor"))
64 colored = FALSE;
65 else if (streq(*argv, "--")) {
66 argv++; argc--;
67 break;
68 } else if (*argv[0] == '-')
69 DIE(usage)
70 else break;
72 if (argc > 1) DIE(usage);
74 init();
75 if (argc == 1) {
76 fileName = strdup(*argv);
77 openFile();
79 initCurses();
80 if (fileName == NULL) {
81 if (!findFile()) {
82 exitCurses();
83 DIE("%s: No such file\n");
85 openFile();
87 readFile();
88 do display();
89 while (key_to_function(getch()));
90 quit();
91 return 0; /* for no warning */
96 /*******************************************************************************/
97 /* other functions */
98 /*******************************************************************************/
99 void init(void)
101 page = 0; /* page == 0 means initCurses is not done */
102 normalSpaces = 3;
103 hexOrAscii = TRUE;
104 copyBuffer = NULL;
105 edited = NULL;
108 void quit(void)
110 exitCurses();
111 free(fileName);
112 free(buffer);
113 free(bufferAttr);
114 FREE(copyBuffer);
115 discardEdited();
116 FREE(lastFindFile); FREE(lastYankToAFile); FREE(lastAskHexString); FREE(lastAskAsciiString); FREE(lastFillWithStringHexa); FREE(lastFillWithStringAscii);
117 exit(0);