Update a configuration file: Difference between revisions

From Rosetta Code
Content added Content deleted
(initial draft)
 
(wiki syntax fixes)
Line 3: Line 3:
We have a configuration file as follows:
We have a configuration file as follows:


# This is a configuration file in standard configuration file format
# This is a configuration file in standard configuration file format
#
#
# Lines begininning with a hash or a semicolon are ignored by the application
# Lines begininning with a hash or a semicolon are ignored by the application
# program. Blank lines are also ignored by the application program.
# program. Blank lines are also ignored by the application program.


# Note that configuration option names are not case sensitive
# Note that configuration option names are not case sensitive


# This is a favourite fruit
# This is a favourite fruit
FAVOURITEFRUIT banana
FAVOURITEFRUIT banana


# This is a boolean that should be set
# This is a boolean that should be set
NEEDSPEELING
NEEDSPEELING


# This boolean is commented out
# This boolean is commented out
; SEEDSREMOVED
; SEEDSREMOVED


# How many bananas we have
# How many bananas we have
NUMBEROFBANANAS 48
NUMBEROFBANANAS 48


The task is to manipulate the configuration file as follows:
The task is to manipulate the configuration file as follows:

Revision as of 00:23, 20 May 2011

Update a configuration file is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

We have a configuration file as follows:

# This is a configuration file in standard configuration file format
#
# Lines begininning with a hash or a semicolon are ignored by the application
# program. Blank lines are also ignored by the application program.
# Note that configuration option names are not case sensitive
# This is a favourite fruit
FAVOURITEFRUIT banana
# This is a boolean that should be set
NEEDSPEELING
# This boolean is commented out
; SEEDSREMOVED
# How many bananas we have
NUMBEROFBANANAS 48

The task is to manipulate the configuration file as follows:

  • Comment out the needspeeling option (using a semicolon prefix)
  • Uncomment the seedsremoved option by removing the semicolon and any leading whitespace
  • Change the numberofbananas parameter to 1024
  • Uncomment or create a new parameter for numberofstrawberries with a value of 62000

Note that configuration option names are not case sensitive. This means that changes should be effected, regardless of the case.

Option comments are made always using a semicolon. Lines beginning with hash symbols should not be manipulated and left unchanged in the revised file.

If a configuration option does not exist within the file, it should be added during this update.

In commenting out an option, any duplicates should also become commented. In uncommenting an option, only the first instance should become uncommented.

If an option for uncommenting cannot be found, then it should be created by this update. Likewise if a commented option cannot be found then it should be created. (So the revised file should contain appropriate entries, whether commented or not for needspeeling,seedsremoved,numberofbananas and numberofstrawberries.)

The update may rewrite configuration entry in capital letters. However lines beginning with hashes and any parameter data must not be capitalized (eg the favourite fruit banana must not become capitalized). The update process should also replace double semicolon prefixes with just a single semicolon (unless it is uncommenting the option, in which case it should remove all leading semicolons).