home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / c2pli.zip / C2PLI.CMD next >
OS/2 REXX Batch file  |  1998-04-20  |  363KB  |  11,573 lines

  1. /****************************** Module Header *******************/
  2. /*                                                                                */
  3. /*  Module Name: C2PLI.CMD                                                   */
  4. /*  C to PL/I Conversion Aid                                                   */
  5. /*                                                                                */
  6. /* Copyright (c) International Business Machines Corporation 1994            */
  7. /*                                                                                */
  8. /* ===========================================================*/
  9.  
  10. /* REXX PROGRAM */
  11. signal on syntax
  12. signal on notready
  13.  
  14.  
  15. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  16. call SysLoadFuncs
  17.  
  18. options exmode  
  19.  
  20.    /*************************************************************************
  21.    *   Utility to convert C header files to PL/I include files              *
  22.    *   This utility is called C2pli and takes the c header file name as     *
  23.    *   argument. This utility is only an aid to conversion. The user needs  *
  24.    *   to manually complete the conversion. Undetected unsupported          *
  25.    *   features may be mapped incorrectly. This utility is not a parser.    *
  26.    *                                                                        *
  27.    **************************************************************************/
  28.  
  29. parse source how why inputfile
  30. say how
  31. say why
  32. say inputfile
  33. parse arg allargs
  34.  
  35. /************
  36.  Set Options
  37. ************/
  38.  
  39. P_opt = OFF
  40. T_opt = OFF
  41. graphicOpt = OFF
  42. left_margin = 2
  43. right_margin = 72
  44.  
  45. arglist = ''
  46. do until words(allargs) == 0
  47.    arg1 = translate(strip(word(allargs, 1),'both'))
  48.    if arg1 == '-P' then
  49.       P_opt = ON
  50.    else if arg1 == '-T' then
  51.      T_opt = ON
  52.    else if arg1 == '-G' then
  53.      graphicOpt = ON
  54.    else if arg1 == '-RM' then do
  55.      allargs = subword(allargs,2)
  56.      right_margin = strip(word(allargs, 1), 'both')
  57.    end
  58.    else if arg1 == '-LM' then do
  59.      allargs = subword(allargs,2)
  60.      left_margin = strip(word(allargs, 1), 'both')
  61.    end
  62.    else
  63.      arglist = arglist arg1
  64.  
  65.    allargs = subword(allargs,2)
  66. end
  67.  
  68. inputfile = arglist
  69.  
  70. if P_opt  == OFF & T_opt == OFF then T_opt = ON /* default */
  71.  
  72. z = ""
  73. do left_margin - 1
  74.    z = z || " "
  75. end
  76.  
  77.  
  78. listfile = ""
  79. infile = inputfile
  80.  
  81.   /*************************
  82.   * Invocation format             *
  83.   *************************/
  84.   if inputfile = "" | inputfile = '?' then do
  85.     say "C to PL/I header file conversion aid.  See cread.me for more information."
  86.     say
  87.     say "Usage: c2pli [-opts] inputfile [outputfile]"
  88.     say
  89.     say "     inputfile:   The C header file to be translated.  Should have"
  90.     say "                  a filetype of h.                                   "
  91.     say "     outputfile:  The name of the PL/I file to be generated.  If     "
  92.     say "                  omitted, defaults to the same name as the inputfile"
  93.     say "                  with a filetype of cpy.                            "
  94.     say "     opts: "
  95.     say "            t  - Preserves C typecasts (default)"
  96.     say "            p  - Preserves statements as preprocessor declares"
  97.     say "            g  - Causes the M suffix to be used on string literals in    "
  98.     say "                 the generated PL/I code (for DBCS strings).             "
  99.     say "            lm - Left margin                                             "
  100.     say "            rm - Right margin                                            "
  101.     say "            Using both the t and p options will produce two translations "
  102.     say "            for some statements."
  103.     say
  104.     say "Examples:     c2pli fn.h"
  105.     say "              c2pli -t fn.h"
  106.     say "              c2pli -p -g -lm 1 -rm 100 fn.h fn.inc"
  107.     exit
  108.  end
  109.  
  110.     /*********************************************************/
  111.    /*                          !!!!!!!  IMPORTANT  !!!!!!!                                   */
  112.    /* PLEASE READ THE FOLLOWING NOTE BELOW IF YOUR FILE USES     */
  113.    /* PREDEFINED SYSTEM LINKAGE CONVENTIONS AND MAKE CHANGES   */
  114.    /*  AS REQUIRED.                                                                        */
  115.    /**********************************************************/
  116.  
  117.    /***********************************************************************/
  118.    /*  Please include your predefined system linkage conventions below if                    */
  119.    /*  it is not already in the list below:                                                                    */
  120.    /*                                                                                                                   */
  121.    /*  ex: If you defined  CALLP16 to be _Far16 _Pascal then the following                   */
  122.    /*  would be the mapping:                                                                                  */
  123.    /*  ex in C:   #define CALLP16 _Far16 _Pascal                                                       */
  124.    /*  ex in PL/I : %dcl CALLP16 char scan;                                                               */
  125.    /*                  %CALLP16 = options(linkage(pascal16) byvalue nodescriptor) external;*/
  126.    /*                                                                                                                   */
  127.    /*  If you then used CALLP16 in a function declaration you would need to manually   */
  128.    /*  add it to the list below in order for the aid to recognize the predefined linkage     */
  129.    /*  name.                                                                                                         */
  130.    /*  ex in C :      int CALLP16 fun1( );                                                                    */
  131.    /*  ex in PL/I:   dcl fun1 entry ( )                                                                        */
  132.    /*                          returns (fixed bin(31) byvalue)                                              */
  133.    /*                           CALLP16                                                                            */
  134.    /*                                                                                                                   */
  135.    /* The list below will look like the following after CALLP16 is added to the list:         */
  136.    /*        linkages = "_System _Optlink _Pascal",                                                      */
  137.    /*                       "_Far16 _Pascal _Far16 _Cdecl",                                                */
  138.    /*                        "_Far16 _Fastcall _Far16",                                                       */
  139.    /*                        "APIENTRY EXPENTRY APIENTRY16",                                         */
  140.    /*                        "PASCAL16 CDECL16 DSQ_API_FN",                                            */
  141.    /*                        "SQL_API_FN _Seg16 SOMLINK",                                                */
  142.    /*                        "CALLP16"                                                                            */
  143.    /*                                                                                                                   */
  144.    /************************************************************************/
  145.  
  146.  
  147.    /********************************************************
  148.    *  Please include your predefined system linkage conventions below if*                                                                       *
  149.    *  it is not already in the list below:                                   *
  150.    *                                                                          *
  151.    *********************************************************/
  152.   linkages = "_System _Optlink _Pascal",
  153.               "_Far16 _Pascal _Far16 _Cdecl",
  154.               "_Far16 _Fastcall _Far16",
  155.               "APIENTRY EXPENTRY APIENTRY16",
  156.               "PASCAL16 CDECL16 DSQ_API_FN",
  157.               "SQL_API_FN _Seg16 SOMLINK"
  158.  
  159.  
  160.    /********************************************************
  161.    *  Scans the number of arguments the aid was invoked with.          *                                                                       *
  162.    *********************************************************/
  163.  
  164.    num_args = words(inputfile)
  165.    if num_args = 2 then
  166.      do
  167.       fname = word(inputfile,num_args)
  168.       inputfile = word(inputfile,1)
  169.     end
  170.  
  171.    else do
  172.      fname = word(inputfile,1)
  173.      inputfile = fname
  174.    end
  175.  orig_retain = inputfile
  176.  
  177.  is_one = stream(inputfile, "C", "query exists");
  178.  If is_one \= '' Then
  179.   Do;
  180.     len = pos(".",inputfile)
  181.     tmp_file = substr(inputfile,1,len)||"#tm"
  182.    "copy" inputfile tmp_file
  183.  End;
  184.  else do
  185.   say "Inputfile "inputfile "not found"
  186.   exit
  187.  end
  188.  
  189.    /********************************************************
  190.    *  Scans file to see if C++ coments are used. If a C++ comment is   *                                                                       *
  191.    *  encountered then the comments are converted to C comments.       *
  192.    *                                                                          *
  193.    *********************************************************/
  194.   say "Converting  "inputfile " to PL/I "
  195.  
  196.   call SysFileSearch "//", tmp_file, 'file'
  197.  
  198.   if file.0 > 0 then
  199.      call change_comments inputfile tmp_file
  200.  
  201.  
  202.    /********************************************************
  203.    *  Checks to see if the aid was invoked with two arguments or one   *                                                                       *
  204.    *  and assigns filenames accordingly.                                    *
  205.    *                                                                          *
  206.    *********************************************************/
  207.  
  208.  
  209.  if inputfile \= "" then do
  210.   if num_args = 1 then
  211.    do
  212.      parse var inputfile fname '.' ext junk
  213.    end
  214.  
  215.    else do
  216.      parse var infile inputfile fname
  217.      inputfile = strip(inputfile)
  218.      fname = strip(fname)
  219.      parse var inputfile inputfile "." ext
  220.   end
  221.  
  222.    /********************************************************
  223.    *  Checks to see if the extension is .h. If not a message is issued   *                                                                       *
  224.    *  program exits.                                                         *
  225.    *                                                                          *
  226.    *********************************************************/
  227.  
  228.  
  229.    ext = strip(ext)
  230.     if translate(ext) \= "H" & translate(ext) \= "MRI" then
  231.      do
  232.        say "Input File should be a .h file"
  233.        say "This utility can only convert a .h file"
  234.        exit
  235.     end
  236.  
  237.  
  238.  
  239.    /********************************************************
  240.    *  Makes back up copy of the existing cpy files or user defined file.  *                                                                       *
  241.    *********************************************************/
  242.  
  243.   if num_args = 1 then
  244.   do
  245.      if translate(ext) = "H" then
  246.      do
  247.         incname = fname||".cpy"
  248.         oldname = fname||".bak"
  249.      end
  250.  
  251.      else if translate(ext) = "MRI" then
  252.      do
  253.         oldname = fname||".bak"
  254.         incname = fname||".mrp"
  255.      end
  256.  end
  257.  
  258.  
  259.  
  260.   if num_args = 2 then
  261.   do
  262.      if translate(ext) = "H" then
  263.      do
  264.         incname = fname
  265.         parse var fname tmp "." ext
  266.         oldname = tmp".bak"
  267.      end
  268.  
  269.      else if translate(ext) = "MRI" then
  270.      do
  271.         incname = fname
  272.         parse var fname tmp "." ext
  273.         oldname = tmp||".bak"
  274.      end
  275.  end
  276.  
  277.      is_one = stream(oldname, "C", "query exists");
  278.      If is_one \= '' Then
  279.       Do;
  280.        call SysFileDelete oldname
  281.      End;
  282.  
  283.    /*  If name.inc already exists, rename to name.bakw no message */
  284.    is_one = stream(incname, "C", "query exists");
  285.    If is_one \= '' Then
  286.    Do;
  287.      tmpname = translate(is_one, " ", "\")
  288.      num_words = words(tmpname)
  289.      tmpname = word(tmpname, num_words)
  290.      parse var tmpname justname"." .
  291.      just_name = justname || ".bak"
  292.      "Rename" incname just_name
  293.    End;
  294.  
  295.     outputfile = incname
  296.      rc = stream(outputfile,"C","OPEN WRITE")
  297.      inputfile = tmp_file
  298. /*  end */
  299.  
  300. /*******************************************************
  301. * Set up counter to control indentation line number and right margins*
  302. ********************************************************/
  303. counter = 0
  304. indent       = 0
  305. indentation  = "   "
  306. strt_counter = 1
  307. line_num     = 0
  308. i = 0
  309. j = 0
  310. k = 0
  311. array.i.k = ""
  312. c. = ""
  313. comment. = ""
  314. out_line = z"/**********************************************************"
  315. rc = lineout(outputfile,out_line)
  316. out_line = z"*   CREATED BY C2PLI CONVERSION UTILITY                   *"
  317. rc = lineout(outputfile,out_line)
  318. out_line = z"**********************************************************/"
  319. rc = lineout(outputfile,out_line)
  320.  
  321. /********************************************
  322. * Open the input file.  Read each line and              *
  323. * call a routine to process the line                      *
  324. ********************************************/
  325.  
  326. rc = stream(inputfile, "C", "OPEN")
  327.  
  328. do while lines(inputfile)
  329.    line = linein(inputfile)
  330.    line_num = line_num + 1
  331.    line =strip(line)
  332.  
  333.  
  334.    /********************************************
  335.    * If the line continues to the next line,                 *
  336.    * append the second line to the first, etc.              *
  337.    ********************************************/
  338.  
  339.    len = lastpos("\",line)
  340.    if len > 0 & len = length(line) then
  341.    do
  342.    do while len > 0
  343.       parse var line line "\"
  344.       line = line || linein(inputfile)
  345.       line = strip(line)
  346.       line_num = line_num + 1
  347.       len = lastpos("\",line)
  348.    end
  349.   end
  350.    call process_line line
  351. end
  352.  
  353.  
  354. /******************************************************
  355. * Close the outputfile and end the conversion process               *
  356. ******************************************************/
  357.  
  358. rc = stream(outputfile, "C", "CLOSE")
  359. rc = stream(inputfile, "C", "CLOSE")
  360.  
  361. say "CONVERSION OF "infile" to PL/I IS COMPLETE."
  362. end
  363. rc = SysFileDelete(tmp_file)
  364. exit
  365.  
  366.    /********************************************************
  367.    *  Routine to convert C++ comments to C comments.                  *                                                                       *
  368.    *********************************************************/
  369.  
  370. change_comments:
  371.   parse arg fn nfn
  372.  
  373. if fn = '?' | fn= '' then
  374.   do
  375.     say 'Usage: COMMENT fn'
  376.     say ''
  377.     say 'Replaces //... with /*...*/'
  378.     exit
  379.   end
  380.  
  381.  
  382.  
  383. rc = stream(nfn,'C','OPEN')
  384.  
  385. do while lines(fn) > 0
  386.   len = 0
  387.   change=0
  388.   l = linein(fn)
  389.   len = lastpos("//",l)
  390.  
  391.   if len > 0 then
  392.   do
  393.     do while pos('//', l) > 0
  394.       l=overlay('/*', l, pos('//', l))
  395.     change=1
  396.   end
  397.  end
  398.  
  399.   if change=1 then
  400.   do
  401.    if lastpos("*/",l) = 0 & len >  0 then
  402.       l = l||' */'
  403.    end
  404.   call lineout nfn,l
  405. end
  406.  
  407. call lineout fn   /* Closes file */
  408. call lineout nfn  /* Closes file */
  409.  
  410.  
  411. return
  412.  
  413.    /********************************************************
  414.    *  Routine invoked when severe error occurs .. program terminates    *                                                                       *
  415.    *********************************************************/
  416. syntax:
  417.  say 'REXX syntax error  ' rc 'in line' sigl':' errortext(rc)
  418.  say sourceline(sigl)
  419.  trace ?r; nop
  420.  
  421.  
  422.  
  423. notready:
  424. out_line = z"%note('Error 1: Unsupported syntax encountered',4);"
  425. rc = lineout(outputfile,out_line)
  426. out_line = z"/* Severe Error occured while processing the file */"
  427. rc = lineout(outputfile,out_line)
  428. out_line = z"/* Program is terminated                           */"
  429. rc = lineout(outputfile,out_line)
  430. out_line = z"/* The original line in the .h file is: "line_num" */"
  431. rc = lineout(outputfile,out_line)
  432. out_line = ""
  433. rc = lineout(outputfile,out_line)
  434. say = "Terminating error occured "
  435. exit
  436.  
  437.    /********************************************************
  438.    *  Routine called by the aid to write information to the .inc file and  *
  439.    *  check the return code for a successful write. If the write failed an *
  440.    *  error message is issued the .inc file is closed and program ends.   *                                                                       *
  441.    *********************************************************/
  442.  
  443.   do_writeout:
  444.    parse arg outputline
  445.  
  446.    len = length(outputline)
  447.    if len > right_margin then
  448.      rc = do_format1(outputline)
  449.    else do
  450.      rc = lineout(outputfile,outputline)
  451.    end
  452.  
  453.    if rc \= 0 then
  454.      do
  455.        out_line = z"%note('Error 2: Unsupported syntax encountered',4);"
  456.        rc = lineout(outputfile,out_line)
  457.        out_line = z"/* Severe Error occured while processing the file */"
  458.        rc = lineout(outputfile,out_line)
  459.        out_line = z"/* Program is terminated                           */"
  460.        rc = lineout(outputfile,out_line)
  461.        out_line = z"/* The original line in the .h file is: "line_num" */"
  462.        rc = lineout(outputfile,out_line)
  463.        out_line = ""
  464.        rc = lineout(outputfile,out_line)
  465.        say = "Terminating error occured "
  466.        rc =stream(inputfile".inc",'C','CLOSE')
  467.        exit
  468.      end
  469.     return
  470.    /*******************************************************************
  471.    *   Subroutine to process a line in the input file                                      *
  472.    ********************************************************************/
  473. process_line:
  474.  
  475.    parse arg line
  476.  
  477.    /*****************************************
  478.    * Remove white space from the beginning          *
  479.    * of the input line                                   *
  480.    *****************************************/
  481.  
  482.   line = strip(line)
  483.  
  484.   if left(line,1,5) = "const" & left(line,6) = " " then
  485.     do
  486.        parse var line "const" line
  487.        line = strip(line)
  488.     end
  489.   else
  490.    /***************************
  491.    * Check for a comment line *
  492.    ***************************/
  493.  
  494.    if substr(line,1,2) = "/*" then call do_comment(line)
  495.  
  496.    /*************************
  497.    * Check for a blank line *
  498.    *************************/
  499.  
  500.    else if line = "" then do
  501.       call do_blank
  502.    end  /* Do */
  503.  
  504.    /***************************************
  505.    * Parse out the first word in the line *
  506.    ***************************************/
  507.  
  508.    else do
  509.       parse var line first rest
  510.  
  511.    /***************************************************
  512.    * Remove spaces between ex:# define ... if it exists*
  513.    ***************************************************/
  514.       if first = "#" then
  515.        do
  516.           parse var rest first1 rest
  517.           if datatype(first1) = "NUM" then
  518.              do
  519.                first = first
  520.                rest = first1
  521.              end
  522.           else
  523.              first = first||first1
  524.       end
  525.       else nop  /* comes in here most of the times. */
  526.  
  527.       first = strip(first)
  528.  
  529.       /*********************************************
  530.       * Determine the type of statement to convert            *
  531.       *********************************************/
  532.       select
  533.          when translate(first) = "#UNDEF" then call do_undef(rest)
  534.          when translate(first) = "#INCLUDE" then call do_include(rest)
  535.          when translate(first) = "#DEFINE" then call do_define(rest)
  536.          when translate(first) = "UNION" then do
  537.              i = 1     /* i & j act as counters to keep track of the level of nesting */
  538.              j = 1
  539.              call do_union(rest)
  540.          end  /* Do */
  541.          when translate(first) = "TYPEDEF" then do
  542.              flag = "typedef"
  543.              tflag = "on"
  544.              i = 1       /* i & j act as counters to keep track of the level of nesting */
  545.              j = 1
  546.              call do_typedef(rest)
  547.          end /* Do */
  548.          when translate(first) = "STRUCT"   then do
  549.              tflag = "off"
  550.              i = 1    /* i & j act as counters to keep track of the level of nesting */
  551.              j = 1
  552.              call do_real_struct(rest)
  553.          end  /* Do */
  554.          when translate(first) = "ENUM" then call do_enum(rest)
  555.          when translate(first) = "#IFDEF" then call do_ifdef(rest)
  556.          when translate(first) = "#IF" then call do_if(rest)
  557.          when translate(first) = "#IFNDEF" then call do_ifndef(rest)
  558.          when translate(first) = "#ENDIF" then call do_endif(rest)
  559.          when translate(first) = "#PRAGMA" then call do_pragma(rest)
  560.          when translate(first) = "#ELSE" then call do_else(rest)
  561.          when translate(first) = "#ERROR" then call do_error(rest)
  562.          when translate(first) = "#LINE" | translate(first) = "#" then call do_line(rest)
  563.          when translate(first) = "SOMEXTERN" then call do_som(rest)
  564.          when translate(first) = "#ELSEIF" then call do_elseif(rest)
  565.          when translate(first) = "#ELIF" then call do_elif(rest)
  566.  
  567.          otherwise do
  568.  
  569.             /********************************************
  570.             * If the line contains none of the previous *
  571.             * commands, check if it is a variable or    *
  572.             * function definition                       *
  573.             ********************************************/
  574.             org_line = line
  575.             call do_variable_or_function(line)
  576.  
  577.             if result = false then
  578.               do
  579.                say " Problem encountered "org_line
  580.                 cpos = pos("/*",org_line)
  581.                 if cpos \= 0 then
  582.                  do
  583.                     comment = substr(org_line,cpos)
  584.                     line = delstr(org_line,cpos)
  585.                  end
  586.                  else
  587.                     line = org_line
  588.  
  589.                 out_line = z"%note('Error 3: Unsupported syntax encountered',4);"
  590.                 call do_writeout(out_line)
  591.                 out_line = z"/* This definition is not supported by this utility. */ "
  592.                 call do_writeout(out_line)
  593.                 out_line = z"/* Error: "line" */ "
  594.                 call do_writeout(out_line)
  595.  
  596.                 if cpos \= 0 then
  597.                    call do_comment(comment)
  598.                 out_line = z"/* The original line in the .h file is: "line_num" */"
  599.                 call do_writeout(out_line)
  600.                 out_line = ""
  601.                 call do_writeout(out_line)
  602.             end
  603.          end
  604.       end  /* select */
  605.    end
  606. return
  607. exit
  608.  
  609.  
  610.    /********************************************************************
  611.    *   Subroutine to process a blank line                              *
  612.    ********************************************************************/
  613.  
  614. /******************************
  615. * If there is a blank line,   *
  616. * output a blank line to the  *
  617. * converted header file       *
  618. ******************************/
  619.  
  620. do_blank:
  621.    rc = lineout(outputfile,line)
  622. return
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.    /********************************************************************
  631.    *   Subroutine to process #undef statement                          *
  632.    ********************************************************************/
  633.  
  634. /********************************
  635. * Routine called to deactivate a statement *
  636. ********************************/
  637.  
  638. do_undef:
  639.  
  640.    parse arg rest
  641.    cpos = pos("/*",rest)
  642.    if cpos \= 0 then
  643.     do
  644.       rest = substr(rest,cpos)
  645.       comment = delstr(rest,cpos)
  646.     end
  647.  
  648.    parse var rest name
  649.    name = check_name(name)
  650.    out_line = z"%deact "name";"
  651.    call do_writeout(out_line)
  652.     if cpos \= 0 then
  653.     call do_comment(comment)
  654. return
  655.  
  656. /********************************************************
  657. * Routine used to format line > right margin in length.
  658. *********************************************************/
  659.  
  660.  
  661. do_format1:
  662.  
  663. parse arg rest_o
  664. len = length(rest_o)
  665. all = rest_o
  666.  
  667.        if substr(rest_o,right_margin) = "*/" then
  668.        do
  669.            rest1 = substr(rest_o,1,right_margin-1)
  670.            rest_o = rest1" */"
  671.            all = rest_o
  672.            o_line =dbleft(rest_o,right_margin)
  673.       end
  674.       else
  675.            o_line =dbleft(rest_o,right_margin)
  676.  
  677.       rc = lineout(outputfile,o_line)
  678.  
  679.       rest_o = z || dbrleft(all,right_margin)
  680.  
  681.       flag_done = false
  682.         do while flag_done=false
  683.            if rest_o \= "" then
  684.              do
  685.  
  686.                if substr(rest_o,right_margin) = "*/" then
  687.                 do
  688.                   rest1 = substr(rest_o,1,right_margin-1)
  689.                   rest_o = rest1" */"
  690.                   o_line = dbleft(rest_o,right_margin)
  691.                end
  692.                else
  693.                   o_line = dbleft(rest_o,right_margin)
  694.  
  695.               rc = lineout(outputfile,o_line)
  696.               rest_o = z || dbrleft(rest_o,right_margin)
  697.             end
  698.             if rest_o \= "" then
  699.                flag_done = false
  700.             else do
  701.                 flag_done = true
  702.                 rest_o = ""
  703.             end
  704.  
  705.        end
  706.   return rc
  707.  
  708.  
  709.  
  710.  
  711.  
  712.    /********************************************************************
  713.    *   Subroutine to process #include statement                        *
  714.    ********************************************************************/
  715.  
  716. do_include:
  717.  parse arg rest
  718.  
  719.    /******************************
  720.    * Parse the include statement *
  721.    ******************************/
  722.  
  723.    cpos=pos('/*', rest)
  724.    if cpos\=0 then
  725.      do
  726.        comment=substr(rest,cpos)
  727.        rest=delstr(rest,cpos)
  728.      end
  729.  
  730.    f_name = strip(rest)
  731.  
  732.    /******************************************
  733.    * Translate the include statement to PL/I *
  734.    ******************************************/
  735.  
  736.    parse value f_name with f_name '.' extension
  737.    f_name = substr(f_name,2)
  738.    f_name= check_name(f_name)
  739.  
  740.    /* change '/' to '\' for os/2 */
  741.    do while (pos('/',f_name) \= 0)
  742.       pos_slash = pos('/',f_name)
  743.       f_name    = overlay('\',f_name, pos_slash)
  744.    end  /* do while (pos('/',f_name) \= 0) */
  745.  
  746.    o_line = z"%include" f_name";"
  747.    o_line = do_indent(o_line)
  748.    call do_writeout(o_line)
  749.  
  750.    if cpos \= 0 then
  751.      call do_comment(comment)
  752.  
  753.  return
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.    /********************************************************************
  766.    *   Subroutine to process #define statement                         *
  767.    ********************************************************************/
  768.  
  769. do_define:
  770.    parse arg rest
  771.    /**********************************************
  772.    * Separate comments from the rest of the line            *
  773.    **********************************************/
  774.  
  775.    cpos=pos('/*', rest)
  776.    if cpos\=0 then
  777.      do
  778.         comment=substr(rest,cpos)
  779.         comment = strip(comment)
  780.         rest=delstr(rest,cpos)
  781.      end
  782.  
  783.    parse var rest name val
  784.  
  785.    if left(val,1) == '"' then do
  786.       notop = 0
  787.       leftshift = 0
  788.       rightshift = 0
  789.       oropr = 0
  790.    end
  791.    else do
  792.       notop = pos("~",val)
  793.       leftshift = pos("<<",val)
  794.       rightshift = pos(">>",val)
  795.       oropr = pos("|",val)
  796.    end
  797.  
  798.    numeric digits 10
  799.    num = ""
  800.    flag = ""
  801.    max_val = "2147483647"
  802.  
  803.    /************************************************
  804.    * Remove the __ prefix from the definition name *
  805.    ************************************************/
  806.  
  807.      if substr(name,1,1) = "_" then
  808.        name = check_name(name)
  809.  
  810.  
  811.    /*********************************************
  812.    * If it is simply a definition which defines              *
  813.    * xxx=XXX then ignore it                                 *
  814.    *********************************************/
  815.  
  816.    val1st = left(strip(val),1)
  817.    if translate(name) = val |,
  818.       name = translate(val) |,
  819.       pos("[",name) \= 0 |,
  820.       (pos("[",val) \= 0 & val1st \= "'" & val1st \= '"'),
  821.       then do
  822.          out_line = z"%note('Error 4: Unsupported syntax encountered',4);"
  823.          call do_writeout(out_line)
  824.  
  825.          out_line = z"/* This definition is not supported by this utility. */ "
  826.          call do_writeout(out_line)
  827.          out_line = z"/* Error: #define "name" "val" */ "
  828.          call do_writeout(out_line)
  829.  
  830.          if cpos \= 0 then
  831.            call do_comment(comment)
  832.  
  833.          out_line = z"/* The original line in the .h file is: "line_num" */"
  834.          call do_writeout(out_line)
  835.          out_line = ""
  836.          call do_writeout(out_line)
  837.        return
  838.   end
  839.  
  840.    /************************************************
  841.    * Processing for left shift and right shift is done below. *
  842.    ************************************************/
  843.  
  844.    select
  845.      when leftshift \= 0 & pos("(",name) = 0 then do
  846.            call  do_shift(name" "val)
  847.  
  848.            if cpos \= 0 then
  849.               call do_comment(comment)
  850.  
  851.            val = done
  852.            return val
  853.       end
  854.  
  855.        when rightshift \= 0 & pos("(",name) = 0 then do
  856.            call do_shift(name" "val)
  857.  
  858.            if cpos \= 0 then
  859.               call do_comment(comment)
  860.  
  861.            val = done
  862.            return val
  863.        end
  864.  
  865.    /************************************************
  866.    * Error messages for Or Not is provided. *
  867.    ************************************************/
  868.  
  869.        when oropr \= 0 & pos("(",name) = 0 then do
  870.           out_line = z"%note('Error 5: Unsupported syntax encountered',4);"
  871.           call do_writeout(out_line)
  872.           out_line = z"/* Or operator is not supported by this utility. */ "
  873.            call do_writeout(out_line)
  874.           out_line = z"/* Error: #define "name" "val" */ "
  875.           call do_writeout(out_line)
  876.  
  877.           if cpos \= 0 then
  878.              call do_comment(comment)
  879.  
  880.           out_line = z"/* The original line in the .h file is: "line_num" */"
  881.           call do_writeout(out_line)
  882.           out_line = ""
  883.           call do_writeout(out_line)
  884.           val = done
  885.           return val
  886.        end
  887.  
  888.         when notop \= 0 & substr(val,1) = "~" & pos("(",name) = 0 then do
  889.             val = strip(val)
  890.             out_line = z"%dcl "name" char ext;"
  891.             call do_writeout(out_line)
  892.             out_line = z"%"name"='"val"';"
  893.             call do_writeout(out_line)
  894.  
  895.             out_line = z"%dcl @"name" char ext;"
  896.             call do_writeout(out_line)
  897.             out_line = z"%@"name"='@"val"';"
  898.             call do_writeout(out_line)
  899.  
  900.             if cpos \= 0 then
  901.                call do_comment(comment)
  902.  
  903.             val = done
  904.             return val
  905.          end
  906.       otherwise
  907.          nop  /* okay to come here */
  908.     end
  909.  
  910.    parse var val val
  911.    val = strip(val)
  912.  
  913.    /**************************************************
  914.    * In case it is a array convert to PL/I array mapping.         *
  915.    **************************************************/
  916.  
  917.      if pos("[",name) \= 0 then
  918.        do
  919.           if pos("][",name) \= 0 then
  920.             do
  921.               name= convert_bracket(name)
  922.               name = convert_finalbracket(name)
  923.             end
  924.             else
  925.               name = convert_finalbracket(name)
  926.        end
  927.  
  928.  
  929.    /********************************
  930.    * Check for pointer definition  *
  931.    * by looking for a *            *
  932.    ********************************/
  933.  
  934.    if val = "*" then return
  935.    if substr(val,1,1) = "*" then do
  936.     val = "pointer"
  937.    end
  938.  
  939.  
  940.    /*******************************************
  941.    * Check to see if the definition sets a                *
  942.    * value, or simply declares a variable as              *
  943.    * defined.  If there is no value, set the               *
  944.    * variable = 'Y'                                        *
  945.    *******************************************/
  946.  
  947.    if val = "" then
  948.      do
  949.        out_line1 = z"%dcl "name" char ext;"
  950.        out_line = z"%"name" = 'Y';"
  951.  
  952.        out_line1 = do_indent(out_line1)
  953.        call do_writeout(out_line1)
  954.  
  955.        out_line = do_indent(out_line)
  956.        call do_writeout(out_line)
  957.        out_line=""
  958.  
  959.        if cpos \= 0 then
  960.           call do_comment(comment)
  961.        val = done
  962.        if val = done then return
  963.  
  964.      end
  965.  
  966.     /************************************************
  967.     * Check to see if the value is of a special kind then        *
  968.     * use %dcl syntax since the value needs to be substituted  *
  969.     *************************************************/
  970.  
  971.       sys_lc = "_System * _Seg16 _Far16 _Far16 _Pascal void _Far16 _Cdecl",
  972.       "_Pascal _Optlink _Far16 _Fastcall"
  973.  
  974.           if wordpos(val,sys_lc) > 0 then
  975.           do
  976.             val = special_value(val)
  977.  
  978.             out_line1 = z"%dcl "name" char scan;"
  979.             out_line  = z"%"name" = '"val"';"
  980.  
  981.             out_line1 = do_indent(out_line1)
  982.             call do_writeout(out_line1)
  983.  
  984.             out_line = do_indent(out_line)
  985.             call do_writeout(out_line)
  986.             out_line=""
  987.  
  988.             if cpos \= 0 then
  989.               call do_comment(comment)
  990.             val = done
  991.             if val = done then return
  992.          end
  993.  
  994.     /*****************************************************
  995.     * Check to see if the value is an alias to a C datatype then       *
  996.     * use define alias syntax.                                           *
  997.     ******************************************************/
  998.  
  999.     datatypes = " long short char int unsigned short long int short int unsigned int ",
  1000.      " unsigned char unsigned long signed short signed int signed long signed char "
  1001.  
  1002.      if wordpos(val,datatypes) > 0  then
  1003.        do
  1004.           val = process_rtype(val)
  1005.  
  1006.           out_line = z"define alias "name" "val";"
  1007.           out_line= do_indent(out_line)
  1008.           call do_writeout(out_line)
  1009.  
  1010.           out_line1 = z"define alias @"name" pointer;"
  1011.           out_line= do_indent(out_line1)
  1012.           call do_writeout(out_line1)
  1013.  
  1014.           out_line = ""
  1015.           out_line1 = ""
  1016.           val = done
  1017.  
  1018.           if cpos \= 0 then
  1019.             call do_comment(comment)
  1020.  
  1021.           if val = done then return
  1022.        end
  1023.  
  1024.  
  1025.  
  1026.  
  1027.     /************************************************
  1028.     * Check to see if the name in #define is FAR or NEAR then*
  1029.     * give it the pointer attribute.                                *
  1030.     *************************************************/
  1031.  
  1032.     if (translate(name) = "FAR" | translate(name) = "NEAR") & (val \= "" )then
  1033.       do
  1034.          val = special_value(val)
  1035.  
  1036.          out_line1 = z"define alias "name" pointer;"
  1037.          out_line1 = do_indent(out_line1)
  1038.          call do_writeout(out_line1)
  1039.  
  1040.          val = done
  1041.          if cpos \= 0 then
  1042.             call do_comment(comment)
  1043.  
  1044.          if val = done then return
  1045.       end
  1046.  
  1047.  
  1048.       /*****************************************************
  1049.       * If there are parentheses in the definition, or value is typecasted*
  1050.       * call a routine to handle them.                                     *
  1051.       *****************************************************/
  1052.  
  1053.  
  1054.        if pos('(', val) \= 0 | pos('(',name) \= 0 then
  1055.           do
  1056.              val = do_typecasts(name,val)
  1057.  
  1058.              if cpos \= 0 then
  1059.                 call do_comment(comment)
  1060.  
  1061.              val = done
  1062.              if val = done then return
  1063.           end
  1064.  
  1065.  
  1066.       /*****************************************************
  1067.       * If the value is a hexadecimal value then call a routine called    *
  1068.       * do_hex to map the value to the PL/I equivalent.                 *
  1069.       *****************************************************/
  1070.  
  1071.         if pos("0X",val) \= 0 | pos("0x",val) \= 0 then
  1072.            do
  1073.               call do_hex(name" "val)
  1074.               if cpos \= 0 then
  1075.                  call do_comment(comment)
  1076.               val = done
  1077.               if val = done then return
  1078.            end
  1079.  
  1080.  
  1081.      /*****************************************************
  1082.       * If the value is none of the above call special_value to see if   *
  1083.       * val is converted.                                                  *
  1084.       *****************************************************/
  1085.  
  1086.  
  1087.        val = special_value(val)
  1088.  
  1089.        operators = "\ ** "
  1090.        addpos = pos("+",val)
  1091.        subbpos = pos("-",val)
  1092.  
  1093.       /*****************************************************
  1094.       * If the value is directly defined then check to see if it is a char,*
  1095.       * string, number, pointer etc and use the appropriate declare       *
  1096.       * statement. If the value is a integer data type and has "UL","L" *
  1097.       * or "US" or "S" then assigns the approriate data type.            *
  1098.       ******************************************************/
  1099.     select
  1100.  
  1101.        when  (addpos \= 0 | subbpos \= 0 )then do
  1102.          out_line1 = z"%dcl "name" char ext;"
  1103.          out_line2 = z"%"name" = '"val"';"
  1104.          addpos = ""
  1105.          subbpos = ""
  1106.        end
  1107.  
  1108.       when wordpos(val,operators) > 0 then do
  1109.          out_line1 = z"/* This utility does not support this kind of operation */"
  1110.          out_line2 = z"/* Error:"first" "name" "val"*/"
  1111.       end
  1112.  
  1113.       when pos('"',val) \= 0 then do
  1114.  
  1115.         if T_opt == ON then
  1116.         do
  1117.          if graphicOpt == ON then
  1118.             out_line1 = z"dcl "name" char value("val"M);"
  1119.          else
  1120.             out_line1 = z"dcl "name" char value("val");"
  1121.          out_line2 = ""
  1122.         end
  1123.  
  1124.         if P_opt == ON then
  1125.         do
  1126.          out_line = z"%dcl "name" char ext noscan;"
  1127.          call do_writeout(out_line)
  1128.          if graphicOpt == ON then
  1129.             out_line = z"%"name" = '"val"M';"
  1130.          else
  1131.             out_line = z"%"name" = '"val"';"
  1132.          call do_writeout(out_line)
  1133.          out_line= ""
  1134.         end
  1135.       end
  1136.  
  1137.        when pos("'",val) \= 0 then do
  1138.            if T_opt == ON then
  1139.              do
  1140.                out_line1 = z"dcl "name" char value("val");"
  1141.                out_line2 = ""
  1142.              end
  1143.            if P_opt == ON then
  1144.              do
  1145.               out_line = z"%dcl "name" char ext noscan;"
  1146.               call do_writeout(out_line)
  1147.               out_line = z'%'name'="'val'";'
  1148.               call do_writeout(out_line)
  1149.               out_line= ""
  1150.             end
  1151.            end
  1152.  
  1153.  
  1154.  
  1155.        when datatype(val) = "NUM" & val <= max_val then do
  1156.          if T_opt == ON then
  1157.           do
  1158.             out_line1 = z"dcl "name" fixed bin(31) value("val");"
  1159.             out_line2= ""
  1160.           end
  1161.          if P_opt == ON then
  1162.          do
  1163.            out_line = z"%dcl "name" fixed ext noscan;"
  1164.            call do_writeout(out_line)
  1165.            out_line = z"%"name" = "val";"
  1166.            call do_writeout(out_line)
  1167.            out_line= ""
  1168.         end
  1169.        end
  1170.  
  1171.  
  1172.        when datatype(val) = "NUM" & val > max_val then do
  1173.          numeric digits 10
  1174.          val = D2X(val)
  1175.          val =  "'"val"'xn"
  1176.          if T_opt == ON then
  1177.            do
  1178.              out_line1 = z"dcl "name" fixed bin(31) value("val");"
  1179.              out_line2= ""
  1180.            end
  1181.          if P_opt == ON then
  1182.           do
  1183.             out_line = z"%dcl "name" fixed ext noscan;"
  1184.             call do_writeout(out_line)
  1185.             out_line = z"%"name" = "val";"
  1186.             call do_writeout(out_line)
  1187.             out_line= ""
  1188.          end
  1189.         end
  1190.  
  1191.    /**************************************************
  1192.    * Conversion of constants with UL.                             *
  1193.    **************************************************/
  1194.  
  1195.  
  1196.        when translate(right(val,2)) = "UL" then do
  1197.          len = length(val)
  1198.          val = strip(val)
  1199.          val = delstr(val,(len - 1),2)
  1200.  
  1201.          if datatype(val) = "NUM" then
  1202.           do
  1203.  
  1204.             if T_opt == ON then
  1205.              do
  1206.               out_line1 = z"dcl "name" unsigned fixed bin(31) value("val");"
  1207.               out_line2 = ""
  1208.              end
  1209.  
  1210.             if P_opt == ON then
  1211.              do
  1212.               out_line = z"%dcl "name" fixed ext noscan;"
  1213.               call do_writeout(out_line)
  1214.               out_line = z"%"name" = "val";"
  1215.               call do_writeout(out_line)
  1216.               out_line= ""
  1217.             end
  1218.            end
  1219.  
  1220.           else do
  1221.              val = val||UL
  1222.              out_line = z"%dcl "name" char ext;"
  1223.              call do_writeout(out_line)
  1224.              out_line = z"%"name"='"val"';"
  1225.  
  1226.              call do_writeout(out_line)
  1227.              out_line1 = z"%dcl @"name" char ext;"
  1228.              out_line2 = z"%@"name"='@"val"';"
  1229.           end
  1230.        end
  1231.    /**************************************************
  1232.    * Conversion of constants with L.                             *
  1233.    **************************************************/
  1234.  
  1235.  
  1236.        when translate(right(val,1)) = L then do
  1237.          len = length(val)
  1238.          val = delstr(val,len,1)
  1239.          if datatype(val) = "NUM" then
  1240.          do
  1241.  
  1242.          if T_opt == ON then
  1243.           do
  1244.             out_line1 = z"dcl "name" fixed bin(31) value("val");"
  1245.             out_line2 = ""
  1246.           end
  1247.  
  1248.          if P_opt == ON then
  1249.           do
  1250.             out_line = z"%dcl "name" fixed ext noscan;"
  1251.             call do_writeout(out_line)
  1252.             out_line = z"%"name" = "val";"
  1253.             call do_writeout(out_line)
  1254.             out_line= ""
  1255.          end
  1256.         end
  1257.          else do
  1258.             val = val||L
  1259.             out_line = z"%dcl "name" char ext;"
  1260.             call do_writeout(out_line)
  1261.             out_line = z"%"name"='"val"';"
  1262.             call do_writeout(out_line)
  1263.             out_line1 = z"%dcl @"name" char ext;"
  1264.             out_line2 = z"%@"name"='@"val"';"
  1265.          end
  1266.        end
  1267.  
  1268.    /**************************************************
  1269.    * Conversion of constants with U.                             *
  1270.    **************************************************/
  1271.  
  1272.        when translate(right(val,1)) = "U" then do
  1273.          len = length(val)
  1274.          val = delstr(val,len,1)
  1275.          if datatype(val) = "NUM" then
  1276.          do
  1277.            if T_opt == ON then
  1278.            do
  1279.             out_line1 = z"dcl "name" unsigned fixed bin(31) value("val");"
  1280.             out_line2 = ""
  1281.            end
  1282.           if P_opt == ON then
  1283.            do
  1284.             out_line = z"%dcl "name" fixed ext noscan;"
  1285.             call do_writeout(out_line)
  1286.             out_line = z"%"name" = "val";"
  1287.             call do_writeout(out_line)
  1288.             out_line= ""
  1289.            end
  1290.          end
  1291.  
  1292.          else do
  1293.             val = val||U
  1294.             out_line = z"%dcl "name" char ext;"
  1295.             call do_writeout(out_line)
  1296.             out_line = z"%"name"='"val"';"
  1297.             call do_writeout(out_line)
  1298.             out_line1 = z"%dcl @"name" char ext;"
  1299.             out_line2 = z"%@"name"='@"val"';"
  1300.          end
  1301.        end
  1302.  
  1303.    /**************************************************
  1304.    * Conversion of constants with US.                             *
  1305.    **************************************************/
  1306.  
  1307.        when translate(right(val,2)) = "US" then do
  1308.          len = length(val)
  1309.          val = delstr(val,(len - 1),2)
  1310.          if datatype(val) = "NUM" then
  1311.          do
  1312.            if T_opt == ON then
  1313.            do
  1314.             out_line1 = z"dcl "name" unsigned fixed bin(16) value("val");"
  1315.             out_line2 = ""
  1316.            end
  1317.  
  1318.  
  1319.            if P_opt == ON then
  1320.            do
  1321.              out_line = z"%dcl "name" fixed ext noscan;"
  1322.              call do_writeout(out_line)
  1323.              out_line = z"%"name" = "val";"
  1324.              call do_writeout(out_line)
  1325.              out_line= ""
  1326.            end
  1327.           end
  1328.          else do
  1329.             val = val||US
  1330.             out_line = z"%dcl "name" char ext;"
  1331.             call do_writeout(out_line)
  1332.             out_line = z"%"name"='"val"';"
  1333.             call do_writeout(out_line)
  1334.             out_line1 = z"%dcl @"name" char ext;"
  1335.             out_line2 = z"%@"name"='@"val"';"
  1336.          end
  1337.        end
  1338.  
  1339.    /**************************************************
  1340.    * Conversion of constants with S.                             *
  1341.    **************************************************/
  1342.  
  1343.        when translate(right(val,1)) = "S" then do
  1344.          len = length(val)
  1345.          val = delstr(val,len,1)
  1346.          if datatype(val) = "NUM" then
  1347.          do
  1348.            if T_opt == ON then
  1349.            do
  1350.             out_line1 = z"dcl "name" signed fixed bin(15) value("val");"
  1351.             out_line2 = ""
  1352.            end
  1353.           if P_opt == ON then
  1354.            do
  1355.             out_line = z"%dcl "name" fixed ext noscan;"
  1356.             call do_writeout(out_line)
  1357.             out_line = z"%"name" = "val";"
  1358.             call do_writeout(out_line)
  1359.             out_line= ""
  1360.          end
  1361.        end
  1362.          else do
  1363.             val = val||S
  1364.             out_line = z"%dcl "name" char ext;"
  1365.             call do_writeout(out_line)
  1366.             out_line = z"%"name"='"val"';"
  1367.             call do_writeout(out_line)
  1368.             out_line1 = z"%dcl @"name" char ext;"
  1369.             out_line2 = z"%@"name"='@"val"';"
  1370.          end
  1371.        end
  1372.  
  1373.       when val = "POINTER" | val = "pointer" then do
  1374.            out_line1 = z"define alias "name" "val";"
  1375.            out_line2 = ""
  1376.       end
  1377.  
  1378.       when val \= "" then do
  1379.            val = check_name(val)
  1380.            out_line = z"%dcl "name" char ext;"
  1381.            call do_writeout(out_line)
  1382.            out_line = z"%"name"='"val"';"
  1383.            call do_writeout(out_line)
  1384.            out_line1 = z"%dcl @"name" char ext;"
  1385.            out_line2 = z"%@"name"='@"val"';"
  1386.            if val = false | val = true then
  1387.               val = done
  1388.        end
  1389.  
  1390.       otherwise
  1391.         nop   /* okay to come here */
  1392.  
  1393.       val = done
  1394.     end  /* Select */
  1395.  
  1396.    num = ""
  1397.  
  1398.          /*******************************************
  1399.          * If the paren routine could not           *
  1400.          * convert the line, issue an error message *
  1401.          *******************************************/
  1402.  
  1403.          if val = false then
  1404.            do
  1405.              out_line = "%note('Error 6: Unsupported syntax encountered',4);"
  1406.              call do_writeout(out_line)
  1407.              out_line = z"/* Or operator is not supported by this utility. */ "
  1408.              call do_writeout(out_line)
  1409.              out_line = z"/* Error: "rest"*/"
  1410.              call do_writeout(out_line)
  1411.  
  1412.              if cpos \= 0 then
  1413.                 call do_comment(comment)
  1414.  
  1415.              out_line = z"/* The original line in the .h file is: "line_num" */"
  1416.              call do_writeout(out_line)
  1417.              out_line = ""
  1418.              call do_writeout(out_line)
  1419.            return
  1420.          end
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.    /***********************************
  1428.    * Output the definition statements *
  1429.    ***********************************/
  1430.    if out_line1 \= "OUT_LINE1" & out_line1 \= ""  then
  1431.     do
  1432.       out_line1 = do_indent(out_line1)
  1433.       call do_writeout(out_line1)
  1434.       out_line1 = ""
  1435.     end
  1436.    if out_line2 \= "OUT_LINE2" & out_line2 \= "" then
  1437.    do
  1438.      out_line2 = do_indent(out_line2)
  1439.      call do_writeout(out_line2)
  1440.      out_line2 = ""
  1441.    end
  1442.  
  1443.  
  1444.    /************************************
  1445.    * If there was a comment at the end *
  1446.    * of the line, convert it           *
  1447.    ************************************/
  1448.  
  1449.    if cpos \= 0 then do
  1450.       call do_comment(comment)
  1451.    end
  1452.  return
  1453.  
  1454.  /***********************************
  1455.  * Outputs the hexadecimal statements      *
  1456.  ***********************************/
  1457.  
  1458. do_hex:
  1459.  
  1460. parse arg rest
  1461. parse var rest name val
  1462.  
  1463.   /**************************************************
  1464.    * Conversion of  expressions with hex constants.  (+)*
  1465.    **************************************************/
  1466.  
  1467.  
  1468.      select
  1469.             when pos("0X",val) \= 0 & pos("+",val) \=0 & substr(val,1,1) \= "+" then do
  1470.                 parse var val val "+" val2
  1471.                 val = strip(val)
  1472.                 val2 = strip(val2)
  1473.  
  1474.                  if pos("0X",val) \= 0 then
  1475.                  do
  1476.                    val = convert_hexval1(val)
  1477.                  end
  1478.                  else
  1479.                    val2= convert_hexval1(val2)
  1480.  
  1481.                 val = val||"+"||val2
  1482.  
  1483.                 out_line1 = z"%dcl "name" char ext;"
  1484.                 call do_writeout(out_line1)
  1485.                 out_line1 = z'%'name'="'val'";'
  1486.                 call do_writeout(out_line1)
  1487.                 val = done
  1488.             end
  1489.  
  1490.  
  1491.              when pos("0x",val) \= 0 & pos("+",val) \=0 & substr(val,1,1) \= "+" then do
  1492.                 parse var val val "+" val2
  1493.                 val = strip(val)
  1494.                 val2 = strip(val2)
  1495.  
  1496.                 if pos("0x",val) \= 0 then
  1497.                  do
  1498.                    val = convert_hexval1(val)
  1499.                  end
  1500.                  else
  1501.                   val2= convert_hexval1(val2)
  1502.  
  1503.                 val = val||"+"||val2
  1504.  
  1505.                 out_line1 = z"%dcl "name" char ext;"
  1506.                 call do_writeout(out_line1)
  1507.                 out_line1 = z'%'name'="'val'";'
  1508.                 call do_writeout(out_line1)
  1509.  
  1510.                 val = done
  1511.                 if val = done then return
  1512.              end
  1513.  
  1514.    /**************************************************
  1515.    * Conversion of  expressions with hex constants.  (-)*
  1516.    **************************************************/
  1517.  
  1518.  
  1519.              when pos("0X",val) \= 0 & pos("-",val) \=0 & substr(val,1,1) \= "-" then do
  1520.                 parse var val val "-" val2
  1521.                 val = strip(val)
  1522.                 val2 = strip(val2)
  1523.  
  1524.                 if pos("0X",val) \= 0 then
  1525.                  do
  1526.                     val = convert_hexval1(val)
  1527.                  end
  1528.                  else
  1529.                     val2= convert_hexval1(val2)
  1530.                 val = val||"-"||val2
  1531.  
  1532.                 out_line1 = z"%dcl "name" char ext;"
  1533.                 call do_writeout(out_line1)
  1534.                 out_line1 = z'%'name'="'val'";'
  1535.                 call do_writeout(out_line1)
  1536.              end
  1537.  
  1538.  
  1539.              when pos("0x",val) \= 0 & pos("-",val) \=0 & substr(val,1,1) \= "-" then do
  1540.                 parse var val val "-" val2
  1541.                 val = strip(val)
  1542.                 val2 = strip(val2)
  1543.  
  1544.                  if pos("0x",val) \= 0 then
  1545.                  do
  1546.                    val = convert_hexval1(val)
  1547.                  end
  1548.                  else
  1549.                    val2= convert_hexval1(val2)
  1550.  
  1551.                 val = val||"-"||val2
  1552.                 out_line1 = z"%dcl "name" char ext;"
  1553.                 call do_writeout(out_line1)
  1554.                 out_line1 = z'%'name'="'val'";'
  1555.                 call do_writeout(out_line1)
  1556.              end
  1557.  
  1558.    /**************************************************
  1559.    * Conversion of  expressions with hex constants.  (-)*
  1560.    **************************************************/
  1561.  
  1562.             when pos("0X",val) \= 0 & substr(val,1,1) = "-" then do
  1563.                parse var val "-" val
  1564.  
  1565.                if pos("-",val) \= 0 then
  1566.                   do
  1567.                     parse var val val "-" val2
  1568.                     val = strip(val)
  1569.                     val2 = strip(val2)
  1570.                     val= convert_hexval1("-"||val)
  1571.                     val = val||" - "||val2
  1572.                  end
  1573.  
  1574.                else if pos("+",val) \= 0 then
  1575.                 do
  1576.                    parse var val val "+" val2
  1577.                    val = strip(val)
  1578.                    val2 = strip(val2)
  1579.                    val= convert_hexval1("+"||val)
  1580.                    val = val||" + "||val2
  1581.                 end
  1582.  
  1583.                else do
  1584.                   val = "-"||val
  1585.                   val = convert_hexval1(val)
  1586.                end
  1587.  
  1588.                 out_line1 = z"%dcl "name" char ext;"
  1589.                 call do_writeout(out_line1)
  1590.  
  1591.                 out_line1 = z'%'name'="'val'";'
  1592.                 call do_writeout(out_line1)
  1593.                 out_line1 = ""
  1594.                 val = done
  1595.              end
  1596.  
  1597.    /**************************************************
  1598.    * Conversion of  expressions with hex constants.  (-)*
  1599.    **************************************************/
  1600.  
  1601.  
  1602.              when pos("0x",val) \= 0 & substr(val,1,1) = "-" then do
  1603.                parse var val "-" val
  1604.  
  1605.                if pos("-",val) \= 0 then
  1606.                  do
  1607.                    parse var val val "-" val2
  1608.                    val = strip(val)
  1609.                    val2 = strip(val2)
  1610.                    val= convert_hexval1("-"||val)
  1611.                    val = val||" - "||val2
  1612.                 end
  1613.  
  1614.                else if pos("+",val) \= 0 then
  1615.                  do
  1616.                     parse var val val "+" val2
  1617.                     val = strip(val)
  1618.                     val2 = strip(val2)
  1619.                     val= convert_hexval1("+"||val)
  1620.                     val = val||" + "||val2
  1621.                  end
  1622.  
  1623.                else do
  1624.                  val = "-"||val
  1625.                  val = convert_hexval1(val)
  1626.                end  /* Do */
  1627.  
  1628.                 out_line1 = z"%dcl "name" char ext;"
  1629.                 call do_writeout(out_line1)
  1630.                 out_line1 = z'%'name'="'val'";'
  1631.                 call do_writeout(out_line1)
  1632.                 val = done
  1633.              end
  1634.  
  1635.    /**************************************************
  1636.    * Conversion of  expressions with hex constants.  (+)*
  1637.    **************************************************/
  1638.  
  1639.               when pos("0X",val) \= 0 & substr(val,1,1) = "+" then do
  1640.                parse var val "+" val
  1641.  
  1642.                if pos("-",val) \= 0 then
  1643.                  do
  1644.                   parse var val val "-" val2
  1645.                   val = strip(val)
  1646.                   val2 = strip(val2)
  1647.  
  1648.                   val= convert_hexval1("-"||val)
  1649.                   val = val||" - "||val2
  1650.                 end
  1651.  
  1652.                else if pos("+",val) \= 0 then
  1653.                  do
  1654.                   parse var val val "+" val2
  1655.                   val = strip(val)
  1656.                   val2 = strip(val2)
  1657.  
  1658.                   val= convert_hexval1("+"||val)
  1659.                   val = val||" + "||val2
  1660.                 end
  1661.  
  1662.               else do
  1663.                  val = "+"||val
  1664.                  val = convert_hexval1(val)
  1665.               end  /* Do */
  1666.  
  1667.                 out_line1 = z"%dcl "name" char ext;"
  1668.                 call do_writeout(out_line1)
  1669.                 out_line1 = z'%'name'="'val'";'
  1670.                 call do_writeout(out_line1)
  1671.              end
  1672.  
  1673.    /**************************************************
  1674.    * Conversion of  expressions with hex constants.  (+)*
  1675.    **************************************************/
  1676.  
  1677.  
  1678.             when pos("0x",val) \= 0 & substr(val,1,1) = "+" then do
  1679.                parse var val "+" val
  1680.  
  1681.                if pos("-",val) \= 0 then
  1682.                 do
  1683.                   parse var val val "-" val2
  1684.                   val = strip(val)
  1685.                   val2 = strip(val2)
  1686.                   val= convert_hexval1("-"||val)
  1687.                   val = val||" - "||val2
  1688.                 end
  1689.  
  1690.              else if pos("+",val) \= 0 then
  1691.               do
  1692.                parse var val val "+" val2
  1693.                val = strip(val)
  1694.                val2 = strip(val2)
  1695.                val= convert_hexval1("+"||val)
  1696.                val = val||" + "||val2
  1697.               end
  1698.  
  1699.               else do
  1700.                  val = "+"||val
  1701.                  val = convert_hexval1(val)
  1702.               end  /* Do */
  1703.  
  1704.                 out_line1 = z"%dcl "name" char ext;"
  1705.                 call do_writeout(out_line1)
  1706.                 out_line1 = z'%'name'="'val'";'
  1707.                 call do_writeout(out_line1)
  1708.              end
  1709.  
  1710.     /**************************************************
  1711.    * Conversion of  expressions with hex constants.  *
  1712.    **************************************************/
  1713.  
  1714.  
  1715.             when pos("0X",val) \= 0 | pos("0x",val) \= 0 then do
  1716.                call convert_hexval( name" "val)
  1717.              end
  1718.  
  1719.             otherwise nop /* okay to come here */
  1720.  
  1721.              end
  1722.     return
  1723.  
  1724.  /**************************************************
  1725.  * Replaces leading underscores in identifiers with leading #   *
  1726.  ***************************************************/
  1727.  
  1728.  
  1729. check_name:
  1730. parse arg n1
  1731.  
  1732. select
  1733.     when substr(n1,1,1) = "_" then do
  1734.        n1 = delstr(n1,1,1)
  1735.        n1 = "#"||n1
  1736.     end  /* Do */
  1737.  
  1738.    when substr(n1,1,2) = "__" then do
  1739.       n1 = delstr(n1,1,2)
  1740.       n1 = "#_"||n1
  1741.    end  /* Do */
  1742.  
  1743.   otherwise nop  /* okay to come here */
  1744.  
  1745.  end  /* select */
  1746. return n1
  1747.  
  1748.  /**************************************************
  1749.  * Processes expressions with right and left shifts.   *
  1750.  ***************************************************/
  1751.  
  1752.  
  1753. do_shift:
  1754.  
  1755.  parse arg line
  1756.  parse var line name val
  1757.  
  1758.  
  1759.       if pos("(",val) \=0  then
  1760.        do
  1761.         parse var val "(" val
  1762.         if pos("(",val) \= 0 then
  1763.           parse var val "(" val ")" num ")"
  1764.       else
  1765.         parse var val val ")" num
  1766.       end
  1767.  
  1768.       if num = "" then
  1769.          parse var val n1 shift n2
  1770.       else
  1771.       if num \= "" then
  1772.         do
  1773.          parse var num n1 shift n2
  1774.        end  /* Do */
  1775.  
  1776.       if pos("<<",n1) \= 0 then
  1777.         do
  1778.           parse var n1 n1 "<<" n2
  1779.           shift ="<<"
  1780.         end
  1781.  
  1782.       if pos(">>",n1) \= 0 then
  1783.         do
  1784.           parse var n1 n1 ">>" n2
  1785.           shift =">>"
  1786.         end
  1787.  
  1788.       shift = strip(shift)
  1789.       n1 = strip(n1)
  1790.       n2 = strip(n2)
  1791.  
  1792.    select
  1793.       when shift = "<<"  then do
  1794.         out_line1 = z"%dcl "name" char ext;"
  1795.         out_line1 = do_indent(out_line1)
  1796.         call do_writeout(out_line1)
  1797.  
  1798.         out_line1 = z"%"name"='raise2("n1","n2")';"
  1799.         out_line1 = do_indent(out_line1)
  1800.         call do_writeout(out_line1)
  1801.       end
  1802.  
  1803.  
  1804.       when shift = ">>"  then do
  1805.         out_line1 = z"%dcl "name" char ext;"
  1806.         out_line1 = do_indent(out_line1)
  1807.         call do_writeout(out_line1)
  1808.  
  1809.         out_line1 = z"%"name"='lower2("n1","n2")';"
  1810.         out_line1 = do_indent(out_line1)
  1811.         call do_writeout(out_line1)
  1812.   end
  1813.  
  1814. otherwise nop  /* okay to come here */
  1815.  
  1816.  end  /* select */
  1817. return
  1818.   /********************************************************************
  1819.    *   Subroutine to handle a definition with typecasts.                   *
  1820.    ********************************************************************/
  1821.  
  1822. do_typecasts:
  1823.  
  1824.    flag_PSZ = false
  1825.    parse arg name, val
  1826.  
  1827.    notop = pos("~",val)
  1828.    parse var val tilda "(" val
  1829.    val = strip(val)
  1830.  
  1831.    leftshift = pos("<<",val)
  1832.    rightshift = pos(">>",val)
  1833.    oropr = pos("|",val)
  1834.    len = length(name)
  1835.  
  1836.      addpos = pos("+",val)
  1837.      subbpos = pos("-",val)
  1838.  
  1839.       /*****************************************************
  1840.       * If the value is directly defined then check to see if it is a char,*
  1841.       * string, number, pointer etc and use the appropriate declare       *
  1842.       * statement. If the value is a integer data type and has "UL","L" *
  1843.       * or "US" or "S" then assigns the approriate data type.            *
  1844.       ******************************************************/
  1845.      tmp_val = val
  1846.      len = pos(")",tmp_val)
  1847.  
  1848.  
  1849.     if  pos("0x",val) = 0 & pos("0x",val) = 0 & pos("(",name) = 0 then
  1850.      if addpos \= 0 | subbpos \= 0 then
  1851.        do
  1852.          val = process_exp(val)
  1853.          out_line1 = z"%dcl "name" char ext;"
  1854.          call do_writeout(out_line1)
  1855.          out_line2 = z"%"name" = '"val"';"
  1856.          call do_writeout(out_line2)
  1857.  
  1858.          addpos = ""
  1859.          subbpos = ""
  1860.          out_line1 =""
  1861.          out_line2 = ""
  1862.  
  1863.          val = done
  1864.          return val
  1865.       end
  1866.  
  1867.      select
  1868.  
  1869.  
  1870.       /*******************************************
  1871.       * If there is a left paren in the name,    *
  1872.       * then assume it is a macro definition.    *
  1873.       * Macros are not converted by this utility *
  1874.       *******************************************/
  1875.  
  1876.       when pos("(", name) \= 0 then do
  1877.          new_file = infile
  1878.          out_line = z"%note('Error 7: Unsupported syntax encountered',4);"
  1879.          call do_writeout(out_line)
  1880.          out_line = z"/* Macros are not supported by this utility. */ "
  1881.          call do_writeout(out_line)
  1882.          out_line = z"/* Error: "name" ("val"*/"
  1883.          call do_writeout(out_line)
  1884.          macrofile = "Macros.h"
  1885.          rc = stream(macrofile,"C","OPEN WRITE")
  1886.          if counter = 0 then
  1887.          do
  1888.            out_line = ""
  1889.            rc = lineout(macrofile,out_line)
  1890.            out_line = "File : "orig_retain
  1891.            rc = lineout(macrofile,out_line)
  1892.            counter = 1
  1893.          end
  1894.  
  1895.          out_line = z"/* The original line in the .h file is: "line_num" */"
  1896.          rc = lineout(macrofile,out_line)
  1897.  
  1898.          out_line = z"#define "name" ("val
  1899.          rc = lineout(macrofile,out_line)
  1900.  
  1901.  
  1902.          if cpos \= 0 then
  1903.             call do_comment(comment)
  1904.  
  1905.          out_line = z"/* The original line in the .h file is: "line_num" */"
  1906.          call do_writeout(out_line)
  1907.          out_line = ""
  1908.  
  1909.          call do_writeout(out_line)
  1910.          cpos = 0
  1911.          val = done
  1912.          return val
  1913.       end
  1914.  
  1915.  
  1916.  
  1917.       /***********************************************
  1918.       * If the line defines a PSZ whith a hex value, remove the *
  1919.       * parenthesis and call convert_hexval for hexadecimal      *
  1920.       * conversion.                                                 *
  1921.       ***********************************************/
  1922.  
  1923.      when pos("PSZ", val) \= 0 & pos("0X", val) \= 0 then do
  1924.        parse var val "PSZ)" val ")"
  1925.  
  1926.        flag_PSZ = true
  1927.        nval = name" "val
  1928.  
  1929.        call convert_hexval(nval)
  1930.  
  1931.        val = done
  1932.        return val
  1933.      end
  1934.  
  1935.  
  1936.       when pos("PSZ", val) \= 0 & pos("0x", val) \= 0 then do
  1937.        parse var val "PSZ)" val ")"
  1938.  
  1939.        flag_PSZ = true
  1940.        nval = name" "val
  1941.  
  1942.        call convert_hexval(nval)
  1943.  
  1944.        val = done
  1945.        return val
  1946.      end
  1947.  
  1948.  
  1949.       /****************************************************
  1950.       * If the value is simply enclosed in parens, just convert it.      *
  1951.       * convert it ex: #define val ((unsigned long) 10) - double parens.*
  1952.       ****************************************************/
  1953.  
  1954.        when pos("(",val) \= 0 & oropr \= 0  then
  1955.          do
  1956.            out_line = z"%note('Error 8: Unsupported syntax encountered',4);"
  1957.            call do_writeout(out_line)
  1958.            out_line = z"/* Or operator is not supported by this utility. */ "
  1959.            call do_writeout(out_line)
  1960.            out_line = z"/* Error: "rest"*/"
  1961.            call do_writeout(out_line)
  1962.  
  1963.            if cpos \= 0 then
  1964.              call do_comment(comment)
  1965.  
  1966.            out_line = z"/* The original line in the .h file is: "line_num" */"
  1967.            call do_writeout(out_line)
  1968.            out_line = ""
  1969.            call do_writeout(out_line)
  1970.            val = done
  1971.         return val
  1972.       end
  1973.  
  1974.  
  1975.      when pos("(",val) \= 0 & verifyval(val) = 0  then
  1976.          parse var val "(" val ")" num ")"
  1977.  
  1978.  
  1979.       when  pos("(",val) \= 0 & verifyval(val) > 0 then do
  1980.         parse var val "(" val ")" num ")"
  1981.         num = strip(num)
  1982.  
  1983.         if pos("+",num) \= 0 & substr(num,1,1) \= "+" then nop
  1984.         else
  1985.         if pos("-",num) \= 0 & substr(num,1,1) \= "-" then nop
  1986.         else do
  1987.            val = val" "num
  1988.            num = ""
  1989.         end
  1990.       end
  1991.  
  1992.        when  pos("(",val) \= 0 & notop \= 0 then do
  1993.         parse var val "(" val ")" num ")"
  1994.         val = "~"||val" "num
  1995.         num = ""
  1996.       end
  1997.  
  1998.       /****************************************************
  1999.       * If the value is simply enclosed in parens, just convert it.      *
  2000.       * convert it ex: #define val (unsigned long) 10 - single parens. *
  2001.       ****************************************************/
  2002.  
  2003.       when pos("(",val) = 0  then
  2004.          parse var val val ")" num
  2005.  
  2006.        otherwise
  2007.         nop /* okay to come here */
  2008.  
  2009.   end /* select */
  2010.  
  2011.        num = strip(num)
  2012.  
  2013.       /*****************************************************
  2014.       * If num is not empty and is a hex value call do_hex to convert  *
  2015.       * num.  (it is associated with a typecast.)                         *                                                             *
  2016.       *****************************************************/
  2017.         if pos("0X",num) = 0 & pos("0x",num)= 0 then
  2018.         do
  2019.         if translate(right(num,1)) = "L" | translate(right(num,1)) = "U" | translate(right(num,1)) = "S" ,
  2020.           | translate(right(num,2)) = "UL" | translate(right(num,2)) = "US" then
  2021.           do
  2022.               num = do_value1(num)
  2023.           end
  2024.         end
  2025.  
  2026.          if num \= "" & pos("0x",num) \= 0 & substr(num,1,1) \= "+" & pos("+",num) \= 0 then
  2027.            do
  2028.              call do_hex(name" "num)
  2029.              val = done
  2030.              if val = done then return val
  2031.            end
  2032.  
  2033.  
  2034.          if num \= "" & pos("0X",num) \= 0 & substr(num,1,1) \= "+" & pos("+",num) \= 0 then
  2035.             do
  2036.               call do_hex(name" "num)
  2037.               val = done
  2038.               if val = done then return val
  2039.             end
  2040.  
  2041.          if num \= "" & pos("0x",num) \= 0 & substr(num,1,1) \= "-" & pos("-",num) \= 0 then
  2042.             do
  2043.               call do_hex(name" "num)
  2044.               val = done
  2045.               if val = done then return val
  2046.             end
  2047.  
  2048.          if num \= "" & pos("0X",num) \= 0 & substr(num,1,1) \= "-" & pos("-",num) \= 0 then
  2049.             do
  2050.               call do_hex(name" "num)
  2051.               val = done
  2052.               if val = done then return val
  2053.             end
  2054.  
  2055.         /*****************************************************
  2056.         * If num is empty and val is a hex value call do_hex to convert  *
  2057.         * val.  (it is not associated with a typecast.)                      *                                                             *
  2058.         *****************************************************/
  2059.  
  2060.          if num = "" & pos("0x",val) \= 0 then
  2061.            do
  2062.              call do_hex(name" "val)
  2063.              val = done
  2064.              if val = done then return val
  2065.            end
  2066.  
  2067.          if num = "" & pos("0X",val) \= 0 then
  2068.            do
  2069.              call do_hex(name" "val)
  2070.              val = done
  2071.              if val = done then return val
  2072.            end
  2073.  
  2074.          if num = ""  then
  2075.             do
  2076.               val = do_value(val)
  2077.               if val = done then return val
  2078.             end
  2079.          val = strip(val)
  2080.          val = space(val,1)
  2081.          val = special_value(val)
  2082.  
  2083.  
  2084.          if pos("0X",num) \= 0 | pos("0x",num) \= 0 then
  2085.            num =  convert_hexval1(num)
  2086.          num = strip(num)
  2087.  
  2088.          addpos = pos("+",num)
  2089.          subbpos = pos("-",num)
  2090.          addval = pos("+",val)
  2091.          subval = pos("-",val)
  2092.  
  2093.       /****************************************************/
  2094.       /* call the appropriate statement to define the correct data type */
  2095.       /* after value is evaluated.                                        */
  2096.       /****************************************************/
  2097.  
  2098.       if substr(num,1,1) = "*" then
  2099.         do
  2100.           out_line1 = z"define alias "name" pointer;"
  2101.         end
  2102.  
  2103.         else if datatype(num) = "NUM" & flag_pointer = true then
  2104.          do
  2105.           if T_opt == ON then
  2106.           do
  2107.            out_line1 = z"dcl "name" pointer value(ptrvalue("num"));"
  2108.           end
  2109.  
  2110.          if P_opt == ON then
  2111.          do
  2112.           out_line = z"%dcl "name" char ext noscan;"
  2113.           call do_writeout(out_line)
  2114.           out_line = z'%'name'="'num'";'
  2115.           call do_writeout(out_line)
  2116.           out_line = ""
  2117.          end
  2118.         end
  2119.  
  2120.         else if flag_pointer = true & translate(right(num,2)) = "XN" then
  2121.          do
  2122.           if T_opt == ON then
  2123.           do
  2124.            out_line1 = z"dcl "name" pointer value(ptrvalue("num"));"
  2125.           end
  2126.  
  2127.           if P_opt == ON then
  2128.            do
  2129.            out_line = z"%dcl "name" char ext noscan;"
  2130.            call do_writeout(out_line)
  2131.            out_line = z'%'name'="'num'";'
  2132.            call do_writeout(out_line)
  2133.            out_line = ""
  2134.          end
  2135.         end
  2136.  
  2137.         else if right(num,2) = "xn"  & flag = "typedval" then
  2138.           do
  2139.            if T_opt == ON then
  2140.            do
  2141.             out_line1 = z"dcl "name" type "val " value("num");"
  2142.             flag = ""
  2143.             out_line2 = ""
  2144.            end
  2145.            if P_opt == ON then
  2146.            do
  2147.             out_line = z"%dcl "name" char ext noscan;"
  2148.             call do_writeout(out_line)
  2149.             out_line = z'%'name'="'num'";'
  2150.             call do_writeout(out_line)
  2151.             out_line= ""
  2152.           end
  2153.          end
  2154.  
  2155.         else if datatype(num) = "NUM"  & flag = "typedval" then
  2156.           do
  2157.            if T_opt == ON then
  2158.            do
  2159.             out_line1 = z"dcl "name" type "val" value("num");"
  2160.             flag = ""
  2161.             out_line2 = ""
  2162.           end
  2163.  
  2164.           if P_opt == ON then
  2165.           do
  2166.             out_line = z"%dcl "name" fixed ext noscan;"
  2167.             call do_writeout(out_line)
  2168.             out_line = z'%'name'='num';'
  2169.             call do_writeout(out_line)
  2170.             out_line= ""
  2171.           end
  2172.          end
  2173.  
  2174.          else if (addpos \= 0 | subbpos \= 0) & flag ="typedval" then
  2175.            do
  2176.             if T_opt == ON then
  2177.              do
  2178.               out_line1 = z"dcl "name" type "val " value("num");"
  2179.               flag = ""
  2180.               addpos = ""
  2181.               subbpos = ""
  2182.              end
  2183.            if P_opt == ON then
  2184.            do
  2185.              out_line = z"%dcl "name" char ext noscan;"
  2186.              call do_writeout(out_line)
  2187.              out_line = z'%'name'="'num'";'
  2188.              call do_writeout(out_line)
  2189.              out_line = ""
  2190.            end  /* Do */
  2191.           end
  2192.  
  2193.         else if (addval \= 0 | subval \= 0) & flag ="typedval" then
  2194.           do
  2195.              out_line1 = z"%dcl "name" char ext;"
  2196.              out_line2 = z"%"name" = '("val")';"
  2197.              flag = ""
  2198.              addval = ""
  2199.              subval = ""
  2200.           end
  2201.  
  2202.         else if datatype(num) = "NUM" then
  2203.           do
  2204.           if T_opt == ON then
  2205.           do
  2206.            out_line1 = z"dcl "name" "val" value("num");"
  2207.           end
  2208.          if P_opt == ON then
  2209.           do
  2210.            out_line = z"%dcl "name" fixed ext noscan;"
  2211.            call do_writeout(out_line)
  2212.            out_line = z'%'name'='num';'
  2213.            call do_writeout(out_line)
  2214.            out_line= ""
  2215.          end
  2216.        end
  2217.  
  2218.         else if val = "POINTER" | val = "pointer" then
  2219.          do
  2220.            if T_opt == ON then
  2221.             do
  2222.              out_line1 = z"dcl "name" "val";"
  2223.             end
  2224.           if P_opt == ON then
  2225.            do
  2226.              out_line = z"%dcl "name" char ext noscan;"
  2227.              call do_writeout(out_line)
  2228.              out_line = z'%'name'="'val'";'
  2229.              call do_writeout(out_line)
  2230.              out_line = ""
  2231.          end
  2232.         end
  2233.  
  2234.         else if num = "" & wordpos(val,datatypes) = 0 then
  2235.           do
  2236.             out_line1 = z"%dcl "name" char ext;"
  2237.             out_line2 = z"%"name" = '("val")';"
  2238.             flag = ""
  2239.           end
  2240.  
  2241.         else if num \= "" & wordpos(val,datatypes) = 0 ,
  2242.          & flag = "typedval" then
  2243.            do
  2244.             if T_opt == ON then
  2245.             do
  2246.              out_line1 = z"dcl "name" type "val " value("num");"
  2247.             end
  2248.            if P_opt == ON then
  2249.            do
  2250.              out_line = z"%dcl "name" char ext noscan;"
  2251.              call do_writeout(out_line)
  2252.              out_line = z'%'name'="'num'";'
  2253.              call do_writeout(out_line)
  2254.              out_line = ""
  2255.            end  /* Do */
  2256.          end
  2257.  
  2258.  
  2259.         else if num \= "" then  do
  2260.           if T_opt == ON then
  2261.           do
  2262.              out_line1 = z"dcl "name" "val" value("num");"
  2263.           end
  2264.           if P_opt == ON then
  2265.            do
  2266.              out_line = z"%dcl "name" char ext noscan;"
  2267.              call do_writeout(out_line)
  2268.              out_line = z'%'name'="'num'";'
  2269.              call do_writeout(out_line)
  2270.              out_line = ""
  2271.            end  /* Do */
  2272.           end
  2273.  
  2274.         num = ""
  2275.  
  2276.  
  2277.    /***********************************
  2278.    * Output the definition statements *
  2279.    ***********************************/
  2280.    if out_line1 \= "" & out_line1 \= "OUT_LINE1" then
  2281.    do
  2282.      call do_writeout(out_line1)
  2283.      out_line1 = ""
  2284.    end
  2285.  
  2286.    if out_line2 \= "" & out_line2 \= "OUT_LINE2" then
  2287.      do
  2288.        out_line2 = do_indent(out_line2)
  2289.         call do_writeout(out_line2)
  2290.      end  /* Do */
  2291.   return val
  2292.  
  2293.  
  2294. /****************************************************
  2295. *  verifies if '+ or - ' is found in val   and process expressions  *
  2296. *  of the form (int (a+b)) or (int) a+b-c                            *
  2297. ****************************************************/
  2298.  
  2299.   process_exp:
  2300.  
  2301.   parse arg val
  2302.  
  2303.   select
  2304.  
  2305.  
  2306.       /***********************************************
  2307.       * If the line defines (unsigned long) a+b remove the *
  2308.       * parenthesis and process the expression depending on *
  2309.       * whether val is a C data type or userdefined type   *
  2310.       ***********************************************/
  2311.  
  2312.        when pos("(",val) = 0 then do
  2313.          parse var val val ")" lval
  2314.          lval = strip(lval)
  2315.  
  2316.         if wordpos(val,datatypes) > 0 then
  2317.           do
  2318.             lval = check_val(lval)
  2319.             val = lval
  2320.           end
  2321.  
  2322.         else
  2323.         if wordpos(val,datatypes) = 0 & lval \= "" then
  2324.         do
  2325.            lval = check_val(lval)
  2326.            val = lval
  2327.         end
  2328.  
  2329.         else
  2330.         if val \= "" & lval = "" then
  2331.          do
  2332.            val = check_val(val)
  2333.            val = val
  2334.          end
  2335.      end  /* Do  for when pos (" = 0*/
  2336.  
  2337.  
  2338.      when pos("(",val) \= 0 then do
  2339.        if left(val,1) = "(" then
  2340.         do
  2341.           parse var val "(" val ")" lval ")"
  2342.  
  2343.       if wordpos(val,datatypes) > 0 then
  2344.         do
  2345.           lval = check_val(lval)
  2346.           val = lval
  2347.         end
  2348.  
  2349.       else
  2350.       if wordpos(val,datatypes) = 0 & lval \= "" then
  2351.         do
  2352.            lval = check_val(lval)
  2353.            val = lval
  2354.         end
  2355.  
  2356.       else
  2357.       if val \= "" & lval = "" then
  2358.         do
  2359.           val = check_val(val)
  2360.           val = val
  2361.         end
  2362.  
  2363.      end  /* Do */
  2364.  
  2365.      else val = "("||val
  2366.    end
  2367.  
  2368.    otherwise do
  2369.       val = "("||val
  2370.    end
  2371.  
  2372.   end  /* select */
  2373.  return val
  2374.  
  2375.  
  2376.  
  2377.  /****************************************************
  2378. *  verifies if '+ or - ' is found in val   and parses the  expressions  *
  2379. *  of the required form for processing.                            *
  2380. ****************************************************/
  2381.  
  2382.   check_val:
  2383.   parse arg lval
  2384.  
  2385.   addpos = "+"
  2386.   subpos = "-"
  2387.   lval = strip(lval)
  2388.  
  2389.   if substr(lval,1,1) = "+" | substr(lval,1,1) = "-" then
  2390.    do
  2391.        sign = delstr(lval,2,length(lval))
  2392.        lval = substr(lval,2,length(lval))
  2393.    end
  2394.  
  2395.    else
  2396.       sign = ""
  2397.        lval = check_name(lval)
  2398.        origlval = lval
  2399.  
  2400.        if pos("+",lval) \= 0 | pos("-",lval) \= 0 then
  2401.          do
  2402.            select
  2403.               when pos("+",lval) \= 0 then do
  2404.                 len = pos("+",lval)
  2405.  
  2406.                 if len > 0 then
  2407.                  do
  2408.                    lval = substr(lval,1,len)
  2409.                    left1 = delstr(origlval,1,len)
  2410.                    left1 = check_name(left1)
  2411.                    lval = lval||left1
  2412.                  end
  2413.                end
  2414.  
  2415.                when pos("-",lval) \= 0 then do
  2416.                 len = pos("-",lval)
  2417.  
  2418.                 if len > 0 then
  2419.                  do
  2420.                    lval = substr(lval,1,len)
  2421.                    left1 = delstr(origlval,1,len)
  2422.                    left1 = check_name(left1)
  2423.                    lval = lval||left1
  2424.                  end
  2425.                end
  2426.  
  2427.                 otherwise nop /* okay to come here */
  2428.  
  2429.            end
  2430.        end
  2431.        return sign||lval
  2432.  
  2433.    /****************************************
  2434.    * Returns 1 or 0 depending on the sign involved *
  2435.    ****************************************/
  2436.  
  2437.  
  2438. verifyval:
  2439.  parse arg rest
  2440.  parse var rest rval
  2441.  
  2442.  select
  2443.     when pos("+",rval) \= 0 then
  2444.        rval = 1
  2445.  
  2446.     when pos("-",rval) \= 0 then
  2447.        rval = 1
  2448.  
  2449.     otherwise
  2450.        rval = 0
  2451.   end
  2452.  return rval
  2453.  
  2454.  
  2455.  
  2456.    /************************************************
  2457.    * Checks for a positive, negative or a UL or L subscripted  *
  2458.    * hexadecimal value and do the appropriate conversion and  *
  2459.    * output the values.                                           *
  2460.    *************************************************/
  2461. convert_hexval:
  2462.  parse arg rest
  2463.  parse var rest name val
  2464.  neg = ""
  2465.  val1 = ""
  2466.  
  2467.  
  2468.    select
  2469.  
  2470.       when substr(val,1,1) = "+" then
  2471.          val = delstr(val,1,1)
  2472.  
  2473.       when substr(val,1,1) = "-" then
  2474.         do
  2475.           neg = "-"
  2476.           val = delstr(val,1,1)
  2477.         end
  2478.  
  2479.      otherwise
  2480.         nop
  2481.    end  /* select */
  2482.  
  2483.   /****************************************
  2484.    * Checks for UL followed by hex constant *
  2485.    ****************************************/
  2486.  
  2487.  
  2488.     if translate(substr(val,1,2)) = "0X" then
  2489.        do
  2490.           val = substr(val, 3)
  2491.           val = strip(val)
  2492.           lpos = translate(right(val,2))
  2493.           if lpos = "UL" then
  2494.             do
  2495.               len = length(val)
  2496.               val = delstr(val,len-1,2)
  2497.               val1 = ' unsigned fixed bin(31) '
  2498.             end
  2499.  
  2500.      /****************************************
  2501.      * Checks for L followed by hex constant *
  2502.      ****************************************/
  2503.  
  2504.           l1pos = translate(right(val,1))
  2505.           if l1pos = "L" then
  2506.              do
  2507.                len = length(val)
  2508.                val = delstr(val,len,1)
  2509.                val1 = 'fixed bin(31)'
  2510.              end
  2511.      /****************************************
  2512.     * Checks for U followed by hex constant *
  2513.     ****************************************/
  2514.  
  2515.  
  2516.           l1pos = translate(right(val,1))
  2517.           if l1pos = "U" then
  2518.             do
  2519.               len = length(val)
  2520.               val = delstr(val,len,1)
  2521.               val1 = 'unsigned fixed bin(31)'
  2522.             end
  2523.  
  2524.     /****************************************
  2525.    * Checks for US followed by hex constant *
  2526.    ****************************************/
  2527.  
  2528.           l1pos = translate(right(val,2))
  2529.           if l1pos = "US" then
  2530.             do
  2531.               len = length(val)
  2532.               val = delstr(val,len-1,2)
  2533.               val1 = ' unsigned fixed bin(15)'
  2534.             end
  2535.  
  2536.     /****************************************
  2537.    * Checks for S followed by hex constant *
  2538.    ****************************************/
  2539.  
  2540.           l1pos = translate(right(val,1))
  2541.           if l1pos = "S" then
  2542.             do
  2543.               len = length(val)
  2544.               val = delstr(val,len,1)
  2545.               val1 = 'signed fixed bin(15)'
  2546.             end
  2547.  
  2548.           val =  "'"val"'xn"
  2549.           if neg \= "" then
  2550.              val = neg||val
  2551.           neg = ""
  2552.     end
  2553.  
  2554.  
  2555.     if val1 = "" then
  2556.       do
  2557.         lenval = length(val)
  2558.         if neg \= "" then val = neg || val
  2559.  
  2560.         if lenval >= 9 then
  2561.           val1 = 'fixed bin(31)'
  2562.         else
  2563.           val1 = 'fixed bin(15)'
  2564.       end
  2565.  
  2566.       /***********************************************
  2567.       * If the line defines a PSZ wth a hex value, remove the *
  2568.       * parenthesis and processes for hexadecimal      *
  2569.       * conversion.                                                 *
  2570.       ***********************************************/
  2571.  
  2572.  
  2573.     if flag_PSZ = true  then
  2574.       do
  2575.        if T_opt == ON then
  2576.        do
  2577.         out_line1 = z"dcl "name" pointer value(ptrvalue("val"));"
  2578.        end
  2579.        if P_opt == ON then
  2580.        do
  2581.         out_line = z"%dcl "name" char ext noscan;"
  2582.         call do_writeout(out_line)
  2583.         out_line = z'%'name'="'val'";'
  2584.         call do_writeout(out_line)
  2585.         out_line = ""
  2586.         flag_PSZ = false
  2587.       end
  2588.      end
  2589.     else  do
  2590.       if T_opt == ON then
  2591.        do
  2592.         out_line1 = z"dcl "name val1" value("val");"
  2593.       end
  2594.       if P_opt == ON then
  2595.        do
  2596.         out_line = z"%dcl "name" char ext noscan;"
  2597.         call do_writeout(out_line)
  2598.         out_line = z'%'name'="'val'";'
  2599.         call do_writeout(out_line)
  2600.         out_line = ""
  2601.        end
  2602.    end
  2603.  
  2604.     if out_line1 \= "" & out_line1 \= "OUT_LINE1" then
  2605.     do
  2606.       out_line1 = do_indent(out_line1)
  2607.       call do_writeout(out_line1)
  2608.       out_line1 = ""
  2609.     end
  2610.     val = done
  2611.     if val = done then return
  2612.  
  2613.  
  2614.     /************************************************
  2615.    * Checks for a positive, negative or a UL or L subscripted  *
  2616.    *  value and does the appropriate conversion and  *
  2617.    * output the values.                                           *
  2618.    *************************************************/
  2619.  
  2620.  
  2621. do_value:
  2622.  parse arg val
  2623.  parse var val val
  2624.  
  2625.   operators = "\ ** "
  2626.   addpos = pos("+",val)
  2627.   subbpos = pos("-",val)
  2628.  
  2629.      /*****************************************************
  2630.       * If the value is directly defined then check to see if it is a char,*
  2631.       * string, number, pointer etc and use the appropriate declare       *
  2632.       * statement. If the value is a integer data type and has "UL","L" *
  2633.       * or "US" or "S" then assigns the approriate data type.            *
  2634.       ******************************************************/
  2635.     select
  2636.  
  2637.    /****************************************
  2638.    * Checks for UL followed by a constant *
  2639.    * or user defined type                         *
  2640.    ***************************************/
  2641.  
  2642.        when translate(right(val,2)) = "UL" then do
  2643.          len = length(val)
  2644.          val = strip(val)
  2645.          val = delstr(val,(len - 1),2)
  2646.          if datatype(val) = "NUM" then
  2647.            do
  2648.             if T_opt == ON then
  2649.             do
  2650.              out_line1 = z"dcl "name" unsigned fixed bin(31) value("val");"
  2651.              out_line2 = ""
  2652.            end
  2653.            if P_opt == ON then
  2654.             do
  2655.              out_line = z"%dcl "name" fixed ext noscan ;"
  2656.              call do_writeout(out_line)
  2657.              out_line = z'%'name'='val';'
  2658.              call do_writeout(out_line)
  2659.              out_line= ""
  2660.            end
  2661.           end
  2662.  
  2663.           else do
  2664.              val = val||UL
  2665.              out_line = z"%dcl "name" char ext;"
  2666.              call do_writeout(out_line)
  2667.              out_line = z"%"name"='"val"';"
  2668.              call do_writeout(out_line)
  2669.              out_line1 = z"%dcl @"name" char ext;"
  2670.              out_line2 = z"%@"name"='@"val"';"
  2671.          end
  2672.        end
  2673.  
  2674.    /****************************************
  2675.    * Checks for L followed by a constant *
  2676.    * or user defined type                         *
  2677.    ***************************************/
  2678.  
  2679.        when translate(right(val,1)) = "L" then do
  2680.          len = length(val)
  2681.          val = delstr(val,len,1)
  2682.          if datatype(val) = "NUM" then
  2683.           do
  2684.            if T_opt == ON then
  2685.            do
  2686.             out_line1 = z"dcl "name" fixed bin(31) value("val");"
  2687.             out_line2 = ""
  2688.            end
  2689.           if P_opt == ON then
  2690.           do
  2691.             out_line = z"%dcl "name" fixed ext noscan;"
  2692.             call do_writeout(out_line)
  2693.             out_line = z'%'name'='val';'
  2694.             call do_writeout(out_line)
  2695.             out_line= ""
  2696.           end
  2697.          end
  2698.           else do
  2699.              val = val||L
  2700.              out_line = z"%dcl "name" char ext;"
  2701.              call do_writeout(out_line)
  2702.              out_line = z"%"name"='"val"';"
  2703.              call do_writeout(out_line)
  2704.              out_line1 = z"%dcl @"name" char ext;"
  2705.              out_line2 = z"%@"name"='@"val"';"
  2706.           end
  2707.         end
  2708.  
  2709.     /****************************************
  2710.    * Checks for U followed by a constant *
  2711.    * or user defined type                         *
  2712.    ***************************************/
  2713.  
  2714.  
  2715.          when translate(right(val,1)) = "U" then do
  2716.          len = length(val)
  2717.          val = delstr(val,len,1)
  2718.          if datatype(val) = "NUM" then
  2719.           do
  2720.            if T_opt == ON then
  2721.             do
  2722.              out_line1 = z"dcl "name" unsigned fixed bin(31) value("val");"
  2723.              out_line2 = ""
  2724.             end
  2725.           if P_opt == ON then
  2726.           do
  2727.             out_line = z"%dcl "name" fixed ext noscan;"
  2728.             call do_writeout(out_line)
  2729.             out_line = z'%'name'='val';'
  2730.             call do_writeout(out_line)
  2731.             out_line= ""
  2732.           end
  2733.          end
  2734.  
  2735.           else do
  2736.              val = val||U
  2737.              out_line = z"%dcl "name" char ext;"
  2738.              call do_writeout(out_line)
  2739.              out_line = z"%"name"='"val"';"
  2740.              call do_writeout(out_line)
  2741.              out_line1 = z"%dcl @"name" char ext;"
  2742.              out_line2 = z"%@"name"='@"val"';"
  2743.           end
  2744.         end
  2745.  
  2746.    /****************************************
  2747.    * Checks for US followed by a constant *
  2748.    * or user defined type                         *
  2749.    ***************************************/
  2750.  
  2751.  
  2752.        when translate(right(val,2)) = "US" then do
  2753.          len = length(val)
  2754.          val = delstr(val,(len - 1),2)
  2755.          if datatype(val) = "NUM" then
  2756.            do
  2757.              if T_opt == ON then
  2758.              do
  2759.              out_line1 = z"dcl "name" unsigned fixed bin(16) value("val");"
  2760.              out_line2 = ""
  2761.             end
  2762.             if P_opt == ON then
  2763.              do
  2764.              out_line = z"%dcl "name" fixed ext noscan;"
  2765.              call do_writeout(out_line)
  2766.              out_line = z'%'name'='val';'
  2767.              call do_writeout(out_line)
  2768.              out_line= ""
  2769.            end
  2770.           end
  2771.          else do
  2772.              val = val||US
  2773.              out_line = z"%dcl "name" char ext;"
  2774.              call do_writeout(out_line)
  2775.              out_line = z"%"name"='"val"';"
  2776.              call do_writeout(out_line)
  2777.              out_line1 = z"%dcl @"name" char ext;"
  2778.              out_line2 = z"%@"name"='@"val"';"
  2779.          end
  2780.        end
  2781.    /****************************************
  2782.    * Checks for S followed by a constant *
  2783.    * or user defined type                         *
  2784.    ***************************************/
  2785.  
  2786.  
  2787.        when translate(right(val,1)) = "S" then do
  2788.          len = length(val)
  2789.          val = delstr(val,len,1)
  2790.          if datatype(val) = "NUM" then
  2791.           do
  2792.            if T_opt == ON then
  2793.             do
  2794.              out_line1 = z"dcl "name" signed fixed bin(15) value("val");"
  2795.              out_line2 = ""
  2796.             end
  2797.            if P_opt == ON then
  2798.             do
  2799.              out_line = z"%dcl "name" fixed ext noscan;"
  2800.              call do_writeout(out_line)
  2801.              out_line = z'%'name'='val';'
  2802.              call do_writeout(out_line)
  2803.              out_line= ""
  2804.           end
  2805.          end
  2806.          else do
  2807.             val = val||S
  2808.             out_line = z"%dcl "name" char ext;"
  2809.             call do_writeout(out_line)
  2810.             out_line = z"%"name"='"val"';"
  2811.             call do_writeout(out_line)
  2812.             out_line1 = z"%dcl @"name" char ext;"
  2813.             out_line2 = z"%@"name"='@"val"';"
  2814.          end
  2815.        end
  2816.  
  2817.    /****************************************
  2818.    * Checks for addittion or subtraction symbols *
  2819.    ***************************************/
  2820.  
  2821.  
  2822.        when addpos \= 0 | subbpos \= 0 then do
  2823.          out_line1 = z"%dcl "name" char ext;"
  2824.          out_line2 = z"%"name" = '"val"';"
  2825.          addpos = ""
  2826.          subbpos = ""
  2827.        end
  2828.  
  2829.  
  2830.       when wordpos(val,operators) > 0 then do
  2831.          out_line1 = z"/* This utility does not support this kind of operation */"
  2832.          out_line2 = z"/* Error:"first" "name" "val"*/"
  2833.       end
  2834.  
  2835.  
  2836.        when pos('"',val) \= 0 then do
  2837.          if T_opt == ON then
  2838.          do
  2839.           out_line1 = z"dcl "name" char value("val");"
  2840.           out_line2 = ""
  2841.         end
  2842.         if P_opt == ON then
  2843.          do
  2844.           out_line = z"%dcl "name" char ext noscan;"
  2845.           call do_writeout(out_line)
  2846.           out_line = z'%'name'="'val'";'
  2847.           call do_writeout(out_line)
  2848.           out_line = ""
  2849.        end
  2850.       end
  2851.  
  2852.        when pos("'",val) \= 0 then do
  2853.          if T_opt == ON then
  2854.          do
  2855.           out_line1 = z"dcl "name" char value("val");"
  2856.           out_line2 = ""
  2857.         end
  2858.         if P_opt == ON then
  2859.          do
  2860.           out_line = z"%dcl "name" char ext noscan;"
  2861.           call do_writeout(out_line)
  2862.           out_line = z'%'name'="'val'";'
  2863.           call do_writeout(out_line)
  2864.           out_line = ""
  2865.          end
  2866.         end
  2867.  
  2868.        when datatype(val) = "NUM" & val <= max_val then do
  2869.          if T_opt == ON then
  2870.          do
  2871.            out_line1 = z"dcl "name" fixed bin(31) value("val");"
  2872.            out_line2= ""
  2873.          end
  2874.          if P_opt == ON then
  2875.          do
  2876.              out_line = z"%dcl "name" fixed ext noscan;"
  2877.              call do_writeout(out_line)
  2878.              out_line = z'%'name'='val';'
  2879.              call do_writeout(out_line)
  2880.              out_line= ""
  2881.        end
  2882.       end
  2883.        when datatype(val) = "NUM" & val > max_val then do
  2884.          numeric digits 10
  2885.          val = D2X(val)
  2886.          val =  "'"val"'xn"
  2887.          if T_opt == ON then
  2888.           do
  2889.            out_line1 = z"dcl "name" fixed bin(31) value("val");"
  2890.            out_line2= ""
  2891.          end
  2892.         if P_opt == ON then
  2893.         do
  2894.           out_line = z"%dcl "name" char ext noscan;"
  2895.           call do_writeout(out_line)
  2896.           out_line = z'%'name'="'val'";'
  2897.           call do_writeout(out_line)
  2898.           out_line = ""
  2899.        end
  2900.       end
  2901.         when val = "POINTER" | val = "pointer" then do
  2902.           if T_opt == ON then
  2903.           do
  2904.            out_line1 = z"define alias "name" "val";"
  2905.            out_line2 = ""
  2906.          end
  2907.          if P_opt == ON then
  2908.          do
  2909.            out_line = z"%dcl "name" char ext noscan;"
  2910.            call do_writeout(out_line)
  2911.            out_line = z'%'name'="'val'";'
  2912.            call do_writeout(out_line)
  2913.            out_line = ""
  2914.         end
  2915.        end
  2916.  
  2917.        when val \= "" then do
  2918.            val = check_name(val)
  2919.            out_line = z"%dcl "name" char ext;"
  2920.            call do_writeout(out_line)
  2921.  
  2922.            out_line = z"%"name"='"val"';"
  2923.            call do_writeout(out_line)
  2924.            out_line1 = z"%dcl @"name" char ext;"
  2925.            out_line2 = z"%@"name"='@"val"';"
  2926.       end
  2927.  
  2928.       otherwise
  2929.            nop  /* okay to come here */
  2930.  
  2931.       val = done
  2932.     end  /* Select */
  2933.  
  2934.    out_line1 = do_indent(out_line1)
  2935.    call do_writeout(out_line1)
  2936.  
  2937.    if out_line2 \= "" | out_line2 \= OUT_LINE2 then
  2938.      do
  2939.        out_line2 = do_indent(out_line2)
  2940.        call do_writeout(out_line2)
  2941.        out_line2 = ""
  2942.      end
  2943.  
  2944.    val = done
  2945.   return val
  2946.  
  2947. do_value1:
  2948.   parse arg num
  2949.  
  2950.  
  2951.      /*****************************************************
  2952.       * If the value is directly defined then check to see if it is a char,*
  2953.       * string, number, pointer etc and use the appropriate declare       *
  2954.       * statement. If the value is a integer data type and has "UL","L" *
  2955.       * or "US" or "S" then assigns the approriate data type, and returns*
  2956.       * the value to be output.
  2957.       ******************************************************/
  2958.     select
  2959.  
  2960.    /****************************************
  2961.    * Checks for UL followed by a constant *
  2962.    * or user defined type                         *
  2963.    ***************************************/
  2964.  
  2965.        when translate(right(num,2)) = "UL" then do
  2966.          len = length(num)
  2967.          num = strip(num)
  2968.          num = delstr(num,(len - 1),2)
  2969.          if datatype(num) = "NUM" then
  2970.            nop /* will do nothing in some cases */
  2971.           else
  2972.              num = num||UL
  2973.        end
  2974.  
  2975.    /****************************************
  2976.    * Checks for L followed by a constant *
  2977.    * or user defined type                         *
  2978.    ***************************************/
  2979.  
  2980.        when translate(right(num,1)) = "L" then do
  2981.          len = length(num)
  2982.          num = delstr(num,len,1)
  2983.          if datatype(num) = "NUM" then
  2984.           nop   /* will do nothing in some cases */
  2985.           else
  2986.              num = num||L
  2987.         end
  2988.    /****************************************
  2989.    * Checks for U followed by a constant *
  2990.    * or user defined type                         *
  2991.    ***************************************/
  2992.  
  2993.         when translate(right(num,1)) = "U" then do
  2994.          len = length(num)
  2995.          num = delstr(num,len,1)
  2996.          if datatype(num) = "NUM" then
  2997.           nop /* will do nothing in some cases */
  2998.           else
  2999.              num = num||U
  3000.         end
  3001.  
  3002.    /****************************************
  3003.    * Checks for US followed by a constant *
  3004.    * or user defined type                         *
  3005.    ***************************************/
  3006.        when translate(right(num,2)) = "US" then do
  3007.          len = length(num)
  3008.          num = delstr(num,(len - 1),2)
  3009.          if datatype(num) = "NUM" then
  3010.            nop         /* will do nothing in some cases */
  3011.          else
  3012.              num = num||US
  3013.        end
  3014.  
  3015.   /****************************************
  3016.    * Checks for US followed by a constant *
  3017.    * or user defined type                         *
  3018.    ***************************************/
  3019.        when translate(right(num,1)) = "S" then do
  3020.          len = length(num)
  3021.          num = delstr(num,len,1)
  3022.          if datatype(num) = "NUM" then
  3023.           nop
  3024.          else
  3025.             num = num||S
  3026.        end
  3027.  
  3028.   otherwise nop /* okay to come here */
  3029. end /* do */
  3030. return num
  3031.  
  3032.    /************************************************
  3033.    * Checks for a positive, negative or a UL or L subscripted  *
  3034.    * hexadecimal value and do the appropriate conversion and  *
  3035.    * does not output the values, but returns the value to the   *
  3036.    * invoked procedure.
  3037.    *************************************************/
  3038.  
  3039.  
  3040.  
  3041. convert_hexval1:
  3042.  parse arg rest
  3043.  parse var rest num
  3044.  neg = ""
  3045.  val1 = ""
  3046.  
  3047.    select
  3048.      when substr(num,1,1) = "+" then
  3049.         num = delstr(num,1,1)
  3050.  
  3051.      when substr(num,1,1) = "-" then do
  3052.         neg = "-"
  3053.         num = delstr(num,1,1)
  3054.      end
  3055.    otherwise
  3056.        nop   /* okay to come here */
  3057.    end  /* select */
  3058.  
  3059.     if translate(substr(num,1,2)) = "0X"  then
  3060.       do
  3061.          num = substr(num, 3)
  3062.  
  3063.          lpos = translate(right(num,2))
  3064.          if lpos = "UL" then
  3065.            do
  3066.              len = length(num)
  3067.              num = delstr(num,len-1,2)
  3068.              val1 = ' unsigned fixed bin(31) '
  3069.            end
  3070.  
  3071.           l1pos = translate(right(num,1))
  3072.           if l1pos = "L" then
  3073.             do
  3074.               len = length(num)
  3075.               num = delstr(num,len,1)
  3076.               val1 = 'fixed bin(31)'
  3077.             end
  3078.  
  3079.            l1pos = translate(right(num,1))
  3080.            if l1pos = "U" then
  3081.              do
  3082.                len = length(num)
  3083.                num = delstr(num,len,1)
  3084.                val1 = 'unsigned fixed bin(31)'
  3085.              end
  3086.  
  3087.            lpos = translate(right(num,2))
  3088.            if lpos = "US" then
  3089.              do
  3090.                len = length(num)
  3091.                num = delstr(num,len-1,2)
  3092.                val1 = ' unsigned fixed bin(16) '
  3093.              end
  3094.  
  3095.  
  3096.          l1pos = translate(right(num,1))
  3097.          if l1pos = "S" then
  3098.             do
  3099.               len = length(num)
  3100.               num = delstr(num,len,1)
  3101.               val1 = 'fixed bin(15)'
  3102.             end
  3103.  
  3104.         num =  "'"num"'xn"
  3105.         if neg \= "" then
  3106.            num = neg||num
  3107.         neg = ""
  3108.      end
  3109.  
  3110.  
  3111.     if val1 = "" then
  3112.      do
  3113.        lenval = length(num)
  3114.        if neg \= "" then num = neg || num
  3115.     end
  3116.    return num
  3117.  
  3118.  
  3119.  
  3120.    /********************************************************************
  3121.    *   Subroutine to process Typedef statement                         *
  3122.    ********************************************************************/
  3123.  
  3124. do_typedef:
  3125.  
  3126.  parse arg rest
  3127.    datatypes = "long short char int unsigned long unsigned short unsigned char",
  3128.    "signed long signed short signed char unsigned signed unsigned int signed int void"
  3129.  
  3130.    set = "STRUCT ENUM UNION"
  3131.    set1 = "struct enum union"
  3132.  
  3133.    cpos=pos('/*', rest)
  3134.    if cpos\=0 then
  3135.      do
  3136.         comment=substr(rest,cpos)
  3137.         rest=delstr(rest,cpos)
  3138.      end
  3139.    rest = space(rest,1)
  3140.    kind2 = ""
  3141.    kind3 = ""
  3142.  
  3143.    /************************************
  3144.    * If there is a left paren on this line,        *
  3145.    * it is probably a function typedef.  These   *
  3146.    * are not currently converted by this utility  *
  3147.    *************************************/
  3148.  
  3149.  
  3150.    if pos("(", rest) \= 0 then
  3151.    do
  3152.      n_lparen = num_left_paren(rest)
  3153.      /*    parse var rest lstr '(' tmp_line ')' rstr                 */
  3154.  
  3155.      parse var rest lstr '(' tmp_line ')' rstr
  3156.      if (n_lparen <  2 | n_lparen > 2 | pos("*",tmp_line) = 0 ) then
  3157.        do
  3158.          call unsupport_typedef_function rest
  3159.          return
  3160.        end
  3161.      else do
  3162.        out_line = z'/*C>typedef '||rest||' <*/'
  3163.        call do_writeout(out_line)
  3164.  
  3165. /******* make up 'rest', pretending it is a regular function prototype *********/
  3166. /* ex: typedef Return_type (*Function)(parm1, parm2, parm3);                    */
  3167. /* is going to send to call do_variable_or_function with:   */
  3168. /*     <Return_type Function(parm1, parm2, parm3)>          */
  3169.  
  3170.  
  3171.    /* remove '*' in rest(pos1:pos2) */
  3172.    do while (pos('*',tmp_line) \=0)
  3173.      pos_star = pos('*',tmp_line)
  3174.      tmp_line = overlay(' ',tmp_line,pos_star)
  3175.    end /* do while (pos('*',tmp_line) \=0) */
  3176.    rest = lstr || tmp_line || rstr
  3177.  
  3178. /******** get ready to call do_variable_or_function **********/
  3179.   /* preserve the original outputfile */
  3180.   o_outputfile = outputfile
  3181.  
  3182.   /* write convertion of this makeup function to ##tmp */
  3183.   outputfile='##tmp'
  3184.  
  3185.   rc = stream(outputfile,"C","OPEN WRITE")
  3186.  call do_variable_or_function(rest)
  3187.  
  3188. /******** change the converted code from:
  3189.   <dcl Function entry (.....) external;>     to:
  3190.   <define alias Function limited entry(....);>
  3191. **************************************************/
  3192.  
  3193.    rc = stream(outputfile,"C",CLOSE)
  3194.    /* read from ##tmp, write to original outputfile */
  3195.    n_infile = outputfile
  3196.    outputfile = o_outputfile          /* restore original outputfile */
  3197.    rc = stream(n_infile,"C","OPEN READ")
  3198.    tmp_line = linein(n_infile)
  3199.  
  3200.    parse var tmp_line 'dcl' tmp_name 'entry' tmp_line
  3201.    tmp_line = z'define alias '||tmp_name||'limited entry '||tmp_line
  3202.    rc = lineout(outputfile, tmp_line)
  3203.    do while lines(n_infile)
  3204.      tmp_line = linein(n_infile)
  3205.      if (pos('external;', tmp_line) \= 0) then
  3206.       do
  3207.         ext = pos('external;', tmp_line)
  3208.         tmp_line = substr(tmp_line,1, ext-1)||";"
  3209.       end
  3210.  
  3211.      rc = lineout(outputfile, tmp_line)
  3212.    end /* do while lines(n_infile) */
  3213.  
  3214.    rc = stream(n_infile,"C",CLOSE)
  3215.     'del 'n_infile
  3216.     out_line = z"define alias @"name" pointer;"
  3217.     call do_writeout(out_line)
  3218.   end /* else do */
  3219.   return
  3220.  end
  3221.  
  3222.  
  3223.    parse var rest kind rest
  3224.  
  3225.     /****************************************
  3226.    * Typedefs with arrays not supported. *
  3227.    ***************************************/
  3228.  
  3229.     if substr(kind,1,1) = "*" |   pos("[",rest) \= 0 then
  3230.      do
  3231.       out_line = z"%note('Error 9: Unsupported syntax encountered',4);"
  3232.       call do_writeout(out_line)
  3233.       out_line = z"/* typedefs of this format is not converted by this utility. */"
  3234.       call do_writeout(out_line)
  3235.       out_line = z"/* Error: typedef " kind rest"*/"
  3236.       call do_writeout(out_line)
  3237.  
  3238.       if cpos \= 0 then
  3239.         call do_comment(comment)
  3240.  
  3241.       out_line = z"/* The original line in the .h file is: "line_num" */"
  3242.       call do_writeout(out_line)
  3243.       out_line = ""
  3244.       call do_writeout(out_line)
  3245.      return
  3246.    end
  3247.  
  3248.    /****************************************
  3249.    * Checks for near or far attributs and pointer *
  3250.    ***************************************/
  3251.  
  3252.    if translate(kind) \= "STRUCT" & translate(kind) \= "UNION" & ,
  3253.    translate(kind) \= "ENUM" then
  3254.       do
  3255.         linkcon = word(rest,2)
  3256.         if pos("*",kind) \= 0 | pos("*",rest) \= 0 & wordpos(linkcon,linkages) = 0 then
  3257.            do
  3258.              select
  3259.                   when left(rest,4) = "near" | left(rest,3) = "far" then do
  3260.                      parse var rest attribute name val ";"
  3261.                        if right(name,1) = "*" then
  3262.                            name = val
  3263.                         if pos("*",name) \= 0 then
  3264.                           do
  3265.                             do while pos("*",name) \= 0
  3266.                                parse var name "*" name
  3267.                             end
  3268.                          end
  3269.                          name = strip(name)
  3270.                        if substr(name,1,1) = "_" then
  3271.                           name = check_name(name)
  3272.                   end
  3273.  
  3274.    /****************************************
  3275.    * Checks for pointer symbol in rest  *
  3276.    ***************************************/
  3277.  
  3278.                   when pos("*",rest) \= 0 then do
  3279.                      parse var rest "*" name val ";"
  3280.                        if right(name,1) = "*" then
  3281.                           name=val
  3282.                        if pos("*",name) \= 0 then
  3283.                           do
  3284.                              do while pos("*",name) \= 0
  3285.                                  parse var name "*" name
  3286.                              end
  3287.                           end
  3288.                       name = strip(name)
  3289.                       if substr(name,1,1) = "_" then
  3290.                           name = check_name(name)
  3291.                   end
  3292.  
  3293.    /****************************************
  3294.    * Checks for pointer symbol in kind  *
  3295.    ***************************************/
  3296.  
  3297.                   when pos("*",kind) \= 0 then do
  3298.                      parse var rest name val ";"
  3299.                      if right(kind,1) = "*" then
  3300.                       do
  3301.                         do while pos("*",kind) \= 0
  3302.                           parse var kind kind "*"
  3303.                         end
  3304.                       end
  3305.                      name = strip(name)
  3306.                      if substr(name,1,1) = "_"  then
  3307.                          name = check_name(name)
  3308.                   end
  3309.  
  3310.           otherwise nop /* okay to come here */
  3311.     end  /* Do */
  3312.  
  3313.    /****************************************
  3314.    * Convert arrays to PLI syntax  *
  3315.    ***************************************/
  3316.  
  3317.  
  3318.      if pos("][",name) \= 0 then
  3319.       do
  3320.          name= convert_bracket(name)
  3321.          name = convert_finalbracket(name)
  3322.      end
  3323.      name = convert_finalbracket(name)
  3324.  
  3325.    /****************************************
  3326.    * Convert to define alias  if val is a C data type *
  3327.    ***************************************/
  3328.  
  3329.  
  3330.      if wordpos(kind,datatypes) > 0 & pos("*",line) \= 0 then
  3331.       do
  3332.        if pos("*",name) \= 0 then
  3333.        do
  3334.          do while pos("*",name) \= 0
  3335.           parse var name "*" name
  3336.        end
  3337.        end
  3338.        name = check_name(name)
  3339.        out_line1 = z"define alias "name" pointer;"
  3340.        out_line1 = do_indent(out_line1)
  3341.        call do_writeout(out_line1)
  3342.  
  3343.        out_line1 = z"define alias @"name" pointer;"
  3344.        out_line1 = do_indent(out_line1)
  3345.        call do_writeout(out_line1)
  3346.       end
  3347.  
  3348.    /****************************************
  3349.    * Convert to user defined type  *
  3350.    ***************************************/
  3351.  
  3352.  
  3353.       else if wordpos(kind, datatypes) = 0 & pos("*",line) \= 0 then
  3354.         do
  3355.          kind = strip(kind)
  3356.          kind = check_name(kind)
  3357.          out_line1 = z"define alias "name" type @"kind";"
  3358.          out_line1 = do_indent(out_line1)
  3359.          call do_writeout(out_line1)
  3360.  
  3361.          out_line1 = z"define alias @"name" pointer;"
  3362.          out_line1 = do_indent(out_line1)
  3363.          call do_writeout(out_line1)
  3364.       end
  3365.  
  3366.      if cpos \= 0 then
  3367.        call do_comment(comment)
  3368.    return
  3369.  end
  3370. end
  3371.  
  3372.  
  3373.  
  3374.    /**********************************************
  3375.    * If the kind is UNSIGNED, STATIC, or SIGNED, *
  3376.    * then the kind consists of 2 words, so read  *
  3377.    * in another word                             *
  3378.    **********************************************/
  3379.  
  3380.    if kind = "unsigned" | kind = "signed" | kind = "static" then
  3381.       parse var rest kind2 rest
  3382.          if kind2 = "long" | kind2 = "short" then
  3383.            do
  3384.              parse var rest name
  3385.  
  3386.              if substr(name,1,4) = "int " then
  3387.                 parse var name temp name
  3388.            end
  3389.  
  3390.          if kind2 = "int" | kind2 = "char" then do
  3391.              parse var rest name
  3392.          end
  3393.  
  3394.          if kind = "short" | kind = "long" | kind = "int" then
  3395.            do
  3396.               parse var rest name
  3397.  
  3398.                if substr(name,1,4) = "int " then
  3399.                   parse var name temp name
  3400.                else
  3401.                   parse var name name
  3402.            end
  3403.  
  3404.    /*******************************************
  3405.    * All of the structures are converted      *
  3406.    * to unaligned PL/I structures which       *
  3407.    * are the equivalent of _Packed structures *
  3408.    *******************************************/
  3409.  
  3410.    if kind = "_Packed" then
  3411.       parse var rest kind rest
  3412.  
  3413.  
  3414.    /********************************************************************
  3415.    *    kind is not any of the above mentioned types then parse rest into name & other *
  3416.    *********************************************************************/
  3417.  
  3418.        if kind = "unsigned" | kind = "signed" | kind = "static" kind = "_Packed",
  3419.         | kind = "long" | kind = "short" | kind = "int" then
  3420.          nop  /* do not do anything in the above cases */
  3421.        else
  3422.          parse var rest name other
  3423.  
  3424.        if name = "*" then do
  3425.  
  3426.          parse var other name1 other
  3427.  
  3428.               if name1 = "_Seg16" then do
  3429.                 val = false
  3430.                  if val = false then
  3431.                   do
  3432.                     out_line = z"%note('Error 10: Unsupported syntax encountered',4);"
  3433.                     call do_writeout(out_line)
  3434.                     out_line = z"/* This utility does not support this declaration */"
  3435.                     call do_writeout(out_line)
  3436.                     out_line = z"/* Error: typedef "kind" "rest"*/"
  3437.                     call do_writeout(out_line)
  3438.  
  3439.                     if cpos \= 0 then
  3440.                       call do_comment(comment)
  3441.                     out_line = z"/* The original line in the .h file is: "line_num" */"
  3442.                     call do_writeout(out_line)
  3443.                     out_line = ""
  3444.                     call do_writeout(out_line)
  3445.                return
  3446.               end
  3447.          end
  3448.       end
  3449.       else
  3450.  
  3451.    /*****************************************
  3452.    * Far pointers are not supported in PL/I *
  3453.    *****************************************/
  3454.  
  3455.    if name = "FAR" | name = "NEAR" then
  3456.     do
  3457.       parse var other name1
  3458.       if name1 \= "" then
  3459.         name = name1
  3460.     end  /* Do */
  3461.  
  3462.  
  3463.    /***************************
  3464.    * Remove ';' from the line *
  3465.    ***************************/
  3466.  
  3467.    parse var name name ';'
  3468.  
  3469.  
  3470.    /*******************************************
  3471.    * Remove the _ prefix from structure names *
  3472.    *******************************************/
  3473.  
  3474.    if substr(name,1,1) = "_" then
  3475.        name = check_name(name)
  3476.  
  3477.  
  3478.  
  3479.       parse var kind
  3480.    /************************************************
  3481.    * If this is a structure or union typedef, call *
  3482.    * a routine to handle it                        *
  3483.    ************************************************/
  3484.  
  3485.     if translate(kind) = "STRUCT" | translate(kind) = "UNION" | translate(kind),
  3486.      = "ENUM" then
  3487.       do
  3488.         last_struct_name = name
  3489.  
  3490.  
  3491.       /*************************************************
  3492.       * If there is a semicolon on the line, then it   *
  3493.       * names a structure or defines a pointer to a    *
  3494.       * structure, but it does not actually define the *
  3495.       * structure type                                 *
  3496.       *************************************************/
  3497.  
  3498.       if pos(';', line) \= 0 & pos("}",line) = 0 then
  3499.          do
  3500.            parse var other s_name ";" comment
  3501.  
  3502.  
  3503.          /************************************************
  3504.          * Check to see if the typedef defines a pointer *
  3505.          * to a structure                                *
  3506.          ************************************************/
  3507.  
  3508.          if pos('*', s_name) \= 0 | right(name,1) = "*" then
  3509.             call name_a_ptrstructure(name" "s_name)
  3510.  
  3511.  
  3512.  
  3513.          /****************************************************
  3514.          * Otherwise call a routine to simply declare a name *
  3515.          * for a previously defined structure type           *
  3516.          ****************************************************/
  3517.          else do
  3518.           switchflag = kind||"#"
  3519.           call name_a_structure(s_name" "name)
  3520.           switchflag = ""
  3521.          end
  3522.          return
  3523.       end
  3524.     end
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.       /*******************************************************
  3531.       * These lines actually declare the first level of the  *
  3532.       * structure or union                                   *
  3533.       *******************************************************/
  3534.  
  3535.       if translate(kind) = "STRUCT" then
  3536.         do
  3537.           call do_real_struct(name||" "||comment)
  3538.           if cpos \= 0 then
  3539.             call do_comment(c.i.j)
  3540.           c. = ""
  3541.           tflag = "off"
  3542.           return
  3543.         end
  3544.        /*******************************************************
  3545.       * These lines actually declare the first level of the  *
  3546.       * structure or union                                   *
  3547.       *******************************************************/
  3548.  
  3549.  
  3550.       if translate(kind) = "UNION"  then
  3551.         do
  3552.           comment1 = comment
  3553.           call do_union(name)
  3554.  
  3555.           if cpos \= 0 then
  3556.             call do_comment(c.i.j)
  3557.             c. = ""
  3558.  
  3559.           tflag="off"
  3560.           return
  3561.         end
  3562.       /*******************************************************
  3563.       * These lines actually declare the first level of the  *
  3564.       * enum                                   *
  3565.       *******************************************************/
  3566.  
  3567.  
  3568.       if translate(kind) = "ENUM" then
  3569.         do
  3570.           comment1 = comment
  3571.           call do_enum(rest)
  3572.  
  3573.           tflag = "off"
  3574.           if cpos \= 0 then
  3575.             call do_comment(comment1)
  3576.           return
  3577.         end
  3578.  
  3579.      else do
  3580.  
  3581.  
  3582.       /*********************************************************
  3583.       * If this is just a typedef which assigns a new name to  *
  3584.       * an existing type, call the #define routine, as this    *
  3585.       * involves the same conversion as a #define equating the *
  3586.       * two types                                              *
  3587.       *********************************************************/
  3588.  
  3589.          define_string = name" "kind" "kind2
  3590.          call do_define1(define_string)
  3591.       end
  3592.       flag = ""
  3593.  
  3594.       if cpos \= 0 then
  3595.         call do_comment(comment)
  3596.     return
  3597.  
  3598.  
  3599.  
  3600.  /************************************************************/
  3601.  /*  Error message for unsupported typedef function                             */
  3602.  /************************************************************/
  3603.  
  3604.  
  3605. unsupport_typedef_function:
  3606. parse arg rest
  3607.        out_line = z"%note('Error 11: Unsupported syntax encountered',4);"
  3608.        call do_writeout(out_line)
  3609.        out_line = z"/* Function typedefs are not converted by this utility. */"
  3610.  
  3611.        call do_writeout(out_line)
  3612.        out_line = z"/* Error: typedef "rest" */"
  3613.        call do_writeout(out_line)
  3614.  
  3615.        do while pos(")", rest) = 0
  3616.           rest = linein(inputfile)
  3617.           line_num = line_num + 1
  3618.        end
  3619.  
  3620.        if cpos \= 0 then
  3621.           call do_comment(comment)
  3622.        out_line = z"/* The original line in the .h file is: "line_num" */"
  3623.        call do_writeout(out_line)
  3624.        out_line = ""
  3625.        call do_writeout(out_line)
  3626.  
  3627. return
  3628.  
  3629.  
  3630. /*************************************************************************
  3631. num_left_paren: return number of left parenthesis for the given argument
  3632. *************************************************************************/
  3633. num_left_paren: procedure expose null
  3634. parse arg line
  3635.  
  3636. nlp = 0
  3637. t_line = strip(line)
  3638. do while (pos('(',t_line) \= 0)
  3639.   nlp = nlp + 1
  3640.   parse var t_line junk '(' t_line
  3641. end
  3642. return nlp;
  3643.  
  3644.  
  3645.  
  3646.  
  3647.    /****************************/
  3648.    /* do_define1 is called by typedef */
  3649.    /****************************/
  3650.  
  3651.   /********************************************************************
  3652.    *   Subroutine to process #define statement                         *
  3653.    ********************************************************************/
  3654.  
  3655.  do_define1:
  3656.    parse arg rest
  3657.    parse var rest name val
  3658.     datatypes = "long short char int unsigned short long int short int unsigned int",
  3659.      "unsigned char unsigned long signed short signed int signed long signed char"
  3660.  
  3661.  
  3662.  
  3663.    /************************************************
  3664.    * Remove the __ prefix from the definition name *
  3665.    ************************************************/
  3666.      if  substr(name,1,1) = "_"then
  3667.        name = check_name(name)
  3668.  
  3669.  
  3670.  
  3671.     /************************************************
  3672.    * Remove the __ prefix from the definition name *
  3673.    ************************************************/
  3674.    if wordpos(val,datatypes) = 0 then
  3675.    do
  3676.     if translate(name) = val | name = translate(val) then
  3677.      do
  3678.        out_line = z"%note('Error 12: Unsupported syntax encountered',4);"
  3679.        call do_writeout(out_line)
  3680.        out_line = z"/* This kind of definition is not supported by this utility. */ "
  3681.        call do_writeout(out_line)
  3682.        out_line = z"/* Error: typedef "val" "name" */ "
  3683.        call do_writeout(out_line)
  3684.  
  3685.        if cpos \= 0 then
  3686.           call do_comment(comment)
  3687.  
  3688.        out_line = z"/* The original line in the .h file is: "line_num" */"
  3689.        call do_writeout(out_line)
  3690.        out_line = ""
  3691.        call do_writeout(out_line)
  3692.       return
  3693.     end
  3694.   end
  3695.  
  3696.  
  3697.    parse var val val
  3698.    val = strip(val)
  3699.  
  3700.  
  3701.    /********************************
  3702.    * Check for pointer definition  *
  3703.    * by looking for a *            *
  3704.    ********************************/
  3705.  
  3706.    if name = "*" then
  3707.      do
  3708.        parse var val name1 val
  3709.        name = name||name1
  3710.     end  /* Do */
  3711.  
  3712.    if substr(name,1,1) = "*" & substr(name,3,3) \= "_" then
  3713.     do
  3714.       parse var name "*" name
  3715.       oldval = val
  3716.       val = "pointer"
  3717.     end
  3718.  
  3719.    /*******************************************
  3720.    * Check to see if the definition sets a    *
  3721.    * value, or simply declares a variable as  *
  3722.    * defined.  If there is no value, set the  *
  3723.    * variable = 'Y'                           *
  3724.    *******************************************/
  3725.  
  3726.    if val = "" then
  3727.      do
  3728.        out_line1 = z"%dcl "name" char ext;"
  3729.        out_line = z"%"name" = 'Y';"
  3730.      end
  3731.    else do
  3732.  
  3733.  
  3734.       /**********************************************
  3735.       * If there are parentheses in the definition, *
  3736.       * call a routine to handle them               *
  3737.       **********************************************/
  3738.  
  3739.       if pos('(', val) \= 0 | pos('(',name) \= 0 then
  3740.          do
  3741.            val = do_paren(name,val)
  3742.            if val = done then return
  3743.          end
  3744.  
  3745.          /*******************************************
  3746.          * If the paren routine could not           *
  3747.          * convert the line, issue an error message *
  3748.          *******************************************/
  3749.  
  3750.          if val = false then
  3751.           do
  3752.             out_line = z"%note('Error 13: Unsupported syntax encountered',4);"
  3753.             call do_writeout(out_line)
  3754.             out_line = z"/* This utility does not support this declaration */"
  3755.             call do_writeout(out_line)
  3756.             out_line = z"/* Error: "rest"*/"
  3757.             call do_writeout(out_line)
  3758.  
  3759.             if cpos \= 0 then
  3760.               call do_comment(comment)
  3761.  
  3762.             out_line = z"/* The original line in the .h file is: "line_num" */"
  3763.             call do_writeout(out_line)
  3764.             out_line = ""
  3765.             call do_writeout(out_line)
  3766.             return
  3767.          end
  3768.       /********************************
  3769.       * Convert to PL/I array mapping.  *
  3770.       ********************************/
  3771.  
  3772.  
  3773.        if pos("[",name) \= 0 then
  3774.          do
  3775.           if pos("][",name) \= 0 then
  3776.            do
  3777.              name= convert_bracket(name)
  3778.              name = convert_finalbracket(name)
  3779.           end
  3780.           else
  3781.              name = convert_finalbracket(name)
  3782.          end
  3783.  
  3784.  
  3785.  
  3786.       /******************************************
  3787.       * Check to see if the value is a one dim char array  *
  3788.       * then it must be uniquely defined                    *
  3789.       * such as a C type which is                          *
  3790.       * not specifically defined in PL/I                    *
  3791.       *******************************************/
  3792.  
  3793.       val = special_value(val)
  3794.  
  3795.       if  pos("(",name) \= 0 & pos(",",name) = 0 & (val = "char") then
  3796.         do
  3797.             lpos = pos('(',name)
  3798.             bounds = substr(name,lpos)
  3799.             name = substr(name,1,(lpos - 1))
  3800.             val = val||bounds
  3801.         end
  3802.  
  3803.       /*********************************************
  3804.       * If it is simply a definition which defines *
  3805.       * xxx=XXX then ignore it                     *
  3806.       *********************************************/
  3807.  
  3808.       if val = name then return
  3809.  
  3810.  
  3811.       /********************************
  3812.       * Check for a hexadecimal value *
  3813.       ********************************/
  3814.  
  3815.       if substr(val,1,2) = "0X" | substr(val,1,2) = "0x" then
  3816.        do
  3817.          val = substr(val, 3)
  3818.          val = "''"val"''xn"
  3819.          lpos = pos("L", val)
  3820.          if lpos \= 0 then
  3821.            val = delstr(val,lpos,1)
  3822.        end  /* If */
  3823.  
  3824.  
  3825.       /*******************************************
  3826.       * The appropriate declarations for different typedefs  *
  3827.       * depending on whether they were pointer, regular    *
  3828.       * C data type or user defined data type are made.     *
  3829.       ********************************************/
  3830.       if flag = "typedval" then
  3831.         do
  3832.           out_line1 = z"define alias "name" type "val";"
  3833.           out_line2 = z"define alias @"name" type @"val";"
  3834.         end
  3835.  
  3836.       else if val = "POINTER" then
  3837.         do
  3838.           datatypes = "unsigned long unsigned short unsigned char",
  3839.           "unsigned int signed long signed short signed char char int short long"
  3840.  
  3841.               if wordpos(oldval,datatypes) > 0 then
  3842.                 do
  3843.                   out_line1 = z"define alias "name" "val";"
  3844.                   out_line2 = z"define alias @"name" pointer;"
  3845.                 end
  3846.               else do
  3847.                   out_line1 = z"define alias "name" type @"oldval";"
  3848.                   out_line2 = z"define alias @"name" "val";"
  3849.               end
  3850.          end
  3851.  
  3852.       else do
  3853.          out_line1 = z"define alias "name" "val";"
  3854.          out_line2 = z"define alias @"name" pointer;"
  3855.       end  /* Do */
  3856.  
  3857.  
  3858.    /***********************************
  3859.    * Output the definition statements *
  3860.    ***********************************/
  3861.  
  3862.    out_line1 = do_indent(out_line1)
  3863.    call do_writeout(out_line1)
  3864.  
  3865.    out_line2 = do_indent(out_line2)
  3866.    call do_writeout(out_line2)
  3867.  
  3868.    out_line1 = ""
  3869.    out_line2 = ""
  3870.    tflag =""
  3871.  
  3872.    /************************************
  3873.    * If there was a comment at the end *
  3874.    * of the line, convert it           *
  3875.    ************************************/
  3876.  
  3877.  return
  3878.  
  3879.  
  3880.   check_comments:
  3881.  
  3882.    parse arg stline
  3883.  
  3884.    cpos = pos("/*",stline)
  3885.    if cpos \= 0 then
  3886.       stline = 0
  3887.    else
  3888.       stline = 1
  3889.    return stline
  3890.  
  3891.  
  3892.    /********************************************************************
  3893.    *   Subroutine to process Structure declarations                    *
  3894.    ********************************************************************/
  3895.  
  3896. do_struct:
  3897.  
  3898.    go = true
  3899.    out_line = ""
  3900.    var_name = ""
  3901.    old_kind = ""
  3902.    types = "int long char short"
  3903.    list = "struct enum union"
  3904.    c.i.j = ""
  3905.    scanline = " volatile "
  3906.    /********************************************************
  3907.    * I is a counter used as the index into array outline.i                 *
  3908.    * which keeps track of the order in which to output the               *
  3909.    * lines in the structure                                                  *
  3910.    ********************************************************/
  3911.  
  3912.  
  3913.    /************************************************
  3914.    * Read in each line of the structure definition               *
  3915.    * and convert it to PL/I                                      *
  3916.    ************************************************/
  3917.  
  3918.    do while go = true
  3919.       line = linein(inputfile)
  3920.       line_num = line_num + 1
  3921.       line = strip(line)
  3922.       if line = "" then
  3923.        do
  3924.          do while line = ""
  3925.            line = linein(inputfile)
  3926.            line_num = line_num + 1
  3927.            line = strip(line)
  3928.          end
  3929.        end
  3930.  
  3931.    /************************************************
  3932.    * Read in each line of the structure after the } brace and *
  3933.    * concatenate it to a single line.                                    *
  3934.    ************************************************/
  3935.  
  3936.  
  3937.     if substr(line,1,2) \= "/*" & pos("}",line) \= 0 & pos(";",line) = 0 then
  3938.      do
  3939.         line1 = linein(inputfile)
  3940.         line_num = line_num + 1
  3941.         line1 = strip(line1)
  3942.         do while pos(";",line1) = 0
  3943.            line = line||line1
  3944.            line1 = linein(inputfile)
  3945.            line_num = line_num + 1
  3946.            line1=strip(line1)
  3947.         end
  3948.         line = line||line1
  3949.      end
  3950.  
  3951.       /*******************
  3952.       * skip blank lines       *
  3953.       *******************/
  3954.  
  3955.       do while line = ""
  3956.          line = linein(inputfile)
  3957.          line_num = line_num + 1
  3958.       end
  3959.       orig = line
  3960.  
  3961.      /*********************************/
  3962.      /* Issue message for bit fields.          */
  3963.      /*********************************/
  3964.      if pos(":",orig) \= 0 then
  3965.      do
  3966.       cpos = pos("/*",line)
  3967.       if cpos \= 0 then
  3968.         do
  3969.           c.i.j = substr(line,cpos)
  3970.           line = delstr(line,cpos)
  3971.         end
  3972.       end
  3973.  
  3974.       do while pos(":",line) \= 0
  3975.           line = orig
  3976.           array.i.j = ""
  3977.           c.i.j = z"%note('Error 14: Unsupported syntax encountered',4);"
  3978.           j = j + 1
  3979.           c.i.j = z"/* This utility does not support Bit fields. */"
  3980.           array.i.j = ""
  3981.           j = j + 1
  3982.  
  3983.           if pos("*/",line) = 0 then
  3984.             c.i.j = z"/* Error: "line"*/"
  3985.           else
  3986.             c.i.j = z"/* Error: "line
  3987.           array.i.j = ""
  3988.           j = j + 1
  3989.           c.i.j = z"/* The original line in the .h file is: "line_num" */"
  3990.           array.i.j = ""
  3991.           j = j + 1
  3992.           line = linein(inputfile)
  3993.           line_num = line_num + 1
  3994.           line = strip(line)
  3995.           orig = line
  3996.  
  3997.             if line = "" then
  3998.             do
  3999.               array.i.j = ""
  4000.               c.i.j = ""
  4001.               j = j +1
  4002.               line = linein(inputfile)
  4003.               line_num = line_num + 1
  4004.               line = strip(line)
  4005.               orig = line
  4006.            end
  4007.  
  4008.  
  4009.           if substr(line,1,2) = "/*" & pos(":",line) \= 0 then
  4010.             do
  4011.               do while pos("*/",line) = 0
  4012.                 line1 = linein(inputfile)
  4013.                 line_num = line_num + 1
  4014.                 line1 = space(line1,1)
  4015.                 line = line||line1
  4016.                 c.i.j = line
  4017.               end
  4018.  
  4019.             c.i.j = line
  4020.             array.i.j = ""
  4021.             j = j + 1
  4022.             line = linein(inputfile)
  4023.             orig = line
  4024.             line_num = line_num + 1
  4025.             if line = "" then
  4026.              do
  4027.                array.i.j = ""
  4028.                c.i.j = ""
  4029.                j = j +1
  4030.                line = linein(inputfile)
  4031.                line_num = line_num + 1
  4032.             end
  4033.           end /* do */
  4034.         end
  4035.  
  4036.  
  4037.       if pos(":",line) = 0 & pos(":",c.i.j) \= 0 then
  4038.        line = orig
  4039.  
  4040.       line = strip(line)
  4041.       cpos = pos("/*",line)
  4042.  
  4043.     /************************************************
  4044.    * Read in lines and check to see if it is a comment block   *
  4045.    * then read in till next statement to be processed is         *
  4046.    * encountered.                                                            *
  4047.    *************************************************/
  4048.  
  4049.  
  4050.       if cpos \= 0 then
  4051.         do
  4052.           c.i.j = substr(line,cpos)
  4053.           c.i.j = space(c.i.j,1)
  4054.           line = delstr(line,cpos)
  4055.           line = strip(line)
  4056.  
  4057.           if line \= "" & pos("*/",orig) = 0 then
  4058.            do
  4059.               len = pos("*/",line)
  4060.                do while len = 0
  4061.                   line1 = linein(inputfile)
  4062.                   line_num = line_num + 1
  4063.                   c.i.j = c.i.j ||line1
  4064.                   len = pos("*/",c.i.j)
  4065.                end
  4066.                c.i.j = space(c.i.j,1)
  4067.             end
  4068.  
  4069.          if line = "" then
  4070.            do
  4071.              array.i.j = ""
  4072.              len = pos("*/",c.i.j)
  4073.              if len = 0 then
  4074.                inloop = true
  4075.              else
  4076.                inloop = false
  4077.     /****************************************
  4078.     * process until ending comment is encountered  *
  4079.     ****************************************/
  4080.  
  4081.            do while len = 0
  4082.              j = j + 1
  4083.              line1 = linein(inputfile)
  4084.              line_num = line_num + 1
  4085.              len = pos("*/",line1)
  4086.              c.i.j = line1
  4087.              array.i.j =""
  4088.            end
  4089.          end
  4090.  
  4091.        end
  4092.       else if substr(line,1,1) = "*" then
  4093.         do
  4094.           c.i.j = line
  4095.           line = ""
  4096.         end  /* Do */
  4097.  
  4098.       else if substr(line,1,1)  \= "*" & cpos = 0 & right(line,1) \= ";" & line \= "" & left(line,1) \= "#",
  4099.       & pos("{",line) = 0 & translate(left(line,6)) \= "STRUCT" & translate(left(line,5)) \= "UNION" then
  4100.         do
  4101.            c.i.j = line
  4102.            c.i.j = space(c.i.j,1)
  4103.            line = ""
  4104.         end
  4105.        else
  4106.            c.i.j = ""
  4107.  
  4108.     /***************************
  4109.     * volatile changed to abnormal *
  4110.     ***************************/
  4111.  
  4112.  
  4113.       if wordpos(scanline,line) > 0 then
  4114.         do
  4115.           vpos=pos("volatile",line)
  4116.           line = overlay("abnormal",line,vpos)
  4117.         end
  4118.  
  4119.  
  4120.       line = space(line,1)
  4121.       org_line = line
  4122.  
  4123.     /*******************************
  4124.     * checks for far and near attributes. *
  4125.     *******************************/
  4126.  
  4127.  
  4128.       line = check_ptrtype(line)
  4129.       parse var line kind line
  4130.  
  4131.  
  4132.        if right(kind,1) = ";" then
  4133.           line = ";"
  4134.  
  4135.        if left(kind,1) = "}" & left(kind,2) \= "} " & left(kind,2) \= "};" then
  4136.          do
  4137.            kind = kind||line
  4138.            line = ";"
  4139.         end  /* Do */
  4140.  
  4141.        if translate(kind) = "CONST" then
  4142.         parse var line kind line
  4143.  
  4144.       /*****************************************
  4145.       * If kind is unsigned, signed, or static                 *
  4146.       * another word must be read for the kind          *
  4147.       *****************************************/
  4148.  
  4149.       if kind = "unsigned" | kind = "signed" | kind = "static" then
  4150.           parse var line kind2 line
  4151.  
  4152.        if right(kind2,1) = ":" then
  4153.          do
  4154.            len = pos(":",kind2)
  4155.            kind2 = delstr(kind2,len,1)
  4156.            line = ":"||line
  4157.          end
  4158.  
  4159.       if pos("far",line) \= 0 | pos("near",line) \= 0 then
  4160.        do
  4161.          parse var line "*" line
  4162.          line=strip(line)
  4163.          line = "*"||line
  4164.        end  /* Do */
  4165.  
  4166.  
  4167.       parse var line name
  4168.  
  4169.  
  4170.       /****************************************
  4171.       * Remove the ; and white space from the         *
  4172.       * variable name, remove leading underscores.   *
  4173.       ****************************************/
  4174.  
  4175.       parse var name name ";" other
  4176.       name = strip(name)
  4177.         if substr(name,1,1) = "_"  then
  4178.             name = check_name(name)
  4179.  
  4180.  
  4181.       /**********************************
  4182.       * Change [] to () for PL/I arrays           *
  4183.       **********************************/
  4184.      if pos(",",name) = 0 then
  4185.       do
  4186.       if pos("][",name) \= 0 then
  4187.         do
  4188.           name= convert_bracket(name)
  4189.           name = convert_finalbracket(name)
  4190.         end
  4191.           name = convert_finalbracket(name)
  4192.     end
  4193.  
  4194.       kind = strip(kind)
  4195.  
  4196.      if wordpos(kind,list) = 0 & substr(kind,1,1) \= "}"  & pos("*",org_line) \= 0 then
  4197.       do
  4198.  
  4199.       select
  4200.          when kind \= "}" & kind = "/*" | kind = "*" | kind = "*/" then do
  4201.             if substr(name,1,1) = "_"  then
  4202.               name = check_name(name)
  4203.             array.i.j = kind" "name
  4204.             j = j + 1
  4205.          end  /* Do */
  4206.  
  4207.       /**********************************
  4208.       * Check for pointers.                            *
  4209.       **********************************/
  4210.  
  4211.  
  4212.          when kind \= "}" & substr(name,1,1) = "*" then do
  4213.             do while pos("*",name) \= 0
  4214.               parse var name "*" name
  4215.             end
  4216.             len = pos("abnormal",name)
  4217.  
  4218.       /**********************************
  4219.       * Check for abnormal attribute.             *
  4220.       **********************************/
  4221.  
  4222.  
  4223.             if len > 0 then
  4224.              do
  4225.                parse var name "abnormal" name
  4226.                name = name||" abnormal"
  4227.              end
  4228.  
  4229.             name = strip(name)
  4230.             if substr(name,1,1) = "_"  then
  4231.               name = check_name(name)
  4232.             if pos("(",name) \= 0 then
  4233.               name = do_ptrname(name)
  4234.  
  4235.             array.i.j = z"2 "name" pointer"
  4236.             j = j + 1
  4237.          end
  4238.  
  4239.       /**********************************
  4240.       *     Output pointer definition                *
  4241.       **********************************/
  4242.  
  4243.  
  4244.          when kind \= "}" &  right(kind,1) = "*" & left(kind,1) \= "/" then do
  4245.             if substr(name,1,1) = "_"  then
  4246.               name = check_name(name)
  4247.               if pos("(",name) \= 0 then
  4248.                  name = do_ptrname(name)
  4249.  
  4250.             array.i.j = z"2 "name" pointer"
  4251.             j = j + 1
  4252.          end
  4253.  
  4254.       /**********************************
  4255.       *     Output pointer definition                *
  4256.       **********************************/
  4257.  
  4258.  
  4259.           when kind \= "}" &  right(kind2,1) = "*" & left(kind2,1) \= "/" then do
  4260.             if substr(name,1,1) = "_"  then
  4261.               name = check_name(name)
  4262.              if pos("(",name) \= 0 then
  4263.               name = do_ptrname(name)
  4264.             array.i.j = z"2 "name" pointer"
  4265.             j = j + 1
  4266.           end
  4267.  
  4268.       /**********************************
  4269.       *     Output pointer definition                *
  4270.       **********************************/
  4271.  
  4272.  
  4273.           when substr(kind,1,1) \= "}" & wordpos(kind,list) = 0 & pos("*",name) \= 0 then do
  4274.              parse var name "*" name
  4275.              if substr(name,1,1) = "_"  then
  4276.                name = check_name(name)
  4277.               if pos("(",name) \= 0 then
  4278.               name = do_ptrname(name)
  4279.              array.i.j = z"2 "name" pointer"
  4280.              j = j + 1
  4281.            end
  4282.  
  4283.           otherwise
  4284.             nop  /* Error in processing */
  4285.       end /* select */
  4286.     end  /* if then do */
  4287.     else
  4288.       select
  4289.  
  4290.  
  4291.          /***********************************************
  4292.          * Handle the beginning brace for the structure *
  4293.          ***********************************************/
  4294.  
  4295.  
  4296.          when kind = "{" then do
  4297.             nop
  4298.          end
  4299.  
  4300.  
  4301.          /*********************************************
  4302.          * Handle the ending brace for the structures             *
  4303.          *********************************************/
  4304.  
  4305.          when kind =  "};" then do
  4306.             go = false
  4307.          end
  4308.  
  4309.  
  4310.          /***********************************************************************
  4311.          * Handle the ending ; for the structures if the brace and ; occured on different lines   *
  4312.          ***********************************************************************/
  4313.  
  4314.  
  4315.          when kind = ";" then do
  4316.             go = false
  4317.             if old_kind = "}" then old_kind = ""
  4318.          end
  4319.  
  4320.          /*********************************************
  4321.          *  Handle preprocessor #ifdef inside a struct union     *
  4322.          *********************************************/
  4323.  
  4324.         when kind = "#ifdef" then
  4325.           do
  4326.             array.i.j = do_functifdef(kind||" "||name)
  4327.             j = j + 1
  4328.           end
  4329.  
  4330.           /*********************************************
  4331.           *  Handle preprocessor #ifndef inside a struct union     *
  4332.           *********************************************/
  4333.  
  4334.          when kind = "#ifndef" then
  4335.           do
  4336.            array.i.j = do_functifndef(kind||" "||name)
  4337.            j = j + 1
  4338.          end
  4339.  
  4340.           /*********************************************
  4341.           *  Handle preprocessor #else inside a struct union     *
  4342.           *********************************************/
  4343.  
  4344.          when kind = "#else" then
  4345.           do
  4346.             array.i.j = do_felse(kind)
  4347.             j = j + 1
  4348.           end
  4349.  
  4350.            /*********************************************
  4351.            *  Handle preprocessor #endif inside a struct union     *
  4352.            *********************************************/
  4353.  
  4354.           when kind = "#endif" then
  4355.           do
  4356.             array.i.j = "%end;"
  4357.             j = j + 1
  4358.           end
  4359.  
  4360.            /*********************************************
  4361.            *  Handle preprocessor #if inside a struct union         *
  4362.            *********************************************/
  4363.  
  4364.           when kind = "#if" then
  4365.             do
  4366.              array.i.j = do_functif(kind||" "||name)
  4367.              j = j + 1
  4368.            end
  4369.  
  4370.  
  4371.          /***********************************************
  4372.          * Handle a single comment line if it exists.                    *
  4373.          ***********************************************/
  4374.  
  4375.  
  4376.          when kind = "" & c.i.j \= "" then do
  4377.            array.i.j= ""
  4378.            j = j + 1
  4379.          end
  4380.  
  4381.          /***********************************************
  4382.          * Output if kind is already processed.                           *
  4383.          ***********************************************/
  4384.  
  4385.          when kind = "/*" | kind = "*" | kind = "*/" | substr(kind,1,2) = "/*" then do
  4386.             array.i.j = kind" "name
  4387.             j = j + 1
  4388.          end  /* Do */
  4389.  
  4390.  
  4391.          /********************************************************************
  4392.          * Handle the ending brace for the structures and if there is a variable declaration *
  4393.          * list following the ending brace store it in a variable called var_name to process *
  4394.          * the list. If there are nested structures all the levels of the structure variable     *
  4395.          * list except level 1 is processed here. level 1 variable list processing is done in    *
  4396.          * do_struct.                                                                                                 *
  4397.          ********************************************************************/
  4398.  
  4399.         when kind = "}" & pos(";",line) = 0 then
  4400.           old_kind = "}"
  4401.  
  4402.         when old_kind = "}"  then do
  4403.  
  4404.         select
  4405.             when right(kind,1) = ";" then
  4406.               var_name = kind
  4407.  
  4408.              when right(kind,1) = "," then do
  4409.                 kind = kind||line
  4410.                 var_name = kind
  4411.              end  /* Do */
  4412.  
  4413.             otherwise
  4414.              nop
  4415.         end /* select */
  4416.  
  4417.          /**************************************************
  4418.          * If level of structure is first then output information and    *
  4419.          * go back to do_real_struct for processing variables.          *
  4420.          **************************************************/
  4421.  
  4422.           if i = 1 then
  4423.            do
  4424.              go = false
  4425.              old_kind = ""
  4426.            end
  4427.  
  4428.  
  4429.           /**************************************************
  4430.          * If level of structure is nested then process the varible list  *
  4431.          * if one exists else go back to process next input line.          *
  4432.          ***************************************************/
  4433.  
  4434.           else if i > 1 then
  4435.             var_name = kind
  4436.               if var_name \= "" then
  4437.                 parse var array.i.2 num1 ss_name u_name","
  4438.  
  4439.              if var_name \= "" & i > 1 then
  4440.                do
  4441.                  l = i - 1
  4442.                  m = index.l
  4443.  
  4444.                  done = false
  4445.                  do while done=false
  4446.                    if var_name \= "" then do
  4447.      /***********************************************
  4448.      * Processing for multiple variables declared.                 *
  4449.      ***********************************************/
  4450.  
  4451.  
  4452.                    select
  4453.                       when pos(",",var_name) \= 0 then do
  4454.                          parse var var_name var1 "," var_name
  4455.                          var1 = strip(var1)
  4456.                            if pos("][",var1) \= 0 then
  4457.                             do
  4458.                               var1= convert_bracket(var1)
  4459.                               var1 = convert_finalbracket(var1)
  4460.                            end
  4461.                            else if pos("[",var1) \= 0 then
  4462.                            var1 = convert_finalbracket(var1)
  4463.                       end
  4464.  
  4465.      /***********************************************
  4466.      * Processing for single variable declared.                     *
  4467.      ***********************************************/
  4468.  
  4469.  
  4470.                       when pos(",",var_name) = 0 then do
  4471.                          parse var var_name var1 ";"
  4472.                          var1 = strip(var1)
  4473.                           if pos("][",var1) \= 0 then
  4474.                             do
  4475.                               var1= convert_bracket(var1)
  4476.                               var1 = convert_finalbracket(var1)
  4477.                            end
  4478.                            else if pos("[",var1) \= 0 then
  4479.                            var1 = convert_finalbracket(var1)
  4480.  
  4481.                          var_name = ""
  4482.                          done = true
  4483.                       end
  4484.  
  4485.                        otherwise
  4486.                         nop /* okay to come here */
  4487.                    end
  4488.  
  4489.      /***********************************************
  4490.      * Processing for pointer to a struct.                             *
  4491.      ***********************************************/
  4492.  
  4493.                 if substr(var1,1,1) = "*" | substr(var1,1,2) = "**" then
  4494.                  do
  4495.                    var1 = space(var1,0)
  4496.                    do while pos("*",var1) \= 0
  4497.                         parse var var1 "*" var1
  4498.                    end
  4499.  
  4500.                    if substr(var1,1,1) = "_"  then
  4501.                     var1 = check_name(var1)
  4502.                    if substr(ss_name,1,1) = "_" then
  4503.                     ss_name = check_name(ss_name)
  4504.  
  4505.                    array.l.m = z"2 "var1" handle" ss_name
  4506.                    c.l.m = ""
  4507.                    index.l = index.l + 1
  4508.                    m = index.l
  4509.                end
  4510.  
  4511.      /***********************************************
  4512.      * Processing for regular variable of type struct             *
  4513.      ***********************************************/
  4514.  
  4515.                else
  4516.                if substr(var1,1,1) \= "*" then
  4517.                do
  4518.                   if substr(var1,1,1) = "_"  then
  4519.                     var1 = check_name(var1)
  4520.                   if substr(ss_name,1,1) = "_" then
  4521.                     ss_name = check_name(ss_name)
  4522.  
  4523.                   array.l.m = z"2 "var1" type" ss_name
  4524.                   c.l.m = ""
  4525.                   index.l = index.l + 1
  4526.                   m = index.l
  4527.                end
  4528.  
  4529.                else if var1 = "" then
  4530.                    done = true;
  4531.              end
  4532.            end
  4533.           end
  4534.        go = false
  4535.       old_kind = ""
  4536.      end
  4537.  
  4538.      /********************************************************
  4539.      * Processing as above but kind and variable list occur on same line *
  4540.      ********************************************************/
  4541.  
  4542.  
  4543.         when kind = "}" | substr(kind,1,1) = "}" & pos(";",line) \= 0 then do
  4544.            len = length(kind)
  4545.            if len > 1 & pos("}",kind) \= 0 then
  4546.             do
  4547.               parse var kind "}" name1
  4548.               parse var line line";"
  4549.               name = name1" "line
  4550.             end
  4551.  
  4552.      /***********************************************
  4553.      * Processing for multiple variables declared.                 *
  4554.      ***********************************************/
  4555.  
  4556.          if name \= "" then
  4557.            var_name = name||";"
  4558.             parse var array.i.2 num1 ss_name u_name","
  4559.              if var_name \= "" & i > 1 then
  4560.               do
  4561.                 l = i - 1
  4562.                 m = index.l
  4563.                 done = false
  4564.                 do while done=false
  4565.                  if var_name \= "" then
  4566.                    do
  4567.  
  4568.       /***********************************************
  4569.      * Processing for multiple variables declared.                 *
  4570.      ***********************************************/
  4571.  
  4572.                         select
  4573.                            when pos(",",var_name) \= 0 then do
  4574.                               parse var var_name var1 "," var_name
  4575.                               var1 = strip(var1)
  4576.                                if pos("][",var1) \= 0 then
  4577.                                 do
  4578.                                  var1= convert_bracket(var1)
  4579.                                  var1 = convert_finalbracket(var1)
  4580.                                end
  4581.                               else if pos("[",var1) \= 0 then
  4582.                                var1 = convert_finalbracket(var1)
  4583.                            end
  4584.      /***********************************************
  4585.      * Processing for single variables declared.                    *
  4586.      ***********************************************/
  4587.  
  4588.                            when pos(",",var_name) = 0 then do
  4589.                               parse var var_name var1 ";"
  4590.                               var1 = strip(var1)
  4591.                                 if pos("][",var1) \= 0 then
  4592.                             do
  4593.                               var1= convert_bracket(var1)
  4594.                               var1 = convert_finalbracket(var1)
  4595.                            end
  4596.                            else if pos("[",var1) \= 0 then
  4597.                            var1 = convert_finalbracket(var1)
  4598.                               var_name = ""
  4599.                               done = true
  4600.                            end
  4601.                            otherwise
  4602.                                nop  /* okay to come here */
  4603.                           end
  4604.  
  4605.       /***********************************************
  4606.      * Processing for pointer to a struct.                             *
  4607.      ***********************************************/
  4608.  
  4609.                  if substr(var1,1,1) = "*" | substr(var1,1,2) = "**" then
  4610.                     do
  4611.  
  4612.                     var1 = space(var1,0)
  4613.                     do while pos("*",var1) \= 0
  4614.                         parse var var1 "*" var1
  4615.                     end
  4616.                    if substr(var1,1,1) = "_"  then
  4617.                     var1 = check_name(var1)
  4618.                    if substr(ss_name,1,1) = "_" then
  4619.                     ss_name = check_name(ss_name)
  4620.  
  4621.                     array.l.m = z"2 "var1" handle" ss_name
  4622.                     c.l.m = " "
  4623.                     index.l = index.l + 1 /* incr j value of level l */
  4624.                     m = index.l
  4625.                    end
  4626.                 else
  4627.  
  4628.      /***********************************************
  4629.      * Processing for regular variable of type struct             *
  4630.      ***********************************************/
  4631.  
  4632.                 if substr(var1,1,1) \= "*" then
  4633.                   do
  4634.                     if substr(var1,1,1) = "_"  then
  4635.                     var1 = check_name(var1)
  4636.                    if substr(ss_name,1,1) = "_" then
  4637.                     ss_name = check_name(ss_name)
  4638.                     array.l.m = z"2 "var1" type" ss_name
  4639.                     c.l.m =" "
  4640.                     index.l = index.l + 1 /* incr j value of level l */
  4641.                     m = index.l
  4642.                   end
  4643.  
  4644.                 else if var1 = "" then
  4645.                    done = true;
  4646.                end
  4647.           end  /* Do */
  4648.         end
  4649.        go = false
  4650.      end
  4651.  
  4652.          /******************************************************
  4653.          * Handle INT or LONG definitions within the structure *
  4654.          ******************************************************/
  4655.  
  4656.          when kind = "int" & pos(":",name) = 0 then do
  4657.             if pos("(",name) \= 0 then
  4658.               name = do_ptrname(name)
  4659.             array.i.j = z"2 "name" fixed bin(31)"
  4660.             j = j + 1
  4661.          end
  4662.  
  4663.          /******************************************
  4664.          * Handle  int array definitions within the structure *
  4665.          ******************************************/
  4666.  
  4667.          when kind = "int"  & pos(":",name) \= 0 & pos("(",name) \= 0 then do
  4668.             if pos("(",name) \= 0 then
  4669.               name = do_ptrname(name)
  4670.             array.i.j = z"2 "name" fixed bin(31)"
  4671.             j = j + 1
  4672.          end
  4673.  
  4674.          /******************************************
  4675.          * Handle  int array definitions within the structure *
  4676.          ******************************************/
  4677.  
  4678.          when kind = "long" & pos(":",name) = 0 then do
  4679.              if pos("(",name) \= 0 then
  4680.               name = do_ptrname(name)
  4681.             array.i.j = z"2 "name" fixed bin(31)"
  4682.             j = j + 1
  4683.          end
  4684.          /******************************************
  4685.          * Handle  int array definitions within the structure *
  4686.          ******************************************/
  4687.  
  4688.           when kind = "long" & pos(":",name) \= 0 & pos("(",name) \= 0 then do
  4689.              if pos("(",name) \= 0 then
  4690.               name = do_ptrname(name)
  4691.             array.i.j = z"2 "name" fixed bin(31)"
  4692.             j = j + 1
  4693.          end
  4694.          /******************************************
  4695.          * Handle  int bit  definitions within the structure   *
  4696.          ******************************************/
  4697.  
  4698.          when kind = "int" & pos(":",name) \= 0 & pos("(",name) = 0 then do
  4699.            parse var name name ":" bit_length ";"
  4700.            name = strip(name)
  4701.            bit_length = strip(bit_length)
  4702.            array.i.j = z"2 "name" bit("bit_length")"
  4703.            j = j + 1
  4704.          end  /* Do */
  4705.          /******************************************
  4706.          * Handle  char bit definitions within the structure *
  4707.          ******************************************/
  4708.  
  4709.          when kind = "char" & pos(":",name) \= 0 & pos("(",name) = 0 then do
  4710.            parse var name name ":" bit_length ";"
  4711.            bit_length = strip(bit_length)
  4712.            array.i.j = z"2 "name" bit("bit_length")"
  4713.            j = j + 1
  4714.          end  /* Do */
  4715.  
  4716.          /********************************************************
  4717.          * Handle CHAR variables or array definitions within the structure.    *
  4718.          ********************************************************/
  4719.  
  4720.          when kind = "char"  then do
  4721.             if pos("(",name) = 0 | pos(",",name) \= 0 then
  4722.               do
  4723.                  if pos("(",name) = 0 then
  4724.                  do
  4725.                   array.i.j = z"2 "name" char"
  4726.                   j = j + 1
  4727.                 end
  4728.                 else if pos(",",name) \= 0 then
  4729.                   do
  4730.                      parse var name name "(" nam1
  4731.                      name = name||" dim("||nam1
  4732.                       array.i.j = z"2 "name" char"
  4733.                   j = j + 1
  4734.                 end
  4735.             end
  4736.  
  4737.       /**********************************************************
  4738.       * Special processing for one dimensional character array.                 *
  4739.       **********************************************************/
  4740.  
  4741.             else do
  4742.              if  pos("(",name) \= 0 & pos(",",name) = 0 then
  4743.                do
  4744.                   lpos = pos('(',name)
  4745.                   bounds = substr(name,lpos)
  4746.                   name = substr(name,1,(lpos - 1))
  4747.                   bounds = check_char(bounds)
  4748.                   array.i.j = z"2 "name" char"bounds" varyingz"
  4749.                   j = j + 1
  4750.                end
  4751.             end
  4752.          end
  4753.  
  4754.          /********************************************************
  4755.          * Handle PSZ variable definitions within the structure.                *
  4756.          ********************************************************/
  4757.  
  4758.          when kind = "PSZ" then do
  4759.             if pos("(",name) \= 0 then
  4760.               name = do_ptrname(name)
  4761.             array.i.j = z"2 "name" type PSZ"
  4762.             j = j + 1
  4763.          end
  4764.  
  4765.          /*****************************************
  4766.          * Handle  SHORT definitions within the structure *
  4767.          *****************************************/
  4768.  
  4769.          when kind = "short" then do
  4770.             if pos("(",name) \= 0 then
  4771.               name = do_ptrname(name)
  4772.             array.i.j = z"2 "name" fixed bin(15)"
  4773.             j = j + 1
  4774.          end
  4775.  
  4776.          /*********************************************************************
  4777.          * Handle a STRUCT definition as a field (no pointer)in the structure declarations.   *
  4778.          *********************************************************************/
  4779.  
  4780.  
  4781.          when translate(kind) = "STRUCT" & pos(" ",name) \= 0 & pos("*",name) =,
  4782.          0 then do
  4783.             parse var name name strt_name
  4784.             strt_name=space(strt_name,0)
  4785.  
  4786.             if substr(strt_name,1,1) = "_"  then
  4787.                strt_name = check_name(strt_name)
  4788.             if substr(name,1,1) = "_" then
  4789.              name = check_name(name)
  4790.             if pos("(",strt_name) \= 0 then
  4791.               strt_name = do_ptrname(strt_name)
  4792.  
  4793.             array.i.j = z"2 "strt_name" type "name
  4794.             j = j + 1
  4795.          end
  4796.          /**********************************************************
  4797.          * Handle a STRUCT definition as a field in the structure declarations.   *
  4798.          **********************************************************/
  4799.  
  4800.  
  4801.           when translate(kind) = "STRUCT" &  pos("*",name) \= 0 then do
  4802.             parse var name name strt_name
  4803.             if strt_name = "" then
  4804.              parse var name name "*" strt_name
  4805.  
  4806.             strt_name=space(strt_name,0)
  4807.  
  4808.                if pos("*",name) \= 0 then
  4809.                 do
  4810.                     do while pos("*",name) \= 0
  4811.                        parse var name name "*"
  4812.                     end
  4813.                 end
  4814.  
  4815.          /**********************************************************
  4816.          * Handle abnormal attribute and remove pointer symbol                   *
  4817.          **********************************************************/
  4818.  
  4819.               do while pos("*",strt_name) \= 0
  4820.                     parse var strt_name "*" strt_name
  4821.               end
  4822.  
  4823.             if pos("abnormal",strt_name) \= 0 then
  4824.              do
  4825.                 parse var strt_name "abnormal" strt_name
  4826.                 strt_name = strt_name||" abnormal"
  4827.              end
  4828.  
  4829.             if substr(strt_name,1,1) = "_"  then
  4830.                strt_name = check_name(strt_name)
  4831.             if pos("(",strt_name) \= 0 then
  4832.               strt_name = do_ptrname(strt_name)
  4833.  
  4834.             array.i.j = z"2 "strt_name" handle "name
  4835.             j = j + 1
  4836.          end
  4837.  
  4838.          /**********************************************************
  4839.          * Handle a UNION definition as a field in the structure declarations.     *
  4840.          **********************************************************/
  4841.  
  4842.          when translate(kind) = "UNION" & pos(" ",name) \= 0 & pos("*",name) = 0 then do
  4843.             parse var name name strt_name
  4844.  
  4845.             if substr(strt_name,1,1) = "_" then
  4846.                strt_name = check_name(strt_name)
  4847.             if substr(name,1,1) = "_" then
  4848.              name = check_name(name)
  4849.  
  4850.             if pos("(",strt_name) \= 0 then
  4851.               strt_name = do_ptrname(strt_name)
  4852.  
  4853.             array.i.j = z"2 "strt_name" type "name
  4854.             j = j + 1
  4855.          end
  4856.  
  4857.       /********************************************************************
  4858.       * Handle a UNION definition as a field in the structure declarations.(with pointers)  *
  4859.       ********************************************************************/
  4860.  
  4861.  
  4862.         when translate(kind) = "UNION" &  pos("*",name) \= 0 then do
  4863.             parse var name name strt_name
  4864.  
  4865.             if strt_name = "" then
  4866.              parse var name name "*" strt_name
  4867.  
  4868.             strt_name=space(strt_name,0)
  4869.  
  4870.       /**********************************************
  4871.       * Handle  pointer on either syntax. name or strt_name *
  4872.       **********************************************/
  4873.  
  4874.             if pos("*",name) \= 0 then do
  4875.                 do while pos("*",name) \= 0
  4876.                     parse var name name "*"
  4877.                 end
  4878.             end
  4879.  
  4880.             do while pos("*",strt_name) \= 0
  4881.                     parse var strt_name "*" strt_name
  4882.             end
  4883.       /******************************************
  4884.       * Remove leading underscores from name.           *
  4885.       ******************************************/
  4886.  
  4887.  
  4888.             if substr(strt_name,1,1) = "_"  then
  4889.                strt_name = check_name(strt_name)
  4890.             if substr(name,1,1) = "_" then
  4891.              name = check_name(name)
  4892.  
  4893.             if pos("(",strt_name) \= 0 then
  4894.               strt_name = do_ptrname(strt_name)
  4895.  
  4896.             array.i.j = z"2 "strt_name" handle "name
  4897.             j = j + 1
  4898.          end
  4899.  
  4900.     /**********************************************************************
  4901.     * Handle a ENUM definition as a field in the structure declarations.(with pointers)     *
  4902.     **********************************************************************/
  4903.  
  4904.         when translate(kind) = "ENUM" &  pos("*",name) \= 0 then do
  4905.             parse var name name strt_name
  4906.  
  4907.             if strt_name = "" then
  4908.                parse var name name "*" strt_name
  4909.             if struct_name = "" then
  4910.                parse var name name "*" strt_name
  4911.  
  4912.             strt_name=space(strt_name,0)
  4913.               if pos("*",name) \= 0 then
  4914.                do
  4915.                     do while pos("*",name) \= 0
  4916.                        parse var name name "*"
  4917.                     end
  4918.                end
  4919.  
  4920.             do while pos("*",strt_name) \= 0
  4921.                     parse var strt_name "*" strt_name
  4922.             end
  4923.  
  4924.             if substr(strt_name,1,1) = "_" then
  4925.                strt_name = check_name(strt_name)
  4926.             if substr(name,1,1) = "_" then
  4927.              name = check_name(name)
  4928.  
  4929.             if pos("(",strt_name) \= 0 then
  4930.               strt_name = do_ptrname(strt_name)
  4931.  
  4932.             array.i.j = z"2 "strt_name" handle "name
  4933.             j = j + 1
  4934.          end
  4935.  
  4936.  
  4937.       /**********************************************************
  4938.       * Handle a UNION definition as a field in the structure declarations.     *
  4939.       **********************************************************/
  4940.  
  4941.          when translate(kind) = "ENUM" & pos(" ",name) \= 0 & pos("*",name) =,
  4942.          0 & pos("{",name) = 0 then do
  4943.             parse var name name strt_name
  4944.  
  4945.             strt_name=space(strt_name,0)
  4946.             if substr(strt_name,1,1) = "_" then
  4947.               strt_name = check_name(strt_name)
  4948.             if substr(name,1,1) = "_" then
  4949.              name = check_name(name)
  4950.  
  4951.             if pos("(",strt_name) \= 0 then
  4952.               strt_name = do_ptrname(strt_name)
  4953.  
  4954.             array.i.j = z"2 "strt_name" ordinal "name
  4955.             j = j + 1
  4956.          end
  4957.  
  4958.       /***********************************************************
  4959.       * Issue error message for enum definition nested inside struct or union.*
  4960.       ***********************************************************/
  4961.  
  4962.          when translate(kind) = "ENUM" & pos("{",name) \= 0 then do
  4963.  
  4964.           select
  4965.              when pos("}",org_line) \= 0 & pos(";",org_line) \= 0 then do
  4966.               c.i.j = "/* "kind" "name" : not supported by this utility */"||c.i.j
  4967.               array.i.j = ""
  4968.                j = j + 1
  4969.              end  /* Do */
  4970.  
  4971.             when pos("{",org_line) \= 0 & pos(";",org_line) = 0 then do
  4972.               c.i.j = "/* "kind" "name" :not supported by this utility */"||c.i.j
  4973.               array.i.j = ""
  4974.                j = j + 1
  4975.  
  4976.      /************************************************************
  4977.       * Read until entire definition is complete and put it in a comment block.*
  4978.       ************************************************************/
  4979.  
  4980.               do while pos(";",line) = 0
  4981.                  line = linein(inputfile)
  4982.                  line_num = line_num + 1
  4983.                  line=strip(line)
  4984.  
  4985.                  cpos = pos("/*",line)
  4986.                    if cpos \= 0 then
  4987.                     do
  4988.                       c.i.j = substr(line,cpos)
  4989.                       line = delstr(line,cpos)
  4990.                     end
  4991.                    else c.i.j = ""
  4992.  
  4993.                   if line \= "" then
  4994.                     c.i.j = "/* "line" not supported by this utility */"||c.i.j
  4995.                   else
  4996.                     c.i.j = c.i.j
  4997.  
  4998.                   array.i.j= ""
  4999.                   j = j + 1
  5000.               end
  5001.            end
  5002.           otherwise nop /* okay to come here */
  5003.         end
  5004.        end  /* Do */
  5005.       /**********************************************
  5006.       * If kind is unsigned, kind2 is tested for the appropriate *
  5007.       * declaration.                                               *
  5008.       ***********************************************/
  5009.  
  5010.          when kind = "unsigned" then do
  5011.             select
  5012.  
  5013.                when wordpos(kind2,types) = 0 & pos(":",org_line) = 0 then do
  5014.                  parse var kind2 kind2 ";"
  5015.                  name = kind2
  5016.  
  5017.                  if substr(name,1,1) = "_" then
  5018.                   name = check_name(name)
  5019.                   if pos("(",name) \= 0 then
  5020.                     name = do_ptrname(name)
  5021.  
  5022.                  array.i.j = z"2 "name" unsigned fixed bin(31) "
  5023.                  j = j + 1
  5024.                end  /* Do */
  5025.  
  5026.                /*****************************************************
  5027.                * Handle LONG or INT definitions labeled as unsigned *
  5028.                *****************************************************/
  5029.  
  5030.                when kind2 = "long" & pos(":",name) = 0 then do
  5031.                    if pos("(",name) \= 0 then
  5032.                       name = do_ptrname(name)
  5033.                    array.i.j = z"2 "name" unsigned fixed bin(31) "
  5034.                    j = j + 1
  5035.                end
  5036.  
  5037.                  when kind2 = "long"  & pos(":",name) \= 0 & pos("(",name) \= 0 then do
  5038.                  if pos("(",name) \= 0 then
  5039.                    name = do_ptrname(name)
  5040.                    array.i.j = z"2 "name" unsigned fixed bin(31)"
  5041.                    j = j + 1
  5042.                end
  5043.  
  5044.                   when kind2 = "int" & pos(":",name) = 0 then do
  5045.                    if pos("(",name) \= 0 then
  5046.                       name = do_ptrname(name)
  5047.  
  5048.                    array.i.j = z"2 "name" unsigned fixed bin(31) "
  5049.                    j = j + 1
  5050.                end
  5051.  
  5052.  
  5053.                when kind2 = "int"  & pos(":",name) \= 0 & pos("(",name) \= 0 then do
  5054.                  if pos("(",name) \= 0 then
  5055.                    name = do_ptrname(name)
  5056.  
  5057.                  array.i.j = z"2 "name" unsigned fixed bin(31)"
  5058.                  j = j + 1
  5059.                end
  5060.  
  5061.                /***********************************************
  5062.                * Handle SHORT definitions labeled as unsigned *
  5063.                ***********************************************/
  5064.  
  5065.                when kind2 = "short" & pos(":",name) = 0 then do
  5066.                   if pos("(",name) \= 0 then
  5067.                       name = do_ptrname(name)
  5068.  
  5069.                   array.i.j = z"2 "name" unsigned fixed bin(16) "
  5070.                   j = j + 1
  5071.                end
  5072.  
  5073.  
  5074.                  when kind2 = "short"  & pos(":",name) \= 0 & pos("(",name) \= 0 then do
  5075.                  if pos("(",name) \= 0 then
  5076.                    name = do_ptrname(name)
  5077.  
  5078.                    array.i.j = z"2 "name" unsigned fixed bin(31)"
  5079.                    j = j + 1
  5080.                end
  5081.  
  5082.  
  5083.                /**********************************************
  5084.                * Handle CHAR definitions labeled as unsigned *
  5085.                **********************************************/
  5086.           when kind2 = "char"  then do
  5087.             if pos("(",name) = 0 | pos(",",name) \= 0 then
  5088.               do
  5089.                  if pos("(",name) = 0 then
  5090.                  do
  5091.                     array.i.j = z"2 "name" char"
  5092.                     j = j + 1
  5093.                 end
  5094.  
  5095.                 else if pos(",",name) \= 0 then
  5096.                   do
  5097.                      parse var name name "(" nam1
  5098.                      name = name||" dim("||nam1
  5099.                      array.i.j = z"2 "name" char"
  5100.                      j = j + 1
  5101.                   end
  5102.             end
  5103.  
  5104.             else do
  5105.              if  pos("(",name) \= 0 & pos(",",name) = 0 then
  5106.                do
  5107.                   lpos = pos('(',name)
  5108.                   bounds = substr(name,lpos)
  5109.                   name = substr(name,1,(lpos - 1))
  5110.                   bounds = check_char(bounds)
  5111.                   array.i.j = z"2 "name" char"bounds" varyingz"
  5112.                   j = j + 1
  5113.                end
  5114.             end
  5115.          end
  5116.  
  5117.       /***********************************
  5118.       * Handle a unsigned char bit definition     *
  5119.       ***********************************/
  5120.  
  5121.  
  5122.                 when kind2 = "char" | kind2 = "int" & pos("(",name) = 0 & pos(":",name) \= 0 then do
  5123.                   parse var name name ":" bit_length ";"
  5124.                   parse var line ":" bit_length ";"
  5125.  
  5126.                   name = strip(name)
  5127.                   bit_length = strip(bit_length)
  5128.  
  5129.                   array.i.j = z"2 "name" bit("bit_length")"
  5130.                   j = j + 1
  5131.                 end  /* Do */
  5132.  
  5133.                when pos(":",kind2) \= 0 & kind2 \= ":" & substr(kind2,1,1) \= ":" then do
  5134.                   parse var kind2 name ":" bit_length ";"
  5135.  
  5136.                   name = strip(name)
  5137.                   bit_length = strip(bit_length)
  5138.  
  5139.                   array.i.j = z"2 "name" bit("bit_length")"
  5140.                   j = j + 1
  5141.                end  /* Do */
  5142.                /*********************
  5143.                * Handle a bit field *
  5144.                *********************/
  5145.  
  5146.                otherwise do
  5147.                 if kind2 = ":" | substr(kind2,1,1) = ":" then
  5148.                   do
  5149.                     line = kind2" "name
  5150.                     kind2 = ""
  5151.                   end
  5152.                   parse var line ":" bit_length ";"
  5153.                   bit_length = strip(bit_length)
  5154.                   array.i.j = z"2 "kind2" bit("bit_length")"
  5155.                   j = j + 1
  5156.                end
  5157.             end
  5158.          end
  5159.  
  5160.       /**********************************************
  5161.       * If kind is signed, kind2 is tested for the appropriate   *
  5162.       * declaration.                                               *
  5163.       ***********************************************/
  5164.  
  5165.         when kind = "signed" then do
  5166.             select
  5167.  
  5168.  
  5169.                /*****************************************************
  5170.                * Handle LONG or INT definitions labeled as signed                *
  5171.                *****************************************************/
  5172.  
  5173.                when wordpos(kind2,types) = 0 & pos(":",org_line) = 0 then do
  5174.                  parse var kind2 kind2 ";"
  5175.                  name = kind2
  5176.  
  5177.                  if substr(name,1,1) = "_" then
  5178.                     name = check_name(name)
  5179.                  if pos("(",name) \= 0 then
  5180.                     name = do_ptrname(name)
  5181.  
  5182.                  array.i.j = z"2 "name" signed fixed bin(31) "
  5183.                  j = j + 1
  5184.                end  /* Do */
  5185.  
  5186.                when kind2 = "long" | kind2 = "int" & pos(":",name) = 0 then do
  5187.                    if pos("(",name) \= 0 then
  5188.                       name = do_ptrname(name)
  5189.                    array.i.j = z"2 "name" signed fixed bin(31) "
  5190.                    j = j + 1
  5191.                end
  5192.  
  5193.                 when kind2 = "long"  | kind2 = "int" & pos(":",name) \= 0 & pos("(",name) \= 0 then do
  5194.                  if pos("(",name) \= 0 then
  5195.                    name = do_ptrname(name)
  5196.                    array.i.j = z"2 "name" signed fixed bin(31)"
  5197.                    j = j + 1
  5198.                end
  5199.  
  5200.                 when kind2 = "short"  & pos(":",name) \= 0 & pos("(",name) \= 0 then do
  5201.                  if pos("(",name) \= 0 then
  5202.                    name = do_ptrname(name)
  5203.                    array.i.j = z"2 "name" signed fixed bin(15)"
  5204.                    j = j + 1
  5205.                end
  5206.  
  5207.                /***********************************************
  5208.                * Handle SHORT definitions labeled as signed              *
  5209.                ***********************************************/
  5210.  
  5211.                when kind2 = "short" & pos(":",name) = 0 then do
  5212.                  if pos("(",name) \= 0 then
  5213.                       name = do_ptrname(name)
  5214.                  array.i.j = z"2 "name" signed fixed bin(15) "
  5215.                   j = j + 1
  5216.                end
  5217.  
  5218.                /**********************************************
  5219.                * Handle CHAR definitions labeled as signed              *
  5220.                **********************************************/
  5221.  
  5222.                when kind2 = "char" & pos(":",name) = 0 then do
  5223.                   if pos("(",name) \= 0 then
  5224.                       name = do_ptrname(name)
  5225.                   array.i.j = z"2 "name" signed fixed bin(7) "
  5226.                   j = j + 1
  5227.                 end
  5228.  
  5229.                 when kind2 = "char"  & pos(":",name) \= 0 & pos("(",name) \= 0 then do
  5230.                  if pos("(",name) \= 0 then
  5231.                    name = do_ptrname(name)
  5232.                    array.i.j = z"2 "name" signed fixed bin(7)"
  5233.                    j = j + 1
  5234.                end
  5235.  
  5236.                 when kind2 = "char" | kind2 = "int" & pos(":",name) \= 0 & pos("(",name) = 0 then do
  5237.                   parse var name name ":" bit_length ";"
  5238.                   parse var line ":" bit_length ";"
  5239.                   name = strip(name)
  5240.  
  5241.                   bit_length = strip(bit_length)
  5242.                   array.i.j = z"2 "name" bit("bit_length")"
  5243.                   j = j + 1
  5244.                 end  /* Do */
  5245.  
  5246.                when pos(":",kind2) \= 0 & kind2 \= ":" & substr(kind2,1,1) \= ":" then do
  5247.                   parse var kind2 name ":" bit_length ";"
  5248.                   name = strip(name)
  5249.                   bit_length = strip(bit_length)
  5250.  
  5251.                   array.i.j = z"2 "name" bit("bit_length")"
  5252.                   j = j + 1
  5253.                end  /* Do */
  5254.                /*********************
  5255.                * Handle a bit field *
  5256.                *********************/
  5257.  
  5258.                otherwise do
  5259.                 if kind2 = ":" | substr(kind2,1,1) = ":" then
  5260.                   do
  5261.                      line = kind2" "name
  5262.                      kind2 = ""
  5263.                   end
  5264.                   parse var line ":" bit_length ";"
  5265.                   bit_length = strip(bit_length)
  5266.                   array.i.j = z"2 "kind2" bit("bit_length")"
  5267.                   j = j + 1
  5268.                end
  5269.             end
  5270.          end
  5271.  
  5272.  
  5273.          /***************************************************************
  5274.          * If there are nested structures or unions within a structure then the routine   *
  5275.          * do_struct or do_union is called to process the declaration. The values to be  *
  5276.          * output are stored in a two dimensional array. The variable 'i' refers to the   *
  5277.          * ith level of the structure and the variable j refers to the jth declarations in   *
  5278.          * the ith level of the structure.                                                    *
  5279.          ****************************************************************/
  5280.  
  5281.          when translate(kind) = "STRUCT" | translate(kind) = "UNION" then do
  5282.               index.i = j            /* save old j values in index.i */
  5283.                                      /* val of index.i where old j values are stored: index.i */
  5284.               i = i + 1             /* i is 2 */
  5285.               j = 1                 /* reset j to 1 to start from begining */
  5286.               recursive = true
  5287.               rest = name
  5288.  
  5289.          /**********************************************************
  5290.          * Give nested struct without tag the name of the outer level || with #*
  5291.          **********************************************************/
  5292.  
  5293.                 if translate(kind) = "STRUCT" then
  5294.                  do
  5295.                    rest = strip(rest)
  5296.                    if rest = "" | rest = "{" then
  5297.                     do
  5298.                       rest1 = s_name||"#"
  5299.                       rest = rest1
  5300.                       count = 1
  5301.                    end
  5302.  
  5303.                    else if right(rest1,1) = "#" then
  5304.                    do
  5305.                       rest1 = rest1||"#"
  5306.                       rest = rest1
  5307.                    end
  5308.          /****************************************
  5309.          * Call do_real_struct to process initial definition.*
  5310.          ****************************************/
  5311.  
  5312.                    call do_real_struct(rest)
  5313.                    i = i - 1        /*  to get ist level */
  5314.                                      /* inside after call to do-realstruct i decre is: i */
  5315.                    j = index.i       /* get old val of j stored in level 1 */
  5316.                                      /* old level j valus of earlier level is retrived: j */
  5317.                  end
  5318.        /**********************************************************
  5319.        * Give nested union without tag the name of the outer level || with #*
  5320.        **********************************************************/
  5321.  
  5322.                  else do
  5323.                    rest = strip(rest)
  5324.                    if rest = "" | rest = "{"then
  5325.                     do
  5326.                       rest1 = s_name||"#"
  5327.                       rest = rest1
  5328.                       count = 1
  5329.                    end
  5330.  
  5331.                    else if right(rest1,1) = "#" then
  5332.                      do
  5333.                        rest1 = rest1||"#"
  5334.                        rest = rest1
  5335.                      end
  5336.        /************************************
  5337.        * Call do_union to process initial definition.*
  5338.        ************************************/
  5339.  
  5340.  
  5341.                    call do_union(rest)
  5342.                      i = i - 1        /*  to get ist level */
  5343.                      j = index.i       /* get old val of j stored in level 1 */
  5344.                  end
  5345.           go = true
  5346.          end /* when */
  5347.         otherwise
  5348.           /*****************************************************
  5349.           * Handle user defined types.                                         *
  5350.           *****************************************************/
  5351.  
  5352.          if  line \= "" & pos(":",org_line) = 0 & kind \= "unsigned" & kind \= "signed" & kind \="static",
  5353.          & kind \= "{" & kind \= "}" & kind \= "int" & kind \= "long",
  5354.          & kind \= "char" &  kind \= "PSZ" ,
  5355.          & kind \= "short" ,
  5356.          & kind \= "struct" & kind \= "union" & kind \= "enum" then
  5357.            do
  5358.              if pos("(",name) \= 0 then
  5359.                  name = do_ptrname(name)
  5360.              array.i.j = z"2 "name" type "kind
  5361.              j = j + 1
  5362.            end
  5363.  
  5364.       /****************************************
  5365.       * Process userdefined bit fields.                      *
  5366.       ****************************************/
  5367.  
  5368.          else do
  5369.             parse var org_line type name":" bit_length ";"
  5370.             bit_length = strip(bit_length)
  5371.             name = strip(name)
  5372.             bit_length=strip(bit_length)
  5373.  
  5374.             array.i.j = z"2 "name" bit("bit_length")"
  5375.             j = j + 1
  5376.          end  /* Do */
  5377.  
  5378.       end /* select */
  5379.  
  5380.    end /* do while outer loop*/
  5381.  
  5382.  
  5383.    /****************************
  5384.    * Output the PL/I Structure *
  5385.    ****************************/
  5386.    do k = 1 to j - 1
  5387.      if array.i.k \= "" & left(array.i.k,1) \= "%" then
  5388.       do
  5389.         m = k
  5390.       end
  5391.    end
  5392.  
  5393.    do k = 1 to j - 1
  5394.       if k = j - 1 & array.i.k \= "" & c.i.k = "" then
  5395.        do
  5396.          if pos(";",array.i.k) = 0 then
  5397.            array.i.k = array.i.k||";"
  5398.          else
  5399.            array.i.k = array.i.k
  5400.          array.i.k = do_indent(array.i.k)
  5401.          array.i.k = indentation||array.i.k
  5402.        end
  5403.  
  5404.  
  5405.       else if k = j - 1 & array.i.k = "" & c.i.k \= "" then
  5406.         do
  5407.           array.i.k = array.i.k||c.i.k
  5408.           array.i.k = do_indent(array.i.k)
  5409.           array.i.k = indentation||array.i.k
  5410.         end  /* Do */
  5411.  
  5412.  
  5413.       else if k = j - 1 & array.i.k \= "" & c.i.k \= "" then
  5414.         do
  5415.           array.i.k = array.i.k";"||c.i.k
  5416.           array.i.k = do_indent(array.i.k)
  5417.           array.i.k = indentation||array.i.k
  5418.         end  /* Do */
  5419.  
  5420.       else if (k = 1 | k = 2)  then
  5421.          array.i.k = array.i.k
  5422.  
  5423.       else do
  5424.         if k = m then
  5425.          do
  5426.            array.i.k = array.i.k||";"||c.i.k
  5427.            array.i.k = do_indent(array.i.k)
  5428.            array.i.k = indentation||array.i.k
  5429.          end  /* Do */
  5430.  
  5431.        else if array.i.k \= "" then
  5432.         do
  5433.           if left(array.i.k,1) \= "%" then
  5434.             array.i.k = array.i.k||","||c.i.k
  5435.           else
  5436.             array.i.k = array.i.k
  5437.           array.i.k = do_indent(array.i.k)
  5438.           array.i.k = indentation||array.i.k
  5439.         end
  5440.  
  5441.        else if array.i.k = "" & c.i.k \= "" then
  5442.          do
  5443.            array.i.k = c.i.k
  5444.            array.i.k = do_indent(array.i.k)
  5445.            array.i.k = indentation||array.i.k
  5446.          end
  5447.       end
  5448.  
  5449.      call do_writeout(array.i.k)
  5450.  
  5451.    end
  5452.    outline = ""
  5453.    call do_writeout(outline)
  5454.    rest1 = ""
  5455.   return
  5456.  
  5457. /****************************
  5458. * add dim attribute to array.       *
  5459. ****************************/
  5460.  
  5461. do_ptrname:
  5462.  parse arg ptname
  5463.  
  5464.   if pos("(",ptname) \= 0 then
  5465.    do
  5466.       parse var ptname ptname "(" tmp
  5467.       ptname = ptname||" dim("||tmp
  5468.    end
  5469. return ptname
  5470. end /* do */
  5471.  
  5472.  
  5473.  /***********************************************
  5474.  * Handle C declaration of arrays ex: array1[2|[4|[6|        *
  5475.  ***********************************************/
  5476.  
  5477.  
  5478.  convert_bracket:
  5479.  
  5480.  parse arg name
  5481.  
  5482.  
  5483.  
  5484.  parse var name nm "[" name
  5485.  name = "["||name
  5486.    done = false
  5487.    do while done = false
  5488.  
  5489.        if pos("][",name) \= 0 then
  5490.         do
  5491.           lrbracket = pos("][", name)
  5492.           name = overlay(", ", name, lrbracket)
  5493.           space = pos(" ",name)
  5494.  
  5495.            if space \= 0 then
  5496.              name =delstr(name,space,1)
  5497.            if pos("][",name) \= 0 then
  5498.  
  5499.            done = false
  5500.         end
  5501.  
  5502.        else
  5503.             done = true
  5504.      end
  5505.  
  5506.     done = false
  5507.     do while done = false
  5508.      comma = pos(",,",name)
  5509.  
  5510.     /****************************************
  5511.     * Handle single dimension || 0:                         *
  5512.     ****************************************/
  5513.  
  5514.      if comma \= 0 then
  5515.       do
  5516.         len = length(name)
  5517.         name = substr(name,1,comma)||"0:*"||substr(name,comma+1,len)
  5518.       end
  5519.  
  5520.       else
  5521.         done = true
  5522.     end
  5523.     /****************************************
  5524.     * Handle ending case in multi dimensional array *
  5525.     ****************************************/
  5526.  
  5527.      comma = pos(",]",name)
  5528.      if comma \= 0 then
  5529.       do
  5530.         len = length(name)
  5531.         name = substr(name,1,comma)||"0:*"||substr(name,comma+1,len)
  5532.       end
  5533.      name = space(name,0)
  5534.  
  5535.  
  5536.      comma = pos("[,",name)
  5537.      if comma \= 0 then
  5538.       do
  5539.         len = length(name)
  5540.         name = substr(name,1,comma)||"0:*"||substr(name,comma+1,len)
  5541.       end
  5542.      name = space(name,0)
  5543.  
  5544.  
  5545.      if nm \= "" | nm \= "NM" then
  5546.       name = nm||name
  5547.     /***********************************************
  5548.     * Add -1 to exisiting dimension to be compatible with C  *
  5549.     ***********************************************/
  5550.  
  5551.  
  5552.     if pos("[", name) \= 0 then
  5553.      do
  5554.         name = change_dimension(name)
  5555.      end
  5556.      return name
  5557.  
  5558.  /***********************************************
  5559.  * Handle the final array declaration ex: array1[2,4,6|       *
  5560.  ************************************************/
  5561.  
  5562.   convert_finalbracket:
  5563.  
  5564.    parse arg name1
  5565.  
  5566.    if pos("[",name1) \= 0 then
  5567.    do
  5568.       parse var name1 name1 "[" name
  5569.        name = "["||name
  5570.  
  5571.        lbracket = pos("[", name)
  5572.        if lbracket \= 0 then
  5573.         do
  5574.           rbracket = pos("]", name)
  5575.           name = overlay("(", name, lbracket)
  5576.           name = overlay(")", name, rbracket)
  5577.         end
  5578.     /****************************************
  5579.     * Handle single dimension || 0:                         *
  5580.     ****************************************/
  5581.  
  5582.  
  5583.        if substr(name,1,1) = "(" & substr(name,2,1) = ")" then
  5584.          do
  5585.            name = "(0:*)"
  5586.         end
  5587.  
  5588.         if pos(",",name) = 0 & pos("*",name) = 0 & pos("(",name) \= 0 then
  5589.          do
  5590.            parse var name "(" name ")"
  5591.            name = "(0:"||name||"-1)"
  5592.          end
  5593.  
  5594.         if name1 \= "" & name1 \= "NAME1" then
  5595.           name = name1||name
  5596.     end
  5597.  
  5598.    else nop /* okay to come here */
  5599.  return name
  5600.  
  5601.     /********************************************
  5602.     * Add -1 to all array dimensions to map to C arrays  *
  5603.     ********************************************/
  5604.  
  5605. change_dimension:
  5606.   parse arg name
  5607.  
  5608.    if pos("[",name) \= 0 then
  5609.     do
  5610.      done = false
  5611.      parse var name temp "[" name
  5612.  
  5613.     if temp \= "" | temp \= "TEMP" then
  5614.      temp = temp||"["
  5615.     else
  5616.      temp = "["
  5617.  
  5618.     name1=""
  5619.     len = pos("]",name)
  5620.     name = overlay(",",name,len)
  5621.  
  5622.    /****************************************
  5623.     * Do loop to process all dimensions.                 *
  5624.     ****************************************/
  5625.  
  5626.     do while pos(",",name) \= 0
  5627.        parse var name chain "," name "]"
  5628.       if substr(chain,1,1) = "_" then
  5629.        chain = check_name(chain)
  5630.  
  5631.       if pos("*",chain) = 0 & chain \= "" then
  5632.        name1 = name1||"0:"||chain"-1,"
  5633.  
  5634.       else if pos("*",chain) \= 0 then
  5635.         name1 = name1||chain","
  5636.  
  5637.       else if pos(",",name) = 0 then
  5638.       do
  5639.         name = ""
  5640.         done = true
  5641.       end
  5642.  
  5643.     end /* do */
  5644.  
  5645.     len = lastpos(",",name1)
  5646.     name = overlay("]",name1,len)
  5647.     name = temp||name
  5648.  
  5649. end
  5650.  return name
  5651.  
  5652.    /********************************************************************
  5653.    *   Subroutine to define a structure of a given type                *
  5654.    ********************************************************************/
  5655.  
  5656.  name_a_structure:
  5657.  
  5658.  
  5659.    /**************************************************************
  5660.    * Declare a structure with name s_name of structure type name *
  5661.    **************************************************************/
  5662.    parse arg all
  5663.    parse var all s_name name
  5664.  
  5665.    /************************************************
  5666.    * Remove the __ prefix from the definition name *
  5667.    ************************************************/
  5668.  
  5669.  
  5670.    if substr(name,1,1) = "_"then
  5671.      name = check_name(name)
  5672.     /**************************************************************
  5673.     * if struct tag name and variable name are same (lowercase & uppercase)*
  5674.     * then PLI is case insensitive so issue error message.                              *
  5675.     **************************************************************/
  5676.  
  5677.  
  5678.     if translate(name) = translate(s_name) | translate(s_name) = translate(name) then
  5679.       do
  5680.         out_line = z"%note('Error 15: Unsupported syntax encountered',4);"
  5681.         call do_writeout(out_line)
  5682.         out_line = z"/* This kind of definition is not supported by this utility. */"
  5683.         call do_writeout(out_line)
  5684.         out_line = z"/* Error: typedef struct "name" "s_name" */ "
  5685.  
  5686.         call do_writeout(out_line)
  5687.         if cpos \= 0 then do
  5688.           call do_comment(comment)
  5689.         end
  5690.  
  5691.         out_line = z"/* The original line in the .h file is: "line_num" */"
  5692.         call do_writeout(out_line)
  5693.         out_line = ""
  5694.         call do_writeout(out_line)
  5695.      return
  5696.      end
  5697.  
  5698.     /****************************************
  5699.     * Output struct declarartion                            *
  5700.     ****************************************/
  5701.    out_line = z"define alias "s_name" type "name";"
  5702.    out_line1 = z"define alias @"s_name" handle "name";"
  5703.    out_line = do_indent(out_line)
  5704.    call do_writeout(out_line)
  5705.  
  5706.    out_line1 = do_indent(out_line1)
  5707.    call do_writeout(out_line1)
  5708.    tflag = "off"
  5709.    switchflag = ""
  5710.  return
  5711.  
  5712.   /**************************************************************
  5713.    * Declare a pointer to a structure with name & s_name                      *
  5714.    **************************************************************/
  5715.  
  5716. name_a_ptrstructure:
  5717.  
  5718.    parse arg all
  5719.  
  5720.    all = space(all,1)
  5721.    parse var all name s_name
  5722.  
  5723.  
  5724.     name = strip(name)
  5725.     s_name = strip(s_name)
  5726.    /**************************************************************
  5727.    * Declare a pointer to a struct and eliminates all pointer symbols.             *
  5728.    **************************************************************/
  5729.  
  5730.  
  5731.     if pos("*",name) \= 0 | pos("*",s_name) \= 0 then
  5732.            do
  5733.  
  5734.                   if left(s_name,4) = "near" | left(s_name,3) = "far" then
  5735.                     do
  5736.                        parse var s_name attribute s_name  ";"
  5737.                         s_name = space(s_name,0)
  5738.                         if pos("*",s_name) \= 0 then
  5739.                           do
  5740.                             do while pos("*",s_name) \= 0
  5741.                                parse var s_name "*" s_name
  5742.                                s_name = strip(s_name)
  5743.                             end
  5744.                          end
  5745.                    end
  5746.                        if pos("*",name) \= 0 then do
  5747.                           parse var name name "*"
  5748.                           name = strip(name)
  5749.                        end
  5750.            end
  5751.  
  5752.     else
  5753.     s_name=space(s_name,0)
  5754.     if pos("*",s_name) \= 0 then
  5755.       do
  5756.         do while pos("*",s_name) \= 0
  5757.           parse var s_name "*" s_name
  5758.           s_name = strip(s_name)
  5759.         end
  5760.     end
  5761.    /******************************
  5762.    * Remove leading underscores.      *
  5763.    ******************************/
  5764.  
  5765.  
  5766.    if pos("_",name) \= 0 | pos("_",s_name) \= 0 then do
  5767.     name = check_name(name)
  5768.     s_name = check_name(s_name)
  5769.    end
  5770.  
  5771.    out_line = z"define alias "s_name" handle "name";"
  5772.    out_line = do_indent(out_line)
  5773.    call do_writeout(out_line)
  5774.    out_line = z"define alias @"s_name" handle "name";"
  5775.    out_line = do_indent(out_line)
  5776.    call do_writeout(out_line)
  5777.   tflag = "off"
  5778. return
  5779.  
  5780.  
  5781.  
  5782.  
  5783.    /********************************************************************
  5784.    *   Subroutine to handle a #if statement                            *
  5785.    ********************************************************************/
  5786.  
  5787. do_if:
  5788.  
  5789.    parse arg rest
  5790.  
  5791.  
  5792.     cpos=pos('/*', rest)
  5793.     if cpos\=0 then
  5794.    do
  5795.     comment=substr(rest,cpos)
  5796.     rest=delstr(rest,cpos)
  5797.   end
  5798.  
  5799.   if pos("defined",rest) = 0 then
  5800.   do
  5801.    out_line = z"%dcl "rest" fixed ext;"
  5802.    call do_writeout(out_line)
  5803.    out_line = z"%if "rest" ^= 0 %then %do"
  5804.    call do_writeout(out_line)
  5805.  
  5806.    if cpos \= 0 then do
  5807.       call do_comment(comment)
  5808.    end
  5809.  
  5810.    return
  5811.   end
  5812.  
  5813.    rest = translate(rest, '^', '!')
  5814.    sympos=pos('||',rest)
  5815.    do while(sympos\=0)
  5816.      rest=delstr(rest,sympos,1)
  5817.      sympos=pos('||',rest)
  5818.    end
  5819.    sympos=pos('&&',rest)
  5820.    do while(sympos\=0)
  5821.      rest=delstr(rest,sympos,1)
  5822.      sympos=pos('&&',rest)
  5823.    end
  5824.  
  5825.    sympos=pos('DEFINED',translate(rest))
  5826.    do while(sympos\=0)
  5827.  
  5828.      first=delstr(rest,sympos)
  5829.      rest=substr(rest,sympos+length('DEFINED')-1)
  5830.  
  5831.      parse var rest '(' varname ')' rest
  5832.      varname=check_name(varname)
  5833.      rest=first||'('varname"^='')"rest
  5834.  
  5835.      out_line = z"%dcl "varname" char ext;"
  5836.      call do_writeout(out_line)
  5837.  
  5838.      sympos=pos('DEFINED',translate(rest))
  5839.    end
  5840.  
  5841.    out_line = z"%if "rest" %then "
  5842.  
  5843.    /*******************************************
  5844.    * Output the condition of the if statement *
  5845.    *******************************************/
  5846.  
  5847.    out_line = do_indent(out_line)
  5848.    call do_writeout(out_line)
  5849.    if cpos \= 0 then
  5850.     call do_comment(comment)
  5851.    out_line = z" %do;"
  5852.    out_line = do_indent(out_line)
  5853.    call do_writeout(out_line)
  5854.    indent = indent + 1
  5855.  
  5856. return
  5857.  
  5858.  
  5859.  
  5860.  
  5861.  
  5862.  
  5863.  
  5864.  
  5865.  
  5866.  
  5867.  
  5868.    /********************************************************************
  5869.    *   Subroutine to process #ifdef statement                          *
  5870.    ********************************************************************/
  5871.  
  5872. do_ifdef:
  5873.    parse arg rest
  5874.    parse var rest name extra
  5875.  
  5876.  
  5877.    /*******************************************
  5878.    * Remove the __ prefix from constant names *
  5879.    *******************************************/
  5880.  
  5881.    if substr(name,1,1) = "_" then do
  5882.      name = check_name(name)
  5883.    end
  5884.  
  5885.  
  5886.    /**********************************
  5887.    * Check for a comment in the line *
  5888.    **********************************/
  5889.  
  5890.    comment = pos('/*', extra)
  5891.  
  5892.  
  5893.    /*******************************************
  5894.    * Check for errors in the #ifdef statement *
  5895.    *******************************************/
  5896.  
  5897.    if (comment = 0) & (extra \= "") then
  5898.       say "Warning : Invalid #ifdef statement"
  5899.    else do
  5900.  
  5901.  
  5902.       /***********************************************
  5903.       * Output an if statement which tests to see    *
  5904.       * if the constant in question equals 'Y'.  If  *
  5905.       * it does, that means it was defined earlier   *
  5906.       * with a #define, and thus the ifdef is true   *
  5907.       ***********************************************/
  5908.  
  5909.       out_line = z"%dcl "name" char ext;"
  5910.       out_line = do_indent(out_line)
  5911.       call do_writeout(out_line)
  5912.       out_line = z"%if "name" ^= '' %then "
  5913.       out_line = do_indent(out_line)
  5914.       call do_writeout(out_line)
  5915.       out_line = z" %do;"
  5916.       out_line = do_indent(out_line)
  5917.       call do_writeout(out_line)
  5918.       indent = indent + 1
  5919.    end
  5920. return
  5921.  
  5922.  
  5923.  
  5924.  
  5925.  
  5926.  
  5927.  
  5928.  
  5929.  
  5930.  
  5931.  
  5932.    /********************************************************************
  5933.    *   Subroutine to handle a #else statement                          *
  5934.    ********************************************************************/
  5935.  
  5936. do_else:
  5937.    parse arg extra
  5938.  
  5939.  
  5940.    /**********************************
  5941.    * Check for a comment on the line *
  5942.    **********************************/
  5943.  
  5944.    comment = pos('/*', extra)
  5945.  
  5946.  
  5947.    /******************************************
  5948.    * Check for errors in the #else statement *
  5949.    ******************************************/
  5950.  
  5951.    if (comment = 0) & (extra \= "") then
  5952.       say "Warning : Invalid #else statement"
  5953.    else do
  5954.  
  5955.  
  5956.       /*******************************************************
  5957.       * Output a %end statement because the %else statement  *
  5958.       * always follows a completed %then %do statement which *
  5959.       * must be ended                                        *
  5960.       *******************************************************/
  5961.  
  5962.       indent = indent - 1
  5963.       out_line = z" %end;"
  5964.       out_line = do_indent(out_line)
  5965.       call do_writeout(out_line)
  5966.       indent = indent - 1
  5967.  
  5968.       /********************************
  5969.       * Output an %else %do statement *
  5970.       ********************************/
  5971.  
  5972.       out_line = z" %else"
  5973.       out_line = do_indent(out_line)
  5974.       call do_writeout(out_line)
  5975.       indent = indent + 1
  5976.       out_line = z" %do;"
  5977.       out_line = do_indent(out_line)
  5978.       call do_writeout(out_line)
  5979.       indent  = indent - 1
  5980.    end
  5981. return
  5982.  
  5983.  
  5984.  
  5985.  
  5986.  
  5987.  
  5988.  
  5989.  
  5990.  
  5991.  
  5992.  
  5993.    /********************************************************************
  5994.    *   Subroutine to process #endif statement                          *
  5995.    ********************************************************************/
  5996.  
  5997. do_endif:
  5998.    parse arg rest
  5999.    parse var rest extra
  6000.  
  6001.  
  6002.    /**********************************
  6003.    * Check for a comment on the line *
  6004.    **********************************/
  6005.  
  6006.    comment  = pos('/*', extra)
  6007.  
  6008.  
  6009.    /*******************************************
  6010.    * Check for errors in the #endif statement *
  6011.    *******************************************/
  6012.  
  6013.    if (comment = 0) & (extra \= "") then
  6014.       say "Warning: Invalid #endif statement"
  6015.    else do
  6016.  
  6017.  
  6018.       /**************************
  6019.       * Output a %end statement *
  6020.       **************************/
  6021.  
  6022.       out_line = z" %end;"
  6023.       indent = indent - 1
  6024.       out_line = do_indent(out_line)
  6025.       call do_writeout(out_line)
  6026.       if comment \= 0 then
  6027.          call do_comment(extra)
  6028.     end
  6029. return
  6030.  
  6031.  
  6032.  
  6033.  
  6034.  
  6035.  
  6036.  
  6037.  
  6038.  
  6039.  
  6040.  
  6041.    /********************************************************************
  6042.    *   Subroutine to process #ifndef statement                         *
  6043.    ********************************************************************/
  6044.  
  6045. do_ifndef:
  6046.    parse arg rest
  6047.    parse var rest name extra
  6048.  
  6049.  
  6050.    /*********************************************
  6051.    * Remove the __ prefix from the #ifndef name *
  6052.    *********************************************/
  6053.  
  6054.    if substr(name,1,1) = "_" then
  6055.       name = check_name(name)
  6056.  
  6057.  
  6058.    /**********************************
  6059.    * Check for a comment on the line *
  6060.    **********************************/
  6061.  
  6062.    comment = pos('/*', extra)
  6063.  
  6064.  
  6065.    /********************************************
  6066.    * Check for errors in the #ifndef statement *
  6067.    ********************************************/
  6068.  
  6069.    if (comment = 0) & (extra \= "") then
  6070.       say "Warning: Invalid #ifndef statement"
  6071.  
  6072.  
  6073.    /*******************************************************
  6074.    * Output an %if statement which checks if the constant *
  6075.    * in question is not equal to 'Y'                      *
  6076.    *******************************************************/
  6077.  
  6078.    else do
  6079.       out_line = z"%dcl "name" char ext;"
  6080.       out_line = do_indent(out_line)
  6081.       call do_writeout(out_line)
  6082.       out_line = z"%if "name" = '' %then "
  6083.       out_line = do_indent(out_line)
  6084.       call do_writeout(out_line)
  6085.       out_line = z" %do;"
  6086.       out_line = do_indent(out_line)
  6087.       call do_writeout(out_line)
  6088.       indent = indent + 1
  6089.    end
  6090. return
  6091.  
  6092.  
  6093.  
  6094.    /********************************************************************
  6095.    *   Subroutine to process a comment line                            *
  6096.    ********************************************************************/
  6097.  
  6098. do_comment:
  6099.    parse arg comment_line
  6100.    tmp_line = ""
  6101.      /************************************************
  6102.    * Insert a space because the first column of a  *
  6103.    * PL/I file is reserved                         *
  6104.    ************************************************/
  6105.    stat_line = pos("*/",comment_line)
  6106.  
  6107.    if stat_line \= 0 then
  6108.      do
  6109.       tmp_line = substr(comment_line,stat_line+2)
  6110.       comment_line = substr(comment_line,1,stat_line+1)
  6111.      end
  6112.  
  6113.  
  6114.    /**************************************************
  6115.    * Keep reading lines and outputting comment lines *
  6116.    * until and end of comment symbol is reached      *
  6117.    **************************************************/
  6118.  
  6119.  
  6120.  
  6121.    done = false
  6122.    do while done = false
  6123.      comment_line=z || comment_line
  6124.      len = length(comment_line)
  6125.      if len > right_margin then do
  6126.        call do_format1(comment_line)
  6127.      end
  6128.  
  6129.      else do
  6130.        rc = lineout(outputfile,comment_line)
  6131.      end
  6132.  
  6133.      end_comment = pos("*/", comment_line)
  6134.      if end_comment = 0 then
  6135.       do
  6136.          comment_line = linein(inputfile)
  6137.          line_num = line_num + 1
  6138.          comment_line = z || comment_line
  6139.          done = false
  6140.       end
  6141.      else
  6142.          done = true
  6143.    end
  6144.  
  6145.       if tmp_line \= "" & tmp_line \= "TMP_LINE" then
  6146.          call process_line tmp_line
  6147. return
  6148.  
  6149.  
  6150.  
  6151.  
  6152.  
  6153.  
  6154.  
  6155.  
  6156.    /********************************************************************
  6157.    *   Subroutine to ignore pragma statements                          *
  6158.    ********************************************************************/
  6159.  
  6160.  
  6161.  
  6162. do_pragma:
  6163.    parse arg rest
  6164.  
  6165.    cpos=pos('/*', rest)
  6166.    if cpos\=0 then
  6167.      do
  6168.        comment=substr(rest,cpos)
  6169.        rest=delstr(rest,cpos)
  6170.      end
  6171.  
  6172.      out_line = z"%note('Error 16: Unsupported syntax encountered',4);"
  6173.      call do_writeout(out_line)
  6174.      out_line = z"/* Pragma directives are not converted. */"
  6175.      call do_writeout(out_line)
  6176.      out_line = z"/* Error: #Pragma "rest" */"
  6177.      call do_writeout(out_line)
  6178.  
  6179.      if cpos \= 0 then do
  6180.         call do_comment(comment)
  6181.      end
  6182.  
  6183.      out_line = z"/* The original line in the .h file is: "line_num" */"
  6184.      call do_writeout(out_line)
  6185.      out_line = ""
  6186.      call do_writeout(out_line)
  6187.      return
  6188.  
  6189.  
  6190.  /*****************************************/
  6191.  /*  Subroutine to handle Enumerated definitions.  */
  6192.  /*****************************************/
  6193.  
  6194.  
  6195. do_enum:
  6196.  
  6197.  parse arg line
  6198.  cflag = "off"
  6199.     if pos("(",line) \= 0 then
  6200.     do
  6201.        cpos = pos("/*",line)
  6202.          if cpos \= 0 then
  6203.           do
  6204.             line = substr(line,cpos)
  6205.             comment = delstr(line,cpos)
  6206.           end
  6207.           else line = rest
  6208.  
  6209.   /******************************************************************
  6210.    * Gather the entire enum definition in to one line if it extends to multiple lines. *
  6211.    ******************************************************************/
  6212.  
  6213.          if  pos(";",line) = 0 then
  6214.            do
  6215.              line1 = linein(inputfile)
  6216.              line_num = line_num + 1
  6217.  
  6218.              cpos = pos("/*",line1)
  6219.              if cpos \= 0 then do
  6220.                line1 = substr(line1,1,cpos-1)
  6221.                comment = delstr(line1,1,cpos-1)
  6222.              end
  6223.              else
  6224.                comment = ""
  6225.  
  6226.             line1 = strip(line1)
  6227.             do while pos(";",line1) = 0 then
  6228.               line = line||line1
  6229.               line1 = linein(inputfile)
  6230.               line_num = line_num + 1
  6231.  
  6232.               cpos = pos("/*",line1)
  6233.               if cpos \= 0 then do
  6234.                 line1 = substr(line1,1,cpos-1)
  6235.                 comment = delstr(line1,1,cpos-1)
  6236.               end
  6237.  
  6238.               else comment = ""
  6239.               line1=strip(line1)
  6240.             end
  6241.            line = line||line1
  6242.         end
  6243.    /******************************************************************
  6244.    * Issue a error message since functions with return type enum is not supported.*
  6245.    ******************************************************************/
  6246.  
  6247.  
  6248.          out_line = z"%note('Error 17: Unsupported syntax encountered',4);"
  6249.          call do_writeout(out_line)
  6250.          out_line = z"/* This utility does not support declarations with */"
  6251.          call do_writeout(out_line)
  6252.  
  6253.          out_line = z"/* return type struct, enum, or union */"
  6254.          call do_writeout(out_line)
  6255.          out_line = z"/* Error: "first" "line" */"
  6256.          call do_writeout(out_line)
  6257.  
  6258.          if cpos \= 0 then
  6259.            call do_comment(comment)
  6260.          out_line = z"/* The original line in the .h file is: "line_num" */"
  6261.          call do_writeout(out_line)
  6262.          out_line = ""
  6263.          call do_writeout(out_line)
  6264.          return
  6265.      end  /* Do */
  6266.  
  6267.   /**************************************************/
  6268.   /* Handle enumerated variable declarations or definitions    */
  6269.   /**************************************************/
  6270.  
  6271.   select
  6272.      when pos(";",line) \= 0 & pos("{",line) = 0 then do
  6273.  
  6274.         cpos = pos('/*',line)
  6275.         if cpos \= 0 then
  6276.           do
  6277.              comment = substr(line,cpos)
  6278.              line=delstr(line,cpos)
  6279.           end
  6280.  
  6281.         parse var line s_name var_name
  6282.         s_name = check_name(s_name)
  6283.  
  6284.        /**************************************************************
  6285.        * Issue a error message since PL/I does not support forward declarations.  *
  6286.        **************************************************************/
  6287.  
  6288.  
  6289.         if var_name = "" then
  6290.           do
  6291.               out_line = z"%note('Error 18: Unsupported syntax encountered',4);"
  6292.          call do_writeout(out_line)
  6293.  
  6294.          out_line = z"/* This utility does not support forward declarations */"
  6295.          call do_writeout(out_line)
  6296.          out_line = z"/* Error:"first" "s_name" */"
  6297.          call do_writeout(out_line)
  6298.  
  6299.          if cpos \= 0 then
  6300.            call do_comment(comment1)
  6301.          out_line = z"/* The original line in the .h file is: "line_num" */"
  6302.          call do_writeout(out_line)
  6303.          out_line = ""
  6304.          call do_writeout(out_line)
  6305.          return
  6306.         end
  6307.  
  6308.         call dcl_enumvar(var_name)
  6309.  
  6310.         if cpos \= 0 then
  6311.            call do_comment(comment)
  6312.  
  6313.      end
  6314.  
  6315.    /*****************************************
  6316.    * Call process_enum to process enum definition.  *
  6317.    *****************************************/
  6318.  
  6319.  
  6320.      when pos(";",line) \= 0 & pos("{",line) \= 0 then do
  6321.  
  6322.         compos = pos('/*',line)
  6323.         if compos \= 0 then
  6324.           do
  6325.              comment1 = substr(line,compos)
  6326.              line=delstr(line,compos)
  6327.          end
  6328.  
  6329.         line = space(line,0)
  6330.         line = check_separator(line)
  6331.         call process_enum(line)
  6332.  
  6333.         if compos \= 0 then
  6334.             call do_comment(comment1)
  6335.      end  /* Do */
  6336.  
  6337.  
  6338.    /***********************************************
  6339.    * Gather all lines if no ; is found at the end of the line.  *
  6340.    ***********************************************/
  6341.  
  6342.  
  6343.      when pos(";",line) = 0 then do
  6344.  
  6345.         cpos = pos('/*',line)
  6346.         if cpos \= 0 then
  6347.           do
  6348.              comment = substr(line,cpos)
  6349.              if pos("{",comment) \= 0 then
  6350.                do
  6351.                   len = pos("{",comment)
  6352.                   comment = overlay("X",comment,len)
  6353.                end
  6354.  
  6355.              line=delstr(line,cpos)
  6356.           end
  6357.  
  6358.         line = space(line,0)
  6359.         if cpos \= 0 then
  6360.             line = line" "comment
  6361.  
  6362.         line1= linein(inputfile)
  6363.         line_num = line_num + 1
  6364.  
  6365.  
  6366.         cpos = pos('/*',line1)
  6367.         if cpos \= 0 then
  6368.           do
  6369.              comment = substr(line1,cpos)
  6370.              if pos("{",comment) \= 0 then
  6371.                do
  6372.                   len = pos("{",comment)
  6373.                   comment = overlay("X",comment,len)
  6374.                end
  6375.  
  6376.              line1=delstr(line1,cpos)
  6377.           end
  6378.  
  6379.          line1 = line1||"~"
  6380.    /************************
  6381.    * Do loop to gather all lines  *
  6382.    *************************/
  6383.  
  6384.  
  6385.          do while pos(";",line1) = 0
  6386.             line1= space(line1,0)
  6387.             if cpos \= 0 then
  6388.                 line1 = line1" "comment
  6389.  
  6390.             line = line||line1
  6391.             line1 = linein(inputfile)
  6392.             line_num = line_num + 1
  6393.  
  6394.  
  6395.  
  6396.            cpos = pos('/*',line1)
  6397.            if cpos \= 0 then
  6398.             do
  6399.               comment = substr(line1,cpos)
  6400.  
  6401.              if pos("{",comment) \= 0 then
  6402.                 do
  6403.                   len = pos("{",comment)
  6404.                   comment = overlay("X",comment,pos)
  6405.                 end
  6406.  
  6407.              line1=delstr(line1,cpos)
  6408.            end
  6409.           line1 = line1||"~"
  6410.          end  /* Do */
  6411.  
  6412.           line1 = space(line1,0)
  6413.           if cpos \= 0 then
  6414.                line1 = line1" "comment
  6415.           line = line||line1
  6416.           line = check_separator(line)
  6417.           call process_enum(line)
  6418.         end
  6419.     otherwise
  6420.        nop   /* will do nothing in some cases */
  6421.  
  6422.   end  /* select */
  6423. return
  6424.  
  6425.  
  6426.   /************************************************************/
  6427.   /*  This routine is called by process enum to process preprocessor        */
  6428.   /*   definitions inside enum definitions.                                               */
  6429.   /************************************************************/
  6430.  
  6431.   process_pre:   procedure expose null
  6432.   parse arg rest
  6433.   parse var rest
  6434.  
  6435.   select
  6436.  
  6437.       when substr(rest,1,6) = "#ifdef" then  do
  6438.         len = length(rest)
  6439.         left = delstr(rest,1,6)
  6440.         rest = do_functifdef(substr(rest,1,6)||" "||left)
  6441.       end
  6442.  
  6443.  
  6444.        when substr(rest,1,7) = "#ifndef" then  do
  6445.          len = length(rest)
  6446.          left = delstr(rest,1,7)
  6447.          rest = do_functifndef(substr(rest,1,7)||" "||left)
  6448.        end
  6449.  
  6450.        when substr(rest,1,3) = "#if" then  do
  6451.         len = length(rest)
  6452.         left = delstr(rest,1,3)
  6453.         rest = do_functif(substr(rest,1,3)||" "||left)
  6454.       end
  6455.  
  6456.       when substr(rest,1,5) = "#else"  then
  6457.         rest = do_felse(rest)
  6458.  
  6459.       when substr(rest,1,6) = "#endif" then
  6460.         rest = "%end;"
  6461.       otherwise nop
  6462.  end
  6463. return rest
  6464.  
  6465.  
  6466.  
  6467.  /*******************************************************/
  6468.  /*  Subroutine to process and output Enumerated definitions.       */
  6469.  /*******************************************************/
  6470.  
  6471.  
  6472.   process_enum:
  6473.   parse arg line
  6474.       ss_name = "dummy#"
  6475.  
  6476.       len = pos("{",line)
  6477.       if len \= 0 then
  6478.        do
  6479.          if substr(line,len+1,1) = "~" then
  6480.          line = delstr(line,len+1,1)
  6481.        end
  6482.  
  6483.       len = lastpos("}",line)
  6484.       if len \= 0 then
  6485.        do
  6486.          if substr(line,len+1,1) = "~" then
  6487.           line = delstr(line,len+1,1)
  6488.        end
  6489.  
  6490.       parse var line name "{" token "~" list "}" rest
  6491.  
  6492.       name = strip(name)
  6493.       len = length(name)
  6494.       do while pos("~",name) \= 0
  6495.          parse var name name "~" name1
  6496.          name = name || name1
  6497.       end
  6498.  
  6499.  
  6500.       if name = "" then
  6501.        do
  6502.          name = ss_name||strt_counter
  6503.          strt_counter = strt_counter+1
  6504.        end
  6505.  
  6506.       name = check_name(name)
  6507.       token = check_name(token)
  6508.  
  6509.       if pos("}",token) \= 0 then
  6510.        do
  6511.          parse var token token "}" rest
  6512.          token = check_name(token)
  6513.          rest = "}"||rest
  6514.        end
  6515.  
  6516.       else
  6517.          rest = "}"||rest
  6518.  
  6519.  
  6520.          /********************************************
  6521.           * The first line declares the function name *
  6522.           ********************************************/
  6523.  
  6524.           out_line.0 = z"define "
  6525.           out_line.1 = z"ordinal"
  6526.           out_line.1 = indentation||out_line.1
  6527.           out_line.2 =  name
  6528.           out_line.2 = indentation||indentation||name
  6529.           i = 2
  6530.           done = false
  6531.           do while done = false
  6532.              i = i + 1
  6533.  
  6534.              if pos("=",token) \= 0  then
  6535.                 token = process_token(token)
  6536.  
  6537.              orig_token = token
  6538.              if token \= "" & token \= "TOKEN" then
  6539.                do
  6540.                  if left(token,1) = "#" then
  6541.                   do
  6542.                      token = process_pre(token)
  6543.                       if i = 3 then
  6544.                         out_line.i = "( "token
  6545.                       else
  6546.                         out_line.i = token
  6547.                    end
  6548.                  else
  6549.                  if i = 3 & pos(",",orig_token) \= 0 then
  6550.                    out_line.i = "( "token
  6551.                  else if i = 3 & pos(",",orig_token) = 0 then
  6552.                    out_line.i = "(  "token
  6553.                  else if i \= 3 & pos(",",orig_token) \= 0 then
  6554.                    out_line.i = token
  6555.                  else
  6556.                    out_line.i = token
  6557.  
  6558.                  parse var list token "~" list
  6559.                  token = check_name(token)
  6560.  
  6561.                  cpos = pos('/*',token)
  6562.                  if cpos \= 0 then
  6563.                    do
  6564.                      epos =pos('*/',token)
  6565.                      comment = substr(token,cpos,epos)
  6566.                      token = delstr(token,cpos,epos)
  6567.                      token = check_name(token)
  6568.                      out_line.i = out_line.i||comment
  6569.                    end
  6570.  
  6571.                end
  6572.  
  6573.              else do
  6574.                 done= true
  6575.                 out_line.i = ");"
  6576.              end
  6577.           end
  6578.  
  6579.  /**************************************************
  6580.  * Output the PL/I enum definitions.                           *
  6581.  **************************************************/
  6582.             do j = 0 to i
  6583.              if pos("X",out_line.j) \= 0 then
  6584.               out_line.j = check_changes(out_line.j)
  6585.               j = j + 1
  6586.              end
  6587.  
  6588.             do j = 0 to i
  6589.               if j = 0 | j = 1 | j = 2 then
  6590.                do
  6591.                  out_line.j = do_indent(out_line.j)
  6592.                  call do_writeout(out_line.j)
  6593.                end
  6594.  
  6595.                else do
  6596.                  out_line.j = indentation||indentation||indentation||out_line.j
  6597.                  out_line.j = do_indent(out_line.j)
  6598.                  call do_writeout(out_line.j)
  6599.                  out_line.j = ""
  6600.                end
  6601.             end
  6602.             var_name=rest
  6603.             if pos("~",var_name) \ = 0 then
  6604.              do
  6605.                do while pos("~",var_name) \= 0
  6606.                 len = pos("~",var_name)
  6607.                 var_name = delstr(var_name,len,1)
  6608.               end
  6609.              end
  6610.             var_name = strip(var_name)
  6611.    /**************************************************************
  6612.    * Process enum variable declartion list after enclosing } braces.               *
  6613.    **************************************************************/
  6614.  
  6615.  
  6616.  
  6617.             if var_name \= "" & var_name \= "};" then
  6618.                do
  6619.  
  6620.                  cpos = pos('/*',var_name)
  6621.                  if cpos \= 0 then
  6622.                    do
  6623.                      comment = substr(var_name,cpos)
  6624.                      var_name = delstr(var_name,cpos)
  6625.                    end
  6626.                  if var_name \= "};" then
  6627.                     do
  6628.                        parse var var_name "}" var_name
  6629.                        s_name = out_line.2
  6630.                        call dcl_enumvar(var_name)
  6631.                     end
  6632.                  if cpos \= 0 then
  6633.                       call do_comment(comment)
  6634.                 end
  6635.                 track = ""
  6636.                 track2 = ""
  6637. /*************************************
  6638. * Return TRUE or FALSE depending on  *
  6639. * whether or not the statement was   *
  6640. * understood and converted           *
  6641. *************************************/
  6642.  
  6643.  
  6644.  if done \= true then return false
  6645.   else
  6646. return true
  6647.  
  6648.  
  6649. /************************************/
  6650. /* check changes called by process_enum */
  6651. /************************************/
  6652. check_changes:
  6653.  
  6654. parse arg st
  6655.  
  6656.   cpos = pos("/*",st)
  6657.   if cpos \= 0 then
  6658.     do
  6659.      comment = substr(st,cpos)
  6660.      st = delstr(st,cpos)
  6661.    end
  6662.  
  6663.    else
  6664.     comment = ""
  6665.  
  6666. /*********************/
  6667. /* convert X to { braces */
  6668. /*********************/
  6669.  if pos("X",comment) \= 0 then
  6670.    do
  6671.       len = pos("X",comment)
  6672.       comment = overlay("{",comment,len)
  6673.    end
  6674.  
  6675.  st = st||comment
  6676. return st
  6677.  
  6678.  
  6679. /********************************************************************
  6680. *   Subroutine to process value initialized in enum declaration                        *
  6681. ********************************************************************/
  6682.  
  6683.  
  6684. process_token:
  6685. parse arg token
  6686.  
  6687. if pos(",",token) \= 0 then
  6688.  pos_comma = 1
  6689. else
  6690.  pos_comma = 0
  6691.  
  6692. parse var token token "=" val ","
  6693. token = token" value("val")"
  6694. if pos_comma = 1 then
  6695.  token = token||","
  6696. token = strip(token)
  6697. return token
  6698.  
  6699.  
  6700.  
  6701.    /********************************************************************
  6702.    *   Subroutine to handle a function or variable declaration         *
  6703.    ********************************************************************/
  6704.  
  6705. do_variable_or_function:
  6706.    parse arg line
  6707.    org_line = line
  6708.    retype = ""
  6709.    ans = ""
  6710.    ret = ""
  6711.  
  6712.    cpos = pos("/*",line)
  6713.    if cpos \= 0 then
  6714.     do
  6715.        epos =pos('*/',line)
  6716.        len = epos - cpos
  6717.        comment = substr(line,cpos,len+2)
  6718.  
  6719.        rest = delstr(line,1,epos+1)
  6720.        rest = strip(rest)
  6721.        line = delstr(line,cpos,epos)
  6722.  
  6723.        if rest \= "" then
  6724.         line = line||rest
  6725.     end
  6726.  
  6727.     else do
  6728.       comment = ""
  6729.       line = line
  6730.     end
  6731.  
  6732.  
  6733.  
  6734.    select
  6735.  
  6736.  
  6737.       /**************************************
  6738.       * If there is no left paren, then it is probably a*
  6739.       * variable declaration.                           *
  6740.       **************************************/
  6741.  
  6742.       when pos('(', line) = 0 & pos(";",line) \= 0 then do
  6743.          call process_var(org_line);
  6744.          result = true
  6745.        end
  6746.  
  6747.  
  6748.       /********************************
  6749.       * If there are parens then this *
  6750.       * is a function definition      *
  6751.       ********************************/
  6752.  
  6753.       when pos('(', line) \= 0 & pos(";",line) \= 0 then do
  6754.          cpos = pos("/*",line)
  6755.          org_line = check_separator(org_line)
  6756.          ans = process_functions(org_line)
  6757.          if ans = true then result = true
  6758.          else
  6759.           result = false
  6760.        end
  6761.  
  6762.  
  6763.       /********************************************************
  6764.       * If there are parens and function continues to next line gather them *
  6765.       * into one statement to be processed.                                  *
  6766.       ********************************************************/
  6767.  
  6768.        when pos('(', line) \= 0 & pos(";",line) = 0 then do
  6769.          statement= gather_routine(org_line)
  6770.          statement = check_separator(statement)
  6771.          ans = process_functions(statement)
  6772.  
  6773.         if ans = true then result = true
  6774.          else
  6775.          result = false
  6776.        end
  6777.  
  6778.        /********************************************************
  6779.       * If there are no parens and function or variable declaration continues *
  6780.       * to next line gather them into one statement to be processed.         *                                  *
  6781.       *********************************************************/
  6782.  
  6783.          when pos('(', line) = 0 & pos(";",line) = 0 then do
  6784.          statement= gather_routine(org_line)
  6785.          if pos("(",statement) \= 0 then
  6786.           do
  6787.             statement = check_separator(statement)
  6788.             ans = process_functions(statement)
  6789.             if ans = true then
  6790.                result = true
  6791.             else
  6792.                result = false
  6793.           end
  6794.           else do
  6795.              comment= comment.1.0
  6796.               call process_var(statement||comment)
  6797.               result = true
  6798.           end
  6799.         end
  6800.  
  6801.       otherwise
  6802.         nop  /* will do nothing in some cases */
  6803.  
  6804.       end /* outer select */
  6805.      return result
  6806.  
  6807.   /****************************************************/
  6808.   /* Add separator after every comma for uniform processing in */
  6809.   /* function declarations, enums etc, because a line is parsed   */
  6810.   /* looking for a ~ as end of a parameter or enum list.             */
  6811.   /****************************************************/
  6812.   check_separator:
  6813.   parse arg str
  6814.  
  6815.      i = 0
  6816.     do while lastpos(",",str) \= 0
  6817.        parse var str lstr ","  other
  6818.  
  6819.        if left(lstr,1) \= "~" then
  6820.           lstr.i = "~"||lstr","
  6821.        else
  6822.           lstr.i = lstr","
  6823.        i = i + 1
  6824.        str = other
  6825.        str = strip(str)
  6826.    end
  6827.  
  6828.    if left(str,1) \= "~" then
  6829.      lstr.i = "~"||str
  6830.   else
  6831.      lstr.i = str
  6832.  
  6833.   str = ""
  6834.   do j = 0 to i
  6835.      str = str||lstr.j
  6836.   end
  6837.  
  6838.   if left(str,1) = "~" then
  6839.     parse var str "~" str
  6840.  
  6841.  return str
  6842.  
  6843.  
  6844.   /********************************
  6845.   * If the function or variable declaration *
  6846.   * extends beyond one line this routine  *
  6847.   * gathers them into one line for uniform*
  6848.   * processing.                             *
  6849.   ********************************/
  6850.  
  6851.  
  6852.  gather_routine:
  6853.  
  6854.  parse arg line
  6855.  statement = ""
  6856.  comment. = ""
  6857.  count = 0
  6858.    i = 0
  6859.    j = 0
  6860.    line = strip(line)
  6861.    /****************************************
  6862.    * process comments from line before processing*
  6863.    ****************************************/
  6864.    cpos = pos("/*",line)
  6865.    if cpos \= 0 then
  6866.     do
  6867.         temp_comment = substr(line,cpos)
  6868.  
  6869.         if pos(")",temp_comment) \= 0 then
  6870.           do
  6871.             len = pos(")",temp_comment)
  6872.             temp_comment = overlay("X",temp_comment,len)
  6873.           end
  6874.  
  6875.         temp_line = delstr(line,cpos)
  6876.     end
  6877.  
  6878.    else do
  6879.      temp_line = line
  6880.      temp_comment=""
  6881.    end
  6882.    /******************************************************************
  6883.    * Issue a error message and terminate since executable statement was found.  *
  6884.    ******************************************************************/
  6885.  
  6886.  
  6887.      if  pos("{",temp_line) \= 0 & pos("=",temp_line) = 0 then
  6888.       do
  6889.            say "Executable st found or format not supported -- Program terminated"
  6890.            say "/*Approximate line of termination is expected to be line# "line_num "in the .h file*/"
  6891.            out_line = z"%note('Error 19: Unsupported syntax encountered',4);"
  6892.            call do_writeout(out_line)
  6893.  
  6894.            out_line = z"/* Utility does not support executable statements */"
  6895.            call do_writeout(out_line)
  6896.            out_line = z"/* or format encountered is not supported. */"
  6897.            call do_writeout(out_line)
  6898.  
  6899.            out_line = z"/* Error:  "temp_line" */"
  6900.            len = length(out_line)
  6901.  
  6902.            if len > right_margin then
  6903.              call do_format1(out_line)
  6904.            else
  6905.               call do_writeout(out_line)
  6906.  
  6907.            if cpos \= 0 then
  6908.              call do_comment(temp_comment)
  6909.  
  6910.            out_line = z"/* The original line in the .h file is: "line_num" */"
  6911.            call do_writeout(out_line)
  6912.            out_line = ""
  6913.            call do_writeout(out_line)
  6914.            exit
  6915.      end  /* Do */
  6916.  
  6917.      line.i = temp_line
  6918.      comment.i.j = temp_comment
  6919.   /*********************************************/
  6920.   /* get next inputline for processing.                         */
  6921.   /*********************************************/
  6922.    line=linein(inputfile)
  6923.    line_num = line_num + 1
  6924.    line = strip(line)
  6925.  
  6926.    cpos = pos("/*",line)
  6927.    if cpos \= 0 then
  6928.     do
  6929.         temp_comment = substr(line,cpos)
  6930.         if pos(")",temp_comment) \= 0 then
  6931.           do
  6932.             len = pos(")",temp_comment)
  6933.             temp_comment = overlay("X",temp_comment,len)
  6934.           end
  6935.         temp_line = delstr(line,cpos)
  6936.     end
  6937.  
  6938.    else do
  6939.      temp_line = line
  6940.      temp_comment= ""
  6941.    end
  6942.  
  6943.  
  6944.    /**************************************************************
  6945.    * If a definition is followed by only a comment line then || the two.          *
  6946.    **************************************************************/
  6947.  
  6948.  
  6949.    if temp_line \= "" then
  6950.      do
  6951.        i = i + 1
  6952.        line.i = temp_line
  6953.        j = 0
  6954.        comment.i.j = temp_comment
  6955.     end
  6956.     else do
  6957.        j = j + 1
  6958.       comment.i.j = temp_comment
  6959.     end
  6960.    /******************************************************************
  6961.    * Issue a error message and terminate since executable statement was found.  *
  6962.    ******************************************************************/
  6963.  
  6964.  
  6965.  
  6966.     line = line.i
  6967.     if  pos("{",line) \= 0 & pos("=",line) = 0 then
  6968.       do
  6969.            say "Executable st found or format not supported -- Program terminated"
  6970.            say "/*Approximate line of termination is expected to be line# "line_num "in the .h file*/"
  6971.  
  6972.            out_line = z"%note('Error 20: Unsupported syntax encountered',4);"
  6973.            call do_writeout(out_line)
  6974.            out_line = z"/* Utility does not support executable statements */"
  6975.            call do_writeout(out_line)
  6976.  
  6977.            out_line = z"/* or format encountered is not supported. */"
  6978.            call do_writeout(out_line)
  6979.            out_line = z"/* Error: "line" */"
  6980.            call do_writeout(out_line)
  6981.  
  6982.            if cpos \= 0 then
  6983.              call do_comment(comment.i.j)
  6984.  
  6985.            out_line = z"/* The original line in the .h file is: "line_num" */"
  6986.            call do_writeout(out_line)
  6987.            out_line = ""
  6988.            call do_writeout(out_line)
  6989.            exit
  6990.      end  /* Do */
  6991.  
  6992.   /*********************************************/
  6993.   /* get next inputline for processing.                         */
  6994.   /*********************************************/
  6995.  
  6996.  
  6997.    do while pos(";",line) = 0
  6998.     line = linein(inputfile)
  6999.     line_num = line_num + 1
  7000.     line = strip(line)
  7001.  
  7002.    cpos = pos("/*",line)
  7003.    if cpos \= 0 then
  7004.     do
  7005.         temp_comment = substr(line,cpos)
  7006.         if pos(")",temp_comment) \= 0 then
  7007.           do
  7008.             len = pos(")",temp_comment)
  7009.             temp_comment = overlay("X",temp_comment,len)
  7010.           end
  7011.         temp_line = delstr(line,cpos)
  7012.     end
  7013.  
  7014.    else do
  7015.     temp_line = line
  7016.     temp_comment=""
  7017.    end
  7018.  
  7019.  
  7020.    /**************************************************************
  7021.    * If a definition is followed by only a comment line then || the two.          *
  7022.    **************************************************************/
  7023.  
  7024.    if temp_line \= "" then
  7025.      do
  7026.        i = i + 1
  7027.        line.i = temp_line
  7028.        j = 0
  7029.        comment.i.j = temp_comment
  7030.      end
  7031.     else do
  7032.       j = j + 1
  7033.       count = j
  7034.       comment.i.j = temp_comment
  7035.     end
  7036.  
  7037.    line = line.i
  7038.    /******************************************************************
  7039.    * Issue a error message and terminate since executable statement was found.  *
  7040.    ******************************************************************/
  7041.  
  7042.        if  pos("{",line) \= 0 & pos("=",line) = 0 then
  7043.         do
  7044.            say "Executable st found or format not supported -- Program terminated"
  7045.            say "/*Approximate line of termination is expected to be line# "line_num "in the .h file*/"
  7046.            out_line = z"%note('Error 21: Unsupported syntax encountered',4);"
  7047.            call do_writeout(out_line)
  7048.  
  7049.            out_line = z"/* Utility does not support executable statements */"
  7050.            call do_writeout(out_line)
  7051.            out_line = z"/* or format encountered is not supported. */"
  7052.  
  7053.            call do_writeout(out_line)
  7054.            out_line = z"/* Error: "line" */"
  7055.            call do_writeout(out_line)
  7056.  
  7057.            if cpos \= 0 then
  7058.              call do_comment(comment.i.j)
  7059.  
  7060.            out_line = z"/* The original line in the .h file is: "line_num" */"
  7061.            call do_writeout(out_line)
  7062.            out_line = ""
  7063.            call do_writeout(out_line)
  7064.       exit
  7065.      end  /* Do */
  7066.  
  7067.    end
  7068.    /********************************************
  7069.    * Concatenate the entire definition into a single line.  *
  7070.    *********************************************/
  7071.      do j = 0 to i
  7072.          if line.j \= "" then
  7073.          line.j = line.j||"~"
  7074.      end /* do */
  7075.  
  7076.      do j = 0 to i
  7077.         statement = statement" "line.j
  7078.         statement=space(statement,1)
  7079.      end /* do */
  7080.    return statement
  7081.  
  7082.  
  7083.    /***********************************************************
  7084.    * process_function calls the different functions appropriate for the one    *
  7085.    * being processed. System linkage conventions need to be included here.  *
  7086.    ************************************************************/
  7087.  
  7088. process_functions:
  7089.      parse arg line
  7090.         line = space(line,1)
  7091.         line = check_attribute(line)
  7092.         line = space(line,1)
  7093.  
  7094.          ori_line = line
  7095.          parse var line first line
  7096.  
  7097.          val1 = ""
  7098.          result = ""
  7099.  
  7100.          datatypes = "int long short char void unsigned long unsigned short",
  7101.          "unsigned int unsigned char signed long signed short signed char signed int"
  7102.  
  7103.          ptr_types ="int* long* short* char* void* "
  7104.         /***************************************************/
  7105.         /* Please include your system linkage conventions in the list   */
  7106.         /* below after the last one before the closing " in the last line.*/
  7107.         /***************************************************/
  7108.  
  7109.  
  7110.       select
  7111.          when translate(first) = "STATIC" then do
  7112.  
  7113.             cpos = pos("/*",line)
  7114.             out_line= z"/* static functions not supported by this utility */"
  7115.             call do_writeout(out_line)
  7116.             say "static functions not supported"
  7117.             val1 = false
  7118.           end  /* Do */
  7119.  
  7120.  
  7121.          when translate(first) = "EXTERN" then do
  7122.             val1 =  do_extern(line)
  7123.           end
  7124.  
  7125.  
  7126.           when first = "*" then do
  7127.             val1 = do_ptrfunct(first" "line)
  7128.           end  /* Do */
  7129.  
  7130.  
  7131.           when substr(first,1,1) = "*" then do
  7132.             first = "*"
  7133.             line = delstr(ori_line,1,1)
  7134.             val1 = do_ptrfunct(first" "line)
  7135.           end  /* Do */
  7136.  
  7137.  
  7138.          when wordpos(first,datatypes) > 0 then do
  7139.             val1 = do_extern(first" "line)
  7140.          end  /* Do */
  7141.  
  7142.           when wordpos(first,ptr_types) > 0 then do
  7143.             val1 = do_extern(first" "line)
  7144.          end  /* Do */
  7145.  
  7146.  
  7147.          when wordpos(first,linkages) > 0 then do
  7148.             line = first" "line
  7149.             val1 = do_linkconventions(line)
  7150.           end  /* Do */
  7151.  
  7152.  
  7153.          when pos("(",first) \= 0 | substr(line,1,1) = "(" then do
  7154.            val1 = do_funct(first" "line)
  7155.          end  /* Do */
  7156.  
  7157.  
  7158.          when wordpos(first,datatypes) = 0 & wordpos(first,linkages) = 0 ,
  7159.           & first \= "*" then do
  7160.             val1 = do_typefunct(first" "line)
  7161.             return val1
  7162.          end  /* Do */
  7163.  
  7164.          otherwise
  7165.            nop  /* Error in processing */
  7166.         end /* select EXTERN */
  7167.       return val1
  7168.  
  7169.   /*********************************************************/
  7170.   /* check for far and near attributes and process them appropriately */
  7171.   /*********************************************************/
  7172.   check_attribute:
  7173.   parse arg line
  7174.  
  7175.   org_line = line
  7176.   parse var line line "(" line1
  7177.  
  7178.    if pos("near",line) = 0 & pos("far",line) = 0 then
  7179.     do
  7180.      line = org_line
  7181.      return line
  7182.     end
  7183.  
  7184.   if pos("far",line) \= 0 then
  7185.     do
  7186.       parse var line line "far" temp
  7187.       line = line||temp
  7188.       line = line||" ("||line1
  7189.     end
  7190.  
  7191.     if  pos("near",line) \= 0 then
  7192.     do
  7193.       parse var line line "near" temp
  7194.       line = line||temp
  7195.       line = line||" ("||line1
  7196.     end
  7197.  
  7198.    return line
  7199.  
  7200.  /********************************************************/
  7201.  /* procedure to process all functions that have extern as first word*/
  7202.  /*********************************************************/
  7203.   do_extern:
  7204.  
  7205.   parse arg line
  7206.    parse var line type rest
  7207.    lc = "_Cdecl _Pascal _Fastcall"
  7208.    oldtype = type
  7209.  
  7210.           temp = type
  7211.           if right(temp,1,1) = "*" then
  7212.             do
  7213.              len = length(temp)
  7214.              type = delstr(temp,len,1)
  7215.              if wordpos(type,datatypes) = 0 then
  7216.                type = temp
  7217.             end
  7218. /***************************************************/
  7219. /*   process C datatypes specified as return types.               */
  7220. /***************************************************/
  7221.           select
  7222.             when wordpos(type,datatypes) > 0 then do
  7223.                 if right(temp,1) = "*" then
  7224.                  do
  7225.                   token1 = "*"
  7226.                   other = rest
  7227.                 end
  7228.  
  7229.               if right(temp,1) \= "*"  then
  7230.                 do
  7231.  
  7232.                 if type = "unsigned" | type = "signed" then
  7233.                  do
  7234.                    parse var rest type1 rest
  7235.                    retype = process_rtype(type" "type1)
  7236.                  end
  7237.  
  7238.                  else do
  7239.                    retype = process_rtype(type)
  7240.                  end
  7241.  
  7242.                parse var rest token1 other
  7243.              end
  7244.  
  7245.                if substr(token1,1,1) = "(" then
  7246.                 do
  7247.                  say "this kind of funct decl is not supported"
  7248.                  out_line = z"/* Utility does not support this kind of func decl. */"
  7249.                  call do_writeout(out_line)
  7250.                  return false
  7251.                end
  7252.  
  7253.     /********************************************
  7254.    * Process pointer attribute if it exists.                     *
  7255.    *********************************************/
  7256.  
  7257.                  select
  7258.                      when token1 = "*" then do
  7259.                            ptr_flag=process_pointer(token1)
  7260.                               parse var other token2 rest
  7261.  
  7262.                                select
  7263.  
  7264.       /********************************************
  7265.       * Process linkage convention if it exists.                  *
  7266.       ********************************************/
  7267.  
  7268.                                    when wordpos(token2,linkages) > 0 then do
  7269.                                       if token2 = "_Far16" then
  7270.                                        do
  7271.                                          old_val = rest
  7272.                                          parse var rest temp rest
  7273.  
  7274.                                          if wordpos(temp,lc) > 0 then
  7275.                                            token2 = token2" "temp
  7276.                                          else do
  7277.                                            token2 = token2
  7278.                                            rest = old_val
  7279.                                          end
  7280.  
  7281.                                       end
  7282.  
  7283.                                       linkconv = process_linkconv(token2)
  7284.                                       ret = dcl_function(rest)
  7285.  
  7286.                                       if ret \= true then
  7287.                                        do
  7288.                                           result = false
  7289.                                           return result
  7290.                                        end
  7291.  
  7292.                                       val = print_ret1(linkconv"%")
  7293.                                       if val = true  then result = true
  7294.                                       return result
  7295.                                    end  /* Do */
  7296.    /********************************************
  7297.    * Process function declaration.                               *
  7298.    *********************************************/
  7299.  
  7300.  
  7301.                                    when pos("(",token2) \= 0 | substr(rest,1,1) = "(" then do
  7302.                                        ret = dcl_function(other)
  7303.  
  7304.                                        if ret \= true then
  7305.                                         do
  7306.                                            result = false
  7307.                                            return result
  7308.                                         end
  7309.  
  7310.                                        val =  print_ret2()
  7311.                                        if val = true  then result = true
  7312.                                        return result
  7313.                                     end  /* Do */
  7314.  
  7315.                                otherwise
  7316.                                    nop   /* Error in processing */
  7317.                                end  /* select  token2*/
  7318.  
  7319.                          end /* when token1 = * */
  7320.       /********************************************
  7321.       * Process linkage convention if it exists.                  *
  7322.       ********************************************/
  7323.  
  7324.  
  7325.                         when wordpos(token1,linkages) > 0 then do
  7326.                             parse var other rest
  7327.  
  7328.                             if token1 = "_Far16" then
  7329.                              do
  7330.                                 old_val = rest
  7331.                                 parse var rest temp rest
  7332.                                 if wordpos(temp,lc) > 0 then
  7333.                                   token1 = token1" "temp
  7334.  
  7335.                                 else do
  7336.                                   token1 = token1
  7337.                                   rest = old_val
  7338.                                 end
  7339.                            end
  7340.  
  7341.                             linkconv = process_linkconv(token1)
  7342.                             ret = dcl_function(rest)
  7343.  
  7344.                             if ret \= true then
  7345.                              do
  7346.                                result = false
  7347.                                return result
  7348.                              end
  7349.  
  7350.                             val =  print_ret3(retype"%"linkconv"%")
  7351.                             if val = true  then result = true
  7352.                             return result
  7353.                          end  /* Do */
  7354.  
  7355.                         when pos("*",token1) = 0 & pos("(",token1) \= 0  then do
  7356.                             ret = dcl_function(rest)
  7357.  
  7358.                             if ret \= true then
  7359.                              do
  7360.                                result = false
  7361.                                return result
  7362.                              end
  7363.  
  7364.                             val =  print_ret4(retype"%")
  7365.                             if val = true  then result = true
  7366.                             return result
  7367.                         end  /* Do */
  7368.  
  7369.                         when pos("*",token1) = 0 &  substr(other,1,1) = "(" then do
  7370.                             ret = dcl_function(rest)
  7371.  
  7372.                             if ret \= true then
  7373.                              do
  7374.                                result = false
  7375.                                return result
  7376.                              end
  7377.  
  7378.                             val =  print_ret4(retype"%")
  7379.                             if val = true  then result = true
  7380.                             return result
  7381.                        end  /* Do */
  7382.  
  7383.                        when pos("*",token1) \= 0 & pos("(",token1) \= 0 then do
  7384.                             rest = delstr(rest,1,1)
  7385.                             ret = dcl_function(rest)
  7386.  
  7387.                             if ret \= true then
  7388.                              do
  7389.                                result = false
  7390.                                return result
  7391.                              end
  7392.  
  7393.                             val =  print_ret2()
  7394.                             if val = true  then result = true
  7395.                             return result
  7396.                        end  /* Do */
  7397.  
  7398.                        when pos("*",token1) \= 0 &  substr(other,1,1) = "(" then do
  7399.                             rest = delstr(rest,1,1)
  7400.                             ret = dcl_function(rest)
  7401.  
  7402.                             if ret \= true then
  7403.                              do
  7404.                                result = false
  7405.                                return result
  7406.                              end
  7407.  
  7408.                             val =  print_ret2()
  7409.                             if val = true  then result = true
  7410.                             return result
  7411.                        end  /* Do */
  7412.  
  7413.  
  7414.                       otherwise
  7415.                        nop  /* Error in processing */
  7416.                    end  /* select  for token1*/
  7417.           end /* type = datatype */
  7418.  
  7419.       /********************************************
  7420.       * Process linkage convention if it exists.                  *
  7421.       ********************************************/
  7422.  
  7423.  
  7424.             when wordpos(type,linkages) > 0  then do
  7425.                if type = "_Far16" then
  7426.                  do
  7427.                     old_val = rest
  7428.                     parse var rest temp rest
  7429.  
  7430.                     if wordpos(temp,lc) > 0 then
  7431.                       type = type" "temp
  7432.                     else do
  7433.                        type = type
  7434.                        rest = old_val
  7435.                     end
  7436.  
  7437.                   end
  7438.  
  7439.                 linkconv = process_linkconv(type)
  7440.                 ret = dcl_function(rest)
  7441.  
  7442.                 if ret \= true then
  7443.                  do
  7444.                   result = false
  7445.                   return result
  7446.                  end
  7447.  
  7448.                 val =  print_ret5(linkconv"%")
  7449.                 if val = true  then result = true
  7450.                 return result
  7451.             end  /* Do */
  7452.  
  7453.  
  7454.              when pos("(",type) \= 0 | left(rest,1) = "(" then do
  7455.                if substr(type,1,1) \= "*" then
  7456.                  do
  7457.                   ret = dcl_function(line)
  7458.  
  7459.                   if ret \= true then
  7460.                    do
  7461.                      result = false
  7462.                      return result
  7463.                   end
  7464.  
  7465.                   val =  print_ret6()
  7466.                   if val = true  then result = true
  7467.                   return result
  7468.                 end  /* Do */
  7469.  
  7470.                else
  7471.                if substr(type,1,1) = "*" & pos("(",type) \= 0 then
  7472.                  do
  7473.                    type = delstr(type,1,1)
  7474.                    type = type" "||rest
  7475.                    type = space(type,1)
  7476.                    ret = dcl_function(type)
  7477.  
  7478.                    if ret \= true then
  7479.                     do
  7480.                       result = false
  7481.                       return result
  7482.                     end
  7483.  
  7484.                    val =  print_ret2()
  7485.                    if val = true  then result = true
  7486.                   return result
  7487.                 end /* usertype *name */
  7488.  
  7489.                 else
  7490.                    if substr(type,1,1) = "*" & left(rest,1) = "(" then
  7491.                  do
  7492.                    type = delstr(type,1,1)
  7493.                    type = type||rest
  7494.                    ret = dcl_function(type)
  7495.  
  7496.                    if ret \= true then
  7497.                     do
  7498.                       result = false
  7499.                       return result
  7500.                     end
  7501.  
  7502.                    val =  print_ret2()
  7503.                    if val = true  then result = true
  7504.                   return result
  7505.                 end /* usertype *name */
  7506.  
  7507.              end /* pos "(" type */
  7508.  
  7509.  
  7510.              when type = "*" | substr(type,1,1) = "*" then do
  7511.                 if type = "*" then
  7512.                   ptr_flag=process_pointer(type)
  7513.                 else
  7514.  
  7515.                 if  left(type,1,1) = "*" then
  7516.                  do
  7517.                    temp = delstr(type,1,1)
  7518.                    type = "*"
  7519.                    rest = temp||rest
  7520.                  end
  7521.        /********************************************
  7522.       * Process linkage convention if it exists.                  *
  7523.       ********************************************/
  7524.  
  7525.                  parse var rest token2 other
  7526.                         if wordpos(token2,linkages) > 0 then
  7527.                             do
  7528.                              if token2 = "_Far16" then
  7529.                                do
  7530.                                  old_val = other
  7531.                                  parse var other temp other
  7532.  
  7533.                                  if wordpos(temp,lc) > 0 then
  7534.                                     token2 = token2" "temp
  7535.                                  else do
  7536.                                    token2 = token2
  7537.                                    other  = old_val
  7538.                                  end
  7539.  
  7540.                                end
  7541.  
  7542.                                 linkconv = process_linkconv(token2)
  7543.                                 ret = dcl_function(other)
  7544.  
  7545.                                 if ret \= true then
  7546.                                  do
  7547.                                    result = false
  7548.                                    return result
  7549.                                  end
  7550.  
  7551.                                 val =  print_ret1(linkconv"%")
  7552.                                 if val = true  then result = true
  7553.                                 return result
  7554.                             end  /* Do */
  7555.                             else
  7556.  
  7557.                             if pos("(",rest) \= 0 then
  7558.                              do
  7559.                                 ret = dcl_function(rest)
  7560.  
  7561.                                 if ret \= true then
  7562.                                  do
  7563.                                   result = false
  7564.                                   return result
  7565.                                  end
  7566.  
  7567.                                 val = print_ret2()
  7568.                                 if val = true  then result = true
  7569.                                 return result
  7570.                             end
  7571.  
  7572.                end /* type = * */
  7573.  
  7574.  
  7575.              when type = "*" & pos("(",rest) \= 0 then do
  7576.                  ptr_flag=process_pointer(type)
  7577.  
  7578.                  if pos("(",rest) \= 0 then
  7579.                     do
  7580.                        ret = dcl_function(rest)
  7581.  
  7582.                        if ret \= true then
  7583.                         do
  7584.                          result = false
  7585.                          return result
  7586.                         end
  7587.  
  7588.                        val = print_ret2()
  7589.                        if val = true  then result = true
  7590.                        return result
  7591.                    end
  7592.               end  /* Do */
  7593.  
  7594.        /********************************************
  7595.       * Process userdefined datatypes                            *
  7596.       ********************************************/
  7597.  
  7598.             when wordpos(type,linkages) = 0 & wordpos(type,datatypes) = 0 then do
  7599.                if right(type,1) = "*" then do
  7600.                  checkname = "*"
  7601.                  parse var rest left
  7602.                end
  7603.  
  7604.                else
  7605.                  parse var rest checkname left
  7606.  
  7607.                   select
  7608.                       when pos("(",checkname) \= 0 & substr(checkname,1,1) \= "*" then do
  7609.                            retype = type
  7610.                            ret = dcl_function(rest)
  7611.  
  7612.                            if ret \= true then
  7613.                             do
  7614.                                result = false
  7615.                                return result
  7616.                             end
  7617.  
  7618.                            val = print_ret7(retype"%")
  7619.                            if val = true  then result = true
  7620.                            return result
  7621.                        end /* usertype nopointer and function */
  7622.  
  7623.  
  7624.                       when left(left,1) = "(" & substr(checkname,1,1) \= "*" then do
  7625.                            retype = type
  7626.                            ret = dcl_function(rest)
  7627.  
  7628.                            if ret \= true then
  7629.                             do
  7630.                                result = false
  7631.                                return result
  7632.                             end
  7633.  
  7634.                            val = print_ret7(retype"%")
  7635.                            if val = true  then result = true
  7636.                            return result
  7637.                        end /* usertype nopointer and function */
  7638.  
  7639.                       when substr(checkname,1,1) = "*" & pos("(",checkname) \= 0 then do
  7640.                           checkname = delstr(checkname,1,1)
  7641.                           retype = type
  7642.                           rest = delstr(rest,1,1)
  7643.                           ret = dcl_function(rest)
  7644.  
  7645.                           if ret \= true then
  7646.                             do
  7647.                                result = false
  7648.                                return result
  7649.                             end
  7650.  
  7651.                           val =  print_ret2()
  7652.                           if val = true  then result = true
  7653.                           return result
  7654.                        end /* usertype *name */
  7655.  
  7656.  
  7657.                       when substr(checkname,1,1) = "*" & substr(left,1,1) = "(" then do
  7658.                           checkname = delstr(checkname,1,1)
  7659.                           retype = type
  7660.                           rest = delstr(rest,1,1)
  7661.                           ret = dcl_function(rest)
  7662.  
  7663.                           if ret \= true then
  7664.                             do
  7665.                                result = false
  7666.                                return result
  7667.                             end
  7668.  
  7669.                           val =  print_ret2()
  7670.                           if val = true  then result = true
  7671.                           return result
  7672.                        end /* usertype *name */
  7673.  
  7674.  
  7675.  
  7676.                      when checkname = "*" then do
  7677.                            ptr_flag=process_pointer(checkname)
  7678.                               parse var left token2 rest
  7679.  
  7680.                                 select
  7681.                                    when wordpos(token2,linkages) > 0 then do
  7682.                                      if token2 = "_Far16" then
  7683.                                        do
  7684.                                          old_val = rest
  7685.                                          parse var rest temp rest
  7686.  
  7687.                                          if wordpos(temp,lc) > 0 then
  7688.                                            token2 = token2" "temp
  7689.                                          else do
  7690.                                            token2 = token2
  7691.                                            rest = old_val
  7692.                                          end
  7693.  
  7694.                                        end
  7695.                                       linkconv = process_linkconv(token2)
  7696.                                       ret = dcl_function(rest)
  7697.  
  7698.                                       if ret \= true then
  7699.                                         do
  7700.                                           result = false
  7701.                                           return result
  7702.                                         end
  7703.  
  7704.                                       val = print_ret1(linkconv"%")
  7705.                                       if val = true  then result = true
  7706.                                       return result
  7707.                                    end  /* Do */
  7708.  
  7709.       /********************************************
  7710.       * Process linkage convention if it exists.                  *
  7711.       ********************************************/
  7712.  
  7713.                                   when wordpos(token2,linkages) = 0 then do
  7714.                                       ret = dcl_function(left)
  7715.  
  7716.                                       if ret \= true then
  7717.                                         do
  7718.                                           result = false
  7719.                                           return result
  7720.                                        end
  7721.  
  7722.                                       val = print_ret2()
  7723.                                       if val = true  then result = true
  7724.                                       return result
  7725.                                    end /* token2 lc or funct */
  7726.  
  7727.                      end /* usertype * name */
  7728.                   end /* checkname */
  7729.  
  7730.          /********************************************
  7731.          * Check to make sure the calling convention *
  7732.          * specified is one which has been defined   *
  7733.          ********************************************/
  7734.  
  7735.  
  7736.                      when wordpos(checkname,linkages) > 0  then do
  7737.                         if checkname = "_Far16" then
  7738.                           do
  7739.                             old_val = left
  7740.                             parse var left temp left
  7741.  
  7742.                             if wordpos(temp,lc) > 0 then
  7743.                                checkname = checkname" "temp
  7744.                             else do
  7745.                                checkname = checkname
  7746.                                left = old_val
  7747.                              end
  7748.  
  7749.                           end
  7750.  
  7751.                            linkconv = process_linkconv(checkname)
  7752.                            retype = type
  7753.                            ret = dcl_function(left)
  7754.  
  7755.                            if ret \= true then
  7756.                             do
  7757.                                result = false
  7758.                                return result
  7759.                             end
  7760.  
  7761.                            val =  print_ret8(retype"%"linkconv"%")
  7762.                            if val = true  then result = true
  7763.                            return result
  7764.                      end  /* Do */ /* usertype lc name */
  7765.  
  7766.  
  7767.                     otherwise
  7768.                       nop  /* Error in processing */
  7769.                   end /* select for pos("(",checkname */
  7770.  
  7771.          end /* wordpos  type linkages */
  7772.       /********************************************
  7773.       * Process userdefined data types as return types.    *
  7774.       ********************************************/
  7775.  
  7776.  
  7777.          when wordpos(type,linkages) = 0 & wordpos(type,datatypes) = 0 then do
  7778.  
  7779.              parse var rest checkname left
  7780.  
  7781.               if pos("*",checkname) \= 0 then
  7782.                 do
  7783.                   retype = type
  7784.                   ret = dcl_function(rest)
  7785.  
  7786.                   if ret \= true then
  7787.                    do
  7788.                        result = false
  7789.                        return result
  7790.                    end
  7791.  
  7792.                   val = print_ret7(retype"%")
  7793.                   if val = true  then result = true
  7794.                   return result
  7795.               end
  7796.           end
  7797.  
  7798.  
  7799.           otherwise
  7800.            nop  /*Error in processing */
  7801.       end  /* select  for type*/
  7802.  
  7803. return result
  7804.  
  7805.  
  7806.  
  7807.          /*************************************
  7808.          * If the type is unsigned, then it              *
  7809.          * is necessary to read another word           *
  7810.          * for the type (return type or parmeter type)  *
  7811.          *************************************/
  7812.          process_rtype:
  7813.  
  7814.          parse arg rtype
  7815.  
  7816.  
  7817.          parse var rtype type type1 pname
  7818.          arr = ""
  7819.          dtypes = "int long char short"
  7820.  
  7821.  
  7822.            if pos("[",rtype) \= 0 & pos("*",rtype) = 0  then
  7823.             do
  7824.               arr = check_array(rtype)
  7825.             end
  7826.  
  7827.             else
  7828.               arr = ""
  7829.  
  7830.          select
  7831.             when pos("*",pname) \= 0 | right(type,1) = "*" then
  7832.               do
  7833.  
  7834.                 if pos("[",rtype) \= 0 then
  7835.                  do
  7836.                    arr = check_array(rtype)
  7837.                    arr = strip(arr)
  7838.                    type = arr" pointer"
  7839.                  end
  7840.  
  7841.                 else
  7842.                    type = "pointer"
  7843.               end
  7844.  
  7845.             when type = "int" | type = "long" then
  7846.                type = "fixed bin(31)"||arr
  7847.  
  7848.             when type = "short" then
  7849.                type = "fixed bin(15)"||arr
  7850.  
  7851.             when type = "void" then
  7852.                type = "    "
  7853.  
  7854.             when type = "char" then
  7855.               do
  7856.                if pos(",",arr) \= 0 then
  7857.                 type = "char"||arr
  7858.                else
  7859.  
  7860.                if pos(",",arr) = 0 & pos("(",arr) \= 0 then
  7861.                  do
  7862.                    parse var arr "dim" arr
  7863.                    parse var arr arr ")"
  7864.                    arr = arr||")"
  7865.                    arr = check_char(arr)
  7866.                    type = "char"||arr||" varyingz"
  7867.                  end
  7868.  
  7869.                 else
  7870.                    type = "char"
  7871.                end
  7872.       /********************************************
  7873.       * Process unsigned return types.         .                  *
  7874.       ********************************************/
  7875.  
  7876.  
  7877.             when type = "unsigned" then do
  7878.  
  7879.                select
  7880.                   when right(type1,1) = "*" then do
  7881.                     if pos("[",type1) \= 0 then
  7882.                       do
  7883.  
  7884.                        do while pos("*",type1) \= 0
  7885.                          parse var type1 type1 "*"
  7886.                        end
  7887.  
  7888.                        arr = check_array(type1)
  7889.                        arr = strip(arr)
  7890.                        type = arr" pointer"
  7891.                      end
  7892.  
  7893.                     else
  7894.                      type = "pointer"
  7895.                  end  /* Do */
  7896.  
  7897.                   when type1 = "int" | type1 = "long" then
  7898.                     type = "unsigned fixed bin(31)"||arr
  7899.  
  7900.                   when type1 = "short" then
  7901.                     type = "unsigned fixed bin(16)"||arr
  7902.  
  7903.  
  7904.                   when type1 = "char" then do
  7905.                      if pos(",",arr) \= 0 then
  7906.                        type = "char"||arr
  7907.                      else
  7908.  
  7909.                      if pos(",",arr) = 0 & pos("(",arr) \= 0 then
  7910.                        do
  7911.                          parse var arr "dim" arr
  7912.                          arr = check_char(arr)
  7913.                          type = "char"||arr||" varyingz"
  7914.                        end
  7915.  
  7916.                      else
  7917.                        type = "char"
  7918.                    end
  7919.  
  7920.                   when wordpos(type1,dtypes) = 0 & pos("[",type1) = 0 then
  7921.                    type = "unsigned fixed bin(31)"||arr
  7922.  
  7923.                otherwise
  7924.                  nop  /* okay to come here */
  7925.                end  /* select */
  7926.             end  /* Do */
  7927.  
  7928.        /********************************************
  7929.        * Process signed datatypes.               .                  *
  7930.        ********************************************/
  7931.  
  7932.              when type = "signed" then do
  7933.  
  7934.                select
  7935.                   when right(type1,1) = "*" then do
  7936.                     if pos("[",type1) \= 0 then
  7937.                       do
  7938.  
  7939.                        do while pos("*",type1) \= 0
  7940.                          parse var type1 type1 "*"
  7941.                        end
  7942.  
  7943.                        arr = check_array(type1)
  7944.                        arr = strip(arr)
  7945.                        type = arr" pointer"
  7946.                      end
  7947.  
  7948.                     else
  7949.                      type = "pointer"
  7950.                  end  /* Do */
  7951.  
  7952.  
  7953.                   when type1 = "int" | type1 = "long" then
  7954.                     type = "signed fixed bin(31)"||arr
  7955.  
  7956.                   when type1 = "short" then
  7957.                     type = "signed fixed bin(15)"||arr
  7958.  
  7959.  
  7960.                   when type1 = "char" then
  7961.                    type = "signed fixed bin(7)"||arr
  7962.  
  7963.                    when wordpos(type1,dtypes) = 0 & pos("[",type1) = 0 then
  7964.                    type = "signed fixed bin(31)"||arr
  7965.  
  7966.                otherwise
  7967.                  nop  /* okay to come here */
  7968.                end  /* select */
  7969.             end  /* Do */
  7970.       /********************************************
  7971.       * Process userdefined data types.       .                  *
  7972.       ********************************************/
  7973.  
  7974.            otherwise
  7975.                   type = "type "type" "arr
  7976.          end  /* select */
  7977.  
  7978.    return type
  7979.  
  7980.     /********************************************
  7981.     * Strip spaces in array dimensions.                         *
  7982.     ********************************************/
  7983.  
  7984.  process_array:
  7985.   parse arg v1
  7986.  
  7987.    len = length(v1)
  7988.    old = v1
  7989.    bpos = pos("[",v1)
  7990.  
  7991.    if bpos \= 0 then
  7992.       do
  7993.         endpos = lastpos("]",v1)
  7994.         arrpos = substr(v1,bpos,endpos)
  7995.         arrpos = space(arrpos,0)
  7996.         arrpos = strip(arrpos)
  7997.       end
  7998.  
  7999.     old1 = substr(v1,1,bpos-1)
  8000.     old1 = space(old1,1)
  8001.  
  8002.     old2 = substr(endpos,len)
  8003.     new = old1||arrpos||old2
  8004.  
  8005.   return new
  8006.  
  8007.     /******************************************************
  8008.     * Process the dimensions for array return types in parameter list *
  8009.     *******************************************************/
  8010.  
  8011. check_array:
  8012.  
  8013.     parse arg rtype1
  8014.     parse var rtype1 type type1 pname
  8015.     dtypes = "short long char int"
  8016.     arr = ""
  8017.  
  8018.      if pname = "]" & type1 \= "" then        /* unsig int[2][  ]  */
  8019.           do
  8020.             pname = ""
  8021.             type1 = type1||"]"
  8022.           end
  8023.  
  8024.          if pos("[",pname) \= 0 & type1 \= "" then  /* unsig int a1[3] */
  8025.           do
  8026.             parse var pname "[" pname
  8027.             type1 = type1||"["||pname
  8028.             pname = ""
  8029.           end
  8030.  
  8031.          if pname = "" then
  8032.           do
  8033.             if pos("[",type1) \= 0 then do   /* unsign int[3][4]  */
  8034.  
  8035.              if type = "unsigned" | type = "signed" then
  8036.               do
  8037.                parse var type1 type1 "[" arr
  8038.                arr = "["||arr
  8039.  
  8040.                if pos("][",arr) \= 0 then
  8041.                   do
  8042.                       arr= convert_bracket(arr)
  8043.                       arr = convert_finalbracket(arr)
  8044.                   end
  8045.                   arr = convert_finalbracket(arr)
  8046.  
  8047.              arr = " dim"||arr
  8048.              end
  8049.  
  8050.       /********************************************
  8051.       * Process array dimension for C datatypes.              *
  8052.       ********************************************/
  8053.  
  8054.              else if wordpos(type,dtypes) > 0 & pos("[",type1) \= 0 then
  8055.                do
  8056.                   parse var type1 "[" type1
  8057.                   arr= "["||type1
  8058.  
  8059.                  if pos("][",arr) \= 0 then
  8060.                   do
  8061.                       arr= convert_bracket(arr)
  8062.                       arr = convert_finalbracket(arr)
  8063.                   end
  8064.                   arr = convert_finalbracket(arr)
  8065.  
  8066.               arr = " dim"||arr
  8067.             end
  8068.       /******************************************************
  8069.       * Process array dimension for C userdefined datatypes.              *
  8070.       *******************************************************/
  8071.  
  8072.               else if wordpos(type,dtypes) = 0 & pos("[",type1) \= 0 then
  8073.                do
  8074.                   parse var type1 "[" type1
  8075.                   arr= "["||type1
  8076.  
  8077.                  if pos("][",arr) \= 0 then
  8078.                   do
  8079.                       arr= convert_bracket(arr)
  8080.                       arr = convert_finalbracket(arr)
  8081.                   end
  8082.  
  8083.                   arr = convert_finalbracket(arr)
  8084.               arr = " dim"||arr
  8085.             end
  8086.           end
  8087.  
  8088.             else
  8089.              if pos("[",type) \= 0  then   /* int[3] */
  8090.                do
  8091.                  bpos = pos("[",type)
  8092.                  if bpos \= 0 then
  8093.                   do
  8094.                    word = substr(type,1,bpos-1)
  8095.                  end
  8096.  
  8097.              if wordpos(word,dtypes) > 0 | wordpos(word,dtypes) = 0 then
  8098.                do
  8099.                  parse var type type "[" arr
  8100.                  arr = "["||arr
  8101.                  if pos("][",arr) \= 0 then
  8102.                   do
  8103.                       arr= convert_bracket(arr)
  8104.                       arr = convert_finalbracket(arr)
  8105.                   end
  8106.                   arr = convert_finalbracket(arr)
  8107.                   arr = " dim"||arr
  8108.               end
  8109.             end
  8110.            end
  8111.          return arr
  8112.  
  8113.  
  8114.          /*************************************
  8115.          * If the type is pointer, then process_pointer *
  8116.          * sets the pointer flag on.                     *
  8117.          *************************************/
  8118.  
  8119.  
  8120.          process_pointer:
  8121.          parse arg rest1
  8122.          parse var rest1 ptr_flag
  8123.  
  8124.           if ptr_flag = "*" then do
  8125.             ptr_flag = "on"
  8126.           end
  8127.            return ptr_flag
  8128.  
  8129.          /*************************************
  8130.          * If there exists a linkage convention then this*
  8131.          * routine sets the appropriate linkage.         *
  8132.          *************************************/
  8133.  
  8134.            process_linkconv:
  8135.  
  8136.            parse arg lcon
  8137.            parse var lcon calling_convention name
  8138.  
  8139.            if calling_convention = "_Far16" then
  8140.              do
  8141.                if wordpos(name,lc) > 0 then
  8142.                  do
  8143.                   name = strip(name)
  8144.                   calling_convention = calling_convention" "name
  8145.                  end
  8146.              end
  8147.  
  8148.            select
  8149.  
  8150.               when calling_convention = "_System" then
  8151.                 calling_convention = "options(linkage(system) byvalue nodescriptor)"
  8152.  
  8153.                when calling_convention = "_Pascal" then
  8154.                 calling_convention = "options(linkage(system) byvalue nodescriptor)"
  8155.  
  8156.               when calling_convention = "_Far16" | calling_convention =,
  8157.                 "_Far16 _Cdecl" then
  8158.                 calling_convention = "options(linkage(cdecl16) byvalue nodescriptor)"
  8159.  
  8160.               when calling_convention = "_Far16 _Pascal" then
  8161.                 calling_convention = "options(linkage(pascal16) byvalue nodescriptor)"
  8162.  
  8163.               when calling_convention = "_Far16 _Fastcall" then
  8164.                 calling_convention = "options(linkage(fastcall16) byvalue nodescriptor)"
  8165.  
  8166.               when calling_convention = "_Optlink" then
  8167.                 calling_convention = "options(linkage(optlink) byvalue nodescriptor)"
  8168.  
  8169.              otherwise
  8170.                calling_convention = calling_convention
  8171.           end  /* select */
  8172.       return calling_convention
  8173.  
  8174.  
  8175.  
  8176.       do_felse:
  8177.        parse arg type
  8178.        type = "%end; %else %do;"
  8179.       return type
  8180.  
  8181.   /************************************************************/
  8182.   /* Routine called by struct union enum and functions to process #ifdef  */
  8183.   /* as fields, or function parameters.                                                   */
  8184.   /************************************************************/
  8185.  
  8186.  
  8187.       do_functifdef:
  8188.  
  8189.        parse arg rest
  8190.        parse var rest extra name
  8191.  
  8192.  
  8193.  /*******************************************
  8194.  * Remove the __ prefix from constant names *
  8195.  *******************************************/
  8196.  
  8197.  if substr(name,1,1) = "_" then do
  8198.    name = check_name(name)
  8199.  end
  8200.  
  8201.  
  8202.     type = "%dcl "name" char ext;"
  8203.     type = type||" %if "name" ^= '' %then "
  8204.     type = type||"  %do;"
  8205. return  type
  8206.  
  8207.  /************************************************************/
  8208.  /* Routine called by struct union enum and functions to process #ifndef */
  8209.  /* as fields, or function parameters.                                                   */
  8210.  /************************************************************/
  8211.  
  8212.      do_functifndef:
  8213.  
  8214.       parse arg rest
  8215.       parse var rest extra name
  8216.  
  8217.  
  8218. /*******************************************
  8219. * Remove the __ prefix from constant names *
  8220. *******************************************/
  8221.  
  8222. if substr(name,1,1) = "_" then do
  8223.   name = check_name(name)
  8224. end
  8225.  
  8226.  
  8227.    type = "%dcl "name" char ext;"
  8228.    type = type||" %if "name" = '' %then "
  8229.    type = type||"  %do;"
  8230. return  type
  8231.  
  8232.  
  8233.  /************************************************************/
  8234.  /* Routine called by struct union enum and functions to process #if       */
  8235.  /* as fields, or function parameters.                                                   */
  8236.  /************************************************************/
  8237.  
  8238.      do_functif:
  8239.  
  8240.       parse arg rest
  8241.       parse var rest extra name
  8242.  
  8243.  
  8244. /*******************************************
  8245. * Remove the __ prefix from constant names *
  8246. *******************************************/
  8247.  
  8248. if substr(name,1,1) = "_" then do
  8249.   name = check_name(name)
  8250. end
  8251.  
  8252.  
  8253.    type = "%dcl "name" fixed ext;"
  8254.    type = type||" %if "name" ^= 0 %then "
  8255.    type = type||"  %do;"
  8256. return  type
  8257.  
  8258.  
  8259.          /**********************************************
  8260.          * Routine is used to process parameter types in function *
  8261.          * declaration.                                               *
  8262.          **********************************************/
  8263.  
  8264.  
  8265.       process_userdifftypes:
  8266.  
  8267.  
  8268.       parse arg difftypes
  8269.  
  8270.  
  8271.       /*******************************************************
  8272.       * Issue error message if mutiple function declarations are found.   *
  8273.       *******************************************************/
  8274.  
  8275.         if pos("(",difftypes) \= 0 then
  8276.           do
  8277.              out_line = z"%note('Error 22: Unsupported syntax encountered',4);"
  8278.              call do_writeout(out_line)
  8279.              out_line = z"/* Utility does not support multiple function declarations. */"
  8280.  
  8281.              call do_writeout(out_line)
  8282.              out_line = z"/* Error: "difftypes") */"
  8283.              call do_writeout(out_line)
  8284.  
  8285.              if cpos \= 0 then
  8286.                  call do_comment(comment)
  8287.  
  8288.              out_line = z"/* The original line in the .h file is: "line_num" */"
  8289.              call do_writeout(out_line)
  8290.  
  8291.              say "/* multiple funct decl not supported */"
  8292.              difftypes = z"/* "||difftypes||")"
  8293.              return  difftypes
  8294.           end
  8295.  
  8296.      if substr(difftypes,1,1) =  "#" then
  8297.       do
  8298.  
  8299.         select
  8300.            when substr(difftypes,1,6) = "#ifdef" then
  8301.               ptype = do_functifdef(difftypes)
  8302.  
  8303.            when substr(difftypes,1,7) = "#ifndef" then
  8304.              ptype = do_functifndef(difftypes)
  8305.  
  8306.            when substr(difftypes,1,3) = "#if" then
  8307.              ptype = do_functif(difftypes)
  8308.  
  8309.            when substr(difftypes,1,5) = "#else"  then
  8310.               ptype = do_felse(difftypes)
  8311.  
  8312.            when substr(difftypes,1,6) = "#endif" then
  8313.              ptype = "%end;"
  8314.            otherwise nop
  8315.       end
  8316.       return ptype
  8317.      end
  8318.       list = "enum struct union"
  8319.       list1 = "ENUM STRUCT UNION"
  8320.       if pos("*",difftypes) \= 0 & wordpos(list,difftypes) = 0 then
  8321.         do
  8322.            if pos("far",difftypes) \= 0 | pos("near",difftypes) \= 0 then
  8323.              difftypes= check_ptrtype(difftypes)
  8324.         end
  8325.  
  8326.      if translate(left(difftypes,1,5)) = "CONST" then
  8327.        parse var difftypes "const" difftypes
  8328.  
  8329.      if pos("[",difftypes) \= 0 then
  8330.        difftypes=process_array(difftypes)
  8331.  
  8332.       parse var difftypes param_type pname
  8333.  
  8334.       /****************************************************
  8335.       * Remove closing parenthesis from parameter type if last one. *
  8336.       ****************************************************/
  8337.  
  8338.        if pos(")",pname) \= 0 then
  8339.         do
  8340.           parse var pname pname ")"
  8341.         end  /* Do */
  8342.  
  8343.          if pos(")",param_type) \= 0 then
  8344.         do
  8345.           parse var param_type param_type ")"
  8346.         end  /* Do */
  8347.  
  8348.       /****************************************************************
  8349.       * Output the different parameter types depending on the different conditions.*
  8350.       *****************************************************************/
  8351.  
  8352.              select
  8353.                  when pos("...",param_type) \= 0 then
  8354.                    ptype = "*"
  8355.  
  8356.  
  8357.                  when right(param_type,1) = "*" then do
  8358.  
  8359.                    do while pos("*",param_type) \= 0
  8360.                      parse var param_type param_type "*"
  8361.                    end
  8362.  
  8363.                    if wordpos(param_type,datatypes) > 0 & pos("[",param_type) = 0 then
  8364.                       ptype = "pointer"
  8365.                    else
  8366.  
  8367.                    if wordpos(param_type,datatypes) = 0 & pos("[",param_type) = 0 then
  8368.                       ptype = "type @"param_type
  8369.  
  8370.                    else do
  8371.                       parse var param_type param_type "[" left
  8372.                       left = "["||left
  8373.  
  8374.                       if wordpos(param_type,datatypes) > 0 then
  8375.                        do
  8376.                          left = process_strtarray(left)
  8377.                          ptype = left" pointer"
  8378.                        end
  8379.  
  8380.                        else do
  8381.                          left = process_strtarray(left)
  8382.                          ptype = left" type @"param_type
  8383.                        end
  8384.  
  8385.                    end
  8386.                  end  /* Do */
  8387.  
  8388.  
  8389.                  when translate(param_type) = "CONST" then do
  8390.                     parse var pname param_type pname
  8391.  
  8392.                     if substr(pname,1,1) = "*" then
  8393.                       ptype = "pointer"
  8394.                     else
  8395.                     ptype = process_rtype(param_type)
  8396.  
  8397.                  end
  8398.  
  8399.  
  8400.                when (substr(pname,1,1) = "*" |  substr(pname,1,2) = "**" ) ,
  8401.                    & wordpos(param_type,datatypes) > 0 then do
  8402.                       pname = space(pname,0)
  8403.  
  8404.                      do while pos("*",pname) \= 0
  8405.                         parse var pname "*" pname
  8406.                      end
  8407.  
  8408.                      pname = process_strtarray(pname)
  8409.  
  8410.                      if pos("(",pname) \= 0 then
  8411.                        ptype = pname" pointer"
  8412.                      else
  8413.                      ptype = "pointer"
  8414.                 end
  8415.  
  8416.  
  8417.                 when translate(pname) = "FAR" | translate(pname) = "NEAR" then
  8418.                    ptype = "pointer"
  8419.  
  8420.  
  8421.                 when (pos("*",pname) \= 0 & wordpos(translate(param_type),list1) > 0 ) then do
  8422.                    parse var pname pname sname
  8423.  
  8424.                    if pos("*",pname) \= 0 then
  8425.                      do
  8426.  
  8427.                        do while pos("*",pname) \= 0
  8428.                          parse var pname pname "*"
  8429.                        end
  8430.                      end
  8431.  
  8432.                     if pos("[",sname) \= 0 then
  8433.                     do
  8434.                       sname = process_strtarray(sname)
  8435.                       pname = strip(pname)
  8436.                        if pos("_",pname) \= 0 then
  8437.                          pname = check_name(pname)
  8438.                       ptype = sname "handle "pname
  8439.                     end
  8440.  
  8441.                     else
  8442.                     if pos("[",sname) = 0 & pos("[",pname) \= 0 then
  8443.                      do
  8444.                       parse var pname pname "[" rest
  8445.                       rest = "["||rest
  8446.  
  8447.                       rest = process_strtarray(rest)
  8448.                       ptype = rest "handle "pname
  8449.                      end
  8450.  
  8451.                     else
  8452.                     if pos("[",sname) = 0 then
  8453.                       do
  8454.                        if pos("_",pname) \= 0 then
  8455.                          pname = check_name(pname)
  8456.                        ptype = "handle "pname
  8457.                      end
  8458.  
  8459.                 end
  8460.  
  8461.              /******************************
  8462.              * Process STRUCT parameter type  *
  8463.              ******************************/
  8464.  
  8465.                 when translate(param_type ) = "STRUCT" & pos(" ",pname) \= 0 then do
  8466.                   parse var pname pname sname temp
  8467.  
  8468.                     if pos("[",sname) \= 0 then
  8469.                     do
  8470.                       sname = process_strtarray(sname)
  8471.                       pname = strip(pname)
  8472.  
  8473.                        if pos("_",pname) \= 0 then
  8474.                          pname = check_name(pname)
  8475.  
  8476.                       ptype = "type "pname" "sname
  8477.                     end
  8478.  
  8479.                    else do
  8480.                    if pos("_",pname) \= 0 then
  8481.                       pname = check_name(pname)
  8482.                    ptype = "type "pname
  8483.                    end
  8484.                 end
  8485.  
  8486.                 when translate(param_type) = "STRUCT" & pos(" ",pname) = 0 then do
  8487.                    if pos("[",pname) \= 0 then
  8488.                     do
  8489.                       parse var pname str "[" pname
  8490.                       pname = "["||pname
  8491.                       pname = process_strtarray(pname)
  8492.  
  8493.                       str = strip(str)
  8494.                        if pos("_",str) \= 0 then
  8495.                          str = check_name(str)
  8496.  
  8497.                       ptype = "type "str" "pname
  8498.                     end
  8499.  
  8500.                     else do
  8501.                      if pos("_",pname) \= 0 then
  8502.                        pname = check_name(pname)
  8503.                       ptype = "type "pname
  8504.                     end
  8505.                    end
  8506.             /*****************************
  8507.             * Process ENUM parameter type    *
  8508.             *****************************/
  8509.  
  8510.  
  8511.                  when (pos("*",pname) \= 0)  & translate(param_type) = "ENUM" then do
  8512.  
  8513.                    parse var pname pname sname
  8514.                    if pos("*",pname) \= 0 then
  8515.                     do
  8516.                       do while pos("*",pname) \= 0
  8517.                          parse var pname pname "*"
  8518.                       end
  8519.                    end
  8520.  
  8521.                    ptype = "handle "pname
  8522.                 end
  8523.  
  8524.  
  8525.                 when pos(" ",pname) \= 0 & translate(param_type) = "ENUM" then do
  8526.                    parse var pname pname sname
  8527.  
  8528.                     if pos("[",sname) \= 0 then
  8529.                     do
  8530.                       sname = process_strtarray(sname)
  8531.                       pname = strip(pname)
  8532.  
  8533.                        if pos("_",pname) \= 0 then
  8534.                          pname = check_name(pname)
  8535.                       ptype = "ordinal "pname" "sname
  8536.                     end
  8537.  
  8538.                     else do
  8539.                       if pos("_",pname) \= 0 then
  8540.                         pname = check_name(pname)
  8541.                       ptype = "ordinal "pname
  8542.                    end
  8543.                 end
  8544.  
  8545.  
  8546.                   when translate(param_type) = "ENUM" & pos(" ",pname) = 0 then do
  8547.                    if pos("[",pname) \= 0 then
  8548.                      do
  8549.                       parse var pname str "[" pname
  8550.                       pname = "["||pname
  8551.  
  8552.                       pname = process_strtarray(pname)
  8553.                       str = strip(str)
  8554.  
  8555.                        if pos("_",str) \= 0 then
  8556.                          str = check_name(str)
  8557.  
  8558.                       ptype = "ordinal "str" "pname
  8559.                     end
  8560.  
  8561.                     else do
  8562.                      if pos("_",pname) \= 0 then
  8563.                        pname = check_name(pname)
  8564.                      ptype = "ordinal "pname
  8565.                     end
  8566.  
  8567.                   end
  8568.  
  8569.           /*****************************
  8570.           * Process UNION parameter type   *
  8571.           *****************************/
  8572.  
  8573.                 when (pos("*",pname) \= 0 | pos("**",pname) \= 0 )  & translate(param_type) = "UNION" then do
  8574.                    parse var pname pname sname
  8575.  
  8576.                    if pos("*",pname) \= 0 then do
  8577.                     do while pos("*",pname) \= 0
  8578.                        parse var pname pname "*"
  8579.                     end
  8580.  
  8581.                    end
  8582.                    ptype = "handle "pname
  8583.                 end
  8584.  
  8585.  
  8586.                 when pos(" ",pname) \= 0 & translate(param_type) = "UNION" then do
  8587.                      parse var pname pname sname
  8588.  
  8589.                       if pos("[",sname) \= 0 then
  8590.                        do
  8591.                          sname = process_strtarray(sname)
  8592.                          pname = strip(pname)
  8593.                          if pos("_",pname) \= 0 then
  8594.                            pname = check_name(pname)
  8595.                          ptype = "type "pname" "sname
  8596.                         end
  8597.  
  8598.                        else do
  8599.                         if pos("_",pname) \= 0 then
  8600.                           pname = check_name(pname)
  8601.                         ptype = "type "pname
  8602.                       end
  8603.                 end
  8604.  
  8605.  
  8606.  
  8607.                   when translate(param_type) = "UNION" & pos(" ",pname) = 0 then do
  8608.                      if pos("[",pname) \= 0 then
  8609.                         do
  8610.                           parse var pname str "[" pname
  8611.                           pname = "["||pname
  8612.                           pname = process_strtarray(pname)
  8613.                           str = strip(str)
  8614.  
  8615.                           if pos("_",str) \= 0 then
  8616.                             str = check_name(str)
  8617.                           ptype = "type "str" "pname
  8618.                        end
  8619.  
  8620.                     else do
  8621.                      if pos("_",pname) \= 0 then
  8622.                        pname = check_name(pname)
  8623.                      ptype = "type "pname
  8624.                     end
  8625.  
  8626.                    end
  8627.  
  8628.             /*************************************
  8629.            * Process pointer to userdefined data type.  *
  8630.            **************************************/
  8631.  
  8632.                  when substr(pname,1,1) = "*" & wordpos(param_type,datatypes) = 0 then do
  8633.                        if pos("_",param_type) \= 0 then
  8634.                         param_type = check_name(param_type)
  8635.  
  8636.                         if pos("[",pname) \= 0 then
  8637.                          do
  8638.                            parse var pname "[" rest
  8639.                            rest = "["||rest
  8640.                            rest = process_strtarray(rest)
  8641.                            ptype = rest "type @"param_type
  8642.                         end
  8643.  
  8644.                         else
  8645.                            ptype = "type @"param_type
  8646.                  end
  8647.  
  8648.  
  8649.                   when  ( param_type \= "long" & param_type \= "short" & param_type \= "char" ,
  8650.                     & param_type \= "unsigned" & param_type \= "signed" & param_type \= "PSZ" &,
  8651.                     param_type \= "int" ) & (substr(pname,1,1) \= "*" ) & right(param_type,1) ,
  8652.                     \= "*" & pos("[",param_type) = 0 & pos("[",pname) = 0 & param_type \= "void" then do
  8653.  
  8654.                       if pos("_",param_type) \= 0 then
  8655.                         param_type = check_name(param_type)
  8656.                       ptype = "type "param_type
  8657.                   end
  8658.  
  8659.  
  8660.                  /*****************************
  8661.                  * Process PSZ parameter type      *
  8662.                  *****************************/
  8663.  
  8664.  
  8665.                   when param_type = "PSZ" | param_type = "psz" then
  8666.                     ptype = "char (*) varyingz byaddr"
  8667.  
  8668.  
  8669.                   otherwise do
  8670.                    /********************************************
  8671.                   * Call process_rtype to process C intrinsic data type.  *
  8672.                   *********************************************/
  8673.  
  8674.  
  8675.                    if param_type = "unsigned" | param_type = "signed" then
  8676.                      do
  8677.                        parse var pname type1 pname
  8678.                        ptype = process_rtype(param_type" "type1" "pname)
  8679.                      end  /* Do */
  8680.                    else
  8681.                      ptype = process_rtype(param_type" "pname)
  8682.                   end
  8683.              end
  8684.       return ptype
  8685.  
  8686.  
  8687.  
  8688.  
  8689.   /**********************************************************
  8690.   * Process array dimension in STRUCT UNION ENUM (parameter type )  *
  8691.   **********************************************************/
  8692.  
  8693.  
  8694.  
  8695.  process_strtarray:
  8696.   parse arg st
  8697.  
  8698.   if pos("[",st) \= 0 then
  8699.   do
  8700.     parse var st temp "[" st
  8701.     st = "["||st
  8702.  
  8703.  
  8704.     if pos("][",st) \= 0 then
  8705.       do
  8706.         st= convert_bracket(st)
  8707.         st = convert_finalbracket(st)
  8708.       end
  8709.     st = convert_finalbracket(st)
  8710.     st = "dim"||st
  8711.  
  8712.   end
  8713.   return st
  8714.     /*****************************
  8715.     * Process far and near attributs.   *
  8716.     *****************************/
  8717.  
  8718.  
  8719.       check_ptrtype:
  8720.       parse arg info
  8721.  
  8722.       if pos("far",info) \= 0 then
  8723.         do
  8724.           parse var info info "far" left
  8725.           info = info||left
  8726.           info = strip(info)
  8727.           info = space(info,1)
  8728.          end
  8729.  
  8730.        if pos("near",info) \= 0 then
  8731.         do
  8732.           parse var info info "near" left
  8733.           info = info||left
  8734.           info = strip(info)
  8735.           info = space(info,1)
  8736.          end
  8737.     return info
  8738.  
  8739.          /*************************************************
  8740.          * If it is a legal calling convention, read in lines                *
  8741.          * until the close paren is encountered.  As lines are          *
  8742.          * read, parse them into parameter defintitions and output *
  8743.          * this as a PL/I function prototype.                                 *
  8744.          *************************************************/
  8745.  
  8746.          dcl_function:
  8747.          parse arg line
  8748.  
  8749.  
  8750.          line = space(line,1)
  8751.  
  8752.          if translate(count) = "COUNT" then
  8753.            count = 0
  8754.  
  8755.          cpos=pos("/*",line)
  8756.          if cpos \= 0 then
  8757.           do
  8758.              i = 0
  8759.              j = 0
  8760.              epos =pos('*/',line)
  8761.              len = epos - cpos
  8762.  
  8763.              comment.i.j = substr(line,cpos,len+2)
  8764.              rest = delstr(line,1,epos+1)
  8765.              rest = strip(rest)
  8766.  
  8767.              line = substr(line,1,cpos-1)
  8768.              if rest \= "" then
  8769.                line = line||rest
  8770.           end
  8771.  
  8772.           else do
  8773.            if comment.i.j = "" & substr(comment.i.j,1,7) = "COMMENT" then
  8774.              comment.i.j = ""
  8775.            line = line
  8776.           end
  8777.  
  8778.          if pos("{",line) \= 0 then
  8779.            do
  8780.               say "Executable st found or format not supported -- Program terminated"
  8781.               say "/*Approximate line of termination is expected to be line# "line_num "in the .h file*/"
  8782.  
  8783.               out_line = z"%note('Error 23: Unsupported syntax encountered',4);"
  8784.               call do_writeout(out_line)
  8785.               out_line = z"/* Utility does not support executable statements */"
  8786.               call do_writeout(out_line)
  8787.  
  8788.               out_line = z"/* or format encountered is not supported. */"
  8789.               call do_writeout(out_line)
  8790.               out_line = z"/* Error: "line" */"
  8791.               call do_writeout(out_line)
  8792.  
  8793.               if cpos \= 0 then
  8794.                 call do_comment(" "||comment.i.j)
  8795.  
  8796.               out_line = z"/* The original line in the .h file is: "line_num" */"
  8797.               call do_writeout(out_line)
  8798.               out_line = ""
  8799.               call do_writeout(out_line)
  8800.              exit
  8801.           end  /* Do */
  8802.  
  8803.  
  8804.          if substr(line,1,1) = "(" then
  8805.              do
  8806.                 say "this kind of funct decl is not supported"
  8807.  
  8808.                  out_line = z"%note('Error 24: Unsupported syntax encountered',4);"
  8809.                  call do_writeout(out_line)
  8810.                  out_line = z"/* Utility does not support this kind of func decl. */"
  8811.                  call do_writeout(out_line)
  8812.                  return false
  8813.             end
  8814.  
  8815.  
  8816.           ptype = ""
  8817.           len = pos("(",line)
  8818.           if substr(line,len+1,1) = "~" | (substr(line,len+1,1) = "" & substr(line,len+2,1) = "~")then
  8819.            do
  8820.               if substr(line,len+1,1) = "~" then
  8821.                 line = delstr(line,len+1,1)
  8822.               else
  8823.                 line = delstr(line,len+2,1)
  8824.            end
  8825.  
  8826.           paren = pos(")",line)
  8827.           len = lastpos("~",line)
  8828.           comma = pos(",",line)
  8829.           if len \= 0 & len > paren & comma < paren then
  8830.            do
  8831.              line = delstr(line,len,1)
  8832.            end
  8833.           parse var line name "(" param_type pname  "~" param ";"
  8834.  
  8835.  
  8836.           param_type =strip(param_type)
  8837.  
  8838.           if left(name,1) = "*" then
  8839.            do
  8840.               do while pos("*",name) \= 0
  8841.                 parse var name "*" name
  8842.               end /* do */
  8843.            end
  8844.  
  8845.  
  8846.           if substr(name,1,1) = "_" then
  8847.              name = check_name(name)
  8848.  
  8849.  
  8850.           if pos(");",param_type) \= 0 then
  8851.              parse var param_type param_type ")"
  8852.  
  8853.  
  8854.           if (param_type = "" & param = "" ) then param_type = ")"
  8855.           else
  8856.           if pos(")",param_type) \= 0 & pos("(",param_type) \= 0 then
  8857.             do
  8858.                say "this kind of parameter type in funct decl is not supported"
  8859.  
  8860.                 out_line = z"%note('Error 25: Unsupported syntax encountered',4);"
  8861.                 call do_writeout(out_line)
  8862.                 out_line = z"/* Utility does not support this kind of func decl. */"
  8863.                 call do_writeout(out_line)
  8864.  
  8865.                 out_line = z"/* Error: "line" */"
  8866.                 call do_writeout(out_line)
  8867.  
  8868.                 if cpos \= 0 then
  8869.                    call do_comment(comment)
  8870.  
  8871.                 out_line = z"/* The original line in the .h file is: "line_num" */"
  8872.                 call do_writeout(out_line)
  8873.                 out_line = ""
  8874.                 call do_writeout(out_line)
  8875.              return false
  8876.           end
  8877.  
  8878.  
  8879.           done = false
  8880.             out_line.0 = z"dcl "name" entry ("
  8881.             i = 0
  8882.             j = 0
  8883.             do while done = false
  8884.  
  8885.                if param_type = ")" | param_type = ");" then
  8886.                  do
  8887.                    out_line.0 = out_line.0" )"
  8888.                    call do_writeout(out_line.0)
  8889.                    out_line.0 = ""
  8890.  
  8891.                    if cpos \= 0 then do
  8892.                      comment.i.j = check_changes1(comment.i.j)
  8893.                      comment.i.j = z||comment.i.j
  8894.                      call do_comment(comment.i.j)
  8895.                    end   /* end for cpos */
  8896.  
  8897.                    if pos("(",param) \= 0 then
  8898.                     do
  8899.                        out_line = z"%note('Error 26: Unsupported syntax encountered',4);"
  8900.                        call do_writeout(out_line)
  8901.                        out_line = z"/* Utility does not support multiple function declarations. */"
  8902.  
  8903.                        call do_writeout(out_line)
  8904.                        out_line = z"/* Error: "param" */"
  8905.                        call do_writeout(out_line)
  8906.  
  8907.                        if cpos \= 0 then
  8908.                            call do_comment(" "||comment.i.j)
  8909.  
  8910.                        out_line = z"/* The original line in the .h file is: "line_num" */"
  8911.                        call do_writeout(out_line)
  8912.                        say "/* multiple funct decl not supported */"
  8913.                     end    /*   end for pos ("(" param) */
  8914.  
  8915.                    done = true
  8916.                    return true
  8917.                  end        /*   end for param_type = ")" | ");" */
  8918.  
  8919.  
  8920.  
  8921.                if param_type = "" & param = ")" then
  8922.                  do
  8923.                    len = lastpos(",",out_line.i)
  8924.                    if len \= 0 & pos("dim",out_line.i) = 0 then
  8925.                       out_line.i = delstr(out_line.i,len,1)
  8926.  
  8927.                    out_line.i = out_line.i" )"
  8928.  
  8929.                    done = true
  8930.                       do j = 0 to i+1
  8931.                          do k = 0 to count+1
  8932.                          if comment.j.k \= "" & substr(comment.j.k,1,7) \= "COMMENT" then
  8933.                              comment.j.k = check_changes1(comment.j.k)
  8934.  
  8935.                             if substr(out_line.j,1,8) \= "OUT_LINE" then
  8936.                               out_line.j = out_line.j
  8937.                            else
  8938.                               out_line.j = ""
  8939.  
  8940.                          if out_line.j \= "" then
  8941.                           do
  8942.                             out_line.j = do_indent(out_line.j)
  8943.                             call do_writeout(out_line.j)
  8944.                             out_line.j = ""
  8945.                           end   /* end for out_line.j \= "" */
  8946.  
  8947.                          if comment.j.k \= "" & substr(comment.j.k,1,7) \= "COMMENT" then
  8948.                             call do_writeout(comment.j.k)
  8949.                          comment.j.k =""
  8950.                         end    /* end for do k = 0 to count */
  8951.                       end     /* end for do j = 0 to i + 1 */
  8952.  
  8953.                    return true
  8954.                 end          /* end for param_type = "" & param = ) */
  8955.  
  8956.                else if param_type \= "" & param = ")" then
  8957.                  do
  8958.                    i = i + 1
  8959.                    orig_param = param_type" "pname
  8960.  
  8961.                    if pos(",",orig_param) \= 0 then
  8962.                     do
  8963.                        if pos(",",pname) \= 0 then
  8964.                         do
  8965.                          len = pos(",",pname)
  8966.                          pname = delstr(pname,len,1)
  8967.                         end     /* end for pos(",",pname) */
  8968.  
  8969.                        else
  8970.                        if pos(",",param_type) \= 0 then
  8971.                         do
  8972.                           len = pos(",",param_type)
  8973.                           param_type = delstr(param_type,len,1)
  8974.                        end  /* end for pos(",",param_type) */
  8975.  
  8976.                     end  /* end for pos(",",orig_param) */
  8977.  
  8978.                    ptype = process_userdifftypes(param_type" "pname)
  8979.                    out_line.i = z"       "ptype" "
  8980.                    out_line.i = overlay(")",out_line.i,length(out_line.i))
  8981.  
  8982.                    if pos("(",difftypes) \= 0 then
  8983.                     do
  8984.                        len = length(out_line.i)
  8985.                        out_line.i = delstr(out_line.i,len,1)
  8986.                        out_line.i = out_line.i||" */"
  8987.  
  8988.                        i = i - 1
  8989.                        len = length(out_line.i)
  8990.                        out_line.i = delstr(out_line.i,len,1)
  8991.                        out_line.i = overlay(")",out_line.i,length(out_line.i)+1)
  8992.                        i = i + 1
  8993.                     end         /* end for pos("(",difftypes) */
  8994.  
  8995.                    done = true
  8996.                    param_type = ""
  8997.  
  8998.                    do j = 0 to i+1
  8999.                      do k = 0 to count+1
  9000.  
  9001.                       if comment.j.k \= "" & substr(comment.j.k,1,7) \= "COMMENT" then
  9002.                           comment.j.k = check_changes1(comment.j.k)
  9003.  
  9004.                         if substr(out_line.j,1,8) \= "OUT_LINE" then
  9005.                            out_line.j = out_line.j
  9006.                         else
  9007.                           out_line.j = ""
  9008.  
  9009.                       if out_line.j \= "" then
  9010.                       do
  9011.                         out_line.j = do_indent(out_line.j)
  9012.                         call do_writeout(out_line.j)
  9013.                         out_line.j = ""
  9014.                       end  /* end for out_line.j \= "" */
  9015.  
  9016.                         if comment.j.k \= "" & substr(comment.j.k,1,7) \= "COMMENT" then
  9017.                             call do_writeout(" "||comment.j.k)
  9018.  
  9019.                       comment.j.k =""
  9020.                      end  /* end for do k = 0 to count */
  9021.                    end    /* end for j = 0 to i + 1 */
  9022.  
  9023.                   return true
  9024.                 end      /* end for param_type \= "" & param = ")" */
  9025.  
  9026.              i = i + 1
  9027.  
  9028.              if param = ")" then
  9029.                do
  9030.                    ptype = process_userdifftypes(param_type" "pname)
  9031.                    out_line.i = z"       "ptype" "
  9032.                    out_line.i = overlay(")",out_line.i,length(out_line.i))
  9033.                    done = true
  9034.                    param_type = ""
  9035.  
  9036.                    do j = 0 to i+1
  9037.                       do k = 0 to count+1
  9038.                       if comment.j.k \= "" & substr(comment.j.k,1,7) \= "COMMENT" then
  9039.                           comment.j.k = check_changes1(comment.j.k)
  9040.  
  9041.                      else   if substr(out_line.j,1,8) \= "OUT_LINE" then
  9042.                           out_line.j = out_line.j
  9043.                      else
  9044.                          out_line.j = ""
  9045.  
  9046.                      if out_line.j \= "" then
  9047.                         do
  9048.                           out_line.j = do_indent(out_line.j)
  9049.                           call do_writeout(out_line.j)
  9050.                           out_line.j = ""
  9051.                         end  /* end for out_line.j \= "" */
  9052.  
  9053.                        if comment.j.k \= "" & substr(comment.j.k,1,7) \= "COMMENT" then
  9054.                              call do_writeout(comment..kj)
  9055.  
  9056.                       comment.j =""
  9057.                     end   /* end for do k = 0 to count */
  9058.                    end    /* end for do j = 0 to i + 1 */
  9059.                  return true
  9060.                end        /* end for param = "(" */
  9061.  
  9062.              orig_param = param_type" "pname
  9063.              if pos(",",orig_param) \= 0 then
  9064.               do
  9065.                 if pos(",",pname) \= 0 then
  9066.                  do
  9067.                    len = pos(",",pname)
  9068.                    pname = delstr(pname,len,1)
  9069.                  end
  9070.                 else
  9071.                 if pos(",",param_type) \= 0 then
  9072.                   do
  9073.                    len = pos(",",param_type)
  9074.                    param_type = delstr(param_type,len,1)
  9075.                   end
  9076.              end   /* end for pos(",",orig_param) */
  9077.  
  9078.              if param_type \= ")" then do
  9079.                ptype = process_userdifftypes(param_type" "pname)
  9080.             end
  9081.              /********************************************
  9082.              * Subsequent lines indicate parameter names *
  9083.              ********************************************/
  9084.              if pos(",",orig_param) \= 0 then
  9085.               out_line.i = z"       "ptype","
  9086.             else
  9087.               out_line.i = z"       "ptype
  9088.  
  9089.  
  9090.              if pos("~",param) = 0 then
  9091.                do
  9092.                  parse var param param_type pname ")"
  9093.                  param = ")"
  9094.                end
  9095.  
  9096.               else
  9097.                 parse var param param_type pname  "~" param
  9098.  
  9099.              done = false
  9100.            end
  9101.  
  9102.           do j = 0 to i
  9103.              do k = 0 to count+1
  9104.             if pos("X",comment.j.k) \= 0 then
  9105.              out_line.j = check_changes1(comment.j.k)
  9106.             j = j + 1
  9107.           end /* do */
  9108.          end
  9109.  
  9110.  
  9111.             do j = 0 to i+1
  9112.               if out_line.j \= "" then
  9113.                do
  9114.                  out_line.j = do_indent(out_line.j)
  9115.                  call do_writeout(out_line.j)
  9116.                  out_line.j = ""
  9117.                end
  9118.                do k = 0 to count+1
  9119.                if comment.j.k \= "" & substr(comment.j.k,1,7) \= "COMMENT" then
  9120.                  call do_writeout(comment.j.k)
  9121.  
  9122.               comment.j.k =""
  9123.            end
  9124.           end
  9125.           j = 0
  9126.           i = 0
  9127.           comment. = ""
  9128.   return true
  9129.  
  9130.    /**********************************/
  9131.    /*check changes called by process_enum */
  9132.    /*to make sure comments are unchanged */
  9133.    /*********************************/
  9134.  
  9135. check_changes1:
  9136.  
  9137. parse arg st
  9138.  
  9139.   cpos = pos("/*",st)
  9140.   if cpos \= 0 then
  9141.     do
  9142.      comment = substr(st,cpos)
  9143.      st = delstr(st,cpos)
  9144.    end
  9145.    else
  9146.     comment = ""
  9147.  
  9148.  
  9149.  if pos("X",comment) \= 0 then
  9150.    do
  9151.       len = pos("X",comment)
  9152.       comment = overlay(")",comment,len)
  9153.    end
  9154.  st = st||comment
  9155. return st
  9156.  
  9157. /*************************************************************
  9158. *   This routine prints the appropriate return type: ptr & linkage convention *
  9159. **************************************************************/
  9160.  
  9161.  print_ret1:
  9162.      parse arg lc
  9163.      parse var lc  lc "%"
  9164.      done =""
  9165.  
  9166.      out_line1 = z"        returns(ptr byvalue)"
  9167.      out_line1 = do_indent(out_line1)
  9168.      call do_writeout(out_line1)
  9169.  
  9170.      out_line2 = z"         "lc" external;"
  9171.      out_line2 = do_indent(out_line2)
  9172.      call do_writeout(out_line2)
  9173.  
  9174.      out_line1 = ""
  9175.      out_line2 = ""
  9176.      done = true
  9177.   return done
  9178.  
  9179.  
  9180.  /***************************************************************
  9181. *   This routine prints the appropriate return type: ptr & no linkage convention *
  9182. ****************************************************************/
  9183.  
  9184.  print_ret2:
  9185.  
  9186.      done =""
  9187.      out_line1 = z"        returns(ptr byvalue)"
  9188.      out_line1 = do_indent(out_line1)
  9189.      call do_writeout(out_line1)
  9190.  
  9191.      out_line2 = z"          options (byvalue nodescriptor) external;"
  9192.      out_line2 = do_indent(out_line2)
  9193.      call do_writeout(out_line2)
  9194.      out_line1 = ""
  9195.      out_line2 = ""
  9196.  
  9197.      done = true
  9198.   return done
  9199.  
  9200.  
  9201. /***************************************************************
  9202. *   This routine prints the appropriate return type  &  linkage convention *
  9203. ****************************************************************/
  9204.  
  9205.  
  9206.  print_ret3:
  9207.  parse arg process
  9208.   parse var process retype "%" lc "%"
  9209.  
  9210.   done = ""
  9211.  
  9212.   if retype \= "" then
  9213.     do
  9214.        out_line1 = z"         returns( "retype" byvalue )"
  9215.        out_line1 = do_indent(out_line1)
  9216.        call do_writeout(out_line1)
  9217.    end
  9218.  
  9219.   out_line2 = z"          "lc" external;"
  9220.   out_line2 = do_indent(out_line2)
  9221.   call do_writeout(out_line2)
  9222.   out_line1 = ""
  9223.   out_line2 = ""
  9224.  
  9225.   done = true
  9226.  return done
  9227.  
  9228. /***************************************************************
  9229. *   This routine prints the appropriate return type:  & no linkage convention *
  9230. ****************************************************************/
  9231.  
  9232.   print_ret4:
  9233.   parse arg process
  9234.   parse var process retype "%"
  9235.  
  9236.   done = ""
  9237.  
  9238.    if retype \= "" then
  9239.     do
  9240.       out_line1 = z"         returns( "retype" byvalue)"
  9241.       out_line1 = do_indent(out_line1)
  9242.       call do_writeout(out_line1)
  9243.     end
  9244.  
  9245.    out_line2 = z"          options (byvalue nodescriptor) external;"
  9246.    out_line2 = do_indent(out_line2)
  9247.    call do_writeout(out_line2)
  9248.  
  9249.    out_line1 = ""
  9250.    out_line2 = ""
  9251.  
  9252.    done = true
  9253.  return done
  9254.  
  9255. /***************************************************************
  9256. *   This routine prints the appropriate return type: int &  linkage convention *
  9257. ****************************************************************/
  9258.  
  9259.  print_ret5:
  9260.   parse arg process
  9261.   parse var process lc "%"
  9262.  
  9263.    done = ""
  9264.  
  9265.     out_line1 = z"         returns( fixed bin(31) byvalue)"
  9266.     out_line1 = do_indent(out_line1)
  9267.     call do_writeout(out_line1)
  9268.  
  9269.     out_line2 = z"          "lc" external;"
  9270.     out_line2 = do_indent(out_line2)
  9271.     call do_writeout(out_line2)
  9272.  
  9273.     out_line1 = ""
  9274.     out_line2 = ""
  9275.  
  9276.   done = true
  9277.  return done
  9278.  
  9279. /***************************************************************
  9280. *   This routine prints the appropriate return type: int & no linkage convention *
  9281. ****************************************************************/
  9282.  
  9283.  
  9284.   print_ret6:
  9285.  
  9286.      done =""
  9287.  
  9288.      out_line1 = z"        returns( fixed bin(31) byvalue)"
  9289.      out_line1 = do_indent(out_line1)
  9290.      call do_writeout(out_line1)
  9291.  
  9292.      out_line2 = z"          options (byvalue nodescriptor) external;"
  9293.      out_line2 = do_indent(out_line2)
  9294.      call do_writeout(out_line2)
  9295.  
  9296.      out_line1 = ""
  9297.      out_line2 = ""
  9298.  
  9299.     done = true
  9300.   return done
  9301.  
  9302. /***************************************************************
  9303. *   This routine prints the appropriate return type  & no linkage convention *
  9304. ****************************************************************/
  9305.  
  9306.  
  9307.  print_ret7:
  9308.   parse arg process
  9309.   parse var process retype "%"
  9310.  
  9311.   done = ""
  9312.  
  9313.    out_line1 = z"         returns( byvalue optional type "retype" )"
  9314.    out_line1 = do_indent(out_line1)
  9315.    call do_writeout(out_line1)
  9316.  
  9317.    out_line2 = z"          options (byvalue nodescriptor) external;"
  9318.    out_line2 = do_indent(out_line2)
  9319.    call do_writeout(out_line2)
  9320.  
  9321.    out_line1 = ""
  9322.    out_line2 = ""
  9323.  
  9324.    done = true
  9325.  return done
  9326.  
  9327. /***************************************************************
  9328. *   This routine prints the appropriate return type  &  linkage convention *
  9329. ****************************************************************/
  9330.  
  9331.  
  9332.  print_ret8:
  9333.   parse arg process
  9334.   parse var process retype "%" lc "%"
  9335.  
  9336.   done = ""
  9337.    out_line1 = z"         returns( byvalue optional type "retype" )"
  9338.    out_line1 = do_indent(out_line1)
  9339.    call do_writeout(out_line1)
  9340.  
  9341.    out_line2 = z"          "lc" external;"
  9342.    out_line2 = do_indent(out_line2)
  9343.    call do_writeout(out_line2)
  9344.  
  9345.    out_line1 = ""
  9346.    out_line2 = ""
  9347.  
  9348.  
  9349.    done = true
  9350.  return done
  9351.  
  9352. /**************************************************************/
  9353. /* This routine processes functions that start with linkage conventions.      */
  9354. /**************************************************************/
  9355.  
  9356.  
  9357.  do_linkconventions:
  9358.  parse arg line
  9359.  parse var line type rest
  9360.  lc = " _Pascal _Fastcall _Cdecl "
  9361.  
  9362.      if wordpos(type,linkages) > 0  then
  9363.         do
  9364.  
  9365.           if type = "_Far16" then
  9366.             do
  9367.               old_val = rest
  9368.               parse var rest temp rest
  9369.               if wordpos(temp,lc) > 0 then
  9370.                  type = type" "temp
  9371.               else do
  9372.                  type = type
  9373.                  rest = old_val
  9374.               end
  9375.            end
  9376.  
  9377.  
  9378.            linkconv = process_linkconv(type)
  9379.            ret = dcl_function(rest)
  9380.  
  9381.            if ret \= true then
  9382.              do
  9383.                  result = false
  9384.                  return result
  9385.              end
  9386.  
  9387.            val =  print_ret5(linkconv"%")
  9388.            if val = true  then result = true
  9389.            return result
  9390.        end  /* Do */
  9391.   return result
  9392.  
  9393. /******************************************************************/
  9394. /* This routine processes functions that have nothing preceding the function name*/
  9395. /******************************************************************/
  9396.  
  9397.  
  9398.  do_funct:
  9399.   parse arg line
  9400.  
  9401.   if pos("(",line) \= 0 then
  9402.      do
  9403.          ret = dcl_function(line)
  9404.          if ret \= true then
  9405.            do
  9406.               result = false
  9407.               return result
  9408.            end
  9409.  
  9410.          val =  print_ret6()
  9411.          if val = true then result = true
  9412.          return result
  9413.      end  /* Do */
  9414.  return result
  9415.  
  9416. /******************************************************************/
  9417. /* This routine processes functions that have userdefined types for return types.  */
  9418. /******************************************************************/
  9419.  
  9420.   do_typefunct:
  9421.  
  9422.    parse arg line
  9423.     parse var line type rest
  9424.     rest = strip(rest)
  9425.  
  9426.    lc = " _Pascal _Fastcall _Cdecl "
  9427.        if wordpos(type,linkages) = 0 & wordpos(type,datatypes) = 0 then
  9428.           do
  9429.                if right(type,1) = "*" then do
  9430.                  checkname = "*"
  9431.                  parse var rest left
  9432.                end
  9433.  
  9434.                else
  9435.                  parse var rest checkname left
  9436.  
  9437.  
  9438.                   select
  9439.                       when pos("(",checkname) \= 0 & substr(checkname,1,1) \= "*" then do
  9440.                            retype = type
  9441.                            ret = dcl_function(rest)
  9442.  
  9443.                            if ret \= true then
  9444.                              do
  9445.                                result = false
  9446.                                return result
  9447.                              end
  9448.  
  9449.                            val = print_ret7(retype"%")
  9450.                            if val = true  then result = true
  9451.                            return result
  9452.                        end
  9453.  
  9454.  
  9455.                        when pos("(",checkname) = 0 & substr(checkname,1,1) \= "*" & substr(left,1,1) = "(" then do
  9456.                           retype = type
  9457.                           ret = dcl_function(rest)
  9458.  
  9459.                             if ret \= true then
  9460.                               do
  9461.                                 result = false
  9462.                                 return result
  9463.                              end
  9464.  
  9465.                             val = print_ret7(retype"%")
  9466.                            if val = true  then result = true
  9467.                            return result
  9468.                        end
  9469.  
  9470.  
  9471.                       when substr(checkname,1,1) = "*" & pos("(",checkname) \= 0 then do
  9472.                           checkname = delstr(checkname,1,1)
  9473.                           retype = type
  9474.                           rest = delstr(rest,1,1)
  9475.                           ret = dcl_function(rest)
  9476.  
  9477.                            if ret \= true then
  9478.                              do
  9479.                                result = false
  9480.                                return result
  9481.                              end
  9482.  
  9483.                           val =  print_ret2()
  9484.                           if val = true  then result = true
  9485.                           return result
  9486.                       end
  9487.  
  9488.  
  9489.                      when substr(checkname,1,1) = "*" & substr(left,1,1) = "(" then do
  9490.                           checkname1 = "*"
  9491.                           ptr_flag=process_pointer(checkname1)
  9492.                           checkname = delstr(checkname,1,1)
  9493.                           retype = type
  9494.  
  9495.                           retype = ""
  9496.                           rest = delstr(rest,1,1)
  9497.                           ret = dcl_function(rest)
  9498.  
  9499.                            if ret \= true then
  9500.                              do
  9501.                                result = false
  9502.                                return result
  9503.                              end
  9504.  
  9505.                           val =  print_ret2()
  9506.                           if val = true  then result = true
  9507.                           return result
  9508.                      end
  9509.       /*************************************
  9510.       * Process userdefined types with pointers.   *
  9511.       *************************************/
  9512.  
  9513.  
  9514.                      when checkname = "*" then do
  9515.                         ptr_flag=process_pointer(checkname)
  9516.                         parse var left token2 rest
  9517.  
  9518.                                 select
  9519.                                    when wordpos(token2,linkages) > 0 then do
  9520.                                      if token2 = "_Far16" then
  9521.                                        do
  9522.                                          old_val = rest
  9523.                                          parse var rest temp rest
  9524.  
  9525.                                          if wordpos(temp,lc) > 0 then
  9526.                                            token2 = token2" "temp
  9527.                                          else do
  9528.                                            token2 = token2
  9529.                                            rest = old_val
  9530.                                          end
  9531.  
  9532.                                        end
  9533.  
  9534.                                       linkconv = process_linkconv(token2)
  9535.                                       ret = dcl_function(rest)
  9536.  
  9537.                                       if ret \= true then
  9538.                                         do
  9539.                                           result = false
  9540.                                           return result
  9541.                                         end
  9542.  
  9543.                                       val = print_ret1(linkconv"%")
  9544.                                       if val = true  then result = true
  9545.                                       return result
  9546.                                    end  /* Do */
  9547.  
  9548.  
  9549.                                   when wordpos(token2,linkages) = 0 then do
  9550.                                       ret = dcl_function(left)
  9551.  
  9552.                                       if ret \= true then
  9553.                                         do
  9554.                                            result = false
  9555.                                            return result
  9556.                                         end
  9557.  
  9558.                                       val = print_ret2()
  9559.                                       if val = true  then result = true
  9560.                                       return result
  9561.                                    end /* token2 lc or funct */
  9562.  
  9563.                                end /* select */
  9564.  
  9565.                      end /* usertype * name */
  9566.  
  9567.  
  9568.                      when wordpos(checkname,linkages) > 0  then do
  9569.                          if checkname = "_Far16" then
  9570.                           do
  9571.                             old_val = left
  9572.                             parse var left temp left
  9573.  
  9574.                             if wordpos(temp,lc) > 0 then
  9575.                                checkname = checkname" "temp
  9576.                             else do
  9577.                                checkname = checkname
  9578.                                left = old_val
  9579.                              end
  9580.  
  9581.                           end
  9582.  
  9583.                           linkconv = process_linkconv(checkname)
  9584.                           retype = type
  9585.                           ret = dcl_function(left)
  9586.  
  9587.                            if ret \= true then
  9588.                             do
  9589.                                result = false
  9590.                                return result
  9591.                             end
  9592.  
  9593.                           val =  print_ret8(retype"%"linkconv"%")
  9594.                           if val = true  then result = true
  9595.                           return result
  9596.                       end  /* Do */ /* usertype lc name */
  9597.  
  9598.                     otherwise
  9599.                          nop  /* error in processing */
  9600.                   end /* select for pos("(",checkname */
  9601.  
  9602.          end /* wordpos  type linkages */
  9603.  
  9604.   return result
  9605.  
  9606. /******************************************************************/
  9607. /* This routine processes functions that have pointers for return types.            */
  9608. /******************************************************************/
  9609.  
  9610.  
  9611.  do_ptrfunct:
  9612.   parse arg line
  9613.   parse var line token1 other
  9614.   lc  = " _Pascal _Fastcall _Cdecl "
  9615.  
  9616.            if token1 = "*" then
  9617.              do
  9618.                 ptr_flag=process_pointer(token1)
  9619.                 parse var other token2 rest
  9620.  
  9621.  
  9622.                     select
  9623.                        when wordpos(token2,linkages) > 0 then do
  9624.  
  9625.                         if token2 = "_Far16" then
  9626.                          do
  9627.                            old_val = rest
  9628.                            parse var rest temp rest
  9629.  
  9630.                            if wordpos(temp,lc) > 0 then
  9631.                               token2 = token2" "temp
  9632.                            else do
  9633.                               token2 = token2
  9634.                               rest = old_val
  9635.                            end
  9636.  
  9637.                         end
  9638.  
  9639.  
  9640.                           linkconv = process_linkconv(token2)
  9641.                           ret = dcl_function(rest)
  9642.  
  9643.                           if ret \= true then
  9644.                            do
  9645.                              result = false
  9646.                              return result
  9647.                            end
  9648.  
  9649.                            val = print_ret1(linkconv"%")
  9650.                            if val = true  then result = true
  9651.                            return result
  9652.                        end  /* Do */
  9653.  
  9654.  
  9655.  
  9656.                        when pos("(",token2) \= 0 | substr(rest,1,1) = "(" then do
  9657.                           ret = dcl_function(other)
  9658.  
  9659.                           if ret \= true then
  9660.                             do
  9661.                               result = false
  9662.                               return result
  9663.                             end
  9664.  
  9665.                           val =  print_ret2()
  9666.                           if val = true  then result = true
  9667.                           return result
  9668.                        end  /* Do */
  9669.  
  9670.                        otherwise
  9671.                          nop   /* error  processing */
  9672.              end  /* select  token2*/
  9673.  
  9674.        end /* when token1 = * */
  9675.  
  9676.   return val
  9677.  
  9678.  
  9679. /***********************************************/
  9680. /* Subroutine to process a variable declaration. The data  */
  9681. /* type could be any user defined data type or any regular */
  9682. /* C data type.                                               */
  9683. /***********************************************/
  9684.  
  9685. process_var:
  9686.  
  9687.     types = "int long short char"
  9688.     scanline = " volatile "
  9689.     val = ""
  9690.     parse arg line
  9691.     parse arg rest
  9692.  
  9693.     do while pos("~",line) \= 0
  9694.        parse var line line "~" l1
  9695.        line = line||l1
  9696.     end
  9697.     rest = line
  9698.     def_val = ""
  9699.     cpos = pos("/*",line)
  9700.     if cpos \= 0 then
  9701.       do
  9702.         comment = substr(line,cpos)
  9703.         rest = delstr(rest,cpos)
  9704.      end  /* Do */
  9705.  
  9706.      if wordpos(scanline,rest) > 0 then
  9707.        do
  9708.          vpos=pos("volatile",rest)
  9709.          rest = overlay("abnormal",rest,vpos)
  9710.        end
  9711.  
  9712.  
  9713.     sdecl = pos(";",rest)
  9714.     origrest = rest
  9715.     rest = substr(rest,1,sdecl)
  9716.  
  9717.     mdecl = substr(origrest,sdecl + 1,cpos)
  9718.  
  9719.     if pos(";",mdecl) \= 0 & pos(" ",mdecl) \= 0 then
  9720.       do
  9721.         say "multiple decl not supported by this utility"
  9722.  
  9723.         out_line = z"%note('Error 27: Unsupported syntax encountered',4);"
  9724.         call do_writeout(out_line)
  9725.         out_line = z"/* This utility does not support multiple declarations. */"
  9726.         call do_writeout(out_line)
  9727.  
  9728.         out_line = z"/* Error: "rest" "mdecl "*/"
  9729.         call do_writeout(out_line)
  9730.  
  9731.         if cpos \= 0 then
  9732.            call do_comment(comment)
  9733.  
  9734.         out_line = z"/* The original line in the .h file is: "line_num" */"
  9735.         call do_writeout(out_line)
  9736.         out_line = ""
  9737.         call do_writeout(out_line)
  9738.         return
  9739.      end
  9740.   /******************************************
  9741.   * Issue error message for { braces.                      *
  9742.   ******************************************/
  9743.  
  9744.  
  9745.     if pos("{",rest) \= 0 & pos("=",rest) = 0 then
  9746.       do
  9747.            say "Executable st found or format not supported -- Program terminated"
  9748.            say "/*Approximate line of termination is expected to be line# "line_num "in the .h file*/"
  9749.  
  9750.            out_line = z"%note('Error 28: Unsupported syntax encountered',4);"
  9751.            call do_writeout(out_line)
  9752.            out_line = z"/* Utility does not support executable statements */"
  9753.            call do_writeout(out_line)
  9754.  
  9755.            out_line = z"/* or format encountered is not supported. */"
  9756.            call do_writeout(out_line)
  9757.            out_line = z"/* Error: "rest" */"
  9758.            call do_writeout(out_line)
  9759.  
  9760.            if cpos \= 0 then
  9761.              call do_comment(comment.i)
  9762.  
  9763.            out_line = z"/* The original line in the .h file is: "line_num" */"
  9764.            call do_writeout(out_line)
  9765.            out_line = ""
  9766.            call do_writeout(out_line)
  9767.         exit
  9768.       end
  9769.  
  9770.     /******************************************
  9771.    * Issue error message for initialization expression. *
  9772.    ******************************************/
  9773.  
  9774.  
  9775.       if pos("{",rest) \= 0 & pos("=",rest) \= 0 then
  9776.       do
  9777.            say "Initialization statement found or format not supported "
  9778.            say "/*Approximate line is expected to be line# "line_num "in the .h file*/"
  9779.  
  9780.            out_line = z"%note('Error 29: Unsupported syntax encountered',4);"
  9781.            call do_writeout(out_line)
  9782.            out_line = z"/* Utility does not support initialization statements */"
  9783.            call do_writeout(out_line)
  9784.  
  9785.            out_line = z"/* or format encountered is not supported. */"
  9786.            call do_writeout(out_line)
  9787.            out_line = z"/* Error: "rest" */"
  9788.            call do_writeout(out_line)
  9789.  
  9790.            if cpos \= 0 then
  9791.              call do_comment(comment.i)
  9792.  
  9793.            out_line = z"/* The original line in the .h file is: "line_num" */"
  9794.            call do_writeout(out_line)
  9795.            out_line = ""
  9796.            call do_writeout(out_line)
  9797.            return
  9798.       end
  9799.  
  9800.    /******************************************
  9801.   * Eliminate const from variable declarations.        *
  9802.   ******************************************/
  9803.  
  9804.  
  9805.    if substr(rest,1,6) = "const" then
  9806.     do
  9807.       parse var rest "const" rest
  9808.       rest = strip(rest)
  9809.     end
  9810.  
  9811.    kind2 = ""
  9812.    kind3 = ""
  9813.  
  9814.    /**********************************************
  9815.    * Issue error message for multiplevariable declarations.*
  9816.    **********************************************/
  9817.    rest = space(rest,1)
  9818.    parse var rest kind rest
  9819.  
  9820.    if pos("_",kind) \= 0 then
  9821.     kind = check_name(kind)
  9822.    if pos(",",rest) \= 0 & pos("[",rest) = 0 then
  9823.      do
  9824.         say "multiple decl not supported by this utility"
  9825.  
  9826.         out_line = z"%note('Error 30: Unsupported syntax encountered',4);"
  9827.         call do_writeout(out_line)
  9828.         out_line = z"/* This utility does not support multiple declarations. */"
  9829.         call do_writeout(out_line)
  9830.  
  9831.         out_line = z"/* Error: "rest" "mdecl "*/"
  9832.         call do_writeout(out_line)
  9833.  
  9834.         if cpos \= 0 then
  9835.            call do_comment(comment)
  9836.  
  9837.         out_line = z"/* The original line in the .h file is: "line_num" */"
  9838.         call do_writeout(out_line)
  9839.         out_line = ""
  9840.         call do_writeout(out_line)
  9841.        return
  9842.     end
  9843.  
  9844.   /***************************************************
  9845.   * Issue error message for user defined FAR and NEAR values. *
  9846.   ****************************************************/
  9847.  
  9848.  
  9849.    if left(rest,4) = "NEAR" | left(rest,3) ="FAR" then
  9850.      do
  9851.         out_line = z"%note('Error 31: Unsupported syntax encountered',4);"
  9852.         call do_writeout(out_line)
  9853.  
  9854.         say "Variable dcls with NEAR or FAR is not supported */"
  9855.         out_line = z"/* Declarations with NEAR or FAR are not supported. */"
  9856.         call do_writeout(out_line)
  9857.         out_line = z"/* Error: "rest" */"
  9858.         call do_writeout(out_line)
  9859.  
  9860.         if cpos \= 0 then
  9861.            call do_comment(comment)
  9862.  
  9863.         out_line = z"/* The original line in the .h file is: "line_num" */"
  9864.         call do_writeout(out_line)
  9865.         out_line = ""
  9866.         call do_writeout(out_line)
  9867.         return
  9868.     end
  9869.    /******************************************
  9870.   * Process if * exists for pointer declaration.         *
  9871.   ******************************************/
  9872.  
  9873.  
  9874.  
  9875.   if pos("*",kind) \= 0 | pos("*",rest) \= 0 then
  9876.     do
  9877.  
  9878.      select
  9879.          when left(rest,4) = "near" | left(rest,3) = "far" then do
  9880.            parse var rest attribute name val ";"
  9881.  
  9882.            if right(name,1) = "*" & pos("*",val) = 0 then
  9883.               name = val
  9884.  
  9885.            else if right(name,1) = "*" & pos("*",val) \= 0 then
  9886.              do
  9887.                name = name||val
  9888.                name = space(name,0)
  9889.                do while pos("*",name) \= 0
  9890.                  parse var name "*" name
  9891.                end
  9892.            end
  9893.  
  9894.  
  9895.            else if pos("*",name) \= 0 then
  9896.              do
  9897.                do while pos("*",name) \= 0
  9898.                  parse var name "*" name
  9899.                end
  9900.             end
  9901.  
  9902.  
  9903.           if substr(name,1,1) = "_" then
  9904.             name = check_name(name)
  9905.  
  9906.         end
  9907.  
  9908.  
  9909.      when pos("*",rest) \= 0 then
  9910.        do
  9911.           parse var rest "*" name val ";"
  9912.           if name = "abnormal" then
  9913.             name = val" "name
  9914.           else
  9915.  
  9916.           if right(name,1) = "*" then
  9917.              name=val
  9918.  
  9919.          if pos("*",name) \= 0 then
  9920.             do
  9921.               do while pos("*",name) \= 0
  9922.                 parse var name "*" name
  9923.               end
  9924.             end
  9925.           name = strip(name)
  9926.  
  9927.           if substr(name,1,1) = "_"  then
  9928.              name = check_name(name)
  9929.  
  9930.        end
  9931.  
  9932.  
  9933.       when pos("*",kind) \= 0 then do
  9934.          parse var rest name val ";"
  9935.  
  9936.          if substr(name,1,1) = "_" then
  9937.             name = check_name(name)
  9938.       end
  9939.  
  9940.       otherwise nop
  9941.     end  /* Do */
  9942.  
  9943.   /******************************************
  9944.   * Convert brackets to PL/I mapping.                     *
  9945.   ******************************************/
  9946.  
  9947.  
  9948.      if pos("][",name) \= 0 then
  9949.        do
  9950.          name= convert_bracket(name)
  9951.          name = convert_finalbracket(name)
  9952.        end
  9953.  
  9954.      name = convert_finalbracket(name)
  9955.  
  9956.      out_line1 = z"dcl "name" pointer;"
  9957.      call do_writeout(out_line1)
  9958.  
  9959.      if cpos \= 0 then
  9960.         call do_comment(comment)
  9961.    return
  9962.  end
  9963.  
  9964.  
  9965.    /**********************************************
  9966.    * If the kind is UNSIGNED, STATIC, or SIGNED,          *
  9967.    * then the kind consists of 2 words, so read              *
  9968.    * in another word                                           *
  9969.    **********************************************/
  9970.    if translate(kind) = "CONST" then
  9971.     parse var rest kind rest
  9972.  
  9973.    /********************************************
  9974.   * Issue error message for static variable declarations. *
  9975.   *********************************************/
  9976.  
  9977.  
  9978.  
  9979.    if translate(kind) = "STATIC" then
  9980.      do
  9981.        out_line = z"%note('Error 32: Unsupported syntax encountered',4);"
  9982.        call do_writeout(out_line)
  9983.  
  9984.        out_line = z"/* Error: Static variables are not supported. */"
  9985.        call do_writeout(out_line)
  9986.        out_line = z"/* Error: "rest" */"
  9987.        call do_writeout(out_line)
  9988.  
  9989.        if cpos \= 0 then
  9990.          call do_comment(comment)
  9991.  
  9992.       out_line = z"/* The original line in the .h file is: "line_num" */"
  9993.       call do_writeout(out_line)
  9994.       out_line = ""
  9995.       call do_writeout(out_line)
  9996.       return
  9997.     end
  9998.  
  9999.   /******************************************
  10000.   * Process for non pointer variable declarations.    *
  10001.   ******************************************/
  10002.  
  10003.  
  10004.    if kind = "unsigned" | kind = "signed"  then
  10005.       parse var rest kind2 rest
  10006.  
  10007.          if kind2 = "long" | kind2 = "short" then
  10008.             do
  10009.               parse var rest name '/*' other
  10010.               if substr(name,1,4) = "int " then
  10011.                   parse var name temp name
  10012.             end
  10013.  
  10014.  
  10015.         if kind2 = "int" | kind2 = "char" then
  10016.           do
  10017.             parse var rest name '/*' other
  10018.           end
  10019.  
  10020.  
  10021.         if kind = "unsigned" | kind = "signed" then
  10022.          do
  10023.            if wordpos(kind2,types) = 0 then
  10024.             do
  10025.               name = kind2
  10026.               kind2 = "int"
  10027.             end
  10028.         end
  10029.  
  10030.  
  10031.    if kind = "short" | kind = "long" | kind = "int" | kind = "char" then
  10032.     do
  10033.       parse var rest name '/*' other
  10034.  
  10035.       if substr(name,1,4) = "int " then
  10036.           parse var name temp name
  10037.       else
  10038.           parse var name name
  10039.    end
  10040.  
  10041.  
  10042.    if translate(kind) = "CONST" | translate(kind) = "EXTERN" then
  10043.       parse var rest kind name rest
  10044.  
  10045.  
  10046.    /*******************************************
  10047.    * All of the structures are converted      *
  10048.    * to unaligned PL/I structures which       *
  10049.    * are the equivalent of _Packed structures *
  10050.    *******************************************/
  10051.  
  10052.    if kind = "_Packed" then
  10053.       parse var rest kind rest
  10054.  
  10055.  
  10056.    /**********************************************
  10057.    * Separate comments from the rest of the line *
  10058.    **********************************************/
  10059.  
  10060.        if kind ="unsigned" | kind = "signed"  | kind = "_Packed" | kind = "long" | kind = "short" | kind = "int" | kind = "char" then
  10061.           nop
  10062.        else
  10063.           parse var rest name '/*' other
  10064.  
  10065.          name=space(name,0)
  10066.  
  10067.  
  10068.    /**********************************************************
  10069.    * Remove ';' from the line and convert square brackets to PL/I brackets*
  10070.    **********************************************************/
  10071.  
  10072.    parse var name name ';'
  10073.  
  10074.    if pos("][",name) \= 0 then
  10075.       do
  10076.         name= convert_bracket(name)
  10077.         name = convert_finalbracket(name)
  10078.       end
  10079.    name = convert_finalbracket(name)
  10080.  
  10081.  
  10082.  
  10083.  
  10084.    /******************************
  10085.    * Remove the _ prefix from names *
  10086.    ******************************/
  10087.  
  10088.    if substr(name,1,1) = "_"  then
  10089.       name = check_name(name)
  10090.  
  10091.   /*********************************************************
  10092.   * If kind or kind2 is of character data then routine process_char is    *
  10093.   * invoked to handle all cases of character variable declaration else the *
  10094.   * routine do_define_var is called to prcocess all other variable         *
  10095.   * declarations.                                                            *
  10096.   *********************************************************/
  10097.  
  10098.  
  10099.          if kind2 = "char" | kind = "char" then
  10100.            do
  10101.               name=space(name,0)
  10102.  
  10103.               select
  10104.                   when kind = "char" then do
  10105.                      def_val = name
  10106.                      call process_char(def_val);
  10107.                   end
  10108.  
  10109.                   when kind2 = "char" then do
  10110.                      def_val = name" "kind" "kind2
  10111.                      call do_define_var(def_val)
  10112.                   end  /* Do */
  10113.  
  10114.                  otherwise
  10115.                     nop /* okay to come here */
  10116.               end
  10117.          end
  10118.  
  10119.    /*********************************************************
  10120.   * call do_define_var to process any other data type other then char. *
  10121.   **********************************************************/
  10122.  
  10123.  
  10124.          else do
  10125.             define_string = name" "kind" "kind2
  10126.             call do_define_var(define_string)
  10127.          end
  10128.  
  10129.      if cpos \= 0 then
  10130.         call do_comment(comment)
  10131.  
  10132.   return
  10133.  
  10134.   /************************************************************/
  10135.   /*   Remove 0: from character arrays with varyingz syntax.                 */
  10136.   /************************************************************/
  10137.  
  10138.   check_char:
  10139.   parse arg ar1
  10140.  
  10141.   parse var ar1 ar1 "(" rest
  10142.   if substr(rest,1,1) = 0 then
  10143.    do
  10144.      len = length(rest)
  10145.      rest = delstr(rest,1,2)
  10146.      ar1 = "("||rest
  10147.   end
  10148. return ar1
  10149.  
  10150.   /************************************************************/
  10151.   /*   Subroutine to process all character variable declarations.            */
  10152.   /************************************************************/
  10153.  
  10154.   process_char:
  10155.  
  10156.    parse arg rest
  10157.     parse var rest name other
  10158.  
  10159.      if substr(name,1,1) = "*" | substr(name,1,2) = "**" then
  10160.       do
  10161.        select
  10162.  
  10163.           when substr(name,1,2) = "**" & pos("(",name) = 0 then do
  10164.            name = delstr(name,1,2)
  10165.            val = "pointer"
  10166.           end
  10167.  
  10168.  
  10169.          when substr(name,1,1) = "*" & pos("(",name) = 0 then do
  10170.            name = delstr(name,1,1)
  10171.            val="pointer"
  10172.          end
  10173.  
  10174.  
  10175.       otherwise
  10176.   /**********************************************/
  10177.   /*   Issue error message for unsupported syntax         */
  10178.   /**********************************************/
  10179.  
  10180.           if pos("(",name) \= 0 & pos("*",name) \=0  then
  10181.             do
  10182.                  say "this kind of definition is not supported"
  10183.                  out_line = z"%note('Error 33: Unsupported syntax encountered',4);"
  10184.                  call do_writeout(out_line)
  10185.  
  10186.                  out_line = z"/* Utility does not support this kind of definition. */"
  10187.                  call do_writeout(out_line)
  10188.                  out_line = z"/* Error: "line" */"
  10189.                  call do_writeout(out_line)
  10190.  
  10191.                  if cpos \= 0 then
  10192.                    call do_comment(comment)
  10193.  
  10194.                  out_line = z"/* The original line in the .h file is: "line_num" */"
  10195.                  call do_writeout(out_line)
  10196.                  out_line = ""
  10197.                  call do_writeout(out_line)
  10198.               return
  10199.            end  /* Do */
  10200.  
  10201.       end  /* select */
  10202.    end  /* Do */
  10203.  
  10204.     if pos("(",name) = 0 & val \= "pointer" then
  10205.        out_line1= z"dcl "name" char;"
  10206.  
  10207.     else if pos("(",name) = 0 & val = "pointer" then
  10208.        out_line1= z"dcl "name" pointer;"
  10209.  
  10210.     else
  10211.     if pos(',',name) = 0 then
  10212.        do
  10213.          lpos = pos('(',name)
  10214.          bounds = substr(name,lpos)
  10215.          name = substr(name,1,(lpos - 1))
  10216.          bounds = check_char(bounds)
  10217.          if pos("(",bounds) = 1  then
  10218.           do
  10219.             len = pos("(",bounds)
  10220.             if substr(bounds,len+1,1) = ")" then
  10221.               bounds = "(*)"
  10222.           end
  10223.  
  10224.          out_line1= z"dcl "name" character "bounds" varyingz;"
  10225.        end
  10226.  
  10227.        else
  10228.            out_line1 = z"dcl "name" char;"
  10229.  
  10230.  
  10231.  
  10232.    /***********************************
  10233.    * Output the definition statements *
  10234.    ***********************************/
  10235.  
  10236.    out_line1 = do_indent(out_line1)
  10237.    call do_writeout(out_line1)
  10238.  
  10239.  
  10240.    /************************************
  10241.    * If there was a comment at the end *
  10242.    * of the line, convert it           *
  10243.    ************************************/
  10244.  
  10245.  return
  10246.  
  10247.  
  10248.  
  10249. /*******************************************************/
  10250. /* subroutine to process all other variable declarations               */
  10251. /*******************************************************/
  10252.   do_define_var:
  10253.    parse arg rest
  10254.  
  10255.     parse var rest name val
  10256.  
  10257.     if name = "*" then
  10258.      do
  10259.        parse var rest ptr name val
  10260.        name = ptr||name
  10261.      end
  10262.  
  10263.    /**********************************************
  10264.    * Separate comments from the rest of the line *
  10265.    **********************************************/
  10266.  
  10267.    parse var val val "/*" other
  10268.    val = strip(val)
  10269.    h_val = "char"
  10270.  
  10271.  
  10272.    /********************************
  10273.    * Check for pointer definition  *
  10274.    * by looking for a *            *
  10275.    ********************************/
  10276.  
  10277.    if substr(name,1,1) = "*" | substr(name,1,2) = "**" then
  10278.     do
  10279.       select
  10280.  
  10281.           when substr(name,1,2) = "**" & pos("(",name) = 0 then do
  10282.             name = delstr(name,1,2)
  10283.             if substr(name,1,1) = "_" then
  10284.               name = check_name(name)
  10285.             val = "pointer"
  10286.           end
  10287.  
  10288.  
  10289.          when substr(name,1,1) = "*" & pos("(",name) = 0 then do
  10290.             name = delstr(name,1,1)
  10291.             if substr(name,1,1) = "_" then
  10292.               name = check_name(name)
  10293.             val="pointer"
  10294.          end
  10295.  
  10296.          otherwise
  10297.  
  10298.          if pos("(",name) \= 0 & pos("*",name) \=0  then
  10299.           do
  10300.                 say "this kind of definition is not supported"
  10301.  
  10302.                 out_line = z"%note('Error 34: Unsupported syntax encountered',4);"
  10303.                  call do_writeout(out_line)
  10304.                  out_line = z"/* Utility does not support this kind of definition. */"
  10305.                  call do_writeout(out_line)
  10306.  
  10307.                  out_line = z"/* Error: "rest" */"
  10308.                  call do_writeout(out_line)
  10309.  
  10310.                  if cpos \= 0 then
  10311.                    call do_comment(comment)
  10312.  
  10313.                  out_line = z"/* The original line in the .h file is: "line_num" */"
  10314.                  call do_writeout(out_line)
  10315.                  out_line = ""
  10316.                  call do_writeout(out_line)
  10317.            return
  10318.         end  /* Do */
  10319.  
  10320.  
  10321.       end  /* select */
  10322.    end  /* Do */
  10323.  
  10324.  
  10325.  
  10326.       /*****************************************
  10327.       * Check to see if the value is                       *
  10328.       * one which must be uniquely defined               *
  10329.       *****************************************/
  10330.       val = special_value(val)
  10331.       if substr(val,1,1) = "_" then
  10332.          val = check_name(val)
  10333.  
  10334.       if pos("abnormal",name) \= 0 then
  10335.         do
  10336.           parse var name "abnormal" name
  10337.           name = name||" abnormal"
  10338.         end
  10339.  
  10340.       /***************************************
  10341.       * Defines the appropriate output statements.     *
  10342.       ***************************************/
  10343.        if flag = "typedval" then
  10344.         do
  10345.           out_line1 = z"dcl "name" type "val";"
  10346.         end
  10347.  
  10348.        else
  10349.         out_line1 = z"dcl "name" "val";"
  10350.  
  10351.  
  10352.    /***********************************
  10353.    * Output the definition statements           *
  10354.    ***********************************/
  10355.  
  10356.    out_line1 = do_indent(out_line1)
  10357.    call do_writeout(out_line1)
  10358.  
  10359.  
  10360.    /************************************
  10361.    * If there was a comment at the end         *
  10362.    * of the line, convert it                       *
  10363.    ************************************/
  10364. return
  10365.  
  10366.  
  10367.  
  10368.  
  10369.  
  10370.  
  10371.    /********************************************************************
  10372.    *   Subroutine to indent a line                                     *
  10373.    ********************************************************************/
  10374.  
  10375. do_indent:
  10376.    parse arg line
  10377.  
  10378.    if indent <= 0 then return line
  10379.  
  10380.  
  10381.    /**************************************************
  10382.    * Indent indentation number or spaces for each                 *
  10383.    * value of indent.  If indentation = 3 and indent               *
  10384.    * = 4 then indent 12 spaces.                                    *
  10385.    **************************************************/
  10386.  
  10387.    do indent
  10388.       line = indentation||line
  10389.    end
  10390. return line
  10391.  
  10392.  
  10393.  
  10394.  
  10395.  
  10396.  
  10397.  
  10398.  
  10399.  
  10400.  
  10401.  
  10402.    /********************************************************************
  10403.    *   Subroutine to handle a special value in a declaration           *
  10404.    ********************************************************************/
  10405.  
  10406. special_value:
  10407.   parse arg val
  10408.    flag =""
  10409.    flag_pointer = ""
  10410.  
  10411.          /***********************************
  10412.          * This is the PL/I syntax for the different *
  10413.          * linkage convention                             *
  10414.          ***********************************/
  10415.  
  10416.    select
  10417.       when val = "_Optlink" then
  10418.          val = "options(linkage (optlink) byvalue nodescriptor) "
  10419.  
  10420.       when val = "_Far16 _Pascal" then
  10421.          val = "options(linkage (pascal16) byvalue nodescriptor) "
  10422.  
  10423.       when val = "_Far16 _Fastcall" then
  10424.          val = "options(linkage (fastcall16) byvalue nodescriptor) "
  10425.  
  10426.       when val = "_Far16 _Cdecl" | val = "_Far16" then
  10427.          val = "options(linkage (cdecl16) byvalue nodescriptor) "
  10428.  
  10429.       when val = "* _Seg16" then
  10430.          val = "pointer segmented"
  10431.  
  10432.         /*****************************************
  10433.          * This is the PL/I syntax for the System *
  10434.          * linkage convention                     *
  10435.          *****************************************/
  10436.       when val = "_System" then
  10437.          val = "options(linkage(system) byvalue nodescriptor) "
  10438.  
  10439.        when val = "_Pascal" then
  10440.          val = "options(linkage(pascal) byvalue nodescriptor) "
  10441.  
  10442.       when val = "void" then
  10443.          val = " "
  10444.  
  10445.       when val = "void far *" | val = "void *" | val = "void near *" ,
  10446.        | val = "far" | val = "near" | val = "void*" then do
  10447.          val = " pointer"
  10448.          flag_pointer = true
  10449.       end
  10450.  
  10451.          /*******************************************
  10452.          * This is the PL/I mapping for different C data types*
  10453.          * linkage convention                                            *
  10454.          ********************************************/
  10455.  
  10456.       when val = "unsigned" | val = "unsigned long" | val = "unsigned int" then
  10457.          val = "unsigned fixed bin(31)"
  10458.  
  10459.       when val = "unsigned short"   then
  10460.          val = "unsigned fixed bin(16)"
  10461.  
  10462.       when val = "long" then
  10463.          val = "fixed bin(31)"
  10464.  
  10465.       when val = "short" then
  10466.          val = "fixed bin(15)"
  10467.  
  10468.       when val = "int" then
  10469.          val = "fixed bin(31)"
  10470.  
  10471.       when val = "unsigned char" then
  10472.          val = "char"
  10473.  
  10474.       when val = "signed char" then
  10475.          val = "signed fixed bin(7)"
  10476.  
  10477.       when val = "signed int" | val = "signed long" | val= "signed"  then
  10478.          val = "signed fixed bin(31)"
  10479.  
  10480.       when val = "signed short" then
  10481.          val = "signed fixed bin(16)"
  10482.  
  10483.       when val = "char" then
  10484.          val = "char"
  10485.  
  10486.        when val \= "pointer" then flag = "typedval"
  10487.  
  10488.       otherwise
  10489.          nop
  10490.    end
  10491.  return val
  10492.  
  10493.  
  10494.  
  10495.  
  10496.  
  10497.  
  10498.  
  10499.  
  10500.  
  10501.  
  10502.  
  10503.    /********************************************************************
  10504.    *   Subroutine to handle a definition with parens                   *
  10505.    ********************************************************************/
  10506.  
  10507.  do_paren:
  10508.    flag_PSZ = false
  10509.    parse arg name, val
  10510.    parse var val tilda "(" val
  10511.    val = strip(val)
  10512.  
  10513.    len = length(name)
  10514.    select
  10515.  
  10516.  
  10517.       /*******************************************
  10518.       * If there is a left paren in the name,    *
  10519.       * then assume it is a macro definition.    *
  10520.       * Macros are not converted by this utility *
  10521.       *******************************************/
  10522.  
  10523.       when pos("(", name) \= 0 then do
  10524.          out_line = z"%note('Error 35: Unsupported syntax encountered',4);"
  10525.          call do_writeout(out_line)
  10526.  
  10527.          out_line = z"/* Macros are not supported by this utility. */ "
  10528.          call do_writeout(out_line)
  10529.  
  10530.          out_line = z"/* Error: "name" "val"  */"
  10531.          call do_writeout(out_line)
  10532.  
  10533.          if cpos \= 0 then
  10534.             call do_comment(comment)
  10535.  
  10536.          out_line = z"/* The original line in the .h file is: "line_num" */"
  10537.          call do_writeout(out_line)
  10538.          out_line = ""
  10539.          call do_writeout(out_line)
  10540.          val = done
  10541.       end
  10542.  
  10543.  
  10544.       /***************************************
  10545.       * If there is a * in the value, assume *
  10546.       * it is a pointer definition           *
  10547.       ***************************************/
  10548.  
  10549.       when pos("*",val) \= 0 then
  10550.          val = pointer
  10551.  
  10552.  
  10553.       /***********************************************
  10554.       * If the line defines a PSZ whith a hex value, *
  10555.       * remove the parens                            *
  10556.       ***********************************************/
  10557.  
  10558.       when pos("PSZ", val) \= 0 & pos("0X", val) \= 0 then do
  10559.         parse var val "PSZ)" val ")"
  10560.           flag_PSZ = true
  10561.       end
  10562.  
  10563.       /**************************************************
  10564.       * If the value is simply enclosed in parens, just *
  10565.       * convert it                                      *
  10566.       **************************************************/
  10567.  
  10568.       when substr(val,1,1) = "(" then do
  10569.          parse var val "(" val ")" num ")"
  10570.          val = special_value(val)
  10571.          num = strip(num)
  10572.          out_line = z"dcl "name" value ("num")" val";"
  10573.          out_line = do_indent(out_line)
  10574.          call do_writeout(out_line)
  10575.          val = done
  10576.        end
  10577.  
  10578.  
  10579.       /***************************************
  10580.       * Change the ~ to a ^ to conform with  *
  10581.       * PL/I syntax                          *
  10582.       ***************************************/
  10583.  
  10584.       when tilda = "~" then
  10585.          val = "^("val
  10586.  
  10587.  
  10588.       /*******************************************
  10589.       * If the value contains an underscore or   *
  10590.       * defines a USHORT, then remove the parens *
  10591.       *******************************************/
  10592.  
  10593.       when substr(val,1,1) = "-" then
  10594.          parse var val val ")"
  10595.  
  10596.       /***************************************
  10597.       * Otherwise put the left paren back in *
  10598.       ***************************************/
  10599.  
  10600.       otherwise do
  10601.          val = "("val
  10602.       end
  10603.    end
  10604.  
  10605.  
  10606. /*************************************
  10607. * Return the new value as determined *
  10608. * by this function                   *
  10609. *************************************/
  10610.  
  10611.  return val
  10612.  
  10613.  
  10614.  
  10615.  
  10616.  
  10617.  
  10618.  
  10619.  
  10620.  
  10621.  
  10622.  
  10623.    /********************************************************************
  10624.    *   Subroutine to interpret the condition of an if statement        *
  10625.    ********************************************************************/
  10626.  
  10627. define_command:
  10628.    parse arg com
  10629.  
  10630.  
  10631.    /*************************************
  10632.    * Check for defined and !defined as  *
  10633.    * conditions for the if statement    *
  10634.    *************************************/
  10635.  
  10636.    if translate(com) = "DEFINED" | translate(com) = "(DEFINED" then
  10637.       newcom = " ^= ''"
  10638.    else if translate(com) = "!DEFINED" | translate(com) = "(!DEFINED" then
  10639.       newcom = " = ''"
  10640.  
  10641.  
  10642.    /**********************************************
  10643.    * If they are not found, keep the C condition *
  10644.    **********************************************/
  10645.  
  10646.    else
  10647.       newcom = com
  10648. return newcom
  10649.  
  10650.  
  10651.  
  10652.  
  10653.  
  10654.  
  10655.    /********************************************************************
  10656.    *   Subroutine to ignore the #error statement                       *
  10657.    ********************************************************************/
  10658.  
  10659. do_error:
  10660.    parse arg rest
  10661.    cpos = pos("/*",rest)
  10662.          if cpos \= 0 then do
  10663.            comment = substr(rest,cpos)
  10664.            rest = delstr(rest,cpos)
  10665.          end
  10666.  
  10667.    say
  10668.    say "The #Error command is not converted by this utility"
  10669.    say "#Error "rest
  10670.  
  10671.    out_line = z"%note('Error 36: Unsupported syntax encountered',4);"
  10672.    call do_writeout(out_line)
  10673.    out_line = z"/* This definition is not supported by this utility. */ "
  10674.    call do_writeout(out_line)
  10675.    out_line = z"/* Error: #Error "rest"*/"
  10676.    call do_writeout(out_line)
  10677.  
  10678.    if cpos \= 0 then
  10679.       call do_comment(comment)
  10680.  
  10681.    out_line = z"/* The original line in the .h file is: "line_num" */"
  10682.    call do_writeout(out_line)
  10683.    out_line = ""
  10684.    call do_writeout(out_line)
  10685. return
  10686.  
  10687.  
  10688.  
  10689.  
  10690.  
  10691.  
  10692.  
  10693.  
  10694.  
  10695.  
  10696.  
  10697.    /********************************************************************
  10698.    *   Subroutine to handle a struct statement or entire declaration of structures unions *                        *
  10699.    ********************************************************************/
  10700.  
  10701. do_real_struct:
  10702.  
  10703.  
  10704.    /**************************************************
  10705.    * Start the structure conversion process          *
  10706.    * if a struct statement is used instead of        *
  10707.    * a typedef struct statement.  This is similar to *
  10708.    * the struct case in the do_typedef function      *
  10709.    **************************************************/
  10710.    parse arg rest
  10711.    scanline = "volatile"
  10712.  
  10713.    rest = check_ptrtype(rest)
  10714.    if pos("(",rest) \= 0 then
  10715.      do
  10716.          cpos = pos("/*",rest)
  10717.          if cpos \= 0 then
  10718.           do
  10719.             line = substr(rest,1,cpos-1)
  10720.             comment = delstr(rest,cpos)
  10721.          end
  10722.  
  10723.          else line = rest
  10724.  
  10725.  
  10726.          if  pos(";",line) = 0 then
  10727.            do
  10728.              line1 = linein(inputfile)
  10729.              line_num = line_num + 1
  10730.  
  10731.              cpos = pos("/*",line1)
  10732.              if cpos \= 0 then do
  10733.                line1 = substr(line1,1,cpos-1)
  10734.                comment = delstr(line1,1,cpos-1)
  10735.              end
  10736.              else
  10737.                comment = ""
  10738.  
  10739.  
  10740.            line1 = strip(line1)
  10741.  
  10742.             do while pos(";",line1) = 0
  10743.               line = line||line1
  10744.               line1 = linein(inputfile)
  10745.               line_num = line_num + 1
  10746.  
  10747.               cpos = pos("/*",line1)
  10748.               if cpos \= 0 then do
  10749.                 line1 = substr(line1,1,cpos-1)
  10750.                 comment = delstr(line1,1,cpos-1)
  10751.               end
  10752.               else comment = ""
  10753.  
  10754.  
  10755.               line1=strip(line1)
  10756.             end
  10757.  
  10758.            line = line||line1
  10759.         end
  10760.  
  10761.          /*********************************************
  10762.          * Error message issued when function return type is  *
  10763.          * struct.                                                              *
  10764.          *********************************************/
  10765.  
  10766.  
  10767.          out_line = z"%note('Error 37: Unsupported syntax encountered',4);"
  10768.          call do_writeout(out_line)
  10769.          out_line = z"/* This utility does not support declarations with */"
  10770.          call do_writeout(out_line)
  10771.  
  10772.          out_line = z"/* return type struct, enum, or union */"
  10773.          call do_writeout(out_line)
  10774.          out_line = z"/* Error: "first" "line" */"
  10775.          call do_writeout(out_line)
  10776.  
  10777.          if cpos \= 0 & comment \= "" then
  10778.            call do_comment(comment)
  10779.  
  10780.          out_line = z"/* The original line in the .h file is: "line_num" */"
  10781.          call do_writeout(out_line)
  10782.          out_line = ""
  10783.          call do_writeout(out_line)
  10784.          return
  10785.      end  /* Do */
  10786.  
  10787.  
  10788.     if wordpos(scanline,rest) > 0 then
  10789.        do
  10790.          vpos=pos("volatile",rest)
  10791.          rest = overlay("abnormal",rest,vpos)
  10792.        end
  10793.  
  10794.     /*******************************************************
  10795.     * Single level of struct without tag is given dummy# as tag name. *
  10796.     ********************************************************/
  10797.  
  10798.    ss_name = "dummy#"
  10799.    cpos = pos("/*",rest)
  10800.    if cpos \= 0 then do
  10801.      comment1 = substr(rest,cpos)
  10802.      rest = delstr(rest,cpos)
  10803.    end
  10804.  
  10805.    rest = space(rest,1)
  10806.    parse var rest s_name comment
  10807.    old_sname = s_name
  10808.    s_name=strip(s_name)
  10809.  
  10810.    if  s_name = "{" |  s_name = "" then
  10811.     do
  10812.       s_name = ss_name||strt_counter
  10813.       strt_counter = strt_counter + 1
  10814.     end
  10815.  
  10816.  
  10817.     if substr(s_name,1,1) = "_"  then
  10818.       s_name = check_name(s_name);
  10819.  
  10820.     if pos(";",s_name) \= 0 | substr(comment,1,1) = ";" then
  10821.       do
  10822.          cpos = pos("/*",comment)
  10823.          if cpos \= 0 then do
  10824.            comment1 = substr(comment,cpos)
  10825.            comment = delstr(comment,cpos)
  10826.          end
  10827.  
  10828.  
  10829.          /*********************************************
  10830.          * Issue error message for struct forward declarations. *
  10831.          **********************************************/
  10832.  
  10833.          out_line = z"%note('Error 38: Unsupported syntax encountered',4);"
  10834.          call do_writeout(out_line)
  10835.          out_line = z"/* This utility does not support forward declarations */"
  10836.          call do_writeout(out_line)
  10837.  
  10838.          out_line = z"/* Error:"first" "s_name" "comment" */"
  10839.          call do_writeout(out_line)
  10840.          if cpos \= 0 then
  10841.            call do_comment(comment1)
  10842.  
  10843.          out_line = z"/* The original line in the .h file is: "line_num" */"
  10844.          call do_writeout(out_line)
  10845.          out_line = ""
  10846.          call do_writeout(out_line)
  10847.          return
  10848.      end  /* Do */
  10849.  
  10850.    else do
  10851.  
  10852.  
  10853.       /*********************************************
  10854.       * Output the initial definition for structure.                 *
  10855.       **********************************************/
  10856.  
  10857.    select
  10858.       when pos(";",comment) =0 then do
  10859.  
  10860.         array.i.j = z"define structure "
  10861.  
  10862.         j = j + 1
  10863.         if cpos \= 0 then
  10864.           array.i.j = z"  1 "s_name",   "||comment1
  10865.         else
  10866.           array.i.j = z"  1 "s_name","
  10867.         j = j + 1
  10868.  
  10869.  
  10870.           /*********************************************
  10871.          * Call do_struct to process rest of the fields.             *
  10872.          **********************************************/
  10873.  
  10874.  
  10875.         call do_struct
  10876.  
  10877.           /*********************************************************
  10878.          * Issue additional define alias statement if struct had typedef struct. *
  10879.          **********************************************************/
  10880.  
  10881.         if tflag = "on" & i = 1 then
  10882.          do
  10883.            parse var array.1.2 num s_name ","
  10884.            s_name=strip(s_name)
  10885.            out_line = z"define alias @"s_name" handle "s_name";"
  10886.            out_line = do_indent(out_line)
  10887.            call do_writeout(out_line)
  10888.            out_line =""
  10889.  
  10890.            if var_name \= "" then
  10891.              do
  10892.                  parse var array.1.2 num s_name ","
  10893.                  call define_type(var_name)
  10894.              end
  10895.         end
  10896.  
  10897.        /*****************************************************
  10898.        * If not a typedef struct then process variable list after struct.. *
  10899.        *****************************************************/
  10900.  
  10901.         if tflag \= "on" & var_name \= "" then
  10902.           if i = 1  then
  10903.             do
  10904.               parse var array.1.2 num s_name ","
  10905.               call dcl_structvar(var_name)
  10906.             end
  10907.     end
  10908.  
  10909.       /*********************************************
  10910.       * processing for just struct variable declarations.        *
  10911.       **********************************************/
  10912.  
  10913.  
  10914.     when pos(";",comment) \= 0  then do
  10915.        parse var comment var_name "\*" comment
  10916.        parse var var_name var_name ";"
  10917.        call dcl_structvar(var_name)
  10918.     end  /* Do */
  10919.  
  10920.    otherwise
  10921.        nop  /* error in processing */
  10922.   end
  10923.  end
  10924. return
  10925.  
  10926.  
  10927. /**************************************************************/
  10928. /*  Structures without tag require a dcl statement rather than a define .      */
  10929. /**************************************************************/
  10930.  
  10931. do_notag:
  10932.  parse arg rest
  10933.  parse var rest s_name comment
  10934.  
  10935.       array.i.j = z"dcl  "
  10936.       j = j + 1
  10937.       array.i.j = z"  1 * ,"
  10938.       j = j + 1
  10939.  
  10940.       call do_struct
  10941.       return
  10942.  
  10943. /***********************************************************/
  10944. /* Subroutine to declare structure variables.                                */
  10945. /***********************************************************/
  10946.  
  10947. dcl_structvar:
  10948.  
  10949.    if var_name \= "" then
  10950.       dflag = false
  10951.        do while dflag = false
  10952.        if var_name \= "" then
  10953.         do
  10954.  
  10955.        /*********************************************
  10956.        * Process multiple variable declarations.                    *
  10957.        **********************************************/
  10958.  
  10959.           select
  10960.             when pos(",",var_name) \= 0 then do
  10961.                parse var var_name var1 "," var_name
  10962.                var1 = strip(var1)
  10963.             end
  10964.  
  10965.          /********************************
  10966.          * Process single variable declaration.. *
  10967.          ********************************/
  10968.  
  10969.            when pos(",",var_name) = 0 then do
  10970.               parse var var_name var1 ";"
  10971.               var1 = strip(var1)
  10972.               if left(var1,1) = "}" then
  10973.                 var1 = delstr(var1,1,1)
  10974.               var_name = ""
  10975.               dflag = true
  10976.            end
  10977.  
  10978.            otherwise
  10979.              nop  /* error in processing */
  10980.          end
  10981.  
  10982.  
  10983.         /************************
  10984.         * Process pointer definition.. *
  10985.         ************************/
  10986.  
  10987.          if substr(var1,1,1) = "*" | right(s_name,1,1) = "*" then
  10988.            do
  10989.               var1 = space(var1,0)
  10990.  
  10991.               do while pos("*",var1) \= 0
  10992.                  parse var var1 "*" var1
  10993.               end
  10994.  
  10995.               if pos("*",s_name) \= 0 then
  10996.                do
  10997.                 do while pos("*",s_name) \= 0
  10998.                    parse var s_name s_name "*"
  10999.                 end
  11000.               end
  11001.  
  11002.  
  11003.              if substr(var1,1,1) = "_"  then
  11004.               var1 = check_name(var1)
  11005.  
  11006.              if substr(s_name,1,1) = "_" then
  11007.                s_name = check_name(s_name)
  11008.  
  11009.              if pos("abnormal",var1) \= 0 then
  11010.               do
  11011.                  parse var var1 "abnormal" var1
  11012.                     var1 = var1||" abnormal"
  11013.               end
  11014.  
  11015.          /********************************
  11016.          * Process array definition if it exists.. *
  11017.          ********************************/
  11018.  
  11019.               if pos("[",var1) \= 0 then
  11020.                do
  11021.                  if pos("][",var1) \= 0 then
  11022.                    do
  11023.                      var1= convert_bracket(var1)
  11024.                      var1 = convert_finalbracket(var1)
  11025.                    end
  11026.                  else
  11027.                     var1 = convert_finalbracket(var1)
  11028.                end
  11029.  
  11030.              out_line = z"dcl "var1" handle" s_name";"
  11031.              out_line = do_indent(out_line)
  11032.              call do_writeout(out_line)
  11033.              out_line =""
  11034.           end
  11035.  
  11036.           else
  11037.           if substr(var1,1,1) \= "*" then
  11038.             do
  11039.  
  11040.              if pos("[",var1) \= 0 then
  11041.                do
  11042.                  if pos("][",var1) \= 0 then
  11043.                    do
  11044.                      var1= convert_bracket(var1)
  11045.                      var1 = convert_finalbracket(var1)
  11046.                    end
  11047.                  else
  11048.                     var1 = convert_finalbracket(var1)
  11049.                end
  11050.  
  11051.  
  11052.           if substr(var1,1,1) = "_"then
  11053.             var1 = check_name(var1)
  11054.  
  11055.           if substr(s_name,1,1) = "_" then
  11056.             s_name= check_name(s_name)
  11057.           /*******************************
  11058.          * Process non pointer struct variable. *
  11059.          ********************************/
  11060.  
  11061.  
  11062.           out_line = z"dcl "var1" type" s_name";"
  11063.           out_line = do_indent(out_line)
  11064.           call do_writeout(out_line)
  11065.           out_line =""
  11066.  
  11067.              if var_name = "" then dflag = true
  11068.         end
  11069.         else if var1 = "" then
  11070.              dflag = true
  11071.       end
  11072.    end
  11073.  return
  11074.  
  11075.       /***********************************************************
  11076.       * Process enum variable declarations because it requires ordinal type. *
  11077.       ***********************************************************/
  11078.  
  11079. dcl_enumvar:
  11080.  
  11081.    if var_name \= "" then do
  11082.       done1 = false
  11083.  
  11084.       do while done1=false
  11085.        if var_name \= "" then
  11086.         do
  11087.  
  11088.        /*********************************************
  11089.        * Process multiple variable declarations.                    *
  11090.        **********************************************/
  11091.  
  11092.  
  11093.           select
  11094.             when pos(",",var_name) \= 0 then do
  11095.                parse var var_name var1 "," var_name
  11096.                var1 = strip(var1)
  11097.             end
  11098.        /********************************
  11099.        * Process single variable declaration.. *
  11100.        ********************************/
  11101.  
  11102.  
  11103.            when pos(",",var_name) = 0 then do
  11104.               parse var var_name var1 ";"
  11105.               var1 = strip(var1)
  11106.               if left(var1,1) = "}" then
  11107.                 var1 = delstr(var1,1,1)
  11108.               var_name = ""
  11109.               done1 = true
  11110.            end
  11111.  
  11112.            otherwise
  11113.              nop
  11114.          end
  11115.          /********************************
  11116.          * Process array definition if it exists.. *
  11117.          ********************************/
  11118.  
  11119.           if pos("[",var1) \= 0 then
  11120.                do
  11121.                  if pos("][",var1) \= 0 then
  11122.                    do
  11123.                      var1= convert_bracket(var1)
  11124.                      var1 = convert_finalbracket(var1)
  11125.                    end
  11126.                  else
  11127.                     var1 = convert_finalbracket(var1)
  11128.                end
  11129.  
  11130.         /************************
  11131.         * Process pointer definition.. *
  11132.         ************************/
  11133.  
  11134.  
  11135.          if substr(var1,1,1) = "*" | right(s_name,1,1) = "*" then
  11136.            do
  11137.               var1 = space(var1,0)
  11138.               do while pos("*",var1) \= 0
  11139.                  parse var var1 "*" var1
  11140.               end
  11141.  
  11142.               if pos("*",s_name) \= 0 then
  11143.                do
  11144.                 do while pos("*",s_name) \= 0
  11145.                    parse var s_name s_name "*"
  11146.                 end /* do */
  11147.               end
  11148.  
  11149.  
  11150.              if substr(var1,1,1) = "_"  then
  11151.               var1 = check_name(var1)
  11152.              if substr(s_name,1,1) = "_" then
  11153.                s_name = check_name(s_name)
  11154.  
  11155.              var1 = strip(var1)
  11156.              s_name = strip(s_name)
  11157.              out_line = z"dcl "var1" handle" s_name";"
  11158.              out_line = do_indent(out_line)
  11159.              call do_writeout(out_line)
  11160.              out_line =""
  11161.           end
  11162.           else
  11163.           if substr(var1,1,1) \= "*" & right(s_name,1,1) \= "*" then
  11164.             do
  11165.  
  11166.              if pos("[",var1) \= 0 then
  11167.                do
  11168.                  if pos("][",var1) \= 0 then
  11169.                    do
  11170.                      var1= convert_bracket(var1)
  11171.                      var1 = convert_finalbracket(var1)
  11172.                    end
  11173.                  else
  11174.                     var1 = convert_finalbracket(var1)
  11175.                end
  11176.  
  11177.          /*******************************
  11178.          * Process non pointer enum variable. *
  11179.          ********************************/
  11180.  
  11181.  
  11182.           var1 = check_name(var1)
  11183.           s_name = check_name(s_name)
  11184.           var1 = strip(var1)
  11185.           s_name = strip(s_name)
  11186.  
  11187.           out_line = z"dcl "var1" ordinal" s_name";"
  11188.           out_line = do_indent(out_line)
  11189.           call do_writeout(out_line)
  11190.           out_line =""
  11191.  
  11192.           if var_name ="" then
  11193.            done1 = true
  11194.         end
  11195.         else if var1 = "" then
  11196.           done1 = true;
  11197.       end
  11198.    end
  11199. end
  11200.  return
  11201.  
  11202.       /**************************************************************
  11203.       * Process typedef list followed by typedef struct union or enum definition. *
  11204.       ***************************************************************/
  11205.  
  11206.  
  11207.   define_type:
  11208.  
  11209.    if var_name \= "" then
  11210.          done2 = false
  11211.          do while done2=false
  11212.             if var_name \= "" then
  11213.              do
  11214.               select
  11215.                  when pos(",",var_name) \= 0 then do
  11216.                    parse var var_name var1 "," var_name
  11217.                    var1 = strip(var1)
  11218.                  end
  11219.  
  11220.                 when pos(",",var_name) = 0 then do
  11221.                    parse var var_name var1 ";"
  11222.                    var1 = strip(var1)
  11223.                    var_name = ""
  11224.                    done2 = true
  11225.                 end
  11226.                 otherwise
  11227.                    nop  /* error in processing */
  11228.              end
  11229.  
  11230.          if substr(var1,1,1) = "*" then
  11231.           do
  11232.            var1 = space(var1,0)
  11233.            do while pos("*",var1) \= 0
  11234.              parse var var1 "*" var1
  11235.            end
  11236.  
  11237.            if pos("*",s_name) \= 0 then
  11238.                do
  11239.                 do while pos("*",s_name) \= 0
  11240.                    parse var s_name s_name "*"
  11241.                 end /* do */
  11242.               end
  11243.  
  11244.            if substr(var1,1,1) = "_"  then
  11245.                var1 = check_name(var1)
  11246.            if substr(s_name,1,1) = "_" then
  11247.                s_name = check_name(s_name)
  11248.            /*******************************
  11249.           * Process pointer typedefs.              *
  11250.           ********************************/
  11251.  
  11252.  
  11253.             out_line = z"define alias "var1" handle" s_name";"
  11254.             out_line = do_indent(out_line)
  11255.             call do_writeout(out_line)
  11256.             out_line =""
  11257.         end
  11258.  
  11259.         else
  11260.           if substr(var1,1,1) \= "*" & translate(var1) \= translate(s_name) then
  11261.             do
  11262.              var1 = check_name(var1)
  11263.              var1 = strip(var1)
  11264.              s_name = strip(s_name)
  11265.  
  11266.           /*******************************
  11267.          * Process non pointer typedef           *
  11268.          ********************************/
  11269.  
  11270.              out_line = z"define alias "var1" type "s_name";"
  11271.              out_line = do_indent(out_line)
  11272.              call do_writeout(out_line)
  11273.              out_line = z"define alias @"var1" type @"s_name";"
  11274.              out_line = do_indent(out_line)
  11275.              call do_writeout(out_line)
  11276.  
  11277.              out_line =""
  11278.            end
  11279.           else if var1 = "" then
  11280.             done2 = true;
  11281.       end
  11282.     end
  11283.    return
  11284.  
  11285.  
  11286.  
  11287.    /**************************************************
  11288.    * Start the UNION conversion process.                          *
  11289.    ***************************************************/
  11290. do_union:
  11291.  
  11292.    parse arg rest
  11293.  
  11294.  
  11295.  
  11296.      if pos("(",rest) \= 0 then
  11297.     do
  11298.        cpos = pos("/*",rest)
  11299.          if cpos \= 0 then do
  11300.            line = substr(rest,1,cpos-1)
  11301.            comment = delstr(rest,1,cpos-1)
  11302.          end
  11303.          else line = rest
  11304.  
  11305.           if  pos(";",line) = 0 then
  11306.            do
  11307.              line1 = linein(inputfile)
  11308.              line_num = line_num + 1
  11309.  
  11310.              cpos = pos("/*",line1)
  11311.              if cpos \= 0 then
  11312.               do
  11313.                 line1 = substr(line1,1,cpos-1)
  11314.                 comment = ""
  11315.                 cpos = 0
  11316.               end
  11317.  
  11318.             line1 = strip(line1)
  11319.  
  11320.             do while pos(";",line1) = 0
  11321.               line = line||line1
  11322.               line1 = linein(inputfile)
  11323.               line_num = line_num + 1
  11324.  
  11325.               cpos = pos("/*",line1)
  11326.               if cpos \= 0 then
  11327.                do
  11328.                 line1 = substr(line1,1,cpos-1)
  11329.                 comment = ""
  11330.                 cpos = 0
  11331.               end
  11332.  
  11333.               line1=strip(line1)
  11334.             end
  11335.            line = line||line1
  11336.         end
  11337.          /*****************************************************
  11338.          * Issue error message for functions with return types as union. *
  11339.          *****************************************************/
  11340.  
  11341.  
  11342.          out_line = z"%note('Error 39: Unsupported syntax encountered',4);"
  11343.          call do_writeout(out_line)
  11344.          out_line = z"/* This utility does not support declarations with */"
  11345.          call do_writeout(out_line)
  11346.  
  11347.          out_line = z"/* return type struct, enum, or union */"
  11348.          call do_writeout(out_line)
  11349.          out_line = z"/* Error: "first" "line" */"
  11350.          call do_writeout(out_line)
  11351.  
  11352.          if cpos \= 0 then
  11353.            call do_comment(comment)
  11354.  
  11355.          out_line = z"/* The original line in the .h file is: "line_num" */"
  11356.          call do_writeout(out_line)
  11357.          out_line = ""
  11358.          call do_writeout(out_line)
  11359.          return
  11360.      end  /* Do */
  11361.  
  11362.  
  11363.  
  11364.    parse var rest s_name comment
  11365.    ss_name ="dummy#"
  11366.  
  11367.    s_name = strip(s_name)
  11368.    s_name = check_name(s_name)
  11369.  
  11370.  
  11371.     /********************************************
  11372.     * Issue error message for enum forward declaration. *
  11373.     ********************************************/
  11374.  
  11375.     if pos(";",s_name) \= 0 | substr(comment,1,1) = ";" then
  11376.       do
  11377.          cpos = pos("/*",comment)
  11378.          if cpos \= 0 then do
  11379.            comment1 = substr(comment,cpos)
  11380.            comment = delstr(comment,cpos)
  11381.          end
  11382.  
  11383.          out_line = z"%note('Error 40: Unsupported syntax encountered',4);"
  11384.          call do_writeout(out_line)
  11385.          out_line = z"/* This utility does not support forward declarations */"
  11386.          call do_writeout(out_line)
  11387.  
  11388.          out_line = z"/* Error:"first" "s_name" "comment" */"
  11389.          call do_writeout(out_line)
  11390.          if cpos \= 0 then
  11391.            call do_comment(comment1)
  11392.  
  11393.          out_line = z"/* The original line in the .h file is: "line_num" */"
  11394.          call do_writeout(out_line)
  11395.          out_line = ""
  11396.          call do_writeout(out_line)
  11397.          return
  11398.      end  /* Do */
  11399.  
  11400.      /*******************************
  11401.      * Union without tag give dummy name*
  11402.      ********************************/
  11403.  
  11404.       if s_name = "" | s_name = "{" then
  11405.        do
  11406.           s_name = ss_name||strt_counter
  11407.           strt_counter = strt_counter + 1
  11408.        end
  11409.  
  11410.   select
  11411.     when pos(";",comment) =0 then do
  11412.       array.i.j = z"define structure "
  11413.        j = j + 1
  11414.       array.i.j = z"1 "s_name" union,"
  11415.       j = j + 1
  11416.  
  11417.       call do_struct
  11418.  
  11419.       if tflag = "on" & i = 1 then
  11420.         do
  11421.          parse var array.1.2 num s_name junk
  11422.          s_name = strip(s_name)
  11423.          s_name=check_name(s_name)
  11424.          out_line = z"define alias @"s_name" handle "s_name";"
  11425.          out_line = do_indent(out_line)
  11426.          call do_writeout(out_line)
  11427.          out_line =""
  11428.  
  11429.          if var_name \= "" then
  11430.            do
  11431.               parse var array.1.2 num s_name ","
  11432.               parse var s_name s_name temp
  11433.               call define_type(var_name)
  11434.            end
  11435.        end
  11436.  
  11437.       if i = 1 & tflag \= "on" then
  11438.         do
  11439.           parse var array.1.2 num s_name u_name","
  11440.           call dcl_structvar(var_name)
  11441.         end
  11442.    end
  11443.  
  11444.  
  11445.    when pos(";",comment) \= 0  then do
  11446.      parse var comment var_name "\*" comment
  11447.      parse var var_name var_name ";"
  11448.      call dcl_structvar(var_name)
  11449.    end  /* Do */
  11450.  
  11451.  
  11452.    otherwise
  11453.      nop  /* error in processing */
  11454.   end
  11455. return
  11456.  
  11457. /**************************************************************/
  11458. /* #elseif statements are not supported by this utility.                     */
  11459. /**************************************************************/
  11460. do_elseif:
  11461. parse arg rest
  11462. cpos = pos("/*",rest)
  11463.     if cpos \= 0 then
  11464.       do
  11465.         comment = substr(rest,cpos)
  11466.         rest = delstr(rest,cpos)
  11467.      end  /* Do */
  11468.  
  11469.      out_line = z"%note('Error 41: Unsupported syntax encountered',4);"
  11470.      call do_writeout(out_line)
  11471.      out_line = z"/* Error: #elseif statements are not supported by this utility. */"
  11472.      call do_writeout(out_line)
  11473.      out_line = z"/* Error: #elseif "rest"*/"
  11474.      call do_writeout(out_line)
  11475.  
  11476.      if cpos \= 0 then
  11477.        call do_comment(comment)
  11478.  
  11479.      out_line = z"/* The original line in the .h file is: "line_num" */"
  11480.      call do_writeout(out_line)
  11481.      out_line = ""
  11482.      call do_writeout(out_line)
  11483.    return
  11484.  
  11485.  
  11486. /**************************************************************/
  11487. /* #line statements are not supported by this utility.                     */
  11488. /**************************************************************/
  11489. do_line:
  11490. parse arg rest
  11491. cpos = pos("/*",rest)
  11492.     if cpos \= 0 then
  11493.       do
  11494.         comment = substr(rest,cpos)
  11495.         rest = delstr(rest,cpos)
  11496.      end  /* Do */
  11497.  
  11498.      out_line = z"%note('Error 42: Unsupported syntax encountered',4);"
  11499.      call do_writeout(out_line)
  11500.      out_line = z"/* Error: #line or # statements are not supported by this utility. */"
  11501.      call do_writeout(out_line)
  11502.      out_line = z"/* Error: #line or # "rest"*/"
  11503.      call do_writeout(out_line)
  11504.  
  11505.      if cpos \= 0 then
  11506.        call do_comment(comment)
  11507.  
  11508.      out_line = z"/* The original line in the .h file is: "line_num" */"
  11509.      call do_writeout(out_line)
  11510.      out_line = " "
  11511.      call do_writeout(out_line)
  11512.    return
  11513.  
  11514.  
  11515.  /**************************************************************/
  11516. /* #elif statements are not supported by this utility.                     */
  11517. /**************************************************************/
  11518. do_elif:
  11519. parse arg rest
  11520. cpos = pos("/*",rest)
  11521.     if cpos \= 0 then
  11522.       do
  11523.         comment = substr(rest,cpos)
  11524.         rest = delstr(rest,cpos)
  11525.      end  /* Do */
  11526.  
  11527.      out_line = z"%note('Error 43: Unsupported syntax encountered',4);"
  11528.      call do_writeout(out_line)
  11529.      out_line = z"/* Error: #elif statements are not supported by this utility. */"
  11530.      call do_writeout(out_line)
  11531.      out_line = z"/* Error: #elif "rest"*/"
  11532.      call do_writeout(out_line)
  11533.  
  11534.      if cpos \= 0 then
  11535.        call do_comment(comment)
  11536.  
  11537.      out_line = z"/* The original line in the .h file is: "line_num" */"
  11538.      call do_writeout(out_line)
  11539.      out_line = ""
  11540.      call do_writeout(out_line)
  11541.    return
  11542.  
  11543.  
  11544.  
  11545.  
  11546. /**************************************************************/
  11547. /* Somextern statements are not supported by this utility.                     */
  11548. /**************************************************************/
  11549. do_som:
  11550. parse arg rest
  11551. cpos = pos("/*",rest)
  11552.     if cpos \= 0 then
  11553.       do
  11554.         comment = substr(rest,cpos)
  11555.         rest = delstr(rest,cpos)
  11556.      end  /* Do */
  11557.  
  11558.      out_line = z"%note('Error 44: Unsupported syntax encountered',4);"
  11559.      call do_writeout(out_line)
  11560.      out_line = z"/* Error: Somextern statements are not supported by this utility. */"
  11561.      call do_writeout(out_line)
  11562.      out_line = z"/* Error: Somextern "rest"*/"
  11563.      call do_writeout(out_line)
  11564.  
  11565.      if cpos \= 0 then
  11566.        call do_comment(comment)
  11567.  
  11568.      out_line = z"/* The original line in the .h file is: "line_num" */"
  11569.      call do_writeout(out_line)
  11570.      out_line = ""
  11571.      call do_writeout(out_line)
  11572. exit
  11573.