From 57a4f6e054b51266830b6ebf16b6db10eba2e1b9 Mon Sep 17 00:00:00 2001 From: "Xingyu.Wang" Date: Sun, 6 May 2018 10:33:32 +0800 Subject: [PATCH 1/7] PRF:20140107 Caffeinated 6.828- Exercise- Shell.md @geekpi --- ...0107 Caffeinated 6.828- Exercise- Shell.md | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/translated/tech/20140107 Caffeinated 6.828- Exercise- Shell.md b/translated/tech/20140107 Caffeinated 6.828- Exercise- Shell.md index 50fb5b6167..126e8c2913 100644 --- a/translated/tech/20140107 Caffeinated 6.828- Exercise- Shell.md +++ b/translated/tech/20140107 Caffeinated 6.828- Exercise- Shell.md @@ -3,9 +3,10 @@ Caffeinated 6.828:练习 shell 通过在 shell 中实现多项功能,该作业将使你更加熟悉 Unix 系统调用接口和 shell。你可以在支持 Unix API 的任何操作系统(一台 Linux Athena 机器、装有 Linux 或 Mac OS 的笔记本电脑等)上完成此作业。请在第一次上课前将你的 shell 提交到[网站][1]。 -如果你在练习中遇到困难或不理解某些内容时,你不要害羞给[员工邮件列表][2]发送邮件,但我们确实希望全班的人能够自行处理这级别的 C 编程。如果你对 C 不是很熟悉,可以认为这个是你对 C 熟悉程度的检查。再说一次,如果你有任何问题,鼓励你向我们寻求帮助。 +如果你在练习中遇到困难或不理解某些内容时,你不要羞于给[员工邮件列表][2]发送邮件,但我们确实希望全班的人能够自行处理这级别的 C 编程。如果你对 C 不是很熟悉,可以认为这个是你对 C 熟悉程度的检查。再说一次,如果你有任何问题,鼓励你向我们寻求帮助。 下载 xv6 shell 的[框架][3],然后查看它。框架 shell 包含两个主要部分:解析 shell 命令并实现它们。解析器只能识别简单的 shell 命令,如下所示: + ``` ls > y cat < y | sort | uniq | wc > y1 @@ -13,31 +14,30 @@ cat y1 rm y1 ls | sort | uniq | wc rm y - ``` -将这些命令剪切并粘贴到 `t.sh `中。 +将这些命令剪切并粘贴到 `t.sh` 中。 + +你可以按如下方式编译框架 shell 的代码: -你可以按如下方式编译框架 shell: ``` $ gcc sh.c - ``` 它会生成一个名为 `a.out` 的文件,你可以运行它: + ``` $ ./a.out < t.sh - ``` -执行会崩溃,因为你还没有实现几个功能。在本作业的其余部分中,你将实现这些功能。 +执行会崩溃,因为你还没有实现其中的几个功能。在本作业的其余部分中,你将实现这些功能。 ### 执行简单的命令 实现简单的命令,例如: + ``` $ ls - ``` 解析器已经为你构建了一个 `execcmd`,所以你唯一需要编写的代码是 `runcmd` 中的 case ' '。要测试你可以运行 “ls”。你可能会发现查看 `exec` 的手册页是很有用的。输入 `man 3 exec`。 @@ -47,10 +47,10 @@ $ ls ### I/O 重定向 实现 I/O 重定向命令,这样你可以运行: + ``` echo "6.828 is cool" > x.txt cat < x.txt - ``` 解析器已经识别出 '>' 和 '<',并且为你构建了一个 `redircmd`,所以你的工作就是在 `runcmd` 中为这些符号填写缺少的代码。确保你的实现在上面的测试输入中正确运行。你可能会发现 `open`(`man 2 open`) 和 `close` 的 man 手册页很有用。 @@ -60,9 +60,9 @@ cat < x.txt ### 实现管道 实现管道,这样你可以运行命令管道,例如: + ``` $ ls | sort | uniq | wc - ``` 解析器已经识别出 “|”,并且为你构建了一个 `pipecmd`,所以你必须编写的唯一代码是 `runcmd` 中的 case '|'。测试你可以运行上面的管道。你可能会发现 `pipe`、`fork`、`close` 和 `dup` 的 man 手册页很有用。 @@ -71,7 +71,6 @@ $ ls | sort | uniq | wc ``` $ ./a.out < t.sh - ``` 无论是否完成挑战任务,不要忘记将你的答案提交给[网站][1]。 @@ -80,11 +79,10 @@ $ ./a.out < t.sh 如果你想进一步尝试,可以将所选的任何功能添加到你的 shell。你可以尝试以下建议之一: - * 实现由 `;` 分隔的命令列表 -  * 通过实现 `(` 和 `)` 来实现子 shell -  * 通过支持 `&` 和 `wait` 在后台执行命令 -  * 实现参数引用 - +* 实现由 `;` 分隔的命令列表 +* 通过实现 `(` 和 `)` 来实现子 shell +* 通过支持 `&` 和 `wait` 在后台执行命令 +* 实现参数引用 所有这些都需要改变解析器和 `runcmd` 函数。 @@ -95,7 +93,7 @@ via: https://sipb.mit.edu/iap/6.828/lab/shell/ 作者:[mit][a] 译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 From 55fff5f1f9c8846dbde728403510ce33146d1b1e Mon Sep 17 00:00:00 2001 From: "Xingyu.Wang" Date: Sun, 6 May 2018 10:33:54 +0800 Subject: [PATCH 2/7] PUB:20140107 Caffeinated 6.828- Exercise- Shell.md @geekpi --- .../20140107 Caffeinated 6.828- Exercise- Shell.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {translated/tech => published}/20140107 Caffeinated 6.828- Exercise- Shell.md (100%) diff --git a/translated/tech/20140107 Caffeinated 6.828- Exercise- Shell.md b/published/20140107 Caffeinated 6.828- Exercise- Shell.md similarity index 100% rename from translated/tech/20140107 Caffeinated 6.828- Exercise- Shell.md rename to published/20140107 Caffeinated 6.828- Exercise- Shell.md From bde1d6a7238a7eda330adbb8e1ff9f4a9a930ee2 Mon Sep 17 00:00:00 2001 From: MjSeven <33125422+MjSeven@users.noreply.github.com> Date: Sun, 6 May 2018 11:08:10 +0800 Subject: [PATCH 3/7] Delete 20180413 Useful Resources for Those Who Want to Know More About Linux.md --- ...Those Who Want to Know More About Linux.md | 129 ------------------ 1 file changed, 129 deletions(-) delete mode 100644 sources/tech/20180413 Useful Resources for Those Who Want to Know More About Linux.md diff --git a/sources/tech/20180413 Useful Resources for Those Who Want to Know More About Linux.md b/sources/tech/20180413 Useful Resources for Those Who Want to Know More About Linux.md deleted file mode 100644 index 3ef2c91b6f..0000000000 --- a/sources/tech/20180413 Useful Resources for Those Who Want to Know More About Linux.md +++ /dev/null @@ -1,129 +0,0 @@ -Translating by MjSeven - - -Useful Resources for Those Who Want to Know More About Linux -====== - -Linux is one of the most popular and versatile operating systems available. It can be used on a smartphone, computer and even a car. Linux has been around since the 1990s and is still one of the most widespread operating systems. - -Linux is actually used to run most of the Internet as it is considered to be rather stable compared to other operating systems. This is one of the [reasons why people choose Linux over Windows][1]. Besides, Linux provides its users with privacy and doesn’t collect their data at all, while Windows 10 and its Cortana voice control system always require updating your personal information. - -Linux has many advantages. However, people do not hear much about it, as it has been squeezed out from the market by Windows and Mac. And many people get confused when they start using Linux, as it’s a bit different from popular operating systems. - -So to help you out we’ve collected 5 useful resources for those who want to know more about Linux. - -### 1.[Linux for Absolute Beginners][2] - -If you want to learn as much about Linux as you can, you should consider taking a full course for beginners, provided by Eduonix. This course will introduce you to all features of Linux and provide you with all necessary materials to help you find out more about the peculiarities of how Linux works. - -You should definitely choose this course if: - - * you want to learn the details about the Linux operating system; - - * you want to find out how to install it; - - * you want to understand how Linux cooperates with your hardware; - - * you want to learn how to operate Linux command line. - - - - -### 2.[PC World: A Linux Beginner’s Guide][3] - -A free resource for those who want to learn everything about Linux in one place. PC World specializes in various aspects of working with computer operating systems, and it provides its subscribers with the most accurate and up-to-date information. Here you can also learn more about the [benefits of Linux][4] and latest news about his operating system. - -This resource provides you with information on: - - * how to install Linux; - - * how to use command line; - - * how to install additional software; - - * how to operate Linux desktop environment. - - - - -### 3.[Linux Training][5] - -A lot of people who work with computers are required to learn how to operate Linux in case Windows operating system suddenly crashes. And what can be better than using an official resource to start your Linux training? - -This resource provides online enrollment on the Linux training, where you can get the most updated information from the authentic source. “A year ago our IT department offered us a Linux training on the official website”, says Martin Gibson, a developer at [Assignmenthelper.com.au][6]. “We took this course because we needed to learn how to back up all our files to another system to provide our customers with maximum security, and this resource really taught us everything.” - -So you should definitely use this resource if: - - * you want to receive firsthand information about the operating system; - - * want to learn the peculiarities of how to run Linux on your computer; - - * want to connect with other Linux users and share your experience with them. - - - - -4. [The Linux Foundation: Training Videos][7] - -If you easily get bored from reading a lot of resources, this website is definitely for you. The Linux Foundation provides training videos, lectures and webinars, held by IT specialists, software developers and technical consultants. - -All the training videos are subdivided into categories for: - - * Developers: working with Linux Kernel, handling Linux Device Drivers, Linux virtualization etc.; - - * System Administrators: developing virtual hosts on Linux, building a Firewall, analyzing Linux performance etc.; - - * Users: getting started using Linux, introduction to embedded Linux and so on. - - - - -5. [LinuxInsider][8] - -Did you know that Microsoft was so amazed by the efficiency of Linux that it [allowed users to run Linux on Microsoft cloud computing device][9]? If you want to learn more about this operating system, Linux Insider provides its subscribers with the latest news on Linux operating systems, gives information about the latest updates and Linux features. - -On this resource, you will have the opportunity to: - - * participate in Linux community; - - * learn about how to run Linux on various devices; - - * check out reviews; - - * participate in blog discussions and read the tech blog. - - - - -### Wrapping up… - -Linux offers a lot of benefits, including complete privacy, stable operation and even malware protection. It’s definitely worth trying, learning how to use will help you better understand how your computer works and what it needs to operate smoothly. - -### About the Author -_Lucy Benton is a digital marketing specialist, business consultant and helps people to turn their dreams into the profitable business. Now she is writing for marketing and business resources. Also Lucy has her own blog_ [_Prowritingpartner.com_][10] _,where you can check her last publications._ - - --------------------------------------------------------------------------------- - -via: https://linuxaria.com/article/useful-resources-for-those-who-want-to-know-more-about-linux - -作者:[Lucy Benton][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) -选题:[lujun9972](https://github.com/lujun9972) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.lifewire.com -[1]:https://www.lifewire.com/windows-vs-linux-mint-2200609 -[2]:https://www.eduonix.com/courses/system-programming/linux-for-absolute-beginners -[3]:https://www.pcworld.com/article/2918397/operating-systems/how-to-get-started-with-linux-a-beginners-guide.html -[4]:https://www.popsci.com/switch-to-linux-operating-system#page-4 -[5]:https://www.linux.com/learn/training -[6]:https://www.assignmenthelper.com.au/ -[7]:https://training.linuxfoundation.org/free-linux-training/linux-training-videos -[8]:https://www.linuxinsider.com/ -[9]:https://www.wired.com/2016/08/linux-took-web-now-taking-world/ -[10]:https://prowritingpartner.com/ -[11]:https://cdn.linuxaria.com/wp-content/plugins/flattr/img/flattr-badge-large.png -[12]:https://linuxaria.com/?flattrss_redirect&id=8570&md5=ee76fa2b44bdf6ef419a7f9906d3a5ad (Flattr) From 5d614bf8834636d8549f7ca0057c400b678fc257 Mon Sep 17 00:00:00 2001 From: MjSeven <33125422+MjSeven@users.noreply.github.com> Date: Sun, 6 May 2018 11:08:38 +0800 Subject: [PATCH 4/7] Create 20180413 Useful Resources for Those Who Want to Know More About Linux.md --- ...Those Who Want to Know More About Linux.md | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 translated/tech/20180413 Useful Resources for Those Who Want to Know More About Linux.md diff --git a/translated/tech/20180413 Useful Resources for Those Who Want to Know More About Linux.md b/translated/tech/20180413 Useful Resources for Those Who Want to Know More About Linux.md new file mode 100644 index 0000000000..68db7151bf --- /dev/null +++ b/translated/tech/20180413 Useful Resources for Those Who Want to Know More About Linux.md @@ -0,0 +1,109 @@ +有用的资源,献给那些想更多了解 Linux 的人 +===== + +Linux 是最流行和多功能的操作系统之一,它可以用在智能手机,电脑甚至汽车上。自 20 世纪 90 年代以来,Linux 一直存在,并且仍然是最普遍的操作系统之一。 + +Linux 实际上用于运行大多数网络服务,因为与其他操作系统相比,它被认为是相当稳定的。这是[人们选择 Linux 多于 Windows的原因][1]之一。此外,Linux 为用户提供了隐私,并且根本不收集用户信息,而 Windows 10 及其 Cortana 语音控制系统总是需要更新你的个人信息。 + +Linux 有很多优点。然而,人们并没有听到太多关于它的消息,因为它已被 Windows 和 Mac 挤出市场。许多人开始使用 Linux 时会感到困惑,因为它与流行的操作系统有点不同。 + +为了帮助你,我们为那些想要了解更多关于 Linux 的人收集了 5 个有用的资源。 + +### 1.[ Linux 纯新手 ][2] + +如果你想尽可能多地学习 Linux,你应该考虑 Eduonix 为初学者提供的 Linux 完整教程。这个课程将向你介绍 Linux 的所有功能,并为你提供所有必要的资料,以帮助你了解更多关于 Linux 工作原理的特性。 + +如果你是以下情况,你应该选择本课程: + +* 你想了解有关 Linux 操作系统的详细信息; +* 你想知道如何安装它; +* 你想了解 Linux 如何与硬件配合使用; +* 你想学习如何操作 Linux 命令行。 + +### 2.[PC World: Linux 初学者指南][3] + +为想要在一个地方学习所有有关 Linux 的人提供免费资源。PC World 专注于计算机操作系统的各个方面,并为订阅用户提供最准确和最新的信息。在这里,你还可以了解更多关于 [Linux 的好处][4] 和关于其操作系统的最新消息。 + +该资源为你提供以下信息: + +* 如何安装 Linux; + +* 如何使用命令行; + +* 如何安装软件; + +* 如何操作 Linux 桌面环境。 + +### 3.[Linux 培训][5] + +很多使用计算机的人都需要学习如何操作 Linux,以防 Windows 操作系统突然崩溃。还有什么比使用官方资源来启动你的 Linux 培训更好呢? + +该资源提供了 Linux 训练的在线注册,你可以从官方来源获取最新信息。“一年前,我们的 IT 部门在官方网站上为我们提供了 Linux 培训” [Assignmenthelper.com.au][6] 的开发人员 Martin Gibson 说道。“我们选择了这门课,因为我们需要学习如何将我们的所有文件备份到另一个系统,为我们的客户提供最大的安全性,而且这个资源真的教会了我们所有的东西。” + +所以你肯定应该使用这个资源,如果: + +* 你想获得有关操作系统的第一手信息; + +* 想要了解如何在你的计算机上运行 Linux 的特性; + +* 想要与其他 Linux 用户联系并与他们分享你的经验。 + +### 4. [The Linux Foundation: 视频培训][7] + +如果你在阅读大量资源时容易感到无聊,那么该网站绝对适合你。Linux Foundation 提供由 IT 专家,软件开发技术人员和技术顾问举办的视频培训,讲座和在线研讨会。 + +所有培训视频分为以下类别: + +* 开发人员: 使用 Linux Kernel 来处理 Linux 设备驱动程序,Linux 虚拟化等; + +* 系统管理员:在 Linux 上开发虚拟主机,构建防火墙,分析 Linux 性能等; + +* 用户:开始使用 Linux,介绍嵌入式 Linux 等。 + +### 5. [LinuxInsider][8] + +你知道吗?微软对 Linux 的效率感到惊讶,它[允许用户在微软云计算设备上运行 Linux][9]。如果你想了解更多关于 Linux 操作系统的知识,Linux Insider 会向用户提供关于 Linux 操作系统的最新消息,以及最新更新和 Linux 特性的信息。 + +在此资源上,你将有机会: + +* 参与 Linux 社区; + +* 了解如何在各种设备上运行 Linux; + +* 看看评论; + +* 参与博客讨论并阅读科技博客。 + +### 总结一下 + +Linux 提供了很多好处,包括完全的隐私,稳定的操作甚至恶意软件保护。它绝对值得尝试,学习如何使用会帮助你更好地了解你的计算机如何工作以及它需要如何平稳运行。 + +### 关于作者 + +Lucy Benton 是一位数字营销专家,商业顾问,帮助人们将他们的梦想变为有利润的业务。现在她正在为营销和商业资源撰写。Lucy 还有自己的博客 [_Prowritingpartner.com_][10],在那里你可以查看她最近的发表。 + + +-------------------------------------------------------------------------------- + +via: https://linuxaria.com/article/useful-resources-for-those-who-want-to-know-more-about-linux + +作者:[Lucy Benton][a] +译者:[MjSeven](https://github.com/MjSeven) +校对:[校对者ID](https://github.com/校对者ID) +选题:[lujun9972](https://github.com/lujun9972) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.lifewire.com +[1]:https://www.lifewire.com/windows-vs-linux-mint-2200609 +[2]:https://www.eduonix.com/courses/system-programming/linux-for-absolute-beginners +[3]:https://www.pcworld.com/article/2918397/operating-systems/how-to-get-started-with-linux-a-beginners-guide.html +[4]:https://www.popsci.com/switch-to-linux-operating-system#page-4 +[5]:https://www.linux.com/learn/training +[6]:https://www.assignmenthelper.com.au/ +[7]:https://training.linuxfoundation.org/free-linux-training/linux-training-videos +[8]:https://www.linuxinsider.com/ +[9]:https://www.wired.com/2016/08/linux-took-web-now-taking-world/ +[10]:https://prowritingpartner.com/ +[11]:https://cdn.linuxaria.com/wp-content/plugins/flattr/img/flattr-badge-large.png +[12]:https://linuxaria.com/?flattrss_redirect&id=8570&md5=ee76fa2b44bdf6ef419a7f9906d3a5ad (Flattr) From 2e669196e9016e1e84a0b720faeeb98404fc6693 Mon Sep 17 00:00:00 2001 From: "Xingyu.Wang" Date: Sun, 6 May 2018 11:25:27 +0800 Subject: [PATCH 5/7] PRF&PUB:20140410 Recursion- dream within a dream.md @qhwdw @FSSlc https://linux.cn/article-9609-1.html --- ...0140410 Recursion- dream within a dream.md | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) rename {translated/tech => published}/20140410 Recursion- dream within a dream.md (77%) diff --git a/translated/tech/20140410 Recursion- dream within a dream.md b/published/20140410 Recursion- dream within a dream.md similarity index 77% rename from translated/tech/20140410 Recursion- dream within a dream.md rename to published/20140410 Recursion- dream within a dream.md index d283bed402..8056001960 100644 --- a/translated/tech/20140410 Recursion- dream within a dream.md +++ b/published/20140410 Recursion- dream within a dream.md @@ -1,11 +1,12 @@ -[递归:梦中梦][1] +递归:梦中梦 ====== -**递归**是很神奇的,但是在大多数的编程类书藉中对递归讲解的并不好。它们只是给你展示一个递归阶乘的实现,然后警告你递归运行的很慢,并且还有可能因为栈缓冲区溢出而崩溃。“你可以将头伸进微波炉中去烘干你的头发,但是需要警惕颅内高压以及让你的头发生爆炸,或者你可以使用毛巾来擦干头发。”难怪人们不愿意使用递归。但这种建议是很糟糕的,因为在算法中,递归是一个非常强大的观点。 +> “方其梦也,不知其梦也。梦之中又占其梦焉,觉而后知其梦也。” —— 《庄子·齐物论》 + +**递归**是很神奇的,但是在大多数的编程类书藉中对递归讲解的并不好。它们只是给你展示一个递归阶乘的实现,然后警告你递归运行的很慢,并且还有可能因为栈缓冲区溢出而崩溃。“你可以将头伸进微波炉中去烘干你的头发,但是需要警惕颅内高压并让你的头发生爆炸,或者你可以使用毛巾来擦干头发。”难怪人们不愿意使用递归。但这种建议是很糟糕的,因为在算法中,递归是一个非常强大的思想。 我们来看一下这个经典的递归阶乘: -递归阶乘 - factorial.c ``` #include @@ -28,15 +29,18 @@ int main(int argc) } ``` +*递归阶乘 - factorial.c* + + 函数调用自身的这个观点在一开始是让人很难理解的。为了让这个过程更形象具体,下图展示的是当调用 `factorial(5)` 并且达到 `n == 1`这行代码 时,[栈上][3] 端点的情况: ![](https://manybutfinite.com/img/stack/factorial.png) 每次调用 `factorial` 都生成一个新的 [栈帧][4]。这些栈帧的创建和 [销毁][5] 是使得递归版本的阶乘慢于其相应的迭代版本的原因。在调用返回之前,累积的这些栈帧可能会耗尽栈空间,进而使你的程序崩溃。 -而这些担心经常是存在于理论上的。例如,对于每个 `factorial` 的栈帧占用 16 字节(这可能取决于栈排列以及其它因素)。如果在你的电脑上运行着现代的 x86 的 Linux 内核,一般情况下你拥有 8 GB 的栈空间,因此,`factorial` 程序中的 `n` 最多可以达到 512,000 左右。这是一个 [巨大无比的结果][6],它将花费 8,971,833 比特来表示这个结果,因此,栈空间根本就不是什么问题:一个极小的整数 - 甚至是一个 64 位的整数 - 在我们的栈空间被耗尽之前就早已经溢出了成千上万次了。 +而这些担心经常是存在于理论上的。例如,对于每个 `factorial` 的栈帧占用 16 字节(这可能取决于栈排列以及其它因素)。如果在你的电脑上运行着现代的 x86 的 Linux 内核,一般情况下你拥有 8 GB 的栈空间,因此,`factorial` 程序中的 `n` 最多可以达到 512,000 左右。这是一个 [巨大无比的结果][6],它将花费 8,971,833 比特来表示这个结果,因此,栈空间根本就不是什么问题:一个极小的整数 —— 甚至是一个 64 位的整数 —— 在我们的栈空间被耗尽之前就早已经溢出了成千上万次了。 -过一会儿我们再去看 CPU 的使用,现在,我们先从比特和字节回退一步,把递归看作一种通用技术。我们的阶乘算法可归结为:将整数 N、N-1、 … 1 推入到一个栈,然后将它们按相反的顺序相乘。实际上我们使用了程序调用栈来实现这一点,这是它的细节:我们在堆上分配一个栈并使用它。虽然调用栈具有特殊的特性,但是它也只是额外的一种数据结构,你可以随意处置。我希望示意图可以让你明白这一点。 +过一会儿我们再去看 CPU 的使用,现在,我们先从比特和字节回退一步,把递归看作一种通用技术。我们的阶乘算法可归结为:将整数 N、N-1、 … 1 推入到一个栈,然后将它们按相反的顺序相乘。实际上我们使用了程序调用栈来实现这一点,这是它的细节:我们在堆上分配一个栈并使用它。虽然调用栈具有特殊的特性,但是它也只是又一种数据结构而已,你可以随意使用。我希望这个示意图可以让你明白这一点。 当你将栈调用视为一种数据结构,有些事情将变得更加清晰明了:将那些整数堆积起来,然后再将它们相乘,这并不是一个好的想法。那是一种有缺陷的实现:就像你拿螺丝刀去钉钉子一样。相对更合理的是使用一个迭代过程去计算阶乘。 @@ -48,7 +52,6 @@ int main(int argc) 每到边缘(线)都让老鼠左转或者右转来到达一个新的位置。如果向哪边转都被拦住,说明相关的边缘不存在。现在,我们来讨论一下!这个过程无论你是调用栈还是其它数据结构,它都离不开一个递归的过程。而使用调用栈是非常容易的: -递归迷宫求解 [下载][2] ``` #include @@ -75,21 +78,24 @@ int explore(maze_t *node) int found = explore(&maze); } ``` + +*递归迷宫求解 [下载][2]* + 当我们在 `maze.c:13` 中找到奶酪时,栈的情况如下图所示。你也可以在 [GDB 输出][8] 中看到更详细的数据,它是使用 [命令][9] 采集的数据。 ![](https://manybutfinite.com/img/stack/mazeCallStack.png) -它展示了递归的良好表现,因为这是一个适合使用递归的问题。而且这并不奇怪:当涉及到算法时,递归是规则,而不是例外。它出现在如下情景中:当进行搜索时、当进行遍历树和其它数据结构时、当进行解析时、当需要排序时:它无处不在。正如众所周知的 pi 或者 e,它们在数学中像“神”一样的存在,因为它们是宇宙万物的基础,而递归也和它们一样:只是它在计算的结构中。 +它展示了递归的良好表现,因为这是一个适合使用递归的问题。而且这并不奇怪:当涉及到算法时,*递归是规则,而不是例外*。它出现在如下情景中——进行搜索时、进行遍历树和其它数据结构时、进行解析时、需要排序时——它无处不在。正如众所周知的 pi 或者 e,它们在数学中像“神”一样的存在,因为它们是宇宙万物的基础,而递归也和它们一样:只是它存在于计算结构中。 -Steven Skienna 的优秀著作 [算法设计指南][10] 的精彩之处在于,他通过“战争故事” 作为手段来诠释工作,以此来展示解决现实世界中的问题背后的算法。这是我所知道的拓展你的算法知识的最佳资源。另一个读物是 McCarthy 的 [关于 LISP 实现的的原创论文][11]。递归在语言中既是它的名字也是它的基本原理。这篇论文既可读又有趣,在工作中能看到大师的作品是件让人兴奋的事情。 +Steven Skienna 的优秀著作 [算法设计指南][10] 的精彩之处在于,他通过 “战争故事” 作为手段来诠释工作,以此来展示解决现实世界中的问题背后的算法。这是我所知道的拓展你的算法知识的最佳资源。另一个读物是 McCarthy 的 [关于 LISP 实现的的原创论文][11]。递归在语言中既是它的名字也是它的基本原理。这篇论文既可读又有趣,在工作中能看到大师的作品是件让人兴奋的事情。 -回到迷宫问题上。虽然它在这里很难离开递归,但是并不意味着必须通过调用栈的方式来实现。你可以使用像 `RRLL` 这样的字符串去跟踪转向,然后,依据这个字符串去决定老鼠下一步的动作。或者你可以分配一些其它的东西来记录追寻奶酪的整个状态。你仍然是去实现一个递归的过程,但是需要你实现一个自己的数据结构。 +回到迷宫问题上。虽然它在这里很难离开递归,但是并不意味着必须通过调用栈的方式来实现。你可以使用像 `RRLL` 这样的字符串去跟踪转向,然后,依据这个字符串去决定老鼠下一步的动作。或者你可以分配一些其它的东西来记录追寻奶酪的整个状态。你仍然是实现了一个递归的过程,只是需要你实现一个自己的数据结构。 那样似乎更复杂一些,因为栈调用更合适。每个栈帧记录的不仅是当前节点,也记录那个节点上的计算状态(在这个案例中,我们是否只让它走左边,或者已经尝试向右)。因此,代码已经变得不重要了。然而,有时候我们因为害怕溢出和期望中的性能而放弃这种优秀的算法。那是很愚蠢的! -正如我们所见,栈空间是非常大的,在耗尽栈空间之前往往会遇到其它的限制。一方面可以通过检查问题大小来确保它能够被安全地处理。而对 CPU 的担心是由两个广为流传的有问题的示例所导致的:哑阶乘(dumb factorial)和可怕的无记忆的 O(2n) [Fibonacci 递归][12]。它们并不是栈递归算法的正确代表。 +正如我们所见,栈空间是非常大的,在耗尽栈空间之前往往会遇到其它的限制。一方面可以通过检查问题大小来确保它能够被安全地处理。而对 CPU 的担心是由两个广为流传的有问题的示例所导致的:哑阶乘dumb factorial和可怕的无记忆的 O( 2^n ) [Fibonacci 递归][12]。它们并不是栈递归算法的正确代表。 -事实上栈操作是非常快的。通常,栈对数据的偏移是非常准确的,它在 [缓存][13] 中是热点,并且是由专门的指令来操作它。同时,使用你自己定义的堆上分配的数据结构的相关开销是很大的。经常能看到人们写的一些比栈调用递归更复杂、性能更差的实现方法。最后,现代的 CPU 的性能都是 [非常好的][14] ,并且一般 CPU 不会是性能瓶颈所在。在考虑牺牲程序的简单性时要特别注意,就像经常考虑程序的性能及性能的[测量][15]那样。 +事实上栈操作是非常快的。通常,栈对数据的偏移是非常准确的,它在 [缓存][13] 中是热数据,并且是由专门的指令来操作它的。同时,使用你自己定义的在堆上分配的数据结构的相关开销是很大的。经常能看到人们写的一些比栈调用递归更复杂、性能更差的实现方法。最后,现代的 CPU 的性能都是 [非常好的][14] ,并且一般 CPU 不会是性能瓶颈所在。在考虑牺牲程序的简单性时要特别注意,就像经常考虑程序的性能及性能的[测量][15]那样。 下一篇文章将是探秘栈系列的最后一篇了,我们将了解尾调用、闭包、以及其它相关概念。然后,我们就该深入我们的老朋友—— Linux 内核了。感谢你的阅读! From 2ddc1a408012ba2f7f32fe8862cef1f817c97371 Mon Sep 17 00:00:00 2001 From: "Xingyu.Wang" Date: Sun, 6 May 2018 13:49:53 +0800 Subject: [PATCH 6/7] PRF:20180220 How to format academic papers on Linux with groff -me.md @amwps290 --- ...academic papers on Linux with groff -me.md | 122 +++--------------- 1 file changed, 18 insertions(+), 104 deletions(-) diff --git a/translated/tech/20180220 How to format academic papers on Linux with groff -me.md b/translated/tech/20180220 How to format academic papers on Linux with groff -me.md index 55b2e48517..52027eccaf 100644 --- a/translated/tech/20180220 How to format academic papers on Linux with groff -me.md +++ b/translated/tech/20180220 How to format academic papers on Linux with groff -me.md @@ -1,64 +1,51 @@ -# 在 Linux 上使用 groff -me 格式化你的学术论文 +在 Linux 上使用 groff -me 格式化你的学术论文 +=========== + +> 学习用简单的宏为你的课程论文添加脚注、引用、子标题及其它格式。 ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/life_paperclips.png?itok=j48op49T) -当我在 1993 年发现 Linux 时,我还是一名本科生。我很兴奋在我的宿舍里拥有 Unix 系统的强大功能,但是尽管它有很多功能,Linux 却缺乏应用程序。像 LibreOffice 和 OpenOffice 这样的文字处理程序还需要几年的时间。如果你想使用文字处理器,你可能会将你的系统引导到 MS-DOS 中,并使用 WordPerfect、shareware GalaxyWrite 或类似的程序。 +当我在 1993 年发现 Linux 时,我还是一名本科生。我很兴奋在我的宿舍里拥有 Unix 系统的强大功能,但是尽管它有很多功能,但 Linux 却缺乏应用程序。像 LibreOffice 和 OpenOffice 这样的文字处理程序还需要几年的时间才出现。如果你想使用文字处理器,你可能会将你的系统引导到 MS-DOS 中,并使用 WordPerfect、共享软件 GalaxyWrite 或类似的程序。 -`nroff` 和 `troff ` 。它们是同一系统的不同接口:`nroff` 生成纯文本输出,适用于屏幕或行式打印机,而 `troff` 产生非常优美的输出,通常用于在激光打印机上打印。 - -这就是我的方法,因为我需要为我的课程写论文,但我更喜欢呆在 Linux 中。我从我们的 “大 Unix ” 校园计算机实验室得知,Unix 系统提供了一组文本格式化的程序。它们是同一系统的不同接口:生成纯文本的输出,适合于屏幕或行打印机,或者生成非常优美的输出,通常用于在激光打印机上打印。 +这就是我的方法,因为我需要为我的课程写论文,但我更喜欢呆在 Linux 中。我从我们的 “大 Unix” 校园计算机实验室得知,Unix 系统提供了一组文本格式化的程序 `nroff` 和 `troff ` ,它们是同一系统的不同接口:`nroff` 生成纯文本输出,适用于屏幕或行式打印机,而 `troff` 产生非常优美的输出,通常用于在激光打印机上打印。 在 Linux 上,`nroff` 和 `troff` 被合并为 GNU troff,通常被称为 [groff][1]。 我很高兴看到早期的 Linux 发行版中包含了某个版本的 groff,因此我着手学习如何使用它来编写课程论文。 我学到的第一个宏集是 `-me` 宏包,一个简单易学的宏集。 -关于 `groff` ,首先要了解的是它根据一组宏处理和格式化文本。一个宏通常是一个两个字符的命令,它自己设置在一行上,并带有一个引导点。宏可能包含一个或多个选项。当 groff 在处理文档时遇到这些宏中的一个时,它会自动对文本进行格式化。 +关于 `groff` ,首先要了解的是它根据一组宏来处理和格式化文本。宏通常是个两个字符的命令,它自己设置在一行上,并带有一个引导点。宏可能包含一个或多个选项。当 `groff` 在处理文档时遇到这些宏中的一个时,它会自动对文本进行格式化。 下面,我将分享使用 `groff -me` 编写课程论文等简单文档的基础知识。 我不会深入细节进行讨论,比如如何创建嵌套列表,保存和显示,以及使用表格和数字。 ### 段落 -让我们从一个简单的例子开始,在几乎所有类型的文档中都可以看到:段落。段落可以格式化第一行的缩进或不缩进(即,与左边齐平)。 包括学术论文,杂志,期刊和书籍在内的许多印刷文档都使用了这两种类型的组合,其中文档或章节中的第一个(主要)段落与左侧的所有段落以及所有其他(常规)段落缩进。 在 `groff -me`中,您可以使用两种段落类型:前导段落(`.lp`)和常规段落(`.pp`)。 +让我们从一个简单的例子开始,在几乎所有类型的文档中都可以看到:段落。段落可以格式化为首行缩进或不缩进(即,与左边齐平)。 包括学术论文,杂志,期刊和书籍在内的许多印刷文档都使用了这两种类型的组合,其中文档或章节中的第一个(主要)段落左侧对齐,而所有其他(常规)的段落缩进。 在 `groff -me`中,您可以使用两种段落类型:前导段落(`.lp`)和常规段落(`.pp`)。 ``` .lp - This is the first paragraph. - .pp - This is a standard paragraph. - ``` ### 文本格式 -用粗体格式化文本的宏是 `.b`,斜体格式是 `.i` 。 如果您将 `.b` 或 `.i` 放在一行上,则后面的所有文本将以粗体或斜体显示。 但更有可能你只是想用粗体或斜体来表示一个或几个词。 要将一个词加粗或斜体,将该单词放在与 `.b` 或 `.i` 相同的行上作为选项。 要用**粗体**或斜体格式化多个单词,请将文字用引号引起来。 +用粗体格式化文本的宏是 `.b`,斜体格式是 `.i` 。 如果您将 `.b` 或 `.i` 放在一行上,则后面的所有文本将以粗体或斜体显示。 但更有可能你只是想用粗体或斜体来表示一个或几个词。 要将一个词加粗或斜体,将该单词放在与 `.b` 或 `.i` 相同的行上作为选项。 要用粗体或斜体格式化多个单词,请将文字用引号引起来。 ``` .pp - You can do basic formatting such as - .i italics - or - .b "bold text." - ``` -在上面的例子中,粗体文本结尾的句点也是粗体。 在大多数情况下,这不是你想要的。 只要文字是粗体字,而不是后面的句点也是粗体字。 要获得您想要的效果,您可以向 `.b` 或 `.i` 添加第二个参数,以指示要以粗体或斜体显示的文本,但是正常类型的文本。 您可以这样做,以确保尾随句点不会以粗体显示。 +在上面的例子中,粗体文本结尾的句点也是粗体。 在大多数情况下,这不是你想要的。 只要文字是粗体字,而不是后面的句点也是粗体字。 要获得您想要的效果,您可以向 `.b` 或 `.i` 添加第二个参数,以指示以粗体或斜体显示的文本后面跟着的任意文本以正常类型显示。 您可以这样做,以确保尾随句点不会以粗体显示。 ``` .pp - You can do basic formatting such as - .i italics - or - .b "bold text" . - ``` ### 列表 @@ -67,64 +54,38 @@ or ``` .pp - Bullet lists are easy to make: - .bu - Apple - .bu - Banana - .bu - Pineapple - .pp - Numbered lists are as easy as: - .np - One - .np - Two - .np - Three - .pp - Note that numbered lists will reset at the next pp or lp. - ``` ### 副标题 -如果你正在写一篇长论文,你可能想把你的内容分成几部分。使用 `groff -me`,您可以创建编号的标题 (`.sh`) 和未编号的标题 (`.uh`)。在这两种方法中,将节标题作为参数括起来。对于编号的标题,您还需要提供标题级别 `:1` 将给出一个一级标题(例如,1)。同样,`2` 和 `3` 将给出第二和第三级标题,如 2.1 或 3.1.1。 +如果你正在写一篇长论文,你可能想把你的内容分成几部分。使用 `groff -me`,您可以创建编号的标题(`.sh`) 和未编号的标题 (`.uh`)。在这两种方法中,将节标题作为参数括起来。对于编号的标题,您还需要提供标题级别 `:1` 将给出一个一级标题(例如,`1`)。同样,`2` 和 `3` 将给出第二和第三级标题,如 `2.1` 或 `3.1.1`。 ``` .uh Introduction - .pp - Provide one or two paragraphs to describe the work - and why it is important. - .sh 1 "Method and Tools" - .pp - Provide a few paragraphs to describe how you - did the research, including what equipment you used - ``` ### 智能引号和块引号 @@ -133,135 +94,88 @@ did the research, including what equipment you used ``` .pp - Christine Peterson coined the phrase \*(lqopen source.\*(rq - ``` `groff -me` 中还有一个快捷方式来创建这些引号(`.q`),我发现它更易于使用。 ``` .pp - Christine Peterson coined the phrase - .q "open source." - ``` -如果引用的是跨越几行的较长的引用,则需要使用一个块引用。为此,在引用的开头和结尾插入块引用宏( - -`.(q`)。 +如果引用的是跨越几行的较长的引用,则需要使用一个块引用。为此,在引用的开头和结尾插入块引用宏(`.(q`)。 ``` .pp - Christine Peterson recently wrote about open source: - .(q - On April 7, 1998, Tim O'Reilly held a meeting of key - leaders in the field. Announced in advance as the first - .q "Freeware Summit," - by April 14 it was referred to as the first - .q "Open Source Summit." - .)q - ``` ### 脚注 -要插入脚注,请在脚注文本前后添加脚注宏(`.(f`),并使用内联宏(`\ **`)添加脚注标记。脚注标记应出现在文本中和脚注中。 +要插入脚注,请在脚注文本前后添加脚注宏(`.(f`),并使用内联宏(`\**`)添加脚注标记。脚注标记应出现在文本中和脚注中。 ``` .pp - Christine Peterson recently wrote about open source:\** - .(f - \**Christine Peterson. - .q "How I coined the term open source." - .i "OpenSource.com." - 1 Feb 2018. - .)f - .(q - On April 7, 1998, Tim O'Reilly held a meeting of key - leaders in the field. Announced in advance as the first - .q "Freeware Summit," - by April 14 it was referred to as the first - .q "Open Source Summit." - .)q - ``` ### 封面 -大多数课程论文都需要一个包含论文标题,姓名和日期的封面。 在 `groff -me` 中创建封面需要一些组件。 我发现最简单的方法是使用居中的文本块并在标题,名称和日期之间添加额外的行。 (我倾向于在每一行之间使用两个空行)。在文章顶部,从标题页(`.tp`)宏开始,插入五个空白行(`.sp 5`),然后添加居中文本(`.(c`) 和额外的空白行(`.sp 2`)。 +大多数课程论文都需要一个包含论文标题,姓名和日期的封面。 在 `groff -me` 中创建封面需要一些组件。 我发现最简单的方法是使用居中的文本块并在标题、名字和日期之间添加额外的行。 (我倾向于在每一行之间使用两个空行)。在文章顶部,从标题页(`.tp`)宏开始,插入五个空白行(`.sp 5`),然后添加居中文本(`.(c`) 和额外的空白行(`.sp 2`)。 ``` .tp - .sp 5 - .(c - .b "Writing Class Papers with groff -me" - .)c - .sp 2 - .(c - Jim Hall - .)c - .sp 2 - .(c - February XX, 2018 - .)c - .bp - ``` 最后一个宏(`.bp`)告诉 groff 在标题页后添加一个分页符。 ### 更多内容 -这些是用 `groff-me` 写一份专业的论文非常基础的东西,包括前导和缩进段落,粗体和斜体,有序和无需列表,编号和不编号的章节标题,块引用以及脚注。 +这些是用 `groff-me` 写一份专业的论文非常基础的东西,包括前导和缩进段落,粗体和斜体,有序和无需列表,编号和不编号的章节标题,块引用以及脚注。 -我已经包含一个示例 groff 文件来演示所有这些格式。 将 `lorem-ipsum.me` 文件保存到您的系统并通过 groff 运行。 `-Tps` 选项将输出类型设置为 `PostScript` ,以便您可以将文档发送到打印机或使用 `ps2pdf` 程序将其转换为 PDF 文件。 +我已经包含一个[示例 groff 文件](https://opensource.com/sites/default/files/lorem-ipsum.me_.txt)来演示所有这些格式。 将 `lorem-ipsum.me` 文件保存到您的系统并通过 groff 运行。 `-Tps` 选项将输出类型设置为 `PostScript` ,以便您可以将文档发送到打印机或使用 `ps2pdf` 程序将其转换为 [PDF 文件](https://opensource.com/sites/default/files/lorem-ipsum.me_.pdf)。 ``` groff -Tps -me lorem-ipsum.me > lorem-ipsum.me.ps - ps2pdf lorem-ipsum.me.ps lorem-ipsum.me.pdf - ``` -如果你想使用 groff-me 的更多高级功能,请参阅 Eric Allman 所著的 “使用 `Groff-me` 来写论文”,你可以在你系统的 groff 的 `doc` 目录下找到一个名叫 `meintro.me` 的文件。这份文档非常完美的说明了如何使用 `groff-me` 宏来格式化你的论文。 +如果你想使用 `groff -me` 的更多高级功能,请参阅 Eric Allman 所著的 “使用 Groff -me 来写论文”,你可以在你系统的 groff 的 `doc` 目录下找到一个名叫 `meintro.me` 的文件。这份文档非常完美的说明了如何使用 `groff-me` 宏来格式化你的论文。 -------------------------------------------------------------------------------- @@ -269,7 +183,7 @@ via: https://opensource.com/article/18/2/how-format-academic-papers-linux-groff- 作者:[Jim Hall][a] 译者:[amwps290](https://github.com/amwps290) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 From 28659ff543d3213a93783f6eaf831dcf29ba71e8 Mon Sep 17 00:00:00 2001 From: "Xingyu.Wang" Date: Sun, 6 May 2018 13:50:19 +0800 Subject: [PATCH 7/7] PUB:20180220 How to format academic papers on Linux with groff -me.md @amwps290 https://linux.cn/article-9610-1.html --- ...80220 How to format academic papers on Linux with groff -me.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {translated/tech => published}/20180220 How to format academic papers on Linux with groff -me.md (100%) diff --git a/translated/tech/20180220 How to format academic papers on Linux with groff -me.md b/published/20180220 How to format academic papers on Linux with groff -me.md similarity index 100% rename from translated/tech/20180220 How to format academic papers on Linux with groff -me.md rename to published/20180220 How to format academic papers on Linux with groff -me.md