mirror of
https://github.com/LCTT/TranslateProject.git
synced 2026-08-23 04:03:29 +08:00
Merge branch 'LCTT:master' into translate
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
[#]: subject: "Doing 64-bit math on a 16-bit system"
|
||||
[#]: via: "https://opensource.com/article/22/10/64-bit-math"
|
||||
[#]: author: "Jerome Shidel https://opensource.com/users/shidel"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "yzuowei"
|
||||
[#]: reviewer: "wxy"
|
||||
[#]: publisher: "wxy"
|
||||
[#]: url: "https://linux.cn/article-15332-1.html"
|
||||
|
||||
如何在 16 位系统上进行 64 位数学运算
|
||||
======
|
||||
|
||||
![][0]
|
||||
|
||||
> 只要对汇编有一点基本的了解,这些函数就能扩展到任意位长的整型数学运算。
|
||||
|
||||
几年前,我为 FreeDOS 写了一个叫做 VMATH 的命令行数学程序。它只能在很小的无符号整型上执行十分简单的数学运算。随着近来 FreeDOS 社区里对基础数学的兴趣,我改进了 VMATH 使其可以为有符号 64 位整型提供基本的数学支持。
|
||||
|
||||
仅使用 16 位 8086 兼容的汇编指令来操控大型数字的过程并不简单。我希望能够分享一些在 VMATH 中用到的技术例子。其中一些方法掌握起来相当容易。而另外一些方法则看起来有点奇怪。你甚至可能学到一种进行基本数学运算的全新方式。
|
||||
|
||||
接下来要讲的加、减、乘、除会用到的技术将不局限于并不局限于 64 位整型。只要对汇编有一点基本的了解,这些函数就能扩展到任意位长的整型数学运算。
|
||||
|
||||
在深入研究这些数学函数前,我想先从计算机的角度介绍一下数字的一些基本知识。
|
||||
|
||||
### 计算机是如何读取数字的
|
||||
|
||||
一个英特尔兼容的 CPU 以<ruby>字节<rt>Byte</rt></ruby>的形式贮存数字,储存顺序为从最低有效字节到最高有效字节。每个字节由 8 个二进<ruby>位<rt>Bit</rt></ruby>组成,两个字节组成一个<ruby>字<rt>Word</rt></ruby>。
|
||||
|
||||
一个储存在内存里的 64 位整型占用了 8 个字节(即 4 个字)。例如,数字 `74565`(十六进制表示为 `0x12345`)的值长得是这个样子的:
|
||||
|
||||
```
|
||||
用字节表示:db 0x45, 0x23, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
用字表示:dw 0x2345, 0x0001, 0x0000, 0x0000
|
||||
```
|
||||
|
||||
当读取或写入数据到内存时,CPU 会以正确的顺序处理这些字节。对于比 8086 更现代的处理器而言,数据分组可以再大些,比如一个<ruby>四字组<rt>Quadword</rt></ruby>就可以表达整个 64 位整型 `0x0000000000012345`。
|
||||
|
||||
8086 CPU 不能理解这么大的数字。当为 FreeDOS 编程时,你想要写的是一个能在任意电脑上跑的程序,甚至是原始的 IBM PC 5150。你想要使用能够扩展到任意大小整型的技术。我们其实并不关心更现代 CPU 的能力。
|
||||
|
||||
为了能做整型运算,我们的数据需要表达两种不同类型的数字。
|
||||
|
||||
第一种是<ruby>无符号<rt>unsigned</rt></ruby>整型,其使用了所有的位来表达一个正数。无符号整型的值域为从 `0` 到 $2^{位长} - 1$。例如,8 位数可以是 `0` 到 `255` 之间的任意值,而 16 位数则在 `0` 到
|
||||
`65535` 之间,以此类推。
|
||||
|
||||
有符号整型也很类似。不同之处在于数字的最高位代表了这个数是一个正数(`0`)还是一个负数 (`1`)。有符号整型的值域前半部分为正数,正数值域是从 `0` 到 $2^{(字长 - 1)} - 1$。整型值域的后半部分为负数,负数值域则从 $0 - (2^{位长 - 1})$ 到 `-1`。
|
||||
|
||||
比如说,一个 8 位数代表着 `0` 到 `127` 之间的任意正数,以及 `-128` 到 `-1` 之间的任意负数。为了能更好的理解这一点,想象 **字节** 为一列数组 `[0...127,-128...-1]`。因为 `-128` 在数组内紧跟着 `127`,`127` 加 `1` 等于 `-128`。当然这可能看起来有点奇怪甚至反常,但这其实让这个层级的基本数学运算变简单了。
|
||||
|
||||
为了能够对大型整型进行简单的加、减、乘、除,你应该摸索一些简单的公式来计算一个数的绝对值或负值。你在做有符号整型运算的时候会用上它们的。
|
||||
|
||||
### 绝对值与负值
|
||||
|
||||
计算一个有符号整型的绝对值并没有它看起来的那么糟糕。由于无符号和有符号数字在内存里的储存形式,我们其实有一个简单的方案。你只需要翻转一个负数的所有字位,得出的结果再加 `1`。
|
||||
|
||||
如果你从没接触过二进制的话,这可能听上去有点奇怪,但这就是这么工作的。让我们来举一个例子,取一个负数的 8 位表达,比如说 `-5`。因为 `-5` 靠近 `[0...127,-128...-1]` 字节组末端,它的十六进制值为 `0xfb`,二进制值为 `11111011`。如果你翻转了所有字位,你会得到 `0x04` 或二进制值 `00000100`。结果加 `1` 你就得到了你的答案:你刚刚把 `-5` 的值变成了 `+5`。
|
||||
|
||||
你可以用汇编写下这个程序用以返回任意 64 位数字的绝对值:
|
||||
|
||||
```
|
||||
; 语法,NASM for DOS
|
||||
proc_ABS:
|
||||
; 启动时,SI 寄存器会指向数据段(DS)内的内存位置,那里存放着程序内包含着
|
||||
; 会被转为正数的 64 位数。
|
||||
; 结束时,如果结果数字不能被转正,CF 寄存器会被设置。这种情况只
|
||||
; 有在遇到最大负值时会发生。其余情况,CF 不会被设置。
|
||||
|
||||
; 检查最高字节的最高位
|
||||
test [si+7], byte 0x80
|
||||
; 如不为 1,值为正值
|
||||
jz .done_ABS
|
||||
; 翻转所有位
|
||||
not word [si+6] ; 字 #4
|
||||
not word [si+4] ; 字 #3
|
||||
not word [si+2] ; 字 #2
|
||||
not word [si] ; 字 #1
|
||||
; 字 #1 加 1
|
||||
inc word [si]
|
||||
; 如结果不为 0,结束
|
||||
jnz .done_ABS
|
||||
; 字 #2 加 1
|
||||
inc word [si+2]
|
||||
; 如结果为 0,进位下一个字
|
||||
jnz .done_ABS
|
||||
inc word [si+4]
|
||||
jnz .done_ABS
|
||||
; 此处无法进位
|
||||
inc word [si+6]
|
||||
; 再一次检查最高位
|
||||
test [si+7], byte 0x80
|
||||
; 如不为 1,我们成功了,结束
|
||||
jz .done_ABS
|
||||
; 溢出错误,它被转成了负数
|
||||
stc
|
||||
; 设置 CF 并返回
|
||||
ret
|
||||
.done_ABS:
|
||||
; 成功,清理 CF 并返回
|
||||
clc
|
||||
ret
|
||||
```
|
||||
|
||||
你可能已经注意到了,这个函数有一个潜在问题。由于正数和负数的二进制值表达方式,最大负数无法被转成正数。以 8 位数为例,最大负数是 `-128`。如果你翻转了 `-128` 的所有位数(二进制 `1__0000000`),你会得到 127(二进制 `0__1111111`)这个最大正值。如果你对结果加 `1`,它会因溢出回到同样的负数(`-128`)。
|
||||
|
||||
要将正数转成负数,你只需要重复计算绝对值的步骤就行。以下的程序十分相似,你唯一需要确认的就是一开始的数字不是已经负了。
|
||||
|
||||
```
|
||||
; 语法, NASM for DOS
|
||||
proc_NEG:
|
||||
; 开始时,SI 会指向需要转负的数字在内存里的位置。
|
||||
; 结束时,CF 永远不会被设置。
|
||||
|
||||
; 检查最高字节的最高位
|
||||
test [si+7], byte 0x80
|
||||
; 如为 1,数已经是负数
|
||||
jnz .done_NEG
|
||||
not word [si+6] ; 翻转字的所有位,字 #4
|
||||
not word [si+4] ; 字 #3
|
||||
not word [si+2] ; 字 #2
|
||||
not word [si] ; 字 #1
|
||||
inc word [si] ; 字 #1 加 1
|
||||
; 如结果不为 0,结束
|
||||
jnz .done_NEG
|
||||
; 字 #2 加 1
|
||||
inc word [si+2]
|
||||
; 如结果为 0,进位下一个字
|
||||
jnz .done_NEG
|
||||
inc word [si+4]
|
||||
jnz .done_NEG
|
||||
; 此处无法进位或转化
|
||||
inc word [si+6]
|
||||
; 正。
|
||||
.done_NEG:
|
||||
clc ; 成功,清理 CF 并返回
|
||||
ret
|
||||
```
|
||||
|
||||
看着这些绝对值函数与负值函数间的通用代码,它们应该被合并起来节约一些字节。合并代码也会带来额外的好处。首先,合并代码能帮助防止简单的笔误。这样也可以减少测试的要求。进一步来讲,这样通常会让代码变得简单易懂。在阅读一长串的汇编指令时,忘记读到哪里是常有的事。现在,我们可以不管这些。
|
||||
|
||||
计算一个数的绝对值或负值并不难。但是,这些函数对于我们即将开始的有符号整型数学运算至关重要。
|
||||
|
||||
我已经介绍了整型数字在位这一层面的基本表示方法,也创造了可以改变这些数字的基本程序,现在我们可以做点有趣的了。
|
||||
|
||||
让我们来做些数学运算吧!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/22/10/64-bit-math
|
||||
|
||||
作者:[Jerome Shidel][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[yzuowei](https://github.com/yzuowei)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/shidel
|
||||
[b]: https://github.com/lkxed
|
||||
[0]: https://img.linux.net.cn/data/attachment/album/202212/09/150829g7c7x5e22qqo53c4.jpg
|
||||
@@ -0,0 +1,91 @@
|
||||
[#]: subject: "Apple Silicon GPU Driver is Now Available in Asahi Linux"
|
||||
[#]: via: "https://news.itsfoss.com/apple-gpu-driver-asahi-linux/"
|
||||
[#]: author: "Sourav Rudra https://news.itsfoss.com/author/sourav/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: " "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Apple Silicon GPU Driver is Now Available in Asahi Linux
|
||||
======
|
||||
|
||||
We finally have a GPU driver for Apple M silicon systems on Asahi Linux.
|
||||
|
||||
![Apple Silicon GPU Driver is Now Available in Asahi Linux][1]
|
||||
|
||||
Asahi Linux aims to be a port of Linux for Apple Silicon Macs; work started on it back in 2020, right after the launch of Apple's M1 chips at the WWDC event.
|
||||
|
||||
A small team is behind all the development behind Asahi Linux and reverse engineering stuff; they have been quite busy since the last time we looked at their work.
|
||||
|
||||
Previously, they worked on improving support for Apple SoCs such as the M1, M1 Pro, and M1 Max. They provided varying levels of support for devices that used these chips.
|
||||
|
||||
It still is a work in progress, but promising results in 2022.
|
||||
|
||||
They have now taken it further by providing initial support for Apple Silicon GPUs by releasing drivers (in _alpha_).
|
||||
|
||||
That sounds great! 😃
|
||||
|
||||
Let me take you through the gist of it.
|
||||
|
||||
### Hardware Acceleration With Desktop Environments and Old Games
|
||||
|
||||
![asahi linux running quake3][2]
|
||||
|
||||
Introduced as an alpha-stage GPU driver, it can run desktop environments and a few games smoothly.
|
||||
|
||||
**The implementation:** The driver features a work-in-progress implementation of OpenGL 2.1 and OpenGL ES 2.0 for current Apple M-series systems.
|
||||
|
||||
They also mention that:
|
||||
|
||||
> These drivers have not yet passed the OpenGL (ES) conformance tests. There will be bugs!
|
||||
|
||||
So, you can expect plenty of hiccups along the way should you choose to run applications using these drivers.
|
||||
|
||||
**How it works now?:** In its current form, the driver can run desktop environments like GNOME and KDE Plasma with hardware acceleration.
|
||||
|
||||
Even older games like [Quake3][3] and [Neverball][4] can run quite well, with these and the desktop environments running at a solid **60 fps at 4k resolution**.
|
||||
|
||||
Many users may also notice that quite a few apps don't work with this driver right away. On that, the developers mention:
|
||||
|
||||
> Since the driver is still in development, there are lots of known issues and we’re still working hard on improving conformance test results. Please don’t open new bugs for random apps not working! It’s still the early days and we know there’s a lot of work to do.
|
||||
|
||||
**What does the future hold?:** The developers have said that while OpenGL (ES) 2 suffices for some applications, newer applications will require new features such as multiple render targets, multisampling, and transform feedback.
|
||||
|
||||
All of this can be achieved with OpenGL (ES) 3, and work on that has already started. But, it will need a lot of developmental effort to get ready.
|
||||
|
||||
They have also hinted at support for Vulkan in the future, although it is a long time in the making.
|
||||
|
||||
Here's what they tell about it:
|
||||
|
||||
> We’re working on it! Although we’re only shipping OpenGL right now, we’re designing with Vulkan in mind. Most of the work we’re putting toward OpenGL will be reused for Vulkan. We estimated that we could ship working OpenGL 2 drivers much sooner than a working Vulkan 1.0 driver, and we wanted to get hardware accelerated desktops into your hands as soon as possible.
|
||||
|
||||
When a Reddit user [asked][5] about **120 Hz support for MacBook Pro**, one of the maintainers had this to say:
|
||||
|
||||
> 120Hz is disabled because it still is capped at 60Hz if we do nothing and was having other weird issues. It's still unclear exactly how VRR works on macOS, we need to figure that out first.
|
||||
|
||||
It seems like Asahi Linux has a lot of room to grow, and improvements like this to GPU drivers on a new Silicon system should finally open up new opportunities in terms of performance.
|
||||
|
||||
Linux users have been asking for something like this for a long time, and it is now closer to becoming a reality than ever before.
|
||||
|
||||
If you are feeling adventurous and want to try the new GPU driver, you can try installing it on your Asahi Linux system. Refer to the [official announcement][6] for instructions to experiment with it.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://news.itsfoss.com/apple-gpu-driver-asahi-linux/
|
||||
|
||||
作者:[Sourav Rudra][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://news.itsfoss.com/author/sourav/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://news.itsfoss.com/content/images/size/w2000/2022/12/apple-gpu-asahi-linux.png
|
||||
[2]: https://news.itsfoss.com/content/images/2022/12/AsahiLinux_Quake3.jpg
|
||||
[3]: https://ioquake3.org
|
||||
[4]: https://neverball.org
|
||||
[5]: https://www.reddit.com/r/AsahiLinux/comments/zeucpz/comment/iza3wwv/?utm_source=share&utm_medium=web2x&context=3
|
||||
[6]: https://asahilinux.org/2022/12/gpu-drivers-now-in-asahi-linux/
|
||||
@@ -0,0 +1,90 @@
|
||||
[#]: subject: "Mastodon's Adoption Gets a Boost With Vivaldi Browser Integration"
|
||||
[#]: via: "https://news.itsfoss.com/vivaldi-mastodon-integration/"
|
||||
[#]: author: "Ankush Das https://news.itsfoss.com/author/ankush/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: " "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Mastodon's Adoption Gets a Boost With Vivaldi Browser Integration
|
||||
======
|
||||
|
||||
Vivaldi's making an effort to have more users join Mastodon with its new update. That's nice to see!
|
||||
|
||||
![Mastodon's Adoption Gets a Boost With Vivaldi Browser Integration][1]
|
||||
|
||||
Vivaldi browser is one of the best web browsers for Linux (Windows, macOS, and mobile platforms).
|
||||
|
||||
I know it is not an open-source pick, but it gets all the lead with its tab management, customizability, and productivity features. And it treats me better than Firefox nowadays (Mozilla, we still need you to do better)🙄
|
||||
|
||||
**Note:**_Vivaldi is **not open-source**. Most of it is based on Chromium, for which you can find the [source code][2]._
|
||||
|
||||
If you did not know, Vivaldi recently built a Mastodon instance (**Vivaldi Social**) to encourage people to use open-source and decentralized social media platforms.
|
||||
|
||||
It is one of the best Mastodon instances you can join:
|
||||
|
||||
To take this further, **Vivaldi 5.6 update** has integrated access to its Mastodon instance from within its web browser.
|
||||
|
||||
> 🐘 Hey! We are on [Mastodon][3] for a while; follow **us if you haven't already**! 😄
|
||||
|
||||
### Access Mastodon From Web Panels
|
||||
|
||||
Web panels on Vivaldi make it a breeze to multitask. You can keep browsing or working on what you want and still access additional services in a single click.
|
||||
|
||||
Here's what it looks like:
|
||||
|
||||
![mastodon on vivaldi][4]
|
||||
|
||||
I can access Vivaldi's Mastodon instance quickly.
|
||||
|
||||
Of course, you can add your custom web panel for any Mastodon instance you like.
|
||||
|
||||
![vivaldi web panel addition][5]
|
||||
|
||||
However, I believe out-of-the-box integration should encourage Vivaldi users to try Mastodon if they haven't yet.
|
||||
|
||||
In the official announcement, Vivaldi also explains it properly for its users:
|
||||
|
||||
> [Vivaldi Social][6] came into existence as we love the idea of distributed social networks based on open standards. We want to offer better alternatives to people to communicate in an algorithm-free environment with no surveillance capitalism, devoid of tracking or data profiling.The Mastodon server platform communicates through the [Activity Pub][7] standard, a decentralized social networking and messaging protocol recommended by the [World Wide Web Consortium (W3C)][8]. Any platform or application that implements ActivityPub becomes a part of a massive social network. This big social network is also called the [Fediverse][9] (“federated” + “universe”).
|
||||
|
||||
Before anyone gets their pitchfork ready, I want Vivaldi to be 100% open-source, but we also want more companies in the mainstream to adopt and encourage the use of open-source tech.
|
||||
|
||||
And I think Vivaldi has got an excellent approach to that.
|
||||
|
||||
So, this integration should ultimately let every Vivaldi (or Linux user) use Mastodon more than often.
|
||||
|
||||
In addition to this change, Vivaldi 5.6 release involves a couple of improvements that include:
|
||||
|
||||
- A new search engine (You.com)
|
||||
- Panels joining editable toolbars
|
||||
- Revamped settings page
|
||||
- Pin tab stacks (_this is exciting!_)
|
||||
|
||||
You can update the browser to get the latest version or download Vivaldi 5.6 on its official website.
|
||||
|
||||
[Download Vivaldi 5.6][10]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://news.itsfoss.com/vivaldi-mastodon-integration/
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://news.itsfoss.com/author/ankush/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://news.itsfoss.com/content/images/size/w2000/2022/12/mastodon-integration-in-vivaldi-browser-1.png
|
||||
[2]: https://vivaldi.com/source/
|
||||
[3]: https://mastodon.social/web/@itsfoss
|
||||
[4]: https://news.itsfoss.com/content/images/2022/12/mastodon-vivaldi.jpg
|
||||
[5]: https://news.itsfoss.com/content/images/2022/12/add-custom-panel.jpg
|
||||
[6]: https://vivaldi.com/blog/news/vivaldi-social-a-new-mastodon-instance/
|
||||
[7]: https://en.wikipedia.org/wiki/ActivityPub
|
||||
[8]: https://www.w3.org/
|
||||
[9]: https://en.wikipedia.org/wiki/Fediverse
|
||||
[10]: https://vivaldi.com/download/
|
||||
@@ -0,0 +1,87 @@
|
||||
[#]: subject: "Convert and Manipulate Images With ‘Converter’ GUI Tool in Linux"
|
||||
[#]: via: "https://itsfoss.com/converter-tool/"
|
||||
[#]: author: "Ankush Das https://itsfoss.com/author/ankush/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: " "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Convert and Manipulate Images With ‘Converter’ GUI Tool in Linux
|
||||
======
|
||||
|
||||
You can always [install ImageMagick][1] on your system to convert images, but not everyone likes to use the terminal for converting and manipulating images.
|
||||
|
||||
So, what if you have a GUI app as a front-end to help with that? **Converter** is precisely that.
|
||||
|
||||
It is a front-end to ImageMagick. So you do not need to use commands to convert and manipulate images.
|
||||
|
||||
Note that most Ubuntu systems usually have ImageMagick pre-installed. You can always refer to our [installation guide][1] if you do not have it on your system.
|
||||
|
||||
### Converter: A Graphical Front-end to ImageMagick
|
||||
|
||||
![converter gui][2]
|
||||
|
||||
It should not take a lot of effort to convert images. It is a simple task, and that is how it should be.
|
||||
|
||||
I do not want to type a command to convert an image quickly. Hence, I prefer graphical tools that enable me to do things faster.
|
||||
|
||||
[Converter][3] is an open-source graphical front-end that enables you to do that. It is a GTK4+libadwaita application.
|
||||
|
||||
You can convert the images to various file formats that include **png, webp, jpeg, heif, heic, and bmp**. It is safe to say that you get support for the most popular image file formats. So, it should come in pretty handy.
|
||||
|
||||
![file format converter][4]
|
||||
|
||||
You can set a location to save all the files, and the converted images will automatically be stored at that location.
|
||||
|
||||
![customize converter][5]
|
||||
|
||||
You can also adjust an image’s quality, size, and background color. To access these options, click on “**More Options**” in the user interface before converting the image.
|
||||
|
||||
![converter more options][6]
|
||||
|
||||
The image size can be customized using its percentage, exact pixels, or ratio. For precise manipulation, changing the dimensions should help.
|
||||
|
||||
If you want the image scaled to an extent, the percentage or ratio functionality should help you do that. You can also choose to add filters to your images.
|
||||
|
||||
Overall, you get the basic options to re-size, convert, and optimize the image quality with Converter.
|
||||
|
||||
You can also [tweak Nautilus][7] to have the [resize option in the right-click context menu][8]. It won’t be as versatile as this tool.
|
||||
|
||||
### Install Converter on Linux
|
||||
|
||||
Converter is available as a Flatpak on [Flathub][9] to install on any Linux distribution of your choice.
|
||||
|
||||
Unfortunately, you do not get any binary packages to install on your Linux system. So, you might want to refer to our [Flatpak guide][10] to get it installed.
|
||||
|
||||
```
|
||||
flatpak install flathub io.gitlab.adhami3310.Converter
|
||||
```
|
||||
|
||||
You can explore more about it on its [GitLab page][3].
|
||||
|
||||
_Do you have any suggestions to nifty tools like this for us to highlight next? Let us know in the comments._
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/converter-tool/
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/ankush/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://itsfoss.com/install-imagemagick-ubuntu/
|
||||
[2]: https://itsfoss.com/wp-content/uploads/2022/12/converter-gui.png
|
||||
[3]: https://gitlab.com/adhami3310/Converter
|
||||
[4]: https://itsfoss.com/wp-content/uploads/2022/12/file-format-converter.png
|
||||
[5]: https://itsfoss.com/wp-content/uploads/2022/12/customize-converter.png
|
||||
[6]: https://itsfoss.com/wp-content/uploads/2022/12/converter-more-options.png
|
||||
[7]: https://itsfoss.com/nautilus-tips-tweaks/
|
||||
[8]: https://itsfoss.com/resize-images-with-right-click/
|
||||
[9]: https://flathub.org/apps/details/io.gitlab.adhami3310.Converter
|
||||
[10]: https://itsfoss.com/flatpak-guide/
|
||||
@@ -0,0 +1,255 @@
|
||||
[#]: subject: "7 pro tips for using the GDB step command"
|
||||
[#]: via: "https://opensource.com/article/22/12/gdb-step-command"
|
||||
[#]: author: "Alexandra https://opensource.com/users/ahajkova"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: " "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
7 pro tips for using the GDB step command
|
||||
======
|
||||
|
||||
A debugger is software that runs your code and examines any problems it finds. [GNU Debugger][1] (GBD) is one of the most popular debuggers, and in this article, I examine GDB's `step` command and related commands for several common use cases. Step is a widely used command but there are a few lesser known things about it which might be confusing. Also, there are ways to step into a function without actually using the `step` command itself such as using the less known `advance` command.
|
||||
|
||||
### No debugging symbols
|
||||
|
||||
Consider a simple example program:
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
|
||||
int num() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
void bar(int i) {
|
||||
printf("i = %d\n", i);
|
||||
}
|
||||
|
||||
int main() {
|
||||
bar(num());
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
If you compile without the debugging symbols first, set a breakpoint on `bar` and then try to step within it. The GDB gives an error message about no line number information:
|
||||
|
||||
```
|
||||
gcc exmp.c -o exmp
|
||||
gdb ./exmp
|
||||
(gdb) b bar
|
||||
Breakpoint 1 at 0x401135
|
||||
(gdb) r
|
||||
Starting program: /home/ahajkova/exmp
|
||||
Breakpoint 1, 0x0000000000401135 in bar ()
|
||||
(gdb) step
|
||||
Single stepping until exit from function bar,
|
||||
which has no line number information.
|
||||
i = 2
|
||||
0x0000000000401168 in main ()
|
||||
```
|
||||
|
||||
### Stepi
|
||||
|
||||
It is still possible to step inside the function that has no line number information but the `stepi` command should be used instead. Stepi executes just one instruction at a time. When using GDB's `stepi` command, it's often useful to first do `display/i $pc`. This causes the program counter value and corresponding machine instruction to be displayed after each step:
|
||||
|
||||
```
|
||||
(gdb) b bar
|
||||
Breakpoint 1 at 0x401135
|
||||
(gdb) r
|
||||
Starting program: /home/ahajkova/exmp
|
||||
Breakpoint 1, 0x0000000000401135 in bar ()
|
||||
(gdb) display/i $pc
|
||||
1: x/i $pc
|
||||
=> 0x401135 <bar+4>: sub $0x10,%rsp
|
||||
```
|
||||
|
||||
In the above `display` command, the `i` stands for machine instructions and `$pc` is the program counter register.
|
||||
|
||||
It can be useful to use info registers and print some register contents:
|
||||
|
||||
```
|
||||
(gdb) info registers
|
||||
rax 0x2 2
|
||||
rbx 0x7fffffffdbc8 140737488346056
|
||||
rcx 0x403e18 4210200
|
||||
(gdb) print $rax
|
||||
$1 = 2
|
||||
(gdb) stepi
|
||||
0x0000000000401139 in bar ()
|
||||
1: x/i $pc
|
||||
=> 0x401139 <bar+8>: mov %edi,-0x4(%rbp)
|
||||
```
|
||||
|
||||
### Complicated function call
|
||||
|
||||
After recompiling the example program with debugging symbols you can set the breakpoint on the `bar` call in main using its line number and then try to step into `bar` again:
|
||||
|
||||
```
|
||||
gcc -g exmp.c -o exmp
|
||||
gdb ./exmp
|
||||
(gdb) b exmp.c:14
|
||||
Breakpoint 1 at 0x401157: file exmp.c, line 14.
|
||||
(gdb) r
|
||||
Starting program: /home/ahajkova/exmp
|
||||
Breakpoint 1, main () at exmp.c:14
|
||||
14 bar(num());
|
||||
```
|
||||
|
||||
Now, let's step into`bar()`:
|
||||
|
||||
```
|
||||
(gdb) step
|
||||
num () at exmp.c:4
|
||||
4 return 2;
|
||||
```
|
||||
|
||||
The arguments for a function call need to be processed before the actual function call, so `num()` is expected to execute before `bar()`is called. But how do you step into the `bar` as was desired? You need to use the `finish` command and `step` again:
|
||||
|
||||
```
|
||||
(gdb) finish
|
||||
Run till exit from #0 num () at exmp.c:4
|
||||
0x0000000000401161 in main () at exmp.c:14
|
||||
14 bar(num());
|
||||
Value returned is $1 = 2
|
||||
(gdb) step
|
||||
bar (i=2) at exmp.c:9
|
||||
9 printf("i = %d\n", i);
|
||||
```
|
||||
|
||||
### Tbreak
|
||||
|
||||
The `tbreak` command sets a temporary breakpoint. It's useful for situations where you don't want to set a permanent breakpoint. For example, if you want to step into a complicated function call like `f(g(h()), i(j()), ...)` , in such a case you need a long sequence of `step/finish/step` to step into `f` . Setting a temporary breakpoint and then using continue can help to avoid using such sequences. To demonstrate this, you need to set the breakpoint to the `bar` call in `main` as before. Then set the temporary breakpoint on `bar`. As a temporary breakpoint it is automatically removed after being hit:
|
||||
|
||||
```
|
||||
(gdb) r
|
||||
Starting program: /home/ahajkova/exmp
|
||||
Breakpoint 1, main () at exmp.c:14
|
||||
14 bar(num());
|
||||
(gdb) tbreak bar
|
||||
Temporary breakpoint 2 at 0x40113c: file exmp.c, line 9.
|
||||
```
|
||||
|
||||
After hitting the breakpoint on the call to `bar` and setting a temporary breakpoint on `bar`, you just need to continue to end up in `bar`.
|
||||
|
||||
```
|
||||
(gdb) continue
|
||||
Continuing.
|
||||
Temporary breakpoint 2, bar (i=2) at exmp.c:9
|
||||
9 printf("i = %d\n", i);
|
||||
```
|
||||
|
||||
### Disable command
|
||||
|
||||
Alternatively, you could set a normal breakpoint on `bar` , continue, and then disable this second breakpoint when it's no longer needed. This way you can achieve the same results as with the `tbreak` with one extra command:
|
||||
|
||||
```
|
||||
(gdb) b exmp.c:14
|
||||
Breakpoint 1 at 0x401157: file exmp.c, line 14.
|
||||
(gdb) r
|
||||
Starting program: /home/ahajkova/exmp
|
||||
Breakpoint 1, main () at exmp.c:14
|
||||
14 bar(num());
|
||||
(gdb) b bar
|
||||
Breakpoint 2 at 0x40113c: file exmp.c, line 9.
|
||||
(gdb) c
|
||||
Continuing.
|
||||
Breakpoint 2, bar (i=2) at exmp.c:9
|
||||
9 printf("i = %d\n", i);
|
||||
(gdb) disable 2
|
||||
```
|
||||
|
||||
As you can see, the `info breakpoints` command displays `n` under `Enb`which means it’s disabled but you can enable it later if it’s needed again.
|
||||
|
||||
```
|
||||
(gdb) info breakpoints
|
||||
Num Type Disp Enb Address What
|
||||
1 breakpoint keep y 0x0000000000401157 in main at exmp.c:14
|
||||
breakpoint already hit 1 time
|
||||
2 breakpoint keep n 0x000000000040113c in bar at exmp.c:9
|
||||
breakpoint already hit 1 time
|
||||
(gdb) enable 2
|
||||
(gdb) info breakpoints
|
||||
Num Type Disp Enb Address What
|
||||
1 breakpoint keep y 0x000000000040116a in main at exmp.c:19
|
||||
breakpoint already hit 1 time
|
||||
2 breakpoint keep y 0x0000000000401158 in bar at exmp.c:14
|
||||
breakpoint already hit 1 time
|
||||
```
|
||||
|
||||
### Advance location
|
||||
|
||||
Another option you can use is an `advance` command. Instead of `tbreak bar ; continue` , you can simply do `advance bar` . This command continues running the program up to the given location.
|
||||
|
||||
The other cool thing about `advance` is that if the location that you try to advance to is not reached, GDB will stop after the current frame's function finishes. Thus, execution of the program is constrained:
|
||||
|
||||
```
|
||||
Breakpoint 1 at 0x401157: file exmp.c, line 14.
|
||||
(gdb) r
|
||||
Starting program: /home/ahajkova/exmp
|
||||
Breakpoint 1, main () at exmp.c:14
|
||||
14 bar(num());
|
||||
(gdb) advance bar
|
||||
bar (i=2) at exmp.c:9
|
||||
9 printf("i = %d\n", i);
|
||||
```
|
||||
|
||||
### Skipping a function
|
||||
|
||||
Yet another way to step into the `bar,` avoiding `num`, is using the `skip` command:
|
||||
|
||||
```
|
||||
(gdb) b exmp.c:14
|
||||
Breakpoint 1 at 0x401157: file exmp.c, line 14.
|
||||
(gdb) skip num
|
||||
Function num will be skipped when stepping.
|
||||
(gdb) r
|
||||
Starting program: /home/ahajkova/exmp
|
||||
Breakpoint 1, main () at exmp.c:14
|
||||
14 bar(num());
|
||||
(gdb) step
|
||||
bar (i=2) at exmp.c:9
|
||||
9 printf("i = %d\n", i);
|
||||
```
|
||||
|
||||
To know which functions are currently skipped, `info skip` is used. The `num` function is marked as enabled to be skipped by `y`:
|
||||
|
||||
```
|
||||
(gdb) info skip
|
||||
Num Enb Glob File RE Function
|
||||
1 y n <none> n num
|
||||
```
|
||||
|
||||
If `skip` is not needed any more it can be disabled (and re-enabled later) or deleted altogether. You can add another `skip` and disable the first one and then delete them all. To disable a certain `skip`, its number has to be specified, if not specified, each `skip`is disabled. It works the same for enabling or deleting a `skip`:
|
||||
|
||||
```
|
||||
(gdb) skip bar
|
||||
(gdb) skip disable 1
|
||||
(gdb) info skip
|
||||
Num Enb Glob File RE Function
|
||||
1 n n <none> n num
|
||||
2 y n <none> n bar
|
||||
(gdb) skip delete
|
||||
(gdb) info skip
|
||||
Not skipping any files or functions.
|
||||
```
|
||||
|
||||
### GDB step command
|
||||
|
||||
Using GDB's `step` command is a useful tool for debugging your application. There are several ways to step into even complicated functions, so give these GDB techniques a try next time you're troubleshooting your code.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/22/12/gdb-step-command
|
||||
|
||||
作者:[Alexandra][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/ahajkova
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://opensource.com/article/21/3/debug-code-gdb
|
||||
@@ -0,0 +1,173 @@
|
||||
[#]: subject: "Our favorite markup languages for documentation"
|
||||
[#]: via: "https://opensource.com/article/22/12/markup-languages-documentation"
|
||||
[#]: author: "Opensource.com https://opensource.com/users/admin"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: " "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Our favorite markup languages for documentation
|
||||
======
|
||||
|
||||
Documentation is important for so many reasons. Readable documentation is even more so. In the world of open source software, documentation is how to use or contribute to an application. It's like the rulebook for a [game][1].
|
||||
|
||||
There are many different types of documentation:
|
||||
|
||||
- Tutorials
|
||||
- How-to guides
|
||||
- Reference guides
|
||||
- Software architecture
|
||||
- Product manuals
|
||||
|
||||
We asked some of the Opensource.com contributors about their technical documentation workflow, which markup language they preferred, and why they might use one over the other. Here's what they had to say.
|
||||
|
||||
### AsciiDoc
|
||||
|
||||
For the past several years, [Markdown][2] has been my standard language. But recently I decided to give [AsciiDoc][3] a try. The syntax is not difficult and [Gedit][4] on my Linux desktop supports it. I plan to stick with it for a while.
|
||||
|
||||
—- [Alan Formy-Duval][5]
|
||||
|
||||
In terms of low-syntax markup, I prefer AsciiDoc. I like it because its conversion process is consistent and predictable, with no surprise "flavor" variations to confuse things. I also love that it outputs to [Docbook][6], which is a markup-heavy syntax that I trust for longevity and flexibility.
|
||||
|
||||
But the "right" choice tends to be what a project is already using. I wouldn't write in AsciiDoc if a project uses Strawberry-flavored Markdown. Well, to be fair, I might write in AsciiDoc and then convert it to Strawberry-flavored Markdown with Pandoc.
|
||||
|
||||
I do think there is a time and place for Markdown. I do find it more readable than AsciiDoc. Links in AsciiDoc:
|
||||
|
||||
```
|
||||
http://example.com[Example website]
|
||||
```
|
||||
|
||||
Links in Markdown:
|
||||
|
||||
```
|
||||
[Example.com](http://example.com)
|
||||
```
|
||||
|
||||
The Markdown syntax is intuitive, delivering the information in the same way that I think most of us parse the same data when reading HTML ("Example website…oh, that's blue text, I'll roll over it to see where it goes…it goes to [example.com][7]").
|
||||
|
||||
In other words, when my audience is a human reader, I do often choose Markdown because its syntax is subtle but it's got enough of a syntax to make conversion possible, so it's still an OK storage format.
|
||||
|
||||
AsciiDoc, as minimal as it is, just looks scarier.
|
||||
|
||||
If my audience is a computer that's going to parse a file, I choose AsciiDoc.
|
||||
|
||||
—- [Seth Kenlon][8]
|
||||
|
||||
### reStructuredText
|
||||
|
||||
I'm a big fan of [docs as code][9] and how it brings developer tools into the content workflows. It makes it easier to have efficient reviews and collaboration, especially if engineers are contributors.
|
||||
|
||||
I'm also a bit of a markup connoisseur, having written whole books in AsciiDoc for O'Reilly, a lot of Markdown for various platforms, including a thousand posts on my blog. Currently, I'm a [reStructuredText][10] convert and maintain some of the tooling in that space.
|
||||
|
||||
—- [Lorna Mitchell][11]
|
||||
|
||||
Obligatory mention of reStructuredText. That's my go-to these days as I do a lot of Python programming. It's also been Python's standard for documentation source and code comments for ages.
|
||||
|
||||
I like that it doesn't suffer quite so much from the proliferation of nonstandards that Markdown does. That said, I do use a lot of Sphinx features and extensions when working on more complex documentation.
|
||||
|
||||
—- [Jeremy Stanley][12]
|
||||
|
||||
### HTML
|
||||
|
||||
I rarely use markup languages if I don't have to.
|
||||
|
||||
I find HTML easier to use than other markup languages though.
|
||||
|
||||
—- [Rikard Grossman-Nielsen][13]
|
||||
|
||||
For me, there are various ways to make documentation. It depends on where the documentation is going to be whether on a website, as part of the software package, or something downloadable.
|
||||
|
||||
For [Scribus][14], the internal documentation is in HTML, since an internal browser is used to access it. On a website, you might need to use a Wiki language. For something downloadable you might create a PDF or an EPUB.
|
||||
|
||||
I tend to write the documentation in a plain text editor. I might use XHTML, so that I can then import these files into an EPUB maker like Sigil. And, of course, Scribus is my go-to app for making a PDF, though I would probably be importing a text file created with a text editor. Scribus has the advantage of including and precisely controlling placement of graphics.
|
||||
|
||||
Markdown has never caught on with me, and I've never tried AsciiDoc.
|
||||
|
||||
—- [Greg Pittman][15]
|
||||
|
||||
I'm writing a lot of documentation in HTML right now, so I'll put in a plug for HTML. You can use HTML to create websites, or to create documentation. Note that the two are not really the same — when you're creating websites, most designers are concerned about presentation. But when you're writing documentation, tech writers should focus on content.
|
||||
|
||||
When I write documentation in HTML, I stick to the tags and elements defined by HTML, and I don't worry about how it will look. In other words, I write documentation in "unstyled" HTML. I can always add a stylesheet later. So if I need to make some part of the text stronger (such as a warning) or add emphasis to a word or phrase, I might use the `<strong>` and `<em>` tags, like this:
|
||||
|
||||
```
|
||||
<p><strong>Warning: Lasers!</strong> Do <em>not</em> look into laser with remaining eye.</p>
|
||||
```
|
||||
|
||||
Or to provide a short code sample within the body of a paragraph, I might write:
|
||||
|
||||
```
|
||||
<p>The <code>puts</code> function prints some text to the user.</p>
|
||||
```
|
||||
|
||||
To format a block of code in a document, I use `<pre><code>..</code></pre>` like this:
|
||||
|
||||
```
|
||||
void
|
||||
print_array(int *array, int size)
|
||||
{
|
||||
for (int i = 0; i < size; i++) {
|
||||
printf("array[%d] = %d\n", i, array[i]);
|
||||
}}
|
||||
```
|
||||
|
||||
The great thing about HTML is you can immediately view the results with any web browser. And any documentation you write in unstyled HTML can be made prettier later by adding a stylesheet.
|
||||
|
||||
—- [Jim Hall][16]
|
||||
|
||||
### Unexpected: LibreOffice
|
||||
|
||||
Back in the 80s and 90s when I worked in System V Unix, SunOS, and eventually Solaris, I used the mm macros with `nroff,``troff` and finally `groff`. Read about MM using groff_mm (provided you have them installed.)
|
||||
|
||||
MM isn't really a markup language, but it feels like one. It is a very semantic set of troff and groff macros. It has most things markup language users would expect—headings, numbered lists, and so on.
|
||||
|
||||
My first Unix machine also had Writers' Workbench available on it, which was a boon for many in our organization who had to write technical reports but didn't particularly write in an "engaging manner". A few of its tools have made it to either BSD or Linux—style, diction, and look.
|
||||
|
||||
I also recall a standard generalized markup language (SGML) tool that came with, or perhaps we bought for, Solaris in the very early 90s. I used this for awhile, which may explain why I don't mind typing in my own HTML.
|
||||
|
||||
I've used Markdown a fair bit, but having said that, I should also be saying "which Markdown", because there are endless flavors and levels of features. I'm not a huge fan of Markdown because of that. I guess if I had a lot of Markdown to do I would probably try to gravitate toward some implementation of [CommonMark][17] because it actually has a formal definition. For example, [Pandoc][18] supports CommonMark (as well as several others).
|
||||
|
||||
I started using AsciiDoc, which I much prefer to Markdown as it avoids the "which version are you using" conversation and provides many useful things. What has slowed me down in the past with respect to AsciiDoc is that for some time it seemed to require installing Asciidoctor—a Ruby toolchain which I was not anxious to install. But these days there are more implementations at least in my Linux distro. Curiously, Pandoc emits AsciiDoc but does not read it.
|
||||
|
||||
Those of you laughing at me for not wanting a Ruby toolchain for AsciiDoc but being satisfied with a Haskell toolchain for Pandoc… I hear you.
|
||||
|
||||
I blush to admit that I mostly use LibreOffice these days.
|
||||
|
||||
—- [Chris Hermansen][19]
|
||||
|
||||
### Document now!
|
||||
|
||||
Documentation can be achieved through many different avenues, as the writers here have demonstrated. It's important to document how to use your code, especially in open source. This ensures that other people can use and contribute to your code properly. It's also wise to tell future users what your code is providing.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/22/12/markup-languages-documentation
|
||||
|
||||
作者:[Opensource.com][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/admin
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://opensource.comttps://opensource.com/life/16/11/software-documentation-tabletop-gaming
|
||||
[2]: https://opensource.com/article/19/9/introduction-markdown
|
||||
[3]: https://opensource.com/article/22/8/drop-markdown-asciidoc
|
||||
[4]: https://opensource.com/%20https%3A//opensource.com/article/20/12/gedit
|
||||
[5]: https://opensource.com/users/alanfdoss
|
||||
[6]: https://opensource.com/article/17/9/docboo
|
||||
[7]: http://example.com/
|
||||
[8]: https://opensource.com/users/seth
|
||||
[9]: https://opensource.com/article/22/10/docs-as-code
|
||||
[10]: https://opensource.com/article/19/11/document-python-sphinx
|
||||
[11]: https://opensource.com/users/lornajane
|
||||
[12]: https://opensource.com/users/fungi
|
||||
[13]: https://opensource.com/users/rikardgn
|
||||
[14]: https://opensource.com/article/21/12/desktop-publishing-scribus
|
||||
[15]: https://opensource.com/users/greg-p
|
||||
[16]: https://opensource.com/users/jim-hall
|
||||
[17]: https://commonmark.org/
|
||||
[18]: https://opensource.com/downloads/pandoc-cheat-sheet
|
||||
[19]: https://opensource.com/users/clhermansen
|
||||
@@ -0,0 +1,150 @@
|
||||
[#]: subject: "Manage your file system from the Linux terminal"
|
||||
[#]: via: "https://opensource.com/article/22/12/linux-file-manager-nnn"
|
||||
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: " "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Manage your file system from the Linux terminal
|
||||
======
|
||||
|
||||
I tend to enjoy lightweight applications. They're good for [low spec computers][1], for [remote shells][2], for the impatient user (OK, I admit, that's me), and for the systems we scrap together to fight the inevitable [zombie apocalypse][3]. In my search for a perfect blend of a lightweight application with all the modern conveniences we've learned from experience, I stumbled across a file manager called **nnn**. The nnn file manager exists in a terminal only, but it feels like a modern keyboard-driven application with intuitive actions and easy navigation.
|
||||
|
||||
![Image of the nnn file manager.][4]
|
||||
|
||||
### Install nnn
|
||||
|
||||
On Linux, you may find nnn in your Linux distribution's software repository. For instance, on Debian:
|
||||
|
||||
```
|
||||
$ sudo apt install nnn
|
||||
```
|
||||
|
||||
If your repository doesn't have nnn available, you can download a package for your distribution from [OBS][5] or from the project [Git repository][6].
|
||||
|
||||
On macOS, use [Homebrew][7] or [MacPort][8].
|
||||
|
||||
### Using nnn
|
||||
|
||||
Launch nnn from a terminal:
|
||||
|
||||
```
|
||||
$ nnn
|
||||
```
|
||||
|
||||
Your terminal is now the nnn interface, and by default it lists the contents of your current directory:
|
||||
|
||||
```
|
||||
1 2 3 4 ~
|
||||
Desktop/
|
||||
Documents/
|
||||
Downloads/
|
||||
Music/
|
||||
Pictures/
|
||||
Public/
|
||||
Templates/
|
||||
Videos/4/8 2022-12-01 15:54 drwxr-xr-x 6B
|
||||
```
|
||||
|
||||
At the top of the nnn interface are tabs (called a "context" in nnn terminology), numbered one to four.
|
||||
|
||||
At the bottom of the nnn interface, there are ownership and permission details about your current selection.
|
||||
|
||||
Use either the **Up** and **Down** arrow keys or the **k** and **j** keys (as in [Vim][9]) to change your selection. Use the **Right** arrow key, **Return**, or the **l** key to enter a directory or to open a file. Use the **Left** arrow key or **h** to back out of a directory.
|
||||
|
||||
That's it for navigation. It's easier than any graphical file manager because there aren't any widgets that get in the way. There's no need to **Tab** over buttons, you just use the arrow keys or the QWERTY home row.
|
||||
|
||||
### Open a file
|
||||
|
||||
One of the reasons you use a file manager is to find a file and then open it. Your desktop already has default applications set, and nnn inherits this knowledge, so press `Return` or `Right` arrow to open a file in its default application.
|
||||
|
||||
Should you need to open a file in something other than its default application, press `=` instead, and then type the name of the application in the prompt at the bottom of the nnn interface.
|
||||
|
||||
### Copy a file
|
||||
|
||||
To copy a file or any number of files, you must first select a file to copy, then navigate to its intended destination, and finally invoke the copy command. Thanks to nnn's context control (those are the numbers at the top of the screen, and you can think of them as tabs in a web browser), this is a quick process.
|
||||
|
||||
- First, select the file you want to copy and press **Spacebar** to select the file. It's marked with a plus sign (**`+`**) to indicate its selected state.
|
||||
- Press **`2`** to change to a new context.
|
||||
- Navigate to the target directory and press **p** to copy.
|
||||
|
||||
### Move a file
|
||||
|
||||
Moving files is the same process as copying a file, but the keyboard shortcut for the action is **v**.
|
||||
|
||||
### Selecting files
|
||||
|
||||
There are a few ways to mark selections in nnn. The first is manual selection. You find a file you want to select, and then press **Spacebar** to mark it as selected. Press **Spacebar** again to deselect it.
|
||||
|
||||
One selection doesn't cancel another, so you can select several files manually, but that can become tedious. Another way to select many files at once is to "mark in " and "mark out". To mark a selection, press `m` on the first file you want to select, and then use your arrow keys to move to the last file you want to select. Press `m` again to close the selection:
|
||||
|
||||
```
|
||||
1 2 3 4 ~
|
||||
+Desktop/
|
||||
+Documents/
|
||||
+Downloads/
|
||||
+Music/
|
||||
+Pictures/
|
||||
+Public/
|
||||
Templates/
|
||||
Videos/6/8 [ +6 ] 2022-12-01 15:54 drwxr-xr-x 6B
|
||||
```
|
||||
|
||||
Finally, the third way to select files is to press `a` to _select all_. Use **`A`** to invert the selection (in this case, to _select none_.)
|
||||
|
||||
### Creating an archive
|
||||
|
||||
To create an archive of a file or a selection of files, press `z`. At the bottom of the nnn interface, you're prompted to choose between your current item of your selection. Then you're prompted for a file name. Luckily, nnn is a smart application and derives its file type from the name you provide. If you name your archive `example.tar.xz` then nnn creates a TAR archive with lzma compression, but if you name it `example.zip` then it creates a ZIP file.
|
||||
|
||||
You can verify the file type yourself by pressing the `f` key with your new archive selected:
|
||||
|
||||
```
|
||||
File: /home/tux/Downloads/example.zip
|
||||
Size: 184707 Blocks: 368 IO Block: 4096 regular file
|
||||
Device: fd00h/64768d Inode: 17842380 Links: 1
|
||||
Access: (0664/-rw-rw-r--) Uid: ( 1002/ tux) Gid: ( 1002/ tux)
|
||||
Context: unconfined_u:object_r:user_home_t:s0
|
||||
Access: 2022-09-20 15:12:09.770187616 +1200
|
||||
Modify: 2022-09-20 15:12:09.775187704 +1200
|
||||
Change: 2022-09-20 15:12:09.775187704 +1200
|
||||
Birth: 2022-09-20 15:12:09.770187616 +1200
|
||||
Zip archive data, at least v2.0 to extract
|
||||
application/zip; charset=binary
|
||||
```
|
||||
|
||||
### Cancel an action
|
||||
|
||||
When you find yourself backed into a corner and need to press a panic button, use the **`Esc`** key. (This is likely to be the single most confusing keyboard shortcut for a longtime terminal user who's accustomed to **Ctrl+C**.)
|
||||
|
||||
### Never close nnn
|
||||
|
||||
To quit nnn, press **`Q`** at any time.
|
||||
|
||||
It's a very capable file manager, with functions for symlinks, FIFO, bookmarks, batch renaming, and more. For a full list of what nnn can do, press the **`?`** key.
|
||||
|
||||
The most clever feature is the shell function. Press **`!`** to open a shell over the nnn interface. You'll forget nnn is there, until you type `exit` and you find yourself back in the nnn interface. It's that easy to leave nnn open all the time, so you can always have quick access to the fastest lightweight file management you're likely to experience.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/22/12/linux-file-manager-nnn
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://opensource.com/article/19/7/how-make-old-computer-useful-again
|
||||
[2]: https://www.redhat.com/sysadmin/access-remote-systems-ssh
|
||||
[3]: https://opensource.com/zombie
|
||||
[4]: https://opensource.com/sites/default/files/2022-10/nnn.filemanager.png
|
||||
[5]: https://software.opensuse.org//download.html?project=home%3Astig124%3Annn&package=nnn
|
||||
[6]: https://github.com/jarun/nnn/releases
|
||||
[7]: https://opensource.com/article/20/6/homebrew-mac
|
||||
[8]: https://opensource.com/article/20/11/macports
|
||||
[9]: https://opensource.com/article/19/3/getting-started-vim
|
||||
@@ -1,157 +0,0 @@
|
||||
[#]: subject: "Doing 64-bit math on a 16-bit system"
|
||||
[#]: via: "https://opensource.com/article/22/10/64-bit-math"
|
||||
[#]: author: "Jerome Shidel https://opensource.com/users/shidel"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "yzuowei "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
在16位系统上做64位数学
|
||||
======
|
||||
|
||||
只需要一点点汇编的基础理解,这些函数就能适应体任意大小的整型数学运算。
|
||||
|
||||
几年前,我为 FreeDOS 写了一个命令行数学程序叫做 VMATH。它可以在很小的无符号整型上执行十分简单的数学运算。出于近来对 FreeDOS 社区里基本数学的兴趣,我改进了 VMATH 使其可以为有符号64位整型提供基本的数学支持。
|
||||
|
||||
仅使用兼容16位 8086 的汇编来操控大型数字的过程并不直接。我希望能够分享一些在 VMATH 中用到的技术的例子。其中一些方法掌握起来还挺容易。同时,也有着别的看起来有点奇怪的方法。你甚至可能学到一种全新的进行基本数学运算的方式。
|
||||
|
||||
接下来要讲的加,减,乘,除会用到的技术将不局限于将不局限于64位整型。只需要一点点汇编的基础理解,这些函数就能适应任意大小的整型数学运算。
|
||||
|
||||
在深挖这些数学函数前,我想要覆盖一些计算机看数字的基础视角。
|
||||
|
||||
### 计算机是如何读取数字的
|
||||
|
||||
一个兼容 Intel 的 CPU 以字节 (byte) 的形式贮存数字,储存顺序为从最低有效字节到最高有效字节。每个字节由8个二进位组成,两个字节组成一个字 (word)。
|
||||
|
||||
一个储存在内存里的64位整型占用了8个字节 (或4个字)。例如,数字74565(十六进制表示为0x12345)的值长得是这个样子的:
|
||||
|
||||
```
|
||||
as bytes: db 0x45, 0x23, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
as words: dw 0x2345, 0x0001, 0x0000, 0x0000
|
||||
```
|
||||
|
||||
当读取或写入数据到内存时,CPU 会以正确的顺序处理这些字节。对于一个比 8086 更现代的处理器而言,数据组可以再大些,比如一个四字组就可以表达整个64为整型为 **0x0000000000012345**。
|
||||
|
||||
8086 CPU 不能理解这么大的数字。当为 FreeDOS 编程时,你想要写的是一个能在任意电脑上跑的程序,甚至是早期的 IBM PC 5150。你想要使用能够适应任意大小整型的技术。我们并不关心现代 CPU 的能力。
|
||||
|
||||
为了能做整型运算,我们的数据需要表达两种不同类型的数字。
|
||||
|
||||
第一种是无符号整型,其使用了所有字位来表达一个正数。无符号整型的值域为从 **0** 到 **(2 ^ (字位数量) - 1)**。例如,8位数可以是 **0** 到 **255** 之间的任意值,而16位数则在 **0** 到
|
||||
**65535** 之间,以此类推。
|
||||
|
||||
有符号整型也很类似。不同之处在于数字的最显著位代表了这个数是一个整数 (**0**) 还是一个负数 (**1**)。有符号整型的值域前半部分位正数,正数值域是从 **0** 到 **(2 ^ (字位数量 - 1) - 1)**。整型值域的后半部分为负数,负数值域则从 **(0-(2 ^ (字位数量 - 1)))** 到 **-1**。
|
||||
|
||||
比如说,一个8位数代表着 **0** 到 **127** 之间的任意正数,以及 **-128** 到 **-1** 之间的任意负数。为了能更好的理解这一点,想象 **字节** 为一列数组 **[0...127,-128...-1]**。因为 **-128** 在数组内紧跟着 **127**,**127** 加 **1** 等于 **-128**。当然这可能看起来有点奇怪甚至反常,但这其实让这个层级的基本数学运算变简单了。
|
||||
|
||||
为了能够对大型整型进行简单的加,减,乘,除,你应该摸索一些简单的公式来计算一个数的绝对值或负值。你在做有符号整型运算的时候会用上它们的。
|
||||
|
||||
|
||||
### 绝对值与负值
|
||||
|
||||
计算一个有符号整型的绝对值并没有它看起来的那么糟糕。由于无符号和有符号数字在内存里的储存形式,我们其实有一个简单的方案。你只需要翻转一个负数的所有字位,得出的结果再加 **1**。
|
||||
|
||||
如果你从没接触过二进制的话这可能听上去有点奇怪,但这就是这么工作的。让我们来举一个例子,取一个负数的8位表达,比如说 **-5**。因为 **-5** 靠近 **[0...127,-128...-1]** 字节组末端,它的十六进制值为 **0xfb**,二进制值为 **11111011**。如果你翻转了所有字位,你会得到 **0x04** 或二进制值 **00000100**。结果加 **1** 你就得到了你的答案。你刚刚把 **-5** 的值变成了 **+5**。
|
||||
|
||||
你可以用汇编写下这个程序用以返回任意64位数字的绝对值:
|
||||
|
||||
```
|
||||
; 语法,NASM for DOS
|
||||
proc_ABS:
|
||||
; 启动时,SI寄存器会指向数据段 (DS) 内的内存位置,那里存放着程序内包含着
|
||||
; 会被转正的64位数。
|
||||
; 结束时,如果结果数字不能被转正,Carry Flag (CF) 会被设置。这种情况只
|
||||
; 有在遇到最大负值时会发生。其余情况,CF 不会被设置。
|
||||
|
||||
; 检查最高字节的最高位
|
||||
test [si+7], byte 0x80
|
||||
; 如不为1,值为正值
|
||||
jz .done_ABS
|
||||
; 翻转字的所有字位 #4
|
||||
not word [si+6]
|
||||
not word [si+4] ; 字 #3
|
||||
not word [si+2] ; 字 #2
|
||||
not word [si] ; 字 #1
|
||||
; 字#1 加一
|
||||
inc word [si]
|
||||
; 如结果不为0,结束
|
||||
jnz .done_ABS
|
||||
; 字#2 加一
|
||||
inc word [si+2]
|
||||
; 如结果为0,进位下一个字
|
||||
jnz .done_ABS
|
||||
inc word [si+4]
|
||||
jnz .done_ABS
|
||||
; 此处无法进位
|
||||
inc word [si+6]
|
||||
; 再一次检查最高位
|
||||
test [si+7], byte 0x80
|
||||
; 如不为1,我们成功了,结束
|
||||
jz .done_ABS
|
||||
; 溢出错误,它被转成了负数
|
||||
stc
|
||||
; 设置 Carry Flag 并返回
|
||||
ret
|
||||
.done_ABS:
|
||||
; 成功,清理 Carry Flag 并返回
|
||||
clc
|
||||
ret
|
||||
```
|
||||
|
||||
你可能已经注意到了,这个函数有一个潜在问题。由于正负数的二进制值表达方式,最大负数无法被转成正数。以8位数为例,最大负数是 **-128**。如果你翻转了 **-128** 的所有位数 (二进制1__0000000),你会得到127 (二进制0__1111111) 即最大正值。如果你对结果加 **1**,它会因溢出回到同样的负数 (-128)。
|
||||
|
||||
你只需要重复计算绝对值的步骤就可以将正数转成负数。以下的程序十分相似,你唯一需要确认的就是一开始的数字不是已经负了。
|
||||
|
||||
```
|
||||
; 语法, NASM for DOS
|
||||
proc_NEG:
|
||||
; 开始时,SI会指向需要转负的数字在内存里的位置。
|
||||
; 结束时,Carry Flag永远不会被设置。
|
||||
|
||||
; 检查最高字节的最高位
|
||||
test [si+7], byte 0x80
|
||||
; 如为1,数已经是负数
|
||||
jnz .done_NEG
|
||||
not word [si+6] ; 翻转字的所有字位 #4
|
||||
not word [si+4] ; 字 #3
|
||||
not word [si+2] ; 字 #2
|
||||
not word [si] ; 字 #1
|
||||
inc word [si] ; 字#1 加一
|
||||
; 如结果不为0,结束
|
||||
jnz .done_NEG
|
||||
; 字#2 加一
|
||||
inc word [si+2]
|
||||
; 如结果为0,进位下一个字
|
||||
jnz .done_NEG
|
||||
inc word [si+4]
|
||||
jnz .done_NEG
|
||||
; 此处无法进位或转化
|
||||
inc word [si+6]
|
||||
; 正。
|
||||
.done_NEG:
|
||||
clc ; 成功,清理 Carry Flag 并返回
|
||||
ret
|
||||
```
|
||||
|
||||
看着这些绝对值与负值函数间的通用代码,它们应该被结合起来来节约一些字节。结合代码也会带来额外的好处。首先,结合代码能帮助防止简单的笔误。这样也可以减少测试的要求。进一步来讲,这样通常会让代码变得简单易懂。在阅读一长串的汇编指令时,忘记读到哪是常有的事。现在,我们可以不管这些。
|
||||
|
||||
计算一个数的绝对值或负值并不难。但是,这些函数对于我们即将开始的有符号整型数学运算至关重要。
|
||||
|
||||
我已经覆盖了整型数字在字位层的表达的基础,也创造了可以改变这些数字的基本程序,现在我们可以做点有趣的了。
|
||||
|
||||
让我们来做些数学吧!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/22/10/64-bit-math
|
||||
|
||||
作者:[Jerome Shidel][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[yzuowei](https://github.com/yzuowei)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/shidel
|
||||
[b]: https://github.com/lkxed
|
||||
|
||||
Reference in New Issue
Block a user