From 7adbcbd8b6469194109f70063e157caaa6425197 Mon Sep 17 00:00:00 2001 From: "Marcel M. Otte" Date: Wed, 25 Dec 2013 16:27:41 +0000 Subject: [PATCH] added makefile and eclipse cdt project files --- c/.cproject | 45 ++++++++++++++++++++++++++++++++ c/.project | 26 +++++++++++++++++++ c/Makefile | 16 ++++++++++++ c/cmdlineoptions.c | 64 ++++++++++++++++++++++++++++++++++------------ c/cmdlineoptions.h | 25 ++++++++++-------- 5 files changed, 149 insertions(+), 27 deletions(-) create mode 100644 c/.cproject create mode 100644 c/.project create mode 100644 c/Makefile diff --git a/c/.cproject b/c/.cproject new file mode 100644 index 0000000..612e212 --- /dev/null +++ b/c/.cproject @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/c/.project b/c/.project new file mode 100644 index 0000000..87a0d19 --- /dev/null +++ b/c/.project @@ -0,0 +1,26 @@ + + + cmdlineoptions-c + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/c/Makefile b/c/Makefile new file mode 100644 index 0000000..3bc33ab --- /dev/null +++ b/c/Makefile @@ -0,0 +1,16 @@ + + +all: build lib static + +build: + gcc -c cmdlineoptions.c + +lib: + rm -f libcmdlineoptions.a + ar cq libcmdlineoptions.a cmdlineoptions.o + + +static: + rm -f cmdlineoptions-static.o libcmdlineoptions.so + gcc -c -fPIC -o cmdlineoptions-static.o cmdlineoptions.c + ld -G cmdlineoptions-static.o -o libcmdlineoptions.so diff --git a/c/cmdlineoptions.c b/c/cmdlineoptions.c index 74ee562..6ce4a7a 100644 --- a/c/cmdlineoptions.c +++ b/c/cmdlineoptions.c @@ -1,33 +1,65 @@ #include "cmdlineoptions.h" - +#include +#include CmdOptions cmdoptions; -void CmdOptions_Init(){ +void CmdOptions_Init() { if (cmdoptions.init == 0) { cmdoptions.init = 1; // do we have to init something? // add the help option - CmdOptions_Add("help","--help"); - CmdOptions_Add("help","-h"); - CmdOptions_Add("help","-?"); - CmdOptions_AddDescription("help","Display the help text."); + CmdOptions_Add("help", "--help"); + CmdOptions_Add("help", "-h"); + CmdOptions_Add("help", "-?"); + CmdOptions_AddDescription("help", "Display the help text."); } } -int CmdOptions_Parse(int argc, char** argv){ +int CmdOptions_Create(char* name) { + if (CmdOptions_NodeGet(name) == 0) { + CONode* newnode = 0; + newnode = malloc(sizeof(CONode)); + if (cmdoptions.options == 0) { + cmdoptions.options = newnode; + } else { + CONode* last = cmdoptions.options; + while (last->next != 0) + last = last->next; + last->next = newnode; + } + newnode->next = 0; + newnode->option = malloc(sizeof(Option)); + newnode->option->name = name; + } +} + +CONode* CmdOptions_NodeGet(char* name) { + if (cmdoptions.options != 0) { + CONode* node = cmdoptions.options; + while (node != 0) { + if (strcmp(name, node->option->name) == 0) { + return node; + } + node = node->next; + } + } + return 0; +} + +int CmdOptions_Parse(int argc, char** argv) { } -int CmdOptions_Add(char* name, char* option){ +int CmdOptions_Add(char* name, char* option) { } -int CmdOptions_AddDefaultParameter(char* name, char* defaultparameter){ +int CmdOptions_AddDefaultParameter(char* name, char* defaultparameter) { } -int CmdOptions_AddPossibleParameter(char* name, char* possibleParameter){ +int CmdOptions_AddPossibleParameter(char* name, char* possibleParameter) { } @@ -35,26 +67,26 @@ int CmdOptions_AddDescription(char* name, char* description) { } -bool CmdOptions_IsSet(char* name) { +int CmdOptions_IsSet(char* name) { } -char* CmdOptions_Get(char* name) { +char* CmdOptions_Get(char* name) { } -int CmdOptions_GetInt(char* name) { +int CmdOptions_GetInt(char* name) { } -long CmdOptions_GetLong(char* name){ +long CmdOptions_GetLong(char* name) { } -double CmdOptions_GetDouble(char* name) { +double CmdOptions_GetDouble(char* name) { } -int CmdOptions_GetAll(char* name, char** values, unsigned int* count) { +int CmdOptions_GetAll(char* name, char** values, unsigned int* count) { } diff --git a/c/cmdlineoptions.h b/c/cmdlineoptions.h index a552f3a..b47f8d7 100644 --- a/c/cmdlineoptions.h +++ b/c/cmdlineoptions.h @@ -1,7 +1,7 @@ #ifndef CMDLINEOPTIONS_H #define CMDLINEOPTIONS_H -struct Option { +typedef struct { char* name; // the name of this option char** options; //dashed option name and alternatives unsigned int optionscount; // count of option alternatives @@ -13,19 +13,20 @@ struct Option { char** values; // values unsigned int valuecount; // size of the values, if more than one... - bool set; // boolean if this option has been set -}; + char set; // boolean if this option has been set +} Option; -struct CONode { - CONode* prev; - CONode* next; + +typedef struct _CONode { + //CONode* prev; + struct _CONode* next; Option* option; -}; +} CONode; -struct CmdOptions { - bool init; +typedef struct { + char init; CONode* options; -}; +} CmdOptions; /* * Main structure @@ -62,7 +63,7 @@ int CmdOptions_AddDescription(char* name, char* description); /** * Check if the option specified by name is set. */ -bool CmdOptions_IsSet(char* name); +int CmdOptions_IsSet(char* name); /** * Get first parameter of the option specified by name. */ @@ -85,5 +86,7 @@ double CmdOptions_GetDouble(char* name); */ int CmdOptions_GetAll(char* name, char** values, unsigned int* count); +int CmdOptions_Create(char* name); +CONode* CmdOptions_NodeGet(char* name); #endif