Add loops, conditionals and simple math.

This commit is contained in:
relyea%netscape.com 2005-11-15 01:49:01 +00:00
Родитель f2232124e1
Коммит 868598f26a
4 изменённых файлов: 164 добавлений и 5 удалений

Просмотреть файл

@ -1221,6 +1221,13 @@ const Commands _commands[] = {
" size number of elements in the array\n", " size number of elements in the array\n",
{ArgVar|ArgNew, ArgVar, ArgULong, ArgNone, ArgNone, {ArgVar|ArgNew, ArgVar, ArgULong, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }}, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"NewInitArg", F_NewInitializeArgs,
"NewInitArg varName string\n\n"
"Creates a new init variable.\n"
" varName variable name of the new initArg\n"
" string string parameter for init arg\n",
{ArgVar|ArgNew, ArgULong, ArgVar|ArgNew, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"NewTemplate", F_NewTemplate, {"NewTemplate", F_NewTemplate,
"NewTemplate varName attributeList\n\n" "NewTemplate varName attributeList\n\n"
"Create a new empty template and populate the attribute list\n" "Create a new empty template and populate the attribute list\n"
@ -1291,11 +1298,21 @@ const Commands _commands[] = {
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }}, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"Restore", F_RestoreVar, {"Restore", F_RestoreVar,
"Restore filename variable\n\n" "Restore filename variable\n\n"
"Restors a variable from a file\n" "Restores a variable from a file\n"
" fileName target file to restore the variable from\n" " fileName target file to restore the variable from\n"
" variable variable to restore\n", " variable variable to restore\n",
{ArgVar|ArgNew, ArgVar, ArgNone, ArgNone, ArgNone, {ArgVar|ArgNew, ArgVar, ArgNone, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }}, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"Increment", F_Increment,
"Increment variable value\n\n"
"Increment a variable by value\n",
{ArgVar, ArgULong, ArgNone, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"Decrement", F_Decrement,
"Decrement variable value\n\n"
"Decrement a variable by value\n",
{ArgVar, ArgULong, ArgNone, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"List", F_List, {"List", F_List,
"List all the variables\n", "List all the variables\n",
{ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, {ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
@ -1315,14 +1332,31 @@ const Commands _commands[] = {
{ArgVar|ArgFull, ArgNone, ArgNone, ArgNone, ArgNone, {ArgVar|ArgFull, ArgNone, ArgNone, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }}, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"System", F_System, {"System", F_System,
"Fix Me... ", "Set System Flag",
{ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, {ArgULong, ArgNone, ArgNone, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }}, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"LoopRun", F_Loop,
"LoopRun filename var start end step\n\n"
"Run in a loop. Loop exit if scrip does and explicit quit (Quit QuitIf etc.)",
{ArgVar|ArgNew, ArgVar|ArgNew, ArgULong, ArgULong, ArgULong,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"Help", F_Help, {"Help", F_Help,
"Help [command]\n\n" "Help [command]\n\n"
"print general help, or help for a specific command\n", "print general help, or help for a specific command\n",
{ArgVar|ArgOpt, ArgNone, ArgNone, ArgNone, ArgNone, {ArgVar|ArgOpt, ArgNone, ArgNone, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }}, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"QuitIf", F_QuitIf,
"QuitIf arg1 comparator arg2\n\n"
"Exit from this program if Condition is valid, valid comparators:\n"
" < > <= >= = !=\n",
{ArgULong, ArgVar|ArgNew, ArgULong, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"QuitIfString", F_QuitIfString,
"QuitIfString arg1 comparator arg2\n\n"
"Exit from this program if Condition is valid, valid comparators:\n"
" = !=\n",
{ArgVar|ArgNew, ArgVar|ArgNew, ArgVar|ArgNew, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"Quit", F_Quit, {"Quit", F_Quit,
"Exit from this program", "Exit from this program",
{ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, {ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,

Просмотреть файл

@ -220,6 +220,12 @@ argFreeData(Value *arg)
free(template[i].pValue); free(template[i].pValue);
} }
} }
if ((arg->type & ArgMask) == ArgInitializeArgs) {
CK_C_INITIALIZE_ARGS *init = (CK_C_INITIALIZE_ARGS *)arg->data;
if (init->LibraryParameters) {
free(init->LibraryParameters);
}
}
free(arg->data); free(arg->data);
} }
arg->type &= ~ArgStatic; arg->type &= ~ArgStatic;
@ -345,7 +351,7 @@ NewValue(ArgType type, CK_ULONG arraySize)
return NULL; return NULL;
} }
value->reference = 1; value->reference = 1;
value->arraySize = arraySize; value->arraySize = (type == ArgChar) ? 1: arraySize;
memset(value->data, 0, value->size); memset(value->data, 0, value->size);
return value; return value;
@ -735,6 +741,22 @@ NewMechanism(const char *bp, CK_ULONG mechType)
return CKR_OK; return CKR_OK;
} }
CK_RV
NewInitializeArgs(const char *bp, CK_ULONG flags, const char *param)
{
Value *value; /* new Value */
CK_C_INITIALIZE_ARGS *init;
value = NewValue(ArgInitializeArgs, 1);
init = (CK_C_INITIALIZE_ARGS *)value->data;
init->flags = flags;
if (strcmp(param, "null") != 0) {
init->LibraryParameters = (CK_CHAR_PTR *)strdup(param);
}
(void) AddVariable(bp, &value);
return CKR_OK;
}
/* /*
* add a new variable to the chain * add a new variable to the chain
*/ */
@ -933,6 +955,26 @@ save(const char *filename,Value *ptr)
return CKR_OK; return CKR_OK;
} }
static CK_RV
increment(Value *ptr, CK_ULONG value)
{
if ((ptr->type & ArgMask) != ArgULong) {
return CKR_ARGUMENTS_BAD;
}
*(CK_ULONG *)ptr->data += value;
return CKR_OK;
}
static CK_RV
decrement(Value *ptr, CK_ULONG value)
{
if ((ptr->type & ArgMask) != ArgULong) {
return CKR_ARGUMENTS_BAD;
}
*(CK_ULONG *)ptr->data -= value;
return CKR_OK;
}
CK_RV CK_RV
printArg(Value *ptr,int arg_number) printArg(Value *ptr,int arg_number)
{ {
@ -1104,6 +1146,9 @@ printArg(Value *ptr,int arg_number)
case ArgInitializeArgs: case ArgInitializeArgs:
initArgs = (CK_C_INITIALIZE_ARGS *)ptr->data; initArgs = (CK_C_INITIALIZE_ARGS *)ptr->data;
printFlags(" Flags: ", initArgs->flags, ConstInitializeFlags); printFlags(" Flags: ", initArgs->flags, ConstInitializeFlags);
if (initArgs->LibraryParameters) {
printf("Params: %s\n",initArgs->LibraryParameters);
}
case ArgFunctionList: case ArgFunctionList:
functionList = (CK_FUNCTION_LIST *)ptr->data; functionList = (CK_FUNCTION_LIST *)ptr->data;
printf(" Version: %d.%02d\n", VERSION(functionList->version)); printf(" Version: %d.%02d\n", VERSION(functionList->version));
@ -1494,8 +1539,43 @@ printGeneralHelp(void)
return CKR_OK; return CKR_OK;
} }
static CK_RV
quitIf(CK_ULONG a, const char *cmp, CK_ULONG b)
{
if (strcmp(cmp, "<") == 0) {
return (a < b) ? CKR_QUIT : CKR_OK;
} else if (strcmp(cmp, ">") == 0) {
return (a > b) ? CKR_QUIT : CKR_OK;
} else if (strcmp(cmp, "<=") == 0) {
return (a <= b) ? CKR_QUIT : CKR_OK;
} else if (strcmp(cmp, ">=") == 0) {
return (a >= b) ? CKR_QUIT : CKR_OK;
} else if (strcmp(cmp, "=") == 0) {
return (a == b) ? CKR_QUIT : CKR_OK;
} else if (strcmp(cmp, "!=") == 0) {
return (a != b) ? CKR_QUIT : CKR_OK;
}
printf("Unkown integer comparator: '%s'\n", cmp);
return CKR_ARGUMENTS_BAD;
}
static CK_RV
quitIfString(const char *a, const char *cmp, const char *b)
{
if (strcmp(cmp, "=") == 0) {
return (strcmp(a,b) == 0) ? CKR_QUIT : CKR_OK;
} else if (strcmp(cmp, "!=") == 0) {
return (strcmp(a,b) != 0) ? CKR_QUIT : CKR_OK;
}
printf("Unkown string comparator: '%s'\n", cmp);
return CKR_ARGUMENTS_BAD;
}
CK_RV run(const char *); CK_RV run(const char *);
CK_RV timeCommand(const char *); CK_RV timeCommand(const char *);
CK_RV loop(const char *filename, const char *var,
CK_ULONG start, CK_ULONG end, CK_ULONG step) ;
/* /*
* Actually dispatch the function... Bad things happen * Actually dispatch the function... Bad things happen
@ -1901,6 +1981,10 @@ do_func(int index, Value **a)
return restore(a[0]->data,a[1]); return restore(a[0]->data,a[1]);
case F_Delete: case F_Delete:
return DeleteVariable(a[0]->data); return DeleteVariable(a[0]->data);
case F_Increment:
return increment(a[0], *(CK_ULONG *)a[1]->data);
case F_Decrement:
return decrement(a[0], *(CK_ULONG *)a[1]->data);
case F_List: case F_List:
return list(); return list();
case F_Run: case F_Run:
@ -1926,6 +2010,9 @@ do_func(int index, Value **a)
case F_NewMechanism: case F_NewMechanism:
(void) DeleteVariable(a[0]->data); (void) DeleteVariable(a[0]->data);
return NewMechanism(a[0]->data,*(CK_ULONG *)a[1]->data); return NewMechanism(a[0]->data,*(CK_ULONG *)a[1]->data);
case F_NewInitializeArgs:
(void) DeleteVariable(a[0]->data);
return NewInitializeArgs(a[0]->data,*(CK_ULONG *)a[1]->data,a[2]->data);
case F_System: case F_System:
value = *(int *)a[0]->data; value = *(int *)a[0]->data;
if (value & 0x80000000) { if (value & 0x80000000) {
@ -1934,6 +2021,9 @@ do_func(int index, Value **a)
systemFlags |= value; systemFlags |= value;
} }
return CKR_OK; return CKR_OK;
case F_Loop:
return loop(a[0]->data,a[1]->data,*(CK_ULONG *)a[2]->data,
*(CK_ULONG *)a[3]->data,*(CK_ULONG *)a[4]->data);
case F_Help: case F_Help:
if (a[0]) { if (a[0]) {
helpIndex = lookup(a[0]->data); helpIndex = lookup(a[0]->data);
@ -1944,6 +2034,10 @@ do_func(int index, Value **a)
return CKR_OK; return CKR_OK;
} }
return printGeneralHelp(); return printGeneralHelp();
case F_QuitIfString:
return quitIfString(a[0]->data,a[1]->data,a[2]->data);
case F_QuitIf:
return quitIf(*(CK_ULONG *)a[0]->data,a[1]->data,*(CK_ULONG *)a[2]->data);
case F_Quit: case F_Quit:
return CKR_QUIT; return CKR_QUIT;
default: default:
@ -1992,7 +2086,8 @@ processCommand(const char * buf)
return error; return error;
} }
CK_RV timeCommand(const char *command) CK_RV
timeCommand(const char *command)
{ {
CK_RV ckrv; CK_RV ckrv;
PRIntervalTime startTime = PR_IntervalNow(); PRIntervalTime startTime = PR_IntervalNow();
@ -2036,7 +2131,8 @@ process(FILE *inFile,int user)
return ckrv; return ckrv;
} }
CK_RV run(const char *filename) CK_RV
run(const char *filename)
{ {
FILE *infile; FILE *infile;
CK_RV ckrv; CK_RV ckrv;
@ -2054,6 +2150,29 @@ CK_RV run(const char *filename)
return ckrv; return ckrv;
} }
CK_RV
loop(const char *filename, const char *var,
CK_ULONG start, CK_ULONG end, CK_ULONG step)
{
CK_ULONG i = 0;
Value *value = 0;
CK_RV ckrv;
for (i=start; i < end; i += step)
{
value = NewValue(ArgULong, 1);
*(CK_ULONG *)value->data = i;
DeleteVariable(var);
AddVariable(var, &value);
ckrv = run(filename);
argFree(value);
if (ckrv == CKR_QUIT) {
break;
}
}
return ckrv;
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {

Просмотреть файл

@ -16,6 +16,7 @@ typedef enum {
F_SetVar, F_SetVar,
F_SetStringVar, F_SetStringVar,
F_NewArray, F_NewArray,
F_NewInitializeArgs,
F_NewTemplate, F_NewTemplate,
F_NewMechanism, F_NewMechanism,
F_BuildTemplate, F_BuildTemplate,
@ -23,15 +24,20 @@ typedef enum {
F_Print, F_Print,
F_SaveVar, F_SaveVar,
F_RestoreVar, F_RestoreVar,
F_Increment,
F_Decrement,
F_Delete, F_Delete,
F_List, F_List,
F_Run, F_Run,
F_Load, F_Load,
F_Unload, F_Unload,
F_System, F_System,
F_Loop,
F_Time, F_Time,
F_Help, F_Help,
F_Quit, F_Quit,
F_QuitIf,
F_QuitIfString,
} FunctionType; } FunctionType;
/* /*

Двоичные данные
security/nss/cmd/pk11util/scripts/pkey

Двоичный файл не отображается.