Skip to content
Commits on Source (3)
  • gambas's avatar
    Fix some spaces in source code. · a0af9b39
    gambas authored
    [GB.GEOM]
    * BUG: Fix some spaces in source code.
    a0af9b39
  • gambas's avatar
    OPEN NULL is a new syntax that opens a null stream. · 3e0398db
    gambas authored
    [INTERPRETER]
    * NEW: OPEN NULL is a new syntax that opens a null stream. Reading always returns end of file, and writing does nothing except advancing the file pointer, allowing to know how many bytes were written.
    
    [COMPILER]
    * NEW: OPEN NULL is a new syntax that opens a null stream.
    3e0398db
  • gambas's avatar
    Forgot the new source file. · 05cc5ee6
    gambas authored
    [INTERPRETER]
    * BUG: Forgot the new source file.
    05cc5ee6
......@@ -49,6 +49,7 @@ enum {
TS_MODE_PIPE = (1 << 7),
TS_MODE_MEMORY = (1 << 8),
TS_MODE_STRING = (1 << 9),
TS_MODE_NULL = (1 << 10),
};
enum {
......@@ -220,7 +221,6 @@ void TRANS_write(void);
void TRANS_open(void);
void TRANS_pipe(void);
void TRANS_memory(void);
void TRANS_open_string(void);
void TRANS_close(void);
void TRANS_lock(void);
void TRANS_unlock(void);
......
......@@ -342,6 +342,7 @@ void TRANS_input(void)
}
}
void TRANS_read_old(void)
{
PATTERN *save_var;
......@@ -375,6 +376,7 @@ void TRANS_read_old(void)
JOB->current = save_current;
}
void TRANS_read(void)
{
bool def = trans_stream_no_check(TS_STDIN);
......@@ -394,6 +396,60 @@ void TRANS_read(void)
}
}
static void TRANS_open_null(void)
{
int mode = TS_MODE_READ;
// file name
CODE_push_null();
// open mode
if (TRANS_is(RS_FOR))
{
if (TRANS_is(RS_READ))
mode |= TS_MODE_READ | TS_MODE_DIRECT;
if (TRANS_is(RS_WRITE))
mode |= TS_MODE_WRITE | TS_MODE_DIRECT;
}
CODE_push_number(mode | TS_MODE_NULL);
TRANS_subr(TS_SUBR_OPEN, 2);
}
static void TRANS_open_string(void)
{
int mode = TS_MODE_READ;
// file name
if (!PATTERN_is(*JOB->current, RS_FOR))
TRANS_expression(FALSE);
else
CODE_push_null();
// open mode
if (TRANS_is(RS_FOR))
{
if (TRANS_is(RS_READ))
mode |= TS_MODE_READ | TS_MODE_DIRECT;
if (TRANS_is(RS_WRITE))
mode |= TS_MODE_WRITE | TS_MODE_DIRECT;
}
CODE_push_number(mode | TS_MODE_STRING);
TRANS_subr(TS_SUBR_OPEN, 2);
}
void TRANS_open(void)
{
int mode = TS_MODE_READ;
......@@ -413,13 +469,17 @@ void TRANS_open(void)
TRANS_open_string();
return;
}
else if (TRANS_is(RS_NULL))
{
TRANS_open_null();
return;
}
/* Nom du fichier */
// file name
TRANS_expression(FALSE);
/* mode d'ouverture */
// open mode
if (TRANS_is(RS_FOR))
{
......@@ -438,9 +498,6 @@ void TRANS_open(void)
else if (TRANS_is(RS_APPEND))
mode |= TS_MODE_APPEND;
//if (TRANS_is(RS_DIRECT))
// mode |= TS_MODE_DIRECT;
if (TRANS_is(RS_WATCH))
mode |= TS_MODE_WATCH;
......@@ -458,16 +515,6 @@ void TRANS_open(void)
CODE_push_number(mode);
TRANS_subr(TS_SUBR_OPEN, 2);
/*if (!TRANS_in_assignment)
{
//CODE_drop();
TRANS_want(RS_AS, NULL);
TRANS_ignore(RS_SHARP);
TRANS_reference();
}*/
}
......@@ -475,11 +522,11 @@ void TRANS_pipe(void)
{
int mode = TS_MODE_READ;
/* Nom du fichier */
// file name
TRANS_expression(FALSE);
/* mode d'ouverture */
// open mode
if (TRANS_is(RS_FOR))
{
......@@ -528,34 +575,6 @@ void TRANS_memory(void)
}
void TRANS_open_string(void)
{
int mode = TS_MODE_READ;
/* Nom du fichier */
if (!PATTERN_is(*JOB->current, RS_FOR))
TRANS_expression(FALSE);
else
CODE_push_null();
/* mode d'ouverture */
if (TRANS_is(RS_FOR))
{
if (TRANS_is(RS_READ))
mode |= TS_MODE_READ | TS_MODE_DIRECT;
if (TRANS_is(RS_WRITE))
mode |= TS_MODE_WRITE | TS_MODE_DIRECT;
}
CODE_push_number(mode | TS_MODE_STRING);
TRANS_subr(TS_SUBR_OPEN, 2);
}
void TRANS_close(void)
{
if (PATTERN_is_newline(*JOB->current))
......@@ -923,7 +942,7 @@ void TRANS_rmdir(void)
CODE_drop();
}
void TRANS_mid()
void TRANS_mid(void)
{
PATTERN *str;
PATTERN *pos;
......
......@@ -38,7 +38,7 @@ gbx3_SOURCES = \
gbx_class_load.c gbx_class_load.h \
gbx_event.h gbx_event.c \
gb_file.h gb_file.c \
gbx_stream.h gbx_stream.c gbx_stream_direct.c gbx_stream_lock.c gbx_stream_buffer.c gbx_stream_memory.c \
gbx_stream.h gbx_stream.c gbx_stream_direct.c gbx_stream_lock.c gbx_stream_buffer.c gbx_stream_memory.c gbx_stream_null.c \
gbx_stream_arch.c gbx_stream_process.c gbx_stream_pipe.c gbx_stream_string.c \
gbx_project.h gbx_project.c \
gbx_library.h gbx_library.c \
......
......@@ -176,6 +176,8 @@ void STREAM_open(STREAM *stream, const char *path, int mode)
sclass = &STREAM_string;
else if (mode & STO_LOCK)
sclass = &STREAM_lock;
else if (mode & STO_NULL)
sclass = &STREAM_null;
else
{
// ".99" is used for opening a file descriptor in direct mode
......
......@@ -129,6 +129,13 @@ typedef
}
STREAM_STRING;
typedef
struct {
STREAM_COMMON common;
intptr_t pos;
}
STREAM_NULL;
typedef
union STREAM {
STREAM_CLASS *type;
......@@ -141,6 +148,7 @@ typedef
STREAM_ARCH arch;
STREAM_PROCESS process;
STREAM_STRING string;
STREAM_NULL null;
}
STREAM;
......@@ -157,7 +165,8 @@ enum {
STO_WATCH = (1 << 6),
STO_PIPE = (1 << 7),
STO_MEMORY = (1 << 8),
STO_STRING = (1 << 9)
STO_STRING = (1 << 9),
STO_NULL = (1 << 10)
};
enum {
......@@ -178,7 +187,7 @@ EXTERN STREAM_CLASS STREAM_memory;
EXTERN STREAM_CLASS STREAM_arch;
EXTERN STREAM_CLASS STREAM_process;
EXTERN STREAM_CLASS STREAM_string;
/*EXTERN STREAM_CLASS STREAM_null;*/
EXTERN STREAM_CLASS STREAM_null;
#else
......
/***************************************************************************
gbx_stream_null.c
(c) 2000-2019 Benoît Minisini <g4mba5@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#define __STREAM_IMPL_C
#include "gb_common.h"
#include "gbx_stream.h"
static int stream_open(STREAM *stream, const char *path, int mode)
{
stream->null.pos = 0;
stream->common.available_now = TRUE;
return FALSE;
}
static int stream_close(STREAM *stream)
{
return FALSE;
}
static int stream_read(STREAM *stream, char *buffer, int len)
{
return 0;
}
static int stream_write(STREAM *stream, char *buffer, int len)
{
stream->null.pos += len;
return len;
}
static int stream_seek(STREAM *stream, int64_t pos, int whence)
{
int64_t new_pos;
switch(whence)
{
case SEEK_SET:
new_pos = pos;
break;
case SEEK_CUR:
new_pos = stream->null.pos + pos;
break;
case SEEK_END:
return TRUE;
default:
return TRUE;
}
if (new_pos < 0)
return TRUE;
stream->null.pos = new_pos;
return FALSE;
}
static int stream_tell(STREAM *stream, int64_t *pos)
{
*pos = (int64_t)stream->null.pos;
return FALSE;
}
static int stream_flush(STREAM *stream)
{
return FALSE;
}
static int stream_eof(STREAM *stream)
{
return TRUE;
}
static int stream_lof(STREAM *stream, int64_t *len)
{
*len = 0;
return TRUE;
}
static int stream_handle(STREAM *stream)
{
return -1;
}
DECLARE_STREAM(STREAM_null);
......@@ -119,7 +119,7 @@ BEGIN_PROPERTY(__name##_Left)
__return(__this->x); \
else \
{ \
__ctype dx = VPROP(__gtype) - __this->x; \
__ctype dx = VPROP(__gtype) - __this->x; \
if (dx > __this->w) \
dx = __this->w; \
\
......@@ -135,7 +135,7 @@ BEGIN_PROPERTY(__name##_Top)
__return(__this->y); \
else \
{ \
__ctype dy = VPROP(__gtype) - __this->y; \
__ctype dy = VPROP(__gtype) - __this->y; \
if (dy > __this->h) \
dy = __this->h; \
\
......