/*********************************************************** * Name: os_assert_failure * * Arguments: const char *msg - message for log (normally condition text) * const char *file - filename of translation unit * const char *func - name of function (NULL if not available) * int line - line number */ void os_assert_failure(const char *msg, const char *file, const char *func, int line) { TBuf8<256> printBuf; if (func) my_sprintf(printBuf, "VC: Assertion failed: %s, function %s, file %s, line %d", msg, func, file, line); else my_sprintf(printBuf, "VC: Assertion failed: %s, file %s, line %d", msg, file, line); Kern::Fault(reinterpret_cast<const char *>(printBuf.Ptr()), KErrGeneral); }
int main(void) { char str_buf[30]; int32_t value =43552; LED_Init(); ILI9341_Init(); Usart1_Init(9600); Myprintf_Init(0x00,myputc); ILI9341_Puts(0,0,"LCD string test",&MY_Font_11x18,ILI9341_COLOR_WHITE,ILI9341_COLOR_BLUE); while(1) { //my_printf("It's usart1 test!\n"); my_sprintf(str_buf,"%d\n",value); my_printf(str_buf); LED_GREEN_ON(); LED_RED_OFF(); delay(800000); LED_GREEN_OFF(); LED_RED_ON(); delay(800000); } return 0; }
void DisplayTopBar(int ypos, int ttexcol, int backcol, char *title, char*texx, ...) { strcpy(topBar.text, get_translation(title)); char displbuf[3001]; va_list ap; va_start(ap,texx); my_sprintf(displbuf, get_translation(texx), ap); va_end(ap); if (ypos > 0) play.top_bar_ypos = ypos; if (ttexcol > 0) play.top_bar_textcolor = ttexcol; if (backcol > 0) play.top_bar_backcolor = backcol; topBar.wantIt = 1; topBar.font = FONT_NORMAL; topBar.height = wgetfontheight(topBar.font); topBar.height += multiply_up_coordinate(play.top_bar_borderwidth) * 2 + get_fixed_pixel_size(1); // they want to customize the font if (play.top_bar_font >= 0) topBar.font = play.top_bar_font; // DisplaySpeech normally sets this up, but since we're not going via it... if (play.cant_skip_speech & SKIP_AUTOTIMER) play.messagetime = GetTextDisplayTime(texx); DisplayAtY(play.top_bar_ypos, displbuf); }
void elevation_bis(t_server *serv, t_client *cl) { char *tmp; t_client_list *list; tmp = my_sprintf("elevation en cours\nniveau actuel : %d\n", cl->level); if (verif_level(serv->clients, cl->level, cl->pos_x, cl->pos_y)) { list = serv->clients; while (list) { if (list->item->pos_x == cl->pos_x && list->item->pos_y == cl->pos_y) { add_client_response(&list->item, tmp); list->item->level++; } list = list->next; } clear_objet(&serv->map[cl->pos_y][cl->pos_x]); } else add_client_response(&cl, "ko\n"); free(tmp); }
void pnwa(t_server *server, t_client *client, char *cmd, char **av) { t_client_list *tmp; char *str; t_client *cl; (void) cmd; tmp = server->clients; if (tablen(av) != 1) { add_client_response(&(client), "sbp\n"); return ; } while (tmp) { if (tmp->item && tmp->item->is_graphic == 0 && cl->team) { cl = tmp->item; str = my_sprintf("pnw %d %d %d %d %d %s\n", cl->fd, cl->pos_x, cl->pos_y, cl->dir, cl->level, cl->team->name); add_client_response(&(client), str); if (str) free(str); } tmp = tmp->next; } }
void Display(char*texx, ...) { char displbuf[STD_BUFFER_SIZE]; va_list ap; va_start(ap,texx); my_sprintf(displbuf, get_translation(texx), ap); va_end(ap); DisplayAtY (-1, displbuf); }
/* *** SCRIPT SYMBOL: [String] String::Format^101 *** */ static const char* String_Format(const char *texx, ...) { char displbuf[STD_BUFFER_SIZE]; va_list ap; va_start(ap,texx); my_sprintf(displbuf, get_translation(texx), ap); va_end(ap); return CreateNewScriptString(displbuf); }
void content_inventory(t_server *serv, t_client *cl, char *cmd, char **command) { int tb[8]; char *str; (void) cmd; (void) command; (void) serv; bzero(tb, sizeof(int) * 8); content_case(LINEMATE, cl->inventory, &tb[0]); str = my_sprintf("nourriture %d, linemate %d, deraumere %d, sibur %d,", cl->life, tb[1], tb[2], tb[3]); str = my_sprintf("%s mendiane %d, phiras %d, thystame %d\n", str, tb[4], tb[5], tb[6]); add_client_response(&cl, str); if (str) free(str); }
/* *** SCRIPT SYMBOL: [String] StrFormat *** */ static void _sc_sprintf(char*destt,char*texx, ...) { char displbuf[STD_BUFFER_SIZE]; VALIDATE_STRING(destt); check_strlen(destt); va_list ap; va_start(ap,texx); my_sprintf(displbuf, get_translation(texx), ap); va_end(ap); my_strncpy(destt, displbuf, MAXSTRLEN - 1); }
/* ** The player forks ** pfk #e\n */ char *player_fork_gr(t_client *client) { char *to_send; char *player_num; player_num = my_sprintf(client->id); to_send = xmalloc(7 + my_strlen(player_num)); my_strcpy(to_send, "pfk #"); my_strcat(to_send, player_num); my_strcat(to_send, "\n"); free(player_num); return (to_send); }
/* ** The player fork is done ** enw #e #n X Y\n */ char *player_end_fork_gr(t_client *client, int id_egg) { char *to_send; char *coordinate; char *player_num; char *egg_num; int len; coordinate = extract_coordinates_from_pos(&(client->pos)); player_num = my_sprintf(client->id); egg_num = my_sprintf(id_egg); len = 9 + my_strlen(egg_num) + my_strlen(player_num) + my_strlen(coordinate); to_send = xmalloc(len); my_strcpy(to_send, "enw #"); my_strcat(to_send, egg_num); my_strcat(to_send, " #"); my_strcat(to_send, player_num); my_strcat(to_send, " "); my_strcat(to_send, coordinate); xfree_n(coordinate, player_num, egg_num, (void *)-1); return (to_send); }
static void send_level(t_client *client, t_client *cl) { char *str; if (cl) { str = my_sprintf("plv %d %d\n", cl->fd, cl->level); add_client_response(&(client), str); if (str) free(str); } }
void DisplayAt(int xxp,int yyp,int widd,char*texx, ...) { char displbuf[STD_BUFFER_SIZE]; va_list ap; va_start(ap,texx); my_sprintf(displbuf, get_translation(texx), ap); va_end(ap); multiply_up_coordinates(&xxp, &yyp); widd = multiply_up_coordinate(widd); if (widd<1) widd=scrnwid/2; if (xxp<0) xxp=scrnwid/2-widd/2; _display_at(xxp,yyp,widd,displbuf,1,0, 0, 0, false); }
void sgt(t_server *server, t_client *client, char *cmd, char **av) { char *str; (void) cmd; if (tablen(av) != 1) { add_client_response(&(client), "sbp\n"); return ; } str = my_sprintf("sgt %d\n", server->game_infos.time); add_client_response(&(client), str); if (str) free(str); }
t_list *prepare_environ() { extern char **environ; t_list *my_environ; int i; char *s; my_environ = my_params_in_list_dup(my_charpp_len(environ), environ); s = get_env_var_value(my_environ, "SHLVL"); i = (s == NULL) ? (0) : (my_atoi(s)); if (s != NULL) free(s); s = my_sprintf(i + 1); set_env_var_value(&my_environ, "SHLVL", s); free(s); return (my_environ); }
/* Argument unmangling for C++ */ static char *unmangptr(char *buf , char *name, char *last) { int cvol = 0; int cconst = 0; while (*name == 'x' || *name == 'y') { if (*name == 'y') cvol++; if (*name == 'x') cconst++; name++; } if (*name == 'p' || *name == 'P') { name = unmangptr(buf, name+1, last); strcat(buf, "*"); if (cconst) { strcat(buf, tn_const); } if (cvol) { strcat(buf , tn_volatile); } if (*name == 'A') { while (*name == 'A') { int n = 0; name++; while (isdigit (*name)) n = n * 10 + (*name ++ & 0xf); my_sprintf(buf + strlen(buf), "[%d]", n); } name = unmangptr(buf, name, last); } } else if (*name != 'A') { char basetp[4096]; int l; if (cconst) { strcat(buf, tn_const); } if (cvol) { strcat(buf , tn_volatile); } if (*name == '#') { name = unmangTemplate(basetp, name, last); } else { name = unmang1(basetp, name, last, FALSE); } l = strlen(basetp); memmove(buf + l, buf, strlen(buf)+1); memcpy(buf, basetp, l); } return name; }
void test_sprintf(void) { static char buf[1024]; static char sp_buf[1024]; sprintf(sp_buf, "hogehoge"); my_sprintf(buf, "hogehoge", 0, 0, 0, 0); printf("%s\n", buf); assert(strcmp(buf, sp_buf) == 0); sprintf(sp_buf, "%s", "piyopiyo"); my_sprintf(buf, "%s", (unsigned long)"piyopiyo", 0, 0, 0); printf("%s\n", buf); assert(strcmp(buf, sp_buf) == 0); sprintf(sp_buf, "foo%%bar%s", "hoge"); my_sprintf(buf, "foo%%bar%s", (unsigned long)"hoge", 0, 0, 0); printf("%s\n", buf); assert(strcmp(buf, sp_buf) == 0); sprintf(sp_buf, "%d, %d, %d, \"%8d\"", 9999, 0, -1, -1234); my_sprintf(buf, "%d, %d, %d, \"%8d\"", 9999, 0, -1, -1234); printf("%s\n", buf); assert(strcmp(buf, sp_buf) == 0); sprintf(sp_buf, "%u, %u, %-d, \"%-8d\"", 12345, 0, -123, -111); my_sprintf(buf, "%u, %u, %-d, \"%-8d\"", 12345, 0, -123, -111); printf("%s\n", buf); assert(strcmp(buf, sp_buf) == 0); sprintf(sp_buf, "\"%d\", \"%8d\", \"%-8d\", \"%s\"", 123456789, 123456, 789, "abcd"); my_sprintf(buf, "\"%d\", \"%8d\", \"%-8d\", \"%s\"", 123456789, 123456, 789, (unsigned long)"abcd"); printf("%s\n", buf); assert(strcmp(buf, sp_buf) == 0); sprintf(sp_buf, "\"%s\", \"%9d\", \"%s\", \"%s\"", "foo", 1234567890, "bar", "abcd"); my_sprintf(buf, "\"%s\", \"%9d\", \"%s\", \"%s\"", (unsigned long)"foo", 1234567890, (unsigned long)"bar", (unsigned long)"abcd"); printf("%s\n", buf); assert(strcmp(buf, sp_buf) == 0); sprintf(sp_buf, "%x, \"%8x\", \"%08X\", \"%10d\"", 0x1234, 0x5678, 0xABCD, 12345); my_sprintf(buf, "%x, \"%8x\", \"%08X\", \"%10d\"", 0x1234, 0x5678, 0xABCD, 12345); printf("%s\n", buf); assert(strcmp(buf, sp_buf) == 0); sprintf(sp_buf, "%x, \"%8x\", \"%-8X\", \"%-10d\"", 0x0, 0x5678, 0xABCD, 12345); my_sprintf(buf, "%x, \"%8x\", \"%-8X\", \"%-10d\"", 0x0, 0x5678, 0xABCD, 12345); printf("%s\n", buf); assert(strcmp(buf, sp_buf) == 0); sprintf(sp_buf, "%c, %c, %c, %c", 'a', '#', '\\', '9'); my_sprintf(buf, "%c, %c, %c, %c", 'a', '#', '\\', '9'); printf("%s\n", buf); assert(strcmp(buf, sp_buf) == 0); sprintf(sp_buf, "%p, %p, %p, %p", (void *)0, (void *)buf, (void *)sp_buf, (void *)0); my_sprintf(buf, "%p, %p, %p, %p", 0, (unsigned long)buf, (unsigned long)sp_buf, 0); printf("%s\n", sp_buf); printf("%s\n", buf); }
void Perl_taint_env(pTHX) { dVAR; SV** svp; MAGIC* mg; const char* const *e; static const char* const misc_env[] = { "IFS", /* most shells' inter-field separators */ "CDPATH", /* ksh dain bramage #1 */ "ENV", /* ksh dain bramage #2 */ "BASH_ENV", /* bash dain bramage -- I guess it's contagious */ #ifdef WIN32 "PERL5SHELL", /* used for system() on Windows */ #endif NULL }; /* Don't bother if there's no *ENV glob */ if (!PL_envgv) return; /* If there's no %ENV hash of if it's not magical, croak, because * it probably doesn't reflect the actual environment */ if (!GvHV(PL_envgv) || !(SvRMAGICAL(GvHV(PL_envgv)) && mg_find((const SV *)GvHV(PL_envgv), PERL_MAGIC_env))) { const bool was_tainted = PL_tainted; const char * const name = GvENAME(PL_envgv); PL_tainted = TRUE; if (strEQ(name,"ENV")) /* hash alias */ taint_proper("%%ENV is aliased to %s%s", "another variable"); else /* glob alias: report it in the error message */ taint_proper("%%ENV is aliased to %%%s%s", name); /* this statement is reached under -t or -U */ PL_tainted = was_tainted; } #ifdef VMS { int i = 0; char name[10 + TYPE_DIGITS(int)] = "DCL$PATH"; STRLEN len = 8; /* strlen(name) */ while (1) { if (i) len = my_sprintf(name,"DCL$PATH;%d", i); svp = hv_fetch(GvHVn(PL_envgv), name, len, FALSE); if (!svp || *svp == &PL_sv_undef) break; if (SvTAINTED(*svp)) { TAINT; taint_proper("Insecure %s%s", "$ENV{DCL$PATH}"); } if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) { TAINT; taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}"); } i++; } } #endif /* VMS */ svp = hv_fetchs(GvHVn(PL_envgv),"PATH",FALSE); if (svp && *svp) { if (SvTAINTED(*svp)) { TAINT; taint_proper("Insecure %s%s", "$ENV{PATH}"); } if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) { TAINT; taint_proper("Insecure directory in %s%s", "$ENV{PATH}"); } } #ifndef VMS /* tainted $TERM is okay if it contains no metachars */ svp = hv_fetchs(GvHVn(PL_envgv),"TERM",FALSE); if (svp && *svp && SvTAINTED(*svp)) { STRLEN len; const bool was_tainted = PL_tainted; const char *t = SvPV_const(*svp, len); const char * const e = t + len; PL_tainted = was_tainted; if (t < e && isALNUM(*t)) t++; while (t < e && (isALNUM(*t) || strchr("-_.+", *t))) t++; if (t < e) { TAINT; taint_proper("Insecure $ENV{%s}%s", "TERM"); } } #endif /* !VMS */ for (e = misc_env; *e; e++) { SV * const * const svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE); if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) { TAINT; taint_proper("Insecure $ENV{%s}%s", *e); } } }
/* Argument unmangling for C++ */ char *unmang1(char *buf, char *name, char *last, BOOLEAN tof) { int v; int cvol = 0, cconst = 0, clrqual = 0, crrqual = 0; char buf1[10000], *p, buf2[10000], buf3[1000]; while (*name == '_') name++; while (*name == 'x' || *name == 'y') { if (*name == 'y') cvol++; if (*name == 'x') cconst++; if (*name == 'r') clrqual++; if (*name == 'R') crrqual++; name++; } if (*name != 'p' && *name != 'P') { if (cconst) strcat(buf, tn_const); if (cvol) strcat(buf, tn_volatile); } start: if (isdigit(*name)) { char *s = buf; v = *name++ - '0'; while (isdigit(*name)) v = v * 10+ *name++ - '0'; if (name[0] == '@') name++,v--; if (v < 0 || v > 200) return unmang1(buf, name, last, tof); // out of sequence, recover while (v > 0) { char *newname; if (name[0] == '#') { newname = unmangTemplate(buf, name, last); v -= newname - name; name = newname; buf += strlen(buf); } else if (name[0] == '$') { if (name[1] == '$') // in case of $$lambda { *buf++ = *name++; *buf++ = *name++; *buf = 0; v -= 2; } else { name++; newname = unmang1(buf, name, last, FALSE); v -= newname - name-1; name = newname; buf += strlen(buf); } } else { v--; if (*name == '@') { *buf++ = ':'; *buf++ = ':'; name++; } else *buf++ = *name++; *buf = 0; } } if (manglenamecount < MAX_MANGLE_NAME_COUNT) strcpy(manglenames[manglenamecount++], s); } else switch (*name++) { case '$': p = buf1; if (*name == 't') { name = unmangcpptype(buf, name, last); } else if (isdigit(*name)) { *p++ = '('; while (*name && *name != '$') { *p++ = *name++; } if (*name) name++; *p++ = ')'; *p = 0; } else if (*name == 's') { name++; *p++ = '('; *p++ = '"'; while (*name && *name != '$') { *p++ = *name++; } if (*name) name++; *p++ = '"'; *p++ = ')'; *p = 0; } break; case 'Q': case 'q': p = buf1; if (!tof) { *p++ = '('; *p++ = '*'; *p++ = ')'; } *p++ = '('; *p = 0; if (*name == 'v') { // special case for func with void argument *p++ = ','; *p++ = ' '; *p = 0; name++; } else { while (*name && *name != '$') { if (*name == '#') { name = unmangTemplate(p, name, last); } else { name = unmang1(p, name, last, FALSE); } p += strlen(p); *p++ = ','; *p++ = ' '; *p = 0; } } if (*name == '$') name++; if (p >= buf1+2) p -= 2; *p = 0; if (*name) { // discard return value buf2[0] = 0; name = unmang1(buf2, name, last, FALSE); } strcpy(buf, buf1); strcat(buf, ")"); if (cconst) strcat(buf, tn_const); if (cvol) strcat(buf, tn_volatile); if (clrqual) strcat(buf, "& "); if (crrqual) strcat(buf, "&& "); buf += strlen(buf); break; case 'h': strcpy(buf, tn_char16_t); buf += strlen(buf); break; case 'H': strcpy(buf, tn_char32_t); buf += strlen(buf); break; case 'S': strcpy(buf, tn_signed); buf = buf + 7; if (*name++ == 'c') strcpy(buf, tn_char); break; case 'u': strcpy(buf, "unsigned "); buf = buf + 9; if (*name == 'N') { strcpy(buf, "unative"); } else switch (*name++) { case 'i': strcpy(buf, tn_int); break; case 'l': strcpy(buf, tn_long); break; case 'L': strcpy(buf, tn_longlong); break; case 's': strcpy(buf, tn_short); break; case 'c': strcpy(buf, tn_char); break; case 'N': strcpy(buf, "native int"); break; } break; case 'M': buf2[0] = 0; if (*name == '#') { name = unmangTemplate(buf2, name, last); } else if (*name == 'n') { name++; v = *name++ - '0'; if (v > 9) v -= 7; strcpy(buf2, manglenames[v]); p = buf2 + strlen(buf2); } else { v = *name++ - '0'; while (isdigit(*name)) v = v * 10+ *name++ - '0'; p = buf3; while (v--) { if (*name == '@') { name++; *p++ = ':'; *p++ = ':'; } else *p++ = *name++; *p = 0; } if (manglenamecount < MAX_MANGLE_NAME_COUNT) strcpy(manglenames[manglenamecount++], buf2); if (buf3[0] == '#') { unmangTemplate(buf2, buf3, last); } else { strcpy(buf2, buf3); } p = buf2 + strlen(buf2); } strcpy(p, "::*"); buf3[0] = 0; if (name[0] == 'q') { name = unmang1(buf3, name, last, TRUE); } buf1[0] = 0; if (name[0] == '$') { name = unmang1(buf1, ++name, last, FALSE); } if (buf3[0]) { my_sprintf(buf, "%s((%s)%s)", buf1, buf2, buf3); } else { my_sprintf(buf, "%s %s", buf1, buf2); } break; case 'n': v = *name++ - '0'; if (v > 9) v -= 7; strcpy(buf, manglenames[v]); break; case 'v': strcpy(buf, tn_void); break; case 'F': strcpy(buf, tn_floatcomplex); break; case 'D': strcpy(buf, tn_doublecomplex); break; case 'G': strcpy(buf, tn_longdoublecomplex); break; case 'f': strcpy(buf, tn_float); break; case 'd': strcpy(buf, tn_double); break; case 'g': strcpy(buf, tn_longdouble); break; case 'i': strcpy(buf, tn_int); break; case 'N': strcpy(buf, "native int"); break; case 'l': strcpy(buf, tn_long); break; case 'L': strcpy(buf, tn_longlong); break; case 's': strcpy(buf, tn_short); break; case 'c': strcpy(buf, tn_char); break; case 'C': strcpy(buf, tn_wchar_t); break; case 'p': case 'P': if (*name == 'q' || *name == 'Q') { strcpy(buf, "(*"); if (cconst) strcat(buf, tn_const); if (cvol) strcat(buf, tn_volatile); strcat(buf, ")"); buf += strlen(buf); name = unmang1(buf, name, last, FALSE); if (clrqual) strcat(buf, "& "); if (crrqual) strcat(buf, "&& "); buf = buf + strlen(buf); } else { name--; name -= cvol + cconst; name = unmangptr(buf, name, last); buf = buf + strlen(buf); } break; case 'R': while (*name == 'x' || *name == 'y') { if (*name == 'y') cvol++; if (*name == 'x') cconst++; if (*name == 'r') clrqual++; if (*name == 'R') crrqual++; name++; } if (cconst) { strcat(buf, tn_const); } if (cvol) { strcat(buf , tn_volatile); } buf = buf + strlen(buf); if (*name == '#') { name = unmangTemplate(buf, name, last); } else { name = unmang1(buf, name, last, FALSE); } buf = buf + strlen(buf); *buf++ = '&'; *buf++ = '&'; *buf = 0; break; case 'r': while (*name == 'x' || *name == 'y') { if (*name == 'y') cvol++; if (*name == 'x') cconst++; if (*name == 'r') clrqual++; if (*name == 'R') crrqual++; name++; } if (cconst) { strcat(buf, tn_const); } if (cvol) { strcat(buf , tn_volatile); } buf = buf + strlen(buf); if (*name == '#') { name = unmangTemplate(buf, name, last); } else { name = unmang1(buf, name, last, FALSE); } buf = buf + strlen(buf); *buf++ = '&'; *buf = 0; break; case 'e': strcpy(buf, tn_ellipse); break; case 'E': name += 3; strcpy(buf, "decltype(...) "); break; case '#': buf += strlen(buf); name = unmangTemplate(buf, name-1, last); break; case 'a': strcpy(buf, "auto"); break; } return name; }