mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-05 17:30:27 +00:00
start on improving __paginate
This commit is contained in:
parent
69db501c68
commit
2a2c1ad806
1 changed files with 10 additions and 2 deletions
|
@ -16,7 +16,9 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/dce.h"
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/intrin/safemacros.internal.h"
|
#include "libc/intrin/safemacros.internal.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
@ -29,16 +31,22 @@
|
||||||
void __paginate(int fd, const char *s) {
|
void __paginate(int fd, const char *s) {
|
||||||
int tfd, pid;
|
int tfd, pid;
|
||||||
char *args[3] = {0};
|
char *args[3] = {0};
|
||||||
char tmppath[] = "/tmp/paginate.XXXXXX";
|
char tmppath[PATH_MAX-32] = "/tmp/paginate.XXXXXX";
|
||||||
char progpath[PATH_MAX];
|
char progpath[PATH_MAX];
|
||||||
if (strcmp(nulltoempty(getenv("TERM")), "dumb") && isatty(0) && isatty(1) &&
|
if (strcmp(nulltoempty(getenv("TERM")), "dumb") && isatty(0) && isatty(1) &&
|
||||||
((args[0] = commandv("less", progpath, sizeof(progpath))) ||
|
((args[0] = commandv("less", progpath, sizeof(progpath))) ||
|
||||||
(args[0] = commandv("more", progpath, sizeof(progpath))) ||
|
(args[0] = commandv("more", progpath, sizeof(progpath))) ||
|
||||||
(args[0] = commandv("more.exe", progpath, sizeof(progpath))))) {
|
(args[0] = commandv("more.exe", progpath, sizeof(progpath))) ||
|
||||||
|
(args[0] = commandv("more.com", progpath, sizeof(progpath))))) {
|
||||||
if ((tfd = mkstemp(tmppath)) != -1) {
|
if ((tfd = mkstemp(tmppath)) != -1) {
|
||||||
write(tfd, s, strlen(s));
|
write(tfd, s, strlen(s));
|
||||||
close(tfd);
|
close(tfd);
|
||||||
args[1] = tmppath;
|
args[1] = tmppath;
|
||||||
|
if (IsWindows() && strcmp(args[0], "/C/Windows/System32/more.com") == 0) {
|
||||||
|
char16_t widepath[PATH_MAX];
|
||||||
|
__mkntpath(tmppath, widepath);
|
||||||
|
tprecode16to8(tmppath, sizeof(tmppath), widepath);
|
||||||
|
}
|
||||||
if ((pid = fork()) != -1) {
|
if ((pid = fork()) != -1) {
|
||||||
putenv("LC_ALL=C.UTF-8");
|
putenv("LC_ALL=C.UTF-8");
|
||||||
putenv("LESSCHARSET=utf-8");
|
putenv("LESSCHARSET=utf-8");
|
Loading…
Add table
Add a link
Reference in a new issue