Note

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

Help:Funtoo Editing Guidelines/Source Code

From Funtoo
Jump to navigation Jump to search

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.