source: WorldVistAEHR/trunk/r/CLINICAL_REMINDERS-PXRM/PXRMTEXT.m@ 975

Last change on this file since 975 was 623, checked in by George Lilly, 15 years ago

revised back to 6/30/08 version

File size: 2.9 KB
Line 
1PXRMTEXT ; SLC/PKR - Text formatting utility routines. ;11/03/2004
2 ;;2.0;CLINICAL REMINDERS;;Feb 04, 2005
3 ;
4 ;================================================================
5NEWLINE ;Put TEXT on a new line to the output, make sure it does not end
6 ;with a " ".
7 N TLEN
8 ;If there is no text in TEXT don't do anything.
9 I TEXT=INDSTR Q
10 S TLEN=$L(TEXT)
11 I $E(TEXT,TLEN)=" " S TEXT=$E(TEXT,1,TLEN-1)
12 S NOUT=NOUT+1,TEXTOUT(NOUT)=TEXT
13 S TEXT=INDSTR,CLEN=0
14 Q
15 ;
16 ;================================================================
17BLANK ;Add a blank line (line containing just " ") to the output.
18 S NOUT=NOUT+1,TEXTOUT(NOUT)=" "
19 S TEXT=INDSTR,CLEN=0
20 Q
21 ;
22 ;================================================================
23CHECKLEN(WORD) ;Check to see if adding the next word makes the line too long.
24 ;If it does add it to the output and start a new line.
25 N LENWORD
26 S LENWORD=$L(WORD)
27 I (CLEN+LENWORD)>WIDTH D
28 . D NEWLINE
29 . I WORD'[" " S WORD=WORD_" ",LENWORD=LENWORD+1
30 . S TEXT=INDSTR_WORD,CLEN=LENWORD
31 E D
32 . I WORD'[" " S WORD=WORD_" ",LENWORD=LENWORD+1
33 . S TEXT=TEXT_WORD,CLEN=CLEN+LENWORD
34 Q
35 ;
36 ;================================================================
37FORMAT(LM,RM,NIN,TEXTIN,NOUT,TEXTOUT) ;Format the text in TEXTIN so it has
38 ;a left margin of LM and a right margin of RM. The formatted text
39 ;is in TEXTOUT. "\\" is the end of line marker. Lines ending with
40 ;"\\" will not have anything appended to them. A blank line can
41 ;be created by creating a line containing just "\\". Lines containing
42 ;nothing but whitespace will also act like a "\\".
43 I NIN=0 S NOUT=0 Q
44 N ACHAR,ALLWSP,CHAR,CLEN,END,IND,INDENT,INDSTR,JND
45 N LWSP,NWSP,START,TEMP,TEXT,TLEN,WIDTH,W1,W2,WORD
46 ;Catalog the whitespace so we have places to break and look for
47 ;end of line markers.
48 F IND=1:1:NIN D
49 . S TEMP=TEXTIN(IND)
50 . S TLEN=$L(TEMP)
51 . S ALLWSP=1,NWSP=0
52 . F JND=1:1:TLEN D
53 .. S CHAR=$E(TEMP,JND)
54 .. S ACHAR=$A(CHAR)
55 .. I ACHAR>32 S ALLWSP=0
56 .. E S NWSP=NWSP+1,LWSP(IND,NWSP)=JND
57 .;Mark the end of the line.
58 . S NWSP=NWSP+1,LWSP(IND,NWSP)=TLEN,LWSP(IND)=NWSP
59 . I ALLWSP S LWSP(IND,"ALLWSP")=""
60 I LM<1 S LM=1
61 S WIDTH=RM-LM+1
62 S INDENT=LM-1
63 S INDSTR=""
64 F IND=1:1:INDENT S INDSTR=INDSTR_" "
65 S NOUT=0
66 S TEXT=INDSTR,CLEN=0
67 F IND=1:1:NIN D
68 .;If there is a blank line force whatever is in TEXT to be output by
69 .;calling NEWLINE and then add the blank.
70 . I $D(LWSP(IND,"ALLWSP")) D NEWLINE,BLANK Q
71 . S TEMP=TEXTIN(IND)
72 . S (END,NWSP)=0
73 . F NWSP=1:1:LWSP(IND) D
74 .. S START=END+1,END=LWSP(IND,NWSP)
75 .. S WORD=$E(TEMP,START,END)
76 .. I WORD["\\" D Q
77 ... S W1=$P(WORD,"\\",1)
78 ... D CHECKLEN(W1)
79 ... D NEWLINE
80 ... S W2=$P(WORD,"\\",2)
81 ... I W2'="" D CHECKLEN(W2)
82 .. D CHECKLEN(WORD)
83 ;Output the last line.
84 D NEWLINE
85 Q
86 ;
87 ;================================================================
88FORMATS(LM,RM,TEXTLINE,NOUT,TEXTOUT) ;Take a single line of input text
89 ;and format it.
90 N TEXTIN
91 S TEXTIN(1)=TEXTLINE
92 D FORMAT(LM,RM,1,.TEXTIN,.NOUT,.TEXTOUT)
93 Q
94 ;
Note: See TracBrowser for help on using the repository browser.