Anonymous avatar Anonymous committed 45c3a60

Remove UICalls as function parameter. Fix string list display. (fdisk@sv.gnu.org/fdisk--main--0--patch-30)
fdisk@sv.gnu.org/fdisk--main--0--patch-30
Keywords:

Comments (0)

Files changed (7)

 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <fcntl.h>
 
-#ifdef ENABLE_MTRACE
-#include <mcheck.h>
-#endif
 
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 	return key;
 }
 
+
 /* String list choice */
 /* The last two parameters specify the number of the selected element and the first element displayed 
    last time. If opts & 1, we assume it is a fullscreen text, not choice*/
 	char *temp;
 	int n,x,y,i;
 	const StrList *current;
-	
+
 	if (opts & 1) {
-		*start = selnum;
+		/* 5 are the additional lines, TODO: make this a #define */
+		*start = selnum - (LINES - 2 - 5);
+		*start = MAX(0,*start);
 		y = 0;
 		n = LINES - 2;
 	}
 	else {
+
 		n = LINES-MENUSIZE-3;
 		y = INFOSIZE;
 		if (selnum - *start < 0)
 			*start = selnum;
 		else if (selnum - *start >= n - INFOSIZE - 4)
 			*start = selnum - n + INFOSIZE + 5;
+
 	}
 	move(y++,0); clrtoeol();
 	move(y,0); clrtoeol(); mvaddstr(y++,5,prompt);
 	const StrList *selected = strlist, *temp;
 	int redraw = 1, key = 0, done = 0, start = 0, selnum = 0;
 	const char* end_warning = opts & 1 ? _("No more text") : _("No more choices");
