Configuration file 
Author Message
 Configuration file

Hi,
I am an absolute newbie, but I have been told to try to figure out a
program for image analyzes made some eight years ago...
In the code, a lot of constants are defined that determines how
objects in the pictures are treated. I would very much like to be able
to adjust these constants without having to recompile all the time.
How can I make some kind of configuration file outside the program.
And how do I actually read the constants into the program?
The program was originally written for the Watcom compiler as a
console program (running in a DOS-window in Win95).
Btw, can I easily switch to OpenWatcom, so I don't have to the old
IDE?
Thanks in advance, Jon
--



Thu, 06 Oct 2005 01:25:01 GMT  
 Configuration file


Quote:
>Hi,
>I am an absolute newbie, but I have been told to try to figure out a
>program for image analyzes made some eight years ago...
>In the code, a lot of constants are defined that determines how
>objects in the pictures are treated. I would very much like to be able
>to adjust these constants without having to recompile all the time.
>How can I make some kind of configuration file outside the program.
>And how do I actually read the constants into the program?
>The program was originally written for the Watcom compiler as a
>console program (running in a DOS-window in Win95).
>Btw, can I easily switch to OpenWatcom, so I don't have to the old
>IDE?
>Thanks in advance, Jon

There is actually a fair chance that you can't. To be honest, if you
really are new to C that kind of task is out of your reach.

As for switching that largely depends on the quality of the code.

--
ACCU Spring Conference 2003 April 2-5
The Conference you should not have missed
ACCU Spring Conference 2004 Late April
Francis Glassborow      ACCU
--



Sat, 08 Oct 2005 00:33:17 GMT  
 Configuration file


Quote:
>I am an absolute newbie, but I have been told to try to figure out a
>program for image analyzes made some eight years ago...
>In the code, a lot of constants are defined that determines how
>objects in the pictures are treated. I would very much like to be able
>to adjust these constants without having to recompile all the time.
>How can I make some kind of configuration file outside the program.
>And how do I actually read the constants into the program?

This is an impossible question to answer, since you've not shown us
what you want to do.  Please give an example piece of code that
defines one of the values you want to make malleable, and show the code
where it is used.  Perhaps we will be able to provide advice then.

The straightforward answer is that you may be able to replace
#define IMAGEWIDTH 1024
with
int imagewidth = 1024;
and change the uses of it appropriately, including a getopt()-using
section at the beginning of main() that would parse "-w 800" on the
command line.  Of course if IMAGEWIDTH is used to size an array, you'll
have to modify that portion of the code to use an array-of-pointers
or similar.

Quote:
>The program was originally written for the Watcom compiler as a
>console program (running in a DOS-window in Win95).
>Btw, can I easily switch to OpenWatcom, so I don't have to the old
>IDE?

You will get better answers to this question if you post to a forum
pertaining directly to Watcom.  Perhaps you could try switching to
OpenWatcom and see if it works.

-andy
--



Sat, 08 Oct 2005 00:33:19 GMT  
 Configuration file

Quote:

> In the code, a lot of constants are defined that determines how
> objects in the pictures are treated. I would very much like to be able
> to adjust these constants without having to recompile all the time.

The two standard methods are as parameters on the command line
when invoking the executable program, and reading from a file
(possibly stdin, but it could be a text file named in a command
line argument).  You need to set up initial "default" values
for the parameters, for use when they aren't overridden from
the command line or parameter file.  Then read the parameters
(store on top of the default initial values), and proceed,
using the values of the parameter variables in place of the
original program's constants.

Quote:
> How can I make some kind of configuration file outside the program.

Text editor.  On Windows that might be Notepad.  A plain ASCII
text format is bar far the best choice.

Quote:
> And how do I actually read the constants into the program?

That depends on how you design the format for the file.
The safest design is to have one parameter per line, with
a name for the parameter alongside its value.  Either
        name=value
or
        name value
Your program would read the parameter file either from stdin
or a stream that was fopen()ed using the name obtained from
the command line.  It should read one line at a time (there
are various ways to do this; the key is to stop after a '\n'),
and for each line look for each parameter name (strncmp() is
useful here) until a match is found, then skip the '=' or
whitespace (isspace() is useful here), then convert the value
text into the value of a variable using sscanf().  There are
a variety of ways to accomplish all this.

It sounds like your best first step might be to spend some
time with a good C tutorial such as 2nd Edition of Kernighan
& Ritchie's "The C Programming Language".
--



Sat, 08 Oct 2005 00:34:13 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. how to: XML file as application configuration file

2. saving configuration files

3. Configuration files for DLL`s when app is unmanaged .exe

4. fgets reading a configuration file: compiles OK but output wrong

5. fgets reading a configuration file:

6. reading a configuration file

7. Loading Configuration files in C#

8. Configuration file

9. reading in configuration files

10. How should I process text configuration files?

11. Application configuration file path

12. gdb and configuration files

 

 
Powered by phpBB® Forum Software