bug-fdisk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-fdisk] third patch


From: Christian
Subject: [bug-fdisk] third patch
Date: Mon, 29 Sep 2008 01:26:57 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041221

Hi! I have update todo and maked a patch with the command:
   darcs diff -u > mypatch.patch
I hope this wil be true! ^_^

All the best!
Christian.

diff -rN -u old-_fdisk0/ChangeLog new-_fdisk0/ChangeLog
--- old-_fdisk0/ChangeLog       2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/ChangeLog       2008-09-29 01:17:16.000000000 +0200
@@ -1,7 +1,22 @@
+2008-09-23  Christian   <address@hidden>
+
+       * ui.c: readline support completed with history and copletion
+       * fdisk: getopt and getopt_long support from GNU lib
+       * fdisk.c: better command line option handling
+       * acinclude.m4: moved in m4/check.m4 m4/libparted.m4
+       * configure.ac: add libreadline check
+       
+2008-09-23  gettextize  <address@hidden>
+
+       * Makefile.am (SUBDIRS): Add m4.
+       (EXTRA_DIST): Add autotools/config.rpath autotools/mkinstalldirs.
+       * configure.ac (AC_CONFIG_FILES): Add po/Makefile.in,
+       (AM_GNU_GETTEXT_VERSION): Bump to 0.14.1.
+
 Please see the RCS change log.
 ------------------------------------------------------------------------------
 
-This file is part of GNU fdisk 
+This file is part of GNU fdisk
 Copyright (C) 2006 Free Software Foundation Inc.
 
 This file may be modified and/or distributed without restriction.  This is
diff -rN -u old-_fdisk0/Makefile.am new-_fdisk0/Makefile.am
--- old-_fdisk0/Makefile.am     2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/Makefile.am     2008-09-29 01:17:16.000000000 +0200
@@ -1,12 +1,15 @@
 PACKAGE = @PACKAGE@
 VERSION = @VERSION@
 
-SUBDIRS = po src doc
+# lib for GNULib
+SUBDIRS = m4 po src doc lib
+
 if MAKE_TESTS
 SUBDIRS += tests
 endif MAKE_TESTS
 
-EXTRA_DIST = autotools/config.rpath autotools/mkinstalldirs \
-            ABOUT-NLS AUTHORS THANKS ChangeLog NEWS README fdisk.spec
+EXTRA_DIST = autotools/config.rpath autotools/mkinstalldirs\
+  autotools/config.rpath autotools/mkinstalldirs \
+  ABOUT-NLS AUTHORS THANKS ChangeLog NEWS README fdisk.spec
 
 ACLOCAL_AMFLAGS = -I m4
diff -rN -u old-_fdisk0/TODO new-_fdisk0/TODO
--- old-_fdisk0/TODO    2008-09-29 01:17:16.000000000 +0200
+++ new-_fdisk0/TODO    2008-09-29 01:17:16.000000000 +0200
@@ -1,19 +1,20 @@
 Suggestion:
 Rename cfdisk to gcfdisk and make cfdisk a symlink to it. Add a
-configure option to remove legacy symlinks, so GNU fdisk and util-linux
-counterparts can coexist on one system. This will make it possible for
-GNU/Linux distributions and Live CDs to include GNU fdisk, while leaving
-util-linux tools included.
+configure option to remove legacy symlinks, so GNU fdisk and
+util-linux counterparts can coexist on one system. This will make it
+possible for GNU/Linux distributions and Live CDs to include GNU
+fdisk, while leaving util-linux tools included.
 
+- resolve multiple invocations of AC_CANONICAL_HOST in configure
 - weed out discrepancies between Linux fdisk and this program
-- add readline support
 - "--help" command dumps core (may only occur without readline support)
 - print error message when a disk label that Linux fdisk doesn't support
   is encountered (?)
+- See the source code for others little things
 
 -----------------------------------------------------------------------------
 
-This file is part of GNU fdisk 
+This file is part of GNU fdisk
 Copyright (C) 2006 Free Software Foundation Inc.
 
 This file may be modified and/or distributed without restriction.  This is
