SICS-687 Add 'nxscript makenamedlink' command.
This commit is contained in:

committed by
Ferdi Franceschini

parent
650d1c0127
commit
e9399b6990
120
nxdict.c
120
nxdict.c
@ -1475,6 +1475,126 @@ NXstatus NXDinfoalias(NXhandle hFil, NXdict dict, char *pAlias, int *rank,
|
|||||||
return iRet;
|
return iRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
NXstatus NXDdefnamedlink(NXhandle hFil, NXdict dict,
|
||||||
|
char *pTarget, char *pVictim, char *newname)
|
||||||
|
{
|
||||||
|
NXdict pDict;
|
||||||
|
ParDat pParseT, pParseV;
|
||||||
|
int iRet, i, iStat;
|
||||||
|
NXlink sLink;
|
||||||
|
|
||||||
|
pDict = NXDIAssert(dict);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DEFDEBUG
|
||||||
|
printf("Linking: %s\n", pVictim);
|
||||||
|
printf("To: %s\n", pTarget);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* parse Victim */
|
||||||
|
pParseV.iMayCreate = 0;
|
||||||
|
pParseV.pPtr = pVictim;
|
||||||
|
pParseV.iDepth = 0;
|
||||||
|
iRet = NXDIDefParse(hFil, pDict, &pParseV);
|
||||||
|
if (iRet == NX_ERROR) {
|
||||||
|
/* unwind and throw up */
|
||||||
|
NXDIUnwind(hFil, pParseV.iDepth);
|
||||||
|
return NX_ERROR;
|
||||||
|
}
|
||||||
|
/* get link data */
|
||||||
|
if (pParseV.iTerminal == TERMSDS) {
|
||||||
|
NXgetdataID(hFil, &sLink);
|
||||||
|
iRet = NXclosedata(hFil);
|
||||||
|
if (iRet != NX_OK) {
|
||||||
|
/* unwind and throw up */
|
||||||
|
NXDIUnwind(hFil, pParseV.iDepth);
|
||||||
|
return NX_ERROR;
|
||||||
|
}
|
||||||
|
} else if (pParseV.iTerminal == TERMVG) {
|
||||||
|
NXgetgroupID(hFil, &sLink);
|
||||||
|
} else {
|
||||||
|
assert(0); /* serious programming error */
|
||||||
|
}
|
||||||
|
/* Unwind */
|
||||||
|
iRet = NXDIUnwind(hFil, pParseV.iDepth);
|
||||||
|
if (iRet != NX_OK) {
|
||||||
|
return NX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* parse Target */
|
||||||
|
pParseT.iMayCreate = 1;
|
||||||
|
pParseT.pPtr = pTarget;
|
||||||
|
pParseT.iDepth = 0;
|
||||||
|
iRet = NXDIDefParse(hFil, pDict, &pParseT);
|
||||||
|
if (iRet == NX_ERROR) {
|
||||||
|
/* unwind and throw up */
|
||||||
|
NXDIUnwind(hFil, pParseT.iDepth);
|
||||||
|
return NX_ERROR;
|
||||||
|
}
|
||||||
|
/* check it being a vGroup! */
|
||||||
|
if (pParseT.iTerminal != TERMVG) {
|
||||||
|
NXReportError("ERROR: can link only into a vGroup");
|
||||||
|
NXDIUnwind(hFil, pParseT.iDepth);
|
||||||
|
return NX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* link, finally */
|
||||||
|
iRet = NXmakenamedlink(hFil, newname, &sLink);
|
||||||
|
/* Unwind anyway */
|
||||||
|
iStat = NXDIUnwind(hFil, pParseT.iDepth);
|
||||||
|
if (iStat != NX_OK) {
|
||||||
|
return NX_ERROR;
|
||||||
|
}
|
||||||
|
return iStat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
NXstatus NXDaliasnamedlink(NXhandle hFil, NXdict dict,
|
||||||
|
char *pTarget, char *pVictim, char *newname)
|
||||||
|
{
|
||||||
|
char pTargetDef[2048], pVictimDef[2048];
|
||||||
|
int iRet;
|
||||||
|
NXdict pDict;
|
||||||
|
pDynString pRep1 = NULL, pRep2 = NULL;
|
||||||
|
|
||||||
|
pDict = NXDIAssert(dict);
|
||||||
|
|
||||||
|
/* get Target Definition String */
|
||||||
|
iRet = NXDget(pDict, pTarget, pTargetDef, 2047);
|
||||||
|
if (iRet != NX_OK) {
|
||||||
|
sprintf(pTargetDef, "ERROR: alias %s not recognized", pTarget);
|
||||||
|
NXReportError(pTargetDef);
|
||||||
|
return NX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get Victim definition string */
|
||||||
|
iRet = NXDget(pDict, pVictim, pVictimDef, 2047);
|
||||||
|
if (iRet != NX_OK) {
|
||||||
|
sprintf(pTargetDef, "ERROR: alias %s not recognized", pTarget);
|
||||||
|
NXReportError(pTargetDef);
|
||||||
|
return NX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* do replacements */
|
||||||
|
pRep1 = NXDItextreplace(dict, pTargetDef);
|
||||||
|
pRep2 = NXDItextreplace(dict, pVictimDef);
|
||||||
|
if ((!pRep1) || (!pRep2)) {
|
||||||
|
if (pRep1)
|
||||||
|
DeleteDynString(pRep1);
|
||||||
|
if (pRep2)
|
||||||
|
DeleteDynString(pRep2);
|
||||||
|
return NX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* call NXdeflin */
|
||||||
|
iRet = NXDdefnamedlink(hFil, pDict, GetCharArray(pRep1), GetCharArray(pRep2), newname);
|
||||||
|
DeleteDynString(pRep1);
|
||||||
|
DeleteDynString(pRep2);
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
NXstatus NXDdeflink(NXhandle hFil, NXdict dict,
|
NXstatus NXDdeflink(NXhandle hFil, NXdict dict,
|
||||||
char *pTarget, char *pVictim)
|
char *pTarget, char *pVictim)
|
||||||
|
29
nxscript.c
29
nxscript.c
@ -1589,6 +1589,31 @@ static void makeLink(SConnection * pCon, SicsInterp * pSics,
|
|||||||
SCSendOK(pCon);
|
SCSendOK(pCon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------*/
|
||||||
|
static void makeNamedLink(SConnection * pCon, SicsInterp * pSics,
|
||||||
|
pNXScript self, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
char pBueffel[256];
|
||||||
|
|
||||||
|
if (argc < 5) {
|
||||||
|
SCWrite(pCon, "ERROR: insufficient number of arguments to makenamedlink",
|
||||||
|
eLogError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = NXDaliasnamedlink(self->fileHandle, self->dictHandle,
|
||||||
|
argv[2], argv[3], argv[4]);
|
||||||
|
if (status != NX_OK) {
|
||||||
|
snprintf(pBueffel, 255, "ERROR: linking %s against %s as %s failed",
|
||||||
|
argv[2], argv[3], argv[4]);
|
||||||
|
SCWrite(pCon, pBueffel, eLogError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCSendOK(pCon);
|
||||||
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------*/
|
||||||
static void updateDictVar(SConnection * pCon, pNXScript self, int argc,
|
static void updateDictVar(SConnection * pCon, pNXScript self, int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
@ -1698,6 +1723,10 @@ int NXScriptAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
|||||||
makeLink(pCon, pSics, self, argc, argv);
|
makeLink(pCon, pSics, self, argc, argv);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (strcmp(argv[1], "makenamedlink") == 0) {
|
||||||
|
makeNamedLink(pCon, pSics, self, argc, argv);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user