Hi all,
I have read the FAQ on running a program from within a program, but I don't think that that's my answer. From google, I only got C++ stuff.
I'd appreciate any input, or ideas on where to start looking (functions, links, etc.)
I basically have the following:
- a file of data (matrices), [cameraFile]
- a file of commands, [commFile]: for example:
<commFile>
# comment
# comment
datafile cameraFile
function1 arg1 arg2 arg3
function1 arg1 arg2
function2 arg1 arg2 arg3 arg4
..... ,,,</commFile>
Now, the user is supposed to type:
myFile commFile
where myFile is my C file with the main.
This will access the command file, fetch the data file name from there, read the data file, store it, and them apply the commands on the data. The commands are functions that I will write (foo(), bar()...).
I wrote the piece of code that reads the commands and stores the data. I intended to put foo(), bar() and the rest of them in the same file as the one called by main, but I'm not sure it's the best idea.
My main problem is that I don't know how to go from the stored commands and args as strings (after I read the command file, e.g. "foo", "bar", "args1", "args2"), to actually calling them: foo(args1), bar(args2). I'm also not sure if I should put them in another file or the same one.
My code (with collapsed functions):
main:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]){
[... var declarations ... ]
readCommands(argv[1]);
return 0;
}
the other file:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "helperFunctions.h"
// returns the tokens in a file, and the number of tokens
int getWords(char *fptr, char* words[]){
}
//store variables in camera file (tokens)
void storeVarsCam(int nbWords, char* words[]){
}
//store variables in command file (tokens)
void storeVarsComm(int nbWords, char* words[], char* cameraFile){
}
//reads data from the camera files and stores it
void readCameras(char* fptr, char* words[]){
}
void readCommands(char* fptr){
int i;
int nbTokens = 0;
char* camFile;
char* tokens[500]; //500 words per file, change to dynamic allocation
camFile = malloc(7*sizeof(char)); //"camera"
for(i=0; i<500; i++){
tokens[i] = malloc(30*sizeof(char)); // 29 characters + '\0'
}
nbTokens = getWords(fptr, tokens);
storeVarsComm(nbTokens, tokens, camFile);
readCameras(camFile, tokens);
}
Thanks.