SASUnit Examples  Version 1.5.0
_scanheader.sas
Go to the documentation of this file.
1 
22 %MACRO _scanHeader (MacroName =
23  ,FilePath =
24  ,LibOutDoc = WORK
25  ,DataOutDoc = _ProgramHeader
26  ,LibOutPgm = WORK
27  ,DataOutPgm = _ProgramCode
28  ,LibOutToDo = WORK
29  ,DataOutToDo = _ToDoDoc
30  ,LibOutTest = WORK
31  ,DataOutTest = _TestDoc
32  ,LibOutBug = WORK
33  ,DataOutBug = _BugDoc
34  ,i_language = EN
35  );
36 
37  %LOCAL l_sHeaderStartTag l_sHeaderEndTag;
38  %LET l_sHeaderStartTag = %str(/)%str(** );
39  %LET l_sHeaderEndTag = %str(*)%str(/);
40 
41  Data WORK.__programHeader (keep=macroname tag name description);
42  Length macroname $80
43  tag $20
44  name $100
45  description $1000
46  headerStmtOpen tagStmtOpen 8;
47  Retain headerStmtOpen tagStmtOpen 0
48  tag name;
49 
50  ***Compile Perl RegEx with PRXPARSE;
51  patternAuthor = PRXPARSE("/^\\author/");
52  patternBrief = PRXPARSE("/^\\brief/");
53  patternCopyright = PRXPARSE("/^\\copyright/");
54  patternDate = PRXPARSE("/^\\date/");
55  patternDetails = PRXPARSE("/^\\details/");
56  patternFile = PRXPARSE("/^\\file/");
57  patternInGroup = PRXPARSE("/^\\ingroup/");
58  patternLink = PRXPARSE("/^\\link/");
59  patternParam = PRXPARSE("/^\\param/");
60  patternReturn = PRXPARSE("/^\\return/");
61  patternRet_Val = PRXPARSE("/^\\ret_val/");
62  patternSa = PRXPARSE("/^\\sa/");
63  patternTodo = PRXPARSE("/^\\todo/");
64  patternTest = PRXPARSE("/^\\test/");
65  patternBug = PRXPARSE("/^\\bug/");
66  patternRemark = PRXPARSE("/^\\remark/");
67  patternVersion = PRXPARSE("/^\\version/");
68 
69  pattern = "/^\\author|\\brief|\\copyright|\\date|\\details|\\file|\\ingroup|\\link|\\param|\\return|\\ret_val|\\sa|\\todo|\\test|\\bug|\\version|\\remark/";
70  patternTag = PRXPARSE(pattern);
71  patternComment = PRXPARSE("/\*\//");
72 
73  ***Input File;
74  Infile "&FilePath.\&MacroName.";
75  Input;
76 
77  *** MacroName for lists (todo, test, bug) ***;
78  macroname = "&MacroName.";
79 
80  l_zeile = compbl (left (_INFILE_));
81 
82  ***Leerzeile;
83  if (compress(l_zeile) = "") then do;
84  ***reset variables;
85  tag = "";
86  name = "";
87  description = "";
88  tagStmtOpen = 0;
89  end;
90 
91  ***Stop scanning if sHeaderStartEnd is found;
92  If (index(_INFILE_, "&l_sHeaderEndTag")>0) Then DO;
93  HeaderStmtOpen = 0;
94  End;
95 
96  ***Check for tag with more than one line;
97  If((tagStmtOpen = 1 AND PRXMATCH(patternTag, l_zeile) = 1) OR PRXMATCH(patternComment, l_zeile) = 1) Then Do;
98  tagStmtOpen = 0;
99  if (PRXMATCH(patternComment, l_zeile) = 1) then do;
100  ***reset variables;
101  tag = "";
102  name = "";
103  description = "";
104  end;
105  End;
106 
107  ***Start Scanning if sHeaderStartTag is found;
108  If (index(l_zeile, "&l_sHeaderStartTag")>0) Then Do;
109  headerStmtOpen = 1;
110  tagPos = Index(l_zeile, "&l_sHeaderStartTag");
111  l_zeile = Strip(substr(l_zeile, tagPos + length("&l_sHeaderStartTag")));
112  End;
113 
114  If (headerStmtOpen = 1) Then Do;
115  ***Only Tag on single line: \file;
116  If (PRXMATCH(patternFile, l_zeile) = 1) Then Do;
117  ***reset variables;
118  tag = "";
119  name = "";
120  description = "";
121  blankPos = Index(l_zeile, ' ');
122  tag = Substr(l_zeile, 1, blankPos);
123  name = "";
124  description = "";
125  End;
126  ***Complex tags with more than one line, 2 columns;
127  Else If (PRXMATCH(patternBrief, l_zeile) = 1 OR
128  PRXMATCH(patternCopyright, l_zeile) = 1 OR
129  PRXMATCH(patternDetails, l_zeile) = 1 OR
130  PRXMATCH(patternSa, l_zeile) = 1 OR
131  PRXMATCH(patternTodo, l_zeile) = 1 OR
132  PRXMATCH(patternTest, l_zeile) = 1 OR
133  PRXMATCH(patternBug, l_zeile) = 1 OR
134  PRXMATCH(patternReturn, l_zeile) = 1 OR
135  PRXMATCH(patternRemark, l_zeile) = 1 OR
136  PRXMATCH(patternVersion, l_zeile) = 1 OR
137  PRXMATCH(patternInGroup, l_zeile) = 1 OR
138  PRXMATCH(patternAuthor, l_zeile) = 1 OR
139  PRXMATCH(patternDate, l_zeile) = 1) Then Do;
140  ***reset variables;
141  tag = "";
142  name = "";
143  description = "";
144  tagStmtOpen = 1;
145  blankPos = Index(l_zeile, ' ');
146  tag = Substr(l_zeile, 1, blankPos);
147  l_zeile = Substr(l_zeile, blankPos+1);
148  description = Strip(l_zeile);
149  End;
150  ***Complex tags with name and more than one line, 3 columns;
151  Else If (PRXMATCH(patternParam, l_zeile) = 1 OR
152  PRXMATCH(patternRet_val, l_zeile) = 1
153  ) Then Do;
154  ***reset variables;
155  tag = "";
156  name = "";
157  description = "";
158  tagStmtOpen = 1;
159  blankPos = Index(l_zeile, ' ');
160  tag = Substr(l_zeile, 1, blankPos);
161  l_zeile = Substr(l_zeile, blankPos+1);
162  blankPos = Index(l_zeile, ' ');
163  name = Substr(l_zeile, 1, blankPos);
164  l_zeile = Substr(l_zeile, blankPos+1);
165  description = Strip(l_zeile);
166  End;
167  Else If (tagStmtOpen) then do;
168  description = Strip(l_zeile);
169  End;
170  End;
171  Run;
172 
173  data WORK.__programHeader;
174  length new_description $3200;
175  set WORK.__programHeader (where=(not missing(tag)));
176  obs_sort = _N_;
177  tag_sort = put (tag, $TagSort.);
178  tag_text = put (tag, $HeaderText_&i_language..);
179  dummy = " ";
180  new_description = tranwrd (description, "<b>", "^{style [font_weight=bold]");
181  new_description = tranwrd (new_description, "</b>", "}");
182  new_description = tranwrd (new_description, "<em>", "^{style [font_style=italic]");
183  new_description = tranwrd (new_description, "</em>", "}");
184  new_description = tranwrd (new_description, "\n", "^n");
185  new_description = tranwrd (new_description, "~ ", "- ");
186  new_description = tranwrd (new_description, "~", "^_^_^_");
187  run;
188 
189  proc sort data=WORK.__programHeader;
190  by tag_sort obs_sort;
191  run;
192 
193  proc append base=&LibOutTodo..&DataOutTodo. data=WORK.__programHeader (where=(tag="\todo"));
194  run;
195 
196  proc append base=&LibOutTest..&DataOutTest. data=WORK.__programHeader (where=(tag="\test"));
197  run;
198 
199  proc append base=&LibOutBug..&DataOutBug. data=WORK.__programHeader (where=(tag="\bug"));
200  run;
201 
202  data &LibOutDoc..&DataOutDoc.;
203  set WORK.__programHeader;
204  if (tag="\todo") then do;
205  new_description ="^{style [background=Bisque] " !! trim (new_description) !! "}";
206  end;
207  if (tag="\test") then do;
208  new_description ="^{style [background=LightBlue] " !! trim (new_description) !! "}";
209  end;
210  if (tag="\bug") then do;
211  new_description ="^{style [background=LightCoral] " !! trim (new_description) !! "}";
212  end;
213  if (tag="\remark") then do;
214  new_description ="^{style [background=LightGreen] " !! trim (new_description) !! "}";
215  end;
216  run;
217 %MEND _scanHeader;