嵌入式linux电子阅读器 综合程序代码解析

博客主要介绍了main.c和draw.c两个文件的功能。main.c负责判断输入参数并调用draw.c函数,而draw.c则调用三大模块函数,涉及代码的基本逻辑和函数调用关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

main.c

判断输入参数及调用draw.c函数

#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");
	//1、使用getopt解析参数里面的选项,当遇到第一个选项字符时,并将全局变量optarg指向该选项的参数,这里使用while,找到了optstring中的所有选项
	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':
			{
		          //2、指定长度的字符串拷贝
				  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;
			}
		}
	}
    //3、optind代表optarg下一个要处理的命令行参数的索引,这里optind >= argc的话,代表没有对应的参数
	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;
	}
        //4、disp显示结构体注册
	iError = DisplayInit();
	if (iError)
	{
		printf("DisplayInit error!\n");
		return -1;
	}
    //5、glyph结构体注册
	iError = FontsInit();
	if (iError)
	{
		printf("FontsInit error!\n");
		return -1;
	}
    //6、编码结构体注册
	iError = EncodingInit();
	if (iError)
	{
		printf("EncodingInit error!\n");
		return -1;
	}

	if (bList)
	{
	        //7、打印所有disp的结构体name(所有支持的disp方式:fb)
		printf("supported display:\n");
		ShowDispOpr();
                //8、打印所有glyph的结构体name(所有获取glyph的方式:ascii,freetype,gbk)
		printf("supported font:\n");
		ShowFontOpr();
        //9、打印所有支持编码的结构体name(所有支持的编码:ascii,utf-8,utf-16)
		printf("supported encoding:\n");
		ShowEncodingOpr();
		return 0;
	}
        //10、optarg解析完参数后,未解析到的参数就是texstfile(novel_file)
	strncpy(acTextFile, arg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值