Please enable JavaScript to view this site.

ESL Documentation

The following sample external conversion routine converts C language 2-byte signed integers to and from ESL integers and floats. For simplicity, this routine handles only ESL floats and integers; it does not handle conversion to ESL strings. When requested to convert data to or from an ESL string, this routine writes an error message to the errorlog and returns a non-zero value indicating that the conversion failed.

 

/********************************************************************

*             Copyright (C) 1982-2016 ESL Syndetic Limited          *

*                     All Rights Reserved.                          *

*                                                                   *

*                           NOTICE                                  *

*                 PROPRIETARY AND CONFIDENTIAL                      *

*                                                                   *

*This computer program is and contains trade secret and confidential*

* and proprietary information of ESL Syndetic Limited. All use,     *

* disclosure, and/or reproduction not specifically authorized in    *

* writing by ESL Syndetic Limited is prohibited. This program may   *

* also be protected under the copyright and trade secrets laws of   *

* countries  other than the U.S.A.                                  *

*                                                                   *

*  ESL is a registered trademark of ESL Syndetic Ltd.               *

********************************************************************/ 

 

#include <io.h>

#include <windows.h>

#include <esllib.h>

#include <esltype.h>

 

char *pszBadArgument = "bad argument\n",

           *pszNotImp = "this conversion not implemented\n",

     *pszNull = "";

 

/* conversion function return codes: */

#define ERR_BADARG          1          /* bad argument */

#define ERR_NOTIMPLEMENTED  2          /* conversion not implemented */

#define ERR_NOMEM           3          /* creation of string failed */

 

int APIENTRY esl_cint ( pField, wType, wFieldLen, 

                        wOpCode, pData, pArg)

char              *pField;      /* address of structure field */ 

unsigned int      wFieldLen,    /* length of structure field */ 

                  wOpCode;      /* conversion opcode */

PEASELTYPE        pData;        /* source OR target data */

char              *pArg;        /* conversion routine argument...*/

                                /* ...if any, (from using clause) */

{

    int retval = 0;         /* indicates successful conversion */

 

    switch (wOpCode)

    {

        case CONVERT_TO_EASEL:         /* convert C integer to Easel type */

            switch (wType)

            {

                /* Always include a case for EACH data type, and     */

                /* code to recognize and handle requests to execute  */

                /* conversions that are not implemented.             */

                

                case ESL_STRING:       /* C integer to Easel string  */

                    /* Write an error message and return an error    */

                    /* code for conversions that are not implemented.*/

                    (void) write (2, pszNotImp, strlen (pszNotImp));

                   if (!(pData->hString = EslCreateString (0, pszNull)))

                         return (ERR_NOMEM);                   

                   return(ERR_NOTIMPLEMENTED);

 

                case ESL_INTEGER:      /* C integer variant to Easel integer */

                    if (wFieldLen == sizeof (int))

                        pData->Integer = (long) (*((int *) pField));

                    else

                    {

                        (void) write (2, pszNotImp, strlen (pszNotImp));

                        return(ERR_NOTIMPLEMENTED);

                    }

                    break;

 

                case ESL_FLOAT:        /* C integer variant to Easel float */

                    if (wFieldLen == sizeof (int))

                        pData->Float = (double) (*((int *) pField));

                    else

                    {

                        (void) write (2, pszNotImp, strlen (pszNotImp));

                        return(ERR_NOTIMPLEMENTED);

                    }

                    break;

 

                default:

                    (void) write (2, pszBadArgument,

                                  strlen (pszBadArgument));

                    return(ERR_BADARG);

                    break;

 

                

            }

 

            break;

                

        case CONVERT_TO_EXTERNAL:

            switch (wType)

            {

                /* Always include a case for EACH data type, and    */

                /* code to recognize and handle requests to execute */

                /* conversions that are not implemented.        */

                

                case ESL_STRING:       /* Easel string to C integer variant */

                    (void) write (2, pszNotImp, strlen (pszNotImp));

                    return(ERR_NOTIMPLEMENTED);

                    break;

 

                case ESL_INTEGER:      /* Easel integer to C integer variant */

                    if (wFieldLen == sizeof (int))

                        (*((int *) pField)) = (int) pData->Integer;

                    else

                    {

                        (void) write (2, pszNotImp, strlen (pszNotImp));

                        return(ERR_NOTIMPLEMENTED);

                    }

                    break;

 

                case ESL_FLOAT:        /* Easel float to C integer variant */

                    if (wFieldLen == sizeof (int))

                        *((int *) pField) = (int) pData->Float;

                    else

                    {

                        (void) write (2, pszNotImp, strlen (pszNotImp));

                        return(ERR_NOTIMPLEMENTED);

                    }

                    break;

 

                default:

                    (void) write (2, pszBadArgument,

                                  strlen (pszBadArgument));

                    return(ERR_BADARG);

                    break;

            }

 

            break;

 

        default:

            (void) write (2, pszBadArgument, strlen (pszBadArgument));

            return(ERR_BADARG);

            break;

    }

    return(retval);

}