+	if (opts & 1) {
+		for (selnum = 0, selected = strlist; 
+		     selnum < LINES-2-5 && selected->next;
+		     selnum++, selected = selected->next);
+	}
 	while (!done) {
 		if (redraw) {
 			clear_menu();
 					}
 				}
 				else if (key == 'A' && !(opts & 2)) { /* That's up arrow */
-					if (strlist == selected)
+					if (strlist == selected || 
+					    ((opts & 1) && selnum <= LINES-2-5))
 						print_warning(end_warning,0);
 					else {
 					/* FIXME: Edit strlist and make this faster */
 }
 
 
-UICalls uiquery;
+static UICalls uiquery;
 static int
 getbool(const char* prompt, int* value) {
 	int result;
 	uiquery.need_commit = 0;
 	uiquery.timer = ped_timer_new (_timer_handler, &timer_context);
 	ped_exception_set_handler(exception_handler);
+	set_uicalls(&uiquery);
 	init_fs_type_str ();
 	init_disk_type_str ();
 }
 	if(!_query_part_position(part_position,&start,&end,start,end,NULL,&opts))
 		return 0;
 
-	if (!do_mkpart(disk,start,end,type,NULL,part,opts,&uiquery)) {
+	if (!do_mkpart(disk,start,end,type,NULL,part,opts)) {
 		if (!*part) {
 			do {
 				temp = ped_disk_next_partition(disk,temp);
 	
 
 	if (opts & UI_CUSTOM_VALUES || start != (*part)->geom.start || end != (*part)->geom.end)
-		if (!do_resize(disk,*part,start,end,opts,&uiquery)) {
+		if (!do_resize(disk,*part,start,end,opts)) {
 			warning_waitkey(N_("Couldn't resize partition."));
 			/* Ooopsy */
 			if (!(opts & UI_NO_FS_RESIZE) && uiquery.need_commit)
 		return 0;
 	}
 	ped_constraint_destroy (constraint);
-	if (!do_move(disk,*part,start,end,opts,&uiquery)) {
+	if (!do_move(disk,*part,start,end,opts)) {
 		warning_waitkey(N_("Partition move failed"));
 		/* Oooops */
 		if (uiquery.need_commit) _disk_reread(part);
 			warning_waitkey(buf);
 		}
 	}
-	if (!do_mkfs (disk, *part, type, UI_WARN_COMMIT, &uiquery)) {
+	if (!do_mkfs (disk, *part, type, UI_WARN_COMMIT)) {
 		warning_waitkey(N_("Partition not formatted successfully"));
 		return 0;
 	}
 
 static int
 action_check (PedPartition **part) {
-	if (!do_check(disk,*part, &uiquery)) {
+	if (!do_check(disk,*part)) {
 		warning_waitkey(N_("The consistency check failed."));
 		return 0;
 	}
 		temp = disk_get_prev_nmd_partition(disk, temp); 
 #endif
 	if(!do_rescue (disk, (*part)->geom.start, (*part)->geom.end, 
-	           UI_WARN_COMMIT | (key == 'c' ? UI_CUSTOM_VALUES : 0), &uiquery)) {
+	           UI_WARN_COMMIT | (key == 'c' ? UI_CUSTOM_VALUES : 0))) {
 		warning_waitkey(N_("There was an error during rescue"));
 		return 0;
 	}
 
 static int
 action_copy(PedPartition **part) {
-	if (!do_cp(disk,*part, UI_WARN_COMMIT, &uiquery)) {
+	if (!do_cp(disk,*part, UI_WARN_COMMIT)) {
 		if (uiquery.need_commit) _disk_reread(part);
 		warning_waitkey(N_("Partition not copied successfully"));
 		return 0;
 
 	getbool(_("Do you want to delete this partition?"),&go);
 	if (!go) return 0;
-	if (!do_rm(disk,*part, &uiquery)) {
+	if (!do_rm(disk,*part)) {
 		warning_waitkey(N_("Can't delete partition"));
 		return 0;
 	}
 
 static int
 action_maximize(PedPartition **part) {
-	if (!do_maximize(disk,*part,&uiquery)) {
+	if (!do_maximize(disk,*part)) {
 		warning_waitkey(N_("Couldn't maximize this partition"));
 		return 0;
 	}
 
 static int
 action_commit () {
-	if (!do_commit(disk,UI_WARN_COMMIT,&uiquery)) {
+	if (!do_commit(disk,UI_WARN_COMMIT)) {
 		warning_waitkey(N_("Commit failed."));
 		return 0;
 	} 
 		return 0;
 	else if (key == 'a')
 		type = ped_file_system_probe(&(*part)->geom);
-	if (!do_set_system(disk,*part,type,&uiquery)) {
+	if (!do_set_system(disk,*part,type)) {
 		warning_waitkey(N_("Couldn't change the filesystem type"));
 		return 0;
 	}
 		warning_waitkey(N_("The partition label doesn't support partition names"));
 		return 0;
 	}
-	if (!do_name(disk,*part, NULL, &uiquery)) {
+	if (!do_name(disk,*part, NULL)) {
 		warning_waitkey(N_("Name wasn't changed successfully."));
 		return 0;
 	} 
 				print_warning(_("Invalid key"),0);
 		}
 		else if (key == CR || key == ' ') {
-			do_set(disk,*part,selected,UI_FLAG_TOGGLE,&uiquery);
+			do_set(disk,*part,selected,UI_FLAG_TOGGLE);
 			redraw = 1;
 		}
 		else 
 			ped_exception_leave_all();
 			menu_title(_("Cannot find a partition table on the disk"));
 			if ('c' == do_menu(custom_label, 8, MENU_BUTTON | MENU_TITLE, "cq", 0)) {
-				if (!do_mklabel (dev, &disk, NULL, &uiquery))
+				if (!do_mklabel (dev, &disk, NULL))
 					do_quit(1,_("Creation of partition table failed"));
 			}
 			else do_quit (0,NULL);
 			ped_exception_leave_all();
 		}
 	} else {
-		if (!do_mklabel (dev, &disk, NULL, &uiquery))
+		if (!do_mklabel (dev, &disk, NULL))
 			do_quit(1,_("Creation of partition table failed"));
 	}
 	//ped_unit_set_default(PED_UNIT_MEGABYTE);
 
 #include "../config.h"
 
-/*#include "command.h"*/
-/*#include "ui.h"*/
-
 #include "strlist.h"
 
 #define N_(String) String
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <fcntl.h>
 
 #include "common.h"
 
+#define SMALLBUF 128
 
-#define SMALLBUF 128
+/* Here we store the struct with interface functions */
+static UICalls *uiquery;
+
+/* This is the function that sets it */
+void
+set_uicalls(UICalls *uiq) {
+	uiquery = uiq;
+}
 
 static int MEGABYTE_SECTORS (PedDevice* dev)
 {
 
 /* This function makes a range less strict... */
 /* FIXME: Make this in a better way */
-void
+static void
 fuzzify (PedGeometry *geom, PedDevice *dev, PedConstraint *constraint) {
 	PedGeometry *new_geom;
 	if (!constraint)
 
 
 static int
-get_device(const char* prompt, PedDevice** value, const UICalls *uiquery)
+get_device(const char* prompt, PedDevice** value)
 {
 	char*		dev_name = *value ? strdup((*value)->path) : NULL;
 	PedDevice*	dev;
 }
 
 static int
-get_disk (const char* prompt, PedDisk** value, const UICalls *uiquery)
+get_disk (const char* prompt, PedDisk** value)
 {
 	PedDevice*	dev = *value ? (*value)->dev : NULL;
-	if (!get_device(prompt, &dev, uiquery))
+	if (!get_device(prompt, &dev))
 		return 0;
 	if (dev != (*value)->dev) {
 		PedDisk* new_disk = ped_disk_new (dev);
  * this enables the use of a shiny interface in the UI */
 
 static int
-get_partition (const char* prompt, PedDisk* disk, PedPartition** value, UICalls *uiquery)
+get_partition (const char* prompt, PedDisk* disk, PedPartition** value)
 {
 	PedPartition*	part;
 	int		num; 
 }
 
 static int
-get_disk_type (const char* prompt, const PedDiskType** value, UICalls *uiquery)
+get_disk_type (const char* prompt, const PedDiskType** value)
 {
 	char*		disk_type_name = NULL;
 	PedDiskType*	disk_type;
 
 
 static int
-get_part_type (const char* prompt, const PedDisk* disk, PedPartitionType* type, UICalls *uiquery)
+get_part_type (const char* prompt, const PedDisk* disk, PedPartitionType* type)
 {
 	StrList*	opts = NULL;
 	StrList*	locopts = NULL;
 
 /* FIXME: I don't like this mkfs thing this way. Find a better one. */
 static int
-get_fs_type (const char* prompt, const PedFileSystemType **value, int mkfs, UICalls *uiquery)
+get_fs_type (const char* prompt, const PedFileSystemType **value, int mkfs)
 {
 
 
 }
 
 static int
-get_part_flag (const char* prompt, PedPartition *part, PedPartitionFlag *value, UICalls *uiquery)
+get_part_flag (const char* prompt, PedPartition *part, PedPartitionFlag *value)
 {
 
 	StrList			*opts = NULL, *locopts = NULL;
 
 static int
 get_sector (const char* prompt, PedDevice* dev, PedSector* value,
-			 PedGeometry** range,  int custom, UICalls *uiquery)
+			 PedGeometry** range,  int custom)
 {
 	char*	def_str;
 	char*	input = NULL;
 }
 
 static int
-ask_boolean_question(const char* prompt, UICalls *uiquery) {
+ask_boolean_question(const char* prompt) {
 	int answer = 0;
 	uiquery->getbool(prompt,&answer);
 	return answer;
 
 /* Check partition consistency */
 int
-do_check (PedDisk* disk, PedPartition* part, UICalls *uiquery)
+do_check (PedDisk* disk, PedPartition* part)
 {
         PedFileSystem*  fs;
 	if (!part) {
-		if (!get_partition (_("Partition"),disk, &part, uiquery))
+		if (!get_partition (_("Partition"),disk, &part))
 			return 0;
 	}
         if (!_partition_warn_busy (part))
    Writes partition table to disk */
 /* If warn is set to 1, warns the user TODO: get rid of warn */
 int
-do_cp (PedDisk* dst_disk, PedPartition* dst, UIOpts opts, UICalls *uiquery)
+do_cp (PedDisk* dst_disk, PedPartition* dst, UIOpts opts)
 {
         PedDisk*                src_disk = NULL;
         PedPartition*           src = NULL;
 
 	if (opts & UI_WARN_COMMIT)
 		if (!ask_boolean_question 
-		(_("WARNING: This writes all data to disk automatically, continue?"),uiquery)) 
+		(_("WARNING: This writes all data to disk automatically, continue?"))) 
 			return 0;
 	/* It doesn't hurt to commit at that point, right? */
-	if (uiquery->need_commit) if (!do_commit(dst_disk,UI_DEFAULT,uiquery)) goto error;
+	if (uiquery->need_commit) if (!do_commit(dst_disk,UI_DEFAULT)) goto error;
         
 
         src_disk = dst_disk;
-	if (!get_disk (_("Source device"), &src_disk, uiquery))
+	if (!get_disk (_("Source device"), &src_disk))
 		goto error_destroy_disk;
         
 
-        if (!get_partition (_("Source partition"),src_disk, &src, uiquery))
+        if (!get_partition (_("Source partition"),src_disk, &src))
                 goto error_destroy_disk;
         if (src->type == PED_PARTITION_EXTENDED) {
                 ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
         if (!_partition_warn_busy (src))
                 goto error_destroy_disk;
 	if (!dst) {
-		if (!get_partition (_("Destination partition"),dst_disk, &dst, uiquery))
+		if (!get_partition (_("Destination partition"),dst_disk, &dst))
 			goto error_destroy_disk;
 	}
         if (!_partition_warn_busy (dst))
    in addition it takes a label type, if NULL, queries... */
 
 int
-do_mklabel (PedDevice* dev, PedDisk** disk, const PedDiskType* type, UICalls *uiquery)
+do_mklabel (PedDevice* dev, PedDisk** disk, const PedDiskType* type)
 {
 	/*
         ped_exception_fetch_all ();
                 ped_disk_destroy (*disk);
         }
 	if (!type) {
-        	if (!get_disk_type (_("New disk label type"), &type, uiquery))
+        	if (!get_disk_type (_("New disk label type"), &type))
                 	goto error;
 	}
 
 /* Create a filesystem. Takes filesystem type as an optional parameter */
 /* If warn is set to 1, warns the user TODO: get rid of warn */
 int
-do_mkfs (PedDisk* disk, PedPartition* part, const PedFileSystemType* type, UIOpts opts, UICalls *uiquery)
+do_mkfs (PedDisk* disk, PedPartition* part, const PedFileSystemType* type, UIOpts opts)
 {
 
         PedFileSystem*          fs;
 	PedConstraint*		constraint = NULL;
 	if (opts & UI_WARN_COMMIT) {
 		if (!ask_boolean_question 
-		(_("WARNING: This writes all data to disk automatically, continue?"),uiquery)) 
+		(_("WARNING: This writes all data to disk automatically, continue?"))) 
 			return 0;
 	}
 
         if (!disk)
                 goto error;
 	if (!part) {
-		if (!get_partition (_("Partition"),disk, &part, uiquery))
+		if (!get_partition (_("Partition"),disk, &part))
 			goto error;
 	}
         if (!_partition_warn_busy (part))
                 goto error;
 	if (!type) {
-        	if (!get_fs_type (_("File system"), &type, 1, uiquery))
+        	if (!get_fs_type (_("File system"), &type, 1))
 	                goto error;
 	}
 	/* We check whether we can create this partition here */
 /* NOTE: On some occassions it changes the *newpart to NULL! */
 int
 do_mkpart (PedDisk* disk, PedSector start, PedSector end, PedPartitionType part_type,
-	const PedFileSystemType* fs_type, PedPartition **newpart, UIOpts opts, UICalls *uiquery)
+	const PedFileSystemType* fs_type, PedPartition **newpart, UIOpts opts)
 {
 	PedGeometry		*range_start = NULL, *range_end = NULL;
         PedPartition*            part;
 			goto error;
                 part_type = PED_PARTITION_NORMAL;
         } else if (opts & UI_SPECIFY_PART_TYPE) {
-                if (!get_part_type (_("Partition type"), disk, &part_type, uiquery))
+                if (!get_part_type (_("Partition type"), disk, &part_type))
                         goto error;
         }
 
             /*|| (peek_word && isdigit (peek_word[0]))) {*/
                 fs_type = NULL;
         } else if (!fs_type) {
-                if (!get_fs_type (_("File system type"), &fs_type, 0, uiquery))
+                if (!get_fs_type (_("File system type"), &fs_type, 0))
                         goto error;
         }
 
                                          PED_DISK_TYPE_PARTITION_NAME)) 
                 uiquery->getstring(_("Partition name"), &part_name, NULL, NULL, 1); 
 
-        if (!get_sector (_("Start"), disk->dev, &start, &range_start, opts & UI_CUSTOM_VALUES, uiquery))
+        if (!get_sector (_("Start"), disk->dev, &start, &range_start, opts & UI_CUSTOM_VALUES))
                 goto error;
-        if (!get_sector (_("End"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES, uiquery))
+        if (!get_sector (_("End"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES))
                 goto error;
         
         /* processing starts here */
 
 int
 do_mkpartfs (PedDisk* disk, PedSector start, PedSector end, PedPartitionType part_type,
-	const PedFileSystemType* fs_type, PedPartition **newpart, UIOpts opts, UICalls *uiquery)
+	const PedFileSystemType* fs_type, PedPartition **newpart, UIOpts opts)
 {
 
         PedPartition*            part = NULL;
 
 	if (opts & UI_WARN_COMMIT) {
 		if (!ask_boolean_question 
-		(_("WARNING: This writes all data to disk automatically, continue?"),uiquery)) 
+		(_("WARNING: This writes all data to disk automatically, continue?"))) 
 			return 0;
 	}
 /*
 			return 0;
                 part_type = PED_PARTITION_NORMAL;
         } else if (!part_type) {
-                if (!get_part_type (_("Partition type"), disk, &part_type, uiquery))
+                if (!get_part_type (_("Partition type"), disk, &part_type))
                         return 0;
         }
 
         }
 */
         if (!fs_type) {
-                if (!get_fs_type (_("File system type"), &fs_type, 1, uiquery))
+                if (!get_fs_type (_("File system type"), &fs_type, 1))
                         return 0;
         }
-	if (!do_mkpart(disk,start,end,part_type,fs_type,&part,opts,uiquery))
+	if (!do_mkpart(disk,start,end,part_type,fs_type,&part,opts))
 		return 0;
-	if (!do_mkfs(disk,part,fs_type,opts & ~UI_WARN_COMMIT,uiquery))
+	if (!do_mkfs(disk,part,fs_type,opts & ~UI_WARN_COMMIT))
 		return 0;
 	if (newpart) *newpart = part;
 	return 1;
 
 /* FIXME: This function seems to be problematic, deal with it appropriately in the ui */
 int
-do_move (PedDisk *disk, PedPartition *part, PedSector start, PedSector end, UIOpts opts, UICalls *uiquery)
+do_move (PedDisk *disk, PedPartition *part, PedSector start, PedSector end, UIOpts opts)
 {
        
         PedFileSystem*  fs;
 	
 	if (opts & UI_WARN_COMMIT) {
 		if (!ask_boolean_question 
-		(_("WARNING: This writes all data to disk automatically, continue?"),uiquery)) 
+		(_("WARNING: This writes all data to disk automatically, continue?"))) 
 			return 0;
 	}
 	/* So the best we can do here is to commit */
 	if (uiquery->need_commit)
-		if (!do_commit(disk,UI_DEFAULT,uiquery))
+		if (!do_commit(disk,UI_DEFAULT))
 			goto error;
 	if (!part)
-        	if (!get_partition (_("Partition"), disk, &part, uiquery))
+        	if (!get_partition (_("Partition"), disk, &part))
                 	goto error;
         if (!_partition_warn_busy (part))
                 goto error;
                 goto error;
 
         /* get new target */
-        if (!get_sector (_("Start"), disk->dev, &start, &range_start, opts & UI_CUSTOM_VALUES, uiquery))
+        if (!get_sector (_("Start"), disk->dev, &start, &range_start, opts & UI_CUSTOM_VALUES))
                 goto error_close_fs;
         if (opts & UI_CUSTOM_VALUES)
 		end = start + old_geom.length - 1;
-        if (!get_sector (_("End"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES, uiquery))
+        if (!get_sector (_("End"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES))
                 goto error_close_fs;
 
         /* set / test on "disk" */
 }
 
 int
-do_name (PedDisk* disk, PedPartition* part, char *name, UICalls *uiquery)
+do_name (PedDisk* disk, PedPartition* part, char *name)
 {
 	const char *temp;
 	int n;
         if (!disk)
                 goto error;
 	if (!part) 
-        	if (!get_partition (_("Partition"), disk, &part, uiquery))
+        	if (!get_partition (_("Partition"), disk, &part))
                 	goto error;
 	if (!name) {
 		temp = ped_partition_get_name(part);
  *      -1 if the user chose to cancel the entire search.
  */
 static int
-_rescue_add_partition (PedPartition* part, UICalls *uiquery)
+_rescue_add_partition (PedPartition* part)
 {
         const PedFileSystemType*        fs_type;
         PedGeometry*                    probed;
  * for RAID, or something...
  */
 static int
-_rescue_pass (PedDisk* disk, PedGeometry* start_range, PedGeometry* end_range, UICalls *uiquery)
+_rescue_pass (PedDisk* disk, PedGeometry* start_range, PedGeometry* end_range)
 {
         PedSector               start;
         PedGeometry             start_geom_exact;
                 ped_exception_fetch_all ();
                 if (ped_disk_add_partition (disk, part, &constraint)) {
                         ped_exception_leave_all ();
-                        switch (_rescue_add_partition (part, uiquery)) {
+                        switch (_rescue_add_partition (part)) {
                         case 1:
                                 ped_constraint_done (&constraint);
                                 return 1;
 }
 
 int
-do_rescue (PedDisk* disk, PedSector start, PedSector end, UIOpts opts, UICalls *uiquery)
+do_rescue (PedDisk* disk, PedSector start, PedSector end, UIOpts opts)
 {
 
         PedSector               fuzz;
                 goto error;
 	if (opts & UI_WARN_COMMIT)
 		if (!ask_boolean_question 
-		(_("WARNING: This writes all data to disk automatically, continue?"),uiquery)) 
+		(_("WARNING: This writes all data to disk automatically, continue?"))) 
 			return 0;
 	/* Why the hell I use two seperate ifs, instead of one? I wish I knew */
 	if (uiquery->need_commit)
-		if (!do_commit(disk,UI_DEFAULT,uiquery))
+		if (!do_commit(disk,UI_DEFAULT))
 			goto error;
-        if (!get_sector (_("Start"), disk->dev, &start, NULL, opts & UI_CUSTOM_VALUES, uiquery))
+        if (!get_sector (_("Start"), disk->dev, &start, NULL, opts & UI_CUSTOM_VALUES))
                 goto error;
-        if (!get_sector (_("End"), disk->dev, &end, NULL, opts & UI_CUSTOM_VALUES, uiquery))
+        if (!get_sector (_("End"), disk->dev, &end, NULL, opts & UI_CUSTOM_VALUES))
                 goto error;
 
         fuzz = PED_MAX (PED_MIN ((end - start) / 10, MEGABYTE_SECTORS(disk->dev)),
                            PED_MIN(2 * fuzz, (disk->dev)->length - (end - fuzz)));
 	/* I don't believe this is dangerous, but still */
 	uiquery->need_commit = 1;
-        if (!_rescue_pass (disk, &probe_start_region, &probe_end_region, uiquery))
+        if (!_rescue_pass (disk, &probe_start_region, &probe_end_region))
                 goto error;
 
 
 
 /* FIXME: It doesn't always work as expected */
 int
-do_resize (PedDisk *disk, PedPartition *part, PedSector start, PedSector end, UIOpts opts, UICalls *uiquery)
+do_resize (PedDisk *disk, PedPartition *part, PedSector start, PedSector end, UIOpts opts)
 {
 
         PedFileSystem           *fs;
                 goto error;
 
 	if (!part) 
-        	if (!get_partition (_("Partition"), disk, &part, uiquery))
+        	if (!get_partition (_("Partition"), disk, &part))
                 	goto error;
 
 	if (!(part->type == PED_PARTITION_EXTENDED || (opts & UI_NO_FS_RESIZE)))  {
 		if (opts & UI_WARN_COMMIT && !ask_boolean_question 
-		(_("WARNING: This writes all data to disk automatically, continue?"),uiquery)) 
+		(_("WARNING: This writes all data to disk automatically, continue?"))) 
 			return 0;
 		if (uiquery->need_commit)
-			if (!do_commit(disk,UI_DEFAULT,uiquery))
+			if (!do_commit(disk,UI_DEFAULT))
 				goto error;
 	}
 
                         goto error;
         }
 
-        if (!get_sector (_("Start"), disk->dev, &start, &range_start, opts & UI_CUSTOM_VALUES, uiquery))
+        if (!get_sector (_("Start"), disk->dev, &start, &range_start, opts & UI_CUSTOM_VALUES))
                 goto error;
-        if (!get_sector (_("End"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES, uiquery))
+        if (!get_sector (_("End"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES))
                 goto error;
 
 	/* FIXME: Decide when exactly we need to "fuzzify" */
 }
 
 int
-do_rm (PedDisk* disk, PedPartition* part, UICalls *uiquery)
+do_rm (PedDisk* disk, PedPartition* part)
 {
        
 
         if (!disk)
                 goto error;
 	if (!part) 
-        	if (!get_partition (_("Partition"), disk, &part, uiquery))
+        	if (!get_partition (_("Partition"), disk, &part))
                 	goto error;
         if (!_partition_warn_busy (part))
                 goto error;
 }
 
 int
-do_maximize (PedDisk* disk, PedPartition* part, UICalls *uiquery)
+do_maximize (PedDisk* disk, PedPartition* part)
 {
 	PedConstraint *constraint = NULL;
 	if (!disk)
 		return 0;
 	if (!part)
-		if (!get_partition(_("Partition"), disk, &part, uiquery))
+		if (!get_partition(_("Partition"), disk, &part))
 			return 0;
 	if (!_partition_warn_busy(part))
 		return 0;
 }
 
 int
-do_set_system (PedDisk* disk, PedPartition* part, const PedFileSystemType *type, UICalls *uiquery)
+do_set_system (PedDisk* disk, PedPartition* part, const PedFileSystemType *type)
 {
 	if (!disk)
 		return 0;
 	if (!part)
-		if (!get_partition(_("Partition"), disk, &part, uiquery))
+		if (!get_partition(_("Partition"), disk, &part))
 			return 0;
 	if (!type) {
-		if (!get_fs_type (_("File system type"), &type, 0, uiquery))
+		if (!get_fs_type (_("File system type"), &type, 0))
 			return 0;
 	}
 	/* FIXME: Is this needed? We don't touch the partition itself */
 
 
 int
-do_set (PedDisk *disk, PedPartition *part, PedPartitionFlag flag, UIOpts opts, UICalls *uiquery)
+do_set (PedDisk *disk, PedPartition *part, PedPartitionFlag flag, UIOpts opts)
 {
         int                     state;
 
         if (!disk)
                 goto error;
         if (!part)
-		if (!get_partition (_("Partition"), disk, &part, uiquery))
+		if (!get_partition (_("Partition"), disk, &part))
 			goto error;
 	if (!flag)
-		if (!get_part_flag (_("Flag to change"), part, &flag, uiquery))
+		if (!get_part_flag (_("Flag to change"), part, &flag))
 			goto error;
         state = (ped_partition_get_flag (part, flag) == 0 ? 1 : 0);
         
 }
 
 int
-do_commit (PedDisk* disk, UIOpts opts, UICalls* uiquery)
+do_commit (PedDisk* disk, UIOpts opts)
 {
 	if (opts & UI_WARN_COMMIT)
 		if (!ask_boolean_question 
-			(_("WARNING: This writes all data to disk, continue?"),uiquery)) 
+			(_("WARNING: This writes all data to disk, continue?"))) 
 				return 0;
 	if (ped_disk_commit(disk)) {
 		uiquery->need_commit = 0;
 #define UI_FLAG_TOGGLE UI_FUNCTION_SPECIFIC_1	/* do_set must toggle flags */
 
 
+/* Setting of UICalls */
+extern void set_uicalls(UICalls *);
+
 /* Lists. Should be initialized. */
 extern StrList *disk_type_list;
 extern StrList *fs_type_list;
 /* NOTE: resize, move and perhaps copy are dangerous. Please, make your ui check their status.
    if they FAIL and leave need_commit to true, please reread the partition table from the device.
    Sorry for the inconvinience. I might change this in the future so that it is not needed */
-extern int do_check (PedDisk*, PedPartition*, UICalls *);
+extern int do_check (PedDisk*, PedPartition*);
 /* The parameters are the *destination* disk and partition */
-extern int do_cp (PedDisk*, PedPartition*, UIOpts, UICalls *);
-extern int do_mklabel (PedDevice*, PedDisk**, const PedDiskType*, UICalls *);
+extern int do_cp (PedDisk*, PedPartition*, UIOpts);
+extern int do_mklabel (PedDevice*, PedDisk**, const PedDiskType*);
 
-extern int do_mkfs (PedDisk*, PedPartition*, const PedFileSystemType*, UIOpts,
-                    UICalls *);
+extern int do_mkfs (PedDisk*, PedPartition*, const PedFileSystemType*, UIOpts);
 
 extern int do_mkpart (PedDisk*, PedSector start, PedSector end,
                       PedPartitionType,	const PedFileSystemType*,
-                      PedPartition **newpart, UIOpts, UICalls *);
+                      PedPartition **newpart, UIOpts);
 
 extern int do_mkpartfs (PedDisk*, PedSector start, PedSector end,
                         PedPartitionType, const PedFileSystemType*,
-                        PedPartition **newpart, UIOpts, UICalls *);
+                        PedPartition **newpart, UIOpts);
 
 extern int do_move (PedDisk*, PedPartition*, PedSector start, PedSector end,
-                    UIOpts, UICalls*);
-extern int do_name (PedDisk*, PedPartition*, char*, UICalls*);
-extern int do_rescue (PedDisk*, PedSector start, PedSector end, UIOpts,
-                      UICalls *);
+                    UIOpts);
+extern int do_name (PedDisk*, PedPartition*, char*);
+extern int do_rescue (PedDisk*, PedSector start, PedSector end, UIOpts);
 extern int do_resize (PedDisk*, PedPartition*, PedSector start, PedSector end,
-                      UIOpts, UICalls*);
-extern int do_rm (PedDisk*, PedPartition*, UICalls*);
-extern int do_set_system (PedDisk*, PedPartition*, const PedFileSystemType*,
-                          UICalls*);
-extern int do_set (PedDisk*, PedPartition*, PedPartitionFlag, UIOpts,UICalls*);
-extern int do_commit (PedDisk*, UIOpts, UICalls*);
-extern int do_maximize (PedDisk*, PedPartition*, UICalls*);
+                      UIOpts);
+extern int do_rm (PedDisk*, PedPartition*);
+extern int do_set_system (PedDisk*, PedPartition*, const PedFileSystemType*);
+extern int do_set (PedDisk*, PedPartition*, PedPartitionFlag, UIOpts);
+extern int do_commit (PedDisk*, UIOpts);
+extern int do_maximize (PedDisk*, PedPartition*);
 
 /* Additional functions */
 extern char* partition_print_flags (PedPartition*);

tests/check_advanced.c

 		unlink_tempfile();
 		fail("Could not open the tempfile");
 	}
-	if (mklabel && !do_mklabel(dev,&disk,ped_disk_type_get("msdos"),&uiquery))
+	if (mklabel && !do_mklabel(dev,&disk,ped_disk_type_get("msdos")))
 		fail("Could not create a label on the tempfile");
 	
 }
 START_TEST (test_resize) {
 	open_tempfile(0);
 	change_size("msdos", UI_DEFAULT);
+	test_exception();
 	/* We will use the result file for testing partition copy */
 	rename(tempfile_name(),tempfile2_name());
 	//close_tempfile();
 	                    oldstart, oldend, part->geom.start, part->geom.end, 
 		            start, end, where.start, where.end);
 	}
+	test_exception();
 	close_tempfile();
 }
 END_TEST
 	PedFileSystemType *fs_type = ped_file_system_type_get("fat32");
 	open_tempfile(0);
 	/* Why not amiga? */
-	fail_unless(do_mklabel(dev,&disk,ped_disk_type_get("msdos"),&uiquery),
+	fail_unless(do_mklabel(dev,&disk,ped_disk_type_get("msdos")),
 	            "Failed to create partition table for partition copy");
 	PedConstraint *constraint = ped_device_get_constraint(dev);
 	
 		integer = i+1;
 		set_exception_error("Copying %d to %llds-%llds",
 		                    i, part->geom.start, part->geom.end);
-		fail_unless(do_cp (disk, part, UI_DEFAULT, &uiquery), 
+		fail_unless(do_cp (disk, part, UI_DEFAULT), 
 		            "%d partition copy failed (from %llds-%llds "
 		            "to %llds-%llds)", i, 0LL, 0LL, part->geom.start,
 		            part->geom.end);
 	/* Now we try to copy from a partition on the same disk */
 	device = dev;
 	integer = 1;
-	fail_unless(do_cp (disk, part, UI_DEFAULT, &uiquery), 
+	fail_unless(do_cp (disk, part, UI_DEFAULT), 
 	            "Partition copy on a single disk failed");
 	ped_disk_destroy(disk2);
 	ped_device_destroy(dev2);
+	test_exception();
 	/* We don't need this anymore. We won't unlink the tempfile, because *
          * we will test the rescue on it.                                    */
 	//close_tempfile();
 		PedPartition *temp = part;
 		part = part->prev;
 		if (!temp->type) {
-			fail_unless(do_rm(disk, part, &uiquery),
+			fail_unless(do_rm(disk, part),
 			            "Rescue could not delete %d partition",
 			            part->num);
 		}
 	}
 	
 	/* Then we try to undelete the last one */
-	fail_unless(do_rescue(disk, geom.start, geom.end, UI_DEFAULT, &uiquery),
+	fail_unless(do_rescue(disk, geom.start, geom.end, UI_DEFAULT),
 	            "Failed to rescue a single partition at %llds-%llds",
 	            geom.start, geom.end);
 	/* part should be the undeleted partition */
                     "Deleted was %llds-%llds, we got %llds-%llds.",
 	            geom.start, geom.end, part->geom.start, part->geom.end);
 	/* We delete it again and try to rescue all */
-	fail_unless(do_rm(disk, part, &uiquery),
+	fail_unless(do_rm(disk, part),
 	            "Rescue could not delete %d partition",
 	            part->num);
 
 	/* The end of the last partition is before 8388604s */
-	fail_unless(do_rescue(disk, 0LL, geom.end, UI_DEFAULT, &uiquery),
+	fail_unless(do_rescue(disk, 0LL, geom.end, UI_DEFAULT),
 	            "Failed to rescue the partitions");
 	/* Now we count them, if they aren't four, we did something wrong */
 	for (part = ped_disk_next_partition(disk,NULL), i = 0;
 			i++;
 	}
 	fail_unless(i == 4, "We got %d partitions instead of 4", i);
+	test_exception();
 	close_tempfile();
 }
 END_TEST
 	check_safety ();
 	int nf;
 	ped_exception_set_handler(exception_handler);
+	set_uicalls(&uiquery);
 	reset_exception_error();
 	string[0][BUFSIZE] = 0;
 	Suite *s = common_suite();

tests/check_common.c

 	/* First we will test with giving it the string */
 	uiquery.getstring = getstring;
 	uiquery.getdisktype = NULL;
-	fail_unless (do_mklabel(dev, &disk, NULL, &uiquery), 
+	fail_unless (do_mklabel(dev, &disk, NULL), 
 	             "Failed to create a label with a getstring query");
 	fail_unless (disk != NULL, "mklabel reported success, but failed");
 	fail_unless (!strcmp(string[0],disk->type->name),
 	/* Then we do it the other way */
 	uiquery.getstring = NULL;
 	uiquery.getdisktype = getdisktype;
-	fail_unless (do_mklabel(dev,&disk, NULL, &uiquery),
+	fail_unless (do_mklabel(dev,&disk, NULL),
 	             "Failed to create a label with a getdisktype query");
 	fail_unless (disk != NULL,
 	             "mklabel reported success, but failed, getdisktype");
 	disk = NULL;
 	/* Then we do it the third way */	
 	uiquery.getdisktype = NULL;
-	fail_unless (do_mklabel(dev,&disk,disk_type,&uiquery),
+	fail_unless (do_mklabel(dev,&disk,disk_type),
 	             "Failed to create a label with a specified type");
 	fail_unless (disk != NULL,
 	             "mklabel reported success, but failed, specified");
 	fail_unless (!strcmp(string[0],disk->type->name),
 	             "mklabel created wrong disk type when we specified it");
+	test_exception();
 	
 }
 END_TEST
 	int i;
 	/* First we create an extended partition */
 	//set_exception_error("Juggling partitions");
-	fail_unless(do_mklabel(dev,&disk,ped_disk_type_get("msdos"),&uiquery),
+	fail_unless(do_mklabel(dev,&disk,ped_disk_type_get("msdos")),
 	            "We could create the label for juggling partitions");
 	fail_unless(do_mkpart(disk,0LL,20000LL,PED_PARTITION_EXTENDED,NULL,NULL,
-	                      UI_DEFAULT,&uiquery),
+	                      UI_DEFAULT),
 	            "Failed to create an extended partition");
 
 	/* Check if it is there */
 	fail_unless(part != NULL, "Can't find the extended partition");
 
 	/* Then we maximize it */
-	fail_unless(do_maximize(disk,part,&uiquery), "Could not maximize the extended");
+	fail_unless(do_maximize(disk,part), "Could not maximize the extended");
 
 	/* We check if our partition is "near" to what they should */
 	fail_unless(are_near(constraint->start_range->start,part->geom.start)
 		if (part && (part->type & PED_PARTITION_FREESPACE))
 			fail("We reached a hole at %llds-%llds, number %d",
 			     part->geom.start, part->geom.end, i);
-		fail_unless (do_rm(disk,temp,&uiquery),
+		fail_unless (do_rm(disk,temp),
 		             "Failed to delete partition after %d",
 		             (part ? part->num : -1));
 		i--;
 	}
 	fail_unless(i == 0, "Not all partitions were deleted. %d remain.", i);
 	ped_geometry_destroy(geom);
-	
+	test_exception();
 }
 END_TEST
 
 /* Here we test (*only*) the size changing with do_resize */
 START_TEST (test_chsize_msdos) {
 	change_size("msdos", UI_NO_FS_RESIZE);
+	test_exception();
 }
 END_TEST
 
 START_TEST (test_chsize_amiga) {
 	change_size("amiga", UI_NO_FS_RESIZE);
+	test_exception();
 }
 END_TEST
 
 START_TEST (test_chsize_mac) {
 	change_size("mac", UI_NO_FS_RESIZE);
+	test_exception();
 }
 END_TEST
 
 START_TEST (test_chsize_dvh) {
 	change_size("dvh", UI_NO_FS_RESIZE);
+	test_exception();
 }
 END_TEST
 
 START_TEST (test_chsize_pc98) {
 	change_size("pc98", UI_NO_FS_RESIZE);
+	test_exception();
 }
 END_TEST
 
 START_TEST (test_chsize_bsd) {
 	change_size("bsd", UI_NO_FS_RESIZE);
+	test_exception();
 }
 END_TEST
 
 START_TEST (test_chsize_sun) {
 	change_size("sun", UI_NO_FS_RESIZE);
+	test_exception();
 }
 END_TEST
 
 START_TEST (test_chsize_gpt) {
 	change_size("gpt", UI_NO_FS_RESIZE);
+	test_exception();
 }
 END_TEST
 
 START_TEST (test_chsize_loop) {
 	change_size("gpt", UI_NO_FS_RESIZE);
+	test_exception();
 }
 END_TEST
 
 		return 1;
 	}
 	ped_exception_set_handler(exception_handler);
+	set_uicalls(&uiquery);
 	reset_exception_error();
 	string[0][BUFSIZE] = 0;
 	Suite *s = common_suite();

tests/functions.c

 			}
 		}
 	}
+	/* Well, there should be no problem, TODO: is it needed? */
 	if (!getuid() || !geteuid()) {
 		printf("You should not run these tests as root.\n"
 		       "Are you sure you want to continue (y/N)? ");
 PedExceptionType ex_type;
 char exception_error[BUFSIZE];// = "%s";
 
+static int exception_count = 0;
 
 int set_exception_error(const char *format, ...) {
 	va_list args;
 
 PedExceptionOption
 exception_handler (PedException* ex) {
+	exception_count++;
 	ex_opts = ex->options;
 	ex_type = ex->type;
 	switch (ex->type) {
 	
 }
 
+
+/* Look for functions who handled exceptions incorrectly.
+   If this does not go to our exception handler, we have a problem.
+   Will check this at the end of each test. */
+void test_exception() {
+	//printf("\nSo far we got %d exceptions\n", exception_count);
+	exception_count = 0;
+	if (ped_exception_throw (PED_EXCEPTION_INFORMATION,
+	                         PED_EXCEPTION_OK,
+	                         "Test") != PED_EXCEPTION_OK)
+		fail ("Exception not handled by our handler");
+	if (exception_count != 1)
+		fail ("Caught %d exceptions instead of 1", exception_count);
+
+}
+
 /* This functions will return what's needed */
 /* NOTE: If the string is DEFAULT_STRING, we return the default string */
 /* Also note that we have two strings here, if the last character is 1, we
                       PedPartition **newpart,
                       int ch_mkpart (PedDisk*, PedSector start, PedSector end,
                                      PedPartitionType, const PedFileSystemType*,
-                                     PedPartition **, UIOpts, UICalls *))
+                                     PedPartition **, UIOpts))
 {
 	switch(how % 3) {
 		/* We create the partition by specifying start and end */
 			strncpy(string[0], fs_type->name, BUFSIZE-1);
 			string[0][BUFSIZE] = 0;
 			return ch_mkpart(disk,start,end,type,NULL,newpart,
-			                 UI_DEFAULT,&uiquery);
+			                 UI_DEFAULT);
 		/* We test that giving the default string is OK */
 		case 1:
 			strncpy(string[0],DEFAULT_STRING,BUFSIZE);
 			uiquery.getstring = getstring;
 			return ch_mkpart(disk,start,end,type,fs_type,newpart,
-			                 UI_CUSTOM_VALUES,&uiquery);
+			                 UI_CUSTOM_VALUES);
 		/* We query the start and end */
 		case 2:
 			uiquery.getstring = getstring;
 			snprintf(string[0],BUFSIZE,"%llds",start);
 			snprintf(string[1],BUFSIZE,"%llds",end);
 			return ch_mkpart(disk,0LL,0LL,type,fs_type,newpart,
-			                 UI_CUSTOM_VALUES,&uiquery);
+			                 UI_CUSTOM_VALUES);
 	}
 	
 }
 _resmov (int how, PedPartition *part, PedSector start, PedSector end,
          UIOpts opts, int action (PedDisk*, PedPartition*,
                                   PedSector start, PedSector end,
-                                  UIOpts, UICalls*))
+                                  UIOpts))
 {
 	switch (how % 3) {
 		/* Specify start, end and partition */
 		case 0:
-			return action (disk, part, start, end, opts,
-			                  &uiquery);
+			return action (disk, part, start, end, opts);
 		/* We specify start and end, ask for partition */
 		case 1:
 			uiquery.getint = NULL;
 			uiquery.getpart = getpart;
 			partition = part;
-			return action (disk, NULL, start, end, opts,
-			                  &uiquery);
+			return action (disk, NULL, start, end, opts);
 		/* We ask for everything, the partition with number */
 		case 2:
 			uiquery.getpart = NULL;
 			snprintf(string[0],BUFSIZE,"%llds",start);
 			snprintf(string[1],BUFSIZE,"%llds",end);
 			opts |= UI_CUSTOM_VALUES;
-			return action (disk, NULL, 0LL, 0LL, opts,
-			                  &uiquery);
+			return action (disk, NULL, 0LL, 0LL, opts);
 	}
 }
 
 	PedPartition *part = NULL;
 	PedFileSystemType *fs_type = ped_file_system_type_get("fat32");
 	int i;
-	fail_unless(do_mklabel(dev,&disk,ped_disk_type_get(ltype),&uiquery),
+	fail_unless(do_mklabel(dev,&disk,ped_disk_type_get(ltype)),
 	            "We could create the %s label for resizing partitions",
 	            ltype);
 	/* NOTE: This might blow up if ltype is less than three chars */

tests/functions.h

 extern PedExceptionOption ex_opts;
 extern PedExceptionType ex_type;
 extern PedExceptionOption exception_handler (PedException*);
+extern void test_exception();
 
 /* This are functions for UICalls */
 /* NOTE: This macros are only for reference */
                       PedPartition **newpart,
                       int mkpart (PedDisk*, PedSector start, PedSector end,
                                   PedPartitionType, const PedFileSystemType*,
-                                  PedPartition **, UIOpts, UICalls *));
+                                  PedPartition **, UIOpts));
 /* This is a function that both resizes and moves */
 extern int _resmov (int how, PedPartition *part, PedSector start, PedSector end,
                     UIOpts opts, int action (PedDisk*, PedPartition*,
                                              PedSector start, PedSector end,
-                                             UIOpts, UICalls*));
+                                             UIOpts));
 
 extern void get_max_geometry(PedGeometry **geom, PedConstraint *constraint, 
                       PedPartition *part);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.