Advertisement

07.06.2007 at 08:40AM PDT, ID: 22679606
[x]
Attachment Details

error C3163: '_vsnprintf': attributes inconsistent with previous declaration

Asked by jnash67 in C Programming Language

Tags: , , , ,

I have an example from Bloomberg that compiles fine in Visual Studio 2003 but gives an error in VS 2008 ORCAS Beta 1.  The only changes I made is made it a .cpp instead of a .c and put in place some reinterpret_casts since the conversion from int * to long * wasn't happening automatically anymore.

In the new Visual Studio I get:

1>------ Rebuild All started: Project: getBBData, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'getBBData', configuration 'Debug|Win32'
1>Compiling...
1>getBBData.cpp
1>c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : error C3163: '_vsnprintf': attributes inconsistent with previous declaration
1>Creating browse information file...
1>Microsoft Browse Information Maintenance Utility Version 9.00.20404
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Build log was saved at "file://c:\code\C_SDK\getBBData VS2007\Debug\BuildLog.htm"
1>getBBData - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========



---------

/*
*THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT
*WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
*INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
*OF MERCHANTABILITY AND/OR FITNESS FOR A  PARTICULAR
*PURPOSE.
*
** Example5.c
**
**
** This program uses the bb_getdatax() call
** You can pass here regular and Bulk fields (0x153f is a Bulk field)
** It also loads the Data Dictionary (bbfields.tbl file) in order to verify if any of
** the requested fields is a Bulk field. There is another example (example6) that
** shows how to use the bb_load_datadictx() function. If you use this function then you must
** define in the Preprocessor Defenitions BB_USING_DLL.
** You can pass a list of securities, fields override fields and override values
** as a command line arguments.
** Here are examples of different requestst:
** Regular Request:
**    example5.exe -s IBM US Equity -s NMX Index -s DELL US Equity -t 730 -f 4aa -f 153f -f 452
** General Override Request:
**    example5.exe -s CT30 Govt -s CT5 Govt -s CT10 Govt -t 730 -f 555  -f 40b  -f 457 -o 555=95.5
** VWAP Request via Overrides:
**    example5.exe -s AAL LN Equity -t 730 -f B60 -o 16BF=20021010 -o 16BD=9:0 -o 16BE=11:00
** -d defaults run, no need to pass securities and fields; it will ignore all other parameters
**    1 for regular fields,
**    2 for regular override
**    3 for VWAP request
** -s is a flag for securities
** -t security type
** -f is a field ID, must be presented as HEX values from the
**    bbfields.tbl file, DO NOT put 0x infront of it.
** -o is a flag fpr overrides
** -f full path to the data dictionary file
** -x is a flag to specify which function to use bb_getdata or bb_getdatax
**    if set 0 then use the bb_getdata, default is 1
** You can run it with no argumnts then it will run its #1 default request
**
** It demonstrates many of the basic techniques for programming the api.
** It is mostly useful to check your build environment.
**
*/

#include "bbapi.h"
#include "bbunix.h"

/* The standard port bbcomm is listening on */
#define BLP_PORT 8194
/* How long to wait for responses */
#define REQUEST_TIMEOUT 30
/* Size of buffer to receive responses */
#define BUF_SIZE 1024

char *pcSecList;
int *piSecTypeList;
int iTickType;
int iNumOfSec;
int *piFieldList;
long *plRequestID;            /*Global to hold the request IDs */
int iNumOfRequests;
int *piNumOfSecInOneReq;
int iNumOfFields;
int  *piGotResponse;            /*Flags to see if we've gotten the responses*/
int iRecievedRequests;
int *piOverFieldList;
char *plOverValuesList;
int iNumOfOverrides;
int iDefFlag;
char cDataDictPath[250];
int  iIsGetDataX;
int iDefRun;
char *permBuffer;

int end=1;

#ifndef _WINSOCKAPI_
#define SOCKET unsigned int
#endif

static char *szErrorMsg[] =
{
      "#N/A Fld",                 // 0
      "#N/A Tim",                 // 1
      "#N/A Com",                 // 2
      "Not Supported",            // 3
      "#N/A Auth",                // 4
      "#N/A Security",            // 5
      "#N/A Intraday",            // 6
      "#N/A History",             // 7
      "#N/A N.A.",                // 8
      "#N/A N Ap",                // 9
      "#N/A Neg",                 // 10
      "#N/A Sec",                 // 11
      "#N/A Trd",                 // 12
      "#N/A Rl Tim",              // 13
      "#N/A Rl Perm",             // 14
      "#N/A Dberr",               // 15
      "#N/A Sec Tp",              // 16
      "#N/A Limit",               // 17
      "#N/A Trd Fld",             // 18
      "#N/A Dbsize",              // 19
      "#N/A Unknown",             // 20
      "#N/A Hist Fld",            // 21
      "#N/A Rte",                 // 22
      "#N/A RTbl",                // 23
      "#N/A Perm",                // 24
      "#N/A Trd Fld",                        // 25 - Trading systems field
      "#N/A Dif VWAP",                  // 26
      "#N/A No Ovrd VWAP"                  // 27
};

