mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
e16a7d8f3b
`et` means `expandtab`. ```sh rg 'vi: .* :vi' -l -0 | \ xargs -0 sed -i '' 's/vi: \(.*\) et\(.*\) :vi/vi: \1 xoet\2:vi/' rg 'vi: .* :vi' -l -0 | \ xargs -0 sed -i '' 's/vi: \(.*\)noet\(.*\):vi/vi: \1et\2 :vi/' rg 'vi: .* :vi' -l -0 | \ xargs -0 sed -i '' 's/vi: \(.*\)xoet\(.*\):vi/vi: \1noet\2:vi/' ```
89 lines
4 KiB
C
89 lines
4 KiB
C
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||
│ │
|
||
│ Lua │
|
||
│ Copyright © 2004-2021 Lua.org, PUC-Rio. │
|
||
│ │
|
||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||
│ a copy of this software and associated documentation files (the │
|
||
│ "Software"), to deal in the Software without restriction, including │
|
||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||
│ the following conditions: │
|
||
│ │
|
||
│ The above copyright notice and this permission notice shall be │
|
||
│ included in all copies or substantial portions of the Software. │
|
||
│ │
|
||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||
│ │
|
||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||
#define lzio_c
|
||
#define LUA_CORE
|
||
#include "libc/str/str.h"
|
||
#include "third_party/lua/llimits.h"
|
||
#include "third_party/lua/lmem.h"
|
||
#include "third_party/lua/lprefix.h"
|
||
#include "third_party/lua/lstate.h"
|
||
#include "third_party/lua/lua.h"
|
||
#include "third_party/lua/lzio.h"
|
||
|
||
asm(".ident\t\"\\n\\n\
|
||
Lua 5.4.3 (MIT License)\\n\
|
||
Copyright 1994–2021 Lua.org, PUC-Rio.\"");
|
||
asm(".include \"libc/disclaimer.inc\"");
|
||
|
||
|
||
int luaZ_fill (ZIO *z) {
|
||
size_t size;
|
||
lua_State *L = z->L;
|
||
const char *buff;
|
||
lua_unlock(L);
|
||
buff = z->reader(L, z->data, &size);
|
||
lua_lock(L);
|
||
if (buff == NULL || size == 0)
|
||
return EOZ;
|
||
z->n = size - 1; /* discount char being returned */
|
||
z->p = buff;
|
||
return cast_uchar(*(z->p++));
|
||
}
|
||
|
||
|
||
void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
|
||
z->L = L;
|
||
z->reader = reader;
|
||
z->data = data;
|
||
z->n = 0;
|
||
z->p = NULL;
|
||
}
|
||
|
||
|
||
/* --------------------------------------------------------------- read --- */
|
||
size_t luaZ_read (ZIO *z, void *b, size_t n) {
|
||
while (n) {
|
||
size_t m;
|
||
if (z->n == 0) { /* no bytes in buffer? */
|
||
if (luaZ_fill(z) == EOZ) /* try to read more */
|
||
return n; /* no more input; return number of missing bytes */
|
||
else {
|
||
z->n++; /* luaZ_fill consumed first byte; put it back */
|
||
z->p--;
|
||
}
|
||
}
|
||
m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
|
||
memcpy(b, z->p, m);
|
||
z->n -= m;
|
||
z->p += m;
|
||
b = (char *)b + m;
|
||
n -= m;
|
||
}
|
||
return 0;
|
||
}
|
||
|