Example #1
0
int
main(int argc, char **argv)
{
	options_type	tOptions;
	const char	*szWordfile;
	int	iFirst, iIndex, iGoodCount;
	BOOL	bUsage, bMultiple, bUseTXT;

	if (argc <= 0) {
		return EXIT_FAILURE;
	}

	szTask = szBasename(argv[0]);

	if (argc <= 1) {
		iFirst = 1;
		bUsage = TRUE;
	} else {
		iFirst = iReadOptions(argc, argv);
		bUsage = iFirst <= 0;
	}
	if (bUsage) {
		vUsage();
		return iFirst < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
	}

	vGetOptions(&tOptions);

	bMultiple = argc - iFirst > 1;
	bUseTXT = tOptions.eConversionType == conversion_text ||
		tOptions.eConversionType == conversion_fmt_text;
	iGoodCount = 0;



	for (iIndex = iFirst; iIndex < argc; iIndex++) {
		if (bMultiple && bUseTXT) {
			szWordfile = szBasename(argv[iIndex]);
			fprintf(stdout, "::::::::::::::\n");
			fprintf(stdout, "%s\n", szWordfile);
			fprintf(stdout, "::::::::::::::\n");
		}
		if (bProcessFile(argv[iIndex])) {
			iGoodCount++;
		}
	}

	DBG_DEC(iGoodCount);
	return iGoodCount <= 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} /* end of main */