char *GetError(int iErrorCode)
{

    if (iErrorCode)
    {
        switch (iErrorCode)
        {

        // Realtime/get_header return codes:

        case -1:  
            return szErrorMsg[11];
            break;
        case -2:
            return szErrorMsg[11];
            break;
        case -3:
            return szErrorMsg[11];
            break;
        case -4:        
            return szErrorMsg[13];
            break;
        case -5:
            return szErrorMsg[12];
            break;
        case -6:
            return szErrorMsg[13];
            break;

        // History error

        case 100:
            return szErrorMsg[7];
            break;

        case 101:
            return szErrorMsg[21];
            break;

        case 102:
            return szErrorMsg[4];   // Not authorized
            break;

        case 103:
            return szErrorMsg[1];   // Timeout
            break;

        case 104:
            return szErrorMsg[8];   // N.A.
            break;

        // Status message code

        case ErrMSG_FULL_REQ_TABLE:
            return szErrorMsg[23];  // Req Table
            break;
        case ErrMSG_REQ_TIME_OUT:
            return szErrorMsg[1];   // Timeout
            break;
        case ErrMSG_COMM_SERVER_DOWN:
            return szErrorMsg[2];   // Comm Error
            break;
        case ErrMSG_BBDB_SERVER_DOWN:
            return szErrorMsg[15];  // DB Error
            break;
        case ErrMSG_UNAUTHORIZED:
            return szErrorMsg[4];   // Not authorized
            break;
        case ErrMSG_NO_ROUTE:
            return szErrorMsg[22];  // No route
            break;

            // Other errors contained within calcrt text.
            case 8:
            case 11:
            case 15:
            case 16:
            case 17:
            case 19:
            case 20:
            case 24:
            case 25:
            case 26:
            case 27:
            return szErrorMsg[iErrorCode];  
            break;

            case 99:
            return szErrorMsg[10];  
            break;


        // Standard BBDB errors


        case SecUNKNOWN:
            return szErrorMsg[11];
            break;
        case SecNOTPRICED:
            return szErrorMsg[21];
            break;
        case SecPROHIBFIELD:
            return szErrorMsg[4];
            break;
        case SecTYPENOTSUPPORTED:
            return szErrorMsg[16];
            break;
        case SecOTHERERROR:
            return szErrorMsg[15];
            break;
        default:
            return szErrorMsg[20];
            break;
        }
    }

    return NULL;
}

int decode_status_msg(bb_msg_header_t *f)
{
      time_t lRecTime;
      long nErrorCode=0;
      int iReqID=0;

      if (f->comm_header.request_id == BB_VAL_MISSING ||
            f->comm_header.return_code == BB_VAL_MISSING) {
            return 1; // just ignoring
      }

      nErrorCode = f->comm_header.return_code;

      time(&lRecTime);

      iReqID = f->comm_header.request_id;
      printf("Recieved Status Message for request ID: %d. ", iReqID);
      printf(" Status Code: %s\n", GetError(nErrorCode));

      return 1;
}


void Trim(char * str) {

      int i;
      int iLenght=0;
      char chTemp[500];
      int iBeg;
      int iEnd;

      if(str) {
            iLenght = strlen(str);
      }
      else {
            return;
      }

      if(strlen(str) < 1) {
            return;
      }

      iBeg = 0;
      iEnd = iLenght-1;

// clean the string from left
      for (i=0; i<iLenght; i++) {
            if (str[i] != ' ') {
                  break;      
            }
            else {
                  iBeg = i+1;
            }
      }

// clean the string from right
      for (i=(iLenght-1); i>0; i--) {
            if (str[i] != ' ') {
                  break;      
            }
            else {
                  iEnd = i-1;
            }
      }

      for (i=0; i<(iEnd-iBeg+1); i++) {
            chTemp[i] = str[iBeg+i];
      }
      chTemp[i] = '\0';

      strcpy(str, chTemp);
}

long search_req_id(long * lReqIDArray, long lNumOfElem, long lReqID) {

      long l=0;
      long r=lNumOfElem;
      long x=0;

      if (lReqID == BB_VAL_MISSING) {
            return -1;
      }
      
      while (r>=0) {
      
            x = (l+r)/2;
            if (lReqID == lReqIDArray[x]) {
                  return x;
            }

            if (lReqID < lReqIDArray[x]) {
                  r = x-1;
            }
            else {
                  l = x+1;
            }

      }

      return -1;
}


