本文整理汇总了C++中pad函数的典型用法代码示例。如果您正苦于以下问题:C++ pad函数的具体用法?C++ pad怎么用?C++ pad使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pad函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hexdump
void
hexdump(FILE *f, int indent, const char *p, int len)
{
const unsigned char *cp = (const unsigned char *)p;
char hex[16 * 3 + 1], *hp, ascii[16 + 1], *ap;
int i, c;
while (len) {
hp = hex;
ap = ascii;
for (i = 0; len && i < 16; i++) {
c = *cp++;
len--;
hp += sprintf(hp, "%02x ", c);
*ap++ = c < 127 && c >= 32 ? c : '.';
}
*ap = 0;
fprintf(f, "%s%-48s |%-16s|\n", pad(indent), hex, ascii);
}
}
示例2: printObject
void printObject(Object* obj, int indent) {
switch (obj->kind) {
case OBJ_CONSTANT:
pad(indent);
printf("Const %s = ", obj->name);
printConstantValue(obj->constAttrs->value);
break;
case OBJ_TYPE:
pad(indent);
printf("Type %s = ", obj->name);
printType(obj->typeAttrs->actualType);
break;
case OBJ_VARIABLE:
pad(indent);
printf("Var %s : ", obj->name);
printType(obj->varAttrs->type);
break;
case OBJ_PARAMETER:
pad(indent);
if (obj->paramAttrs->kind == PARAM_VALUE)
printf("Param %s : ", obj->name);
else
printf("Param VAR %s : ", obj->name);
printType(obj->paramAttrs->type);
break;
case OBJ_FUNCTION:
pad(indent);
printf("Function %s : ", obj->name);
printType(obj->funcAttrs->returnType);
printf("\n");
printScope(obj->funcAttrs->scope, indent + 4);
break;
case OBJ_PROCEDURE:
pad(indent);
printf("Procedure %s\n", obj->name);
printScope(obj->procAttrs->scope, indent + 4);
break;
case OBJ_PROGRAM:
pad(indent);
printf("Program %s\n", obj->name);
printScope(obj->progAttrs->scope, indent + 4);
break;
}
}
示例3: encode_sequence
static void encode_sequence(const char *plain, int len, char *coded) {
assert(len >= 0 && len <= 5);
for (int block = 0; block < 8; block++) {
int octet = get_octet(block);
int junk = get_offset(block);
if (octet >= len) {
pad(&coded[block], 8 - block);
return;
}
char c = shift_right(plain[octet], junk);
if (junk < 0 && octet < len - 1) {
c |= shift_right(plain[octet+1], 8 + junk);
}
coded[block] = encode_char(c);
}
}
示例4: if
void vcat_pic::display(std::ostream &os, ht_sz row, bool do_pad) const
{
wd_sz w = 0;
if(row < top->height())
{
// we are in the top subpicture
top->display(os,row,do_pad);
w = top->width();
}
else if(row < height())
{
// we are in the bottom subpicture
bottom->display(os,row-top->height(),do_pad);
w = bottom->width();
}
if(do_pad)
{
pad(os,w,width());
}
}
示例5: putop
void putop(int op)
{
int i;
int seg;
i = 0;
while( opl[i].s )
{
if( opl[i].ov == (op & 255))
{
//seg = op & 0xFF00;
//if (seg != 0) {
// fprintf(output, "%s:", segstr(op));
//}
ofs.write(pad(opl[i].s));
return;
}
++i;
}
printf("DIAG - illegal opcode.\n");
}
示例6: allocateMemAboveBase
void* IATModifier::allocateMemAboveBase(void* baseAddress, size_t size) {
try {
MEMORY_BASIC_INFORMATION mbi;
for (char* currentAddress = (char*)baseAddress;; currentAddress = (char*)mbi.BaseAddress + mbi.RegionSize) {
mbi = process_.queryMemory(currentAddress);
if (mbi.State != MEM_FREE) continue;
// Walk memory region in allocation granularity steps.
char* bruteForce = (char*)pad((unsigned int)currentAddress, 0xFFFF);
while (bruteForce < (char*)mbi.BaseAddress + mbi.RegionSize) {
try {
process_.allocMem(size, bruteForce, MEM_RESERVE | MEM_COMMIT);
return bruteForce;
}catch (MemoryAllocationException) {
}
bruteForce += 0x10000;
}
}
} catch (const MemoryQueryException&) {
return NULL;
}
}
示例7: write_bmp
void write_bmp(const BMP<DIB, I, D>& bmp, std::ostream& os)
{
typedef typename BMP<DIB, I, D>::color_type C;
unsigned int l = bmp.dib_h.width * (bmp.dib_h.bpp / 8);
unsigned int rowsize = ((bmp.dib_h.bpp * bmp.dib_h.width + 31) / 32) * 4;
std::vector<D> buf(bmp.dib_h.width);
std::vector<std::uint8_t> pad(rowsize - l);
I i(bmp.iter);
os << aux::write_to(bmp.bmp_h);
os << aux::write_to(bmp.dib_h);
for(int h = 0 ; h < bmp.dib_h.height ; ++h)
{
aux::transform_n(i, bmp.dib_h.width, buf.begin(), [](const C& c) { return static_cast<D>(c); });
os << aux::write_to(*buf.begin(), l);
os << aux::write_to(*pad.begin(), pad.size());
}
}
示例8: emit_value
/* emit_value - emits an initialization for the type given by ty */
static int emit_value(int lc, Type ty, ...) {
Value v;
va_list ap;
va_start(ap, ty);
if (lc == 0)
maxalign = 0;
lc = pad(ty->align, lc);
switch (ty->op) {
case INT: v.i = va_arg(ap, long); break;
case UNSIGNED: v.u = va_arg(ap, unsigned long); break;
case FLOAT: v.d = va_arg(ap, long double); break;
case POINTER:
defpointer(va_arg(ap, Symbol));
return lc + ty->size;
default: assert(0);
}
va_end(ap);
(*IR->defconst)(ty->op, ty->size, v);
return lc + ty->size;
}
示例9: dumpregs
void dumpregs(struct TrapData *td)
{ int i;
XIOdebug("Registers dump:\n");
XIOdebug("Trapdata is at %X\n",(int)td);
for( i = 0; i< 32; i+=4)
{ int j;
for( j = i; j < i+4; j++)
{ char * f;
int fwidth;
f = j< 10? "r%d = %X":"r%d = %X";
fwidth = XIOdebug(f,j,td->intregs[j]);
pad(17,fwidth);
}
XIOdebug("\n");
}
XIOdebug("psr = %X\n",td->PSR);
XIOdebug("db = %X\n",td->DB);
XIOdebug("dirbase = %X\n",td->DIRBASE);
XIOdebug("fir = %X\n",td->FIR);
XIOdebug("fsr = %X\n",td->FSR);
}
示例10: elf32DumpDynamic
void
elf32DumpDynamic(FILE *f, const Elf32_Dyn *dyn, int indent)
{
const char *padding = pad(indent);
static const char *tagNames[] = {
"DT_NULL",
"DT_NEEDED",
"DT_PLTRELSZ",
"DT_PLTGOT",
"DT_HASH",
"DT_STRTAB",
"DT_SYMTAB",
"DT_RELA",
"DT_RELASZ",
"DT_RELAENT",
"DT_STRSZ",
"DT_SYMENT",
"DT_INIT",
"DT_FINI",
"DT_SONAME",
"DT_RPATH",
"DT_SYMBOLIC",
"DT_REL",
"DT_RELSZ",
"DT_RELENT",
"DT_PLTREL",
"DT_DEBUG",
"DT_TEXTREL",
"DT_JMPREL",
"DT_BIND_NOW"
};
#ifndef DT_COUNT
#define DT_COUNT (sizeof tagNames / sizeof tagNames[0])
#endif
fprintf(f, "%stag: %d (%s)\n", padding, dyn->d_tag,
dyn->d_tag >= 0 && dyn->d_tag <= DT_COUNT ?
tagNames[dyn->d_tag] : "(unknown)");
fprintf(f, "%sword/addr: %d (%x)\n",
padding, dyn->d_un.d_val, dyn->d_un.d_val);
}
示例11: putop
void putop(Instruction *insn,int op, int len)
{
int i;
char buf[100];
i = 0;
// while( opl[i].mnem )
// {
// if( opl[i].opcode == (op & 0x1FF))
// {
//seg = op & 0xFF00;
//if (seg != 0) {
// fprintf(output, "%s:", segstr(op));
//}
if (len) {
if (len <= 16) {
switch(len) {
case 1: sprintf_s(buf, sizeof(buf), "%s.b", insn->mnem); break;
case 2: sprintf_s(buf, sizeof(buf), "%s.c", insn->mnem); break;
case 4: sprintf_s(buf, sizeof(buf), "%s.h", insn->mnem); break;
case 8: sprintf_s(buf, sizeof(buf), "%s", insn->mnem); break;
}
}
else {
if (len != 'w' && len!='W')
sprintf_s(buf, sizeof(buf), "%s.%c", insn->mnem, len);
else
sprintf_s(buf, sizeof(buf), "%s", insn->mnem);
}
}
else
sprintf_s(buf, sizeof(buf), "%s", insn->mnem);
ofs.write(pad(buf));
return;
// }
// ++i;
// }
printf("DIAG - illegal opcode (%d).\n", op);
}
示例12: printEntries
void printEntries(std::ostream &o, const std::vector<Entry *> &entries, const std::string &indent, double parent_time) {
if (parent_time <= 0.0) {
parent_time = 0.0;
for (size_t i = 0; i < entries.size(); ++i) {
parent_time += entries[i]->time;
}
}
double t_tot = 0.0;
for (size_t i = 0; i < entries.size(); ++i) {
const Entry *entry = entries[i];
std::ostringstream r;
r << indent;
std::string str = names[entry->id];
if (str.empty()) {
r << "(" << entry->id << ")";
} else {
r << str;
}
r << " ";
std::string pad(r.str().size(), ' ');
r << " - exectime: " << entry->time << "s (" << (entry->time * 100.0 / parent_time) << "%)" << std::endl;
if (entry->allocTotal || entry->memoryDiff) {
r << pad << " - alloc: " << formatMemory(entry->allocTotal) << " delta: " << formatMemory(entry->memoryDiff) << std::endl;
r << pad << " - alloc blks:";
for (int i = 0; i < 32; i++) { if (entry->delta_blk_cnt_total[i]) r << ' ' << ((1 << (i - 1)) + 1) << '-' << (1 << i) << ':' << entry->delta_blk_cnt_total[i]; }
r << std::endl;
r << pad << " - delta blks:";
for (int i = 0; i < 32; i++) { if (entry->delta_blk_cnt_curr[i]) r << ' ' << ((1 << (i - 1)) + 1) << '-' << (1 << i) << ':' << entry->delta_blk_cnt_curr[i]; }
r << std::endl;
}
o << r.str();
t_tot += entry->time;
if (entry->children.size()) printEntries(o, entry->children, indent + " ", entry->time);
}
if (t_tot < parent_time) {
o << indent << "*** unaccounted: " << (parent_time - t_tot) << "s (" << (100.0 - t_tot * 100.0 / parent_time) << "%)" << std::endl;
}
}
示例13: cmd_score
mixed cmd_score(string cmd, string str, object actor){
mapping stats;
int i;
string *attributes;
stats = actor->query_stats();
attributes = map_indices(stats);
i = sizeof(attributes);
str = actor->query_Name() + "\n";
while(i--){
str += "%^BOLD%^%^CYAN%^"+pad(capitalize(attributes[i])+": ", 15)+"%^RESET%^"+stats[attributes[i]]+"\n";
}
#ifdef ASTARIA_CLONE
str += "hp "+actor->query_health()+" / "+actor->query_max_health()+"\n";
#else
str += actor->query_diagram();
#endif
actor->message(str);
return 1;
}
示例14: modulePrefix
static inline std::string modulePrefix(module_t m, message_t msgType)
{
if(m == MODULES_ALL) {
switch(msgType) {
case MSG_TRACE:
return "[trace] ";
case MSG_DEBUG:
return "[debug] ";
case MSG_INFO:
return "[info] ";
case MSG_WARNING:
return "[warning] ";
case MSG_ERROR:
return "[error] ";
case MSG_FATAL:
return "[fatal] ";
default:
return "[...] ";
}
}
return pad(std::string(1, '[') + moduleToString(m) + "] ");
}
示例15: pad
extern void *__construct_new_array(void *block,ConstructorDestructor ctor,ConstructorDestructor dtor,size_t size,size_t n)
{
char *ptr;
if((ptr=(char *)block)!=0L)
{
size_t *p = (size_t *)ptr;
// store number of allocated objects and size of one object at the beginnig of the allocated block
p[0]=size;
p[1]=n;
ptr+=ARRAY_HEADER_SIZE;
if(ctor)
{ // call constructor to initialize array
__partial_array_destructor pad(ptr,size,n,dtor);
char *p;
for(pad.i=0,p=(char *)ptr; pad.i<n; pad.i++,p+=size) CTORCALL_COMPLETE(ctor,p);
}
}
return ptr; // return pointer to first object;
}