火曜日, 7月 07, 2009

法律の尊厳

7月5日発生した新疆ウゥグル自治区ウルムチの暴動は国外のメディアによって、伝えられましたが、本質的に暴力犯罪のことを人権問題にすりかえられ、中国批判になろうという欧米、日本のメディアの下心は丸々見えになってしまいました。

暴動の背景にある中国の少数民族に対する人権問題などで、国際社会の批判も高まりつつあり、サミットでも取り上げられるのは確実な情勢だった。

ジャーナリズムがなんだろう、ジャーナリストとしての使命がなんだろうという基本の人格問題として、自問自答にしていただきたい。巧みの言葉ででっち上げるのは紛れもなく人間失格です。

中国の少数民族政策は世界中に最も優れた政策で、全地球中に、別の民族を受け入れ、VIPとして扱う民族が漢民族しかないと言い切れます。人権、民主、自由を叫び続けるアメリカ、ヨーロッパの歴史は、別民族の大虐殺しかありません。

どんな自由の国でも、どんな綺麗な民主でも、その前提として、法律を守ることです。7月5日に暴動を参加したウゥグル族の暴徒を厳罰することは平和の中国民族大家庭を幸せに、嘘で生活する外国ジャーナリストを墓場へ導く唯一の対処方法です。

土曜日, 7月 04, 2009

ld --verbose

ld --verbose



See Also:
How to embed binary data in an ELF file
ELF Binary Optimization for size
The Linker Script at The Basic Kernel

Embed Glade files in executable


  • Gtk#

    Just bundle glade files as resources (using the -resource: option in the compiler) and change constructor call or use the Glade.XML.FromAssembly () method to create Glade.XML ui.
    See also A google search application using Gtk#

  • Gtk+(Embedding Binary Blobs With GCC)
    1. Excerpt From Embedding Binary Blobs With GCC
      $ echo Hello, World > foo.txt
      $ ld -r -b binary -o foo.o foo.txt
      $ objdump -x foo.o

      test.c
      #include <stdio.h>
      extern char _binary_foo_txt_start[];

      int main (void) {
      puts (_binary_foo_txt_start);
      return 0;
      }



      $ gcc -o test test.c foo.o
      $ ./test
      Hello, World!

      Change the string itself in the .data section, which is read/write, to be read-only data in the .rodata section so that it isn't copied for every instance of the application.
      $ objcopy --rename-section .data=.rodata,alloc,load,readonly,data,contents foo.o foo.o
      $ objdump -h foo.o

    2. You might find GNU as's .incbin directive more useful for this purpose - you can control the symbol name, section, and add a NUL terminator. You do have to write little wrapper .s files though. For example
      $ echo hello world > demo.txt
      $ cat > demo.s
      .section ".rodata"
      .globl demo
      .type demo, @object
      demo:
      .incbin "demo.txt"
      .byte 0
      .size demo, .-demo
      ^D
      $ as demo.s -o demo.o
      $ nm demo.o
      00000000 R demo
      $ strings demo.o
      hello world


  • wxWidget(xml-based resource system overview)


For More, See:
Add icons to ELF files
How do I add an icon to a mingw-gcc compiled executable?
  1. create a .rc file that looks id ICON "path/to/my.ico"
  2. windres my.rc -O coff -o my.res
  3. g++ -o my_app obj1.o obj2.o my.res

金曜日, 7月 03, 2009

Creating a GUI using PyGTK and Glade

Creating a GUI using PyGTK and Glade


The First Step:
#!/usr/bin/env python

import sys
try:
    import pygtk
    pygtk.require("2.0")
except:
    pass
try:
    import gtk
    import gtk.glade
except:
    sys.exit(1)


The Full Sample(Glade Object File:Libglade)
#!/usr/bin/env python

import sys
try:
    import pygtk
    pygtk.require("2.0")
except:
    pass
try:
    import gtk
    import gtk.glade
except:
    sys.exit(1)

class HellowWorldGTK:
    """This is an Hello World GTK application"""

    def __init__(self):
        
        #Set the Glade file
        self.gladefile = "pyhelloworld.glade"  
        self.wTree = gtk.glade.XML(self.gladefile)
        
        #Create our dictionay and connect it
        dic = { "on_btnHelloWorld_clicked" : self.btnHelloWorld_clicked,
            "on_MainWindow_destroy" : gtk.main_quit }
        self.wTree.signal_autoconnect(dic)

    def btnHelloWorld_clicked(self, widget):
        print "Hello World!"


if __name__ == "__main__":
    hwg = HellowWorldGTK()
    gtk.main()


The Full Sample(Glade Object File:GtkBuilder)
#!/usr/bin/env python

import pygtk
import gtk
pygtk.require("2.0")

