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

275 строки
5.4 KiB
C
Исходник Обычный вид История

1998-03-28 05:44:41 +03: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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
// Registry interpreter
#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 09:40:37 +04:00
printf("\t%s -- OK\n", func);
1998-03-28 05:44:41 +03:00
}
else
{
1999-04-15 09:40:37 +04:00
printf("\t%s -- %s\n", func, errstr(err));
1998-03-28 05:44:41 +03:00
}
return err;
} // error
static char *GetNextWord(char *cmd, char *buf)
{
// copies until ',' or eos, then skips spaces
if (!cmd || !buf)
return 0;
while (*cmd && *cmd != ',')
*buf++ = *cmd++;
*buf = '\0';
if (*cmd == ',')
{
cmd++;
while(*cmd && *cmd == ' ')
cmd++;
}
return cmd;
} // GetNextWord
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
void vCreate(char *cmd)
{
// Syntax: Create [new,] 5.0b1
1999-04-15 09:40:37 +04:00
char buf[512];
1998-03-28 05:44:41 +03:00
int flag = 0;
cmd = GetNextWord(cmd, buf);
1999-04-15 09:40:37 +04:00
error("VR_CreateRegistry", VR_CreateRegistry("Communicator", buf, cmd));
1998-03-28 05:44:41 +03:00
} // vCreate
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
void vHelp(char *cmd)
{
puts("Enter a command:");
1999-04-15 09:40:37 +04: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 05:44:41 +03:00
puts("\tI)nstall <name>, <version>, <path> - install a new component");
puts("\tR)emove <name> - deletes a component from the Registry");
1999-04-15 09:40:37 +04: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 05:44:41 +03:00
puts("\tQ)uit - end the program");
} // vHelp
void vInstall(char *cmd)
{
char name[MAXREGPATHLEN+1];
char path[MAXREGPATHLEN+1];
1999-04-15 09:40:37 +04:00
char ver[MAXREGPATHLEN+1];
1998-03-28 05:44:41 +03:00
1999-04-15 09:40:37 +04:00
char *pPath, *pVer;
1998-03-28 05:44:41 +03:00
1999-04-15 09:40:37 +04:00
cmd = GetNextWord(cmd, name);
cmd = GetNextWord(cmd, ver);
cmd = GetNextWord(cmd, path);
1998-03-28 05:44:41 +03:00
1999-04-15 09:40:37 +04:00
pVer = ( ver[0] != '*' ) ? ver : NULL;
pPath = ( path[0] != '*' ) ? path : NULL;
1998-03-28 05:44:41 +03:00
1999-04-15 09:40:37 +04:00
error("VR_Install", VR_Install(name, pPath, pVer, FALSE));
1998-03-28 05:44:41 +03:00
1999-04-15 09:40:37 +04:00
} // vInstall
1998-03-28 05:44:41 +03:00
1999-04-15 09:40:37 +04:00
1998-03-28 05:44:41 +03:00
void interp(void)
{
char line[256];
char *p;
while(1)
{
putchar('>');
putchar(' ');
flushall();
gets(line);
// p points to next word after verb on command line
p = line;
while (*p && *p!=' ')
p++;
if (!*p)
p = 0;
else
{
while(*p && *p==' ')
p++;
}
switch(toupper(line[0]))
{
1999-04-15 09:40:37 +04:00
case 'N':
1998-03-28 05:44:41 +03:00
vCreate(p);
break;
1999-04-15 09:40:37 +04:00
case 'A':
error("VR_SetRegDirectory", VR_SetRegDirectory(p));
break;
case 'C':
error("VR_Close", VR_Close());
break;
1998-03-28 05:44:41 +03:00
case 'I':
vInstall(p);
break;
case 'R':
1999-04-15 09:40:37 +04:00
error("VR_Remove", VR_Remove(p));
1998-03-28 05:44:41 +03:00
break;
1999-04-15 09:40:37 +04: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 05:44:41 +03:00
break;
case 'Q':
return;
} // switch
} // while
assert(0);
return; // shouldn't get here
} // interp
// EOF: interp.c