Exemplo n.º 1
0
void main (int argc, char **argv, char **envp)
{
    char    szSrcFil[FIOMAXNAM] = {'\0'};
    char    szTrgSpc[FIOMAXNAM] = {'\0'};
    char   *pcWrkPtr;

    /********************************************************************/
    /********************************************************************/
    printf (MsgUseIni);

    /********************************************************************/
    /* Check argument count. Skip program name                          */
    /********************************************************************/
    if (strncmp (*++argv, "-h", 2) == 0) DspHlpEnd ();
    if (argc < 2) UseErrEnd (NULL);

    /********************************************************************/
    /* Get name of source file                                          */
    /********************************************************************/
    _fstrncpy (szSrcFil, *argv++, FIOMAXNAM);
    argc = argc - 2;                    /* Indicate name & 1 arg used   */

    /********************************************************************/
    /* Get name of new file name (if specified)                         */
    /********************************************************************/
    if ((0 != argc) && (NULL == strchr (*argv, '-'))) {
        _fstrncpy (szTrgSpc, *argv++, FIOMAXNAM);
        argc--;
    }

    /********************************************************************/
    /* Initialize and allocate effects resources                        */
    /********************************************************************/
    if (EffFrqIni (NULL, &pcWrkPtr)) UseErrEnd (pcWrkPtr);
                                          
    /********************************************************************/
    /* Get dash parameters                                              */
    /********************************************************************/
    if (pcWrkPtr = GetDshPrm (argc, argv, &cbCfgBlk, &fbFrqBlk)) 
        UseErrEnd (pcWrkPtr);

    /********************************************************************/
    /********************************************************************/
    BinFilRep (szSrcFil, szTrgSpc, cbCfgBlk.usRepFlg, RepChkFil, RepPCMFil, 
        RepEndFil, NULL, &fbFrqBlk);
    printf ("%ld converted\n", fbFrqBlk.ulTotCnt);

    /********************************************************************/
    /* Free effects resources                                           */
    /********************************************************************/
    EffFrqTrm ();

    /********************************************************************/
    /********************************************************************/
    exit (0);

}
Exemplo n.º 2
0
WORD    ChkRegKey (char far *pcOrgKeyArr, char far *pcSeqNumArr, WORD far *pusCmpCod)
{
    char    szWrkKey[REGKEYLEN+1];
    DWORD   ulKeyApp, ulKeyUsr, ulSeqNum, ulFulApp, ulCurDay;

    /********************************************************************/
    /********************************************************************/
    *pusCmpCod = 0;

    /********************************************************************/
    /* Keys stored in reversed strings to increase random appearance    */          
    /********************************************************************/
    _fstrncpy (szWrkKey, pcOrgKeyArr, REGKEYLEN);
    szWrkKey[REGKEYLEN] = '\0';
    _fstrrev (szWrkKey);

    ulKeyUsr = _fstrtoul (&szWrkKey[4], NULL, 36);      /* Convert tail */
    szWrkKey[4] = '\0';                                 /* Terminate    */
    ulKeyApp = _fstrtoul (&szWrkKey[0], NULL, 36);      /* Convert head */

    _fstrncpy (szWrkKey, pcSeqNumArr, SERSEGLEN);
    szWrkKey[SERSEGLEN] = '\0';
    ulSeqNum = _fstrtoul (&szWrkKey[0], NULL, 10);      /* Convert Seq# */

    ulCurDay = _Day1970 ();                             /* Since 1/1/70 */

    /********************************************************************/
    /* Check for "Demo Only" string                                     */
    /********************************************************************/
    if ((ulKeyApp == 0L) || (ulKeyUsr == 0L)) return (REGDEMKEY);

    /********************************************************************/
    /* Application Key is a prime number mult of ulFulApp (or master)   */
    /* Check App Key against multiple & check Usr Key against sequence# */
    /* Check App Key against master key multiplier                      */
    /********************************************************************/
    if ((0L == (ulKeyApp % atol (KEYEVLAPP))) && (ulKeyUsr > ulCurDay))
        return (REGEVLKEY);
    if ((0L == (ulKeyApp % atol (KEYSEQAPP))) && (ulKeyUsr == ulSeqNum))
        return (REGFULKEY);
    if ((0L == (ulKeyApp % atol (KEYMASAPP))) && (0L == (ulKeyApp % atol (KEYMASAPP))))
        return (REGMASKEY);

    /********************************************************************/
    /* Load ulFulApp divisor from hardware and check caller key strings */
    /********************************************************************/
    if (0 != (ulFulApp = GetEncKey (pcSeqNumArr, 0, pusCmpCod))) {
        if ((0L == (ulKeyApp % ulFulApp)) && (ulKeyUsr == ulSeqNum))
            return (REGFULKEY);
    }    

    /********************************************************************/
    /********************************************************************/
    return (REGDEMKEY);

}
Exemplo n.º 3
0
/*
 * create a new line. make a copy of the text.
 *
 * if the list is non-null, allocate on the list. if null, alloc from
 * gmem_get.
 */