int main (int argc, char *argv[])
  {
    FILE              * psuOutFile;         // Output file handle
    SuIrig106Time       suTime;
    char              * szTime;
    int                 iMilliSec;
    char                szInFile[80];       // Input file name
    char                szOutFile[80];      // Output file name
    int                 iIdx;
    int                 iArgIdx;
    int                 bVerbose;
    int                 bDumpAttitude;      // Dump INS aircraft attitude
    int                 bGotINS;            // Got milk?
    int                 bInRange;
    int                 bInRangePrev;
    int                 bPrintTMATS;
    unsigned            uChannel;           // Channel number
    unsigned            uRTAddr;            // RT address of INS
    unsigned            uTR;                // Transmit bit
    unsigned            uSubAddr;           // Subaddress of INS message
    unsigned            uDecimation;        // Decimation factor
    unsigned            uDecCnt;            // Decimation count
    unsigned            uINSType;           // Type of INS
    int                 iDumpRelIdx;
    unsigned long       lINSPoints = 0L;
    unsigned long       lMsgs = 0L;         // Total message

    SuAC_Data           suAC;               // Aircraft data

    float               fDumpRadius;
    SuTargPosLL       * psuFirstTarg = NULL;
    SuTargPosLL      ** ppsuCurrTarg = &psuFirstTarg;
    SuTargPosLL       * psuCurrTarg;

    EnI106Status        enStatus;
    SuI106Ch10Header    suI106Hdr;

    unsigned long       ulBuffSize = 0L;
    unsigned char     * pvBuff  = NULL;

    Su1553F1_CurrMsg    su1553Msg;
    SuTmatsInfo         suTmatsInfo;

    SuINS_Data        * psuINS01     = NULL;
    SuINS_F15_Data    * psuINS_F15   = NULL;

/* Make sure things stay on UTC */

    putenv("TZ=GMT0");
    tzset();

/*
 * Process the command line arguements
 */

    if (argc < 2) 
        {
        vUsage();
        return 1;
        }

/* Preset default values */

    suAC.bHaveAttitude = bFALSE;
    bDumpAttitude      = bFALSE;
    fDumpRadius        = 0.0;
    bInRangePrev       = bTRUE;

    uChannel    =  0;                    /* Default INS bus                   */
    uRTAddr     =  6;                    /* RT address of INS                 */
    uTR         =  1;                    /* Transmit bit                      */
    uSubAddr    = 16;                    /* Subaddress of INS message         */
    uDecimation =  1;                    /* Decimation factor                 */
    uINSType    =  1;
    bVerbose    = bFALSE;               // No verbosity
    bPrintTMATS = bFALSE;

    szInFile[0]  = '\0';
    strcpy(szOutFile,"con");            // Default is stdout

    for (iArgIdx=1; iArgIdx<argc; iArgIdx++) 
        {

        switch (argv[iArgIdx][0]) 
            {

            case '-' :
                switch (argv[iArgIdx][1]) 
                    {

                    case 'v' :                   /* Verbose switch */
                        bVerbose = bTRUE;
                        break;

                    case 'a' :                   /* Aircraft attitude switch */
                        bDumpAttitude = bTRUE;
                        break;

                    case 'c' :                   /* Channel number */
                        iArgIdx++;
                        sscanf(argv[iArgIdx],"%d",&uChannel);
                        break;

                    case 'r' :                   /* RT address */
                        iArgIdx++;
                        sscanf(argv[iArgIdx],"%d",&uRTAddr);
                        if (uRTAddr>31) 
                            {
                            printf("Invalid RT address\n");
                            vUsage();
                            return 1;
                            }
                        break;

                    case 't' :                   /* TR bit */
                        iArgIdx++;
                        sscanf(argv[iArgIdx],"%d",&uTR);
                        if ((uTR!=0)&&(uTR!=1)) 
                            {
                            printf("Invalid TR flag\n");
                            vUsage();
                            return 1;
                            }
                        break;

                    case 's' :                   /* Subaddress */
                        iArgIdx++;
                        sscanf(argv[iArgIdx],"%d",&uSubAddr);
                        if (uSubAddr>31) 
                            {
                            printf("Invalid subaddress\n");
                            vUsage();
                            return 1;
                            }
                        break;

                    case 'd' :                   /* Decimation */
                        iArgIdx++;
                        sscanf(argv[iArgIdx],"%d",&uDecimation);
                        break;

                    case 'i' :                   /* INS type */
                        iArgIdx++;
                        sscanf(argv[iArgIdx],"%d",&uINSType);
                        if (uINSType>2) 
                            {
                            printf("Invalid INS type\n");
                            vUsage();
                            return 1;
                            }
                        break;

                    case 'g' :                   /* Ground target position */
                        *ppsuCurrTarg = malloc(sizeof(SuTargPosLL));
                        (*ppsuCurrTarg)->psuNext = NULL;
                        iArgIdx++;
                        sscanf(argv[iArgIdx],"%lf",&((*ppsuCurrTarg)->suPos.dLat));
                        iArgIdx++;
                        sscanf(argv[iArgIdx],"%lf",&((*ppsuCurrTarg)->suPos.dLon));
                        iArgIdx++;
                        sscanf(argv[iArgIdx],"%f", &((*ppsuCurrTarg)->suPos.fAltitude));
                        (*ppsuCurrTarg)->suPos.fRoll    = 0.0f;
                        (*ppsuCurrTarg)->suPos.fPitch   = 0.0f;
                        (*ppsuCurrTarg)->suPos.fHeading = 0.0f;
                        ppsuCurrTarg = &((*ppsuCurrTarg)->psuNext);
                        break;

                    case 'm' :                   /* Dump radius */
                        iArgIdx++;
                        sscanf(argv[iArgIdx],"%f",&fDumpRadius);
                        break;

                    case 'T' :                   /* Print TMATS flag */
                        bPrintTMATS = bTRUE;
                        break;

                    default :
                        break;
                    } // end flag switch
                break;

            default :
                if (szInFile[0] == '\0') strcpy(szInFile, argv[iArgIdx]);
                else                     strcpy(szOutFile,argv[iArgIdx]);
                break;

            } // end command line arg switch
        } // end for all arguments

    if ((strlen(szInFile)==0) || (strlen(szOutFile)==0)) 
        {
        vUsage();
        return 1;
        }

    if ((uChannel == 0) && (bPrintTMATS == bFALSE))
        {
        vUsage();
        printf("\nERROR - A channel number must be specified\n");
        return 1;
        }

/* Now initialize a bunch of stuff based on input parameters */

    uDecCnt = uDecimation;

    if (psuFirstTarg != NULL)
        bDumpAttitude = bTRUE;

    if ((fDumpRadius != 0.0) && (psuFirstTarg == NULL))
        fDumpRadius = 0.0;

    bGotINS = bFALSE;

/*
 *  Open file and allocate a buffer for reading data.
 */

    enStatus = enI106Ch10Open(&m_iI106Handle, szInFile, I106_READ);
    switch (enStatus)
        {
        case I106_OPEN_WARNING :
            fprintf(stderr, "Warning opening data file : Status = %d\n", enStatus);
            break;
        case I106_OK :
            break;
        default :
            fprintf(stderr, "Error opening data file : Status = %d\n", enStatus);
            return 1;
            break;
        }

    enStatus = enI106_SyncTime(m_iI106Handle, bFALSE, 0);
    if (enStatus != I106_OK)
        {
        fprintf(stderr, "Error establishing time sync : Status = %d\n", enStatus);
        return 1;
        }


/*
 * Open the output file
 */

    psuOutFile = fopen(szOutFile,"w");
    if (psuOutFile == NULL) 
        {
        printf("Error opening output file\n");
        return 1;
        }

/*
 * Read the first header. If TMATS flag set, print TMATS and exit
 */

    // Read first header and check for data read errors
    enStatus = enI106Ch10ReadNextHeader(m_iI106Handle, &suI106Hdr);
    if (enStatus != I106_OK)
        return 1;

    // If TMATS flag set, just print TMATS and exit
    if (bPrintTMATS == bTRUE)
        {
        if (suI106Hdr.ubyDataType == I106CH10_DTYPE_TMATS)
            {
            // Make a data buffer for TMATS
            pvBuff = malloc(suI106Hdr.ulPacketLen);
            ulBuffSize = suI106Hdr.ulPacketLen;

            // Read the data buffer and check for read errors
            enStatus = enI106Ch10ReadData(m_iI106Handle, suI106Hdr.ulPacketLen, pvBuff);
            if (enStatus != I106_OK)
                return 1;

            // Process the TMATS info
            memset( &suTmatsInfo, 0, sizeof(suTmatsInfo) );
            enStatus = enI106_Decode_Tmats(&suI106Hdr, pvBuff, &suTmatsInfo);
            if (enStatus != I106_OK) 
                {
                fprintf(stderr, " Error processing TMATS record : Status = %d\n", enStatus);
                return 1;
                }

            vPrintTmats(&suTmatsInfo, psuOutFile);
            } // end if TMATS

        // TMATS not first message
        else
            {
            printf("Error - TMATS message not found\n");
            return 1;
            }

        fclose(psuOutFile);
        return 0;
        } // end if print TMATS

/*
 * Hold onto your shorts, here we go...
 */

    fprintf(stderr, "\nIDMPINS "MAJOR_VERSION"."MINOR_VERSION"\n");
    fprintf(stderr, "Freeware Copyright (C) 2007 Irig106.org\n\n");

    fprintf(stderr, "Input Data file '%s'\n", szInFile);
    fprintf(psuOutFile,"Input Data file '%s'\n", szInFile);

    printf("Chan %d  RT %d  TR %d  SA %d  INS Position/Attitude\n",
        uChannel, uRTAddr, uTR, uSubAddr);
    fprintf(psuOutFile,"Chan %d  RT %d  TR %d  SA %d  INS Position/Attitude\n",
        uChannel, uRTAddr, uTR, uSubAddr);

    if (psuFirstTarg != NULL) 
        {
        psuCurrTarg = psuFirstTarg;
        while (psuCurrTarg != NULL) 
            {
            fprintf(psuOutFile,"Ground Target   Lat %12.6f  Lon %12.6f  Elev %5.0f\n",
                psuCurrTarg->suPos.dLat,
                psuCurrTarg->suPos.dLon, 
                psuCurrTarg->suPos.fAltitude);
            psuCurrTarg = psuCurrTarg->psuNext;
            } // end while relative targets to calculate for
        }

    if (fDumpRadius != 0.0) 
        {
        fprintf(psuOutFile,"Dump Radius %6.1f nm\n", fDumpRadius);
        }

    fprintf(psuOutFile,"\n");

/* This queer little piece of code is strictly for the convenience of the
 * programmer.  You see, there are multiple lines of header information to
 * write out to the output file but depending upon the command line flags
 * not all columns of data may be needed.  This weird structure allows me
 * to keep data column headers together to make it easier to keep things
 * lined up and looking pretty.  I just wanted to let you know that, no,
 * I haven't lost my ever lovin' mind.
 */

    for (iIdx=1; iIdx<=4; iIdx++) 
        {

        if  (iIdx==1)                   fprintf(psuOutFile,"           ");
        if  (iIdx==2)                   fprintf(psuOutFile,"           ");
        if  (iIdx==3)                   fprintf(psuOutFile,"    Time   ");
        if  (iIdx==4)                   fprintf(psuOutFile,"   (UTC)   ");

        if  (iIdx==1)                   fprintf(psuOutFile,"    Raw INS    Raw INS    INS ");
        if  (iIdx==2)                   fprintf(psuOutFile,"   Longitude  Latitude   Data ");
        if  (iIdx==3)                   fprintf(psuOutFile,"   (+ East)   (+ North)  Valid");
        if  (iIdx==4)                   fprintf(psuOutFile,"   (- West)   (- South)       ");

        if ((iIdx==1)&&(bDumpAttitude)) fprintf(psuOutFile,"                                                      ");
        if ((iIdx==2)&&(bDumpAttitude)) fprintf(psuOutFile,"    INS      True     Roll     Pitch           Ground ");
        if ((iIdx==3)&&(bDumpAttitude)) fprintf(psuOutFile,"  Altitude  Heading  (+ Right) (+ Up  )        Speed  ");
        if ((iIdx==4)&&(bDumpAttitude)) fprintf(psuOutFile,"   (MSL)             (- Left ) (- Down)   G's   (kts) ");

        psuCurrTarg  = psuFirstTarg;
        iDumpRelIdx = 1;
        while (psuCurrTarg != NULL) 
            {
            if (iIdx==1)                  fprintf(psuOutFile,"  ------------ Ground Target %d ------------", iDumpRelIdx);
            if (iIdx==2)                  fprintf(psuOutFile,"  Target  Az to   Elev to   Az to   Elev to");
            if (iIdx==3)                  fprintf(psuOutFile,"   Range  Target  Target     A/C     A/C   ");
            if (iIdx==4)                  fprintf(psuOutFile,"   (NM)                                    ");
            psuCurrTarg = psuCurrTarg->psuNext;
            iDumpRelIdx++;
            }

        fprintf(psuOutFile,"\n");

        } /* end for each header line */

/*
 * Read messages until error or EOF
 */

    lMsgs = 1;

    while (1==1) 
        {

        // Read the next header
        enStatus = enI106Ch10ReadNextHeader(m_iI106Handle, &suI106Hdr);

        // Setup a one time loop to make it easy to break out on error
        do
            {
            if (enStatus == I106_EOF)
                break;

            // Check for header read errors
            if (enStatus != I106_OK)
                break;

            // If 1553 message and right channel then process it
            if ((suI106Hdr.ubyDataType == I106CH10_DTYPE_1553_FMT_1) &&
                (uChannel == suI106Hdr.uChID))
                {

                // Make sure our buffer is big enough, size *does* matter
                if (ulBuffSize < suI106Hdr.ulPacketLen)
                    {
                    pvBuff = realloc(pvBuff, suI106Hdr.ulPacketLen);
                    ulBuffSize = suI106Hdr.ulPacketLen;
                    }

                // Read the data buffer
                enStatus = enI106Ch10ReadData(m_iI106Handle, ulBuffSize, pvBuff);

                // Check for data read errors
                if (enStatus != I106_OK)
                    break;

                lMsgs++;
                if (bVerbose) 
                    fprintf(stderr, "%8.8ld Messages \r",lMsgs);

                    // Step through all 1553 messages
                enStatus = enI106_Decode_First1553F1(&suI106Hdr, pvBuff, &su1553Msg);
                while (enStatus == I106_OK)
                    {
                    SuCmdWordU   * psuCmdWord;

                     // Look for INS packets
                    if ((!su1553Msg.psu1553Hdr->bRT2RT) || (uTR == 0))
                        psuCmdWord = su1553Msg.psuCmdWord1;
                    else
                        psuCmdWord = su1553Msg.psuCmdWord2;

                    if ((psuCmdWord->suStruct.uRTAddr  == uRTAddr ) &&
                        (psuCmdWord->suStruct.bTR      == uTR     ) &&
                        (psuCmdWord->suStruct.uSubAddr == uSubAddr) &&
                        (i1553WordCnt(psuCmdWord)      >= 1      ))
                    //if ((su1553Msg.psuCmdWord1->suStruct.uRTAddr  == uRTAddr ) &&
                    //    (su1553Msg.psuCmdWord1->suStruct.bTR      == uTR     ) &&
                    //    (su1553Msg.psuCmdWord1->suStruct.uSubAddr == uSubAddr) &&
                    //    (i1553WordCnt(su1553Msg.psuCmdWord1)      >= 24 ))
                        {

                        // Decode INS data
                        // ---------------

                        // F-16/C-130/A-10 EGI
                        if (uINSType == 1) 
                            {

                            // If decimation counter down to 1 then  calculate
                            if (uDecCnt == 1) 
                                {

                                psuINS01 = (SuINS_Data *)(su1553Msg.pauData);

                                // Convert INS Lat and Lon to degrees if it is to be used
                                suAC.suPos.dLat  = (180.0/M_PI)*asin((float)((long)(psuINS01->sCXZ_MSW)<<16 | (long)(psuINS01->uCXZ_LSW))/(float)0x40000000);
                                suAC.suPos.dLon  = (180.0     )*    ((float)((long)(psuINS01->sLon_MSW)<<16 | (long)(psuINS01->uLon_LSW))/(float)0x7fffffff);
                                suAC.bValid      = (psuINS01->uStatus & 0xf800) == 0;

                                if (bDumpAttitude) 
                                    {
                                    suAC.suPos.fRoll     = 180.0f * psuINS01->sRoll        / (float)0x7fff;
                                    suAC.suPos.fPitch    = 180.0f * psuINS01->sPitch       / (float)0x7fff;
                                    suAC.suPos.fHeading  = 180.0f * psuINS01->uTrueHeading / (float)0x7fff;
                                    suAC.suPos.fAltitude = psuINS01->sAlt * 4.0f;
                                    suAC.fAccel          = sqrt((float)psuINS01->sAccX*(float)psuINS01->sAccX +
                                                                (float)psuINS01->sAccY*(float)psuINS01->sAccY +
                                                                (float)psuINS01->sAccZ*(float)psuINS01->sAccZ) / 32.0f;
                                    suAC.fSpeed          = sqrt((float)psuINS01->sVelX_MSW*(float)psuINS01->sVelX_MSW +
                                                                (float)psuINS01->sVelY_MSW*(float)psuINS01->sVelY_MSW) * 3600.0f / (4.0f * 6080.0f);
                                    suAC.bHaveAttitude   = bTRUE;
                                    } // end dump attitude

                                uDecCnt = uDecimation;
                                bGotINS = bTRUE;

                                lINSPoints++;
                                if (bVerbose) printf("%8.8ld INS points     \r",lINSPoints);

                                } // end if decimation count down to 1

                            // else decrement decimation counter 
                            else 
                                uDecCnt--;

                            } // end if F-16/C-130/A-10 EGI case

                        // F-15
                        if (uINSType == 2) 
                            {

                            if (uDecCnt == 1) 
                                {

                                // Convert INS Lat and Lon to degrees if it is to be used
                                suAC.suPos.dLat   = (180.0)*((float)((long)(psuINS_F15->sLat_MSW)<<16 | (long)(psuINS_F15->uLat_LSW))/(float)0x7fffffff);
                                suAC.suPos.dLon   = (180.0)*((float)((long)(psuINS_F15->sLon_MSW)<<16 | (long)(psuINS_F15->uLon_LSW))/(float)0x7fffffff);
                                suAC.bValid      = (psuINS_F15->uStatus & 0x0003) == 3;  // 0xc000 ???

                                if (bDumpAttitude) 
                                    {
                                    suAC.suPos.fRoll     = 180.0f * psuINS_F15->sRoll        / (float)0x7fff;
                                    suAC.suPos.fPitch    = 180.0f * psuINS_F15->sPitch       / (float)0x7fff;
                                    suAC.suPos.fHeading  = 180.0f * psuINS_F15->uTrueHeading / (float)0x7fff;
//                fAltitude = psuINS_F15->sAlt * 4.0f;
// ???                fAccel    = sqrt((float)psuINS_F15->sAccNorth*(float)psuINS_F15->sAccNorth +
//                                     (float)psuINS_F15->sAccEast *(float)psuINS_F15->sAccEast  +
//                                     (float)psuINS_F15->sAccUp   *(float)psuINS_F15->sAccUp)    / 32.0f;
// ???                fSpeed    = sqrt((float)psuINS_F15->sVelNorth*(float)psuINS_F15->sVelNorth +
//                                     (float)psuINS_F15->sVelEast *(float)psuINS_F15->sVelEast) * 3600.0f / (4.0f * 6080.0f);
                                    suAC.bHaveAttitude = bTRUE;
                                    } // end dump attitude

                                uDecCnt = uDecimation;
                                bGotINS = bTRUE;

                                lINSPoints++;
                                if (bVerbose) printf("%8.8ld INS points     \r",lINSPoints);

                                } // end if decimation count down to 1

                            else 
                                uDecCnt--;
              
                            } // end if F-15 case



                        // If we got INS data then do some calculations and print it
                        // ---------------------------------------------------------

                        if (bGotINS == bTRUE) 
                            {

                            // If no ground target then we are always in range   
                            if (psuFirstTarg == NULL)
                                bInRange = bTRUE;

                            // If there is a ground target then do some calculations and see 
                            // if we are in range.
                            else 
                                {
                                if (fDumpRadius == 0.0)
                                    bInRange = bTRUE;
                                else
                                    bInRange = bFALSE;
                                psuCurrTarg = psuFirstTarg;
                                while (psuCurrTarg != NULL) 
                                    {

                                    // Calculate relative position
                                    vCalcRel(&suAC.suPos,            &(psuCurrTarg->suPos),  &(psuCurrTarg->suAC2Target));
                                    vCalcRel(&(psuCurrTarg->suPos),  &suAC.suPos,            &(psuCurrTarg->suTarget2AC));

                                    // See if in range of target
                                    if (bInRange == bFALSE)
                                        bInRange = (psuCurrTarg->suAC2Target.fRange <= fDumpRadius);

                                    // Go to the next target
                                    psuCurrTarg = psuCurrTarg->psuNext;
                                    } // end while relative targets to calculate for
                                } // end ground target calculations


                            // Print out the data
                            if (bInRange == bTRUE)
                                {

                                // If we weren't in range last time put a blank line
                                if (bInRangePrev == bFALSE)
                                    fprintf(psuOutFile,"\n");

                                enI106_Rel2IrigTime(m_iI106Handle,
                                    su1553Msg.psu1553Hdr->aubyIntPktTime, &suTime);
                                szTime = ctime((time_t *)&suTime.ulSecs);
                                szTime[19] = '\0';
                                iMilliSec = (int)(suTime.ulFrac / 10000.0);

                                fprintf(psuOutFile,"%s.%3.3d", &szTime[11], iMilliSec);
                                fprintf(psuOutFile," %11.6f %10.6f   %u ", suAC.suPos.dLon,suAC.suPos.dLat,suAC.bValid);

                                if (suAC.bHaveAttitude) 
                                    {
                                    fprintf(psuOutFile," %7.0f     %5.1f  %8.3f   %7.3f   %6.3f  %5.1f ",
                                        suAC.suPos.fAltitude,suAC.suPos.fHeading,suAC.suPos.fRoll,suAC.suPos.fPitch,suAC.fAccel,suAC.fSpeed);
                                    }

                                psuCurrTarg = psuFirstTarg;
                                while (psuCurrTarg != NULL) 
                                    {
                                    fprintf(psuOutFile,"  %6.2f  %5.1f    %5.1f    %5.1f   %5.1f  ",
                                        psuCurrTarg->suAC2Target.fRange, 
                                        psuCurrTarg->suAC2Target.fAz, psuCurrTarg->suAC2Target.fEl,
                                        psuCurrTarg->suTarget2AC.fAz, psuCurrTarg->suTarget2AC.fEl);
                                    psuCurrTarg = psuCurrTarg->psuNext;
                                    }

                                fprintf(psuOutFile,"\n");

                                bGotINS           = bFALSE;
                                suAC.bHaveAttitude = bFALSE;
                                } // end if in range

                            bInRangePrev = bInRange;

                            } // end if got INS data

                        } // end if RT, TR, and WC are OK

                    // Get the next 1553 message
                    enStatus = enI106_Decode_Next1553F1(&su1553Msg);
                    } // end while processing 1553 messages from an IRIG packet

                } // end if 1553 and right channel


            } while (bFALSE); // end one time loop

        // If EOF break out of main read loop
        if (enStatus == I106_EOF)
            {
            fprintf(stderr, "End of file\n");
            break;
            }

        }   // End while

    // Finish up */

    printf("Total INS points %8.8ld\n",lINSPoints);
    printf("Total Message %lu\n", lMsgs);

/*
 * Close data file and generally clean up
 */

    fclose(psuOutFile);

    return 0;
    }
