× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Somebody asked for a sample of a Code macro.  I was tinkering with a parser
for RPG (to enforce standards) and worked up a skeleton.  It's bare-bones
but shows some of the things one can do in ReXX.  Comments and critiques
welcome!

/* Parse out RPG names */
/* Lessons learnt:
   1) Use the macro log!  (ALT-W, a) */

/* Make sure we're reading rpg! */
'extract doctype into sourceDocType'
if (sourceDocType <> 'IRP') then
  do
    say '"'sourceDocType'" files can''t be processed.'
    exit
  end

/* Find the install directory */
'extract global.CODEINSTALLDIR into codeDir'

/* Who am I? */
'extract docnum into sourceDoc'
'extract name into sourceName'

/* create the log window, and go there */
lx codeDir'\Tmp\names.txt'
'extract docnum into targetDoc'
'insert Name log from' sourceName

/* Go back to the source window */
lxi 'godoc docnum' sourceDoc

/* move to top of source and begin processing */
top
'extract elements into sourceLineCount'

/* Read lines */
do i = 1 to sourceLineCount
  'extract content into sourceLine'

  /* log the line into the target */
  lxi 'godoc docnum' targetDoc
  insert sourceLine

  /* Parse it */
  select
  when sourceDocType='IRP' then
    rc = parseRPG(sourceLine)
  otherwise
    NOP
  end

  /* move down one line */
  lxi 'godoc docnum' sourceDoc
  primitive newline

end

exit

parseRPG: procedure
  parse upper arg line

  /* What sort of line is it? */
  spec                 = substr(line,6,1)
  commentFlag          = substr(line,7,1)
  compileTimeArrayFlag = substr(line,1,2)

  if (compileTimeArrayFlag = '**') then
    do
      insert 'CT data found - ending'
      exit
    end

  select
  when (commentFlag = '*') then do
    NOP
    end
  when (spec=' ') then do
    NOP
    end
  when (spec='H') then do
    NOP
    end
  when (spec='F') then do
    rc=parseRPGFspec(line)
    end
  when (spec='D') then do
    NOP
    end
  when (spec='I') then do
    NOP
    end
  when (spec='C') then do
    NOP
    end
  when (spec='O') then do
    NOP
    end
  otherwise
    insert 'unknown'
  end

return 0


parseRPGFspec: procedure
  parse arg line

  /* fixed columns */
  fileName=substr(line,7,10)
  if (fileName<>'') then
    insert 'file name='fileName

  /* keywords */
  parse var line pre '(' kwd ')' post
  /* kwd with colon like sfile(recfmt:sflrrn) */
  if (POS(':',kwd)>0) then do
    parse var kwd kwd1 ':' kwd2
    insert 'kwd1='STRIP(kwd1)
    insert 'kwd2='STRIP(kwd2)
  end
  else
    insert 'kwd='STRIP(kwd)

return 0

  --buck


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.