static void outnum(unsigned int num, const long base) { char* cp; int negative; char outbuf[32]; const char digits[] = "0123456789ABCDEF"; /* Check if number is negative */ /* NAK 2009-07-29 Negate the number only if it is not a hex value. */ if ((int)num < 0L && base != 16L) { negative = 1; num = -num; } else negative = 0; /* Build number (backwards) in outbuf */ cp = outbuf; do { *cp++ = digits[(int)(num % base)]; } while ((num /= base) > 0); if (negative) *cp++ = '-'; *cp-- = 0; /* Move the converted number to the buffer and */ /* add in the padding where needed. */ len = strlen(outbuf); padding(!left_flag); while (cp >= outbuf) out_char(*cp--); padding(left_flag); }
static void outnum( const long n, const long base, params_t *par) { charptr cp; int negative; char outbuf[32]; const char digits[] = "0123456789ABCDEF"; unsigned long num; /* Check if number is negative */ if (base == 10 && n < 0L) { negative = 1; num = -(n); } else{ num = (n); negative = 0; } /* Build number (backwards) in outbuf */ cp = outbuf; do { *cp++ = digits[(int)(num % base)]; } while ((num /= base) > 0); if (negative) *cp++ = '-'; *cp-- = 0; /* Move the converted number to the buffer and */ /* add in the padding where needed. */ par->len = strlen(outbuf); padding( !(par->left_flag), par); while (cp >= outbuf) OS_PUTCHAR( *cp--); padding( par->left_flag, par); }
void A3::p_localtime() { while(1) { current_time = time(0); lcl_tm = localtime(¤t_time); cout << getpid() << " - Current Time - " << padding(lcl_tm->tm_hour,2) << ":" << padding(lcl_tm->tm_min,2) << ":" << padding(lcl_tm->tm_sec,2) << endl; sleep(1); } }
void print_rule(const EtalisEventNode* temp_event) { padding(' ',4) ; printf("New Rule ->\n"); padding(' ',14); printf("+Label: %s\n",temp_event->childNode->label); padding(' ',14); printf("+Complex Event: %s/%d\n",temp_event->event.name,temp_event->event.arity); padding(' ',14); printf("+Final Operator: %s\n",temp_event->childNode->name); if(temp_event->childNode->condition != NULL) { padding(' ',14); printf("+Node Condition: %s\n",temp_event->childNode->condition); } if(temp_event->childNode->window_size != 0) { padding(' ',14); printf("+Sliding Window Size: %f sec\n",temp_event->childNode->window_size); } else { padding(' ',14); printf("+Sliding Window Size: Unlimited\n"); } padding(' ',14); printf("++@l-Event: %s/%d\n",temp_event->childNode->leftChild->event.name,temp_event->childNode->leftChild->event.arity); if(temp_event->childNode->op_type == binary) { padding(' ',14); printf("++@r-Event: %s/%d\n",temp_event->childNode->rightChild->event.name,temp_event->childNode->rightChild->event.arity); } }
void printTree(Node* root, int depth) { if (root == NULL) { padding(depth); printf("~\n"); } else { printTree(root->right, depth + 1); padding(depth); printf("%d\n", root->data); printTree(root->left, depth + 1); } }
void A3::p_countdown() { int min; int seconds; while(runtime >= 0) { seconds = runtime % 60; min = (runtime / 60) % 60; cout << getpid() << " - Countdown Timer - " << padding(min, 2) << ":" << padding(seconds, 2) << endl; runtime--; sleep(1); } }
void unit_test_int(const char* msg, long long attendu, long long obtenu) { int len = strlen(msg); printf("%s", msg); if (attendu == obtenu) { padding(80 - len - 4); printf("[OK]\n"); } else { padding(80 - len - 7); printf("[ERROR]\n"); printf("Attendu : %ld, Obtenu : %ld\n", attendu, obtenu); } }
QPainterPath CompassFloatItem::backgroundShape() const { QRectF contentRect = this->contentRect(); QPainterPath path; int fontheight = QFontMetrics( font() ).ascent(); int compassLength = static_cast<int>( contentRect.height() ) - 5 - fontheight; path.addEllipse( QRectF( QPointF( marginLeft() + padding() + ( contentRect.width() - compassLength ) / 2, marginTop() + padding() + 5 + fontheight ), QSize( compassLength, compassLength ) ).toRect() ); return path; }
void displayTree(Node* root, int depth){ if (root == NULL) { padding (' ', depth); printf("-\n"); } else { displayTree(root->right, depth+1); padding(' ', depth); printf ( "%d\n", root->data); displayTree(root->left, depth+1); } }
void unit_test_str(const char* msg, const char* attendu, const char* obtenu) { int len = strlen(msg); printf("%s", msg); if (strcmp(attendu, obtenu) == 0) { padding(80 - len - 4); printf("[OK]\n"); } else { padding(80 - len - 7); printf("[ERROR]\n"); printf("Attendu : %s, Obtenu : %s\n", attendu, obtenu); } }
void structure(BST* root, int level) { int i; if (root == NULL) { padding('\t', level); puts("~"); } else { structure(root->right, level+1); padding('\t', level); printf("%d\n", root->data); structure(root->left, level+1); } }
// Recursive function used with printTree. Provided for you; do not modify. You should // not call this function directly. Instead, call printTree. void displayTree(Tree* root, int depth) { if (root == NULL) { padding(' ', depth); printf("-\n"); return; } displayTree(root->left, depth+4); padding(' ', depth); printf("%d\n", root->data); displayTree(root->right, depth+4); }
std::string DatFile::serialise(const std::string &key, const std::string &value) { std::string output; output.append(key); output.append(padding(1)); output.append(std::string(1,char(2))); output.append(padding(1)); output.append(nullPad(value)); if(output.length() > 128) output = output.substr(0,128); else output.append(padding(128 - output.length())); return output; }
void printBaum ( struct baum *root, int level ) { int i; if ( root == NULL ) { padding ( '\t', level ); puts ( "~" ); } else { printBaum ( root->rechts, level + 1 ); padding ( '\t', level ); printf ( "%d\n", root->wert ); printBaum ( root->links, level + 1 ); } }
static void outs( char * lp) { /* pad on left if needed */ len = strlen((const char *)lp); padding( !left_flag); /* Move string to the buffer */ while (*lp && num2--) out_char( *lp++); /* Pad on right if needed */ len = strlen((const char *)lp); padding( left_flag); }
QPainterPath ProgressFloatItem::backgroundShape() const { QPainterPath path; if ( active() ) { // Circular shape if active, invisible otherwise QRectF rect = contentRect(); qreal width = rect.width(); qreal height = rect.height(); path.addEllipse( marginLeft() + 2 * padding(), marginTop() + 2 * padding(), width, height ); } return path; }
static void outnum( const s32 n, const s32 base, struct params_s *par) { charptr cp; s32 negative; s32 i; char8 outbuf[32]; const char8 digits[] = "0123456789ABCDEF"; u32 num; for(i = 0; i<32; i++) { outbuf[i] = '0'; } /* Check if number is negative */ if ((base == 10) && (n < 0L)) { negative = 1; num =(-(n)); } else{ num = n; negative = 0; } /* Build number (backwards) in outbuf */ i = 0; do { outbuf[i] = digits[(num % base)]; i++; num /= base; } while (num > 0); if (negative != 0) { outbuf[i] = '-'; i++; } outbuf[i] = 0; i--; /* Move the converted number to the buffer and */ /* add in the padding where needed. */ par->len = (s32)strlen(outbuf); padding( !(par->left_flag), par); while (&outbuf[i] >= outbuf) { #ifdef STDOUT_BASEADDRESS outbyte( outbuf[i] ); i--; #endif } padding( par->left_flag, par); }
static void outs( charptr lp, params_t *par) { /* pad on left if needed */ par->len = strlen( lp); padding( !(par->left_flag), par); /* Move string to the buffer */ while (*lp && (par->num2)--) OS_PUTCHAR( *lp++); /* Pad on right if needed */ /* CR 439175 - elided next stmt. Seemed bogus. */ /* par->len = strlen( lp); */ padding( par->left_flag, par); }
void structure ( struct treeNode *temp, int level ) { int i; if ( temp == NULL ) { padding ( '\t', level ); puts ( "~" ); } else { structure ( temp->right, level + 1 ); padding ( '\t', level ); printf ( "%d\n", temp->data ); structure ( temp->left, level + 1 ); } }
static void outnum1( const s64 n, const s32 base, params_t *par) { charptr cp; s32 negative; s32 i; char8 outbuf[64]; const char8 digits[] = "0123456789ABCDEF"; u64 num; for(i = 0; i<64; i++) { outbuf[i] = '0'; } /* Check if number is negative */ if ((par->unsigned_flag == 0) && (base == 10) && (n < 0L)) { negative = 1; num =(-(n)); } else { num = (n); negative = 0; } /* Build number (backwards) in outbuf */ i = 0; do { outbuf[i] = digits[(num % base)]; i++; num /= base; } while (num > 0); if (negative != 0) { outbuf[i] = '-'; i++; } outbuf[i] = 0; i--; /* Move the converted number to the buffer and */ /* add in the padding where needed. */ par->len = (s32)strlen(outbuf); padding( !(par->left_flag), par); while (&outbuf[i] >= outbuf) { outbyte( outbuf[i] ); i--; } padding( par->left_flag, par); }
static int write_vertical_file(state *s) { int32_t i,j, bytes_read = 0; off_t location; int32_t offset = (s->image_width * s->image_height) - s->image_width; unsigned char c; #ifdef DEBUG print_status ("offset %"PRId32" length %"PRId32" width %"PRId32"\n", offset, s->input_length, s->image_width); #endif for (i = 0 ; i < s->image_height ; ++i) { for (j = 0 ; j < s->image_width ; ++j) { if (s->direction) { location = offset - (s->image_width * i) + j; if (location < s->input_length) { #ifdef DEBUG print_status ("bytes read %06"PRId32" seeking to %06"PRId32, bytes_read, location); #endif if (fseeko(s->in_handle, location, SEEK_SET)) { return TRUE; } c = fgetc(s->in_handle); } else { #ifdef DEBUG print_status ("padding"); #endif // We pad the image with black when necessary c = padding(); } } else { if (bytes_read < s->input_length) c = fgetc(s->in_handle); else c = padding(); } ++bytes_read; write_byte(s, c); } if (s->direction) pad_image(s,s->image_width); } return FALSE; }
/** * \brief run all of the test cases in this test set and output their * name and success/failure to stderr. */ bool run() { bool okay = true; size_t maxPad = this->maxNameLength(); for (size_t i = 0; i < tests.size(); ++i) { assert(tests[i]->getTestName().size() <= maxPad); size_t pad = maxPad - tests[i]->getTestName().size(); std::string padding (pad, ' '); std::cout << tests[i]->getTestName() << " ... " << padding; try { tests[i]->runTest(); std::cout << "[PASSED]" << std::endl; } catch (const TinyTestException &e) { if (std::string(e.what()).empty()) std::cout << "[FAILED] [Reason: UNKNOWN]" << std::endl; else std::cout << "[FAILED] [Reason: " << e.what() << "]" << std::endl; okay = false; } catch (const std::exception& ex) { if (std::string(ex.what()).empty()) std::cout << "[FAILED] [Reason: An unexpected exception was thrown " << "-- no further details]" << std::endl; else std::cout << "[FAILED] [Reason: An unexpected exception was thrown " << "details: " << ex.what() << "]" << std::endl; okay = false; } catch (...) { std::cout << "[FAILED] [Reason: An unexpected exception was thrown " << "-- no further details]" << std::endl; okay = false; } } return okay; }
std::string CBC_Mode::name() const { if(m_padding) return cipher().name() + "/CBC/" + padding().name(); else return cipher().name() + "/CBC/CTS"; }
// Fits strings into a single padded string string justifyString(vector<string> A, int stringLength, int totalLength) { string justifiedString = ""; if (A.size() == 1) { // Pad spaces at end of A[0] string padding(totalLength-stringLength, ' '); justifiedString = A[0] + padding; } else { int padding = (totalLength-stringLength)/(A.size()-1); int offset = (totalLength-stringLength)%(A.size()-1); //cout<<padding<<endl<<offset<<endl; for (int i = 0; i < A.size()-1; i++) { int paddingLength = padding; if (offset>0) { paddingLength++; offset--; } string padding(paddingLength, ' '); justifiedString = justifiedString + A[i] + padding; } justifiedString += A[A.size()-1]; } //cout<<justifiedString<<endl; return justifiedString; }
int my_printf(char *format, ...){ struct flag result; int padding_ok; va_start (va, format); for (int i = 0; format[i]; i++){ if(format[i] == '%'){ i++; if((format[i] == '#' && format[i+1] == 'd')) i++; else if((format[i] == '#' && format[i+1] == 'x')){ my_puts("0x"); i++; }else if((format[i] == '#' && format[i+1] == 'o')){ my_puts_nbr(0); i++; }else if((format[i] == '0' && format[i+1] == 'd')) i++; else if((format[i] == '+' && format[i+1] == 'd')){ my_puts("+"); i++; } else if((format[i] == '-' && format[i+1] == 'd')) i++; padding_ok = padding(format[i]); if(padding_ok == 1) i++; result = search_index_flags(format[i]); select_function(format[i], va, result); } else my_puts_char(format[i]); } va_end (va); return 0; }
void structure( Node *root, int level ) { int i; if ( root == NULL ) { padding ( '\t', level ); puts ( "~" ); } else { structure ( root->right, level + 1 ); padding ( '\t', level ); // if(root->l==0) // printf("here\n"); printf ( "[%d,%d)\n", root->l,root->u ); structure ( root->left, level + 1 ); } }
void wx_entry_print(entry e, int depth) { wxString padding(wxT("")); switch(e.type()) { case entry::int_t: wxLogMessage(wxT("print:")+padding.Pad(depth, '\t')+wxString::Format(_T("int: %u"), e.integer())); break; case entry::string_t: wxLogMessage(wxT("print:")+padding.Pad(depth, '\t')+wxString::Format(wxT("str-len: %u "), e.string().length())+wxT("str: ")+wxString(e.string().c_str(), wxConvUTF8)); break; case entry::list_t: for (entry::list_type::const_iterator i = e.list().begin(); i != e.list().end(); ++i) { wx_entry_print(*i, depth+1); } break; case entry::dictionary_t: for (entry::dictionary_type::const_iterator i = e.dict().begin(); i != e.dict().end(); ++i) { wx_entry_print(i->first, depth+1);// write key wx_entry_print(i->second, depth+1);// write value } break; default: break; } }
QRect calculateBoundingRect(const std::unordered_map<core::MapNode*, QPoint>& nodesPos, int tileSize) { if (nodesPos.size() == 0) return QRect(0, 0, 0, 0); QPoint bpos = nodesPos.begin()->second; QPoint topLeft = bpos; QPoint bottomRight = bpos; for (const auto& element : nodesPos) { QPoint pos = element.second; topLeft.setX(std::min(pos.x(), topLeft.x())); bottomRight.setX(std::max(pos.x(), bottomRight.x())); topLeft.setY(std::min(pos.y(), topLeft.y())); bottomRight.setY(std::max(pos.y(), bottomRight.y())); } // x,y is the top-left corner of the node so we need to add the tile // size bottomRight += QPoint(tileSize, tileSize); // leave a half-tile padding QPoint padding(tileSize / 2, tileSize / 2); topLeft -= padding; bottomRight += padding; return QRect(topLeft, bottomRight); }
static int write_horizontal_file(state *s) { int32_t i,j,location; unsigned char c; for (i = 0 ; i < s->image_width ; i++) { for (j = 0 ; j < s->image_height ; ++j) { if (s->direction) location = (s->image_width * (j+1)) - (i+1); else location = s->image_height * (s->image_width - i -1) + j; if (location < s->input_length) { fseeko(s->in_handle,location,SEEK_SET); c = fgetc(s->in_handle); } else { // We pad the image with black when necessary c = padding(); } write_byte(s,c); } pad_image(s,s->image_height); } return FALSE; }
void CRIFFChunkTreeDlg::RenderItem(STREAM* file, HTREEITEM _hItem, int iLevel) { HTREEITEM hItem = _hItem; std::string newLine; newLine.push_back(0x0D); newLine.push_back(0x0A); std::string padding(2 * iLevel, ' '); const char* ptrPadding = padding.c_str(); char textBuffer[1024]; while (hItem) { TVITEMEX item; memset(textBuffer, 0, 1024); memset(&item, 0, sizeof(item)); item.hItem = hItem; item.cchTextMax = 1023; item.pszText = textBuffer; item.mask = TVIF_TEXT | TVIF_HANDLE; TreeView_GetItem(m_Tree, &item); file->Write(const_cast<char*>(ptrPadding), padding.size()); file->Write(const_cast<char*>(item.pszText), strlen(item.pszText)); file->Write(const_cast<char*>(newLine.c_str()), 2); RenderItem(file, m_Tree.GetChildItem(hItem), iLevel+1); hItem = m_Tree.GetNextSiblingItem(hItem); } }