int main(int argc, char *argv[]){ ///////////////PARAMETER ERROR CHECKER///////////////// //This is to check to make sure that the user //inputs the correct number of parameters. if(argc !=2){ err_sys("Invalid Number of Parameters. Try Again"); } //////////////End of Parameter Error Checker/////////// int num = atoi(argv[1]); storage = arrayalloc(num); directory = diralloc(num); diroffset = 0; int fd = openfile(); int storagefd = openstorage(); int endofile = 0; int count = 0; char * chunk = (char) 0; while(endofile !=-1){ endofile = fillbuffer(&fd); count++; fprintf(stderr,"Here: %d times.\n",count); processbuffer(&fd, &storagefd, endofile); } fprintf(stderr,"\nNumber of Records: %d.\n",numorecords); close(fd); close(storagefd); return 0; }
virtual void blitRect(int x, int y, int width, int height) { SkASSERT(width > 0 && height > 0); SK_RESTRICT SkPMColor* dst = fDevice->getAddr32(x, y); const SK_RESTRICT SkPMColor16* src = fSource->getAddr16(x - fLeft, y - fTop); unsigned dstRB = fDevice->rowBytes(); unsigned srcRB = fSource->rowBytes(); SK_RESTRICT SkPMColor* buffer = fBuffer; SkColorFilter* colorFilter = fColorFilter; SkXfermode* xfermode = fXfermode; do { fillbuffer(buffer, src, width); if (NULL != colorFilter) { colorFilter->filterSpan(buffer, width, buffer); } if (NULL != xfermode) { xfermode->xfer32(dst, buffer, width, NULL); } else { fProc32(dst, buffer, width, fAlpha); } dst = (SK_RESTRICT SkPMColor*)((char*)dst + dstRB); src = (const SK_RESTRICT SkPMColor16*)((const char*)src + srcRB); } while (--height != 0); }
void newframe(void) { #ifndef ARM Uint5 t; if (synchvid) { for (;curtime<ftime;curtime+=17094) { /* 17094 = ticks in a refresh */ #ifdef _WINDOWS do_windows_events(); #endif fillbuffer(); gretrace(); checkkeyb(); } curtime-=ftime; fillbuffer(); } else { do { #ifdef _WINDOWS do_windows_events(); #endif fillbuffer(); /* Idle time */ t=gethrt(); checkkeyb(); } while (curtime+ftime>t && t>curtime); curtime=t; } #else for (;curtime<ftime;curtime+=15000) { fillbuffer(); gretrace(); soundint(); checkkeyb(); } curtime-=ftime; #endif #ifdef INTDRF frame++; #endif }
uint64_t BinaryReader::next() { if(buffer64count == 0){ fillbuffer(); } buffer64count--; return buffer64[buffer64count]; }
/** utilize tq[1024] to fill the buffer send,once index->1000, or EOF is detected */ void to_transport_layerc(packet p){ fillbuffer(p); app("Client","abc"); }
void drawbackg(int16_t l) { int16_t x,y; for (y=14;y<200;y+=4) { fillbuffer(); for (x=0;x<320;x+=20) drawmiscspr(x,y,93+l,5,4); } }
void skipWhiteSpace(Lexer* l) { while (isblank(_BC)) { if (_BC == '\n') { l->line_num += 1; } l->bufp++; while (EOB) { if (fillbuffer(l) == -1) { return; } } } }
void skipComment(Lexer* l) { if(_BC == '"') { do { if (_BC == '\n') { l->line_num += 1; } l->bufp++; while (EOB) { if (fillbuffer(l) == -1) { return; } } } while(_BC != '"'); l->bufp++; } }
static void startft(Tox *tox, uint32_t fid, uint8_t *path, uint8_t *name, uint16_t name_length) { debug("Sending: %s\n", path); FILE *file = fopen((char*)path, "rb"); if(!file) { return; } uint64_t size; fseek(file, 0, SEEK_END); size = ftell(file); fseek(file, 0, SEEK_SET); int filenumber = tox_new_file_sender(tox, fid, size, name, name_length); if(filenumber != -1) { FILE_T *ft = &friend[fid].outgoing[filenumber]; memset(ft, 0, sizeof(FILE)); *file_tend++ = ft; ft->fid = fid; ft->filenumber = filenumber; name_length = name_length > sizeof(ft->name) ? sizeof(ft->name) : name_length; ft->name_length = name_length; ft->status = FT_PENDING; ft->sendsize = tox_file_data_size(tox, fid); memcpy(ft->name, name, name_length); ft->total = size; ft->path = (uint8_t*)strdup((char*)path); ft->data = file; ft->buffer = malloc(ft->sendsize); fillbuffer(ft); postmessage(FRIEND_FILE_OUT_NEW, fid, filenumber, NULL); } else {
void lexString(Lexer* l) { l->sym = STString; l->symc = 0; char* t = l->text; l->bufp++; while(_BC != '\'') { if (_BC == '\n') { l->line_num += 1; } lexStringChar(l, &t); while (EOB) { if (fillbuffer(l) == -1) { return; } } } *t = 0; l->bufp++; }
void fillbuffers(uint8_t pattern){ fillbuffer(pattern, inbuf); fillbuffer(pattern, outbuf); }
void cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){ (void)argc; (void)argv; uint32_t i = 0; chprintf(chp, "Trying to connect SDIO... "); chThdSleepMilliseconds(100); if (!sdcConnect(&SDCD1)) { chprintf(chp, "OK\r\n"); chprintf(chp, "*** Card CSD content is: "); chprintf(chp, "%X %X %X %X \r\n", (&SDCD1)->csd[3], (&SDCD1)->csd[2], (&SDCD1)->csd[1], (&SDCD1)->csd[0]); chprintf(chp, "Single aligned read..."); chThdSleepMilliseconds(100); if (sdcRead(&SDCD1, 0, inbuf, 1)) chSysHalt(); chprintf(chp, " OK\r\n"); chThdSleepMilliseconds(100); chprintf(chp, "Single unaligned read..."); chThdSleepMilliseconds(100); if (sdcRead(&SDCD1, 0, inbuf + 1, 1)) chSysHalt(); if (sdcRead(&SDCD1, 0, inbuf + 2, 1)) chSysHalt(); if (sdcRead(&SDCD1, 0, inbuf + 3, 1)) chSysHalt(); chprintf(chp, " OK\r\n"); chThdSleepMilliseconds(100); chprintf(chp, "Multiple aligned reads..."); chThdSleepMilliseconds(100); fillbuffers(0x55); /* fill reference buffer from SD card */ if (sdcRead(&SDCD1, 0, inbuf, SDC_BURST_SIZE)) chSysHalt(); for (i=0; i<1000; i++){ if (sdcRead(&SDCD1, 0, outbuf, SDC_BURST_SIZE)) chSysHalt(); if (memcmp(inbuf, outbuf, SDC_BURST_SIZE * MMCSD_BLOCK_SIZE) != 0) chSysHalt(); } chprintf(chp, " OK\r\n"); chThdSleepMilliseconds(100); chprintf(chp, "Multiple unaligned reads..."); chThdSleepMilliseconds(100); fillbuffers(0x55); /* fill reference buffer from SD card */ if (sdcRead(&SDCD1, 0, inbuf + 1, SDC_BURST_SIZE)) chSysHalt(); for (i=0; i<1000; i++){ if (sdcRead(&SDCD1, 0, outbuf + 1, SDC_BURST_SIZE)) chSysHalt(); if (memcmp(inbuf, outbuf, SDC_BURST_SIZE * MMCSD_BLOCK_SIZE) != 0) chSysHalt(); } chprintf(chp, " OK\r\n"); chThdSleepMilliseconds(100); #if SDC_DATA_DESTRUCTIVE_TEST chprintf(chp, "Single aligned write..."); chThdSleepMilliseconds(100); fillbuffer(0xAA, inbuf); if (sdcWrite(&SDCD1, 0, inbuf, 1)) chSysHalt(); fillbuffer(0, outbuf); if (sdcRead(&SDCD1, 0, outbuf, 1)) chSysHalt(); if (memcmp(inbuf, outbuf, MMCSD_BLOCK_SIZE) != 0) chSysHalt(); chprintf(chp, " OK\r\n"); chprintf(chp, "Single unaligned write..."); chThdSleepMilliseconds(100); fillbuffer(0xFF, inbuf); if (sdcWrite(&SDCD1, 0, inbuf+1, 1)) chSysHalt(); fillbuffer(0, outbuf); if (sdcRead(&SDCD1, 0, outbuf+1, 1)) chSysHalt(); if (memcmp(inbuf+1, outbuf+1, MMCSD_BLOCK_SIZE) != 0) chSysHalt(); chprintf(chp, " OK\r\n"); chprintf(chp, "Running badblocks at 0x10000 offset..."); chThdSleepMilliseconds(100); if(badblocks(0x10000, 0x11000, SDC_BURST_SIZE, 0xAA)) chSysHalt(); chprintf(chp, " OK\r\n"); #endif /* !SDC_DATA_DESTRUCTIVE_TEST */ /** * Now perform some FS tests. */ FRESULT err; uint32_t clusters; FATFS *fsp; FIL FileObject; uint32_t bytes_written; uint32_t bytes_read; FILINFO filinfo; uint8_t teststring[] = {"This is test file\r\n"}; chprintf(chp, "Register working area for filesystem... "); chThdSleepMilliseconds(100); err = f_mount(0, &SDC_FS); if (err != FR_OK){ chSysHalt(); } else{ fs_ready = TRUE; chprintf(chp, "OK\r\n"); } #if SDC_DATA_DESTRUCTIVE_TEST chprintf(chp, "Formatting... "); chThdSleepMilliseconds(100); err = f_mkfs (0,0,0); if (err != FR_OK){ chSysHalt(); } else{ chprintf(chp, "OK\r\n"); } #endif /* SDC_DATA_DESTRUCTIVE_TEST */ chprintf(chp, "Mount filesystem... "); chThdSleepMilliseconds(100); err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { chSysHalt(); } chprintf(chp, "OK\r\n"); chprintf(chp, "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n", clusters, (uint32_t)SDC_FS.csize, clusters * (uint32_t)SDC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE); chprintf(chp, "Create file \"chtest.txt\"... "); chThdSleepMilliseconds(100); err = f_open(&FileObject, "0:chtest.txt", FA_WRITE | FA_OPEN_ALWAYS); if (err != FR_OK) { chSysHalt(); } chprintf(chp, "OK\r\n"); chprintf(chp, "Write some data in it... "); chThdSleepMilliseconds(100); err = f_write(&FileObject, teststring, sizeof(teststring), (void *)&bytes_written); if (err != FR_OK) { chSysHalt(); } else chprintf(chp, "OK\r\n"); chprintf(chp, "Close file \"chtest.txt\"... "); err = f_close(&FileObject); if (err != FR_OK) { chSysHalt(); } else chprintf(chp, "OK\r\n"); chprintf(chp, "Check file size \"chtest.txt\"... "); err = f_stat("0:chtest.txt", &filinfo); chThdSleepMilliseconds(100); if (err != FR_OK) { chSysHalt(); } else{ if (filinfo.fsize == sizeof(teststring)) chprintf(chp, "OK\r\n"); else chSysHalt(); } chprintf(chp, "Check file content \"chtest.txt\"... "); err = f_open(&FileObject, "0:chtest.txt", FA_READ | FA_OPEN_EXISTING); chThdSleepMilliseconds(100); if (err != FR_OK) { chSysHalt(); } uint8_t buf[sizeof(teststring)]; err = f_read(&FileObject, buf, sizeof(teststring), (void *)&bytes_read); if (err != FR_OK) { chSysHalt(); } else{ if (memcmp(teststring, buf, sizeof(teststring)) != 0){ chSysHalt(); } else{ chprintf(chp, "OK\r\n"); } } chprintf(chp, "Umount filesystem... "); f_mount(0, NULL); chprintf(chp, "OK\r\n"); chprintf(chp, "Disconnecting from SDIO..."); chThdSleepMilliseconds(100); if (sdcDisconnect(&SDCD1)) chSysHalt(); chprintf(chp, " OK\r\n"); chprintf(chp, "------------------------------------------------------\r\n"); chprintf(chp, "All tests passed successfully.\r\n"); chThdSleepMilliseconds(100); } else{ chSysHalt(); } }
Symbol Lexer_get_sym(Lexer* l) { if (l->peekDone) { l->peekDone = false; l->sym = l->nextSym; l->symc = l->nextSymc; strcpy(l->text, l->nextText); return l->sym; } do { if (EOB) fillbuffer(l); skipWhiteSpace(l); skipComment(l); } while((EOB || isblank(_BC) || _BC == '"') && l->infile); if(_BC == '\'') { lexString(l); } else _MATCH('[', NewBlock) else _MATCH(']', EndBlock) else if(_BC == ':') { if(l->buf[l->bufp+1] == '=') { l->bufp += 2; l->sym = Assign; l->symc = 0; sprintf(l->text, ":="); } else { l->bufp++; l->sym = Colon; l->symc = ':'; sprintf(l->text, ":"); } } else _MATCH('(', NewTerm) else _MATCH(')', EndTerm) else _MATCH('#', Pound) else _MATCH('^', Exit) else _MATCH('.', Period) else if(_BC == '-') { if(!strncmp(l->buf + l->bufp, SEPARATOR, strlen(SEPARATOR))) { char* t = l->text; while(_BC == '-') *t++ = l->buf[l->bufp++]; *t = 0; l->sym = Separator; } else { lexOperator(l); } } else if(_ISOP(_BC)) { lexOperator(l); } else if(!strncmp(l->buf + l->bufp, PRIMITIVE, strlen(PRIMITIVE))) { l->bufp += strlen(PRIMITIVE); l->sym = Primitive; l->symc = 0; sprintf(l->text, PRIMITIVE); } else if(isalpha(_BC)) { char* t = l->text; l->symc = 0; while(isalpha(_BC) || isdigit(_BC) || _BC == '_') *t++ = l->buf[l->bufp++]; l->sym = Identifier; if(l->buf[l->bufp] == ':') { l->sym = Keyword; l->bufp++; *t++ = ':'; if(isalpha(_BC)) { l->sym = KeywordSequence; while(isalpha(_BC) || _BC == ':') *t++ = l->buf[l->bufp++]; } } *t = 0; } else if(isdigit(_BC)) { lexNumber(l); } else { l->sym = NONE; l->symc = _BC; sprintf(l->text, "%c", _BC); } return l->sym; }
/* Counts number of frames. */ int count(int frames, int out) { unsigned int count = 0; int n, pos, offset; int32_t flen = 0; /* * continue is used for each frame * break is used when needing to refill the buffer * I did this mostly for personal amusement. */ pos = 0; offset = 0; while ((n = fillbuffer(offset)) > 0) { n += offset; do { offset = 0; if (flen == 0) { if (n - pos >= 12) { ttyheader(inbuf+pos, &flen); flen += 12; } else { /* ends in middle of flen header*/ offset = n - pos; memmove(inbuf, inbuf+pos, offset); break; } } if (n - pos >= flen) { if (out) memcpy(outbuf+pos, inbuf+pos, flen); pos += flen; flen = 0; count++; if (frames != 0 && count == frames) { lseek(infd, pos - n, SEEK_CUR); goto end; } continue; } else { if (out) memcpy(outbuf+pos, inbuf+pos, n - pos); flen -= (n - pos); pos = n; break; } } while (1); if (out) flushbuffer(pos); pos = 0; } end: if (out) flushbuffer(pos); return count; }
void cmd_sdiotest(void) { uint32_t i = 0; FRESULT err = 0; bool format = false; chThdSleepMilliseconds(100); if (!sdioConnect ()) { sdioDebug (" FAIL\r\n "); return; } if (TRUE) { sdioDebug ("OK\r\n"); sdioDebug ("*** Card CSD content is: "); sdioDebug ("%X %X %X %X \r\n", (&SDCD1)->csd[3], (&SDCD1)->csd[2], (&SDCD1)->csd[1], (&SDCD1)->csd[0]); sdioDebug ("capacity = %d sectors of 512 bytes = %d Mo\r\n", SDCD1.capacity, SDCD1.capacity / 2048); sdioDebug ("Single aligned read..."); chThdSleepMilliseconds(100); if (sdcRead(&SDCD1, 0, inbuf, 1)) goto error; sdioDebug (" OK\r\n"); chThdSleepMilliseconds(100); sdioDebug ("Single unaligned read..."); chThdSleepMilliseconds(100); if (sdcRead(&SDCD1, 0, inbuf + 1, 1)) goto error; if (sdcRead(&SDCD1, 0, inbuf + 2, 1)) goto error; if (sdcRead(&SDCD1, 0, inbuf + 3, 1)) goto error; sdioDebug (" OK\r\n"); chThdSleepMilliseconds(100); sdioDebug ("Multiple aligned reads..."); chThdSleepMilliseconds(100); fillbuffers(0x55); /* fill reference buffer from SD card */ if (sdcRead(&SDCD1, 0, inbuf, SDC_BURST_SIZE)) goto error; for (i=0; i<1000; i++){ if (sdcRead(&SDCD1, 0, outbuf, SDC_BURST_SIZE)) goto error; if (memcmp(inbuf, outbuf, SDC_BURST_SIZE * MMCSD_BLOCK_SIZE) != 0) goto error; } sdioDebug (" OK\r\n"); chThdSleepMilliseconds(100); sdioDebug ("Multiple unaligned reads..."); chThdSleepMilliseconds(100); fillbuffers(0x55); /* fill reference buffer from SD card */ if (sdcRead(&SDCD1, 0, inbuf + 1, SDC_BURST_SIZE)) goto error; for (i=0; i<1000; i++){ if (sdcRead(&SDCD1, 0, outbuf + 1, SDC_BURST_SIZE)) goto error; if (memcmp(inbuf, outbuf, SDC_BURST_SIZE * MMCSD_BLOCK_SIZE) != 0) goto error; } sdioDebug (" OK\r\n"); chThdSleepMilliseconds(100); #if SDC_DATA_DESTRUCTIVE_TEST if (format) { sdioDebug ("Single aligned write..."); chThdSleepMilliseconds(100); fillbuffer(0xAA, inbuf); if (sdcWrite(&SDCD1, 0, inbuf, 1)) goto error; fillbuffer(0, outbuf); if (sdcRead(&SDCD1, 0, outbuf, 1)) goto error; if (memcmp(inbuf, outbuf, MMCSD_BLOCK_SIZE) != 0) goto error; sdioDebug (" OK\r\n"); sdioDebug ("Running badblocks at 0x10000 offset..."); chThdSleepMilliseconds(100); if(badblocks(0x10000, 0x11000, SDC_BURST_SIZE, 0xAA)) goto error; sdioDebug (" OK\r\n"); } else { } #endif /* !SDC_DATA_DESTRUCTIVE_TEST */ /** * Now perform some FS tests. */ DWORD clusters=0; FATFS *fsp=NULL; FIL FileObject; uint32_t bytes_written=0; uint32_t bytes_read=0; FILINFO fno ; #if _USE_LFN char lfn[_MAX_LFN + 1]; fno.lfname = lfn; fno.lfsize = sizeof lfn; #endif const uint8_t teststring[] = {"This is test file\r\n"} ; /* FS object.*/ static FATFS SDC_FS; #if SDC_DATA_DESTRUCTIVE_TEST if (format) { sdioDebug ("Formatting... "); chThdSleepMilliseconds(100); sdioDebug ("Register working area for filesystem... "); chThdSleepMilliseconds(100); err = f_mount(0, &SDC_FS); if (err != FR_OK){ goto error; } else{ sdioDebug ("OK\r\n"); } } if (format) { sdioDebug ("f_mkfs starting ... "); chThdSleepMilliseconds(100); err = f_mkfs (0,0,0); if (err != FR_OK){ goto error; } else { sdioDebug ("OK\r\n"); } } #endif /* SDC_DATA_DESTRUCTIVE_TEST */ sdioDebug ("get free space on filesystem... "); chThdSleepMilliseconds(100); err = f_getfree(NULL, &clusters, &fsp); if (err != FR_OK) goto error; sdioDebug ("OK\r\n"); sdioDebug ("FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n", clusters, (uint32_t)SDC_FS.csize, clusters * (uint32_t)SDC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE); sdioDebug ("Create file \"chtest.txt\"... "); chThdSleepMilliseconds(100); err = f_open(&FileObject, "chtest.txt", FA_WRITE | FA_OPEN_ALWAYS); if (err != FR_OK) { goto error; } sdioDebug ("OK\r\n"); sdioDebug ("Write some data in it... "); chThdSleepMilliseconds(100); err = f_write(&FileObject, teststring, sizeof(teststring), (void *)&bytes_written); if (err != FR_OK) { goto error; } else sdioDebug ("OK\r\n"); sdioDebug ("Close file \"chtest.txt\"... "); err = f_close(&FileObject); if (err != FR_OK) { goto error; } else sdioDebug ("OK\r\n"); sdioDebug ("Check file size \"chtest.txt\"... "); chThdSleepMilliseconds(10); err = f_stat("chtest.txt", &fno); chThdSleepMilliseconds(100); if (err != FR_OK) { goto error; } else { if (fno.fsize == sizeof(teststring)) { sdioDebug ("OK\r\n"); } else goto error; } sdioDebug ("Check file content \"chtest.txt\"... "); err = f_open(&FileObject, "chtest.txt", FA_READ | FA_OPEN_EXISTING); chThdSleepMilliseconds(100); if (err != FR_OK) { goto error; } uint8_t buf[sizeof(teststring)]; err = f_read(&FileObject, buf, sizeof(teststring), (void *)&bytes_read); if (err != FR_OK) { goto error; } else { if (memcmp(teststring, buf, sizeof(teststring)) != 0){ goto error; } else { sdioDebug ("OK\r\n"); } } { FILINFO fno; DIR dir; // char *fn; /* This function is assuming non-Unicode cfg. */ #if _USE_LFN char lfn[_MAX_LFN + 1]; fno.lfname = lfn; fno.lfsize = sizeof lfn; #endif const char *path = ""; FRESULT res =0; res = f_opendir(&dir, path); /* Open the directory */ if (res == FR_OK) { for (;;) { res = f_readdir(&dir, &fno); /* Read a directory item */ if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ if (fno.fname[0] == '.') continue; /* Ignore dot entry */ #if _USE_LFN // fn = fno.lfname; #else // fn = fno.fname; #endif /* It is a file. */ //chprintf(chp, "readdir %s/%s\r\n", path, fn); } } } sdioDebug ("Umount filesystem... "); f_mount(0, NULL); sdioDebug ("OK\r\n"); sdioDebug ("Disconnecting from SDIO..."); chThdSleepMilliseconds(100); if (!sdioDisconnect()) goto error; sdioDebug (" OK\r\n"); sdioDebug ("------------------------------------------------------\r\n"); sdioDebug ("All tests passed successfully.\r\n"); chThdSleepMilliseconds(100); sdioDisconnect(); return; } error: sdioDebug ("SDC error [%d] occurs\r\n", err); sdioDisconnect(); }