Mrs S” works for a large software vendor. This vendor has a tendency to quickly increase staffing to hit arbitrary release targets, and thus relies heavily on contractors. Since they’re usually doing this during a time crunch, these contractors may have a… dubious skill set.

They also don’t care. There is no documentation, no tests, and no explanation. They are just paid tho write the code, not maintain it. They’ll be on another contract before long, so it’s some other schmuck’s problem.

Which is why “Mrs S” found this code, which takes a version number, as a pair of integers, and converts them to a string, but still couldn’t tell you why it does any of the things that it does.

void SetFileName(unsigned short FileID, unsigned short* VersionNumber)
{
    //...
    for (i = 0; i < 2; i++)
    {
        if (VersionNumber[i] > 89)
        {
            FilePutName[13 + (2 * i) + i] = '9';
            switch (VersionNumber[i])
            {
            case 91:
                FilePutName[14 + (2 * i) + i] = '1';
                break;
            case 92:
                FilePutName[14 + (2 * i) + i] = '2';
                break;
            case 93:
                FilePutName[14 + (2 * i) + i] = '3';
                break;
            case 94:
                FilePutName[14 + (2 * i) + i] = '4';
                break;
            case 95:
                FilePutName[14 + (2 * i) + i] = '5';
                break;
            case 96:
                FilePutName[14 + (2 * i) + i] = '6';
                break;
            case 97:
                FilePutName[14 + (2 * i) + i] = '7';
                break;
            case 98:
                FilePutName[14 + (2 * i) + i] = '8';
                break;
            case 99:
                FilePutName[14 + (2 * i) + i] = '9';
                break;
            }
        }
        else if (VersionNumber[i] > 79)
        {
            FilePutName[13 + (2 * i) + i] = '8';
            switch (VersionNumber[i])
            {
            case 81:
                FilePutName[14 + (2 * i) + i] = '1';
                break;
            case 82:
                FilePutName[14 + (2 * i) + i] = '2';
                break;
            case 83:
                FilePutName[14 + (2 * i) + i] = '3';
                break;
            case 84:
                FilePutName[14 + (2 * i) + i] = '4';
                break;
            case 85:
                FilePutName[14 + (2 * i) + i] = '5';
                break;
            case 86:
                FilePutName[14 + (2 * i) + i] = '6';
                break;
            case 87:
                FilePutName[14 + (2 * i) + i] = '7';
                break;
            case 88:
                FilePutName[14 + (2 * i) + i] = '8';
                break;
            case 89:
                FilePutName[14 + (2 * i) + i] = '9';
                break;
            }
        }
        else if (VersionNumber[i] > 69)
        {
            FilePutName[13 + (2 * i)] = '7';
            switch (VersionNumber[i])
            {
            case 71:
                FilePutName[14 + (2 * i) + i] = '1';
                break;
            case 72:
                FilePutName[14 + (2 * i) + i] = '2';
                break;
            case 73:
                FilePutName[14 + (2 * i) + i] = '3';
                break;
            case 74:
                FilePutName[14 + (2 * i) + i] = '4';
                break;
            case 75:
                FilePutName[14 + (2 * i) + i] = '5';
                break;
            case 76:
                FilePutName[14 + (2 * i) + i] = '6';
                break;
            case 77:
                FilePutName[14 + (2 * i) + i] = '7';
                break;
            case 78:
                FilePutName[14 + (2 * i) + i] = '8';
                break;
            case 79:
                FilePutName[14 + (2 * i) + i] = '9';
                break;
            }
        }
        else if (VersionNumber[i] > 59)
        {
            FilePutName[13 + (2 * i) + i] = '6';
            switch (VersionNumber[i])
            {
            case 61:
                FilePutName[14 + (2 * i) + i] = '1';
                break;
            case 62:
                FilePutName[14 + (2 * i) + i] = '2';
                break;
            case 63:
                FilePutName[14 + (2 * i) + i] = '3';
                break;
            case 64:
                FilePutName[14 + (2 * i) + i] = '4';
                break;
            case 65:
                FilePutName[14 + (2 * i) + i] = '5';
                break;
            case 66:
                FilePutName[14 + (2 * i) + i] = '6';
                break;
            case 67:
                FilePutName[14 + (2 * i) + i] = '7';
                break;
            case 68:
                FilePutName[14 + (2 * i) + i] = '8';
                break;
            case 69:
                FilePutName[14 + (2 * i) + i] = '9';
                break;
            }
        }
        else if (VersionNumber[i] > 49)
        {
            FilePutName[13 + (2 * i) + i] = '5';
            switch (VersionNumber[i])
            {
            case 51:
                FilePutName[14 + (2 * i) + i] = '1';
                break;
            case 52:
                FilePutName[14 + (2 * i) + i] = '2';
                break;
            case 53:
                FilePutName[14 + (2 * i) + i] = '3';
                break;
            case 54:
                FilePutName[14 + (2 * i) + i] = '4';
                break;
            case 55:
                FilePutName[14 + (2 * i) + i] = '5';
                break;
            case 56:
                FilePutName[14 + (2 * i) + i] = '6';
                break;
            case 57:
                FilePutName[14 + (2 * i) + i] = '7';
                break;
            case 58:
                FilePutName[14 + (2 * i) + i] = '8';
                break;
            case 59:
                FilePutName[14 + (2 * i) + i] = '9';
                break;
            }
        }
        else if (VersionNumber[i] > 39)
        {
            FilePutName[13 + (2 * i) + i] = '4';
            switch (VersionNumber[i])
            {
            case 41:
                FilePutName[14 + (2 * i) + i] = '1';
                break;
            case 42:
                FilePutName[14 + (2 * i) + i] = '2';
                break;
            case 43:
                FilePutName[14 + (2 * i) + i] = '3';
                break;
            case 44:
                FilePutName[14 + (2 * i) + i] = '4';
                break;
            case 45:
                FilePutName[14 + (2 * i) + i] = '5';
                break;
            case 46:
                FilePutName[14 + (2 * i) + i] = '6';
                break;
            case 47:
                FilePutName[14 + (2 * i) + i] = '7';
                break;
            case 48:
                FilePutName[14 + (2 * i) + i] = '8';
                break;
            case 49:
                FilePutName[14 + (2 * i) + i] = '9';
                break;
            }
        }
        else if (VersionNumber[i] > 29)
        {
            FilePutName[13 + (2 * i) + i] = '3';
            switch (VersionNumber[i])
            {
            case 31:
                FilePutName[14 + (2 * i) + i] = '1';
                break;
            case 32:
                FilePutName[14 + (2 * i) + i] = '2';
                break;
            case 33:
                FilePutName[14 + (2 * i) + i] = '3';
                break;
            case 34:
                FilePutName[14 + (2 * i) + i] = '4';
                break;
            case 35:
                FilePutName[14 + (2 * i) + i] = '5';
                break;
            case 36:
                FilePutName[14 + (2 * i) + i] = '6';
                break;
            case 37:
                FilePutName[14 + (2 * i) + i] = '7';
                break;
            case 38:
                FilePutName[14 + (2 * i) + i] = '8';
                break;
            case 39:
                FilePutName[14 + (2 * i) + i] = '9';
                break;
            }
        }
        else if (VersionNumber[i] > 19)
        {
            FilePutName[13 + (2 * i) + i] = '2';
            switch (VersionNumber[i])
            {
            case 21:
                FilePutName[14 + (2 * i) + i] = '1';
                break;
            case 22:
                FilePutName[14 + (2 * i) + i] = '2';
                break;
            case 23:
                FilePutName[14 + (2 * i) + i] = '3';
                break;
            case 24:
                FilePutName[14 + (2 * i) + i] = '4';
                break;
            case 25:
                FilePutName[14 + (2 * i) + i] = '5';
                break;
            case 26:
                FilePutName[14 + (2 * i) + i] = '6';
                break;
            case 27:
                FilePutName[14 + (2 * i) + i] = '7';
                break;
            case 28:
                FilePutName[14 + (2 * i) + i] = '8';
                break;
            case 29:
                FilePutName[14 + (2 * i) + i] = '9';
                break;
            }
        }
        else if (VersionNumber[i] > 9)
        {
            FilePutName[13 + (2 * i) + i] = '1';
            switch (VersionNumber[i])
            {
            case 11:
                FilePutName[14 + (2 * i) + i] = '1';
                break;
            case 12:
                FilePutName[14 + (2 * i) + i] = '2';
                break;
            case 13:
                FilePutName[14 + (2 * i) + i] = '3';
                break;
            case 14:
                FilePutName[14 + (2 * i) + i] = '4';
                break;
            case 15:
                FilePutName[14 + (2 * i) + i] = '5';
                break;
            case 16:
                FilePutName[14 + (2 * i) + i] = '6';
                break;
            case 17:
                FilePutName[14 + (2 * i) + i] = '7';
                break;
            case 18:
                FilePutName[14 + (2 * i) + i] = '8';
                break;
            case 19:
                FilePutName[14 + (2 * i) + i] = '9';
                break;
            }
        }
        else
        {
            switch (VersionNumber[i])
            {
            case 1:
                FilePutName[14 + (2 * i) + i] = '1';
                break;
            case 2:
                FilePutName[14 + (2 * i) + i] = '2';
                break;
            case 3:
                FilePutName[14 + (2 * i) + i] = '3';
                break;
            case 4:
                FilePutName[14 + (2 * i) + i] = '4';
                break;
            case 5:
                FilePutName[14 + (2 * i) + i] = '5';
                break;
            case 6:
                FilePutName[14 + (2 * i) + i] = '6';
                break;
            case 7:
                FilePutName[14 + (2 * i) + i] = '7';
                break;
            case 8:
                FilePutName[14 + (2 * i) + i] = '8';
                break;
            case 9:
                FilePutName[14 + (2 * i) + i] = '9';
                break;
            }
        }
    }
}

It puts me in mind of this sketch from the classic MST3K episode. They just didn’t care.

[Advertisement] Incrementally adopt DevOps best practices with BuildMaster, ProGet and Otter, creating a robust, secure, scalable, and reliable DevOps toolchain.