void add_security_to_array(char *pcEntity) {
      Trim(pcEntity);
      iNumOfSec++;
      if (iNumOfSec == 1) {
            piSecTypeList = (int *) malloc (sizeof(int));
            pcSecList = (char *) malloc (32*sizeof(char));
      }
      else {
/*
            In order to not read the command line twice we use here realloc()
            in a real application with large number of securities/fields you should not
            use the realloc(). First find out how may securities you are going to
            use and then use the malloc() function. You may find some other better
            way of allocating memory, it is up to your design.
*/
            piSecTypeList = (int *) realloc (piSecTypeList, (iNumOfSec)*sizeof(int));
            pcSecList = (char *) realloc (pcSecList, (iNumOfSec*32)*sizeof(char));
      }

      pcSecList += iNumOfSec*32 - 32;
      strcpy(pcSecList, pcEntity);
      pcSecList -= iNumOfSec*32 - 32;

//      piSecTypeList[iNumOfSec-1] = iTickType;
}


void load_default_1() {

            char cSec[32];
            int n;

            iTickType = 730; // BB_IDX_TICKERX

            iNumOfSec = 0;
            strcpy(cSec, "MSFT US Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "IBM US Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "BMW GY Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "ADS GY Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "AMP AU Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "NCP AU Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "MKS LN Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "VOD LN Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "7751 JT Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "5108 JT Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "BBAS3 BS Equity");
            add_security_to_array(cSec);
            strcpy(cSec, "CGE FP Equity");
            add_security_to_array(cSec);

            if (iIsGetDataX) {
                  plRequestID = (long *) malloc (2 * sizeof(long));
                  piNumOfSecInOneReq = (int *) malloc (2 * sizeof(int));
                  piGotResponse = (int *) malloc (2 * sizeof(int));

                  piNumOfSecInOneReq[0] = 10;
                  piNumOfSecInOneReq[1] = 2;
                  iNumOfRequests = 2;
            }
            else {
                  iNumOfRequests = iNumOfSec;
                  plRequestID = (long *) malloc (iNumOfRequests * sizeof(long));
                  piNumOfSecInOneReq = (int *) malloc (iNumOfRequests * sizeof(int));
                  piGotResponse = (int *) malloc (iNumOfRequests * sizeof(int));
                  for (n=0; n<iNumOfRequests; n++) {
                        piNumOfSecInOneReq[n] = 1;
                  }
            }



            piFieldList = (int *) malloc (6 * sizeof(int));
            iNumOfFields = 6;
            piFieldList[0] = 0x4aa;
            piFieldList[1] = 0x4ad;
            piFieldList[2] = 0x16bc;
            piFieldList[3] = 0x4b6;
            piFieldList[4] = 0x452;
            piFieldList[5] = 0x46f;

            for (n=0; n<iNumOfSec; n++) {
                  piSecTypeList[n] = iTickType;
            }
}

void load_default_2() {

            char cSec[32];
            int i, n;

            iTickType = 730; // BB_IDX_TICKERX
// in case if there are no parameters create a list of 12 securities
            strcpy(cSec, "CT30 Govt");
            add_security_to_array(cSec);
            add_security_to_array(cSec);
            add_security_to_array(cSec);
            add_security_to_array(cSec);
            add_security_to_array(cSec);
            add_security_to_array(cSec);
            add_security_to_array(cSec);
            add_security_to_array(cSec);
            add_security_to_array(cSec);
            add_security_to_array(cSec);
            add_security_to_array(cSec);
            add_security_to_array(cSec);

            iNumOfRequests = iNumOfSec;
            plRequestID = (long *) malloc (iNumOfRequests * sizeof(long));
            piNumOfSecInOneReq = (int *) malloc (iNumOfRequests * sizeof(int));
            piGotResponse = (int *) malloc (iNumOfRequests * sizeof(int));

            for (i=0; i<iNumOfRequests; i++) {
                  piNumOfSecInOneReq[i] = 1;
                  piNumOfSecInOneReq[i] = 1;
            }

            for (n=0; n<iNumOfSec; n++) {
                  piSecTypeList[n] = iTickType;
            }

            iNumOfFields = 3;
            piFieldList = (int *) malloc (iNumOfFields * sizeof(int));
            piFieldList[0] = 0x555;
            piFieldList[1] = 0x40b;
            piFieldList[2] = 0x457;

            iNumOfOverrides = 1;
            piOverFieldList = (int *) malloc (iNumOfOverrides * sizeof(int));
            plOverValuesList = (char *) malloc (1*32*sizeof(char));

            piOverFieldList[0] = 0x555;
}

