/** * Replaces tabs in the input stream with spaces according to the hardcoded * TAB_WIDTH. If there are mixed tabs and spaces, spaces are accounted for when * calculating the amount of spaces tabs have to be converted to. E.g. * * Example: * TAB_WIDTH = 4 * * Input: * ___\t (3 spaces and a tab) * * Output: * ____ (tab converted to (TAB_WIDTH - 3) spaces) * * Input: * \t * * Output: * ____ */ int main() { int c; // number of continuous spaces int cont_spaces = 0; while ((c = getchar()) != EOF) { if (c == ' ') { // every TAB_WIDTH spaces we reset the counter cont_spaces = (cont_spaces + 1) % TAB_WIDTH; putchar(c); } else if (c == '\t') { if (cont_spaces > 0) { // we have some spaces occupying the column, // only need to fill the rest print_spaces(TAB_WIDTH - cont_spaces); } else { print_spaces(TAB_WIDTH); } cont_spaces = 0; } else { cont_spaces = 0; putchar(c); } } return 0; }
static void open_tag(int level, const char *tag) { if(current_tag>level) { close_tag(level); printf(",\n"); } if(current_tag==level) { printf("\n"); print_spaces(current_tag); printf("},\n"); print_spaces(current_tag); printf("{\n"); } for(; current_tag<level; current_tag++) { if(tag) { print_spaces(current_tag+1); printf("\"%s\":\n", tag); } print_spaces(current_tag+1); printf("%c\n", current_tag%2?'{':'['); } }
void correction_inspect_indented(const Correction *correction, int32_t indentation) { printf("<#Correction\n"); print_spaces(indentation); printf(" layers: %d\n", correction->layers); print_spaces(indentation); printf(" biases:\n"); for(int32_t index = 0; index < correction->layers; index += 1) { print_spaces(indentation); printf(" %d: ", index); matrix_inspect_internal(correction->biases[index], indentation + 7); printf("\n"); } print_spaces(indentation); printf(" weights:\n"); for(int32_t index = 0; index < correction->layers; index += 1) { print_spaces(indentation); printf(" %d: ", index); matrix_inspect_internal(correction->weights[index], indentation + 7); if (index < correction->layers -1) printf("\n"); } printf(">"); }
void print_message_text (int level, const char *text) { if (level >= 0) { begin_line (); print_spaces (level); } while (*text) { if (!strncmp (text, "<br>", 4)) { end_line (); begin_line (); print_spaces (level); text += 4; } else if (!strncmp (text, "<", 4)) { add_char_line ('<'); text += 4; } else if (!strncmp (text, ">", 4)) { add_char_line ('>'); text += 4; } else { add_char_line (*(text ++)); } } if (line_pos) { end_line (); } }
boolean Thought_Bubble::dump(output_stream &stream, boolean just_prepare, boolean , boolean ) { if (just_prepare) return(FALSE); int dump_index = about_to_dump(this,stream); // rewritten on 020802 if (dump_index < 0) return(FALSE); // new on 051099 #if TT_DEBUG_ON if (tt_debug_mode == 160299 && !tt_dumping_to_test_equality_or_describe) { print_spaces(min(tt_debug_dump_depth,max_debug_depth),tt_error_file()); tt_error_file() << "About to dump "; print(tt_error_file()); tt_error_file() << endl; tt_debug_dump_depth++; }; #endif if (cubby != NULL) { // && cubby->pointer_to_leader() == this) { // changed to top_level_dump on 060201 since there should be no connections between stuff in the thought bubble and outside cubby->top_level_dump(stream); } else if (robot->pointer_to_body() != NULL) { // a bit of a hack to distinguish trained robots with empty thought bubbles from untrained ones stream.put(NOTHING_MARKER); } else { stream.put((char) NONE_GIVEN); }; #if TT_DEBUG_ON if (tt_debug_mode == 160299 && !tt_dumping_to_test_equality_or_describe) { print_spaces(min(tt_debug_dump_depth,max_debug_depth),tt_error_file()); tt_error_file() << "Finished dumping "; print(tt_error_file()); tt_error_file() << endl; tt_debug_dump_depth--; }; #endif return(TRUE); };
void print_identifier(identifier_t * node, int spaces) { if(node != NULL) { print_spaces(spaces); fprintf(stderr, "IDENT: %s\n", node->ident); } else { print_spaces(spaces); fprintf(stderr, "IDENT NOT FOUND!!!!"); } }
void print_user (int level, const struct user *user) { print_spaces (level); printf ("User #%d: %s %s. URL: https://vk.com/%s\n", user->id, user->first_name, user->last_name, user->screen_name); print_spaces (level + 1); printf ("Birthday %s. Sex %s.\n", user->birth, user->sex == 2 ? "male" : user->sex == 1 ? "female" : "unknown"); print_spaces (level + 1); printf ("Status %s\n", user->activity); }
/* Load a binary file into memory via the UART If its an elf file, copy it into the correct memory areas and execute it. */ void load_run( int type, unsigned int address ) { int file_size; /* testing tyhe boot loader itself in simulation */ if ( type == 2 ) { print_help(); _core_status(); print_spaces(16); _testpass(); } /* Load a file but don't run it */ else if ( type == 1 ) { /* Load a file using the xmodem protocol */ printf ("Send file w/ 1K Xmodem protocol from terminal emulator now...\n"); /* Destination, Destination Size */ file_size = xmodemReceive((char *) FILE_LOAD_BASE, FILE_MAX_SIZE); if (file_size < 0 || file_size > FILE_MAX_SIZE) { printf ("Xmodem error file size 0x%x \n", file_size); return; } printf("\nelf split\n"); elfsplitter(FILE_LOAD_BASE, file_size); } /* Hello world special start address - simulations only */ else if ( type == 4 ) { _jump_to_program(0x0080e400); } /* Load a binary file into memory */ else if ( type == 5 ) { /* Destination, Destination Size */ file_size = xmodemReceive((char *) address, FILE_MAX_SIZE); if (file_size < 0 || file_size > FILE_MAX_SIZE) { printf ("Xmodem error file size 0x%x \n", file_size); return; } } /* Run the program */ else { printf("j 0x%08x\n", JUMP_ADR); /* Flush the uart tx buffer with spaces */ print_spaces(16); printf("\n"); /* pc jump */ _jump_to_program(JUMP_ADR); _testpass(); } }
void serializeio_print_xdeltachecksum_obj (SerialXdeltaChecksum* obj, guint indent_spaces) { print_spaces (indent_spaces); g_print ("[ST_XdeltaChecksum]\n"); print_spaces (indent_spaces); g_print ("high = "); g_print ("%d\n", obj->high); print_spaces (indent_spaces); g_print ("low = "); g_print ("%d\n", obj->low); }
void serializeio_print_version0instruction_obj (SerialVersion0Instruction* obj, guint indent_spaces) { print_spaces (indent_spaces); g_print ("[ST_Version0Instruction]\n"); print_spaces (indent_spaces); g_print ("offset = "); g_print ("%d\n", obj->offset); print_spaces (indent_spaces); g_print ("length = "); g_print ("%d\n", obj->length); }
int dump_bytes(int col, char *msg,unsigned char *bytes,int length) { print_spaces(stderr,col); fprintf(stderr,"%s:\n",msg); for(int i=0;i<length;i+=16) { print_spaces(stderr,col); fprintf(stderr,"%04X: ",i); for(int j=0;j<16;j++) if (i+j<length) fprintf(stderr," %02X",bytes[i+j]); fprintf(stderr,"\n"); } return 0; }
/** * From Gordon's paper, the gen function. * @param pos The offset from an anchor square. * @param word The word generated so far. * @param rack The player's current rack. * @param arc An Arc to the initial state of the GADDAG. */ void gen(int pos, char* word, uint8_t* rack, ARC* arc, int spaces) { // If a letter L is on this square, go_on // What square am I on? #ifdef DEBUG_ print_spaces(spaces); printf("in gen, %d, Word: %s,", pos, word); print_rack(rack); #endif uint8_t blank_position = game_state.num_distinct_letters - 1; uint8_t i, k; char letter = is_letter( game_state.game_board[game_state.current_anchor_row] [game_state.current_anchor_col]); if (letter) { go_on(pos, letter, word, rack, next_arc(arc, letter), arc, spaces); } else if (letters_remain(rack)) { /* * TODO: for each letter ALLOWED ON THIS SQUARE, not just all * letters. */ // For all letters, except the blank. for (i = 0; i < game_state.num_distinct_letters - 1; i++) { if (rack[i] > 0) { #ifdef DEBUG_ print_spaces(spaces); printf("%d %cs\n", rack[i], i + 'A'); #endif // Letter (i + 'A') is on this rack. Temporarily remove it. rack[i]--; go_on(pos, i + 'A', word, rack, next_arc(arc, i + 'A'), arc, spaces + 1); // Re-add letter. rack[i]++; } } // Check if there is a blank. if (rack[blank_position] > 0) { // For each blank for (k = 0; k < game_state.num_distinct_letters; k++) { /** * TODO: For each letter the blank could be ALLOWED * ON THIS SQUARE. */ rack[blank_position]--; go_on(pos, k + 'A', word, rack, next_arc(arc, k + 'A'), arc, spaces + 1); rack[blank_position]++; } } } }
void serializeio_print_rsyncindex_obj (SerialRsyncIndex* obj, guint indent_spaces) { print_spaces (indent_spaces); g_print ("[ST_RsyncIndex]\n"); print_spaces (indent_spaces); g_print ("seg_len = "); g_print ("%d\n", obj->seg_len); print_spaces (indent_spaces); g_print ("file_len = "); g_print ("%d\n", obj->file_len); print_spaces (indent_spaces); g_print ("file_md5 = "); serializeio_print_bytes (obj->file_md5, 16); print_spaces (indent_spaces); g_print ("index = "); g_print ("{\n"); { gint i; for (i = 0; i < obj->index_len; i += 1) { print_spaces (indent_spaces); g_print ("%d:\n", i); print_spaces (indent_spaces); serializeio_print_rsyncindexelt_obj (& (obj->index[i]), indent_spaces + 2); print_spaces (indent_spaces); ; } } g_print ("}\n"); }
void serializeio_print_version0sourceinfo_obj (SerialVersion0SourceInfo* obj, guint indent_spaces) { print_spaces (indent_spaces); g_print ("[ST_Version0SourceInfo]\n"); print_spaces (indent_spaces); g_print ("md5 = "); serializeio_print_bytes (obj->md5, 16); print_spaces (indent_spaces); g_print ("real_md5 = "); serializeio_print_bytes (obj->real_md5, 16); print_spaces (indent_spaces); g_print ("length = "); g_print ("%d\n", obj->length); }
void serializeio_print_xdeltainstruction_obj (SerialXdeltaInstruction* obj, guint indent_spaces) { print_spaces (indent_spaces); g_print ("[ST_XdeltaInstruction]\n"); print_spaces (indent_spaces); g_print ("index = "); g_print ("%d\n", obj->index); print_spaces (indent_spaces); g_print ("offset = "); g_print ("%d\n", obj->offset); print_spaces (indent_spaces); g_print ("length = "); g_print ("%d\n", obj->length); }
static void si_dump_reg(FILE *file, unsigned offset, uint32_t value, uint32_t field_mask) { int r, f; for (r = 0; r < ARRAY_SIZE(sid_reg_table); r++) { const struct si_reg *reg = &sid_reg_table[r]; const char *reg_name = sid_strings + reg->name_offset; if (reg->offset == offset) { bool first_field = true; print_spaces(file, INDENT_PKT); fprintf(file, COLOR_YELLOW "%s" COLOR_RESET " <- ", reg_name); if (!reg->num_fields) { print_value(file, value, 32); return; } for (f = 0; f < reg->num_fields; f++) { const struct si_field *field = sid_fields_table + reg->fields_offset + f; const int *values_offsets = sid_strings_offsets + field->values_offset; uint32_t val = (value & field->mask) >> (ffs(field->mask) - 1); if (!(field->mask & field_mask)) continue; /* Indent the field. */ if (!first_field) print_spaces(file, INDENT_PKT + strlen(reg_name) + 4); /* Print the field. */ fprintf(file, "%s = ", sid_strings + field->name_offset); if (val < field->num_values && values_offsets[val] >= 0) fprintf(file, "%s\n", sid_strings + values_offsets[val]); else print_value(file, val, util_bitcount(field->mask)); first_field = false; } return; } }
void serializeio_print_rsyncindexelt_obj (SerialRsyncIndexElt* obj, guint indent_spaces) { print_spaces (indent_spaces); g_print ("[ST_RsyncIndexElt]\n"); print_spaces (indent_spaces); g_print ("md5 = "); serializeio_print_bytes (obj->md5, 16); print_spaces (indent_spaces); g_print ("cksum = "); g_print ("{\n"); serializeio_print_xdeltachecksum_obj (& obj->cksum, indent_spaces + 2); print_spaces (indent_spaces); ; g_print ("}\n"); }
void print_expression_list(expression_list_t * node, int spaces) { print_spaces(spaces); fprintf(stderr, "EXPR_LIST:\n"); for(; node != NULL; node = node->next) print_expression(node->expression, spaces + SP_INDENT); }
void print_subprogram_head(subprogram_head_t * node, int spaces) { print_spaces(spaces); fprintf(stderr, "SUBPROGRAM HEAD:\n"); print_identifier(node->ident, spaces + SP_INDENT); print_parameter_list(node->params, spaces + SP_INDENT); print_type(node->type, spaces + SP_INDENT); }
/* prints the contents of a cell. */ void print_cell(CELL_CONTENTS board[][BOARD_WIDTH], int row, int col) { switch (get_contents(board, row, col)) { case PEG : printf(COLOR_LINES); putchar('|'); putchar(' '); printf(COLOR_PEG); putchar('o'); putchar(' '); printf(COLOR_RESET); break; case HOLE : printf(COLOR_LINES); putchar('|'); putchar(' '); printf(COLOR_HOLE); putchar('.'); putchar(' '); printf(COLOR_RESET); break; case INVALID : print_spaces(board, row, col, CELL_LINE); break; } }
static void print_named_value(FILE *file, const char *name, uint32_t value, int bits) { print_spaces(file, INDENT_PKT); fprintf(file, COLOR_YELLOW "%s" COLOR_RESET " <- ", name); print_value(file, value, bits); }
int print_int(long long n, t_a *arg) { int len; static int sign = 0; static int depth = 0; depth++; len = 1; if (n < 0) { if (n == LLONG_MIN) { len = print_str("-9223372036854775808", arg); return (len); } n = -n; len++; sign = -1; } if (n > 9) len += print_int(n / 10, arg); if (n <= 9 && n >= 0) len += print_spaces(arg, depth, sign); print_char(n % 10 + '0'); sign = 0; depth = 0; return (len); }
void print_parameter_list(parameter_list_t * node, int spaces) { print_spaces(spaces); fprintf(stderr, "PARAMETER_LIST:\n"); for(; node != NULL; node = node->next) { print_identifier_list(node->idents, spaces + SP_INDENT); print_type(node->type, spaces + SP_INDENT); } }
void serializeio_print_xdeltaindex_obj (SerialXdeltaIndex* obj, guint indent_spaces) { print_spaces (indent_spaces); g_print ("[ST_XdeltaIndex]\n"); print_spaces (indent_spaces); g_print ("file_len = "); g_print ("%d\n", obj->file_len); print_spaces (indent_spaces); g_print ("file_md5 = "); serializeio_print_bytes (obj->file_md5, 16); print_spaces (indent_spaces); g_print ("index = "); g_print ("{\n"); { gint i; for (i = 0; i < obj->index_len; i += 1) { print_spaces (indent_spaces); g_print ("%d:\n", i); print_spaces (indent_spaces); serializeio_print_xdeltachecksum_obj (& (obj->index[i]), indent_spaces + 2); print_spaces (indent_spaces); ; } } g_print ("}\n"); }
static void print_the_symtab(symtab st){ base_record record; linelist line; char str[255]; int str_len=0; int i; print_spaces(st->level); printf("Scope level : %d para_mem : %d local_mem : %d\n ",st->level,st->para_mem,st->local_mem); print_spaces(st->level); printf("Variable Name Location Type Symbol_Type Array(size) Line Numbers\n"); print_spaces(st->level); printf("------------- -------- -------- ----------- ----------- ------------\n"); for(i=0;i<SIZE;i++){ if( (record=st->table[i]) != NULL){ print_spaces(st->level); while(record!=NULL){ line = record->lines; printf("%-14s " , record->name); printf("%-8d ",record->memloc); printf("%-8s ",ExpType_strs[record->type]); printf("%-11s ",record->symbol_type); if( !strcmp(record->symbol_type,"parameter") || !strcmp(record->symbol_type,"variable")){ if(record->attr.size>=0) sprintf(str,"yes(%d)",record->attr.size); else if(record->attr.size==-1) sprintf(str,"yes"); else sprintf(str,""); }else{ sprintf(str,""); } printf("%-11s ",str); str_len=0; sprintf(str,""); while(line != NULL){ //sprintf(str+str_len,"%d ",line->num); if(line->num){ printf("%d ",line->num); str_len=strlen(str); } line=line->next; } puts("");//printf("%-11s\n",str); record=record->next; } } } puts(""); }
// recursively prints the members of an expression virtual std::ostream& printExpMembers(std::ostream& os, unsigned depth=0) { os<< std::endl; print_spaces(os, depth+1); os << "Call: " << fident() << " "; if(_args) os << std::endl; if(_args) _args->printRec(os, depth+1); return os; }
static void close_tag(int level) { for(; current_tag>=level; current_tag--) { printf("\n"); print_spaces(current_tag); printf("%c", current_tag%2?']':'}'); } }
/* mvp 5-17-94 */ void print_consed_list_of_conditions(list * c, int indent) { for (; c != NIL; c = c->rest) { if (get_printer_output_column() >= COLUMNS_PER_LINE - 20) print("\n "); /* mvp 5-17-94 */ print_spaces(indent); print_condition(c->first); } }
static void cfg_field_print(struct cfg_field *self, int n_indent, FILE* stream) { size_t el=0; if (!self) return; // scalars not allowed to be "empty" if (CFG_TYPE_SCALAR == CFG_FIELD_TYPE(self) && 0==CFG_FIELD_ARR_SIZE(self)) return; print_spaces(n_indent, stream); fprintf(stream, "%s", CFG_FIELD_NAME(self)); fprintf(stream," %c ", CFG_ASSIGN); if (CFG_TYPE_ARRAY==CFG_FIELD_TYPE(self)) { fprintf(stream,"%c", CFG_ARRAY_BEG); for (el=0; el<CFG_FIELD_ARR_SIZE(self); el++) { cfg_field_print_data(self, el, stream); /* if (el < (CFG_FIELD_ARR_SIZE(self)-1)) { fprintf(stream,"%c", CFG_ARRAY_SEP); } */ if (el < (CFG_FIELD_ARR_SIZE(self)-1)) { fprintf(stream," "); } } fprintf(stream,"%c", CFG_ARRAY_END); } else if (CFG_TYPE_CFG == CFG_FIELD_TYPE(self)) { fprintf(stream,"%c\n", CFG_CFG_BEG); _cfg_print(CFG_FIELD_GET_SUB(self),n_indent+4,stream); print_spaces(n_indent, stream); fprintf(stream,"%c", CFG_CFG_END); } else { cfg_field_print_data(self, 0, stream); } fprintf(stream,"\n"); }
void get_uid_name(t_opts *options, struct stat fstats, int max_u) { struct passwd *uid_name; if (!G) { uid_name = getpwuid(fstats.st_uid); if (uid_name) { ft_putstr(uid_name->pw_name); ft_putstr(" "); print_spaces(max_u - ft_strlen(uid_name->pw_name)); } else { ft_putnbr(fstats.st_uid); ft_putstr(" "); print_spaces(max_u - get_nbr_length(fstats.st_uid)); } } }