Beispiel #1
0
void preamble()                 /* process preamble, use random access       */
{

    mseek(DVIfile, 0L, absolute);       /* read the dvifile from the start   */
    if ((opcode = skipnops()) != PRE)
        errorexit(nopre);
    opcode = (int) get1();        /* check id in preamble, ignore rest of it */
    if (opcode != VERSIONID)
        errorexit(badid);
    mseek(DVIfile, 12L, relative);  /* numerator, denominator, magnification */
    mseek(DVIfile, get1(), relative);         /* skip job identification     */

} /* preamble */
Beispiel #2
0
void walkpages()                  /* process the pages in the DVI-file */
{
    register bool wantpage;

    pagecounter = 0L;
    while ((opcode = skipnops()) != POST) {
        if (opcode != BOP)              /* should be at start of page now    */
            errorexit(nobop);
        else {
            pagecounter++;
            pagenr = sget4();           /* get TeX page number               */
            mseek(DVIfile, 36L, relative); /* skip page header */
            backpointer = sget4();      /* get previous page offset          */
            if (pageswitchon)
                if (sequenceon)
                    wantpage = inlist(pagecounter);
                else
                    wantpage = inlist(pagenr);
            else
                wantpage = TRUE;

            if (wantpage) {
                initpage();
                dopage();
                printpage();
            }
            else {
                skippage();
            }
        }
    }

} /* walkpages */
int main(){
	Color black = make_color(0, 0, 0);
	MMC mmc, *mp;
	IMG img, *ip;

	while(1){
		mmc = mopen(), mp = &mmc;
		mseek(mp, PROGRAM_SIZE, SEEK_CUR);
		
		img = iopen(mp), ip = &img;
		
		draw_clear(&black);
		draw_img(ip);

		while(1){
			if(check_switch(SWITCH1, ON)){

				if(seek_next_img(ip)){
					mclose(mp);
					break;
				}

				draw_img(ip);
			}
		}
	}
}
Beispiel #4
0
int hio_seek(HIO_HANDLE *h, long offset, int whence)
{
	switch (HIO_HANDLE_TYPE(h)) {
	case HIO_HANDLE_TYPE_FILE:
		return fseek(h->handle.file, offset, whence);
	case HIO_HANDLE_TYPE_MEMORY:
		return mseek(h->handle.mem, offset, whence);
	default:
		return -1;
	}
}
Beispiel #5
0
int mcopy(memstream *to, const unsigned int size, memstream *s){
	int _size=size;
	if(_size>mavail(s))_size=mavail(s);
	if(_size>mavail(to))_size=mavail(to);
	if(!_size)return 0;

	mread((unsigned char*)(to->p)+mtell(to),_size,s);mseek(to,_size,SEEK_CUR);
	//mwrite((unsigned char*)(s->p)+mtell(s),_size,to);mseek(s,_size,SEEK_CUR);

	return _size;
}
Beispiel #6
0
void postamble()            /* find and process postamble, use random access */
{
    register long size;
    register int  count;
    struct stat st;

    fstat (fileno(DVIfile), &st);
    size = (long) st.st_size;                   /* get size of file          */
    count = -1;
    do {              /* back file up past signature bytes (223), to id-byte */
        if (size == 0)
            errorexit(nopst);
        size--;
        mseek(DVIfile, size, absolute);
        opcode = (int) get1();
        count++;
    } while (opcode == TRAILER);
    if (count < 4) {                            /* must have 4 trailer bytes */
         foo = count;
         errorexit(fwsgn);
    }
    if (opcode != VERSIONID)
        errorexit(badid);
    mseek(DVIfile, size-4, absolute);       /* back up to back-pointer       */
    mseek(DVIfile, sget4(), absolute);      /* and to start of postamble   */
    if (get1() != POST)
        errorexit(nopst);
    mseek(DVIfile, 20L, relative); /* lastpageoffset, numerator, denominator */
                                   /* magnification, maxpageheight           */
    maxpagewidth = sget4();
    charwidth = maxpagewidth / (ttywidth + espace); 
    stackmax = (int) get2();
    if ((stack = (stackitem *) malloc(stackmax * sizeof(stackitem))) == NULL)
       errorexit(stkrq);

    /* get2() -- totalpages */
    /* fontdefs  do fontdefs in flight ... */

} /* postamble */
Beispiel #7
0
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_file(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    types::String* pSAction = NULL;

    if (in.size() > 6)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "file", 0, 6);
        return types::Function::Error;
    }

    if (in.size() == 0)
    {
        return sci_file_no_rhs(in, _iRetCount, out);
    }

    if (in.size() == 1)
    {
        return sci_file_one_rhs(in, _iRetCount, out);
    }

    // get action
    if (in[0]->isString() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d : string expected.\n"), "file", 1);
        return types::Function::Error;
    }

    pSAction = in[0]->getAs<types::String>();

    if (pSAction->isScalar() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d : A single string expected.\n"), "file", 1);
        return types::Function::Error;
    }

    if (wcscmp(pSAction->get(0), L"open") == 0)
    {
        types::String* pSPath   = NULL;
        types::String* pSOption = NULL;
        types::Double* pSRecl   = NULL;

        int iStatus = 0;
        int iAccess = 0;
        int iForm   = 0;
        int iRecl   = 0;

        int piMode[2] = {0, 0};

        // get path
        if (in[1]->isString() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d : string expected.\n"), "file", 2);
            return types::Function::Error;
        }

        pSPath = in[1]->getAs<types::String>();

        if (pSPath->isScalar() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d : A single string expected.\n"), "file", 2);
            return types::Function::Error;
        }

        // get optional inputs
        for (int i = 2; i < in.size(); i++)
        {
            if (in[i]->isString())
            {
                pSOption = in[i]->getAs<types::String>();
            }
            else if (i != 2 && in[i]->isDouble())
            {
                pSRecl = in[i]->getAs<types::Double>();
                if (pSRecl->isScalar() == false)
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d : A scalar expected.\n"), "file", i + 1);
                    return types::Function::Error;
                }

                iRecl = (int)pSRecl->get(0);
                piMode[1] = iRecl;
                continue;
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d : string expected.\n"), "file", i + 1);
                return types::Function::Error;
            }

            if (pSOption->isScalar() == false)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d : A single string expected.\n"), "file", i + 1);
                return types::Function::Error;
            }

            if (wcscmp(pSOption->get(0), L"new") == 0)
            {
                iStatus = 0;
            }
            else if (wcscmp(pSOption->get(0), L"old") == 0)
            {
                iStatus = 1;
                // file must already exists.
                if (FileExistW(pSPath->get(0)) == false)
                {
                    if (_iRetCount == 2)
                    {
                        out.push_back(types::Double::Empty());
                        out.push_back(new types::Double(240));
                        return types::Function::OK;
                    }
                    else
                    {
                        char* pstrFilename = wide_string_to_UTF8(pSPath->get(0));
                        if (pstrFilename)
                        {
                            Scierror(240, _("%s: The file \"%s\" does not exist.\n"), "file", pstrFilename);
                            FREE(pstrFilename);
                            pstrFilename = NULL;
                        }
                        else
                        {
                            Scierror(240, _("%s: The file does not exist.\n"), "file");
                        }

                        return types::Function::Error;
                    }
                }
            }
            else if (wcscmp(pSOption->get(0), L"scratch") == 0)
            {
                iStatus = 2;
            }
            else if (wcscmp(pSOption->get(0), L"unknown") == 0)
            {
                iStatus = 3;
            }
            else if (wcscmp(pSOption->get(0), L"sequential") == 0)
            {
                iAccess = 0;
            }
            else if (wcscmp(pSOption->get(0), L"direct") == 0)
            {
                iAccess = 1;
            }
            else if (wcscmp(pSOption->get(0), L"formatted") == 0)
            {
                iForm = 0;
            }
            else if (wcscmp(pSOption->get(0), L"unformatted") == 0)
            {
                iForm = 1;
            }
            else
            {
                Scierror(999, _("%s: Wrong value for input argument #%d.\n"), "file", i + 1);
                return types::Function::Error;
            }
        }

        piMode[0] = iStatus + 10 * (iAccess + 10 * iForm);
        int lunit = 0; // file unit. 0 mean we open the file by this name.
        char* pstFilename = wide_string_to_UTF8(pSPath->get(0));
        int iErr = C2F(clunit)(&lunit, pstFilename, piMode, (int)strlen(pstFilename));
        if (iErr)
        {
            if (_iRetCount == 1)
            {
                switch (iErr)
                {
                    case 65  :
                        Scierror(iErr, _("%s: %d logical unit already used.\n"), "file", lunit);
                        break;
                    case 66  :
                        Scierror(iErr, _("%s: Too many files opened!\n"), "file");
                        break;
                    case 67  :
                        Scierror(iErr, _("%s: Unknown file format.\n"), "file");
                        break;
                    case 240 :
                        Scierror(iErr, _("%s: File \"%s\" already exists or directory write access denied.\n"), "file", pstFilename);
                        break;
                    case 241 :
                        Scierror(iErr, _("%s: File \"%s\" does not exist or read access denied.\n"), "file", pstFilename);
                        break;
                    default  :
                        Scierror(iErr, _("%s: Can not open File \"%s\"\n"), "file", pstFilename);
                }

                return types::Function::Error;
            }
            else
            {
                out.push_back(types::Double::Empty());
                out.push_back(new types::Double((double)iErr));
                return types::Function::OK;
            }
        }

        out.push_back(new types::Double((double)lunit));
        if (_iRetCount == 2)
        {
            out.push_back(new types::Double(0.0));
        }

        FREE(pstFilename);
    }
    else if (wcscmp(pSAction->get(0), L"close") == 0 ||
             wcscmp(pSAction->get(0), L"rewind") == 0 ||
             wcscmp(pSAction->get(0), L"backspace") == 0 ||
             wcscmp(pSAction->get(0), L"last") == 0)
    {
        if (_iRetCount != 1)
        {
            Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "file", 1);
            return types::Function::Error;
        }

        if (in.size() != 2)
        {
            Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "file", 2);
            return types::Function::Error;
        }

        if (in[1]->isDouble() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), "file", 2);
            return types::Function::Error;
        }

        types::Double* pDblFileUnit = in[1]->getAs<types::Double>();
        double* pdblUnit = pDblFileUnit->get();

        if (wcscmp(pSAction->get(0), L"close") == 0)
        {
            for (int i = 0; i < pDblFileUnit->getSize(); i++)
            {
                int iErr = mclose((int)(pdblUnit[i]));
                if (iErr)
                {
                    Scierror(999, _("%s: Cannot close file %d.\n"), "file", (int)pdblUnit[i]);
                    return types::Function::Error;
                }
            }
        }
        else if (wcscmp(pSAction->get(0), L"rewind") == 0)
        {
            int iFileUnit = (int)pdblUnit[0];
            types::File* pFile = FileManager::getFile(iFileUnit);

            if (pFile && pFile->getFileType() == 2)
            {
                mseek(iFileUnit, 0, SEEK_SET);
            }
            else if (pFile && pFile->getFileType() == 1)
            {
                C2F(rewindinter)(&iFileUnit);
            }
            else
            {
                Scierror(999, _("%s: Unknown file format.\n"), "file");
                return types::Function::Error;
            }
        }
        else if (wcscmp(pSAction->get(0), L"backspace") == 0)
        {
            int iFileUnit = (int)pdblUnit[0];
            types::File* pFile = FileManager::getFile(iFileUnit);

            if (pFile && pFile->getFileType() == 2)
            {
                Scierror(999, _("%s: Wrong input argument #%d.\n"), "file", 1);
                return types::Function::Error;
            }
            else if (pFile && pFile->getFileType() == 1)
            {
                C2F(backspaceinter)(&iFileUnit);
            }
            else
            {
                Scierror(67, _("%s: Unknown file format.\n"), "file");
                return types::Function::Error;
            }
        }
        else if (wcscmp(pSAction->get(0), L"last") == 0)
        {
            int iFileUnit = (int)pdblUnit[0];
            types::File* pFile = FileManager::getFile(iFileUnit);

            if (pFile && pFile->getFileType() == 2)
            {
                mseek(iFileUnit, 0, SEEK_END);
            }
            else if (pFile && pFile->getFileType() == 1)
            {
                int iErr = 0;
                while (iErr == 0)
                {
                    iErr = C2F(readinter)(&iFileUnit, "(a)", 1L);
                }

                if (iErr == 2)
                {
                    Scierror(999, _("%s: \n"), "file");
                    return types::Function::Error;
                }

                C2F(backspaceinter)(&iFileUnit);
            }
            else
            {
                Scierror(67, _("%s: Unknown file format.\n"), "file");
                return types::Function::Error;
            }
        }
    }
    else
    {
        Scierror(49, _("%s: Wrong value for input argument #%d: \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" \n"), "file", 1, "open", "close", "rewind", "backspace", "last");
        return types::Function::Error;
    }

    return types::Function::OK;
}
Beispiel #8
0
void skippage()                /* skip past one page */
{
    register int opcode;

    while ((opcode = (int) get1()) != EOP) {
        if (opcode > POST_POST)
            errorexit(illop);
        else
            switch (opcode) {
                case SET1     :
                case PUT1     :
                case RIGHT1   :
                case W1       :
                case X1       :
                case DOWN1    :
                case Y1       :
                case Z1       : /* assume FNT change can also be skipped */
                case FNT1     : mseek(DVIfile, 1L, relative); break;
                case SET2     :
                case PUT2     :
                case RIGHT2   :
                case W2       :
                case X2       :
                case DOWN2    :
                case Y2       :
                case Z2       :
                case FNT2     : mseek(DVIfile, 2L, relative); break;
                case SET3     :
                case PUT3     :
                case RIGHT3   :
                case W3       :
                case X3       :
                case DOWN3    :
                case Y3       :
                case Z3       :
                case FNT3     : mseek(DVIfile, 3L, relative); break;
                case SET4     :
                case PUT4     :
                case RIGHT4   :
                case W4       :
                case X4       :
                case DOWN4    :
                case Y4       :
                case Z4       :
                case FNT4     : mseek(DVIfile, 4L, relative); break;
                case SET_RULE :
                case PUT_RULE : mseek(DVIfile, 8L, relative); break;
                case BOP      : errorexit(bdbop); break;
                case XXX1     : mseek(DVIfile, get1(), relative); break;
                case XXX2     : mseek(DVIfile, get2(), relative); break;
                case XXX3     : mseek(DVIfile, get3(), relative); break;
                case XXX4     : mseek(DVIfile, get4(), relative); break;
                case FNT_DEF1 :
                case FNT_DEF2 :
                case FNT_DEF3 :
                case FNT_DEF4 : fontdef(opcode - FNT_DEF1 + 1); break;
                case PRE      : errorexit(bdpre); break;
                case POST     : errorexit(bdpst); break;
                case POST_POST: errorexit(bdpp); break;
        }
    }

} /* skippage */
Beispiel #9
0
void dopage()
{

    while ((opcode = (int) get1()) != EOP) {    /* process page until eop */
        if (opcode <= LASTCHAR)
            dochar((char) opcode);
        else if ((opcode >= FONT_00) && (opcode <= FONT_63)) 
            setfont(opcode - FONT_00);
        else if (opcode > POST_POST)
            errorexit(illop);
        else
            switch (opcode) {
                case SET1     : setchar(get1()); break;
                case SET2     : setchar(get2()); break;
                case SET3     : setchar(get3()); break;
                case SET4     : setchar(get4()); break;
                case SET_RULE : { long height = sget4();
                                  rule(MOVE, sget4(), height); break;
                                }
                case PUT1     : putcharacter(get1()); break;
                case PUT2     : putcharacter(get2()); break;
                case PUT3     : putcharacter(get3()); break;
                case PUT4     : putcharacter(get4()); break;
                case PUT_RULE : { long height = sget4();
                                  rule(STAY, sget4(), height); break;
                                }
                case NOP      : break;  /* no-op */
                case BOP      : errorexit(bdbop); break;
/*              case EOP      : break;  strange place to have EOP */
                case PUSH     : if (sptr >= stackmax)            /* push */
                                     errorexit(stkof);
                                stack[sptr].hh = h;
                                stack[sptr].vv = v;
                                stack[sptr].ww = w;
                                stack[sptr].xx = x;
                                stack[sptr].yy = y;
                                stack[sptr].zz = z;
                                sptr++;
                                break;
                case POP      : if (sptr == 0)                   /* pop */
                                    errorexit(stkuf);
                                sptr--;
                                h = stack[sptr].hh;
                                v = stack[sptr].vv;
                                w = stack[sptr].ww;
                                x = stack[sptr].xx;
                                y = stack[sptr].yy;
                                z = stack[sptr].zz;
                                break;
                case RIGHT1   : (void) horizontalmove(sget1()); break;
                case RIGHT2   : (void) horizontalmove(sget2()); break;
                case RIGHT3   : (void) horizontalmove(sget3()); break;
                case RIGHT4   : (void) horizontalmove(sget4()); break;
                case W0       : h += w; break;
                case W1       : w = horizontalmove(sget1()); break;
                case W2       : w = horizontalmove(sget2()); break;
                case W3       : w = horizontalmove(sget3()); break;
                case W4       : w = horizontalmove(sget4()); break;
                case X0       : h += x; break;
                case X1       : x = horizontalmove(sget1()); break;
                case X2       : x = horizontalmove(sget2()); break;
                case X3       : x = horizontalmove(sget3()); break;
                case X4       : x = horizontalmove(sget4()); break;
                case DOWN1    : v += sget1(); break;
                case DOWN2    : v += sget2(); break;
                case DOWN3    : v += sget3(); break;
                case DOWN4    : v += sget4(); break;
                case Y0       : v += y; break;
                case Y1       : y = sget1(); v += y; break;
                case Y2       : y = sget2(); v += y; break;
                case Y3       : y = sget3(); v += y; break;
                case Y4       : y = sget4(); v += y; break;
                case Z0       : v += z; break;
                case Z1       : z = sget1(); v += z; break;
                case Z2       : z = sget2(); v += z; break;
                case Z3       : z = sget3(); v += z; break;
                case Z4       : z = sget4(); v += z; break;
                case FNT1     :
                case FNT2     :
                case FNT3     :
                case FNT4     : setfont(num(opcode - FNT1 + 1));
                                break;
                case XXX1     : mseek(DVIfile, get1(), relative); break;
                case XXX2     : mseek(DVIfile, get2(), relative); break;
                case XXX3     : mseek(DVIfile, get3(), relative); break;
                case XXX4     : mseek(DVIfile, get4(), relative); break;
                case FNT_DEF1 :
                case FNT_DEF2 :
                case FNT_DEF3 :
                case FNT_DEF4 : fontdef(opcode - FNT_DEF1 + 1);
                                break;
                case PRE      : errorexit(bdpre); break;
                case POST     : errorexit(bdpst); break;
                case POST_POST: errorexit(bdpp); break;
            }
    }

} /* dopage */
Beispiel #10
0
static void seek(InputPlayback *ipb, int time)
{
	mseek(ipb, time * 1000);
}
Beispiel #11
0
void socket_protocol_process(MFILE *mfp, int sockfd)
{
	mseek(mfp);

    // read
    char cmd_type[MAX_LINE] = {0};
    char cmd_name[MAX_LINE] = {0};
    int flag = 0;
    int read_line_finish = 1;
    char buf[MAX_LINE] = {0};
    char *pbuf = buf;
    char ch;
    int i, n, j;

    char response_buf[MAX_LINE] = {0};

	while (1) {
        // 从mfp中逐行取每条指令处理
        memset(buf, 0, sizeof(buf));
        n = mread_line(mfp, buf, sizeof(buf));
        if (n == 0) {
            if (*buf == '\0') {
                break;
            }

            // 未读完一行,mfp中还有数据,这行太长了
            read_line_finish = 0;
        }
        log_debug("read data from mfp data:[%d]%s", n, buf);

        flag = 0;
        for (i=0,j=0; i<=n ;i++) {
            ch = buf[i];
    		//log_debug("%s get ch:%c", sid, ch);

            if (ch == 0 || ch == '\r' || ch == '\n') {
                break;
            }

            if (ch == ' ' || ch == '\r' || ch == '\n') {
                if (flag == 0) {
                    cmd_type[j] = '\0';
                } else {
                    cmd_name[j] = '\0';

                    break;
                }

                flag++;
                j = 0;
                continue;
            }

            if (flag == 0) {
                cmd_type[j] = ch;
            } else if (flag == 1) {
                cmd_name[j] = ch;
            }

            j++;
        }

        if (strcasecmp(buf, "QUIT\r\n") == 0) {
    		char tmp_buf[4196] = {0};
    		int tmp_buf_len = mread(mfp, tmp_buf, sizeof(tmp_buf));
    		log_debug("%s read data from client:[%d]%s", sid, tmp_buf_len, tmp_buf);

            n = snprintf(buf, sizeof(buf), "220 Bye.\r\n");
            n = write(sockfd, buf, n);

            _exit(110);

        } else {
			int nw = write(client_fd, pbuf+i-strlen(cmd_name), strlen(pbuf+i)+strlen(cmd_name));
			if (nw < 0) {
				n = snprintf(buf, sizeof(buf), "FAIL To Write");
                write(sockfd, buf, n);
                return ;
			}
			log_debug("%s write data to fd:%d data:[%d]%s", sid, pfd_w, nw, pbuf+i-strlen(cmd_name));

			if (read_line_finish == 0) {
            	while (((n = mread_line(mfp, buf, sizeof(buf))) == 0) && (*buf != '\0')) {
					nw = write(client_fd, buf, n);
					if (nw < 0) {
						log_error("%s write to fd:%d fail:%m", sid, client_fd);
						return;
					}
					log_debug("%s write to fd:%d data:[%d]%s", sid, pfd_w, nw, pbuf);
					memset(buf, 0, sizeof(buf));
				}	
				if (*buf != '\0') {
					nw = write(client_fd, buf, n);
					if (nw < 0) {
						log_error("%s write to fd:%d fail:%m", sid, client_fd);
						return;
					}
					log_debug("%s write to client fd:%d data:[%d]%s", sid, client_fd, nw, buf);
				}
			}

		}

    }
}