void load_default_3() {
            char cSec[32];
            int i, n;

            iTickType = 730; // BB_IDX_TICKERX
// in case if there are no parameters create a list of 12 securities
            strcpy(cSec, "AAL LN Equity");
            add_security_to_array(cSec);

            iNumOfRequests = iNumOfSec;
            plRequestID = (long *) malloc (iNumOfRequests * sizeof(long));
            piNumOfSecInOneReq = (int *) malloc (iNumOfRequests * sizeof(int));
            piGotResponse = (int *) malloc (iNumOfRequests * sizeof(int));

            for (i=0; i<iNumOfRequests; i++) {
                  piNumOfSecInOneReq[i] = 1;
                  piNumOfSecInOneReq[i] = 1;
            }

            for (n=0; n<iNumOfSec; n++) {
                  piSecTypeList[n] = iTickType;
            }

            iNumOfFields = 1;
            piFieldList = (int *) malloc (iNumOfFields * sizeof(int));
            piFieldList[0] = 0xB60;

            iNumOfOverrides = 3;
            piOverFieldList = (int *) malloc (iNumOfOverrides * sizeof(int));
            plOverValuesList = (char *) malloc (3*32*sizeof(char));

            piOverFieldList[0] = 0x16BF;
            piOverFieldList[1] = 0x16BD;
            piOverFieldList[2] = 0x16BE;

            strcpy(plOverValuesList, "20020101");
            plOverValuesList += 32;
            strcpy(plOverValuesList, "9:0");
            plOverValuesList += 32;
            strcpy(plOverValuesList, "11:00");

            plOverValuesList -= 2*32*sizeof(char);



}

int load_data_dic() {

      int iNumOfFields = 0;
      int rcode = 0;

      if (strlen(cDataDictPath) > 0) {
            rcode = bb_load_datadictx(cDataDictPath);
      }
      else {
#if defined (WIN32)
            rcode = bb_load_datadictx(NULL);
#else
            printf("On Unix platfor you need to pass the full path to the data dictionary... exiting\n");
            exit(1);
#endif
      }

      iNumOfFields = MAX_Field;

      if (rcode > 0 && iNumOfFields > 0) {
            return 1;
      }
      else
            return 0;

}

int is_Bulk_field (long lFieldID) {

      int i;

      for (i=0; i<MAX_Field; i++) {
            if (bbFieldArrayx[i].FieldId == lFieldID) {
                  if (bbFieldArrayx[i].FieldFormat == 8) {
                        return 1;
                  }
                  else {
                        return 0;
                  }

                  break;
            }
      }

      return 0;
}

int decodeBulkData(char *pFieldData)
{
      char *token;
      int iIsValidData=0;
      int iIsTokenDataType;
      int iNumOfDim;
      int i;
      char delimiter[2];
      
      delimiter[0] = pFieldData[0];
      delimiter[1] = '\0';

      /* parse out number of element and dimension info here */
      token = strtok(pFieldData, delimiter);

      if (!token) {
            printf("\t\t\t\t No Data\n");
            return 0;
      }

      iNumOfDim = atoi(token);

      for (i=0; i<iNumOfDim; i++) {
            token = strtok(NULL, delimiter);
      }
      token = strtok(NULL, delimiter);

      iIsTokenDataType =1 ;
      while (token != NULL)
      {

            if (!iIsTokenDataType) {
                  printf("\t\t\t\t%s\n", token);
                  iIsValidData = 1;
                  iIsTokenDataType = 1;
            }
            else {
                  iIsTokenDataType = 0;
            }

            token = strtok(NULL, delimiter);//get next
      }

      if (token == NULL && !iIsValidData) {
            printf("\t\t\t\t No Data\n");
      }

      fflush(stdout);

      return 0;
}

int decode_fields_x(bb_msg_fieldsx_t *f)
{
    char *p;
      int lp;
      int i;
      int n;
      int iFoundFlag;
      char *pcSecName;
    /*
    ** Match this responses request_id to the one that we're
    ** expecting.  Print a warning if we're getting a response
    ** to a request that's already been fufilled, or if we're
    ** getting a response to an unknown request
    */

      iFoundFlag = 0;

      i = search_req_id(plRequestID, iNumOfRequests, f->comm_header.request_id);

      if (i == -1) {
        printf("WARNING: Recieved a response to unknown request id %i:",
                         f->comm_header.request_id);
      }
      else {
            piGotResponse[i] = 1;
            iFoundFlag = i+1;;
            iRecievedRequests ++;
      }


      iFoundFlag--;

    /*
    ** Get the pointer to the first security fields into p.  The field_ptr array will
    ** have the pointers to the fields for each security in the order we
    ** requested them.  For each security, we will get null-terminated
    ** strings with the field data, one after another in the order we
    ** requested the fields.
    */

      for (i=0; i<f->comm_header.num_items; i++) {
            pcSecName = pcSecList + iFoundFlag*piNumOfSecInOneReq[0]*32 + i*32;
            printf("Data for %s:\n", pcSecName);
            p = f->field_ptr[i];

            for (n=0; n<iNumOfFields; n++) {
                  lp = strlen(p)+1;
                  if (is_Bulk_field(piFieldList[n])) {
                        printf ("\tField: 0x%X  Bulk Data:\n", piFieldList[n]);
                        decodeBulkData (p);
                  }
                  else {
                        printf ("\tField: 0x%X \t=\t%s\n", piFieldList[n],p);
                  }
                  p += lp;
            }


      }

      fflush(stdout);

      if (iRecievedRequests == iNumOfRequests) {
      end=0;
      return 1;
      }
      else
        return 0;

}

