Initial checkin of Pika from heckimp

This commit is contained in:
2023-09-25 15:35:21 -07:00
commit 891e999216
6761 changed files with 5240685 additions and 0 deletions

View File

@ -0,0 +1,31 @@
LICENSE TERMS
(c) 2002 Manuel Heras-Gilsanz (manuel@heras-gilsanz.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Neither the name of Manuel Heras-Gilsanz nor the names of the
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,99 @@
TinyScheme Extensions (TSX) 1.1 [September, 2002]
(c) 2002 Manuel Heras-Gilsanz (manuel@heras-gilsanz.com)
This software is subject to the license terms contained in the
LICENSE file.
Changelog:
1.1 (Sept. 2002) Updated to tinyscheme 1.31
1.0 (April 2002) First released version
WHAT IS TSX?
TinyScheme Extensions is a set of dynamic libraries incorporating
additional funcionality to TinyScheme, a lightweight
implementation of the Scheme programming language. TinyScheme
(http://tinyscheme.sourceforge.net) is maintained by D. Souflis
(dsouflis@acm.org), and is based on MiniSCHEME version 0.85k4.
Scheme is a very nice and powerful programming language, but the
basic language is very minimalistic in terms of library functions;
only basic file input / output functionality is specified.
Different implementations of the language (MIT Scheme, GUILE,
Bigloo...) provide their own extension libraries. TSX attempts to
provide commonly needed functions at a small cost in terms of
additional program footprint. The library is modularized, so that
it is possible (and easy!) to select desired functionality via
#defines in tsx.h.
INSTALLATION
TSX has been tested on GNU/Linux 2.4.2 with gcc 2.96 and
libc-2.2.2, with TinyScheme 1.31.
To install, copy the distribution file to the directory
where TinyScheme is installed (and where scheme.h lies),
and run make. If building succeeds, a file called tsx.so
should be created. This file can be loaded as a TinyScheme
extension with
(load-extension "tsx-1.0/tsx")
After loading TSX, you can make use of its functions.
To reduce footprint, you can choose the functionality which
will be included. To do so, have a look at tsx.h and
comment the #defines for unneeded modules.
If you get compiler errors, make sure you have enabled
dynamic modules in your tinyscheme runtime (define USE_DL
somewhere near the top in scheme.h).
SAMPLE APPLICATIONS
Three sample applications are distributed with TSX 1.0.
The code is not particularly elegant, nor written in proper
functional style, but is provided for illustration of the
implemented calls.
-smtp.scm
Sends an email to the user getting the username from
the USER shell variable, connecting to the SMTP port
on the local machine.
-listhome.scm
Provides a list of all the files on the user's home
directory (obtained with the HOME environment variable).
-srepl.scm
Provides a socket-based read-eval-print-loop. It listens
for connections on the 9000 port of the local machines,
and executes the commands received. To test it, run
telnet localhost 9000
after starting the sample application, and type Scheme
expressions. You will get the evaluations. To exit the
session, type "quit" and TinyScheme will exit, closing
the socket. The output of some functions will not
be the same as you would obtain on TinyScheme's
"command line", because standard output is not
redirected to the socket, but most commands work ok.
You should copy these applications to the directory where
TinyScheme is installed (i.e., where the "scheme" binary
file resides), and can be run with:
./scheme listhome.scm
./scheme smtp.scm
./scheme srepl.scm
TSX FUNCTIONS
The extension functions implemented by TinyScheme Extensions are
documented in the file "tsx-functions.txt".
END

View File

@ -0,0 +1,119 @@
File and Time Extensions for TinyScheme (FTX) 1.0 [August, 2004]
Based on the TinyScheme Extensions (TSX) 1.1 [September, 2002]
(c) 2002 Manuel Heras-Gilsanz (manuel@heras-gilsanz.com)
This software is subject to the license terms contained in the
LICENSE file.
TSX FUNCTIONS
TSX incorporates the following functions:
*File system (included if HAVE_FILESYSTEM is defined in tsx.h)
Scheme already defines functions to read and write files. These
functions allow access to the filesystem to check if a certain
file exists, to get its size, etc.
In addition to these functions, a string constant DIR-SEPARATOR
has been defined. It should be used in scripts which build file
names that include one or more directories to keep the scripts
portable to different operating systems.
(file-exists? filename)
filename: string
This function returns #t if the indicated file exists, and
#f if it does not exist or if it is not accessible to the
requesting user. Accessibility is based on the real user
and group ID rather than the effective user ID and group ID.
(file-type filename)
filename: string
This function returns a value based on the file type. It
returns FILE_TYPE_FILE (1) for regular files, FILE_TYPE_DIR
(2) for directories, and FILE_TYPE_LINK (3) for symbolic
links. The value FILE_TYPE_OTHER (0) is returned if the file
is of some other type, does not exist, or if the user does
not have sufficient privileges to allow the file type to be
determined.
(file-size filename)
filename: string
This function returns the size (in bytes) of the
indicated file, or #f if the file does not exists or
is not accessible to the requesting user.
(file-delete filename)
filename: string
Removes the specified file. It returns #t if the operation
succeeds, or #f otherwise (e.g., because the file is
read-only, or because the file does not exist).
(dir-open-stream path)
path: string
Opens a "directory stream" on the provided directory path.
This stream will provide all the files within the directory,
using the function read-dir-entry. The stream should be closed
at the end with dir-close-stream.
(dir-read-entry dirstream)
dirstream: directory stream, obtained with dir-open-stream.
It returns the name of the following directory entry, or eof
if all the entries were provided. Check the return value with
with eof-object?.
(dir-rewind dirstream)
dirstream: directory stream, obtained with dir-open-stream.
Resets the given directory stream. The next call to dir-read-entry
will return the first entry again. It returns #t if the operation
succeeds, or #f otherwise (ie. dirstream not valid)..
(dir-close-stream dirstream)
dirstream: directory stream, obtained with dir-open-stream.
Close directory stream. No further calls to read-dir-entry should
be performed.
(dir-make dirname . mode)
dirname: string
mode: integer representing permissions
Create the directory specified, setting the directory permissions based
upon the optional mode argument (taking into account the current
umask). If no mode is specified then use the default (umask)
permissions. Returns #t if the operation succeeds, otherwise #f.
Possible reasons for failure are that the directory already exists,
the user is not authorized to create it, or the mode is incorrectly
specified).
*Time (available if HAVE_TIME is defined in tsx.h)
(time)
Returns the current local time, as a list of integer
containing:
(year month day-of-month hour min sec millisec)
The year is expressed as an offset from 1900.
(gettimeofday)
Returns a list containing the number of seconds from
the beginning of the day, and microseconds within the
current second.
(usleep microsec)
microsec: integer
Suspends execution of the calling thread during the
specified number of microseconds.
END

