Anonymous avatar Anonymous committed 30ea15b

Implement arrow cursor, write some in-program help, finish text displayer to correctly display in-program help, and one-two fixes. (fdisk@sv.gnu.org/fdisk--main--0--patch-31)
fdisk@sv.gnu.org/fdisk--main--0--patch-31
Keywords:

Comments (0)

Files changed (4)

 [options] [device]
 .SH DESCRIPTION
 .B cfdisk
-is a disk partition manipulation, which allows to create, destroy, resize, move and copy partitions using a simple menu-driven interface. It is useful for organising the disk space on a new drive, reorganising an old drive, creating space for new operating systems, and copying data to new hard disks. For a list of the supported partition types, see the
+is a disk partition manipulation program, which allows you to create, destroy, resize, move and copy partitions on a hard drive using a simple menu-driven interface. It is useful for organising the disk space on a new drive, reorganising an old drive, creating space for new operating systems, and copying data to new hard disks. For a list of the supported partition types, see the
 .B --list-partition-types
 option below.
 .SH OPTIONS
 .B -v, --version
 displays the program's version.
 .TP
+.B -a, --arrow-cursor
+use an arrow cursor, instead of reverse video highlighting, in case your terminal doesn't support it.
+.TP
 .B -z, --new-table
 create a new partition table on the disk. This is useful if you want to change the partition table type or want to repartition you entire drive. Note that this does not delete the old table on the disk until you commit the changes.
 .TP
 @item @b{@minus{}v, @minus{}@minus{}version}
 Displays the program's version.
 
+@item @b{@minus{}a, @minus{}@minus{}arrow-cursor}
+Use an arrow cursor, instead of reverse video highlighting, in 
+case your terminal doesn't support it.
+
 @item @b{@minus{}z, @minus{}@minus{}new-table}
 Create a new partition table on the disk. This is useful if  you
 want  to  change the partition table type or want to repartition
 {
 	{"help",	'h', NULL,	N_("displays this help message")},
 	{"version",	'v', NULL,	N_("displays the version")},
+	{"arrow-cursor", 'a', NULL, 	N_("use an arrow cursor instead of reverse video")},
 	{"new-table",	'z', NULL,	N_("create a new partition table on the disk")},
 	{"units",	'u', N_("UNIT"),N_("sets the default display units to UNIT")},
 	{"list-partition-types", 'l', NULL, N_("displays a list of supported partition types")},
 
 /* Help should go here */
 static const char *help = N_(
-     "Join us now and share the software;\n"
-     "You'll be free, hackers, you'll be free.\n"
-     "Join us now and share the software;\n"
-     "You'll be free, hackers, you'll be free.\n"
-     "\n"
-     "Hoarders may get piles of money,\n"
-     "That is true, hackers, that is true.\n"
-     "But they cannot help their neighbors;\n"
-     "That's not good, hackers, that's not good.\n"
-     "\n"
-     "When we have enough free software\n"
-     "At our call, hackers, at our call,\n"
-     "We'll throw out those dirty licenses\n"
-     "Ever more, hackers, ever more.\n"
-     "\n"
-     "Join us now and share the software;\n"
-     "You'll be free, hackers, you'll be free.\n"
-     "Join us now and share the software;\n"
-     "You'll be free, hackers, you'll be free.\n"
-     "\n"
-     "Hoarders may get piles of money,\n"
-     "That is true, hackers, that is true.\n"
-     "But they cannot help their neighbors;\n"
-     "That's not good, hackers, that's not good.\n"
-     "\n"
-     "When we have enough free software\n"
-     "At our call, hackers, at our call,\n"
-     "We'll throw out those dirty licenses\n"
-     "Ever more, hackers, ever more.\n"
+	"This is a curses-based disk partition manipulation program, which "
+	"allows you create, destroy, resize, move and copy partitions on "
+	"a hard drive.\n\n"
+	"Copyright (C) 2006 Free Software Foundation, Inc.\n\n"
+	"Key\tFunction\n"
+	"---\t--------\n\n"
+	" n\tCreate a new partition residing on the free space.\n"
+	" d\tDelete the selected partition.\n"
+	" c\tCheck the selected partition for consistency.\n"
+	" r\tResize the selected partition or change the size of the "
+	"entry in the partition table\n"
+	" o\tMove the partition to another place on the drive.\n"
+	" y\tCopies another partition over the selected one.\n"
+	" s\tLook for deleted file systems in the selected free space.\n"
+	" b\tDisplay or change partition flags, such as the bootable flag.\n"
+	" t\tChange the system type on the partition in the partition "
+	"in case it is currently wrong.\n"
+	" m\tChange the partition name, if supported.\n"
+	" x\tMaximize the extended partition.\n"
+	" z\tMinimize the extended partition.\n"
+	" u\tChange the display units.\n"
+	" i\tDisplay partition info.\n"
+	" w\tWrite the changes to the disk.\n"
+	" q\tQuit the program.\n"
+	" h\tDisplay this help.\n"
 );
 
 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
 char *info_sectors;
 char *info_cylsize;
 
-int new_table;
-
+int new_table = 0;
+int arrow_cursor = 0;
 
 
 static void
 	mvaddstr(LINES - 2 - MENUSIZE, MENUDIV, title);	
 }
 
