From: <hp...@we...> - 2022-06-18 09:55:55
|
Hi Jeff! Am 18.06.2022 um 00:56 schrieb Jeff Hennick: > The WORDS option of the SPECs stage is supported in NetRexx Pipelines. FIELDS, > and the SEPERATORs are not yet. (WORDS uses a simple PARSE, but using a > non-SPACE separator will require more code, probably PARSE in a loop.) More code for sure, but PARSE in a loop? How about masking blanks, if there are more word-separators mask them too, change the fs to blank, parse "words" as you are used to, and undo all masking. Drawback: chars used for masking must not exist in input, else you have a problem. But, IMO, it's worth it, otherwise, how do you handle CSV files? CSV files? Yes, this "simple as that"-format for tables. It would be my next challenge after the OS/2 to NetRexx migration. Is it possible to run such "DIY" stages in NetRexx Pipelines: > /* CSVCLN REXX: brush-up a CSV file */ > /* (CSV = character separated values, a table transfer format) */ > /* Operation: change separating comma to TAB, single doubled quotes */ > /* and strip quotes from quoted values */ > /* */ > /* Ð×××××××××××××××××××××××××××××××××××××××××××××××××××××××××ׯ */ > /* ³ ³ */ > /* ³ >>××CSVCLN×ײ×××××××××××××××××××××××××××××××××××ײ××××>< ³ */ > /* ³ ¿××oldsep××ײ××××××××××××××××××××××ײ| ³ */ > /* ³ ¿××newsep××ײ×××××××××ײ| ³ */ > /* ³ ¿××nixbix××| ³ */ > /* ³ ³ */ > /* ¿××××××××××××××××××××××××××××××××××××××××××××××××××××××××××| */ > /* */ > /* OLDSEP specify the separation character used in input CSV, */ > /* default is comma (,) */ > /* NEWSEP define the separation character in output, */ > /* default is TAB (hex 05) */ > /* (OLDSEP and NEWSEP may be defined in hex or as a single */ > /* character, but % or § will fail) */ > /* NIXBIX is used as a place-holder for treatment of double quotes */ > /* its occurrence in input is not tested */ > /* Note: if you specify a wrong OLDSEP, output is chopped at quotes */ > /* .....Mike 190299 */ > /* ----------------------------------------------------------------- */ > /* Change 050799: Now doubled speed by Melinda's suggestion. */ > /* Note 1: Now a wrong OLDSEP will chop at leading quotes. */ > /* Note 2: Now two new "nixbix" are hardcoded: x00 and x01 should */ > /* not occur in input. */ > /* ----------------------------------------------------------------- */ > trace o /* in case of stall */ > signal on novalue /* No uninitialised variables */ > signal on failure /* Allow RC > 0 for a moment */ > 'STAGENUM' /* Where are we? */ > first? = RC = 1 /* first or not? */ > 'MAXSTREAM IN' /* Check only one stream */ > signal on error /* now stop for any error */ > if RC ^= 0 then 'ISSUEMSG 264 PIPCSV' /* too many streams: crash */ > if first? then 'ISSUEMSG 127 PIPCSV' /* if first: stop and say why */ > parse arg oc nc ph z /* args in mixed case */ > if z ^='' then 'ISSUEMSG 111 PIPCSV "' z '"' /* too many args */ > if oc = '' then oc = ',' /* default old sep char */ > else do /* user defined sep char */ > oc = strip(oc) /* no blanks arround it */ > l = length(oc) /* how many letters? */ > select /* marginal test */ > when l = 1 then nop /* a single character is ok */ > when l = 2 then oc = x2c(oc) /* hex assumed */ > otherwise 'ISSUEMSG 50 PIPCSV "' oc '"' /* invalid argument: stop */ > end; end /* end Select and Else Do */ > if nc = '' then nc = '05'x /* default new sep char */ > else do /* user defined sep char */ > nc = strip(nc) /* no blanks around it */ > l = length(nc) /* how many letters? */ > select /* marginal test */ > when l = 1 then nop /* a single character is ok */ > when l = 2 then nc = x2c(nc) /* hex assumed */ > otherwise 'ISSUEMSG 50 PIPCSV "' nc '"' /* invalid argument: stop */ > end; end /* end Select and Else Do */ > if ph = '' then ph = 'NixBix' /* default place holder for "" */ > 'CALLPIPE (sep % end § name CSVCLN.REXX) *:', /* ------- in ------ */ > '% change /""""/'ph'/', /* single inch-sign */ > '% change /'oc'"""/'oc'"'ph'/', /* leading inch-sign */ > '% change 1.3 /"""/"'ph'/', /* same in fst column */ > '% change /'oc'""/'oc'/', /* empty cells */ > '% change 1.2 /""//', /* same in fst column */ > '% change /""/'ph'/', /* example: "zizu = 8"" etc." */ > '% strip trailing' oc, /* no empty cells at end of record */ > '% xlate 1-* 40 00', /* Mask the blanks. */ > '% tokenize /"/ x01', /* Tokenize and delimit. */ > '%q:outside /"/ /"/', /* branch quoted values */ > '% xlate 1-*' oc nc, /* replace old by new sep-char */ > '%f:faninany', /* collect all parts of record */ > '% deblock linend 01 terminate', /* Re-form original records. */ > '% change /'ph'/"/', /* place holder to inch-sign */ > '% xlate 1-* 00 40', /* Unmask the blanks. */ > '%*:', /* ----------- out ----------- */ > '§q:', /* from OUTSIDE */ > '% nfind "' !!, /* Get rid of the quotes. */ > '%f:' /* to FANINAY */ > failure:; error: exit (RC * (RC ^= 12 & RC ^= 8)) /* RC = 0 if EOF */ I'm retired, so I stipulate as license: don't ask, don't tell ;) (Alter codepage for nice railroad tracks in header.) I hope your answer will be 'yes, no problem.' Best, M. |