def tokenize_line(line):
    """
    Tokenize a line:
    * split tokens on whitespace
    * treat quoted strings as a single token
    * drop comments
    * handle escaped spaces and comment delimiters
    """
    ret = []
    escape = False
    quote = False
    tokbuf = ''
    ll = list(line)
    while len(ll) > 0:
        c = ll.pop(0)
        if c.isspace():
            if not quote and not escape:
                if len(tokbuf) > 0:
                    ret.append(tokbuf)
                tokbuf = ''
            elif quote:
                tokbuf += c
            elif escape:
                tokbuf += c
                escape = False
            else:
                tokbuf = ''
            continue
        if c == '\\':
            escape = True
            continue
        elif c == '"':
            if not escape:
                if quote:
                    ret.append(tokbuf)
                    tokbuf = ''
                    quote = False
                    continue
                else:
                    quote = True
                    continue
        elif c == ';':
            if not escape:
                ret.append(tokbuf)
                tokbuf = ''
                break
        tokbuf += c
        escape = False
    if len(tokbuf.strip(' ').strip('\n')) > 0:
        ret.append(tokbuf)
    return ret
