From owner-p4-projects@FreeBSD.ORG Sat Aug 5 19:39:32 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DDD1E16A4E5; Sat, 5 Aug 2006 19:39:31 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B75E016A4E1 for ; Sat, 5 Aug 2006 19:39:31 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5E14643D46 for ; Sat, 5 Aug 2006 19:39:31 +0000 (GMT) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k75JdVU5034965 for ; Sat, 5 Aug 2006 19:39:31 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k75JdU65034962 for perforce@freebsd.org; Sat, 5 Aug 2006 19:39:30 GMT (envelope-from jb@freebsd.org) Date: Sat, 5 Aug 2006 19:39:30 GMT Message-Id: <200608051939.k75JdU65034962@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 103273 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Aug 2006 19:39:32 -0000 http://perforce.freebsd.org/chv.cgi?CH=103273 Change 103273 by jb@jb_freebsd2 on 2006/08/05 19:39:07 IFC Affected files ... .. //depot/projects/dtrace/doc/en_US.ISO8859-1/articles/contributors/contrib.additional.sgml#20 integrate .. //depot/projects/dtrace/doc/zh_TW.Big5/books/developers-handbook/introduction/chapter.sgml#3 integrate .. //depot/projects/dtrace/doc/zh_TW.Big5/books/developers-handbook/tools/chapter.sgml#3 integrate .. //depot/projects/dtrace/doc/zh_TW.Big5/books/fdp-primer/sgml-primer/chapter.sgml#3 integrate .. //depot/projects/dtrace/doc/zh_TW.Big5/books/handbook/book.sgml#3 integrate .. //depot/projects/dtrace/doc/zh_TW.Big5/books/handbook/linuxemu/chapter.sgml#2 integrate .. //depot/projects/dtrace/doc/zh_TW.Big5/books/handbook/multimedia/chapter.sgml#4 integrate .. //depot/projects/dtrace/doc/zh_TW.Big5/books/handbook/ports/chapter.sgml#6 integrate .. //depot/projects/dtrace/src/sbin/dump/optr.c#3 integrate .. //depot/projects/dtrace/src/sbin/ipfw/ipfw2.c#6 integrate .. //depot/projects/dtrace/src/sys/dev/ata/ata-chipset.c#6 integrate .. //depot/projects/dtrace/src/sys/dev/ata/ata-pci.h#5 integrate .. //depot/projects/dtrace/src/sys/dev/ath/if_ath.c#9 integrate .. //depot/projects/dtrace/src/sys/dev/ath/if_athioctl.h#3 integrate .. //depot/projects/dtrace/src/sys/dev/isp/isp.c#7 integrate .. //depot/projects/dtrace/src/sys/dev/wi/if_wavelan_ieee.h#3 integrate .. //depot/projects/dtrace/src/sys/dev/wi/if_wi.c#5 integrate .. //depot/projects/dtrace/src/sys/dev/wi/if_wireg.h#3 integrate .. //depot/projects/dtrace/src/sys/kern/Makefile#4 integrate .. //depot/projects/dtrace/src/sys/netatalk/ddp_usrreq.c#4 integrate .. //depot/projects/dtrace/src/sys/vm/swap_pager.c#6 integrate .. //depot/projects/dtrace/src/tools/tools/ath/athstats/athstats.c#3 integrate .. //depot/projects/dtrace/src/tools/tools/net80211/Makefile#3 integrate .. //depot/projects/dtrace/src/tools/tools/net80211/README#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/stumbler/Makefile#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/stumbler/stumbler.c#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/Makefile#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/Makefile.inc#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/README#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/ap/Makefile#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/ap/ap.c#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/assoc/Makefile#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/assoc/assoc.c#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/expand/Makefile#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/expand/expand.c#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/libw00t/Makefile#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/libw00t/w00t.c#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/libw00t/w00t.h#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/prga/Makefile#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/prga/prga.c#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/redir/Makefile#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/redir/buddy.c#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/w00t/redir/redir.c#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/wlaninject/Makefile#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/wlaninject/README#1 branch .. //depot/projects/dtrace/src/tools/tools/net80211/wlaninject/wlaninject.c#1 branch .. //depot/projects/dtrace/src/usr.sbin/kldxref/kldxref.c#5 integrate .. //depot/projects/dtrace/www/en/gnome/docs/faq214.sgml#3 integrate .. //depot/projects/dtrace/www/en/projects/acpi/index.sgml#3 integrate Differences ... ==== //depot/projects/dtrace/doc/en_US.ISO8859-1/articles/contributors/contrib.additional.sgml#20 (text+ko) ==== @@ -1,4 +1,4 @@ - + @@ -73,11 +73,9 @@ <filename class="directory">/usr/src</filename> 的架構 - - 完整的 FreeBSD 原始碼都在公開的 CVS repository 中。 + 完整的 FreeBSD 原始碼都在公開的 CVS repository 中。 通常 FreeBSD 原始碼都會裝在 /usr/src, - 而且包含下列子目錄: - + 而且包含下列子目錄: ==== //depot/projects/dtrace/doc/zh_TW.Big5/books/developers-handbook/tools/chapter.sgml#3 (text+ko) ==== @@ -1,7 +1,7 @@ @@ -23,94 +23,77 @@ 程式開發工具 概敘 - - 本章將介紹如何使用一些 FreeBSD 所提供的程式開發工具(programing tools), + 本章將介紹如何使用一些 FreeBSD 所提供的程式開發工具(programing tools), 本章所介紹的工具程式在其他版本的 &unix; 上也可使用, 在此 並不會 嘗試描述寫程式時的每個細節, 本章大部分篇幅都是假設你以前沒有或只有少數的寫程式經驗, - 不過,還是希望大多數的程式開發人員都能從中重新得到一些啟發。 - + 不過,還是希望大多數的程式開發人員都能從中重新得到一些啟發。 簡介 - - FreeBSD 提供一個非常棒的開發環境, + FreeBSD 提供一個非常棒的開發環境, 比如說像是 C、C++、Fortran 和 assembler(組合語言)的編譯器(compiler), 在 FreeBSD 中都已經包含在基本的系統中了 更別提 Perl 和其他標準 &unix; 工具,像是sed 以及 awk, 如果你還是覺得不夠,FreeBSD在 Ports collection 中還提供其他的編譯器和直譯器(interpreter), FreeBSD 相容許多標準,像是 &posix;ANSI C, 當然還有它所繼承的 BSD 傳統。 - 所以在 FreeBSD 上寫的程式不需修改或頂多稍微修改,就可以在許多平台上編譯、執行。 - + 所以在 FreeBSD 上寫的程式不需修改或頂多稍微修改,就可以在許多平台上編譯、執行。 - - 無論如何,就算你從來沒在 &unix; 平台上寫過程式,也可以徹底感受到FreeBSD 令人無法抗拒的迷人魔力。 + 無論如何,就算你從來沒在 &unix; 平台上寫過程式,也可以徹底感受到FreeBSD 令人無法抗拒的迷人魔力。 本章的目標就是協助你快速上手,而暫時不需深入太多進階主題, - 並且講解一些基礎概念,以讓你可以瞭解我們在講些什麼。 - + 並且講解一些基礎概念,以讓你可以瞭解我們在講些什麼。 - - 本章內容並不要求你得有程式開發經驗,或者你只有一點點的經驗而已。 + 本章內容並不要求你得有程式開發經驗,或者你只有一點點的經驗而已。 不過,我們假設你已經會 &unix; 系統的基本操作, - 而且更重要的是,請保持樂於學習的心態! - + 而且更重要的是,請保持樂於學習的心態! Programming 概念 - - 簡單的說,程式只是一堆指令的集合體;而這些指令是用來告訴電腦應該要作那些事情。 + 簡單的說,程式只是一堆指令的集合體;而這些指令是用來告訴電腦應該要作那些事情。 有時候,指令的執行取決於前一個指令的結果而定。 本章將會告訴你有 2 個主要的方法,讓你可以對電腦下達這些指示(instruction) 或 命令(commands)。 第一個方法就是 直譯器(interpreter), 而第二個方法是 編譯器(compiler)。 由於對於電腦而言,人類語言的語意過於模糊而太難理解, - 因此命令(commands)就常會以一種(或多種)程式語言寫成,用來指示電腦所要執行的特定動作為何。 - + 因此命令(commands)就常會以一種(或多種)程式語言寫成,用來指示電腦所要執行的特定動作為何。 直譯器 - - 使用直譯器時,所使用的程式語言就像變成一個會和你互動的環境。 + 使用直譯器時,所使用的程式語言就像變成一個會和你互動的環境。 當在命令提示列上打上命令時,直譯器會即時執行該命令。 在比較複雜的程式中,可以把所有想下達的命令統統輸入到某檔案裡面去, 然後呼叫直譯器去讀取該檔案,並且執行你寫在這個檔案中的指令。 如果所下的指令有錯誤產生,大多數的直譯器會進入偵錯模式(debugger), - 並且顯示相關錯誤訊息,以便對程式除錯。 - + 並且顯示相關錯誤訊息,以便對程式除錯。 - - 這種方式好處在於:可以立刻看到指令的執行結果,以及錯誤也可迅速修正。 - 相對的,最大的壞處便是當你想把你寫的程式分享給其他人時,這些人必須要有跟你一樣的直譯器。 - 而且別忘了,他們也要會使用直譯器直譯程式才行。 - 當然使用者也不希望不小心按錯鍵,就進入偵錯模式而不知所措。 - 就執行效率而言,直譯器會使用到很多的記憶體, - 而且這類直譯式程式,通常並不會比編譯器所編譯的程式的更有效率。 - + 這種方式好處在於:可以立刻看到指令的執行結果,以及錯誤也可迅速修正。 + 相對的,最大的壞處便是當你想把你寫的程式分享給其他人時,這些人必須要有跟你一樣的直譯器。 + 而且別忘了,他們也要會使用直譯器直譯程式才行。 + 當然使用者也不希望不小心按錯鍵,就進入偵錯模式而不知所措。 + 就執行效率而言,直譯器會使用到很多的記憶體, + 而且這類直譯式程式,通常並不會比編譯器所編譯的程式的更有效率。 - - 筆者個人認為,如果你之前沒有學過任何程式語言,最好先學學習直譯式語言(interpreted languages), - 像是 Lisp,Smalltalk,Perl 和 Basic 都是,&unix; 的 shell 像是 shcsh - 它們本身就是直譯器,事實上,很多人都在它們自己機器上撰寫各式的 shell script, - 來順利完成各項 housekeeping(維護) 任務。 - &unix; 使用哲學之一就是提供大量的小工具, - 並使用 shell script 來組合運用這些小工具,以便工作更有效率。 + 筆者個人認為,如果你之前沒有學過任何程式語言,最好先學學習直譯式語言(interpreted languages), + 像是 Lisp,Smalltalk,Perl 和 Basic 都是,&unix; 的 shell 像是 shcsh + 它們本身就是直譯器,事實上,很多人都在它們自己機器上撰寫各式的 shell script, + 來順利完成各項 housekeeping(維護) 任務。 + &unix; 的使用哲學之一就是提供大量的小工具, + 並使用 shell script 來組合運用這些小工具,以便工作更有效率。 FreeBSD 提供的直譯器 - - 下面這邊有份 &os; Ports Collection 所提供的直譯器清單,還有討論一些比較受歡迎的直譯式語言 + 下面這邊有份 &os; Ports Collection 所提供的直譯器清單,還有討論一些比較受歡迎的直譯式語言 - - 至於如何使用 Ports Collection 安裝的說明,可參閱 FreeBSD Handbook 中的 + 至於如何使用 Ports Collection 安裝的說明,可參閱 FreeBSD Handbook 中的 Ports章節 @@ -146,8 +129,7 @@ ,此外 CMUCL(包含一個已經最佳化的編譯器), 以及其他簡化版的 LISP 直譯器(比如以 C 語言寫的 SLisp,只用幾百行程式碼就實作大多數 Common Lisp 的功能) 則是分別收錄在 lang/cmucl 以及 - lang/slisp。 - + lang/slisp @@ -169,8 +151,7 @@ Scheme 是 LISP 的另一分支,Scheme 的特點就是比 Common LISP 還要簡潔有力。 由於 Scheme 簡單,所以很多大學拿來當作第一堂程式語言教學教材。 - 而且對於研究人員來說也可以快速的開發他們所需要的程式。 - + 而且對於研究人員來說也可以快速的開發他們所需要的程式。 Scheme 收錄在 lang/elk, Elk Scheme 直譯器(由麻省理工學院所發展的 Scheme 直譯器)收錄在 @@ -208,8 +189,7 @@ Python 是物件導向的直譯式語言, Python 的擁護者總是宣稱 Python 是最好入門的程式語言。 雖然 Python 可以很簡單的開始,但是不代表它就會輸給其他直譯式語言(像是 Perl 和 Tcl), - 事實證明 Python 也可以拿來開發大型、複雜的應用程式。 - + 事實證明 Python 也可以拿來開發大型、複雜的應用程式。 &os; Ports Collection 收錄在 lang/python @@ -245,9 +225,9 @@ 編譯器 編譯器和直譯器兩者相比的話,有些不同,首先就是必須先把程式碼統統寫入到檔案裡面, - 然後必須執行編譯器來試著編譯程式,如果編譯器不接受所寫的程式,那就必須一直修改程式, - 直到編譯器接受且把你的程式編譯成執行檔。 - 此外,也可以在提示命令列,或在除錯器中執行你編譯好的程式看看它是否可以運作。 + 然後必須執行編譯器來試著編譯程式,如果編譯器不接受所寫的程式,那就必須一直修改程式, + 直到編譯器接受且把你的程式編譯成執行檔。 + 此外,也可以在提示命令列,或在除錯器中執行你編譯好的程式看看它是否可以運作。 如果在提示命令列下執行,那麼有可能會產生 core dump。 @@ -260,8 +240,7 @@ 而編譯器與直譯器最大的差別在於:當你想把你寫好的程式拿到另外一台機器上跑時, 你只要將編譯器編譯出來的可執行檔,拿到新機器上便可以執行, 而直譯器則必須要求新機器上,必須要有跟另一台機器上相同的直譯器, - 才能組譯執行你的程式! - + 才能組譯執行你的程式! 編譯式的程式語言包含 Pascal、C 和 C++, C 和 C++ 不是一個親和力十足的語言,但是很適合具有經驗的 Programmer。 @@ -271,8 +250,10 @@ lang/gpclang/fpc 中找到。 如果你用不同的程式來寫編譯式程式,那麼不斷地編輯-編譯-執行-除錯的這個循環肯定會很煩人, - 為了更簡化、方便程式開發流程,很多商業編譯器廠商開始發展所謂的 IDE(Integrated Development Environments) 開發環境, - FreeBSD 預設並沒有把 IDE 整合進 base system 中,但是你可透過 devel/kdevelop 安裝 kdevelop + 為了更簡化、方便程式開發流程,很多商業編譯器廠商開始發展所謂的 IDE + (Integrated Development Environments) 開發環境, + FreeBSD 預設並沒有把 IDE 整合進 base system 中, + 但是你可透過 devel/kdevelop 安裝 kdevelop 或使用 Emacs 來體驗 IDE 開發環境。 在後面的 專題將介紹,如何以 Emacs 來作為 IDE 開發環境。 @@ -338,7 +319,7 @@ 幸運的是,你可以不用理會以上細節,編譯器都會自動完成。 因為 cc 只是是個前端程式(front end),它會依照正確的參數來呼叫相關程式幫你處理。 - 只需打: + 只需打: &prompt.user; cc foobar.c 上述指令會把 foobar.c 開始編譯,並完成上述動作。 @@ -362,7 +343,7 @@ 編譯後的執行檔檔名,如果沒有使用這選項的話, - 編譯好的程式預設檔名將會是 a.out + 編譯好的程式預設檔名將會是 a.out 至於 的原因,則是一團歷史迷霧了。 @@ -398,8 +379,7 @@ - - 將會把一些給 gdb 用的除錯訊息包進去執行檔裡面,所謂的除錯訊息例如: + 將會把一些給 gdb 用的除錯訊息包進去執行檔裡面,所謂的除錯訊息例如: 程式在第幾行出錯、那個程式第幾行做什麼函式呼叫等等。除錯資訊非常好用。 但缺點就是:對於程式來說,額外的除錯訊息會讓編譯出來的程式比較肥些。 的適用時機在於:當程式還在開發時使用就好, @@ -426,13 +406,12 @@ 會產生最佳化的執行檔, - 編譯器會使用一些技巧,來讓程式可以跑的比未經最佳化的程式還快, - 你可以在大寫 O 後面加上數字來指明你想要的最佳化層級。 - 但是最佳化還是會有一些錯誤,舉例來說在當在 FreeBSD 2.10 release 中使用 cc - 並且指定 時,在某些情形下會產生錯誤的執行檔。 + 編譯器會使用一些技巧,來讓程式可以跑的比未經最佳化的程式還快, + 可以在大寫 O 後面加上數字來指明想要的最佳化層級。 + 但是最佳化還是會有一些錯誤,舉例來說在 FreeBSD 2.10 release 中用 cc + 且指定 時,在某些情形下會產生錯誤的執行檔。 - 只有當要釋出發行版本、或者加速程式時,才需要使用最佳化選項。 - + 只有當要釋出發行版本、或者加速程式時,才需要使用最佳化選項。 &prompt.user; cc -O -o foobar foobar.c @@ -444,11 +423,9 @@ - - 以下三個參數將會強迫 cc 確認程式碼是否符合一些國際標準的規範, + 以下三個參數將會強迫 cc 確認程式碼是否符合一些國際標準的規範, 也就是通常說的 ANSI 標準, - 而 ANSI 嚴格來講屬 ISO 標準。 - + 而 ANSI 嚴格來講屬 ISO 標準。 @@ -501,15 +478,14 @@ 告訴 gcc 在連結(linking)程式時你需要用到的函式庫名稱。 最常見的情況就是,當你在程式中使用了 C 數學函式庫, - 跟其他作業平台不一樣的是,這些數學函式都不在標準函式庫(library)中, + 跟其他作業平台不一樣的是,這函示學函式都不在標準函式庫(library)中, 因此編譯器並不知道這函式庫名稱,你必須告訴編譯器要加上它才行。 - 這規則很簡單,如果有個函式庫叫做 libsomething/a, + 規則很簡單,如果有個函式庫叫做 libsomething.a, 就必須在編譯時加上參數 才行。 舉例來說,數學函式庫叫做 libm.a, 所以你必須給 cc 的參數就是 。 - 一般情況下,通常會把這參數必須放在指令的最後。 - + 一般情況下,通常會把這參數必須放在指令的最後。 &prompt.user; cc -o foobar foobar.c -lm @@ -522,42 +498,34 @@ 。 如果你的 FreeBSD 是 2.2(含)以後版本, 你可以用指令 c++ 來取代 cc。 - 在 FreeBSD 上 c++ 也可以用 g++ 取代。 - + 在 FreeBSD 上 c++ 也可以用 g++ 取代。 - &prompt.user; cc -o foobar foobar.cc -lg++ For FreeBSD 2.1.6 and earlier -&prompt.user; cc -o foobar foobar.cc -lstdc++ For FreeBSD 2.2 and later + &prompt.user; cc -o foobar foobar.cc -lg++ 適用 FreeBSD 2.1.6 或更早期的版本 +&prompt.user; cc -o foobar foobar.cc -lstdc++ 適用 FreeBSD 2.2 及之後的版本 &prompt.user; c++ -o foobar foobar.cc - Each of these will both produce an executable - foobar from the C++ source file - foobar.cc. Note that, on &unix; - systems, C++ source files traditionally end in - .C, .cxx or - .cc, rather than the - &ms-dos; style - .cpp (which was already used for - something else). gcc used to rely on - this to work out what kind of compiler to use on the - source file; however, this restriction no longer applies, - so you may now call your C++ files - .cpp with impunity! + 上述指令都會從原始檔 foobar.cc 編譯產生名為 fooboar 的執行檔。 + 這邊要提醒的是在 &unix; 系統中 C++ 程式傳統都以 .C、 + .cxx 或者是 .cc 作為副檔名, + 而非 &ms-dos; 那種以 .cpp 作為副檔名的命名方式(不過也越來越普遍了)。 + gcc 會依副檔名來決定用哪一種編譯器編譯, + 然而,現在已經不再限制副檔名了, + 所以可以自由的使用 .cpp 作為 C++ 程式碼的副檔名! - Common <command>cc</command> Queries and Problems + 常見的 <command>cc</command> 問題 - I am trying to write a program which uses the - sin() function and I get an error - like this. What does it mean? + 我用 sin() 函示撰寫我的程式, + 但是有個錯誤訊息(如下),這代表著? /var/tmp/cc0143941.o: Undefined symbol `_sin' referenced from text segment @@ -566,10 +534,8 @@ - When using mathematical functions like - sin(), you have to tell - cc to link in the math library, like - so: + 當使用 sin() 這類的數學函示時, + 你必須告訴 cc 要和數學函式庫作連結(linking),就像這樣: &prompt.user; cc -o foobar foobar.c -lm @@ -580,9 +546,7 @@ - All right, I wrote this simple program to practice - using . All it does is raise 2.1 to - the power of 6. + 好吧,我試著寫些簡單的程式,來練習使用 -lm 選項(該程式會運算 2.1 的 6 次方) #include <stdio.h> @@ -597,15 +561,14 @@ - and I compiled it as: + 然後進行編譯: &prompt.user; cc temp.c -lm - like you said I should, but I get this when I run - it: + 編譯後執行程式,得到下面這結果: &prompt.user; ./a.out @@ -613,30 +576,24 @@ - This is not the right answer! - What is going on? + 很明顯的,程式結果不是正確答案,到底是哪邊出錯? - When the compiler sees you call a function, it - checks if it has already seen a prototype for it. If it - has not, it assumes the function returns an - int, which is definitely not what you want - here. + 當編譯器發現你呼叫一個函示時,它會確認該函示的回傳值類型(prototype), + 如果沒有特別指明,則預設的回傳值類型為 int(整數)。 + 很明顯的,你的程式所需要的並不是回傳值類別為 int - So how do I fix this? + 那如何才可以修正剛所說的問題? - The prototypes for the mathematical functions are in - math.h. If you include this file, - the compiler will be able to find the prototype and it - will stop doing strange things to your - calculation! + 數學函示的回傳值類型(prototype)會定義在 math.h, + 如果你有 include 這檔,編譯器就會知道該函示的回傳值類型,如此一來該運算就會得到正確的結果! #include <math.h> @@ -647,8 +604,7 @@ - After recompiling it as you did before, run - it: + 加了上述內容之後,再重新編譯,最後執行: &prompt.user; ./a.out @@ -656,27 +612,21 @@ - If you are using any of the mathematical functions, - always include - math.h and remember to link in the - math library. + 如果有用到數學函式,請確定要有 include math.h 這檔, + 而且記得要和數學函式庫作連結。 - I compiled a file called - foobar.c and I cannot find an - executable called foobar. Where has - it gone? + 已經編譯好 foobar.c, + 但是編譯後找不到 foobar 執行檔。 該去哪邊找呢? - Remember, cc will call the - executable a.out unless you tell it - differently. Use the - - option: + 記得,除非有指定編譯結果的執行檔檔名,否則預設的執行檔檔名是 a.out。 + 用 參數, + 就可以達到所想要的結果,比如: &prompt.user; cc -o foobar foobar.c @@ -687,108 +637,88 @@ - OK, I have an executable called - foobar, I can see it when I run - ls, but when I type in - foobar at the command prompt it tells - me there is no such file. Why can it not find - it? + 好,有個編譯好的程式叫做 foobar, + 用 ls 指令時可以看到, + 但執行時,訊息卻說卻沒有這檔案。為什麼? - Unlike &ms-dos;, &unix; does not - look in the current directory when it is trying to find - out which executable you want it to run, unless you tell - it to. Either type ./foobar, which - means run the file called - foobar in the current - directory, or change your PATH - environment - variable so that it looks something like + 與 &ms-dos; 不同的是,除非有指定執行檔的路徑, + 否則 &unix; 系統並不會在目前的目錄下尋找你想執行的檔案。 + 在指令列下打 ./foobar 代表 + 執行在這個目錄底下名為 foobar 的程式, + 或者也可以更改 PATH 環境變數設定如下,以達成類似效果: bin:/usr/bin:/usr/local/bin:. - The dot at the end means look in the current - directory if it is not in any of the - others. + 上一行最後的 "." 代表如果在前面寫的其他目錄找不到,就找目前的目錄 - I called my executable test, - but nothing happens when I run it. What is going - on? + 試著執行 test 執行檔, + 但是卻沒有任何事發生,到底是哪裡出錯了? - Most &unix; systems have a program called - test in /usr/bin - and the shell is picking that one up before it gets to - checking the current directory. Either type: + 大多數的 &unix; 系統都會在路徑 /usr/bin 擺放執行檔。 + 除非有指定使用在目前目錄內的 test,否則 shell 會優先選擇位在 + /usr/bintest, + 要指定檔名的話,作法類似: &prompt.user; ./test - or choose a better name for your program! + 為了避免上述困擾,請為你的程式取更好的名稱吧! - I compiled my program and it seemed to run all right - at first, then there was an error and it said something - about core dumped. What does that - mean? + 當執行我寫的程式時剛開始正常, + 接下來卻出現 core dumped 錯誤訊息。這錯誤訊息到底代表什麼? - The name core dump dates back - to the very early days of &unix;, when the machines used - core memory for storing data. Basically, if the program - failed under certain conditions, the system would write - the contents of core memory to disk in a file called - core, which the programmer could - then pore over to find out what went wrong. + 關於 core dumped 這個名稱的由來, + 可以追溯到早期的 &unix; 系統開始使用 core memory 對資料排序時。 + 基本上當程式在很多情況下發生錯誤後, + 作業系統會把 core memory 中的資訊寫入 core 這檔案中, + 以便讓 programmer 知道程式到底是為何出錯。 - Fascinating stuff, but what I am supposed to do - now? + 真是太神奇了!程式居然發生 core dumped 了,該怎麼辦? - Use gdb to analyze the core (see - ). + 請用 gdb 來分析 core 結果(詳情請參考 )。 - When my program dumped core, it said something about - a segmentation fault. What is - that? + 當程式已經把 core memory 資料 dump 出來後, + 同時也出現另一個錯誤 segmentation fault 這意思是? - This basically means that your program tried to - perform some sort of illegal operation on memory; &unix; - is designed to protect the operating system and other - programs from rogue programs. + 基本上,這個錯誤表示你的程式在記憶體中試著做一個嚴重的非法運作(illegal operation), + &unix; 就是被設計來保護整個作業系統免於被惡質的程式破壞,所以才會告訴你這個訊息。 - Common causes for this are: + 最常造成segmentation fault的原因通常為: - Trying to write to a NULL - pointer, eg + 試著對一個 NULL 的指標(pointer)作寫入的動作,如 char *foo = NULL; strcpy(foo, "bang!"); @@ -796,25 +726,21 @@ - Using a pointer that has not been initialized, - eg + 使用一個尚未初始化(initialized)的指標,如: char *foo; strcpy(foo, "bang!"); - The pointer will have some random value that, - with luck, will point into an area of memory that - is not available to your program and the kernel will - kill your program before it can do any damage. If - you are unlucky, it will point somewhere inside your - own program and corrupt one of your data structures, - causing the program to fail mysteriously. + 尚未初始化的指標的初始值將會是隨機的,如果你夠幸運的話, + 這個指標的初始值會指向 kernel 已經用到的記憶體位置, + kernel 會結束掉這個程式以確保系統運作正常。如果你不夠幸運, + 初始指到的記憶體位置是你程式必須要用到的資料結構(data structures)的位置, + 當這個情形發生時程式將會當的不知其所以然。 - Trying to access past the end of an array, - eg + 試著寫入超過陣列(array)元素個數,如: int bar[20]; bar[27] = 6; @@ -822,8 +748,7 @@ - Trying to store something in read-only memory, - eg + 試著讀寫在唯讀記憶體(read-only memory)中的資料,如: char *foo = "My string"; strcpy(foo, "bang!"); ==== //depot/projects/dtrace/doc/zh_TW.Big5/books/fdp-primer/sgml-primer/chapter.sgml#3 (text+ko) ==== @@ -27,23 +27,21 @@ ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - $FreeBSD: doc/zh_TW.Big5/books/fdp-primer/sgml-primer/chapter.sgml,v 1.3 2006/07/19 15:21:42 vanilla Exp $ + $FreeBSD: doc/zh_TW.Big5/books/fdp-primer/sgml-primer/chapter.sgml,v 1.4 2006/08/05 05:10:18 vanilla Exp $ Original revision: 1.45 --> SGML Primer - The majority of FDP documentation is written in applications of - SGML. This chapter explains exactly what that means, how to read - and understand the source to the documentation, and the sort of SGML - tricks you will see used in the documentation. + FDP 文件幾乎都是以 SGML 相關程式寫的。本章會介紹 SGML 是什麼、 + 如何閱讀、理解這些 SGML 原稿,以及本文件中所運用的各項 SGML 技巧。 - Portions of this section were inspired by Mark Galassi's Get Going With DocBook. + 本節部分靈感啟發來自 Mark Galassi 的這篇 Get Going With DocBook - Overview + 簡介 Way back when, electronic text was simple to deal with. Admittedly, you had to know which character set your document was written in (ASCII, ==== //depot/projects/dtrace/doc/zh_TW.Big5/books/handbook/book.sgml#3 (text+ko) ==== @@ -1,7 +1,7 @@ @@ -126,14 +126,14 @@ FreeBSD &rel.current;-RELEASE 的安裝和日常使用。 這份使用手冊是很多人的集體創作,而且仍然『持續不斷』的進行中。 許多章節仍未完成,已完成的部份也有些需要更新。 - 如果您對協助本計畫的進行有興趣的話,請寄 e-mail 到 &a.doc;。 + 如果您有興趣協助本計畫的話,請寄 e-mail 到 &a.doc;。 在 FreeBSD 網站 可以找到這份文件的最新版本(舊版文件可從 取得),也可以從 FreeBSD FTP 伺服器 或是眾多 mirror 站臺 - 下載不同格式及不同壓縮選項的資料。 - 如果比較偏好擁有實體書面資料,那可以在 + 下載不同格式的資料。 + 如果比較偏好實體書面資料,那可以在 FreeBSD Mall 購買。 此外,也可以在 使用手冊 中搜尋資料。 ==== //depot/projects/dtrace/doc/zh_TW.Big5/books/handbook/linuxemu/chapter.sgml#2 (text+ko) ==== @@ -1,8 +1,8 @@ @@ -28,101 +28,85 @@ - Linux Binary Compatibility + 與 Linux Binary 的相容方面 - Synopsis + 概述 Linux binary compatibility binary compatibility Linux - FreeBSD provides binary compatibility with several other - &unix; like operating systems, including Linux. At this point, - you may be asking yourself why exactly, does - FreeBSD need to be able to run Linux binaries? The answer to that - question is quite simple. Many companies and developers develop - only for Linux, since it is the latest hot thing in - the computing world. That leaves the rest of us FreeBSD users - bugging these same companies and developers to put out native - FreeBSD versions of their applications. The problem is, that most - of these companies do not really realize how many people would use - their product if there were FreeBSD versions too, and most continue - to only develop for Linux. So what is a FreeBSD user to do? This - is where the Linux binary compatibility of FreeBSD comes into - play. + FreeBSD 有提供其他幾種 &unix; like 作業系統的 binary 相容性,其中包括了 Linux。 + 你可能會納悶:為什麼 FreeBSD 需要能夠執行 Linux 專用執行檔(binary)呢?答案很簡單, + 許多公司、開發者只會 Linux 開發程式,因為這是目前資訊界 最熱門 的玩意。 + 這逼得許多 FreeBSD 使用者不得不去勸說這些人是否提供可直接在 FreeBSD 上執行的版本。 + 但問題是,大多數公司並不瞭解會有多少人會用 FreeBSD 版,因此他們仍只開發 Linux 版。 + 那麼 FreeBSD 使用者該怎麼辦呢?答案就是用 FreeBSD 所提供的 Linux binary 相容。 - In a nutshell, the compatibility allows FreeBSD users to run - about 90% of all Linux applications without modification. This - includes applications such as &staroffice;, - the Linux version of &netscape;, - &adobe; &acrobat;, - RealPlayer, - VMware, - &oracle;, - WordPerfect, Doom, - Quake, and more. It is also reported - that in some situations, Linux binaries perform better on FreeBSD - than they do under Linux. + 簡單來講,這種相容性可讓 FreeBSD 使用者直接執行約 90% 的 Linux 程式,而不必做任何修改。 + 這些包括了: &staroffice;、 + &netscape; 的 Linux 版、 + &adobe; &acrobat;、 + RealPlayer、 + VMware、 + &oracle;、 + WordPerfectDoom、 + Quake 等等。此外,也有人回報說在某些情況下, + 這些在 FreeBSD 上執行的 Linux 程式,甚至比原本在 Linux 執行得更好。 - There are, however, some Linux-specific operating system - features that are not supported under FreeBSD. Linux binaries will - not work on FreeBSD if they overly use &i386; specific - calls, such as enabling virtual 8086 mode. + 然而呢,還是有些只限 Linux 特定的作業系統功能,在 FreeBSD 上並未支援。 + 如果 Linux 程式過於濫用只有 &i386; 架構上才能用的功能,比如:虛擬 8086 模式, + 則可能無法在 FreeBSD 運作正常。 - After reading this chapter, you will know: + 讀完這章,您將了解: - How to enable Linux binary compatibility on your system. + 如何啟用 Linux 相容模式。 - How to install additional Linux shared - libraries. + 如何安裝額外的 Linux share libraries。 - How to install Linux applications on your FreeBSD system. + 如何在 FreeBSD 上安裝 Linux 程式。 - The implementation details of Linux compatibility in FreeBSD. + FreeBSD 上的 Linux 相容模式的實作細節。 - Before reading this chapter, you should: + 在閱讀這章之前,您應當了解: - Know how to install additional third-party - software (). + 知道如何透過 port 機制來安裝軟體()。 - Installation + 安裝 KLD (kernel loadable object) - Linux binary compatibility is not turned on by default. The - easiest way to enable this functionality is to load the + 預設並不會打開 Linux 相容模式,最簡單的啟用方式,就是載入 linux KLD object (Kernel LoaDable - object). You can load this module by typing the - following as root: + object)。 載入方式,請切為 root + 權限,然後打下列指令: &prompt.root; kldload linux - If you would like Linux compatibility to always be enabled, - then you should add the following line to - /etc/rc.conf: + 若要每次開機都啟用的話,請把下列內容加到 + /etc/rc.conf 檔: linux_enable="YES" - The &man.kldstat.8; command can be used to verify that the - KLD is loaded: + 另外可以用 &man.kldstat.8; 指令,來確認有哪些 KLD 有載入: &prompt.user; kldstat Id Refs Address Size Name @@ -130,7 +114,7 @@ 7 1 0xc24db000 d000 linux.ko kernel options - LINUX + COMPAT_LINUX If for some reason you do not want to or cannot load the KLD, @@ -160,7 +144,7 @@ from the Ports Collection. Simply do the following: - &prompt.root; cd /usr/ports/emulators/linux_base + &prompt.root; cd /usr/ports/emulators/linux_base-fc4 &prompt.root; make install distclean You should now have working Linux binary compatibility. @@ -1563,8 +1547,7 @@ Installation of FreeBSD First you have to install FreeBSD. There are several ways to do - this (FreeBSD 4.3 was installed via FTP, FreeBSD 4.5 directly from - the RELEASE CD) for more information read the . @@ -2066,7 +2049,7 @@ and &oracle;, therefore choose a larger number of shared memory pages. - With the default installation of FreeBSD 4.5 on &i386;, + With the default installation of FreeBSD on &i386;, leave MAXDSIZ and DFLDSIZ at 1 GB maximum. Otherwise, strange errors like ORA-27102: out of memory and Linux Error: 12: Cannot allocate memory @@ -3037,7 +3020,7 @@ >>> TRUNCATED FOR MAIL (1000 lines) <<<