diff --git a/newrpl/directory.c b/newrpl/directory.c index 2501666..b5466d4 100644 --- a/newrpl/directory.c +++ b/newrpl/directory.c @@ -871,3 +871,53 @@ BINT rplIsVarEmptyDir(WORDPTR *var) } return 0; } + + +// RETURNS A POINTER TO THE START OF A DIRECTORY +// FROM A LIST OF DIRECTORIES IN A PATH +// uselastname=0 --> DISREGARD THE LAST NAME (ASSUME IT'S A VARIABLE) +// uselastname=1 --> THE ENTIRE LIST IS A PATH + +// RETURN NULL IF ANY DIRECTORY IS NOT FOUND +// PATH CAN BE ABSOLUTE OR RELATIVE TO CurrentDir +// LIST MAY CONTAIN HOME AND UPDIR + +WORDPTR *rplFindDirFromPath(WORDPTR pathlist,BINT uselastname) +{ + WORDPTR ident, last; + if(!ISLIST(*pathlist)) return CurrentDir; + WORDPTR *dir=CurrentDir; + + last=rplSkipOb(pathlist)-1; // POINT TO CMD_ENDLIST + + if(!uselastname) { + ident=pathlist+1; + while(rplSkipOb(ident)65535)||(cols<1)||(cols>65535)) { + rplError(ERR_INVALIDDIMENSION); + return; + } + + + // DO IT MANUALLY INSTEAD OF USING rplMatrixTranspose() and rplMatrixConj() + // TO AVOID DOUBLE rplMatrixCompose() OVERHEAD + + + WORDPTR *savestk=DSTop; + + WORDPTR *a=DSTop; + + rplPushData(*var); + + // TRANSPOSE IS DONE DURING EXPLODE + rplMatrixExplodeByCols(); + if(Exceptions) { DSTop=savestk; return; } + + BINT i,j; + + // CONVENIENCE MACRO TO ACCESS ELEMENTS DIRECTLY ON THE STACK + // a IS POINTING TO THE MATRIX, THE FIRST ELEMENT IS a[1] +#define STACKELEM(r,c) a[((r)-1)*rows+(c)] + + // NOW DO THE COMPLEX CONJUGATE + for(i=1;i<=cols;++i) + { + for(j=1;j<=rows;++j) { + rplPushData(STACKELEM(i,j)); + if(Exceptions) { DSTop=savestk; return; } + rplCallOperator(CMD_CONJ); + if(Exceptions) { DSTop=savestk; return; } + if(ISSYMBOLIC(*rplPeekData(1))) { + rplSymbAutoSimplify(); + if(Exceptions) { DSTop=savestk; return; } + } + STACKELEM(i,j)=rplPopData(); + } + } + +#undef STACKELEM + + WORDPTR newmat=rplMatrixCompose(cols,rows); + + DSTop=savestk; + if(newmat) { + *var=newmat; + if(var!=DSTop-1) rplDropData(1); + } + return; } case VANDERMONDE: diff --git a/newrpl/matrix.c b/newrpl/matrix.c index f5e70bd..3cfdf02 100644 --- a/newrpl/matrix.c +++ b/newrpl/matrix.c @@ -308,7 +308,7 @@ BINT j; for(j=0;j