###
DEF 5.8 C/C++ Programming Interface (Open Licensing Program)

# 2

# DEF Reader Setup and Control Routines

The Cadence® Design Exchange Format (DEF) reader provides several routines that initialize the reader and set global variables that are used by the reader.

The following routines described in this section set options for reading a DEF file.

| defrInit

| defrInitSession

| defrClear

| defrRead

| defrSetUserData

| defrGetUserData

| defrSetAddPathToNet

| defrSetAllowComponentNets

| defrGetAllowComponentNets

| defrSetCommentChar

| defrSetRegisterUnusedCallbacks

| defrPrintUnusedCallbacks

| defrUnusedCallbackCount

## DEF API Routines

The following DEF reader setup and control routines are available in the API.

### defrInit

Initializes internal variables in the DEF reader. You must use this routine before using defrRead. You can use other routines to set callback functions before or after this routine.

#### Syntax

int defrInit()

### defrInitSession

Starts a new parsing session and closes any old parsing session, if open. You must use this routine before using defrRead.

#### Syntax

int defrInitSession (
  int startSession = 1)

#### Arguments

startSession

> Boolean. If is non-zero, performs the parser initialization in session-based mode; otherwise, the function will initialize parsing in the compatibility mode, working exactly as a defrInit() call.

### defrClear

Releases all parsing session data and closes the parsing session. If the call to defrClear() is skipped, the data cleaning and the session closing is done by the next defrInitSession() call.

#### Syntax

int defrClear()

### defrRead

Specifies the DEF file to read. Any callbacks that have been set are called from within this routine. If the file parses with no errors, that is, all callbacks return OK condition codes, this routine returns zero.

#### Syntax

int defrRead(
  FILE*
file,
const char* fileName,
defiUserData* data,
int case_sensitive)

#### Arguments

file

> Specifies a pointer to an already open file. This allows the parser to work with either a disk file or a piped stream. This argument is required. Any callbacks that have been set will be called from within this routine.

fileName

> Specifies a UNIX filename using either a complete or a relative path specification.

data

> Specifies the data type.

case_sensitive

> Specifies whether the data is case sensitive.

### defrSetUserData

Sets the user-provided data. The DEF reader does not look at this data, but passes an opaque defiUserData pointer back to the application with each callback. You can set or change the user data at any time using the defrSetUserData and defrGetUserData routines. Every callback returns user data as the third argument.

#### Syntax

void defrSetUserData(
  defiUserData*
data)

#### Arguments

data

> Specifies the user-provided data.

### defrGetUserData

Retrieves the user-provided data. The DEF reader returns an opaque defiUserData pointer, which you set using defrSetUserData. You can set or change the user data at any time with the defrSetUserData and defrGetUserData calls. Every callback returns the user data as the third argument.

#### Syntax

defiUserData defrGetUserData()

### defrSetAddPathToNet

Adds path data to the appropriate net data. When the net callback is used, the net class and structure information and the path information are returned. This statement does not require any additional arguments.

#### Syntax

void defrSetAddPathToNet(void)

### defrSetAllowComponentNets

Ignores component net information. Component nets are valid DEF syntax but are no longer used. By default, the DEF reader reports component net data as a syntax error. This routine overrides the default so no error is reported. This statement does not require any additional arguments.

#### Syntax

void defrSetAllowComponentNets(void)

### defrGetAllowComponentNets

Returns non-zero value if component nets are allowed.

#### Syntax

int defrGetAllowComponentNets()

### defrSetCommentChar

Changes the character used to indicate comments in the DEF file.

#### Syntax

void defrSetCommentChar(char c)

#### Arguments

c

> Specifies the comment character. The default is a pound sign (#).

### defrSetRegisterUnusedCallbacks

Keeps track of all the callback routines that are not set. You can use this routine to keep track of DEF constructs that are in the input file but do not trigger a callback. This statement does not require any additional arguments.

#### Syntax

void defrSetRegisterUnusedCallbacks(void)

### defrPrintUnusedCallbacks

Prints all callback routines that are not set but have constructs in the DEF file.

#### Syntax

void defrPrintUnusedCallbacks(FILE* log)

#### Arguments

log

> Specifies the file to which the unused callbacks are printed.

### defrUnusedCallbackCount

Returns the number of callback routines that are not set. That is, routines that have constructs in the input file but no callback trigger. This statement does not require any additional arguments.

#### Syntax

int* defrUnusedCallbackCount(void)

### Example

The following example shows how to initialize the reader.

int setupRoutine() {
  FILE* f;
  int res;
  int userData = 0x01020304;
  ...

  // Initialize the reader. This routine has to call first.
  defrInit();

  // Set user data
  defrSetUserData ((void *)3);

  // Open the def file for the reader to read
  if ((f = fopen("defInputFileName","r")) == 0) {
  printf("Couldn't open input file '%s'\n",
  "defInputFileName");
  return(2);
  }
  // Invoke the parser
  res = defrRead(f, "defInputFileName", (void*)userData);
  if (res != 0) {
  printf("DEF parser returns an error\n");
  return(2);
  }
  fclose(f);
  return 0;}

Return to top of page

For support, see Cadence Online Support service.
Copyright © 2016, Cadence Design Systems, Inc.
All rights reserved.