This program enlarges mGi soft keyboard by two times. You can change the factor by changing the function times_two.
/*
* read from keyboard.c, scale the rect for each key, and put it in new_keyboard.c
* -Zhao Jihua
*/
#include
#include
#include
#define BUF_SIZE 512
static int IsDigit (int c){
if (strchr ("0123456789", c))
return 1;
else
return 0;
}
static void times_two (char* s){
char* tmp;
tmp = strdup (s);
sprintf (s, "%d", atoi(tmp) * 2);
free (tmp);
}
int main (void){
char buf[BUF_SIZE], *p, *p_sec_brace;
char wbuf[BUF_SIZE];
FILE *fin;
FILE *fout;
int i, j = 0, which = 0, count = 0;
int sec_brace_pos;
char num[4][8];
char in_file[] = "./keyboard.c";
char start[] = "static MGI_SOFTKEY_INFO new_keyboard[] = {\n";
char end[] = "};\n";
fin = fopen (in_file, "r");
if (!fin){
perror ("fopen");
return -1;
}
fout = fopen ("./new_keyboard.c", "w");
if (!fin){
perror ("fopen");
return -1;
}
fputs (start, fout);
buf[BUF_SIZE - 2] = '\0';
while ( (p = fgets (buf, BUF_SIZE, fin)) != NULL){
if (strstr(p, "SFT_SCANCODE, NULL")){
//find second '{' position
for (i = 0; i < strlen(p); i++){
if (buf[i] == '{'){
count ++;
if (count == 2){
sec_brace_pos = i;
count = 0;
}
}
}
p_sec_brace = &buf[sec_brace_pos];
//extract all the numbers
for (i = 0; i < strlen(p_sec_brace); i++){
if (IsDigit(p_sec_brace[i])){
num[which][j] = p_sec_brace[i];
j++;
}
if (p_sec_brace[i] == ','){
num[which][j] = '\0';
printf ("%s\n", &num[which][0]);
which++;
j = 0;
}
if (p_sec_brace[i] == '}'){
num[which][j] = '\0';
printf ("%s\n", &num[which][0]);
which=0;
j=0;
break;
}
}
memset (wbuf, '\0', sizeof(wbuf));
strncpy (wbuf, p, (sec_brace_pos + 1));
for (i = 0; i < 4; i++){
times_two (&num[i][0]);
printf ("doubled: %s\n", &num[i][0]);
strcat (wbuf, &num[i][0]);
if (i < 3)
strcat (wbuf, ",");
printf ("wbuf: %s\n", wbuf);
}
strcat (wbuf, "}, 0},\n");
fputs (wbuf, fout);
}
}
fputs (end, fout);
}
阅读(1036) | 评论(0) | 转发(0) |