Commits

Anonymous committed ca934f7

fix compilation error when readline is not found, fix bug in default input, fix error in partition system listing, fix some warnings

  • Participants
  • Parent commits 2c5a558

Comments (0)

Files changed (6)

File configure.ac

 dnl check for libtermcap first
 fdisk_have_libtermcap=0
 AC_CHECK_HEADERS([termcap.h])
-AC_CHECK_LIB( [termcap], [tgetnum], 
-	      [fdisk_have_libtermcap="termcap"], 
-	      [AC_CHECK_LIB( [termlib], [tgetnum], 
-	      		     [fdisk_have_libtermcap="termlib"], 
-			     [fdisk_have_libtermcap="false"])])
+AC_CHECK_LIB( [termcap], [tgetnum], [fdisk_have_libtermcap="termcap"], 
+	[AC_CHECK_LIB( [termlib], [tgetnum], [fdisk_have_libtermcap="termlib"], [fdisk_have_libtermcap="false"])])
 
 if test "$fdisk_have_libtermcap" != "false" ; then
    AC_DEFINE( [HAVE_LIBTERMCAP], 1, [Defined to 1 if you have termcap or termlib library])
 
 dnl check for readline
 fdisk_have_libreadline=0
+
 AC_CHECK_LIB([readline], [readline], [fdisk_have_libreadline=1; LIBS="$LIBS -lreadline";], [fdisk_have_libreadline=0], [])
-AC_DEFINE_UNQUOTED([HAVE_LIBREADLINE], [$fdisk_have_libreadline],
-	[Defined to 1 if your system have readline library])
-AC_CHECK_HEADERS([readline/readline.h readline/history.h])
+AC_CHECK_HEADERS([readline/readline.h readline/history.h], [], [fdisk_have_libreadline=0; break;])
+
+AC_CHECK_TYPES([rl_compentry_func_t], [], [], [
+#if HAVE_LIBREADLINE
+#	include <readline/readline.h>
+# include <readline/history.h>
+#endif
+])
+
+AC_DEFINE_UNQUOTED([HAVE_LIBREADLINE], [$fdisk_have_libreadline], [Defined to 1 if your system have readline library])
+
 dnl <END> readline checking
 
 dnl Check if we have check...

File src/cfdisk.c

 		else
 			snprintf(buf,SMALLBUF,_("An operation is now taking place."));
 		set_status(buf,0);
