星期二, 四月 14, 2009

部分常用的命令备份

今天突然想查一下服务器的CPU类型,结果想了半天没有想起来,好记性不如烂笔头啊,记录下来备用。

AIX CPU类型信息:prtconf
HP CPU类型信息:machinfo
HP aCC 版本信息:aCC -V
gdb 打印调用堆栈:bt
查看AIX系统版本:oslevel -r

查看各种C编译器的预定义宏:http://predef.sourceforge.net/

i386 : Intel 386 ( 老的386机器,也泛指IA32体系的CPU)
i486 : Intel 486
i586 : Intel 586 ( Pentium ,K6 级别CPU )
i686 : Intel 686 ( Pentium II, Pentium III , Pentim 4, K7 级别CPU )
IA32 : 32 bits Intel Architecture (32位带宽Intel构架)

以上的86 也可以叫做 x86, 通称说 x86也是指 IA32构架CPU。IA-32、x86-32、x86-64
都属于x86,即英特尔的32位x86架构,x86-64基础架构还是IA-32,只是在此架构基础之
上作了一些扩展,以支持64位程序的应用,进一步提高处理器的运算性能。

IA64 : 64 bits Intel Architecture (64位带宽Intel构架) 英特尔为了全面提高以前 IA
-32位处理器的运算性能,是Intel和Hp共同开发了的64位CPU架构,是专为服务器市场开发
的一种全新的架构。

RISC:IBM Power PC、Compaq Alpha 、HP PA-8X00、Sun UltraSPARC等。

#EOF

星期一, 三月 30, 2009

删除CC视图

今天整理桌面,发现了一个以前给公司管理CC的MM写过的一个删除多余视图的脚本,放上来
吧。
@echo off
if "%1"=="" goto usage
if not "%2"=="" goto usage
set view_name=%1
cleartool lsview -long %view_name% > uuid 2>nul
if not "%errorlevel%"=="0" (
echo 没有这个视图:%view_name%
goto exit
)
for /f "delims=: tokens=1*" %%a in (uuid) do (
if "%%a"==" View tag uuid" set uuid=%%b
)
if "%uuid%"=="" (
echo 获取UUID失败.
goto error
)
echo uuid:%uuid% >rmview.log
cleartool rmview -f -all -uuid %uuid% >>rmview.log
if "%errorlevel%"=="0" (
cleartool unregister -view -uuid %uuid% >> rmview.log
if "%errorlevel%"=="0" (
cleartool rmtag -view %view_name%
if not "%errorlevel%"=="0" (
echo 删除标签失败.
goto error
) else (
if exist rmview.log del rmview.log
echo 删除视图:%view_name%完全成功.
goto exit
)
) else (
echo 注销注册失败.
)
) else (
echo 删除视图失败.
)
:usage
echo 使用方法:%0 视图名
goto exit
:error
echo 请联系作者.
:exit
if exist uuid del uuid

#EOF

星期五, 三月 20, 2009

Google 拼音输入法 V2.0.4.36 雅黑字体补丁

今天发现输入法更新了,很高兴,不过我不是很喜欢默认的字体,但是目前还没有提供修改字体的方法,所以小小的修改了一下,修改内容:
 
  1.放大默认的字体大小
  2.开启字体的 ClearType 效果
  3.修改汉字字体为微软雅黑


使用说明:
  请关闭系统当中正在使用 Google 拼音输入法的程序,再打补丁,否则可能失败.若仍然补丁失败,可以重启之后立即打补丁.
注意:
  1.若系统当中没有微软雅黑字体,请上网下载字体文件到 C:\windows\fonts 目录下即可.
  2.打过补丁之后,Google 拼音的数字签名会自动失效.
补丁文件可以在这里下载.
--

星期三, 八月 27, 2008

const char* const 的使用

以前代码里面一直这么写,也没有出什么问题,今天看了相关的讨论才发现这么做的问题。如下的例子:
header.h

