Experimental Linux GUI based on web browser

This commit is contained in:
longpanda 2021-02-26 21:36:53 +08:00
parent 7279ba9bc8
commit 43e8ec5785
158 changed files with 43670 additions and 0 deletions

View file

@ -0,0 +1,96 @@
/*
* Test application for xz_boot.c
*
* Author: Lasse Collin <lasse.collin@tukaani.org>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define STATIC static
#define INIT
static void error(/*const*/ char *msg)
{
fprintf(stderr, "%s\n", msg);
}
/* Disable the CRC64 support even if it was enabled in the Makefile. */
#undef XZ_USE_CRC64
#include "../linux/lib/decompress_unxz.c"
static uint8_t in[1024 * 1024];
static uint8_t out[1024 * 1024];
static int fill(void *buf, unsigned int size)
{
return fread(buf, 1, size, stdin);
}
static int flush(/*const*/ void *buf, unsigned int size)
{
return fwrite(buf, 1, size, stdout);
}
static void test_buf_to_buf(void)
{
size_t in_size;
int ret;
in_size = fread(in, 1, sizeof(in), stdin);
ret = decompress(in, in_size, NULL, NULL, out, NULL, &error);
/* fwrite(out, 1, FIXME, stdout); */
fprintf(stderr, "ret = %d\n", ret);
}
static void test_buf_to_cb(void)
{
size_t in_size;
int in_used;
int ret;
in_size = fread(in, 1, sizeof(in), stdin);
ret = decompress(in, in_size, NULL, &flush, NULL, &in_used, &error);
fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used);
}
static void test_cb_to_cb(void)
{
int ret;
ret = decompress(NULL, 0, &fill, &flush, NULL, NULL, &error);
fprintf(stderr, "ret = %d\n", ret);
}
/*
* Not used by Linux <= 2.6.37-rc4 and newer probably won't use it either,
* but this kind of use case is still required to be supported by the API.
*/
static void test_cb_to_buf(void)
{
int in_used;
int ret;
ret = decompress(in, 0, &fill, NULL, out, &in_used, &error);
/* fwrite(out, 1, FIXME, stdout); */
fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used);
}
int main(int argc, char **argv)
{
if (argc != 2)
fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]);
else if (strcmp(argv[1], "bb") == 0)
test_buf_to_buf();
else if (strcmp(argv[1], "bc") == 0)
test_buf_to_cb();
else if (strcmp(argv[1], "cc") == 0)
test_cb_to_cb();
else if (strcmp(argv[1], "cb") == 0)
test_cb_to_buf();
else
fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]);
return 0;
}

View file

