- added FindCommandDescriptor to SCinter.*
- modified support for dynamic objects - improved logger system - various fixes
This commit is contained in:
@@ -121,29 +121,31 @@ static int DriverList(SConnection *con, SicsInterp *sics,
|
||||
static int RemoveObject(SConnection *con, SicsInterp *sics,
|
||||
void *data, int argc, char *argv[]) {
|
||||
CmdInitializer cmdin;
|
||||
CommandList *command;
|
||||
ObjectDescriptor *desc;
|
||||
char *className;
|
||||
char shortClassName[32];
|
||||
char *p;
|
||||
int removeAllowed;
|
||||
char *creationCommand;
|
||||
|
||||
if (argc != 2) {
|
||||
SCPrintf(con, eError, "ERROR: should be: %s <object>", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
command = FindCommand(sics, argv[1]);
|
||||
if (!command) {
|
||||
desc = FindCommandDescriptor(sics, argv[1]);
|
||||
if (!desc) {
|
||||
SCPrintf(con, eError, "ERROR: %s not found", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (((pDummy)command->pData)->pDescriptor->creationCommand != NULL) {
|
||||
creationCommand = GetDescriptorKey(desc, "creationCommand");
|
||||
if (creationCommand != NULL) {
|
||||
/* if there is a creationCommand, we are allowed to remove */
|
||||
removeAllowed = 1;
|
||||
} else {
|
||||
/* if we have an initializer: we are also allowed to remove */
|
||||
className = ((pDummy)command->pData)->pDescriptor->name;
|
||||
className = desc->name;
|
||||
cmdin = (CmdInitializer)GetInitializer("Object", className);
|
||||
if (cmdin == 0) {
|
||||
/* allow also a longer descriptor starting with the initializer name and a blank */
|
||||
@@ -169,22 +171,33 @@ static int RemoveObject(SConnection *con, SicsInterp *sics,
|
||||
}
|
||||
}
|
||||
|
||||
static int SaveCreationCommands(void *object, char *name, FILE *fil) {
|
||||
CommandList *p;
|
||||
ObjectDescriptor *desc;
|
||||
int printHeader = 0;
|
||||
typedef struct {
|
||||
int printHeader;
|
||||
FILE *fil;
|
||||
} SaveData;
|
||||
|
||||
static int SaveCreationCommand(char *name, pDummy object, void *userData) {
|
||||
SaveData *saveData = userData;
|
||||
char *creationCommand;
|
||||
|
||||
for (p = pServ->pSics->pCList; p != NULL; p = p->pNext) {
|
||||
desc = ((pDummy)p->pData)->pDescriptor;
|
||||
if (desc->creationCommand && strcmp(desc->creationCommand, "0") != 0) {
|
||||
if (printHeader == 0) {
|
||||
printHeader = 1;
|
||||
fprintf(fil, "\n#--- BEGIN creation commands\n");
|
||||
}
|
||||
fprintf(fil, "%s\n", desc->creationCommand);
|
||||
creationCommand = GetDescriptorKey(object->pDescriptor, "creationCommand");
|
||||
if (creationCommand && strcmp(creationCommand, "0") != 0) {
|
||||
if (saveData->printHeader == 0) {
|
||||
saveData->printHeader = 1;
|
||||
fprintf(saveData->fil, "\n#--- BEGIN creation commands\n");
|
||||
}
|
||||
fprintf(saveData->fil, "%s\n", creationCommand);
|
||||
}
|
||||
if (printHeader == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int SaveCreationCommands(void *object, char *name, FILE *fil) {
|
||||
SaveData saveData;
|
||||
|
||||
saveData.fil = fil;
|
||||
saveData.printHeader = 0;
|
||||
ForEachCommand(SaveCreationCommand, &saveData);
|
||||
if (saveData.printHeader == 1) {
|
||||
fprintf(fil, "#--- END creation commands\n\n");
|
||||
}
|
||||
return 1;
|
||||
@@ -193,37 +206,43 @@ static int SaveCreationCommands(void *object, char *name, FILE *fil) {
|
||||
static int CreationCommand(SConnection *con, SicsInterp *sics,
|
||||
void *data, int argc, char *argv[]) {
|
||||
CmdInitializer cmdin;
|
||||
CommandList *command;
|
||||
char *className;
|
||||
char shortClassName[32];
|
||||
char *p;
|
||||
int removeAllowed;
|
||||
ObjectDescriptor *desc;
|
||||
char *creationCommand;
|
||||
char buf[256];
|
||||
|
||||
if (argc < 2) {
|
||||
SCPrintf(con, eError, "ERROR: should be: %s <object> [<creation command>]", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
command = FindCommand(sics, argv[1]);
|
||||
if (!command) {
|
||||
desc = FindCommandDescriptor(sics, argv[1]);
|
||||
if (!desc) {
|
||||
SCPrintf(con, eError, "ERROR: %s not found", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
desc = ((pDummy)command->pData)->pDescriptor;
|
||||
creationCommand = GetDescriptorKey(desc, "creationCommand");
|
||||
if (argc < 3) {
|
||||
if (desc->creationCommand != NULL) {
|
||||
SCPrintf(con, eValue, "%s", desc->creationCommand);
|
||||
if (creationCommand != NULL) {
|
||||
SCPrintf(con, eValue, "%s", creationCommand);
|
||||
} else {
|
||||
SCPrintf(con, eValue, "<static object>");
|
||||
}
|
||||
} else {
|
||||
if (! desc->creationCommand) {
|
||||
if (!creationCommand) {
|
||||
SCPrintf(con, eValue, "ERROR: %s is a static object", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
free(desc->creationCommand);
|
||||
desc->creationCommand = Arg2Tcl(argc - 2, argv + 2, NULL, -1);
|
||||
creationCommand = Arg2Tcl(argc - 2, argv + 2, buf, sizeof buf);
|
||||
if (creationCommand) {
|
||||
SetDescriptorKey(desc, "creationCommand", creationCommand);
|
||||
if (creationCommand != buf) free(creationCommand);
|
||||
} else {
|
||||
SetDescriptorKey(desc, "creationCommand", "0");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user