[C/C++] cstring (string.h) 函式:strcat, strncat, strcmp, strncmp

串接函式 strcat strcat 此函式用來連接兩字串合併成單一字串,直接看底下範例: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 /* strcat example */ #include <stdio.h> #include <string.h> int main () { char str[80]; strcpy (str,"these "); strcat (str,"strings "); strcat (str,"are "); strcat (str,"concatenated."); puts (str); return 0; } output: 1 these strings are concatenated. 看一下 strcat 原始碼: 1 2 3 4 5 6 7 8 9 char * strcat(char * __restrict s, const char * __restrict append) { char *save = s; for (; *s; ++s); while ((*s++ = *append++)); return(save); } 設定指標 save 成 source,再將 s 指標指向最後,接下來根據 append 字串一個一個往後串接,直到碰到 \0 終止 while 迴圈,最後在將指標 *save 回傳即可。 [Read More]

[C/C++] cstring (string.h) 搜尋函式:strstr, strchr

這次介紹 C 語言常用 string 函式:strstr,主要是針對兩個輸入參數做比對,Parameters 1 是輸入字串,Parameters 2 是找尋字串,strstr 會先將頭一次比對成功的 pointer 回傳,也就是如果要找尋 appleboyappleboy 字串中的 boy,函式會回傳第一次比對成功的 boy pointer,而並非回傳最後一個比對到的,底下是一個參考範例: strstr 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /* strstr example */ #include <stdio.h> #include <string.h> int main () { char str[] ="This is a simple string"; char * pch; /* 找尋 simple 字串 */ pch = strstr (str,"simple"); /* 將 simple 換成 sample */ strncpy (pch,"sample",6); puts (str); return 0; } 看一下 Kernel 原始檔案,strstr 函式: [Read More]

[網站] 好站連結 (七) Android, javascript, Css, PHP, Perl, FreeBSD, Linux

Windows C# C# 比較字串 MSDN 比較字串 Request.Form Collection Request Query String / Form Parametrs ASP.NET QueryString Usage Using include files with ASP.NET html [將所有 的內容包到一個 中][7] apache Fixing mod_rewrite and .htaccess on GoDaddy Hosting javascript jQuery Week Calendar Javascript: reference the parent window from a popup How to get and set form element values with jQuery How to check and uncheck a checkbox with jQuery Loop through parameters passed to a Javascript function perl-completion. [Read More]

[Kernel Driver] 撰寫簡易 Timer 機制

在底層 Linux Kernel 提供了時序(timing)機制,方便驅動程式設計者所使用,核心是依據硬體發出的『計時器中斷』來追蹤時間的流動狀況。我們可以依據 HZ 的值來設計 Delay 機制,讓驅動程式可以每隔固定一段時間啟動或者是發出訊號,也可以利用 Timer 來讓 LED 閃爍變化,在介紹 Timer API 之前,可以先參考 Linux Kernel: 簡介HZ, tick and jiffies 這篇文章,瞭解一些相關名詞,舉例:如果想知道一秒後的 jiffies 時間,可以寫成底下: #ifdef CONFIG_BMA150_TIMER #include #endif j = jiffies; /* 一秒之後 */ stamp_1 = j + HZ; /* 半秒之後 */ stamp_1 = j + HZ/2; /* 20秒之後 */ stamp_1 = j + 20*HZ; Timer API 用法 筆記一下自己在寫 BOSCH Sensortec 三軸加速偵測器(BMA150 Sensor) Driver 的時候,遇到底層要回報 input event X,Y,Z 到 Android HAL(Hardware abstraction layer),所以利用 Timer 的機制定時 report 給 Android。 首先宣告: [Read More]

[Linux Kernel] 簡單 hello world: License and Module 介紹(part 3)

在 Kernel 2.4 或以上版本,在編譯模組完成,要進行 load module 之前,你會發現底下訊息: # insmod hello-3.o Warning: loading hello-3.o will taint the kernel: no license See http://www.tux.org/lkml/#export-tainted for information about tainted modules 很顯然這訊息是要您在 kernel module 裡面加上版權宣告,例如:"GPL","GPL v2"…等來宣告您的 module 並非 open source,利用 MODULE_LICENSE() 巨集來宣告程式 License,同樣的,可以用 MODULE_DESCRIPTION() 來描述此模組或者是 Driver 的功用跟簡介,以及用 MODULE_AUTHOR() 來定義此模組作者,這些巨集都可以在 linux/module.h 裡找到,但是這些並非用於 Kernel 本身,如果大家想看範例程式,可以到 drivers/ 資料夾底下觀看每一個 Driver 程式,底下是簡單 hello world 範例: #include /* pr_info所需 include 檔案*/ #include #include /* 所有 module 巨集需要檔案*/ #include static int __init hello_init(void) { pr_info(" [Read More]

[高雄美食]道明中學武廟路好吃愛嬌姨臭豆腐

IMG_1290