LINE
line_new(LPSTR text, int linelength, UINT linenr, LIST list)
{
        LINE line;

        /* alloc a line. from the list if there is a list */
        if (list) {
                line = List_NewLast(list, sizeof(struct fileline));
                if (line == NULL) {
                        return(NULL);
                }
                line->flags = 0;
        } else {
                line = (LINE) gmem_get(hHeap, sizeof(struct fileline));
                if (line == NULL) {
                        return(NULL);
                }
                line->flags = LF_DISCARD;
        }

        /* alloc space for the text. remember the null character */
        line->text = gmem_get(hHeap, linelength + 1);
        _fstrncpy(line->text, text, linelength);
        line->text[linelength] = '\0';

        line->link = NULL;
        line->linenr = linenr;

        return(line);
}
Exemplo n.º 4
0
short FAR PASCAL FilHdlOpn (const char far *lpFilNam, unsigned short usOpnFlg)
{
    static  char    szLocNam[FIOMAXNAM];

    /********************************************************************/
    /* Make a local copy of the file name                               */
    /********************************************************************/
    _fstrncpy (szLocNam, lpFilNam, FIOMAXNAM);

#if (defined (W31)) /****************************************************/
    /********************************************************************/
    /* _lopen does not have O_BINARY option                             */
    /********************************************************************/
    usOpnFlg &=  ~O_BINARY;
    /********************************************************************/
    /* _lopen does not have O_CREAT & _O_TRUNC option                   */
    /********************************************************************/
    if ((O_TRUNC & usOpnFlg) || ((O_CREAT & usOpnFlg) && FilGetSta (szLocNam, NULL))) {
        return (FilHdlCre (szLocNam, usOpnFlg, S_IWRITE));
    }
    return (_lopen (szLocNam, usOpnFlg));
#endif /*****************************************************************/

#if (defined (DOS)) /****************************************************/
    return (_open (szLocNam, usOpnFlg));
#endif /*****************************************************************/

}
Exemplo n.º 5
0
//*************************************************************
//
//  AddNewItem()
//
//  Purpose:
//              Add an item at the begin of the list
//
//  Parameters:
//      LPMRUMENU lpMruMenu -      pointer on MRUMENU
//      LPSTR lpItem -             String contain the filename to add
//
//  Return: (BOOL)
//      TRUE  - Function run successfully
//      FALSE - Function don't run successfully
//
//
//  Comments:
//      Used when used open a file (using File Open common
//        dialog, Drag and drop or MRU)
//
//  History:    Date       Author       Comment
//              09/24/94   G. Vollant   Created
//
//*************************************************************
void AddNewItem( LPMRUMENU lpMruMenu, LPSTR lpItem ) {
	WORD i, j;
	for( i = 0; i < lpMruMenu->wNbItemFill; i++ )
		if( lstrcmpi( lpItem, ( lpMruMenu->lpMRU ) +
					  ( ( lpMruMenu->wMaxSizeLruItem ) * ( UINT )i ) ) == 0 ) {
			// Shift the other items
			for( j = i; j > 0; j-- )
				lstrcpy( ( lpMruMenu->lpMRU ) + ( lpMruMenu->wMaxSizeLruItem * ( UINT )j ),
						 ( lpMruMenu->lpMRU ) + ( lpMruMenu->wMaxSizeLruItem * ( UINT )( j - 1 ) ) );
			_fstrncpy( lpMruMenu->lpMRU, lpItem, lpMruMenu->wMaxSizeLruItem - 1 );
			return ;
		}
	lpMruMenu->wNbItemFill = min( lpMruMenu->wNbItemFill + 1, lpMruMenu->wNbLruMenu );
	for( i = lpMruMenu->wNbItemFill - 1; i > 0; i-- )
		lstrcpy( lpMruMenu->lpMRU + ( lpMruMenu->wMaxSizeLruItem * ( UINT )i ),
				 lpMruMenu->lpMRU + ( lpMruMenu->wMaxSizeLruItem * ( UINT )( i - 1 ) ) );
	_fstrncpy( lpMruMenu->lpMRU, lpItem, lpMruMenu->wMaxSizeLruItem - 1 );
}
Exemplo n.º 6
0
//*************************************************************
//
//  SetMenuItem()
//
//  Purpose:
//              Set the filename of an item
//
//  Parameters:
//      LPMRUMENU lpMruMenu -      pointer on MRUMENU
//      WORD wItem -               Number of Item to set, zero based
//      LPSTR lpItem -             String, contain the filename of the item
//
//
//  Return: (BOOL)
//      TRUE  - Function run successfully
//      FALSE - Function don't run successfully
//
//
//  Comments:
//      used when load .INI or reg database
//
//  History:    Date       Author       Comment
//              09/24/94   G. Vollant   Created
//
//*************************************************************
BOOL SetMenuItem( LPMRUMENU lpMruMenu, WORD wItem, LPSTR lpItem )
{
    if ( wItem >= NBMRUMENU )
        return FALSE;
    _fstrncpy( ( lpMruMenu->lpMRU ) +
               ( ( lpMruMenu->wMaxSizeLruItem ) * ( UINT )wItem ),
               lpItem, lpMruMenu->wMaxSizeLruItem - 1 );
    lpMruMenu->wNbItemFill = max( lpMruMenu->wNbItemFill, wItem + 1 );
    return TRUE;
}
Exemplo n.º 7
0
//*************************************************************
//
//  GetMenuItem()
//
//  Purpose:
//              Get the filename of an item
//
//  Parameters:
//      LPMRUMENU lpMruMenu -      pointer on MRUMENU
//      WORD wItem -               Number of Item to set, zero based
//      BOOL fIDMBased -           TRUE :  wItem is based on ID menu item
//                                 FALSE : wItem is zero-based
//      LPSTR lpItem -             String where the filename of the item will be
//                                   stored by GetMenuItem()
//      UINT  uiSize -             Size of the lpItem buffer
//
//
//  Return: (BOOL)
//      TRUE  - Function run successfully
//      FALSE - Function don't run successfully
//
//
//  Comments:
//      Used for saving in .INI or reg database, or when user select
//        an MRU in File menu
//
//  History:    Date       Author       Comment
//              09/24/94   G. Vollant   Created
//
//*************************************************************
BOOL GetMenuItem( LPMRUMENU lpMruMenu, WORD wItem,
                  BOOL fIDMBased, LPSTR lpItem, UINT uiSize )
{
    if ( fIDMBased )
        wItem -= ( lpMruMenu->wIdMru + 1 );
    if ( wItem >= lpMruMenu->wNbItemFill )
        return FALSE;
    _fstrncpy( lpItem, ( lpMruMenu->lpMRU ) +
               ( ( lpMruMenu->wMaxSizeLruItem ) * ( UINT )( wItem ) ), uiSize );
    *( lpItem + uiSize - 1 ) = '\0';
    return TRUE;
}
Exemplo n.º 8
0
DWORD   _fstrtoul (LPSTR lpString, LPSTR FAR *ppStrEnd, int iRadix)
{
    static char szWrkBuf[TBXMAXSTR];
    static char *pcTmpPtr;
    DWORD       ulRetVal;

    /********************************************************************/
    /********************************************************************/
    _fstrncpy (szWrkBuf, lpString, TBXMAXSTR);
    ulRetVal = strtoul (szWrkBuf, &pcTmpPtr, iRadix);
    if (ppStrEnd) *ppStrEnd = pcTmpPtr;
    return (ulRetVal);
}
Exemplo n.º 9
0
void TestMoveF( void )
{
    char            bufA[80] = "FoO baR gOoBeR bLaH";
    char            bufB[80];
    char __far      *bufPtr;
    char __far      *newBuf;
    int             status;

    bufPtr = _fstrcpy( bufB, "FoO baR" );       /* copy string */
    VERIFY( bufPtr == bufB );

    bufPtr = _fstrcat( bufB, " gOoBeR bLaH" );  /* append the rest */
    VERIFY( bufPtr == bufB );

    status = _fstrcmp( bufA, bufB );            /* check result */
    VERIFY( status == 0 );

    bufPtr = _fstrset( bufB, 0x00 );            /* zero out buffer */
    VERIFY( bufPtr == bufB );

    bufPtr = _fstrncpy( bufB, "ABCDEFGHIJ", 2 );/* copy two bytes */
    VERIFY( bufPtr == bufB );

    bufPtr = _fstrncat( bufB, "CDEFGHIJ", 3 );  /* copy three more */
    VERIFY( bufPtr == bufB );

    status = _fstrcmp( bufB, "ABCDE" );         /* ensure only five bytes */
    VERIFY( status == 0 );

    bufPtr = _fstrnset( bufB, 0x00, 10 );       /* blank string */
    VERIFY( bufPtr == bufB );

    status = _fstrcmp( bufB, "" );              /* verify empty */
    VERIFY( status == 0 );

    bufPtr = _fstrcpy( bufB, "abcdefghij" );    /* copy string */
    VERIFY( bufPtr == bufB );

    bufPtr = _fstrrev( bufB );                  /* reverse it */
    VERIFY( bufPtr == bufB );

    status = _fstrcmp( bufB, "jihgfedcba" );    /* ensure reversed ok */
    VERIFY( status == 0 );

    newBuf = _fstrdup( bufA );                  /* duplicate string */
    status = _fstrcmp( bufA, newBuf );
    VERIFY( status == 0 );
}
Exemplo n.º 10
0
/////////////////////////////////////////////////////////////////////////////
// Audio ToolBox Installation DLL
// Copyright (c) 1987-1996 Andrew J. Michalik
/////////////////////////////////////////////////////////////////////////////
DWORD FAR PASCAL ChkRegSer (WORD usRsv001, LPCSTR szSerNum)
{
	/////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////
	#define		DIGSUMCNT   10			// Number of digits to sum
	#define		DIGPOSMUL  100			// Digit position multiplier
	#define		SERMAXLEN   64			// Maximum serial number length
	#define		ASCNUMBAS 0x30			// ASCII numeric base value
	static char	szTmp[SERMAXLEN];		// Temporary work string
	char *		pTmp = szTmp;			// Temporary work string
	long		lSum = 0L;
	int			ii = 0;

	/////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////
	if (!szSerNum) return (0L);

	/////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////
	_fstrncpy (szTmp, szSerNum, SERMAXLEN - 1);
	szTmp[SERMAXLEN - 1] = '\0';

	/////////////////////////////////////////////////////////////////////////
	// Calculate the sum of the first DIGSUMCNT digits
	/////////////////////////////////////////////////////////////////////////
	while ((ii < DIGSUMCNT) && _fstrlen(pTmp)) {
		if (isdigit (*pTmp)) {
			lSum = lSum + (*pTmp - ASCNUMBAS);
			ii++;
		}
		pTmp++;
	}

	/////////////////////////////////////////////////////////////////////////
	// Return sum count if requested
	/////////////////////////////////////////////////////////////////////////
	if (usRsv001) return (3 * (lSum * lSum)); 

	/////////////////////////////////////////////////////////////////////////
	// Verify correct number of sum digits
	// Compare Mod of (3 * (sum * sum)) to last digits
	/////////////////////////////////////////////////////////////////////////
	if ((DIGSUMCNT == ii) && (((3 * (lSum * lSum)) % DIGPOSMUL) 
		== atol(pTmp))) return (TRUE);

	/////////////////////////////////////////////////////////////////////////
	return (FALSE);
}
Exemplo n.º 11
0
WORD    GetEncKey (char far *pcSeqNumArr, WORD usKeyFld, WORD far *pusCmpCod)
{
    char    szWrkKey[SERSEGLEN+1];
    SCB     SCB;
    DWORD   ulSeqNum; 

    /********************************************************************/
    /********************************************************************/
    *pusCmpCod = 0;

    /********************************************************************/
    /********************************************************************/
    _fstrncpy (szWrkKey, pcSeqNumArr, SERSEGLEN);
    szWrkKey[SERSEGLEN] = '\0';
    ulSeqNum = _fstrtoul (&szWrkKey[0], NULL, 10);      /* Convert Seq# */

    /********************************************************************/
    /********************************************************************/
    _fstrcpy(SCB.id, "..?Z");           /* Signature Literal            */
    SCB.return_code = -1;               /* Init to invalid return code  */
    SCB.function_code = 1;              /* Code 0, 1, or 2              */
    _fstrcpy(SCB.product_name, "VFEdit");
    SCB.pin_number = 1637034832;        /*  Verify Personal ID Number   */

    /********************************************************************/
    /********************************************************************/
    SCB.product_serial = ulSeqNum;

    /********************************************************************/
    /********************************************************************/
    if (*pusCmpCod = KECHK (&SCB)) {
        if (TBxGlo.usDebFlg & KEY___DEB) 
            MsgDspUsr ("Accelerator I/O Error: %04x\n", *pusCmpCod);
        return (0);
    }
    if (SCB.return_code) {
        if (TBxGlo.usDebFlg & KEY___DEB) 
            MsgDspUsr ("Accelerator Access Error: %04x-%04x-%04x\n",
                SCB.return_code, SCB.return_status, SCB.return_function);
        *pusCmpCod = 0x8000;            // Force completion code non-zero
        return (0);
    }
    return (((WORD *) SCB.user_data)[usKeyFld]);

}
Exemplo n.º 12
0
short FAR PASCAL FilHdlCre (const char far *lpFilNam, unsigned short usOpnFlg, unsigned short usModFlg)
{
    static  char    szLocNam[FIOMAXNAM];
    short           sFilHdl = 0;

    /********************************************************************/
    /* Make a local copy of the file name                               */
    /********************************************************************/
    _fstrncpy (szLocNam, lpFilNam, FIOMAXNAM);

#if (defined (W31)) /****************************************************/
    if (-1 == (sFilHdl = _lcreat (szLocNam, (S_IWRITE & usModFlg) ? 0 : 1)))
        return (-1);
    FilHdlCls (sFilHdl);
    return (FilHdlOpn (szLocNam, usOpnFlg & ~(O_TRUNC | O_CREAT)));
#endif /*****************************************************************/

#if (defined (DOS)) /****************************************************/
    return (_open (szLocNam, usOpnFlg | O_CREAT | O_TRUNC, usModFlg));
#endif /*****************************************************************/
}
Exemplo n.º 13
0
short FAR PASCAL FilGetSta (const char far *lpFilNam, struct _stat far *lpFilSta)
{
    static  char        szLocNam[FIOMAXNAM];
    static struct _stat ssStaBlk;
    unsigned int        uiErrCod;

    /********************************************************************/
    /* Make a local copy of the file name                               */
    /********************************************************************/
    _fstrncpy (szLocNam, lpFilNam, FIOMAXNAM);

    /********************************************************************/
    /********************************************************************/
    uiErrCod = _stat (szLocNam, &ssStaBlk);
    if (NULL != lpFilSta) *lpFilSta = ssStaBlk;

    /********************************************************************/
    /********************************************************************/
    return (uiErrCod);

}
Exemplo n.º 14
0
void FAR PASCAL PathUp (LPSTR lpDest,LPCSTR lpSource)
{
    if (lpDest)
        if (!lpSource || !(*lpSource))
        {
            *lpDest = 0;
        }
        else
        {
            LPCSTR lpLastSlash = lpSource;
            LPCSTR c           = lpSource+lstrlen (lpSource);

            /************************************************************
             *  Always truncate at least one character from end.
             *  This guarantees that a directory will be removed if
             *  the last character of the path name is a "\" or ":".
             ************************************************************/
            c = AnsiPrev (lpSource,c);
            while (c > lpSource)
            {
                c = AnsiPrev (lpSource,c);
                if ((*c=='\\') || (*c==':'))
                {
                    lpLastSlash = c;
                    break;
                }
            }

            /************************************************************
             *  Truncate the path.
             ************************************************************/
            if (lpDest != lpSource)
                _fstrncpy (lpDest,lpSource,lpLastSlash-lpSource);
            lpDest[lpLastSlash-lpSource] = 0; // cuz lpLastSlash is const
        }
}
Exemplo n.º 15
0
void main(int argc, char** argv)
{
	BYTE far*	bp;
	fossil_info_t info;
	WORD	ax,bx;
	char id_string[128];
	union REGS regs;
	struct SREGS sregs;

	printf("\nChecking FOSSIL interrupt vector (interrupt 0x%02X)\n", FOSSIL_INTERRUPT);
	bp=(void far*)_dos_getvect(FOSSIL_INTERRUPT);

	printf("FOSSIL interrupt vector: 0x%08lX\n",bp);
	printf("Signature: 0x%04X (should be 0x%04X)\n", *(WORD far*)(bp+6), FOSSIL_SIGNATURE);
	printf("Highest function supported: 0x%02X\n", *(BYTE far*)(bp+8));


	printf("\nInitializing FOSSIL\n");
	regs.h.ah = FOSSIL_FUNC_INIT;
	int86(FOSSIL_INTERRUPT, &regs, &regs);
	printf("AX=0x%04X (should be 0x%04X)\n", regs.x.ax, FOSSIL_SIGNATURE);
	printf("BX=0x%04X (FOSSIL rev %u, highest function supported: 0x%02X)\n"
		,regs.x.bx, regs.h.bh, regs.h.bl);

	printf("\nGetting FOSSIL Information\n");
	printf("sizeof(info)=%u\n",sizeof(info));
	memset(&info,0,sizeof(info));

/**
 AH = 1Bh    Return information about the driver

           Parameters:
               Entry:  CX = Size of user info buffer in bytes
                       DX = Port number
                       ES = Segment of user info buffer
                       DI = Offset into ES of user info buffer
               Exit:   AX = Number of bytes actually transferred

**/

	bp = (BYTE far*)&info;
	regs.h.ah = FOSSIL_FUNC_GET_INFO;
	regs.x.cx = sizeof(info);
	regs.x.dx = 0;
	sregs.es = FP_SEG(bp);
	regs.x.di = FP_OFF(bp);

	int86x(FOSSIL_INTERRUPT, &regs, &regs, &sregs);
	printf("AX=0x%04X (%u)\n",regs.x.ax,regs.x.ax);
	printf("Information structure size: %u\n", info.info_size);
    printf("FOSSIL specific revision: %u\n", info.curr_fossil);
    printf("FOSSIL driver revision: %u\n", info.curr_rev);
    printf("ID string: 0x%08lX\n",info.id_string);
	if(info.id_string) {
		_fstrncpy(id_string,(char far *)info.id_string,sizeof(id_string));
		printf("ID string: %s\n", id_string);
	}
    printf("Receive buffer size: %u\n", info.inbuf_size);
    printf("Receive buffer space: %u\n",info.inbuf_free);
    printf("Transmit buffer size: %u\n", info.outbuf_size);
    printf("Transmit buffer space: %u\n",info.outbuf_free);
    printf("Screen width: %u\n",info.screen_width);
    printf("Screen height: %u\n", info.screen_height);
    printf("Baud rate: 0x%02X (%u %c-%u-%u)\n"
		,info.baud_rate
		,fossil_baud_rate[(info.baud_rate&FOSSIL_BAUD_RATE_MASK)>>FOSSIL_BAUD_RATE_SHIFT]
		,fossil_parity[(info.baud_rate&FOSSIL_PARITY_MASK)>>FOSSIL_PARITY_SHIFT]
		,fossil_data_bits[(info.baud_rate&FOSSIL_DATA_BITS_MASK)>>FOSSIL_DATA_BITS_SHIFT]
		,fossil_stop_bits[(info.baud_rate&FOSSIL_STOP_BITS_MASK)>>FOSSIL_STOP_BITS_SHIFT]
		);

	if(argc>1 && stricmp(argv[1],"pause")==0) {
		printf("\nHit enter to continue...");
		getchar();
	}
}	
Exemplo n.º 16
0
//---------------------------------------------------------------------------
// ParseCommandLine
//
// This routine parses the command line given.  If the command line is valid,
// then it is assumed that the user's intention is to execute the test given
// and then exit -- without using the UI for anything.  Else, we display the
// usage message box (if the cmdline wasn't valid), and return.
//
// RETURNS:     NULL if cmdline was valid (script run made, or attempted),
//                   or if command line was invalid and usage was given,
//              OR pointer to script to load if /RUN not present given.
//
//              NOTE:   If no script was given, this function returns a ptr
//                      to a null string.
//---------------------------------------------------------------------------
HANDLE *ParseCommandLine (LPSTR cmdline)
{
    CHAR    *tok, *scr;
    INT     doit = 0, scriptfound = 0;
    static  HANDLE  hScr[9] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};