const char* const gmsg = "ABC_DEF_GHI_JKL_XYZ";

void testfunc1();

void testfunc2();

 
cpp1.cpp

#include <iostream>

#include "header.h"

 

void testfunc1()

{

   std::cout << "msg from testfunc1:" << gmsg << '\n';

}

 

int main()

{

   testfunc1();

   testfunc2();

   return 0;

}

 
cpp2.cpp

#include<iostream>

#include "header.h"

void testfunc2()

{

   std::cout << "msg from testfunc2:" << gmsg << '\n';

}

然后我使用 VS2005 测试过程如下:
cl/EHsc cpp1.cpp cpp2.cpp
程序的执行结果没有任何问题,用记事本打开编译出来的 cpp1.exe,
搜索 ABC_DEF_GHI_JKL_XYZ 会发现有两份。
查询一下标准,原来 C++ 中 const 默认为内部链接的。
3.5
Change: A name of file scope that is explicitly declared const, and not explicitly declared extern, has internal linkage, while in C it would have external linkage
Rationale: Because const objects can be used as compile-time values in C + +, this feature urges programmers to provide explicit initializer values for each const.
 
因此有多少个编译单位就会有多少份 gmsg 的拷贝,对于 VC 可以采用编译选项,启用"字符串池"来避免这个问题的出现.虽然编译的 binary 没有大多少,但是还是采用如下的写法比较好,只有一份拷贝:
header.h

extern const char* const gmsg;

void testfunc1();

void testfunc2();

 
cpp1.cpp

#include <iostream>

#include "header.h"

const char* const gmsg = "ABC_DEF_GHI_JKL_XYZ";

void testfunc1()

{

   std::cout << "msg from testfunc1:" << gmsg << '\n';

}

 

int main()

{

   testfunc1();

   testfunc2();

   return 0;

}

 

cpp2.cpp

#include<iostream>

#include "header.h"

void testfunc2()

{

   std::cout << "msg from testfunc2:" << gmsg << '\n';

}

 

这样虽然在写的时候不是很舒服(代码提示的时候不能提示出来对应的字符串的内容),但是问题也不大习惯习惯就好了。
 
#END
 
 
 

星期六, 四月 19, 2008

在 C++ 当中调用 Python 时异常信息的获取

    使用Boost::Ptyhon 可以很方便的将C++当中的对象暴露给 Python 对象,同时也可以通过 虚函数 而后在 Python 当中重写的方式来实现运行时的多态。但是如何在 C++ 当中获取 Python 运行时的错误呢?翻遍了Boost::Python的文档我都没有找到,只是在 Python 的 C API 当中发现了这个方法:


void PyErr_Print( )

Print a standard traceback to sys.stderr and clear the error indicator. Call this function only when the error indicator is set. (Otherwise it will cause a fatal error!)

想当然的就认为和在 C 里面一样,有了 perror 一样,就应该有 strerror 。于是我找啊找啊,就是找不到。没办法了,G了一把之后曲线救国。先在 Python 里面重定向 stderr,然后通过 PyErr_Print 获取异常信息,然后自己再取出来,具体实现如下:

class ErrorCatcher

{//助手类,用来获取python脚本的错误文本

public:

   ErrorCatcher() { clear(); }

   void write( const std::string& str ) { m_text.append(str); }

 

   const std::string& what(void) { return m_text; }

   void clear(void) { m_text.clear(); }

 

private:

   std::string m_text;

};

当然,还是要把这个类导出到 Python 当中:

namespace bp = boost::python;

bp::class_<Base::ErrorCatcher,Base::ErrorCatcherPtr, boost::noncopyable >("ErrorCatcher")

.def( "write", &Base::ErrorCatcher::write )

;

在 Python 脚本的头上这么写:

    #为了配合C++获取异常的错误信息
    import sys
    oldstdcerr = sys.stderr ;
    newstdcerr = core.initalize(...);
    sys.stderr = newstdcerr ;
    #异常处理设置完毕

