summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile26
-rwxr-xr-xinc/slices.h2
-rwxr-xr-xinc/util.h10
-rwxr-xr-xsrc/ddhardrescue.c10
-rw-r--r--src/essais/test2.c120
-rwxr-xr-xsrc/util.c24
6 files changed, 181 insertions, 11 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..be9fc08
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,26 @@
+BIN=ddhardrescue
+CFLAGS=-Iinc -Wall -g -pg
+LIBS=-lpanel -lncurses
+
+
+#FIXME : liste des dépendances = tous les .c trouvés. C'est nul.
+$(BIN): bin/$(BIN)
+
+bin/$(BIN): obj/$(BIN).o $(patsubst src/%.c,obj/%.o,$(wildcard src/*.c))
+ gcc -o $@ $^ $(CFLAGS) $(LIBS)
+
+obj/%.o:
+ gcc -c -o $@ $< $(CFLAGS)
+
+deps/%.d: src/%.c
+ gcc -o $@ $< $(CFLAGS) -MM -MG -MT $(patsubst src/%.c,obj/%.o,$<)
+
+Makefile src/%.c inc/%.h: ;
+
+.PHONY: clean
+
+clean:
+ -rm -f obj/*.o deps/*.d bin/*
+
+include $(patsubst src/%.c,deps/%.d,$(wildcard src/*.c))
+
diff --git a/inc/slices.h b/inc/slices.h
index 4b60ebc..5e56269 100755
--- a/inc/slices.h
+++ b/inc/slices.h
@@ -31,7 +31,7 @@ int sliceSplit(slices_t *slices, slice_t *initialSlice, address_t splitAt, slice
slices_t *slicesNewEmpty();
-slices_t *sliceNewSingleton(begin, end, sliceStatus_t status);
+slices_t *sliceNewSingleton(address_t begin, address_t end, sliceStatus_t status);
void slicesAppend(slices_t *slices, slice_t *slice);
diff --git a/inc/util.h b/inc/util.h
new file mode 100755
index 0000000..0724e72
--- /dev/null
+++ b/inc/util.h
@@ -0,0 +1,10 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+#include "slices.h"
+
+int parseArgs(int argc, char **argv, char *src, char *dst, char *ddOpts, address_t *beginSector, address_t *endSector);
+
+void usage();
+
+#endif /*UTIL_H*/
diff --git a/src/ddhardrescue.c b/src/ddhardrescue.c
index f97ae99..df61bc6 100755
--- a/src/ddhardrescue.c
+++ b/src/ddhardrescue.c
@@ -20,16 +20,6 @@ int main() {
slice_t *curr, *toFree;
//TODO Parse args
- src="/dev/sdb";
- dst="./test.img";
- ddOpts="";
- beginSector=0;
- endSector=21474836480ULL; //10 Tio
-// depth=1;
-/*
- endSector=1999999999;
- depth=100000;
-*/
//TODO signal...
srand(4);
diff --git a/src/essais/test2.c b/src/essais/test2.c
new file mode 100644
index 0000000..3a34414
--- /dev/null
+++ b/src/essais/test2.c
@@ -0,0 +1,120 @@
+
+#include <string.h>
+#include <panel.h>
+
+#define NLINES 10
+#define NCOLS 40
+
+void init_wins(WINDOW **wins, int n);
+void win_show(WINDOW *win, char *label, int label_color);
+void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
+
+int main()
+{ WINDOW *my_wins[3];
+ PANEL *my_panels[3];
+ PANEL *top;
+ int ch;
+
+ /* Initialize curses */
+ initscr();
+ start_color();
+ cbreak();
+ noecho();
+ keypad(stdscr, TRUE);
+
+ /* Initialize all the colors */
+ init_pair(1, COLOR_RED, COLOR_BLACK);
+ init_pair(2, COLOR_GREEN, COLOR_BLACK);
+ init_pair(3, COLOR_BLUE, COLOR_BLACK);
+ init_pair(4, COLOR_CYAN, COLOR_BLACK);
+
+ init_wins(my_wins, 3);
+
+ /* Attach a panel to each window */ /* Order is bottom up */
+ my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */
+ my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */
+ my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */
+
+ /* Set up the user pointers to the next panel */
+ set_panel_userptr(my_panels[0], my_panels[1]);
+ set_panel_userptr(my_panels[1], my_panels[2]);
+ set_panel_userptr(my_panels[2], my_panels[0]);
+
+ /* Update the stacking order. 2nd panel will be on top */
+ update_panels();
+
+ /* Show it on the screen */
+ attron(COLOR_PAIR(4));
+ mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F2 to Exit)");
+ attroff(COLOR_PAIR(4));
+ doupdate();
+
+ top = my_panels[2];
+ while((ch = getch()) != KEY_F(2))
+ { switch(ch)
+ { case 9:
+ top = (PANEL *)panel_userptr(top);
+ top_panel(top);
+ break;
+ }
+ update_panels();
+ doupdate();
+ }
+ endwin();
+ return 0;
+}
+
+/* Put all the windows */
+void init_wins(WINDOW **wins, int n)
+{ int x, y, i;
+ char label[80];
+
+ y = 2;
+ x = 10;
+ for(i = 0; i < n; ++i)
+ { wins[i] = newwin(NLINES, NCOLS, y, x);
+ sprintf(label, "Window Number %d", i + 1);
+ win_show(wins[i], label, i + 1);
+ y += 3;
+ x += 7;
+ }
+}
+
+/* Show the window with a border and a label */
+void win_show(WINDOW *win, char *label, int label_color)
+{ int startx, starty, height, width;
+
+ getbegyx(win, starty, startx);
+ getmaxyx(win, height, width);
+
+ box(win, 0, 0);
+ mvwaddch(win, 2, 0, ACS_LTEE);
+ mvwhline(win, 2, 1, ACS_HLINE, width - 2);
+ mvwaddch(win, 2, width - 1, ACS_RTEE);
+
+ print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color));
+}
+
+void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)
+{ int length, x, y;
+ float temp;
+
+ if(win == NULL)
+ win = stdscr;
+ getyx(win, y, x);
+ if(startx != 0)
+ x = startx;
+ if(starty != 0)
+ y = starty;
+ if(width == 0)
+ width = 80;
+
+ length = strlen(string);
+ temp = (width - length)/ 2;
+ x = startx + (int)temp;
+ wattron(win, color);
+ mvwprintw(win, y, x, "%s", string);
+ wattroff(win, color);
+ refresh();
+}
+
diff --git a/src/util.c b/src/util.c
new file mode 100755
index 0000000..cb01f08
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include "util.h"
+
+int parseArgs(int argc, char **argv, char *src, char *dst, char *ddOpts, address_t *beginSector, address_t *endSector) {
+ //TODO : implement that
+ src="/dev/sdb";
+ dst="./test.img";
+ ddOpts="";
+ *beginSector=0;
+ *endSector=21474836480ULL; //10 Tio
+
+ return 0;
+}
+
+void usage(char *progname) {
+ printf(
+"Usage %s <src> <dst> [<beginSector> <endSector> [ddOpts]] \
+ <src>\t\t \
+ <dst>\t\t \
+ <beginSector>\t \
+ <endSector>\t \
+ <ddOpts>\t \
+", progname);
+}