« 2006年11月 | (回到Blog入口) | 2007年03月 »

2006年12月 归档

2006年12月05日

讨厌的Ultra Edit

UltraEdit 一向以多语法高亮编辑和二进制编辑集一身为特色,而且更是提供了多种编码与系统下不同格式文件的转换方法。如 UTF8文件转换为 UTF16格式文件。
可是,在yayv开发UTF6到UTF8的转换程序的时候,发现UltraEdit其实用了很讨巧的方法来处理的UTF8

打开一个 UTF16的文本文件,转换为UTF8文件,再次用UltraEdit打开,观看这两个文件的二进制格式,你会发现他们的内容一模一样。经过反复观察和测试,终于确定,这个是UltraEdit的问题,他在打开之后在自己的缓冲区中进行了转码和现实,二进制编辑则打开的这个缓冲区中的文件。

最后,还是用 VS.net的二进制编辑工具搞定了这个问题。

完成 UTF8 和 UTF16 转换函数

UTF8文本头为 EF BB BF
UTF16 文本头: Big-Endian的FEFF; 表明这个字节流是;Little-Endian的FFFE

int convertUTF8UTF16(unsigned char* utf8, int& size8, char* utf16, int& size16)
{
int count =0, i;
char tmp1, tmp2;
unsigned short int integer;
unsigned short int *p;
for(i=0;i {
p = (unsigned short int*)&utf16[i];

if( utf8[count] < 0x80)
{
// <0x80
integer = utf8[count];
count++;
}
else if( (utf8[count] < 0xDF) && (utf8[count]>=0x80))
{
integer = utf8[count] & 0x1F;
integer = integer << 6;
integer += utf8[count+1] &0x3F;
count+=2;
}
else if( (utf8[count] <= 0xEF) && (utf8[count]>=0xDF))
{
integer = utf8[count] & 0x0F;
integer = integer << 6;
integer += utf8[count+1] &0x3F;
integer = integer << 6;
integer += utf8[count+2] &0x3F;
count+=3;
}
else
{
printf("error!\n");
}
*p = integer;
}
size8 = count;
size16 = i;

return size16;
}

int convertUTF16UTF8(char* utf16, int& size16, char* utf8, int& size8)
{
int i=0, count=0;
char tmp1, tmp2;

unsigned short int integer;
for(i=0;i {
integer = *(unsigned short int*)&utf16[i];

if( integer<0x80)
{
utf8[count] = utf16[i] & 0x7f;
count++;
}
else if( integer>=0x80 && integer<0x07ff)
{
tmp1 = integer>>6;
utf8[count] = 0xC0 | (0x1F & integer>>6);
utf8[count+1] = 0x80 | (0x3F & integer);
count+=2;
}
else if( integer>=0x0800 )
{
tmp1 = integer>>12;
utf8[count] = 0xE0 | (0x0F & integer>>12);
utf8[count+1] = 0x80 | ((0x0FC0 & integer)>>6);
utf8[count+2] = 0x80 | (0x003F & integer);

count += 3;
}
else
{
printf("error\n");
}
}

size16 = i;
size8 = count;
return count;
}

2006年12月08日

mod_python配置,及简单psp开发入门

安装mod_python模块,Linux下建议使用系统对应的 rpm 进行安装,理由:安装简单,省心!

设置某个目录可以使用 psp, 可以按照下例配置
<Directory /some/path>
AddHandler mod_python .psp
PythonHandler mod_python.psp
PythonDebug On
</Directory>

现在基本就配置好了
可以在 /some/path 下写 psp脚本文件了。关于如何让 /some/path 可以在网页上被访问到,可以参见apache的其他文章或者手册

第一个简单的psp脚本: test.psp

<html>
<%
if form.has_key('name'):
greet = 'Hello, %s!' % form['name'].capitalize()
else:
greet = 'Hello there!'
# end
%>
<h1><%= greet %></h1>
</html>


注意书写格式,psp脚本跟python一样是对书写格式有严格要求的。

psp中可以使用的输入参数有:

1.req 包含了全部的来自客户端的请求信息
2.psp 一个PSPInstance类对象,在后面再详细解释
3.form 一个字典类型的变量,
4.session session变量
5.

服务器端包含(SSI Server Side Include )格式为

<%@ include file='filename'>


psp对模板文件的支持:

使用 psp对象的 PSP方法,

2006年12月17日

在windows下配置apache+php遇到的"找不到指定的模块"问题解决

只需要把 php4apache2.dll(或php4apache.dll php5apache.dll php5apache2.dll)所在的路径加入到系统环境变量 path 中,apache就能找到这个模块了。

一行结果,半晌思索。其实就这么简单!

2006年12月18日

python的4种rails框架

CherryPy、Karrigell、TurboGears和Django

备注下,以后研究

关于 2006年12月

此页面包含了在2006年12月发表于刘策(liuce)的所有日记,它们从老到新列出。

前一个存档 2006年11月

后一个存档 2007年03月

更多信息可在 主索引 页和 归档 页看到。

Powered by
Movable Type 3.33