Esempio n. 1
0
 const SharedItemList& seek(const Query& query) const
 {
     items.clear();
     FilterChain::rebuild(filter, query);
     _seek(query);
     return items;
 }
Esempio n. 2
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNLOBDATAPOOL_MATCH, "_rtnLobDataPool::match" )
   BOOLEAN _rtnLobDataPool::match( SINT64 offset )
   {
      PD_TRACE_ENTRY( SDB_RTNLOBDATAPOOL_MATCH ) ;
      BOOLEAN matched = FALSE ;
      if ( _pool.empty() )
      {
         /// do nothing.
      }
      else if ( offset == _currentTuple.offset )
      {
         matched = TRUE ;
      }
      else
      {
         const tuple &first = _pool[0] ;
         if ( first.offset <= offset &&
              offset < ( first.offset + _dataSz ) )
         {
            _seek( offset ) ;
            matched = TRUE ;
         }
      }

      PD_TRACE_EXIT( SDB_RTNLOBDATAPOOL_MATCH ) ;
      return matched ;
   }
Esempio n. 3
0
/** Moves the file pointer to some place in the file. If the file is in buffered
 *  state, then the data is flushed and then the real seek takes place.
 * \param[in] llOffset - offset of the new file pointer position
 * \param[in] uiFrom - specifies the relative point (FS_*) from which the llOffset will be counted
 */
void file::seek(longlong_t llOffset, uint_t uiFrom)
{
	// flush buffer
	flush();

	// seek
	_seek(llOffset, uiFrom);
}
Esempio n. 4
0
vlong
seek(int fd, vlong o, int p)
{
	vlong l;

	if(_seek(&l, fd, o, p) < 0)
		l = -1LL;
	return l;
}
Esempio n. 5
0
u32 elf_loader_read(t_elf_desc* elf_desc,u32 fault_addr,u32 page_addr)
{
	u32 offset;
	t_ext2* ext2;
	
	ext2=system.root_fs;

	offset=(fault_addr & (~(PAGE_SIZE-1))) - PROC_VIRT_MEM_START_ADDR + elf_desc->file_offset;
	_seek(ext2,elf_desc->file_desc,offset,SEEK_SET);
	_read(ext2,elf_desc->file_desc,page_addr,PAGE_SIZE);
}
Esempio n. 6
0
u32 elf_loader_init(t_elf_desc* elf_desc,char* path)
{
	int i;
	unsigned char* process_space;
	int fd;
	unsigned int process_size;
	Elf32_Ehdr* elf_header;
	Elf32_Phdr* elf_prg_header;
	Elf32_Shdr* elf_sct_header;
	t_ext2* ext2;

	void* xxx=elf_desc;

	ext2=system.root_fs;
	fd=_open(ext2,path,O_RDWR | O_APPEND);
	if (fd==-1)
	{
		return -1;
	}
	
	elf_header=kmalloc(sizeof(Elf32_Ehdr));
	_read(ext2,fd,elf_header,sizeof(Elf32_Ehdr));
	elf_prg_header=kmalloc(sizeof(Elf32_Phdr)*elf_header->e_phnum);
	_seek(ext2,fd,elf_header->e_phoff,SEEK_SET);
	elf_desc->file_desc=-1;

	for (i=0;i<elf_header->e_phnum;i++)
	{
		_read(ext2,fd,&elf_prg_header[i],sizeof(Elf32_Phdr));
		if (elf_prg_header[i].p_type==PT_LOAD)
		{
			elf_desc->file_desc=fd;
			elf_desc->file_offset=elf_prg_header[i].p_offset;
			elf_desc->file_size=elf_prg_header[i].p_memsz;
			break;
		}
	}
	kfree(elf_header);
	kfree(elf_prg_header);

	if (elf_desc->file_desc==-1)
	{
		return -1;
	}
	return 0;

}
Esempio n. 7
0
File: rpmio.c Progetto: akozumpl/rpm
int Fseek(FD_t fd, off_t offset, int whence)
{
    int rc = -1;

    if (fd != NULL) {
	fdio_seek_function_t _seek = FDIOVEC(fd, seek);

	fdstat_enter(fd, FDSTAT_SEEK);
	rc = (_seek ? _seek(fd, offset, whence) : -2);
	fdstat_exit(fd, FDSTAT_SEEK, rc);
    }

    DBGIO(fd, (stderr, "==>\tFseek(%p,%ld,%d) rc %lx %s\n",
	  fd, (long)offset, whence, (unsigned long)rc, fdbg(fd)));

    return rc;
}
Esempio n. 8
0
/** Does anything only if the file is opened, the operation is being buffered and the data
 *  count contained in the internal buffer is >0. If the last operation performed was
 *  storing data then the function tries to store a packet of data to the file. If the data
 *  has been read lately then only the file pointer will be repositioned. Also the internal buffer
 *  will be made empty. Function can throw an ch::exception in case of error.
 */
