- enhancements (new command makestaticobject)

This commit is contained in:
zolliker
2008-01-18 07:25:48 +00:00
parent 1bcb418ad4
commit af233c713a
2 changed files with 24 additions and 13 deletions

View File

@@ -39,7 +39,7 @@ void MakeInitializer(const char *type, const char *name, Initializer maker,
Initializer GetInitializer(const char *type, const char *name) {
Item *p, **last;
if (startup && pServ->pReader != NULL) {
/* pServ->pReader exists: startup finished */
startup = 0;
@@ -57,12 +57,10 @@ Initializer GetInitializer(const char *type, const char *name) {
}
}
}
p = list;
while (p != NULL && (strcasecmp(p->name, name) != 0 || strcasecmp(p->type, type) != 0)) {
p = p->next;
}
if (p) {
return p->maker;
for (p = list; p != NULL; p = p->next) {
if (strcasecmp(p->name, name) == 0 && strcasecmp(p->type, type) == 0) {
return p->maker;
}
}
return NULL;
}
@@ -70,8 +68,6 @@ Initializer GetInitializer(const char *type, const char *name) {
static int MakeObject(SConnection *con, SicsInterp *sics,
void *data, int argc, char *argv[]) {
CmdInitializer cmdin;
CommandList *command;
char *className;
if (argc < 3) {
SCPrintf(con, eError, "%s needs more arguments", argv[0]);
@@ -80,7 +76,7 @@ static int MakeObject(SConnection *con, SicsInterp *sics,
cmdin = (CmdInitializer)GetInitializer("Object", argv[2]);
if (cmdin) {
return cmdin(con, argc, argv, ! startup);
return cmdin(con, argc, argv, strcasecmp(argv[0],"makeobject") == 0);
} else {
SCPrintf(con, eError, "do not know how to make a %s object", argv[2]);
return 0;
@@ -126,6 +122,8 @@ static int RemoveObject(SConnection *con, SicsInterp *sics,
CmdInitializer cmdin;
CommandList *command;
char *className;
char shortClassName[32];
char *p;
if (argc != 2) {
SCPrintf(con, eError, "%s needs 1 argument", argv[0]);
@@ -139,6 +137,14 @@ static int RemoveObject(SConnection *con, SicsInterp *sics,
}
className = ((pDummy)command->pData)->pDescriptor->name;
cmdin = (CmdInitializer)GetInitializer("Object", className);
if (cmdin == 0) {
/* allow also a longer descriptor starting with the initializer name and a blank */
p = strchr(className, ' ');
if (p) {
snprintf(shortClassName, sizeof shortClassName, "%.*s", p - className, className);
cmdin = (CmdInitializer)GetInitializer("Object", shortClassName);
}
}
if (cmdin) {
/* if we have an initializer, we are allowed to remove */
if (pServ->pExecutor && isInRunMode(pServ->pExecutor)) {
@@ -173,6 +179,7 @@ static void KillInitializers(void *data) {
void MakeDriver(const char *driver, CmdInitializer maker, int startupOnly, const char *desc) {
if (! FindCommand(pServ->pSics, "MakeObject")) {
AddCommandWithFlag(pServ->pSics, "MakeObject", MakeObject, KillInitializers, NULL, 0);
AddCommandWithFlag(pServ->pSics, "MakeStaticObject", MakeObject, NULL, NULL, 0);
AddCommandWithFlag(pServ->pSics, "RemoveObject", RemoveObject, NULL, NULL, 0);
AddCommandWithFlag(pServ->pSics, "DriverList", DriverList, NULL, NULL, 0);
}