2012년 11월 20일 화요일

mingw 로 qrencode dll 빌드



http://fukuchi.org/works/qrencode/index.html.en

./configure
make
make install

qrencode 를 mingw + msys 로 dll 빌드시 계속 static 라이브러리만 생성됨.
ubuntu 에서는 정상적으로 so 파일 생성.

구글링해보니 약간의 패치가 옵션조정이 필요함.
pthread 라이브러리 링크에 문제가 있는 것으로 보임.
pthread  static 라이브러를 링크해볼려고 했으나 mingw 의 pthread static 라이브러리에 문제가 있는 것 같음.

http://lrn.no-ip.info/other/mingw/mingw32/qrencode/3.3.1-2/

Makefile.in 에서 다음줄을 찾아서  -no-undefined 추가.
libqrencode_la_LDFLAGS = -version-number $(MAJOR_VERSION):$(MINOR_VERSION):$(MICRO_VERSION)
libqrencode_la_LDFLAGS = -version-number $(MAJOR_VERSION):$(MINOR_VERSION):$(MICRO_VERSION) -no-undefined
다시 빌드.
make clean
./configure --without-tools --disable-thread-safety
make
mae install
./libs 폴더에 dll 이 생성된 것을 볼 수가 있음.
thread safe 하지 않으므로 lock 은 알아서 잘 해야 될 것 같음.

2012년 10월 19일 금요일

Trac wikiprint 한글글꼴 설정.

아래 링크를 참조하여 한글이 포함된 trac 페이지도 wikiprint 로 PDF 문서를 잘 생성해서 쓰고 있었는데 어느때인가? ubuntu 를 업그레이드하면서 한글이 깨지기 시작했다.
http://kldp.org/node/109178

오늘 ubuntu 12.10 으로 업그레이드하면서 다시 확인해봤는데 역시나~~
이것저것 삽질하다 보니 짜안 한글이 TT_TT..
/usr/share/pyshared/wikipiprint/defaults.py 를 아래와 같이 수정.
  • 원본..
"""
Author: Alvaro Iradier
"""

