home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ppwizard.zip / nestchk.h < prev    next >
Text File  |  1999-11-13  |  12KB  |  280 lines

  1. ;----------------------------------------------------------------------------
  2. ;     MODULE NAME:   NESTCHK.H
  3. ;
  4. ;         $Author:   Dennis_Bareis  $
  5. ;       $Revision:   1.4  $
  6. ;           $Date:   13 Nov 1999 13:39:22  $
  7. ;        $Logfile:   E:/DB/PVCS.IT/OS2/PPWIZARD/NESTCHK.H_V  $
  8. ;
  9. ;        REQUIRES:   Regina 0.08f onwards, or you get clause length problems.
  10. ;
  11. ;     DESCRIPTION:   This is a header file for generic handling of
  12. ;                    nesting checking. This is where you must have matching
  13. ;                    "whatevers" such as a matching "</TABLE>" for a
  14. ;                    "<TABLE>" etc.
  15. ;
  16. ;                    "TABLE" checking is a good example as are "FRAMESET"
  17. ;                    statements as the Netscape browser will not display
  18. ;                    an incorrectly nested page (common cause of "blank"
  19. ;                    pages). This header file can be used to detect these
  20. ;                    errors while still developing the pages rather than
  21. ;                    HOPING that testing will show up the errors.
  22. ;
  23. ;                    Because these macros are generic you would usually have
  24. ;                    your own header file to front end them, for example your
  25. ;                    header could begin with:
  26. ;
  27. ;                       ;--- Prepare table nesting checking code ---
  28. ;                       #include "NESTCHK.H"
  29. ;                       <$NestingInit Id="HTMLTAG_TABLE" DESC="HTML TABLE tag">
  30. ;                       #define TABLE                             \
  31. ;                               <TABLE{$?}>                      -\
  32. ;                               <$NestingInc Id="HTMLTAG_TABLE">
  33. ;                       #define /TABLE                            \
  34. ;                               </TABLE>                         -\
  35. ;                               <$NestingDec Id="HTMLTAG_TABLE">
  36. ;
  37. ;                    Your code would then always use the table macros defined
  38. ;                    above rather than the HTML table tags directly, example:
  39. ;
  40. ;                       <$TABLE BORDER=5 CELLPADDING=10>
  41. ;                               <TR>         ;;Could validate TD /TD etc!
  42. ;                                  ...
  43. ;                               </TR>
  44. ;                       <$/TABLE>
  45. ;
  46. ;                    You would probably do more that just "TABLE" tags in the
  47. ;                    above example! Notice that the only difference in your
  48. ;                    actual code is an extra '$'!
  49. ;
  50. ;                    Macro "HtmlNesting"
  51. ;                    ~~~~~~~~~~~~~~~~~~~
  52. ;
  53. ;                    This header file now allows easy creation of macros such
  54. ;                    as the "TABLE" and "/TABLE" shown above. For example to
  55. ;                    create nest checking macros for "TABLE", "/TABLE", "TH",
  56. ;                    "/TH", "TD" and "/TD" you would use:
  57. ;
  58. ;                         <$HtmlNesting TAG="TABLE">
  59. ;                         <$HtmlNesting TAG="TH">
  60. ;                         <$HtmlNesting TAG="TD">
  61. ;
  62. ;
  63. ;                    Macro "NestingInit"
  64. ;                    ~~~~~~~~~~~~~~~~~~~
  65. ;
  66. ;                    This macro takes the following parameters:
  67. ;
  68. ;                         ID
  69. ;                         ~~
  70. ;                         Manditory. Short name to describe what we wish
  71. ;                         to check.  Must contain only characters which
  72. ;                         are valid in rexx variable names (no checking of
  73. ;                         this is done).
  74. ;
  75. ;                         DESC
  76. ;                         ~~~~
  77. ;                         A description which is displayed if a nesting
  78. ;                         error is found.
  79. ;
  80. ;
  81. ;                    Macro "NestingInc"
  82. ;                    ~~~~~~~~~~~~~~~~~~
  83. ;
  84. ;                    This macro takes the following parameters:
  85. ;
  86. ;                         ID
  87. ;                         ~~
  88. ;                         Manditory. Matches that used on "NestingInit".
  89. ;                         You are increasing the level of nesting.
  90. ;
  91. ;
  92. ;                    Macro "NestingDec"
  93. ;                    ~~~~~~~~~~~~~~~~~~
  94. ;
  95. ;                    This macro takes the following parameters:
  96. ;
  97. ;                         ID
  98. ;                         ~~
  99. ;                         Manditory. Matches that used on "NestingInit".
  100. ;                         You are decreasing the level of nesting.
  101. ;
  102. ;
  103. ;                    Macro "NestingLevel"
  104. ;                    ~~~~~~~~~~~~~~~~~~~
  105. ;
  106. ;                    This macro takes the following parameters:
  107. ;
  108. ;                         ID
  109. ;                         ~~
  110. ;                         Manditory. Matches that used on "NestingInit".
  111. ;                         Returns the name of the variable which contains
  112. ;                         the level (0= neutral, 1 = down one etc).
  113. ;
  114. ;----------------------------------------------------------------------------
  115.  
  116. ;--- Only include this header once! -----------------------------------------
  117. #ifndef   VERSION_NESTCHK_H
  118.  
  119.  
  120. ;--- Define the version number of this header file --------------------------
  121. #define   VERSION_NESTCHK_H    99.317
  122. #require  99.317
  123.  
  124. ;--- Register checking macro ------------------------------------------------
  125. #OnExit  <$NestingCheck>
  126.  
  127. ;--- Currently not tracking nesting of anything -----------------------------
  128. #RexxVar NestingIdCount = 0
  129.  
  130. ;--- Define macro to keep track of items ------------------------------------
  131. #DefineRexx NestingInit_REXX
  132.             ;--- Ensure ID is valid (needs to be valid rexx var format) -----
  133.             if symbol('{$ID $$SQx2}') = 'BAD' then
  134.                Error('The ID of "{$ID $$SQx2}" contains invalid characters!', 'It must be in the format of a valid rexx variable name');
  135.             if symbol('{$ID $$SQx2}_Level') = 'VAR' then
  136.                Error('The ID of "{$ID $$SQx2}" has already been initialized!');
  137.  
  138.             ;--- Remember ID details --------------------------
  139.             NestingIdCount = NestingIdCount + 1;
  140.             call _valueS "NESTINGID.NestingIdCount.ID",    '{$ID $$SQx2}';
  141.             call _valueS "NESTINGID.NestingIdCount.DESC",  '{$DESC}';
  142.             call _valueS "{$ID $$SQx2}_DESC",              '{$DESC}';
  143.  
  144.             ;--- Initialize level counter ---------------------
  145.             call _valueS '{$ID $$SQx2}_Level', 0;
  146. #DefineRexx
  147. #define NestingInit                                                   \
  148.         #evaluate  '' ^<$NestingInit_REXX ID='{$ID}' DESC='{$DESC}'>^
  149.  
  150. ;--- We are going down one level of nesting ---------------------------------
  151. ;                                                     [SaveSourceAndLocnInfo] (Ignore this - this bit used to include section into doco)
  152. #DefineRexx NestingInc_REXX
  153.             ;--- Ensure ID is valid -------
  154.             if symbol('{$ID $$SQx2}_Level') <> 'VAR' then
  155.                Error('The ID of "{$ID $$SQx2}" is unknown (you must use "NestingInit")!');
  156.  
  157.             ;--- Increase nesting level ---
  158.             call _valueS "{$ID}_Level", {$ID}_Level + 1;
  159.  
  160.             ;--- Record details about current location ---
  161.             call _valueS "{$ID}_FilePosn.{$ID}_Level", GetInputFileNameAndLine();
  162.             call _valueS "{$ID}_CurrLine.{$ID}_Level", GetFileLineBeingProcessed();
  163. #DefineRexx
  164. #define NestingInc                                            \
  165.         #evaluate  '' ^<$NestingInc_REXX ID='{$ID}'>^
  166. ;                                                     [SaveSourceAndLocnInfo] (Ignore this - this bit used to include section into doco)
  167.  
  168.  
  169. ;--- We are going up one level of nesting -----------------------------------
  170. #DefineRexx NestingDec_REXX
  171.             ;--- Ensure ID is valid -------
  172.             if symbol('{$ID $$SQx2}_Level') <> 'VAR' then
  173.                Error('The ID of "{$ID $$SQx2}" is unknown (you must use "NestingInit")!');
  174.  
  175.             ;--- Decrease nesting level ---
  176.             NewLevel = {$ID}_Level - {$DecreaseBy="1"};
  177.             if NewLevel < 0 then
  178.                call Error "Too many end tags for " || {$ID}_DESC;
  179.  
  180.             ;--- Record updated details ---
  181.             call _valueS "{$ID}_Level", NewLevel;
  182. #DefineRexx
  183. #define NestingDec                                            \
  184.         #evaluate  '' ^<$NestingDec_REXX ID='{$ID}' {$?}>^
  185.  
  186. ;--- Allow user to access the counter variable ------------------------------
  187. #define NestingLevel                                          \
  188.         {$ID}_Level
  189.  
  190.  
  191. ;--- Check nesting of all ID's ----------------------------------------------
  192. #DefineRexx NestingCheck_REXX
  193.            ;--- Loop though all registered "nesting" items ---
  194.            NestingError = 0;       ;;No errors found yet
  195.            do CheckIndex = 1 to NestingIdCount;
  196.                ;--- Get basic information about item ---
  197.               _ID    = NESTINGID.CheckIndex.ID;
  198.               _DESC  = NESTINGID.CheckIndex.DESC;
  199.  
  200.               _Level = _valueG(_ID || "_Level");
  201.               if _Level <> 0 then;
  202.               do;
  203.                  if NestingError = 0 then;
  204.                  do;
  205.                     say '';
  206.                     say 'NESTING ERRORS';
  207.                     say '~~~~~~~~~~~~~~';
  208.                  end;
  209.                  NestingError = NestingError + 1;
  210.                  if _Level < 0 then;
  211.                      say 'Have ' || abs(_Level) || ' too many end nesting tags on "' || _DESC || '"';
  212.                  else;
  213.                  do;
  214.                      ;--- display nesting info ---
  215.                      say 'Missing ' || _Level || ' end nesting tag(s) on "' || _DESC || '"';
  216.                      do _ThisLevel = 1 to _Level;
  217.                         say '  * ' || _valueG(_ID || "_FilePosn._ThisLevel");
  218.                         say '    ' || _valueG(_ID || "_CurrLine._ThisLevel");
  219.                      end;
  220.                  end;
  221.               end;
  222.            end;
  223. #DefineRexx
  224. #define NestingCheck                                            \
  225.         #evaluate  '' ^<$NestingCheck_REXX>^                    \
  226.         #if [NestingError <> 0]                                 \
  227.             #error ^NestingCheck(): Found <??NestingError> nesting error(s) as described above^ \
  228.         #endif
  229.  
  230.  
  231.  
  232. ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  233. ;%%%[ The following macros allow you to easily define HTML tag Nesting ]%%%
  234. ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  235.  
  236.  
  237. ;--- This is the only tag of the following you should use! ----------------
  238. #define  HtmlNesting                                                   \
  239.          ;--- Initialization for this tag ---                         -\
  240.          <$NestingInit Id="HTML_{$TAG}"                                \
  241.                        DESC='HTML {$TAG} tag nesting'                 -\
  242.          >                                                            -\
  243.                                                                       -\
  244.          #evaluate ^^ ^<$REXX_HTML_NESTING TAG=^{$TAG}^ Type="Inc">^  -\
  245.          #evaluate ^^ ^<$REXX_HTML_NESTING TAG=^{$TAG}^ Type="Dec">^
  246.  
  247. ;--- Define GENERIC macros for TAG and /TAG (use pseudo parameters) -------
  248. #define  _HTML_NESTING_Inc                       \
  249.          <[Tag]{$?}>                            -\
  250.          <$NestingInc Id="HTML_[Tag]">
  251. #define  _HTML_NESTING_Dec                       \
  252.          </[Tag]{$?}>                           -\
  253.          <$NestingDec Id="HTML_[Tag]">
  254.  
  255.  
  256. ;--- Define code which creates TAG start/end macros -----------------------
  257. #DefineRexx REXX_HTML_NESTING
  258.             ;--- Get GENERIC Macro (START or END) ---
  259.             TagMacro = MacroGet('_HTML_NESTING_{$Type}');
  260.  
  261.             ;--- Replace pseudo parameters ---
  262.             TagMacro = ReplaceString(TagMacro, '[Tag]',  '{$TAG $$SQx2}');
  263.  
  264.             ;--- Create START or END html tag macro ---
  265.             if '{$Type}' = 'Inc' then
  266.                HtmlTag = '{$TAG $$SQx2}';
  267.             else
  268.                HtmlTag = '/{$TAG $$SQx2}';
  269.             call MacroSet HtmlTag, TagMacro;
  270. #DefineRexx
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278. ;--- Only include this header once! -----------------------------------------
  279. #endif
  280.