View File

@ -0,0 +1,415 @@
/* TinyScheme Extensions
* (c) 2002 Visual Tools, S.A.
* Manuel Heras-Gilsanz (manuel@heras-gilsanz.com)
*
* This software is subject to the terms stated in the
* LICENSE file.
*/
#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <time.h>
#include <glib.h>
#include "tinyscheme/scheme-private.h"
#undef cons
typedef enum
{
FILE_TYPE_UNKNOWN = 0, FILE_TYPE_FILE, FILE_TYPE_DIR, FILE_TYPE_LINK
} FileType;
struct
named_constant {
const char *name;
FileType value;
};
struct named_constant
file_type_constants[] = {
{ "FILE-TYPE-UNKNOWN", FILE_TYPE_UNKNOWN },
{ "FILE-TYPE-FILE", FILE_TYPE_FILE },
{ "FILE-TYPE-DIR", FILE_TYPE_DIR },
{ "FILE-TYPE-LINK", FILE_TYPE_LINK },
{ NULL, 0 }
};
pointer foreign_fileexists(scheme *sc, pointer args);
pointer foreign_filetype(scheme *sc, pointer args);
pointer foreign_filesize(scheme *sc, pointer args);
pointer foreign_filedelete(scheme *sc, pointer args);
pointer foreign_diropenstream(scheme *sc, pointer args);
pointer foreign_dirreadentry(scheme *sc, pointer args);
pointer foreign_dirrewind(scheme *sc, pointer args);
pointer foreign_dirclosestream(scheme *sc, pointer args);
pointer foreign_mkdir(scheme *sc, pointer args);
pointer foreign_getenv(scheme *sc, pointer args);
pointer foreign_time(scheme *sc, pointer args);
pointer foreign_gettimeofday(scheme *sc, pointer args);
pointer foreign_usleep(scheme *sc, pointer args);
void init_ftx (scheme *sc);
pointer foreign_fileexists(scheme *sc, pointer args)
{
pointer first_arg;
char *filename;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_string(first_arg))
return sc->F;
filename = sc->vptr->string_value(first_arg);
filename = g_filename_from_utf8 (filename, -1, NULL, NULL, NULL);
if (g_file_test(filename, G_FILE_TEST_EXISTS))
return sc->T;
return sc->F;
}
pointer foreign_filetype(scheme *sc, pointer args)
{
pointer first_arg;
char *filename;
int retcode;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_string(first_arg))
return sc->F;
filename = sc->vptr->string_value(first_arg);
filename = g_filename_from_utf8 (filename, -1, NULL, NULL, NULL);
if (g_file_test(filename, G_FILE_TEST_IS_SYMLINK))
retcode = FILE_TYPE_LINK;
else if (g_file_test(filename, G_FILE_TEST_IS_REGULAR))
retcode = FILE_TYPE_FILE;
else if (g_file_test(filename, G_FILE_TEST_IS_DIR))
retcode = FILE_TYPE_DIR;
else
retcode = FILE_TYPE_UNKNOWN;
return sc->vptr->mk_integer(sc, retcode);
}
pointer foreign_filesize(scheme *sc, pointer args)
{
pointer first_arg;
pointer ret;
struct stat buf;
char * filename;
int retcode;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_string(first_arg))
return sc->F;
filename = sc->vptr->string_value(first_arg);
filename = g_filename_from_utf8 (filename, -1, NULL, NULL, NULL);
retcode = stat(filename, &buf);
if (retcode == 0)
ret = sc->vptr->mk_integer(sc,buf.st_size);
else
ret = sc->F;
return ret;
}
pointer foreign_filedelete(scheme *sc, pointer args)
{
pointer first_arg;
pointer ret;
char * filename;
int retcode;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_string(first_arg)) {
return sc->F;
}
filename = sc->vptr->string_value(first_arg);
filename = g_filename_from_utf8 (filename, -1, NULL, NULL, NULL);
retcode = unlink(filename);
if (retcode == 0)
ret = sc->T;
else
ret = sc->F;
return ret;
}
pointer foreign_diropenstream(scheme *sc, pointer args)
{
pointer first_arg;
char *dirpath;
GDir *dir;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_string(first_arg))
return sc->F;
dirpath = sc->vptr->string_value(first_arg);
dirpath = g_filename_from_utf8 (dirpath, -1, NULL, NULL, NULL);
dir = g_dir_open(dirpath, 0, NULL);
if (dir == NULL)
return sc->F;
/* Stuffing a pointer in a long may not always be portable ~~~~~ */
return (sc->vptr->mk_integer(sc, (long) dir));
}
pointer foreign_dirreadentry(scheme *sc, pointer args)
{
pointer first_arg;
GDir *dir;
gchar *entry;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_integer(first_arg))
return sc->F;
dir = (GDir *) sc->vptr->ivalue(first_arg);
if (dir == NULL)
return sc->F;
entry = (gchar *)g_dir_read_name(dir);
if (entry == NULL)
return sc->EOF_OBJ;
entry = g_filename_to_utf8 (entry, -1, NULL, NULL, NULL);
return (sc->vptr->mk_string(sc, entry));
}
pointer foreign_dirrewind(scheme *sc, pointer args)
{
pointer first_arg;
GDir *dir;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_integer(first_arg))
return sc->F;
dir = (GDir *) sc->vptr->ivalue(first_arg);
if (dir == NULL)
return sc->F;
g_dir_rewind(dir);
return sc->T;
}
pointer foreign_dirclosestream(scheme *sc, pointer args)
{
pointer first_arg;
GDir *dir;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_integer(first_arg))
return sc->F;
dir = (GDir *) sc->vptr->ivalue(first_arg);
if (dir == NULL)
return sc->F;
g_dir_close(dir);
return sc->T;
}
pointer foreign_mkdir(scheme *sc, pointer args)
{
pointer first_arg;
pointer rest;
pointer second_arg;
char *dirname;
mode_t mode;
int retcode;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_string(first_arg))
return sc->F;
dirname = sc->vptr->string_value(first_arg);
dirname = g_filename_from_utf8 (dirname, -1, NULL, NULL, NULL);
rest = sc->vptr->pair_cdr(args);
if (sc->vptr->is_pair(rest)) /* optional mode argument */
{
second_arg = sc->vptr->pair_car(rest);
if (!sc->vptr->is_integer(second_arg))
return sc->F;
mode = sc->vptr->ivalue(second_arg);
}
else
mode = 0777;
retcode = g_mkdir(dirname, (mode_t)mode);
if (retcode == 0)
return sc->T;
else
return sc->F;
}
pointer foreign_getenv(scheme *sc, pointer args)
{
pointer first_arg;
pointer ret;
char *varname;
const char *value;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_string(first_arg))
return sc->F;
varname = sc->vptr->string_value(first_arg);
value = g_getenv(varname);
if (value == NULL)
ret = sc->F;
else
ret = sc->vptr->mk_string(sc,value);
return ret;
}
pointer foreign_time(scheme *sc, pointer args)
{
time_t now;
struct tm *now_tm;
pointer ret;
if (args != sc->NIL)
return sc->F;
time(&now);
now_tm = localtime(&now);
ret = sc->vptr->cons(sc, sc->vptr->mk_integer(sc,(long) now_tm->tm_year),
sc->vptr->cons(sc, sc->vptr->mk_integer(sc,(long) now_tm->tm_mon),
sc->vptr->cons(sc, sc->vptr->mk_integer(sc,(long) now_tm->tm_mday),
sc->vptr->cons(sc, sc->vptr->mk_integer(sc,(long) now_tm->tm_hour),
sc->vptr->cons(sc, sc->vptr->mk_integer(sc,(long) now_tm->tm_min),
sc->vptr->cons(sc, sc->vptr->mk_integer(sc,(long) now_tm->tm_sec),sc->NIL))))));
return ret;
}
pointer foreign_gettimeofday(scheme *sc, pointer args)
{
pointer ret;
gint64 time;
time = g_get_real_time ();
ret = sc->vptr->cons(sc, sc->vptr->mk_integer(sc,(long) time / G_USEC_PER_SEC),
sc->vptr->cons(sc, sc->vptr->mk_integer(sc,(long) time % G_USEC_PER_SEC),
sc->NIL));
return ret;
}
pointer foreign_usleep(scheme *sc, pointer args)
{
pointer first_arg;
long usec;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_integer(first_arg))
return sc->F;
usec = sc->vptr->ivalue(first_arg);
g_usleep(usec);
return sc->T;
}
/* This function gets called when TinyScheme is loading the extension */
void init_ftx (scheme *sc)
{
int i;
sc->vptr->scheme_define(sc,sc->global_env,
sc->vptr->mk_symbol(sc,"getenv"),
sc->vptr->mk_foreign_func(sc, foreign_getenv));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"time"),
sc->vptr->mk_foreign_func(sc, foreign_time));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"gettimeofday"),
sc->vptr->mk_foreign_func(sc, foreign_gettimeofday));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"usleep"),
sc->vptr->mk_foreign_func(sc, foreign_usleep));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"file-exists?"),
sc->vptr->mk_foreign_func(sc, foreign_fileexists));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"file-type"),
sc->vptr->mk_foreign_func(sc, foreign_filetype));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"file-size"),
sc->vptr->mk_foreign_func(sc, foreign_filesize));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"file-delete"),
sc->vptr->mk_foreign_func(sc, foreign_filedelete));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"dir-open-stream"),
sc->vptr->mk_foreign_func(sc, foreign_diropenstream));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"dir-read-entry"),
sc->vptr->mk_foreign_func(sc, foreign_dirreadentry));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"dir-rewind"),
sc->vptr->mk_foreign_func(sc, foreign_dirrewind));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"dir-close-stream"),
sc->vptr->mk_foreign_func(sc, foreign_dirclosestream));
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"dir-make"),
sc->vptr->mk_foreign_func(sc, foreign_mkdir));
for (i = 0; file_type_constants[i].name != NULL; ++i)
{
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc, file_type_constants[i].name),
sc->vptr->mk_integer(sc, file_type_constants[i].value));
}
}

