⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.c

📁 一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上
💻 C
📖 第 1 页 / 共 3 页
字号:
				next_record_index = temp_II_index_list->next;
				for( i = 0; i < temp_II_index_list->num; i++ )
				{
					//获取记录表上已有记录的同一字段值
					tmp_id = next_record_index->index;
					time = GetRecordInfo( tmp_id, lacb->gacb->PLInfo, &head_info, time_field );
						
					if( ( field_I_index + 1 ) != 1 )
					{
						if( com_time_int.year == time.year )
						{
							count++;
							next_record_data->index = tmp_id;
							next_record_data->data = (BYTE *)head_info;
							next_record_data->datalen = head_info->size;
							next_record_data++;
						}else{
							SysLfree( head_info );
						}
//						else if( count == lacb->head->num )
//						{
//							break;
//						}
					}else{
						if( ( com_time_int.year - 1 ) == time.year )
						{
							count++;
							next_record_data->index = tmp_id;
							next_record_data->data = (BYTE *)head_info;
							next_record_data->datalen = head_info->size;
							next_record_data++;
						}else{
							SysLfree( head_info );
						}
//						else if( count == lacb->head->num )
//						{
//							break;
//						}
					}
					next_record_index = next_record_index->next;
				}
				temp_II_index_list--;
			}while( ( temp_II_index_list + 1 ) != week_II_index_list_1 );

			if( special_II_index_list == NULL )
			{
				goto	GetSearchList;
			}else{
				temp_II_index_list = special_II_index_list;
			}
			next_record_index = temp_II_index_list->next;
			for( i = 0; i < temp_II_index_list->num; i++ )
			{
				//获取记录表上已有记录的同一字段值
				tmp_id = next_record_index->index;
				time = GetRecordInfo( tmp_id, lacb->gacb->PLInfo, &head_info, time_field );
					
				if( com_time_int.year == time.year )	//同年
				{
					count++;
					next_record_data->index = tmp_id;
					next_record_data->data = (BYTE *)head_info;
					next_record_data->datalen = head_info->size;
					next_record_data++;
				}else{
					SysLfree( head_info );
				}
//				else if(  count == lacb->head->num )
//				{
//					break;
//				}
				next_record_index = next_record_index->next;
			}
			goto	GetSearchList;
			
			break;
		case YEAR_RANGE:
			month_I_index_list = lacb->gacb->FList[time_field].head;
			for( i = 0; i < lacb->gacb->FList[time_field].num; i++ )
			{
				temp_II_index_list = month_I_index_list->sub;
				for( j = 0; j < month_I_index_list->num; j++ )
				{
					lacb->head->num = (WORD)(lacb->head->num + temp_II_index_list->num );
					temp_II_index_list++;
				}
				month_I_index_list++; 
			}

			if( lacb->head->num == 0 )
				goto  endrv;

			if( ( record_head = (RECORDDATA *)SysLmalloc( sizeof(RECORDDATA) * lacb->head->num ) ) == NULL ) 
				return NULL;

			count = 0;//计算实际符合搜索的记录
			next_record_data = record_head;
			month_I_index_list = I_index_list;
			temp_II_index_list = II_index_list;	
			day_num = (WORD)( field_II_index + 1 );

			month_I_index_list = lacb->gacb->FList[time_field].head;	//1月
			for( k = 0; k < lacb->gacb->FList[time_field].num; k++ )	//12个月
			{
				temp_II_index_list = month_I_index_list->sub;			
				for( j = 0; j < month_I_index_list->num; j++ )			//28,29,30,31天	
				{
					next_record_index = temp_II_index_list->next;
					for( i = 0; i < temp_II_index_list->num; i++ )
					{
						//获取记录表上已有记录的同一字段值
						tmp_id = next_record_index->index;
						time = GetRecordInfo( tmp_id, lacb->gacb->PLInfo, &head_info, time_field );
						
						if( ( ( com_time_int.year == time.year ) && ( com_time_int.month > time.month ) )	
						|| ( ( com_time_int.year == time.year ) && ( com_time_int.month == time.month ) && ( com_time_int.day >= time.day ) )
						|| ( ( ( com_time_int.year - 1 ) == time.year ) && ( com_time_int.month == time.month ) && ( com_time_int.day < time.day ) )
						|| ( ( ( com_time_int.year - 1 ) == time.year ) && ( com_time_int.month < time.month ) ) )
						{
							count++;
							next_record_data->index = tmp_id;
							next_record_data->data = (BYTE *)head_info;
							next_record_data->datalen = head_info->size;
							next_record_data++;
						}else{
							SysLfree( head_info );
						}
//						else if( count == lacb->head->num ) 
//						{
//							break;
//						}
						next_record_index = next_record_index->next;
					}
					temp_II_index_list++;
				}
				month_I_index_list++; 
			}
			break;
	}

GetSearchList:
	lacb->head->num = count;
	if( count == 0 )
	{
		SysLfree( record_head );
		goto  endrv;
	}
	if( ( record_data_head = (RECORDDATA *)SysLmalloc( sizeof(RECORDDATA) * count ) ) == NULL ) 
		return NULL;
	memcpy( record_data_head, record_head, ( sizeof(RECORDDATA) * count ) );
