hexdiff-0.0.53/0000755000175000017500000000000011145070305013066 5ustar dolanordolanorhexdiff-0.0.53/fileinfo.c0000644000175000017500000000666511133161445015045 0ustar dolanordolanor/* * fileinfo.c * * Copyright: (c) 2005 Thierry Boudet * This program is free software; you can redistribute it and/or * modify it under the terms of the Do What The Fuck You Want To * Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/projects/COPYING.WTFPL for more details. */ #include #include #include #include #include #include #include #include #include #include "hexdiff.h" /*----------------------------------------------------------------*/ /* private vars of this module */ /*----------------------------------------------------------------*/ /* * this func need more "configurability" */ static void prtime(time_t t, char *pstr) { struct tm *ptm; int foo; ptm = gmtime(&t); foo = strftime(pstr, 99, "%Y-%m-%d %H:%M:%S", ptm); } /*----------------------------------------------------------------*/ #define W_FILEINFO 48 WINDOW * do_fileinfo(int fd, int ligne) { WINDOW * popup; int foo, lig, hpopup; struct stat stat_buf; char buffer[100]; struct passwd *pass; struct group *grp; if (config.ext_fileinfo) hpopup = 13; else hpopup = 12; popup = newwin(hpopup, W_FILEINFO, ligne, 15); if ( popup==NULL ) return NULL; bordure(popup); #if TRACE sprintf(buffer, " fileinfos fd %d ", fd); mvwaddstr(popup, 0, 10, buffer); #endif foo = fstat(fd, &stat_buf); if (foo==0) { lig = 2; sprintf(buffer, "dev: %ld", (long)(stat_buf.st_dev)); mvwaddstr(popup, lig, 2, buffer); sprintf(buffer, "inode: %ld", stat_buf.st_ino); mvwaddstr(popup, lig, 22, buffer); lig += 2; sprintf(buffer, "uid: %d", stat_buf.st_uid); mvwaddstr(popup, lig, 2, buffer); sprintf(buffer, "gid: %d", stat_buf.st_gid); mvwaddstr(popup, lig, 22, buffer); if (config.ext_fileinfo) { lig++; pass = getpwuid(stat_buf.st_uid); if (pass==NULL) strcpy(buffer, "unknow user"); else sprintf(buffer, "user: %s", pass->pw_name); mvwaddstr(popup, lig, 2, buffer); grp = getgrgid(stat_buf.st_gid); if (grp==NULL) strcpy(buffer, "unknow group"); else sprintf(buffer, "group: %s", grp->gr_name); mvwaddstr(popup, lig, 22, buffer); } lig+=2; /* Nov 2004: may be, here, we need a 'ls-like' display , with "-rwxr-x---" look'n'feel ? */ sprintf(buffer, "rwx: %05o", stat_buf.st_mode & 01777); mvwaddstr(popup, lig, 2, buffer); sprintf(buffer, "size: %ld", stat_buf.st_size); mvwaddstr(popup, lig, 22, buffer); lig+=2; /* we don't display the atime, because, after all, hexdiff _is_ reading the file :) */ prtime(stat_buf.st_mtime, buffer); mvwaddstr(popup, lig, 4, "mtime:"); mvwaddstr(popup, lig, 14, buffer); lig++; prtime(stat_buf.st_ctime, buffer); mvwaddstr(popup, lig, 4, "ctime:"); mvwaddstr(popup, lig, 14, buffer); } else { sprintf(buffer, "fstat error = %d", foo); mvwaddstr(popup, 6, 2, buffer); } wrefresh(popup); return popup; } /*----------------------------------------------------------------*/ int fileinfo(int fd, int ligne) { WINDOW * pop; pop = do_fileinfo(fd, ligne); getch(); delwin(pop); return 0; } /*----------------------------------------------------------------*/ int double_fileinfo(int fd1, int ligne1, int fd2, int ligne2) { WINDOW * pop1, * pop2; pop1 = do_fileinfo(fd1, ligne1); pop2 = do_fileinfo(fd2, ligne2); getch(); delwin(pop1); delwin(pop2); return 0; } /*----------------------------------------------------------------*/ hexdiff-0.0.53/hexdiff.h0000644000175000017500000000371011133162627014663 0ustar dolanordolanor/* * hexdiff.h : global header for hexdiff * * Copyright: (c) 2005 Thierry Boudet * This program is free software; you can redistribute it and/or * modify it under the terms of the Do What The Fuck You Want To * Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/projects/COPYING.WTFPL for more details. */ #include /* "#define VERSION" is now in the Makefile */ #define T_BUFF 4242 #define T_NOM 360 typedef struct { int fd; long taille; long offset; long lus; char nom[T_NOM+1]; /* buffer overflow ? */ unsigned char buffer[T_BUFF]; } Fichier; typedef struct { int nice_border; int show_8bits; char *language; int offsets_in_hex; int ext_fileinfo; int show_hidden; int sf_flag; int explique; /* not used */ int zoom; int asciiview; /* not used */ } configuration; /* * declaration of globals vars */ #ifdef MAIN #define EXTERN #else #define EXTERN extern #endif EXTERN Fichier f1, f2; EXTERN int fenetre_active; EXTERN configuration config; /* * macros de positionnement en hauteur */ #define HAUT ((LINES-3)/2) #define HAUT_1 1 #define BARRE_1 (HAUT_1+HAUT) #define HAUT_2 (HAUT_1+(HAUT)+1) #define BARRE_2 (HAUT_2+HAUT) /* * prototype des fonctions */ void barre_inverse(char c, int ligne); int ecrire_barres_fichiers(void); int fond_ecran(void); void about(void); void aide_cl(int flag); void bordure(WINDOW * w); void popup_aide(void); long saisir_un_long(char *txt); void version(void); int is_printable(int octet); int ouvre_fichier(char *nom); /* * file parse_rc.c */ #define HEXDIFF_RC ".hexdiffrc" int init_configuration(void); int lire_configuration(int flag); /* * file fileinfo.c */ int fileinfo(int fd, int ligne); int double_fileinfo(int, int, int, int); /* * file sel_file.c */ int select_new_file(char *, int, int); int select_set_opt(int flg); /* * file asciiview.c */ int asciiview(void); int octalview(void); /* not urgent */ hexdiff-0.0.53/memcheck.sh0000644000175000017500000000042510337125437015210 0ustar dolanordolanor#!/bin/sh # # seek for memory leaks # --------------------- # you need a recent version of http://www.valgrind.org/ # make hexdiff rm valgr-plop* valgrind --tool=memcheck --log-file=valgr-plop \ --leak-check=yes --show-reachable=yes \ ./hexdiff hexdiff.o fonctions.o hexdiff-0.0.53/Makefile0000644000175000017500000000227611145070305014535 0ustar dolanordolanor# # VISUEL HEXDIFF # -------------- # # http://tboudet.free.fr/hexdiff/ # # # if you define TRACE to a non zero value, you get a # lot of debugging trace on _stderr_ # CFLAGS+=-g -DVERSION=\"$(VERSION)\" -DTRACE=0 -ansi LDFLAGS+=-lncurses PREFIX=/usr/local VERSION=$(shell dirname $(PWD)/. | sed "s/^.*-//") PROJECT=hexdiff TARNAME=$(PROJECT)-$(VERSION).tar.gz EXEC=$(PROJECT) SRC=${wildcard *.c} OBJECTS=${SRC:.c=.o} FILES=$(shell cat MANIFEST) #hexdiff.c hexdiff.fr_FR.1 Makefile README TODO BUGS fonctions.c CHANGES \ # COPYING hexdiff.h parse_rc.c hexdiff.rc fileinfo.c sel_file.c \ # asciiview.c memcheck.sh all: ${EXEC} $(EXEC): $(OBJECTS) $(CC) -o $@ $^ $(LDFLAGS) %.o: %.c $(CC) -o $@ -c $< $(CFLAGS) install: ${EXEC} @echo "Stripping $(EXEC)..." @strip $(EXEC) @echo "Installing exec and man pages" @install -m 744 $(EXEC) $(PREFIX)/bin/ @mkdir -p $(PREFIX)/share/man/man1 @install -m 644 hexdiff.1 $(PREFIX)/share/man/man1 .PHONY: clean mrproper clean: @rm -f $(OBJECTS) mrproper: clean @rm -f $(EXEC) tarball: mrproper $(FILES) @echo "Creating $(TARNAME)" tar -C .. -czvf ../$(TARNAME) hexdiff-$(VERSION) date >> tarball lines: $(FILES) wc $(FILES) | sort -n hexdiff-0.0.53/BUGS0000644000175000017500000000061110153151560013550 0ustar dolanordolanor VISUAL HEXDIFF: les nombreux bugs: ----------------------------------------------------------- tous les écrans n'ont pas 80 colonnes... la page de man est mal écrite et pas synchrone avec le code. la fonction de saisie d'un "long" est codée par un goret. le sélecteur de fichier ne permet pas de changer de répertoire. ----------------------------------------------------------- hexdiff-0.0.53/MANIFEST0000644000175000017500000000025411145070331014217 0ustar dolanordolanorasciiview.c BUGS CHANGES COPYING fileinfo.c fonctions.c hexdiff.c hexdiff.fr.1 hexdiff.h hexdiff.rc Makefile MANIFEST memcheck.sh parse_rc.c README sel_file.c tarball TODO hexdiff-0.0.53/asciiview.c0000644000175000017500000001121211133161506015213 0ustar dolanordolanor/* * asciiview.c * * Copyright: (c) 2005 Thierry Boudet * This program is free software; you can redistribute it and/or * modify it under the terms of the Do What The Fuck You Want To * Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/projects/COPYING.WTFPL for more details. */ #include #include #include "hexdiff.h" /*----------------------------------------------------------------*/ static void av_sauve_contexte(void) { /* code to be defined ? */ } /*----------------------------------------------------------------*/ static void av_restaure_contexte(void) { /* code to be defined ? */ } /*----------------------------------------------------------------*/ static char * ascii_name(int code) { static char static_buffer[20]; /* XXX this big switch must be audited.... */ switch (code) { case 0: return "NUL"; case 1: return "SOH ^a"; case 2: return "STX ^b"; case 3: return "ETX ^c"; case 4: return "EOT ^d"; case 5: return "ENQ ^e"; case 6: return "ACQ ^f"; case 7: return "BEL ^g"; case 8: return "BS ^h"; case 9: return "HT ^i"; case 10: return "LF ^j"; case 11: return "VT ^k"; case 12: return "FF ^l"; case 13: return "CR ^m"; case 14: return "SO ^n"; case 15: return "SI ^o"; case 16: return "DLE ^p"; case 17: return "DC1 ^q"; case 18: return "DC2 ^r"; case 19: return "DC3 ^s"; case 20: return "DC4 ^t"; case 21: return "NAK ^u"; case 22: return "SYN ^v"; case 23: return "ETB ^w"; case 24: return "CAN ^x"; case 25: return "EM ^y"; case 26: return "SUB ^z"; case 27: return "ESC"; case 28: return "FS "; case 29: return "GS "; case 30: return "RS "; case 31: return "US "; case 32: return "SPACE"; case 127: return "DEL"; } if (code < 128) { sprintf(static_buffer, "'%c'", code); return static_buffer; } /* may be for code > 127, we can put the "html" code &blabla; ? */ return ""; } /*----------------------------------------------------------------*/ #define ASCV_I2LIG(idx) ((idx)>>6) #define ASCV_I2COL(idx) ((idx)&63) static int av_affiche(Fichier *fic, WINDOW *pop, int clig, int ccol) { int foo, lig, col, car; char chaine[100]; long depl; unsigned char octet; wstandout(pop); for (foo=1; foo<65; foo++) mvwaddch(pop, 1, foo, ' '); mvwaddstr(pop, 1, 2, fic->nom); depl = (clig*64)+ccol; octet = fic->buffer[depl]; sprintf(chaine, "%7ld : %3d 0x%02x 0%03o", fic->offset+depl, octet, octet, octet); mvwaddstr(pop, 18, 1, chaine); mvwaddstr(pop, 18, 33, " "); mvwaddstr(pop, 18, 33, ascii_name(fic->buffer[depl])); wstandend(pop); for (foo=0; foo<16*64; foo++) { lig = ASCV_I2LIG(foo); col = ASCV_I2COL(foo); car = fic->buffer[foo]; car = is_printable(car) ? car : ' '; if (clig==lig && ccol==col) wstandout(pop); mvwaddch(pop, lig+2, col+1, car); if (clig==lig && ccol==col) wstandend(pop); } /* put the cursor at the current location */ /* this was a really bad idea for Xterm users, because * current pos char was written in "standout", and the * text cursor of xterm re-reverse it. * XXX wmove(pop, clig+2, ccol+1); */ wmove(pop,1,64); wrefresh(pop); return 0; } /*----------------------------------------------------------------*/ /* new: 2004 Nov. * still in developement. */ int asciiview(void) { WINDOW * popup; int foo, key, flag_exit; int clig, ccol; /* position du curseur */ Fichier * fic; av_sauve_contexte(); popup = newwin(21, 66, 3, 5); bordure(popup); wstandout(popup); for (foo=1; foo<65; foo++) mvwaddch(popup, 19, foo, ' '); mvwaddstr(popup, 19, 1, " 'Q' quit, see other file"); for (foo=1; foo<65; foo++) mvwaddch(popup, 18, foo, ' '); wstandend(popup); wrefresh(popup); flag_exit = 0; clig = ccol = 0; do { if (fenetre_active==0) fic = &f1; else fic = &f2; av_affiche(fic, popup, clig, ccol); key = getch(); switch (key) { case 'q': case 'Q': flag_exit = 1; break; case '\t': fenetre_active ^= 1; break; case KEY_UP: if (clig>0) clig--; break; case KEY_DOWN: if (clig<15) clig++; break; case KEY_LEFT: if (ccol>0) ccol--; else if (clig>0) { /* go to the previous line */ ccol=63; clig--; } break; case KEY_RIGHT: if (ccol<63) ccol++; else if (clig<15) { /* go to the next line */ ccol=0; clig++; } break; case KEY_HOME: ccol = clig = 0; break; case KEY_END: ccol = 63; clig = 15; break; default: flash(); break; } } while ( ! flag_exit ); delwin(popup); av_restaure_contexte(); return 42; } /*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/ hexdiff-0.0.53/hexdiff.fr.10000644000175000017500000000754211144777032015215 0ustar dolanordolanor.TH HexDiff 1 "November 1905" "Divers Un*ces" "TontonTh tools" .SH NAME hexdiff \- un 'visuel diff' pour les fichiers binaires .SH SYNOPSIS \fBhexdiff\fP -V .br \fBhexdiff\fP -h|-? .br \fBhexdiff\fP file1 file2 .SH DESCRIPTION \fBhexdiff\fP a été crée pour faciliter le débuggage de routines d'écriture de fichiers images (PCX et BMP, comme par hasard). En comparant un fichier kimarche et un fichier que je fabrique, ça va aider :) .br \fBhexdiff\fP affiche, après le lancement, deux fenètres montrant un dump hexadécimal et ascii du début des deux fichiers. Deux barres d'état donnent le nom du fichier, sa taille et l'offset courant. La fenêtre courante est marquée par '**' à gauche de l'écran. A l'aide de diverses touches du clavier, vous pouvez vous déplacer simultanément dans les deux fichiers, et le dump vous montrera alors, en vidéo inverse, les octets qui sont différents entre les deux fichiers. Après, hein, c'est à vous d'interpréter... .SH OPTIONS .B -V Pour connaitre la version du machin-bidule. .br .B -h | -? Ah, il y a un peu de l'aide. Bon à savoir. .br .B -X Help for debugging your ~/.hexdiffrc, or the rc file parser. .SH KEYBOARD COMMANDS .B x q Quitte le programme. Parfois... .br .B u j U Remonte d'une ligne (de 16 octets), ou de quatre, dans les deux fichiers. .br .B d k D Descend d'une ou quatre lignes dans les deux fichiers. .br .B Descend de plusieurs lignes dans les deux fichiers. Ce nombre étant calculé selon la taille de l'écran, je ne peux le révéler ici. .br .B 0 Reprend au début des deux fichiers. .br .B $ Vous emmène aux environs de juste avant la fin du plus petit des deux fichiers. .br .B g Propose de saisir un nouvel offset pour les deux fichiers. Attention, cette fonctions a été écrite à la 'Gruik' et n'est donc pas fiable. .br .B H Bascule l'affichage des offsets entre le décimal et l'hexadécimal. Le mode initial est configurable. .br .B i Affichage des informations 'fstat' sur le fichier sélectionné. .br .B I Affiche les mêmes informations, mais pour les deux fichiers simultanément. .br .B A Open the (currently) experimental AsciiViewer. Maybe coredump with no request. switch as usual. .br .B ^O Ouverture d'un nouveau fichier dans la fenêtre courante. Le "selecteur de fichier" est encore rudimentaire. Utiliser 'Q' pour annuler, pour valider, et '?' pour l'aide. .br .B n Part à la recherche de la prochaine différence entre les deux fichiers. .br .B Change la fenètre active. Pour le moment, ça ne sert presque à rien. Ah, non, il parait que ça joue sur le contexte d'autres fonctions. Personne ne m'en a parlé, je ne suis au courant de rien, alors je --->[] .br .B ? "Popupe" une fenètre d'aide reprenant les principales commandes. Pour les autres commandes: un seul slogan, Utsl. .SH CONFIG FILE Le fichier de configuration est .B .hexdiffrc et doit se trouver dans le .B $HOME de l'utilisateur. Une ligne commençant par un .B '#' est un commentaire. Les lignes vides sont ignorées. Pour plus de détails, consulter le fichier 'hexdiff.rc' qui devrait se trouver dans l'archive. .SH SEE ALSO .BR diff (1), .BR cmp (1) .SH BUGS Si vous redimensionnez votre xterm, \fBhexdiff\fP se prend un SIGWINCH, et s'en va probablement visiter le pays des Slashies. Dans la pratique, il en revient très vite. .br L'affichage en fin de fichier, si les tailles sont différentes, est parfois un peu déglingué. Mais je vais réparer ça. .br Cette page de man n'est pas synchrone avec la réalité virtuelle du code. Car le code évolue plus vite que la réalité. Parfois. .SH AUTHOR Thierry Boudet aka .B tTh qui 'spleytise' avec vigueur ce petit programme depuis Mars 2002. Pour en savoir un peu plus sur ce logiciel: http://tboudet.free.fr/hexdiff/ et sur moi: http://tontonth.free.fr/plop/ .SH DEDICACE Ce logiciel est dédié aux kamarades trolleurs de l'équipe HardStory du CULTe, sans qui rien n'est pas faisable. hexdiff-0.0.53/sel_file.c0000644000175000017500000001651411135245126015027 0ustar dolanordolanor/* * sel_file.c * * Copyright: (c) 2005 Thierry Boudet * This program is free software; you can redistribute it and/or * modify it under the terms of the Do What The Fuck You Want To * Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/projects/COPYING.WTFPL for more details. */ #include #include #include #include #include #include #include #include #include /* nasty hack */ char *strdup(char *); /* end of hack */ #include #include #include "hexdiff.h" /*----------------------------------------------------------------*/ /* private vars of this module */ typedef struct { long taille; char *nom; int idx; } FICH; static FICH *liste; static int taille; /* taille de la liste */ static int nombre; /* nbre d'entrées dans la liste */ #define TCHONK 42 /*----------------------------------------------------------------*/ static int teste_dirent(const struct dirent *de, struct stat *pstat) { int foo; foo = stat(de->d_name, pstat); if (S_ISDIR(pstat->st_mode)) return 0; if (config.show_hidden==0 && de->d_name[0]=='.') return 0; return 1; } /*----------------------------------------------------------------*/ static int compare_nom_asc(const void *pa, const void *pb) { return strcmp( ((FICH *)pa)->nom, ((FICH *)pb)->nom); } static int compare_nom_desc(const void *pa, const void *pb) { return strcmp( ((FICH *)pb)->nom, ((FICH *)pa)->nom); } static int compare_taille_asc(const void *pa, const void *pb) { return ((FICH *)pa)->taille - ((FICH *)pb)->taille; } static int compare_taille_desc(const void *pa, const void *pb) { return ((FICH *)pb)->taille - ((FICH *)pa)->taille; } static int compare_idx(const void *pa, const void *pb) { return ((FICH *)pa)->idx - ((FICH *)pb)->idx; } #define PAR_NOM_ASC 1 #define PAR_NOM_DESC 2 #define PAR_TAILLE_ASC 3 #define PAR_TAILLE_DESC 4 #define PAR_IDX 5 #define PAR_PLOP 6 static int trier_la_liste(int comment) { switch (comment) { case PAR_NOM_ASC: qsort(liste, nombre, sizeof(FICH), compare_nom_asc); break; case PAR_NOM_DESC: qsort(liste, nombre, sizeof(FICH), compare_nom_desc); break; case PAR_TAILLE_ASC: qsort(liste, nombre, sizeof(FICH), compare_taille_asc); break; case PAR_TAILLE_DESC: qsort(liste, nombre, sizeof(FICH), compare_taille_desc); break; case PAR_IDX: qsort(liste, nombre, sizeof(FICH), compare_idx); break; } return 0; } /*----------------------------------------------------------------*/ static int liste_fichiers(WINDOW *win, int flag) { DIR *dir; struct dirent *de; struct stat statbuf; int foo; /* * initializing local vars, for list-of-files */ if ( NULL == (liste = malloc(TCHONK*sizeof(FICH))) ) { wprintw(win, "no mem for file list"); wrefresh(win); return 1; } taille = TCHONK; dir = opendir("."); if (dir == NULL) { wprintw(win, "error on 'opendir'"); wrefresh(win); return 1; } nombre = 0; while ( (de=readdir(dir)) != NULL) { if ( ! teste_dirent(de, &statbuf) ) { continue; } /* strdup is a 'non-portable' function ? */ liste[nombre].nom = strdup(de->d_name); liste[nombre].taille = statbuf.st_size; liste[nombre].idx = nombre; nombre++; wrefresh(win); /* * if needed, increase the size of the list */ if (nombre >= taille) { liste = realloc(liste, sizeof(FICH)*(taille+TCHONK)); taille += TCHONK; } } foo = closedir(dir); return nombre; } /*----------------------------------------------------------------*/ char *txt_aide_fs[] = { "\n WARNING !\n\n", " this file selector is a 'quick and dirty' hack\n", " and code was written with a 'Spleyt' spirit :)\n\n", "\n", " smart keys are:\n\n", " a -> sort by name ascending\n", " A -> sort by name reversing\n", " s -> sort by size\n", " S -> sort reverse by size\n", " n -> no sort\n", "", "sort by date is a work in progress..." }; int help_on_file_selector(WINDOW *win, int flag) { int foo; werase(win); for (foo=0; foo<(sizeof(txt_aide_fs)/sizeof(char *)); foo++) { wprintw(win, txt_aide_fs[foo]); wrefresh(win); } foo = getch(); return 0; } /*----------------------------------------------------------------*/ /* * new, 2005 June: now, we get the max usable length for *nomfich. */ int select_new_file(char *nomfich, int t_nom, int flags) { int ligmax, largmax, affh, idx = -1; WINDOW *fen_1, *fen_2; int foo, first, curseur, flag_exit, key; char chaine[T_NOM]; /* * quick'n'dirty security check, need more work. */ if (t_nom > T_NOM) { fprintf(stderr, "\n%s:%d possible buffer overflow\n", __FILE__, __LINE__); exit(1); } ligmax = LINES-8; /* taille verticale de la popup */ largmax = 62; fen_1 = newwin(ligmax, largmax, 2, 12); bordure(fen_1); wrefresh(fen_1); /* * first line of popup display active win number * and current win directory. as this time, we can't * select another directory ;-( */ wstandout(fen_1); for (foo=1; foo", fenetre_active); mvwaddstr(fen_1, 1, 2, chaine); */ if (getcwd(chaine,99)!=NULL) mvwaddstr(fen_1, 1, 3, chaine); else mvwaddstr(fen_1, 1, 9, " can't get cwd, sorry... "); mvwaddstr(fen_1, ligmax-2, 4, "'Q' to abort, to select, '?' for help"); wstandend(fen_1); wrefresh(fen_1); /* * create a subwindow for the scrolling selector */ fen_2 = derwin(fen_1, ligmax-4, largmax-2, 2, 1); scrollok(fen_2, 1); affh = ligmax-4; /* XXX need a valid value :) */ foo = liste_fichiers(fen_2, 0); #if TRACE wprintw(fen_2, "ret liste fichiers = %d\n", foo); wrefresh(fen_2); getch(); #endif trier_la_liste(PAR_NOM_ASC); /* * now, the file list is built, so display the selector. */ first = curseur = 0; flag_exit = 0; do { werase(fen_2); for (foo=0; foo= nombre) break; if (curseur==foo) wstandout(fen_2); mvwprintw(fen_2, foo, 1, " %-46s %9ld ", liste[idx].nom, liste[idx].taille); if (curseur==foo) wstandend(fen_2); } wrefresh(fen_2); #if TRACE mvwprintw(fen_1, 1, 2, "curs %3d first %3d ", curseur, first); wrefresh(fen_1); #endif /* * user interaction */ key = getch(); switch (key) { case KEY_UP: if (curseur) curseur--; else if (first>0) first--; break; case KEY_DOWN: if ((curseur+first) >= (nombre-1)) break; if (curseur < affh-1) curseur++; else if (first<(nombre-affh)) first++; break; /* SORT operations */ case 'a': trier_la_liste(PAR_NOM_ASC); break; case 'A': trier_la_liste(PAR_NOM_DESC); break; case 's': trier_la_liste(PAR_TAILLE_ASC); break; case 'S': trier_la_liste(PAR_TAILLE_DESC); break; case '?': help_on_file_selector(fen_2, 0); break; case '\r': idx = curseur+first; flag_exit = 1; break; case 'Q': flag_exit = -1; break; } } while ( ! flag_exit ); delwin(fen_1); if (flag_exit == 1) { strcpy(nomfich, liste[idx].nom); } /* * free the memory used by our list */ for (foo=0; foo * This program is free software; you can redistribute it and/or * modify it under the terms of the Do What The Fuck You Want To * Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/projects/COPYING.WTFPL for more details. */ #include #include #include #include #include #include #include #include #define MAIN #include "hexdiff.h" /*----------------------------------------------------------------*/ static void finish(int signal) { endwin(); exit(0); } /*----------------------------------------------------------------*/ int affiche_les_dumps(void) { int foo, bar, idx, flag; char buff[50]; char *format_offset; memset(f1.buffer, 0, T_BUFF); memset(f2.buffer, 0, T_BUFF); /* * lire les deux fichiers... */ lseek(f1.fd, f1.offset, SEEK_SET); f1.lus = read(f1.fd, f1.buffer, T_BUFF); lseek(f2.fd, f2.offset, SEEK_SET); f2.lus = read(f2.fd, f2.buffer, T_BUFF); ecrire_barres_fichiers(); /* * afficher les offsets */ format_offset = config.offsets_in_hex ? "%08lx" : "%8ld"; for (foo=0; foo15) f1.offset -= 16; if (f2.offset>15) f2.offset -= 16; break; case 'U': f1.offset -= 64; if (f1.offset<0) f1.offset=0; f2.offset -= 64; if (f2.offset<0) f2.offset=0; break; case 'd': case 'k': case KEY_DOWN: if (pas_a_la_fin) { f1.offset += 16; f2.offset += 16; } break; case 'D': if (pas_a_la_fin) { f1.offset += 64; f2.offset += 64; } break; case 'H': config.offsets_in_hex ^= 1; break; case ' ': case KEY_NPAGE: if (pas_a_la_fin) { f1.offset += (HAUT-1)*16; f2.offset += (HAUT-1)*16; } break; case KEY_PPAGE: lfoo = f1.offset - (HAUT-1)*16; if (lfoo<0) lfoo = 0; f1.offset = f2.offset = lfoo; break; case '0': case KEY_HOME: f1.offset = f2.offset = 0; break; case '7': config.show_8bits = 0; break; case '8': config.show_8bits = 1; break; case '$': /* jump to the end of the smallest file */ lfoo = (f1.taille 127. charset dependant. # you can toogle this flag with the 7 and 8 keys show_8bits 1 # enable or disable usage of semi-graphic chars # around the various popup windows. nice_border 0 # select decimal or hexa display of file offset. # the key 'H' switch interactively beetwen the two modes. offsets_in_hex 0 # sorry, at this time, no octal offset display... # if set to 1, display the id of user and group # in the fileinfo popup (access by 'i' or 'I' key ext_fileinfo 1 # those flags is not yet used... language fr asciiview 0 # is the file selector display hidden file ? show_hidden 0 hexdiff-0.0.53/COPYING0000644000175000017500000000077411145031076014133 0ustar dolanordolanor DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar 22 rue de Plaisance, 75014 Paris, France Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. You just DO WHAT THE FUCK YOU WANT TO. hexdiff-0.0.53/README0000644000175000017500000000024610215376053013756 0ustar dolanordolanor look at: - the Makefile - the man page - the source code website: http://tboudet.free.fr/hexdiff/ installation: 1) run make 2) patch 3) goto 1 hexdiff-0.0.53/TODO0000644000175000017500000000056510652763577013612 0ustar dolanordolanor add a '/' keystroke for searching a byte sequence in the current file. drink a beer ? or, better, eat a Guinness ? write a better english. write a better doc. write a better manpage. write a better code. make a Slackware package. Mmmeee. ask my girlfriend: "can you make a .deb ?" move the config file from $HOME/.hexdiffrc to $HOME/.tth/hexdiff.rc hexdiff-0.0.53/CHANGES0000644000175000017500000000374311145000144014062 0ustar dolanordolanor12 Février 2009 - Changed manpage name to automatically detect lang 21 Septembre 2005 - Added the left/right cursor wrapping in the asciiview. 27 Juin 2005 - the function select_new_file have two new arguments: first for max len of destination string, second for future flags. 4 Jan 2005 - manpage debugged, code audited, pastis drinked. 15 Dec 2004 - little bug in asciiview on xterm corrected. 30 Nov 2004: - asciiview works for me. Activate with 'A', browse the 1k page with arrows key, switch file with . 27 Octobre 2004: - start of a new function: asciiview ! 20 Novembre 2003: - I'm adding various sort options to the file selector. May be, this will work for the next release ? 12 Novembre 2003: - added a quick and dirty file selector. need more work. the display is very slow. no sorting of files. 17 Octobre 2003: - Version string is now defined in the Makefile 11 Février 2003: - With the 'I' key, you get _two_ file infos popups, and just for the price of _one_ ! Marvellous ! 5 Novembre 2002: - added a file informations popup. need more work. 14 Octobre 2002: - now, file offsets (left column) can be displayed in hexadecimal. .hexdiffrc flag name is 'offsets_in_hex'. Toggle key is 'H'. Many thanks to Mark Glines for this nice idea. 16 Juillet 2002: - display of iso-latin1 characters is working. Juillet 2002: - le parser du fichier de conf marche, mais il n'y a pas grand chose à configurer pour le moment: * le type de bordure pour les fenètres. * la langue ? 22 Mai 2002: - début de la lecture du fichier de configuration, bien que je je sache pas encore quoi y mettre... En plus, à la lecture du source (parse_rc.c), vous verrez que je TRACE féroce. 25 Avril 2002: - rajout d'une option de compilation: pour les systemes qui ne supportent pas les jolis bordures de fenètres avec les caractères semi-graphiques, un #define NICE_BORDER est dans le Makefile. 12 Avril 2002: - réorganisation des sources. hexdiff-0.0.53/fonctions.c0000644000175000017500000001743711133161550015250 0ustar dolanordolanor/* * fonctions.c * * Copyright: (c) 2005 Thierry Boudet * This program is free software; you can redistribute it and/or * modify it under the terms of the Do What The Fuck You Want To * Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/projects/COPYING.WTFPL for more details. */ #include #include #include #include #include #include #include #include #include "hexdiff.h" /*----------------------------------------------------------------*/ int is_printable(int octet) { if (config.show_8bits) return isprint(octet & 0x7f); return isprint(octet); } /*----------------------------------------------------------------*/ int ouvre_fichier(char *nom) { int fd, foo; struct stat statbuf; Fichier *fichier; long offset; if ( (fd=open(nom, O_RDONLY)) < 0) { return 0; } if (fenetre_active==0) { fichier = &f1; offset = f2.offset; } else { fichier = &f2; offset = f1.offset; } /* * close the old file */ close(fichier->fd); /* * store information on newly open file */ strncpy(fichier->nom, nom, T_NOM); foo = fstat(fd, &statbuf); fichier->fd = fd; fichier->taille = statbuf.st_size; fichier->offset = offset; fichier->lus = 0; return 1; } /*----------------------------------------------------------------*/ void barre_inverse(char c, int ligne) { int foo; standout(); for (foo=0; foo<80; foo++) mvaddch(ligne, foo, c); standend(); /* refresh(); */ } /*----------------------------------------------------------------*/ /* new 28 juillet 2007 */ static int calcul_pourcent(Fichier *f) { float foo; if (f->taille < 16) return 0; foo = ((float)f->offset * 100.0) / (float)f->taille; return (int)foo; } /*----------------------------------------------------------------*/ int ecrire_barres_fichiers(void) { char buffer[150]; int pourcent; barre_inverse(' ', BARRE_1); barre_inverse(' ', BARRE_2); standout(); mvaddstr(BARRE_1, 0, fenetre_active ? " " : "**"); mvaddstr(BARRE_1, 3, f1.nom); pourcent = calcul_pourcent(&f1); sprintf(buffer, "%8ld %8ld %3d%%", f1.taille, f1.offset, pourcent); /*sprintf(buffer, "%8ld %8ld %8ld", f1.taille, f1.offset, f1.lus);*/ mvaddstr(BARRE_1, 52, buffer); mvaddstr(BARRE_2, 0, fenetre_active ? "**" : " "); mvaddstr(BARRE_2, 3, f2.nom); pourcent = calcul_pourcent(&f2); sprintf(buffer, "%8ld %8ld %3d%%", f2.taille, f2.offset, pourcent); mvaddstr(BARRE_2, 52, buffer); if (config.show_8bits) mvaddstr(0, 72, " 8bits "); else mvaddstr(0, 72, " 7bits "); if (config.offsets_in_hex) mvaddstr(0, 66, " hex "); else mvaddstr(0, 66, " dec "); standend(); return 0; } /*----------------------------------------------------------------*/ int fond_ecran(void) { #if TRACE int foo; char buffer[200]; #endif barre_inverse(' ', 0); standout(); mvaddstr(0, 2, " Visuel HexDiff v " VERSION " by tTh 2007 "); #if TRACE sprintf(buffer, " écran %dx%d ", COLS, LINES); foo = strlen(buffer); mvaddstr(0, COLS-2-foo, buffer); #endif standend(); refresh(); #if TRACE fprintf(stderr, "HAUT %3d\n", HAUT); fprintf(stderr, "HAUT_1 %3d BARRE_1 %3d\n", HAUT_1, BARRE_1); fprintf(stderr, "HAUT_2 %3d BARRE_2 %3d\n", HAUT_2, BARRE_2); #endif return 0; } /*----------------------------------------------------------------*/ void bordure(WINDOW * w) { if (config.nice_border) box(w, 0, 0); else wborder(w, '|', '|', '-', '-', '+', '+', '+', '+'); } /*----------------------------------------------------------------*/ typedef struct { int ligne; char * texte; } ligne_aide; ligne_aide lignes[] = { { 2, "x q : quit now, 'tfatf'" }, { 4, "u j (U) : go up one (4) lines" }, { 5, "d k (D) : go down one (4) lines" }, { 6, " : go down one full page" }, { 7, "0 : back to begin of files" }, { 8, "$ : goto end of shortest file" }, { 9, " : toggle the active window" }, { 10, "g : input a new file offset" }, /* { 11, "= : synchronize the two offsets" }, */ { 12, "H : 'toogle' hex/dec offset display" }, { 13, "7 8 : display control of bit 7" }, { 14, "i (I) : info about file(s)" }, { 15, "n : jump to the next difference" }, { 16, "^O : open new file in current win" }, { 17, "A : Ascii View (new feature :)" } }; #define NB_LIG (sizeof(lignes)/sizeof(ligne_aide)) #define L_POPUP 2 #define C_POPUP 11 void popup_aide(void) { WINDOW * popup; int foo, bar, ligmax, largmax; ligmax = largmax = 0; for (foo=0; foo ligmax) ligmax = bar; if ((bar=strlen(lignes[foo].texte)) > largmax) largmax = bar; } ligmax += 3; largmax += 7; popup = newwin(ligmax, largmax, L_POPUP, C_POPUP); bordure(popup); for (foo=0; foo * This program is free software; you can redistribute it and/or * modify it under the terms of the Do What The Fuck You Want To * Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/projects/COPYING.WTFPL for more details. */ /* Attention, programmation à la "Gruiik" !-) Il y a plein de GOTO dans cette fonction, mais je les déguise habilement en fortranisme. -- tTh -- */ #include #include #include /* pour strtok */ /* certaines mauvaises langues prétendent * que 'strtok' est obsolete, insecure et * pas élégant. moi, je veux bien, mais * alors,il faut me montrer par quoi le * remplacer... */ #include "hexdiff.h" /*----------------------------------------------------------------*/ /* * positionner à des valeurs connues toutes les options de * configuration. * * 18juin2002: euh, ça ne pourrait pas être fait à la * déclaration de la variable ? */ int init_configuration(void) { config.nice_border = 0; config.show_8bits = 0; config.language = "fr"; config.offsets_in_hex = 0; config.ext_fileinfo = 0; config.show_hidden = 1; config.sf_flag = 0; config.explique = 0; config.zoom = 0; config.asciiview = 0; return 51; /* have a Pastis ? */ } /*----------------------------------------------------------------*/ #define DO_NICE_BORDER 1 #define DO_LANGUAGE 2 #define DO_SHOW_8BITS 3 #define DO_OFFSET_HEX 4 #define DO_EXT_FILEINFO 5 #define DO_SHOW_HIDDEN 20 #define DO_FS_FLAG 21 #define DO_EXPLIQUE 24 #define DO_START_ZOOM 25 #define DO_ASCIIVIEW 26 #define FLAG 1 #define TEXTE 2 #define NOMBRE 3 #define KEY_ALIAS 4 struct conf_var { char *nom; int code; int type; }; struct conf_var conf_vars[] = { { "nice_border", DO_NICE_BORDER, FLAG }, { "language", DO_LANGUAGE, TEXTE }, { "show_8bits", DO_SHOW_8BITS, FLAG }, { "offsets_in_hex", DO_OFFSET_HEX, FLAG }, { "ext_fileinfo", DO_EXT_FILEINFO, FLAG }, { "show_hidden", DO_SHOW_HIDDEN, FLAG }, { "fs_flag", DO_FS_FLAG, NOMBRE }, { "explique", DO_EXPLIQUE, FLAG }, { "start_zoom", DO_START_ZOOM, FLAG }, { "asciiview", DO_ASCIIVIEW, NOMBRE } } ; #define NB_TOKEN ( sizeof(conf_vars) / sizeof(struct conf_var) ) /*----------------------------------------------------------------*/ static int lookup_token(char *token) { int foo; for (foo=0; foo LIGNE_RC) { fprintf(stderr, ".hexdiffrc buff overflow %d, bad $HOME ?\n", foo); exit(1); } strcpy(ligne, home); strcat(ligne, "/"); strcat(ligne, HEXDIFF_RC); } else /* * oui, bon, c'est pas très cohérent, mais je ne * savais pas trop quoi faire en cas de 'homeless', * alors je me suis permis de supposer un contexte * msdos/djgpp ... */ { strcpy(ligne, "c:\\hexdiff.rc"); } #if TRACE if (flag) /* we are in .rc debug context */ { strcpy(ligne, "hexdiff.rc"); } #endif if ( (fp = fopen(ligne, "r")) == NULL ) { perror("hexdiff config file"); return -1; } line_number = 1; while ( fgets(ligne, LIGNE_RC, fp) != NULL ) { /* * virer le caractere de fin de ligne (Gruiikage) */ foo=strlen(ligne); if (foo>0) ligne[foo-1] = '\0'; #if TRACE fprintf(stderr, "%4d %4d : %s\n", line_number, foo, ligne); #endif line_number++; /* * decomposition de la ligne en machins */ machin = strtok(ligne, delim); if (machin == NULL) /* ya pas de token */ { continue; } if ( machin[0] == '#' ) /* c'est un commentaire */ { continue; } numtok = lookup_token(machin); if (flag) fprintf(stderr, "TOKEN = [%s] code=%d\n", machin, numtok); if ( numtok < 0 ) { continue; } valeur = strtok(NULL, delim); /* is strtok() usable in 2007 ? */ if ( valeur != NULL ) { if (flag) fprintf(stderr, "VALUE = [%s]\n", valeur); switch(conf_vars[numtok].code) { case DO_NICE_BORDER: config.nice_border = atoi(valeur); break; case DO_SHOW_8BITS: config.show_8bits = atoi(valeur); break; case DO_LANGUAGE: #if TRACE fprintf(stderr, "lang=%s\n", valeur); #endif break; case DO_OFFSET_HEX: config.offsets_in_hex = atoi(valeur); break; case DO_EXT_FILEINFO: config.ext_fileinfo = atoi(valeur); break; case DO_SHOW_HIDDEN: config.show_hidden = atoi(valeur); break; case DO_FS_FLAG: break; case DO_EXPLIQUE: break; } } else /* valeur == NULL */ { #if TRACE fprintf(stderr, "null value ?\n"); #endif continue; } } fclose(fp); return 42; /* thx for all the fishes, Douglas */ } /*----------------------------------------------------------------*/ hexdiff-0.0.53/tarball0000644000175000017500000000034211145070044014431 0ustar dolanordolanormercredi 14 janvier 2009, 10:56:34 (UTC+0100) mercredi 14 janvier 2009, 10:57:48 (UTC+0100) mercredi 14 janvier 2009, 10:59:33 (UTC+0100) jeudi 12 février 2009, 19:52:56 (UTC+0100) jeudi 12 février 2009, 19:53:24 (UTC+0100)