gecko-dev/modules/libreg/tests/interp.c

279 lines
5.6 KiB
C
Raw Normal View History

1998-03-28 02:44:41 +00:00
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
1998-03-28 02:44:41 +00:00
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
1998-03-28 02:44:41 +00:00
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
1998-03-28 02:44:41 +00:00
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
1998-03-28 02:44:41 +00:00
*/
/* Registry interpreter */
1998-03-28 02:44:41 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "VerReg.h"
#include "NSReg.h"
extern char *errstr(REGERR err);
extern int DumpTree(void);
int error(char *func, int err)
{
if (err == REGERR_OK)
{
1999-04-15 05:40:37 +00:00
printf("\t%s -- OK\n", func);
1998-03-28 02:44:41 +00:00
}
else
{
1999-04-15 05:40:37 +00:00
printf("\t%s -- %s\n", func, errstr(err));
1998-03-28 02:44:41 +00:00
}
return err;
} /* error */
1998-03-28 02:44:41 +00:00
static char *GetNextWord(char *cmd, char *buf)
{
/* copies until ',' or eos, then skips spaces */
1998-03-28 02:44:41 +00:00
if (!cmd || !buf)
return 0;
while (*cmd && *cmd != ',')
*buf++ = *cmd++;
*buf = '\0';
if (*cmd == ',')
{
cmd++;
while(*cmd && *cmd == ' ')
cmd++;
}
return cmd;
} /* GetNextWord */
1998-03-28 02:44:41 +00:00
static int vr_ParseVersion(char *verstr, VERSION *result)
{
result->major = result->minor = result->release = result->build = 0;
result->major = atoi(verstr);
while (*verstr && *verstr != '.')
verstr++;
if (*verstr)
{
verstr++;
result->minor = atoi(verstr);
while (*verstr && *verstr != '.')
verstr++;
if (*verstr)
{
verstr++;
result->release = atoi(verstr);
while (*verstr && *verstr != '.')
verstr++;
if (*verstr)
{
verstr++;
result->build = atoi(verstr);
while (*verstr && *verstr != '.')
verstr++;
}
}
}
return REGERR_OK;
} /* ParseVersion */
1998-03-28 02:44:41 +00:00
void vCreate(char *cmd)
{
/* Syntax: Create [new,] 5.0b1 */
1999-04-15 05:40:37 +00:00
char buf[512];
1998-03-28 02:44:41 +00:00
int flag = 0;
cmd = GetNextWord(cmd, buf);
1999-04-15 05:40:37 +00:00
error("VR_CreateRegistry", VR_CreateRegistry("Communicator", buf, cmd));
1998-03-28 02:44:41 +00:00
} /* vCreate */
1998-03-28 02:44:41 +00:00
void vFind(char *cmd)
{
VERSION ver;
char path[MAXREGPATHLEN];
if (error("VR_GetVersion", VR_GetVersion(cmd, &ver)) == REGERR_OK)
{
if (error("VR_GetPath", VR_GetPath(cmd, sizeof(path), path)) == REGERR_OK)
{
printf("%s found: ver=%d.%d.%d.%d, check=0x%04x, path=%s\n",
cmd, ver.major, ver.minor, ver.release, ver.build, ver.check,
path);
return;
}
}
printf("%s not found.\n", cmd);
return;
} /* vFind */
1998-03-28 02:44:41 +00:00
void vHelp(char *cmd)
{
puts("Enter a command:");
1999-04-15 05:40:37 +00:00
puts("\tN)ew <dir> [, <ver>] - create a new registry");
puts("\tA)pp <dir> - set application directory");
puts("\tC)lose - close the registry");
puts("");
1998-03-28 02:44:41 +00:00
puts("\tI)nstall <name>, <version>, <path> - install a new component");
puts("\tR)emove <name> - deletes a component from the Registry");
1999-04-15 05:40:37 +00:00
puts("\tX)ists <name> - checks for existence in registry");
puts("\tT)est <name> - validates physical existence");
puts("\tE)num <name> - dumps named subtree");
puts("");
puts("\tV)ersion <name> - gets component version");
puts("\tP)ath <name> - gets component path");
puts("\treF)count <name> - gets component refcount");
puts("\tD)ir <name> - gets component directory");
puts("\tSR)efcount <name>- sets component refcount");
puts("\tSD)ir <name> - sets component directory");
puts("");
1998-03-28 02:44:41 +00:00
puts("\tQ)uit - end the program");
} /* vHelp */
1998-03-28 02:44:41 +00:00
void vInstall(char *cmd)
{
char name[MAXREGPATHLEN+1];
char path[MAXREGPATHLEN+1];
1999-04-15 05:40:37 +00:00
char ver[MAXREGPATHLEN+1];
1998-03-28 02:44:41 +00:00
1999-04-15 05:40:37 +00:00
char *pPath, *pVer;
1998-03-28 02:44:41 +00:00
1999-04-15 05:40:37 +00:00
cmd = GetNextWord(cmd, name);
cmd = GetNextWord(cmd, ver);
cmd = GetNextWord(cmd, path);
1998-03-28 02:44:41 +00:00
1999-04-15 05:40:37 +00:00
pVer = ( ver[0] != '*' ) ? ver : NULL;
pPath = ( path[0] != '*' ) ? path : NULL;
1998-03-28 02:44:41 +00:00
1999-04-15 05:40:37 +00:00
error("VR_Install", VR_Install(name, pPath, pVer, FALSE));
1998-03-28 02:44:41 +00:00
} /* vInstall */
1998-03-28 02:44:41 +00:00
1999-04-15 05:40:37 +00:00
1998-03-28 02:44:41 +00:00
void interp(void)
{
char line[256];
char *p;
while(1)
{
putchar('>');
putchar(' ');
fflush(stdin); fflush(stdout); fflush(stderr);
1998-03-28 02:44:41 +00:00
gets(line);
/* p points to next word after verb on command line */
1998-03-28 02:44:41 +00:00
p = line;
while (*p && *p!=' ')
p++;
if (!*p)
p = 0;
else
{
while(*p && *p==' ')
p++;
}
switch(toupper(line[0]))
{
1999-04-15 05:40:37 +00:00
case 'N':
1998-03-28 02:44:41 +00:00
vCreate(p);
break;
1999-04-15 05:40:37 +00:00
case 'A':
error("VR_SetRegDirectory", VR_SetRegDirectory(p));
break;
case 'C':
error("VR_Close", VR_Close());
break;
1998-03-28 02:44:41 +00:00
case 'I':
vInstall(p);
break;
case 'R':
1999-04-15 05:40:37 +00:00
error("VR_Remove", VR_Remove(p));
1998-03-28 02:44:41 +00:00
break;
1999-04-15 05:40:37 +00:00
case 'X':
error("VR_InRegistry", VR_InRegistry(p));
break;
case 'T':
error("VR_ValidateComponent", VR_ValidateComponent(p));
break;
#if LATER
case 'E':
vEnum(p);
break;
case 'V':
vVersion(p);
break;
case 'P':
vPath(p);
break;
case 'F':
vGetRefCount(p);
break;
case 'D':
vGetDir(p);
break;
case 'S':
puts("--Unsupported--");
#endif
case 'H':
default:
vHelp(line);
1998-03-28 02:44:41 +00:00
break;
case 'Q':
return;
} /* switch */
} /* while */
1998-03-28 02:44:41 +00:00
assert(0);
return; /* shouldn't get here */
1998-03-28 02:44:41 +00:00
} /* interp */
1998-03-28 02:44:41 +00:00
/* EOF: interp.c */