class GUI(object):
    def __init__(self):
        builder = gtk.Builder()
        builder.add_from_file("GUI.xml")
        builder.connect_signals(self)
        self.window1 = builder.get_object("window1")
        self.window1.show()

    def on_window1_destroy(self,widget,data=None):
        gtk.main_quit()

    def on_button1_clicked(self,widget,data=None):
        gtk.main_quit()  

if __name__ == "__main__":
    app = GUI()
    gtk.main()


More Simple Sample(test003.py)
#!/usr/bin/env python

import sys
try:
    import pygtk
    pygtk.require("2.0")
except:
    pass
try:
    import gtk
    #Libglade
    #import gtk.glade
except:
    sys.exit(1)

class TestMain:
    """This is an Hello World GTK application"""

    def __init__(self):
        
        #Set the Glade file
        self.gladefile = "test003.glade"
        self.glade = gtk.Builder()
        self.wTree = self.glade.add_from_file(self.gladefile)

        #Create our dictionay and connect it
        #dic = { "on_btnHelloWorld_clicked" : self.btnHelloWorld_clicked,
        #    "on_windowMaindow_destroy" : gtk.main_quit }
        #1.Libglade Auto Connect
        #self.wTree.signal_autoconnect(dic)
        #2.GktBuilder Auto Connect
        #glader.connect_signals(dic)

        #Main Window
        self.windowMain = self.glade.get_object("windowMain")
        self.windowMain.connect("destroy", self.on_windowMain_destroy)
        self.windowMain.show()

        #GktImage
        self.imageMain = self.glade.get_object("imageMain")
        self.imageMain.set_from_file("airplane.jpg")
        #MenuItem Activate
        self.menuitemQuit = self.glade.get_object("imagemenuitemQuit")
        self.menuitemQuit.connect("activate", self.on_windowMain_destroy)

    def on_windowMain_destroy(self, widget, data=None):
        gtk.main_quit()

    def btnHelloWorld_clicked(self, widget, data=None):
        print "Hello World!"

if __name__ == "__main__":
    hwg = TestMain()
    gtk.main()


And the test003.glade file
<?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.16"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkWindow" id="windowMain">
    <child>
      <object class="GtkVBox" id="vboxMain">
        <property name="visible">True</property>
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkMenuBar" id="menubarMain">
            <property name="visible">True</property>
            <child>
              <object class="GtkMenuItem" id="menuitemFile">
                <property name="visible">True</property>
                <property name="label" translatable="yes">&#x30D5;&#x30A1;&#x30A4;&#x30EB;(_F)</property>
                <property name="use_underline">True</property>
                <child type="submenu">
                  <object class="GtkMenu" id="menuFile">
                    <property name="visible">True</property>
                    <child>
                      <object class="GtkImageMenuItem" id="imagemenuitemNew">
                        <property name="label">gtk-new</property>
                        <property name="visible">True</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkImageMenuItem" id="imagemenuitemOpen">
                        <property name="label">gtk-open</property>
                        <property name="visible">True</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkImageMenuItem" id="imagemenuitemSave">
                        <property name="label">gtk-save</property>
                        <property name="visible">True</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkImageMenuItem" id="imagemenuitemSaveAs">
                        <property name="label">gtk-save-as</property>
                        <property name="visible">True</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
                        <property name="visible">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkImageMenuItem" id="imagemenuitemQuit">
                        <property name="label">gtk-quit</property>
                        <property name="visible">True</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem" id="menuitem2">
                <property name="visible">True</property>
                <property name="label" translatable="yes">&#x7DE8;&#x96C6;(_E)</property>
                <property name="use_underline">True</property>
                <child type="submenu">
                  <object class="GtkMenu" id="menu2">
                    <property name="visible">True</property>
                    <child>
                      <object class="GtkImageMenuItem" id="imagemenuitem6">
                        <property name="label">gtk-cut</property>
                        <property name="visible">True</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkImageMenuItem" id="imagemenuitem7">
                        <property name="label">gtk-copy</property>
                        <property name="visible">True</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkImageMenuItem" id="imagemenuitem8">
                        <property name="label">gtk-paste</property>
                        <property name="visible">True</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkImageMenuItem" id="imagemenuitem9">
                        <property name="label">gtk-delete</property>
                        <property name="visible">True</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem" id="menuitem3">
                <property name="visible">True</property>
                <property name="label" translatable="yes">&#x8868;&#x793A;(_V)</property>
                <property name="use_underline">True</property>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem" id="menuitem4">
                <property name="visible">True</property>
                <property name="label" translatable="yes">&#x30D8;&#x30EB;&#x30D7;(_H)</property>
                <property name="use_underline">True</property>
                <child type="submenu">
                  <object class="GtkMenu" id="menu3">
                    <property name="visible">True</property>
                    <child>
                      <object class="GtkImageMenuItem" id="imagemenuitem10">
                        <property name="label">gtk-about</property>
                        <property name="visible">True</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkImage" id="imageMain">
            <property name="visible">True</property>
            <property name="stock">gtk-missing-image</property>
          </object>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkStatusbar" id="statusbarMain">
            <property name="visible">True</property>
            <property name="spacing">2</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="position">2</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>

