progName = strrchr(argv[0], '/'); progName = progName ? progName+1 : argv[0];
main(int argc, char *argv[]){	int errcode = SUCCESS;	PRBool createdb, readOnly;#define STDINBUF_SIZE 80	char stdinbuf[STDINBUF_SIZE];	PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);	if(parse_args(argc, argv) != SUCCESS) {		usage();		errcode = INVALID_USAGE_ERR;		goto loser;	}	if(verify_params() != SUCCESS) {		usage();		errcode = INVALID_USAGE_ERR;		goto loser;	}	if(command==NO_COMMAND) {		PR_fprintf(PR_STDERR, errStrings[NO_COMMAND_ERR]);		usage();		errcode = INVALID_USAGE_ERR;		goto loser;	}	/* Set up crypto stuff */	createdb = command==CREATE_COMMAND;	readOnly = command==LIST_COMMAND;	/* Make sure browser is not running if we're writing to a database */	/* Do this before initializing crypto */	if(!readOnly && !force) {		char *response;		PR_fprintf(PR_STDOUT, msgStrings[BROWSER_RUNNING_MSG]);		if( ! PR_fgets(stdinbuf, STDINBUF_SIZE, PR_STDIN)) {			PR_fprintf(PR_STDERR, errStrings[STDIN_READ_ERR]);			errcode = STDIN_READ_ERR;			goto loser;		}		if( (response=strtok(stdinbuf, " \r\n\t")) ) {			if(!PL_strcasecmp(response, "q")) {				PR_fprintf(PR_STDOUT, msgStrings[ABORTING_MSG]);				errcode = SUCCESS;				goto loser;			}		}		PR_fprintf(PR_STDOUT, "\n");	}	errcode = init_crypto(createdb, readOnly);	if( errcode != SUCCESS) {		goto loser;	}	/* Execute the command */	switch(command) {	case ADD_COMMAND:		errcode = AddModule(moduleName, libFile, ciphers, mechanisms);		break;	case CHANGEPW_COMMAND:		errcode = ChangePW(tokenName, pwFile, newpwFile);		break;	case CREATE_COMMAND:		/* The work was already done in init_crypto() */		break;	case DEFAULT_COMMAND:		errcode = SetDefaultModule(moduleName, slotName, mechanisms);		break;	case DELETE_COMMAND:		errcode = DeleteModule(moduleName);		break;	case DISABLE_COMMAND:		errcode = EnableModule(moduleName, slotName, PR_FALSE);		break;	case ENABLE_COMMAND:		errcode = EnableModule(moduleName, slotName, PR_TRUE);		break;	case FIPS_COMMAND:		errcode = FipsMode(fipsArg);		break;	case JAR_COMMAND:		Pk11Install_SetErrorHandler(install_error);		errcode = Pk11Install_DoInstall(jarFile, installDir, tempDir,						PR_STDOUT, force, nocertdb);		break;	case LIST_COMMAND:		if(moduleName) {			errcode = ListModule(moduleName);		} else {			errcode = ListModules();		}		break;	case UNDEFAULT_COMMAND:		errcode = UnsetDefaultModule(moduleName, slotName, mechanisms);		break;	default:		PR_fprintf(PR_STDERR, "This command is not supported yet.\n");		errcode = INVALID_USAGE_ERR;		break;	}loser:	PR_Cleanup();	return errcode;}