forked from cc/osmo-cc-ss5-endpoint
Improved status display
This commit is contained in:
parent
846addb9af
commit
3e5f378f66
|
@ -45,6 +45,8 @@ void print_help_common(void)
|
|||
printf(" a0<number>c: national number\n");
|
||||
printf(" b<cc>X<number>c: international number, digit X is removed\n");
|
||||
printf("<cc> and <number> are separated automatically by known list of country codes.\n");
|
||||
printf("\n");
|
||||
printf("Press 'c' to toggle status display on or off.\n");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -96,11 +96,60 @@ void display_status_start(void)
|
|||
line_count = 1;
|
||||
}
|
||||
|
||||
const char *display_digits(const char *digits)
|
||||
{
|
||||
static char display[256];
|
||||
int i, j;
|
||||
|
||||
if (*digits == '\0')
|
||||
return "";
|
||||
|
||||
for (i = 0, j = 0; digits[i]; i++) {
|
||||
/* We need minimum of 5 digits space: e.g. '-C11\0' */
|
||||
if (j + 5 > (int)sizeof(display))
|
||||
break;
|
||||
/* if this is not the first digits && this is special digit or previous digit was special digit */
|
||||
if (i && ((digits[i - 1] >= 'a' && digits[i - 1] <= 'e') || (digits[i] >= 'a' && digits[i] <= 'e')))
|
||||
display[j++] = '-';
|
||||
switch (digits[i]) {
|
||||
case 'a':
|
||||
display[j++] = 'K';
|
||||
display[j++] = 'P';
|
||||
display[j++] = '1';
|
||||
break;
|
||||
case 'b':
|
||||
display[j++] = 'K';
|
||||
display[j++] = 'P';
|
||||
display[j++] = '2';
|
||||
break;
|
||||
case 'c':
|
||||
display[j++] = 'S';
|
||||
display[j++] = 'T';
|
||||
break;
|
||||
case 'd':
|
||||
display[j++] = 'C';
|
||||
display[j++] = '1';
|
||||
display[j++] = '1';
|
||||
break;
|
||||
case 'e':
|
||||
display[j++] = 'C';
|
||||
display[j++] = '1';
|
||||
display[j++] = '2';
|
||||
break;
|
||||
default:
|
||||
display[j++] = digits[i];
|
||||
}
|
||||
}
|
||||
|
||||
display[j] = '\0';
|
||||
return display;
|
||||
}
|
||||
|
||||
void display_status_line(const char *if_name, int link_count, const char *from_id, const char *to_id, const char *state_name)
|
||||
{
|
||||
char line[MAX_DISPLAY_WIDTH + 4096];
|
||||
char color[MAX_DISPLAY_WIDTH + 4096];
|
||||
int index, from_len, to_len;
|
||||
int index, from_len;
|
||||
|
||||
memset(color, 7, sizeof(color)); // make valgrind happy
|
||||
|
||||
|
@ -126,13 +175,12 @@ void display_status_line(const char *if_name, int link_count, const char *from_i
|
|||
|
||||
if (from_id && to_id) {
|
||||
/* '<id>' */
|
||||
sprintf(line + index, " \'%s\' -> \'%s\' ", from_id, to_id);
|
||||
sprintf(line + index, " \'%s\' -> \'%s\' (%s) ", from_id, to_id, display_digits(to_id));
|
||||
from_len = strlen(from_id);
|
||||
to_len = strlen(to_id);
|
||||
memset(color + index, 1, 4 + from_len);
|
||||
memset(color + index + 4 + from_len, 7, 2);
|
||||
memset(color + index + 4 + from_len + 2, 2, 4 + to_len);
|
||||
index += 4 + from_len + 2 + 4 + to_len;
|
||||
memset(color + index + 4 + from_len + 2, 2, strlen(line + index) - 4 - from_len - 2);
|
||||
index += strlen(line + index);
|
||||
line[index] = '\0';
|
||||
|
||||
strcpy(line + index, state_name);
|
||||
|
|
Loading…
Reference in New Issue