diff -rN -u old-_fdisk0/acinclude.m4 new-_fdisk0/acinclude.m4
--- old-_fdisk0/acinclude.m4    2008-09-29 01:17:16.000000000 +0200
+++ new-_fdisk0/acinclude.m4    1970-01-01 01:00:00.000000000 +0100
@@ -1,346 +0,0 @@
-# library paths for libparted
-# written by Damien Genet <address@hidden>
-
-dnl Usage:
-dnl CHECK_LIBPARTED([MINIMUM-VERSION, [ACTION-IF-FOUND [, 
ACTION-IF-NOT-FOUND]]])
-dnl where MINIMUM-VERSION must be >= 1.2.8 and != 1.3.0
-dnl
-dnl Example:
-dnl CHECK_LIBPARTED(1.2.8, , [AC_MSG_ERROR([*** libparted >= 1.2.8 not 
installed - please install first ***])])
-dnl
-dnl Adds the required libraries to $PARTED_LIBS and does an
-dnl AC_SUBST(PARTED_LIBS)
-dnl
-
-
-AC_DEFUN([CHECK_LIBPARTED],
-[
-AC_REQUIRE([AC_CANONICAL_HOST])
-
-dnl save LIBS
-saved_LIBS="$LIBS"
-
-dnl Check for headers and library
-AC_CHECK_HEADER(parted/parted.h, ,
-               [AC_MSG_ERROR([<parted/parted.h> not found; install 
GNU/Parted])]
-               $3)
-AC_CHECK_LIB(uuid, uuid_generate, ,
-            [AC_MSG_ERROR([libuuid not found; install e2fsprogs available at 
http://web.mit.edu/tytso/www/linux/e2fsprogs.html])]
-             $3)
-AC_CHECK_LIB(parted,ped_device_read, ,
-             [AC_MSG_ERROR([libparted not found; install GNU/Parted available 
at http://www.gnu.org/software/parted/parted.html])]
-             $3)
-
-case "$host_os" in
-       gnu*)   # The Hurd requires some special system libraries
-               # with very generic names, which is why we special
-               # case these tests.
-
-               AC_CHECK_LIB(shouldbeinlibc,lcm, ,
-                       [AC_MSG_ERROR([libshouldbeinlibc not found; install the 
Hurd development libraries.])]
-                $3)
-
-               AC_CHECK_LIB(store,store_open, ,
-                       [AC_MSG_ERROR([libstore not found; install the Hurd 
development libraries.])]
-                $3)
-               ;;
-       *)      ;;
-esac
-
-AC_MSG_CHECKING(for libparted - version >= $1)
-
-AC_TRY_LINK_FUNC(ped_get_version,,
-                 AC_MSG_RESULT(failed)
-                 AC_MSG_ERROR([*** libparted < 1.2.8 or == 1.3.0 can't execute 
test ***]))
-
-dnl Get major, minor, and micro version from arg MINIMUM-VERSION
-parted_config_major_version=`echo $1 | \
-    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
-parted_config_minor_version=`echo $1 | \
-    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
-parted_config_micro_version=`echo $1 | \
-    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
-
-dnl Compare MINIMUM-VERSION with libparted version
-AC_TRY_RUN([
-#include <stdio.h>
-#include <stdlib.h>
-#include <parted/parted.h>
-
-int main ()
-{
-       int             major, minor, micro;
-       const char      *version;    
-       
-       if ( !(version = ped_get_version ()) )
-               exit(1);
-       if (sscanf(version, "%d.%d.%d", &major, &minor, &micro) != 3) {
-               printf("%s, bad version string\n", version);
-               exit(1);
-       }
-       
-       if ((major > $parted_config_major_version) ||
-          ((major == $parted_config_major_version) && (minor > 
$parted_config_minor_version)) ||
-          ((major == $parted_config_major_version) && (minor == 
$parted_config_minor_version) && (micro >= $parted_config_micro_version))) {
-               return 0;
-       } else {
-               printf("\n*** An old version of libparted (%s) was found.\n",
-                      version);
-               printf("*** You need a version of libparted equal to or newer 
than %d.%d.%d.\n",
-                       $parted_config_major_version, 
-                       $parted_config_minor_version,
-                       $parted_config_micro_version);
-               printf("*** You can get it at - 
ftp://ftp.gnu.org/gnu/parted/\n";);
-               return 1;
-       }
-}
-], 
-    AC_MSG_RESULT(yes); $2,
-    AC_MSG_RESULT(no) ; $3,
-    [echo $ac_n "cross compiling; assumed OK... $ac_c"])
-
-dnl restore orignial LIBS and set @PARTED_LIBS@
-PARTED_LIBS="$LIBS"
-LIBS="$saved_LIBS"
-AC_SUBST(PARTED_LIBS)
-
-dnl Execute ACTION-IF-FOUND
-$2
-
-])
-
-dnl Usage:
-dnl CHECK_CHECK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
-dnl
-dnl Adds the required libraries to $CHECK_LIBS and $CHECK_CFLAGS does an
-dnl AC_SUBST(CHECK_LIBS) and AC_SUBST(CHECK_CFLAGS)
-dnl
-
-
-AC_DEFUN([CHECK_CHECK],
-[
-AC_REQUIRE([AC_CANONICAL_HOST])
-
-
-AC_ARG_WITH(check,
-       AS_HELP_STRING([--with-check=PATH],
-                      [prefix where check is installed [default=auto]]))
-
-if test x$with_check = xno; then
-
-$3
-
-else
-
-
-
-dnl save LIBS
-saved_LIBS="$LIBS"
-saved_CFGLAGS="$CFLAGS"
-
-if test x$with_check != x; then
-       CFLAGS="$CFLAGS -I$with_check/include"
-       LIBS="$LIBS -L$with_check/lib -lcheck"
-fi
-
-AC_MSG_CHECKING(for check >= $1)
-
-dnl Get major, minor, and micro version from arg MINIMUM-VERSION
-check_config_major_version=`echo $1 | \
-    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
-check_config_minor_version=`echo $1 | \
-    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
-check_config_micro_version=`echo $1 | \
-    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
-
-dnl Compare MINIMUM-VERSION with libparted version
-AC_TRY_RUN([
-#include <stdio.h>
-#include <stdlib.h>
-#include <check.h>
-
-int main ()
-{
-       int             major = CHECK_MAJOR_VERSION,
-                       minor = CHECK_MINOR_VERSION,
-                       micro = CHECK_MICRO_VERSION;
-       const char      *version;    
-       
-
-       if ((major > $check_config_major_version) ||
-          ((major == $check_config_major_version) && (minor > 
$check_config_minor_version)) ||
-          ((major == $check_config_major_version) && (minor == 
$check_config_minor_version) && (micro >= $check_config_micro_version))) {
-
-               return 0;
-       } else {
-               printf(" *** Looked for check version >= %d.%d.%d, found 
%d.%d.%d\n",
-                       $check_config_major_version, 
$check_config_minor_version,
-                       $check_config_micro_version, major, minor, micro);
-               return 1;
-       }
-}
-], 
-    AC_MSG_RESULT(yes),
-    AC_MSG_RESULT(no) ; $3,
-    [echo $ac_n "cross compiling; assumed OK... $ac_c"])
-
-dnl restore orignial LIBS and set @CHECK_LIBS@
-
-if test x$with_check != x; then
-       CHECK_CFLAGS="-I$with_check/include"
-       CHECK_LIBS="-L$with_check/lib -lcheck"
-else
-       CHECK_LIBS="-lcheck"
-       CHECK_CFLAGS=""
-fi
-AC_SUBST(CHECK_LIBS)
-AC_SUBST(CHECK_CFLAGS)
-LIBS="$saved_LIBS"
-
-
-dnl Execute ACTION-IF-FOUND
-$2
-
-fi
-
-])
-
-
-dnl Usage:
-dnl CHECK_CHECK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
-dnl
-dnl Adds the required libraries to $CHECK_LIBS and $CHECK_CFLAGS does an
-dnl AC_SUBST(CHECK_LIBS) and AC_SUBST(CHECK_CFLAGS)
-dnl
-
-
-AC_DEFUN([CHECK_CHECK],
-[
-AC_REQUIRE([AC_CANONICAL_HOST])
-
-
-AC_ARG_WITH(check,
-       AS_HELP_STRING([--with-check=PATH],
-                      [prefix where check is installed [default=auto]]))
-
-if test x$with_check = xno; then
-
-$3
-
-else
-
-
-
-dnl save LIBS
-saved_LIBS="$LIBS"
-saved_CFGLAGS="$CFLAGS"
-
-if test x$with_check != x; then
-       CFLAGS="$CFLAGS -I$with_check/include"
-       LIBS="$LIBS -L$with_check/lib -lcheck"
-fi
-
-AC_MSG_CHECKING(for check >= $1)
-
-dnl Get major, minor, and micro version from arg MINIMUM-VERSION
-check_config_major_version=`echo $1 | \
-    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
-check_config_minor_version=`echo $1 | \
-    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
-check_config_micro_version=`echo $1 | \
-    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
-
-dnl Compare MINIMUM-VERSION with libparted version
-AC_TRY_RUN([
-#include <stdio.h>
-#include <stdlib.h>
-#include <check.h>
-
-int main ()
-{
-       int             major = CHECK_MAJOR_VERSION,
-                       minor = CHECK_MINOR_VERSION,
-                       micro = CHECK_MICRO_VERSION;
-       const char      *version;    
-       
-
-       if ((major > $check_config_major_version) ||
-          ((major == $check_config_major_version) && (minor > 
$check_config_minor_version)) ||
-          ((major == $check_config_major_version) && (minor == 
$check_config_minor_version) && (micro >= $check_config_micro_version))) {
-
-               return 0;
-       } else {
-               printf(" *** Looked for check version >= %d.%d.%d, found 
%d.%d.%d\n",
-                       $check_config_major_version, 
$check_config_minor_version,
-                       $check_config_micro_version, major, minor, micro);
-               return 1;
-       }
-}
-], 
-    AC_MSG_RESULT(yes),
-    AC_MSG_RESULT(no) ; $3,
-    [echo $ac_n "cross compiling; assumed OK... $ac_c"])
-
-dnl restore orignial LIBS and set @CHECK_LIBS@
-
-if test x$with_check != x; then
-       CHECK_CFLAGS="-I$with_check/include"
-       CHECK_LIBS="-L$with_check/lib -lcheck"
-else
-       CHECK_LIBS="-lcheck"
-       CHECK_CFLAGS=""
-fi
-AC_SUBST(CHECK_LIBS)
-AC_SUBST(CHECK_CFLAGS)
-LIBS="$saved_LIBS"
-
-fi
-
-])
-
-
-dnl Usage:
-dnl CHECK_CURSES([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
-dnl
-dnl Example:
-dnl CHECK_CURSES(, AC_MSG_ERROR([ncurses not installed; please install it 
first]))
-dnl
-dnl Adds the required libraries to $CURSES_LIBS and does an
-dnl AC_SUBST(CURSES_LIBS)
-dnl
-
-AC_DEFUN([CHECK_CURSES],
-[
-AC_REQUIRE([AC_CANONICAL_HOST])
-
-dnl save LIBS
-saved_LIBS="$LIBS"
-LIBS=""
-
-
-dnl Check for headers and library
-AC_CHECK_HEADER(ncurses.h, have_ncurses_h=true
-               AC_DEFINE(HAVE_NCURSES_H, 1, [We have the ncurses.h header.]),
-               [AC_CHECK_HEADER(curses.h, 
-               have_ncurses_h=false
-               AC_DEFINE(HAVE_CURSES_H, 1, [We have the curses.h header.]),
-               $2)])
-if test x$have_ncurses_h == xtrue; then
-       AC_CHECK_LIB(ncurses, getch, LIBS="-lncurses"
-               $1 ,
-               $2)
-else
-       AC_CHECK_LIB(curses, getch, LIBS="-lcurses"
-               $1 ,
-               $2)
-fi
-
-
-
-dnl restore orignial LIBS and set @CURSES_LIBS@
-CURSES_LIBS="$LIBS"
-LIBS="$saved_LIBS"
-AC_SUBST(CURSES_LIBS)
-
-
-])
diff -rN -u old-_fdisk0/configure.ac new-_fdisk0/configure.ac
--- old-_fdisk0/configure.ac    2008-09-29 01:17:16.000000000 +0200
+++ new-_fdisk0/configure.ac    2008-09-29 01:17:16.000000000 +0200
@@ -1,10 +1,11 @@
-AC_PREREQ(2.50)
+# 2.59 is needed by GNULib modules
+AC_PREREQ([2.59])
 AC_INIT(fdisk, 1.0, address@hidden)
 AC_CONFIG_AUX_DIR(autotools)
 
 AM_INIT_AUTOMAKE
 AM_CONFIG_HEADER(config.h)
-AM_GNU_GETTEXT_VERSION([0.16.1])
+AM_GNU_GETTEXT_VERSION(0.14.1)
 AM_GNU_GETTEXT([external])
 
 AM_MAINTAINER_MODE
@@ -17,19 +18,26 @@
 AC_PROG_AWK
 AC_LANG_C
 AC_PROG_CC
+
+# add calls for gnulib
+gl_EARLY
+
 AC_PROG_INSTALL
 AC_PROG_LN_S
 
-
+# configure.ac:24: warning: AC_CANONICAL_HOST invoked multiple times (mmm...)
 AC_CANONICAL_HOST
 case "$host_os" in
-       linux*) AC_DEFINE([NAMING_LINUX], [1], [Define 1 if this is an OS with 
Linux naming scheme]) ;;
-       freebsd*) AC_DEFINE([NAMING_BSD], [1], [Define 1 if this is an OS with 
BSD naming scheme]) ;;
+       linux*)
+               AC_DEFINE([NAMING_LINUX], [1], [Define 1 if this is an OS with 
Linux naming scheme]) ;;
+       freebsd*)
+               AC_DEFINE([NAMING_BSD], [1], [Define 1 if this is an OS with 
BSD naming scheme]) ;;
 esac
 
 # Check headers.
-AC_CHECK_HEADERS([ctype.h errno.h stdio.h getopt.h stdarg.h string.h \
-                stdlib.h unistd.h parted/parted.h])
+# getopt.h removed because we already have it;
+AC_CHECK_HEADERS([ctype.h errno.h stdio.h stdarg.h locale.h])
+AC_CHECK_HEADERS([string.h stdlib.h unistd.h parted/parted.h])
 
 # Check for library functions.
 #AC_CHECK_FUNCS([])
@@ -40,17 +48,36 @@
 
 dnl libparted
 # hack
+# LIBS="$LIBS -ldl"
+## better hack
+XLIBS="$LIBS"
 LIBS="$LIBS -ldl"
 CHECK_LIBPARTED([1.7.0], ,
-                       AC_MSG_ERROR([*** libparted >= 1.7.0 not installed - 
please install first ***]))
-
+       AC_MSG_ERROR([*** libparted >= 1.7.0 not installed - please install 
first ***]))
 AC_SUBST(PARTED_LIBS)
-
+LIBS="$XLIBS"
 
 dnl ncurses
 CHECK_CURSES(have_curses=true , have_curses=false)
 AC_SUBST(CURSES_LIBS)
 
+dnl <BEGIN> readline checking
+
+XLIBS="$LIBS"
+LIBS="$XLIBS -ltermcap"
+fdisk_have_libreadline=0
+
+AC_CHECK_LIB(  [readline], [readline],
+       [fdisk_have_libreadline=1; LIBS="$LIBS -lreadline";],
+       [fdisk_have_libreadline=0; LIBS="$XLIBS"], [])
+
+AC_DEFINE_UNQUOTED([HAVE_READLINE], [$fdisk_have_libreadline],
+       [Defined to 1 if your system have readline library])
+
+AC_CHECK_HEADERS([readline/readline.h readline/history.h])
+
+dnl <END> readline checking
+
 dnl Check if we have check...
 
 dnl PKG_CHECK_MODULES([CHECK],[check >= 0.8.2], have_check=true, 
have_check=false)
@@ -91,7 +118,7 @@
      no)  cfdisk=false ;;
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-cfdisk) ;;
    esac],
-   [cfdisk=auto])  
+   [cfdisk=auto])
 
 if test x$cfdisk = xtrue && test x$have_curses != xtrue; then
        AC_MSG_ERROR([*** curses required for cfdisk ***])
@@ -99,6 +126,12 @@
 
 AM_CONDITIONAL(MAKE_CFDISK, test x$cfdisk != xfalse && test x$have_curses = 
xtrue)
 
-AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile tests/Makefile 
po/Makefile.in])
+# add for gnulib
+gl_INIT
+
+# lib/Makefile is for GNULib
+AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile
+ tests/Makefile po/Makefile.in m4/Makefile lib/Makefile])
+
 AC_OUTPUT
 
diff -rN -u old-_fdisk0/po/Makevars new-_fdisk0/po/Makevars
--- old-_fdisk0/po/Makevars     2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/po/Makevars     2008-09-29 01:17:16.000000000 +0200
@@ -1,3 +1,4 @@
+# -*- Makefile -*-
 # Makefile variables for PO directory in any package using GNU gettext.
 
 # Usually the message domain is the same as the package name.
diff -rN -u old-_fdisk0/po/POTFILES.in new-_fdisk0/po/POTFILES.in
--- old-_fdisk0/po/POTFILES.in  2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/po/POTFILES.in  2008-09-29 01:17:16.000000000 +0200
@@ -1,3 +1,5 @@
 # List of source files which contain translatable strings.
 src/common.c
-src/cfdisk.c
\ No newline at end of file
+src/cfdisk.c
+src/fdisk.c
+src/strlist.c
diff -rN -u old-_fdisk0/src/Makefile.am new-_fdisk0/src/Makefile.am
--- old-_fdisk0/src/Makefile.am 2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/src/Makefile.am 2008-09-29 01:17:16.000000000 +0200
@@ -8,6 +8,9 @@
 DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
 LIBS = @LIBINTL@ @LIBS@
 
+AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
+LDADD = $(top_builddir)/lib/libgnu.a
+
 sbin_PROGRAMS =  fdisk
 
 fdisk_SOURCES = main.c         \
diff -rN -u old-_fdisk0/src/command.h new-_fdisk0/src/command.h
--- old-_fdisk0/src/command.h   2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/src/command.h   2008-09-29 01:17:16.000000000 +0200
@@ -30,14 +30,14 @@
        int             (*method) (PedDisk** disk);
        StrList*        summary;
        StrList*        help;
-        int             non_interactive:1;     
+  int non_interactive:1;
 } FdiskCommand;
 
 extern FdiskCommand* fdisk_command_create (const StrList* names,
                                int (*method) (PedDisk** disk),
                                const StrList* summary,
                                const StrList* help,
-                                int non_interactive);
+        int non_interactive);
 extern void fdisk_command_destroy (FdiskCommand* cmd);
 void fdisk_command_register (FdiskCommand** list, FdiskCommand* cmd);
 
diff -rN -u old-_fdisk0/src/common.c new-_fdisk0/src/common.c
--- old-_fdisk0/src/common.c    2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/src/common.c    2008-09-29 01:17:16.000000000 +0200
@@ -59,7 +59,7 @@
 /* TODO: Decide if these should be moved to UICalls */
 StrList *disk_type_list;
 StrList *fs_type_list;
-//StrList *fs_type_resize;
+/*StrList *fs_type_resize;*/
 StrList *fs_type_mkfs;
 StrList *flag_name_list;
 
@@ -231,14 +231,14 @@
 }
 
 /* This function returns the number of a metadata sectors, which are needed
-   after a partition, for example, in msdos partition table, the sector, 
+   after a partition, for example, in msdos partition table, the sector,
    after a logical partition, describes the next logical partition */
 static PedSector metadata_tail_sectors(PedPartition *part) {
        /* TODO: Make this support other partition types */
        if (part == NULL || part->disk->type == NULL)
                return 0;
-       
-       if (!strcmp(part->disk->type->name, "msdos") 
+
+       if (!strcmp(part->disk->type->name, "msdos")
              && part->type & PED_PARTITION_LOGICAL) {
                return 1;
        }
@@ -420,7 +420,7 @@
 /* This function makes a range less strict... */
 /* FIXME: Make this in a better way */
 static void
-fuzzify (PedGeometry *geom, PedDevice *dev, PedConstraint *constraint, 
+fuzzify (PedGeometry *geom, PedDevice *dev, PedConstraint *constraint,
         PedSector before, PedSector after) {
        PedGeometry *new_geom;
        if (!constraint)
@@ -437,7 +437,7 @@
 }
 /* This functions constructs a constraint from the following information:
  *      start, is_start_exact, end, is_end_exact.
- *      
+ *
  * If is_start_exact == 1, then the constraint requires start be as given in
  * "start".  Otherwise, the constraint does not set any requirements on the
  * start.
@@ -485,11 +485,11 @@
                if (*start != new_geom->start || *end != new_geom->end) {
                        *start = new_geom->start;
                        *end = new_geom->end;
-                       
+
                }
                ped_geometry_destroy(new_geom);
                return 1;
-       } 
+       }
 
        return 0;
 
@@ -530,7 +530,7 @@
                if (sector < 0LL)
                        sector = 0LL;
        }
- 
+
        if (end >= dev->length) {
                end = dev->length - 1LL;
                if (sector >= dev->length)
@@ -541,7 +541,7 @@
                return 0;
        value->sector = sector;
        return 1;
-       
+
 }
 
 #define ESC    '\033'  /* ^[ */
@@ -552,7 +552,7 @@
 query_part_position(const char* prompt, const void* context, PartPos *pos,
                     PedSector first, PedSector last, PedDevice *dev,
                     PedConstraint *constraint, UIOpts *opts) {
-       
+
        PedSector length = pos->end.sector - pos->start.sector + 1LL;
        PedSector min_len = 0, max_len = dev->length;
        PedGeometry *range = NULL;
@@ -565,14 +565,14 @@
 
        i = 0;
        /* If we have a constraint, check whether we can move the partition 
start */
-       if (constraint && (constraint->start_align->grain_size == 0 || 
+       if (constraint && (constraint->start_align->grain_size == 0 ||
                           constraint->start_range->length == 1))
                where = 's';
        else {
        /* If there the first possible sector is not the start of the selected 
partition,
        we need one choice in the menu to make the start fixed and one to move 
it back.
        When it is, 'b' and 's' do the same. We ditch 'b' for more friendly 
resize menu,
-       action_new should use 's' as it doesn't matter there. 
+       action_new should use 's' as it doesn't matter there.
        FIXME: I wrote this fragment better, but ruined it. Now I'm too lazy to 
fix it */
                if (first < pos->start.sector) possibilities[i++] = 'b';
                possibilities[i++] = 's';
@@ -618,7 +618,7 @@
                                        if (def_str) ped_free(def_str);
                                        return 0;
                                }
-       
+
                                done = 1;
                                /* Get the new size only if the user modified 
it */
                                if(strcmp(temp,def_str)) {
@@ -665,7 +665,7 @@
                                                        last-63LL, 64LL);
 
                                pos->end.sector = last;
-                               /* Desired: start = last-length+1LL */ 
+                               /* Desired: start = last-length+1LL */
                                pos->start.sector = length;
                                pos->start.range = range;
                                
move_sector(dev,&(pos->start),last-2*length+1LL);
@@ -681,7 +681,7 @@
                }
        }
        return 1;
-       
+
 }
 
 int
@@ -729,9 +729,9 @@
 get_partition (const char* prompt, PedDisk* disk, PedPartition** value)
 {
        PedPartition*   part;
-       int             num; 
+       int             num;
        char            buf[SMALLBUF];
-       if (!disk) 
+       if (!disk)
                return 0;
        if (!uiquery->getpart) {
                snprintf(buf,SMALLBUF,_("%s number (1-%d)"),
@@ -782,7 +782,7 @@
                free (disk_type_name);
                if (!disk_type)
                        return 0;
-               
+
        } else {
                if (!uiquery->getdisktype(prompt, &disk_type)) return 0;
        }
@@ -820,7 +820,7 @@
        }
 
        status = uiquery->getstring(prompt,&type_name,opts,locopts,-1);
-       
+
        str_list_destroy (opts);
        str_list_destroy (locopts);
        if (!status) {
@@ -927,7 +927,7 @@
                return 0;
        }
        free (flag_name);
-       
+
        *value = flag;
        return 1;
 }
@@ -937,7 +937,7 @@
    we want to query sector when UI_CUSTOM_VALUES is specified */
 typedef enum {
        /* Query the user for a new sector */
-       GET_SECT = UI_CUSTOM_VALUES, 
+       GET_SECT = UI_CUSTOM_VALUES,
        /* Initialise the range */
        NO_RANGE = UI_CUSTOM_VALUES*2,
        /* We are looking where to place the start of a new partition */
@@ -949,7 +949,7 @@
 
 
 /* This function gets sector. The prev option specifies
-   the previous selected sector, used if the user 
+   the previous selected sector, used if the user
    wants to specify a size, not a position */
 static int
 get_sector (const char* prompt, PedDevice* dev, SectPos *value,
@@ -959,7 +959,7 @@
        char*   input = NULL;
        char*   buf;
        int     valid;
-       
+
        /* If the user should be queried about the sector and a range needs to
           be initialised, initialise one with a length of 1 sector, but please,
           when using this function, NOTE that this is not always enough */
@@ -972,10 +972,10 @@
        }
 
        def_str = ped_unit_format (dev, value->sector);
-       if (def_str) 
+       if (def_str)
                input = strdup(def_str);
        uiquery->getstring(prompt,&input,NULL,NULL,1);
-       
+
 
        /* def_str might have rounded sector a little bit.  If the user picked
         * the default, make sure the selected sector is identical to the
@@ -1008,7 +1008,7 @@
        /* If the string starts with +, interpret as size */
        if (prev >= 0 && input[0] == '+') {
                /* TODO: Improve */
-               SectPos pos; 
+               SectPos pos;
                /* We parse it into a SectPos */
                buf = calloc(128,sizeof(char));
                valid = sscanf(input, "+%127s", buf);
@@ -1032,7 +1032,7 @@
                } else {
                        ped_geometry_destroy(pos.range);
                }
-               
+
        } else {
                valid = ped_unit_parse(input, dev, &(value->sector),
                                                   &(value->range));
@@ -1044,7 +1044,7 @@
 /* Looks for the first suitable free space for a new partition */
 place_part_start(PedDisk *disk, PartPos *pos, PedPartitionType type) {
        PedPartition *part = NULL;
-       type = (type & PED_PARTITION_LOGICAL) | PED_PARTITION_FREESPACE; 
+       type = (type & PED_PARTITION_LOGICAL) | PED_PARTITION_FREESPACE;
        for (part = ped_disk_next_partition(disk, NULL);
             part; part = ped_disk_next_partition(disk,part)) {
                if (part->type == type) {
@@ -1061,12 +1061,12 @@
 static int
 place_part_end(PedDisk *disk, PartPos *pos) {
        PedPartition *part = ped_disk_get_partition_by_sector(disk,
-                                                       pos->start.sector); 
+                                                       pos->start.sector);
        if (part->type & PED_PARTITION_FREESPACE) {
                pos->end.sector = part->geom.end;
                pos->end.range = ped_geometry_new (disk->dev,
                                        part->geom.end - 7LL, 8LL);
-               return 1;       
+               return 1;
        }
        else
                return 0;
@@ -1074,7 +1074,7 @@
 
 
 /* Do not confuse this with query_part_position, this queries the user for
-   start and end of the partition and is called from the functions in here */ 
+   start and end of the partition and is called from the functions in here */
 static int
 get_position(PartPos* pos, PedDisk *disk, GSOpts opts)
 {
@@ -1137,7 +1137,7 @@
                 return 0;
         if (!ped_file_system_check (fs, uiquery->timer)) {
                ped_file_system_close (fs);
-               return 0;       
+               return 0;
        }
 
         ped_file_system_close (fs);
@@ -1157,22 +1157,22 @@
         PedFileSystem*          src_fs;
         PedFileSystem*          dst_fs;
         PedFileSystemType*      dst_fs_type;
-       
+
        if (!dst_disk)
                 goto error;
 
        if (opts & UI_WARN_COMMIT)
-               if (!ask_boolean_question 
-               (_("WARNING: This writes all data to disk automatically, 
continue?"))) 
+               if (!ask_boolean_question
+               (_("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 && !perform_commit(dst_disk,UI_DEFAULT)) goto 
error;
-        
+
 
         src_disk = dst_disk;
        if (!get_disk (_("Source device"), &src_disk))
                goto error_destroy_disk;
-        
+
 
         if (!get_partition (_("Source partition"),src_disk, &src))
                 goto error_destroy_disk;
@@ -1253,7 +1253,7 @@
         *disk = ped_disk_new_fresh (dev, type);
         if (!*disk)
                 goto error;
-       
+
         /*if (!ped_disk_commit (*disk))
                 goto error;*/
        uiquery->need_commit = 1;
@@ -1272,8 +1272,8 @@
         PedFileSystem*          fs;
        PedConstraint*          constraint = NULL;
        if (opts & UI_WARN_COMMIT) {
-               if (!ask_boolean_question 
-               (_("WARNING: This writes all data to disk automatically, 
continue?"))) 
+               if (!ask_boolean_question
+               (_("WARNING: This writes all data to disk automatically, 
continue?")))
                        return 0;
        }
 
@@ -1352,7 +1352,7 @@
         char*                    part_name = NULL;
         char                     *start_usr = NULL, *end_usr = NULL;
         char                     *start_sol = NULL, *end_sol = NULL;
-        
+
         if (!disk)
                 goto error;
 
@@ -1365,7 +1365,7 @@
                         goto error;
         }
 
-            
+
         if (part_type == PED_PARTITION_EXTENDED) {
                if (opts & UI_MAKEPARTFS) {
                        ped_exception_throw (PED_EXCEPTION_ERROR, 
PED_EXCEPTION_CANCEL,
@@ -1383,8 +1383,8 @@
 
 
         if (ped_disk_type_check_feature (disk->type,
-                                         PED_DISK_TYPE_PARTITION_NAME)) 
-                uiquery->getstring(_("Partition name"), &part_name, NULL, 
NULL, 1); 
+                                         PED_DISK_TYPE_PARTITION_NAME))
+                uiquery->getstring(_("Partition name"), &part_name, NULL, 
NULL, 1);
 
 
        if ((opts & UI_CUSTOM_VALUES) &&
@@ -1404,7 +1404,7 @@
         if (!part)
                 goto error;
 
-       /* Check if the partition occupying the space before the place we 
+       /* Check if the partition occupying the space before the place we
           are trying to put this one, requires a metadata sectors after it,
           and if so, increase the range of the constraint */
 
@@ -1414,7 +1414,7 @@
                        disk_get_prev_nmd_partition(
                                disk,
                                ped_disk_get_partition_by_sector(
-                                       disk, 
+                                       disk,
                                        pos->start.sector
                                )
                        )
@@ -1442,15 +1442,15 @@
         if (!ped_disk_add_partition (disk, part, final_constraint)) {
                ped_exception_catch();
                 ped_exception_leave_all();
-               
+
                 if (ped_disk_add_partition (disk, part,
                                         ped_constraint_any (disk->dev))) {
                         start_usr = ped_unit_format (disk->dev, 
pos->start.sector);
                         end_usr   = ped_unit_format (disk->dev, 
pos->end.sector);
                         start_sol = ped_unit_format (disk->dev, 
part->geom.start);
                         end_sol   = ped_unit_format (disk->dev, 
part->geom.end);
-                       /* TODO: With the changes from 06/08/06, we might 
remove 
-                          the "if" and warn the user always if this is out of 
+                       /* TODO: With the changes from 06/08/06, we might remove
+                          the "if" and warn the user always if this is out of
                           range */
                        if (opts & UI_CUSTOM_VALUES)
                                switch (ped_exception_throw (
@@ -1522,22 +1522,22 @@
                 goto error;
         if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
                 ped_partition_set_flag (part, PED_PARTITION_LBA, 1);
-        
+
         /*if (!ped_disk_commit (disk))
                 goto error;*/
        uiquery->need_commit = 1;
-        
+
         /* clean up */
         ped_constraint_destroy (final_constraint);
         ped_constraint_destroy (user_constraint);
         ped_constraint_destroy (dev_constraint);
 
-        
+
         if (pos->start.range != NULL)
                 ped_geometry_destroy (pos->start.range);
         if (pos->end.range != NULL)
                 ped_geometry_destroy (pos->end.range);
-        
+
         if (start_usr != NULL)
                 ped_free (start_usr);
         if (end_usr != NULL)
@@ -1585,13 +1585,13 @@
 
         PedPartition*            part = NULL;
 
-        
+
         if (!disk)
                 return 0;
 
        if (opts & UI_WARN_COMMIT) {
-               if (!ask_boolean_question 
-               (_("WARNING: This writes all data to disk automatically, 
continue?"))) 
+               if (!ask_boolean_question
+               (_("WARNING: This writes all data to disk automatically, 
continue?")))
                        return 0;
        }
 
@@ -1613,7 +1613,7 @@
 int
 perform_move (PedDisk *disk,  PedPartition* part, PartPos *pos, UIOpts opts)
 {
-       
+
         PedFileSystem*  fs;
         PedFileSystem*  fs_copy;
         PedConstraint*  constraint;
@@ -1622,10 +1622,10 @@
 
         if (!disk)
                 goto error;
-       
+
        if (opts & UI_WARN_COMMIT) {
-               if (!ask_boolean_question 
-               (_("WARNING: This writes all data to disk automatically, 
continue?"))) 
+               if (!ask_boolean_question
+               (_("WARNING: This writes all data to disk automatically, 
continue?")))
                        return 0;
        }
        /* So the best we can do here is to commit */
@@ -1671,7 +1671,7 @@
                         ped_file_system_get_copy_constraint (fs, disk->dev),
                         constraint_from_start_end (disk->dev, pos->start.range,
                                                    pos->end.range));
-       /* So here we do something worth commiting and dangerous. UI *must* 
+       /* So here we do something worth commiting and dangerous. UI *must*
           do something if we fail and need_commit is true... */
        uiquery->need_commit = 1;
         if (!ped_disk_set_partition_geom (disk, part, constraint,
@@ -1729,7 +1729,7 @@
        int n;
         if (!disk)
                 goto error;
-       if (!part) 
+       if (!part)
                if (!get_partition (_("Partition"), disk, &part))
                        goto error;
        if (!name) {
@@ -1917,8 +1917,8 @@
         if (!disk)
                 goto error;
        if (opts & UI_WARN_COMMIT)
-               if (!ask_boolean_question 
-               (_("WARNING: This writes all data to disk automatically, 
continue?"))) 
+               if (!ask_boolean_question
+               (_("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)
@@ -1969,13 +1969,13 @@
         if (!disk)
                 goto error;
 
-       if (!part) 
+       if (!part)
                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?"))) 
+               if (opts & UI_WARN_COMMIT && !ask_boolean_question
+               (_("WARNING: This writes all data to disk automatically, 
continue?")))
                        return 0;
                if (uiquery->need_commit)
                        if (!perform_commit(disk,UI_DEFAULT))
@@ -1988,7 +1988,7 @@
         }
 
        if (!get_position(pos, disk,opts & UI_CUSTOM_VALUES))
-               goto error; 
+               goto error;
 
        /* FIXME: This is most likely not needed */
        //if (!(opts & UI_CUSTOM_VALUES) && (opts & UI_NO_FS_RESIZE)) {
@@ -2015,7 +2015,7 @@
                         goto error_destroy_constraint;
                if (part->type == PED_PARTITION_EXTENDED)
                        ped_partition_set_system (part, NULL);
-               
+
                uiquery->need_commit = 1;
         } else {
                fs = ped_file_system_open (&part->geom);
@@ -2062,19 +2062,19 @@
 int
 perform_rm (PedDisk* disk, PedPartition* part)
 {
-       
 
-  
+
+
         if (!disk)
                 goto error;
-       if (!part) 
+       if (!part)
                if (!get_partition (_("Partition"), disk, &part))
                        goto error;
         if (!_partition_warn_busy (part))
                 goto error;
        if (!_warn_ext_not_empty (part))
                goto error;
-               
+
         ped_disk_delete_partition (disk, part);
         uiquery->need_commit = 1;
         return 1;
@@ -2142,12 +2142,12 @@
                if (!get_part_flag (_("Flag to change"), part, &flag))
                        goto error;
         state = (ped_partition_get_flag (part, flag) == 0 ? 1 : 0);
-        
+
         if (!(opts & UI_FLAG_TOGGLE)) {
                 if (!uiquery->getbool (_("New state"), &state))
                            goto error;
         }
-    
+
         if (!ped_partition_set_flag (part, flag, state))
                        goto error;
        uiquery->need_commit = 1;
@@ -2162,8 +2162,8 @@
 perform_commit (PedDisk* disk, UIOpts opts)
 {
        if (opts & UI_WARN_COMMIT)
-               if (!ask_boolean_question 
-                       (_("WARNING: This writes all data to disk, 
continue?"))) 
+               if (!ask_boolean_question
+                       (_("WARNING: This writes all data to disk, continue?")))
                                return 0;
        if (ped_disk_commit(disk)) {
                uiquery->need_commit = 0;
@@ -2210,10 +2210,10 @@
                                        data->geom.start, data->geom.end);
 
        range_start = ped_geometry_new (disk->dev,data->geom.start, 1);
-       range_end = ped_geometry_new (disk->dev,data->geom.end, 1); 
+       range_end = ped_geometry_new (disk->dev,data->geom.end, 1);
        constraint = constraint_from_start_end(disk->dev,
                                                range_start,range_end);
-       memcpy(part->disk_specific, data->part_data, DOS_DATA_SIZE); 
+       memcpy(part->disk_specific, data->part_data, DOS_DATA_SIZE);
        success = ped_disk_add_partition (disk, part, constraint);
 
        if (constraint) ped_constraint_destroy(constraint);
@@ -2231,7 +2231,7 @@
                ped_exception_throw(PED_EXCEPTION_NO_FEATURE,
                                    PED_EXCEPTION_CANCEL,
                                    _("Fixing partition order on %s partition "
-                                     "label type not implemented."), 
+                                     "label type not implemented."),
                                    disk->type->name);
                return 0;
        }
@@ -2259,15 +2259,15 @@
                                break;
                        }
                }
-       }       
-       if (i != -1 && j != -1) 
+       }
+       if (i != -1 && j != -1)
                return 1;
 
        /* We make sure that there are no mounted partitions */
        for (i = 1; i <= 4; i++) {
                walk = ped_disk_get_partition(disk,i);
                if (walk && !_partition_warn_busy(walk))
-                       return 0; 
+                       return 0;
        }
 
        /* We will issue warning to the user for now */
@@ -2282,8 +2282,8 @@
        struct DOSGeomList *pdata = NULL;
        struct DOSGeomList **ptr = &partitions;
 
-       
-       
+
+
 
        /* We save the partitions */
        for (walk = ped_disk_next_partition(disk,NULL); walk;
@@ -2316,7 +2316,7 @@
                _fix_order_add_part(disk, pdata);
                pdata = pdata->next;
        }
-       
+
        /* We clear the saved data */
        pdata = partitions;
        while (pdata) {
@@ -2325,7 +2325,7 @@
                free(pdata);
                pdata = next;
        }
-               
+
        /* We're done */
        uiquery->need_commit = 1;
        return 1;
@@ -2344,7 +2344,7 @@
        sscanf(part_chs, "%d,%d,%d", &end_cyl, &end_head, &end_sector);
        ped_free(part_chs);
 
-       /* If, for example, this is a msdos logical partition, it has a 
+       /* If, for example, this is a msdos logical partition, it has a
            tail of one sector, specifying the next partition. */
        tail = metadata_tail_sectors(part);
 
@@ -2398,7 +2398,7 @@
         PedPartitionFlag        flag;
         int                     first_flag;
         const char*             name;
-        char*                   res = ped_malloc(1); 
+        char*                   res = ped_malloc(1);
         void*                   _res = res;
 
         *res = '\0';
@@ -2492,7 +2492,7 @@
 {
        int count = 0;
        PedPartition *walk;
-       for (walk = ped_disk_next_partition (disk, NULL); walk; 
+       for (walk = ped_disk_next_partition (disk, NULL); walk;
             walk = ped_disk_next_partition (disk, walk)) {
                if (walk->type & (PED_PARTITION_FREESPACE | 
PED_PARTITION_METADATA))
                        continue;
diff -rN -u old-_fdisk0/src/fdisk.c new-_fdisk0/src/fdisk.c
--- old-_fdisk0/src/fdisk.c     2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/src/fdisk.c     2008-09-29 01:17:16.000000000 +0200
@@ -25,14 +25,15 @@
 #include "command.h"
 #include "ui.h"
 
+/* From gettextize */
+#include "gettext.h"
+
+#if HAVE_LOCALE_H
+# include <locale.h>
+#endif /* HAVE_LOCALE_H */
+
 #define N_(String) String
-#if ENABLE_NLS
-#  include <libintl.h>
-#  include <locale.h>
-#  define _(String) dgettext (PACKAGE, String)
-#else
-#  define _(String) (String)
-#endif /* ENABLE_NLS */
+#define _(String) dgettext (PACKAGE, String)
 
 #include <parted/parted.h>
 #include <parted/debug.h>
@@ -49,7 +50,6 @@
 #include <mcheck.h>
 #endif
 
-#ifdef HAVE_GETOPT_H
 #include <getopt.h>
 
 /* minimum amount of free space to leave, or maximum amount to gobble up,
@@ -68,52 +68,46 @@
 } TimerContext;
 
 
-/* NOTE: options and options_help MUST be in the same order and count */
-static struct option   options[] = {
-       /* name, has-arg, string-return-val, char-return-val */
-       {"help",        0, NULL, 'h'},
-       {"list",        0, NULL, 'l'},
-       {"raw-print",   0, NULL, 'r'},
-       {"size",        1, NULL, 's'},
+/* I have created this struct to store options (in short and long form)
+ * and help in the same variable. The struct option array, wich is
+ * needed for getopt_long is build dynamically by build_option_table()
+ * using this array. We can add options here there isn't problems
+ * with getopt_long() */
+struct {
+       char *id;
+       int has_arg;
+       int *flag;
+       int val;
+       char *help;
+} extd_options[] = {
+  /* name   has_arg      flag  val  help */
+       { "help", no_argument, NULL, 'h', "displays this help message"},
+       { "list", no_argument, NULL, 'l', "list partition table(s)"},
+       { "raw-print", no_argument, NULL, 'r', "show the raw data in the 
partition table(s)"},
+       { "size", required_argument, NULL, 's', "show partition size"},
 #ifdef GNU_EXT
-       {"linux-fdisk", 0, NULL, 'L'},
-       {"gnu-fdisk",   0, NULL, 'G'},
-#endif
-       {"interactive", 0, NULL, 'i'},
-       {"script",      0, NULL, 'p'},
-       {"sector-units",0, NULL, 'u'},
-       {"sector-size", 1, NULL, 'b'},
-       {"cylinders",   1, NULL, 'C'},
-       {"heads",       1, NULL, 'H'},
-       {"sectors",     1, NULL, 'S'},
-       {"list-partition-types", 0, NULL, 't'},
-       {"version",     0, NULL, 'v'},
-       {NULL,          0, NULL, 0}
+       {       "linux-fdisk", no_argument, NULL, 'L', "enable Linux fdisk 
compatibility mode"},
+       { "gnu-fdisk", no_argument, NULL, 'G', "disable Linux fdisk 
compatibility mode"},
+#endif /* GNU_EXT */
+       { "interactive", no_argument, NULL, 'i', "where necessary, prompts for 
user intervention"},
+       { "script", no_argument, NULL, 'p', "never prompts for user 
intervention"},
+       { "sector-units", no_argument, NULL, 'u', "use sectors instead of 
cylinder as a default unit"},
+       { "sector-size", required_argument, NULL, 'b', "specify the sector size 
in bytes"},
+       { "cilyndres", required_argument, NULL, 'C', "specify the number of 
cylinders, actually does nothing"},
+       { "heads", required_argument, NULL, 'H', "in lfdisk, specify the number 
of heads of the disk"},
+       { "sectors", required_argument, NULL, 'S', "in lfdisk, specify the 
number of sectors per track"},
+       { "list-partition-types", no_argument, NULL, 't', "displays a list of 
supported partition types"},
+       { "version", no_argument, NULL, 'v', "displays the version"},
+
+       /* Last element must be NULL */
+       { NULL, 0, NULL, 0, NULL}
 };
-#endif
 
 
-/* NOTE: options and options_help MUST be in the same order and count */
-static char*   options_help [][2] = {
-       {"help",        N_("displays this help message")},
-       {"list",        N_("list partition table(s)")},
-       {"raw-print",   N_("show the raw data in the partition table(s)")},
-       {"size",        N_("show partition size")},
-#ifdef GNU_EXT
-       {"linux-fdisk", N_("enable Linux fdisk compatibility mode")},
-       {"gnu-fdisk",   N_("disable Linux fdisk compatibility mode")},
-#endif
-       {"interactive", N_("where necessary, prompts for user intervention")},
-       {"script",      N_("never prompts for user intervention")},
-       {"sector-units",N_("use sectors instead of cylinder as a default 
unit")},
-       {"sector-size", N_("specify the sector size in bytes")},
-       {"cylinders",   N_("specify the number of cylinders, actually does 
nothing")},
-       {"heads",       N_("in lfdisk, specify the number of heads of the 
disk")},
-       {"sectors",     N_("in lfdisk, specify the number of sectors per 
track")},
-       {"list-partition-types", N_("displays a list of supported partition 
types")},
-       {"version",     N_("displays the version")},
-       {NULL,          NULL}
-};
+/* String to use whit getopt() or getopt_long() if you update extd_options[] 
you must
+ * also add option in short form to this string
+   NOTE: I will make function to build dynamic in the future */
+static const char* short_option_string = "hlipvLGs:utb:C:H:S:r";
 
 #ifdef GNU_EXT
 int fdisk_compatibility_mode = 0;
@@ -181,7 +175,7 @@
 
 static void _done (PedDevice* dev);
 
-/* Timer handler and other UI functions */ 
+/* Timer handler and other UI functions */
 static void
 _timer_handler (PedTimer* timer, void* context)
 {
@@ -214,8 +208,6 @@
        }
 }
 
-
-
 static int
 getstring (const char* prompt, char** value, const StrList* words,
           const StrList* locwords, int multi_word)
@@ -274,7 +266,7 @@
 }
 /* We don't need this one
 static int
-(*getint) (const char* prompt, int* value) = fdisk_command_line_get_integer; 
+(*getint) (const char* prompt, int* value) = fdisk_command_line_get_integer;
 */
 
 #if 0
@@ -481,7 +473,7 @@
 
 /* This functions constructs a constraint from the following information:
  *     start, is_start_exact, end, is_end_exact.
- *     
+ *
  * If is_start_exact == 1, then the constraint requires start be as given in
  * "start".  Otherwise, the constraint does not set any requirements on the
  * start.
@@ -503,21 +495,21 @@
        return result;
 }
 #endif
-static void 
-help_on (char* topic) 
-{ 
-        FdiskCommand*  cmd; 
-  
-        cmd = fdisk_command_get (fdisk_main_menu_commands, topic); 
+static void
+help_on (char* topic)
+{
+        FdiskCommand*  cmd;
+
+        cmd = fdisk_command_get (fdisk_main_menu_commands, topic);
         if (!cmd) return;
-  
-        fdisk_command_print_help (cmd); 
+
+        fdisk_command_print_help (cmd);
 }
 
 
 static int
 _disk_reread(PedDisk **disk) {
-       
+
        PedDevice *dev = (*disk)->dev;
 
        ped_disk_destroy(*disk);
@@ -539,33 +531,19 @@
        return perform_cp(*disk,NULL,UI_WARN_COMMIT);
 }
 
-/* FIXME: Doesn't work correctly without getopt.h */
-void 
+void
 fdisk_print_options_help ()
-{ 
-        int            i; 
-#ifdef HAVE_GETOPT_H
-       for (i=0; options_help [i][0] && options[i].val; i++) {
-#else 
-#warning Printing help without getopt.h is broken. Fix it.
-       for (i=0; options_help [i][0]; i++) {
-#endif
-               printf ("  -%c, --%-23.23s %s\n",
-#ifdef HAVE_GETOPT_H 
-                       options [i].val,
-#else
-                       options[i][0][0],
-#endif 
-                       options_help [i][0], 
-                       _(options_help [i][1])); 
-       } 
+{
+       unsigned int i;
+       for(i=0; extd_options[i].id != NULL; i++)
+               printf("  -%c, --%-23.23s %s\n", extd_options[i].val, 
extd_options[i].id, _(extd_options[i].help));
 }
 
 void
 fdisk_print_commands_help (FdiskCommand* cmds[])
 {
         int            i;
-  
+
        if (cmds) {
                for (i=0; cmds [i]; i++)
                        fdisk_command_print_summary (cmds [i]);
@@ -588,7 +566,7 @@
 static int
 do_help(PedDisk** disk)
 {
-       printf (_("Command action\n"));
+       puts(_("Command action"));
        if (in_menu == 0)
                fdisk_print_commands_help(fdisk_main_menu_commands);
        else if (in_menu == 1)
@@ -601,9 +579,9 @@
 static int
 do_msdos_mklabel (PedDisk** disk)
 {
-       PedDevice               *dev = (*disk)->dev; /* Save the address of 
dev, 
-                                                       because we are going to 
-                                                       destroy disk. */ 
+       PedDevice               *dev = (*disk)->dev; /* Save the address of dev,
+                                                       because we are going to
+                                                       destroy disk. */
        const PedDiskType*      type = ped_disk_type_get ("msdos");
 
        return perform_mklabel(dev,disk,type);
@@ -612,9 +590,9 @@
 static int
 do_sun_mklabel (PedDisk** disk)
 {
-       PedDevice               *dev = (*disk)->dev; /* Save the address of 
dev, 
-                                                       because we are going to 
-                                                       destroy disk. */ 
+       PedDevice               *dev = (*disk)->dev; /* Save the address of dev,
+                                                       because we are going to
+                                                       destroy disk. */
        const PedDiskType*      type = ped_disk_type_get ("sun");
 
                return perform_mklabel(dev,disk,type);
@@ -623,9 +601,9 @@
 static int
 do_dvh_mklabel (PedDisk** disk)
 {
-       PedDevice               *dev = (*disk)->dev; /* Save the address of 
dev, 
-                                                       because we are going to 
-                                                       destroy disk. */ 
+       PedDevice               *dev = (*disk)->dev; /* Save the address of dev,
+                                                       because we are going to
+                                                       destroy disk. */
        const PedDiskType*      type = ped_disk_type_get ("dvh");
 
        return perform_mklabel(dev,disk,type);
@@ -634,9 +612,9 @@
 static int
 do_mklabel (PedDisk** disk)
 {
-       PedDevice               *dev = (*disk)->dev; /* Save the address of 
dev, 
-                                                       because we are going to 
-                                                       destroy disk. */ 
+       PedDevice               *dev = (*disk)->dev; /* Save the address of dev,
+                                                       because we are going to
+                                                       destroy disk. */
        const PedDiskType*      type = ped_disk_probe (dev);
 
 
@@ -659,9 +637,9 @@
        const PedFileSystemType *fs_type = ped_file_system_type_get ("ext2");
        char*                    peek_word;
        UIOpts                   opts = UI_CUSTOM_VALUES;
-       
 
-       
+
+
 
        if (!get_part_type (_("Partition type"), *disk,
                                               &part_type))
@@ -690,7 +668,7 @@
        if (!fdisk_compatibility_mode && fs_type->ops->create &&
            part_type != PED_PARTITION_EXTENDED &&
            command_line_prompt_boolean_question(
-               _("Do you want to create the filesystem on the partition?"))) 
+               _("Do you want to create the filesystem on the partition?")))
        {
                return perform_mkpartfs (*disk, &pos, part_type, fs_type,
                                         NULL, opts | UI_WARN_COMMIT);
@@ -700,7 +678,7 @@
                return perform_mkpart (*disk, &pos, part_type, fs_type,
                                       NULL, opts);
        }
-       
+
 }
 
 #if 0
@@ -708,13 +686,13 @@
 do_mkpartfs (PedDisk** disk)
 {
        PartPos pos;
-       
+
        pos.start.sector = 0LL;
        pos.end.sector = 0LL;
        pos.start.range = NULL;
        pos.end.range = NULL;
-       return perform_mkpartfs (*disk, &pos, 0, NULL, NULL, 
-                                UI_CUSTOM_VALUES | UI_WARN_COMMIT | 
+       return perform_mkpartfs (*disk, &pos, 0, NULL, NULL,
+                                UI_CUSTOM_VALUES | UI_WARN_COMMIT |
                                 UI_SPECIFY_PART_TYPE);
 }
 #endif
@@ -801,7 +779,7 @@
                return 1;
 
         printf ("\n");
-     
+
        printf (_("Minor: %d\n"), part->num);
        printf (_("Flags: ")); partition_print_flags (part); printf("\n");
        printf (_("File System: %s\n"), fs->type->name);
@@ -849,7 +827,7 @@
                                       "partition table is not supported in GNU 
fdisk."));
                return 0;
        }
-       
+
        PedPartition *part;
        int sect_size = (*disk)->dev->sector_size;
 
@@ -871,7 +849,7 @@
                                     _("There is a BSD partition on the disk "
                                       "but it seems to contain a filesystem. "
                                       "This is going to destroy it. "
-                                      "Are you sure you want to continue?")) 
+                                      "Are you sure you want to continue?"))
                                        == PED_EXCEPTION_NO) {
                                        
ped_device_end_external_access((*disk)->dev);
                                        return 0;
@@ -880,14 +858,14 @@
                        /* If there is no already created BSD label created,
                           and there is a filesystem on the partition, OR
                           we are in gfdisk, we warn the user about it */
-                       else if (!is_bsd_partition((*disk)->dev->path, 
-                               part->geom.start * sect_size, sect_size) && 
+                       else if (!is_bsd_partition((*disk)->dev->path,
+                               part->geom.start * sect_size, sect_size) &&
                                (!fdisk_compatibility_mode)) {
                                if (ped_exception_throw(PED_EXCEPTION_WARNING,
                                                        PED_EXCEPTION_YES_NO,
                                     _("There is a BSD partition on the disk, "
                                       "but there is no BSD disklabel on it. "
-                                      "Do you want to create one?")) 
+                                      "Do you want to create one?"))
                                        == PED_EXCEPTION_NO) {
                                        
ped_device_end_external_access((*disk)->dev);
                                        return 0;
@@ -956,7 +934,7 @@
        PedSector               cyl_start;
        PedSector               cyl_end;
        PedSector               unit = ped_unit_get_default ();
-       PedSector               blocks;                 
+       PedSector               blocks;
        PedSector               sects_nbytes;
 
        chs          = &((*disk)->dev)->bios_geom;
@@ -972,37 +950,37 @@
        cyl_size[strlen (cyl_size) - 1] = '\0';
 
        PedSector total_drive_size = heads * sectors * cylinders * sect_size;
-       printf (_("\nDisk %s: %lld %s, %lld bytes\n"), (*disk)->dev->path, 
-                total_drive_size >= 1000000000 ? 
-                total_drive_size  / 1000000000 : 
-                total_drive_size  / 1000000, 
+       printf (_("\nDisk %s: %lld %s, %lld bytes\n"), (*disk)->dev->path,
+                total_drive_size >= 1000000000 ?
+                total_drive_size  / 1000000000 :
+                total_drive_size  / 1000000,
                (total_drive_size >= 1000000000) ? "GB" : "MB",
                heads * sectors * cylinders * sect_size);
 
        if (unit == PED_UNIT_SECTOR)
                printf (_("%lld heads, %lld sectors/track, %lld cylinders, 
total %lld sectors\n"
                        "Units = sectors of %d * %d = %d bytes\n"),
-                       heads, sectors, cylinders, (heads * sectors * 
cylinders), 1, 
+                       heads, sectors, cylinders, (heads * sectors * 
cylinders), 1,
                        sect_size, sect_size);
        else
                printf (_("%lld heads, %lld sectors/track, %lld cylinders\n"
                        "Units = cylinders of %lld * %d = %s bytes\n"),
-                       heads, sectors, cylinders, (heads * sectors), 
+                       heads, sectors, cylinders, (heads * sectors),
                        sect_size, cyl_size);
 
         printf ("\n");
-        
+
        has_extended = ped_disk_type_check_feature ((*disk)->type,
                                         PED_DISK_TYPE_EXTENDED);
 
        unsigned int i;
-       
+
        unsigned int pathlen;
-       
-       /* TODO: Make this output the same output as util-linux fdisk(?), 
+
+       /* TODO: Make this output the same output as util-linux fdisk(?),
           possibly split into seperate functions */
        if (fdisk_compatibility_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");
        }
@@ -1022,36 +1000,36 @@
        for (part = ped_disk_next_partition (*disk, NULL); part;
             part = ped_disk_next_partition (*disk, part)) {
 
-               
-               cyl_start     = (part->geom.start / (total_cyl)) + 1; 
+
+               cyl_start     = (part->geom.start / (total_cyl)) + 1;
                cyl_end       = (part->geom.end   / (total_cyl)) + 1;
 
                if (unit == PED_UNIT_SECTOR) {
                        /* In Linux fdisk compatibility mode, display exact */
                        if (fdisk_compatibility_mode) {
                                start = part->geom.start;
-                               end = part->geom.end; 
+                               end = part->geom.end;
                        }
                        /* In fdisk, round up the sectors to cylinders */
-                       else {  
-                               start = (part->geom.start / total_cyl 
-                                               * total_cyl) + sectors; 
+                       else {
+                               start = (part->geom.start / total_cyl
+                                               * total_cyl) + sectors;
                                end   = part->geom.end / total_cyl * total_cyl;
                        }
-                       blocks    = ((cyl_end * total_cyl) 
-                                               - ((part->num == 1) ? 
-                       (cyl_start * sectors) : (cyl_start * total_cyl))) 
+                       blocks    = ((cyl_end * total_cyl)
+                                               - ((part->num == 1) ?
+                       (cyl_start * sectors) : (cyl_start * total_cyl)))
                                        / (1024 / sect_size);
                } else {
                        start     = cyl_start;
                        end       = cyl_end;
-                       blocks    = ((end * total_cyl) - ((part->num == 1) ? 
+                       blocks    = ((end * total_cyl) - ((part->num == 1) ?
                        (start * sectors) : (start * total_cyl))) / (1024 / 
sect_size);
                }
-       
+
                if (!ped_partition_is_active (part))
                        continue;
-       
+
 
                if (fdisk_compatibility_mode && 
!strcmp((*disk)->type->name,"bsd")) {
                        printf("  %c: ", 'a' + part->num - 1);
@@ -1064,7 +1042,7 @@
                        printf("  *  ");
                else
                        printf("     ");
-               
+
                }
 
 
@@ -1073,7 +1051,7 @@
                int type_size;
                unsigned int part_type = get_disk_specific_system_type (part, 
&type_size);
                type_size *= 2;
-               char *type_name = _(get_disk_specific_system_name(part,0)); 
+               char *type_name = _(get_disk_specific_system_name(part,0));
                if (type_size)
                        printf("  %*x  %s", type_size, part_type, type_name);
                else if(type_name)
@@ -1082,13 +1060,13 @@
                else {
                        ped_device_begin_external_access((*disk)->dev);
                        char *type = (char *)ped_partition_type_get_name 
(part->type);
-                       if (part->fs_type 
+                       if (part->fs_type
                                && !strcmp (part->fs_type->name, "linux-swap"))
                                printf ("%+4s %+21s ", _("82"), _("Linux Swap / 
Solaris"));
-                       else if (is_bsd_partition ((*disk)->dev->path, 
+                       else if (is_bsd_partition ((*disk)->dev->path,
                                part->geom.start * sect_size, sect_size))
                                printf ("%+4s %+17s ", _("a5"), 
_("Free/Net/OpenBSD"));
-                       else if (!strcmp (type, "primary")) 
+                       else if (!strcmp (type, "primary"))
                                printf ("%+4s %+6s ", _("83"), _("Linux"));
                        else if (!strcmp (type, "extended"))
                                printf ("%+4s %+9s ", _("5"), _("Extended"));
@@ -1101,7 +1079,7 @@
                        check_partition_consistency(part);
        }
        ped_free (cyl_size);
-        
+
        /*if (fdisk_list_table == 1)
          do_quit (disk);*/
 
@@ -1122,7 +1100,7 @@
        PedDevice *dev = (*disk)->dev;
        PedCHSGeometry *chs = &(dev->bios_geom);
 
-       int is_boot, start_cyl, start_head, start_sector, 
+       int is_boot, start_cyl, start_head, start_sector,
                     end_cyl, end_head, end_sector;
 
        char *part_chs = NULL;
@@ -1135,10 +1113,10 @@
             part = ped_disk_next_partition (*disk, part)) {
                if (!ped_partition_is_active(part))
                        continue;
-               
+
                /* We skip primary partitions, if needed */
                if (extend && !part->type)
-                       continue;  
+                       continue;
 
 
                /* TODO: Calculate, instead of parsing the string */
@@ -1154,15 +1132,15 @@
 
 
                is_boot = ped_partition_get_flag(part,PED_PARTITION_BOOT);
-               
+
                printf("%2d %02x%4d%4d%8d%4d%4d%8d%11lld%11lld %02x\n",
-                      part->num, is_boot ? 0x80 : 0, 
+                      part->num, is_boot ? 0x80 : 0,
                       start_head, start_sector, start_cyl,
                       end_head, end_sector, end_cyl,
-                      part->geom.start, part->geom.length, 
-                      get_disk_specific_system_type(part, NULL)); 
-               
-                       
+                      part->geom.start, part->geom.length,
+                      get_disk_specific_system_type(part, NULL));
+
+
                check_partition_consistency(part);
        }
 }
@@ -1214,7 +1192,7 @@
 }
 
 static int
-do_raw (PedDisk **disk) 
+do_raw (PedDisk **disk)
 {
        /* TODO: Make this for other disklabels, too */
        if (strcmp((*disk)->type->name, "msdos")) {
@@ -1232,13 +1210,13 @@
 
        /* First we print the MBR */
        print_sector((*disk)->dev,0);
-       
+
        /* Then we print the partition table sectors for the logical partitions 
*/
        for (part = ped_disk_get_partition(*disk, i = 5); part;
             part = ped_disk_get_partition(*disk, ++i))
        {
                print_sector((*disk)->dev, part->prev->geom.start);
-       } 
+       }
 
 }
 
@@ -1259,37 +1237,37 @@
                PedSector               sect_size;
                PedSector               heads;
                PedSector               total_cyl;
-       
+
                chs          = &(disk->dev)->bios_geom;
                sectors      = chs->sectors;
                heads        = chs->heads;
                total_cyl    = heads * sectors;
                sect_size    = disk->dev->sector_size;
-               cyl_start     = (part->geom.start / (total_cyl)) + 1; 
+               cyl_start     = (part->geom.start / (total_cyl)) + 1;
                cyl_end       = (part->geom.end   / (total_cyl)) + 1;
                //ped_unit_set_default(PED_UNIT_CYLINDER);
 
                printf("%lld\n",
-                       ((cyl_end * total_cyl) - ((part->num == 1) ? 
-                       (cyl_start * sectors) : (cyl_start * total_cyl))) / 
+                       ((cyl_end * total_cyl) - ((part->num == 1) ?
+                       (cyl_start * sectors) : (cyl_start * total_cyl))) /
                        (1024 / sect_size)
                );
                exit(0);
        }
-       
+
 }
 
-static void 
+static void
 do_list_devices (PedDisk* disk) {
         if (disk == NULL) {
                 PedDevice* dev = NULL;
-    
+
                 ped_device_probe_all ();
-    
+
                 while ((dev = ped_device_get_next (dev))) {
                         if (!ped_device_open(dev))
                                break;
-     
+
                         PedDisk *disk = ped_disk_new(dev);
                        if (!disk) // Not fatal error
                                continue;
@@ -1468,7 +1446,7 @@
        if (!*disk)
                goto error;
 
-       if (!command_line_prompt_boolean_question 
+       if (!command_line_prompt_boolean_question
        (_("WARNING: rescue writes all data to disk automatically, continue")))
                return 1;
 
@@ -1506,7 +1484,7 @@
                { 'e', _("place it at the end") },
                { 'c', _("select custom start and end") },
                { '\0', NULL }
-               
+
        };
        PartPos pos;
        PedPartition *part = NULL, *temp;
@@ -1544,14 +1522,14 @@
        else if (part->type != PED_PARTITION_EXTENDED) {
                ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
                                    _("No filesystem detected on the 
partition."));
-               return 0; 
+               return 0;
        }
        pos.start.sector = part->geom.start;
        pos.end.sector = part->geom.end;
 
        desired = PED_PARTITION_FREESPACE |
                                   (part->type & PED_PARTITION_LOGICAL);
-       
+
        temp = part_list_prev(part,PED_PARTITION_METADATA);
 
        if (temp && (temp->type & desired))
@@ -1560,10 +1538,10 @@
                first = part->geom.start;
 
        temp = part_list_next(part,PED_PARTITION_METADATA);
-       
+
        if (temp && (temp->type & desired))
                last = temp->geom.end;
-       else 
+       else
                last = part->geom.end;
 
        if(!query_part_position(_("Place for the resized partition"),
@@ -1592,7 +1570,7 @@
        if (!*disk)
                goto error;
 
-       if (!command_line_prompt_boolean_question 
+       if (!command_line_prompt_boolean_question
        (_("WARNING: resize writes all data to disk automatically, continue")))
                return 1;
 
@@ -1675,8 +1653,8 @@
        if (!ped_device_open (dev))
                return 0;
 
-       if (uiquery.need_commit) 
-               if (!command_line_prompt_boolean_question 
+       if (uiquery.need_commit)
+               if (!command_line_prompt_boolean_question
                (_("WARNING: changes were made to the disk, "
                   "are you sure you want to discard them")))
                        return 1;
@@ -1685,7 +1663,7 @@
        ped_disk_destroy (*disk);
        if (!(*disk = ped_disk_new (dev)))
                return 0;
-       
+
        /* Tell the user we are using the new device. */
        fdisk_print_using_dev (dev);
 
@@ -1703,8 +1681,8 @@
 static int
 do_toggle_boot_flag (PedDisk** disk)
 {
-       
-       
+
+
        return perform_set (*disk, NULL, PED_PARTITION_BOOT, UI_FLAG_TOGGLE);
 }
 
@@ -1728,9 +1706,9 @@
 /*
  * do_commit: write all configuration changes to disk.
  */
-static int 
+static int
 do_commit (PedDisk **disk)
-{  
+{
        /* TODO: Move these to common! */
        if ((*disk)->dev->boot_dirty && (*disk)->dev->type != PED_DEVICE_FILE) {
                ped_exception_throw (
@@ -1761,7 +1739,7 @@
                do_quit (disk);
 
         return 1;
-       
+
  error:
        return 0;
 }
@@ -1790,7 +1768,7 @@
         old_menu = in_menu;
        in_menu = 1;
 
-       status = fdisk_interactive_menu (disk, 
+       status = fdisk_interactive_menu (disk,
                fdisk_ex_menu_commands, 0);
 
        in_menu = old_menu;
@@ -1841,9 +1819,9 @@
        const char *type_name = NULL;
        SysType *types = get_disklabel_system_types((*disk)->type);
        if (!types) {
-               if (!command_line_prompt_boolean_question 
+               if (!command_line_prompt_boolean_question
                        (_("WARNING: System types for this disk label type "
-                           "seem unavailable, continue?"))) 
+                           "seem unavailable, continue?")))
                        return 0;
        }
        const char prompt[] = "Hex code (type L to list codes)";
@@ -1873,7 +1851,7 @@
                }
        if (!type_name)
                type_name = _("Unknown");
-       
+
        printf(_("Changed type of partition %d to %x (%s)\n"),
                part->num, type, type_name);
        return 1;
@@ -1936,14 +1914,14 @@
 
        pos.start.range = NULL;
        pos.end.range = NULL;
-       
+
        /* This gets the new start in sectors */
        while (1) {
                if (!fdisk_command_line_get_llinteger(_("New beginning of 
data"),
                                                 &pos.start.sector))
                        return 0;
-               if (pos.start.sector < part->geom.start || 
-                               pos.start.sector >= part->geom.end) 
+               if (pos.start.sector < part->geom.start ||
+                               pos.start.sector >= part->geom.end)
                        printf(_("Value out of range."));
                else
                        break;
@@ -2173,7 +2151,7 @@
 _(" w   write disklabel to disk"),
 NULL), NULL, 1));
 
-       
+
 }
 static void
 _init_ex_menu_commands () {
@@ -2182,13 +2160,16 @@
   if (!fdisk_compatibility_mode)
   {
 
-       fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
-               str_list_create_unique ("v", _("v"), NULL),
-               do_move,
-               str_list_create (
-_(" v   move a partition"),
-NULL), 
-               str_list_create (_(number_msg), _(start_end_msg), NULL), 1));
+       fdisk_command_register (
+               fdisk_ex_menu_commands,
+                       fdisk_command_create (
+                               str_list_create_unique ("v", _("v"), NULL),
+                               do_move,
+                               str_list_create (_(" v   move a partition"), 
NULL),
+                               str_list_create (_(number_msg), 
_(start_end_msg), NULL),
+                       1)
+               );
+
        fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
                str_list_create_unique ("c", _("c"), NULL),
                do_rescue,
@@ -2226,7 +2207,7 @@
 NULL), NULL, 1));
 
 
-  } 
+  }
   if (fdisk_compatibility_mode)
        fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
                str_list_create_unique ("b", _("b"), NULL),
@@ -2302,7 +2283,7 @@
                str_list_create (
 _(" q   quit without saving changes"),
 NULL), NULL, 1));
-  
+
 
         fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
                str_list_create_unique ("r", _("r"), NULL),
@@ -2334,7 +2315,7 @@
 _(" w   write table to disk and exit"),
 NULL), NULL, 1));
 
-  
+
 }
 
 
@@ -2476,11 +2457,11 @@
 _init_i18n ()
 {
 /* intialize i18n */
-#ifdef ENABLE_NLS
-       setlocale(LC_ALL, "");
-       bindtextdomain(PACKAGE, LOCALEDIR);
-       textdomain(PACKAGE);
-#endif /* ENABLE_NLS */
+#if ENABLE_NLS && HAVE_LOCALE_H
+  setlocale(LC_ALL, "");
+  bindtextdomain(PACKAGE, LOCALEDIR);
+  textdomain(PACKAGE);
+#endif /* ENABLE_NLS && HAVE_LOCALE_H */
 }
 
 /* initialise UI calls structure */
@@ -2507,250 +2488,310 @@
 static void
 _version ()
 {
-       printf ("%s\n", interface_name);
-       exit (0);
+  puts(interface_name);
+  exit (0);
+}
+
+/**
+ * build a struct option array from extd_options table
+ * \return a pointer to NULL terminated struct option array
+ * allocated with malloc */
+static struct option *
+build_option_table(void)
+{
+  unsigned int i, len = sizeof(extd_options) / sizeof(extd_options[0]);
+  struct option *option = malloc(sizeof(struct option) * len);
+  if(option == NULL)
+    {
+      perror(_("dynamic memory allocation failure"));
+      exit(EXIT_FAILURE);
+    }
+  for(i=0; i < len; i++)
+    memcpy(&(option[i]), &(extd_options[i]), sizeof(struct option));
+  return option;
 }
 
 static int
 _parse_options (int* argc_ptr, char*** argv_ptr)
 {
-       int     opt;
+  int opt;
+  struct option *options_table, *ptr;
 
-       while (1)
+  /* Build option table we need two pointers because getopt long
+   * modify `ptr' and we can't feree it */
+  options_table = ptr = build_option_table();
+
+  while((opt = getopt_long(*argc_ptr, *argv_ptr, 
+                          short_option_string, ptr, NULL)) != -1)
+    {
+      /* NOTE: b, C, H, S are ignored, for Linux fdisk compatibility */
+      switch (opt) 
        {
-       /* NOTE: b, C, H, S are ignored, for Linux fdisk compatibility */
-#ifdef HAVE_GETOPT_H
-               opt = getopt_long (*argc_ptr, *argv_ptr, "hlipvLGs:utb:C:H:S:r",
-                                  options, NULL);
-#else
-               opt = getopt (*argc_ptr, *argv_ptr, "hlipvLGs:utb:C:H:S:r");
-#endif
-               if (opt == -1)
-                       break;
-
-               switch (opt) {
-                       case 'h': fdisk_help_msg (); break;
-                       case 'l': fdisk_list_table = 1; break;
-
-                       case 'r': fdisk_list_table = 1;
-                                 fdisk_print_raw = 1;
-                                 break;
-
-                       case 'i': fdisk_opt_script_mode = 0; break;
-                       case 'p': fdisk_opt_script_mode = 1; break;
+       case 'h': 
+         fdisk_help_msg ();
+         break;
+       case 'l': 
+         fdisk_list_table = 1;
+         break;
+       case 'r': 
+         fdisk_list_table = 1;
+         fdisk_print_raw = 1;
+         break;
+       case 'i':
+         fdisk_opt_script_mode = 0;
+         break;
+       case 'p':
+         fdisk_opt_script_mode = 1;
+         break;
 #ifdef GNU_EXT
-                       case 'G': fdisk_compatibility_mode = 0; break;
-                       case 'L': fdisk_compatibility_mode = 1; break;
+       case 'G':
+         fdisk_compatibility_mode = 0;
+         break;
+       case 'L':
+         fdisk_compatibility_mode = 1;
+         break;
 #endif
-                       case 's': fdisk_partsize_device = optarg; break;
-                       case 't': print_partition_types(); break;
-                       case 'u': ped_unit_set_default(PED_UNIT_SECTOR);
-                                 cylinder_unit = 0;
-                                 break;
-                       case 'v': _version (); break;
-                       case 'b': 
-                               user_sectsize = atoll(optarg);
-                               if (user_sectsize <= 0 || user_sectsize % 512) {
-                                       fdisk_usage_msg();
-                                       return 0;
-                               }
-                               break;
-                       case 'C': user_cyls = atoi(optarg); break;
-                       case 'H': user_heads = atoi(optarg); break;
-                       case 'S': user_sectors = atoi(optarg); break;
-               }
+       case 's':
+         fdisk_partsize_device = optarg;
+         break;
+       case 't':
+         print_partition_types();
+         break;
+       case 'u':
+         ped_unit_set_default(PED_UNIT_SECTOR);
+         cylinder_unit = 0;
+         break;
+       case 'v':
+         _version();
+         break;
+       case 'b':
+         user_sectsize = atoll(optarg);
+         if (user_sectsize <= 0 || user_sectsize % 512)
+           {
+             fdisk_usage_msg();
+             return 0;
+           }
+         break;
+       case 'C':
+         user_cyls = atoi(optarg);
+         break;
+       case 'H':
+         user_heads = atoi(optarg);
+         break;
+       case 'S':
+         user_sectors = atoi(optarg);
+         break;
        }
-
-       *argc_ptr -= optind;
-       *argv_ptr += optind;
-       return 1;
-
+    }
+  
+  *argc_ptr -= optind;
+  *argv_ptr += optind;
+  
+  free(options_table);
+  
+  return 1;
+/* what is? */
 error:
-       return 0;
+  return 0;
 }
 
 static PedDevice*
 _choose_device (int* argc_ptr, char*** argv_ptr)
 {
-       PedDevice*      dev;
-       const char*     path = NULL;
+  PedDevice* dev;
+  const char* path = NULL;
 
-       /* if we want partition size */
-       if (fdisk_partsize_device) {
-               static char buf[512];
-               fdisk_partsize_part = cut_device_partnum(buf, sizeof(buf), 
fdisk_partsize_device);
-               path = buf;
-       }
-       else if (*argc_ptr) {
-               path = (*argv_ptr) [0];
-       }
-
-       /* specified on comand line? */
-       if (path) {
-               dev = ped_device_get (path);
-               if (!dev) {
-                       printf(_("Unable to open %s\n"), path);
-                       return NULL;
-               }
-               /* TODO: I have no idea why this is here, but I leave it as is 
*/
-               if (*argc_ptr) {
-                       (*argc_ptr)--;
-                       (*argv_ptr)++;
-               }
-               /* If sector size, cylnders, heads or sectors are specified on
-                  the command line */
-               if (fdisk_compatibility_mode) {
-                       if (user_sectsize) {
-                               /* This should be multiple of 512, checked at
-                                  option parsing */
-                               PedSector bytes = dev->sector_size * 
dev->length;
-                               dev->sector_size = user_sectsize;
-                               dev->length = bytes / user_sectsize;    
-                       }
-                       if (user_sectors || user_heads) {
-                               /* NOTE: PedSector is long long */
-                               long long llcyl;
-                               if (user_sectors)
-                                       dev->bios_geom.sectors = user_sectors;
-                               if (user_heads)
-                                       dev->bios_geom.heads = user_heads;
-                               llcyl = dev->length / 
-                                               ((long long)dev->bios_geom.heads
-                                               * dev->bios_geom.sectors);
-                               dev->bios_geom.cylinders = llcyl;
-                               /* If it was truncated, use the max value,
-                                  as Linux fdisk */
-                               /* FIXME: Linux fdisk uses uint */
-                               if (dev->bios_geom.cylinders != llcyl)
-                                       dev->bios_geom.cylinders = INT_MAX;
-                               if (!dev->bios_geom.cylinders)
-                                       dev->bios_geom.cylinders = user_cyls;
-                       }
-               }
-               
-               if (!ped_device_open (dev)) {
-                       printf(_("Unable to open %s\n"), path); 
-                       return NULL;
-               }
-               return dev;
+  /* if we want partition size */
+  if (fdisk_partsize_device) 
+    {
+      static char buf[512];
+      fdisk_partsize_part = 
+       cut_device_partnum(buf, sizeof(buf), fdisk_partsize_device);
+      path = buf;
+    }
+  else if (*argc_ptr) 
+    path = (*argv_ptr) [0];
+  /* specified on comand line? */
+  if (path) 
+    {
+      dev = ped_device_get (path);
+      if (!dev) 
+       {
+         printf(_("Unable to open %s\n"), path);
+         return NULL;
+       }
+      /***************************************************************/
+      /* TODO: I have no idea why this is here, but I leave it as is */
+      /***************************************************************/
+      if (*argc_ptr) 
+       {
+         (*argc_ptr)--;
+         (*argv_ptr)++;
+       }
+      /* If sector size, cylnders, heads or sectors are specified on
+        the command line */
+      if (fdisk_compatibility_mode) 
+       {
+         if (user_sectsize) 
+           {
+             /* This should be multiple of 512, checked at
+                option parsing */
+             PedSector bytes = dev->sector_size * dev->length;
+             dev->sector_size = user_sectsize;
+             dev->length = bytes / user_sectsize;
+           }
+         if (user_sectors || user_heads) 
+           {
+             /* NOTE: PedSector is long long */
+             long long llcyl;
+             if (user_sectors)
+               dev->bios_geom.sectors = user_sectors;
+             if (user_heads)
+               dev->bios_geom.heads = user_heads;
+             llcyl = dev->length / 
+               ((long long)dev->bios_geom.heads
+                * dev->bios_geom.sectors);
+             dev->bios_geom.cylinders = llcyl;
+             /* If it was truncated, use the max value,
+                as Linux fdisk */
+             /* FIXME: Linux fdisk uses uint */
+             if (dev->bios_geom.cylinders != llcyl)
+               dev->bios_geom.cylinders = INT_MAX;
+             if (!dev->bios_geom.cylinders)
+               dev->bios_geom.cylinders = user_cyls;
+           }
        }
-       return NULL;    
+      if (!ped_device_open (dev)) 
+       {
+         printf(_("Unable to open %s\n"), path);
+         return NULL;
+       }
+      return dev;
+    }
+  return NULL;
 }
 
 static PedDevice*
 _init (int* argc_ptr, char*** argv_ptr)
 {
-       PedDevice*      dev;
+  PedDevice*   dev;
 
 #ifdef ENABLE_MTRACE
-       mtrace();
+  mtrace();
 #endif
 
-       _init_i18n ();
-       if (!fdisk_init_ui ())
-               goto error;
-
-       _init_messages ();
-
-
-       /* The default units are cylinders */
-       ped_unit_set_default(PED_UNIT_CYLINDER);
-
-       /* TODO: Make _init_messages init these, remove messages from ui.c */
-       init_flag_str();
-       init_fs_type_str();
-       init_disk_type_str();
-       
-       if (!_parse_options (argc_ptr, argv_ptr))
-               goto error_done_commands;
-
-       dev = _choose_device (argc_ptr, argv_ptr);
-
-       _init_ex_menu_commands ();
-       _init_bsd_menu_commands ();
-       _init_main_menu_commands ();
+  _init_i18n ();
+  if (!fdisk_init_ui ())
+    goto error;
+
+  _init_messages ();
+
+  /* The default units are cylinders */
+  ped_unit_set_default(PED_UNIT_CYLINDER);
+
+  /* TODO: Make _init_messages init these, remove messages from ui.c */
+  init_flag_str();
+  init_fs_type_str();
+  init_disk_type_str();
 
-       if (!dev) {
-               goto error_done_commands;
-       }
-       _init_uicalls();
-
-       if (!uiquery.timer)
-               goto error_done_commands;
-       timer_context.last_update = 0;
-
-       return dev;
+  if (!_parse_options (argc_ptr, argv_ptr))
+    goto error_done_commands;
+  
+  dev = _choose_device (argc_ptr, argv_ptr);
 
-error_done_commands:
-       _done_commands ();
-       _done_messages ();
-error_done_ui:
-       fdisk_done_ui ();
-error:
-       return NULL;
+  _init_ex_menu_commands ();
+  _init_bsd_menu_commands ();
+  _init_main_menu_commands ();
+  
+  if (!dev) {
+    goto error_done_commands;
+  }
+  _init_uicalls();
+  
+  if (!uiquery.timer)
+    goto error_done_commands;
+  timer_context.last_update = 0;
+  
+  return dev;
+  
+ error_done_commands:
+  _done_commands ();
+  _done_messages ();
+  
+ error_done_ui:
+  fdisk_done_ui ();
+  
+ error:
+  return NULL;
 }
 
 static void
 _done (PedDevice* dev)
 {
-       ped_device_close (dev);
-
-       /* TODO: _done_uicalls? */
-       ped_timer_destroy (uiquery.timer);
-       _done_commands ();
-       _done_messages ();
-       fdisk_done_ui();
+  ped_device_close (dev);
+  
+  /* TODO: _done_uicalls? */
+  ped_timer_destroy (uiquery.timer);
+  _done_commands ();
+  _done_messages ();
+  fdisk_done_ui();
 }
 
+/**
+ * Program entry point
+ * \param argc number of command line arguments
+ * \param argv array of command line arguments
+ * \return EXIT_SUCCESS or EXIT_FAILURE
+ */
 int
 fdisk (int argc, char** argv)
 {
-        PedDevice*     dev;
-       PedDisk*        disk; 
-       int             status;
-
-       if (argc <= 1) {
-               fdisk_usage_msg();
-               return -1;
-       }
-
-       
+  PedDevice* dev;
+  PedDisk* disk;
+  
+  if (argc <= 1)
+    {
+      /* Missing device parameter */
+      fdisk_usage_msg();
+      return EXIT_FAILURE;
+    }
+  
 #ifdef GNU_EXT
-       /* See whether we should enable Linux fdisk compatibility mode */
-       if (argv[0]) {
-               char *program_name = strrchr(argv[0], '/');
-               if (program_name)
-                       program_name++;
-               else
-                       program_name = argv[0];
-               fdisk_compatibility_mode = !strcmp(program_name,"lfdisk");
-       }
-       else
-               fdisk_compatibility_mode = 0;
-#endif
-
-       dev = _init (&argc, &argv);
-
-       if (!dev && fdisk_list_table)
-               /* List all devices. */
-               do_list_devices (NULL);
-       else if (!dev)
-               return 1;
-
-       disk = ped_disk_new (dev);
+  /* See whether we should enable Linux fdisk compatibility mode */
+  if (argv[0]) 
+    {
+      char *program_name = strrchr(argv[0], '/');
+      if (program_name)
+       program_name++;
+      else
+       program_name = argv[0];
+      fdisk_compatibility_mode = !strcmp(program_name,"lfdisk");
+    }
+  else
+    fdisk_compatibility_mode = 0;
+#endif /* GNU_EXT */
+  
+  dev = _init (&argc, &argv);
+  
+  if (!dev && fdisk_list_table)
+    /* List all devices. */
+    do_list_devices (NULL);
+  else if(!dev)
+    return EXIT_FAILURE;
 
-       if (!disk) 
-               return 1;
-       /* Show the size of the partition */
-       if (fdisk_partsize_device)
-               print_partition_size(disk);
-
-       /* List the specified disk. */
-       if (fdisk_list_table)
-                do_list_devices(disk);
-       
-       status = fdisk_interactive_mode (&disk, fdisk_main_menu_commands);
-       
-       return !status;
+  disk = ped_disk_new(dev);
+  
+  if(!disk)
+    return EXIT_FAILURE;
+  
+  /* Show the size of the partition */
+  if(fdisk_partsize_device)
+    print_partition_size(disk);
+  
+  /* List the specified disk. */
+  if (fdisk_list_table)
+    do_list_devices(disk);
+  
+  return (fdisk_interactive_mode(&disk, fdisk_main_menu_commands) 
+         ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-
diff -rN -u old-_fdisk0/src/main.c new-_fdisk0/src/main.c
--- old-_fdisk0/src/main.c      2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/src/main.c      2008-09-29 01:17:16.000000000 +0200
@@ -18,11 +18,13 @@
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */
 
+/**
+ * Main entry point.
+ */
 extern int fdisk (int argc, char** argv);
 
 int
 main (int argc, char** argv)
 {
-        return fdisk (argc, argv);
+       return fdisk(argc, argv);
 }
-
diff -rN -u old-_fdisk0/src/strlist.c new-_fdisk0/src/strlist.c
--- old-_fdisk0/src/strlist.c   2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/src/strlist.c   2008-09-29 01:17:16.000000000 +0200
@@ -19,7 +19,14 @@
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */
 
-#include "config.h"
+#include "../config.h"
+
+#include "gettext.h"
+#if ENABLE_NLS
+# include <locale.h>
+#endif /* ENABLE_NLS */
+#define N_(String) String
+#define _(String) dgettext (PACKAGE, String)
 
 #include <parted/debug.h>
 
@@ -31,7 +38,7 @@
 #include <string.h>
 #include <limits.h>
 
-#ifdef ENABLE_NLS
+#if ENABLE_NLS
 
 #undef __USE_GNU
 #define __USE_GNU
@@ -39,7 +46,7 @@
 #include <wchar.h>
 #include <wctype.h>
 
-#else /* ENABLE_NLS */
+#else /* !ENABLE_NLS */
 
 #ifdef wchar_t
 #undef wchar_t
@@ -56,7 +63,7 @@
 int
 wchar_strlen (const wchar_t* str)
 {
-#ifdef ENABLE_NLS
+#if ENABLE_NLS
        return wcslen (str);
 #else
        return strlen (str);
@@ -66,7 +73,7 @@
 wchar_t*
 wchar_strchr (const wchar_t* str, char ch)
 {
-#ifdef ENABLE_NLS
+#if ENABLE_NLS
        return wcschr (str, ch);
 #else
        return strchr (str, ch);
@@ -76,7 +83,7 @@
 int
 wchar_strcasecmp (const wchar_t* a, const wchar_t* b)
 {
-#ifdef ENABLE_NLS
+#if ENABLE_NLS
        return wcscasecmp (a, b);
 #else
        return strcasecmp (a, b);
@@ -86,7 +93,7 @@
 int
 wchar_strncasecmp (const wchar_t* a, const wchar_t* b, size_t n)
 {
-#ifdef ENABLE_NLS
+#if ENABLE_NLS
        return wcsncasecmp (a, b, n);
 #else
        return strncasecmp (a, b, n);
@@ -96,7 +103,7 @@
 wchar_t*
 wchar_strdup (const wchar_t* str)
 {
-#ifdef ENABLE_NLS
+#if ENABLE_NLS
        return wcsdup (str);
 #else
        return strdup (str);
@@ -106,7 +113,7 @@
 /* converts a string from the encoding in the gettext catalogues to wide
  * character strings (of type wchar_t*).
  */
-#ifdef ENABLE_NLS
+#if ENABLE_NLS
 static wchar_t*
 gettext_to_wchar (const char* str)
 {
@@ -129,22 +136,20 @@
        return result;
 
 error:
-       printf ("Error during translation: %s\n", strerror (errno));
+       printf ("%s: %s\n", _("Error during translation"), strerror (errno));
        exit (1);
 }
 
-#else /* ENABLE_NLS */
-
+#else /* !ENABLE_NLS */
 static wchar_t*
 gettext_to_wchar (const char* str)
 {
        return strdup (str);
 }
+#endif /* ENABLE_NLS */
 
-#endif /* !ENABLE_NLS */
 
-
-#ifdef ENABLE_NLS
+#if ENABLE_NLS
 static char*
 wchar_to_str (const wchar_t* str, size_t count)
 {
@@ -178,7 +183,7 @@
        return result;
 
 error:
-       printf ("Error during translation: %s\n", strerror (errno));
+       printf ("%s: %s\n", _("Error during translation"), strerror (errno));
        exit (1);
 }
 
@@ -205,7 +210,7 @@
        free (tmp);
 }
 
-static StrList* 
+static StrList*
 str_list_alloc ()
 {
        StrList*        list;
@@ -228,7 +233,8 @@
 void
 str_list_destroy_node (StrList* list)
 {
-       free ((wchar_t*) list->str);
+       /* Warning about qualifyers */
+       free (list->str);
        free (list);
 }
 
@@ -538,9 +544,8 @@
 int
 str_list_match_node (const StrList* list, const char* str)
 {
-       wchar_t*        wc_str = gettext_to_wchar (str);        /* FIXME */
        int             status;
-
+       wchar_t*        wc_str = gettext_to_wchar (str);        /* FIXME */
        status = _str_list_match_node (list, wc_str);
        free (wc_str);
 
diff -rN -u old-_fdisk0/src/ui.c new-_fdisk0/src/ui.c
--- old-_fdisk0/src/ui.c        2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/src/ui.c        2008-09-29 01:17:16.000000000 +0200
@@ -32,62 +32,55 @@
 #include "command.h"
 #include "strlist.h"
 #include "ui.h"
-#define N_(String) String
-#if ENABLE_NLS
-#  include <libintl.h>
-#  include <locale.h>
-#  define _(String) dgettext (PACKAGE, String)
-#else
-#  define _(String) (String)
-#endif /* ENABLE_NLS */
 
-#ifdef HAVE_LIBREADLINE
+#if HAVE_LOCALE_H
+# include <locale.h>
+#endif /* HAVE_LOCALE_H */
 
-#ifdef HAVE_TERMCAP_H
-#include <termcap.h>
-#else
-extern int tgetnum (char* key);
-#endif
+#include "gettext.h"
+#define N_(String) String
+#define _(String) dgettext (PACKAGE, String)
 
-#include <readline/readline.h>
-#include <readline/history.h>
+/* BEGIN readline stuff */
+#if HAVE_READLINE
 
-#ifndef HAVE_RL_COMPLETION_MATCHES
-#define rl_completion_matches completion_matches
-#endif
+/* termcap library */
+# if HAVE_TERMCAP_H
+#  include <termcap.h>
+# else
+    extern int tgetnum (char* key);
+# endif /* HAVE_TERMCAP_H */
+
+/* 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 */
+
+/* history library */
+# if HAVE_READLINE_HISTORY_H
+#  include <readline/history.h>
+# else
+#  define _add_history_unique add_history
+# endif
+  
+
+# ifndef HAVE_RL_COMPLETION_MATCHES
+#  define rl_completion_matches completion_matches
+# endif
+
+# ifndef rl_compentry_func_t
+#  define rl_compentry_func_t void
+# endif
 
-#ifndef rl_compentry_func_t
-#define rl_compentry_func_t void
-#endif
+#endif /* HAVE_READLINE */
 
-#endif /* HAVE_LIBREADLINE */
-char* interface_name = "GNU Fdisk " VERSION;
+/* END readline stuff */
 
-static char* banner_msg = N_(
-"Copyright (C) 1998 - 2006 Free Software Foundation, Inc.\n"
-"This program is free software, covered by the GNU General Public License.\n"
-"\n"
-"This program is distributed in the hope that it will be useful, "
-"but WITHOUT ANY WARRANTY; without even the implied warranty of "
-"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the "
-"GNU General Public License for more details.\n\n");
-
-static char* usage_msg = N_(
-"Usage: fdisk [OPTION]... [DEVICE]\n");
- 
-static char* bug_msg = N_(
-"You found a bug in GNU Fdisk.\n"
-"This may have been fixed in the last version of GNU Parted that you can find 
at:\n"
-"\thttp://ftp.gnu.org/gnu/parted/\n\n";
-"Please check this version prior to bug reporting.\n\n"
-"If this has not been fixed yet or if you don't know how to check, please 
email:\n"
-"address@hidden"
-"or (preferably) file a bug report at:\n"
-"\thttp://parted.alioth.debian.org/bugs/\n\n";
-"Your report should contain the version of this release (%s) along with the\n"
-"error message below, the output of\n"
-"\tparted DEVICE unit co print unit s print\n"
-"and additional information about your setup you consider important.\n");
+/* global and used in fdisk.c */
+char* interface_name = "GNU Fdisk " VERSION;
 
 #define MAX_WORDS      1024
 
@@ -100,172 +93,231 @@
 static StrList*                fs_type_list;
 static StrList*                disk_type_list;
 
+/* Declare readline_state */
 static struct {
-       const StrList*  possibilities;
-       const StrList*  cur_pos;
-       int             in_readline;
-       sigjmp_buf      jmp_state;
+  const StrList* possibilities;
+  const StrList* cur_pos;
+  int           in_readline;
+  sigjmp_buf    jmp_state;
 } readline_state;
 
-static PedExceptionOption      current_exception_opt = 0;
+static PedExceptionOption current_exception_opt = 0;
 
-/* If we don't want the possibilities to appear on the prompt, this 
+/* If we don't want the possibilities to appear on the prompt, this
    should be set to 0. TODO: Making this without a global variable
    might be a good idea */
 static prompt_possibilities = 1;
 
-#ifdef HAVE_LIBREADLINE
+
+#ifdef HAVE_READLINE
 /* returns matching commands for text */
 static char*
 command_generator (char* text, int state)
 {
-       if (!state)
-               readline_state.cur_pos = readline_state.possibilities;
+  if (!state)
+    readline_state.cur_pos = readline_state.possibilities;
 
-       while (readline_state.cur_pos) {
-               const StrList*  cur = readline_state.cur_pos;
-               readline_state.cur_pos = cur->next;
-               if (str_list_match_node (cur, text))
-                       return str_list_convert_node (cur);
-       }
+  while (readline_state.cur_pos) {
+    const StrList* cur = readline_state.cur_pos;
+    readline_state.cur_pos = cur->next;
+    if (str_list_match_node (cur, text))
+      return str_list_convert_node (cur);
+  }
 
-       return NULL;
+  return NULL;
 }
 
 /* completion function for readline() */
 char**
 fdisk_complete_function (char* text, int start, int end)
 {
-       return rl_completion_matches (text,
-               (rl_compentry_func_t*) command_generator);
+  return rl_completion_matches (text, (rl_compentry_func_t*) 
command_generator);
 }
 
+#if HAVE_READLINE_HISTORY_H
 static void
 _add_history_unique (const char* line)
 {
-       HIST_ENTRY*     last_entry = current_history ();
-       if (!strlen (line))
-               return;
-       if (!last_entry || strcmp (last_entry->line, line))
-               add_history ((char*) line);
+  HIST_ENTRY** p;
+
+  /* Check if line is empty */
+  if (!line || !line[0])
+    return;
+
+  /* Get all entryes of history and find if current line 
+   * is already in one history entry. */
+  p = history_list();
+  
+  if(p != NULL)
+    /* if the history is not empty we search for line in all entryes */
+    {
+      unsigned int i;
+      for(i = 0; p[i] != NULL; i++)
+       if(strcmp(p[i]->line, line) == 0)
+         /* match */
+         return;
+    }
+  /* no match */
+  add_history(line);
 }
-#endif /* HAVE_LIBREADLINE */
+#endif /* HAVE_READLINE_HISTORY_H */
+
+#endif /* HAVE_READLINE */
 
 static void
 interrupt_handler (int signum)
 {
-       int     in_readline = readline_state.in_readline;
+  int in_readline = readline_state.in_readline;
 
-       readline_state.in_readline = 0;
+  readline_state.in_readline = 0;
 
-       signal (signum, &interrupt_handler);
+  signal (signum, &interrupt_handler);
 
-       if (in_readline) {
-               printf ("\n");
-               siglongjmp (readline_state.jmp_state, 1);
-       }
+  if (in_readline) {
+    printf ("\n");
+    siglongjmp (readline_state.jmp_state, 1);
+  }
+}
+
+/* check if line is only spaces */
+static int
+is_empty_line(const char *s)
+{
+  while(*s)
+    if(!isspace(*s++))
+      return 0;
+  return 1;
 }
 
 static char*
 _readline (const char* prompt, const StrList* possibilities)
 {
-       char*           line;
+  char* line = NULL;
 
-       readline_state.possibilities = possibilities;
-       readline_state.cur_pos = NULL;
-       readline_state.in_readline = 1;
-
-       if (sigsetjmp (readline_state.jmp_state, 1))
-               return NULL;
-
-       fdisk_wipe_line ();
-#ifdef HAVE_LIBREADLINE
-       if (!fdisk_opt_script_mode) {
-               /* XXX: why isn't prompt const? */
-               line = readline ((char*) prompt);
-               if (line)
-                       _add_history_unique (line);
-       } else
+  readline_state.possibilities = possibilities;
+  readline_state.cur_pos = NULL;
+  readline_state.in_readline = 1;
+
+  if (sigsetjmp (readline_state.jmp_state, 1))
+    return NULL;
+
+  fdisk_wipe_line ();
+
+  if (!fdisk_opt_script_mode)
+#ifdef HAVE_READLINE
+    { /* !fdisk_opt_script_mode && HAVE_READLINE */
+      line = readline(prompt);
+      if(line && *line)
+       _add_history_unique (line);
+    }
+#else
+    { /* !fdisk_opt_script_mode */
+      printf ("%s", prompt);
+      fflush (stdout);
+      line = (char*) calloc(sizeof(char), 256);
+      if (fgets (line, 256, stdin) == NULL || is_empty_line(line))
+       {
+         free (line);
+         line = NULL;
+       }
+    }
 #endif
+  /* MMM... I assume that `disk_opt_script_mode' is true when fdisk
+   * would be used whit a script, but this script where come from,
+   * a file or stdin? the following codo works on stdin
+   * but we kan do better with an option and a file... ? */
+  else
+    { /* disk_opt_script_mode */
+      line = (char*) calloc(sizeof(char), 256);
+      if (fgets (line, 256, stdin) == NULL || is_empty_line(line))
        {
-               printf ("%s", prompt);
-               fflush (stdout);
-               line = (char*) malloc (256);
-               if (fgets (line, 256, stdin) && strcmp (line, "") != 0) {
-                       line [strlen (line) - 1] = 0;   /* kill trailing CR */
-               } else {
-                       free (line);
-                       line = NULL;
-               }
+         free (line);
+         line = NULL;
        }
-
-       readline_state.in_readline = 0;
-       return line;
+    }
+  readline_state.in_readline = 0;
+  return line;
 }
 
 static PedExceptionOption
 option_get_next (PedExceptionOption options, PedExceptionOption current)
 {
-       PedExceptionOption      i;
-
-       if (current == 0)
-               i = PED_EXCEPTION_OPTION_FIRST;
-       else
-               i = current * 2;
+  PedExceptionOption i;
 
-       for (; i <= options; i *= 2) {
-               if (options & i)
-                       return i;
-       }
+  i = 
+    current == 0 ? PED_EXCEPTION_OPTION_FIRST : current * 2;
 
-       return 0;
+#if 0
+  if (current == 0)
+    i = PED_EXCEPTION_OPTION_FIRST;
+  else
+    i = current * 2;
+#endif 
+
+  for (; i <= options; i *= 2) 
+    {
+      if (options & i)
+       return i;
+    }
+  return 0;
 }
 
 static void
 _print_exception_text (PedException* ex)
 {
-       StrList*                text;
-
-       fdisk_wipe_line ();
-
-       if (ex->type == PED_EXCEPTION_BUG) {
-               printf (bug_msg, VERSION);
-               text = str_list_create ("\n", ex->message, "\n", NULL);
-       } else {
-               text = str_list_create (
-                          _(ped_exception_get_type_string (ex->type)),
-                          ": ", ex->message, "\n", NULL);
-       }
-
-       str_list_print_wrap (text, fdisk_screen_width (), 0, 0);
-       str_list_destroy (text);
+  StrList*             text;
+  char* bug_msg = _(
+"You found a bug in GNU Fdisk.\n\
+This may have been fixed in the last version of \
+GNU Parted that you can find at:\n\
+\thttp://ftp.gnu.org/gnu/parted/\n\n\
+Please check this version prior to bug reporting.\n\n\
+If this has not been fixed yet or if you don't \
+know how to check, please email:\n\
address@hidden
+or (preferably) file a bug report at:\n\
+\thttp://parted.alioth.debian.org/bugs/\n\n\
+Your report should contain the version of this release (%s) along with the\n\
+error message below, the output of\n\
+\tparted DEVICE unit co print unit s print\n\
+and additional information about your setup you consider important.\n");
+
+  fdisk_wipe_line ();
+
+  if (ex->type == PED_EXCEPTION_BUG) 
+    {
+      printf (bug_msg, VERSION);
+      text = str_list_create ("\n", ex->message, "\n", NULL);
+    } 
+  else 
+    text = str_list_create (_(ped_exception_get_type_string (ex->type)),
+                           ": ", ex->message, "\n", NULL);
+  str_list_print_wrap (text, fdisk_screen_width (), 0, 0);
+  str_list_destroy (text);
 }
 
 static PedExceptionOption
 exception_handler (PedException* ex)
 {
-       PedExceptionOption      opt;
-
-       _print_exception_text (ex);
-
-       /* only one choice?  Take it ;-) */
-       opt = option_get_next (ex->options, 0);
-       if (!option_get_next (ex->options, opt))
-               return opt;
+  PedExceptionOption opt;
 
-       /* script-mode: don't handle the exception */
-       if (fdisk_opt_script_mode)
-               return PED_EXCEPTION_UNHANDLED;
+  _print_exception_text (ex);
 
-       do {
-               opt = fdisk_command_line_get_ex_opt ("", ex->options);
-       } while (opt == PED_EXCEPTION_UNHANDLED && isatty (0));
-       return opt;
+  /* only one choice?  Take it ;-) */
+  opt = option_get_next (ex->options, 0);
+  if (!option_get_next (ex->options, opt))
+    return opt;
+
+  /* script-mode: don't handle the exception */
+  if (fdisk_opt_script_mode)
+    return PED_EXCEPTION_UNHANDLED;
+
+  do {
+    opt = fdisk_command_line_get_ex_opt ("", ex->options);
+  } while (opt == PED_EXCEPTION_UNHANDLED && isatty (0));
+  return opt;
 }
 
-
-
-
 static int
 _str_is_spaces (const char* str)
 {
@@ -277,250 +329,279 @@
 static char*
 realloc_and_cat (char* str, const char* append)
 {
-       int     length = strlen (str) + strlen (append) + 1;
-       char*   new_str = realloc (str, length);
-       strcat (new_str, append);
-       return new_str;
+  int length = strlen (str) + strlen (append) + 1;
+  char*        new_str = realloc (str, length);
+  strcat (new_str, append);
+  return new_str;
 }
 
 static char*
 _construct_prompt (const char* head, const char* def,
                   const StrList* possibilities)
 {
-       char*   prompt = strdup (head);
+  char*        prompt = strdup (head);
 
-       if (def && possibilities)
-               PED_ASSERT (str_list_match_any (possibilities, def),
-                           return NULL);
-
-       if (possibilities && prompt_possibilities && 
-           str_list_length (possibilities) < 8) {
-               const StrList*  walk;
-               if (strlen (prompt))
-                       prompt = realloc_and_cat (prompt, " ");
-
-               for (walk = possibilities; walk; walk = walk->next) {
-                       if (walk != possibilities)
-                               prompt = realloc_and_cat (prompt, "/");
-
-                       if (def && str_list_match_node (walk, def) == 2) {
-                               prompt = realloc_and_cat (prompt, "[");
-                               prompt = realloc_and_cat (prompt, def);
-                               prompt = realloc_and_cat (prompt, "]");
-                       } else {
-                               char*   text = str_list_convert_node (walk);
-                               prompt = realloc_and_cat (prompt, text);
-                               free (text);
-                       }
-               }
-               prompt = realloc_and_cat (prompt, ": ");
-       } else if (def) {
-               size_t len = strlen (prompt);
-               if (len && prompt[len-1] != '\n')
-                       prompt = realloc_and_cat (prompt, "  ");
-               prompt = realloc_and_cat (prompt, "(default ");
-               prompt = realloc_and_cat (prompt, def);
-               prompt = realloc_and_cat (prompt, "): ");
-       } else {
-               size_t len = strlen (prompt);
-               if (len && prompt[--len] != '\n') {
-                       if (prompt[len] == ':' || prompt[len] == '?')
-                               prompt = realloc_and_cat (prompt, " ");
-                       else
-                               prompt = realloc_and_cat (prompt, ": ");
-               }
-       }
+  if (def && possibilities)
+    PED_ASSERT (str_list_match_any (possibilities, def), return NULL);
 
-       return prompt;
+  if (possibilities &&
+      prompt_possibilities &&
+      str_list_length (possibilities) < 8) 
+    {
+      const StrList* walk;
+      if (strlen (prompt))
+       prompt = realloc_and_cat (prompt, " ");
+      
+      for (walk = possibilities; walk; walk = walk->next) 
+       {
+         if (walk != possibilities)
+           prompt = realloc_and_cat (prompt, "/");
+         if (def && str_list_match_node (walk, def) == 2) 
+           {
+             prompt = realloc_and_cat (prompt, "[");
+             prompt = realloc_and_cat (prompt, def);
+             prompt = realloc_and_cat (prompt, "]");
+           } 
+         else 
+           {
+             char* text = str_list_convert_node (walk);
+             prompt = realloc_and_cat (prompt, text);
+             free (text);
+           }
+       }
+      prompt = realloc_and_cat (prompt, ": ");
+    } 
+  else if (def) 
+    {
+      size_t len = strlen (prompt);
+      if (len && prompt[len-1] != '\n')
+       prompt = realloc_and_cat (prompt, "  ");
+      prompt = realloc_and_cat (prompt, "(default ");
+      prompt = realloc_and_cat (prompt, def);
+      prompt = realloc_and_cat (prompt, "): ");
+    } 
+  else 
+    {
+      size_t len = strlen (prompt);
+      if (len && prompt[--len] != '\n') 
+       {
+         if (prompt[len] == ':' || prompt[len] == '?')
+           prompt = realloc_and_cat (prompt, " ");
+         else
+           prompt = realloc_and_cat (prompt, ": ");
+       }
+    }
+  return prompt;
 }
 
 static int
 _can_create_primary (const PedDisk* disk)
 {
-       int     i;
+  int i;
 
-       for (i = 1; i <= ped_disk_get_max_primary_partition_count (disk); i++) {
-               if (!ped_disk_get_partition (disk, i))
-                       return 1;
-       }
-
-       return 0;
+  for (i = 1; i <= ped_disk_get_max_primary_partition_count (disk); i++) 
+    {
+      if (!ped_disk_get_partition (disk, i))
+       return 1;
+    }
+  return 0;
 }
 
 static int
 _can_create_extended (const PedDisk* disk)
 {
-       if (!_can_create_primary (disk))
-               return 0;
-       if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED))
-               return 0;
-       if (ped_disk_extended_partition (disk))
-               return 0;
-       return 1;
+  if (!_can_create_primary (disk))
+    return 0;
+  if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED))
+    return 0;
+  if (ped_disk_extended_partition (disk))
+    return 0;
+  return 1;
 }
 
 static int
 _can_create_logical (const PedDisk* disk)
 {
-       if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED))
-               return 0;
-       return ped_disk_extended_partition (disk) != 0;
+  if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED))
+    return 0;
+  return ped_disk_extended_partition (disk) != 0;
 }
 
 static int
 init_ex_opt_str ()
 {
-       int                     i;
-       PedExceptionOption      opt;
+  int i;
+  PedExceptionOption opt;
 
-       for (i = 0; (1 << i) <= PED_EXCEPTION_OPTION_LAST; i++) {
-               opt = (1 << i);
-               ex_opt_str [i]
-                       = str_list_create (
-                               ped_exception_get_option_string (opt),
-                               _(ped_exception_get_option_string (opt)),
-                               NULL);
-               if (!ex_opt_str [i])
-                       return 0;
-       }
-
-       ex_opt_str [i] = NULL;
-       return 1;
+  for (i = 0; (1 << i) <= PED_EXCEPTION_OPTION_LAST; i++) 
+    {
+      opt = (1 << i);
+      ex_opt_str[i] = 
+       str_list_create (ped_exception_get_option_string (opt),
+                        _(ped_exception_get_option_string (opt)), NULL);
+      if (!ex_opt_str [i])
+       return 0;
+    }
+  ex_opt_str [i] = NULL;
+  return 1;
 }
 
 static void
 done_ex_opt_str ()
 {
-       int     i;
+  int i;
 
-       for (i=0; ex_opt_str [i]; i++)
-               str_list_destroy (ex_opt_str [i]);
+  for (i=0; ex_opt_str [i]; i++)
+    str_list_destroy (ex_opt_str [i]);
 }
 
 static int
 init_state_str ()
 {
-       on_list = str_list_create_unique (_("on"), "on", NULL);
-       off_list = str_list_create_unique (_("off"), "off", NULL);
-       on_off_list = str_list_join (str_list_duplicate (on_list),
-                                    str_list_duplicate (off_list));
-       return 1;
+  on_list = str_list_create_unique (_("on"), "on", NULL);
+  off_list = str_list_create_unique (_("off"), "off", NULL);
+  on_off_list = str_list_join (str_list_duplicate (on_list),
+                              str_list_duplicate (off_list));
+  return 1;
 }
 
 static void
 done_state_str ()
 {
-       str_list_destroy (on_list);
-       str_list_destroy (off_list);
-       str_list_destroy (on_off_list);
+  str_list_destroy (on_list);
+  str_list_destroy (off_list);
+  str_list_destroy (on_off_list);
 }
 
 static int
 init_fs_type_str ()
 {
-       PedFileSystemType*      walk;
-
-       fs_type_list = NULL;
+  PedFileSystemType* walk;
 
-       for (walk = ped_file_system_type_get_next (NULL); walk;
-            walk = ped_file_system_type_get_next (walk))
-       {
-               fs_type_list = str_list_insert (fs_type_list, walk->name);
-               if (!fs_type_list)
-                       return 0;
-       }
+  fs_type_list = NULL;
 
-       return 1;
+  for (walk = ped_file_system_type_get_next (NULL); walk;
+       walk = ped_file_system_type_get_next (walk))
+    {
+      fs_type_list = str_list_insert (fs_type_list, walk->name);
+      if (!fs_type_list)
+       return 0;
+    }
+  return 1;
 }
 
 static int
 init_disk_type_str ()
 {
-       PedDiskType*    walk;
+  PedDiskType* walk;
 
-       disk_type_list = NULL;
-
-       for (walk = ped_disk_type_get_next (NULL); walk;
-            walk = ped_disk_type_get_next (walk))
-       {
-               disk_type_list = str_list_insert (disk_type_list, walk->name);
-               if (!disk_type_list)
-                       return 0;
-       }
+  disk_type_list = NULL;
 
-       return 1;
+  for (walk = ped_disk_type_get_next (NULL); walk;
+       walk = ped_disk_type_get_next (walk))
+    {
+      disk_type_list = str_list_insert (disk_type_list, walk->name);
+      if (!disk_type_list)
+       return 0;
+    }
+  return 1;
 }
 
-void 
-fdisk_usage_msg() {
-        printf (_(usage_msg));
+void
+fdisk_usage_msg()
+{
+  char *s = _("Usage: fdisk [OPTION]... [DEVICE]");
+  puts(s);
 }
 
 void
 fdisk_help_msg ()
 {
-        fdisk_usage_msg();
+  fdisk_usage_msg();
 
-       printf ("\n%s\n", _("OPTIONs:"));
-       fdisk_print_options_help ();
+  printf ("\n%s\n", _("OPTIONs:"));
+  fdisk_print_options_help ();
 /*
        printf ("\n%s\n", _("COMMANDs:"));
        fdisk_print_commands_help ((FdiskCommand**)NULL);
 */
-       exit (0);
+  exit (0);
 }
 
+/* move all in a function so we reduce stack size */
+static void
+do_banner_message(void)
+{
+  char* banner_msg = 
+"Copyright (C) 1998 - 2006 Free Software Foundation, Inc.\n\
+This program is free software, covered by the GNU General Public License.\n\
+\n\
+This program is distributed in the hope that it will be useful,\n\
+but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
+GNU General Public License for more details.\n\n";
+
+  StrList* list;
+  
+  list = str_list_create (_(banner_msg), NULL);
+  str_list_print_wrap (list, fdisk_screen_width (), 0, 0);
+  str_list_destroy (list);
+}
+/*
+ * Begin interactive mode
+ */
 int
 fdisk_interactive_mode (PedDisk** disk, FdiskCommand* cmd_list[])
 {
-       char*           line;
-       StrList*        list;
-       StrList*        command_names = fdisk_command_get_names (cmd_list);
-
-       printf ("%s\n", interface_name);
-
-       list = str_list_create (_(banner_msg), NULL);
-       str_list_print_wrap (list, fdisk_screen_width (), 0, 0);
-       str_list_destroy (list);
-
-       fdisk_print_using_dev ((*disk)->dev);
-
-       while (1) {
-               char*           word;
-               FdiskCommand*   cmd;
-
-               commands = cmd_list;    /* FIXME yucky, nasty, evil hack */
+  char*        line;
+  StrList* list;
+  StrList* command_names = fdisk_command_get_names (cmd_list);
+  
+  puts (interface_name);
+  do_banner_message();
+  fdisk_print_using_dev ((*disk)->dev);
+
+  while (1) 
+    {
+      char* word;
+      FdiskCommand* cmd;
 
-               while (!fdisk_command_line_get_word_count ()) {
-                       if (feof (stdin)) {
-                               printf ("\n");
-                               return 1;
-                       }
-                       prompt_possibilities = 0;
-                       fdisk_command_line_prompt_words ("Command (m for 
help):", NULL,
-                                                        command_names, 1);
-                       prompt_possibilities = 1;
-               }
+      commands = cmd_list;     /* FIXME yucky, nasty, evil hack */
 
-               word = fdisk_command_line_pop_word ();
-               if (word) {
-                       cmd = fdisk_command_get (commands, word);
-                       free (word);
-                       if (cmd) {
-                               if (!fdisk_command_run (cmd, disk))
-                                       fdisk_command_line_flush ();
-                       } else {
-                               fdisk_print_commands_help (commands);
-                       }
-               }
+      while (!fdisk_command_line_get_word_count ()) 
+       {
+         if (feof (stdin))
+           {
+             printf ("\n");
+             return 1;
+           }
+         prompt_possibilities = 0;
+         fdisk_command_line_prompt_words ("Command (m for help):", 
+                                          NULL, command_names, 1);
+         prompt_possibilities = 1;
        }
-
-       return 1;
+      word = fdisk_command_line_pop_word ();
+      if (word) 
+       {
+         cmd = fdisk_command_get (commands, word);
+         free (word);
+         if (cmd) 
+           {
+             if (!fdisk_command_run (cmd, disk))
+               fdisk_command_line_flush ();
+           } 
+         else 
+           {
+             fdisk_print_commands_help (commands);
+           }
+       }
+    }
+  return 1;
 }
 
 /* If menu equals:
  * 0 - expert menu.
- * 1 - filesystem menu. 
+ * 1 - filesystem menu.
  * 2 - bsd menu
  */
 int
@@ -533,7 +614,7 @@
        /* FIXME yucky, nasty, evil hack */
        FdiskCommand **saved_commands = commands;
        commands = cmd_list;
-       
+
 
        while (1) {
                char*           word;
@@ -603,7 +684,7 @@
                return 32768;   /* no wrapping ;) */
 
 /* HACK: don't specify termcap separately - it'll annoy the users. */
-#ifdef HAVE_LIBREADLINE
+#ifdef HAVE_READLINE
        width = tgetnum ("co");
 #endif
 
@@ -634,7 +715,7 @@
        const char*             opt_name;
        int                     i = 0, result;
 
-       for (opt = option_get_next (options, 0); opt && i < sizeof(optlist) - 
1; 
+       for (opt = option_get_next (options, 0); opt && i < sizeof(optlist) - 1;
             opt = option_get_next (options, opt), i++) {
                opt_name = ped_exception_get_option_string (opt);
                optlist[i].option = tolower(opt_name[0]);
@@ -646,10 +727,10 @@
        if (!result)
                return PED_EXCEPTION_UNHANDLED;
 
-       for (opt = option_get_next (options, 0); opt; 
+       for (opt = option_get_next (options, 0); opt;
             opt = option_get_next (options, opt)) {
                opt_name = ped_exception_get_option_string (opt);
-               if (result == tolower(opt_name[0])) 
+               if (result == tolower(opt_name[0]))
                        break;
        }
        return opt;
@@ -973,7 +1054,7 @@
        StrList *possibilities = NULL;
        char *prompt = strdup(head);
        char *result;
-       char buf[128]; 
+       char buf[128];
        int i;
 
        buf[1] = '\0';
@@ -997,14 +1078,14 @@
        /* We add a newline at the end, so _construct_prompt
            handles it as it should */
        prompt = realloc_and_cat (prompt, "\n");
-       
+
 
        /* Queries the user about the option, we turn off the automatic
           adding of possibilities to the prompt */
        prompt_possibilities = 0;
        result = fdisk_command_line_get_word (prompt, NULL, possibilities, 1);
        prompt_possibilities = 1;
-       
+
        /* We can use i, not very intuitive to the coder, but who cares */
        if (result) {
                i = result[0];
@@ -1015,12 +1096,12 @@
        }
        free(prompt);
        return i;
-} 
+}
 
 int
 fdisk_get_partpos (const char* prompt, const void* context, const char 
*possibilities)
 {
-       
+
        const Option *orig_opts = (Option *) context;
        Option opts[5];
        int i,j;
@@ -1032,7 +1113,7 @@
                }
        }
        opts[j].option = 0;
-       
+
        return fdisk_command_line_get_option(prompt, opts);
 }
 int
@@ -1055,7 +1136,7 @@
        if (_can_create_primary (disk)) {
                opts[i].option = 'p';
                opts[i].description = _("primary partition (1-4)");
-               i++; 
+               i++;
        }
        opts[i].option = 0;
        if (i == 0)
@@ -1184,34 +1265,37 @@
 int
 fdisk_init_ui ()
 {
-       fdisk_opt_script_mode = !isatty (0);
+/* Readline support */
 
-       if (!init_ex_opt_str ()
-           || !init_state_str ()
-           || !init_fs_type_str ()
-           || !init_disk_type_str ())
-               return 0;
-       ped_exception_set_handler (exception_handler);
-
-#ifdef HAVE_LIBREADLINE
-       rl_initialize ();
-       rl_attempted_completion_function = (CPPFunction*) 
fdisk_complete_function;
-       readline_state.in_readline = 0;
-#endif
+/* End readline support */
+  fdisk_opt_script_mode = !isatty (0);
+  
+  if (!init_ex_opt_str ()
+      || !init_state_str ()
+      || !init_fs_type_str ()
+      || !init_disk_type_str ())
+    return 0;
+  ped_exception_set_handler (exception_handler);
+
+#ifdef HAVE_READLINE
+  rl_initialize ();
+  rl_attempted_completion_function = (CPPFunction*) fdisk_complete_function;
+  readline_state.in_readline = 0;
+#endif /* HAVE_READLINE */
 
-       signal (SIGINT, &interrupt_handler);
+  signal (SIGINT, &interrupt_handler);
 
-       return 1;
+  return 1;
 }
 
 void
 fdisk_done_ui ()
 {
-       ped_exception_set_handler (NULL);
-       done_ex_opt_str ();
-       done_state_str ();
-       str_list_destroy (fs_type_list);
-       str_list_destroy (disk_type_list);
+  ped_exception_set_handler (NULL);
+  done_ex_opt_str ();
+  done_state_str ();
+  str_list_destroy (fs_type_list);
+  str_list_destroy (disk_type_list);
 }
 
 int
diff -rN -u old-_fdisk0/src/ui.h new-_fdisk0/src/ui.h
--- old-_fdisk0/src/ui.h        2008-09-29 01:17:15.000000000 +0200
+++ new-_fdisk0/src/ui.h        2008-09-29 01:17:16.000000000 +0200
@@ -34,14 +34,14 @@
 
 extern char*   fdisk_prog_name;
 extern int     fdisk_opt_script_mode;
-extern char* interface_name;
+extern char *interface_name;
 extern void fdisk_usage_msg();
 extern void fdisk_help_msg ();
 extern int fdisk_interactive_mode (PedDisk** disk, FdiskCommand* cmd_list[]);
 extern int fdisk_interactive_menu (PedDisk** disk, FdiskCommand* cmd_list[], 
int menu);
 extern int fdisk_screen_width ();
 extern void fdisk_wipe_line ();
-extern PedExceptionOption 
+extern PedExceptionOption
 fdisk_command_line_get_ex_opt (const char* prompt, PedExceptionOption options);
 extern void fdisk_print_options_help ();
 extern void fdisk_print_commands_help (FdiskCommand* cmds[]);
@@ -63,7 +63,7 @@
 /*extern int fdisk_command_line_get_disk (const char* prompt, PedDisk** 
value);*/
 /*extern int fdisk_command_line_get_partition (const char* prompt, PedDisk* 
disk,
                                      PedPartition** value);*/
-/*extern int fdisk_command_line_get_fs_type (const char* prompt, 
+/*extern int fdisk_command_line_get_fs_type (const char* prompt,
                                           const PedFileSystemType*(* value));*/
 /*extern int fdisk_command_line_get_disk_type (const char* prompt, const 
PedDiskType*(* value));*/
 /*extern int fdisk_command_line_get_device (const char* prompt, PedDevice** 
value);*/
@@ -73,7 +73,7 @@
                                      PedPartitionType* type);
 extern char* fdisk_command_line_peek_word ();
 extern int fdisk_command_line_get_option (const char* head, const Option* 
opts);
-extern int fdisk_get_partpos (const char* prompt, const void* context, 
+extern int fdisk_get_partpos (const char* prompt, const void* context,
                               const char *possibilities);
 /*extern int fdisk_command_line_get_sector (const char* prompt, PedDevice* 
dev, PedSector* value,
                                          PedGeometry** range);*/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]