Commit 609d3219 authored by ROOL's avatar ROOL 🤖
Browse files

This commit was manufactured by cvs2git to create tag 'initial'.

Sprout from master 1999-11-16 14:48:43 UTC Stewart Brodie <sbrodie@gitlab.riscosopen.org> '  Import of assembler headers which declare Toolbox SWI symbols.'
Delete:
    !MkClean,fd7
    !MkExpHdr,fd7
    !MkExpLib,fd7
    Makefile
    VersionNum
    c/debug
    c/mem
    c/messages
    c/objsupport
    c/rmensure
    c/slist
    c/string32
    h/colpicker
    h/const
    h/debug
    h/macros
    h/mem
    h/messages
    h/objsupport
    h/os
    h/rmensure
    h/services
    h/slist
    h/string32
    h/style
    h/toolboxmem
    h/twimp
    objects/h/DCS
    objects/h/Quit
    objects/h/colourdbox
    objects/h/colourmenu
    objects/h/fileinfo
    objects/h/fontdbox
    objects/h/fontmenu
    objects/h/generic
    objects/h/iconbar
    objects/h/menu
    objects/h/printdbox
    objects/h/proginfo
    objects/h/saveas
    objects/h/scale
    objects/h/toolbox
    objects/h/window
    s/toolboxmem
