|
Post Scarcity
A prototype for a post scarcity programming environment
|
#include <grp.h>#include <langinfo.h>#include <pwd.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include <uuid/uuid.h>#include <wchar.h>#include <wctype.h>#include <curl/curl.h>#include "arith/integer.h"#include "debug.h"#include "io/fopen.h"#include "io/io.h"#include "memory/conspage.h"#include "memory/consspaceobject.h"#include "ops/intern.h"#include "ops/lispops.h"#include "utils.h"Go to the source code of this file.
Functions | |
| struct cons_pointer | add_meta_integer (struct cons_pointer meta, wchar_t *key, long int value) |
| struct cons_pointer | add_meta_string (struct cons_pointer meta, wchar_t *key, char *value) |
| struct cons_pointer | add_meta_time (struct cons_pointer meta, wchar_t *key, time_t *value) |
| void | collect_meta (struct cons_pointer stream, char *url) |
| URL_FILE * | file_to_url_file (FILE *f) |
| given this file handle f, return a new url_file handle wrapping it. | |
| struct cons_pointer | get_default_stream (bool inputp, struct cons_pointer env) |
Resutn the current default input, or of inputp is false, output stream from this environment. | |
| int | io_init () |
| Initialise the I/O subsystem. | |
| struct cons_pointer | lisp_close (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env) |
| Function, sort-of: close the file indicated by my first arg, and return nil. | |
| struct cons_pointer | lisp_open (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env) |
| Function: return a stream open on the URL indicated by the first argument; if a second argument is present and is non-nil, open it for reading. | |
| struct cons_pointer | lisp_read_char (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env) |
| Function: return the next character from the stream indicated by arg 0; further arguments are ignored. | |
| struct cons_pointer | lisp_slurp (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env) |
| Function: return a string representing all characters from the stream indicated by arg 0; further arguments are ignored. | |
| char * | lisp_string_to_c_string (struct cons_pointer s) |
| Convert this lisp string-like-thing (also works for symbols, and, later keywords) into a UTF-8 string. | |
| wint_t | url_fgetwc (URL_FILE *input) |
| get one wide character from the buffer. | |
| wint_t | url_ungetwc (wint_t wc, URL_FILE *input) |
Variables | |
| CURLSH * | io_share |
| The sharing hub for all connections. | |
| struct cons_pointer | lisp_io_in = NIL |
| bound to the Lisp string representing C_IO_IN in initialisation. | |
| struct cons_pointer | lisp_io_out = NIL |
| bound to the Lisp string representing C_IO_OUT in initialisation. | |
| wint_t | ungotten = 0 |
| Allow a one-character unget facility. | |
| struct cons_pointer add_meta_integer | ( | struct cons_pointer | meta, |
| wchar_t * | key, | ||
| long int | value | ||
| ) |
Definition at line 268 of file io.c.
References c_string_to_lisp_keyword(), make_cons(), make_integer(), and NIL.
Referenced by collect_meta().
| struct cons_pointer add_meta_string | ( | struct cons_pointer | meta, |
| wchar_t * | key, | ||
| char * | value | ||
| ) |
Definition at line 276 of file io.c.
References c_string_to_lisp_keyword(), c_string_to_lisp_string(), make_cons(), and trim().
Referenced by add_meta_time(), and collect_meta().
| struct cons_pointer add_meta_time | ( | struct cons_pointer | meta, |
| wchar_t * | key, | ||
| time_t * | value | ||
| ) |
| void collect_meta | ( | struct cons_pointer | stream, |
| char * | url | ||
| ) |
Definition at line 360 of file io.c.
References add_meta_integer(), add_meta_string(), add_meta_time(), CFTYPE_CURL, CFTYPE_FILE, CFTYPE_NONE, fcurl_data::handle, cons_space_object::payload, pointer2cell, and fcurl_data::type.
Referenced by lisp_open().
| URL_FILE * file_to_url_file | ( | FILE * | f | ) |
given this file handle f, return a new url_file handle wrapping it.
| f | the file to be wrapped; |
Definition at line 134 of file io.c.
References CFTYPE_FILE, fcurl_data::handle, and fcurl_data::type.
Referenced by check_exception(), debug_dump_object(), debug_print_object(), lisp_inspect(), lisp_print(), lisp_read(), and main().
| struct cons_pointer get_default_stream | ( | bool | inputp, |
| struct cons_pointer | env | ||
| ) |
Resutn the current default input, or of inputp is false, output stream from this environment.
Definition at line 411 of file io.c.
References c_assoc(), lisp_io_in, lisp_io_out, and NIL.
Referenced by lisp_inspect(), lisp_print(), lisp_read(), and lisp_repl().
| int io_init | ( | ) |
| struct cons_pointer lisp_close | ( | struct stack_frame * | frame, |
| struct cons_pointer | frame_pointer, | ||
| struct cons_pointer | env | ||
| ) |
Function, sort-of: close the file indicated by my first arg, and return nil.
If the first arg is not a stream, does nothing. All other args are ignored.
| frame | my stack_frame. |
| frame_pointer | a pointer to my stack_frame. |
| env | my environment. |
Definition at line 254 of file io.c.
References NIL, pointer2cell, readp, TRUE, url_fclose(), and writep.
Referenced by main().
| struct cons_pointer lisp_open | ( | struct stack_frame * | frame, |
| struct cons_pointer | frame_pointer, | ||
| struct cons_pointer | env | ||
| ) |
Function: return a stream open on the URL indicated by the first argument; if a second argument is present and is non-nil, open it for reading.
At present, further arguments are ignored and there is no mechanism to open to append, or error if the URL is faulty or indicates an unavailable resource.
| frame | my stack_frame. |
| frame_pointer | a pointer to my stack_frame. |
| env | my environment. |
Definition at line 437 of file io.c.
References c_string_to_lisp_string(), CFTYPE_CURL, CFTYPE_FILE, CFTYPE_NONE, collect_meta(), DEBUG_IO, debug_printf(), fcurl_data::handle, lisp_string_to_c_string(), make_exception(), make_read_stream(), make_write_stream(), NIL, nilp, pointer2cell, stringp, fcurl_data::type, and url_fopen().
Referenced by main().
| struct cons_pointer lisp_read_char | ( | struct stack_frame * | frame, |
| struct cons_pointer | frame_pointer, | ||
| struct cons_pointer | env | ||
| ) |
Function: return the next character from the stream indicated by arg 0; further arguments are ignored.
| frame | my stack_frame. |
| frame_pointer | a pointer to my stack_frame. |
| env | my environment. |
Definition at line 504 of file io.c.
References make_string(), NIL, pointer2cell, readp, and url_fgetwc().
Referenced by main().
| struct cons_pointer lisp_slurp | ( | struct stack_frame * | frame, |
| struct cons_pointer | frame_pointer, | ||
| struct cons_pointer | env | ||
| ) |
Function: return a string representing all characters from the stream indicated by arg 0; further arguments are ignored.
TODO: it should be possible to optionally pass a string URL to this function,
| frame | my stack_frame. |
| frame_pointer | a pointer to my stack_frame. |
| env | my environment. |
Definition at line 533 of file io.c.
References debug_dump_object(), DEBUG_IO, debug_print(), debug_println(), make_string(), NIL, cons_space_object::payload, pointer2cell, readp, url_feof(), and url_fgetwc().
Referenced by main().
| char * lisp_string_to_c_string | ( | struct cons_pointer | s | ) |
Convert this lisp string-like-thing (also works for symbols, and, later keywords) into a UTF-8 string.
NOTE that the returned value has been malloced and must be freed. TODO: candidate to moving into a utilities file.
| s | the lisp string or symbol; |
Definition at line 95 of file io.c.
References DEBUG_IO, debug_print(), debug_print_object(), debug_printf(), nilp, pointer2cell, stringp, and symbolp.
Referenced by lisp_open(), and set().
| wint_t url_fgetwc | ( | URL_FILE * | input | ) |
get one wide character from the buffer.
| file | the stream to read from; |
Definition at line 151 of file io.c.
References CFTYPE_CURL, CFTYPE_FILE, CFTYPE_NONE, DEBUG_IO, debug_print(), debug_printf(), fcurl_data::handle, fcurl_data::type, ungotten, and url_fgets().
Referenced by lisp_car(), lisp_cdr(), lisp_read_char(), lisp_slurp(), read(), read_continuation(), read_list(), read_map(), read_number(), read_path(), read_string(), and read_symbol_or_key().
| wint_t url_ungetwc | ( | wint_t | wc, |
| URL_FILE * | input | ||
| ) |
Definition at line 220 of file io.c.
References CFTYPE_CURL, CFTYPE_FILE, CFTYPE_NONE, fcurl_data::handle, fcurl_data::type, and ungotten.
Referenced by read_continuation(), read_number(), read_path(), and read_symbol_or_key().
| CURLSH* io_share |
The sharing hub for all connections.
TODO: Ultimately this probably doesn't work for a multi-user environment and we will need one sharing hub for each user, or else we will need to not share at least cookies and ssl sessions.
Definition at line 46 of file io.c.
Referenced by io_init(), and url_fopen().
| struct cons_pointer lisp_io_in = NIL |
bound to the Lisp string representing C_IO_IN in initialisation.
Definition at line 51 of file io.c.
Referenced by get_default_stream(), and main().
| struct cons_pointer lisp_io_out = NIL |
bound to the Lisp string representing C_IO_OUT in initialisation.
Definition at line 55 of file io.c.
Referenced by get_default_stream(), and main().
| wint_t ungotten = 0 |
Allow a one-character unget facility.
This may not be enough - we may need to allocate a buffer.
Definition at line 62 of file io.c.
Referenced by url_fgetwc(), and url_ungetwc().