int decode_fields(bb_msg_fields_t *f)
{
    char *p;
      int lp;
      int i;
      int n;
      int iFoundFlag;
      char *pcSecName;
    /*
    ** Match this responses request_id to the one that we're
    ** expecting.  Print a warning if we're getting a response
    ** to a request that's already been fufilled, or if we're
    ** getting a response to an unknown request
    */

      iFoundFlag = 0;

      i = search_req_id(plRequestID, iNumOfRequests, f->comm_header.request_id);

      if (i == -1) {
        printf("WARNING: Recieved a response to unknown request id %i:",
                         f->comm_header.request_id);
      }
      else {
            piGotResponse[i] = 1;
            iFoundFlag = i+1;;
            iRecievedRequests ++;
      }


      iFoundFlag--;

    /*
    ** Get the pointer to the first security fields into p.  The field_ptr array will
    ** have the pointers to the fields for each security in the order we
    ** requested them.  For each security, we will get null-terminated
    ** strings with the field data, one after another in the order we
    ** requested the fields.
    */

            pcSecName = pcSecList + iFoundFlag*piNumOfSecInOneReq[iFoundFlag]*32;
            printf("Data for %s:\n", pcSecName);
//            p = f->field_ptr[i];
            p = f->data_byte;

            for (n=0; n<iNumOfFields; n++) {
                  lp = strlen(p)+1;
                  if (is_Bulk_field(piFieldList[n])) {
                        printf ("\tField: 0x%X  Bulk Data:\n", piFieldList[n]);
                        decodeBulkData (p);
                  }
                  else {
                        printf ("\tField: 0x%X \t=\t%s\n", piFieldList[n],p);
                  }
                  p += lp;
            }



      fflush(stdout);

      if (iRecievedRequests == iNumOfRequests) {
      end=0;
      return 1;
      }
      else
        return 0;

}
int receive(bb_connect_t *connection)
{
  /* receive data from a Bloomberg API connection.  This routine should
  ** be called after select indicates there is data on the socket.  
  ** return values are:
  **   -1  error
  **    0  normal
  **    1  all expected data received
  */

//  static char permBuffer[BUF_SIZE];
  char *pBuffer = NULL;
  long lBufSize;
  long lMsgSize;
  int bbSvcCode;
  BOOL bDone = FALSE;

  while (!bDone) {
 
        lMsgSize = bb_sizeof_nextmsg (connection);

        if (lMsgSize > BUF_SIZE) {
        
              pBuffer = (char *) malloc (lMsgSize);
              if (!pBuffer) {
                    fprintf(stderr, "cannot allocate memory for receive buffer.\n");
                    return -1;
              }
              lBufSize = lMsgSize;       
        }
        else {
              pBuffer = permBuffer;
              lBufSize = BUF_SIZE;
        }

        if (lMsgSize) {      // If bb_sizeof_nextmsg returns 0 don't call bb_rcvdata
          bbSvcCode = bb_rcvdata (connection, pBuffer, lBufSize);
          }
        else
              bbSvcCode = 0;

        if (bbSvcCode == -1) {
              printf("Permissioning problem.\n");
              break;
        }

        if (bbSvcCode < -1900) {
              bDone = TRUE;      
              if ( bbSvcCode == ExitFAILCONNECTION || bbSvcCode == ExitFAILRECEIVE ) {
                    printf("Receive data error.\n");      
                    break;
              }
        }

        if(bbSvcCode>0)
            printf("Received message service code=%i\n", bbSvcCode);

        switch( bbSvcCode ) {

              case BB_SVC_CONNECTSUCCEEDED:
                          printf("We are now connected to bbcomm, ready to make requests.\n");
                          end=0;
                          bDone = TRUE;
                          break;

              case BB_SVC_CONNECTFAILED:
                          printf("Unable to connect to bbcomm.  Bloomberg data not available.\n");
                          end=0;
                          bDone = TRUE;
                          break;

              case BB_SVC_INCOMPLETE:
                          bDone = TRUE;
                          break;

          case BB_SVC_GETDATAX:
                          decode_fields_x((bb_msg_fieldsx_t *)pBuffer);
                        break;

          case BB_SVC_GETDATA:
                          decode_fields((bb_msg_fields_t *)pBuffer);
                        break;

          case BB_SVC_STATUS:
                          decode_status_msg((bb_msg_header_t *) pBuffer);
                        break;

              default:
                          printf("Unhandled message type: %d.\n", bbSvcCode);
                          break;

        }

        if (pBuffer != permBuffer) {
              free (pBuffer);
              pBuffer = permBuffer;;
              lBufSize = BUF_SIZE;
        }

  }

  return 1;
}

