OScript Beautifier

OpenText Content Server Builder is the IDE for OpenText Content Server. It's an advanced IDE given its age, but a missing feature of the IDE is a code formatter. For example, consider the following OScript and imagine how difficult it would be to read if it were 500 lines long (yes, some people write scripts this long, but that's another topic):

/**
* Dump a module to the file system.
*/
function dump(String moduleName, \
String subdirectory="dmp")

Object module = $Kernel.ModuleSubsystem.GetItem(moduleName)

if IsDefined( module )

String ospace

 for ospace in module.fOSpaces
String path = module.PathPrefix() + subdirectory + File.Separator()
File.Create(path)
String filename = Str.Format('%1%2.dmp', path, ospace)
$Builder.Utilities.ExportOSpace( filename, OS.Root(ospace) )
end

    else
echo("Module not found: %1", moduleName)
end
  end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

To fix this problem I created an OScript Beautifier, which formats OScript into something more readable:

/**
 * Dump a module to the file system.
 */
function dump(String moduleName, \
        String subdirectory="dmp")

    Object module = $Kernel.ModuleSubsystem.GetItem(moduleName)

    if IsDefined( module )

        String ospace

        for ospace in module.fOSpaces
            String path = module.PathPrefix() + subdirectory + File.Separator()
            File.Create(path)
            String filename = Str.Format('%1%2.dmp', path, ospace)
            $Builder.Utilities.ExportOSpace( filename, OS.Root(ospace) )
        end

    else
        echo("Module not found: %1", moduleName)
    end
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

The beautifier integrates into Builder and can be run against a script by executing a function from the Tools menu. It has saved me countless hours of formatting.

You can download beautify_oscript.lxe (opens new window) from GitHub as a Gist. Feel free to clone the gist and improve it.