Пример #1
0
//USAGE: create a b9modelloader object and if readyread returns true, begin using loadnexttri()
B9ModelLoader::B9ModelLoader( QString filename, bool &readyRead, QObject *parent) :
    QObject(parent)
{   
    qDebug() << "B9ModelLoader: Initializing..";
    this->byteCount = 0;
    this->triCount = 0;
    this->lastError = "";
    this->lastpercent = 0.0;
    QFileInfo info(filename);

    fileType = DetermineFileType(filename, readyRead);

    if(readyRead == false)//it could be possible that the file couldnt even be opened.
        return;

    if(fileType == "BIN_STL")
    {
        PrepareSTLForReading(filename,readyRead);
    }
    else if(fileType == "ASCII_STL")
    {
        PrepareSTLForReading(filename,readyRead);
    }
    else if(fileType == "UNCOMPRESSED_AMF")
    {

    }




}
Пример #2
0
BOOL RC_PreProcess(PCHAR szname)
{
    PFILE fhout;        /* fhout: is temp file with rcincluded stuff */
    PFILE fhin;
    CHAR nm[_MAX_PATH*2];
    PCHAR pch;
    PWCHAR pwch;
    PWCHAR pfilename;
    WCHAR readszbuf[READ_MAX];
    WCHAR szT[ MAXSTR ];
    UINT iLine = 0;
    int fBlanks = TRUE;
    INT fFileType;

    /* Open the .RC source file. */
    MultiByteToWideChar(uiCodePage, MB_PRECOMPOSED, szname, -1, Filename, MED_BUFFER+1);
    fhin = fopen(szname, "rb");
    if (!fhin) {
        SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(1110), szname);
        return(FALSE);
    }

    /* Open the temporary output file. */
    fhout = fopen(szTempFileName, "w+b");
    if (!fhout) {
        strcpy(Msg_Text, GET_MSG(2180));
        return(FALSE);
    }

    /* output the current filename for RCPP messages */
    for (pch=nm ; *szname ; szname = CharNextA(szname)) {
        *pch++ = *szname;
        if (IsDBCSLeadByteEx(uiCodePage, *szname))
            *pch++ = *(szname + 1);
        /* Hack to fix bug #8786: makes '\' to "\\" */
        else if (*szname == '\\')
            *pch++ = '\\';
    }
    *pch++ = '\000';

    /* Output the current filename for RCPP messages */
    wcscpy(szT, L"#line 1\"");
    // hack - strlen("#line 1\"") is 8.
    MultiByteToWideChar(uiCodePage, MB_PRECOMPOSED, nm, -1, szT+8, MAXSTR+1-8);
    wcscat(szT, L"\"\r\n");
    MyWrite(fhout, szT, wcslen(szT) * sizeof(WCHAR));

    /* Determine if the input file is Unicode */
    fFileType = DetermineFileType (fhin);

    /* Process each line of the input file. */
    while (fgetl(readszbuf, READ_MAX, fFileType == DFT_FILE_IS_16_BIT, fhin)) {

        /* keep track of the number of lines read */
        Linenumber = iLine++;

        if ((iLine & RC_PREPROCESS_UPDATE) == 0)
            UpdateStatus(1, iLine);

        /* Skip the Byte Order Mark and the leading bytes. */
        pwch = readszbuf;
        while (*pwch && (iswspace(*pwch) || *pwch == 0xFEFF))
            pwch++;

        /* if the line is a rcinclude line... */
        if (strpre(L"rcinclude", pwch)) {
            /* Get the name of the rcincluded file. */
            pfilename = skipblanks(pwch + 9, TRUE);

            MyWrite(fhout, L"#include \"", 10 * sizeof(WCHAR));
            MyWrite(fhout, pfilename, wcslen(pfilename) * sizeof(WCHAR));
            MyWrite(fhout, L"\"\r\n", 3 * sizeof(WCHAR));

        }
        else if (strpre(L"#pragma", pwch)) {
            WCHAR cSave;

            pfilename = skipblanks(pwch + 7, FALSE);
            if (strpre(L"code_page", pfilename)) {
                pfilename = skipblanks(pfilename + 9, FALSE);
                if (*pfilename == L'(') {
                    ULONG cp = 0;

                    pfilename = skipblanks(pfilename + 1, FALSE);
                    // BUGBUG really should allow hex/octal, but ...
                    if (iswdigit(*pfilename)) {
                        while (iswdigit(*pfilename)) {
                            cp = cp * 10 + (*pfilename++ - L'0');
                        }
                        pfilename = skipblanks(pfilename, FALSE);
                    }
                    else if (strpre(L"default", pfilename)) {
                        cp = uiDefaultCodePage;
                        pfilename = skipblanks(pfilename + 7, FALSE);
                    }

                    if (cp == 0) {
                        wsprintfA(Msg_Text, "%s%ws", GET_MSG(4212), pfilename);
                        error(4212);
                    }
                    else if (*pfilename != L')') {
                        strcpy (Msg_Text, GET_MSG (4211));
                        error(4211);
                    }
                    else if (cp == CP_WINUNICODE) {
                        strcpy (Msg_Text, GET_MSG (4213));
                        warning(4213);
                    }
                    else if (!IsValidCodePage(cp)) {
                        strcpy (Msg_Text, GET_MSG (4214));
                        warning(4214);
                    }
                    else {
                        uiCodePage = cp;
                        /* Copy the #pragma line to the temp file. */
                        MyWrite(fhout, pwch, wcslen(pwch) * sizeof(WCHAR));
                        MyWrite(fhout, L"\r\n", 2 * sizeof(WCHAR));
                    }
                }
                else {
                    strcpy (Msg_Text, GET_MSG (4210));
                    error(4210);
                }
            }
        }
        else if (!*pwch)
            fBlanks = TRUE;
        else {
            if (fBlanks) {
                swprintf(szT, L"#line %d\r\n", iLine);
                MyWrite(fhout, szT, wcslen(szT) * sizeof(WCHAR));
                fBlanks = FALSE;
            }
            /* Copy the .RC line to the temp file. */
            MyWrite(fhout, pwch, wcslen(pwch) * sizeof(WCHAR));
            MyWrite(fhout, L"\r\n", 2 * sizeof(WCHAR));
        }
    }

    lCPPTotalLinenumber = iLine;
    Linenumber = 0;

    uiCodePage = uiDefaultCodePage;

    fclose(fhout);
    fclose(fhin);

    return(TRUE);
}
Пример #3
0
/************************************************************************
 * NEWINPUT - A new input file is to be opened, saving the old.
 *
 * ARGUMENTS
 *	char *newname - the name of the file
 *
 * RETURNS  - none
 *
 * SIDE EFFECTS  
 *	- causes input stream to be switched
 *	- Linenumber is reset to 1
 *	- storage is allocated for the newname
 *	- Filename is set to the new name
 *
 * DESCRIPTION  
 *	The file is opened, and if successful, the current input stream is saved
 *	and the stream is switched to the new file. If the newname is NULL,
 *	then stdin is taken as the new input.
 *
 * AUTHOR - Ralph Ryan, Sept. 9, 1982
 *
 * MODIFICATIONS - none
 *
 ************************************************************************/