void file::flush()
{
	if (m_hFile && m_bBuffered && m_uiDataCount > 0)
	{
		if (m_bLastOperation)
		{
			// last operation - storing data
			_write_packet();
		}
		else
		{
			// last - reading data
			// set file pointer to position current-(m_uiDataCount-m_uiCurrentPos)
			_seek(-(longlong_t)(m_uiDataCount-m_uiCurrentPos), FS_CURRENT);
			m_uiCurrentPos=0;
			m_uiDataCount=0;
		}
	}
}
Esempio n. 9
0
/** Retrieves the current file pointer position (corrected by the content of
 *  internal buffer if buffered mode enabled).
 * \return Current file position.
 */
longlong_t file::getpos()
{
	// return corrected by internal members current file position
	return _seek(0, FS_CURRENT)-m_uiDataCount+m_uiCurrentPos;
}
Esempio n. 10
0
void main(void) {
    uint8_t inputProgramType;
    char *inputProgram;
    uint16_t inputProgramSize;
    ti_var_t programSlot;
    uint8_t selectedProgram, amountOfPrograms, res = VALID, type;
    unsigned int programDataSize, offset, totalSize;
    uint8_t beginList, amountOfProgramsToDisplay;
    uint8_t relativeSelectedProgram;
    const char ICEheader[] = {tii, 0};
    ti_var_t tempProg;
    char buf[30], *temp_name = "", var_name[9];
    sk_key_t key = 0;
    void *search_pos;
    bool didCompile;

    // Install hooks
    ti_CloseAll();
    if ((tempProg = ti_Open("ICEHOOKS", "r"))) {
        ti_SetArchiveStatus(true, tempProg);
        SetHooks(ti_GetDataPtr(tempProg));
    }
    
    // Enable lowercase
    asm("ld iy, 0D00080h");
    asm("set 3, (iy+024h)");

    // check if a program was used as input
    ti_CloseAll();
    ice.usingInputProgram = false;
    inputProgram = os_RclAns(&inputProgramType);
    if (inputProgram && inputProgramType == TI_STRING_TYPE && inputProgram[2] == tProg && (inputProgramSize = *(uint16_t*)inputProgram) < 10) {
        memset(var_name, 0, sizeof var_name);
        memcpy(var_name, inputProgram + 3, inputProgramSize - 1);
        programSlot = ti_OpenVar(var_name, "r", TI_PRGM_TYPE);
        if (programSlot) {
            ice.usingInputProgram = true;
        }
    }

    // Yay, GUI! :)
displayMainScreen:
    gfx_Begin();

    gfx_SetColor(189);
    gfx_FillRectangle_NoClip(0, 0, 320, 10);
    gfx_SetColor(0);
    gfx_SetTextFGColor(0);
    gfx_HorizLine_NoClip(0, 10, 320);
    gfx_PrintStringXY(infoStr, 12, 1);

    // Get all the programs that start with the [i] token
    selectedProgram = 0;
    didCompile = false;
    ti_CloseAll();

    if (ice.usingInputProgram) {
        goto compile_program;
    }

    search_pos = NULL;
    while ((temp_name = ti_DetectAny(&search_pos, ICEheader, &type)) != NULL) {
        if (type == TI_PRGM_TYPE || type == TI_PPRGM_TYPE) {
            // Hidden programs
            if ((uint8_t)(*temp_name) < 64) {
                *temp_name += 64;
            }

            // Save the program name
            inputPrograms[selectedProgram] = malloc(9);
            strcpy(inputPrograms[selectedProgram++], temp_name);
        }
        
        if (selectedProgram >= NUMBEROFPROGRAM) {
            break;
        }
    }

    amountOfPrograms = selectedProgram;
    beginList = 0;
    amountOfProgramsToDisplay = (amountOfPrograms > PROGRAMPERSCREEN ? PROGRAMPERSCREEN : amountOfPrograms);

    // Check if there are ICE programs
    if (!amountOfPrograms) {
        gfx_PrintStringXY("No programs found!", 10, 13);
        goto stop;
    }

    // Display all the sorted programs
    qsort(inputPrograms, amountOfPrograms, sizeof(char *), myCompare);
    displayProgramList(beginList, amountOfProgramsToDisplay);
    
    // Display buttons
    gfx_PrintStringXY("Build", 4, 232);
    printButton(1);
    gfx_PrintStringXY("Debug", 66, 232);
    printButton(65);
    gfx_PrintStringXY("Quit", 285, 232);
    printButton(279);
    gfx_SetColor(0);

    // Select a program
    selectedProgram = 1;
    relativeSelectedProgram = 1;
    while ((key = os_GetCSC()) != sk_Enter && key != sk_2nd && key != sk_Yequ && key != sk_Window) {
        uint8_t selectionOffset = relativeSelectedProgram * 10 + 3;

        gfx_PrintStringXY(">", 1, selectionOffset);

        if (key) {
            gfx_SetColor(255);
            gfx_FillRectangle_NoClip(1, selectionOffset, 8, 8);

            // Stop and quit
            if (key == sk_Clear || key == sk_Graph) {
                goto err;
            }

            // Select the next program
            if (key == sk_Down) {
                if (selectedProgram != amountOfPrograms) {
                    selectedProgram++;
                    relativeSelectedProgram++;
                    if (relativeSelectedProgram > PROGRAMPERSCREEN) {
                        clearProgramList();
                        relativeSelectedProgram--;
                        beginList++;
                        displayProgramList(beginList, amountOfProgramsToDisplay);
                    }
                } else {
                    clearProgramList();
                    selectedProgram = 1;
                    relativeSelectedProgram = 1;
                    beginList = 0;
                    displayProgramList(beginList, amountOfProgramsToDisplay);
                }
            }

            // Select the previous program
            if (key == sk_Up) {
                if (selectedProgram != 1) {
                    selectedProgram--;
                    relativeSelectedProgram--;
                    if(relativeSelectedProgram == 0) {
                        clearProgramList();
                        relativeSelectedProgram++;
                        beginList--;
                        displayProgramList(beginList, amountOfProgramsToDisplay);
                    }
                } else {
                    clearProgramList();
                    selectedProgram = amountOfPrograms;
                    relativeSelectedProgram = (amountOfPrograms > PROGRAMPERSCREEN ? PROGRAMPERSCREEN : amountOfPrograms);
                    beginList = (selectedProgram >= PROGRAMPERSCREEN ? selectedProgram - PROGRAMPERSCREEN : 0);
                    displayProgramList(beginList, amountOfProgramsToDisplay);
                }
            }
        }
    }
    
    // Set some vars
    strcpy(var_name, inputPrograms[selectedProgram - 1]);
    for (selectedProgram = 0; selectedProgram < amountOfPrograms; selectedProgram++) {
        free(inputPrograms[selectedProgram]);
    }

compile_program:

    // Erase screen
    gfx_SetColor(255);
    gfx_FillRectangle_NoClip(0, 11, 320, 210);
    gfx_FillRectangle_NoClip(0, 220, 270, 20);

    didCompile = true;
    memset(&ice, 0, sizeof ice);
    memset(&expr, 0, sizeof expr);
    memset(&reg, 0, sizeof reg);
    memset(&prescan, 0, sizeof prescan);
    memset(&debug, 0, sizeof debug);
    
    // Output debug appvar
    if (key == sk_Window) {
        ice.debug = true;
    }

    gfx_SetTextXY(1, 12);
    displayMessageLineScroll("Prescanning...");
    displayLoadingBarFrame();

    ice.inPrgm = _open(var_name);
    _seek(0, SEEK_END, ice.inPrgm);

    ice.programLength   = _tell(ice.inPrgm);
    ice.programData     = (uint8_t*)0xD52C00;
    ice.programPtr      = ice.programData;
    ice.programDataData = ice.programData + 0xFFFF;
    ice.programDataPtr  = ice.programDataData;
    
    // Get the name/icon/description
    _rewind(ice.inPrgm);
    if ((res = getNameIconDescription()) != VALID) {
        displayError(res);
        goto stop;
    }
    
    // Open debug appvar to store things to
    sprintf(buf, "%.5sDBG", ice.outName);
    debug.dbgPrgm = ti_Open(buf, "w");
    
    if (ice.debug) {
        if (!debug.dbgPrgm) {
            displayError(E_NO_DBG_FILE);
            goto stop;
        }
        
        // Write version bytes to debug appvar
        ti_PutC(DEBUG_VERSION_MAJOR, debug.dbgPrgm);
        ti_PutC(DEBUG_VERSION_MINOR, debug.dbgPrgm);
        
        // Write amount of programs to debug appvar
        ti_PutC(0, debug.dbgPrgm);
    } else if (debug.dbgPrgm) {
        ti_Delete(buf);
    }

    // Prescan the program and output the header
    preScanProgram();
    if ((res = parsePrescan()) != VALID) {
        displayError(res);
        goto stop;
    }
	
	if (prescan.amountOfVariablesUsed > 84) {
		gfx_SetTextFGColor(224);
		sprintf(buf, "Too much variables used: %d", prescan.amountOfVariablesUsed);
		displayMessageLineScroll(buf);
		didCompile = false;
		goto stop;
	}

    // Allow hidden programs from Cesium
    if (*var_name < 64) {
        *var_name += 64;
    }
    sprintf(buf, "Compiling program %s...", var_name);
    displayMessageLineScroll(buf);

    // Create or empty the output program if parsing succeeded
    if ((res = parseProgram()) == VALID) {
        unsigned int previousSize = 0;

        // Get the sizes of both stacks
        ice.programSize = (uintptr_t)ice.programPtr - (uintptr_t)ice.programData;
        programDataSize = (uintptr_t)ice.programDataData - (uintptr_t)ice.programDataPtr;

        // Change the pointers to the data as well, but first calculate the offset
        offset = PRGM_START + ice.programSize - (uintptr_t)ice.programDataPtr;
        while (ice.dataOffsetElements--) {
            unsigned int *tempDataOffsetStackPtr = ice.dataOffsetStack[ice.dataOffsetElements];

            *tempDataOffsetStackPtr += offset;
        }
        totalSize = ice.programSize + programDataSize + 3;

        // Export the program
        ice.outPrgm = _open(ice.outName);
        if (ice.outPrgm) {
            // This program already exists
            if ((uint8_t)ti_GetC(ice.outPrgm) != 0xEF || (uint8_t)ti_GetC(ice.outPrgm) != 0x7B) {
                gfx_SetTextFGColor(224);
                displayMessageLineScroll("Output program already exists!");
                displayMessageLineScroll("Delete program to continue.");
                didCompile = false;
                goto stop;
            }
            
            previousSize = ti_GetSize(ice.outPrgm);
            ti_Close(ice.outPrgm);
        }
        ice.outPrgm = _new(ice.outName);
        if (!ice.outPrgm) {
            displayMessageLineScroll("Failed to open output file");
            goto stop;
        }

        // Write ASM header
        ti_PutC(tExtTok, ice.outPrgm);
        ti_PutC(tAsm84CeCmp, ice.outPrgm);

        // Write ICE header to be recognized by Cesium
        ti_PutC(0x7F, ice.outPrgm);

        // Write the header, main program, and data to output :D
        ti_Write(ice.programData, ice.programSize, 1, ice.outPrgm);
        if (programDataSize) ti_Write(ice.programDataPtr, programDataSize, 1, ice.outPrgm);
        _rewind(ice.outPrgm);
        
        // Write final CRC to debug program, as well as the ending line of the first program and the amount of total programs
        if (ice.debug) {
            uint16_t CRC;
            
            CRC = GetCRC(ti_GetDataPtr(ice.outPrgm), ti_GetSize(ice.outPrgm));
            WriteWordToDebugProg(CRC);
            ti_Seek(3 + offsetof(debug_prog_t, endingLine), SEEK_SET, debug.dbgPrgm);
            WriteWordToDebugProg(debug.currentLine);
            ti_Seek(2, SEEK_SET, debug.dbgPrgm);
            ti_PutC(debug.amountOfPrograms + 1, debug.dbgPrgm);         // +1 because the main program starts at 0
        }

        // Yep, we are really done!
        gfx_SetTextFGColor(4);
        displayMessageLineScroll("Successfully compiled!");
        if (ice.debug) {
            displayMessageLineScroll("Successfully exported debug appvar");
        }

        // Skip line
        displayMessageLineScroll(" ");

        // Display the size
        gfx_SetTextFGColor(0);
        sprintf(buf, "Output size: %u bytes", totalSize);
        displayMessageLineScroll(buf);
        if (previousSize) {
            sprintf(buf, "Previous size: %u bytes", previousSize);
            displayMessageLineScroll(buf);
        }
        sprintf(buf, "Output program: %s", ice.outName);
        displayMessageLineScroll(buf);
    } else if (res != W_VALID) {
        displayError(res);
    }

stop:
    gfx_SetTextFGColor(0);
    if (didCompile) {
        if (res == VALID) {
            gfx_PrintStringXY("Run", 9, 232);
            printButton(1);
        } else if (!ti_IsArchived(ice.inPrgm)) {
            gfx_PrintStringXY("Goto", 222, 232);
            printButton(217);
        }
        gfx_PrintStringXY("Back", 70, 232);
        printButton(65);
        gfx_PrintStringXY("Quit", 285, 232);
        printButton(279);
    }
    while (!(key = os_GetCSC()));
err:
    gfx_End();

    if (key != sk_Graph && didCompile) {
        if (key == sk_Yequ && res == VALID) {
            RunPrgm(ice.outName);
        }
        if (key == sk_Window) {
            // Erase screen
            gfx_SetColor(255);
            gfx_FillRectangle_NoClip(0, 11, 320, 229);

            goto displayMainScreen;
        }
        if (key == sk_Trace && res != VALID && !ti_IsArchived(ice.inPrgm)) {
            char buf[9];
            
            ti_GetName(buf, ice.inPrgm);
            GotoEditor(buf, ti_Tell(ice.inPrgm) - 1);
        }
    }
    ti_CloseAll();
}
Esempio n. 11
0
	void StdioInterface::seekStep(FileOffsetT step){
		_seek(step, SEEK_CUR);
	}