-		snprintf(buf,SMALLBUF,_("Progress: %3.1f%%   Time left: %4.2d:%.2d"),
+		snprintf(buf,SMALLBUF,_("Progress: %3.1f%%   Time left: %4.2ld:%.2ld"),
 		         100.0 * timer->frac,
 		         tcontext->predicted_time_left / 60,
 		         tcontext->predicted_time_left % 60); 
 print_usage() {
 	int i;
 	char buf[SMALLBUF];
-	printf(_(usage_msg));
+	fputs(_(usage_msg), stdout);
 	printf("\n%s\n",_("OPTIONs:"));
 	for (i = 0; options_help[i].opt; i++) {
 		if (options_help[i].arg)
 
 static void
 print_version() {
-	printf(prog_name);
-	printf(_(license_msg));
+	fputs(prog_name, stdout);
+	fputs(_(license_msg), stdout);
 	exit(0);
 }
 

File src/common.c

 	/* uiquery->getstring free input if it's not NULL */
 	uiquery->getstring(prompt,&input,NULL,NULL,1);
 
+	/* Christian: 
+	 * uiquery->getstring free input and set it to NULL (inserting `printf("**** INPUT: %p\n", input);' here)
+	 *
+	 * Command (m for help): n
+	 * Partition type                                                            
+   *	e   extended
+   *	p   primary partition (1-4)
+	 * p
+	 * First cylinder  (default 0cyl):
+	 * **** INPUT: (nil)
+	 * Command (m for help):
+	 *
+	 * Force */
+
+	if(input == NULL && def_str != NULL)
+		input = strdup(def_str);
 
 	/* def_str might have rounded sector a little bit.  If the user picked
 	 * the default, make sure the selected sector is identical to the
 
 	/* We delete the partitions */
 	for (i = 1; i <= 4; i++) {
-		if (walk = ped_disk_get_partition(disk,i))
+		if ((walk = ped_disk_get_partition(disk,i)) != NULL)
 			ped_disk_delete_partition (disk, walk);
 	}
 
 
 #include <getopt.h>
 
-#if HAVE_READLINE
+#if HAVE_READLINE && HAVE_LIBTERMCAP
 /* This function is defined in ui.c */
 extern void init_termcap_library(void);
-#endif
+#endif /* HAVE_READLINE && HAVE_LIBTERMCAP */
 
 /* Christian <mail.kristian@yahoo.it>
  *
 
 		if (timer->state_name)
 			printf ("%s... ", timer->state_name);
-		printf (_("%0.f%%\t(time left %.2d:%.2d)"),
+		printf (_("%0.f%%\t(time left %.2ld:%.2ld)"),
 			100.0 * timer->frac,
 			tcontext->predicted_time_left / 60,
 			tcontext->predicted_time_left % 60);
 			ped_device_end_external_access((*disk)->dev);
 			return 0;
 		}
-		printf("Reading disklabel of %s at sector %d.\n",
+		printf("Reading disklabel of %s at sector %lld.\n",
 			(*disk)->dev->path, part->geom.start);
 		ped_exception_fetch_all ();
 		label_disk = ped_disk_new(label_dev);
 	/* TODO: Make this output the same output as util-linux fdisk(?),
 	   possibly split into seperate functions */
 	if (compat_mode && !strcmp((*disk)->type->name,"bsd")) {
-		printf ("%s %+10s %+11s %+11s %+4s %+7s ", _("#   "),
+		printf ("%s %10s %11s %11s %4s %7s ", _("#   "),
 		      _("start"), _("end"), _("blocks"), _("id"), _("system"));
 		printf ("\n");
 	}
 		pathlen += fix;
 		for (i = 0; i < (pathlen - 5 - fix); i++)
   		printf (" ");
-		printf ("%s %s %+10s %+11s %+11s %+4s %+7s ", _("Device"),
+		printf ("%s %s %10s %11s %11s %4s %7s ", _("Device"),
 			 _("Boot"), _("Start"), _("End"), _("Blocks"), _("Id"),
 			 _("System"));
 	printf ("\n");
 		}
 
 
-		printf ("%10lld %11lld %11lu ", start, end, blocks);
+		printf ("%10lld %11lld %11lld ", start, end, blocks);
 
 		int type_size;
 		unsigned int part_type = get_disk_specific_system_type (part, &type_size);
 			char *type = (char *)ped_partition_type_get_name (part->type);
 			if (part->fs_type
 				&& !strncmp (part->fs_type->name, "linux-swap", 10))
-				printf ("%+4s %+21s ", _("82"), _("Linux Swap / Solaris"));
+				printf ("%4s %21s ", _("82"), _("Linux Swap / Solaris"));
 			else if (is_bsd_partition ((*disk)->dev->path,
 				part->geom.start * sect_size, sect_size))
-				printf ("%+4s %+17s ", _("a5"), _("Free/Net/OpenBSD"));
+				printf ("%4s %17s ", _("a5"), _("Free/Net/OpenBSD"));
 			else if (!strcmp (type, "primary"))
-				printf ("%+4s %+6s ", _("83"), _("Linux"));
+				printf ("%4s %6s ", _("83"), _("Linux"));
 			else if (!strcmp (type, "extended"))
-				printf ("%+4s %+9s ", _("5"), _("Extended"));
+				printf ("%4s %9s ", _("5"), _("Extended"));
 			ped_device_end_external_access((*disk)->dev);
 		}
 		printf ("\n");
 		input = fdisk_command_line_get_word (prompt, NULL, NULL, 1);
 		if (!input)
 			return 0;
-		if (!strcmp(input,"L") && !strcmp(input,"l")) {
+		if (toupper(*input) == 'L') {
 			free(input);
 			do_list_systypes(disk);
 		}
   mtrace();
 #endif
 
-#if HAVE_READLINE
+#if HAVE_READLINE && HAVE_LIBTERMCAP
   init_termcap_library();
-#endif
+#endif /* HAVE_READLINE && HAVE_LIBTERMCAP */
 
   _init_i18n ();
   

File src/strlist.c

 str_list_destroy_node (StrList* list)
 {
 	/* Warning about qualifyers */
-	free (list->str);
+	/* Christian Cast to void* is safe here */ 
+	free ((void*)list->str);
 	free (list);
 }
 
 /* BEGIN readline stuff */
 #if HAVE_LIBREADLINE
 
-/* Termcap need this buffer to initialize terminal database, I think
-   the db is stored into this buffer but I'm not sure. */
-enum { TERMCAP_BUFFER_SIZE = 2048 };
-static char termcap_buffer[TERMCAP_BUFFER_SIZE] = {0};
+/* If the macro "HAVE_LIBREADLINE corresponds to a digit other than zero
+ * the readline is present along with the respective `readline/readline.h'
+ * and `readline/history.h' header file's */
 
-/* Use this flag to know if termcap is propely initialized
-   and ready or should not be used */
-static enum { TERMCAP_OK, TERMCAP_ERROR } termcap_status;
 
 /* termcap library */
-# if HAVE_TERMCAP_H
-#  include <termcap.h>
-# else
-#  if HAVE_LIBTERMCAP
-    extern int tgetnum (char* key);
-#  endif
-# endif /* HAVE_TERMCAP_H */
+#	if HAVE_LIBTERMCAP
+	/* Termcap need this buffer to initialize terminal database, I think
+	 * the db is stored into this buffer but I'm not sure. */
+		enum { TERMCAP_BUFFER_SIZE = 2048 };
+		static char termcap_buffer[TERMCAP_BUFFER_SIZE] = {0};
 
-/* readline/readline.h */
-# if HAVE_READLINE_READLINE_H
-#  include <readline/readline.h>
-# else
-   extern char * readline ();
-   extern void add_history ();
-# endif /* HAVE_READLINE_READLINE_H */
+		/* Use this flag to know if termcap is propely initialized
+			 and ready or should not be used */
+		static enum { TERMCAP_OK, TERMCAP_ERROR } termcap_status;
+#		if HAVE_TERMCAP_H
+#			include <termcap.h>
+# 	else
+    	extern int tgetnum (char* key);
+#  	endif /* HAVE_TERMCAP_H */
+# endif /* HAVE_LIBTERMCAP */
 
-/* history library */
-# if HAVE_READLINE_HISTORY_H
-#  include <readline/history.h>
-# else
-#  define _add_history_unique add_history
-# endif
+# include <readline/readline.h>
+# include <readline/history.h>
   
-
+/* Both `HAVE_RL_COMPLETION_MATCHES' and `completion_matches' are unused */
+#if 0
 # ifndef HAVE_RL_COMPLETION_MATCHES
 #  define rl_completion_matches completion_matches
 # endif
+#endif /* 0 */
 
-# ifndef rl_compentry_func_t
+# if !HAVE_RL_COMPENTRY_FUNC_T
+	/* cast to (void*) */
 #  define rl_compentry_func_t void
 # endif
 
 static prompt_possibilities = 1;
 
 
-#if HAVE_LIBREADLINE && HAVE_LIBTERMCAP
+#if HAVE_LIBREADLINE
+#	if HAVE_LIBTERMCAP
 /* This function initialize the termcap library */
 void init_termcap_library(void)
 {
  _Error:
   termcap_status = TERMCAP_ERROR;
 }
+#endif /* HAVE_LIBTERMCAP */
 
 /* returns matching commands for text */
 static char*
     return 32768;	/* no wrapping ;) */
 
 /* HACK: don't specify termcap separately - it'll annoy the users. */
-#if HAVE_LIBREADLINE
+#if HAVE_LIBREADLINE && HAVE_LIBTERMCAP
   if(termcap_status == TERMCAP_OK)
     width = tgetnum ("co");
 #endif
 
 #if HAVE_LIBREADLINE
   rl_initialize ();
-  rl_attempted_completion_function = (CPPFunction*) fdisk_complete_function;
+	rl_attempted_completion_function = (CPPFunction*) fdisk_complete_function;
 #endif /* HAVE_LIBREADLINE */
 
   readline_state.in_readline = 0;