/* Add replacement string to the output buffer, recognizing special * constructs and replacing them with substrings of the original string. */ static void add_replace(const char *string, regex_t *re, const char *replace, regmatch_t *pm) { const char *p; for (p = replace; *p != '\0'; p++) { if (*p == '&' && !mimic_gnu) { add_sub(0, string, re, pm); continue; } if (*p == '\\') { if (p[1] == '\\') { addchar(p[1]); p++; continue; } if (p[1] == '&') { if (mimic_gnu) add_sub(0, string, re, pm); else addchar(p[1]); p++; continue; } if (isdigit((unsigned char)p[1])) { add_sub(*(++p) - '0', string, re, pm); continue; } } addchar(*p); } }
void print_str(pstream_t *p, const char *s, strprops_t props) { const char *s_orig = s; int npad = props.npad; if (npad > 0) { npad -= strlen(s_orig); while (npad > 0) { addchar(p, props.pad); --npad; } } while (*s) addchar(p, *s++); if (npad < 0) { props.pad = ' '; /* ignore '0' flag with '-' flag */ npad += strlen(s_orig); while (npad < 0) { addchar(p, props.pad); ++npad; } } }
// ajout d'un entier en fin de buffer void Prodbuffer::addint(int i) { addchar(i); i>>=8; addchar(i); i>>=8; addchar(i); i>>=8; addchar(i); }
/* * render() processes a html page and returns a buffer containing the * rendered page */ Page * render(FILE *input, int screenwidth) { Page *bfr; if ((bfr = malloc(sizeof *bfr)) == 0) return 0; bfr->pagealloc= 10240; /* alloc 10k for the page */ bfr->page = malloc(bfr->pagealloc); bfr->pagelen = 0; /* nothing written yet */ bfr->xp = 0; /* set up xp and start of */ bfr->startx = 0; /* line */ bfr->hrefs = malloc(1); /* prepare the href array */ bfr->nrhrefs = 0; bfr->title = 0; /* ... the title */ bfr->titlelen = 0; bfr->isbol = 1; /* and mark beginning of line */ memset(&state, 0, sizeof state); /* reset state block */ state.align = wwLEFT; state.width = screenwidth; state.doing = D_VANILLA; state.page = bfr; addchar(DLE); addchar(' '); parse_it(input, 0, 0, ALL_TAGS); addchar(0); /* null-terminate the page */ bfr->pagelen--; return bfr; } /* render */
void text_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix) { internal_t*i = (internal_t*)dev->internal; double xshift = matrix->tx - i->currentx; double yshift = matrix->ty - i->currenty; i->currentx = matrix->tx; i->currenty = matrix->ty; if(fabs(yshift)>1.0) { addchar(dev, 10); } else if(xshift > i->lastadvance*1.3 || xshift<0) { addchar(dev, 32); } int u; if(font) { i->lastadvance = font->glyphs[glyphnr].advance*matrix->m00; u = font->glyphs[glyphnr].unicode; } else { u = glyphnr; i->currentx = 0;i->currenty = 0; } if(u>13) { addchar(dev, u); } }
/**************************************************************************** splitline Splits inchrline at the last word break (bunch of consecutive blanks). Makes a new line out of the first part and prints it using printline. Makes a new line out of the second part and returns. ****************************************************************************/ void splitline(UR_OBJECT user, UR_OBJECT u, RM_OBJECT rm) { int i,gotspace=0,lastspace=0,len1,len2; long *part1,*part2; set_crash(); part1 = (long*)myalloc(sizeof(long)*(inchrlinelen+1)); part2 = (long*)myalloc(sizeof(long)*(inchrlinelen+1)); for (i=inchrlinelen-1;i>=0;i--) { if (!gotspace && inchrline[i]==' ') { gotspace = 1; lastspace = i; } if (gotspace && inchrline[i]!=' ') break; } len1 = i+1; len2 = inchrlinelen-lastspace-1; for (i=0;i<len1;i++) part1[i] = inchrline[i]; for (i=0;i<len2;i++) part2[i] = inchrline[lastspace+1+i]; fclearline(); for (i=0;i<len1;i++) addchar(part1[i]); printline(user, u, rm); for (i=0;i<len2;i++) addchar(part2[i]); free(part1); free(part2); }
char *buffer_char(t_buffer *buff) { char *tmp; char c; if (buff->e == buff->l) return (NULL); if (find_n(buff)) { tmp = NULL; while ((c = ((char *)buff->buff)[buff->l]) != '\n') { tmp = addchar(tmp, c); buff->l++; if (buff->l == P_MAX + 1) buff->l = 0; } tmp = addchar(tmp, '\n'); buff->l++; if (buff->l == P_MAX + 1) buff->l = 0; return (tmp); } return (NULL); }
void doformat(const char *argv[], int argc) { const char *format = argv[2]; int pos = 3; int left_padded; long width; size_t l; const char *thisarg = NULL; char temp[2]; long extra; while (*format != 0) { if (*format != '%') { addchar(*format++); continue; } format++; if (*format == '%') { addchar(*format++); continue; } if (*format == 0) { addchar('%'); break; } if (*format == '*') { format++; if (pos >= argc) m4errx(1, "Format with too many format specifiers."); width = strtol(argv[pos++], NULL, 10); } else { width = strtol(format, __DECONST(char **,&format), 10); } if (width < 0) { left_padded = 1; width = -width; } else { left_padded = 0; } if (*format == '.') { format++; if (*format == '*') { format++; if (pos >= argc) m4errx(1, "Format with too many format specifiers."); extra = strtol(argv[pos++], NULL, 10); } else { extra = strtol(format, __DECONST(char **, &format), 10); } } else {
/* * addnewline() writes an end-of-line to the rendered page */ static void addnewline() { addchar('\n'); /* put out the end-of-line marker */ XP = 0; LASTWASSPACE = 0; STARTX = PAGELEN; /* mark the start of the next line */ addchar(DLE); addchar(' '); state.page->isbol = 1; } /* addnewline */
/* * addstring() is a local that writes a string to the rendered page, * properly dealing with escape codes, and ignoring \n */ static void addstring(unsigned char *s) { while (*s) { if ( (*s == bcfID) || (*s == DLE) || (*s == bctID) ) addchar(*s); if (*s == '\n') ++s; else addchar(*s++); } }
static void chr_event(void *opaque, int event) { IPMIBmcExtern *ibe = opaque; IPMIInterface *s = ibe->parent.intf; IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s); unsigned char v; switch (event) { case CHR_EVENT_OPENED: ibe->connected = true; ibe->outpos = 0; ibe->outlen = 0; addchar(ibe, VM_CMD_VERSION); addchar(ibe, VM_PROTOCOL_VERSION); ibe->outbuf[ibe->outlen] = VM_CMD_CHAR; ibe->outlen++; addchar(ibe, VM_CMD_CAPABILITIES); v = VM_CAPABILITIES_IRQ | VM_CAPABILITIES_ATTN; if (k->do_hw_op(ibe->parent.intf, IPMI_POWEROFF_CHASSIS, 1) == 0) { v |= VM_CAPABILITIES_POWER; } if (k->do_hw_op(ibe->parent.intf, IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP, 1) == 0) { v |= VM_CAPABILITIES_GRACEFUL_SHUTDOWN; } if (k->do_hw_op(ibe->parent.intf, IPMI_RESET_CHASSIS, 1) == 0) { v |= VM_CAPABILITIES_RESET; } if (k->do_hw_op(ibe->parent.intf, IPMI_SEND_NMI, 1) == 0) { v |= VM_CAPABILITIES_NMI; } addchar(ibe, v); ibe->outbuf[ibe->outlen] = VM_CMD_CHAR; ibe->outlen++; ibe->sending_cmd = false; continue_send(ibe); break; case CHR_EVENT_CLOSED: if (!ibe->connected) { return; } ibe->connected = false; if (ibe->waiting_rsp) { ibe->waiting_rsp = false; ibe->inbuf[1] = ibe->outbuf[1] | 0x04; ibe->inbuf[2] = ibe->outbuf[2]; ibe->inbuf[3] = IPMI_CC_BMC_INIT_IN_PROGRESS; k->handle_rsp(s, ibe->outbuf[0], ibe->inbuf + 1, 3); } break; } }
static void ipmi_bmc_extern_handle_command(IPMIBmc *b, uint8_t *cmd, unsigned int cmd_len, unsigned int max_cmd_len, uint8_t msg_id) { IPMIBmcExtern *ibe = IPMI_BMC_EXTERN(b); IPMIInterface *s = ibe->parent.intf; uint8_t err = 0, csum; unsigned int i; if (ibe->outlen) { /* We already have a command queued. Shouldn't ever happen. */ fprintf(stderr, "IPMI KCS: Got command when not finished with the" " previous commmand\n"); abort(); } /* If it's too short or it was truncated, return an error. */ if (cmd_len < 2) { err = IPMI_CC_REQUEST_DATA_LENGTH_INVALID; } else if ((cmd_len > max_cmd_len) || (cmd_len > MAX_IPMI_MSG_SIZE)) { err = IPMI_CC_REQUEST_DATA_TRUNCATED; } else if (!ibe->connected) { err = IPMI_CC_BMC_INIT_IN_PROGRESS; } if (err) { IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s); unsigned char rsp[3]; rsp[0] = cmd[0] | 0x04; rsp[1] = cmd[1]; rsp[2] = err; ibe->waiting_rsp = false; k->handle_rsp(s, msg_id, rsp, 3); goto out; } addchar(ibe, msg_id); for (i = 0; i < cmd_len; i++) { addchar(ibe, cmd[i]); } csum = ipmb_checksum(&msg_id, 1, 0); addchar(ibe, -ipmb_checksum(cmd, cmd_len, csum)); ibe->outbuf[ibe->outlen] = VM_MSG_CHAR; ibe->outlen++; /* Start the transmit */ continue_send(ibe); out: return; }
/* quote characters inside a word bounded by "quotes" */ static int quotecollect(PCONF_CTX *ctx) { /* user is trying to break us */ if (ctx->ch == '#') { pconf_seterr(ctx, "Unbalanced word due to unescaped # in quotes"); endofword(ctx); /* this makes us drop all the way out of the caller */ return STATE_PARSEERR; } /* another " means we're done with this word */ if (ctx->ch == '"') { endofword(ctx); return STATE_FINDWORDSTART; } /* literal - special case since it needs to return here */ if (ctx->ch == '\\') return STATE_QC_LITERAL; /* otherwise save it and loop back */ addchar(ctx); return STATE_QUOTECOLLECT; }
static char * getstring() { addchar('\0'); current = 0; return buffer; }
int main(int argc, char *argv){ char *msg; init_server(); while(1){ printf("%s%s", username, ": "); msg = input(); if(strlen(msg) == 0){ setmsg("\n"); } else if(strcmp(msg,"/exit") == 0){ free(msg); killout(); pthread_exit(&retm); }else{ char *newline = "\n"; msg = addchar(msg, newline); setmsg(msg); pthread_t tid; pthread_create(&tid, NULL, sendmesgptr, NULL); pthread_join(tid, NULL); } free(msg); } killout(); killinc(); }
int TokenUnitario(char caracter){ addchar(); switch(caracter){ case '{': NextToken = KEY_L; break; case '}': NextToken = KEY_R; break; case '(': NextToken = PARENT_L; break; case ')': NextToken = PARENT_R; break; case ';': NextToken = PUNTO_COMA; break; case ',': NextToken = COMA; break; case '*': NextToken = POINTER; break; default: NextToken = EOF; break; } return NextToken; }
void Buffer::update(int ch) { switch (ch) { case KEY_UP: prevline(); break; case KEY_DOWN: nextline(); break; case KEY_RIGHT: nextchar(); break; case KEY_LEFT: prevchar(); break; case KEY_HOME: begofline(); break; case KEY_END: endofline(); break; case 127: delchar(); break; case '\n': case '\r': newline(); break; default: addchar(ch); } }
/* collect characters inside a word */ static int collect(PCONF_CTX *ctx) { /* comment means the word is done, and skip to the end of the line */ if (ctx->ch == '#') { endofword(ctx); return STATE_FINDEOL; } /* newline means the word is done, and the line is done */ if (ctx->ch == 10) { endofword(ctx); return STATE_ENDOFLINE; } /* space means the word is done */ if (isspace(ctx->ch)) { endofword(ctx); return STATE_FINDWORDSTART; } /* \ = literal = accept the next char blindly */ if (ctx->ch == '\\') return STATE_COLLECTLITERAL; /* otherwise store it and come back for more */ addchar(ctx); return STATE_COLLECT; }
/* look for the beginning of a word */ static int findwordstart(PCONF_CTX *ctx) { /* newline = the physical line is over, so the logical one is too */ if (ctx->ch == 10) return STATE_ENDOFLINE; /* the rest of the line is a comment */ if (ctx->ch == '#') return STATE_FINDEOL; /* space = not in a word yet, so loop back */ if (isspace(ctx->ch)) return STATE_FINDWORDSTART; /* \ = literal = accept the next char blindly */ if (ctx->ch == '\\') return STATE_COLLECTLITERAL; /* " = begin word bounded by quotes */ if (ctx->ch == '"') return STATE_QUOTECOLLECT; /* at this point the word just started */ addchar(ctx); return STATE_COLLECT; }
/* In Gnu m4 mode, parentheses for backmatch don't work like POSIX 1003.2 * says. So we twiddle with the regexp before passing it to regcomp. */ static char * twiddle(const char *p) { /* + at start of regexp is a normal character for Gnu m4 */ if (*p == '^') { addchar(*p); p++; } if (*p == '+') { addchar('\\'); } /* This could use strcspn for speed... */ while (*p != '\0') { if (*p == '\\') { switch(p[1]) { case '(': case ')': case '|': addchar(p[1]); break; case 'w': addconstantstring("[_a-zA-Z0-9]"); break; case 'W': addconstantstring("[^_a-zA-Z0-9]"); break; case '<': addconstantstring("[[:<:]]"); break; case '>': addconstantstring("[[:>:]]"); break; default: addchars(p, 2); break; } p+=2; continue; } if (*p == '(' || *p == ')' || *p == '|') addchar('\\'); addchar(*p); p++; } return getstring(); }
/* take almost anything literally, but return to quotecollect */ static int qc_literal(PCONF_CTX *ctx) { /* continue onto the next line of the file */ if (ctx->ch == 10) return STATE_QUOTECOLLECT; addchar(ctx); return STATE_QUOTECOLLECT; }
/* take almost anything literally */ static int collectliteral(PCONF_CTX *ctx) { /* continue to the next line */ if (ctx->ch == 10) return STATE_COLLECT; addchar(ctx); return STATE_COLLECT; }
int AToken(){ int i = 0; LenLex = 0; borrarblancos(); switch(ClassChar){ case LETTER: addchar(); Get(); while(ClassChar == LETTER || ClassChar == DIGITO){ addchar(); Get(); } while(i<=4 && strcmp(storage[i], Lexeme)!=0) i++; if(i<=4) NextToken = T_STORAGE; else{ i=0; while(i<=8 && strcmp(type[i], Lexeme)!=0) i++; if(i<=8) NextToken = T_TYPE; else NextToken = IDENT; } break; case UNKNOWN: TokenUnitario(NextChar); Get(); break; case EOF: NextToken = EOF; Lexeme[0] = 'E'; Lexeme[1] = 'O'; Lexeme[2] = 'F'; Lexeme[3] = 0; break; } printf("EL SIGUIETE TOKEN ES %d,EL SIGUIENTE LEXEMA ES %s \n",NextToken,Lexeme); return NextToken; }
void proccess(void) { char *p = NULL; current = 1; top = 0; while(fgets(buffer, 65535, stdin)) { if(0 == strcmp(buffer, "END OF CASE\n")) break; p = buffer; while(*p && *p != '\n') addchar(*p++); ++current; } }
/* * addspace() adds space to the rendered page, breaking the line as appropriate */ void addspace(char *space) { switch (state.doing) { case D_PRE: /* when doing a PRE segment, we need to catch \n's and properly * expand them into \n, DLE, ' ' */ while (*space) { if (*space == '\n') addnewline(); else { linestart(); addchar(*space); } ++space; } break; case D_TITLE: if (!LASTWASSPACE) { state.page->titlelen++; state.page->title = realloc(state.page->title, state.page->titlelen+2); strcat(state.page->title, " "); } break; default: if (!LASTWASSPACE) { if (XP >= state.width) breakline(); else if (XP > 0) { linestart(); addchar(' '); XP++; } } break; } LASTWASSPACE = 1; } /* addspace */
void pdp11::cons::poll() { if (Serial.available()) { addchar(Serial.read()); } count++; if (count > 64) { if ((TPS & 0x80) == 0) { Serial.write(TPB & 0x7f); TPS |= 0x80; if (TPS & (1 << 6)) { interrupt(INTTTYOUT, 4); } } } }
/* argv[2]: string * argv[3]: regexp * argv[4]: opt rep */ void dopatsubst(const char *argv[], int argc) { if (argc <= 3) { warnx("Too few arguments to patsubst"); return; } /* special case: empty regexp */ if (argv[3][0] == '\0') { const char *s; size_t len; if (argc > 4 && argv[4]) len = strlen(argv[4]); else len = 0; for (s = argv[2]; *s != '\0'; s++) { addchars(argv[4], len); addchar(*s); } } else { int error; regex_t re; regmatch_t *pmatch; int mode = REG_EXTENDED; const char *source; size_t l = strlen(argv[3]); if (!mimic_gnu || (argv[3][0] == '^') || (l > 0 && argv[3][l-1] == '$')) mode |= REG_NEWLINE; source = mimic_gnu ? twiddle(argv[3]) : argv[3]; error = regcomp(&re, source, mode); if (error != 0) exit_regerror(error, &re, source); pmatch = xreallocarray(NULL, re.re_nsub+1, sizeof(regmatch_t), NULL); do_subst(argv[2], &re, source, argc > 4 && argv[4] != NULL ? argv[4] : "", pmatch); free(pmatch); regfree(&re); } pbstr(getstring()); }
static int gen_dump_string(struct parse_string *p, const struct parse_struct *pinfo, const char *data, unsigned indent) { const char *ptr = *(char **)data; char *s = encode_bytes(ptr, strlen(ptr)); if (addtabbed(p, pinfo->name, indent) || addstr(p, " = ") || addchar(p,'{') || addstr(p, s) || addstr(p, "}\n")) { free(s); return -1; } FREE(s); return 0; }
/* dump a single non-array element, hanlding struct and enum */ static int gen_dump_one(struct parse_string *p, const struct parse_struct *pinfo, const char *ptr, unsigned indent) { if (pinfo->dump_fn == gen_dump_char && pinfo->ptr_count == 1) { char *s = encode_bytes(ptr, strlen(ptr)); if (addchar(p,'{') || addstr(p, s) || addstr(p, "}")) { free(s); return -1; } FREE(s); return 0; } return pinfo->dump_fn(p, ptr, indent); }
//英雄选择菜单回调函数,可共用,根据tag判定选择结果.注意:player1是默认选择,需在场景载入时就读入player1数据,回调函数不一定触发 void SelectHero::radiomenucallback(cocos2d::CCObject *pSender){ choice=((CCMenuItemImage*)pSender)->getTag(); CCLOG("choose player%d",choice); Name_Label->setString(addchar("NAME:", dbResult[choice*column+1])); HP_Label->setString(addchar("HP:", dbResult[choice*column+3])); ATK_Label->setString(addchar("ATK:", dbResult[choice*column+4])); DEF_Label->setString(addchar("DEF:", dbResult[choice*column+5])); AGI_Label->setString(addchar("AGI:", dbResult[choice*column+6])); LUK_Label->setString(addchar("LUK:", dbResult[choice*column+7])); }