#! srexx

/*
 *   main_name: returns either the current file file-name, or "main" if
 *              "main" is found in it
 *
 *   Warning: the first line must start with #! srexx in order
 *            to allow dynamic loading
 */

signal on novalue

/* procedure: */

'extract/line/scope/fname/cursor'

if line.0 = 0 then return ''

trace off
'top'
'scope all'

/*
 * We look for something like   main (
 */
'r/\<main\> *('
rr = rc
'delay'

lg_main = ~rr
':'line.1
'scope 'scope.1
'cursor screen 'cursor.1 cursor.2
'msg'

if lg_main then return 'main'
else            return fname.1
