#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
typedef struct child
{
struct node * son;
struct child * next;
}child_node;
typedef struct node
{
struct node * father;
int step;
int checked;
char map_string[17];
struct node * next;
}map_node;
int Map[4][4];
map_node * Map_Que=NULL;
child_node * Final=NULL;
int MinStep=-1;
clock_t start,end;
void print_map(void)
{
int i,xpos,ypos;
for (i=0;i<16;i++)
{
xpos=i%4;
ypos=i/4;
if (Map[xpos][ypos]<10)
{
printf("%2u",Map[xpos][ypos]);
}
else
{
printf("%2c",Map[xpos][ypos]+55);
}
if (xpos==3) printf(" ");
}
}
void string_to_map(char *map_string)
{
int i,xpos,ypos;
for(i=0;i<16;i++)
{
xpos=i%4;
ypos=i/4;
if (map_string[i]<='9')
{
Map[xpos][ypos]=map_string[i]-0x30;
}
else
{
Map[xpos][ypos]=map_string[i]-0x37;
}
}
}
char *map_to_string()
{
static char map_string[17];
int i,xpos,ypos;
map_string[16]=0;
for(i=0;i<16;i++)
{
xpos=i%4;
ypos=i/4;
if (Map[xpos][ypos]<10)
{
map_string[i]=Map[xpos][ypos]+0x30;
}
else
{
map_string[i]=Map[xpos][ypos]+0x37;
}
}
return map_string;
}
int calculate_map_string(char*map_string,int mode)
{
int i,xpos,ypos,x,y,distance,val,dist,times=14;
distance=dist=0;
//成功与否在你真正实现之前,我们能做的只能是评估。
//而评估的方法千差万别,但对你修正自己的目标却是至关重要!
for(i=0;i<16;i++)
{
if (map_string[i]==0x30) continue;
xpos=i%4;
ypos=i/4;
val=map_string[i]-0x30;
if (val>9) val-=7;
if (val==i+1) times--;
x=(val-1)%4;
y=(val-1)/4;
distance+=abs(x-xpos)+abs(y-ypos);
dist+=(x-xpos)*(x-xpos)+(y-ypos)*(y-ypos);
}
//而且在不同的场合我们所需要的评估手段也不尽相同
if (mode==1) return distance;
return dist*times;
}
map_node *new_map_status(map_node * father_node,char *map_string,int steps)
{
map_node *new_node;
new_node=(map_node *)malloc(sizeof(map_node));
if (new_node!=NULL)
{
//每一步的都是崭新的,但是也已经蕴藏了是否能成功的关键
new_node->father=father_node;
strcpy(new_node->map_string,map_string);
new_node->step=steps;
new_node->next=NULL;
new_node->checked=0;
}
return new_node;
}
int compare_map(char *map1,int step1,char *map2,int step2)
{
int dist1,dist2;
dist1=calculate_map_string(map1,0);
dist2=calculate_map_string(map2,0);
if (dist1>dist2) return 1;
if (dist1<dist2) return -1;
//在成功之前,我们面对的竞争是残酷的,即使一点微小的差别,也会导致落选!
if (step1>step2) return 1;
if (step1<step2) return -1;
return 0;
}
map_node * insert_map_que(map_node *father_node,char *map_string,int steps)
{
map_node * queue=Map_Que;
map_node * result=NULL;
map_node * last=NULL;
int checked=0;
while (queue!=NULL)
{
//迟到会让机会永远跟你说再见
if (checked==0 && queue->step<steps && strcmp(queue->map_string,map_string)==0) return NULL;
//如果有人成功过,那么你所面临的淘汰可能是空前的!
if (checked==1 && MinStep>0 && queue->step+calculate_map_string(queue->map_string,1)>MinStep)
{
if (last!=NULL)
{
last->next=queue->next;
free(queue);
queue=last->next;
continue;
}
else
{
Map_Que=queue->next;
free(queue);
queue=Map_Que;
continue;
}
}
//先下手未必强,后来者也可居上!
if (checked==1 && queue->step>steps && strcmp(queue->map_string,map_string)==0)
{
last->next=queue->next;
free(queue);
queue=last->next;
continue;
}
//竞争的残酷,居然可以蔓延到下一代!
if (checked==1 && queue->father!=NULL && queue->father->map_string!=NULL && strcmp(queue->father->map_string,map_string)==0)
{
queue->father=result;
last=queue;
queue=queue->next;
continue;
}
//肃清运动一定会是彻底而残酷的!
if (checked==1)
{
last=queue;
queue=queue->next;
continue;
}
//在队列中找到了自己的位置,那只是一切的开始!
if (compare_map(map_string,steps,queue->map_string,queue->step)==-1 || queue->next==NULL)
{
result=new_map_status(father_node,map_string,steps);
if (result==NULL)
{
printf("ERROR IN INSERT_MAP_QUE! ");
exit(1) ;
}
if (last!=NULL)
{
last->next=result;
}
else
{
Map_Que=result;
}
result->next=queue;
result->checked=0;
checked=1;
}
last=queue;
queue=queue->next;
}
return result;
}
void add_child(map_node* now_node)
{
child_node * new_node;
new_node=(child_node *)malloc(sizeof(child_node));
if (new_node==NULL)
{
printf("ERROR IN APPLY MEMORY IN ADD_CHILD! ");
exit(1) ;
}
new_node->son=now_node;
new_node->next=Final;
Final=new_node;
return;
}
int develop_node(map_node* now_node)
{
int i;
char map_string[17];
map_node* candidate;
for (i=0;i<16;i++)
{
if (now_node->map_string[i]=='0')
{
//寻找出路的过程是漫长而乏味的,上下以求索,是成功前必由之路
//Up Side Move
strcpy(map_string,now_node->map_string);
if (i/4>=1)
{
map_string[i-4]=now_node->map_string[i];
map_string[i]=now_node->map_string[i-4];
if (MinStep==-1 || calculate_map_string(map_string,1)+now_node->step<MinStep)
{
//能够成为候选者应该是一种荣幸,特别是在有人成功以后!
candidate=insert_map_que(now_node,map_string,now_node->step+1);
}
}
//Left Side Move
strcpy(map_string,now_node->map_string);
if (i%4>0)
{
map_string[i-1]=now_node->map_string[i];
map_string[i]=now_node->map_string[i-1];
if (MinStep==-1 || calculate_map_string(map_string,1)+now_node->step<MinStep)
{
candidate=insert_map_que(now_node,map_string,now_node->step+1);
}
}
//Right Side Move
strcpy(map_string,now_node->map_string);
if (i%4<3)
{
map_string[i+1]=now_node->map_string[i];
map_string[i]=now_node->map_string[i+1];
if (MinStep==-1 || calculate_map_string(map_string,1)+now_node->step<MinStep)
{
candidate=insert_map_que(now_node,map_string,now_node->step+1);
}
}
//Down Side Move
strcpy(map_string,now_node->map_string);
if (i/4<3)
{
map_string[i+4]=now_node->map_string[i];
map_string[i]=now_node->map_string[i+4];
if (MinStep==-1 || calculate_map_string(map_string,1)+now_node->step<MinStep)
{
candidate=insert_map_que(now_node,map_string,now_node->step+1);
}
}
}
}
return 0;
}
map_node *get_next_node()
{
map_node* queue=Map_Que;
map_node* last=NULL;
while(queue!=NULL)
{
//成功者是暂时的强者,但它可以用来鉴定后来者的质素!
if (MinStep>0 && queue->step+calculate_map_string(queue->map_string,1)>MinStep)
{
if (last!=NULL)
{
last->next=queue->next;
free(queue);
queue=last->next;
continue;
}
else
{
Map_Que=queue->next;
free(queue);
queue=Map_Que;
continue;
}
}
//尚未触及的世界总是值得我们去探知的!
if (queue->checked==0)
{
queue->checked=1;
return queue;
}
last=queue;
queue=queue->next;
}
return NULL;
}
int main()
{
int i,now_distance=-1;
int xpos,ypos;
map_node* now_node;
void *last;
//机遇和挑战常常是以时间作为自变量的随机函数!
//会有雷同,但不停变化!
srand(time(NULL));
for(i=0;i<16;i++)
{
xpos=i%4;
ypos=i/4;
Map[xpos][ypos]=0;
}
for(i=0;i<14;i++)
{
do
{
xpos=rand()*4/(RAND_MAX+1);
ypos=rand()*4/(RAND_MAX+1);
}while (Map[xpos][ypos]!=0);
//面临的一切总不相同!
Map[xpos][ypos]=i+1;
}
print_map();
getchar();
start=clock();
//一切问题的开始总是那么简单,然而处理的过程有时却恰恰相反!
Map_Que=new_map_status(NULL,map_to_string(),0);
now_node=get_next_node();
while(now_node!=NULL)
{
//探索的过程总是很乏味的,发现,判断,继续发现,继续判断,直到我们找到我们人为最好的解决方法
develop_node(now_node);
if (now_distance==-1 || calculate_map_string(now_node->map_string,0)<now_distance)
{
string_to_map(now_node->map_string);
print_map();
end=clock();
printf("[%7lf] Step:%3u Distance:%2u ",(double)(end-start)/(double)CLOCKS_PER_SEC,now_node->step,calculate_map_string(now_node->map_string,0));
now_distance=calculate_map_string(now_node->map_string,0);
}
if (calculate_map_string(now_node->map_string,0)==0)
{
if (MinStep==-1 || now_node->step<MinStep)
{
MinStep=now_node->step;
end=clock();
printf("[%7lf] Now Min Step Is %u ",(double)(end-start)/(double)CLOCKS_PER_SEC,MinStep);
}
}
now_node=get_next_node();
}
printf(" ");
end=clock();
printf("[%7lf] Seeking Finished! ",(double)(end-start)/(double)CLOCKS_PER_SEC);
printf(" ");
if (MinStep!=-1)
{
now_node=Map_Que;
while(now_node!=NULL)
{
//这些才是最终胜出的!
if (calculate_map_string(now_node->map_string,0)==0)
{
add_child(now_node);
while(Final!=NULL)
{
string_to_map(Final->son->map_string);
print_map();
printf("Step %u Distance %u ",Final->son->step,calculate_map_string(Final->son->map_string,0));
last=Final;
Final=Final->next;
free(last);
}
printf("=============================== ");
}
now_node=now_node->next;
}
}
//学会清理是很重要的!
while(Map_Que!=NULL)
{
last=Map_Que->next;
free(Map_Que);
Map_Que=last;
}
exit(0);
}
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
typedef struct child
{
struct node * son;
struct child * next;
}child_node;
typedef struct node
{
struct node * father;
int step;
int checked;
char map_string[17];
struct node * next;
}map_node;
int Map[4][4];
map_node * Map_Que=NULL;
child_node * Final=NULL;
int MinStep=-1;
clock_t start,end;
void print_map(void)
{
int i,xpos,ypos;
for (i=0;i<16;i++)
{
xpos=i%4;
ypos=i/4;
if (Map[xpos][ypos]<10)
{
printf("%2u",Map[xpos][ypos]);
}
else
{
printf("%2c",Map[xpos][ypos]+55);
}
if (xpos==3) printf(" ");
}
}
void string_to_map(char *map_string)
{
int i,xpos,ypos;
for(i=0;i<16;i++)
{
xpos=i%4;
ypos=i/4;
if (map_string[i]<='9')
{
Map[xpos][ypos]=map_string[i]-0x30;
}
else
{
Map[xpos][ypos]=map_string[i]-0x37;
}
}
}
char *map_to_string()
{
static char map_string[17];
int i,xpos,ypos;
map_string[16]=0;
for(i=0;i<16;i++)
{
xpos=i%4;
ypos=i/4;
if (Map[xpos][ypos]<10)
{
map_string[i]=Map[xpos][ypos]+0x30;
}
else
{
map_string[i]=Map[xpos][ypos]+0x37;
}
}
return map_string;
}
int calculate_map_string(char*map_string,int mode)
{
int i,xpos,ypos,x,y,distance,val,dist,times=14;
distance=dist=0;
//成功与否在你真正实现之前,我们能做的只能是评估。
//而评估的方法千差万别,但对你修正自己的目标却是至关重要!
for(i=0;i<16;i++)
{
if (map_string[i]==0x30) continue;
xpos=i%4;
ypos=i/4;
val=map_string[i]-0x30;
if (val>9) val-=7;
if (val==i+1) times--;
x=(val-1)%4;
y=(val-1)/4;
distance+=abs(x-xpos)+abs(y-ypos);
dist+=(x-xpos)*(x-xpos)+(y-ypos)*(y-ypos);
}
//而且在不同的场合我们所需要的评估手段也不尽相同
if (mode==1) return distance;
return dist*times;
}
map_node *new_map_status(map_node * father_node,char *map_string,int steps)
{
map_node *new_node;
new_node=(map_node *)malloc(sizeof(map_node));
if (new_node!=NULL)
{
//每一步的都是崭新的,但是也已经蕴藏了是否能成功的关键
new_node->father=father_node;
strcpy(new_node->map_string,map_string);
new_node->step=steps;
new_node->next=NULL;
new_node->checked=0;
}
return new_node;
}
int compare_map(char *map1,int step1,char *map2,int step2)
{
int dist1,dist2;
dist1=calculate_map_string(map1,0);
dist2=calculate_map_string(map2,0);
if (dist1>dist2) return 1;
if (dist1<dist2) return -1;
//在成功之前,我们面对的竞争是残酷的,即使一点微小的差别,也会导致落选!
if (step1>step2) return 1;
if (step1<step2) return -1;
return 0;
}
map_node * insert_map_que(map_node *father_node,char *map_string,int steps)
{
map_node * queue=Map_Que;
map_node * result=NULL;
map_node * last=NULL;
int checked=0;
while (queue!=NULL)
{
//迟到会让机会永远跟你说再见
if (checked==0 && queue->step<steps && strcmp(queue->map_string,map_string)==0) return NULL;
//如果有人成功过,那么你所面临的淘汰可能是空前的!
if (checked==1 && MinStep>0 && queue->step+calculate_map_string(queue->map_string,1)>MinStep)
{
if (last!=NULL)
{
last->next=queue->next;
free(queue);
queue=last->next;
continue;
}
else
{
Map_Que=queue->next;
free(queue);
queue=Map_Que;
continue;
}
}
//先下手未必强,后来者也可居上!
if (checked==1 && queue->step>steps && strcmp(queue->map_string,map_string)==0)
{
last->next=queue->next;
free(queue);
queue=last->next;
continue;
}
//竞争的残酷,居然可以蔓延到下一代!
if (checked==1 && queue->father!=NULL && queue->father->map_string!=NULL && strcmp(queue->father->map_string,map_string)==0)
{
queue->father=result;
last=queue;
queue=queue->next;
continue;
}
//肃清运动一定会是彻底而残酷的!
if (checked==1)
{
last=queue;
queue=queue->next;
continue;
}
//在队列中找到了自己的位置,那只是一切的开始!
if (compare_map(map_string,steps,queue->map_string,queue->step)==-1 || queue->next==NULL)
{
result=new_map_status(father_node,map_string,steps);
if (result==NULL)
{
printf("ERROR IN INSERT_MAP_QUE! ");
exit(1) ;
}
if (last!=NULL)
{
last->next=result;
}
else
{
Map_Que=result;
}
result->next=queue;
result->checked=0;
checked=1;
}
last=queue;
queue=queue->next;
}
return result;
}
void add_child(map_node* now_node)
{
child_node * new_node;
new_node=(child_node *)malloc(sizeof(child_node));
if (new_node==NULL)
{
printf("ERROR IN APPLY MEMORY IN ADD_CHILD! ");
exit(1) ;
}
new_node->son=now_node;
new_node->next=Final;
Final=new_node;
return;
}
int develop_node(map_node* now_node)
{
int i;
char map_string[17];
map_node* candidate;
for (i=0;i<16;i++)
{
if (now_node->map_string[i]=='0')
{
//寻找出路的过程是漫长而乏味的,上下以求索,是成功前必由之路
//Up Side Move
strcpy(map_string,now_node->map_string);
if (i/4>=1)
{
map_string[i-4]=now_node->map_string[i];
map_string[i]=now_node->map_string[i-4];
if (MinStep==-1 || calculate_map_string(map_string,1)+now_node->step<MinStep)
{
//能够成为候选者应该是一种荣幸,特别是在有人成功以后!
candidate=insert_map_que(now_node,map_string,now_node->step+1);
}
}
//Left Side Move
strcpy(map_string,now_node->map_string);
if (i%4>0)
{
map_string[i-1]=now_node->map_string[i];
map_string[i]=now_node->map_string[i-1];
if (MinStep==-1 || calculate_map_string(map_string,1)+now_node->step<MinStep)
{
candidate=insert_map_que(now_node,map_string,now_node->step+1);
}
}
//Right Side Move
strcpy(map_string,now_node->map_string);
if (i%4<3)
{
map_string[i+1]=now_node->map_string[i];
map_string[i]=now_node->map_string[i+1];
if (MinStep==-1 || calculate_map_string(map_string,1)+now_node->step<MinStep)
{
candidate=insert_map_que(now_node,map_string,now_node->step+1);
}
}
//Down Side Move
strcpy(map_string,now_node->map_string);
if (i/4<3)
{
map_string[i+4]=now_node->map_string[i];
map_string[i]=now_node->map_string[i+4];
if (MinStep==-1 || calculate_map_string(map_string,1)+now_node->step<MinStep)
{
candidate=insert_map_que(now_node,map_string,now_node->step+1);
}
}
}
}
return 0;
}
map_node *get_next_node()
{
map_node* queue=Map_Que;
map_node* last=NULL;
while(queue!=NULL)
{
//成功者是暂时的强者,但它可以用来鉴定后来者的质素!
if (MinStep>0 && queue->step+calculate_map_string(queue->map_string,1)>MinStep)
{
if (last!=NULL)
{
last->next=queue->next;
free(queue);
queue=last->next;
continue;
}
else
{
Map_Que=queue->next;
free(queue);
queue=Map_Que;
continue;
}
}
//尚未触及的世界总是值得我们去探知的!
if (queue->checked==0)
{
queue->checked=1;
return queue;
}
last=queue;
queue=queue->next;
}
return NULL;
}
int main()
{
int i,now_distance=-1;
int xpos,ypos;
map_node* now_node;
void *last;
//机遇和挑战常常是以时间作为自变量的随机函数!
//会有雷同,但不停变化!
srand(time(NULL));
for(i=0;i<16;i++)
{
xpos=i%4;
ypos=i/4;
Map[xpos][ypos]=0;
}
for(i=0;i<14;i++)
{
do
{
xpos=rand()*4/(RAND_MAX+1);
ypos=rand()*4/(RAND_MAX+1);
}while (Map[xpos][ypos]!=0);
//面临的一切总不相同!
Map[xpos][ypos]=i+1;
}
print_map();
getchar();
start=clock();
//一切问题的开始总是那么简单,然而处理的过程有时却恰恰相反!
Map_Que=new_map_status(NULL,map_to_string(),0);
now_node=get_next_node();
while(now_node!=NULL)
{
//探索的过程总是很乏味的,发现,判断,继续发现,继续判断,直到我们找到我们人为最好的解决方法
develop_node(now_node);
if (now_distance==-1 || calculate_map_string(now_node->map_string,0)<now_distance)
{
string_to_map(now_node->map_string);
print_map();
end=clock();
printf("[%7lf] Step:%3u Distance:%2u ",(double)(end-start)/(double)CLOCKS_PER_SEC,now_node->step,calculate_map_string(now_node->map_string,0));
now_distance=calculate_map_string(now_node->map_string,0);
}
if (calculate_map_string(now_node->map_string,0)==0)
{
if (MinStep==-1 || now_node->step<MinStep)
{
MinStep=now_node->step;
end=clock();
printf("[%7lf] Now Min Step Is %u ",(double)(end-start)/(double)CLOCKS_PER_SEC,MinStep);
}
}
now_node=get_next_node();
}
printf(" ");
end=clock();
printf("[%7lf] Seeking Finished! ",(double)(end-start)/(double)CLOCKS_PER_SEC);
printf(" ");
if (MinStep!=-1)
{
now_node=Map_Que;
while(now_node!=NULL)
{
//这些才是最终胜出的!
if (calculate_map_string(now_node->map_string,0)==0)
{
add_child(now_node);
while(Final!=NULL)
{
string_to_map(Final->son->map_string);
print_map();
printf("Step %u Distance %u ",Final->son->step,calculate_map_string(Final->son->map_string,0));
last=Final;
Final=Final->next;
free(last);
}
printf("=============================== ");
}
now_node=now_node->next;
}
}
//学会清理是很重要的!
while(Map_Que!=NULL)
{
last=Map_Que->next;
free(Map_Que);
Map_Que=last;
}
exit(0);
}
说老实话,个人觉得OpenSUSE除了它的GRUB出彩一点,其它的都很一般。所以为了更好的利用这个很酷的启动界面,试着用它创建了Live USB和Live CD。考虑到大多数玩家喜欢Windows多一些,把所有的创建过程移植到了Windows平台。这里先把相关的工具包放出来,之后慢慢说如何启动WINPE和制作或定制Live Ubuntu。顺便把抑制的mkblfont源代码挂上来。有兴趣的朋友可以写个GUI的程序,我比较懒,而且喜欢脚本和命令行多于GUI。抱歉了。关于如何使用工具包,压缩包里有较为详细地说明。
Frankly, I think the OpenSUSE nothing better except the GRUB. So in order to take the advantage of this cool boot interface, I tried to establish my Live USB and Live CD based on it. Considering most of buddies like Windows more, I did some work to migrate the whole thing to Windows platform. Here I just release the tool kits and discuss the detail processing of booting WINPE or customerize Live Ubuntu later. BTW, I also put the source code of mkblfont for Windows here. If anyone interesting in writing a GUI tool to cover all those function would be great, since I'm lazy and preffer the script and text mode command line more than GUI. So sorry about NO GUI here. About how to use the tools pack, please reference the readme inside the zip file, it should be clarify most issues.
mkblfont<--源代码[Source Code]
tools <--工具包[Tools Pack]
Frankly, I think the OpenSUSE nothing better except the GRUB. So in order to take the advantage of this cool boot interface, I tried to establish my Live USB and Live CD based on it. Considering most of buddies like Windows more, I did some work to migrate the whole thing to Windows platform. Here I just release the tool kits and discuss the detail processing of booting WINPE or customerize Live Ubuntu later. BTW, I also put the source code of mkblfont for Windows here. If anyone interesting in writing a GUI tool to cover all those function would be great, since I'm lazy and preffer the script and text mode command line more than GUI. So sorry about NO GUI here. About how to use the tools pack, please reference the readme inside the zip file, it should be clarify most issues.
mkblfont<--源代码[Source Code]
tools <--工具包[Tools Pack]
更新了在Ubuntu上修改gfxmenu中文显示的脚本。有空的时候,将它改成Windows下可以运行的执行文件。
Bash语言: gfxmenu中文显示脚本
01 #!/bin/bash
02 DEBUG=1
03 START_DIR=`pwd`
04 ##定义图形启动包的位置
05 MESSAGE=/boot/message
06 ##定义字形生成程序位置
07 MKBLFONT=mkblfont
08 ##定义menu.lst位置
09 MENU_LST=/boot/grub/menu.lst
10 ##定义键盘映射程序位置
11 KEYMAPCHARS=/usr/share/gfxboot/bin/keymapchars
12 ##定义键盘映射表位置
13 KEYTABLES=/usr/share/gfxboot-theme-ubuntu/keytables.inc
14 ##定义临时文件位置
15 TMP_FOLD=message
16 ##定义字形所用字体
17 TTFFont=simli
18 ##定义字体目录
19 TTFPath=/usr/share/fonts/truetype/microsoft
20 ##定义界面语言
21 LANGUAGE=简体中文
22 ##定义语言ID
23 LANG_ID=zh
24 ##定义默认启动语言
25 DEF_LANG=zh_CN
26 debug_msg()
27 {
28 [ $DEBUG == 1 ] && echo "[`date +"%F %T"`] $@" >&2
29 }
30
31 install_pkg()
32 {
33 local PKG=`sudo dpkg-query -W --showformat='${Package} ' |grep $1`
34 if [ -z $PKG ]; then
35 sudo aptitude install $1 -y
36 debug_msg "安装软件包 $1"
37 else
38 debug_msg "软件包 $1 已安装"
39 fi
40 }
41 install_pkg gfxboot-theme-ubuntu
42 echo $DEF_LANG >lang
43 mkdir $TMP_FOLD 2>/dev/null
44 cd $TMP_FOLD
45 #ls -l $MESSAGE #>/dev/null 2>&1
46 if [ -e $MESSAGE ]; then
47 cat $MESSAGE |cpio -i
48 else
49 echo "抱歉没发现要修改的$MESSAGE"
50 exit
51 fi
52 echo $DEF_LANG >lang
53 if [ -e translations.$LANG_ID ]
54 then
55 echo "发现${LANGUAGE}翻译文件!"
56 else
57 echo "没有${LANGUAGE}的翻译文件,退出!"
58 exit
59 fi
60 if grep -q $LANG_ID languages
61 then
62 echo "文件languages含有${LANGUAGE}的ID!"
63 else
64 echo $LANG_ID > tmp.txt
65 cat tmp.txt languages >languages1
66 mv -f languages1 languages
67 echo "文件languages含有${LANGUAGE}的ID!"
68 fi
69 cat *.tr translations.* $MENU_LST >tmp.txt
70 echo $LANGUAGE>> tmp.txt
71 set -x
72 $MKBLFONT -v -l 18 -p /usr/share/fonts/X11/misc
73 -c ISO-8859-15 -c ISO-8859-2 -c koi8-r
74 `$KEYMAPCHARS $KEYTABLES`
75 -t tmp.txt
76 -p $TTFPath
77 -f $TTFFont:prop=2:space_width=4:size=17:nobitmap=1:autohint=1
78 16x16.fnt >16x16.fnt.log
79 set +x
80 rm -f tmp.txt
81 mv 16x16.fnt.log $START_DIR
82 echo "备份以前文件"
83 mv $MESSAGE $MESSAGE.bck
84 ls . |cpio -o > $MESSAGE
85 cd $START_DIR
86 rm -rf $TMP_FOLD
02 DEBUG=1
03 START_DIR=`pwd`
04 ##定义图形启动包的位置
05 MESSAGE=/boot/message
06 ##定义字形生成程序位置
07 MKBLFONT=mkblfont
08 ##定义menu.lst位置
09 MENU_LST=/boot/grub/menu.lst
10 ##定义键盘映射程序位置
11 KEYMAPCHARS=/usr/share/gfxboot/bin/keymapchars
12 ##定义键盘映射表位置
13 KEYTABLES=/usr/share/gfxboot-theme-ubuntu/keytables.inc
14 ##定义临时文件位置
15 TMP_FOLD=message
16 ##定义字形所用字体
17 TTFFont=simli
18 ##定义字体目录
19 TTFPath=/usr/share/fonts/truetype/microsoft
20 ##定义界面语言
21 LANGUAGE=简体中文
22 ##定义语言ID
23 LANG_ID=zh
24 ##定义默认启动语言
25 DEF_LANG=zh_CN
26 debug_msg()
27 {
28 [ $DEBUG == 1 ] && echo "[`date +"%F %T"`] $@" >&2
29 }
30
31 install_pkg()
32 {
33 local PKG=`sudo dpkg-query -W --showformat='${Package} ' |grep $1`
34 if [ -z $PKG ]; then
35 sudo aptitude install $1 -y
36 debug_msg "安装软件包 $1"
37 else
38 debug_msg "软件包 $1 已安装"
39 fi
40 }
41 install_pkg gfxboot-theme-ubuntu
42 echo $DEF_LANG >lang
43 mkdir $TMP_FOLD 2>/dev/null
44 cd $TMP_FOLD
45 #ls -l $MESSAGE #>/dev/null 2>&1
46 if [ -e $MESSAGE ]; then
47 cat $MESSAGE |cpio -i
48 else
49 echo "抱歉没发现要修改的$MESSAGE"
50 exit
51 fi
52 echo $DEF_LANG >lang
53 if [ -e translations.$LANG_ID ]
54 then
55 echo "发现${LANGUAGE}翻译文件!"
56 else
57 echo "没有${LANGUAGE}的翻译文件,退出!"
58 exit
59 fi
60 if grep -q $LANG_ID languages
61 then
62 echo "文件languages含有${LANGUAGE}的ID!"
63 else
64 echo $LANG_ID > tmp.txt
65 cat tmp.txt languages >languages1
66 mv -f languages1 languages
67 echo "文件languages含有${LANGUAGE}的ID!"
68 fi
69 cat *.tr translations.* $MENU_LST >tmp.txt
70 echo $LANGUAGE>> tmp.txt
71 set -x
72 $MKBLFONT -v -l 18 -p /usr/share/fonts/X11/misc
73 -c ISO-8859-15 -c ISO-8859-2 -c koi8-r
74 `$KEYMAPCHARS $KEYTABLES`
75 -t tmp.txt
76 -p $TTFPath
77 -f $TTFFont:prop=2:space_width=4:size=17:nobitmap=1:autohint=1
78 16x16.fnt >16x16.fnt.log
79 set +x
80 rm -f tmp.txt
81 mv 16x16.fnt.log $START_DIR
82 echo "备份以前文件"
83 mv $MESSAGE $MESSAGE.bck
84 ls . |cpio -o > $MESSAGE
85 cd $START_DIR
86 rm -rf $TMP_FOLD
很喜欢OpenSUSE的图形化GRUB启动菜单,但是在使用的时候发现,菜单内容不能使中文。搜索后发现图形菜单可以自己修改的,并发现起重新组装的部分可以利用来生成其中关键文件16x16.fnt文件。动手写了个小脚本,保存一下,供以后修改。目前在OpenSUSE上修改成功。Ubuntu下面没有测试过。主要是不知道gfxboot-font和keymapschar文件是否存在。
Bash语言: GFXBOOT菜单中文显示修改脚本
01 #!/bin/bash
02 echo "Please wait for searching the gfxboot-font & keymapchars command available or not ..."
03 ##Define gfxmenu used message
04 MESSAGE=/boot/message
05 ##Define the gfxboot-font command localtion
06 #You can manual specify the location
07 GFXBOOT_FONT=`find / -name gfxboot-font -type f 2>/dev/null |head -n 1`
08 ##Define keymapschars command location
09 KEYMAPCHARS=`find / -name keymapchars -type f 2>/dev/null |head -n 1`
10 ##Define keymaps directory location
11 #KEYMAPS=/usr/share/gfxboot/themes/openSUSE/keymaps
12 KEYMAPS=`find / -name keymap.cs_CZ.inc -type f 2>/dev/null |head -n 1`
13 KEYMAPS=${KEYMAPS%/keymap.cs_CZ.inc}
14 ##Define temp fold location
15 TMP_FOLD=message
16 ##Define langauge need font name
17 TTFFont=ukai
18 ##Define langauge will show on the boot menu
19 LANGUAGE=简体中文
20 ##Define language ID will add into languages
21 LANG_ID=zh
22 ##Define default boot menu language ID
23 DEF_LANG=zh_CN
24 mkdir $TMP_FOLD
25 cd $TMP_FOLD
26 cat $MESSAGE |cpio -i
27 echo $DEF_LANG >lang
28 echo "File lang is ready!"
29 if [ -e translations.$LANG_ID ]
30 then
31 echo "File translations.$LANG_ID is ready!"
32 else
33 echo "Sorry the translation file is not there! Quiting..."
34 exit
35 fi
36 if grep -q $LANG_ID languages
37 then
38 echo "File languages is ready!"
39 else
40 echo $LANG_ID > tmp.txt
41 cat tmp.txt languages >languages1
42 cp -f languages1 languages
43 rm -f languages1
44 echo "File languages is ready!"
45 fi
46 cat *.tr translations.* pabout.txt /boot/grub/menu.lst >tmp.txt
47 echo $LANGUAGE>> tmp.txt
48 $GFXBOOT_FONT -v -l 18
49 -c ISO-8859-15 -c ISO-8859-2 -c koi8 -c utf8 -r
50 `$KEYMAPCHARS $KEYMAPS/keymap.*.inc`
51 -t tmp.txt
52 -t languages
53 -f NachlieliCLM-Bold:size=14:c=0x590-0x5ff
54 -f KacstOne:size=14:c=0x600-0x6ff,0xfe70-0xfefc:dy=2
55 -f MuktiNarrow:size=18:c=0x0981-0x09fa:bold=1
56 -f lohit_hi:size=18:c=0x0901-0x0970:bold=1
57 -f lohit_pa:size=19:c=0x0a01-0x0a74:bold=1:autohint=1
58 -f lohit_gu:size=18:c=0x0a81-0x0af1:bold=1
59 -f TSCu_Paranar:size=18:c=0x0b82-0x0bfa:dy=2:bold=1
60 -f lklug:size=17:c=0x0d82-0x0df4:bold=1:dy=1
61 -f Loma:size=17:c=0x0e01-0x0e7f:bold=0:dy=-2
62 -f KhmerOS_sys:size=16:c=0x1780-0x17f9:dy=-2
63 -f DejaVuSans-Bold:size=14
64 -f $TTFFont:size=17:nobitmap=1:autohint=1
65 -f gulim:size=17:bold=1:nobitmap=1:autohint=1
66 16x16.fnt >16x16.fnt.log
67 echo "File 16x16.fnt is ready!"
68 rm -f tmp.txt
69 mv 16x16.fnt.log ../
70 echo "Making backup..."
71 cp $MESSAGE $MESSAGE.bck
72 ls . |cpio -o > $MESSAGE
73 echo "Please clear the tmp directory message!"
02 echo "Please wait for searching the gfxboot-font & keymapchars command available or not ..."
03 ##Define gfxmenu used message
04 MESSAGE=/boot/message
05 ##Define the gfxboot-font command localtion
06 #You can manual specify the location
07 GFXBOOT_FONT=`find / -name gfxboot-font -type f 2>/dev/null |head -n 1`
08 ##Define keymapschars command location
09 KEYMAPCHARS=`find / -name keymapchars -type f 2>/dev/null |head -n 1`
10 ##Define keymaps directory location
11 #KEYMAPS=/usr/share/gfxboot/themes/openSUSE/keymaps
12 KEYMAPS=`find / -name keymap.cs_CZ.inc -type f 2>/dev/null |head -n 1`
13 KEYMAPS=${KEYMAPS%/keymap.cs_CZ.inc}
14 ##Define temp fold location
15 TMP_FOLD=message
16 ##Define langauge need font name
17 TTFFont=ukai
18 ##Define langauge will show on the boot menu
19 LANGUAGE=简体中文
20 ##Define language ID will add into languages
21 LANG_ID=zh
22 ##Define default boot menu language ID
23 DEF_LANG=zh_CN
24 mkdir $TMP_FOLD
25 cd $TMP_FOLD
26 cat $MESSAGE |cpio -i
27 echo $DEF_LANG >lang
28 echo "File lang is ready!"
29 if [ -e translations.$LANG_ID ]
30 then
31 echo "File translations.$LANG_ID is ready!"
32 else
33 echo "Sorry the translation file is not there! Quiting..."
34 exit
35 fi
36 if grep -q $LANG_ID languages
37 then
38 echo "File languages is ready!"
39 else
40 echo $LANG_ID > tmp.txt
41 cat tmp.txt languages >languages1
42 cp -f languages1 languages
43 rm -f languages1
44 echo "File languages is ready!"
45 fi
46 cat *.tr translations.* pabout.txt /boot/grub/menu.lst >tmp.txt
47 echo $LANGUAGE>> tmp.txt
48 $GFXBOOT_FONT -v -l 18
49 -c ISO-8859-15 -c ISO-8859-2 -c koi8 -c utf8 -r
50 `$KEYMAPCHARS $KEYMAPS/keymap.*.inc`
51 -t tmp.txt
52 -t languages
53 -f NachlieliCLM-Bold:size=14:c=0x590-0x5ff
54 -f KacstOne:size=14:c=0x600-0x6ff,0xfe70-0xfefc:dy=2
55 -f MuktiNarrow:size=18:c=0x0981-0x09fa:bold=1
56 -f lohit_hi:size=18:c=0x0901-0x0970:bold=1
57 -f lohit_pa:size=19:c=0x0a01-0x0a74:bold=1:autohint=1
58 -f lohit_gu:size=18:c=0x0a81-0x0af1:bold=1
59 -f TSCu_Paranar:size=18:c=0x0b82-0x0bfa:dy=2:bold=1
60 -f lklug:size=17:c=0x0d82-0x0df4:bold=1:dy=1
61 -f Loma:size=17:c=0x0e01-0x0e7f:bold=0:dy=-2
62 -f KhmerOS_sys:size=16:c=0x1780-0x17f9:dy=-2
63 -f DejaVuSans-Bold:size=14
64 -f $TTFFont:size=17:nobitmap=1:autohint=1
65 -f gulim:size=17:bold=1:nobitmap=1:autohint=1
66 16x16.fnt >16x16.fnt.log
67 echo "File 16x16.fnt is ready!"
68 rm -f tmp.txt
69 mv 16x16.fnt.log ../
70 echo "Making backup..."
71 cp $MESSAGE $MESSAGE.bck
72 ls . |cpio -o > $MESSAGE
73 echo "Please clear the tmp directory message!"
前段时间在ChinaUnix上看到一个关于质数寻找的数学赛题,需要利用计算机辅助搜寻。很感兴趣,便作为了思维体操的题目。研究了4天多,得出了一些结果,但是也放下了一段时间。这里做个整理,记录一下相关进展。
搜寻质数的思路是限定以一个搜寻范围,即定义一个最大数Max_Int,然后在这个正整数范围内产生所有的N个自然数的组合,进行组合运算的测试。组合 运算是指N个数各自在于-1,0,+1相乘后的结果求和的运算。如果组合运算的结果是质
搜寻质数的思路是限定以一个搜寻范围,即定义一个最大数Max_Int,然后在这个正整数范围内产生所有的N个自然数的组合,进行组合运算的测试。组合 运算是指N个数各自在于-1,0,+1相乘后的结果求和的运算。如果组合运算的结果是质




May 2, 2006 @ 07:06,