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 unmount_disks(void) { /* better to use umount directly because it may be smarter than us */ int pid; int result; int status; sync(); if ((pid = fork()) < 0) { my_puts(_("Cannot fork for umount, trying manually.")); unmount_disks_ourselves(); return; } if (!pid) { execl(_PATH_UMOUNT, UMOUNT_ARGS, NULL); /* need my_printf instead of my_puts here */ freopen(_PATH_CONSOLE, "w", stdout); printf(_("Cannot exec %s, trying umount.\n"), _PATH_UMOUNT); fflush(stdout); execlp("umount", UMOUNT_ARGS, NULL); my_puts(_("Cannot exec umount, giving up on umount.")); exit(0); } while ((result = wait(&status)) != -1 && result != pid) ; my_puts(_("Unmounting any remaining filesystems...")); unmount_disks_ourselves(); }
void swap_off(void) { /* swapoff esp. swap FILES so the underlying partition can be unmounted. It you don't have swapoff(1) or use mount to add swapspace, this may not be necessary, but I guess it won't hurt */ int pid; int result; int status; sync(); if ((pid = fork()) < 0) { my_puts(_("Cannot fork for swapoff. Shrug!")); return; } if (!pid) { execl("/sbin/swapoff", SWAPOFF_ARGS, NULL); execl("/etc/swapoff", SWAPOFF_ARGS, NULL); execl("/bin/swapoff", SWAPOFF_ARGS, NULL); execlp("swapoff", SWAPOFF_ARGS, NULL); my_puts(_("Cannot exec swapoff, " "hoping umount will do the trick.")); exit(0); } while ((result = wait(&status)) != -1 && result != pid) ; }
int main(int argc, char*argv[]) { (void) argc; (void) argv; my_puts("Hello world\n"); return 0; }
void int_handler(int sig) { unlink(_PATH_NOLOGIN); signal(SIGINT, SIG_DFL); my_puts(_("Shutdown process aborted")); exit(1); }
void ShowError(DWORD dwErrorCode, LPCTSTR s) { LPVOID p1 = NULL, p2 = NULL; DWORD r; TCHAR buf[ 1024 ]; DWORD_PTR pArgs[ 2 ]; __try{ r = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &p1, 0,NULL); if( r ){ if( s ){ pArgs[ 0 ] = (DWORD_PTR)s; pArgs[ 1 ] = (DWORD_PTR)p1; r = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, (LPCVOID)_T("%1!s!:%2!s!"), 0, 0, (LPTSTR)&p2, 0, (va_list*)pArgs ); if( r ){ my_puts( hStderr, (LPCTSTR)p2 ); }else{ my_puts( hStderr, (LPCTSTR)p1 ); } }else{ my_puts( hStderr, (LPCTSTR)p1 ); } }else{ StringCchPrintf( buf, _countof( buf ), s ? _T("Error:%lu\n%s\n") : _T("Error:%lu\n"), dwErrorCode, s ); my_puts( hStderr, buf ); } } __finally{ if( p1 ) LocalFree( p1 ); if( p2 ) LocalFree( p2 ); } }
void printk(const char *fmt, ...) { va_list args; int i; /* Should not be a problem with 8kB of stack */ char buf[1024]; va_start(args, fmt); i = k_vsprintf(buf, fmt, args); va_end(args); my_puts((u_char*)buf); }
void _eCardCore_debug(const char *format, ...) { va_list params; char newMessage[BUFFERSIZE]; int rlen = 0; va_start(params, format); rlen = vsnprintf(newMessage, BUFFERSIZE, format, params); if(rlen >= BUFFERSIZE) { /*Buffer is too small, have to dynamically alocate more memory*/ char * dynMessage = (char*) malloc(rlen + 1); vsnprintf(dynMessage, rlen + 1, format , params); my_puts(dynMessage); free(dynMessage); } else { my_puts(newMessage); } }
void blue_tooth_uart_init(void) { system_clk_div(CLK_24M); int_enter_pro[INT_UART_BRK] = uart_isr; #ifdef BLUE_TOOTH_UART_AT_DPDM USB_CON0 = 0x11; USB_CON2 &= ~(BIT(1)); P3PU &= ~((BIT(6))|(BIT(7))); P3PD &= ~((BIT(6))|(BIT(7))); P3DIR &= ~(BIT(6)); P3DIR |= (BIT(7)); IO_MC0 |= (BIT(7) | BIT(6)); #elif defined(BLUE_TOOTH_UART_AT_P24P25) P2DIR &= ~(BIT(4)); P2DIR |= BIT(5); P2PU &= ~(BIT(3)); P2PD &= ~(BIT(3)); P2DIR |= BIT(3); IO_MC0 |= BIT(6); #elif defined(BLUE_TOOTH_UART_AT_P32P33) P3DIR &= ~BIT(2); P3DIR |= BIT(3); IO_MC0 |= BIT(7); #else P0PU &= ~((BIT(6))|(BIT(7))); P0PD &= ~((BIT(6))|(BIT(7))); P0DIR &= ~(BIT(6)); /* P06 for transmit */ P0DIR |= (BIT(7)); /* P07 for receive */ IO_MC0 &=~(BIT(7) | BIT(6)); #endif #ifdef BLUE_TOOTH_UART_BAUDRATE_AT_9600 UART_BAUD = 0x38 ; #else UART_BAUD = 0x9C; //12MHZ_19200: 0x4E ; #endif UART_CON = UART_REG; /* enable uart */ #ifdef BLUETOOTH_UART_DRV_DEBUG my_puts("blue_tooth_uart_init \r\n"); #endif delay_n10ms(1); }
void debug_adkey_func(void) { my_puts("-----> start debug_ir_func -----\n"); #ifdef WDT_EN config_wdt(0x40); //关掉看门狗 #endif while(1){ my_printf(" --->debug_adkey_func --> bChIndex : %x --- > wADValue : %x \r\n", (u16)(AD_var.bChIndex),(AD_var.wADValue[AD_var.bChIndex])); delay_n10ms(20); } }
static void flush_log(void) { console_log *p, *next; if (console_global_data.vacuum_sent) { #ifdef TRACE_FLUSH_LOG printk("%d characters sent into oblivion before MM init!\n", console_global_data.vacuum_sent); #endif } for(p=console_global_data.log; p; p=next) { my_puts(p->data); next = p->next; pfree(p); } }
void unmount_disks_ourselves(void) { /* unmount all disks */ FILE *mtab; struct mntent *mnt; char *mntlist[128]; int i; int n; char *filesys; sync(); if (!(mtab = setmntent(_PATH_MTAB, "r"))) { my_puts("shutdown: Cannot open " _PATH_MTAB "."); return; } n = 0; while (n < 100 && (mnt = getmntent(mtab))) { /* * Neil Phillips: trying to unmount temporary / kernel * filesystems is pointless and may cause error messages; * /dev can be a ramfs managed by udev. */ if (strcmp(mnt->mnt_type, "devfs") == 0 || strcmp(mnt->mnt_type, "proc") == 0 || strcmp(mnt->mnt_type, "sysfs") == 0 || strcmp(mnt->mnt_type, "ramfs") == 0 || strcmp(mnt->mnt_type, "tmpfs") == 0 || strcmp(mnt->mnt_type, "devpts") == 0) continue; mntlist[n++] = strdup(mnt->mnt_dir); } endmntent(mtab); /* we are careful to do this in reverse order of the mtab file */ for (i = n - 1; i >= 0; i--) { filesys = mntlist[i]; #ifdef DEBUGGING printf("umount %s\n", filesys); #else if (umount(mntlist[i]) < 0) printf(_("shutdown: Couldn't umount %s: %s\n"), filesys, ERRSTRING); #endif } }
/** * Printf wrapper over my_puts. Besides, save the line for log output * This function used for unaligned output and error messages */ int my_printf(const TCHAR * format, ...) { int chars_printed; TCHAR buf[2048]; va_list va; va_start(va, format); chars_printed = _vsntprintf(buf, 2048, format, va); if (g_report_file) { // Save line to print together with aligned lines after // comparison anchors_save_line(NULL, buf); } my_puts(buf); return chars_printed; }
/* ** Function to add padding ** Param: number */ int padding(int search){ char *flags_nbr; int padding_ok, flags_nbr_size; flags_nbr = "0123456789"; padding_ok = 0; flags_nbr_size = my_strlen(flags_nbr); for(int i=0; i < flags_nbr_size; i++){ if(flags_nbr[i] == search){ padding_ok = 1; for(int j = 0; j < i; j++){ my_puts(" "); } } } return padding_ok; }
VOID my_printf( HANDLE h, LPCTSTR lpszFormat, ... ) { va_list ap; LPTSTR buf; DWORD r; va_start( ap, lpszFormat ); r = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING, (LPCVOID)lpszFormat, 0, 0, (LPTSTR)&buf, 0, &ap ); if( r ) my_puts( h, buf ); va_end( ap ); LocalFree( buf ); }
int main() { #ifndef LOCAL_TEST uart_init(); #endif #ifdef LOCAL_TEST puts("hello"); #endif while (1) { my_puts("hello"); DELAY(1); } return 0; }
my_master_dispatch(char * buf, int len) { // reply to slave read request. // write data to slave and wait for next read int llen,ret; char t; char lbuf[600]; if (len > -1) my_psend('d',buf,len); next: llen = myReadFromNamedPipe(lbuf, 600); llen -- ; t = lbuf[llen]; lbuf[llen] ='\0'; TEST_PRINT("%s dispatch - received: %s\n",&t,""); if (t == 'x') { exit(0); } else if(t == 'b') bruch_bruch--; else if(t == 'w') { local_puts(lbuf); my_psend('k',buf,0); } else if(t == 'c') // slave calls master { ret=my_plocalcall(lbuf,llen); // call local procedure my_psend('a',lbuf,ret); // result return goto next; } else if(t == 'r') // read data return(0); else { sprintf(lbuf,"master error: unexpected message %d: >%c<\n",llen,t); my_puts(lbuf); } goto next; }
void debug_ir_func(void) { my_puts("-----> start debug_ir_func -----\n"); #ifdef WDT_EN config_wdt(0x40); //关掉看门狗 #endif while(1){ //my_printf(" --->debug_ir_func state %x \r\n",(u16)IR_code.bState); if(IR_code.bState == 32){ my_printf(" --->debug_ir_func --> IR_code : %x --- > USER_code : %x \r\n", (u16)(IR_code.wData&0x00FF),(u16)(IR_code.wUserCode)); } delay_n10ms(10); } }
u8 bluetooth_cmd_parse(void) { u8 i=0xFF,j=0; u8 rev_reg[5]={0}; //UART_CON = (UART_REG&(~INT_UART_MASK)); /* enable uart */ my_memcpy(rev_reg,rev_cmd+2,5); #ifdef BLUETOOTH_UART_DRV_DEBUG my_puts(" "); for(j=0;j<5;j++) my_printf("--->rev data %x \r\n",(u16)rev_reg[j]); #endif parse_i=rev_reg[0]+1; for(i=0;i<REV_CMD_LEN;i++){ for(j=0;j<parse_i;){ if(rev_reg[j]!=BT_REV_CMD[i][2+j]){ j=0; break; } j++; } if(j==parse_i){ break; } } if(j==0){ i= 0xFF; } //UART_CON = UART_REG; return i; }
void power_key_hdlr(SYS_PWR_HDLR pwr_cmd) { u8 key_msg=0; if(pwr_cmd == SYS_PWR_ON){ #ifdef USE_POWER_KEY u8 key_hold_timer=4,pwr_key_valid_sec=0; sys_gpio_ctrl_pwr(SYS_PWR_ON); while(1){ key_msg = app_get_msg(); #if 0 if(key_msg!= NO_MSG) my_printf(" --->power_key_hdlr key_msg : %x \r\n",(u16)key_msg); #endif switch(key_msg){ case MSG_HALF_SECOND: //my_printf(" --->power_key_hdlr %x \r\n",(u16)key_hold_timer); if(key_hold_timer>3){ pwr_key_valid_sec++; if(pwr_key_valid_sec == (POWER_KEY_HOLD_VALID_TIME_SEC*2)){ goto __POWER_ON; } } key_hold_timer--; if(key_hold_timer==0){ goto __POWER_OFF; } break; case MSG_POWER_KEY_HOLD: // my_printf(" --->power_key_hdlr key_msg %x \r\n",(u16)key_msg); key_hold_timer=5; break; default: break; } } __POWER_ON: UI_menu(MENU_POWER_UP); sys_gpio_ctrl_pwr(SYS_PWR_ON); #endif } else if(pwr_cmd == SYS_PWR_OFF){ #ifdef USE_POWER_KEY __POWER_OFF: my_puts("__POWER_OFF \r\n"); UI_menu(MENU_POWER_DOWN); sys_gpio_ctrl_pwr(SYS_PWR_OFF); ext_pa_mute(PA_MUTE); delay_n10ms(20); EA = 0; #ifdef WDT_EN config_wdt(0x40); //关掉看门狗 #endif while(1); #endif } else if(pwr_cmd == SYS_PWR_IDLE){ #ifdef USE_POWER_IDLE_MODE UI_menu(MENU_POWER_DOWN); ext_pa_mute(PA_MUTE); set_play_status_led(LED_SPARK_STOP); while(1){ key_msg = app_get_msg(); switch(key_msg){ case MSG_POWER_DOWN: set_play_status_led(LED_SPARK_ON); func_msg_hdlr(S_FUNC,SYS_USB_MODE); return; default: break; } } #endif } }
void _hexdump(const char *const caption, const void *const buffer, size_t length) { char line[ ADDRESS_LENGTH + 1 + /* Address */ BYTES_PER_LINE / 8 + /* Extra separator between every 8 bytes */ BYTES_PER_LINE * 3 + 1 + /* Byte printed in hex */ 2 + /* Left bar */ BYTES_PER_LINE + /* Byte Printed in ASCII */ 1 + /* Right bar */ 1 /* Terminator */ ]; char *pline; unsigned char *p = (unsigned char *) buffer; size_t done = 0; size_t i; int printed; if (caption) my_puts(caption); if (!length || !buffer) { my_puts("<absent>"); } else while (length > done) { pline = line; /* Address */ printed = sprintf(pline, "%0*zX ", ADDRESS_LENGTH, p - (unsigned char *) buffer); if (printed < 0) return; pline += printed; for (i = 0; i < BYTES_PER_LINE; i++) { /* Extra separator between every 8 bytes */ if ((i % 8) == 0) { printed = sprintf(pline, " "); if (printed < 0) return; pline += printed; } /* Byte printed in hex */ if (done + i >= length) printed = sprintf(pline, " "); else printed = sprintf(pline, "%02X ", p[i]); if (printed < 0) return; pline += printed; } /* Left bar */ printed = sprintf(pline, " |"); if (printed < 0) return; pline += printed; /* Byte Printed in ASCII */ for (i = 0; i < BYTES_PER_LINE; i++) { if (done + i >= length) printed = 0; else { if (isprint(p[i])) printed = sprintf(pline, "%c", p[i]); else printed = sprintf(pline, "."); } if (printed < 0) return; pline += printed; } /* Right bar */ printed = sprintf(pline, "|"); if (printed < 0) return; pline += printed; /* Terminator */ *pline = '\0'; my_puts(line); done += BYTES_PER_LINE; p += BYTES_PER_LINE; } }
int main(int argc, char *argv[]) { int c, i, fd; char *ptr; i = getdtablesize (); for (fd = 3; fd < i; fd++) close (fd); if (getpid () == 1) { for (fd = 0; fd < 3; fd++) close (fd); while (1) wait (NULL); /* Grim reaper never stops */ } sigsetmask (0); /* simpleinit(8) blocks all signals: undo for ALRM */ for (i = 1; i < NSIG; i++) signal (i, SIG_DFL); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #ifndef DEBUGGING if(setreuid (0, 0)) { fprintf(stderr, _("%s: Only root can shut a system down.\n"), argv[0]); exit(1); } #endif if(*argv[0] == '-') argv[0]++; /* allow shutdown as login shell */ prog = argv[0]; if((ptr = strrchr(argv[0], '/'))) prog = ++ptr; /* All names (halt, reboot, fasthalt, fastboot, shutdown) refer to the same program with the same options, only the defaults differ. */ if(!strcmp("halt", prog)) { opt_reboot = 0; opt_quiet = 1; opt_fast = 0; timeout = 0; } else if(!strcmp("fasthalt", prog)) { opt_reboot = 0; opt_quiet = 1; opt_fast = 1; timeout = 0; } else if(!strcmp("reboot", prog)) { opt_reboot = 1; opt_quiet = 1; opt_fast = 0; timeout = 0; } else if(!strcmp("fastboot", prog)) { opt_reboot = 1; opt_quiet = 1; opt_fast = 1; timeout = 0; } else { /* defaults */ opt_reboot = 0; opt_quiet = 0; opt_fast = 0; timeout = 2*60; } c = 0; while(++c < argc) { if(argv[c][0] == '-') { for(i = 1; argv[c][i]; i++) { switch(argv[c][i]) { case 'C': opt_use_config_file = 1; break; case 'h': opt_reboot = 0; break; case 'r': opt_reboot = 1; break; case 'f': opt_fast = 1; break; case 'q': opt_quiet = 1; break; case 's': opt_single = 1; break; default: usage(); } } } else if(!strcmp("now", argv[c])) { timeout = 0; } else if(argv[c][0] == '+') { timeout = 60 * atoi(&argv[c][1]); } else if (isdigit(argv[c][0])) { char *colon; int hour = 0; int minute = 0; time_t tics; struct tm *tt; int now, then; if((colon = strchr(argv[c], ':'))) { *colon = '\0'; hour = atoi(argv[c]); minute = atoi(++colon); } else usage(); (void) time(&tics); tt = localtime(&tics); now = 3600 * tt->tm_hour + 60 * tt->tm_min; then = 3600 * hour + 60 * minute; timeout = then - now; if(timeout < 0) { fprintf(stderr, _("That must be tomorrow, " "can't you wait till then?\n")); exit(1); } } else { xstrncpy(message, argv[c], sizeof(message)); opt_msgset = 1; } } halt_action[0] = 0; /* No doubt we shall want to extend this some day and register a series of commands to be executed at various points during the shutdown sequence, and to define the number of milliseconds to sleep, etc. */ if (opt_use_config_file) { char line[256], *p; FILE *fp; /* Read and parse the config file */ halt_action[0] = '\0'; if ((fp = fopen (_PATH_SHUTDOWN_CONF, "r")) != NULL) { if (fgets (line, sizeof(line), fp) != NULL && strncasecmp (line, "HALT_ACTION", 11) == 0 && iswhitespace(line[11])) { p = index(line, '\n'); if (p) *p = 0; /* strip final '\n' */ p = line+11; while(iswhitespace(*p)) p++; strcpy(halt_action, p); } fclose (fp); } } if(!opt_quiet && !opt_msgset) { /* now ask for message, gets() is insecure */ int cnt = sizeof(message)-1; char *ptr; printf("Why? "); fflush(stdout); ptr = message; while(--cnt >= 0 && (*ptr = getchar()) && *ptr != '\n') { ptr++; } *ptr = '\0'; } else if (!opt_msgset) { strcpy(message, _("for maintenance; bounce, bounce")); } #ifdef DEBUGGING printf(_("timeout = %d, quiet = %d, reboot = %d\n"), timeout, opt_quiet, opt_reboot); #endif /* so much for option-processing, now begin termination... */ if(!(whom = getlogin()) || !*whom) whom = "ghost"; if(strlen(whom) > 40) whom[40] = 0; /* see write_user() */ setpriority(PRIO_PROCESS, 0, PRIO_MIN); signal(SIGINT, int_handler); signal(SIGHUP, int_handler); signal(SIGQUIT, int_handler); signal(SIGTERM, int_handler); chdir("/"); if(timeout > 5*60) { sleep(timeout - 5*60); timeout = 5*60; } if((fd = open(_PATH_NOLOGIN, O_WRONLY|O_CREAT, 0644)) >= 0) { /* keep xgettext happy and leave \r\n outside strings */ WRCRLF; WR(_("The system is being shut down within 5 minutes")); WRCRLF; write(fd, message, strlen(message)); WRCRLF; WR(_("Login is therefore prohibited.")); WRCRLF; close(fd); } signal(SIGPIPE, SIG_IGN); if(timeout > 0) { wall(); sleep(timeout); } timeout = 0; wall(); sleep(3); /* now there's no turning back... */ signal(SIGINT, SIG_IGN); /* do syslog message... */ openlog(prog, LOG_CONS, LOG_AUTH); if (opt_reboot) syslog(LOG_NOTICE, _("rebooted by %s: %s"), whom, message); else syslog(LOG_NOTICE, _("halted by %s: %s"), whom, message); closelog(); if(opt_fast) if((fd = open("/fastboot", O_WRONLY|O_CREAT, 0644)) >= 0) close(fd); kill(1, SIGTSTP); /* tell init not to spawn more getty's */ write_wtmp(); if(opt_single) if((fd = open(_PATH_SINGLE, O_CREAT|O_WRONLY, 0644)) >= 0) close(fd); sync(); signal(SIGTERM, SIG_IGN); if(fork() > 0) sleep(1000); /* the parent will die soon... */ setpgrp(); /* so the shell wont kill us in the fall */ #ifndef DEBUGGING /* a gentle kill of all other processes except init */ kill_mortals (SIGTERM); for (fd = 0; fd < 3; fd++) close (fd); stop_finalprog (); sleep (1); /* Time for saves to start */ kill (1, SIGTERM); /* Tell init to kill spawned gettys */ usleep (100000); /* Wait for gettys to die */ my_puts (""); /* Get past the login prompt */ system ("/sbin/initctl -r"); /* Roll back services */ syncwait (1); my_puts ("Sending SIGTERM to all remaining processes..."); kill (-1, SIGTERM); sleep (2); /* Default 2, some people need 5 */ kill (-1, SIGKILL); /* Now use brute force... */ /* turn off accounting */ acct(NULL); #endif /* RedHat and SuSE like to remove /etc/nologin. Perhaps the usual sequence is touch nologin; shutdown -h; fiddle with hardware; boot; fiddle with software; rm nologin and removing it here will be counterproductive. Let us see whether people complain. */ unlink(_PATH_NOLOGIN); /* Tell init(8) to exec so that the old inode may be freed cleanly if required. Need to sleep before remounting root read-only */ kill (1, SIGQUIT); sleep (1); /* Time for processes to die and close files */ syncwait (2); /* remove swap files and partitions using swapoff */ swap_off(); /* unmount disks... */ unmount_disks(); syncwait (1); if(opt_reboot) { my_reboot(LINUX_REBOOT_CMD_RESTART); /* RB_AUTOBOOT */ my_puts(_("\nWhy am I still alive after reboot?")); } else { my_puts(_("\nNow you can turn off the power...")); /* allow C-A-D now, [email protected], re-fixed 8-Jul-96 */ my_reboot(LINUX_REBOOT_CMD_CAD_ON); /* RB_ENABLE_CAD */ sleep (1); /* Wait for devices to finish writing to media */ do_halt(halt_action); } /* NOTREACHED */ exit(0); /* to quiet gcc */ }
/** * Comparison report (short or long) */ void OUTPUT_print_file_stat (wav_file_t * wf[2], file_stat_t * diff, cmdline_options_t * opt) { unsigned int i; double dblPCMscale; static TCHAR s[4096]; TCHAR * p; double absmax_scaled; channel_stat_t * tot = diff->ch + diff->nch; channel_stat_t * ch = diff->ch; unsigned int nch = diff->nch; double n_samples = (double)diff->samlpes_count; double tot_samples = nch * n_samples; int have_offset = OffsetInfoHaveOffset(diff, opt); int stat_bips = MIN(labs(wf[0]->fmt.bips), labs(wf[1]->fmt.bips)); if (wf[0]->fmt.pcm_type == E_PCM_IEEE_FLOAT) { stat_bips = wf[1]->fmt.pcm_type == E_PCM_IEEE_FLOAT ? 16 : labs(wf[1]->fmt.bips); } if (wf[1]->fmt.pcm_type == E_PCM_IEEE_FLOAT) { stat_bips = wf[0]->fmt.pcm_type == E_PCM_IEEE_FLOAT ? 16 : labs(wf[0]->fmt.bips); } dblPCMscale = ldexp(1, stat_bips - 1); if (opt->listing == E_LISTING_SHORT || (opt->listing == E_LISTING_NO_BITEXACT && (tot->d_sumSqr != 0 || have_offset))) { ptrdiff_t anchors[ANCHORS_COUNT]; p = s; p += _stprintf(p, _T("PSNR (dB):%-9.9s"), DB(tot->d_sumSqr, tot_samples)); #if 0 // use minimum BIPS of comparing files p += _stprintf(p, _T("Max*2^%2d:(%.0f"), stat_bips, diff_stat_abs_max(ch + 0) * dblPCMscale); for (i = 1; i < nch; i++) { p += _stprintf(p, _T(" : %.0f"), diff_stat_abs_max(ch + i) * dblPCMscale); } p += _stprintf(p, _T(")")); #else // always use 16-bit BIPS absmax_scaled = diff_stat_abs_max(diff->ch + 0) * (1<<15); p += _stprintf(p, _T("Max*2^16:(%s"), print_float(absmax_scaled, 9, (absmax_scaled != 0 && absmax_scaled < 1)?2:0)); for (i = 1; i < nch; i++) { absmax_scaled = diff_stat_abs_max(diff->ch + i) * (1<<15); p += _stprintf(p, _T(" : %s"), print_float(absmax_scaled, 9, (absmax_scaled != 0 && absmax_scaled < 1)?2:0)); } p += _stprintf(p, _T(")")); #endif #define FIX_ANCHORS(z) for (anchors[z] = p - s; anchors[z] < g_anchors[z]; anchors[z]++) *p++ = ' '; while (p - s < 40 || (p - s) % 8) { *p++ = ' '; } FIX_ANCHORS(0) if (wf[0]->container != wf[1]->container) { p += _stprintf(p, _T(" %s<->%s/"), WAV_format_string(wf[0]), WAV_format_string(wf[1])); } else { p += _stprintf(p, _T(" %s/"), WAV_format_string(wf[0])); } FIX_ANCHORS(1) if (wf[0]->fmt.bips != wf[1]->fmt.bips || wf[0]->fmt.pcm_type != wf[1]->fmt.pcm_type) { p += print_bips_short(p, wf[0]); p += _stprintf(p, _T("<->")); p += print_bips_short(p, wf[1]); } else { p += print_bips_short(p, wf[0]); } FIX_ANCHORS(2) if (wf[0]->fmt.hz != wf[1]->fmt.hz && wf[0]->fmt.hz != 0 && wf[1]->fmt.hz != 0) { p += _stprintf(p, _T("/%5lu<->%5lu "), wf[0]->fmt.hz, wf[1]->fmt.hz); } else { p += _stprintf(p, _T("/%5lu "), wf[0]->fmt.hz ? wf[0]->fmt.hz : wf[1]->fmt.hz); } FIX_ANCHORS(3) p += _stprintf(p, _T("[%7u smp] "), diff->samlpes_count); FIX_ANCHORS(4) if (have_offset) { p += _stprintf(p, _T(" Offsets: ")); if (opt->offset_bytes[0]) { p += _stprintf(p, _T("%u bytes + "), opt->offset_bytes[0]); } if (diff->actualOffsetSamples[0]) { p += _stprintf(p, _T("%lu+"), diff->actualOffsetSamples[0]); } p += _stprintf(p, _T("[1st]")); if (diff->remainingSamples[0]) { p += _stprintf(p, _T("+%") _T(PRIi64), diff->remainingSamples[0]); } FIX_ANCHORS(5) p += _stprintf(p, _T(" <-> ")); if (opt->offset_bytes[1]) { p += _stprintf(p, _T("%u bytes + "), opt->offset_bytes[1]); } if (diff->actualOffsetSamples[1]) { p += _stprintf(p, _T("%u+"), diff->actualOffsetSamples[1]); } p += _stprintf(p, _T("[2nd]")); if (diff->remainingSamples[1]) { p += _stprintf(p, _T("+%") _T(PRIi64), diff->remainingSamples[1]); } } else { FIX_ANCHORS(5) } while ((p - s) % 16) { *p++ = ' '; } FIX_ANCHORS(6) p += _stprintf(p, _T(" %s"), PATH_after_last_separator(opt->file_name[0])); if (_tcscmp( PATH_after_last_separator(opt->file_name[0]), PATH_after_last_separator(opt->file_name[1]) )) { while ((p - s) % 16) { *p++ = ' '; } FIX_ANCHORS(7) p += _stprintf(p, _T(" <-> ")); p += _stprintf(p, _T(" %s"), PATH_after_last_separator(opt->file_name[1])); } else { FIX_ANCHORS(7) } *p++ = '\n'; *p++ = '\0'; FIX_ANCHORS(8) anchors_save_line(anchors, s); my_puts(s); }
pmelden(char * fmt,char * p1, char * p2) { char str[100]; sprintf(str,fmt,who(),p1,p2); if(slave_mode) puts(str); else my_puts(str); }
void TestHook(int i) { my_puts("TestHook "); OrigTest(i); }