OSDN Git Service

roast_consle_util.c Add
[roast/pendding.git] / source / roast_consle_util.c
1 /*      Roast+ License v1.0
2
3 //      ### C compilable ###
4 */
5 #include <stdio.h>
6 #include <string.h>
7
8 __ROAST_EXTERN_C_START
9
10 /*  roast_strccpy  */
11 void roast_console_stick_turning(int turn_sleep, int count, const int* end_flag)
12 {
13         int i;
14         for(i=0; i<4*count; i++)
15         {
16                 if ( end_flag != NULL && *end_flag )
17                         break;
18                 switch(i%4)
19                 {
20                 case 0:
21                         printf("|\b"); break;
22                 case 1:
23                         printf("/\b"); break;
24                 case 2:
25                         printf("-\b"); break;
26                 case 3:
27                         printf("\\\b"); break;
28                 }
29                 Sleep(turn_sleep);
30         }
31 }
32
33 void roast_console_print_progress_bar(char c, int length, int percent)
34 {
35         int i;
36         for(i=0; i<length; i++)
37         {
38                 if ( i <= length * percent / 100 )
39                         putc(c, stdout);
40                 else
41                         putc(' ', stdout);
42         }
43 }
44
45 void roast_console_progress_bar(const char* head_out, const char* tail_out, char c, int length, const int* percent_ptr, int sleep_time)
46 {
47         for(;;)
48         {
49                 printf("\r");
50                 printf(head_out);
51                 roast_console_print_progress_bar('#', 30, *percent_ptr);
52                 printf(tail_out);
53
54                 if ( *percent_ptr == 100 ){
55                         printf("\n");
56                         break;
57                 }
58
59                 Sleep(sleep_time);
60         }
61 }
62
63 void roast_memdump(const void* mem, size_t length, size_t width, int flags)
64 {
65         const unsigned char* p;
66         size_t i;
67         const char* p_ascii_print;
68
69         p = (const unsigned char*)mem;
70
71         printf("          ");
72         for(i=0; i<width; i++)
73         {
74                 printf("%02X ", i);
75         }
76         printf("\n---------------------------------------------------------\n");
77
78         for(i=0; i<length; i++)
79         {
80                 if ( i%width == 0 )
81                         printf("%08X: ");
82
83                 printf("%02X ", p[i]);
84
85                 if ( i%width == width-1 || i == length-1 )
86                 {
87                         p_ascii_print = (const char*)(p - (i%width));
88                         printf("| %s\n", p_ascii_print);
89                 }
90         }
91 }
92
93 __ROAST_EXTERN_C_END