我相信在高雄要吃到好吃的臭豆腐,無非就是豪記臭豆腐,大家可以參考懶喵兒滴窩:『[高雄-三民]豪記臭豆腐王【港式臭豆腐專賣店】 (新址)』,但是這次要來介紹也許在高雄比較少人知道的路邊攤臭豆腐,它位於高雄市武廟路上一間不起眼的臭豆腐,道明中學對面巷子走進去接到武廟路就可以吃到了,營業時間是下午15:30~19:40,時間不長,但是大排長龍阿,想要去吃的,最好不要挑晚餐時間,因為自己那個時間去吃,至少等了半小時。

[Read More]

[Linux Kernel] 撰寫 Hello, World module: The __init and __exit Macros (part 2).

再看此篇之前,可以先閱讀作者先前寫的:『[Linux Kernel Driver] 撰寫簡單 Hello, World module (part 1).』,今天要介紹 Driver 的 init module 區別,在 Kernel 2.4 版本,您可以自行定義 init 跟 cleanup 函式,他們不再被個別稱為 init_module() 和 cleanup_module(),現在都使用 module_init() 和 module_exit() 兩大巨集,這兩函式被定義在 linux/init.h 檔案裡面,所以在寫程式務必將其 include 喔,另外一個核心模組(MODULE_LICENSE),用於讓核心知道此模組遵守自由授權條款,若沒這項宣告,核心會跟您抱怨的喔,底下為範例: #include /* pr_info所需 include 檔案*/ #include #include /* 所有 module 需要檔案*/ #include MODULE_DESCRIPTION("Hello World !!"); MODULE_AUTHOR("Bo-Yi Wu "); MODULE_LICENSE("GPL"); static int __init hello_init(void) { pr_info("Hello, world appleboy\n"); pr_info("The process is \"%s\" (pid %i)\n", current->comm, current->pid); return 0; } static void __exit hello_exit(void) { printk(KERN_INFO " [Read More]

ProFTPD UseEncoding 繁體中文亂碼解決 Localization

Proftpd ProFTPD 一直都是我最喜歡使用的 FTP 伺服器,設定方式簡單淺顯易懂,最近在用 PSPad 寫程式,發現使用內建 FTP 功能時候,連不上 FreeBSD 架設的 ProFTPD,連線過程出現許多亂碼,所以造成 PSPad 斷線出現錯誤,解決方式就是利用 mod_lang 模組,設定 UseEncoding 讓系統可以顯示 Big5 中文編碼,FreeBSD Ports 請勾選

[X] NLSUOTA Use nls (builds mod_lang)
自行編譯請按照底下步驟
./configure --enable-nls
make
make install 

UseEncoding 設定

Syntax: UseEncoding on|off|local-charset client-charset
Default: None
Context: "server config", , 
Module: mod_lang
Compatibility: 1.3.2rc1
在 1.3.2rc1 版本之後才有支援,請複製底下設定,貼到 proftpd.conf
# 简体中文環境
UseEncoding UTF-8 GBK
# 繁体中文環境
UseEncoding UTF-8 Big5
Reference:

ProFTPD module mod_lang centos上解決proftp中文亂碼問題

[phpBB3] BBCode [url] Tag 支援中文網址

在 phpBB2 的時候就有發現這問題了,當時並沒有想去解決這問題,然而至今到了 phpBB3,依然出現這問題,不過我想這是因為中文網址的盛行,以及像 Wiki 之類都會有中文標籤,例如:一分鐘教室-userChrome.css,解決方法可以透過 urlencode 函式來處理掉網址編碼問題,在 phpBB 處理文章儲存,會先經過 bbcode 的處理,將 **** 標籤,會經過 get_preg_expression(‘url’) 這函式的驗證,看 url 是否合法,當然如果網址列有中文就不可能通過,所以必須在網址驗證之前,把網址編碼過,通過驗證之後再把網址解碼,這樣就沒問題了,底下為安裝步驟 打開 includes/message_parser.php 找尋 function validate_url($var1, $var2) 前面加入 /** * url encode * * @param string $string http url */ function encode_url($string) { $entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D'); $replacements = array('!', '*', "'", "(", ")", ";", ":", " [Read More]

[FreeBSD] update apache -> 2.2.15, PHP -> 5.3.2, and MySQL downgrade to 5.1.9

昨天升級了 FreeBSD 的 Apache, PHP, and MySQL,遇到很多地雷阿,最多的就是 PHP 的部份,因為本來自己使用 5.2.11 版本,但是在 commit port 的時候發生去裝 5.3.2 版本,所以就直接砍掉全部重練,先是遇到 MySQL 問題,原先在 database/mysql60-server 已經被 FreeBSD 移除,任何關於 mysql60 的相關 port 都被 remove 掉了,只好 downgrade 到 mysql 5.1.48 版本,移除同時順手把 apache PHP 相關都拿掉了。 移除 apache mysql php 相關 ports -rf 依序找尋相關 Mysql ports 移除 pkg_deinstall -rf mysql60-server 接下來安裝 MySQL 5.1.48 Server and Client,可以找到在 databases/mysql51-server and databases/mysql51-client,直接安裝即可 cd /usr/ports/databases/mysql51-server && make install 安裝 Apache 2.2.15 cd /usr/ports/www/apache22 && make WITH_MPM=worker install 安裝 PHP 5. [Read More]