c到pascal的语法对应

tzh2001 2003-11-02 10:23:00
我最近要将一个c的头文件转换为pascal
但不知道一些c特有的语法怎样在pascal中实现
示例代码如下:
#ifndef _time_calls
#define _time_calls

#ifdef WIN_NT_DRIVER

#include "debug.h"

/*!
\brief A microsecond precise timestamp.

included in the sf_pkthdr or the bpf_hdr that NPF associates with every packet.
*/

struct timeval {
long tv_sec; ///< seconds
long tv_usec; ///< microseconds
};

#endif /*WIN_NT_DRIVER*/

struct time_conv
{
ULONGLONG reference;
struct timeval start;
};

#ifdef WIN_NT_DRIVER

__inline void TIME_DESYNCHRONIZE(struct time_conv *data)
{
data->reference = 0;
data->start.tv_sec = 0;
data->start.tv_usec = 0;
}

#ifdef KQPC_TS

/* KeQueryPerformanceCounter TimeStamps */

#pragma optimize ("g",off) //Due to some weird behaviour of the optimizer of DDK build 2600

__inline VOID TIME_SYNCHRONIZE(struct time_conv *data)
{
struct timeval tmp;
LARGE_INTEGER SystemTime;
LARGE_INTEGER i;
ULONG tmp2;
LARGE_INTEGER TimeFreq,PTime;

if (data->reference!=0)
return;

// get the absolute value of the system boot time.

PTime=KeQueryPerformanceCounter(&TimeFreq);
KeQuerySystemTime(&SystemTime);

tmp.tv_sec=(LONG)(SystemTime.QuadPart/10000000-11644473600);

tmp.tv_usec=(LONG)((SystemTime.QuadPart%10000000)/10);

tmp.tv_sec-=(ULONG)(PTime.QuadPart/TimeFreq.QuadPart);

tmp.tv_usec-=(LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);

if (tmp.tv_usec<0)
{
tmp.tv_sec--;
tmp.tv_usec+=1000000;
}

data->start=tmp;
data->reference=1;
}

__inline void GET_TIME(struct timeval *dst, struct time_conv *data)
{
LARGE_INTEGER PTime, TimeFreq;
LONG tmp;

PTime=KeQueryPerformanceCounter(&TimeFreq);
tmp=(LONG)(PTime.QuadPart/TimeFreq.QuadPart);
dst->tv_sec=data->start.tv_sec+tmp;
dst->tv_usec=data->start.tv_usec+(LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);

if (dst->tv_usec>=1000000)
{
dst->tv_sec++;
dst->tv_usec-=1000000;
}

}

#pragma optimize ("g",on) //Due to some weird behaviour of the optimizer of DDK build 2600

__inline void FORCE_TIME(struct timeval *src, struct time_conv *dest)
{
dest->start=*src;
}


#else

/*RDTSC timestamps*/

/* callers must be at IRQL=PASSIVE_LEVEL */
#pragma optimize ("g",off) //Due to some weird behaviour of the optimizer of DDK build 2600

__inline VOID TIME_SYNCHRONIZE(struct time_conv *data)
{
struct timeval tmp;
LARGE_INTEGER system_time;
ULONGLONG curr_ticks;
KIRQL old;
LARGE_INTEGER start_kqpc,stop_kqpc,start_freq,stop_freq;
ULONGLONG start_ticks,stop_ticks;
ULONGLONG delta,delta2;
KEVENT event;
LARGE_INTEGER i;
ULONGLONG reference;

if (data->reference!=0)
return;

KeInitializeEvent(&event,NotificationEvent,FALSE);

i.QuadPart=-3500000;

KeRaiseIrql(HIGH_LEVEL,&old);
start_kqpc=KeQueryPerformanceCounter(&start_freq);
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, start_ticks
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}

KeLowerIrql(old);

KeWaitForSingleObject(&event,UserRequest,KernelMode,TRUE ,&i);

KeRaiseIrql(HIGH_LEVEL,&old);
stop_kqpc=KeQueryPerformanceCounter(&stop_freq);
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, stop_ticks
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}
KeLowerIrql(old);

delta=stop_ticks-start_ticks;
delta2=stop_kqpc.QuadPart-start_kqpc.QuadPart;
if (delta>10000000000)
{
delta/=16;
delta2/=16;
}

reference=delta*(start_freq.QuadPart)/delta2;

data->reference=reference/1000;

if (reference%1000>500)
data->reference++;

data->reference*=1000;

reference=data->reference;

KeQuerySystemTime(&system_time);

__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, curr_ticks
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}

tmp.tv_sec=-(LONG)(curr_ticks/reference);

tmp.tv_usec=-(LONG)((curr_ticks%reference)*1000000/reference);

system_time.QuadPart-=116444736000000000;

tmp.tv_sec+=(LONG)(system_time.QuadPart/10000000);
tmp.tv_usec+=(LONG)((system_time.QuadPart%10000000)/10);

if (tmp.tv_usec<0)
{
tmp.tv_sec--;
tmp.tv_usec+=1000000;
}

data->start=tmp;

IF_LOUD(DbgPrint("Frequency %I64u MHz\n",data->reference);)
}
#pragma optimize ("g",on) //Due to some weird behaviour of the optimizer of DDK build 2600

__inline void FORCE_TIME(struct timeval *src, struct time_conv *dest)
{
dest->start=*src;
}

__inline void GET_TIME(struct timeval *dst, struct time_conv *data)
{

ULONGLONG tmp;
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, tmp
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}

if (data->reference==0)
{
return;
}
dst->tv_sec=(LONG)(tmp/data->reference);

dst->tv_usec=(LONG)((tmp-dst->tv_sec*data->reference)*1000000/data->reference);

dst->tv_sec+=data->start.tv_sec;

dst->tv_usec+=data->start.tv_usec;

if (dst->tv_usec>=1000000)
{
dst->tv_sec++;
dst->tv_usec-=1000000;
}


}

#endif /*KQPC_TS*/

#endif /*WIN_NT_DRIVER*/


#endif /*_time_calls*/



其中的结构体在其它头文件中定义
...全文
57 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxc163 2003-11-08
  • 打赏
  • 举报
回复
那里有C代码转Delphi的工具下载呢?
pressman 2003-11-08
  • 打赏
  • 举报
回复
这么长,自己用工具吧
我有,要的话给你!
liyangyao970 2003-11-07
  • 打赏
  • 举报
回复
狂晕哪
up
toyjoy 2003-11-03
  • 打赏
  • 举报
回复
这么长,你还是自己看看Pascal语法吧,几个小时可以看一遍的!
vcshcn 2003-11-03
  • 打赏
  • 举报
回复
struct = packed record
a->b = a^.b
_asm = asm
Linux2001 2003-11-03
  • 打赏
  • 举报
回复
网上有工具可以把C转换为Pascal
z820401 2003-11-03
  • 打赏
  • 举报
回复
angelface 2003-11-03
  • 打赏
  • 举报
回复
我晕~~ 不是不想帮你,, 实在是太长了, 没有时间, 自己转吧, 不是太难的

16,743

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