-#if 0
-/* TODO: Improve this. */
-void
-display_message (const char *msg) {
-	int y = INFOSIZE+1, x = 0, i,n = strlen(msg);
-	move(y++,0); clrtoeol();
-	mvaddch(y,0,' ');
-	for (x = 1; x < COLS-1; x++) {
-		mvaddch(y,x,'-'); 
-        }
-	mvaddch(y++,x,' ');
-	x = 0;
-	move(y,x);
-	clrtoeol();
-	for (i = 0; i < n; i++) {
-		mvaddch(y,x,msg[i]);
-		if (++x >= COLS) {
-			move(++y,x=0);
-			clrtoeol();
-		}	
-	}
-	while (y++ < LINES-4-MENUSIZE) {
-		move (y,0);
-		clrtoeol();
-	}
-}
-#endif
 
+enum _MsgOpts {
+	DOUBLE_NEW_LINE = 1,
+	/* Ignore space at the beginning of the line */
+	IGNORE_SPACE = 2,
+	/* Use \t to indent the whole text, even after newline */
+	TAB_TO_INDENT = 4
+	
+};
+typedef enum _MsgOpts MsgOpts;
 
 /* This is an ancient magic that turns a char* into a StrList, so we can display it */
 static StrList*
-_message_display_strlist(const char *msg, int *lines, int double_new_line) {
-	int x = 0, y = 0, lastword = 0, isnewline = 0, i;
+_message_display_strlist(const char *msg, int *lines, MsgOpts opts) {
+	int x = 0, y = 0, lastword = 0, isnewline = 0, i, indent = 0;
 	StrList *message = NULL;
 	char buf[SMALLBUF];
 	/* We save the lines in a string list, counting them */
-	/* TODO: It doesn't deal with tabs correctly, I hope we don't need this anyway */
+	/* TODO: It doesn't deal with tabs correctly, this is currently
+           only with tabs in the beginning of the text. */
+	/* NOTE: We calculate indent, even when we don't use it */
 	for (i = 0; msg[i]; i++) {
 		/* If we reached the end of the line, move to the next line */
 		if (x >= SMALLBUF - 1 || x >= COLS-2) {
-			if (isblank(msg[i]) || msg[i] == '\r' || msg[i] == '\n' || !lastword) {
+			if (isblank(msg[i]) || msg[i] == '\r' ||
+			    msg[i] == '\n' || !lastword) {
 				buf[x] = '\0';
 				message = str_list_append(message,buf);
 				y++;
 				/* Real new line is two lines. */
 				if (msg[i] == '\n') { 
-					if (double_new_line) message = str_list_append(message,"");
+					if (opts & DOUBLE_NEW_LINE)
+						message = str_list_append(
+								message,"");
 					y++;
 					isnewline = 1;
 				}
-				lastword = 0;
-				x = 0;
 			}
 			/* If this is not the end of the word, go back to the beginning of the word. */
 			else {
 				message = str_list_append(message,buf);
 				y++;
 				i = i-x+lastword;
-				lastword = 0;
-				x = 0;
+			}
+			lastword = 0;
+			x = 0;
+			/* If the text was indented, move it right */
+			if (msg[i] == '\n')
+				indent = 0;
+			else if ((opts & TAB_TO_INDENT) && indent > 0) {
+				/* If the line is indented */
+				for (; x <= indent && x < SMALLBUF - 1 ; x++) {
+					buf[x] = ' ';
+				}
 			}
 		}
-		/* If the line begins with a blank, skip it */
+		/* We ignore carriage returns */
 		if (msg[i] == '\r') {
 			continue;
 		}
+		/* We indent the text right, if we see a tab */
+		else if (msg[i] == '\t') {
+			lastword = x+1;
+			int n = ((x+9)/9)*9;
+			n = MIN(COLS-2,n);
+			for (; x <= n && x < SMALLBUF - 1; x++) {
+				buf[x] = ' ';
+			}
+			indent += 9;
+			continue;
+		}
+		/* If the line begins with a blank, skip it */
 		else if (isblank(msg[i])) {
-			if (x == 0) continue;
+			if ((opts & IGNORE_SPACE) && x == 0) continue;
 			else lastword = x+1;
 		}
 		else if (msg[i] == '\n') {
 			if (!isnewline) {
 				buf[x] = '\0';
 				message = str_list_append(message,buf);
-				if (double_new_line) message = str_list_append(message,"");
+				if (opts & DOUBLE_NEW_LINE)
+					message = str_list_append(message,"");
 				y += 2;
 			}
 			x = 0;
 			lastword = 0;
+			indent = 0;
 			continue;
 		}
+		
+		
 		isnewline = 0;
 		buf[x] = msg[i];
 		x++;
 display_message (const char* title, const char *msg) {
 	int lines;
 	StrList *message;
-	message = _message_display_strlist(msg,&lines,1);
+	message = _message_display_strlist(msg,&lines,IGNORE_SPACE | DOUBLE_NEW_LINE);
 	_display_strlist(title, message, lines);
 	str_list_destroy(message);
 	
 	move(y++,0); clrtoeol();
 	x = (opts & 1 ? 1 : 7);
 	for (current = strlist, i = 0; current && y < n; current = current->next, i++) {
+		move(y,0); clrtoeol();
 		if (i < *start)
 			continue;
-		if (!(opts & 1) && current == selected)
-			attron(A_STANDOUT);
-		move(y,0); clrtoeol();
+		if (!(opts & 1) && current == selected) {
+			if (arrow_cursor)
+				mvaddstr(y,3,"-->");
+			else
+				attron(A_STANDOUT);
+		}
+		
 		temp = str_list_convert_node(current);
 		mvaddstr(y,x,temp);
 		if (temp) free(temp);
-		if (!(opts & 1) && current == selected)
+		if (!(opts & 1) && current == selected && !arrow_cursor)
 			attroff(A_STANDOUT);
 		y++;
 	}
 	if (!ped_partition_is_flag_available(part,flag))
 		return;
 	move(*y,0); clrtoeol();
-	if (selected == flag)
-		attron(A_STANDOUT);
+	if (selected == flag) {
+		if (arrow_cursor)
+			mvaddstr(*y,3,"-->");
+		else
+			attron(A_STANDOUT);
+	}
 	/* Find suitable text */
 	for (i = 0; labels[i].flag; i++) {
 		if (flag == labels[i].flag) {
 	mvaddch((*y),8,ped_partition_get_flag (part, flag) ? 'X' : ' ');
 	mvaddstr((*y),9,"] ");
 	mvaddstr((*y)++,11,text);
-	if (selected == flag)
+	if (selected == flag && !arrow_cursor)
 		attroff(A_STANDOUT);
 	
 
 
 static int
 action_help () {
-	StrList *message = _message_display_strlist(help,NULL,0);
+	StrList *message = _message_display_strlist(help,NULL,TAB_TO_INDENT);
 	do_strlist(_("cfdisk help"),message,1);
 	str_list_destroy(message);
 	return 1;
 		if (i < *start) continue;	/* If the user has scrolled down, skip hidden */
 
 		int free = part->type & PED_PARTITION_FREESPACE;
-		if (part == selected) attron(A_STANDOUT);
+		if (part == selected) {
+			if (arrow_cursor)
+				mvaddstr(y,0,"-->");
+			else {
+				attron(A_STANDOUT);
+				mvaddstr(y,0,"   ");
+			}
+		} else
+			mvaddstr(y,0,"   ");
 		if (!free)
-			snprintf(buf, SMALLBUF, "%*d%*s", col_name+4,part->num, col_flags-col_name-4, "");
+			snprintf(buf, SMALLBUF, "%*d%*s", 4,part->num, col_flags-col_name-4, "");
 		else
 			snprintf(buf, SMALLBUF, "%*s", col_flags, "");
-		mvaddstr(y,0,buf);
+		mvaddstr(y,col_name,buf);
 		/* ped_partition_get_flag(part, PED_PARTITION_BOOT) throws an exception when ran on a
 		   free space. */
 		snprintf(buf, SMALLBUF, "%-*s", col_type-col_flags,
 		         ped_unit_format (part->disk->dev, part->geom.length));
 		mvaddstr(y++,col_size,buf);
 
-		if (part == selected) attroff(A_STANDOUT);
+		if (part == selected && !arrow_cursor) attroff(A_STANDOUT);
 	}
 	/* Please note that we clean one more line */
 	while (y < n+1) {
 	static struct option long_options[] = {
 		{ "new-table", no_argument, NULL, 'z' },
 		{ "version", no_argument, NULL, 'v' },
+		{ "arrow-cursor", no_argument, NULL, 'a' },
 		{ "units", required_argument, NULL, 'u' },
 		{ "help", no_argument, NULL, 'h' },
 		{ "list-partition-types", no_argument, NULL, 'l' },
 	};
 
 	int opt,option_index;
-	while ((opt = getopt_long(argc,argv, "hzvlu:", long_options, &option_index)) != -1) {
+	while ((opt = getopt_long(argc,argv, "hazvlu:", long_options, &option_index)) != -1) {
 #else
 	int opt;
-	while ((opt = getopt(argc,argv,"hzvlu:")) != -1) {
+	while ((opt = getopt(argc,argv,"hazvlu:")) != -1) {
 #endif		
 		switch (opt) {
 			case 'v':
 				print_usage();
 			case 'l':
 				print_partition_types();
+			case 'a':
+				arrow_cursor = 1;
+				break;
 			case 'z': 
 				new_table = 1;
 				break;

tests/functions.c

 /* I don't believe our tests require this now, but I leave this here */
 #if 0
 long long llrand() {
-	
+
 	/* We assume that long long is always 64 bits and that int is always 32 bits,
 	   as per /usr/include/bits/types.h */
-#define STEP 32;
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define D >>
-#else
-#define D <<
-#endif
 
 	long long result;
 	result = (long long) rand();
-	result = result D STEP;
-	result |= (long long) rand();
+	result *= 4294967296;
+	result += (long long) rand();
 	
 	return result;
 
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.