@ -0,0 +1,48 @@
/*
* Test application to test buffer-to-buffer decoding
*
* Author: Lasse Collin <lasse.collin@tukaani.org>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "xz.h"
#define BUFFER_SIZE (1024 * 1024)
static uint8_t in[BUFFER_SIZE];
static uint8_t out[BUFFER_SIZE];
int main(void)
{
struct xz_buf b;
struct xz_dec *s;
enum xz_ret ret;
xz_crc32_init();
s = xz_dec_init(XZ_SINGLE, 0);
if (s == NULL) {
fputs("Initialization failed", stderr);
return 1;
}
b.in = in;
b.in_pos = 0;
b.in_size = fread(in, 1, sizeof(in), stdin);
b.out = out;
b.out_pos = 0;
b.out_size = sizeof(out);
ret = xz_dec_run(s, &b);
xz_dec_end(s);
fwrite(out, 1, b.out_pos, stdout);
fprintf(stderr, "%d\n", ret);
return 0;
}

View file

@ -0,0 +1,135 @@
/*
* Lazy test for the case when the output size is known
*
* Author: Lasse Collin <lasse.collin@tukaani.org>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "xz.h"
static uint8_t in[1];
static uint8_t out[BUFSIZ];
int main(int argc, char **argv)
{
struct xz_buf b;
struct xz_dec *s;
enum xz_ret ret;
const char *msg;
size_t uncomp_size;
if (argc != 2) {
fputs("Give uncompressed size as the argument", stderr);
return 1;
}
uncomp_size = atoi(argv[1]);
xz_crc32_init();
/*
* Support up to 64 MiB dictionary. The actually needed memory
* is allocated once the headers have been parsed.
*/
s = xz_dec_init(XZ_DYNALLOC, 1 << 26);
if (s == NULL) {
msg = "Memory allocation failed\n";
goto error;
}
b.in = in;
b.in_pos = 0;
b.in_size = 0;
b.out = out;
b.out_pos = 0;
b.out_size = uncomp_size < BUFSIZ ? uncomp_size : BUFSIZ;
while (true) {
if (b.in_pos == b.in_size) {
b.in_size = fread(in, 1, sizeof(in), stdin);
b.in_pos = 0;
}
ret = xz_dec_run(s, &b);
if (b.out_pos == sizeof(out)) {
if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos) {
msg = "Write error\n";
goto error;
}
uncomp_size -= b.out_pos;
b.out_pos = 0;
b.out_size = uncomp_size < BUFSIZ
? uncomp_size : BUFSIZ;
}
if (ret == XZ_OK)
continue;
#ifdef XZ_DEC_ANY_CHECK
if (ret == XZ_UNSUPPORTED_CHECK) {
fputs(argv[0], stderr);
fputs(": ", stderr);
fputs("Unsupported check; not verifying "
"file integrity\n", stderr);
continue;
}
#endif
if (uncomp_size != b.out_pos) {
msg = "Uncompressed size doesn't match\n";
goto error;
}
if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos
|| fclose(stdout)) {
msg = "Write error\n";
goto error;
}
switch (ret) {
case XZ_STREAM_END:
xz_dec_end(s);
return 0;
case XZ_MEM_ERROR:
msg = "Memory allocation failed\n";
goto error;
case XZ_MEMLIMIT_ERROR:
msg = "Memory usage limit reached\n";
goto error;
case XZ_FORMAT_ERROR:
msg = "Not a .xz file\n";
goto error;
case XZ_OPTIONS_ERROR:
msg = "Unsupported options in the .xz headers\n";
goto error;
case XZ_DATA_ERROR:
case XZ_BUF_ERROR:
msg = "File is corrupt\n";
goto error;
default:
msg = "Bug!\n";
goto error;
}
}
error:
xz_dec_end(s);
fputs(argv[0], stderr);
fputs(": ", stderr);
fputs(msg, stderr);
return 1;
}

View file

@ -0,0 +1,124 @@
/*
* Private includes and definitions for userspace use of XZ Embedded
*
* Author: Lasse Collin <lasse.collin@tukaani.org>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#ifndef XZ_CONFIG_H
#define XZ_CONFIG_H
/* Uncomment to enable CRC64 support. */
/* #define XZ_USE_CRC64 */
/* Uncomment as needed to enable BCJ filter decoders. */
/* #define XZ_DEC_X86 */
/* #define XZ_DEC_POWERPC */
/* #define XZ_DEC_IA64 */
/* #define XZ_DEC_ARM */
/* #define XZ_DEC_ARMTHUMB */
/* #define XZ_DEC_SPARC */
/*
* MSVC doesn't support modern C but XZ Embedded is mostly C89
* so these are enough.
*/
#ifdef _MSC_VER
typedef unsigned char bool;
# define true 1
# define false 0
# define inline __inline
#else
# include <stdbool.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "xz.h"
#define kmalloc(size, flags) malloc(size)
#define kfree(ptr) free(ptr)
#define vmalloc(size) malloc(size)
#define vfree(ptr) free(ptr)
#define memeq(a, b, size) (memcmp(a, b, size) == 0)
#define memzero(buf, size) memset(buf, 0, size)
#ifndef min
# define min(x, y) ((x) < (y) ? (x) : (y))
#endif
#define min_t(type, x, y) min(x, y)
/*
* Some functions have been marked with __always_inline to keep the
* performance reasonable even when the compiler is optimizing for
* small code size. You may be able to save a few bytes by #defining
* __always_inline to plain inline, but don't complain if the code
* becomes slow.
*
* NOTE: System headers on GNU/Linux may #define this macro already,
* so if you want to change it, you need to #undef it first.
*/
#ifndef __always_inline
# ifdef __GNUC__
# define __always_inline \
inline __attribute__((__always_inline__))
# else
# define __always_inline inline
# endif
#endif
/* Inline functions to access unaligned unsigned 32-bit integers */
#ifndef get_unaligned_le32
static inline uint32_t get_unaligned_le32(const uint8_t *buf)
{
return (uint32_t)buf[0]
| ((uint32_t)buf[1] << 8)
| ((uint32_t)buf[2] << 16)
| ((uint32_t)buf[3] << 24);
}
#endif
#ifndef get_unaligned_be32
static inline uint32_t get_unaligned_be32(const uint8_t *buf)
{
return (uint32_t)(buf[0] << 24)
| ((uint32_t)buf[1] << 16)
| ((uint32_t)buf[2] << 8)
| (uint32_t)buf[3];
}
#endif
#ifndef put_unaligned_le32
static inline void put_unaligned_le32(uint32_t val, uint8_t *buf)
{
buf[0] = (uint8_t)val;
buf[1] = (uint8_t)(val >> 8);
buf[2] = (uint8_t)(val >> 16);
buf[3] = (uint8_t)(val >> 24);
}
#endif
#ifndef put_unaligned_be32
static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
{
buf[0] = (uint8_t)(val >> 24);
buf[1] = (uint8_t)(val >> 16);
buf[2] = (uint8_t)(val >> 8);
buf[3] = (uint8_t)val;
}
#endif
/*
* Use get_unaligned_le32() also for aligned access for simplicity. On
* little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
* could save a few bytes in code size.
*/
#ifndef get_le32
# define get_le32 get_unaligned_le32
#endif
#endif

