home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
prgramer
/
rexx
/
4macrs
/
smartc.rex
< prev
Wrap
OS/2 REXX Batch file
|
1993-05-27
|
10KB
|
411 lines
/* extended smart c template editing for SourceLink32 */
/*
Creation 93/03/12 by Thomas Korfhage, tel&fax ++49 6446 2931
CIS: 100271,16
Description
This macro has 4 entrys.
If there is an argument it might be either UP, DOWN or FCTYPE.
UP - goto prev. function header. (match { at pos 1)
DOWN - goto next function header. (match { at pos 1)
FCTYPE - asume the actual line is a complete function declaration.
Take this and insert it under the first FTY eyecatcher comment
found in file and append a ';'.
any other argument will be ignored and the macro will do a C-template
edition. It will expand one or more letters to a C-template
i -> if; e -> else; f -> for; w -> while; d -> do.while; b or { -> braces
if the letter(s) are lower case a short template will be created
e.g. i -> if ()
if the letter(s) are upper case the result is a full template (with braces)
e.g. I -> if () {
}
all text following the letter(s) on the same line goes into the parens.
(cl, ce, h are unchanged from the original SLINK2 SMARTC.REX)
If any text is selected, the user will be asked for the type of template
before the template will be created arround it.
The selected text then becomes the body of the block.
Normaly only full lines should be selected.
The created template are adapted to my style.
Indentation will be 1 tab.
*/
'S_CLEAR_MACRO_OUTPUT'
if ARG(1,'E')then do
ARG ExtFunc
if Wordpos( ExtFunc, 'UP DOWN FCTYPE') \= 0 then do
'S_DISABLE_WINDOW'
Signal Value ExtFunc
end
exit
end
'S_GET_SELECTED_SIZE' 'Len'
If Len <= 1 THEN SIGNAL SMART_UNSEL
'S_PROMPT Create block over selected code (i-e-f-w-d-b-{), CCode'
'S_DISABLE_WINDOW'
'S_CUT_SEL_TO_PASTE'
'S_GET_LINE_NUM' 'SaveLineNum'
'S_GET_COL_NUM' 'SaveColNum'
'S_INDENT'
SELECT
WHEN abbrev( 'if', CCode, 1 ) THEN
do
'S_INSERT_LINE' 'if () {'
NrBS = 3
end
WHEN abbrev( 'while', CCode, 1 ) THEN
do
'S_INSERT_LINE' 'while () {'
NrBS = 3
end
WHEN abbrev( 'for', CCode, 1 ) THEN
do
'S_INSERT_LINE' 'for (;;) {'
NrBS = 5
end
WHEN (WCode = '{') | abbrev( 'b', CCode, 1 ) THEN
do
'S_INSERT_LINE' '{'
NrBS = 0
end
WHEN abbrev( 'do', CCode, 1 ) THEN
do
'S_INSERT_LINE' 'do {'
'S_INDENT'
'S_INSERT_LINE' '} while (#) ;'
call insertpaste
'S_SEARCH_FWD' 1 0 '} while (#) ;'
'S_END_OF_LINE'
'S_PREV_CHAR'
'S_PREV_CHAR'
'S_PREV_CHAR'
'S_PREV_CHAR'
'S_DEL_CHAR'
'S_ENABLE_WINDOW'
EXIT
end
OTHERWISE
'S_INSERT_PASTE'
'S_ENABLE_WINDOW'
EXIT
end
'S_INDENT'
'S_INSERT_LINE' '}'
call insertpaste
'S_GOTO_LINE' SaveLineNum
'S_GOTO_COL' SaveColNum
'S_END_OF_LINE'
DO I=1 TO NrBS
'S_PREV_CHAR'
end
'S_ENABLE_WINDOW'
EXIT
SMART_UNSEL:
'S_GET_CURR_WORD' 'WCode'
CCode = WCode
CCode = translate( WCode)
FULLCode = WCode == CCode
MoreInLine = 0
SELECT
WHEN abbrev( 'IF', CCode, 1 ) THEN
do
call isMoreInLine
MoreInLine = RESULT
call insertcode( "if ()" )
'S_PREV_CHAR'
end
WHEN abbrev( 'ELSE', CCode, 1 ) THEN
do
call insertcode( "else" )
if FULLCode == 1 then do
'S_END_OF_LINE'
ADDSTR = ' '
'S_INSERT_LINE' ADDSTR
'S_INDENT'
'S_INSERT_STRING' ADDSTR
'S_END_OF_LINE'
end
else do
'S_END_OF_LINE'
ADDSTR = ' '
'S_INSERT_STRING' ADDSTR
end
end
WHEN abbrev( 'WHILE', CCode, 1 ) THEN
do
call isMoreInLine
MoreInLine = RESULT
call insertcode( "while ()" )
'S_PREV_CHAR'
end
WHEN abbrev( 'SWITCH', CCode, 1 ) THEN
do
call isMoreInLine
MoreInLine = RESULT
call insertcode( "switch ()" )
'S_PREV_CHAR'
end
WHEN abbrev( 'CASE', CCode, 1 ) THEN
do
call insertcode( "case :" )
'S_PREV_CHAR'
end
WHEN abbrev( 'FOR', CCode, 1 ) THEN
do
call insertcode( "for( ; ; )" )
'S_PREV_CHAR'
'S_PREV_CHAR'
'S_PREV_CHAR'
'S_PREV_CHAR'
'S_PREV_CHAR'
end
WHEN abbrev( 'DO', CCode, 1 ) THEN
do
call insertline( "do" ) /* do */
ADDSTR = '{'
'S_INSERT_LINE' ADDSTR /* { */
'S_INDENT'
ADDSTR = ' '
'S_INSERT_LINE' ADDSTR /* blank line */
'S_INDENT'
'S_PREV_CHAR'
ADDSTR = '} while( )'
'S_INSERT_LINE' ADDSTR /* } while () */
'S_PREV_LINE'
'S_PREV_LINE'
'S_INDENT'
ADDSTR = ' '
'S_INSERT_STRING' ADDSTR
end
WHEN WCode = 'b' | WCode = '{' THEN
do
call insertline( "{" )
ADDSTR = ' '
'S_INSERT_LINE' ADDSTR
'S_INDENT'
'S_PREV_CHAR'
ADDSTR = '}'
'S_INSERT_STRING' ADDSTR
'S_PREV_LINE'
'S_END_OF_LINE'
end
WHEN WCode = 'cl' THEN
do
'S_PROMPT' 'Enter Comment,' 'Comment'
NEWCODE = '/* ' || Comment '*/'
call insertcode( NEWCODE )
'S_INSERT_LINE' ' '
'S_INDENT'
end
WHEN WCode = 'ce' THEN
do
'S_PROMPT' 'Enter Comment,' 'Comment'
'S_SELECT_WORD'
'S_DEL_SELECTED'
StrLen = LENGTH( Comment )
Justify = 'LEFT'
IF Justify = 'RIGHT' THEN
IF ( StrLen >= 70 ) THEN
CommentCol = 1
ELSE
CommentCol = 70 - StrLen + 1
ELSE
CommentCol = 45
'S_END_OF_LINE'
IF rc \= 0 THEN DO
SAY 'S_ Error = ' rc
EXIT
END
'S_GET_COL_NUM' 'CURRCOL'
IF rc \= 0 THEN DO
SAY 'S_ Error = ' rc
EXIT
END
IF CurrCol < CommentCol THEN
DO
'S_GOTO_COL' CommentCol
'S_INSERT_STRING' '// ' || Comment
END
ELSE
DO
'S_PREV_LINE'
'S_END_OF_LINE'
ForceNewLine = ' '
'S_INSERT_LINE' ForceNewLine
NewComment = COPIES(' ', CommentCol - 1 ) || '// ' || Comment
'S_INSERT_STRING' NewComment
END
end
WHEN WCode = 'h' THEN
do
'S_SELECT_WORD'
'S_DEL_SELECTED'
'S_PROMPT' 'Enter Function Comments,' 'NEWFILENAME'
comment = '/'|| copies('*',67)
'S_INSERT_LINE' comment
'S_INSERT_LINE' '*'
'S_INSERT_LINE' '* ' || NEWFILENAME
'S_INSERT_LINE' '*'
comment = copies('*',67) || '/'
'S_INSERT_LINE' comment
end
OTHERWISE
NOP
end
exit
insertcode: procedure expose MoreInLine FULLCode
parse arg CodeToAdd
'S_SELECT_WORD'
'S_DEL_SELECTED'
'S_INSERT_STRING' CodeToAdd
if MoreInLine == 1 then do
'S_PREV_CHAR'
'S_DEL_CHAR'
'S_DEL_CHAR'
'S_END_OF_LINE'
do forever
'S_PREV_CHAR'
'S_GET_CURR_CHAR' 'curchar'
if (curchar \= " " & curchar \= ";") then leave
'S_DEL_CHAR'
end
'S_NEXT_CHAR'
'S_INSERT_STRING' ')'
end
if FULLCode == 1 then do
'S_GET_LINE_NUM' 'SaveLineNum'
'S_GET_COL_NUM' 'SaveColNum'
'S_INSERT_LINE' ' {'
'S_INDENT'
'S_INSERT_STRING }'
'S_GOTO_LINE' SaveLineNum
'S_GOTO_COL' SaveColNum
end
return
insertline: procedure
parse arg CodeToAdd
'S_SELECT_WORD'
'S_DEL_SELECTED'
'S_INSERT_LINE' CodeToAdd
'S_INDENT'
return
insertpaste: procedure
'S_PREV_LINE'
'S_GET_LINE_NUM' 'ZAnum'
'S_INSERT_PASTE'
'S_GET_LINE_NUM' 'ZEnum'
'S_GOTO_LINE' ZAnum
AddTab = '9'x
do I=ZAnum+1 to ZEnum by 1
'S_BEG_OF_LINE'
'S_INSERT_STRING' AddTab
'S_NEXT_LINE'
end
return
isMoreInLine: procedure
'S_GET_COL_NUM' 'Col'
'S_GET_LINE_LEN' 'LLen'
return LLen > (Col+2)
UP: /* search back line with brace at 1 pos */
'S_GET_LINE_NUM' 'SaveLineNum'
'S_GET_COL_NUM' 'SaveColNum'
'S_SEARCH_BACK' 1 '{'
do forever
if RC = 0 then do
'S_GET_COL_NUM' 'ColNum'
if ColNum <= 2 then do
'S_ENABLE_WINDOW'
exit
end
else
'S_SEARCH_NEXT'
end
else
leave
end
'S_GOTO_LINE' SaveLineNum
'S_GOTO_COL' SaveColNum
'S_ENABLE_WINDOW'
exit
DOWN: /* search forward for line with brace at 1 pos */
'S_GET_LINE_NUM' 'SaveLineNum'
'S_GET_COL_NUM' 'SaveColNum'
'S_SEARCH_FWD' 1 0 '{'
do forever
if RC = 0 then do
'S_GET_COL_NUM' 'ColNum'
if ColNum <= 2 then do
'S_ENABLE_WINDOW'
exit
end
else
'S_SEARCH_NEXT'
end
else
leave
end
'S_GOTO_LINE' SaveLineNum
'S_GOTO_COL' SaveColNum
'S_ENABLE_WINDOW'
exit
/* Get the function header an put it unter the FTY - comment on top of file */
/* Current position has to be the line containing the function declaration */
/* For my needs only 1 line is ok. Change the code for more lines */
FCTYPE:
'S_GET_LINE_NUM' 'SaveLineNum'
'S_GET_COL_NUM' 'SaveColNum'
'S_SELECT_LINE'
'S_GET_SELECTED_TEXT' 'FtyLine'
'S_SEARCH_FWD' 1 1 '/*FTY*/'
if RC = 0 then do
'S_NEXT_LINE'
'S_BEG_OF_LINE'
'S_INSERT_STRING' INSERT(';',FtyLine,LENGTH(FtyLine)-2)
end
'S_GOTO_LINE' SaveLineNum+1
'S_GOTO_COL' SaveColNum
'S_ENABLE_WINDOW'
exit