//	lacb->head->num = count;
	lacb->head->head = record_data_head;
	SysLfree( record_head );
endrv:
	return	lacb->head;
}

/**********************************************************************/
//获取年和记录数据
//DWORD GetRecordInfo( DWORD id, DBPHYLAYERINFO *info, DBRECORDHEAD **head_info, WORD *year, BYTE time_field )
TIME_INDEX GetRecordInfo( DWORD id, DBPHYLAYERINFO *info, DBRECORDHEAD **head_info, BYTE time_field )
{
	BYTE		*record, *record_data, *field_value;
#ifdef SIM_ON_PC
	WORD		*field_head;
#else
	WORD		field_head;
#endif
	TIME_INDEX  time, conversion_time;
	DWORD		read_rv = DB_OK;
	
	//获取记录表上已有记录的同一字段值
	GlobalReadRecord( info, id, &record );
	*head_info = (DBRECORDHEAD *)record;

	record_data = (BYTE *)(&(*head_info)->data);
#ifdef SIM_ON_PC
	field_head = (WORD *)record_data;
	if( field_head[time_field] != 0 )			// 字段有字段值
	{
		field_value = record_data + field_head[time_field];
#else
	Bytes2Word( &field_head, record_data+time_field*sizeof(WORD) );
	if( field_head != 0 )			// 字段有字段值
	{
		field_value = record_data + field_head;
#endif

		memcpy( &time, field_value, sizeof( TIME_INDEX ) );
		Time2Int( &time, &conversion_time );
	}
	return conversion_time;
}

/**********************************************************************/
//获取查找表
//LOCALSEARCHLIST *ObtainSearchList( LOCALSEARCHLIST *searchlist, DBPHYLAYERINFO *info, RECORDINDEX *local_search_list, WORD num )
RECORDDATA *ObtainSearchList( DBPHYLAYERINFO *info, RECORDINDEX *local_search_list, WORD num )
{
	RECORDDATA			*record_data_head, *next_record_data;
	RECORDINDEX			*next_record_index;
	DBRECORDHEAD		*head_info;
	WORD				i;
	DWORD				tmp_id;
	DWORD				read_rv = DB_OK;
	BYTE				*record, *record_data = NULL;

	if( ( record_data_head = (RECORDDATA *)SysLmalloc( sizeof(RECORDDATA) * num ) ) == NULL ) 
		return NULL;

	next_record_data = record_data_head;
	next_record_index = local_search_list;
	for( i = 0; i < num; i++ )
	{
		//获取记录表上已有记录的同一字段值
		tmp_id = next_record_index->index;
		read_rv = GlobalReadRecord( info, tmp_id, &record );
		if( read_rv != DB_OK )
			goto endrv;
		head_info = (DBRECORDHEAD *)record;
//		record_data = (BYTE *)(&head_info->data);

		next_record_data->index = tmp_id;
		next_record_data->data = record;
		next_record_data->datalen = head_info->size;

		next_record_index = next_record_index->next;
		next_record_data++;
	}

endrv:
	return	record_data_head;
}

/**********************************************************************/
//获取时间字段值的一二级索引
void GetTimeFieldIandIIIndex( BYTE *field_value, WORD *field_I_index, WORD *field_II_index )
{
	TIME_INDEX	time;

	memcpy( &time, field_value, sizeof(TIME_INDEX) );
#ifdef SIM_ON_PC	
	*field_I_index = (WORD)( ( time.month & 0x0f ) * 10 + ( ( time.month >> 8 ) & 0x0f ) - 1 );
	*field_II_index = (WORD)( ( time.day & 0x0f ) * 10 + ( ( time.day >> 8 ) & 0x0f ) - 1 );
#else
	*field_I_index = (WORD)( ( time.month & 0x0f ) + ( ( time.month >> 8 ) & 0x0f ) * 10 - 1 );
	*field_II_index = (WORD)( ( time.day & 0x0f )+ ( ( time.day >> 8 ) & 0x0f ) * 10 - 1 );
#endif
}

/**********************************************************************/
//获取需用查找模式的记录列表
DWORD SearchPreciseRecord( FIELDINDEX *II_index_list, DBLACB *lacb, BYTE field, BYTE *data, BYTE mode )
{
	WORD				i, count = 0;
	CHAR				rv;			//字段值比较结果
	DBRECORDHEAD		*head_info;
	RECORDINDEX			*next_record_index; 
	RECORDDATA			*record_head, *next_record_data;
	BYTE				*record;	//记录数据
	BYTE				*record_data = NULL, *field_value, *tmp_field_value;
	WORD				record_size, cmp_data_size;
#ifdef SIM_ON_PC
	WORD				*field_head;
#else
	WORD				field_head;
#endif
	DWORD				tmp_id;		//记录地址
	DWORD				read_rv = DB_OK;
	
	if( ( record_head = (RECORDDATA *)SysLmalloc( sizeof(RECORDDATA) * II_index_list->num ) ) == NULL ) 
		return DB_ERROR;

	next_record_data = record_head;
	next_record_index = II_index_list->next;
	for( count = 0, i = 0; i < II_index_list->num; i++ )
	{
		//获取记录表上已有记录的同一字段值
		tmp_id = next_record_index->index;
		read_rv = GlobalReadRecord( lacb->gacb->PLInfo, tmp_id, &record );
		if( read_rv != DB_OK )
		{
			SysLfree( record_head );
			return DB_ERROR;
		}
		head_info = (DBRECORDHEAD *)record;
		record_size = head_info->size;

		record_data = (BYTE *)(&head_info->data);
#ifdef SIM_ON_PC
		field_head = (WORD *)record_data;
		if( field_head[field] != 0 )			// 字段有字段值
#else
		Bytes2Word( &field_head, record_data+field*sizeof(WORD) );
		if( field_head != 0 )			// 字段有字段值
#endif
		{
#ifdef SIM_ON_PC
			field_value = record_data + field_head[field];
#else
			field_value = record_data + field_head;
#endif
			rv = strcmp( field_value, data );	//比较同一字段

			if( ( ( rv == 0 ) && ( mode == PRECISE_FULL_MATCH ) )		//完全匹配
				|| ( ( rv >= 0 ) && ( mode == PRECISE_PART_MATCH ) ) )	//部分匹配	
			{
				if( mode == PRECISE_PART_MATCH )	//部分匹配只用在姓名字段上
				{
					cmp_data_size = (WORD)strlen(data);
					if( ( tmp_field_value = SysLmalloc( cmp_data_size + 1 ) ) == NULL )
						return DB_ERROR;
					memcpy( tmp_field_value, field_value, cmp_data_size );
					*( tmp_field_value + cmp_data_size ) = '\0';
					rv = strcmp( tmp_field_value, data );
					SysLfree( tmp_field_value );
				}
				
				if( rv == 0 )
				{
					next_record_data->index = tmp_id;
					next_record_data->datalen = record_size;
					next_record_data->data = record;
					count++;
					next_record_data++;
				}else{
					SysLfree( record );
				}
			}else{
				SysLfree( record );
			}
		}
		next_record_index = next_record_index->next;
	}

	lacb->head->num = count;
	if( count != 0)
	{
		lacb->head->head = record_head;
	}else{
		SysLfree( record_head );
	}
	return DB_OK;
}

/***********************************************************************************************/
//把字符串型的时间转换成整型值的时间	
void Time2Int( TIME_INDEX *time, TIME_INDEX *conversion_time )
{
#ifdef SIM_ON_PC	
	conversion_time->year = (DWORD)( ( ( time->year & 0x0f )*1000 ) + ( (time->year >> 8 ) & 0x0f )*100
							+ ( ( time->year >> 16 ) & 0x0f )*10 + ( ( time->year >> 24 ) & 0x0f ) );
	conversion_time->month = (WORD)( ( ( time->month & 0x0f )*10 ) + ( (time->month >> 8 ) & 0x0f ) );
	conversion_time->day = (WORD)( ( ( time->day & 0x0f )*10 ) + ( (time->day >> 8 ) & 0x0f ) );
	conversion_time->hour = (WORD)( ( ( time->hour & 0x0f )*10 ) + ( (time->hour >> 8 ) & 0x0f ) );
	conversion_time->minute = (WORD)( ( ( time->minute & 0x0f )*10 ) + ( (time->minute >> 8 ) & 0x0f ) );
	conversion_time->second = (WORD)( ( ( time->second & 0x0f )*10 ) + ( (time->second >> 8 ) & 0x0f ) );
#else
	conversion_time->year = ( ( ( time->year & 0x0f ) ) + ( (time->year >> 8 ) & 0x0f )*10
							+ ( ( time->year >> 16 ) & 0x0f )*100 + ( ( time->year >> 24 ) & 0x0f )*1000 );
	conversion_time->month = (WORD)( ( ( time->month & 0x0f )*10 ) + ( (time->month >> 8 ) & 0x0f ) );
	conversion_time->day = (WORD)( ( ( time->day & 0x0f ) ) + ( (time->day >> 8 ) & 0x0f )*10 );
	conversion_time->hour = (WORD)( ( ( time->hour & 0x0f ) ) + ( (time->hour >> 8 ) & 0x0f )*10 );
	conversion_time->minute = (WORD)( ( ( time->minute & 0x0f ) ) + ( (time->minute >> 8 ) & 0x0f )*10  );
	conversion_time->second = (WORD)( ( ( time->second & 0x0f ) ) + ( (time->second >> 8 ) & 0x0f )*10 );
#endif

}

/***********************************************************************************************/
//释放记录列表	
void FreeRecordList( RECORDINDEX *record_list)
{
	RECORDINDEX *next_record_index, *prev_record_index;

	next_record_index = record_list;
	while( next_record_index != NULL )
	{
		prev_record_index = next_record_index->next;
		SysLfree(next_record_index);
		next_record_index = prev_record_index;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -