static void outputParagraph( para *p, range *r, int lines ) { int i, j; fputspc( p->indent ); for( i = 0; i < lines - 1; i++ ) { if( f_mode & FMT_CENTRE ) { fputspc( r[i].left / 2 ); } for( j = r[ i ].start; j < r[ i + 1 ].start - 1; j++ ) { fputs( p->words[ j ].text, stdout ); fputspc( p->words[ j ].spc ); } fputs( p->words[ j ].text, stdout ); fputchar( '\n' ); fputspc( p->offset ); } if( f_mode & FMT_CENTRE ) { fputspc( r[lines - 1].left / 2 ); } for( j = r[lines - 1].start; j < p->len - 1; j++ ) { fputs( p->words[ j ].text, stdout ); fputspc( p->words[ j ].spc ); } fputs( p->words[ j ].text, stdout ); fputchar( '\n' ); }
static void PutString(char *pszStr, int bCR) { int rval; char *pszBS; if (g_bRedirected) { rval = (bCR ? puts(pszStr) : fputs(pszStr, stdout)); if (rval) { fputs("\nCannot write to stdout.\n", stderr); exit(-1); } } else { pszBS = strchr(pszStr, '\b'); while (pszBS) { *pszBS = '\0'; OutText(pszStr); fputchar('\b'); pszStr = pszBS + 1; pszBS = strchr(pszStr, '\b'); } OutText(pszStr); if (bCR) OutText("\r\n"); } }
int fputs(hal_uart_name_t u, const char *s) { fputstr(u, s); fputchar(u, '\n'); return 0; }
void main() { char c; PRS("De caracteres...<R> para terminar."); while ( (c=getch()) != 13) /* La funcion getch(), no hace eco */ fputchar (c); /* Escribe c en el video */ }
void uart0Printf(UINT8 *str) { UINT8 i; for(i=0;i<strlen(str);i++) fputchar(str[i]); }
int fputstr(hal_uart_name_t u, const char *s) { while (*s) fputchar(u, *s++); return 0; }
void print_hex(FILE* f, int n){ char* hex_tab = "0123456789ABCDEF"; char* s = (char*) &n; int i; for(i = 4; i >= 0; i--){ fputchar(f, hex_tab[(s[i] & 0xF0) >> 4]); fputchar(f, hex_tab[s[i] & 0x0F]); } }
int fnputstr(hal_uart_name_t u, const char *s, int len) { int x = 0; while (*s && (len > x++)) fputchar(u, *s++); return x; }
static int wait_signaled(HANDLE h, int seconds) { int i; for (i = 0; ; ) { if (WaitForSingleObject(h, 1000L) == WAIT_OBJECT_0) return 0; if (++i >= seconds) return -1; fputchar('.'); fflush(stdout); } }
void main() { char c; // Se ejecuta asi: // Oprimir caracter y <R> // Cuando se quiera finalizar, se orpime CTRL-Z while (!feof(stdin)) { c = fgetchar (); fputchar(c); } }
void print_decimal(FILE* f, int n){ if(n == 0){ fputchar(f, '0'); return; } if(n < 0){ fputchar(f, '-'); n *= -1; } char output[20]; int end = 0; while(n != 0){ char digit = n % 10; output[end++] = '0' + digit; n /= 10; } while(end >= 0) fputchar(f, output[--end]); }
static int wait_evt_running(int seconds, int exists) { int i; if (event_exists(EVT_RUNNING) == exists) return 0; for (i = 0; ; ) { Sleep(1000); if (event_exists(EVT_RUNNING) == exists) return 0; if (++i >= seconds) return -1; fputchar('.'); fflush(stdout); } }
static void formatFile( FILE *fp, int width, int offset ) { int ret; para p = { NULL, 0, 0, 0, 0 }; int oldos = 0; int erros = -1; wordlist *list = NULL; expandParagraph( &p, DEF_PARA_LEN ); for( ; ; ) { ret = getParagraph( fp, &p, &list ); if( ret & OUT_OF_MEM ) { if( erros != p.len ) { trimParagraph( &p ); erros = p.len; continue; } else if( p.len == 0 ) { Die( "fmt: out of memory error\n" ); } } if( p.len != 0 ) { if( p.indent <= oldos ) { // keep track of offsets & indents p.indent = oldos; // in case of out of mem. errors p.offset = oldos; } oldos = p.offset; formatParagraph( &p, width, offset, ret & OUT_OF_MEM ); } if( ret & END_LINE ) { // no need to format blank line fputchar( '\n' ); oldos = 0; } resetParagraph( &p ); resetWordlist( list ); if( ret & END_FILE ) { break; } erros = -1; } free( p.words ); // free the paragraph space freeWordlist( list ); // free the text space }
int fprintf(FILE* f, const char* fmt, ...){ va_list params; va_start(params, fmt); int arg = 0; while(*fmt != '\0'){ if(*fmt == '%'){ fmt++; char op = *fmt; switch(op){ case 'd': case 'i': print_decimal(f, va_arg(params, int)); break; case 'x': case 'X': print_hex(f, va_arg(params, int)); break; case 'c': fputchar(f, va_arg(params, int)); break; case 's': fprint(f, va_arg(params, char*)); break; default: return -1; } } else fputchar(f, *fmt); fmt++; } return 0; }
// \n inline void fnewline(hal_uart_name_t u) { fputchar(u, '\n'); }
static void fputspc( int num ) { for( ; num > 0; num-- ) { // simply output a given number of fputchar( ' ' ); // spacees } }