木曜日, 7月 02, 2009

Change file to html using VIM

2html.vim : Transform a file into HTML, using the current syntax highlighting

2html.vimスクリプトで、テキストをHTML化するコマンド
:TOhtml

:TOhtmlコマンドを範囲指定付きで実行する例
:12,19TOhtml

水曜日, 7月 01, 2009

Adding a symbol to the dynamic symbol table

Adding a symbol to the dynamic symbol table

  • --export-dynamic or -Bdynamic - add all symbols to
    the dynamic symbol table.

    Add symbols needed by the dynamic object to the dynamic symbol
    table
  • --version-script

    SOMENAME {
    global:
    foo;
    bar;
    local:
    *;
    };

    That tells the linker that 'foo' and 'bar' are to be exported
    and anything else not. I usually use the name of the library
    for 'SOMENAME', but you can get a lot more fancy when you need
    to support several versions of your library. You can use wild-
    cards in the names of the variables, so e.g. 'foo_*' would mean
    all symbols with names starting with 'foo_'. The '*' in local
    simply means all symbols not yet set to global.

    例として、ライブラリの外に公開するシンボルを制限する

    Version Script
    __asm__(".symver old_foo1,foo@VERS_1.2");

  • --dynamic-list
    a script which simply contains:

    {foo;};


objdump --dynamic-syms
ファイルの動的なシンボルテーブルエントリを表示する。これはある種の共有ライブラリのように、動的なオブジェクトの場合にのみ意味を持つ。これは nm プログラムに -D (--dynamic) オプションを指定した場合に得られる情報とほぼ同じ。


Why is the new C++ visibility support so useful?

GTK+ Application Built on GtkBuilder Using Glade

  • GTK+ programs with GtkBuilder and dynamic signal handlers

    Excert Hello.c Sample
    #include <gtk/gtk.h>
    void close_app(GtkWidget* widget,gpointer user_data) {
    gtk_main_quit();
    }
    int main (int argc, char **argv) {
    GtkBuilder *gtkBuilder;
    GtkWidget *mainwin;
    gtk_set_locale();
    /* Initialize the widget set */
    gtk_init (&argc, &argv);
    /* Create the main window */
    gtkBuilder= gtk_builder_new();
    gtk_builder_add_from_file(gtkBuilder,"hello.ui",NULL);
    gtk_builder_connect_signals ( gtkBuilder, NULL );
    mainwin= GTK_WIDGET(gtk_builder_get_object(gtkBuilder,"window1"));
    g_object_unref ( G_OBJECT(gtkBuilder) );
    /* Show the application window */
    gtk_widget_show_all ( mainwin );
    /* Enter the main event loop, and wait for user interaction */
    gtk_main ();
    /* The user lost interest */
    return 0;
    }

    コンパイル:
    gcc -Wall -g -o hello hello.c -export-dynamic `pkg-config --cflags --libs gtk+-2.0`

    "-export-dynamic"フラグを追加して、作成した実行ファイルとこフラグがない時に作成した実行ファイルはどこかに差がありますか?下の分が全然読み取れません。


    9 Dlopened modules
    Another situation where you would use `-export-dynamic' is if symbols from your executable are needed to satisfy unresolved references in a library you want to dlopen. In this case, you should use `-export-dynamic' while linking the executable that calls dlopen:
    burger$ libtool gcc -export-dynamic -o hell-dlopener main.o

    Windows上に-export-dynamicを使わなくて、関数の前にG_MODULE_EXPORTを付けば、関数をクスポートできます。


  • GTK+ and Glade3 GUI Programming Tutorial - Part 3


GGCで-export-dynamicで関数をエクスポートする時、不用意にすべての関数が外から参照できるようになってます。これを解消するため、Why is the new C++ visibility support so useful?に説明した遣り方で指定した関数だけをエクスポートできるようになります。
  1. コンパイル
    gcc -Wall -g -o hello hello.c -export-dynamic -fvisibility=hidden `pkg-config --cflags --libs gtk+-2.0`

  2. エクスポート関数の前に追加:
    __attribute__ ((visibility("default")))

    或いはエクスポート関数の前後に追加:
    #pragma GCC visibility push(default)
    extern void exportfunct(int);
    #pragma GCC visibility pop