linux应用程序_1_文本浏览器_6_main测试
至此还没有抽象出输入结构体,仅使用串口完成测试
main流程:
1、解析命令行参数,根据参数发出不同动作
若参数满足
2、打开文本(选中编码)
3、选中显示设备
4、显示开始
完整代码
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <config.h>
#include <draw.h>
#include <encoding_manager.h>
#include <fonts_manager.h>
#include <disp_manager.h>
int main(int argc, char *argv[])
{
char pcHzkName[20];
char pcFreetypeName[20];
char pcTextName[20];
char pcDispName[20];
int iError;
int iList = 0;
int iFontSize = 16;
char cOneChar;
pcHzkName[0] = 0;
pcFreetypeName[0] = 0;
pcTextName[0] = 0;
pcDispName[0] = 0;
strcpy(pcDispName,"fb");
while ((iError = getopt(argc, argv, "ls:f:h:d:")) != -1)
{
switch(iError)
{
case 'l' :
{
iList = 1;
break;
}
case 's' :
{
iFontSize = strtoul(optarg, NULL, 0);
break;
}
case 'f' :
{
strncpy(pcFreetypeName, optarg, 20);
pcFreetypeName[19] = '0';
break;
}
case 'h' :
{
strncpy(pcHzkName, optarg, 20);
pcHzkName[19] = '0';
break;
}
case 'd' :
{
strncpy(pcDispName, optarg, 20);
pcDispName[19] = '\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;
}
}
}
if (!iList && (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 = DrawInit();
if(iError)
{
printf("DrawInit error!\n");
return -1;
}
if(iList)
{
ShowDispOpr();
ShowSupportFont();
ShowSupportEncoding();
return 0;
}
strncpy(pcTextName, argv[optind], 20);
pcTextName[19] = '\0';
iError = OpenTextFile(pcTextName);
if (iError)
{
printf("OpenTextFile error!\n");
return -1;
}
iError = SetFontsDetail(pcHzkName, pcFreetypeName, iFontSize);
if (iError)
{
printf("SetFontsDetail error!\n");
return -1;
}
iError = SelectAndInitDisplay(pcDispName);
if (iError)
{
printf("SelectAndInitDisplay error!\n");
return -1;
}
printf("Enter 'n' to show next page, 'u' to show previous page, 'q' to exit: \r\n");
ShowNextPage();
while(1)
{
do
{
cOneChar = getchar();
}
while((cOneChar != 'n') && (cOneChar != 'u') && (cOneChar != 'q'));
switch(cOneChar)
{
case 'u' :
{
ShowPrePage();
break;
}
case 'n' :
{
ShowNextPage();
break;
}
case 'q' :
{
printf("\r\n\r\nexit!\r\n");
DisplayExit();
return 0;
}
}
}
return 0;
}