int newinput (char *newname, int m_open)
{
    filelist_t *pF;
    TEXT_TYPE	p;
    WCHAR	*pwch;

    if( newname == NULL ) {
	Fp = stdin;
    }
    else if((Fp = fopen(newname, "rb")) == NULL)
    {
	if(m_open == MUST_OPEN) {
	    Msg_Temp = GET_MSG (1013);
	    SET_MSG (Msg_Text, Msg_Temp, newname);
	    fatal(1013);
	}
	return(FALSE);
    }

    /* now push it onto the file stack */
    ++Findex;
    if(Findex >= LIMIT_NESTED_INCLUDES) {
	Msg_Temp = GET_MSG (1014);
	SET_MSG (Msg_Text, Msg_Temp);
	fatal(1014);
    }
    pF = &Fstack[Findex];
    if(Findex == 0) {
	p = &InputBuffer[(IO_BLOCK * 0) + PUSHBACK_BYTES];
	pwch = &wchInputBuffer[(IO_BLOCK * 0) + PUSHBACK_BYTES];
	pF->fl_bufsiz = SIX_K;
    }
    else {
	filelist_t	*pPrevF;

	pPrevF = pF - 1;
	if(Findex == 1) {			/* first level include */
	    p = &InputBuffer[(IO_BLOCK * 1) + PUSHBACK_BYTES];
	    pwch = &wchInputBuffer[(IO_BLOCK * 1) + PUSHBACK_BYTES];
	    pF->fl_bufsiz = FOUR_K;
	}
	else {		/* (Findex > 1) */
	    /* nested includes . . . */
	    p = &InputBuffer[(IO_BLOCK * 2) + PUSHBACK_BYTES];
	    pwch = &wchInputBuffer[(IO_BLOCK * 2) + PUSHBACK_BYTES];
	    pF->fl_bufsiz = TWO_K;
	}
	if((pPrevF->fl_numread > TWO_K) || (Findex > 2)) {
	    /*
		**  the parent file has read something into the upper section
		**  or this is a nested include at least 3 deep.
		**  the child will overwrite some parent info. we must take this
		**  into account for the parent to reread when the time comes.
		**  we also must stick in the eos char into the parents buffer.
		**  (this latter is the useless thing in deeply nested
		**  includes since we overwrite the thing we just put in. we'll
		**  handle this later when we fpop the child.)
		*/
	    TEXT_TYPE	pCurrC;
	    long		seek_posn;

	    seek_posn = pPrevF->fl_totalread;
	    if( Macro_depth != 0 ) {
		/*
		**  in a macro, the 'current char' we want is kept as the
		**  first thing in the macro structure.
		*/
		pCurrC = (TEXT_TYPE)Macro_expansion[1].exp_string;
	    }
	    else {
		pCurrC = (TEXT_TYPE)Current_char;
	    }
	    if(pCurrC >= p) {
		/*
		**  p is the start of the child section.
		**  current char is past it. ie, we've already read some
		**  from the upper section.
		**  current char - p = # of characters used in upper section.
		**  numread = 0 implies there are no chars left from the parent.
		**  since, this is really the 'end' of the parent's buffer,
		**  we'll have to update the info so that the next read from the
		**  parent (after the child is finished) will be the terminator
		**  and we want the io_eob handler to refill the buffer.
		**  we reset the parent's cur char ptr to the beginning of its
		**  buffer, and put the terminator there.
		*/
		seek_posn += (pCurrC - pPrevF->fl_buffer);
		pPrevF->fl_totalread += (pCurrC - pPrevF->fl_buffer);
		pPrevF->fl_numread = 0;
		if( Macro_depth != 0 ) {
		    Macro_expansion[1].exp_string = pPrevF->fl_buffer;
		}
		else {
		    Current_char = pPrevF->fl_buffer;
		}
		*(pPrevF->fl_buffer) = EOS_CHAR;
		*(pPrevF->fl_pwchBuffer) = EOS_CHAR;
	    }
	    else {
		/*
		**  the upper section has not been read from yet,
		**  but it has been read into.
		**  'p' is pointing to the start of the child's buffer.
		**  we add the terminator to the new end of the parent's buffer.
		*/
		seek_posn += TWO_K;
		pPrevF->fl_numread = TWO_K;
		*(pPrevF->fl_buffer + TWO_K) = EOS_CHAR;
		*(pPrevF->fl_pwchBuffer + TWO_K) = EOS_CHAR;
	    }

	    if (pPrevF->fl_fFileType == DFT_FILE_IS_8_BIT) {
		fseek(pPrevF->fl_file, seek_posn, SEEK_SET);
	    
	    } else {

		fseek(pPrevF->fl_file, seek_posn * sizeof (WCHAR), SEEK_SET);
	    }
	}
    }
    pF->fl_currc = Current_char;/*  previous file's current char */
    pF->fl_lineno = Linenumber;	/*  previous file's line number  */
    pF->fl_file = Fp;			/*  the new file descriptor  */
    pF->fl_buffer = p;
    pF->fl_pwchBuffer = pwch;
    pF->fl_numread = 0;
    pF->fl_totalread = 0;

    //- Added to support 16-bit files.
    //- 8-2-91 David Marsyla.
    pF->fl_fFileType = DetermineFileType (Fp);

    //- The file type is unknown, warn them and then take a stab at an
    //- 8-bit file.  8-2-91 David Marsyla.
    if (pF->fl_fFileType == DFT_FILE_IS_UNKNOWN) {
	Msg_Temp = GET_MSG (4413);
	SET_MSG (Msg_Text, Msg_Temp, newname);
	warning (4413);
	pF->fl_fFileType = DFT_FILE_IS_8_BIT;
    }

    vfCurrFileType = pF->fl_fFileType;

    Current_char = (ptext_t)p;
    io_eob();					/*  fill the buffer  */
    /*
	* Note that include filenames will live the entire compiland. This
	* puts the burden on the user with MANY include files.  Any other
	* scheme takes space out of static data.
	* Notice also, that we save the previous filename in the new file's
	* fl_name.
	*/
    pF->fl_name = pstrdup(Filename);
    strncpy(Filebuff,newname,sizeof(Filebuff));
    Linenumber = 0;	/*  do_newline() will increment to the first line */
    if(Eflag) {
	emit_line();
	fwrite("\n", 1, 1, OUTPUTFILE);		/* this line is inserted */
    }
    do_newline();	/*  a new file may have preproc cmd as first line  */
    return(TRUE);
}