之后在 C++ 当中调用脚本的时候,可以通过这样的方式来捕获异常:

void processPyException()

{

   const char* desc = NULL;

   if( PyErr_ExceptionMatches(PyExc_ZeroDivisionError) ) {

      desc = "除异常!";

   } // process others errors

 

   PyErr_Print();

   logger.write(desc,gErrorCatcher->what() );

   gErrorCatcher->clear();

}

try{

   ...;//调用脚本

}catch (boost::python::error_already_set& ){

   processPyException();

}

 

在脚本当中发生的异常的输出类似于:

2008-04-19 17:34:23 (2628) [Application] ERROR 执行脚本时发生异常:Traceback (most recent call last):
  File "C:\codes\work\XXXX\debug\StdAlgorithms\XXXXX.py", line 23, in compute
    sonRelationList = mp.getSonRelations();
Boost.Python.ArgumentError: Python argument types in
    MeterPoint.getSonRelations(MeterPoint)
did not match C++ signature:
    getSonRelations(class Core::MeterPoint {lvalue}, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > relaString)


实在是难以理解为啥 Python 不提供一个直接获取错误字符串描述或者根据错误码获取错误信息的 API。

若有更好的方法,敬请各位看官指教。

#EOF


 

 

星期日, 四月 06, 2008

开始更新BLOG

不知道因为什么原因(奥运会?),GFW 突然开放了 blogspot 的浏览。所以我决定开始持续更新本BLOG,作为我生活、工作的记录。

星期六, 四月 05, 2008

Windows平台编译安装 OpenSSL 0.9.8g



Windows平台编译安装 OpenSSL 0.9.8g

http://xuziding.blogspot.com/2008/04/windows-openssl-098g.html

  1. 需要
    • MS VC 80(其他6.0版本以及以上的都可以)
    • Perl (可以使用AvtivePrel)
    • openssl-0.9.8g.zip (可从 www.openssl.org 下载)
  2. 准备
    • 将 openssl-0.9.8g.zip 解压缩到目录 E:\libs\openssl-0.9.8g 下
    • 打开VC命令行编译环境。start ->Microsoft Visual Studio 2005->Visual Studio Tools->Visual Studio 2005 Command Prompt
    • 将 perl.exe 加入PATH 当中。set PATH=C:\Activeprel\bin;%path%
  3. 配置
    • > cd E:\libs\openssl-0.9.8g
    • > perl Configure enable-camellia threads zlib no-shared enable-camellia --openssldir=D:/Dev/libs/openssl-0.9.8g -IE:/libs/zlib-1.2.3 -LE:/libs/zlib-1.2.3/lib/zlib.lib VC-WIN32
      ('enable-camellia' 打开对称密码 'Camellia' (128-bit, 192-bit, 256-bit key 版本))
      (--openssldir=要安装到哪里的目录其中注意路径要用 Unix 路径分隔符 / 来分隔)
  4. 编译
    • 编译汇编的优化代码 > ms\do_masm 执行完了这一步,所有的 makefile 都已经生成好了,若你需要自定义一些与默认的编译选项不一致的东西,就需要手工更改。比如你的 zlib.lib 的 PATH ,使用的 CRT 的版本是(MD还是MDd)等等。
    • 编译库 > nmake -f ms\nt.mak (nt.mak 为静态lib,ntdll.mak 为 DLL 版本)
  5. 测试、安装
    • 测试库 > nmake -f ms\nt.mak test 若测试通过,最后应该告诉你 all test passed.
    • 安装库 > nmake -f ms\nt.mak install 安装库和头文件到上面指定的要安装目录
  6. 测试安装好的程序
    • 执行 openssl
    • OpenSSL> version (应该输出 OpenSSL 0.9.8g 19 Oct 2007 )
    • OpenSSL> s_client -connect www.openssl.org:443 (回车)
    • GET /(两次回车) 这时候应该显示出来www.openssl.org 的首页的 html 代码。