Commit c9b6d7f3 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Some library fixes

Fix for problem passing long command lines via system(), while there are good arguments to leave the threshold at 255, non DDEUtils aware programs get brutally truncated command strings, and since the old threshold of 255 applied when the kernel handled 256 command lines, upping the limit to 1k is no worse than before.
Fix for Edit failing to draw lines of text longer than 192 characters (ticket #350). Several factors were conspiring here: on a mode change the window width in characters wasn't being clamped, whereas user entered limits in the menu were, then the internal buffer ("PAINTBUFSIZE") was too short so lines got truncated, and when larger than 256 got wrapped modulo 256 due to the use of an array of chars. Now set at compile time with BIG_WINDOW_SIZE_LIMIT with a new theoretical maximum of 8192. Currently limited to 480 since it uses stack variables.

In the C library:
 armsys.c: adapt the threshold at which to use DDEUtils based on the kernel version number
 scanf.c: squash a warning
 time.c: mark the table of month lengths as constant so we can claw back 13 words of static workspace without having to change the stubs

In RISC OS lib:
 bbc.c: remove local definitions of some SWI numbers
 template.c: squash a warning
 txt.c: delete Modula-2 support
 txt1.c: compare pointer with NULL not an integer
 txtar.c: introduce BIG_WINDOW_SIZE_LIMIT, rationalise a few sprintf's, mark private functions as static
 txtundo.c/txtedit.c: squash old style function warnings
 txtoptmenu.c: clamp the window width read from Edit$Options properly, delete long disabled code
 txtscrap.c: dead function deleted


Version 5.78. Tagged as 'RISC_OSLib-5_78'
parent df9e8415
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "5.77"
Module_Version SETA 577
Module_MajorVersion SETS "5.78"
Module_Version SETA 578
Module_MinorVersion SETS ""
Module_Date SETS "24 Mar 2013"
Module_ApplicationDate SETS "24-Mar-13"
Module_Date SETS "24 Oct 2013"
Module_ApplicationDate SETS "24-Oct-13"
Module_ComponentName SETS "RISC_OSLib"
Module_ComponentPath SETS "castle/RiscOS/Sources/Lib/RISC_OSLib"
Module_FullVersion SETS "5.77"
Module_HelpVersion SETS "5.77 (24 Mar 2013)"
Module_FullVersion SETS "5.78"
Module_HelpVersion SETS "5.78 (24 Oct 2013)"
END
/* (5.77)
/* (5.78)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 5.77
#define Module_MajorVersion_CMHG 5.78
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 24 Mar 2013
#define Module_Date_CMHG 24 Oct 2013
#define Module_MajorVersion "5.77"
#define Module_Version 577
#define Module_MajorVersion "5.78"
#define Module_Version 578
#define Module_MinorVersion ""
#define Module_Date "24 Mar 2013"
#define Module_Date "24 Oct 2013"
#define Module_ApplicationDate "24-Mar-13"
#define Module_ApplicationDate "24-Oct-13"
#define Module_ComponentName "RISC_OSLib"
#define Module_ComponentPath "castle/RiscOS/Sources/Lib/RISC_OSLib"
#define Module_FullVersion "5.77"
#define Module_HelpVersion "5.77 (24 Mar 2013)"
#define Module_LibraryVersionInfo "5:77"
#define Module_FullVersion "5.78"
#define Module_HelpVersion "5.78 (24 Oct 2013)"
#define Module_LibraryVersionInfo "5:78"
......@@ -67,7 +67,7 @@ const char *_clib_version(void)
#undef str
#undef xstr
static int unused[3];
static int unused[15];
/* timing things... */
......@@ -626,8 +626,9 @@ void _terminate_getenv(void)
#define DDEUtils_SetCLSize 0x42581
#define DDEUtils_SetCL 0x42582
#define DDEUtils_FlushCL 0x4258B
#endif
static int _cli_limit;
#endif
int system(const char *string)
{
#define CALL 0
......@@ -666,7 +667,7 @@ int system(const char *string)
}
#ifdef DDE
cmd_string = 0;
if (strlen(string) > 255) {
if (strlen(string) >= _cli_limit) {
s = (char *)string;
while (*s == ' ') s++;
cmd = s;
......@@ -718,6 +719,12 @@ void _armsys_lib_init(void)
(void) unused;
_getenv_value = NULL;
_error_recursion = 0;
#ifdef DDE
if ((_kernel_osbyte(129, 0, 255) & 0xFF) >= 0xA8)
_cli_limit = 1024; /* Ursula long command lines */
else
_cli_limit = 256; /* Pre Ursula shorter ones */
#endif
_ctype_init(); /* C locale */
_exit_init(); /* must happen before exit() can be called */
_signal_init(); /* had better be done pretty early */
......
......@@ -790,7 +790,7 @@ case '%': { int field = 0, flag = 0;
for (i=0; i<8; i++) charmap[i] = 0;
/* the 'do' next allows special treatment of %[]})] */
do { if (fch==0) return cnt; /* %[... unterminated */
charmap[fch/32] |= 1uL<<(fch%32);
charmap[fch/32] |= 1u<<(fch%32);
} while ((fch = *fmt++) != ']');
if (negated) for (i=0; i<8; i++)
charmap[i] = ~charmap[i];
......
......@@ -44,7 +44,7 @@ extern int __locales[5];
/* N.B. clock() and time() are defined in armsys.c */
static int monlen[13] = { 31,29,31,30,31,30,31,31,30,31,30,31,0x40000000 };
static const int monlen[13] = { 31,29,31,30,31,30,31,31,30,31,30,31,0x40000000 };
double difftime(time_t time1, time_t time0)
{ return (double)time1 - (double)time0;
......
......@@ -67,6 +67,10 @@ typedef struct {
#ifdef BIG_WINDOWS
BOOL big_windows;
int big_window_size;
#define BIG_WINDOW_SIZE_LIMIT 480 /* Measured in characters. Mostly arbitrary: the writable icon will
limit you to 3 digits, the 16 bit offsets will limit you to
2^14 (worst case when whole buffer gets expanded to '[hh]'), the
VDU should be good to 2^15/(bbc_GCharSpaceX in EX2) = 8192 */
#endif
} txtar_options;
/* Future fields may be added to this record in the future. So, always
......
......@@ -42,9 +42,6 @@
#include "swis.h"
#define XOS_Write0 0x00000002 | os_X
#define XOS_Plot 0x00000045 | os_X
/* Sound SWIs */
#define Configure 0x00040140
......@@ -261,7 +258,7 @@ os_error *bbc_gcol(int a, int b)
/* Perform an operating system plot operation. Plot number, x, y. */
os_error *bbc_plot(int n, int x, int y)
{
return(os_swi3(XOS_Plot, n, x, y));
return(os_swix3(OS_Plot, n, x, y));
}
/* Move graphics cursor to an absolute position. */
......@@ -402,7 +399,7 @@ os_error *bbc_tab(int x, int y)
/* Print a null-terminated string to the screen. */
os_error *bbc_stringprint(char *s)
{
return(os_swi1(XOS_Write0, (int) s));
return(os_swix1(OS_Write0, (int) s));
}
/* ----------- Sound ----------- */
......
......@@ -134,7 +134,7 @@ template *template_copy(template *from)
return to;
}
BOOL (template_readfile)(char *filename)
static BOOL (template_readfile)(char *filename)
{
template *to; /* for insertion into linked list */
int sprites = 0; /* are sprites used? */
......
......@@ -368,306 +368,4 @@ void txt_init(void)
return; /* @@@ Do nothing for the moment (maybe one day) */
}
/* -------- STUBS FOR M2. -------- */
#if FALSE
/* -------- Modula-2 equivalents. -------- */
txt Texts_New(char *title);
void Texts_Show(txt t);
void Texts_Hide(txt t);
void Texts_SetTitle(txt t, char* title);
void Texts_Dispose(txt *t);
/* -------- General control operations. -------- */
int Texts_BufSize(txt t);
int Texts_SetBufSize(txt t, int s);
txt_overflowaction Texts_OAction(txt);
void Texts_SetOAction(txt t, txt_overflowaction);
txt_charoption Texts_CharOptions(txt);
void Texts_SetCharOptions(txt t, txt_charoption affect, txt_charoption values);
/* -------- Operations on the array of characters. -------- */
txt_index Texts_Dot(txt);
txt_index Texts_Size(txt); /* max value that dot can take */
void Texts_SetDot(txt t, txt_index);
void Texts_MoveDot(txt t, int by);
void Texts_InsertChar(txt t, char);
void Texts_InsertString(txt t, char*);
void Texts_Delete(txt t, int);
void Texts_ReplaceChars(txt t, int ntodelete, char*, int n);
char Texts_CharAtDot(txt);
char Texts_CharAt(txt t, txt_index);
void Texts_CharsAtDot(txt t, char*/*out*/ buffer, int* /*inout*/ n);
/* -------- Layout-dependent Operations. -------- */
void Texts_MoveVertical(txt t, int by, int caretstill);
void Texts_MoveHorizontal(txt t, int by);
int Texts_VisibleLineCount(txt);
int Texts_VisibleColCount(txt);
/* -------- Operations on Markers. -------- */
void Texts_NewMarker(txt t, txt_marker*);
void Texts_MoveMarker(txt t, txt_marker*, txt_index to);
void Texts_MoveDotToMarker(txt t, txt_marker*);
txt_index Texts_IndexOfMarker(txt t, txt_marker*);
void Texts_DisposeMarker(txt t, txt_marker*);
/* -------- Operations on the selection. -------- */
int Texts_SelectSet(txt); /* returns 1 or 0 */
txt_index Texts_SelectStart(txt);
txt_index Texts_SelectEnd(txt);
void Texts_SetSelect(txt t, txt_index start, txt_index end);
/* -------- Input from the user -------- */
txt_eventcode Texts_Get(txt);
int Texts_Queue(txt);
void Texts_EventHandler(txt t, void(e)(txt,void*), void*);
/* -------- Direct Access to the array of characters. -------- */
void Texts_ArraySegment(txt t, txt_index at, char **a, int *n);
/* -------- System hook. -------- */
int Texts_SysHandle(txt);
/* end */
/*************************************/
txt txt_new(char *title)
{
return(Texts_New(title));
}
void txt_show(txt t)
{
Texts_Show(t);
}
void txt_hide(txt t)
{
Texts_Hide(t);
}
void txt_settitle(txt t, char* title)
{
Texts_SetTitle(t, title);
}
void txt_dispose(txt *t)
{
Texts_Dispose(t);
}
/* -------- General control operations. -------- */
int txt_bufsize(txt t)
{
return Texts_BufSize(t);
}
int txt_setbufsize(txt t, int size)
{
return Texts_SetBufSize(t, size);
}
txt_overflowaction txt_oaction(txt t)
{
return Texts_OAction(t);
}
void txt_setoaction(txt t, txt_overflowaction o)
{
Texts_SetOAction(t, o);
}
txt_charoption txt_charoptions(txt t)
{
return Texts_CharOptions(t);
}
void txt_setcharoptions(txt t, txt_charoption affect, txt_charoption values)
{
Texts_SetCharOptions(t, affect, values);
}
/* -------- Operations on the array of characters. -------- */
txt_index txt_dot(txt t)
{
return Texts_Dot(t);
}
txt_index txt_size(txt t) /* max value that dot can take */
{
return Texts_Size(t);
}
void txt_setdot(txt t, txt_index i)
{
Texts_SetDot(t, i);
}
void txt_movedot(txt t, int by)
{
Texts_MoveDot(t, by);
}
void txt_insertchar(txt t, char c)
{
Texts_InsertChar(t, c);
}
void txt_insertstring(txt t, char* s)
{
Texts_InsertString(t, s);
}
void txt_delete(txt t, int n)
{
Texts_Delete(t, n);
}
void txt_replacechars(txt t, int ntodelete, char* chars, int n)
{
Texts_ReplaceChars(t, ntodelete, chars, n);
}
char txt_charatdot(txt t)
{
return Texts_CharAtDot(t);
}
char txt_charat(txt t, txt_index i)
{
return Texts_CharAt(t, i);
}
void txt_charsatdot(txt t, char/*out*/ *buffer, int /*inout*/ *n)
{
Texts_CharsAtDot(t, buffer, n);
}
/* -------- Layout-dependent Operations. -------- */
void txt_movevertical(txt t, int by, int caretstill)
{
Texts_MoveVertical(t, by, caretstill);
}
void txt_movehorizontal(txt t, int by)
{
Texts_MoveHorizontal(t, by);
}
int txt_visiblelinecount(txt t)
{
return Texts_VisibleLineCount(t);
}
int txt_visiblecolcount(txt t)
{
return Texts_VisibleColCount(t);
}
/* -------- Operations on Markers. -------- */
void txt_newmarker(txt t, txt_marker* m)
{
Texts_NewMarker(t, m);
}
void txt_movemarker(txt t, txt_marker* m, txt_index to)
{
Texts_MoveMarker(t, m, to);
}
void txt_movedottomarker(txt t, txt_marker* m)
{
Texts_MoveDotToMarker(t, m);
}
txt_index txt_indexofmarker(txt t, txt_marker* m)
{
return Texts_IndexOfMarker(t, m);
}
void txt_disposemarker(txt t, txt_marker* m)
{
Texts_DisposeMarker(t, m);
}
/* -------- Operations on the selection. -------- */
int txt_selectset(txt t) /* returns 1 or 0 */
{
return Texts_SelectSet(t);
}
txt_index txt_selectstart(txt t)
{
return Texts_SelectStart(t);
}
txt_index txt_selectend(txt t)
{
return Texts_SelectEnd(t);
}
void txt_setselect(txt t, txt_index start, txt_index end)
{
Texts_SetSelect(t, start, end);
}
/* -------- Input from the user -------- */
txt_eventcode txt_get(txt t)
{
return Texts_Get(t);
}
int txt_queue(txt t)
{
return Texts_Queue(t);
}
void txt_eventhandler(txt t, void(e)(txt,void*), void* handle)
{
Texts_EventHandler(t, e, handle);
}
/* -------- Direct Access to the array of characters. -------- */
void txt_arrayseg(txt t, txt_index at, char **a, int *n)
{
Texts_ArraySegment(t, at, a, n);
}
/* -------- System hook. -------- */
int txt_syshandle(txt t)
{
return Texts_SysHandle(t);
}
#endif
/* end */
......@@ -1860,15 +1860,9 @@ static void txt1__paintcall(
/* >>>> Limit the number of calls? to how many? 3*no of lines perhaps? */
{
txt1_call *c = malloc(sizeof(txt1_call));
#if FALSE
if (c == 0) {
tracef0("txt1/malloc store problem.\n");
c = malloc(sizeof(txt1_call));
};
#endif
if (c == 0) {
werr(TRUE, msgs_lookup(MSGS_txt49));
};
if (c == NULL) {
werr(TRUE, msgs_lookup(MSGS_txt49));
}
c->x = x;
c->y = y;
c->ad = ad;
......
......@@ -76,6 +76,8 @@
#include "VerIntern/messages.h"
#define UNICODE
#define WIMPSETFONTCOLOUR TRUE
#define INVERTSELECTION TRUE
/*#ifdef UNICODE
#include "utf8.h"
......@@ -83,24 +85,19 @@
/* -------- Forward references -------- */
void txtar__redrawtext(txt t);
void txtar__fontpaintseveral(
txt t,
txt1_call *calls,
wimp_box *grclip /*in*/,
BOOL alreadycorrect);
static void txtar__redrawtext(txt t);
void txtar__doopenevent(txt t, wimp_openstr *o /*in*/);
static void txtar__fontpaintseveral(txt, txt1_call *, wimp_box *, BOOL);
void txtar__dobuttonevent(txt t, wimp_eventstr *e /*in*/);
static void txtar__doopenevent(txt t, wimp_openstr *o /*in*/);
void txtar__docharevent(txt t, txt_eventcode e);
static void txtar__dobuttonevent(txt t, wimp_eventstr *e /*in*/);
void txtar__dodrag(txt t);
static void txtar__docharevent(txt t, txt_eventcode e);
void txtar__dothumb(txt t, int offset);
static void txtar__dodrag(txt t);
static void txtar__dothumb(txt t, int offset);
/* -------- Data for each window. -------- */
......@@ -147,7 +144,7 @@ file within the window imagewidth excludes the left hand pixel border. */
/* -------- Static variables -------- */
static txtar__sysdata *all = 0; /* list of all sysdata records. */
static txtar__sysdata *all = NULL; /* list of all sysdata records. */
static BOOL txtar__withinredraw = FALSE; /* see txtar__redrawwindow */
static BOOL txtar__redrawdone = FALSE;
......@@ -205,13 +202,6 @@ static int txtar__screenheight(void)
return (1 + bbc_vduvar(bbc_YWindLimit)) << bbc_vduvar(bbc_YEigFactor);
}
#if FALSE
int txtar__scrollbarwidth(void)
{
return 52; /* >>>> bodge! */
}
#endif
static int txtar__max(int a, int b) {return(a > b ? a : b);}
static int txtar__min(int a, int b) {return(a < b ? a : b);}
......@@ -224,16 +214,11 @@ static void txtar__setmode(txtar__sysdata *s) {
t->w->highlight_reversable = wimpt_bpp() <= 4;
s->screenmode = wimpt_mode();
#if FALSE
s->sysfontwidth = 8 * wimpt_dx(); /* >>>> read variable! */
s->sysfontheight = 8 * wimpt_dy();
#else
s->sysfontwidth = wimpt_dx() * bbc_vduvar(bbc_GCharSpaceX);
s->sysfontheight = wimpt_dy() * bbc_vduvar(bbc_GCharSpaceY);
#ifdef BIG_WINDOWS
if (!s->o.big_windows)
s->o.big_window_size = screenwidth/s->sysfontwidth - 3;
#endif
s->o.big_window_size = txtar__min(screenwidth/s->sysfontwidth - 3 /*scrollbar*/, BIG_WINDOW_SIZE_LIMIT);
#endif
}
......@@ -610,10 +595,10 @@ void txtar_setoptions(txt t, txtar_options *o /*in*/)
char a[MAXSYSVARSIZE];
txtar__sysdata *s = (txtar__sysdata*) t->w->syshandle;
#ifdef SETOPTIONS
strcpy(a, "*Set ");
strcpy(a, "Set ");
strncat(a, txtopt_get_name(), MAXSYSVARSIZE-1);
strncat(a, "$Options", MAXSYSVARSIZE-1);
sprintf(a+strlen(a), " f%i b%i l%i m%i h%i w%i %s",
sprintf(a+strlen(a), " f%i b%i l%i m%i h%i w%i%s",
s->o.forecolour,
s->o.backcolour,
s->o.leading,
......@@ -622,7 +607,7 @@ void txtar_setoptions(txt t, txtar_options *o /*in*/)
s->o.fontwidth,
(s->o.wraptowindow ? " r" : ""));
#else
sprintf(a, "*Set Edit$Options f%i b%i l%i m%i h%i w%i%s",
sprintf(a, "Set Edit$Options f%i b%i l%i m%i h%i w%i%s",
s->o.forecolour,
s->o.backcolour,
s->o.leading,
......@@ -632,9 +617,9 @@ void txtar_setoptions(txt t, txtar_options *o /*in*/)
(s->o.wraptowindow ? " r" : ""));
#endif
#ifdef SET_MISC_OPTIONS
if (s->o.overwrite) sprintf(a+strlen(a), " O");
if (!s->o.wordtab) sprintf(a+strlen(a), " T");
if (s->o.wordwrap) sprintf(a+strlen(a), " D");
if (s->o.overwrite) strcat(a, " O");
if (!s->o.wordtab) strcat(a, " T");
if (s->o.wordwrap) strcat(a, " D");
if (s->o.undosize != 5000) sprintf(a+strlen(a), " u%i", s->o.undosize);
#endif
#ifdef BIG_WINDOWS
......@@ -656,6 +641,13 @@ void txtar_setoptions(txt t, txtar_options *o /*in*/)
/* -------- Painting. -------- */
#define PAINTBUFSIZE 484
#ifdef BIG_WINDOWS
#if (BIG_WINDOW_SIZE_LIMIT+4) > PAINTBUFSIZE
#error "Can't paint that window reliably"
#endif
#endif
static void txtar__rawsetsize(txt t)
/* We can count on t->s->d being accurate about the current state of
things. We must reset the extent of the work area so that arthur redraws
......@@ -803,7 +795,7 @@ static void txtar__expandchars(
char *a,
int n, /* number of chars */
char *cbuf /*out*/, /* where to put expanded chars */
char *obuf /*out*/, /* matching offset into original string */
short *obuf /*out*/, /* matching offset into original string */
int bufsize, /* cbuf and obuf sizes */
int *nchars /*inout*/) /* no of output chars */
/* Expands the characters of the string out into the buffer, with funny
......@@ -922,9 +914,6 @@ void txtar__safewrch(char c)
}
#endif