Chinaunix首页 | 论坛 | 博客
  • 博客访问: 292508
  • 博文数量: 76
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 715
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-20 20:38
文章分类
文章存档

2016年(20)

2015年(56)

分类: 嵌入式

2015-08-23 16:47:12

Main.c

15年8月23日16:18:56

#include <unistd.h>

#include <stdlib.h>

#include <stdio.h>

#include <config.h>

#include <draw.h>

#include <encoding_manager.h>

#include <fonts_manager.h>

#include <disp_manager.h>

#include <string.h>


/* ./show_file [-s Size] [-f freetype_font_file] [-h HZK] <text_file> */

int main(int argc, char **argv)

{

int iError;

unsigned int dwFontSize = 16;

char acHzkFile[128];

char acFreetypeFile[128];

char acTextFile[128];


char acDisplay[128];


char cOpr;

int bList = 0;


acHzkFile[0] = '\0';

acFreetypeFile[0] = '\0';

acTextFile[0] = '\0';


strcpy(acDisplay, "fb");

while ((iError = getopt(argc, argv, "ls:f:h:d:")) != -1)

{

switch(iError)

{

case 'l':

{

bList = 1;

break;

}

case 's':

{

dwFontSize = strtoul(optarg, NULL, 0);

break;

}

case 'f':

{

strncpy(acFreetypeFile, optarg, 128);

acFreetypeFile[127] = '\0';

break;

}

case 'h':

{

strncpy(acHzkFile, optarg, 128);

acHzkFile[127] = '\0';

break;

}

case 'd':

{

strncpy(acDisplay, optarg, 128);

acDisplay[127] = '\0';

break;

}

default:

{

printf("Usage: %s [-s Size] [-d display] [-f font_file] [-h HZK] <text_file>\n", argv[0]);

printf("Usage: %s -l\n", argv[0]);

return -1;

break;

}

}

}


if (!bList && (optind >= argc))

{

printf("Usage: %s [-s Size] [-d display] [-f font_file] [-h HZK] <text_file>\n", argv[0]);

printf("Usage: %s -l\n", argv[0]);

return -1;

}

iError = DisplayInit();

if (iError)

{

printf("DisplayInit error!\n");

return -1;

}


iError = FontsInit();

if (iError)

{

printf("FontsInit error!\n");

return -1;

}


iError = EncodingInit();

if (iError)

{

printf("EncodingInit error!\n");

return -1;

}


if (bList)

{

printf("supported display:\n");

ShowDispOpr();


printf("supported font:\n");

ShowFontOpr();


printf("supported encoding:\n");

ShowEncodingOpr();

return 0;

}


strncpy(acTextFile, argv[optind], 128);

acTextFile[127] = '\0';

iError = OpenTextFile(acTextFile);

if (iError)

{

printf("OpenTextFile error!\n");

return -1;

}


iError = SetFontsDetail(acHzkFile, acFreetypeFile, dwFontSize);

if (iError)

{

printf("SetTextDetail error!\n");

return -1;

}


DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);


iError = SelectAndInitDisplay(acDisplay);

if (iError)

{

printf("SelectAndInitDisplay error!\n");

return -1;

}

DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);

iError = ShowNextPage();

DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);

if (iError)

{

printf("Error to show first page\n");

return -1;

}


while (1)

{

printf("Enter 'n' to show next page, 'u' to show previous page, 'q' to exit: ");


do {

cOpr = getchar();

} while ((cOpr != 'n') && (cOpr != 'u') && (cOpr != 'q'));


if (cOpr == 'n')

{

ShowNextPage();

}

else if (cOpr == 'u')

{

ShowPrePage();

}

else

{

return 0;

}

}

return 0;

}


想要理解那些文件的关系,最好的开始方式是从main函数开始分析:

1main函数开始用一个getopt函数来选择输入输入选项,这个函数的介绍可以去参考《UNIX环境高级编程》书里面。暂时不分析,先分析函数的执行步骤。

2DisplayInit()函数,调用FBInit()函数将g_tFBDispOpr结构体添加到g_ptDispOprHead;链表中。

3FontsInit()函数,分别调用ASCIIInit()GBKInit()FreeTypeInit()三个函数,分别将g_tASCIIFontOprg_tGBKFontOprg_tFreeTypeFontOpr三个结构体,注册到 g_ptFontOprHead链表中。这样这个链表中就有3项了~

4EncodingInit()函数,分别调用AsciiEncodingInit()Utf16leEncodingInit()Utf16beEncodingInit()Utf8EncodingInit()四个函数,这四个函数分别将g_tAsciiEncodingOprg_tUtf16leEncodingOprg_tUtf16beEncodingOprg_tUtf8EncodingOpr这四个结构体注册到g_ptEncodingOprHead链表中,但是在注册到链表之前,对于每一个结构体,先将每种编码方式支持的字体添加到对应结构体里面的ptFontOprSupportedHead链表中。

5)如果输入了”l”选项,就将bList设置为1了,这样就打印出一些设备,字体,编码支持信息。

6OpenTextFile()函数,根据传入的acTextFile参数,打开文件,获取文件信息,然后映射到内存中,调用SelectEncodingOprForFile()函数,来选择文件支持的编码方式,这个函数返回的结构体存在g_ptEncodingOprForFile中,如果确定编码的话,就可以确定g_pucLcdFirstPosAtFile参数,这样就可以从这个位置取编码了。

7)获取编码以后,调用SetFontsDetail()函数来设置字体细节,这个函数根据g_ptEncodingOprForFile->ptFontOprSupportedHead这个链表选取编码支持的字体进行设置。

8SelectAndInitDisplay()函数根据acDisplay这个参数选择显示的设备,从g_ptDispOpr链表中选择与acDisplay名字相同的设备,并初始化它。

9)以上步骤完成以后,就可以调用ShowNextPage()函数了,pucTextFileMemCurPos = g_pucLcdFirstPosAtFile,然后调用ShowOnePage(pucTextFileMemCurPos)函数来显示一页,ShowOnePage函数从内存中一一取出编码,根据编码选择字体,然后显示,直到文件结束或者满屏了。如果显示一页成功以后,在ShowNextPage函数中记录下这一页的信息。

10main函数进入while循环来等待用户输入。


阅读(1777) | 评论(0) | 转发(0) |
0

上一篇:电子书-fonts_manager.c

下一篇:电子书-Utf-8.c

给主人留下些什么吧!~~