+++ /dev/null
-/***********************************************************************************************************************\r
-* DISCLAIMER\r
-* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No \r
-* other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all \r
-* applicable laws, including copyright laws. \r
-* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING\r
-* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, \r
-* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM \r
-* EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES \r
-* SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS \r
-* SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\r
-* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of \r
-* this software. By using this software, you agree to the additional terms and conditions found by accessing the \r
-* following link:\r
-* http://www.renesas.com/disclaimer \r
-*\r
-* Copyright (C) 2012 Renesas Electronics Corporation. All rights reserved. \r
-***********************************************************************************************************************/\r
-/***********************************************************************************************************************\r
-* File Name : lowsrc.c\r
-* Description : Functions to support stream I/O\r
-***********************************************************************************************************************/\r
-/***********************************************************************************************************************\r
-* History : DD.MM.YYYY Version Description\r
-* : 26.10.2011 1.00 First Release\r
-***********************************************************************************************************************/\r
-/***********************************************************************************************************************\r
-Includes <System Includes> , "Project Includes"\r
-***********************************************************************************************************************/\r
-#include <string.h>\r
-#include <stdio.h>\r
-#include <stddef.h>\r
-\r
-/***********************************************************************************************************************\r
-Macro definitions\r
-***********************************************************************************************************************/\r
-/*Number of I/O Stream*/
-#define IOSTREAM 20
-
-/* file number */\r
-#define STDIN 0 /* Standard input (console) */\r
-#define STDOUT 1 /* Standard output (console) */\r
-#define STDERR 2 /* Standard error output (console) */\r
-\r
-#define FLMIN 0 /* Minimum file number */\r
-#define _MOPENR 0x1\r
-#define _MOPENW 0x2\r
-#define _MOPENA 0x4\r
-#define _MTRUNC 0x8\r
-#define _MCREAT 0x10\r
-#define _MBIN 0x20\r
-#define _MEXCL 0x40\r
-#define _MALBUF 0x40\r
-#define _MALFIL 0x80\r
-#define _MEOF 0x100\r
-#define _MERR 0x200\r
-#define _MLBF 0x400\r
-#define _MNBF 0x800\r
-#define _MREAD 0x1000\r
-#define _MWRITE 0x2000\r
-#define _MBYTE 0x4000\r
-#define _MWIDE 0x8000\r
-/* File Flags */\r
-#define O_RDONLY 0x0001 /* Read only */\r
-#define O_WRONLY 0x0002 /* Write only */\r
-#define O_RDWR 0x0004 /* Both read and Write */\r
-#define O_CREAT 0x0008 /* A file is created if it is not existed */\r
-#define O_TRUNC 0x0010 /* The file size is changed to 0 if it is existed. */\r
-#define O_APPEND 0x0020 /* The position is set for next reading/writing */\r
- /* 0: Top of the file 1: End of file */\r
-\r
-/* Special character code */\r
-#define CR 0x0d /* Carriage return */\r
-#define LF 0x0a /* Line feed */\r
-\r
-#if defined( __RX )\r
-const long _nfiles = IOSTREAM; /* The number of files for input/output files */\r
-#else\r
-const int _nfiles = IOSTREAM; /* The number of files for input/output files */\r
-#endif\r
-char flmod[IOSTREAM]; /* The location for the mode of opened file. */\r
-\r
-unsigned char sml_buf[IOSTREAM];\r
-\r
-#define FPATH_STDIN "C:\\stdin"\r
-#define FPATH_STDOUT "C:\\stdout"\r
-#define FPATH_STDERR "C:\\stderr"\r
-\r
-/* H8 Normal mode ,SH and RX */\r
-#if defined( __2000N__ ) || defined( __2600N__ ) || defined( __300HN__ ) || defined( _SH )\r
-/* Output one character to standard output */\r
-extern void charput(char);\r
-/* Input one character from standard input */\r
-extern char charget(void);\r
-/* Output one character to the file */\r
-extern char fcharput(char, unsigned char);\r
-/* Input one character from the file */\r
-extern char fcharget(char*, unsigned char);\r
-/* Open the file */\r
-extern char fileopen(char*, unsigned char, unsigned char*);\r
-/* Close the file */\r
-extern char fileclose(unsigned char);\r
-/* Move the file offset */\r
-extern char fpseek(unsigned char, long, unsigned char);\r
-/* Get the file offset */\r
-extern char fptell(unsigned char, long*);\r
-\r
-/* RX */\r
-#elif defined( __RX )\r
-/* Output one character to standard output */\r
-extern void charput(unsigned char);\r
-/* Input one character from standard input */\r
-extern unsigned char charget(void);\r
-\r
-/* H8 Advanced mode */\r
-#elif defined( __2000A__ ) || defined( __2600A__ ) || defined( __300HA__ ) || defined( __H8SXN__ ) || defined( __H8SXA__ ) || defined( __H8SXM__ ) || defined( __H8SXX__ )\r
-/* Output one character to standard output */\r
-extern void charput(char);\r
-/* Input one character from standard input */\r
-extern char charget(void);\r
-/* Output one character to the file */\r
-extern char fcharput(char, unsigned char);\r
-/* Input one character from the file */\r
-extern char fcharget(char*, unsigned char);\r
-/* Open the file */\r
-/* Specified as the number of register which stored paramter is 3 */\r
-extern char __regparam3 fileopen(char*, unsigned char, unsigned char*);\r
-/* Close the file */\r
-extern char fileclose(unsigned char);\r
-/* Move the file offset */\r
-extern char fpseek(unsigned char, long, unsigned char);\r
-/* Get the file offset */\r
-extern char fptell(unsigned char, long*);\r
-\r
-/* H8300 and H8300L */\r
-#elif defined( __300__ ) || defined( __300L__ )\r
-/* Output one character to standard output */\r
-extern void charput(char);\r
-/* Input one character from standard input */\r
-extern char charget(void);\r
-/* Output one character to the file */\r
-extern char fcharput(char, unsigned char);\r
-/* Input one character from the file */\r
-extern char fcharget(char*, unsigned char);\r
-/* Open the file */\r
-/* Specified as the number of register which stored paramter is 3 */\r
-extern char __regparam3 fileopen(char*, unsigned char, unsigned char*);\r
-/* Close the file */\r
-extern char fileclose(unsigned char);\r
-/* Move the file offset */\r
-/* Move the file offset */\r
-extern char __regparam3 fpseek(unsigned char, long, unsigned char);\r
-/* Get the file offset */\r
-extern char fptell(unsigned char, long*);\r
-#endif\r
-\r
-#include <stdio.h>\r
-FILE *_Files[IOSTREAM]; // structure for FILE\r
-char *env_list[] = { // Array for environment variables(**environ)\r
- "ENV1=temp01",\r
- "ENV2=temp02",\r
- "ENV9=end",\r
- '\0' // Terminal for environment variables\r
-};\r
-\r
-char **environ = env_list;\r
-\r
-/****************************************************************************/\r
-/* _INIT_IOLIB */\r
-/* Initialize C library Functions, if necessary. */\r
-/* Define USES_SIMIO on Assembler Option. */\r
-/****************************************************************************/\r
-void _INIT_IOLIB( void )\r
-{\r
- /* A file for standard input/output is opened or created. Each FILE */\r
- /* structure members are initialized by the library. Each _Buf member */\r
- /* in it is re-set the end of buffer pointer. */\r
-\r
- /* Standard Input File */\r
- if( freopen( FPATH_STDIN, "r", stdin ) == NULL )\r
- stdin->_Mode = 0xffff; /* Not allow the access if it fails to open */\r
- stdin->_Mode = _MOPENR; /* Read only attribute */\r
- stdin->_Mode |= _MNBF; /* Non-buffering for data */\r
- stdin->_Bend = stdin->_Buf + 1; /* Re-set pointer to the end of buffer */\r
-\r
- /* Standard Output File */\r
- if( freopen( FPATH_STDOUT, "w", stdout ) == NULL ) \r
- stdout->_Mode = 0xffff; /* Not allow the access if it fails to open */\r
- stdout->_Mode |= _MNBF; /* Non-buffering for data */\r
- stdout->_Bend = stdout->_Buf + 1;/* Re-set pointer to the end of buffer */\r
- \r
- /* Standard Error File */\r
- if( freopen( FPATH_STDERR, "w", stderr ) == NULL )\r
- stderr->_Mode = 0xffff; /* Not allow the access if it fails to open */\r
- stderr->_Mode |= _MNBF; /* Non-buffering for data */\r
- stderr->_Bend = stderr->_Buf + 1;/* Re-set pointer to the end of buffer */\r
-}\r
-\r
-/****************************************************************************/\r
-/* _CLOSEALL */\r
-/****************************************************************************/\r
-void _CLOSEALL( void )\r
-{\r
- long i;\r
-\r
- for( i=0; i < _nfiles; i++ )\r
- {\r
- /* Checks if the file is opened or not */\r
- if( _Files[i]->_Mode & (_MOPENR | _MOPENW | _MOPENA ) )\r
- fclose( _Files[i] ); /* Closes the file */\r
- }\r
-}\r
-\r
-/**************************************************************************/\r
-/* open:file open */\r
-/* Return value:File number (Pass) */\r
-/* -1 (Failure) */\r
-/**************************************************************************/\r
-#if defined( __RX )\r
-long open(const char *name, /* File name */\r
- long mode, /* Open mode */\r
- long flg) /* Open flag */\r
-#else\r
-int open(char *name, /* File name */\r
- int mode, /* Open mode */\r
- int flg) /* Open flag */\r
-#endif\r
-{\r
-\r
-\r
- if( strcmp( name, FPATH_STDIN ) == 0 ) /* Standard Input file? */\r
- {\r
- if( ( mode & O_RDONLY ) == 0 ) return -1;\r
- flmod[STDIN] = mode;\r
- return STDIN;\r
- }\r
- else if( strcmp( name, FPATH_STDOUT ) == 0 )/* Standard Output file? */\r
- {\r
- if( ( mode & O_WRONLY ) == 0 ) return -1;\r
- flmod[STDOUT] = mode;\r
- return STDOUT;\r
- }\r
- else if(strcmp(name, FPATH_STDERR ) == 0 ) /* Standard Error file? */\r
- {\r
- if( ( mode & O_WRONLY ) == 0 ) return -1;\r
- flmod[STDERR] = mode;\r
- return STDERR;\r
- }\r
- else return -1; /*Others */\r
-}\r
-\r
-#if defined( __RX )\r
-long close( long fileno )\r
-#else\r
-int close( int fileno )\r
-#endif\r
-{\r
- return 1;\r
-}\r
-\r
-/**************************************************************************/\r
-/* write:Data write */\r
-/* Return value:Number of write characters (Pass) */\r
-/* -1 (Failure) */\r
-/**************************************************************************/\r
-#if defined( __RX )\r
-long write(long fileno, /* File number */\r
- const unsigned char *buf, /* The address of destination buffer */\r
- long count) /* The number of chacter to write */\r
-#else\r
-int write(int fileno, /* File number */\r
- char *buf, /* The address of destination buffer */\r
- int count) /* The number of chacter to write */\r
-#endif\r
-{\r
- long i; /* A variable for counter */\r
- unsigned char c; /* An output character */\r
-\r
- /* Checking the mode of file , output each character */\r
- /* Checking the attribute for Write-Only, Read-Only or Read-Write */\r
- if(flmod[fileno]&O_WRONLY || flmod[fileno]&O_RDWR)\r
- {\r
- if( fileno == STDIN ) return -1; /* Standard Input */\r
- else if( (fileno == STDOUT) || (fileno == STDERR) ) \r
- /* Standard Error/output */\r
- {\r
- for( i = count; i > 0; --i )\r
- {\r
- c = *buf++;\r
- charput(c);\r
- }\r
- return count; /*Return the number of written characters */\r
- }\r
- else return -1; /* Incorrect file number */\r
- }\r
- else return -1; /* An error */\r
-}\r
-\r
-#if defined( __RX )\r
-long read( long fileno, unsigned char *buf, long count )\r
-#else\r
-int read( int fileno, char *buf, unsigned int count )\r
-#endif\r
-{\r
- long i;\r
-\r
- /* Checking the file mode with the file number, each character is input and stored the buffer */\r
-\r
- if((flmod[fileno]&_MOPENR) || (flmod[fileno]&O_RDWR)){\r
- for(i = count; i > 0; i--){\r
- *buf = charget();\r
- if(*buf==CR){ /* Replace the new line character */\r
- *buf = LF;\r
- }\r
- buf++;\r
- }\r
- return count;\r
- }\r
- else {\r
- return -1;\r
- }\r
-}\r
-\r
-#if defined( __RX )\r
-long lseek( long fileno, long offset, long base )\r
-#else\r
-long lseek( int fileno, long offset, int base )\r
-#endif\r
-{\r
- return -1L;\r
-}\r
-\r