This section is intended for whose who wants to extend the command line user interface. The interface can be easily extended in two ways: either new commands can be added or behaviour of command line can be modified (for detailed description see section General structure of command line user interface code). This section is not definitely interested for you if you plan only using command line interface of Partition Surprise.
The implementation of command line user interface can be found
in src/client/cmdline/interface.c
. This file contains
the only function int cmdline(void)
which initializes used data
structures and starts a loop in which it reads in a command and processes
it. Library libreadline
is used for reading input if available.
The processing of input is simple - all the implemented commands are listed
in array cmdline_implemented
located
in src/client/cmdline/implemented.c
. The function simply
scans the array and if the command is found the appropriate
routine is called. The number of implemented commands is stored
in constant int cmdline_numimplemented
.
Each of the routines can be found in a separate file named
src/client/cmdline/cmdline_name.c
where `name' is the name of the command.
The cmdline_implemented
array is an array of
the following data structure:
struct cmdline_commands { char *cc_name; int (*cc_command)(char *,struct resources *,struct final *,ERR_PARAM); char *cc_description; };
The member item cc_name
contains the name of the command (e.g. `start').
The member item cc_command
is the routine to be called if the command
is read from the user. This routine has four parameters - the first one is
the command of the user, the second one is struct resources
describing
resources of the computer returned by a call of get_resources()
,
the third one is struct final
which is passed to commit()
during
the partition modification process and the last one is a pseudoparameter
of error system. The last member item cc_description
contains
simple info about the command (e.g. `start - restarts Partition Surprise').
The function cmdline()
maintains two main global structures -
one is of type struct resources
and the other of type
struct final
. Both these structures are passed and can be modified
and routines for performing user commands. Routine for `start' command
simply discards both these structures, calls get_resources()
to
obatin an original struct resources
and fills in appropriately (with
defaults) struct final
. Routine for `move' command will only
modify struct final
to reflect the move of a partition requested
by a user.
The routine function usually takes use of some special macros or
special functions for parsing input and modifiing the structures
struct resources
and struct final
; their description can
be found in Section
Special purpose functions of command line user interface code. The routine function can returned
one of the following three values: CMDL_OKAY
if the command was
succesfully processed, CMDL_QUIT
if the command line user interface
should be quited after the command or CMDL_ERROR
if a fatal error
occured. Note that if only there are only non-fatal errors returned
by calling surprise library CMDL_OKAY
should be returned. The value
CMDL_ERROR
should be returned only in cases such as low memory.
After the routine is performed all the errors returned by the routine are
shown to the user.
There are two special functions to perform progress indicating and
conversion abort during the conversion (when commit()
is called
in modification mode). These functions are:
This function is called during conversion to update the progress bar
to the user. If the flag cmdline_gotabort
it returns an appropriate
value to notify the converter (part of Surprise Library) to abort
the conversion if possible (i.e. not dangerous).
This function si called during conversion if SIGINT
received.
The only purpose of this function is to set flag cmdline_gotabort
.
The list of routines implementing the commands follows. Each of the routine
is located in a separate file src/client/cmdline/name.c
where
`name' is the name of the routine.
This routine initializes data structures
by calling function get_resources
.
This routine causes the interface to quit.
This routine prints out the version of the Surprise library.
This routine prints out basic help containg information about implemented commands.
This routine add a new device to the list of probed devices; the routine
does not call get_resources()
, the routine only add the device to
the list.
This routine prints the list of probed devices.
This routine removes a device from the list of probed devices.
This routine prints out basic information about disk or partition.
This routine summarizes available space on disk.
This routine prints out the state - e.g. the information about the original and the planned partitioning of the disk.
This routine calls commit()
in check-only mode.
This routine calls commit()
in modification mode.
This routine creates a new partition.
This routine deletes a partition.
This routine creates an empty filesystem on a specified partition.
This routine converts (changes) the filesystem on a specified partition.
This routine changes the name (i.e. the order) of a specified partition.
This routine moves a specified partition.
This routine makes a copy of a specified partition.
This routine changes the size (shrinks or enlarge) a specified partition.
This routine prints out the parameters of the filesystem detected by Surprise Library and allows to change them.
This routine prints out and modifies the global conversion parameters.
This routine prints out and modifies parameters of created filesystems.
There are generally three kinds of special purpose functions: ones
for parsing input, the others for printing out output and the last ones
for modifiing data structures struct resources
and struct final
.
All of these functions are desribed in this section.
This macro declares local variables used for parsing input.
This macro calls function cmd_analyze
to analyze the input line.
This macro sets int variable p
to one if the option s
is present.
This macro adds an error if there is an option not processed by CMD_OPTION
.
This macro frees memory used for storing the input line if library libreadline
used.
This macro uses CMD_RETURN_FREE
and quits the routine with a value of x
returned.
This string contains all the characters to be considered as white characters.
This functions parses input line pointed by line
. The number of options
is stored in optnum
and the optiones theirselves in the array options
.
The number of parameters is stored in parnum
and the parameters
theirselves in the array parameters
.
This functions reads in number pointed by c
and stores in memory
location pointed by b
. The function support suffixes k
,
M
and G
.
This function search array r
containing count
structures
for a disk named *c1
. If search is unsuccessful parameter c2
is used in an error message.
This function search array r
containing count
structures
for a partition with number *c1
.
If search is unsuccessful parameter c2
is used in an error message.
This macro prints out the string specified by Fmt
.
This function prints out information about the partition on which data
pointed by struct user_directory *
are planned to be stored.
The strcuture struct resources *
is used to obtain information
about original location of datas.
This function prints out the parameter pointed by its first argument.
This function returns the name of filesystem type
; the information
about supported filesystems are stored in struct resources *r
.
This function sorts the partitions in array par
(the number of
partitions is num
) accroding to their numbers (up_num
).
This function sets the parameter which
in array par
of
containing num
parameters to value
. The flag imp
is
set if the partition is considered as imported and unset otherwise.
This function invalidates partition entries in struct disk_info *p
supposing that partition numbered num
was modified.
This function removes all the parameters with unset `import flag'.
This function removes all the parameters with unset `export flag'.
This function fills struct user_partition
with defaults
proposed by struct resources
.