void process_text(char *in_buffer) { uint8_t last_pos = *ringbuffer_pos; char buffer[64] = {0}; while(1) { uint8_t new_pos; while(last_pos == (new_pos = *ringbuffer_pos)) { uint64_t info = wait_for_interrupt(); if(INT_ID(info) == CLOCK_ID) { toggle_pos(cursor_pos, normal, inverted); } } while(last_pos != new_pos) { uint8_t c; c = keyboard_ringbuffer[last_pos]; process_char(c,1); last_pos = ((last_pos + 1) % RINGBUFFER_SIZE); if(c == '\r') { strcpy(in_buffer, input); process_char('\r',0); input_size = 0; memset(input,0,sizeof(input)); goto done; } } } done: return; }
int main(int argc,char **argv) { if (argc>2&&argv[2]) start_addr=strtoll(argv[2],NULL,16); if (argc>3&&argv[3]) end_addr=strtoll(argv[3],NULL,16); printf("Dumping memory from $%x to $%x\n",start_addr,end_addr); errno=0; fd=open(argv[1],O_RDWR); perror("A"); if (fd==-1) perror("open"); perror("B"); fcntl(fd,F_SETFL,fcntl(fd, F_GETFL, NULL)|O_NONBLOCK); perror("C"); struct termios t; if (cfsetospeed(&t, B230400)) perror("Failed to set output baud rate"); perror("D"); if (cfsetispeed(&t, B230400)) perror("Failed to set input baud rate"); perror("E"); t.c_cflag &= ~PARENB; t.c_cflag &= ~CSTOPB; t.c_cflag &= ~CSIZE; t.c_cflag &= ~CRTSCTS; t.c_cflag |= CS8 | CLOCAL; t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOE); t.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR | INPCK | ISTRIP | IXON | IXOFF | IXANY | PARMRK); t.c_oflag &= ~OPOST; if (tcsetattr(fd, TCSANOW, &t)) perror("Failed to set terminal parameters"); perror("F"); unsigned long long last_check = gettime_ms(); while(1) { int b; char read_buff[1024]; switch(state) { case 0: case 99: errno=0; b=read(fd,read_buff,1024); if (b>0) { int i; for(i=0;i<b;i++) { process_char(read_buff[i],1); } } else { usleep(1000); } if (gettime_ms()>last_check) { if (state==99) printf("sending M command to sync.\n"); sprintf(filename,"M%x\r",start_addr); slow_write(fd,filename,strlen(filename)); last_check=gettime_ms()+50; } break; } } return 0; }
void process_input (SLOT *sp) { unsigned char buf[MAXBUF]; int i, len; if (sp->flags.die) return; cur_slot = sp; len = read (cur_slot->fd, (char *)buf, MAXBUF); if (len > 0) { for (i = 0; i < len; i++) process_char (buf[i]); } else { transmit (cur_slot); if (!sp->flags.die) { if (cur_slot->acct.chan < NUMCHANNELS) { /* protect against people whose logins time our or something before they're fully "on" the system */ remove_from_channel (cur_slot, cur_slot->acct.chan); remove_from_channel (cur_slot, MAINLIST); } if (cur_slot->acct.chan && cur_slot->flags.on) { paabout (cur_slot, DISCONNECTED); cur_slot->acct.last_logout = time(NULL); } inactivate_slot (cur_slot, 0); } } }
int main(int argc,char **argv) { search_path=argv[2]; fd=open(argv[1],O_RDWR); if (fd==-1) perror("open"); if (fcntl(fd,F_SETFL,fcntl(fd, F_GETFL, NULL)|O_NONBLOCK)) perror("fcntl"); struct termios t; if (cfsetospeed(&t, B230400)) perror("Failed to set output baud rate"); if (cfsetispeed(&t, B230400)) perror("Failed to set input baud rate"); t.c_cflag &= ~PARENB; t.c_cflag &= ~CSTOPB; t.c_cflag &= ~CSIZE; t.c_cflag |= CS8; t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOE); t.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR | INPCK | ISTRIP | IXON | IXOFF | IXANY | PARMRK); t.c_oflag &= ~OPOST; if (tcsetattr(fd, TCSANOW, &t)) perror("Failed to set terminal parameters"); // Send ^U r <return> to print registers and get into a known state. usleep(20000); slow_write(fd,"\r",1); usleep(50000); slow_write(fd,"r\r",2); unsigned long long last_check = gettime_ms(); while(1) { int b; char read_buff[1024]; b=read(fd,read_buff,1024); if (b>0) { int i; for(i=0;i<b;i++) { process_char(read_buff[i],1); } } else usleep(10000); if (gettime_ms()>last_check) { if (!toggle) { char cmd[1024]; // set debug coordinates debug_x++; debug_x&=0xfff; sprintf(cmd,"sffd30fc %02x %02x %02x %02x\r", debug_x&0xff,debug_x>>8,debug_y&0xff,debug_y>>8); slow_write(fd,cmd,strlen(cmd)); } else { // read debug registers slow_write(fd,"mffd30f0\r",9); } toggle^=1; // Allow 2 frames before advancing debug point last_check=gettime_ms()+(1000/60)*2; }
void print_number(int n) { char buffer[10]; int size=0,i; while(n > 0) { buffer[size++] = n%10; n/=10; } for(i=size-1;i>=0;i--) { process_char('0' + buffer[i],0); } }
int process_waiting(int fd) { unsigned char read_buff[1024]; int b=read(fd,read_buff,1024); while (b>0) { int i; for(i=0;i<b;i++) { process_char(read_buff[i],1); } b=read(fd,read_buff,1024); } return 0; }
void __attribute__((interrupt, no_auto_psv)) _U2RXInterrupt(void) { /* Read the receive receive_buffer till no more characters can be read */ while(U2STAbits.URXDA) process_char(uart2, U2RXREG); if(U2STAbits.OERR) U2STAbits.OERR = 0; if(U2STAbits.FERR) U2STAbits.FERR = 0; IFS1bits.U2RXIF = 0; }
void printf_formattert::print(std::ostream &out) { format_pos=0; next_operand=operands.begin(); try { while(!eol()) process_char(out); } catch(eol_exceptiont) { } }
void process_text(char *in_buffer, int remaining) { uint8_t last_pos = *ringbuffer_pos; char buffer[64] = {0}; if(remaining > 0) { //Dammit there's no standard library so I can't use sprintf :( strcpy(buffer,"You have guesses remaining\r>"); if(remaining >= 10) { buffer[9] = '0' + (remaining/10); } buffer[10] = '0' + (remaining%10); process_string(buffer); } else { process_string("You ran out, I picked a new number\r>"); } while(1) { uint8_t new_pos; while(last_pos == (new_pos = *ringbuffer_pos)) { uint64_t info = wait_for_interrupt(); if(INT_ID(info) == CLOCK_ID) { toggle_pos(cursor_pos, normal, inverted); } } while(last_pos != new_pos) { uint8_t c; c = keyboard_ringbuffer[last_pos]; process_char(c,1); last_pos = ((last_pos + 1) % RINGBUFFER_SIZE); if(c == '\r') { memcpy(in_buffer, input, input_size); input_size = 0; memset(input,0,sizeof(input)); goto done; } } } done: return; }
int main(int argc, char * argv[]) { char input_buffer[BUFFER_SIZE]; int i, ifd = 0, ofd = 1; for(i = 1; i < argc; i++) { if ( (!strcmp(argv[i], "-h")) || (!strcmp(argv[i], "--help")) ) { fprintf(stderr, "Usage:\n\t%s [-h | --help] [-i | --indent] [-f[nn]]\n" "\t\t[if=input] [of=output]\n", argv[0]); fprintf(stderr, "\n"); fprintf(stderr, "\t--help\tPrint this help message.\n"); fprintf(stderr, "\t--indent\tIndent messages and continued lines.\n"); fprintf(stderr, "\t-f[nn]\tFold lines that are over nn (default 80) characters.\n" "\t\tImplies --indent.\n" ); fprintf(stderr, "\tif=\tSpecify input file name.\n"); fprintf(stderr, "\tof=\tSpecify output file name.\n"); return 0; } else if ( (strcmp(argv[i], "-i") == 0) || (strcmp(argv[i], "--indent") == 0) ) { indent = 1; } else if (!strncmp(argv[i], "if=", 3)) { ifd = open(&argv[i][3], O_RDONLY); if (ifd == -1) { fprintf(stderr, "%s: %s\n", &argv[i][3], strerror(errno)); return 1; } } else if (!strncmp(argv[i], "of=", 3)) { ofd = open(&argv[i][3], O_WRONLY | O_CREAT, 0644); if (ofd == -1) { fprintf(stderr, "%s: %s\n", &argv[i][3], strerror(errno)); return 1; } } else if (!strncmp(argv[i], "-f", 2)) { fold = 1; indent = 1; if (strlen(argv[i]) > 2) { char* endptr; width = strtol(argv[i] + strlen("-f"), &endptr, 10); if (endptr != argv[i] + strlen(argv[i])) { fprintf(stderr, "Badly formatted width: '%s'\n", argv[i]); return 1; } else if (width < 9) { fprintf(stderr, "Width value too small: %d\n", width); return 1; } } } else { fprintf(stderr, "Unknown option: %s\n", argv[i]); return 1; } } position = 0; line_tabbed = 0; i = read(ifd, input_buffer, BUFFER_SIZE); state = indent ? StartLine : InMessage; while(i && i != -1) { int j; for(j = 0; j != i; j++) process_char(input_buffer[j], ofd); i = read(ifd, input_buffer, BUFFER_SIZE); } flush_buffer(ofd); return 0; }
date_time_t to_date_time(const pstring& str) { date_time_t ret; int dash_count = 0, t_count = 0, colon_count = 0; const char* p = str.get(); const char* p_end = p + str.size(); const char* digit = p; size_t digit_len = 0; bool valid = true; for (; p != p_end && valid; ++p) { switch (*p) { case '-': { if (t_count || colon_count || !digit) { // Invalid date-time value. All dashes must occur before // any of 'T' and ':' occur. valid = false; break; } switch (dash_count) { case 0: // Flush year. flush_int(ret.year, digit, digit_len); break; case 1: // Flush month. flush_int(ret.month, digit, digit_len); break; default: valid = false; } ++dash_count; } break; case 'T': { if (t_count || dash_count != 2 || !digit) { // Invalid date-time value. valid = false; break; } // Flush day. ret.day = strtol(digit, NULL, 10); digit = NULL; digit_len = 0; ++t_count; } break; case ':': { if (!t_count || !digit) { // Invalid date-time value. valid = false; break; } switch (colon_count) { case 0: // Flush hour. flush_int(ret.hour, digit, digit_len); break; case 1: // Flush minute. flush_int(ret.minute, digit, digit_len); break; default: valid = false; } ++colon_count; } break; default: { if (t_count) { // Time element. switch (colon_count) { case 0: // Hour process_char(p, digit, digit_len); break; case 1: // Minute process_char(p, digit, digit_len); break; case 2: // Second process_char(p, digit, digit_len); break; default: valid = false; } } else { // Date element. switch (dash_count) { case 0: // Year process_char(p, digit, digit_len); break; case 1: // Month process_char(p, digit, digit_len); break; case 2: // Day process_char(p, digit, digit_len); break; default: valid = false; } } } } } if (!valid || !digit) return ret; if (t_count) { // Flush second. ret.second = strtod(digit, NULL); } else { // Flush day. ret.day = strtol(digit, NULL, 10); } return ret; }
void Settings_ProcessBuffer(uint8 buf[], uint8 buflen){ uint8 i = 0; for(i=0;i<buflen;i++){ process_char(buf[i]); } }
void Sim900::parse(char c) { process_char(c); }
void process_string(char *s) { while(*s) { process_char(*s++,0); } }
EVENT intern process_menuevent( VSCREEN *vptr, EVENT ev ) /*******************************************************/ { register int index; register int oldmenu = 0; register EVENT itemevent; auto EVENT newevent; auto DESCMENU* desc; auto int menu; auto bool select; auto ORD mouserow; auto ORD mousecol; auto int mouseon; newevent = ev; if( ev > EV_NO_EVENT && ev <= EV_LAST_KEYBOARD ) { /* this allows alt numeric keypad stuff to not activate the menus */ Menu->altpressed = FALSE; } if( isdialogue( vptr ) == FALSE ) { if( NumMenus > 0 ) { desc = &Describe[ Menu->menu - 1 ]; newevent = EV_NO_EVENT; /* Moved here from "else" case below */ if( Menu->popuppending ) { Menu->popuppending = FALSE; itemevent = createpopup( desc, &ev ); } else { itemevent = EV_NO_EVENT; } if( Menu->active ) { oldmenu = menu = Menu->menu; } else { oldmenu = menu = 0; } select = FALSE; if( ev == EV_ALT_PRESS && !Menu->ignorealt ) { Menu->altpressed = TRUE; } else if( ev == EV_ALT_RELEASE && Menu->altpressed ) { if( Menu->active ) { menu = 0; } else { desc = &Describe[ 0 ]; menu = 1; } Menu->altpressed = FALSE; } else if( ev == EV_FUNC( 10 ) && UIData->f10menus ) { desc = &Describe[ 0 ]; menu = 1; } else if( ev == EV_MOUSE_PRESS_R || ev == EV_MOUSE_PRESS_M ) { newevent = ev; menu = 0; Menu->draginmenu = FALSE; } else if( ( ev == EV_MOUSE_PRESS ) || ( ev == EV_MOUSE_DRAG ) || ( ev == EV_MOUSE_REPEAT ) || ( ev == EV_MOUSE_RELEASE ) || ( ev == EV_MOUSE_DCLICK ) ) { uigetmouse( &mouserow, &mousecol, &mouseon ); if( ( mouserow < uimenuheight() ) && ( Menu->active || ev == EV_MOUSE_PRESS || ev == EV_MOUSE_DCLICK || ev == EV_MOUSE_DRAG || ev == EV_MOUSE_REPEAT ) ) { if( ev == EV_MOUSE_DCLICK ) { ev = EV_MOUSE_PRESS; } menu = 0; for( index = 0 ; !MENUENDMARKER( Menu->titles[ index ] ); ++index ) { desc = &Describe[ index ]; if( ( MENU_GET_ROW( desc ) == mouserow ) && ( desc->titlecol <= mousecol ) && ( mousecol < desc->titlecol + desc->titlewidth + 2 ) ) { Menu->draginmenu = TRUE; Menu->popuppending = TRUE; menu = index + 1; break; } } } else if( Menu->active || Menu->draginmenu ) { if( ( desc->area.col < mousecol ) && ( mousecol < desc->area.col + desc->area.width - 1 ) && ( mouserow < desc->area.row + desc->area.height - 1 ) && ( desc->area.row <= mouserow ) ) { Menu->movedmenu = TRUE; } else if( ev == EV_MOUSE_PRESS ) { newevent = ev; menu = 0; Menu->draginmenu = FALSE; } else if( ev == EV_MOUSE_RELEASE ) { menu = 0; Menu->draginmenu = FALSE; } } else { newevent = ev; } if( ev != EV_MOUSE_RELEASE && menu != oldmenu ) { Menu->movedmenu = TRUE; } if( ev == EV_MOUSE_RELEASE ) { if( !Menu->movedmenu ) { menu = 0; } else { select = TRUE; } Menu->movedmenu = FALSE; } } else if( uialtchar( ev ) != '\0' ) { process_char( uialtchar( ev ), &desc, &menu, &select ); newevent = EV_NO_EVENT; } else if( Menu->active ) { switch( ev ) { case EV_ESCAPE : menu = 0; break; case EV_RETURN : if( menu > 0 ) { Menu->popuppending = TRUE; } break; case EV_CURSOR_LEFT : menu -= 1; if( menu == 0 ) { menu = NumMenus; } Menu->popuppending = TRUE; desc = &Describe[ menu - 1 ]; break; case EV_CURSOR_RIGHT : menu += 1; if( menu > NumMenus ) { menu = 1; } Menu->popuppending = TRUE; desc = &Describe[ menu - 1 ]; break; case EV_CURSOR_DOWN : Menu->popuppending = TRUE; break; case EV_NO_EVENT : break; default : if( ev <= EV_LAST_KEYBOARD ) { if( process_char( ev, &desc, &menu, &select ) ) { break; } } if( itemevent != EV_NO_EVENT ) { newevent = itemevent; select = TRUE; } else { newevent = ev; } } } else { newevent = ev; } if( menu != oldmenu ) { if( menu > 0 && !Menu->active ) { newevent = EV_MENU_ACTIVE; } Menu->active = ( menu > 0 ); if( oldmenu > 0 ) { menutitle( oldmenu, FALSE ); } if( menu > 0 ) { Menu->menu = menu; menutitle( menu, TRUE ); } if( menu == 0 || oldmenu == 0 ) { uimenutitlebar(); } } if( Menu->active ) { if( itemevent == EV_NO_EVENT ) { if( MENUGRAYED(Menu->titles[ menu-1]) ) { Menu->popuppending = FALSE; } else { itemevent = Menu->titles[ menu-1 ].event; } } Menu->event = itemevent; if( select ) { newevent = Menu->event; Menu->active = FALSE; uimenutitlebar(); } } } } if( ev == EV_MOUSE_RELEASE ) { Menu->draginmenu = FALSE; } if( Menu->ignorealt ) { Menu->ignorealt = FALSE; } if( ( !Menu->active && ( oldmenu != 0 ) ) || ( Menu->active && ( oldmenu != Menu->menu ) ) ) { if( ( Menu->menu > 0 ) && Menu->active ) { uimenucurr( &Menu->titles[Menu->menu - 1 ] ); } else { /* no current menu */ uimenucurr( NULL ); } } if ( Menu->popuppending ) { InitMenuPopupPending = TRUE; } return( newevent ); }
int hc_encode (struct or_blobrec * targblobrec, UCHAR *charbuf, int charcount, int file_pos) { /********** replaced by blobrec above... union charint { char ch[2]; INT orig_char_count; } un1; static char temp1 [MAX_NUM_CHAR+1]; ...repl by blobrec; ************/ char *targ, *src; int i, j; char temp; char ret_code = TRUE; char write = FALSE; char last_call = FALSE; if (charcount == 0) { last_call = TRUE; charcount = 1; } for (i = 0; i < charcount; i++) { if (!last_call) { ret_code = process_char (charbuf[i], (char *) blobrec.or_blob); } if ((ret_code == NO_SPACE) || (file_pos && (i == (charcount - 1)))) { if (!last_call) { if (file_pos && (i == (charcount - 1))) { num_char_coded++; } } if (bit_pos) { strncat (coded_bits_str, zero_str, (size_t) bits_left); convert_str_2_char (&temp); blobrec.or_blob[total_num_chars - 1][0] = temp; } write = TRUE; /********** un1.orig_char_count = num_char_coded; bitstring[0] = un1.ch[0]; bitstring[1] = un1.ch[1]; for (j = 0; j <= total_num_chars; j++) { *(bitstring + j + 2) = *(temp1 + j); }; **************/ targblobrec->or_bloblen = num_char_coded; targ = (char *) targblobrec->or_blob; src = (char *) blobrec.or_blob; for (j = 0; j < total_num_chars; j++) *targ++ = *src++; num_char_coded = 0; bit_pos = 0; total_num_chars = 0; if (file_pos && (i == (charcount - 1))) { return write; } i--; } else { num_char_coded++; } } return write; }
void process_file (FILE **filev, int counts[], int *others, int *control) /* procedure to read file and determine character frequency counts */ { char ch; while ((ch = getc (*filev)) != EOF) process_char (ch, counts, others, control); }
static int gt_sequence_buffer_fasta_advance(GtSequenceBuffer *sb, GtError *err) { int currentchar, ret = 0; unsigned long currentoutpos = 0, currentfileadd = 0, currentfileread = 0; GtSequenceBufferMembers *pvt; GtSequenceBufferFasta *sbf; gt_error_check(err); sbf = (GtSequenceBufferFasta*) sb; pvt = sb->pvt; while (true) { if (currentoutpos >= (unsigned long) OUTBUFSIZE) { if (pvt->filelengthtab != NULL) { pvt->filelengthtab[pvt->filenum].length += (uint64_t) currentfileread; pvt->filelengthtab[pvt->filenum].effectivelength += (uint64_t) currentfileadd; } break; } if (sbf->nextfile) { if (pvt->filelengthtab != NULL) { pvt->filelengthtab[pvt->filenum].length = 0; pvt->filelengthtab[pvt->filenum].effectivelength = 0; } sbf->nextfile = false; sbf->indesc = false; sbf->firstseqinfile = true; currentfileadd = 0; currentfileread = 0; pvt->linenum = (uint64_t) 1; pvt->inputstream = gt_file_xopen(gt_str_array_get(pvt->filenametab, (unsigned long) pvt->filenum), "rb"); pvt->currentinpos = 0; pvt->currentfillpos = 0; } else { currentchar = inlinebuf_getchar(sb, pvt->inputstream); if (currentchar == EOF) { gt_file_delete(pvt->inputstream); pvt->inputstream = NULL; if (pvt->filelengthtab != NULL) { pvt->filelengthtab[pvt->filenum].length += currentfileread; pvt->filelengthtab[pvt->filenum].effectivelength += currentfileadd; } if ((unsigned long) pvt->filenum == gt_str_array_size(pvt->filenametab)-1) { pvt->complete = true; break; } pvt->filenum++; sbf->nextfile = true; } else { currentfileread++; if (sbf->indesc) { if (currentchar == NEWLINESYMBOL) { pvt->linenum++; sbf->indesc = false; } if (pvt->descptr != NULL) { if (currentchar == NEWLINESYMBOL) { gt_queue_add(pvt->descptr, gt_cstr_dup(gt_str_get(sbf->headerbuffer))); gt_str_reset(sbf->headerbuffer); } else { gt_str_append_char(sbf->headerbuffer, currentchar); } } } else { if (!isspace((int) currentchar)) { if (currentchar == FASTASEPARATOR) { if (sbf->firstoverallseq) { sbf->firstoverallseq = false; sbf->firstseqinfile = false; } else { if (sbf->firstseqinfile) { sbf->firstseqinfile = false; } else { currentfileadd++; } pvt->outbuf[currentoutpos++] = (GtUchar) SEPARATOR; pvt->lastspeciallength++; } sbf->indesc = true; } else { if ((ret = process_char(sb, currentoutpos, currentchar, err))) return ret; currentoutpos++; currentfileadd++; } } } } } } if (sbf->firstoverallseq) { gt_error_set(err,"no sequences in multiple fasta file(s) %s ...", gt_str_array_get(pvt->filenametab,0)); return -2; } pvt->nextfree = currentoutpos; return 0; }