diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/Makefile | 2 | ||||
-rw-r--r-- | module/header.cmhg | 3 | ||||
-rw-r--r-- | module/header.h | 242 | ||||
-rw-r--r-- | module/kernel.h | 2 | ||||
-rw-r--r-- | module/menu.c | 27 | ||||
-rw-r--r-- | module/module.c | 2 | ||||
-rw-r--r-- | module/wrapper.c | 4 |
7 files changed, 151 insertions, 131 deletions
diff --git a/module/Makefile b/module/Makefile index a57f240..fb618db 100644 --- a/module/Makefile +++ b/module/Makefile @@ -60,7 +60,7 @@ module: release $(OBJS_$(d)) # Target for building module header (mildly hacky) $(HEADER): $(addprefix $(d), header.cmhg) ifeq ($(TARGET),riscos) - @$(CMHG) $(CMHGFLAGS) $< -o $@ -d $(addprefix $(d), header.h) + @$(CMHG) $(CMHGFLAGS) $< -o $@ -d $(subst .o,.h,$@) else @$(TOUCH) $@ endif diff --git a/module/header.cmhg b/module/header.cmhg index 5f7fe5e..63dbc3e 100644 --- a/module/header.cmhg +++ b/module/header.cmhg @@ -13,6 +13,9 @@ swi-handler-code: swi_handler swi-decoding-table: Iconv, Open, Iconv, Close, Convert, CreateMenu, DecodeMenu command-keyword-table: command_handler + Iconv(min-args: 0, max-args: 255, + invalid-syntax: "Syntax: *Iconv [OPTION...] [FILE...]", + help-text: "*Iconv converts the given files from one encoding to another.\n\n Input/Output format specification:\n -f <encoding> encoding of original text\n -t <encoding> encoding for output\n\n Information:\n -l list all known coded character sets\n\n Output control:\n -c omit invalid characters from output\n -o <file> output file\n -s suppress warnings\n -v print progress information\n"), ReadAliases(min-args: 0, max-args: 0, invalid-syntax: "Syntax: *ReadAliases", help-text: "*ReadAliases rereads the encoding aliases file.\n") diff --git a/module/header.h b/module/header.h index df5ff48..0678cd7 100644 --- a/module/header.h +++ b/module/header.h @@ -1,126 +1,144 @@ -/* - * Created by cmhg vsn 5.42 [01 Mar 2002] - */ +/* Generated by CMunge 0.76 (10 May 2006) + * CMunge Copyright (c) 1999-2006 Robin Watts/Justin Fletcher */ -#ifndef __cmhg_header_h -#define __cmhg_header_h +#ifndef _CMUNGE_Iconv_H_ +#define _CMUNGE_Iconv_H_ -#ifndef __kernel_h #include "kernel.h" -#endif -#define CMHG_VERSION 542 +#define CMUNGE_VERSION (76) +#define CMHG_VERSION (531) /* Nearest equivalent version */ -#define Module_Title "Iconv" -#define Module_Help "Iconv" -#define Module_VersionString "0.08" -#define Module_VersionNumber 8 +#define Module_Title "Iconv" +#define Module_Help "Iconv" +#define Module_VersionString "0.08" +#define Module_VersionNumber 8 #ifndef Module_Date -#define Module_Date "11 Mar 2007" +#define Module_Date "11 Nov 2008" #endif - -/* - * Initialisation code - * =================== - * - * Return NULL if your initialisation succeeds; otherwise return a pointer - * to an error block. cmd_tail points to the string of arguments with which - * the module is invoked (may be "", and is control-terminated, not zero - * terminated). - * podule_base is 0 unless the code has been invoked from a podule. - * pw is the 'R12' value established by module initialisation. You may - * assume nothing about its value (in fact it points to some RMA space - * claimed and used by the module veneers). All you may do is pass it back - * for your module veneers via an intermediary such as SWI OS_CallEvery - * (use _swix() to issue the SWI call). - */ -_kernel_oserror *mod_init(const char *cmd_tail, int podule_base, void *pw); - - -/* - * Finalisation code - * ================= - * - * Return NULL if your finalisation succeeds. Otherwise return a pointer to - * an error block if your finalisation handler does not wish to die (e.g. - * toolbox modules return a 'Task(s) active' error). - * fatal, podule and pw are the values of R10, R11 and R12 (respectively) - * on entry to the finalisation code. - */ -_kernel_oserror *mod_fini(int fatal, int podule, void *pw); - - -/* - * Command handler - * =============== - * - * If cmd_no identifies a command, then arg_string gives the command tail - * (which you may not overwrite), and argc is the number of parameters. - * NB. arg_string is control terminated so it may not be a C string. - * Return NULL if the command has been successfully handled; otherwise - * return a pointer to an error block describing the failure (in this - * case, the veneer code will set the 'V' bit). - * - * If cmd_no identifies a *Help entry, then arg_string denotes a buffer - * that you can assemble your output into. cmd_handler must return - * NULL, an error pointer or help_PRINT_BUFFER (if help_PRINT_BUFFER) - * is returned, the zero-terminated buffer will be printed). - * - * If cmd_no identifies a *Configure option, then arg_string gives the - * command tail, and argc the number of parameters. Return NULL, an error - * pointer, or one of the four special values defined below. If arg_string - * is set to arg_CONFIGURE_SYNTAX, the user has typed *Configure with no - * parameter; simply print your syntax string. If arg_string is set to - * arg_STATUS, print your current configured status. Otherwise use - * arg_string and argc to set the *Configure option. - * - * pw is the private word pointer ('R12') value passed into the entry - * veneer - */ -#define help_PRINT_BUFFER ((_kernel_oserror *) arg_string) -#define arg_CONFIGURE_SYNTAX ((char *) 0) -#define arg_STATUS ((char *) 1) -#define configure_BAD_OPTION ((_kernel_oserror *) -1) -#define configure_NUMBER_NEEDED ((_kernel_oserror *) 1) -#define configure_TOO_LARGE ((_kernel_oserror *) 2) -#define configure_TOO_MANY_PARAMS ((_kernel_oserror *) 3) - -#define CMD_ReadAliases 0 - -_kernel_oserror *command_handler(const char *arg_string, int argc, int cmd_no, void *pw); - - -/* - * SWI handler code - * ================ - * - * swi_offset contains the offset of the SWI into your SWI chunk. - * r points to the registers passed to the SWI. - * - * Return NULL if the SWI is handled successfully; otherwise return - * a pointer to an error block which describes the error. - * The veneer code sets the 'V' bit if the returned value is non-NULL. - * The special value error_BAD_SWI may be returned if you do not - * implement a SWI; the veneer will arrange for the appropriate - * standard internationalised error 'SWI value out of range for - * module Iconv' to be returned. - * The handler may update any of its input registers (R0-R9). - * pw is the private word pointer ('R12') value passed into the - * SWI handler entry veneer. - */ -#define Iconv_00 0x057540 -#ifndef Iconv_Open -#define Iconv_Open 0x057540 -#define Iconv_Iconv 0x057541 -#define Iconv_Close 0x057542 -#define Iconv_Convert 0x057543 -#define Iconv_CreateMenu 0x057544 -#define Iconv_DecodeMenu 0x057545 +#ifdef __cplusplus +extern "C" { #endif + +/*************************************************************************** + * Function: mod_init + * Description: Initialise the module, setting up vectors, callbacks and + * any other parts of the system necessary for the module to + * function. + * Parameters: tail = pointer to command line (control terminated) + * podule_base = address of podule module was started from, or + * NULL if none + * pw = private word for module + * On exit: Return NULL for successful initialisation, or a pointer to + * an error block if the module could not start properly. + **************************************************************************/ +_kernel_oserror *mod_init(const char *tail, int podule_base, void *pw); + + +/*************************************************************************** + * Function: mod_fini + * Description: Finalise the module, shutting down any systems necessary, + * freeing vectors and releasing workspace + * Parameters: fatal = fatality indicator; 1 if fatal, 0 if + * reinitialising + * podule_base = address of podule module was started from, or + * NULL if none + * pw = private word for module + * On exit: Return 0 for successful finalisation, or a pointer to an + * error block if module was not shutdown properly. + **************************************************************************/ +_kernel_oserror *mod_fini(int fatal, int podule_base, void *pw); + + +/*************************************************************************** + * Description: Star command and help request handler routines. + * Parameters: arg_string = pointer to argument string (control + * terminated), or output buffer + * argc = number of arguments passed + * number = command number (see CMD_* definitions below) + * pw = private word for module + * On exit: If number indicates a help entry: + * To output, assemble zero terminated output into + * arg_string, and return help_PRINT_BUFFER to print it. + * To stay silent, return NULL. + * To given an error, return an error pointer. + * [In this case, you need to cast the 'const' away] + * If number indicates a configure option: + * If arg_string is arg_STATUS, then print status, otherwise + * use argc and arg_string to set option. + * Return NULL for no error. + * Return one of the four error codes below (configure_*) + * for a generic error message. + * Return an error pointer for a custom error. + * If number indicates a command entry: + * Execute the command given by number, and arg_string. + * Return NULL on success, + * Return a pointer to an error block on failure. + **************************************************************************/ +_kernel_oserror *command_handler(const char *arg_string, int argc, + int number, void *pw); +#define help_PRINT_BUFFER ((_kernel_oserror *) arg_string) +#define arg_CONFIGURE_SYNTAX ((char *) 0) +#define arg_STATUS ((char *) 1) +#define configure_BAD_OPTION ((_kernel_oserror *) -1) +#define configure_NUMBER_NEEDED ((_kernel_oserror *) 1) +#define configure_TOO_LARGE ((_kernel_oserror *) 2) +#define configure_TOO_MANY_PARAMS ((_kernel_oserror *) 3) + +/* Command numbers, as passed to the command handler functions (see above) */ +#undef CMD_Iconv +#define CMD_Iconv (0) +#undef CMD_ReadAliases +#define CMD_ReadAliases (1) + + +/*************************************************************************** + * Description: SWI handler routine. All SWIs for this module will be + * passed to these routines. + * Parameters: number = SWI number within SWI chunk (i.e. 0 to 63) + * r = pointer to register block on entry + * pw = private word for module + * On exit: Return NULL if SWI handled sucessfully, setting return + * register values (r0-r9) in r. + * Return error_BAD_SWI for out of range SWIs. + * Return an error block for a custom error. + **************************************************************************/ +/* Function called to handle SWI calls */ +_kernel_oserror *swi_handler(int number, _kernel_swi_regs *r, void *pw); +/* SWI number definitions */ +#define Iconv_00 (0x00057540) +#undef Iconv_Open +#undef XIconv_Open +#define Iconv_Open (0x00057540) +#define XIconv_Open (0x00077540) +#undef Iconv_Iconv +#undef XIconv_Iconv +#define Iconv_Iconv (0x00057541) +#define XIconv_Iconv (0x00077541) +#undef Iconv_Close +#undef XIconv_Close +#define Iconv_Close (0x00057542) +#define XIconv_Close (0x00077542) +#undef Iconv_Convert +#undef XIconv_Convert +#define Iconv_Convert (0x00057543) +#define XIconv_Convert (0x00077543) +#undef Iconv_CreateMenu +#undef XIconv_CreateMenu +#define Iconv_CreateMenu (0x00057544) +#define XIconv_CreateMenu (0x00077544) +#undef Iconv_DecodeMenu +#undef XIconv_DecodeMenu +#define Iconv_DecodeMenu (0x00057545) +#define XIconv_DecodeMenu (0x00077545) + +/* Special error for 'SWI values out of range for this module' */ #define error_BAD_SWI ((_kernel_oserror *) -1) -_kernel_oserror *swi_handler(int swi_offset, _kernel_swi_regs *r, void *pw); +#ifdef __cplusplus +} +#endif #endif diff --git a/module/kernel.h b/module/kernel.h index fa92afe..2c560e4 100644 --- a/module/kernel.h +++ b/module/kernel.h @@ -3,7 +3,7 @@ #ifndef iconv_myswis_h_ #define iconv_myswis_h_ -#include <inttypes.h> +#include <stdint.h> typedef struct _kernel_oserror { int errnum; diff --git a/module/menu.c b/module/menu.c index d83cb61..8a63c15 100644 --- a/module/menu.c +++ b/module/menu.c @@ -1,7 +1,7 @@ /* Encoding menu */ #include <ctype.h> -#include <inttypes.h> +#include <stdint.h> #ifdef MTEST #include <stdio.h> #endif @@ -334,9 +334,9 @@ static char *menu_op(const struct menu_desc *d, char *buf, *bp++ = 7; *bp++ = 2; *bp++ = 7; *bp++ = 0; /* width, height, gap */ - *((int *)bp) = 200; bp += 4; - *((int *)bp) = 44; bp += 4; - *((int *)bp) = 0; bp += 4; + *((int *) (void *) bp) = 200; bp += 4; + *((int *) (void *) bp) = 44; bp += 4; + *((int *) (void *) bp) = 0; bp += 4; memcpy(dp, val, strlen(val) + 1); dp += strlen(val) + 1; @@ -382,16 +382,17 @@ static char *menu_op(const struct menu_desc *d, char *buf, menuf &= ~0x1; if (flags & MENU_CLEAR_SELECTIONS) { - ((wimp_menu *)buf)->entries[e].menu_flags = menuf; + ((wimp_menu *) (void *) buf)->entries[e].menu_flags = + menuf; } if ((flags & MENU_CREATE)) { - *((int *)bp) = menuf; bp += 4; - *((int *)bp) = -1; bp += 4; - *((int *)bp) = icon; bp += 4; - *((int *)bp) = (intptr_t)(dp); bp += 4; - *((int *)bp) = (intptr_t)(*data); bp += 4; - *((int *)bp) = strlen(pos) + 1; bp += 4; + *((int *) (void *) bp) = menuf; bp += 4; + *((int *) (void *) bp) = -1; bp += 4; + *((int *) (void *) bp) = icon; bp += 4; + *((int *) (void *) bp) = (intptr_t)(dp); bp += 4; + *((int *) (void *) bp) = (intptr_t)(*data); bp += 4; + *((int *) (void *) bp) = strlen(pos) + 1; bp += 4; memcpy(dp, pos, strlen(pos) + 1); dp += strlen(pos) + 1; @@ -403,7 +404,7 @@ static char *menu_op(const struct menu_desc *d, char *buf, /* fixup parent's pointer to this menu */ if (parent && (flags & MENU_CREATE)) - parent->entries[which].sub_menu = (int *)buf; + parent->entries[which].sub_menu = (int *) (void *) buf; /* and recurse */ for (e = 0; e < top; e++) { @@ -419,7 +420,7 @@ static char *menu_op(const struct menu_desc *d, char *buf, sizeof(sub_menus[0]), (int (*)(const void *, const void *))strcmp); if (s) - bp = menu_op(s->desc, bp, (wimp_menu *)buf, + bp = menu_op(s->desc, bp, (wimp_menu *) (void *) buf, submenus[e].e, flags, charset, s->lut, &dp); } diff --git a/module/module.c b/module/module.c index 8b7bf8d..de04796 100644 --- a/module/module.c +++ b/module/module.c @@ -5,8 +5,6 @@ #include <stdlib.h> #include <string.h> -#include <sys/errno.h> - #include <iconv/iconv.h> #include "errors.h" diff --git a/module/wrapper.c b/module/wrapper.c index 1567f0c..506a5ae 100644 --- a/module/wrapper.c +++ b/module/wrapper.c @@ -1,11 +1,11 @@ /* Wrapper around module API so we can run/test it on non-RO machines */ -#ifndef __riscos__ - #include <stdio.h> #include "header.h" +#ifndef __riscos__ + int main(int argc, char **argv) { _kernel_oserror *error; |