注意:
The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Difference between revisions of "Help:Funtoo Editing Guidelines/Source Code"
Jump to navigation
Jump to search
(Created page with "=== Displaying Source Code === To display source code, use can use the file template, specifying a <tt>lang=</tt> parameter: <pre> {{file|name=foobar|lang=python|desc=foobar...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
To display source code, use can use the file template, specifying a <tt>lang=</tt> parameter: | To display source code, use can use the file template, specifying a <tt>lang=</tt> parameter: | ||
< | {{file|name=source code wikitext example|body=<nowiki> | ||
{{file|name= | {{file|name=qemu-arm-wrapper.c|lang=C|desc=qemu arm wrapper|body= | ||
/* | |||
* Call QEMU binary with additional "-cpu cortex-a7" argument. | |||
* | |||
* Copyright (c) 2018 sakaki <sakaki@deciban.com> | |||
* License: GPL v3.0+ | |||
* | |||
* Based on code from the Gentoo Embedded Handbook | |||
* ("General/Compiling_with_qemu_user_chroot") | |||
*/ | |||
#include <string.h> | |||
#include <unistd.h> | |||
int main(int argc, char **argv, char **envp) { | |||
char *newargv[argc + 3]; | |||
newargv[0] = argv[0]; | |||
newargv[1] = "-cpu"; | |||
newargv[2] = "cortex-a7"; | |||
memcpy(&newargv[3], &argv[1], sizeof(*argv) * (argc -1)); | |||
newargv[argc + 2] = NULL; | |||
return execve("/usr/local/bin/qemu-arm", newargv, envp); | |||
} | |||
}} | }} | ||
</ | </nowiki>}} | ||
This will produce: | This will produce: | ||
{{file|name= | {{file|name=qemu-arm-wrapper.c|lang=C|desc=qemu arm wrapper|body= | ||
/* | |||
* Call QEMU binary with additional "-cpu cortex-a7" argument. | |||
* | |||
* Copyright (c) 2018 sakaki <sakaki@deciban.com> | |||
* License: GPL v3.0+ | |||
* | |||
* Based on code from the Gentoo Embedded Handbook | |||
* ("General/Compiling_with_qemu_user_chroot") | |||
*/ | |||
#include <string.h> | |||
#include <unistd.h> | |||
int main(int argc, char **argv, char **envp) { | |||
char *newargv[argc + 3]; | |||
newargv[0] = argv[0]; | |||
newargv[1] = "-cpu"; | |||
newargv[2] = "cortex-a7"; | |||
memcpy(&newargv[3], &argv[1], sizeof(*argv) * (argc -1)); | |||
newargv[argc + 2] = NULL; | |||
return execve("/usr/local/bin/qemu-arm", newargv, envp); | |||
} | |||
}} | }} | ||
Latest revision as of 01:18, July 24, 2019
Displaying Source Code
To display source code, use can use the file template, specifying a lang= parameter:
source code wikitext example
{{file|name=qemu-arm-wrapper.c|lang=C|desc=qemu arm wrapper|body=
/*
* Call QEMU binary with additional "-cpu cortex-a7" argument.
*
* Copyright (c) 2018 sakaki <sakaki@deciban.com>
* License: GPL v3.0+
*
* Based on code from the Gentoo Embedded Handbook
* ("General/Compiling_with_qemu_user_chroot")
*/
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv, char **envp) {
char *newargv[argc + 3];
newargv[0] = argv[0];
newargv[1] = "-cpu";
newargv[2] = "cortex-a7";
memcpy(&newargv[3], &argv[1], sizeof(*argv) * (argc -1));
newargv[argc + 2] = NULL;
return execve("/usr/local/bin/qemu-arm", newargv, envp);
}
}}
This will produce:
qemu-arm-wrapper.c
(C source code) - qemu arm wrapper/*
* Call QEMU binary with additional "-cpu cortex-a7" argument.
*
* Copyright (c) 2018 sakaki <sakaki@deciban.com>
* License: GPL v3.0+
*
* Based on code from the Gentoo Embedded Handbook
* ("General/Compiling_with_qemu_user_chroot")
*/
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv, char **envp) {
char *newargv[argc + 3];
newargv[0] = argv[0];
newargv[1] = "-cpu";
newargv[2] = "cortex-a7";
memcpy(&newargv[3], &argv[1], sizeof(*argv) * (argc -1));
newargv[argc + 2] = NULL;
return execve("/usr/local/bin/qemu-arm", newargv, envp);
}
The parameters name
(filename), lang
(language for syntax highlighting) and desc
(Description, appearing as a caption) are optional. For a list of supported languages, see this list.
Important
If you need to display the pipe ("|") character within the body of a file template, replace each "|" with {{!}} -- otherwise your file contents will not display properly. This is necessary because {{file}} is a template and the "|" character is used as a delimiter for arguments to the template.