Example #3
0
int
main(int argc, char **argv)
{
	options_type	tOptions;
	const char	*szWordfile;
	int	iFirst, iIndex, iGoodCount;
	BOOL	bUsage, bMultiple, bUseTXT, bUseXML;

	if (argc <= 0) {
		return EXIT_FAILURE;
	}

	szTask = szBasename(argv[0]);

	if (argc <= 1) {
		iFirst = 1;
		bUsage = TRUE;
	} else {
		iFirst = iReadOptions(argc, argv);
		bUsage = iFirst <= 0;
	}
	if (bUsage) {
		vUsage();
		return iFirst < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
	}

#if defined(N_PLAT_NLM) && !defined(_VA_LIST)
	nwinit();
#endif /* N_PLAT_NLM && !_VA_LIST */

	vGetOptions(&tOptions);

#if !defined(__dos)
	if (is_locale_utf8()) {
#if defined(__STDC_ISO_10646__)
		/*
		 * If the user wants UTF-8 and the envirionment variables
		 * support UTF-8, than set the locale accordingly
		 */
		if (tOptions.eEncoding == encoding_utf_8) {
			if (setlocale(LC_CTYPE, "") == NULL) {
				werr(1, "Can't set the UTF-8 locale! "
					"Check LANG, LC_CTYPE, LC_ALL.");
			}
			DBG_MSG("The UTF-8 locale has been set");
		} else {
			(void)setlocale(LC_CTYPE, "C");
		}
#endif /* __STDC_ISO_10646__ */
	} else {
		if (setlocale(LC_CTYPE, "") == NULL) {
			werr(0, "Can't set the locale! Will use defaults");
			(void)setlocale(LC_CTYPE, "C");
		}
		DBG_MSG("The locale has been set");
	}
#endif /* !__dos */

	bMultiple = argc - iFirst > 1;
	bUseTXT = tOptions.eConversionType == conversion_text ||
		tOptions.eConversionType == conversion_fmt_text;
	bUseXML = tOptions.eConversionType == conversion_xml;
	iGoodCount = 0;

#if defined(__dos)
	if (tOptions.eConversionType == conversion_pdf) {
		/* PDF must be written as a binary stream */
		setmode(fileno(stdout), O_BINARY);
	}
#endif /* __dos */

	if (bUseXML) {
		fprintf(stdout,
	"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
	"<!DOCTYPE %s PUBLIC \"-//OASIS//DTD DocBook XML V4.1.2//EN\"\n"
	"\t\"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">\n",
		bMultiple ? "set" : "book");
		if (bMultiple) {
			fprintf(stdout, "<set>\n");
		}
	}

	for (iIndex = iFirst; iIndex < argc; iIndex++) {
		if (bMultiple && bUseTXT) {
			szWordfile = szBasename(argv[iIndex]);
			fprintf(stdout, "::::::::::::::\n");
			fprintf(stdout, "%s\n", szWordfile);
			fprintf(stdout, "::::::::::::::\n");
		}
		if (bProcessFile(argv[iIndex])) {
			iGoodCount++;
		}
	}

	if (bMultiple && bUseXML) {
		fprintf(stdout, "</set>\n");
	}

	DBG_DEC(iGoodCount);
	return iGoodCount <= 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} /* end of main */