home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / pgmutil / val_link.zip / LANGEXT.H < prev    next >
Text File  |  1989-02-18  |  7KB  |  213 lines

  1. /*                                 LANGEXT.H                               */
  2.  
  3. /* Fixup some C syntax I really don't like
  4.    De gustibus non est desputandum
  5.    (Concerning taste there is not argument -- or
  6.     Only fools argue where taste is concerned) */
  7.  
  8.  
  9. /* Block basic C commands */
  10.  
  11. #define If                   if (
  12. #define Then                 ) {
  13. #define Else                 } else {
  14. #define ElseIf               } else if (
  15. #define EndIf                }
  16.  
  17. #define Using                switch (
  18. #define BeginCase            ) {
  19. #define When                 case
  20. #define Otherwise            default
  21. #define EndCase              }
  22.  
  23. #define Loop                 while(1)
  24. #define BeginLoop            {
  25. #define EndLoop              }
  26. #define ExitLoop             break
  27. #define ContinueLoop         continue
  28. #define ExitIf(cond)         if (cond) break
  29. #define LoopIf(cond)         if (cond) continue
  30.  
  31. #define While                while (
  32. #define BeginWhile           ) {
  33. #define EndWhile             }
  34.  
  35. #define Repeat               do
  36. #define BeginRepeat          {
  37. #define RepeatIf             } while ((
  38. #define Until                } while (!(
  39. #define EndRepeat            ))
  40.  
  41. #define For                  for (
  42. #define BeginFor             ) {
  43. #define EndFor               }
  44.  
  45. #define BeginDeclarations    {
  46. #define EndDeclarations
  47. #define BeginCode
  48. #define EndCode              }
  49.  
  50. #define Type                 typedef
  51.  
  52. #define Structure           struct
  53. #define BeginStructure      {
  54. #define EndStructure        }
  55.  
  56. #define Union               union
  57. #define BeginUnion          {
  58. #define EndUnion            }
  59.  
  60. #define Enumeration         enum
  61. #define BeginEnumeration    {
  62. #define EndEnumeration      }
  63.  
  64. /* Extended C commands */
  65.  
  66. /* Linked List commands */
  67.  
  68. #define ListTypeOf(exp) \
  69. Structure exp##_list_struct \
  70.  BeginStructure \
  71.   exp##_ptr                            first; \
  72.   exp##_ptr                            last; \
  73.  EndStructure; \
  74. Type Structure exp##_list_struct       exp##_list
  75.  
  76. Structure Generic_Element_struct
  77.  BeginStructure
  78.   Structure Generic_Element_struct far   *next;
  79.  EndStructure;
  80.  
  81. Type Structure Generic_Element_struct  Generic_Element_type;
  82. Type Generic_Element_type far         *Generic_Element_ptr;
  83.  
  84. ListTypeOf(Generic_Element);
  85.  
  86. #define TraverseList(lst,elm)  for(elm=lst.first; elm IsNotNull; Next(elm))
  87. #define BeginTraverse        {
  88. #define EndTraverse          }
  89.  
  90. #define Insert               ListInsert((Generic_Element_ptr)
  91. #define After                ,0,(Generic_Element_ptr)
  92. #define AtEnd                ,1,Null
  93. #define AtBeginning          ,2,Null
  94. #define InList               ,(Generic_Element_list far *) &(
  95. #define EndInsert            ))
  96.  
  97. #define Delete               ListDelete((Generic_Element_ptr)
  98. #define FromList             ,(Generic_Element_list far *) &(
  99. #define EndDelete            ))
  100.  
  101. #define Push                 ListInsert((Generic_Element_ptr)
  102. #define OnTo                 ,2,Null,(Generic_Element_list far *) &(
  103. #define EndPush              ))
  104.  
  105. #define Pop                  ListPop((Generic_Element_list far *) &(
  106. #define InTo                 ),(Generic_Element_ptr *) &(
  107. #define EndPop               ))
  108.  
  109. #define LastInList(ptr)      ((*ptr).next == NULL)
  110. #define Next(ptr)            ptr = (*ptr).next
  111. #define First(list)          list.first
  112. #define Last(list)           list.last
  113.  
  114. /* Make operations less cryptic */
  115.  
  116. /* Logical operators */
  117. #define AndIf                &&
  118. #define OrIf                 ||
  119. #define Not                  !
  120. #define Is                   ==
  121. #define IsNot                !=
  122. #define IsEqualTo            ==
  123. #define Equals               ==
  124. #define IsNotEqualTo         !=
  125. #define LessThan             <
  126. #define NotLessThan          >=
  127. #define LessThanOrEqualTo    <=
  128. #define GreaterThan          >
  129. #define Exceeds              >
  130. #define Positive             > 0
  131. #define Negative             < 0
  132. #define IsZero               == 0
  133. #define IsNull               == 0
  134. #define IsNotNull            != 0
  135. #define IsEmpty              == 0
  136. #define IsNotEmpty           != 0
  137. #define IsNotZero            != 0
  138. #define IsTrue               != 0
  139. #define IsFalse              == 0
  140. #define NotGreaterThan       <=
  141. #define GreaterThanOrEqualTo >=
  142. #define IsIdentifier(x)      (((x>='A') && (x<='Z')) || \
  143.                               ((x>='a') && (x<='z')) || \
  144.                                (x=='_'))
  145. #define IsNumber(x)          ((x>='0') && (x<='9'))
  146.  
  147. /* Bitwise operators */
  148. #define And                  &
  149. #define Or                   |
  150. #define Xor                  ^
  151. #define Complement           ~
  152. /* Some other operators */
  153. #define Addr(exp)            &(exp)
  154. #define Mod                  %
  155. #define ShiftedLeft          <<
  156. #define ShiftedRight         >>
  157.  
  158. /* Some useful constants */
  159.  
  160. #define False                0
  161. #define Null                 0
  162. #define True                 1
  163.  
  164. /* Some helpful types */
  165. Type unsigned char           bit_8;
  166. Type unsigned int            bit_16;
  167. Type unsigned long           bit_32;
  168. Type unsigned char           byte;
  169. Type byte far               *byte_ptr;
  170. Type void far               *far_ptr;
  171. Type signed char             int_8;
  172. Type signed int              int_16;
  173. Type signed long             int_32;
  174. Type void near              *near_ptr;
  175. Type char near              *char_ptr;
  176.  
  177. Structure string_struct
  178.  BeginStructure
  179.   bit_16                     max_length;
  180.   bit_16                     length;
  181.   byte                       text[1];
  182.  EndStructure;
  183.  
  184. Type Structure string_struct string_type;
  185. Type string_type far        *string_ptr;
  186.  
  187. #define String(str)          ((byte_ptr) ((*str).text))
  188. #define Length(str)          (*str).length
  189. #define MaxLength(str)       (*str).max_length
  190. #define FirstCharIn(str)     *String(str)
  191. #define LastCharIn(str)      String(str)[Length(str)-1]
  192.  
  193. /* Some helpful type casts */
  194.  
  195. #define Bit_8(exp)           ((bit_8)      (exp))
  196. #define Bit_16(exp)          ((bit_16)     (exp))
  197. #define Bit_32(exp)          ((bit_32)     (exp))
  198. #define Int_8(exp)           ((int_8)      (exp))
  199. #define Int_16(exp)          ((int_16)     (exp))
  200. #define Int_32(exp)          ((int_32)     (exp))
  201. #define CharPtr(exp)         ((char *)     (exp))
  202. #define Byte(exp)            ((byte)       (exp))
  203. #define BytePtr(exp)         ((byte_ptr )  (exp))
  204. #define NearPtr(exp)         ((near_ptr)   (exp))
  205. #define FarPtr(exp)          ((far_ptr)    (exp))
  206. #define StringPtr(exp)       ((string_ptr) (exp))
  207. #define Offset(exp)          ((bit_16)     (exp))
  208. #define Segment(exp)         ((bit_16)     (((bit_32) (exp)) >> 16L))
  209. #define Low(exp)             ((bit_16)     (exp))
  210. #define High(exp)            ((bit_16)     (((bit_32) (exp)) >> 16L))
  211. #define MakeFarPtr(seg,off)  ((far_ptr)    ((((bit_32) (seg)) << 16L)|(off)))
  212.  
  213.