#ifdef DEBUG
    fDiags = 0;
#endif
    // We always return at least one file name, so allocate it now
    //-----------------------------------------------------------------------
    listflag = 0;
    if (!(hScr[0] = LocalAlloc (LHND, 128)))
        {
        MPError (NULL, MB_OK | MB_ICONEXCLAMATION, IDS_OUTOFMEM);
        return (NULL);
        }
    scr = LocalLock (hScr[0]);

    // Return now if no cmdline args given
    //-----------------------------------------------------------------------
    scr[0] = 0;
    tok = GetCmdToken(cmdline);
    if (!tok)
        return (hScr);

    do
        {
        // Check here for the /T (testmode) switch and get its parameter
        //-------------------------------------------------------------------
        if (!_stricmp (tok, "/T") || !_stricmp (tok, "-T"))
            {
            tok = GetCmdToken(cmdline);
            if (!tok)
                {
                Usage();
                return (NULL);
                }
            lstrcpy (tmbuf, tok);
            }

        // Here we check for /C (command) switch
        //-------------------------------------------------------------------
        else if (!_stricmp (tok, "/C") || !_stricmp (tok, "-C"))
            {
            tok = GetCmdToken(cmdline);
            if (!tok)
                {
                Usage();
                return (NULL);
                }
            lstrcpy (cmdbuf, tok);
            }

        // /NOE (no error dialog)
        //-------------------------------------------------------------------
        else if (!_stricmp (tok, "/NOE") || !_stricmp (tok, "-NOE"))
            {
            NOERRDLG = 1;
            }

        // /A (filename) switch (produce assembly listing/diagnostics)
        //-------------------------------------------------------------------
        else if (!_stricmp (tok, "/A") || !_stricmp (tok, "-A"))
            {
            tok = GetCmdToken (cmdline);
            if (!tok)
                {
                Usage();
                return (NULL);
                }
            SetAssemblyListFile (tok);
            }

        // /RUN switch
        //-------------------------------------------------------------------
        else if (!_stricmp (tok, "/RUN") || !_stricmp (tok, "-RUN"))
            {
            doit = 1;
            }
#ifdef DEBUG
        else if (!_stricmp (tok, "/DIAG") || !_stricmp (tok, "-DIAG"))
            {
            fDiags = 1;
            }
#endif

        // /D (define) switch
        //-------------------------------------------------------------------
        else if (!_stricmp (tok, "/D") || !_stricmp (tok, "-D"))
            {
            tok = GetCmdToken(cmdline);
            if (!tok)
                {
                Usage();
                return (NULL);
                }
            if (SymCount == 16)
                {
                MPError (NULL, MB_OK | MB_ICONSTOP, IDS_MANYSYMBOLS);
                return (NULL);
                }
            _fstrncpy (DefSym[SymCount], tok, MAXSYMLEN);
            DefSym[SymCount++][MAXSYMLEN] = 0;
            }

        // If this was nothing above, we assume it's a script name
        //-------------------------------------------------------------------
        else if (scriptfound < 8)
            {
            if (!hScr[scriptfound])
                {
                if (!(hScr[scriptfound] = LocalAlloc (LHND, 128)))
                    {
                    MPError (NULL, MB_OK | MB_ICONEXCLAMATION, IDS_OUTOFMEM);
                    return (NULL);
                    }
                scr = LocalLock (hScr[scriptfound]);
                }
            lstrcpy (scr, tok);
            LocalUnlock (hScr[scriptfound]);
            scriptfound += 1;
            }

        // Must have given too many script names
        //-------------------------------------------------------------------
        else
            {
            Usage ();
            return (NULL);
            }
        }
    while (tok = GetCmdToken(cmdline));

    // No error dialog gets nullified if we're running the environment
    //-----------------------------------------------------------------------
    if (NOERRDLG && (!doit))
        NOERRDLG = 0;

    // Return a pointer to the scripts given if no /RUN switch given
    //-----------------------------------------------------------------------
    if (!doit)
        return (hScr);

    // Give an error if no script name found, or more than one
    //-----------------------------------------------------------------------
    if (scriptfound != 1)
        {
        Usage ();
        return (NULL);
        }

    // Okay, we got a valid cmdline and we need to run.  Send the script to
    // the parsing engine.
    //
    // NEW:  Create a simple window which stays minimized and behind every
    // NEW:  other window.  The window text for this will contain the name
    // NEW:  of the script running.
    //-----------------------------------------------------------------------
    EnsureExt (scr, 80);
    AnsiUpper (scr);
    Command = cmdbuf;
    TestMode = tmbuf;

    // KLUDGE:  Call peekmessage to yield once...
    {
    MSG     msg;
    CHAR    buf[256], fmt[40];

    PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE);

    // Change the window text of the viewport for this guy...
    //-----------------------------------------------------------------------
    if (LoadString (hInst, IDS_VPRUNTITLE, fmt, sizeof(fmt)))
        {
        wsprintf (buf, fmt, (LPSTR)scr);
        SetWindowText (hwndViewPort, buf);
        }
    }

    // Here's where we create the dummy window
    //-----------------------------------------------------------------------
    hwndDummy = CreateWindow (szRBRun, (LPSTR)scr,
                              WS_OVERLAPPED|WS_SYSMENU,
                              0, 0, 0, 0, NULL, NULL, hInst, NULL);
    SetWindowPos (hwndDummy, (HWND)1, 0, 0, 0, 0,
                  SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
    ShowWindow (hwndDummy, SW_SHOWMINNOACTIVE);

    // Okay, here we go.
    //-----------------------------------------------------------------------
    if (InitParser ())
	{
	// HACKHACK: ntbldrus (kenhia) - on x86, complains about uninit var
	//	     41 lines below (in final else WITHIN this if block)
	HCURSOR hOld = 0;

        // Initialize the scanner
        //-------------------------------------------------------------------
        if (BeginScan (scr, CBLoaderImmediate, SymCount, DefPtrs))
            {
#ifdef DEBUG
            if (fDiags)
                OpenDiagFile (scr);
#endif
            hOld = SetCursor (LoadCursor (NULL, IDC_WAIT));
            if (!PcodeCompile())
                {
                if (PcodeFixup(0))
                    {
                    SetCursor (hOld);
                    PcodeExecute(PE_RUN, NULL);
                    DestroyWindow (hwndDummy);
                    DestroyWindow (hwndViewPort);
                    exit (ExitVal);
                    }
                else
                    {
                    SetCursor (hOld);
                    DestroyWindow (hwndDummy);
                    DestroyWindow (hwndViewPort);
                    exit (1);
                    }
                }
            else
                {
                SetCursor (hOld);
                DestroyWindow (hwndDummy);
                DestroyWindow (hwndViewPort);
                exit (1);
                }
            EndScan ();
            }
        else
            {
            SetCursor (hOld);
            AbortParser();
            MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTREAD, (LPSTR)scr);
            DestroyWindow (hwndDummy);
            DestroyWindow (hwndViewPort);
            exit (1);
            }
        }
    else
        MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTINIT);

    DestroyWindow (hwndViewPort);
    DestroyWindow (hwndDummy);
    exit (1);
}
Exemplo n.º 17
0
int
main(int argc, char **argv)
#endif
{
	LPSTR tail;
	int i;

#ifdef WGP_CONSOLE
	HINSTANCE hInstance = GetModuleHandle(NULL), hPrevInstance = NULL;
#endif


#ifndef WGP_CONSOLE
# if defined( __MINGW32__) && !defined(_W64)
#  define argc _argc
#  define argv _argv
# else /* MSVC, WATCOM, MINGW-W64 */
#  define argc __argc
#  define argv __argv
# endif
#endif /* WGP_CONSOLE */

        szModuleName = (LPSTR)malloc(MAXSTR+1);
        CheckMemory(szModuleName);

        /* get path to EXE */
        GetModuleFileName(hInstance, (LPSTR) szModuleName, MAXSTR);
        if ((tail = (LPSTR)_fstrrchr(szModuleName,'\\')) != (LPSTR)NULL)
        {
                tail++;
                *tail = 0;
        }
        szModuleName = (LPSTR)realloc(szModuleName, _fstrlen(szModuleName)+1);
        CheckMemory(szModuleName);

        if (_fstrlen(szModuleName) >= 5 && _fstrnicmp(&szModuleName[_fstrlen(szModuleName)-5], "\\bin\\", 5) == 0)
        {
                int len = _fstrlen(szModuleName)-4;
                szPackageDir = (LPSTR)malloc(len+1);
                CheckMemory(szPackageDir);
                _fstrncpy(szPackageDir, szModuleName, len);
                szPackageDir[len] = '\0';
        }
        else
                szPackageDir = szModuleName;

#ifndef WGP_CONSOLE
        textwin.hInstance = hInstance;
        textwin.hPrevInstance = hPrevInstance;
        textwin.nCmdShow = nCmdShow;
        textwin.Title = "gnuplot";
#endif

		/* create structure of first graph window */
		graphwin = (LPGW) calloc(1, sizeof(GW));
		listgraphs = graphwin;

		/* locate ini file */
		{
			char * inifile;
			get_user_env(); /* this hasn't been called yet */
			inifile = gp_strdup("~\\wgnuplot.ini");
			gp_expand_tilde(&inifile);

			/* if tilde expansion fails use current directory as
			   default - that was the previous default behaviour */
			if (inifile[0] == '~') {
				free(inifile);
				inifile = "wgnuplot.ini";
			}

#ifndef WGP_CONSOLE
			textwin.IniFile = inifile;
#endif
			graphwin->IniFile = inifile;

			ReadMainIni(inifile, "WGNUPLOT");
		}

#ifndef WGP_CONSOLE
        textwin.IniSection = "WGNUPLOT";
        textwin.DragPre = "load '";
        textwin.DragPost = "'\n";
        textwin.lpmw = &menuwin;
        textwin.ScreenSize.x = 80;
        textwin.ScreenSize.y = 80;
        textwin.KeyBufSize = 2048;
        textwin.CursorFlag = 1; /* scroll to cursor after \n & \r */
        textwin.shutdown = MakeProcInstance((FARPROC)ShutDown, hInstance);
        textwin.AboutText = (LPSTR)malloc(1024);
        CheckMemory(textwin.AboutText);
        sprintf(textwin.AboutText,
	    "Version %s patchlevel %s\n" \
	    "last modified %s\n" \
	    "%s\n%s, %s and many others\n" \
	    "gnuplot home:     http://www.gnuplot.info\n",
            gnuplot_version, gnuplot_patchlevel,
	    gnuplot_date,
	    gnuplot_copyright, authors[1], authors[0]);
        textwin.AboutText = (LPSTR)realloc(textwin.AboutText, _fstrlen(textwin.AboutText)+1);
        CheckMemory(textwin.AboutText);

        menuwin.szMenuName = szMenuName;
#endif

        pausewin.hInstance = hInstance;
        pausewin.hPrevInstance = hPrevInstance;
        pausewin.Title = "gnuplot pause";

        graphwin->hInstance = hInstance;
        graphwin->hPrevInstance = hPrevInstance;
#ifdef WGP_CONSOLE
        graphwin->lptw = NULL;
#else
        graphwin->lptw = &textwin;
#endif

		/* init common controls */
	{
	    INITCOMMONCONTROLSEX initCtrls;
	    initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
	    initCtrls.dwICC = ICC_WIN95_CLASSES;
	    InitCommonControlsEx(&initCtrls);
	}

#ifndef WGP_CONSOLE
	if (TextInit(&textwin))
		gp_exit(EXIT_FAILURE);
	textwin.hIcon = LoadIcon(hInstance, "TEXTICON");
	SetClassLongPtr(textwin.hWndParent, GCLP_HICON, (LONG_PTR)textwin.hIcon);

	/* Note: we want to know whether this is an interactive session so that we can
	 * decide whether or not to write status information to stderr.  The old test
	 * for this was to see if (argc > 1) but the addition of optional command line
	 * switches broke this.  What we really wanted to know was whether any of the
	 * command line arguments are file names or an explicit in-line "-e command".
	 * (This is a copy of a code snippet from plot.c)
	 */
	for (i = 1; i < argc; i++) {
		if (!stricmp(argv[i], "/noend"))
			continue;
		if ((argv[i][0] != '-') || (argv[i][1] == 'e')) {
			interactive = FALSE;
			break;
		}
	}
	if (interactive)
		ShowWindow(textwin.hWndParent, textwin.nCmdShow);
	if (IsIconic(textwin.hWndParent)) { /* update icon */
		RECT rect;
		GetClientRect(textwin.hWndParent, (LPRECT) &rect);
		InvalidateRect(textwin.hWndParent, (LPRECT) &rect, 1);
		UpdateWindow(textwin.hWndParent);
	}
# ifndef __WATCOMC__
	/* Finally, also redirect C++ standard output streams. */
	RedirectOutputStreams(TRUE);
# endif
#else /* WGP_CONSOLE */
#ifdef CONSOLE_SWITCH_CP
        /* Change codepage of console to match that of the graph window.
           WinExit() will revert this.
           Attention: display of characters does not work correctly with
           "Terminal" font! Users will have to use "Lucida Console" or similar.
        */
        cp_input = GetConsoleCP();
        cp_output = GetConsoleOutputCP();
        if (cp_input != GetACP()) {
            cp_changed = TRUE;
            SetConsoleCP(GetACP()); /* keyboard input */
            SetConsoleOutputCP(GetACP()); /* screen output */
            SetFileApisToANSI(); /* file names etc. */
        }
#endif
#endif

	gp_atexit(WinExit);

	if (!isatty(fileno(stdin)))
		setmode(fileno(stdin), O_BINARY);

	gnu_main(argc, argv);

	/* First chance to close help system for console gnuplot,
	   second for wgnuplot */
	WinCloseHelp();
	gp_exit_cleanup();
	return 0;
}
Exemplo n.º 18
0
/*
 * create a slm object for the given directory. The pathname may include
 * a filename component.
 * If the directory is not enlisted in a SLM library, this will return NULL.
 *
 * Check that the directory is valid, and that we can open slm.ini, and
 * build a UNC path to the master source library before declaring everything
 * valid.
 */
