home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / h2d130.zip / DOC / h2d.inf (.txt)
OS/2 Help File  |  1997-07-12  |  57KB  |  1,927 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Disclaimer ΓòÉΓòÉΓòÉ
  3.  
  4. This on-line document was generated automatically from its printed version 
  5. LaTeX source. 
  6.  
  7.  
  8. ΓòÉΓòÉΓòÉ 2. Title Page ΓòÉΓòÉΓòÉ
  9.  
  10.  XDS Family of Products 
  11.  
  12.  H2D User's Guide 
  13.  
  14.  xTech Ltd, 1997 
  15.  
  16. XDS software and documentation copyright (c) 1991-1997 xTech Ltd. (xTech). 
  17.  
  18. Information in this document is subject to change without notice and does not 
  19. represent a commitment on the part of xTech. 
  20.  
  21. All rights reserved. You may use the enclosed software on a single computer; 
  22. transfer the software from one computer to another, provided that the software 
  23. is used on only one computer at a time and that you remove any copies of the 
  24. software on the computer from which the copies were made; make copies of the 
  25. software for backup purposes only. 
  26.  
  27. XDS software and documentation have been tested and reviewed. Nevertheless, 
  28. xTech makes no warranty or representation, either express or implied, with 
  29. respect to the software and documentation included with XDS. In no event will 
  30. xTech be liable for direct, indirect, special, incidental or consequential 
  31. damages resulting from any defect in the software or documentation included 
  32. with this product. In particular, xTech shall have no liability for any 
  33. programs or data used with this product, including the cost of recovering 
  34. programs or data. 
  35.  
  36. XDS is a trademark of xTech Ltd. 
  37.  
  38. All trademarks and copyrights mentioned in this documentation are the property 
  39. of their respective holders. 
  40.  
  41.  
  42. ΓòÉΓòÉΓòÉ 3. Introduction ΓòÉΓòÉΓòÉ
  43.  
  44. Sooner or later, every Modula-2 programmer encounters four problems. These are: 
  45. absence, incompleteness, unportability, and low quality of libraries. At the 
  46. same time, C/C++ programmers usually have problems choosing from a huge set of 
  47. free, public domain, shareware, and commercial libraries of various purpose, 
  48. size, and quality which are in many cases portable or are available for a 
  49. number of platforms. Moreover, the Application Programming Interfaces (APIs) of 
  50. the most widely used software products (operating systems, database engines, 
  51. etc.), are defined in terms of the C programming language. 
  52.  
  53. In order to use this resources galore from Modula-2, a programmer needs, first, 
  54. a Modula-2 compiler which supports C calling/naming conventions and a set of 
  55. types corresponding to C types, and, second, definition modules corresponding 
  56. to the C headers of the library/API. Finding a suitable compiler is not a very 
  57. big deal, but manual conversion of C headers turns to a real nightmare when it 
  58. comes to, say, the X Window API. That is why we created H2D. 
  59.  
  60. H2D does the job automatically, i.e. translates C header files into Modula-2 
  61. definition modules. H2D is intended to be used with XDS version 2.10 or later 
  62. and is included in the XDS distribution package. However, the generated 
  63. definition modules may be used with any ISO-compliant Modula-2 compiler. The 
  64. required modifications are minor and may be done using text editor macros or a 
  65. simple REXX, sed, etc script. 
  66.  
  67. The source language is a subset of ANSI C, which includes declarations and 
  68. preprocessor directives, with some extensions (See Non-standard qualifiers and 
  69. Chapter Project files). Destination language is ISO Modula-2 with some XDS 
  70. language extensions. XDS allows to use the resulting definition modules with 
  71. both Modula-2 and Oberon-2. 
  72.  
  73. H2D generates definition modules suitable for either XDS-C, Native XDS, or 
  74. both. In case of Native XDS, module template for function-like C macros may be 
  75. generated (See Native code). In case of XDS-C, an extra header file containing 
  76. C declarations of types introduced by H2D is generated (See Convertor to C). 
  77.  
  78.      New in version 1.30 
  79.      Typographic conventions 
  80.  
  81.  
  82. ΓòÉΓòÉΓòÉ 3.1. New in version 1.30 ΓòÉΓòÉΓòÉ
  83.  
  84. Major improvements in v1.30: 
  85.  
  86.      Generalized #variant directive 
  87.  
  88.      Custom mapping of C base types to Modula-2 types 
  89.  
  90.      Non-standard directives extraction 
  91.  
  92.      Options renamed to follow XDS compilers style 
  93.  
  94.      Control file syntax now closely matches used by XDS compilers (see 
  95.       Chapters Configuring H2D and Project files) 
  96.  
  97.  
  98. ΓòÉΓòÉΓòÉ 3.2. Typographic conventions ΓòÉΓòÉΓòÉ
  99.  
  100.      Language descriptions 
  101.      Source code fragments 
  102.  
  103.  
  104. ΓòÉΓòÉΓòÉ 3.2.1. Language descriptions ΓòÉΓòÉΓòÉ
  105.  
  106. Where formal descriptions for language syntax constructions appear, an extended 
  107. Backus-Naur Formalism (EBNF) is used. 
  108.  
  109. These descriptions are set in a monospaced font. 
  110.  
  111. Text = Text [{Text}] | Text.
  112.  
  113. In EBNF, brackets [ and ] denote optionality of the enclosed expression, braces 
  114. { and } denote repetition (possibly 0 times), and the line | denotes other 
  115. possible valid descriptions. 
  116.  
  117. Non-terminal symbols start with an upper case letter (e.g. Statement). Terminal 
  118. symbols either start with a lower case letter (e.g. ident), or are written in 
  119. all upper case letters (e.g. BEGIN), or are enclosed within quotation marks 
  120. (e.g. ":="). 
  121.  
  122.  
  123. ΓòÉΓòÉΓòÉ 3.2.2. Source code fragments ΓòÉΓòÉΓòÉ
  124.  
  125. When fragments of a source code are used for examples or appear within a text 
  126. they are set in a monospaced font. 
  127.  
  128. /* example.h */
  129.  
  130. typedef unsigned long int UINT;
  131.  
  132.  
  133. ΓòÉΓòÉΓòÉ 4. Configuring H2D ΓòÉΓòÉΓòÉ
  134.  
  135.      Setting up system search path 
  136.      Working configuration 
  137.      Redirection file 
  138.      Configuration file 
  139.      Customizing H2D messages 
  140.  
  141.  
  142. ΓòÉΓòÉΓòÉ 4.1. Setting up system search path ΓòÉΓòÉΓòÉ
  143.  
  144. If you installed H2D as part of an XDS package, no additional setup is 
  145. required. Otherwise you must tell your operating system where to find the 
  146. executable before using H2D. Refer to the h2d.txt file from the on-line 
  147. documentation. 
  148.  
  149.  
  150. ΓòÉΓòÉΓòÉ 4.2. Working configuration ΓòÉΓòÉΓòÉ
  151.  
  152. The H2D working configuration includes an executable file and a set of system 
  153. files: 
  154.  
  155. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  156.  h2d.red  Search path redirection file
  157.  
  158.  h2d.cfg  Configuration file
  159.  
  160.  h2d.msg  Message file
  161. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  162.  
  163. Upon invocation, H2D tries to locate these files in the current directory and 
  164. then in the directory where H2D executable resides. If a redirection file, 
  165. h2d.red is found, all other files are searched for/created using paths defined 
  166. in it, otherwise the current directory is used for all input and output, except 
  167. files specified with directories. 
  168.  
  169. The configuration file contains various H2D settings. If the configuration file 
  170. is not found, default settings are used. 
  171.  
  172. The message file contains texts of error messages. 
  173.  
  174.  
  175. ΓòÉΓòÉΓòÉ 4.3. Redirection file ΓòÉΓòÉΓòÉ
  176.  
  177. Upon activation, H2D looks for a file called h2d.red - the redirection file. 
  178. This file defines directories in which all other files are searched for or 
  179. created. A redirection file has to be placed in the current directory, 
  180. otherwise the master redirection file from the directory where H2D executable 
  181. resides is used. 
  182.  
  183. A redirection file consists of several redirections: 
  184.  
  185.   Redirection = Pattern "=" directory {";" directory} 
  186.  
  187. Pattern is a regular expression which all file names used by H2D will be 
  188. compared with. A regular expression is a string containing certain special 
  189. characters: 
  190.  
  191. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  192.  Sequence  Denotes
  193.  
  194.  *         an arbitrary sequence of any characters, possibly empty
  195.  
  196.            (equivalent to {\000-\377} expression)
  197.  
  198.  ?         any single character
  199.  
  200.            (equivalent to [\000-\377] expression)
  201.  
  202.  [...]     one of the listed characters
  203.  
  204.  {...}     an arbitrary sequence of the listed characters, possibly empty
  205.  
  206.  \nnn      the ASCII character with octal code nnn, where n is [0-7]
  207.  
  208.  &         the logical operation AND
  209.  
  210.  |         the logical operation OR
  211.  
  212.  ^         the logical operation NOT
  213.  
  214.  (...)     the priority of operations
  215. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  216.  
  217. A sequence of the form a-b used within either [] or {} brackets denotes all 
  218. characters from a to b. 
  219.  
  220. When H2D looks for or intends to create a file, its name is sequentially 
  221. compared with all patterns from the top of the redirection file. A file is 
  222. created in the first directory of the list corresponding to the matched 
  223. pattern. A file is searched for in all directories in the list (from first to 
  224. last) until it is found or the directory list is exhausted. If a match is not 
  225. found, the file is created or searched for in the current directory. Note: If a 
  226. match is found, the current direcory is not searched unless it is explicitly 
  227. specified in the directory list. 
  228.  
  229. It is possible to put comment lines into the redirection file. A comment line 
  230. should be started with the % character. 
  231.  
  232.      Example 
  233.  
  234.  
  235. ΓòÉΓòÉΓòÉ 4.3.1. Example ΓòÉΓòÉΓòÉ
  236.  
  237. *.h       = h; .; c:\bc\include
  238. mac_*.def = macro;
  239. *.def     = def;
  240. mac_*.mod = macro;
  241. *.h2d     = h2d;
  242.  
  243.  
  244. ΓòÉΓòÉΓòÉ 4.4. Configuration file ΓòÉΓòÉΓòÉ
  245.  
  246. The configuration file is used to set options which control various aspects of 
  247. H2D behaviour: names of generated files, source/target language extensions, 
  248. mapping of C base types to Modula-2 types etc. It should reside in the current 
  249. directory or in the directory with H2D executable (the master configuration 
  250. file). However, it is recommended to use a project file instead of a local 
  251. configuration file to specify options for a particular set of header files. 
  252.  
  253. An option is a pair (name, value). Every line in the configuration file may 
  254. contain only one option setup directive. Arbitrary spaces are permitted. The % 
  255. character starts a one-line comment. Option setup directives have the following 
  256. syntax: 
  257.  
  258.   Option = "-" name ("-" | "+" | "=" (string | integer)) 
  259.  
  260. The same syntax is used for command line options and in a project file. 
  261. Command-line options have the highest priority. Options specified in a project 
  262. file override the configuration file settings. 
  263.  
  264. Options, their meanings and valid values are described in Chapter Options 
  265. Reference. 
  266.  
  267. Figure 1. Configuration file example 
  268.  
  269.  
  270. ΓòÉΓòÉΓòÉ 4.5. Customizing H2D messages ΓòÉΓòÉΓòÉ
  271.  
  272. The file h2d.msg contains error messages in the form 
  273.  
  274.   number text 
  275.  
  276. The following is an excerpt from h2d.msg: 
  277.  
  278.     001 Can't open file %s
  279.        .  .  .
  280.     010 Invalid use of modifier
  281.        .  .  .
  282.  
  283. Some messages contain format specifiers for additional arguments. In the 
  284. example above, the message number 001 contains a %s specifier which is 
  285. substituted with a file name when the message is printed. 
  286.  
  287. In order to use a language other than English for messages it is necessary to 
  288. translate message texts, preserving error numbers and the number and order of 
  289. format specifiers. 
  290.  
  291.  
  292. ΓòÉΓòÉΓòÉ 5. Getting Started ΓòÉΓòÉΓòÉ
  293.  
  294. In this chapter we assume that H2D is properly installed and configured (See 
  295. Chapter Configuring H2D). 
  296.  
  297.      Creating a working directory 
  298.      Invoking H2D 
  299.      H2D usage example 
  300.      Error reporting 
  301.  
  302.  
  303. ΓòÉΓòÉΓòÉ 5.1. Creating a working directory ΓòÉΓòÉΓòÉ
  304.  
  305. Redirection files give you complete freedom over where you keep your header 
  306. files and any files which H2D itself creates for further use. It is recommended 
  307. to work in a project oriented fashion - i.e. to have a separate directory 
  308. hierarchy for each set of header files you wish to translate. 
  309.  
  310. In this case, each project shall have a main working directory. The script 
  311. called h2dwork may be used to create the required subdirectories and a 
  312. redirection file. For example, to create a directory structure for a project 
  313. called myproj in the current directory, issue the following commands: 
  314.  
  315.   mkdir myproj 
  316.   cd myproj 
  317.   h2dwork 
  318.  
  319. Note: Since H2D preserves directory hierarchies of original header files. you 
  320. may also need to create additional subdirectories. See File inclusion for more 
  321. information. 
  322.  
  323.  
  324. ΓòÉΓòÉΓòÉ 5.2. Invoking H2D ΓòÉΓòÉΓòÉ
  325.  
  326. H2D is implemented as a command line utility called h2d. To translate a header 
  327. file (or a set of header files), type 
  328.  
  329.   h2d { HeaderFile } { Option } [ -prj=ProjectFile ] 
  330.  
  331. at the command prompt, where HeaderFile is a header file name. 
  332.  
  333. The syntax for Option is described in Configuration file. 
  334.  
  335. If you specify the -prj option, each header will be translated as if it was 
  336. specified in a !module directive in ProjectFile. 
  337.  
  338. To process a project file, type 
  339.  
  340.   h2d =p ProjectFile { Option } 
  341.  
  342. To view the default option values, type 
  343.  
  344.   h2d =o 
  345.  
  346. If invoked without parameters, the utility prints a brief help information. 
  347.  
  348.  
  349. ΓòÉΓòÉΓòÉ 5.3. H2D usage example ΓòÉΓòÉΓòÉ
  350.  
  351. Copy the H2D sample included in your XDS or H2D distribution to a working 
  352. directory and type 
  353.  
  354.   h2d =p example.h2d 
  355.  
  356. at the command prompt. The H2D banner line will appear: 
  357.  
  358.   H2D v1.30 (c) xTech 1996-1997 
  359.   File example.h 
  360.  
  361. After translation the following lines will be displayed: 
  362.  
  363.   no errors, lines 23. 
  364.   ---------------- 
  365.   Files 1, lines 23, no errors, time 0:3. 
  366.  
  367. showing the number of errors, the number of source lines in the file, and some 
  368. statistics. The following files will be generated: 
  369.  
  370. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  371.  h2d_example.def  basic definition module
  372.  
  373.  h2d_example.h    definitions of types generated by H2D
  374.  
  375.  mac_example.def  macro definition module
  376.  
  377.  mac_example.mod  prototype macro implementation module
  378. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  379.  
  380.  
  381. ΓòÉΓòÉΓòÉ 5.4. Error reporting ΓòÉΓòÉΓòÉ
  382.  
  383. When H2D detects an error in the input file, it displays an error report. It 
  384. contains the file name and position (line and column numbers) where the error 
  385. occurred: 
  386.  
  387.   Error [ example.h 16:44 ] ** Duplicate identifier 'insert' 
  388.  
  389. The error which is often encountered is 
  390.  
  391.   Error [...] ** Expected  , or ; 
  392.  
  393. In most cases it means that an identifier is undefined for some reason. Try to 
  394. put "," or ";" at the specified position to find out what is the problem 
  395. source. 
  396.  
  397.  
  398. ΓòÉΓòÉΓòÉ 6. Translation Rules ΓòÉΓòÉΓòÉ
  399.  
  400.      Comments 
  401.      Identifiers 
  402.      Types 
  403.      Type synonyms 
  404.      Variables 
  405.      Function prototypes 
  406.      Non-standard qualifiers 
  407.      Preprocessor directives 
  408.      Non-standard preprocessor directives 
  409.      Module names 
  410.  
  411.  
  412. ΓòÉΓòÉΓòÉ 6.1. Comments ΓòÉΓòÉΓòÉ
  413.  
  414. All comments from the original C text are copied to generated definition 
  415. modules. Their placement, however, is not preserved in some cases. The 
  416. COMMENTPOS option may be used to align comments which are placed next to 
  417. declarations. 
  418.  
  419. C++ compilers are usually able to recognize C++-style comments (beginning with 
  420. '//') even while operating in C mode. The CPPCOMMENTS option controls whether 
  421. H2D recognizes such comments as well. 
  422.  
  423.  
  424. ΓòÉΓòÉΓòÉ 6.2. Identifiers ΓòÉΓòÉΓòÉ
  425.  
  426. In most cases, H2D preserves original C identifiers. Exceptions are structure, 
  427. union, and enumeration tags, which constitute a separate name space in C. If 
  428. there is a constant, type, variable, or function identifier which coincides 
  429. with a tag, H2D appends "_struct", "_union" or "_enum" to that tag. 
  430.  
  431. In some situations, H2D itself generates additional identifiers, e.g. for 
  432. unnamed function arguments, derived types, and formal types. 
  433.  
  434. H2D may append digits to generated identifiers to avoid conflicts with existent 
  435. ones. 
  436.  
  437. Identifiers matching Modula-2 keywords are not allowed in source files. 
  438. However, Modula-2 pervasive identifiers (e.g. INTEGER or HALT) are permitted. 
  439.  
  440.      Example 
  441.  
  442.  
  443. ΓòÉΓòÉΓòÉ 6.2.1. Example ΓòÉΓòÉΓòÉ
  444.  
  445. The following C declarations were taken from the sys/stat.h file: 
  446.  
  447. struct stat { ... };
  448. int stat( const char *, struct stat * );
  449.  
  450. TYPE stat_struct = RECORD ... END;
  451.      PtrChar = POINTER TO CHAR;
  452. PROCEDURE stat(arg0: PtrChar; arg1: stat_struct): SYSTEM.int;
  453.  
  454.  
  455. ΓòÉΓòÉΓòÉ 6.3. Types ΓòÉΓòÉΓòÉ
  456.  
  457. C types are translated to Modula-2 types according to the following table: 
  458.  
  459. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  460.  C type                  Modula-2 type
  461.  
  462.  base (int, char, etc.)  (see Base types mapping)
  463.  
  464.  void*                   SYSTEM.ADDRESS
  465.  
  466.  pointer                 pointer
  467.  
  468.  array                   array
  469.  
  470.  enumeration             (see Enumeration)
  471.  
  472.  structure               record
  473.  
  474.  union                   variant record
  475.  
  476.  pointer to function     procedure type
  477. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  478.  
  479. Notes: 
  480.  
  481.      Structure, union, and enumeration tags are not preserved in cases of 
  482.       collision. It may cause problems with Modula-2 to C convertors (e.g. 
  483.       XDS-C). See Identifiers. 
  484.  
  485.      Examples 
  486.      Derived types 
  487.      Enumeration 
  488.  
  489.  
  490. ΓòÉΓòÉΓòÉ 6.3.1. Examples ΓòÉΓòÉΓòÉ
  491.  
  492. struct STRUCTURE{       TYPE STRUCTURE = RECORD
  493.   int    field1;            field1: SYSTEM.int;
  494.   char   field2;            field2: CHAR;
  495.   double field3;            field3: LONGREAL;
  496. };                        END;
  497.  
  498. union  UNION {          TYPE UNION = RECORD
  499.   int    field1;            CASE : INTEGER OF
  500.   char   field2;             0: field1: SYSTEM.int;
  501.   double field3;            |1: field2: CHAR;
  502. };                          |2: field3: LONGREAL;
  503.                             END;
  504.                           END;
  505.  
  506.  
  507. ΓòÉΓòÉΓòÉ 6.3.2. Derived types ΓòÉΓòÉΓòÉ
  508.  
  509. For objects declared as having derived types (pointer or array) either a new 
  510. Modula-2 type is introduced or a previously declared type synonym is used to 
  511. improve readability. For pointers to base types, a new type is always declared. 
  512.  
  513. In particular, a C structure may contain fields which type is defined as 
  514. pointer to that structure. In this case H2D also automatically inserts a 
  515. necessary forward pointer type declaration. 
  516.  
  517. This may cause type compatibility problems. Fortunately, in XDS, compatibility 
  518. rules for foreign objects are relaxed, e.g. two "C" pointer types are 
  519. compatible if their base types are the same. Additional setup or postprocessing 
  520. may be required when H2D is used with third-party Modula-2 compilers. 
  521.  
  522. char *str1;             TYPE
  523. char *str1;               H2D_PtrSChar = POINTER TO CHAR;
  524.  
  525.                         VAR
  526.                           str1: H2D_PtrSChar;
  527.                           str2: H2D_PtrSChar;
  528.  
  529. struct s {              TYPE
  530.   int i;                  s = RECORD
  531. };                          i: SYSTEM.int;
  532.                           END;
  533. struct s *p;              H2D_Ptrs = POINTER TO s;
  534.  
  535.                         VAR
  536.                           p: H2D_Ptrs;
  537.  
  538. struct s {              TYPE
  539.   int i;                  s = RECORD
  540. };                          i: SYSTEM.int;
  541.                           END;
  542.  
  543. typedef struct s *ps;     ps = POINTER TO s;
  544.  
  545. struct s *p;            VAR
  546.                           p: ps;
  547.  
  548. struct Node {           TYPE
  549.    int i;                 PtrNode = POINTER TO Node;
  550.    struct Node *next;     Node = RECORD
  551. };                          i: SYSTEM.int;
  552.                             next: PtrNode;
  553.                           END;
  554.  
  555.  
  556. ΓòÉΓòÉΓòÉ 6.3.3. Enumeration ΓòÉΓòÉΓòÉ
  557.  
  558. An enumeration (enum) is not actually a distinct type in C - it is just a 
  559. convenient way to declare integer constants (but in C++ enumeration is a 
  560. distinct type). Moreover, since it is possible in C to explicitly specify 
  561. enumeration constant value, translation to Modula-2 enumeration type may be 
  562. incorrect. H2D may translate C enumerations into either Modula-2 enumeration 
  563. types or Modula-2 constant declarations, depending on the GENENUM option 
  564. setting. For instance, if GENENUM is set to "Const" or "Mixed", the following C 
  565. type synonym declaration: 
  566.  
  567.   typedef enum{ one=1, two } Number; 
  568.  
  569. will be translated to 
  570.  
  571.     (* H2D: enumerated type: Number *)
  572.     CONST
  573.       one = 1;
  574.       two = 2;
  575.     TYPE
  576.       Number = SYSTEM.int;
  577.     (* H2D: End of enumerated type: Number *)
  578.  
  579. If GENENUM is set to "Enum", the same declaration will be translated unsafely 
  580. (a warning comment will be added): 
  581.  
  582.     TYPE
  583.       Number = (
  584.         one, (* H2D: integer value was 1 *)
  585.         two
  586.       );
  587.  
  588.  
  589. ΓòÉΓòÉΓòÉ 6.4. Type synonyms ΓòÉΓòÉΓòÉ
  590.  
  591. C declarations of type synonyms (typedef) are translated to Modula-2 type 
  592. declarations. If there are multiple synonyms declared for a type, their 
  593. equivalence is preserved: 
  594.  
  595. typedef char String[256];  TYPE String = ARRAY [0..255] OF CHAR;
  596. typedef String *PString;        PString = POINTER TO String;
  597. typedef String *Buffer;         Buffer = PString;
  598.  
  599. Note: In C, function type synonyms may be used in function declarations. These 
  600. synonyms are processed in a way they are processed by a C compiler and do not 
  601. appear in output files (see Function prototypes). 
  602.  
  603.  
  604. ΓòÉΓòÉΓòÉ 6.5. Variables ΓòÉΓòÉΓòÉ
  605.  
  606. Variables are translated to variables. Variables declared with the const 
  607. qualifier are translated to read-only variables (XDS extension). The volatile 
  608. qualifier is currently ignored. 
  609.  
  610. extern int i;              VAR i  : SYSTEM.int;
  611. extern const int j;        VAR j- : SYSTEM.int;
  612.  
  613.  
  614. ΓòÉΓòÉΓòÉ 6.6. Function prototypes ΓòÉΓòÉΓòÉ
  615.  
  616. C function prototypes declared as void are translated to proper procedure 
  617. declarations; other are translated to function procedure declarations. If there 
  618. is no name specified for a function parameter, argx is substituted, where x is 
  619. a number unique for each unnamed parameter. 
  620.  
  621. In C, a derived type (more precisely, pointer or array) may be specified for a 
  622. function parameter. In Modula-2, the formal type of a procedure parameter have 
  623. to be either type name or open array type. H2D translates parameters of array 
  624. type to open array value parameters. 
  625.  
  626. The translation procedure for pointers is more complicated. By default, H2D 
  627. searches for a type synonym, previously declared via typedef. The synonym, if 
  628. found, is used as formal type; otherwise H2D automatically declares one. If 
  629. automatic declaration is undesirable, required synonyms may be declared in the 
  630. project file. Other variants of translation may be explicitly specified by 
  631. means of the #variant directive. 
  632.  
  633. See also Non-standard qualifiers. 
  634.  
  635.      Examples 
  636.  
  637.  
  638. ΓòÉΓòÉΓòÉ 6.6.1. Examples ΓòÉΓòÉΓòÉ
  639.  
  640. void p(int,int);              PROCEDURE p ( arg0 : SYSTEM.int;
  641.                                             arg1 : SYSTEM.int );
  642.  
  643. int f(char c);                PROCEDURE f ( c : CHAR ): SYSTEM.int;
  644.  
  645. void P(T *t);                 TYPE PtrT = POINTER TO T;
  646.                               PROCEDURE P ( t : PtrT );
  647.  
  648. void Q(T t[])                 PROCEDURE Q ( t : ARRAY OF T );
  649.  
  650. int strlen(char *);           PROCEDURE strlen ( arg0 : ARRAY OF CHAR )
  651. #variant strlen(0) : ARRAY                     : SYSTEM.int;
  652.  
  653.  
  654. ΓòÉΓòÉΓòÉ 6.7. Non-standard qualifiers ΓòÉΓòÉΓòÉ
  655.  
  656. In practice, header files are not "pure" ANSI C. The most common extension is a 
  657. set of additional keywords (qualifiers) which may be used to specify 
  658. calling/naming conventions used in a particular library or API. 
  659.  
  660. Since XDS provides the similar mechanism called direct language specification 
  661. (DLS), H2D recognizes a number of such keywords, which are translated to the 
  662. following DLS strings: 
  663.  
  664. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  665.  C keyword  DLS String
  666.  
  667.  cdecl      none
  668.  
  669.  fortran    none
  670.  
  671.  interrupt  none
  672.  
  673.  pascal     "Pascal" for types and variables
  674.  
  675.             "StdCall" for functions
  676.  
  677.  syscall    "Syscall"
  678. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  679.  
  680. near, far, and huge qualifiers are recognized but ignored. 
  681.  
  682.  
  683. ΓòÉΓòÉΓòÉ 6.8. Preprocessor directives ΓòÉΓòÉΓòÉ
  684.  
  685.      Macro definitions 
  686.      File inclusion 
  687.      Conditional compilation 
  688.      Other directives 
  689.  
  690.  
  691. ΓòÉΓòÉΓòÉ 6.8.1. Macro definitions ΓòÉΓòÉΓòÉ
  692.  
  693. A #define C preprocessor directive may contain an object-like definition or a 
  694. function-like definition which are translated differently. 
  695.  
  696. #define identifier Text 
  697.  
  698. If Text is a constant expression, the directive is translated to a constant 
  699. declaration or a read-only variable declararion (see Preserving constant 
  700. names). If Text is a type identifier, the directive is translated to a type 
  701. declaration. If Text is an identifier of a function, a macro definition, or a 
  702. constant, the directive is translated to a constant declaration. In all other 
  703. cases, it is interpreted in a C preprocessor manner. 
  704.  
  705. #define identifier"(" idenifier, { identifier } ")" Text 
  706.  
  707. Translated to a proper procedure declaration with all parameters having type 
  708. ARRAY OF SYSTEM.BYTE. These declarations are marked with a special comment and 
  709. may be corrected after translation to reflect the actual semantics of a macro 
  710. by changing parameter types and/or adding return types. See also Native code 
  711. for information about macro prototype modules. 
  712.  
  713. #undef identifier 
  714.  
  715. Undefines identifier as it is done by a C preprocessor. 
  716.  
  717.      Example 
  718.  
  719.  
  720. ΓòÉΓòÉΓòÉ 6.8.1.1. Example ΓòÉΓòÉΓòÉ
  721.  
  722. #define str_constant "Hello World!\n"
  723.  
  724. #define constant 0x10
  725. #define constant_synonym constant
  726.  
  727. #define macro_with_params(p1,p2,p3) p1+p2+p3
  728. #define macro_with_params_synonym macro_with_params
  729.  
  730. int function(int);
  731. #define function_synonym function
  732.  
  733. typedef int INT;
  734. #define INTEGER INT
  735.  
  736. CONST
  737.   str_constant = 'Hello World!' + 12C;
  738.   constant = 10H;
  739.   constant_synonym = constant;
  740.  
  741. <* IF __GEN_C__ THEN *>
  742.  
  743. (* H2D: this procedure was generated from Macro. *)
  744. PROCEDURE macro_with_params ( p1, p2, p3: ARRAY OF SYSTEM.BYTE );
  745.  
  746. <* ELSE *>
  747.  
  748. PROCEDURE  / macro_with_params ( p1, p2, p3: ARRAY OF SYSTEM.BYTE );
  749.  
  750. <* END *>
  751.  
  752. <* IF __GEN_C__ THEN *>
  753.  
  754. CONST
  755.   macro_with_params_synonym = macro_with_params;
  756.  
  757. <* END *>
  758.  
  759. PROCEDURE function ( arg0: SYSTEM.int ): SYSTEM.int;
  760.  
  761. CONST
  762.   function_synonym = function;
  763.  
  764. TYPE
  765.   INT = SYSTEM.int;
  766.  
  767.   INTEGER = SYSTEM.int;
  768.  
  769.  
  770. ΓòÉΓòÉΓòÉ 6.8.2. File inclusion ΓòÉΓòÉΓòÉ
  771.  
  772. #include <file_name>
  773. #include "file_name"
  774.  
  775. If the file specified by file_name has to be merged with the current file (see 
  776. Headers merging), H2D treats this directive exactly as a C preprocessor, i.e. 
  777. replaces it with contents of a specified file. Otherwise, file_name is added to 
  778. the import list and the file specified by it is translated into a separate 
  779. definition module. If file_name contains directories, the output files are 
  780. placed to the same subdirectory. 
  781.  
  782. The GENLONGNAMES option controls conversion of included header file names which 
  783. contain path: 
  784.  
  785.   #include <sys/stat.h> 
  786.  
  787. is translated to 
  788.  
  789.   IMPORT stat; 
  790.  
  791. if GENLONGNAMES is OFF and to 
  792.  
  793.   IMPORT sys_stat; 
  794.  
  795. if GENLONGNAMES is ON. 
  796.  
  797. See also Module names. 
  798.  
  799.  
  800. ΓòÉΓòÉΓòÉ 6.8.3. Conditional compilation ΓòÉΓòÉΓòÉ
  801.  
  802. H2D handles conditional compilation directives #if, #ifdef, #ifndef, #else, and 
  803. #endif the same way as a C preprocessor does. A project file may be used to 
  804. define constants which are used in arguments of these directives. 
  805.  
  806.  
  807. ΓòÉΓòÉΓòÉ 6.8.4. Other directives ΓòÉΓòÉΓòÉ
  808.  
  809. H2D recognizes and ignores #line, #error, and #pragma C preprocessor 
  810. directives. 
  811.  
  812.  
  813. ΓòÉΓòÉΓòÉ 6.9. Non-standard preprocessor directives ΓòÉΓòÉΓòÉ
  814.  
  815. H2D recognizes two non-standard preprocessor directives: #merge and #variant. 
  816. These directives are related to definiton module generation only and do not 
  817. affect the C text, so they may be placed arbitrarily in a header file. 
  818. Typically they are collected in project files inside a corresponding !header 
  819. directive. 
  820.  
  821. The advanced technique is to put these directives right into working copies of 
  822. header files, next to the corresponding declarations. Then, after successful 
  823. translation of all headers, these directives may be extracted with the help of 
  824. GENDIRS option and moved to the project file. Now original headers may be used 
  825. for translation. 
  826.  
  827.      #merge 
  828.      #variant 
  829.  
  830.  
  831. ΓòÉΓòÉΓòÉ 6.9.1. #merge ΓòÉΓòÉΓòÉ
  832.  
  833. #merge ( <file_name> | "file_name" )
  834.  
  835. This directive lists included header files which should be merged even if the 
  836. MERGEALL option is OFF. This feature may be useful in some cases (see Headers 
  837. merging). 
  838.  
  839. When placed in a header file, this directive has effect only in this file. When 
  840. placed in a project file, it has effect in all headers matching the surrounding 
  841. !header directive. 
  842.  
  843.  
  844. ΓòÉΓòÉΓòÉ 6.9.2. #variant ΓòÉΓòÉΓòÉ
  845.  
  846. #variant Designator ":" Type
  847. Designator = identifier { "^" | "[ ]" | "." identifier } |
  848.              Parameter
  849. Parameter  = identifier "(" number ")"
  850. Type       = qualident
  851.  
  852. This form of the #variant directive allows to explicitly specify a Modula-2 
  853. Type for an object denoted by Designator. See Base types mapping for more 
  854. information. 
  855.  
  856. Designator specifies a named object or its element which is subject to the 
  857. #variant directive: 
  858.  
  859. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  860.  "^"             pointer dereference
  861.  
  862.  "[ ]"           array indexing
  863.  
  864.  "." identifier  structure or union field selection
  865. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  866.  
  867. Parameter specifies a function identifier and its parameter number 
  868. (zero-based). 
  869.  
  870. #variant Parameter  ":" ( "VAR" | "ARRAY" | "VAR ARRAY" )
  871.  
  872. This form is used to control translation of a function Parameter, which has a 
  873. pointer type. 
  874.  
  875. By default, pointer type function parameters are translated to pointer type 
  876. procedure parameters (see Function prototypes). The #variant directive allows 
  877. to specify one of the following alternative rules for a particular parameter: 
  878.  
  879. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  880.  Modifier   T *p is translated to
  881.  
  882.  VAR        VAR p: T
  883.  
  884.  ARRAY      p: ARRAY OF T
  885.  
  886.  VAR ARRAY  VAR p: ARRAY OF T
  887. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  888.  
  889. See also Pointer type function parameters. 
  890.  
  891. #variant f(0) : VAR ARRAY
  892. void f(char*);
  893.  
  894. PROCEDURE f ( VAR arg0: ARRAY OF CHAR );
  895.  
  896. A #variant directive has effect only in the file where it is located, or, if 
  897. specified in a project file, in all files matching the surrounding !header 
  898. directive. Therefore, Designator should specify an object declared in this file 
  899. or in one of the files which it includes. If an object specified by Designator 
  900. is not present, an error message is displayed. 
  901.  
  902.  
  903. ΓòÉΓòÉΓòÉ 6.10. Module names ΓòÉΓòÉΓòÉ
  904.  
  905. By default, H2D uses a header file name without ".h" extension as a definition 
  906. module name. If a file name contains characters which are not allowed in 
  907. identifiers, the !name directive must be used in a project file to specify a 
  908. proper identifier. 
  909.  
  910.  
  911. ΓòÉΓòÉΓòÉ 7. Using H2D ΓòÉΓòÉΓòÉ
  912.  
  913.      Headers merging 
  914.      Fitting a Modula-2 compiler 
  915.      Modifying translation rules 
  916.  
  917.  
  918. ΓòÉΓòÉΓòÉ 7.1. Headers merging ΓòÉΓòÉΓòÉ
  919.  
  920. A C header file may contain one or more #include directives. H2D offer the 
  921. following translation variants for included headers: 
  922.  
  923.      All headers are merged and translated into a single definition module 
  924.       (the MERGEALL option is set ON). 
  925.  
  926.      Each included header is translated into a separate definition module 
  927.       which name is added to the import list (the MERGEALL option is set OFF). 
  928.  
  929.      The headers which have to be merged are explicitly specified using the 
  930.       #merge directive (the MERGEALL option must be OFF). 
  931.  
  932.  If the GENSEP option is set ON, H2D separates pieces of Modula-2 text, which 
  933.  correspond to different merged headers, with comments containing header file 
  934.  names. 
  935.  
  936.  The #merge directive provides more flexible method of merging control than the 
  937.  MERGEALL option. The example illustrates situation in which this directive is 
  938.  very helpful. 
  939.  
  940.      Example 
  941.  
  942.  
  943. ΓòÉΓòÉΓòÉ 7.1.1. Example ΓòÉΓòÉΓòÉ
  944.  
  945. /* m1.h */                      /* m2.h */
  946. typedef int INTEGER;            struct descriptor{
  947. #include <m2.h>                   INTEGER handl;
  948. #include <m3.h>                 };
  949. #include <m4.h>                 typedef int far * RETVAL;
  950. RETVAL handler();               /* end m2.h */
  951. /* end m1.h */
  952.  
  953. In this example, the RETVAL declaration from m2.h is used in m1.h. On the other 
  954. hand, m2.h uses the declaration from m1.h (INTEGER). Setting the MERGEALL 
  955. option ON results in all headers (m1.h, m2.h, m3.h, and m4.h) being merged and 
  956. translated into the single definition module m1. If this is not a desired 
  957. behaviour, the #merge directive should be used instead. If the MERGEALL option 
  958. is OFF and the line 
  959.  
  960.   #merge <m2.h> 
  961.  
  962. is added to either m1.h or the corresponding #header directive in a project 
  963. file, H2D produces three definition modules m1, m3 and m4, where m1 is a result 
  964. of translation of two merged headers m1.h and m2.h. 
  965.  
  966.  
  967. ΓòÉΓòÉΓòÉ 7.2. Fitting a Modula-2 compiler ΓòÉΓòÉΓòÉ
  968.  
  969. Some of H2D translation rules depend on the target Modula-2 compiler; even 
  970. XDS-C and Native XDS require different definition modules. The BACKEND option 
  971. is used to reflect the major difference: whether the target Modula-2 compiler 
  972. is a native code compiler (-BACKEND = Native) or a convertor to C (-BACKEND = 
  973. C). It is also possible to produce definition modules suitable for both XDS-C 
  974. and Native XDS (-BACKEND = Common). In this case H2D encloses target-dependent 
  975. parts with XDS conditional compilation directives. 
  976.  
  977.      Native code 
  978.      Convertor to C 
  979.  
  980.  
  981. ΓòÉΓòÉΓòÉ 7.2.1. Native code ΓòÉΓòÉΓòÉ
  982.  
  983. C headers often contain a number of useful function-like macros. These macros 
  984. are translated into procedure declarations with parameters having type ARRAY OF 
  985. SYSTEM.BYTE, which is assignment compatible with any other type. But C macros 
  986. exist only at compile-time and are not present in object files. Therefore, a 
  987. Modula-2 compiler is unable to handle them properly unless it is implemented as 
  988. a convertor to C. Nevertheless, H2D provides a technique which allows to use C 
  989. function-like macros even with a native code Modula-2 compiler. 
  990.  
  991. If the BACKEND option is set to either Native or Common and the GENMACRO option 
  992. is set ON, H2D produces an additional module containing macro prototypes - 
  993. procedures corresponding to function-like macros, which bodies consist of a 
  994. comment with C macro definition and are expected to be written by a programmer. 
  995. These procedures are then declared as external in the main definition module. 
  996. Thus, a macro prototype module need not to be imported, it should be just 
  997. linked into an executable which uses the generated definition module. 
  998.  
  999. A macro prototype module name is constructed from a header module name and a 
  1000. prefix specified by the MACPFX option. 
  1001.  
  1002.      Example 
  1003.  
  1004.  
  1005. ΓòÉΓòÉΓòÉ 7.2.1.1. Example ΓòÉΓòÉΓòÉ
  1006.  
  1007. /* macro.h */
  1008.     ...
  1009. #define cube(x) (x*x*x)
  1010.     ...
  1011.  
  1012. (* macro.def  Sep 20  2:38:9  1996 *)
  1013.     ...
  1014. DEFINITION MODULE ["C"] macro;
  1015.     ...
  1016. PROCEDURE  / cube ( x: ARRAY OF SYSTEM.BYTE );
  1017.     ...
  1018. END macro.
  1019.  
  1020. (* m_macro.def  Sep 20  2:38:9  1996 *)
  1021.     ...
  1022. DEFINITION MODULE m_macro;
  1023.  
  1024. IMPORT SYSTEM;
  1025.     ...
  1026. PROCEDURE ["C"] cube ( x: ARRAY OF SYSTEM.BYTE );
  1027.     ...
  1028. END m_macro.
  1029.  
  1030. (* m_macro.mod  Sep 20  2:38:9  1996 *)
  1031.     ...
  1032. IMPLEMENTATION MODULE m_macro;
  1033.  
  1034. IMPORT SYSTEM;
  1035.     ...
  1036. PROCEDURE ["C"] cube ( x: ARRAY OF SYSTEM.BYTE );
  1037. (*
  1038. #define cube(x) (x*x*x)
  1039. *)
  1040. BEGIN
  1041. END cube;
  1042.     ...
  1043. END m_macro.
  1044.  
  1045.  
  1046. ΓòÉΓòÉΓòÉ 7.2.2. Convertor to C ΓòÉΓòÉΓòÉ
  1047.  
  1048. A Modula-2 compiler implemented as a convertor to C (e.g. XDS-C) converts 
  1049. definition modules written by a programmer to C headers. But headers 
  1050. corresponding to definition modules generated by H2D already exist. To prevent 
  1051. them from being overridden, H2D inserts the NOHEADER XDS option, which disables 
  1052. header file generation, at the beginning of each definition module. 
  1053.  
  1054. For all included header files, which are not merged (see Headers merging), H2D 
  1055. also sets the CSTDLIB XDS option according to the parenthesis used in the 
  1056. #include directive - double quotes or angle brackets. For top-level header 
  1057. files, this option is set equal to the value of the CSTDLIB option. 
  1058.  
  1059. H2D usually has to introduce a number of additional types in the definition 
  1060. module (see Function prototypes and Types). These types are absent in the 
  1061. original header file, and their usage would cause C compilation to fail. To 
  1062. solve this problem, H2D constructs a resulting definition module name from a 
  1063. header file name and a prefix specified by the DEFPFX option. Then, it produces 
  1064. a "wrapper" header file, which name corresponds to the name of a definition 
  1065. module, containing an #include directive with original header name, followed by 
  1066. required type declarations. Type declarations from a project file are copied to 
  1067. a wrapper file as well. 
  1068.  
  1069.      Example 
  1070.  
  1071.  
  1072. ΓòÉΓòÉΓòÉ 7.2.2.1. Example ΓòÉΓòÉΓòÉ
  1073.  
  1074. /* type.h */
  1075.  
  1076. struct Node {
  1077.   struct Node *next;
  1078.   struct Node *prev;
  1079.   int          hash;
  1080. };
  1081.  
  1082. int Hash(char * str);
  1083.  
  1084. (* h2d_type.def  Sep 20  2:51:7  1996 *)
  1085.     ...
  1086. DEFINITION MODULE ["C"] h2d_type;
  1087.  
  1088. IMPORT SYSTEM;
  1089.     ...
  1090. <*- GENTYPEDEF *>
  1091.  
  1092. TYPE
  1093.   PtrNode = POINTER TO Node;
  1094.  
  1095. <*+ GENTYPEDEF *>
  1096.  
  1097.   Node = RECORD
  1098.     next: PtrNode;
  1099.     prev: PtrNode;
  1100.     hash: SYSTEM.int;
  1101.   END;
  1102.  
  1103. <*- GENTYPEDEF *>
  1104.  
  1105.   PtrSChar = POINTER TO CHAR;
  1106.  
  1107. PROCEDURE Hash ( str: PtrSChar ): SYSTEM.int;
  1108.  
  1109. END h2d_type.
  1110.  
  1111. /* h2d_type.h  Sep 20  2:51:7  1996 */
  1112.     ...
  1113. #include "type.h"
  1114.  
  1115. #ifndef h2d_type_H_
  1116. #define h2d_type_H_
  1117.  
  1118. typedef struct Node * PtrNode;
  1119. typedef signed char * PtrSChar;
  1120.  
  1121. #endif  /* h2d_type_H_ */
  1122.  
  1123.  
  1124. ΓòÉΓòÉΓòÉ 7.3. Modifying translation rules ΓòÉΓòÉΓòÉ
  1125.  
  1126.      Base types mapping 
  1127.      Pointer type function parameters 
  1128.      Preserving constant names 
  1129.  
  1130.  
  1131. ΓòÉΓòÉΓòÉ 7.3.1. Base types mapping ΓòÉΓòÉΓòÉ
  1132.  
  1133. The CTYPE and M2TYPE options in conjunction with the #variant directive provide 
  1134. complete control over mapping of C base types to Modula-2 types. 
  1135.  
  1136. The CTYPE option specifies sizes (in bytes) of C base types, and their default 
  1137. mapping to Modula-2: 
  1138.  
  1139.   -CTYPE = float        = 4, REAL 
  1140.    . . . 
  1141.   -CTYPE = unsigned short int = 2, SYSTEM.CARD16 
  1142.  
  1143. The M2TYPE option specifies Modula-2 types supported by a particular compiler, 
  1144. with their sizes and families to which they belong: 
  1145.  
  1146.   -M2TYPE = CARDINAL     = 4, UNSIGNED 
  1147.   -M2TYPE = CHAR       = 1, CHAR 
  1148.    . . . 
  1149.   -M2TYPE = SYSTEM.SET16   = 2, SET 
  1150.  
  1151. Finally, the #variant directive allows to explicitly specify a Modula-2 type 
  1152. for a particular object: 
  1153.  
  1154.   void f(unsigned short mask)  PROCEDURE f(mask : SYSTEM.SET16); 
  1155.   #variant f(0) : SYSTEM.SET16 
  1156.  
  1157. Note: In order to keep original headers intact, #variant directives may be 
  1158. placed into the project file inside the corresponding !header directive. 
  1159.  
  1160. H2D checks type mappings for correctness using the following rules: 
  1161.  
  1162.      type sizes must match 
  1163.  
  1164.      floating point C types may only be mapped to Modula-2 types defined as 
  1165.       REAL by M2TYPE option. 
  1166.  
  1167.      signed integer C types may be mapped to any Modula-2 type except REAL and 
  1168.       UNSIGNED. 
  1169.  
  1170.      unsigned integer C types may be mapped to any Modula-2 type except REAL 
  1171.       and SIGNED. 
  1172.  
  1173.  One of the most advanced features of this mechanism is the ability to use 
  1174.  Modula-2 set types for C objects. The C programming language, as well as C++, 
  1175.  has no built-in set type. The common practice is to treat unsigned integer 
  1176.  types as bit scales and to use bitwise logical operators to manipulate them. 
  1177.  Since Modula-2 provides set types (and no bitwise operators), it would be more 
  1178.  convenient to translate individual integer constants and types to set 
  1179.  constants and types. 
  1180.  
  1181.      Example 
  1182.  
  1183.  
  1184. ΓòÉΓòÉΓòÉ 7.3.1.1. Example ΓòÉΓòÉΓòÉ
  1185.  
  1186. struct s{
  1187.   unsigned int field;
  1188. };
  1189. typedef unsigned long BITSCALE;
  1190. int variable;
  1191. void long function(unsigned argument);
  1192. char bitarray[10];
  1193. #define constant 0x0011
  1194.  
  1195. #variant s.field     : BITSET
  1196. #variant BITSCALE    : BITSET
  1197. #variant variable    : BITSET
  1198. #variant function(0) : BITSET
  1199. #variant bitarray[]  : SYSTEM.SET8
  1200. #variant constant    : SYSTEM.SET16
  1201.  
  1202. TYPE
  1203.   s = RECORD
  1204.     field: BITSET;
  1205.   END;
  1206.  
  1207.   BITSCALE = BITSET;
  1208.  
  1209. VAR
  1210.   variable: BITSET;
  1211.  
  1212. PROCEDURE function ( argument: BITSET );
  1213.  
  1214. VAR
  1215.   bitarray: ARRAY [0..9] OF SYSTEM.SET8;
  1216.  
  1217. CONST
  1218.   constant = SYSTEM.SET16{0, 4};
  1219.  
  1220.  
  1221. ΓòÉΓòÉΓòÉ 7.3.2. Pointer type function parameters ΓòÉΓòÉΓòÉ
  1222.  
  1223. In C, the actual semantics of a pointer type function parameter depends on that 
  1224. function and cannot be determined automatically. A function may interpret its 
  1225. parameter of type T* as either: 
  1226.  
  1227.      pointer to T (type defined as POINTER TO T) 
  1228.  
  1229.      single value passed by reference (VAR T) 
  1230.  
  1231.      array (ARRAY OF T) 
  1232.  
  1233.      array passed by reference (VAR ARRAY OF T) 
  1234.  
  1235.  where the corresponding Modula-2 formal types are given in parenthesis. 
  1236.  
  1237.  The #variant directive may be used to explicitly point out the semantics of 
  1238.  each pointer type parameter. 
  1239.  
  1240.  Note: In order to keep original headers intact, #variant directives may be 
  1241.  placed into the project file inside the corresponding !header directive. 
  1242.  
  1243.      Example 
  1244.  
  1245.  
  1246. ΓòÉΓòÉΓòÉ 7.3.2.1. Example ΓòÉΓòÉΓòÉ
  1247.  
  1248. #variant function(0) : VAR
  1249. #variant function(1) : ARRAY
  1250. #variant function(2) : VAR ARRAY
  1251.  
  1252. void function(int*, int*, int*, int*);
  1253.  
  1254. is translated to: 
  1255.  
  1256. TYPE
  1257.   PtrSInt = POINTER TO SYSTEM.int;
  1258.  
  1259. PROCEDURE function ( VAR arg0: SYSTEM.int;
  1260.                          arg1: ARRAY OF SYSTEM.int;
  1261.                      VAR arg2: ARRAY OF SYSTEM.int;
  1262.                          arg3: PtrSInt );
  1263.  
  1264.  
  1265. ΓòÉΓòÉΓòÉ 7.3.3. Preserving constant names ΓòÉΓòÉΓòÉ
  1266.  
  1267. By default, a #define directive introducing a constant is translated to a 
  1268. constant declaration: 
  1269.  
  1270.   #define ENOTEXIST 10        CONST 
  1271.  ENOTEXIST = 10; 
  1272.  
  1273. This is the only way in case of a native code Modula-2 compiler, since such 
  1274. constants are substituted by a C preprocessor and do not appear in object 
  1275. files. But in case of a convertor to C, the original C headers will be used 
  1276. after conversion and it would be useful to refer to their names in the 
  1277. generated C text. Setting the GENROVARS option ON forces constants to be 
  1278. translated to read-only variables (Note: this is an XDS language extension). 
  1279. This option has no effect on generation for a native-code Modula-2 compiler. 
  1280.  
  1281. The #variant directive may be used to specify a type for a variable: 
  1282.  
  1283.   #define  ENOTEXIST 10       VAR 
  1284.   #variant ENOTEXIST : CARDINAL    ENOTEXIST-: CARDINAL; 
  1285.  
  1286.  
  1287. ΓòÉΓòÉΓòÉ 8. Project files ΓòÉΓòÉΓòÉ
  1288.  
  1289.      Overview 
  1290.      Project file contents 
  1291.  
  1292.  
  1293. ΓòÉΓòÉΓòÉ 8.1. Overview ΓòÉΓòÉΓòÉ
  1294.  
  1295. The most powerful and multi-purpose feature of H2D is the project file, which 
  1296. name may be specified at the command line after =p. 
  1297.  
  1298. The project file may be used: 
  1299.  
  1300.      To translate a set of header files at once, using the same option 
  1301.       settings: 
  1302.  
  1303.       -BACKEND=C 
  1304.       -GENROVARS+ 
  1305.       !module <stdio.h> 
  1306.       !module <stdlib.h> 
  1307.  
  1308.      To map calling/naming convention qualifiers used by a particular C 
  1309.       compiler to those supported by H2D (see Non-standard qualifiers), or to 
  1310.       make them ignorable: 
  1311.  
  1312.       !header <*.h>       /* define for all headers */ 
  1313.       #define _System syscall 
  1314.       #define far 
  1315.       !end 
  1316.  
  1317.      To define macros which are predefined by a particular C compiler or are 
  1318.       used in conditional compilation preprocessor directives (see Conditional 
  1319.       compilation): 
  1320.  
  1321.       !header <*.h> 
  1322.       #define __WATCOM_C__ 
  1323.       #define INCL_DOS 
  1324.       !end 
  1325.  
  1326.      To declare type synonyms in order to prevent H2D from automatic type 
  1327.       declarations (see Function prototypes and Types): 
  1328.  
  1329.       !header <*.h> 
  1330.       typedef char *String   /* no more PtrChar */ 
  1331.       !end 
  1332.  
  1333.      To collect non-standard preprocessor directives in order to keep original 
  1334.       header files intact (see Project file contents): 
  1335.  
  1336.       !header <string.h> 
  1337.       #variant strlen(0) : ARRAY 
  1338.       !end 
  1339.  
  1340.      Example 
  1341.  
  1342.  
  1343. ΓòÉΓòÉΓòÉ 8.1.1. Example ΓòÉΓòÉΓòÉ
  1344.  
  1345. The header files a.h and m1.h: 
  1346.  
  1347. /* a.h */
  1348.   #include "m1.h"
  1349.   #define constant1 0x11u
  1350.   __PASCAL function3( float * arg0, unsigned long arg1 );
  1351. /* end a.h */
  1352.  
  1353. /* m1.h */
  1354.   #define constant2 0x111u
  1355.   __PASCAL function1( float * arg0, float * arg1 );
  1356.   function2( unsigned long arg0, unsigned long arg1 );
  1357. /* end m1.h */
  1358.  
  1359. with project file p.h2d: 
  1360.  
  1361. !header "*.h"
  1362.   #define __PASCAL pascal
  1363. !end
  1364. !header "a.h"
  1365.   #merge "m1.h"
  1366. !end
  1367. !header "m1.h"
  1368.   #variant function1 (1) : VAR
  1369.   #variant constant2 : BITSET
  1370.   #variant function2 (1) : BITSET
  1371. !end
  1372. !module "a.h"
  1373.  
  1374. are translated to 
  1375.  
  1376. (* ************************ *)
  1377. (*           m1.h           *)
  1378. (* ************************ *)
  1379. CONST
  1380.   constant2 = {0, 4, 8};
  1381. <*- GENTYPEDEF *>
  1382. TYPE
  1383.   PtrFloat = POINTER TO REAL;
  1384. PROCEDURE ["StdCall"] function1 ( arg0: PtrFloat;
  1385.                            VAR arg1: REAL ): SYSTEM.int;
  1386. PROCEDURE function2 ( arg0: LONGCARD; arg1: BITSET ): SYSTEM.int;
  1387. (* *********************** *)
  1388. (*           a.h           *)
  1389. (* *********************** *)
  1390. CONST
  1391.   constant1 = 111H;
  1392. PROCEDURE ["StdCall"] function3 ( arg0: PtrFloat;
  1393.                             arg1: LONGCARD ): SYSTEM.int;
  1394.  
  1395.  
  1396. ΓòÉΓòÉΓòÉ 8.2. Project file contents ΓòÉΓòÉΓòÉ
  1397.  
  1398. A project file may contain options settings and directives. Option settings in 
  1399. a project file override settings in the configuration file. 
  1400.  
  1401. H2D recognizes the following directives in project files: !header, !module, and 
  1402. !name, which are described is the following sections. 
  1403.  
  1404.      !header 
  1405.      !module 
  1406.      !name 
  1407.  
  1408.  
  1409. ΓòÉΓòÉΓòÉ 8.2.1. !header ΓòÉΓòÉΓòÉ
  1410.  
  1411. !header ( '<' Pattern '>' | '"' Pattern '"' )
  1412.   Prologue
  1413. [
  1414. !footer
  1415.   Epilogue
  1416. ]
  1417. !end
  1418.  
  1419. Pattern is a regular expression (see Redirection file) representing a set of 
  1420. file names. Prologue and Epilogue are arbitrary sequences of C language tokens. 
  1421. Prologue is inserted at the beginning of any header file which name matches 
  1422. Pattern; Epilogue is appended to its end. !footer and Epilogue may be omitted. 
  1423.  
  1424. If a header file name matches Pattern in more than one !header directive, their 
  1425. Prologue and Epilogue' sections are merged. 
  1426.  
  1427. Prologue usually contains: 
  1428.  
  1429.      #merge and #variant directives 
  1430.  
  1431.      Predefined macros of a particular C compiler 
  1432.  
  1433.      Type synonym declarations to prevent automatic type names generation 
  1434.  
  1435.  Note: If there are #include directives in either Prolodue or Epilogue ensure 
  1436.  that names of the included files do not match Pattern, to avoid recursive 
  1437.  inclusion: 
  1438.  
  1439.   !header <*.h&^mytypes.h>
  1440.   #include <mytypes.h>
  1441.   !end
  1442.  
  1443.  
  1444. ΓòÉΓòÉΓòÉ 8.2.2. !module ΓòÉΓòÉΓòÉ
  1445.  
  1446. !module ( <file_name> | "file_name" )
  1447.  
  1448. The !module directive is used to specify header files which are to be 
  1449. translated when H2D processes the project file. 
  1450.  
  1451. Translating more than one header at once has one more advantage. A header file 
  1452. name may occur multiple times in #include directives. H2D keeps information 
  1453. about each translated header in memory, and if an already transtaled header 
  1454. file is encountered, it is not processed again. Note: In this case H2D requires 
  1455. more memory. 
  1456.  
  1457.      Example 
  1458.  
  1459.  
  1460. ΓòÉΓòÉΓòÉ 8.2.2.1. Example ΓòÉΓòÉΓòÉ
  1461.  
  1462. !module <ctype.h>
  1463. !module <math.h>
  1464. !module <stdio.h>
  1465. !module <stdlib.h>
  1466. !module <string.h>
  1467.  
  1468.  
  1469. ΓòÉΓòÉΓòÉ 8.2.3. !name ΓòÉΓòÉΓòÉ
  1470.  
  1471. !name ( '<' file_name '>' | '"' file_name '"' ) identifier
  1472.  
  1473. H2D replaces file_name with identifier when generating module names. This may 
  1474. be useful when file_name contains special characters (e.g. my-header.h), or 
  1475. when there are headers with equal names in different directories. See also the 
  1476. description of the GENLONGNAMES option. 
  1477.  
  1478.      Example 
  1479.  
  1480.  
  1481. ΓòÉΓòÉΓòÉ 8.2.3.1. Example ΓòÉΓòÉΓòÉ
  1482.  
  1483. !name <errno.h>   errno 
  1484. !name <sys\errno.h> syserrno 
  1485.  
  1486.  
  1487. ΓòÉΓòÉΓòÉ 9. Options Reference ΓòÉΓòÉΓòÉ
  1488.  
  1489. This chapter contains brief descriptions of all options that may be specified 
  1490. in either configuration file. or project file. 
  1491.  
  1492. The general option syntax is: 
  1493.  
  1494.   Option = "-" name ("+" | "-" | "=" (string | integer)) 
  1495.  
  1496. Option names are case insensitive. Case is preserved when string option values 
  1497. are stored or emitted, but is ignored when they are compared. 
  1498.  
  1499. Examples 
  1500.  
  1501.     -mergeall+
  1502.     -GENWIDTH=78
  1503.     -BackEnd=Common
  1504.  
  1505.      File extensions and prefixes 
  1506.      Translation options 
  1507.      Base types definition 
  1508.  
  1509.  
  1510. ΓòÉΓòÉΓòÉ 9.1. File extensions and prefixes ΓòÉΓòÉΓòÉ
  1511.  
  1512. This group of options sets file name extensions and prefixes for H2D input and 
  1513. output files. 
  1514.  
  1515. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  1516.  Option   Sets extension for...                        Default
  1517.  
  1518.  DEFEXT   definition modules                           def
  1519.  
  1520.  DIREXT   directive files                              dir
  1521.  
  1522.  HEADEXT  header files                                 h
  1523.  
  1524.  MODEXT   implementation modules                       mod
  1525.  
  1526.  PRJEXT   project files                                h2d
  1527.  
  1528.  TREEEXT  include tree files (see the GENTREE option)  tre
  1529.  
  1530.  Option   Sets prefix for...                           Default
  1531.  
  1532.  DEFPFX   definition modules                           none
  1533.  
  1534.  MACPFX   macro prototype modules                      _
  1535. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  1536.  
  1537.  
  1538. ΓòÉΓòÉΓòÉ 9.2. Translation options ΓòÉΓòÉΓòÉ
  1539.  
  1540. For each option, a set of possible values is given in parenthesis: 
  1541.  
  1542. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  1543.  string   an arbitrary sequence of characters
  1544.  
  1545.  numeric  an unsigned integer number
  1546.  
  1547.  boolean  ON or OFF
  1548. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  1549.  
  1550.      BACKEND - target compiler back-end 
  1551.      CHANGEDEF - enable retranslation 
  1552.      COMMENTPOS - preserved comments position 
  1553.      CPPCOMMENTS - recognize C++ comments 
  1554.      CSTDLIB - set CSTDLIB value 
  1555.      GENDIRS - extract non-standard directives 
  1556.      GENENUM - enum translation mode 
  1557.      GENLONGNAMES - keep directory names 
  1558.      GENMACRO - produce macro prototype modules 
  1559.      GENROVARS - translate constants to read-only variables 
  1560.      GENSEP - insert merged headers separators 
  1561.      GENTREE - generate inclusion tree 
  1562.      GENWIDTH - limit output line length 
  1563.      MERGEALL - merge all headers 
  1564.      PROGRESS - enable progress indicator 
  1565.  
  1566.  
  1567. ΓòÉΓòÉΓòÉ 9.2.1. BACKEND - target compiler back-end ΓòÉΓòÉΓòÉ
  1568.  
  1569. (Native/C/Common) 
  1570.  
  1571. Enables generation of definition modules suitable for either native-code 
  1572. compiler, translator to C, or both. It also affects generation of additional 
  1573. modules (See Fitting a Modula-2 compiler). 
  1574.  
  1575. Default: Common - both native and translator. 
  1576.  
  1577.  
  1578. ΓòÉΓòÉΓòÉ 9.2.2. CHANGEDEF - enable retranslation ΓòÉΓòÉΓòÉ
  1579.  
  1580. (boolean) 
  1581.  
  1582. If this option is set OFF, H2D does not translate a header file if a definition 
  1583. module corresponding to it already exists. Otherwise, H2D produces a new 
  1584. definition module which may overwrite the old one. 
  1585.  
  1586. See also Redirection file. 
  1587.  
  1588. Default: OFF - do not process already translated headers 
  1589.  
  1590.  
  1591. ΓòÉΓòÉΓòÉ 9.2.3. COMMENTPOS - preserved comments position ΓòÉΓòÉΓòÉ
  1592.  
  1593. (numeric) 
  1594.  
  1595. Sets starting position of comments preserved by H2D in output files. Has effect 
  1596. only on comments which are placed next to declarations. 
  1597.  
  1598. Default: delimit comments with a single blank. 
  1599.  
  1600.  
  1601. ΓòÉΓòÉΓòÉ 9.2.4. CPPCOMMENTS - recognize C++ comments ΓòÉΓòÉΓòÉ
  1602.  
  1603. (boolean) 
  1604.  
  1605. If this option is set ON, H2D recognizes C++-style comments (started with '//') 
  1606. in header files. 
  1607.  
  1608. Default: ON - recognize C++ comments. 
  1609.  
  1610.  
  1611. ΓòÉΓòÉΓòÉ 9.2.5. CSTDLIB - set CSTDLIB value ΓòÉΓòÉΓòÉ
  1612.  
  1613. (boolean) 
  1614.  
  1615. Sets value of the CSTDLIB XDS option in output definition modules corresponding 
  1616. to top-level header files (listed on the command line or in a project file). 
  1617. See Convertor to C for more information. 
  1618.  
  1619. Default: OFF - set CSTDLIB off in definition modules. 
  1620.  
  1621.  
  1622. ΓòÉΓòÉΓòÉ 9.2.6. GENDIRS - extract non-standard directives ΓòÉΓòÉΓòÉ
  1623.  
  1624. (boolean) 
  1625.  
  1626. If this option is set ON, a file containing non-standard preprocessor 
  1627. directives is produced for each header file. 
  1628.  
  1629. Deafult: OFF - do not extract non-standard directives 
  1630.  
  1631.  
  1632. ΓòÉΓòÉΓòÉ 9.2.7. GENENUM - enum translation mode ΓòÉΓòÉΓòÉ
  1633.  
  1634. (Const/Enum/Mixed) 
  1635.  
  1636. Defines whether C enumerations should be unconditionally translated to integer 
  1637. constants (Const) or Modula-2 enumeration types (Enum). If set to Mixed, only 
  1638. enumerations with default (or explicitly specified, but matching default) 
  1639. constant values are translated to enumeration types; all other are translated 
  1640. to constants. See also Enumeration. 
  1641.  
  1642. Default: Const - always translate to constants 
  1643.  
  1644.  
  1645. ΓòÉΓòÉΓòÉ 9.2.8. GENLONGNAMES - keep directory names ΓòÉΓòÉΓòÉ
  1646.  
  1647. (boolean) 
  1648.  
  1649. This option controls translation of the #include directive in cases when a 
  1650. specified file name contains directories. If this option is set OFF, H2D strips 
  1651. directory names. Otherwise directory names are kept and separators are replaced 
  1652. with underscore characters: 
  1653.  
  1654. #include <sys\errno.h>      IMPORT sys_errno; 
  1655.  
  1656. See also !name. 
  1657.  
  1658. Default: OFF - strip directory names 
  1659.  
  1660.  
  1661. ΓòÉΓòÉΓòÉ 9.2.9. GENMACRO - produce macro prototype modules ΓòÉΓòÉΓòÉ
  1662.  
  1663. (boolean) 
  1664.  
  1665. Setting this option ON forces H2D to produce prototype modules for 
  1666. function-like C macros encountered in header files (prototype means that 
  1667. implementation modules contain procedures with empty bodies; the actual code 
  1668. has to be written by hand). These modules have not to be imported, but to be 
  1669. added to the link list. See also Native code. 
  1670.  
  1671. This option is ignored if the target is XDS-C (the BACKEND option is set to C). 
  1672.  
  1673. Default: OFF - do not generate macro modules. 
  1674.  
  1675.  
  1676. ΓòÉΓòÉΓòÉ 9.2.10. GENROVARS - translate constants to read-only variables ΓòÉΓòÉΓòÉ
  1677.  
  1678. (boolean) 
  1679.  
  1680. Being set ON, enables translation of #defined constants to read-only variables. 
  1681. Have no effect in native back-end sections. See Preserving constant names for 
  1682. more information. 
  1683.  
  1684. Default: OFF - do not translate constants to variables. 
  1685.  
  1686.  
  1687. ΓòÉΓòÉΓòÉ 9.2.11. GENSEP - insert merged headers separators ΓòÉΓòÉΓòÉ
  1688.  
  1689. (boolean) 
  1690.  
  1691. Setting this option ON forces H2D to insert a comment containing name of a 
  1692. merged header before declarations from that header. 
  1693.  
  1694. Default: OFF - do not insert separators 
  1695.  
  1696.  
  1697. ΓòÉΓòÉΓòÉ 9.2.12. GENTREE - generate inclusion tree ΓòÉΓòÉΓòÉ
  1698.  
  1699. (boolean) 
  1700.  
  1701. If this option is set ON, H2D produces a text file containing a tree of 
  1702. #include directives for each header file specified on the command line or in a 
  1703. project file using the !module directive. A name of a tree file is a name of a 
  1704. corresponding header file with extension defined by the TREEEXT option. 
  1705.  
  1706. Default: OFF - do not produce tree files 
  1707.  
  1708.  
  1709. ΓòÉΓòÉΓòÉ 9.2.13. GENWIDTH - limit output line length ΓòÉΓòÉΓòÉ
  1710.  
  1711. (numeric) 
  1712.  
  1713. Sets maximum length of a string in the output file. 
  1714.  
  1715. Default: do not limit string length. 
  1716.  
  1717.  
  1718. ΓòÉΓòÉΓòÉ 9.2.14. MERGEALL - merge all headers ΓòÉΓòÉΓòÉ
  1719.  
  1720. (boolean) 
  1721.  
  1722. If this option is set ON, H2D merges all header files included into the 
  1723. translated header by means of the #include directive. If this option is set 
  1724. OFF, H2D generates separate definition module for each header which is not 
  1725. specified in the #merge directive. 
  1726.  
  1727. See also File inclusion and Headers merging. 
  1728.  
  1729. Default: OFF - do not merge headers which are not specified in the #merge 
  1730. directive. 
  1731.  
  1732.  
  1733. ΓòÉΓòÉΓòÉ 9.2.15. PROGRESS - enable progress indicator ΓòÉΓòÉΓòÉ
  1734.  
  1735. (boolean) 
  1736.  
  1737. Setting this option ON enables progress indicator. 
  1738.  
  1739. Default: OFF - show no progress indicator 
  1740.  
  1741.  
  1742. ΓòÉΓòÉΓòÉ 9.3. Base types definition ΓòÉΓòÉΓòÉ
  1743.  
  1744. The base types definition and mapping options, CTYPE and M2TYPE, have a special 
  1745. syntax. Either of them may be specified more than once in a project or 
  1746. configuration file, provided that each time a new type is defined. See Base 
  1747. types mapping for more information on usage of these directives. 
  1748.  
  1749. By default, H2D is configured to support XDS compilers. 
  1750.  
  1751.      CTYPE - define a C base type 
  1752.      M2TYPE - define a Modula-2 type 
  1753.  
  1754.  
  1755. ΓòÉΓòÉΓòÉ 9.3.1. CTYPE - define a C base type ΓòÉΓòÉΓòÉ
  1756.  
  1757. (special) 
  1758.  
  1759. This option defines size and default mapping of a C base type. 
  1760.  
  1761. CTypeOption = '-' 'CTYPE' '=' Type '=' size ',' qualident
  1762. Type = 'signed char'     | 'unsigned char'      |
  1763.        'short int'       | 'unsigned short int' |
  1764.        'signed int'      | 'unsigned int'       |
  1765.        'signed long int' | 'unsigned long int'  |
  1766.        'float'           | 'double'             |
  1767.        'long float'      | 'long double'
  1768.  
  1769. size is the size of Type in bytes, and qualident is a Modula-2 type to which 
  1770. Type should be translated by default: 
  1771.  
  1772. -CTYPE = signed char = 1, CHAR 
  1773.  
  1774. See Base types mapping for more information. 
  1775.  
  1776.  
  1777. ΓòÉΓòÉΓòÉ 9.3.2. M2TYPE - define a Modula-2 type ΓòÉΓòÉΓòÉ
  1778.  
  1779. (special) 
  1780.  
  1781. This option defines a Modula-2 type. 
  1782.  
  1783. M2TypeOption = '-' 'M2TYPE' '=' qualident '=' size ',' Attr
  1784. Attr = 'BOOL'   | 'CHAR' |
  1785.        'REAL'   | 'SET'  |
  1786.        'SIGNED' | 'UNSIGNED'
  1787.  
  1788. qualident is a Modula-2 type being defined, size is its size in bytes, and Attr 
  1789. is a family to which it belongs: 
  1790.  
  1791. -M2TYPE = SYSTEM.INT16 = 2, SIGNED 
  1792.  
  1793. See Base types mapping for more information. 
  1794.  
  1795.  
  1796. ΓòÉΓòÉΓòÉ 10. XDS ΓòÉΓòÉΓòÉ
  1797.  
  1798. XDS is a family name for development systems featuring Modula-2 and Oberon-2 
  1799. programming languages. It is available for the most popular platforms, 
  1800. including IBM PC (OS/2, Linux, Windows NT/95 editions), and various Unix 
  1801. workstations (Sun, HP, DEC, etc.). XDS provides an uniform programming 
  1802. environment for all mentioned platforms and allows to design and implement 
  1803. truly portable software. 
  1804.  
  1805. The XDS Modula-2 compiler implements ISO standard of Modula-2. The ISO standard 
  1806. library set is accessible for both Modula-2 and Oberon-2. 
  1807.  
  1808. All XDS implementations share the same platform-independent front-end for both 
  1809. source languages. The output code can be either native code for the target 
  1810. platform (Native XDS) or text in the ANSI C language (XDS-C). ANSI C code 
  1811. generation is available for all platforms. 
  1812.  
  1813. XDS includes standard ISO and PIM libraries along with a set of utility 
  1814. libraries and an interface to the ANSI C library set. 
  1815.  
  1816. Native XDS-x86 produces highly optimized 32-bit code for Intel x86 family. It 
  1817. is available for OS/2, Linux, Windows NT, and Windows 95. 
  1818.  
  1819. XDS for OS/2 and Win32 platforms come with two major enhancements: the IDE and 
  1820. the interface to the host operating system API for both Modula-2 and Oberon-2. 
  1821.  
  1822.  For more information about XDS, please visit our Web page at: 
  1823.  
  1824. http://www.xds.ru/xds/ 
  1825.  
  1826. or write an e-mail to: 
  1827.  
  1828. support@xds.ru. 
  1829.  
  1830.  
  1831. ΓòÉΓòÉΓòÉ 11. Tables ΓòÉΓòÉΓòÉ
  1832.  
  1833.  
  1834. ΓòÉΓòÉΓòÉ 11.1. Table 1. Configuration file example ΓòÉΓòÉΓòÉ
  1835.  
  1836. -DEFEXT  = def    % file extensions
  1837. -HEADEXT = h
  1838. -MODEXT  = d
  1839. -PRJEXT  = prj
  1840. -TREEEXT = inc
  1841. -DIREXT  = dir
  1842.  
  1843. -DEFPFX = h2d_    % prefix for output definition modules
  1844. -MACPFX = m_      % prefix for macro prototype modules
  1845.  
  1846. -BACKEND = COMMON % M2 compiler compatibility mode: C, NATIVE, COMMON
  1847. -GENMACRO-        % do not generate macro prototype modules
  1848. -GENWIDTH = 70    % maximum string length in output files
  1849. -COMMENTPOS = 0   % comment position
  1850. -CHANGEDEF+       % allow to overwrite existing definition modules
  1851. -PROGRESS+        % enable progress indicator
  1852. -CSTDLIB-         % do not set C standard library option
  1853. -CPPCOMMENTS+     % recognize C++ comments
  1854. -MERGEALL+        % merge all #included headers
  1855. -GENSEP-          % separate merged headers with comments
  1856. -GENLONGNAMES-    % prepen module name with directory names
  1857. -GENENUM = CONST  % enum transtaltion mode: CONST, ENUM, AUTO
  1858. -GENTREE+         % create file with include/merge tree
  1859. -GENDIRS+         % extract non-standrard directives
  1860. -GENROVARS+       % translate constants to read-only variables
  1861.  
  1862. % C BASE TYPES SYNONYMS:
  1863.  
  1864. -ctype = signed char        =  1, CHAR
  1865. -ctype = signed int         =  4, SYSTEM.int
  1866.   .  .  .
  1867. -ctype = long float         =  8, UNDEF
  1868. -ctype = long double        =  8, UNDEF
  1869.  
  1870. % MODULA-2 TYPES:
  1871.  
  1872. -m2type = INTEGER         = 4, SIGNED
  1873. -m2type = SHORTINT        = 1, SIGNED
  1874.   .  .  .
  1875. -m2type = SYSTEM.SET32    = 4, SET
  1876. -m2type = SYSTEM.int      = 4, SIGNED
  1877. -m2type = SYSTEM.unsigned = 4, UNSIGNED
  1878.  
  1879.  
  1880. ΓòÉΓòÉΓòÉ 12. Figures ΓòÉΓòÉΓòÉ
  1881.  
  1882.  
  1883. ΓòÉΓòÉΓòÉ 12.1. Figure 1. Configuration file example ΓòÉΓòÉΓòÉ
  1884.  
  1885. -DEFEXT  = def    % file extensions
  1886. -HEADEXT = h
  1887. -MODEXT  = d
  1888. -PRJEXT  = prj
  1889. -TREEEXT = inc
  1890. -DIREXT  = dir
  1891.  
  1892. -DEFPFX = h2d_    % prefix for output definition modules
  1893. -MACPFX = m_      % prefix for macro prototype modules
  1894.  
  1895. -BACKEND = COMMON % M2 compiler compatibility mode: C, NATIVE, COMMON
  1896. -GENMACRO-        % do not generate macro prototype modules
  1897. -GENWIDTH = 70    % maximum string length in output files
  1898. -COMMENTPOS = 0   % comment position
  1899. -CHANGEDEF+       % allow to overwrite existing definition modules
  1900. -PROGRESS+        % enable progress indicator
  1901. -CSTDLIB-         % do not set C standard library option
  1902. -CPPCOMMENTS+     % recognize C++ comments
  1903. -MERGEALL+        % merge all #included headers
  1904. -GENSEP-          % separate merged headers with comments
  1905. -GENLONGNAMES-    % prepen module name with directory names
  1906. -GENENUM = CONST  % enum transtaltion mode: CONST, ENUM, AUTO
  1907. -GENTREE+         % create file with include/merge tree
  1908. -GENDIRS+         % extract non-standrard directives
  1909. -GENROVARS+       % translate constants to read-only variables
  1910.  
  1911. % C BASE TYPES SYNONYMS:
  1912.  
  1913. -ctype = signed char        =  1, CHAR
  1914. -ctype = signed int         =  4, SYSTEM.int
  1915.   .  .  .
  1916. -ctype = long float         =  8, UNDEF
  1917. -ctype = long double        =  8, UNDEF
  1918.  
  1919. % MODULA-2 TYPES:
  1920.  
  1921. -m2type = INTEGER         = 4, SIGNED
  1922. -m2type = SHORTINT        = 1, SIGNED
  1923.   .  .  .
  1924. -m2type = SYSTEM.SET32    = 4, SET
  1925. -m2type = SYSTEM.int      = 4, SIGNED
  1926. -m2type = SYSTEM.unsigned = 4, UNSIGNED
  1927.