int4 make_request(bb_connect_t *conn)
{
  int i;
  int *piBegSecType;
  int iTotalMove = 0;
  double dLowValue = 95.0;

  iRecievedRequests = 0;
  piBegSecType = piSecTypeList;

  for (i=0; i<iNumOfRequests; i++) {

        if (iDefFlag == 2)
              sprintf(plOverValuesList, "%f", dLowValue);
        if (iIsGetDataX) {
              plRequestID[i] = bb_getdatax(conn, piNumOfSecInOneReq[i], reinterpret_cast<long *>(piSecTypeList), (char *)pcSecList,                
                                                            iNumOfFields, reinterpret_cast<long *>(piFieldList), iNumOfOverrides,
                                                            reinterpret_cast<long *>(piOverFieldList), plOverValuesList);
        }
        else {
              plRequestID[i] = bb_getdata(conn, piSecTypeList[0], (char *)pcSecList,                
                              iNumOfFields, reinterpret_cast<long *>(piFieldList),
                              iNumOfOverrides, reinterpret_cast<long *>(piOverFieldList), plOverValuesList);
 
        }

        if (plRequestID[i] < 0) {
            fprintf(stderr, "Error from bb_getdatax(), plRequestID=%d.\n", plRequestID[i]);
            return(-1);
        }
        pcSecList += piNumOfSecInOneReq[i]*32;
          piSecTypeList += piNumOfSecInOneReq[i];
        iTotalMove += piNumOfSecInOneReq[i]*32;
        piGotResponse[i] = 0;

        if (iDefFlag == 2)
            dLowValue += 0.5;

  }
  pcSecList -= iTotalMove;
  piSecTypeList = piBegSecType;

  printf("%d Requests sent out.\n", iNumOfRequests);

  return 0;
}


void response_loop(bb_connect_t *conn)
{
    SOCKET bb_sock;
    fd_set read_set, exec_set;
    int rcode;
    struct timeval timeout = {1, 0};
    time_t final_timeout;

    bb_sock = bb_getsocket(conn);
    /* give ourselves 30 seconds before we give up waiting */
    final_timeout = time(0) + REQUEST_TIMEOUT;

    do {
       /* build select masks with our socket in them */
       FD_ZERO(&read_set);
       FD_ZERO(&exec_set);
       FD_SET((int) bb_sock, &read_set);
       FD_SET((int) bb_sock, &exec_set);

       /* set the select timeout to 1 second */
       timeout.tv_sec = 1;
       timeout.tv_usec = 0;

       /*
       ** We care about the socket being readable or having an exception,
       ** not about it being writeable, so the third paramter of select is
       ** null
       */
       rcode = select(bb_sock + 1, &read_set, NULL, &exec_set, &timeout);

       if (rcode == 0) {
           /*
           ** select timed out.  If we had something else to do, we could
           ** do it here.
           */
           if (time(0) > final_timeout) {
                fprintf(stderr, "timed out waiting for response.\n");
                return;
           }
           printf("Still waiting...\n");
                  if(end)
                    continue;
       }

#ifdef WIN32
       if (rcode == SOCKET_ERROR) {
           fprintf(stderr, "error %i from select.\n", WSAGetLastError());
           return;
       }
#else
       if (rcode == -1) {
           fprintf(stderr, "error %i from select.\n", errno);
           return;
       }
#endif

       if (FD_ISSET((int)  bb_sock, &exec_set)) {
           fprintf(stderr, "execption on Bloomberg socket\n");
           return;
       }

       if (FD_ISSET((int) bb_sock, &read_set)) {
           rcode = receive(conn);
         
           if (rcode == 1 && !end) {
               /* we're done */
               return;
           }

           if (rcode == -1) {
               fprintf(stderr, "error in receive.\n");
               return;
           }
       }
    } while (1);

}

