Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
/* Copyright (C) 2009 The PARI group.12This file is part of the PARI/GP package.34PARI/GP is free software; you can redistribute it and/or modify it under the5terms of the GNU General Public License as published by the Free Software6Foundation; either version 2 of the License, or (at your option) any later7version. It is distributed in the hope that it will be useful, but WITHOUT8ANY WARRANTY WHATSOEVER.910Check the License for details. You should have received a copy of it, along11with the package; see the file 'COPYING'. If not, write to the Free Software12Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */1314/* Originally written by Vasili Burdo */1516#include "pwinver.h"17#include <windows.h>18#include <stdio.h>19#include "mingw.h"2021static const char * pariwin32_basedir = NULL;2223const char*24win32_basedir(void)25{26if (!pariwin32_basedir)27{28char basedir[1024];29char* slash;30GetModuleFileNameA(0, basedir, sizeof(basedir) );31slash = strrchr(basedir, '\\');32if (slash) slash[1] = 0;33pariwin32_basedir = strdup(basedir);34}35return pariwin32_basedir;36}3738char*39win32_datadir(void)40{41char datadir[1029];42const char * basedir = win32_basedir();43sprintf(datadir, "%sdata", basedir);44return strdup(datadir);45}4647static WORD48win32_console_color(unsigned long c)49{50int shift, intense = 0;51if( c >= 30 && c <= 37 ) { shift = 0; c -= 30; } else52if( c >= 40 && c <= 47 ) { shift = 4; c -= 40; } else53if( c >= 90 && c <= 97 ) { shift = 0; intense = 8; c -= 90; } else54if(c >= 100 && c <= 107) { shift = 4; intense = 8; c -= 100; } else55return 0;5657WORD w = 0;58switch(c) {59case 0: w = 0; break; /* black */60case 1: w = 4; break; /* red */61case 2: w = 2; break; /* green */62case 3: w = 6; break; /* yellow RG */63case 4: w = 1; break; /* blue */64case 5: w = 5; break; /* magenta RB */65case 6: w = 3; break; /* cyan GB */66case 7: w = 7; break; /* white RGB */67}68return (w|intense) << shift;69}7071void72win32_ansi_fputs(const char* s, void* f)73{74WORD color;75unsigned long c[3];76long nbarg;77if( !(f == stdout || f == stderr) ) {78fputs(s,f);79return;80}8182while(1) {83char *p;84p = strstr(s, "\x1b[");85if( p > s )86fwrite(s,p-s,1,f);8788if( p )89p += 2;90else {91fputs(s,f);92return;93}94nbarg = 0;95c[nbarg++] = strtoul(p,&p,10);96if( *p == ';' ) c[nbarg++] = strtoul(p+1,&p,10);97if( *p == ';' ) c[nbarg++] = strtoul(p+1,&p,10);98if( *p++ == 'm' ) {99switch(nbarg)100{101case 1:102color = 7;103break;104case 2:105color = win32_console_color(c[1]);106if (c[0]&4) color |= 0x8000;107break;108case 3:109color = win32_console_color(c[1]) | win32_console_color(c[2]);110if (c[0]&4) color |= 0x8000;111}112fflush(f);113SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color);114}115s = p;116}117}118119int120win32_terminal_width(void)121{122CONSOLE_SCREEN_BUFFER_INFO sbi;123if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &sbi))124return 0;125return sbi.srWindow.Right - sbi.srWindow.Left + 1;126}127128int129win32_terminal_height(void)130{131CONSOLE_SCREEN_BUFFER_INFO sbi;132if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &sbi))133return 0;134return sbi.srWindow.Bottom - sbi.srWindow.Top + 1;135}136137void138win32_set_codepage(void)139{140SetConsoleCP( GetACP() );141SetConsoleOutputCP( GetACP() );142}143144void145win32_set_pdf_viewer(void)146{147char *s = getenv("GP_PDF_VIEWER");148if (!s)149{150HKEY handle;151const char *key = "AcroExch.Document\\shell\\open\\command";152const long SZ = 512;153char str[SZ], *buf;154int status;155DWORD L = SZ;156157(void)RegOpenKeyEx(HKEY_CLASSES_ROOT, key, 0, KEY_READ, &handle);158status = RegQueryValueEx(handle, NULL, 0, NULL, (LPBYTE)str, &L);159RegCloseKey(handle);160if (status) return;161buf = malloc(strlen(str)+16); /*must not be freed*/162sprintf(buf,"GP_PDF_VIEWER=%s",str);163putenv(buf);164}165}166167extern int win32ctrlc, win32alrm;168static HANDLE hTimerQueue = NULL;169170static void CALLBACK171win32_cb_alarm(void *lpParam, BOOLEAN TimerOrWaitFired)172{173(void) lpParam; (void) TimerOrWaitFired;174win32ctrlc++;175win32alrm = 1;176}177178void179win32_alarm(unsigned int s)180{181if (hTimerQueue)182{183HANDLE oldhTimerQueue = hTimerQueue;184hTimerQueue = NULL;185DeleteTimerQueue(oldhTimerQueue);186}187if (s)188{189void *arg = NULL;190HANDLE hTimer = NULL;191hTimerQueue = CreateTimerQueue();192CreateTimerQueueTimer( &hTimer, hTimerQueue,193(WAITORTIMERCALLBACK)win32_cb_alarm, &arg , s*1000, 0, 0);194}195}196197#define WIN32_FILETIME_PER_MILLISECOND 10000198199long200win32_timer(void)201{202FILETIME lpCreation, lpExit, lpKernel, lpUser;203LARGE_INTEGER time;204GetProcessTimes(205GetCurrentProcess(),206&lpCreation, &lpExit, &lpKernel, &lpUser207);208time.HighPart = lpUser.dwHighDateTime;209time.LowPart = lpUser.dwLowDateTime;210time.QuadPart /= WIN32_FILETIME_PER_MILLISECOND;211return time.LowPart;212}213214long215win32_nbthreads(void)216{217SYSTEM_INFO system_info;218GetSystemInfo(&system_info);219return system_info.dwNumberOfProcessors;220}221222223