View file

@ -0,0 +1,135 @@
/*
* Simple XZ decoder command line tool
*
* Author: Lasse Collin <lasse.collin@tukaani.org>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
/*
* This is really limited: Not all filters from .xz format are supported,
* only CRC32 is supported as the integrity check, and decoding of
* concatenated .xz streams is not supported. Thus, you may want to look
* at xzdec from XZ Utils if a few KiB bigger tool is not a problem.
*/
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "xz.h"
static uint8_t in[BUFSIZ];
static uint8_t out[BUFSIZ];
int main(int argc, char **argv)
{
struct xz_buf b;
struct xz_dec *s;
enum xz_ret ret;
const char *msg;
if (argc >= 2 && strcmp(argv[1], "--help") == 0) {
fputs("Uncompress a .xz file from stdin to stdout.\n"
"Arguments other than `--help' are ignored.\n",
stdout);
return 0;
}
xz_crc32_init();
#ifdef XZ_USE_CRC64
xz_crc64_init();
#endif
/*
* Support up to 64 MiB dictionary. The actually needed memory
* is allocated once the headers have been parsed.
*/
s = xz_dec_init(XZ_DYNALLOC, 1 << 26);
if (s == NULL) {
msg = "Memory allocation failed\n";
goto error;
}
b.in = in;
b.in_pos = 0;
b.in_size = 0;
b.out = out;
b.out_pos = 0;
b.out_size = BUFSIZ;
while (true) {
if (b.in_pos == b.in_size) {
b.in_size = fread(in, 1, sizeof(in), stdin);
b.in_pos = 0;
}
ret = xz_dec_run(s, &b);
if (b.out_pos == sizeof(out)) {
if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos) {
msg = "Write error\n";
goto error;
}
b.out_pos = 0;
}
if (ret == XZ_OK)
continue;
#ifdef XZ_DEC_ANY_CHECK
if (ret == XZ_UNSUPPORTED_CHECK) {
fputs(argv[0], stderr);
fputs(": ", stderr);
fputs("Unsupported check; not verifying "
"file integrity\n", stderr);
continue;
}
#endif
if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos
|| fclose(stdout)) {
msg = "Write error\n";
goto error;
}
switch (ret) {
case XZ_STREAM_END:
xz_dec_end(s);
return 0;
case XZ_MEM_ERROR:
msg = "Memory allocation failed\n";
goto error;
case XZ_MEMLIMIT_ERROR:
msg = "Memory usage limit reached\n";
goto error;
case XZ_FORMAT_ERROR:
msg = "Not a .xz file\n";
goto error;
case XZ_OPTIONS_ERROR:
msg = "Unsupported options in the .xz headers\n";
goto error;
case XZ_DATA_ERROR:
case XZ_BUF_ERROR:
msg = "File is corrupt\n";
goto error;
default:
msg = "Bug!\n";
goto error;
}
}
error:
xz_dec_end(s);
fputs(argv[0], stderr);
fputs(": ", stderr);
fputs(msg, stderr);
return 1;
}