ks_sys.c 文件分析
来源:互联网 发布:mysql not like 编辑:程序博客网 时间:2024/05/17 23:05
ks_sys.c 用来创建配置文件,主要配置:[HOST] [ IP] [ DHCP] [HCLONE] [PPPOE] [SWITCH]......
把这个文件反复看了几遍,因为要用到里面的几个文件操作函数,试着分析了一下,能力有限,错误难免.
static char *fconfig = "/tmp/sysconfig"; /* file name */
char glvalue[256]; /* globe var */
/*
* 计算行的字符数
*/
static int fgetline(FILE * fwd, char * linebuf)
{
int data;
int i;
i = 0;
while (((data = fgetc(fwd)) != EOF) && (data != '/n')) { // 读取文件数据判断有效并不是回车
*(linebuf+i) = data; /* 给指针赋值.并指向下一个地址. */
i++;
}
*(linebuf+i) = '/0'; /* 最后补上/0,字符串. */
if (data == EOF) /* 无值. */
return EOF;
return i; /* 得到的行字符数返回. */
}
/* this is the entry point for shell program sysconfig */
int sysconfig(int argc, char argv[3][200], char *supBuf)
/* index the number of item to be skipped, starting from 1 */
static int print_config(FILE *handle, char *category, char* item, int index )
{
int i, result;
if ( 0 == (result= find_category(handle, category))) // 找寻目录[ ]
{
/*skip first index items*/
for ( i=1; i<index; i++)
{
result = find_item(handle, item); // 找寻[ ] 中的一行值.
if ( 0 != result )
return (result);
}
/*get to the target item */
if ( 0 == (result = find_item(handle, item)))
print_item_value(handle); // 输出到配置文件
}
return (result);
}
/* 文件位置 */
static long find_postion(FILE *handle, char *item, int flag)
{
int index;
long position;
char tmp[3], temp[128], fg;
if ( flag == 0 )
fg = '/n'; /*by whole item string match*/
else
fg = '='; /*by item number in the list first one is 1 */
do
{
index = 0;
position = ftell(handle); // 得到文件位置值.
do
{
if ( 0 != fread(tmp, sizeof(char), 1, handle) ) // 读文件最开始的一个值.
{
temp[index++] = tmp[0]; // 读到的第一个值存入temp[]数组中.
if ( tmp[0] == '[') // 最开始值为'['
return -1L;
}
else
return (-1L);
}while ( tmp[0] != fg ); // fg 为上面得到的值,由flag参数习决定.
if ( fg == '=')
temp[index] = '/0';
else
temp[index-1] = '/0';
#ifndef WINDOWS
if (!strcasecmp (item, temp))
#else
if (!stricmp(item, temp))
#endif
{
if ( 0 == fseek(handle, position, SEEK_SET))
return (position);
else
return (-1L);
}
else
{
if ( fg == '=')
{
do
{
if ( 0 == fread(tmp, sizeof(char), 1, handle))
return (-1L);
}while (tmp[0] != '/n');
}
position = ftell(handle);
}
} while (tmp[0] != '[');
return (-1L);
}
- ks_sys.c 文件分析
- mpegts.c文件分析
- sharelist.c文件分析
- mpegts.c文件分析
- mpegts.c文件分析
- mpegts.c文件分析
- lib\kobject.c文件分析
- lib\kobject.c文件分析
- STM32 usb_pwr.c文件分析
- android init.c 文件分析
- FaceBook/infer-分析C文件
- STM32 system_stm32f10x.c文件分析
- net/ipv4/route.c文件分析
- BMP图形文件分析类(c#)
- BMP图形文件分析类(c#)
- linux内核之trap.c文件分析
- linux0.01内核trap.c文件分析
- kobject之kobject_uevent.c文件分析
- C语言嵌入式系统编程修炼(内存操作)
- Access 的 AutoExec 宏
- Windows网络编程示例二——反应式echo服务器
- web编程 之document对象详解
- GUnwrapper v 1.3.3 by dr.carbon
- ks_sys.c 文件分析
- Linux下常用CVS命令
- 牛人总结:懒男人的十二大好处
- opentelnet.exe 源代码
- 70,80,90后的离奇区别
- 我的IT这几年(三)
- 如何判断一个单向链表是否有环路
- 给C++初学者的50个忠告(转)
- 电脑自动关机如何设置