/*
 * $VER: ged4indent 1.0 (26.1.97)
 *
 * ged4indent - indent a C sourcefile in GoldEd, using GNUindent
 *
 * Written by Thomas Aglassinger <agi@giga.or.at>
 */

/*
 * The variable `indentOpts' holds the command line
 * options, which are passed to indent to format ouput.
 * You can adopt them to your needs.
 * The default formats corresponds to the style GoldEd
 * supports.
 */
indentOpts = "-br -ce -i4 -sob -sc -npsl -npcs -lp"

/* style I prefer: */
/* indentOpts = "-bl -bli0 -i4 -sob -sc -npsl -npcs -lp" */

OPTIONS RESULTS                             /* enable return codes     */

if (LEFT(ADDRESS(), 6) ~= "GOLDED") then    /* not started by GoldEd ? */
    address 'GOLDED.1'

'LOCK CURRENT RELEASE=4'                    /* lock GUI, gain access   */
OPTIONS FAILAT 6                            /* ignore warnings         */
SIGNAL ON SYNTAX                            /* ensure clean exit       */

/* obtain current filename */
'QUERY DOC VAR=filename'
filename = RESULT

/* save file, remember current position */
'SAVE ALL'
'PING 0'

/* invoke indent */
indentCommand = 'indent' indentOpts '-o "' || filename || '" "' || filename || '"'
ADDRESS COMMAND indentCommand

/* reload indented file, restore position */
'OPEN AGAIN FORCE'
'PONG 0'

'UNLOCK' /* VERY important: unlock GUI */
EXIT

SYNTAX:

SAY "Sorry, error line" SIGL ":" ERRORTEXT(RC) ":-("
'UNLOCK'
EXIT
