home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
OSPORT.ZIP
/
SHTOLONG.KEX
< prev
Wrap
Text File
|
1992-05-15
|
6KB
|
205 lines
/**
*** ┌─────────────────────────────────────────────────────────────────────────┐
*** │ │
*** │ This macro will assist in the migration of OS/2 1.x C programs │
*** │ to OS/2 2.0 by changing the SHORT references to LONG references. This │
*** │ is not a complete migration utility, but is meant to aid in the │
*** │ conversion. │
*** │ │
*** │ ═══════════════════════════════════════════════════════════════════════ │
*** │ Copyright(c) 1991, Hilbert Computing. Released to the public domain. │
*** │ No warranty expressed or implied. │
*** │ ═══════════════════════════════════════════════════════════════════════ │
*** │ │
*** │ If this has been useful to you, I would like to know. Drop me a line │
*** │ on Prodigy [VWSD07A] or CompuServe [73457,365]. If there are any │
*** │ errors or improvements, let me know. │
*** │ │
*** └─────────────────────────────────────────────────────────────────────────┘
**/
'preserve'
'case m r'
'msgmode off'
do while MarkProcedure() = 0
call RemoveTypeCast
/* Confine the search to this procedure */
'set range block'
'sos blockstart'
do until code <> 0
code = Convert()
end
if code = -2 then
call Terminate
/* Restore the settings */
'set range -* *'
'sos blockend'
'+1'
end
call Terminate
exit
Terminate: procedure
/**
*** This will return everything to a normal state
**/
'restore'
'range -* *'
'reset block'
'zone 1 *'
exit
MarkProcedure: procedure
/**
*** This will mark a procedure. Since there was no quick way to determine
*** the beginning of a C procedure without some sophisticated lexical
*** analysis, we assume the cursor is at the beginning.
**/
'reset block'
'extract/line/'
CursorLine = line.1
':'CursorLine
'mark line'
'clocate/{/'
if rc = 2 then
return -1
'cmatch'
'mark line'
'+1'
return 0
Convert: procedure
/**
*** This will convert a single SHORT reference to a LONG reference
**/
if block() = 0 then
do
'alert /No Marked Block/ TITLE /Short To Long/ OK'
return -1
end
'clocate/SHORT /'
if rc = 2 then
do
'set range -* *'
return -1
end
/* Pull out the current column location */
'extract/column/curline/'
CurCol = column.1 - 1
parse var curline.3 . +(CurCol) . ShortVar .
/* Make sure there are not two variables within the ShortVar */
parse var ShortVar ShortVar ',' .
parse var ShortVar ShortVar ';' .
/* Remove any trailing punctuation */
ShortVar = strip(ShortVar, 'Trailing', ',')
ShortVar = strip(ShortVar, 'Trailing', ';')
ShortVar = strip(ShortVar, 'Trailing', ')')
ShortVar = strip(ShortVar, 'Trailing', ' ')
'dialog /Do you want to change' ShortVar'?/ TITLE /Short To Long/ YESNOCANCEL'
if dialog.2 = 'NO' then
do
'clocate +5' /* Skip past the SHORT */
return 0
end
if dialog.2 = 'CANCEL' then
return -2
'zone' CurCol '*'
'c/SHORT /LONG / 1 1'
'zone 1 *'
/* Determine the type */
select
when abbrev(ShortVar, 'fs') then LongVar = 'fl'substr(ShortVar, 3)
when abbrev(ShortVar, 's') then LongVar = 'l'substr(ShortVar, 2)
when abbrev(ShortVar, 'us') then LongVar = 'ul'substr(ShortVar, 3)
when abbrev(ShortVar, 'pus') then LongVar = 'pul'substr(ShortVar, 4)
when abbrev(ShortVar, 'ps') then LongVar = 'pl'substr(ShortVar, 3)
when abbrev(ShortVar, 'px') then LongVar = ShortVar
when abbrev(ShortVar, 'py') then LongVar = ShortVar
when abbrev(ShortVar, 'x') then LongVar = ShortVar
when abbrev(ShortVar, 'y') then LongVar = ShortVar
when abbrev(ShortVar, 'cb') then LongVar = ShortVar
when abbrev(ShortVar, 'l') then LongVar = ShortVar
when abbrev(ShortVar, 'ul') then LongVar = ShortVar
when abbrev(ShortVar, 'pul') then LongVar = ShortVar
when abbrev(ShortVar, 'pl') then LongVar = ShortVar
when abbrev(ShortVar, 'rc') then LongVar = ShortVar
when abbrev(ShortVar, 'EXPENTRY') then LongVar = ShortVar
otherwise
do
'msgmode on'
'msg Warning: The variable didn''t match a standard prefix.'
LongVar = ShortVar
'msgmode off'
end
end /* select */
'c/'ShortVar'/'LongVar'/ block *'
return 0
RemoveTypeCast: procedure
/**
*** This will remove or change the typecast of variables to SHORTs
**/
if block() = 0 then
do
'alert /No Marked Block/ TITLE /Short To Long/ OK'
return -1
end
'set range block'
'sos blockstart'
'clocate/SHORT)/'
if rc = 0 then
do
'dialog /Remove SHORT casts? (Yes, No = Convert, Cancel = Do Nothing)?/ TITLE /Short To Long/ YESNOCANCEL'
select
when dialog.2 = "CANCEL" then
nop
when dialog.2 = "YES" then
do
'c/(SHORT)// block *'
'c/(PSHORT)// block *'
'c/(USHORT)// block *'
'c/(PUSHORT)// block *'
end
when dialog.2 = "NO" then
do
'c/(SHORT)/(LONG)/ block *'
'c/(PSHORT)/(PLONG)/ block *'
'c/(USHORT)/(ULONG)/ block *'
'c/(PUSHORT)/(PULONG)/ block *'
end
end /* select */
end /* if */
'set range -* *'
return