How to check if lib, cell, or view exists?

Discussion in 'Cadence' started by Reotaro Hashemoto, Jun 25, 2009.

  1. Hi,

    I was using a SKILL code to let the use graphically browse for a cell.
    I tried to check if the lib, cell, or view exists, and if not print an
    error message and return nil.

    This is my trial:
    libName = CSForm->srcLib->value
    cellName = CSForm->srcCell->value
    viewName = CSForm->srcView->value

    ; Try to check if lib, cell, and view exists otherwise give error and
    return(nil)!!!
    prog(()
    when( null(ddGetObj(libName))
    printf("Unkown library %L" libName)
    return(nil)

    when( null(ddGetObj(libName cellName))
    printf("Unknown cell %L" cellName)
    return(nil)

    when( null(ddGetObj(libName cellName viewName))
    printf("Unknown view %L" viewName)
    return(nil)
    )
    )
    )
    ); prog

    I can't catch why it is not working..

    Any notice?
    Thanks,
    Ahmad
     
    Reotaro Hashemoto, Jun 25, 2009
    #1
  2. Reotaro Hashemoto wrote, on 06/25/09 08:52:
    Ahmad,

    Because it will never reach the second when if the library exists. The first
    condition is null(ddGetObj(libName)) - that will be true if the library does not
    exist, and so the whole of the code inside the when body only gets executed if
    the library does not exist. The same is true for the second when.

    A better approach is:

    cond(
    (!ddGetObj(libName)
    printf("Unknown library %s\n" libName)
    nil)
    (!ddGetObj(libName cellName)
    printf("Unknown cell %s\n" cellName)
    nil)
    (!ddGetObj(libName cellName viewName)
    printf("Unknown view %s\n" viewName)
    nil)
    ; it exists, so return t
    (t t)
    )

    cond() is essentially an efficient and compact if-elseif-elseif-else type form.

    Regards,

    Andrew.
     
    Andrew Beckett, Jun 25, 2009
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.