;N txt.cam - a CAMILA library for text representation ;A J.N. Oliveira (jno@di.uminho.pt) ;D ; This library provides for a simple representation of (nested) text. Text can involve strings, integers and symbols. ; Last Update: 1999.11.11 ;E TYPE txtEntry = STR | INT | SYM | txt; txt = txtEntry-seq; ENDTYPE FUNC txtFlat(l:txt):STR-seq ; ; txtFlat(l) flattens l while converting integers and symbols to strings. ; RETURN CONC(< if is-STR(x) then < x > else if is-INT(x) then < itoa(x) > else if is-SYM(x) then < symstr(x) > else txtFlat(x) | x <- l >); FUNC txt2File(fn:STR,t:txt):SYM ; ; txt2File(fn,t) writes txt object t into file fn. ; This function is obsolete and has been replaced by ioTxt2File(fn,t) available in library io.cam. ; RETURN let (p=txtFlat(t), _=princ("\nWarning: replace *txt2File* by *ioTxt2File* and include *io.cam*\n ")) in do(sh(strcat("rm ",fn)), _f<- fopen(fn,"w"), foreach(x,p,if x=="" then princ(".") else fputs(x,_f)), fclose(_f), sh(strcat("ls -l ",fn)), ); FUNC txtAddNL(l:txt):txt ; ; txtAddNL(l) adds newline characters to every "line" in l. ; This may help in avoiding too long lines when dumping txt objects to ; files via txt2File. ; RETURN < if (is-STR(a) || is-INT(a) || is-SYM(a)) then a else a ^ <"\n"> | a <- l>;