The initial file name is determined by the name of the unit that the file contains. The name is formed by taking the full expanded name of the unit and replacing the separating dots with hyphens and using lowercase for all letter, except that a hyphen in the second character position is replaced by a tilde if the first character is a, i, g, or s. The extension is .ads for a specification and .adb for a body. Crunching does not affect the extension, but the file name is shorted to the specified length by following these rules:
The name is divided into segments separated by hyphens, tildes or underscores and all hyphens, tildes, and underscores are eliminated. If this leaves the name short enough, we are done.
If not the longest segment is located (left-most if there are two of equal length), and shortened by dropping its last character. This is repeated until the name is short enough.
As an example, consider the krunch of our-strings-wide_fixed.adb to fit the name into 8 characters as required by some operating systems.
The file names for all predefined units are always crunched to eight characters. The crunching of these predefined units uses the following special prefix replacements:
replaced by a-
replaced by g-
replaced by i-
replaced by s-
These system files have a hyphen in the second character position. That is why normal user files replace such a character with a tilde, to avoid confusion with system file names.
As an example of this special rule, consider ada-strings-wide_fixed.adb, which gets crunched as follows:
Of course no file shortening algorithm can guarantee uniqueness over all possible unit names, and if file name crunching is used then it is your responsibility to ensure that no name clashes occur. The utility program gnatkr is supplied for conveniently determining the crunched name of a file.