void parse_com_line (char *cmd_line) {

      char *cToken;
      char cTmpStr[80];
      char cKey;
      char cOverKey;
      int i;
      int  pos;
      int iNumOfFullReq;

      iNumOfSec = 0;
      iNumOfOverrides = 0;
      iNumOfFields = 0;
      iDefFlag = 0;

      cToken = strtok(cmd_line, "-");
      Trim(cToken);
      while (cToken != NULL) {

            cKey = cToken[0];
            cToken++;

            switch(cKey) {

                  case 'd':
                        strcpy(cTmpStr, cToken);
                        Trim(cTmpStr);
                        iDefFlag = atoi(cToken);
//                        return;
                  break;

                  case 's':
                        strcpy(cTmpStr, cToken);
                        add_security_to_array(cTmpStr);
                  break;

                  case 'b':
                        strcpy(cTmpStr, cToken);
                        Trim(cTmpStr);
                        strcpy(cDataDictPath, cTmpStr);
                  break;

                  case 'f':
                        Trim(cToken);
                        strcpy(cTmpStr, "0x");
                        strcat(cTmpStr, cToken);
                        Trim(cTmpStr);
                        iNumOfFields++;
                        if (iNumOfFields == 1) {
                              piFieldList = (int *) malloc (sizeof(int));
                        }
                        else {
/*
                              In order to not read the command line twice we use here realloc()
                              in a real application with large number of securities/fields you should not
                              use the realloc(). First find out how may securities you are going to
                              use and then use the malloc() function. You may find some other better
                              way of allocating memory, it is up to your design.
*/
                              piFieldList = (int *) realloc (piFieldList, iNumOfFields * sizeof(int));
                        }
                        piFieldList[iNumOfFields-1] = strtol(cTmpStr, 0, 0);
//                        iNumOfFields++;
                  break;

                  case 'o':
                        Trim(cToken);
                        cOverKey = cToken[0];
                        iNumOfOverrides ++;

                        if (iNumOfOverrides == 1) {
                              piOverFieldList = (int *) malloc (sizeof(int));
                              plOverValuesList = (char *) malloc (32*sizeof(char));
                        }
                        else {
                              piOverFieldList = (int *) realloc (piOverFieldList, (iNumOfOverrides)*sizeof(int));
                              plOverValuesList = (char *) realloc (plOverValuesList, (iNumOfOverrides*32)*sizeof(char));
                        }

                        pos = strcspn (cToken, "=");

                        strcpy(cTmpStr, "0x");
                        strncpy(cTmpStr+2, cToken, pos);
                      cTmpStr[pos+2] = '\0';
                        Trim(cTmpStr);
                        piOverFieldList[iNumOfOverrides-1] = strtol(cTmpStr, 0, 0);
                        cToken += pos+1;
                        strcpy(cTmpStr, cToken);

                        plOverValuesList += iNumOfOverrides*32 - 32;
                        strcpy(plOverValuesList, cTmpStr);
                        plOverValuesList -= iNumOfOverrides*32 - 32;

                  break;

                  case 't':
                        strcpy(cTmpStr, cToken);
                        Trim(cTmpStr);
                        iTickType = atoi(cToken);
                  break;

                  case 'x':
                        strcpy(cTmpStr, cToken);
                        Trim(cTmpStr);
                        iIsGetDataX = atoi(cToken);
                  break;

                  default:
                        printf("Unexpected flag in the parameters... Correct usage is:\n");
                        printf ("example5.exe -s CT30 Govt -s CT5 Govt -s CT10 Govt -t 730 -f 555 , -f 40b , -f 457 -o 555=95.5\n");
                        printf ("OR just Example5.exe to run with deafoult securiites\fields\n");
                        printf ("See comments in the example5.c file for additional options to run this example\n");
                        exit(1);
                  break;
            
            }

            cToken = strtok( NULL,"-");
      }

      if (iNumOfSec > 0) {
            if (iIsGetDataX) {
                  iNumOfFullReq = iNumOfSec/10;
                  iNumOfRequests = iNumOfFullReq;

                  if (!iNumOfFullReq)
                        iNumOfFullReq = 1;

                  
                  if ((iNumOfRequests * 10) != iNumOfSec)
                        iNumOfRequests ++;

                  plRequestID = (long *) malloc (iNumOfRequests * sizeof(long));
                  piNumOfSecInOneReq = (int *) malloc (iNumOfRequests * sizeof(int));
                  piGotResponse = (int *) malloc (iNumOfRequests * sizeof(int));

                  for (i=0; i<iNumOfFullReq; i++) {
                        if (iNumOfSec > 10) {
                              piNumOfSecInOneReq[i] = 10;
                        }
                        else {
                              piNumOfSecInOneReq[i] = iNumOfSec;
                        }
                  }

                  if (iNumOfRequests > iNumOfFullReq) {
                        piNumOfSecInOneReq[iNumOfRequests-1] = iNumOfSec - iNumOfFullReq*10;
                  }
            }
            else {
                  iNumOfRequests = iNumOfFullReq = iNumOfSec;
                  plRequestID = (long *) malloc (iNumOfRequests * sizeof(long));
                  piNumOfSecInOneReq = (int *) malloc (iNumOfRequests * sizeof(int));
                  piGotResponse = (int *) malloc (iNumOfRequests * sizeof(int));
                  for (i=0; i<iNumOfFullReq; i++) {
                        piNumOfSecInOneReq[i] = 1;
                  }
            }
      }
/*
      iNumOfRequests = iNumOfSec;
      
      plRequestID = (long *) malloc (iNumOfRequests * sizeof(long));
      piNumOfSecInOneReq = (int *) malloc (iNumOfRequests * sizeof(int));
      piGotResponse = (int *) malloc (iNumOfRequests * sizeof(int));

      for (i=0; i<iNumOfRequests; i++) {
            piNumOfSecInOneReq[i] = 1;
      }
*/
}

