發表文章

目前顯示的是 2月, 2012的文章

C Programming: Structure Assignment

這篇文章主要是記錄自己的孤陋寡聞 ... 今天同事在聊一段程式碼(內容就不多講了,反正簡化後如下)。乍看之下大吃一驚,為什麼Structure 間可以直接使用 Assignment?在我過去的認知裡面,如果要對 Structure 作拷貝的動作,應該要使用 memcpy 才對吧?所以才寫了小小的程式碼測試一下。 # include < stdio.h > # include < stdlib.h > struct tObj { int a ; double b ; int c [ 3 ] ; } ; int main ( ) { struct tObj obj1 ; struct tObj obj2 ; obj1 . a = 1 ; obj1 . b = 2.0 ; obj1 . c [ 0 ] = 3 ; obj1 . c [ 1 ] = 4 ; obj1 . c [ 2 ] = 5 ; obj2 . a = 0 ; obj2 . b = 0.0 ; obj2 . c [ 0 ] = 0 ; obj2 . c [ 1 ] = 0 ; obj2 . c [ 2 ] = 0 ; obj2 = obj1 ; printf ( " obj2.a = %d \n " , obj2 . a ) ; printf ( " obj2.b = %f \n " , obj2 . b ) ; printf ( " obj2.c[0] = %d \n " , obj2 . c [ 0 ] ) ; printf ( " obj2.c[1] = %d \n " , obj2 . c [ 1 ] ) ; printf ( " obj2.c[2] = %d \n " , obj2 . c [ 2 ] ) ; ret

Linux Daemon 的雛型

本篇文章是紀錄 Linux Daemon 撰寫的雛型,程式碼引用自 Fred 的 Blog。 # include < stdio.h > # include < stdlib.h > # include < unistd.h > int main ( ) { pid_t pid ; pid = fork ( ) ; // If pid > 0, the process is the parent process and will be killed. // If pid = 0, the process is the child process. if ( pid > 0 ) { exit ( 0 ) ; } while ( 1 ) { // Infinite loop for the child process which will be executed in the background. } return 0 ; } 程式碼很簡單,就不加以說明了。紀錄在這邊純粹方便之後的修改。

軟體分享(Linux)~ PDF Shuffler, Xournal, Imagination, Winff, Maxima

紀錄一些 Linux 上的軟體,有需要就可以拿來用了。 1. PDF Shuffler ( http://sourceforge.net/projects/pdfshuffler/ ) PDF-Shuffler is a small python-gtk application, which helps the user to merge or split pdf documents and rotate , crop and rearrange their pages using an interactive and intuitive graphical interface. It is a frontend for python-pyPdf. 2. Xournal ( http://xournal.sourceforge.net/ ) Xournal is an application for notetaking, sketching, keeping a journal using a stylus. It is free software (GNU GPL) and runs on Linux (recent distributions) and other GTK+/Gnome platforms.  Xournal supports annotation of PDF files . Xournal uses the Poppler library to render PDF documents. The documents then become immutable background images. Annotation can then proceed using any of Xournal's standard tools: Pen, eraser, text, and highlighter. 3. Imagination ( http://imagination.sourceforge.net/ ) Imagination is a lightweight and simple DVD slide show maker for Linux and FreeBSD written in C lang

我看「家政婦三田」

過年在家一口氣把 家政婦三田 看完了,好看~不愧是去年收視率最高的日劇。劇情大綱如下(取自wiki): 因為母親的意外而瀕臨瓦解的阿須田一家,聘請了一位名叫三田的幫傭家政婦。吩咐的工作她全部都能完美達成,但卻總是像個機器人般面無表情。不論是什麼樣的命令,甚至是犯罪,三田都會冷靜的執行,讓阿須田家中的成員以及身邊人們驚訝不已。然而三田的種種行動,卻逐漸讓分崩離析的家庭開始產生出乎意料的變化。 不管是女主角松嶋菜菜子的演技、扣人心弦的劇情,都讓人欲罷不能,只好一口氣看完了。看完後,我覺得這部戲只在談一個問題:「 任性 。」透過一個近乎全能的家政婦三田燈(根本就是小叮噹),因為這個家政婦有著絕對聽從命令的屬性(先不管合不合理),所以會把所有人心中的「任性」作無限制的放大。 常見的對象如下: XX:「無論吩咐你什麼事情,你都會作到嗎?」 三田:「只要是我能力做的到的話」 XX:「那你就去 ...」 三田;「我知道了」 這些事情包含了殺人、綁架、放火、性行為 ... 但等到事情真正發生的,卻又全部回過來指責三田:「 叫你作什麼就做什麼,你沒有常識嗎?這是你的問題吧? 」問題是,這些命令是誰下的啊?還不就是這些吩咐三田的人嗎? 任性的下達命令,不考慮後果,事後再來抱怨、卸責,我想這才是導演、編劇最想提醒觀眾的地方吧!

Linux Driver Example: virmouse

我很喜歡在網路上找一些簡單的程式範例,一來可以幫助自己學習,二來以後要拿來用比較方便。找範例程式的最高指導原則是: 簡單 !一個程式最好只說明一樣東西,而且不需要加上太多的廢話說明就可以看懂,這樣以後拿來用比較快,不用在花太多時間去重新想這個程式在做什麼。今天要放上的程式範例是一個 Linux Driver 的範例,網路上大部分的範例都是「Hello World」,簡單,但這樣的範例幾乎不具備任何參考價值。今天在網路上看到 Fred 所撰寫的一個 virtual mouse 的範例,所以就紀錄在這裡。但因為在下功力太差,所以之後會在加上一些自己的說明。 /*  * A Virtual Mouse Driver to send fake events from userspace.  *  * Written by Fred Chien < fred@ullab.org >  * Modified by Neokent.  * 1. Change some coding styles.  * 2. Add some comments for myself.  *  */ # include < linux/fs.h > # include < asm/uaccess.h > # include < linux/pci.h > # include < linux/input.h > # include < linux/platform_device.h > struct input_dev * virmouse_input_dev ; static struct platform_device * virmouse_dev ; /* Device structure */ /* Sysfs method to input simulated coordinates */ static ssize_t write_virmouse ( struct device * dev , struct device_attribute * attr ,