parent cb30a819
| Copyright 1997 Acorn Computers Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
Dir <Obey$Dir>
amu_machine clean
| Copyright 1997 Acorn Computers Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
Dir <Obey$Dir>
amu_machine export_hdrs
| Copyright 1997 Acorn Computers Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
Dir <Obey$Dir>
amu_machine export_libs
hdr/** gitlab-language=armasm linguist-language=armasm linguist-detectable=true
s/** gitlab-language=armasm linguist-language=armasm linguist-detectable=true
c/** gitlab-language=c linguist-language=c linguist-detectable=true
h/** gitlab-language=c linguist-language=c linguist-detectable=true
**/h/** gitlab-language=c linguist-language=c linguist-detectable=true
# Copyright 1996 Acorn Computers Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Makefile for tboxlib and debuglib
#
# ***********************************
# *** C h a n g e L i s t ***
# ***********************************
# Date Name Description
# ---- ---- -----------
# 09 Oct 1997 RWB Tidied up old Toolbox.Common build
#
#
# Paths
#
LIBDIR = <Lib$Dir>
#
# Generic options:
#
MKDIR = cdir
AS = objasm
CC = cc
CMHG = cmhg
CP = copy
LD = link
RM = remove
WIPE = -wipe
CD = dir
LIBFILE = libfile
CFLAGS = -c -depend !Depend -Wap -zps0 ${INCLUDES} -fah -Fn ${DFLAGS}
CFLAGSZM = -c -depend !Depend -Wap -zps1 ${INCLUDES} -fah -Fn ${DFLAGS} -zM
CPFLAGS = ~cfr~v
WFLAGS = ~c~v
LIBFILEFLAGS = -c -o $@
CCZM= ${CC} ${CFLAGSZM}
#
# Libraries
#
CLIB = CLIB:o.stubs
RLIB = RISCOSLIB:o.risc_oslib
RSTUBS = RISCOSLIB:o.rstubs
ROMSTUBS = RISCOSLIB:o.romstubs
ROMCSTUBS = RISCOSLIB:o.romcstubs
ABSSYM = RISC_OSLib:o.AbsSym
#
# Include files
#
INCLUDES = -IC:,<Lib$Dir>.tboxlibint.
DFLAGS =
# Program specific options:
#
TBOXLIB = tboxlib
TBOXLIBZM = tboxlibm
DEBUGLIB = debuglib
DEBUGLIBZM = debuglibm
EXPORTS = ${LIBDIR}.tboxlibint
OBJ = o.mem o.messages o.string32 o.rmensure o.objsupport o.slist o.toolboxmem
OBJZM = z.mem z.messages z.string32 z.rmensure z.objsupport z.slist z.toolboxmem
DBG_OBJ = o.debug
DBG_OBJZM = z.debug
#
# Rule patterns
#
.SUFFIXES: .z .o .c .s
.c.o:; ${CC} ${CFLAGS} -o $@ $<
.c.z:; ${CCZM} -c -o $@ $<
.s.o:; ${AS} ${ASFLAGS} -o $@ $<
.s.z:; ${AS} ${ASFLAGS} -o $@ $<
#
# Build
#
${TBOXLIB}: ${OBJ}
${LIBFILE} ${LIBFILEFLAGS} ${OBJ}
${TBOXLIBZM}: ${OBJZM}
${LIBFILE} ${LIBFILEFLAGS} ${OBJZM}
${DEBUGLIB}: ${OBJ} ${DBG_OBJ}
${LIBFILE} ${LIBFILEFLAGS} ${OBJ} ${DBG_OBJ}
${DEBUGLIBZM}: ${OBJZM} ${DBG_OBJZM}
${LIBFILE} ${LIBFILEFLAGS} ${OBJZM} ${DBG_OBJZM}
clean:
${WIPE} o.* ${WFLAGS}
${WIPE} z.* ${WFLAGS}
${WIPE} ${DEBUGLIB} ${WFLAGS}
${WIPE} ${DEBUGLIBZM} ${WFLAGS}
${WIPE} ${TBOXLIB} ${WFLAGS}
${WIPE} ${TBOXLIBZM} ${WFLAGS}
@echo ${DEBUGLIB} and ${TBOXLIB}: cleaned
export: export_${PHASE}
export_hdrs: dirs
${CP} objects ${EXPORTS}.objects ${CPFLAGS}
${CP} h.* ${EXPORTS}.h.* ${CPFLAGS}
@echo ${DEBUGLIB} and ${TBOXLIB}: export complete (hdrs)
export_libs: ${TBOXLIB} ${TBOXLIBZM} ${DEBUGLIB} ${DEBUGLIBZM} dirs
${CP} ${TBOXLIB} ${EXPORTS}.o.${TBOXLIB} ${CPFLAGS}
${CP} ${TBOXLIBZM} ${EXPORTS}.o.${TBOXLIBZM} ${CPFLAGS}
${CP} ${DEBUGLIB} ${EXPORTS}.o.${DEBUGLIB} ${CPFLAGS}
${CP} ${DEBUGLIBZM} ${EXPORTS}.o.${DEBUGLIBZM} ${CPFLAGS}
@echo ${DEBUGLIB} and ${TBOXLIB}: export complete (libs)
dirs:
${MKDIR} ${LIBDIR}
${MKDIR} ${EXPORTS}
${MKDIR} ${EXPORTS}.h
${MKDIR} ${EXPORTS}.o
#
# Dynamic dependencies:
/* (0.04)
*
* This file is automatically maintained by srccommit, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 0.04
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 17 Mar 1999
#define Module_MajorVersion "0.04"
#define Module_Version 4
#define Module_MinorVersion ""
#define Module_Date "17 Mar 1999"
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: debug.c
* Purpose: debugging routines for the Toolbox
* Author: Ian Johnson
* History: 16-Sep-93: IDJ: created
*
*/
#include "debug.h"
#include "swis.h"
#include "kernel.h"
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#ifndef HostFS_HostVDU
#define HostFS_HostVDU 0x40100
#endif
#ifndef HostFS_TubeVDU
#define HostFS_TubeVDU 0x40101
#endif
#ifndef HostFS_WriteC
#define HostFS_WriteC 0x40102
#endif
static char output_buffer[256];
static char var_val[256] = "";
static char debug_var[256] = "";
static void host_out (char *format, ...);
void debug_dump (void *start, int length) {
_kernel_swi_regs regs;
char buffer[256];
char *address = start;
regs.r[0] = (int)"Hex$Dump";
regs.r[1] = (int)buffer;
regs.r[2] = 255;
regs.r[3] = 0;
regs.r[4] = 3;
_kernel_swi (OS_ReadVarVal, &regs, &regs);
if (regs.r[2] == 0) return;
{
int i, j, k, rows, columns;
int colour, word;
char *ptr,
chr;
enum { black, red, green, yellow, blue, magenta, cyan, white } colours;
char col[8][] = { "\x011\x00", "\x011\x01", "\x011\x02", "\x011\x03",
"\x011\x04", "\x011\x05", "\x011\x06", "\x011\x07"};
buffer[regs.r[2]] = '\0'; /* set correct terminator for end of string */
colour = (int) strstr (buffer, "colour");
word = (int) strstr (buffer, "word");
if ((ptr = strstr (buffer,"R")) == NULL)
rows = 24;
else
sscanf (ptr+1, "%d", &rows);
if (rows<3) rows = 3;
if ((ptr = strstr (buffer,"C")) == NULL)
columns = 16;
else
sscanf (ptr+1, "%d", &columns);
if (columns<4) columns = 4;
ptr = address;
while (ptr < address+length) {
host_out ("\n\r%sAddress ",colour?col[white]:"");
for (j=0;j<columns;j += word?4:1)
if (word)
host_out (" %02x ",(((int)ptr+j) & 0xff));
else
host_out (" %02x",(((int)ptr+j) & 0xff));
host_out (" Characters\n\r");
for (i=0;i<rows-2;i++) {
host_out ("%s%08x%s ",colour?col[cyan]:"",(int)ptr,colour?col[red]:"");
for (j=0;j<columns;j += word?4:1) {
if (ptr+j >= address+length) break;
if (word)
host_out (" %08x",*((int *)(ptr+j)));
else
host_out (" %02x",*(ptr+j));
}
if (j < columns)
for (k=0;k<columns-j;k += word?4:1)
host_out (word?" ":" ");
host_out (" %s",colour?col[magenta]:"");
for (j=0;j<columns;j++) {
if (ptr+j >= address+length) break;
chr = *(ptr+j);
host_out ("%s%c%s",(chr<32?(colour?col[white]:""):""),(chr<32?'.':chr),(chr<32?(colour?col[magenta]:""):""));
}
ptr += j;
host_out ("\n\r");
if (ptr >= address+length) break;
}
}
host_out ("\x014");
}
}
void host_out (char *format, ...) {
va_list args;
char *ptr, buffer[1024];
_kernel_swi_regs regs;
va_start (args, format);
vsprintf (buffer, format, args);
ptr = buffer;
while (*ptr != '\0') {
regs.r[0] = *ptr;
_kernel_swi (HostFS_WriteC, &regs, &regs);
ptr++;
}
va_end (args);
}
extern void debug_set_var_name (char *var_name)
{
strcpy (debug_var, var_name);
}
extern void debug_output (char *allow, char *string, ...)
{
/*
* Function to output the given variable list down the tube. String is a
* printf format string. String is only printed if the given allow string
* appears in the system variable debug_var
*
*/
_kernel_swi_regs regs;
_kernel_oserror *e;
va_list args;
char *p;
va_start(args, string);
regs.r[0] = (int)debug_var;
regs.r[1] = (int)var_val;
regs.r[2] = 255;
regs.r[3] = 0;
regs.r[4] = 3;
_kernel_swi (OS_ReadVarVal, &regs, &regs);
var_val[regs.r[2]] = '\0';
if ((strstr (var_val, allow) != NULL) || !strcmp (allow, "force"))
{
vsprintf (output_buffer, string, args);
for (p = output_buffer; *p != '\0'; p++)
{
if ((*p >= ' ' && *p <= '~') || *p == '\n')
regs.r[0] = (int)*p;
else
regs.r[0] = '*';
_kernel_swi (HostFS_WriteC, &regs, &regs);
if (*p == '\n')
{
regs.r[0] = '\r';
_kernel_swi (HostFS_WriteC, &regs, &regs);
}
}
}
va_end(args);
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: mem.c
* Purpose: memory allocation in the Toolbox
* Author: Ian Johnson
* History: 6-Aug-93: IDJ: created
*/
/*
* This is a central memory allocation place for the Toolbox.
* A doubly-linked list of all allocated blocks is kept (maybe remove this
* if using too much memory!).
* To enable debugging of memory allocation, the calling functions should be
* compiled without -ff, so that fn names are in the code area. Compile
* this code with -DDEBUG_MEMORY.
* Memory tracing is turned on by setting the letter 'm' in the central
* debug string.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "kernel.h"
#include "swis.h"
#include "debug.h"
#include "mem.h"
#include "objects.toolbox.h"
#undef mem_allocate
#undef mem_free
#undef mem_print_list
#undef mem_extend
#undef mem_chk
#include "toolboxmem.h"
#define calloc(m,s) toolbox_memory_alloc_c((m)*(s))
#define free(p) toolbox_memory_free_c(p)
#define reallocate(b,by) toolbox_memory_extend_c(b,by)
typedef struct block
{
struct block *next; /* next one in the chain */
struct block *prev; /* previous one in the chain */
unsigned int size; /* size of allocated block */
#ifdef DEBUG_MEMORY
int guard; /* should be 'TBOX' */
char *fn; /* name of function which did the allocating */
char *tag; /* extra info entered by caller (eg line #) */
#endif
/* caller gets a pointer to here */
} mem__Block;
#define GUARD_WORD *(int *)"TBOX"
static mem__Block *mem__block_list = 0; /* linked list of all allocated blocks */
enum {
memorysys_USE_TOOLBOX = 1,
memorysys_USE_OWN_CODE = 2
};
static int memory_sys_flag = 0;
/* This function must only ever be called by the Toolbox module and is used to bypass the
* problem of not being able to call our own SWIs during module initialisation.
*/
extern void mem_i_am_the_toolbox (void)
{
memory_sys_flag = memorysys_USE_TOOLBOX;
}
extern void mem_init (void)
{
if (_swix(Toolbox_Memory, _INR(0,2), 2, 0, 0) == NULL) {
/* Then a suitable Toolbox module *was* present */
memory_sys_flag = memorysys_USE_TOOLBOX;
}
else {
memory_sys_flag = memorysys_USE_OWN_CODE;
}
}
static void *(reallocate)(void *p, int by)
{
/*
* own implementation of realloc, cos broken in 3.10
*/
DEBUG debug_output ("memory", "Reallocating %p to %d\n", p, by);
if (p == 0 || by == 0) /* not like real realloc! */
return 0;
else
{
void *newp;
if (_swix (OS_Module, _IN(0)|_INR(2,3)|_OUT(2),
13, /* extend RMA block */
p,
by,
&newp
) != 0)
{
DEBUG debug_output ("memory", "Failed\n");
return 0;
}
else
{
DEBUG debug_output ("memory", "Old p %p, new p %p\n", p, newp);
return newp;
}
}
}
static void *toolbox_memory_alloc_c(int s)
{
if (memory_sys_flag == memorysys_USE_TOOLBOX)
return toolbox_memory_alloc(s);
else if (memory_sys_flag == memorysys_USE_OWN_CODE)
return (calloc)(s, 1);
else {
mem_init();
return toolbox_memory_alloc_c(s);
}
}
static void toolbox_memory_free_c(void *p)
{
if (memory_sys_flag == memorysys_USE_TOOLBOX)
toolbox_memory_free(p);
else if (memory_sys_flag == memorysys_USE_OWN_CODE)
(free)(p);
else {
mem_init();
toolbox_memory_free_c(p);
}
}
static void *toolbox_memory_extend_c(void *b, int by)
{
if (memory_sys_flag == memorysys_USE_TOOLBOX)
return toolbox_memory_extend(b, by);
else if (memory_sys_flag == memorysys_USE_OWN_CODE)
return (reallocate)(b, by);
else {
mem_init();
return toolbox_memory_extend_c(b, by);
}
}
static void mem__add_block (mem__Block *b)
{
/*
* Function to add an element to the linked list of memory blocks
* (add at head of list)
*/
b->next = mem__block_list;
b->prev = NULL;
if (mem__block_list != NULL)
mem__block_list->prev = b;
mem__block_list = b;
b->size = 0;
#ifdef DEBUG_MEMORY
b->fn = 0;
b->tag = 0;
#endif
}
static void mem__remove_block (mem__Block *b)
{
/*
* Function to remove an element from the linked list of memory blocks
*
*/
if (b == mem__block_list)
{
mem__block_list = b->next;
if (b->next != NULL)
b->next->prev = NULL;
}
else
{
b->prev->next = b->next;
if (b->next != NULL)
b->next->prev = b->prev;
}
}
/********************************* MEMORY DEBUGGING CODE *****************************/
#ifdef DEBUG_MEMORY
static unsigned int mem__total_size (void)
{
/*
* Function to return total memory usage
*
*/
mem__Block *b = mem__block_list;
int total = 0;
while (b != NULL)
{
total += b->size;
b = b->next;
}
return total;
}
extern void mem_print_list (void)
{
/*
* Function to print out list of currently allocated blocks
*
*/
mem__Block *b;
b = mem__block_list;
debug_output ("memory", "Memory usage\n");
debug_output ("memory", "------------\n");
debug_output ("memory", "Block size allocated by tag\n");
debug_output ("memory", "----- ---- ------------ ---\n");
while (b != NULL)
{
debug_output ("memory", "%08.8p %08.8d %-33.33s %s\n",
(void *)(b+1),
b->size,
(b->fn)?b->fn:"<unknown fn>",
(b->tag)?b->tag:"<unknown tag>");
b = b->next;
}
debug_output ("memory", "------------------------------\n");
debug_output ("memory", "Total %08.8d\n", mem__total_size());
debug_output ("memory", "------------------------------\n");
}
extern void mem_chk (void *ptr, unsigned int flags, int line, char *file)
{
/*
* Types of memory check:
*
* CHECK_HEAP
* CHECK_NONZERO
*/
_kernel_swi_regs regs;
int carry;
if (ptr == 0)
{
if (flags & CHECK_NONZERO)
debug_output ("memory", "Warning: ptr is zero: %d %s\n", line, file);
return; /* zero is OK */
}
if (flags & CHECK_HEAP)
{
/* check the ptr is inside one of our allocated blocks */
mem__Block *b = mem__block_list;
while (b != NULL)
{
if (ptr <= (void *)((char *)(b+1) + b->size)) /* it's pointing inside this block */
return;
b = b->next;
}
debug_output ("memory", "Warning: ptr is not in a currently allocated block %d %s\n", line, file);
return;
}
/* finally do an OS_ValidateAddress on the ptr */
regs.r[0] = (int)ptr;
regs.r[1] = (int)ptr;
_kernel_swi_c (OS_ValidateAddress, &regs, &regs, &carry);
if (carry != 0)
debug_output ("memory", "Warning: ptr is not a valid address %d %s\n", line, file);
}
/* ------------------------------------ horrible hackery to get calling function name -------------------- */
static unsigned int fpoffz()
{
return 0;
}
static unsigned int *myfp()
{
unsigned int local;
return (unsigned int *)*(&local + 1 + fpoffz());
}
#define CALLER_FP() ((unsigned int *)(*(myfp()-3)))
static char *mem__get_fn_name (unsigned int *fp)
{
/*
* Given a pointer to a caller's frame (if any) this function returns
* its name which appears "before" it in the code area if the code
* has not been compiled cc -ff. If no name is found, returns 0
*
*/
/* --- search to find magic marker 0xff00XXXX, where XXXX is the length
of the function name --- */
int i;
char *name = 0;
unsigned int *code_wordp;
/*
* check the sanity of the address first!
*/
if (fp == 0)
return NULL;
else
code_wordp = (unsigned int *)(*fp & 0x03fffffc);
for (i = 0; i < 10; i++) /* same as backtrace code in C library (yuk) */
{
int w = *--code_wordp;
if ((w & 0xffff0000) == 0xff000000)
{
name = (char *)code_wordp - (w & 0xffff);
break;
}
}
return name;
}
/* -------------------------------- freeing memory --------------------------------- */
extern void mem_free (void *block, char *msg)
{
/*
* Function to free a given block, and output debugging info.
*
* We print out who allocated the block (+tag info), and who is
* doing the free.
* We also give current total memory usage.
*
*/
char *fn_name;
mem__Block *b = (mem__Block *)block - 1;
fn_name = mem__get_fn_name (CALLER_FP());
debug_output ("memory", "Freeing block %p from %s (%s) - [allocated from %s (%s)",
(void *)(b+1),
(fn_name)?fn_name:"<unknown fn>",
(msg)?msg:"<unknown tag>",
(b->fn)?b->fn:"<unknown fn>",
(b->tag)?b->tag:"<unknown tag>");
debug_output ("memory", "(%d)] %d", b->size, mem__total_size());
/* --- check guard word --- */
if (b->guard != GUARD_WORD)
debug_output ("memory", "\nInvalid guard word in memory block - block start at %p\n", block);
/* --- remove it from list of allocated blocks --- */
mem__remove_block(b);
/* --- free debug info from block --- */
if (b->fn)
{
free(b->fn);
}
if (b->tag)
{
free(b->tag);
}
/* --- ... and free the block itself --- */
free(b);
debug_output ("memory", " => %d\n", mem__total_size());
}
extern void mem_free_all (void)
{
mem__Block *b = mem__block_list, *next;
while (b != NULL)
{
next = b->next;
mem__remove_block (b);
if (b->fn)
free(b->fn);
if (b->tag)
free(b->tag);
free(b);
b = next;
}
}
/* -------------------------------- allocating memory ------------------------------ */
extern void *mem_allocate(unsigned int size, char *tag)
{
/*
* Function to allocate "size" bytes of store, with debugging info
*
* We store:
* - name of fn doing the allocating
* - size of requested store
* - extra info string
* - followed in memory by the "real" block
*
* All allocated memory blocks are stored in a linked list, so that
* we can easily work out how much is allocated at one time, and why.
*
* To get fn names caller must not be compiled -ff
* fn points at calling function, and we go back through the code area
* to find its textual name (use 0 if none there)
*
* Tag is some more info if appropriate
*
*/
char *fn_name = mem__get_fn_name(CALLER_FP());
mem__Block *new_block;
debug_output ("memory", "Allocating %d bytes in %s (%s) %d",
size,
(fn_name)?fn_name:"<unknown fn>",
(tag)?tag:"<no tag>",
mem__total_size(),
0);
/* --- allocate new block to put in list of all allocated blocks --- */
if ((new_block = (mem__Block *)calloc(sizeof(mem__Block) + size, sizeof(char))) == 0)
return 0;
mem__add_block (new_block);
/* --- mark it for checking --- */
new_block->guard = GUARD_WORD;
/* --- note the name of the calling function --- */
if (fn_name != NULL)
{
if ((new_block->fn = calloc(strlen (fn_name) + 1, sizeof(char))) == 0)
{
mem_free ((void *)(new_block+1), "no mem for fn name");
return 0;
}
strcpy (new_block->fn, fn_name);
}
/* --- note size of requested store --- */
new_block->size = size;
/* --- note tag passed by calling function --- */
if (tag != NULL)
{
if ((new_block->tag = calloc(strlen (tag) + 1, sizeof(char))) == 0)
{
mem_free ((void *)(new_block+1), "no mem for tag");
return 0;
}
strcpy (new_block->tag, tag);
}
/* --- return "real" block pointer to caller --- */
debug_output ("memory", " => %d [@%p]\n", mem__total_size(), (void *)(new_block+1));
return (void *)(new_block+1);
}
extern void *mem_extend (void *block, int by)
{
/*
* Function to extend an existing block of memory, with debugging info
*
*/
char *fn_name = mem__get_fn_name(CALLER_FP());
mem__Block *b;
mem__Block *old_b;
if (block == NULL)
return mem_allocate (by, "extend block 0");
b = (mem__Block *)block - 1;
old_b = b;
debug_output ("memory", "Extending block %p by %d bytes in %s (=>%d)",
b,
by,
(fn_name)?fn_name:"<unknown fn>",
mem__total_size());
/* --- extend existing block --- */
if ((b = (mem__Block *)reallocate((void *)b, by)) == 0)
return 0;
/* --- check to see if block has moved, and if so, update pointers --- */
if (old_b != b)
{
if (b->prev != NULL)
b->prev->next = b;
if (b->next != NULL)
b->next->prev = b;
if (old_b == mem__block_list)
mem__block_list = b;
}
/* --- adjust size of store --- */
b->size += by;
/* --- return "real" block pointer to caller --- */
debug_output ("memory", " => %d [@%p]\n", mem__total_size(), (void *)(b+1));
return (void *)(b+1);
}
#else
/* -------------------------------- freeing memory --------------------------------- */
extern void mem_free (void *block)
{
/*
* Function to free a given block.
*
*/
mem__Block *b = (mem__Block *)block - 1;
/* --- remove it from list of allocated blocks --- */
mem__remove_block (b);
/* --- ... and free the block itself --- */
free(b);
}
extern void mem_free_all (void)
{
mem__Block *b = mem__block_list, *next;
while (b != NULL)
{
next = b->next;
mem__remove_block (b);
free(b);
b = next;
}
}
/* -------------------------------- allocating memory ------------------------------ */
extern void *mem_allocate (unsigned int size)
{
/*
* Function to allocate "size" bytes of store.
*
* All allocated memory blocks are stored in a linked list, so that
* we can easily ensure it is freed on finalisation.
*
*/
mem__Block *new_block;
/* --- allocate new block to put in list of all allocated blocks --- */
if ((new_block = (mem__Block *)calloc(sizeof(mem__Block) + size, sizeof(char))) == 0)
return 0;
mem__add_block (new_block);
/* --- record size of block --- */
new_block->size = size;
/* --- return "real" block pointer to caller --- */
return (void *)(new_block+1);
}
extern void *mem_extend (void *block, int by)
{
/*
* Function to extend an existing block of memory
*
*/
mem__Block *b;
mem__Block *old_b;
if (block == NULL)
return mem_allocate (by);
b = (mem__Block *)block - 1;
old_b = b;
/* --- extend existing block --- */
if ((b = (mem__Block *)reallocate((void *)b, by)) == 0)
return 0;
/* --- check to see if block has moved, and if so, update pointers --- */
if (old_b != b)
{
if (b->prev != NULL)
b->prev->next = b;
if (b->next != NULL)
b->next->prev = b;
if (old_b == mem__block_list)
mem__block_list = b;
}
/* --- keep size up to date --- */
b->size += by;
/* --- return "real" block pointer to caller --- */
return (void *)(b+1);
}
#endif
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: messages.c
* Purpose: accessing an Object modules messages file (inc error reporting)
* Author: Timothy Roddis
* History: 24-Jan-94: IDJ: created from original TGR sources
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "objects.toolbox.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "twimp.h"
#include "style.h"
#include "messages.h"
static int messages_fd[4]; /* the messages file descriptor */
static _kernel_oserror global_error_block={0,0};
/* ------------------------------------ raising errors ---------------------------------------- */
extern _kernel_oserror *make_error (int err_num, int num_args, ...)
{
/*
* Generate a RISC OS error block.
*/
va_list ap;
char *s,
token [4];
int i=4;
_kernel_oserror *e;
_kernel_swi_regs regs = {0,0,0,0,0,0,0,0};
global_error_block.errnum = err_num;
num_args = (num_args>4)?4:num_args;
for (va_start (ap, num_args); num_args--; i++)
{
s = va_arg (ap, char *);
regs.r[i] = (int) ((s && *s) ? s : NULL); /* copy (pointer to args)s into registers */
}
sprintf (token, "E%02x", err_num&0x3f);
DEBUG debug_output ("error", "make_error: looking for %s\n", token);
regs.r[0] = (int) messages_fd;
regs.r[1] = (int) token;
regs.r[2] = (int) global_error_block.errmess;
regs.r[3] = sizeof global_error_block - sizeof global_error_block.errnum; /* 252! */
e = _kernel_swi (MessageTrans_Lookup, &regs, &regs); /* Hope this doesn't return an error */
DEBUG
{
if (e != NULL) debug_output ("error", "make_error: msgtrans error (%s)\n", e->errmess);
}
va_end (ap);
return &global_error_block;
}
extern _kernel_oserror *make_error_hex (int err_num, int num_args, ...)
{
/*
* Generate a RISC OS error block, with integer params printed in hex.
*/
va_list ap;
char arg[4][11] = { "\0","\0","\0","\0" };
int i,
n;
num_args = (num_args>4)?4:num_args;
va_start (ap, num_args);
for (i=0; i<num_args; i++)
{
n = va_arg (ap, int);
sprintf (arg[i], "0x%x",n);
}
va_end(ap);
return make_error (err_num, num_args, arg[0], arg[1], arg[2], arg[3]);
}
extern void raise_toolbox_error (int err_num, ObjectID object_id, ComponentID component_id, int num_args, ...)
{
/*
* Raise a Toolbox_Error event
*/
ToolboxErrorEvent error_block;
va_list ap;
char *s,
token [4];
int i=4;
_kernel_oserror *e;
_kernel_swi_regs regs = {0,0,0,0,0,0,0,0};
error_block.errnum = err_num;
num_args = (num_args>4)?4:num_args;
for (va_start (ap, num_args); num_args--; i++)
{
s = va_arg (ap, char *);
regs.r[i] = (int) ((s && *s) ? s : NULL); /* copy (pointer to args)s into registers */
}
regs.r[0] = (int) messages_fd;
regs.r[1] = (int) token;
regs.r[2] = (int) error_block.errmess;
regs.r[3] = sizeof global_error_block - sizeof global_error_block.errnum; /* 252! */
e = _kernel_swi (MessageTrans_Lookup, &regs, &regs); /* Hope this doesn't return an error */
error_block.hdr.event_code = Toolbox_Error;
regs.r[0] = 0;
regs.r[1] = (int) object_id;
regs.r[2] = component_id;
regs.r[3] = (int) &error_block;
e = _kernel_swi (Toolbox_RaiseToolboxEvent, &regs, &regs);
va_end (ap);
}
extern void raise_toolbox_error_hex (int err_num, ObjectID object_id, ComponentID component_id, int num_args, ...)
{
/*
* Raise a Toolbox_Error event, with integer parameters printed in hex
*/
va_list ap;
char arg[4][11] = { "\0","\0","\0","\0" };
int i=0,
n;
num_args = (num_args>4)?4:num_args;
va_start (ap, num_args);
for (i=0; i<num_args; i++)
{
n = va_arg (ap, int);
sprintf (arg[i], "0x%x",n);
}
raise_toolbox_error_hex (err_num, object_id, component_id, num_args, arg[0], arg[1], arg[2], arg[3]);
va_end(ap);
}
extern void raise_toolbox_oserror (_kernel_oserror *e, ObjectID object_id, ComponentID component_id)
{
/*
* Raise a Toolbox_Error event, given a RISC OS error block
*/
ToolboxErrorEvent error_block;
_kernel_swi_regs regs;
error_block.errnum = e->errnum;
strcpy (error_block.errmess, e->errmess);
error_block.hdr.event_code = Toolbox_Error;
error_block.hdr.size = 256-20-sizeof(ToolboxEventHeader)-sizeof(ObjectID)-sizeof(ComponentID);
regs.r[0] = 0;
regs.r[1] = (int) object_id;
regs.r[2] = component_id;
regs.r[3] = (int) &error_block;
e = _kernel_swi (Toolbox_RaiseToolboxEvent, &regs, &regs);
}
/* --------------------------------------- message file handling ------------------------------ */
extern _kernel_oserror *messages_file_open (char *messages_filename)
{
return _swix(MessageTrans_OpenFile, _INR(0,2), messages_fd, messages_filename, 0 /* use RMA */);
}
extern _kernel_oserror *messages_file_close (void)
{
return _swix (MessageTrans_CloseFile, _IN(0), messages_fd);
}
extern _kernel_oserror *messages_file_lookup (char *token, char *buffer, int *buffer_size, int num_args, ...)
{
va_list ap;
char *s;
int i = 4;
_kernel_oserror *e = NULL;
_kernel_swi_regs regs = {0,0,0,0,0,0,0,0};
num_args = (num_args>4)?4:num_args;
for (va_start (ap, num_args); num_args--; i++)
{
s = va_arg (ap, char *);
regs.r[i] = (int) ((s && *s) ? s : NULL); /* copy (pointer to args)s into registers */
}
regs.r[0] = (int) messages_fd;
regs.r[1] = (int) token;
regs.r[2] = (int) buffer;
regs.r[3] = (buffer && buffer_size)?*buffer_size:0;
e = _kernel_swi (MessageTrans_Lookup, &regs, &regs); /* Hope this doesn't return an error */
if (buffer == NULL && buffer_size != NULL)
*buffer_size = regs.r[3]+1; /* add one to allow for terminator */
va_end (ap);
return e;
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: objsupport.c
* Purpose: Support Library for object modules
* Author: Neil Kelleher
* History: 1-Jul-1994: NK: created
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include "kernel.h"
#include "swis.h"
#include "debug.h"
#include "objects.toolbox.h"
#include "objects.window.h"
#include "mem.h"
#include "objsupport.h"
#include "string32.h"
static _kernel_oserror *extract_gadget_info(char *tm,ComponentID id,void **p,int *l)
{
return _swix(Window_ExtractGadgetInfo, _INR(0,2) | _OUTR(0,1), 0,tm,id, p,l);
}
char *copy_template(char *name)
{
char *tm;
ObjectTemplateHeader *obj;
if(_swix(Toolbox_TemplateLookUp, _INR(0,1) | _OUT(0),0,name,&obj)) tm = NULL;
else {
tm = mem_allocate(obj->total_size,"template copy");
if(tm) {
memcpy(tm,obj,obj->total_size);
((ObjectTemplateHeader *)tm)->body =
(WindowTemplate *) (tm + ((int) ((WindowTemplate *) obj->body)) - ((int) obj));
((WindowTemplate *) (((ObjectTemplateHeader *)tm)->body))-> gadgets =
(Gadget *) (tm + ((int) ((WindowTemplate *) obj->body)->gadgets) - ((int) obj));
}
}
return tm;
}
_kernel_oserror *__zap_gadget(char *tm,ComponentID id,int off,int val)
{
_kernel_oserror *e=NULL;
int *p,l;
e=extract_gadget_info(tm,id,(void **) &p,&l);
if(!e) *(p+ off/sizeof(int)) = val;
return e;
}
_kernel_oserror *__zap_gadget_string(char *tm,ComponentID id,int off,const char* val,int offlen)
{
/* Zaps the string into the gadget template and checks the length against a length field
* in the same template, increasing the value if necessary
*/
int *p,l;
_kernel_oserror *e=__zap_gadget(tm,id,off,(int)val);
if (e) return e;
e=extract_gadget_info(tm,id,(void **) &p,&l);
if(!e) {
int cl=*(p+ offlen/sizeof(int));
int rl=string_length((char *)val)+1;
if (cl<rl) e=__zap_gadget(tm,id,offlen,rl);
}
return e;
}
int *__read_gadget(char *tm,ComponentID id,int off)
{
int *p,l;
if (extract_gadget_info(tm,id,(void **)&p,&l) == NULL)
return (p+ off/sizeof(int));
else return 0;
}
_kernel_oserror *__zap_window(char *tm,int off,int val)
{
char *p = (char *)((WindowTemplate *) (((ObjectTemplateHeader *)tm)->body));
DEBUG debug_output("objsupport","zapping word +%x with %x\n",off,val);
if ((((ObjectTemplateHeader *)tm)->version == 101) && (off >= offsetof(WindowTemplate,default_focus))) off -=24;
* ((int *) (p+off)) =val;
return NULL;
}
_kernel_oserror *create_from_template(char *template_id, ObjectID *handle)
{
_kernel_oserror *er=NULL;
if ((er=_swix(Toolbox_CreateObject, _INR(0,1) | _OUT(0),
1, /* flags */
template_id,
handle)) != NULL) {
mem_free(template_id,"freeing template copy");
return er;
}
mem_free(template_id,"freeing template copy");
return NULL;
}
/* for word aligned overlapping areas */
static void _mem_cpy(char *a,char *b,int size)
{
int *c=(int *)a;
int *d=(int *)b;
size = size/(sizeof(int));
DEBUG debug_output("objsupport","Copying %d words from %x to %x\n",size,b,a);
while (size>0) {
size--;
*c++ = *d++;
}
}
_kernel_oserror *delete_gadget(char *tm,ComponentID id)
{
_kernel_oserror *e=NULL;
char *p;
int l;
ObjectTemplateHeader *obj = (ObjectTemplateHeader *)tm;
e=extract_gadget_info(tm,id,(void **)&p,&l);
if(!e) {
DEBUG debug_output("objsupport","Deleting gadget from template: Template size %d, Gadget size %d\n",obj->total_size,l);
DEBUG debug_output("objsupport","about to copy %d bytes\n",(obj->total_size) - (((int)p) - ((int)tm)) -l);
_mem_cpy(p,p+l,(obj->total_size) - (((int)p) - ((int)tm)) -l);
(obj->total_size) -= l;
(((WindowTemplate *)obj->body)->num_gadgets) -= 1;
}
return e;
}
int *__read_window(char *tm,int off)
{
char *p = (char *)((WindowTemplate *) (((ObjectTemplateHeader *)tm)->body));
DEBUG debug_output("objsupport","reading word +%x \n",off);
if ((((ObjectTemplateHeader *)tm)->version == 101) && (off >= offsetof(WindowTemplate,default_focus))) off -=24;
return ((int *) (p+off));
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: rmensure.c
* Purpose: ensuring a module is loaded
* Author: IDJ
* History: 24-Jun-94: IDJ: created
* 02-Dec-96: KJB: modified ROM conditional - RAM modules still need
* to use rmensure in TinyStubs
*/
#include <stdio.h>
#include "kernel.h"
#include "swis.h"
#include "rmensure.h"
#include "macros.h"
_kernel_oserror *rmensure (char *module_name, char *file_name, char *module_version)
{
#if defined(ROM) && !defined(BUILDING_TINYSTUBS)
IGNORE(module_area);
IGNORE(file_name);
IGNORE(module_version);
return NULL;
#else
_kernel_oserror *e;
char command[256];
/*
* see if the module is there at all!
*/
sprintf (command, "RMEnsure %s %s RMLoad System:Modules.%s", module_name,
module_version, file_name);
if ((e = _swix (OS_CLI, _IN(0), command)) != NULL)
return e;
sprintf (command, "RMEnsure %s %s", module_name, module_version);
return _swix (OS_CLI, _IN(0), command);
#endif
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include "slist.h"
#include "mem.h"
void *slist_add_new(void **_head,int size,char *tag)
{
SList *newl,**head = (SList **)_head;
(void) tag;
newl = mem_allocate(size,tag);
if (newl) {
newl->next = *head;
*head = newl;
}
return newl;
}
void slist_delete_member(void **_head,void *member)
{
SList *prev=NULL,*list = (SList *) (*_head),*tst = (SList *)member;
while(list) {
if (list == tst) {
if (prev) prev->next = list->next;
else *_head = (void *) (list->next);
mem_free(list,"Freeing list member");
return;
}
prev =list;
list = list->next;
}
}
void *slist_find_member(void **_head,int field, int value)
{
SList *list = (SList *) (*_head);
while(list) {
if (list->members[field] == value) break;
list = list->next;
}
return list;
}
void *slist_find_matched_member(void **_head,int (*func)(void *list,int value), int value)
{
SList *list = (SList *) (*_head);
while(list) {
if (func(list, value)) break;
list = list->next;
}
return list;
}
void slist_delete_and_call(void **_head,void (*func)(void * d))
{
SList *next,*list = (SList *) (*_head);
while(list) {
func(list);
next = list->next;
mem_free(list,"Freeing list member");
list = next;
}
*_head = NULL;
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: string32.c
* Purpose: strings terminated by char < 32
* Author: Timothy Roddis
* History: 24-Jan-94: IDJ: created from original TGR sources
*/
#include "string32.h"
/* Strings passed to the toolbox might be terminated with any control character ... */
#define NULL 0
void string_copy (char *dst_txt, char *src_txt)
{
/*
* copy a ctrl-terminated string to a buffer big enough to
* hold the result (no length checking).
*/
if (!src_txt) src_txt = "";
while ((*(dst_txt++)=*(src_txt++))>=32);
*(--dst_txt) = '\0';
}
char *string_copy_chk (char *dst_txt, char *src_txt, int max_len)
{
int i;
/*
* copy a ctrl-terminated string to a buffer checking it is big enough to
* hold the result. Return NULL and nul-terminate, if dst buffer not
* big enough.
*/
if (dst_txt == NULL || max_len == 0)
return NULL;
if (!src_txt) src_txt = "";
for (i=1;(*dst_txt++=*src_txt++)>=32;i++)
if (i>=max_len) {
*(--dst_txt) = '\0';
return NULL;
}
*(--dst_txt) = '\0';
return dst_txt;
}
int string_length (char *txt)
{
int i=0;
/*
* return length of ctrl-terminated string
*/
if (!txt) return 0;
while (*txt++>=32) i++;
return i;
}
void string_to_buffer (char *dst_txt, char *src_txt, int *max_len)
{
/*
* general purpose routine to fill in a user-supplied buffer (and report
* number of bytes written), or just report size of buffer needed.
* If buffer is supplied (dst_txt != 0), then *max_len gives size of supplied
* buffer; if this is not large enough, don't return an error, but return
* size of bufer required!
*/
int src_len = string_length (src_txt) + 1;
if (dst_txt == NULL)
*max_len = src_len;
else /* user-supplied buffer */
{
if (*max_len >= src_len)
string_copy (dst_txt, src_txt);
else
string_copy_chk (dst_txt, src_txt, *max_len);
*max_len = string_length (dst_txt) + 1;
}
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __colpicker_h
#define __colpicker_h
/* SWIs */
#ifndef ColourPicker_RegisterModel
#define ColourPicker_RegisterModel 0x047700
#define ColourPicker_DeregisterModel 0x047701
#define ColourPicker_OpenDialogue 0x047702
#define ColourPicker_CloseDialogue 0x047703
#define ColourPicker_UpdateDialogue 0x047704
#define ColourPicker_ReadDialogue 0x047705
#define ColourPicker_SetColour 0x047706
#define ColourPicker_HelpReply 0x047707
#define ColourPicker_ModelSWI 0x047708
#endif
/* Various ColourPicker related structs (broken up into strange lumps for convenience ***********/
typedef struct {
char nought; /* = 0 */
char blue;
char green;
char red;
int extension_size;
} ColourDescriptorHeader;
typedef struct {
unsigned int flags;
char *title;
int x;
int reserved0; /* = 0x80000000 */
int reserved1; /* = 0x7fffffff */
int y;
int reserved2; /* = 0 */
int reserved3; /* = 0 */
ColourDescriptorHeader descriptor_hdr;
} ColourPickerHeader;
typedef struct {
unsigned int model; /* This extension caters fully for only three models */
union {
struct {
int red; /* % */
int green; /* % */
int blue; /* % */
} rgb;
struct {
int cyan; /* % */
int magenta; /* % */
int yellow; /* % */
int key; /* % */
} cmyk;
struct {
int hue; /* angle (degrees) */
int saturation; /* % */
int value; /* % */
} hsv;
char bytes[16];
int words[4];
} data;
} ColourModelData;
typedef struct {
ColourPickerHeader hdr;
ColourModelData ext;
} ColourPickerExtended;
typedef struct {
ColourDescriptorHeader hdr;
ColourModelData ext;
} ColourDescriptorBlock;
/* ColourPicker dialogue types *****************************************************************/
#define ColourPickerType_Normal 0x00000000
#define ColourPickerType_Menu 0x00000001
#define ColourPickerType_Toolbox 0x00000002
#define ColourPickerType_SubMenu 0x00000003
/* ColourPicker flags (OpenDialogue) ***********************************************************/
#define ColourPickerFlags_IncludeNoneButton 0x00000001
#define ColourPickerFlags_SelectNoneButton 0x00000002
#define ColourPickerFlags_ChangeInfoExceptDrag 0x00000004
#define ColourPickerFlags_AllChangeInfo 0x00000008
#define ColourPickerFlags_IgnoreHelpRequest 0x00000010
/* ColourPicker flags (UpdateDialogue) *********************************************************/
#define ColourPicker_Update_IncludeNoneButton 0x00000001
#define ColourPicker_Update_SelectNoneButton 0x00000002
#define ColourPicker_Update_WhenChangeInfo 0x00000004
#define ColourPicker_Update_VisibleSize 0x00000008
#define ColourPicker_Update_Reserved 0x00000010
#define ColourPicker_Update_WindowTitle 0x00000020
#define ColourPicker_Update_RGBSetting 0x00000040
#define ColourPicker_Update_ModelAndSetting 0x00000080
/* Messages ************************************************************************************/
#define colourpicker_MPICKERCHOICE 0x00047700
#define colourpicker_MCOLOURCHANGED 0x00047701
#define colourpicker_MCLOSEDIALOGUEREQUEST 0x00047702
#define colourpicker_MOPENPARENTREQUEST 0x00047703
typedef struct {
int dialogue_handle;
int flags;
struct {
ColourDescriptorHeader hdr;
struct {
unsigned int model; /* This extension caters fully for only three models */
union {
struct {
int red; /* % */
int green; /* % */
int blue; /* % */
} rgb;
struct {
int cyan; /* % */
int magenta; /* % */
int yellow; /* % */
int key; /* % */
} cmyk;
struct {
int hue; /* angle (degrees) */
int saturation; /* % */
int value; /* % */
} hsv;
char bytes[256-sizeof(wimp_MsgHdr)-sizeof(ColourDescriptorHeader)-sizeof(int)];
int words[(256-sizeof(wimp_MsgHdr)-sizeof(ColourDescriptorHeader)-sizeof(int))/4];
} data;
} colour_model;
} colour_descriptor_block;
} colourpicker_PickerChoice, colourpicker_ColourChanged;
typedef struct {
int dialogue_handle;
} colourpicker_CloseDialogueRequest, colourpicker_OpenParentRequest;
typedef struct {
wimp_MsgHdr hdr;
colourpicker_ColourChanged message;
} ColourPicker_ColourChanged_Event;
typedef struct {
wimp_MsgHdr hdr;
colourpicker_PickerChoice message;
} ColourPicker_PickerChoice_Event;
typedef struct {
wimp_MsgHdr hdr;
colourpicker_CloseDialogueRequest message;
} ColourPicker_CloseDialogueRequest_Event;
typedef struct {
wimp_MsgHdr hdr;
colourpicker_OpenParentRequest message;
} ColourPicker_OpenParentRequest_Event;
#endif
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: const.h
* Purpose: useful constants for the Toolbox
* Author: Ian Johnson
* History: 10-Aug-93: IDJ: created
*
*/
#ifndef __const_h
#define __const_h
#define MAXSTRINGLEN 256 /* useful biggest string value */
#define MAXFILENAME 256 /* maximum chars in a filename */
#endif
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: debug.h
* Purpose: debugging routines for the Toolbox
* Author: Ian Johnson
* History: 16-Sep-93: IDJ: created
*
*/
#ifndef __debug_h
#define __debug_h
#ifndef debugging
#define debugging 0
#endif
#define DEBUG if (!debugging) ; else
extern void debug_output (char *allow, char *string, ...);
extern void debug_set_var_name (char *var_name);
extern void debug_dump (void *start, int length);
#endif
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: macros.h
* Purpose: useful macros for the Toolbox
* Author: Ian Johnson
* History: 10-Aug-93: IDJ: created
*
*/
#ifndef __macros_h
#define __macros_h
#define IGNORE(x) (x=x)
#define TRUE 1
#define FALSE 0
#define BOOL int
#define MAX(a,b) ((a)>(b))?(a):(b)
#define MIN(a,b) ((a)<(b))?(a):(b)
#define USER_REGS(regs) ((_kernel_swi_regs *)regs->r[4])
#endif
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: mem.h
* Purpose: memory allocation in the Toolbox
* Author: Ian Johnson
* History: 6-Aug-93: IDJ: created
*/
/*
* This is a central memory allocation place for the Toolbox core module.
* A doubly-linked list of all allocated blocks is kept (maybe remove this
* if using too much memory!).
* To enable debugging of memory allocation, the calling functions should be
* compiled without -ff, so that fn names are in the code area. Compile
* this code with -DDEBUG_MEMORY.
* Memory tracing is turned on by setting the letter 'm' in the central
* debug string (got by calling debugging('m')).
*
* Calling code will always call the debugging versions eg
* b = memory_allocate (1024, &fn, "some extra info");
* Macros ensure the debugging code is removed.
*
*/
#ifndef __mem_h
#define __mem_h
extern void mem_free_all (void);
extern void mem_init (void);
extern void mem_i_am_the_toolbox (void);
/*
* Description: for internal use by the Toolbox module ONLY.
* in order to enable it to initialise the mem library
* correctly.
*
* Parameters: None
*
* Returns: void
*
*/
#define CHECK_HEAP (1u << 0)
#define CHECK_NONZERO (1u << 1)
#ifdef DEBUG_MEMORY
extern void mem_chk (void *p, unsigned int flags, int line, char *file);
#define mem_chk(p,f) mem_chk ((void *)p, f, __LINE__, __FILE__)
/*
* Description: checks a memory pointer.
*
* Parameters: p - the pointer
* flags - what sort of checking
* line - line number in source file
* file - source filename
*
* Returns: void
*
*/
extern void mem_print_list (void);
/*
* Description: prints out all allocated memory blocks.
*
* Parameters: none
*
* Returns: void
*
*/
extern void mem_free (void *block, char *msg);
/*
* Description: frees a block of memory.
*
* Parameters: void *block - the block to be freed
* char *msg - informational message from caller
*
* Returns: void
*
*/
extern void *mem_allocate(unsigned int size, char *tag);
/*
* Description: allocates block of memory of 'size' bytes, with debug
* info - size, name of calling fn, and tag.
*
* Parameters: unsigned int size - size of block to be allocated
* char *tag - extra info to be stored in block
* (eg line nunber of caller?)
*
* Returns: pointer to allocated block (without header).
*
*/
extern void *mem_extend(void *p, int by);
/*
* Description: extends an existing block block of memory by "by" bytes,
* with debug info.
*
* Parameters: void *p - the previously allocated block
* int by - amount of bytes to extend by
*
* Returns: pointer to extended block (without header).
*
*/
#else
#define mem_print_list() ((void)0)
#define mem_chk(p,f) ((void)0)
extern void mem_free (void *block);
#define mem_free(a,b) mem_free(a)
/*
* Description: frees a block of memory.
*
* Parameters: void *block - the block to be freed
*
* Returns: void
*
*/
extern void *mem_allocate (unsigned int size);
#define mem_allocate(a,b) mem_allocate(a)
/*
* Description: allocates block of memory of 'size' bytes.
*
* Parameters: unsigned int size - size of block to be allocated
*
* Returns: pointer to allocated block (without header).
*
*/
extern void *mem_extend(void *p, int by);
#define mem_extend(a,b) mem_extend(a,b)
/*
* Description: extends an existing block block of memory by "by" bytes.
*
* Parameters: void *p - the previously allocated block
* int by - amount of bytes to extend by
*
* Returns: pointer to extended block (without header).
*
*/
#endif
#endif
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: messages.h
* Purpose: accessing an Object modules messages file (inc error reporting)
* Author: Timothy Roddis
* History: 24-Jan-94: IDJ: created from original TGR sources
*/
#include "kernel.h"
#ifndef __toolbox_h
#include "objects.toolbox.h"
#endif
/* ------------------------------------ raising errors ---------------------------------------- */
extern _kernel_oserror *make_error (int err_num, int num_args, ...);
/*
* Generate a RISC OS error block.
*/
extern _kernel_oserror *make_error_hex (int err_num, int num_args, ...);
/*
* Generate a RISC OS error block, with integer params printed in hex.
*/
extern void raise_toolbox_error (int err_num, ObjectID object_id, ComponentID component_id, int num_args, ...);
/*
* Raise a Toolbox_Error event
*/
extern void raise_toolbox_error_hex (int err_num, ObjectID object_id, ComponentID component_id, int num_args, ...);
/*
* Raise a Toolbox_Error event, with integer parameters printed in hex
*/
extern void raise_toolbox_oserror (_kernel_oserror *e, ObjectID object_id, ComponentID component_id);
/*
* Raise a Toolbox_Error event, given a RISC OS error block
*/
/* --------------------------------------- message file handling ------------------------------ */
extern _kernel_oserror *messages_file_open (char *messages_filename);
/*
* Open the module's messages file (and cache file descriptor)
*/
extern _kernel_oserror *messages_file_close (void);
/*
* Close the module's messages file
*/
extern _kernel_oserror *messages_file_lookup (char *token, char *buffer, int *buffer_size, int num_args, ...);
/*
* Lookup given token in message file.
* Result is placed in buffer, unless buffer == NULL, in which case
* the size of buffer required is returned in *buffer_size
*/
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* File: objsupport.h
* Purpose: Standard Dialogue support library.
* Author: Neil Kelleher
* History: 5-Jul-1994 : NK: created
*/
#include "stddef.h"
#include "objects.toolbox.h"
#include "objects.window.h"
/* copies named template to a buffer, returns NULL if can't find or no memory */
char *copy_template(char *name);
/* creates object from buffer then frees it */
_kernel_oserror *create_from_template(char *template_id, ObjectID *handle);
/* zaps gadget attributes, NOTE: use macro form below */
_kernel_oserror *__zap_gadget(char *tm,ComponentID id,int off,int val);
_kernel_oserror *__zap_gadget_string(char *tm,ComponentID id,int off,const char* val,int offlen);
int *__read_gadget(char *tm,ComponentID id,int off);
/* zaps window template, NOTE: use macro form below */
_kernel_oserror *__zap_window(char *tm,int off,int val);
int *__read_window(char *tm,int off);
/* deletes a gadget from a template */
_kernel_oserror *delete_gadget(char *tm,ComponentID id);
/* zap_gadget(char *template,typedef GadgetType, ComponentID component, structure member, value */
#define zap_gadget(a,b,c,d,e) __zap_gadget(a,c,sizeof(GadgetHeader) + offsetof(b,d),(int) (e))
/* zap_gadget_string(char *template,typedef GadgetType, ComponentID component, structure member, value, structure member (length)
* This is used to up the max buffer length if the string was too long to fit in the buffer.
* This avoids problems of too small buffer lengths in Res files causing problems.
*/
#define zap_gadget_string(a,b,c,d,e,f) __zap_gadget_string(a,c,sizeof(GadgetHeader) + offsetof(b,d),(e), sizeof(GadgetHeader)+offsetof(b,f))
#define zap_gadget_header(a,c,d,e) __zap_gadget(a,c, offsetof(GadgetHeader,d),(int) (e))
/* zap_window(char *template,WindowTemplate structure member,value) */
#define zap_window(a,d,e) __zap_window(a,offsetof(WindowTemplate,d),(int) (e))
#define read_gadget(a,b,c,d) __read_gadget(a,c,sizeof(GadgetHeader) + offsetof(b,d))
#define read_gadget_header(a,c,d) __read_gadget(a,c, offsetof(GadgetHeader,d))
#define read_window(a,d) __read_window(a,offsetof(WindowTemplate,d))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment