/*------------------------------------------------------------------- rexxservice(opt,string) Sends contents of string to REXX interpreter. Returns result. If 0 is returned, operation was not successful! EXAMPLE: rexxservice("cmd","xrange('a','z')' 'xrange('A','Z')"); rexxservice("cmd"," X2B('7') "); rexxservice("cmd"," date('n') "); rexxservice("cmd"," 'DATE = 'date('n')' TIME ='time('n') "); rexxservice("cmd"," FORMAT('54372.845',8,2) "); rexxservice("exec","h:\\u\\spfpc40\\macros\\h3.spf cmd words"); Just remember about command line character limitations ie <> | etc. Change rexxpath to point to your REXX interpreter Mark McDonald 2008 ---------------------------------------------------------------------*/ char rexxservice(char *xopt, char *x){ char *xfins = "c:\\temp\\dret.ins"; char *xfret = "c:\\temp\\dret.ret"; char *rexxpath = "h:\\u\\pcdos\\rexx.exe "; //DOSREXX Interpreter //char *rexxpath = "c:\\ooRexx\\rexx.exe "; //OOREXX Interpreter int xhin; int xhret; char *tr; char *td; char *xret = "OK"; char *tcmd; if(xopt == "cmd"){ tr = filedelete(xfret); td = strcompose("rs = ",x,"; tr = lineout('",xfret,"', rs, 1); tr = lineout('",xfret,"'); exit 0;"); xhin = fileopen(xfins,"w"); tr = filerecwrite(xhin,td); fileclose(xhin); tcmd = strcompose("system NOBATCH NOSTOP ",rexxpath, " c:\\temp\\dret.ins"); spfservice("cmd",tcmd); xhret = fileopen(xfret,"r"); if(xhret == 0){return("REXXERROR");} tr = filerecread(xhret,xret); fileclose(xhret); } if(xopt == "exec"){ tcmd = strcompose("system NOBATCH NOSTOP ",rexxpath,x); spfservice("cmd",tcmd); } return(xret); }//rexxservice /*------------------------------------------------------------------- xwordindex(x,n,delim) returns start col of word n of delimited words if n > nbr of words 0 is returned if delim = "" then " " is used Mark McDonald 2008 -------------------------------------------------------------------*/ int *xwordindex(char *x, int xn, char *xdelim){ char *xarray[]; char *td; int xret = 0; int nwrds; int xcnt; if(xn == 0){return(0);} if(xdelim == ""){strcpy(xdelim," ");} nwrds = strparsex(xarray, x, xdelim); strcpy(td,xarray[xn-1]); xret = strfindsubstr(x, td, 1); return(xret); }//xwordindex /*------------------------------------------------------------------- xwordlength(x,n,char) returns length of word n in x char words if n > nbr of words 0 is returned Mark McDonald 2008 -------------------------------------------------------------------*/ int *xwordlength(char *x, int xn, char *xdelim){ char *xarray[]; int xret; int nwrds; nwrds = strparsex(xarray, x, xdelim); if(xn > nwrds){return (0);} xn--; xret = strlen(xarray[xn]); }//xwordlength /*------------------------------------------------------------------- xwordpos(word, string, start, char) returns the word position of word in string of char delimited words starting at startword if start is 0 search begins with word 1 if start is > 0 search begins with word number start if worddelim is "" space is used Mark McDonald 2008 -------------------------------------------------------------------*/ int *xwordpos(char *xwrd, char *x, int xsp, char *xdelim){ char *xarray[]; int xret = 0; int nwrds; int xcnt; if(xsp == 0){xsp = 1;} if(xdelim == ""){strcpy(xdelim," ");} nwrds = strparsex(xarray, x, xdelim); if(xsp == 0){xcnt = 0;} if(xsp > 0){xcnt = xsp-1;} while(xcnt < nwrds){ if(xarray[xcnt] == xwrd){xret = xcnt+1; return(xret);} xcnt++; }//wend return(xret); }//xwordpos /*------------------------------------------------------------------- xlength(x) returns length of x Mark McDonald 2008 -------------------------------------------------------------------*/ int *xlength(char *x){ int xret = 0; xret = strlen(x); return(xret); }//xlength /*------------------------------------------------------------------- xpos(needle, haystack,start) returns start position of needle in haystack if found If needle not found, 0 is returned Mark McDonald 2008 -------------------------------------------------------------------*/ int *xpos(char *xneedle, char xhay, int xsp){ int xret = 0; if(xsp < 1){xsp = 1;} if(xsp => strlen(xhay)){return(0);} xret = strfindsubstr(xhay, xneedle, xsp); return(xret); }//xpos /*------------------------------------------------------------------- xlastpos(needle, haystack) If needle not found, 0 is returned Mark McDonald 2008 -------------------------------------------------------------------*/ int *xlastpos(char *xneedle, char xhay){ int xret = 0; xret = strfindlast(xhay, xneedle); return(xret); }//xlastpos /*------------------------------------------------------------------- xcenter(x,length,pad) returns string center to length with pad If length = 0 then string is center within existing length If pad = "" then pad = " " Mark McDonald 2008 -------------------------------------------------------------------*/ char *xcenter(char *x, int xn, char*xpad){ char *xret = ""; int xlen; int xdif; int xleftn; int xrightn; if(xn == 0){xn = strlen(x);} strstripleading(x, " "); strstriptrailing(x, " "); xlen = strlen(x); xdif = xn - xlen; xleftn = xdif / 2; xrightn = xdif - xleftn; xret = strcompose(strgenstr(xpad, xleftn), x, strgenstr(xpad,xrightn); return(xret); }//xcenter /*------------------------------------------------------------------- xsubstr(x,startcol,length,padchar) returns string from within x starting at startcol for length characters padded with padchar if returned length does not match length If startcol = 0 then 1 is used If length = 0 then from startcol to end of string If padchar = "" then padchar becomes " " Mark McDonald 2008 -------------------------------------------------------------------*/ char *xsubstr(char *x, int xsp, int xn, char*xpad){ char *xret = ""; char *xpadchars =""; int xlen; xlen = strlen(x); if(xsp > xlen){return(xret);} if(xsp == 0){xsp = 1;} if(xpad == ""){strcpy(xpad," ");} /*Set Default if Needed*/ if(xn > 0){ xpadchars = strgenstr(xpad, xn); strcat(x,xpadchars); }//endif if(xn == 0){ xn = xlen - xsp + 1; }//endif xret = strgetsubstr(x,xsp,xn); return(xret); }//xsubstr /*------------------------------------------------------------------- xcopies(string,n) returns string witn n copies of string Mark McDonald 2008 -------------------------------------------------------------------*/ char *xcopies(char *x, int xn){ char *xret; int xcnt; while( xcnt <= xn){ strcat(xret,x); xcnt++; }//wend return(xret); }//xcopies /*------------------------------------------------------------------- xlower(string) returns string converted to lower case Mark McDonald 2008 -------------------------------------------------------------------*/ char *xlower(char *x){ char *xret; strcpy(xret,x); strlwr(xret); return(xret); }//xlower /*------------------------------------------------------------------- xupper(string) returns string converted to upper case Mark McDonald 2008 -------------------------------------------------------------------*/ char *xupper(char *x){ char *xret; strcpy(xret,x); strupr(xret); return(xret); }//xupper /*------------------------------------------------------------------- xspace(string,padchar,padcnt,delim) Insert fill characters between words. string = source string padchar = what char(s) you want between words padcnt = how many padcars between words cwrdelim = what char currently delimits words (usaully a space) td = xspace("this is a test to see if this works"," ",1," ") td = xspace("this is a test to see if this works","-",3,"") Mark McDonald 2008 -------------------------------------------------------------------*/ char *xspace(char *x, char *xpad, int xpcnt, char *xdelim){ char *xret = ""; char *xarray[]; int xwrdcnt; int xlen; int xcnt; char *xchars = ""; char *xtd; xlen = strlen(x); if(xlen > 0){ xcnt = 1; //--Build string pattern--- while( xcnt <= xpcnt){ strcat(xchars,xpad); xcnt++; }//wend if(xdelim == ""){strcpy(xdelim," ");} xwrdcnt = strparsex(xarray, x, xdelim); xcnt = 0; while(xcnt < xwrdcnt-1){ xtd = strcompose(xarray[xcnt],xchars); strcat(xret,xtd); xcnt++; }//wend strcat(xret,xarray[xcnt]); }//endif return(xret); }//xspace /*------------------------------------------------------------------- xtranslate(string,strout,strin) returns string where individual occurances of strin are changed to strout Not quite the same as REXX. It changes one character at a time. Mark McDonald -------------------------------------------------------------------*/ char *xtranslate(char *x, char *xout, char* xin){ char *xret=""; char *td; int xlenout; int xlenin; int xcnt; int xoutcnt; int xlen; char *xoutchar; char *xinchar; xlen = strlen(x); xlenout = strlen(xout); xlenin = strlen(xin); //Translate to upper case when no parms passed----- if(xlenout == 0){strcpy(xret,x); strupr(xret);} //Translate chars in x from xin char to xout char-- if(xlenout > 0){ xcnt = 1; while(xcnt <= xlen){ td = strgetsubstr(x,xcnt,1); xoutcnt = 1; while(xoutcnt <= xlenout){ xoutchar = strgetsubstr(xout,xoutcnt,1); xinchar = strgetsubstr(xin,xoutcnt,1); if(xinchar == td){strovlsubstr(x,xoutchar,xcnt);} xoutcnt++; }//wend xcnt++; }//wend strcpy(xret,x); }//endif return(xret); }//xtranslate /*------------------------------------------------------------------- xfilespec(string,opt) opt: D c:\testpath\name.ext = 'c' E c:\testpath\name.ext = 'ext' F same as spfservice("query,"FILESPEC") P c:\testpath\name.ext = '\testpath\' L c:\testpath\name.ext = ':\testpath\name.ext' M c:\testpath\name.ext = 'name.ext' N c:\testpath\name.ext = 'name' DPN c:\testpath\name.ext = 'c:\testpath\name' DP c:\testpath\name.ext = 'c:\testpath\' S c:\testpath\name.ext = 'c \testpath\ name ext' -------------------------------------------------------------------*/ char *xfilespec(char *x, char *xopt){ char *xret =""; char *xfilespec; char *xdrv; char *xext =""; char *xpath = ""; char *xname = ""; //File name without ext char *xmbr = ""; //File name with ext int xlen; int xsp; int xep; int xlth; char *xt; xlen = strlen(x); //Get Drive Letter----------------- xdrv = strgetsubstr(x,1,1); //Get Filespec Exnt---------------- xsp = strfindlast(x,"."); if(xsp > 0){ xsp++; xlth = xlen - xsp +1; xext = strgetsubstr(x,xsp,xlth); }//endif //Get Path------------------------- xsp = strfindsubstr(x,"\\",1); xep = strfindlast(x,"\\"); if(xsp > 0){ xlth = xep - xsp + 1; xpath = strgetsubstr(x,xsp,xlth); }//endif //Get File name(no ext)------------ xsp = xep + 1; xep = strfindlast(x,"."); if(xep ==0) xep = xlen; xlth = xep - xsp + 1; xname = strgetsubstr(x,xsp,xlth); xlth = strlen(xname); xt = strgetsubstr(xname,xlth,1); if(xt == "."){ xlth = xlth -1; xname = strgetsubstr(xname,1,xlth); }//endif //Get Member (with ext)------------ xlth = xlen - xsp + 1; xmbr = strgetsubstr(x,xsp,xlth); xlth = strlen(xmbr); //Return Option-------------------- if(xopt == "L"){ xlth = xlen - 1; xret = strgetsubstr(x,2,xlth); } if(xopt == "F"){xret = spfservice("query","FILESPEC");} if(xopt == "D"){xret = strgetsubstr(x,1,1);} if(xopt == "E"){strcpy(xret,xext);} if(xopt == "M"){strcpy(xret,xmbr);} if(xopt == "N"){strcpy(xret,xname);} if(xopt == "P"){strcpy(xret,xpath);} if(xopt == "DPN"){xret = strcompose(strgetsubstr(x,1,1),":",xpath,xname);} if(xopt == "DP"){xret = strcompose(strgetsubstr(x,1,1),":",xpath);} if(xopt == "S"){xret = strcompose(strgetsubstr(x,1,1)," ",xpath," ",xname," ",xext);} return (xret); }//xfilespec /*------------------------------------------------------------------- xstrip(string,stropt,strchar) stropt = "L" remove all strchars from left of string "T" right of string "B" left/right of string -------------------------------------------------------------------*/ char *xstrip(char *x, char *xopt, char *xchar){ int xcnt; int xlen; int xnlen; xlen = strlen(x); if(xopt == "B" || xopt =="L"){ xcnt = 1; while(strgetsubstr(x,xcnt,1) == xchar){ xcnt++; }//wend xnlen = xlen - xcnt + 1; x = strgetsubstr(x,xcnt,xnlen); xlen = strlen(x); }//endif if(xopt =="B" || xopt =="T"){ xcnt = xlen; while(strgetsubstr(x,xcnt,1) == xchar){ xcnt--; }//wend x = strgetsubstr(x,1,xcnt); }//endif return(x); }//xstrip /*------------------------------------------------------------------- xtriml(string,n) trims off n chars on left of string -------------------------------------------------------------------*/ char *xtriml(char *x, int xn){ char *xret = ""; int xlth; int nlth; int xsp; xlth = strlen(x); if(xn < 1) return(x); if(xn == xlth) return(xret); if(xn > xlth) return(xret); nlth = xlth - xn; xsp = xn + 1; xret = strgetsubstr(x,xsp,nlth); return(xret); }//xtriml /*------------------------------------------------------------------- xtrimr(string,n) trims off n chars on right of string -------------------------------------------------------------------*/ char *xtrimr(char *x, int xn){ char *xret =""; int xlth; int nlth; int xsp; xlth = strlen(x); if(xn < 1) return(x); //Same Length - Return nothing if(xn == xlth) return(xret); //Trim more than length return nothing if(xn > xlth) return(xret); //Trim it nlth = xlth - xn; xret = strgetsubstr(x,1,nlth); return(xret); }//trimr /*------------------------------------------------------------------- xright(string,cols,pad) returns right most cols in string -------------------------------------------------------------------*/ char *xright(char *x, int xcols, char*xpad){ char *xret = ""; int xsp; int xlth; int xadd; xlth = strlen(x); //Same length just return it if(xcols == xlth) return (x); // Pad it? if(xcols => xlth){ xadd = xcols - xlth; xret = strcompose(strgenstr(xpad, xadd), x); return (xret); } //Must be less than length xsp = xlth - xcols; if(xsp < xlth){xret = strgetsubstr(x, xsp, xcols);} return (xret); }//right /*------------------------------------------------------------------- xwords(string,delimchar) SPFSE REXX Returns number of delimited words in stringf -------------------------------------------------------------------*/ char *xwords(char *x, char *xdelim) { char *xarray[]; int xret = 0; xret = strparsex(xarray, x, xdelim); return (xret); }//xwords //-------------------------------------------------------------------------------------------------- /*-------------------------------------------------------------------------------------------------- xleft(string, cols, pad) Returns chars from col 1 to tcols --------------------------------------------------------------------------------------------------*/ char xleft(char *x, int xcols, char *xpad){ char *xret = ""; int xlth; int xadd; xlth = strlen(x); // Same length if(xlth == xcols){ return(x); } // Pad it? if(xcols => xlth){ xadd = xcols - xlth; xret = strcompose(x,strgenstr(xpad, xadd)); return (xret); } //Must be less if (xcols < xlth){ xret = strgetsubstr(x, 1, xcols); } return(xret); }//xleft //-------------------------------------------------------------------------------------------------- /*-------------------------------------------------------------------*/ /* xword(string,n,delimchar) SPFSE REXX */ /* Returns the nth delmited word in a string */ /*-------------------------------------------------------------------*/ char *xword(char *x, int xn, char *xdelim) { char *xarray[]; char *xret = ""; int nwrds; nwrds = strparsex(xarray, x, xdelim); if(xn > 0 && xn <= nwrds){xret = xarray[xn-1];} return (xret); }//word //--------------------------------------------------------------------------------------------------