SLMOBJECT
SLM_New(LPSTR pathname)
{
    SLMOBJECT pslm;
    char slmpath[MAX_PATH];
    HFILE fh;
    BOOL bOK;
    LPSTR pfinal = NULL;



    pslm = (SLMOBJECT) gmem_get(hHeap, sizeof(struct _slmobject));

    if (pslm == NULL) {
	return(NULL);
    }

    if (pathname == NULL) {
	pathname = ".";
    }

    /*
     * find the directory portion of the path.
     */
    if (dir_isvaliddir(pathname)) {

	/*
	 * its a valid directory as it is.
	 */
	lstrcpy(pslm->CurDir, pathname);

    } else {

	/* it's not a valid directory, perhaps because it has a filename on
	 * the end. remove the final element and try again.
	 */

	pfinal = _fstrrchr(pathname, '\\');
	if (pfinal == NULL) {
	    /*
	     * there is no backslash in this name and it is not a directory
	     * - it can only be valid if it is a file in the current dir.
	     * so create a current dir of '.'
	     */
	    lstrcpy(pslm->CurDir, ".");

	    // remember the final element in case it was a wild card
	    pfinal = pathname;
	} else {
	    /*
	     * pfinal points to the final backslash.
	     */
	    _fstrncpy(pslm->CurDir, pathname, pfinal - pathname);
	}
    }

    /*
     * look for slm.ini in the specified directory
     */
    lstrcpy(slmpath, pslm->CurDir);
    if (pslm->CurDir[lstrlen(pslm->CurDir) -1] != '\\') {
	lstrcat(slmpath, "\\");
    }
    lstrcat(slmpath, "slm.ini");

    fh = _lopen(slmpath, 0);
    if (fh != -1) {
	bOK = SLM_ReadIni(pslm, fh);

	/*
	 * if pfinal is not null, then it might be a *.* wildcard pattern
	 * at the end of the path - if so, we should append it to the masterpath.
	 */
	if (pfinal && (_fstrchr(pfinal, '*') || _fstrchr(pfinal, '?'))) {
    	    if ( (pslm->MasterPath[lstrlen(pslm->MasterPath)-1] != '\\') &&
		 (pfinal[0] != '\\')) {
		     lstrcat(pslm->MasterPath, "\\");
	    }
	    lstrcat(pslm->MasterPath, pfinal);
	}


    	_lclose(fh);
    } else {
	bOK = FALSE;
    }

    if (!bOK) {
	gmem_free(hHeap, (LPSTR) pslm, sizeof(struct _slmobject));
	return(NULL);
    } else {
	return(pslm);
    }
}
Exemplo n.º 19
0
int main(int argc, char **argv)
#endif
{
        /*WNDCLASS wndclass;*/
        LPSTR tail;

#ifdef WGP_CONSOLE
# define _argv argv
# define _argc argc
        HINSTANCE hInstance = GetModuleHandle(NULL), hPrevInstance = NULL;
#else
#if defined(__MSC__) || defined(__WATCOMC__)
#  define _argv __argv
#  define _argc __argc
#endif
#endif /* WGP_CONSOLE */

        szModuleName = (LPSTR)malloc(MAXSTR+1);
        CheckMemory(szModuleName);

        /* get path to EXE */
        GetModuleFileName(hInstance, (LPSTR) szModuleName, MAXSTR);
        if ((tail = (LPSTR)_fstrrchr(szModuleName,'\\')) != (LPSTR)NULL)
        {
                tail++;
                *tail = 0;
        }
        szModuleName = (LPSTR)realloc(szModuleName, _fstrlen(szModuleName)+1);
        CheckMemory(szModuleName);

        if (_fstrlen(szModuleName) >= 5 && _fstrnicmp(&szModuleName[_fstrlen(szModuleName)-5], "\\bin\\", 5) == 0)
        {
                int len = _fstrlen(szModuleName)-4;
                szPackageDir = (LPSTR)malloc(len+1);
                CheckMemory(szPackageDir);
                _fstrncpy(szPackageDir, szModuleName, len);
                szPackageDir[len] = '\0';
        }
        else
                szPackageDir = szModuleName;

#ifndef WGP_CONSOLE
        textwin.hInstance = hInstance;
        textwin.hPrevInstance = hPrevInstance;
        textwin.nCmdShow = nCmdShow;
        textwin.Title = "gnuplot";
#endif

		/* create structure of first graph window */
		graphwin = calloc(1, sizeof(GW));
		listgraphs = graphwin;

		/* locate ini file */
		{
			char * inifile;
			get_user_env(); /* this hasn't been called yet */
			inifile = gp_strdup("~\\wgnuplot.ini");
			gp_expand_tilde(&inifile);

			/* if tilde expansion fails use current directory as
			   default - that was the previous default behaviour */
			if (inifile[0] == '~') {
				free(inifile);
				inifile = "wgnuplot.ini";
			}

#ifndef WGP_CONSOLE
			textwin.IniFile = inifile;
#endif
			graphwin->IniFile = inifile;

			ReadMainIni(inifile, "WGNUPLOT");
		}

#ifndef WGP_CONSOLE
        textwin.IniSection = "WGNUPLOT";
        textwin.DragPre = "load '";
        textwin.DragPost = "'\n";
        textwin.lpmw = &menuwin;
        textwin.ScreenSize.x = 80;
        textwin.ScreenSize.y = 80;
        textwin.KeyBufSize = 2048;
        textwin.CursorFlag = 1; /* scroll to cursor after \n & \r */
        textwin.shutdown = MakeProcInstance((FARPROC)ShutDown, hInstance);
        textwin.AboutText = (LPSTR)malloc(1024);
        CheckMemory(textwin.AboutText);
        sprintf(textwin.AboutText,
	    "Version %s patchlevel %s\n" \
	    "last modified %s\n" \
	    "%s\n%s, %s and many others\n" \
	    "gnuplot home:     http://www.gnuplot.info\n",
            gnuplot_version, gnuplot_patchlevel,
	    gnuplot_date,
	    gnuplot_copyright, authors[1], authors[0]);
        textwin.AboutText = (LPSTR)realloc(textwin.AboutText, _fstrlen(textwin.AboutText)+1);
        CheckMemory(textwin.AboutText);

        menuwin.szMenuName = szMenuName;
#endif

        pausewin.hInstance = hInstance;
        pausewin.hPrevInstance = hPrevInstance;
        pausewin.Title = "gnuplot pause";

        graphwin->hInstance = hInstance;
        graphwin->hPrevInstance = hPrevInstance;
#ifdef WGP_CONSOLE
        graphwin->lptw = NULL;
#else
        graphwin->lptw = &textwin;
#endif

		/* init common controls */
	{
	    INITCOMMONCONTROLSEX initCtrls;
	    initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
	    initCtrls.dwICC = ICC_WIN95_CLASSES;
	    InitCommonControlsEx(&initCtrls);
	}

#ifndef WGP_CONSOLE
        if (TextInit(&textwin))
                exit(1);
        textwin.hIcon = LoadIcon(hInstance, "TEXTICON");
        SetClassLong(textwin.hWndParent, GCL_HICON, (DWORD)textwin.hIcon);
        if (_argc>1) {
                int i,noend=FALSE;
                for (i=0; i<_argc; ++i)
                        if (!stricmp(_argv[i],"-noend") || !stricmp(_argv[i],"/noend")
                            || !stricmp(_argv[i],"-persist"))
                                noend = TRUE;
                if (noend)
                        ShowWindow(textwin.hWndParent, textwin.nCmdShow);
        }
        else
                ShowWindow(textwin.hWndParent, textwin.nCmdShow);
        if (IsIconic(textwin.hWndParent)) { /* update icon */
                RECT rect;
                GetClientRect(textwin.hWndParent, (LPRECT) &rect);
                InvalidateRect(textwin.hWndParent, (LPRECT) &rect, 1);
                UpdateWindow(textwin.hWndParent);
        }
#else /* WGP_CONSOLE */
#ifdef CONSOLE_SWITCH_CP
        /* Change codepage of console to match that of the graph window.
           WinExit() will revert this.
           Attention: display of characters does not work correctly with
           "Terminal" font! Users will have to use "Lucida Console" or similar.
        */
        cp_input = GetConsoleCP();
        cp_output = GetConsoleOutputCP();
        if (cp_input != GetACP()) {
            cp_changed = TRUE;
            SetConsoleCP(GetACP()); /* keyboard input */
            SetConsoleOutputCP(GetACP()); /* screen output */
            SetFileApisToANSI(); /* file names etc. */
        }
#endif
#endif

        atexit(WinExit);

        if (!isatty(fileno(stdin)))
            setmode(fileno(stdin), O_BINARY);

        gnu_main(_argc, _argv, environ);

        /* First chance to close help system for console gnuplot,
        second for wgnuplot */
        WinCloseHelp();
        return 0;
}
Exemplo n.º 20
0
void main (int argc, char **argv, char **envp)
{
    char    szCurDir[FIOMAXNAM] = {'\0'};
    char    szAppDir[FIOMAXNAM] = {'\0'};
    char    szSrcFil[FIOMAXNAM] = {'\0'};
    char    szTrgSpc[FIOMAXNAM] = {'\0'};
    WORD    usRepFlg = 0;
    WORD    usi;

    /********************************************************************/
    /********************************************************************/
    printf (MsgUseIni);

    /********************************************************************/
    /* Get current working directory (with trailing slash).             */
    /* Get application executable directory; remove program file name.  */
    /********************************************************************/
    xgetdcwd (szCurDir, FIOMAXNAM - 1);
    usi = _fstrlen (_fstrncpy (szAppDir, *argv, FIOMAXNAM));
    while (usi--) if ('\\' == szAppDir[usi]) {
        szAppDir[usi+1] = '\0';        
        break;
    }    

    /********************************************************************/
    /* Check argument count. Skip program name                          */
    /********************************************************************/
    if (strncmp (*++argv, "-h", 2) == 0) DspHlpEnd ();
    if (argc < 2) UseErrEnd (NULL);

    /********************************************************************/
    /* Get name of source file                                          */
    /********************************************************************/
    strncpy (szSrcFil, *argv++, FIOMAXNAM);
    argc = argc - 2;                    /* Indicate name & 1 arg used   */

    /********************************************************************/
    /* Get name of new file name (if specified)                         */
    /********************************************************************/
    if ((0 != argc) && (NULL == strchr (*argv, '-'))) {
        strncpy (szTrgSpc, *argv++, FIOMAXNAM);
        argc--;
    }

    /********************************************************************/
    /********************************************************************/
    IniSu4Hdr (&rbRepBlk.shSu4Hdr);

    /********************************************************************/
    /********************************************************************/
    while (0 < argc--) {
        if (!strcmp (*argv, "-a")) rbRepBlk.shSu4Hdr.ulEncFmt = DW_SWP(SU4PCMA08);
          else if (!strcmp (*argv, "-b")) usRepFlg |= BFRBKIFLG; 
            else if (!strncmp (*argv, "-d", 2)) strncpy (rbRepBlk.shSu4Hdr.ucFilDes, &(*argv)[2], SU4DESLEN);
              else if (!strncmp (*argv, "-i", 2)) rbRepBlk.shSu4Hdr.ulFil_ID = DW_SWP((DWORD) atol (&(*argv)[2]));
                else if (!strncmp (*argv, "-l", 2)) rbRepBlk.shSu4Hdr.ulLibCod = DW_SWP((DWORD) atol (&(*argv)[2]));
                  else UseErrEnd (*argv);
        *argv++;
    }

    /********************************************************************/
    /********************************************************************/
    BinFilRep (szSrcFil, szTrgSpc, usRepFlg, Su4ChkFil, Su4RepFil, Su4EndFil, NULL, &rbRepBlk);
    printf ("%ld converted\n", rbRepBlk.ulFilCnt);
    exit (0);

}
Exemplo n.º 21
0
/****************************************************************************
 * Creator: T. M. Farrington
 * Purpose: To search a binary file that contains command syntaxes.
 *
 * Inputs:  One binary file, the name of which is defined in the include file.
 *          Character pointer to the function name to be looked up.
 *          Character pointer to a buffer where the full command syntax will
 *             be placed if it is found.
 *          Maximum string size that the buffer can receive.
 *
 * Outputs: Return TRUE if search was successful, FALSE if not.
 *          If TRUE, places full command syntax in the buffer.
 *
 ****************************************************************************/
