home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / OSPORT.ZIP / SHTOLONG.KEX < prev   
Text File  |  1992-05-15  |  6KB  |  205 lines

  1. /**
  2. *** ┌─────────────────────────────────────────────────────────────────────────┐
  3. *** │                                                                         │
  4. *** │ This macro will assist in the migration of OS/2 1.x C programs          │
  5. *** │ to OS/2 2.0 by changing the SHORT references to LONG references.  This  │
  6. *** │ is not a complete migration utility, but is meant to aid in the         │
  7. *** │ conversion.                                                             │
  8. *** │                                                                         │
  9. *** │ ═══════════════════════════════════════════════════════════════════════ │
  10. *** │  Copyright(c) 1991, Hilbert Computing.  Released to the public domain.  │
  11. *** │                    No warranty expressed or implied.                    │
  12. *** │ ═══════════════════════════════════════════════════════════════════════ │
  13. *** │                                                                         │
  14. *** │ If this has been useful to you, I would like to know.  Drop me a line   │
  15. *** │ on Prodigy [VWSD07A] or CompuServe [73457,365].  If there are any       │
  16. *** │ errors or improvements, let me know.                                    │
  17. *** │                                                                         │
  18. *** └─────────────────────────────────────────────────────────────────────────┘
  19. **/
  20.  
  21. 'preserve'
  22. 'case m r'
  23. 'msgmode off'
  24.  
  25. do while MarkProcedure() = 0
  26.    call RemoveTypeCast
  27.  
  28.    /* Confine the search to this procedure */
  29.  
  30.    'set range block'
  31.    'sos blockstart'
  32.  
  33.    do until code <> 0
  34.       code = Convert()
  35.    end
  36.    if code = -2 then
  37.       call Terminate
  38.  
  39.    /* Restore the settings */
  40.  
  41.    'set range -* *'
  42.    'sos blockend'
  43.    '+1'
  44. end
  45. call Terminate
  46. exit
  47.  
  48.  
  49. Terminate: procedure
  50.    /**
  51.    ***  This will return everything to a normal state
  52.    **/
  53.  
  54.    'restore'
  55.    'range -* *'
  56.    'reset block'
  57.    'zone 1 *'
  58.    exit
  59.  
  60.  
  61. MarkProcedure: procedure
  62.    /**
  63.    ***  This will mark a procedure.  Since there was no quick way to determine
  64.    ***  the beginning of a C procedure without some sophisticated lexical
  65.    ***  analysis, we assume the cursor is at the beginning.
  66.    **/
  67.  
  68.    'reset block'
  69.    'extract/line/'
  70.    CursorLine = line.1
  71.    ':'CursorLine
  72.    'mark line'
  73.    'clocate/{/'
  74.    if rc = 2 then
  75.       return -1
  76.  
  77.    'cmatch'
  78.    'mark line'
  79.    '+1'
  80.    return 0
  81.  
  82.  
  83. Convert: procedure
  84.    /**
  85.    ***  This will convert a single SHORT reference to a LONG reference
  86.    **/
  87.  
  88.    if block() = 0 then
  89.       do
  90.       'alert /No Marked Block/ TITLE /Short To Long/ OK'
  91.       return -1
  92.       end
  93.  
  94.    'clocate/SHORT /'
  95.  
  96.    if rc = 2 then
  97.       do
  98.       'set range -* *'
  99.       return -1
  100.       end
  101.  
  102.    /* Pull out the current column location */
  103.  
  104.    'extract/column/curline/'
  105.    CurCol = column.1 - 1
  106.    parse var curline.3 . +(CurCol) . ShortVar .
  107.  
  108.    /* Make sure there are not two variables within the ShortVar */
  109.  
  110.    parse var ShortVar ShortVar ',' .
  111.    parse var ShortVar ShortVar ';' .
  112.  
  113.    /* Remove any trailing punctuation */
  114.  
  115.    ShortVar = strip(ShortVar, 'Trailing', ',')
  116.    ShortVar = strip(ShortVar, 'Trailing', ';')
  117.    ShortVar = strip(ShortVar, 'Trailing', ')')
  118.    ShortVar = strip(ShortVar, 'Trailing', ' ')
  119.  
  120.    'dialog /Do you want to change' ShortVar'?/ TITLE /Short To Long/ YESNOCANCEL'
  121.    if dialog.2 = 'NO' then
  122.       do
  123.       'clocate +5'  /* Skip past the SHORT */
  124.       return 0
  125.       end
  126.  
  127.    if dialog.2 = 'CANCEL' then
  128.       return -2
  129.  
  130.    'zone' CurCol '*'
  131.    'c/SHORT /LONG  / 1 1'
  132.    'zone 1 *'
  133.  
  134.    /* Determine the type */
  135.  
  136.    select
  137.       when abbrev(ShortVar, 'fs')        then LongVar = 'fl'substr(ShortVar, 3)
  138.       when abbrev(ShortVar, 's')         then LongVar = 'l'substr(ShortVar, 2)
  139.       when abbrev(ShortVar, 'us')        then LongVar = 'ul'substr(ShortVar, 3)
  140.       when abbrev(ShortVar, 'pus')       then LongVar = 'pul'substr(ShortVar, 4)
  141.       when abbrev(ShortVar, 'ps')        then LongVar = 'pl'substr(ShortVar, 3)
  142.       when abbrev(ShortVar, 'px')        then LongVar = ShortVar
  143.       when abbrev(ShortVar, 'py')        then LongVar = ShortVar
  144.       when abbrev(ShortVar, 'x')         then LongVar = ShortVar
  145.       when abbrev(ShortVar, 'y')         then LongVar = ShortVar
  146.       when abbrev(ShortVar, 'cb')        then LongVar = ShortVar
  147.       when abbrev(ShortVar, 'l')         then LongVar = ShortVar
  148.       when abbrev(ShortVar, 'ul')        then LongVar = ShortVar
  149.       when abbrev(ShortVar, 'pul')       then LongVar = ShortVar
  150.       when abbrev(ShortVar, 'pl')        then LongVar = ShortVar
  151.       when abbrev(ShortVar, 'rc')        then LongVar = ShortVar
  152.       when abbrev(ShortVar, 'EXPENTRY')  then LongVar = ShortVar
  153.       otherwise
  154.          do
  155.          'msgmode on'
  156.          'msg Warning: The variable didn''t match a standard prefix.'
  157.          LongVar = ShortVar
  158.          'msgmode off'
  159.          end
  160.    end /* select */
  161.    'c/'ShortVar'/'LongVar'/ block *'
  162.    return 0
  163.  
  164.  
  165. RemoveTypeCast: procedure
  166.    /**
  167.    ***  This will remove or change the typecast of variables to SHORTs
  168.    **/
  169.  
  170.    if block() = 0 then
  171.       do
  172.       'alert /No Marked Block/ TITLE /Short To Long/ OK'
  173.       return -1
  174.       end
  175.  
  176.    'set range block'
  177.    'sos blockstart'
  178.  
  179.    'clocate/SHORT)/'
  180.    if rc = 0 then
  181.       do
  182.       'dialog /Remove SHORT casts? (Yes, No = Convert, Cancel = Do Nothing)?/ TITLE /Short To Long/ YESNOCANCEL'
  183.       select
  184.          when dialog.2 = "CANCEL" then
  185.             nop
  186.          when dialog.2 = "YES"    then
  187.             do
  188.             'c/(SHORT)// block *'
  189.             'c/(PSHORT)// block *'
  190.             'c/(USHORT)// block *'
  191.             'c/(PUSHORT)// block *'
  192.             end
  193.          when dialog.2 = "NO" then
  194.             do
  195.             'c/(SHORT)/(LONG)/ block *'
  196.             'c/(PSHORT)/(PLONG)/ block *'
  197.             'c/(USHORT)/(ULONG)/ block *'
  198.             'c/(PUSHORT)/(PULONG)/ block *'
  199.             end
  200.       end /* select */
  201.       end /* if */
  202.  
  203.    'set range -* *'
  204.    return
  205.