// Detect It Easy: detection rule file
// Author: Jason Hood <jadoxa@yahoo.com.au>

meta("compiler", "WATCOM C");

function detect() {
    if (MSDOS.compareEP("E9....'WATCOM C'")) {
        bDetected = true;
    } else if (MSDOS.isSignaturePresent(0, Math.min(2048, MSDOS.getSize()), "'WATCOM C'")) {
        bDetected = true;
    } else if (MSDOS.isLE()) {
        var nLE = MSDOS.getNEOffset();
        var nDataPage = MSDOS.readDword(nLE + 0x80);
        var nOffset = MSDOS.readDword(nLE + 0x1C);
        if (MSDOS.compare("EB..'WATCOM C'", nDataPage + nOffset)) {
            bDetected = true;
        }
    } else if (MSDOS.compareEP("e9$$$$fbb9....8ec126bb....83c3..80e3..26891e....268c1e....01e383c3..80e3..8ed189dc26891e....89dad1ea")) {
        sName = "Open Watcom C/C++16";
        sVersion = "2002 by Sybase, Inc.";
        bDetected = true;
    } else if (MSDOS.compareEP("e9$$$$fbb9....8ec1bb....83c3..80e3..26891e....268c1e")) {
        sName = "Open Watcom C/C++16";
        sVersion = "1988-2002 by Sybase, Inc.";
        bDetected = true;
    } else if (MSDOS.compareEP("8cd8bb....8edb8b1e....0bdb74..8cd18bd4fa8ed3bc....fb50535152a3....e8....5a595b580bdb74..fa8ed18be2fb")) {
        sName += "/C++";
        sVersion = "1990 by WATCOM Systems Inc.";
        bDetected = true;
    } else if (MSDOS.compareEP("eb$$2e8c06....2e8c16....2e8926....fa8cc88ed0bc....fb2ec706........b8....cd213c..72..2e830e......e8....8bd8")) {
        sName += "/C++";
        sVersion = "1991 by WATCOM Systems Inc.";
        bDetected = true;
    } else if (MSDOS.compareEP("eb$$2e8c06....2e8c16....2e8926....2ea1....2e0306....fa8ed0bc....fbb8....b1..d3e874..33c054593bcc75..9cb9")) {
        sVersion = "1992 by WATCOM Systems Inc.";
        bDetected = true;
    } else if (MSDOS.compareEP("eb$$33ed2e8e1e....26a1....a3....8d06....a3....8d06....a3....8d06....a3....8cd88d1e....8ed08be3bb....26891e")) {
        sName += " 386";
        sVersion = "1990 by WATCOM Systems Inc.";
        bDetected = true;
    } else if (MSDOS.compareEP("eb$$2e8c06....2e8c16....2e8926....2ea3....2e8916....2e891e....fa8cc88ed0bc....fbe8....8bd8e8....2ea2....fa")) {
        sVersion = "1990 by WATCOM Systems Inc.";
        bDetected = true;
    } else if (MSDOS.compareEP("faba....8eda8916....8c06....8c0e....b8....a3....b8....a3....8ed28be0fb0633c9518becbe....268b04a3....8ec28e1e")) {
        sVersion = "1988 by WATCOM Systems Inc.";
        bDetected = true;
    } else if (MSDOS.compareEP("eb$$2e8c06....2e8c16....2e8926....2ea3....2e8916....2e891e....2e8c1e....fa8cc88ed0bc....fbe8....8bd8fa2e8e16")) {
        sVersion = "1992 by WATCOM Systems Inc.";
        bDetected = true;
    } else if (MSDOS.compareEP("EB....00'*** NULL assignment detected'00'")) {
        sName = "Open Watcom C/C++16";
        sVersion = "2.0";
        bDetected = true;
    }

    sLang = sName.indexOf("C++") !== -1 ? "C" : "C++";

    return result();
}