int W_EXPORT KpeGetKALHelp(LPSTR fnameptr, LPSTR buffer, int maxsiz)
{
    FILE *finptr;
    int iFile;
    OFSTRUCT of;
    char pFullPath[FILENAME_MAX];
    unsigned short csfname = lstrlen(fnameptr) + 1;
    unsigned short ssfname, ssrecord;
    unsigned short found = FALSE;

    /* First look for the file in KAPPA's system directory. *
     * If not there, then use the PATH.                     */
    KppGetSystemDirectory(pFullPath, FILENAME_MAX);
    strncat(pFullPath, binary_file, FILENAME_MAX - strlen(pFullPath) - 1);
    if ((iFile = OpenFile(pFullPath, &of, OF_READ)) == -1)
        iFile = OpenFile(binary_file, &of, OF_READ);

    if ((iFile == -1) || ((finptr = fdopen(iFile, "rb")) == NULL))
    {
        RegisterKappaMessage(IDE_FCANTOPEN,
                             KppAddAtom(binary_file), NULLID, NULLID);
        KppIncrementPopupCountCB(EDITW);
        PostKappaMessage();
        KppDecrementPopupCountCB(EDITW);
        return FALSE;
    }

    rewind(finptr);

    /* While not found, get the two string length values (2 bytes each)
     * at the begining of the record. 
     */
    while (!found)
    {
        fread(&ssfname, 2, 1, finptr);
        if (feof(finptr))
            break;

        fread(&ssrecord, 2, 1, finptr);
        if (feof(finptr))
            break;

        /* If the size of the parameter function name ==
            * size of the scanned function name,
                */
        if (csfname == ssfname)
        {
            char data[MAX_RECORD_LENGTH];

            /* then read the function name and if the strings match, */
            if ((fread(data, ssfname, 1, finptr) != NULL) &&
                (!lstrcmp(fnameptr, data)))
            {
                /* get the rest of the record and concatenate both strings
                    into the output file,
                        RBP: Do not concatenate */
                /* kstrcpy (buffer, data, maxsiz); */
                if (fread(data, ssrecord - ssfname - 4, 1, finptr) != NULL)
                    _fstrncpy(buffer, data, maxsiz);

                /* Stop the search. */
                found = TRUE;
            }
            else
                /* otherwise advance the file pointer to the next record.*/
                fseek(finptr, (long) ssrecord - 4 - ssfname, SEEK_CUR);
        }
        else                        /* otherwise advance the file pointer to the next record. */
            fseek(finptr, (long) ssrecord - 4, SEEK_CUR);
    }

    fclose(finptr);

    if (!found && (KppGetKalFunctionSyntaxCB(KppCheckAtom(fnameptr),
                                             buffer, maxsiz) != -1 ||
                   KppGetDLLFunctionSyntax(fnameptr, buffer, maxsiz) != -1))
        found = TRUE;

    return found;
}