Esempio n. 12
0
	void StdioInterface::seekEnd(){
		_seek(0, SEEK_END);
	}
Esempio n. 13
0
	void StdioInterface::seekBegin(){
		_seek(0, SEEK_SET);
	}
Esempio n. 14
0
	void StdioInterface::seek(FileOffsetT _pos){
		_seek(_pos, SEEK_SET);
	}
Esempio n. 15
0
/// Start seek mode downwards.
void TEA5767::seekDown(bool toNextSender) {
  _seek(false);
} // seekDown()
Esempio n. 16
0
/// Start seek mode upwards.
void TEA5767::seekUp(bool toNextSender) {
  DEBUG_FUNC0("seekUp");
  _seek(true);
} // seekUp()
Esempio n. 17
0
void speed()
{
        int keyboard = _open("/dev/keyboard", 0, 0);
        int stdin = _open("/dev/stdin", 0, 0);
        char ch;
        int fd = _open(active_proc->name, 0, 0);
        int size = _seek(fd, 0, SEEK_END);
        size++; //terminating '\0'
        _seek(fd, 0, SEEK_SET);
        char* str = _malloc(size);
        bzero(str, size);
        _read(fd, str, size);
        line *startline = _malloc(sizeof(line));
        startline->num_chars=0;
        startline->offset=0;
        startline->next = NULL;
        startline->prev = NULL;
        line * actualline = startline;

        int pos = 0;
        while (str[pos]!='\0') {
                _printf("%c", str[pos]);
                if(str[pos] == '\n' || str[pos] == '\t') {
                        NEXT_LINE
                } else {
                        actualline->num_chars++;
                }
                pos++;
                if(pos == size - 1) { //terminating \0
                        size*=2;
                        str = resize_buf(size, str);
                }
        }
        _close(fd);

        //flush stdin
        while (_read(stdin, &ch, sizeof(ch)) != 0) ;

        while (!keydown(ESCAPE, keyboard)) {
                if(pos == size - 1) { //terminating \0
                        size *= 2;
                        str = resize_buf(size, str);
                }
                ch = _fgetch(stdin);
                switch(ch){
                case '\a':
                        break;
                case '\b':
                        if(actualline == startline && startline->num_chars == 0) { //nothing to erase
                                break;
                        }
                        if(str[pos - 1]=='\n' || str[pos - 1]=='\t') { //erase '\n' or '\t'
                                PREV_LINE
                        } else { //erase 1 character
                                actualline->num_chars--;
                                _printf("%c", ch);
                        }
                        str[--pos] = '\0';
                        if (pos == size / 4 - 1) {
                                size /= 2;
                                str = resize_buf(size, str);
                        }
                        break;
                default:
                        _printf("%c", ch);
                        str[pos] = ch;
                        if(ch == '\n' || ch == '\t') {
                                NEXT_LINE
                        } else {
                                actualline->num_chars++;
                        }
                        pos++;
                }
        }

        //flush stdin
        while (_read(stdin, &ch, sizeof(ch)) != 0) ;
        //DUMP_LINES
        _unlink(active_proc->name);
        //        fd = _open(active_proc->name, 0, 0);
        //        int fsize = _seek(fd, 0, SEEK_END);
        //        _close(fd);
        //        fd = _open(active_proc->name, 0, 0);
        //        char* nullstring = _malloc(fsize);
        //        bzero(nullstring, fsize);
        //        _free(nullstring);
        //        _write(fd, nullstring, fsize);
        //        _close(fd);

        fd = _open(active_proc->name, O_CREAT, 0);
        _write(fd, str, strlen(str));
        for(line *temp = startline; temp != NULL; temp = temp->next) {
                _free(temp);
        }
        _free(str);
        _close(keyboard);
        _close(stdin);
        _close(fd);
        _exit(0);
}