void add_securities(char *cSec, int iSecCount) {
      pcSecList += iSecCount*32;
      strcpy(pcSecList, cSec);
      pcSecList -= iSecCount*32;
}


void main( int argc, char **argv)
{
    bb_connect_t *Connection;
    int rcode;
      char command_line[255];
      int n;
//      char cSec[32];

#ifdef WIN32
    /* If we're running with winsock, check WS versions and do a startup */
    WORD i;
    WSADATA wver;

    i = MAKEWORD(1,1);
    rcode = WSAStartup(i, &wver);
    if (rcode != 0 || LOBYTE(wver.wVersion) != 1 || HIBYTE(wver.wVersion) !=1 ) {
        printf("Unable to start winsock version 1.1.\n");
        exit(1);
    }
#endif

      permBuffer = (char *) malloc (BUF_SIZE);

      pcSecList = NULL;
      piSecTypeList = NULL;
      piFieldList = NULL;
      plRequestID = NULL;            
      piNumOfSecInOneReq = NULL;
      piGotResponse = NULL;            
      piOverFieldList = NULL;
      plOverValuesList = NULL;
      memset(cDataDictPath, 0, 250);
      iIsGetDataX = 1;

      iDefFlag = 1;

      if (argc >1) {
            iDefRun = 0;
// take parameters and prepare a security list and calculate number of requests
            strcpy(command_line, argv[1]);

            if (!strcmp(command_line, "-?") || !strcmp(command_line, "/?") || !strcmp(command_line, "help") ){
                  printf("Example of passing parameters:\n");
                  printf ("example5.exe -s CT30 Govt -s CT5 Govt -s CT10 Govt -t 730 -f 555 , -f 40b , -f 457 -o 555=95.5\n");
                  printf ("OR just Example5.exe to run with deafoult securiites\fields\n");
                  exit(1);
            }

            for (n=2; n<argc; n++) {
                  strcat(command_line, " ");
                  strcat(command_line, argv[n]);
            }

            parse_com_line(command_line);

            if ( !load_data_dic() ) {
                  printf ("Cannot load the Data Dictionary... try to pass the full path to it using -b flag\n");
                  return;
            }

            if (!iDefFlag) {
                  for (n=0; n<iNumOfSec; n++) {
                        piSecTypeList[n] = iTickType;
                  }
            }
            else {

                  if (iDefFlag == 1) {
                        load_default_1();
                  }
                  else if (iDefFlag == 2) {
                        load_default_2();
                  }
                  else if (iDefFlag == 3) {
                        load_default_3();
                  }
                  else {
                        iDefFlag = 1;
                        load_default_1();
                  }

            }

            if (!iNumOfRequests) {
                  iDefFlag = 1;
                  load_default_1();
            }


      }
      else {
            iDefRun = 1;
            iNumOfSec = 0;

            if ( !load_data_dic() ) {
                  printf ("Cannot load the Data Dictionary...  \n");
//                  return;
            }

            load_default_1();
      }

      if (!iNumOfRequests && !iDefRun) {
            printf ("Invalid list of securities. Type Example5.exe -? for help or run it with no arguments\n");
            exit(1);
      }


    Connection = bb_connect(BLP_PORT);

    if (Connection == NULL) {
        printf("Unable to connect to bbcomm.\n");
        exit (2);
    }
   
      rcode = bb_getsocket(Connection);
    printf("Successfully connected to bbcomm on socket %d.\n", rcode);

    if (make_request(Connection) != 0) {
        fprintf(stderr, "Failed to make requests.\n");
        exit(10);
    }

    response_loop(Connection);

    rcode = bb_disconnect(Connection);
    if (rcode != ExitOK) {
        printf("Failed to disconnect, error %i.\n", rcode);
        exit (3);
    }

      free(pcSecList);
      free(plRequestID);
      free(piNumOfSecInOneReq);
      free(piGotResponse);
      free(piSecTypeList);
      free(piFieldList);
      free(piOverFieldList);
      free(plOverValuesList);
      free(permBuffer);

    printf("Successfully disconnected from bbcomm.\n");

}

Start Free Trial
 
Loading Advertisement...
 
[+][-]07.06.2007 at 09:04AM PDT, ID: 19432801

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.06.2007 at 09:18AM PDT, ID: 19432885

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.06.2007 at 09:34AM PDT, ID: 19433008

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: inconsistent, attributes, error, previous, declaration
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32