View File

@ -0,0 +1,2 @@
/* This function gets called when TinyScheme is initializing the extension */
void init_ftx (scheme *sc);

View File

@ -0,0 +1,58 @@
; listhome.scm
; Sample usage of TinyScheme Extension
; This simple program lists the directory entries on the
; user's home directory.
; It uses the following TinyScheme Extension functions:
; getenv
; Used to get HOME environment variable.
; open-dir-stream
; Used to open directory stream.
; read-dir-entry
; Used to read directory entries.
; close-dir-entry
; Used at the end, to close directory stream when done.
; check that extensions are enabled
(if (not (defined? 'load-extension))
(begin
(display "TinyScheme has extensions disabled. Enable them!!")
(newline)
(quit)))
; load TinyScheme extension
(load-extension "tsx-1.1/tsx")
; check that the necessary functions are available (the user
; might have removed some functionality...)
(if (or
(not (defined? 'getenv))
(not (defined? 'dir-open-stream))
(not (defined? 'dir-read-entry))
(not (defined? 'dir-close-stream)))
(begin
(display "Some necessary functions are not available. Exiting!")
(newline)
(quit)))
; get user's home dir from HOME environment var
(define homedir (getenv "HOME"))
(display "Listing contents of ") (display homedir) (newline)
; create directory stream to read dir entries
(define dirstream (dir-open-stream homedir))
(if (not dirstream)
(begin
(display "Unable to open home directory!! Check value of HOME environment var.")
(quit)))
(let listentry ((entry (dir-read-entry dirstream)))
(if (eof-object? entry)
#t
(begin
(display entry)
(newline)
(listentry (dir-read-entry dirstream)))))
(dir-close-stream dirstream)

View File

@ -0,0 +1,12 @@
scriptfu_ftx = static_library('scriptfu-ftx',
'ftx.c',
include_directories: [ rootInclude, libscriptfuInclude, ],
dependencies: [
glib,
],
c_args: [
'-DUSE_INTERFACE=1',
],
install: false,
)