#Default CSS to use for xhtml2pdf
CSS = """
html {
    font-family: Helvetica;
    font-size: 10px;
    font-weight: normal;
    color: #000000;
    background-color: transparent;
  • 수정본
"""
Author: Alvaro Iradier
"""

#Default CSS to use for xhtml2pdf
CSS = """
@font-face {
    font-family: NanumGothic;
    src: url(file:///usr/share/fonts/truetype/nanum/NanumGothic.ttf);
    }
html {
    font-family: NanumGothic;
    font-size: 10px;
    font-weight: normal;
    color: #000000;
    background-color: transparent;

2012년 10월 18일 목요일

리눅스배포판 정보 얻기

$ lsb_release -rd
Description:    Ubuntu 12.10
Release:    12.10

파이썬에서 r"\x30" 디코딩하기.


>>> r"\x30".decode("string_escape")
'0'

2012년 3월 7일 수요일

gcc 에서 디버깅심볼을 별도 파일로 저장하기.

http://stackoverflow.com/questions/866721/how-to-generate-gcc-debug-symbol-outside-the-build-target

분리할 때..
gcc -ggdb -o test test.c;
cp test test.debug;
strip --only-keep-debug test.debug;
strip test;


합칠 때
objcopy --add-gnu-debuglink=test.debug test


gdb 에서..
http://sigquit.wordpress.com/2008/09/15/debugging-programs-with-a-external-symbol-file/
(gdb) symbol-file test.debug

2012년 2월 9일 목요일

라자루스에서 TForm 생성시 class name 바꾸기..

아래링크를 참조하여 윈도용 라자루스에서 TForm 의 Class Name 을 바꿔보려 했다.
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=1072
라자루스에서 TForm 의 기본 class name 은 'Window' 인데 아래와 같이 해도 바뀌지는 않는다.

type
{ TFormMain }
TFormMain = class(TForm)
....
protected
PrevWndProc: Windows.WNDPROC;
procedure WndProc( var TheMessage: TLMessage); override;
procedure CreateParams(var Params: TCreateParams); override;
end;

procedure TFormMain.CreateParams(var Params: TCreateParams);
begin
inherited;
StrCopy(Params.WinClassName, 'MyClass');
end;

procedure TFormMain.MenuItem2Click(Sender: TObject);
var
class_name :array [0..255] of Char;
ret :LongInt;
begin
ret := GetClassName(WindowHandle, class_name, SizeOf(class_name));
if ret > 0 then
begin
MessageDlg(class_name, mtInformation, [mbOK], 0 )
end;
end;
그래서, 라자루스 포럼에 질문을 올렸더니, 직접 패치를 만들어보라는 대답이 돌아왔다. TT_TT;;
http://www.lazarus.freepascal.org/index.php/topic,15941.msg86071.html#msg86071
그래서, 직접 수정해보기로 했다.
라자루스 소스를 분석해보면 TCreateParams.WinClassName 를 전혀 사용하지 않고 있다.
아래 코드와 같이 대충 동작하도록 만들어보았는데, 윈7, XP 에서 동작하는 것을 확인했다.
Ansi 쪽이 호출되는 상황이면 충돌이 발생하는데 그 원인을 모르겠다.
파스칼,델파이,라자루스 모두 익숙하지 않은지라 그리 깔끔해보지는 않는다.
고수님들이 손 봐줬으면 좋겠다.
Lazarus-0.9.31-35255-fpc-2.6.1-20120209-win32.exe 에 포함된 소스를 기준으로 작업

unit Win32WSForms;

{$mode objfpc}{$H+}
{$I win32defines.inc} // added

interface
....
....
class function TWin32WSCustomForm.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
var
Params: TCreateWindowExParams;
lForm: TCustomForm absolute AWinControl;
Bounds: TRect;
SystemMenu: HMenu;
// addtion start
WindowClass: WndClass;
{$ifdef WindowsUnicodeSupport}
WindowClassW: WndClassW;
{$endif}
AErrorCode: Cardinal;
// addtion end
begin
// general initialization of Params
PrepareCreateWindow(AWinControl, AParams, Params);
// customization of Params
with Params do
begin
if (Parent = 0) then
begin
 ......
end;
CalcFormWindowFlags(lForm, Flags, FlagsEx);
pClassName := @ClsName[0];

// addtion start
if AParams.WinClassName[0] <> #0 then
begin
pClassName := @AParams.WinClassName[0];
{$ifdef WindowsUnicodeSupport}
if UnicodeEnabledOS then
begin
  if not GetClassInfoW(System.HInstance(), PWideChar(WideString(pClassName)), @WindowClassW) then
  begin
    if GetClassInfoW(System.HInstance(), PWideChar(WideString(ClsName)), @WindowClassW) then
    begin
  WindowClassW.lpszClassName:=PWideChar(WideString(pClassName));
  if Windows.RegisterClassW(@WindowClassW) = 0 then
  begin
    AErrorCode := GetLastError;
    //DebugLn(['Failed to RegisterClassW, error: ', AErrorCode, ' : ', GetLastErrorText(AErrorCode)]);
    raise Exception.Create('Failed to RegisterClassW, error: ' + IntToStr(AErrorCode) + ' : ' + GetLastErrorText(AErrorCode));
  end;
    end
    else
    begin
      AErrorCode := GetLastError;
  //DebugLn(['Failed to GetClassInfoW, error: ', AErrorCode, ' : ', GetLastErrorText(AErrorCode)]);
  raise Exception.Create('Failed to GetClassInfoW, error: ' + IntToStr(AErrorCode) + ' : ' + GetLastErrorText(AErrorCode));
    end;
  end;
end
else
{$endif}
begin
  FillChar(WindowClass, SizeOf(WindowClass),0);
  if not GetClassInfo(System.HInstance(), pClassName, @WindowClass) then
  begin
    if GetClassInfo(System.HInstance(), PChar(AnsiString(ClsName)), @WindowClass) then
    begin
  WindowClass.lpszClassName:=pClassName;
  if Windows.RegisterClass(@WindowClass) = 0 then
  begin
    AErrorCode := GetLastError;
    //DebugLn(['Failed to RegisterClass, error: ', AErrorCode, ' : ', GetLastErrorText(AErrorCode)]);
    raise Exception.Create('Failed to RegisterClass, error: ' + IntToStr(AErrorCode) + ' : ' + GetLastErrorText(AErrorCode));
  end;
    end
    else
    begin
      AErrorCode := GetLastError;
  //DebugLn(['Failed to GetClassInfo, error: ', AErrorCode, ' : ', GetLastErrorText(AErrorCode)]);
  raise Exception.Create('Failed to GetClassInfo, error: ' + IntToStr(AErrorCode) + ' : ' + GetLastErrorText(AErrorCode));
    end;
  end;
end;
end;
// addtion end

WindowTitle := StrCaption;
AdjustFormBounds(lForm, Bounds);
if (lForm.Position in [poDefault, poDefaultPosOnly]) and not (csDesigning in lForm.ComponentState) then
begin
....

2011년 10월 4일 화요일

파이썬으로 자기 PC IP 알아내는 방법.

자기PC 의 IP를 알아내는 방법은 여러가지가 있겠지만 파이썬에서는 아래 코드가 가장 심플한듯..
http://python.kr/viewtopic.php?p=76315#76315
>>> import urllib
>>> urllib.thishost()
'192.168.10.101'