Update of /cvsroot/ro-oslib/OSLib/!OsLib/Tools/oslib/unix In directory sc8-pr-cvs1:/tmp/cvs-serv28678/!OsLib/Tools/oslib/unix Added Files: Tag: unix-build kernel.c messagetrans.c os.c osargs.c osfile.c osfind.c osgbpb.c osword.c territory.c Log Message: Unix Build --- NEW FILE: kernel.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: messagetrans.c --- /* * OS Lib very limited port */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include "oslib/messagetrans.h" #include "oslib/osfile.h" /* --- types ------------------------------------------------------------- */ typedef struct s__msgtrans { struct s__msgtrans *next; char *token; char *value; } s_msgtrans; /* --- gloabl data ------------------------------------------------------- */ extern os_error oserr; /* ------------------------------------------------------------------------ * Function: messagetrans_file_info() * * Description: Gives information about a message file * * Input: file_name - value of R1 on entry * * Output: flags - value of R0 on exit * size - value of R2 on exit * * Other notes: Calls SWI 0x41500. */ extern os_error *xmessagetrans_file_info (char const *file_name, messagetrans_file_flags *flags, int *size) { os_error *perr = NULL; fileswitch_object_type obj_type; bits load_addr; bits exec_addr; fileswitch_attr attr; bits file_type; if((perr = xosfile_read_stamped( file_name, &obj_type, &load_addr, &exec_addr, size, &attr, &file_type ) )==NULL) { if(obj_type==osfile_NOT_FOUND) { perr = &oserr; oserr.errnum = error_MESSAGE_TRANS_FILE_OPEN; strcpy(oserr.errmess, "Unable to find Messagetrans file"); } else { /* request 1 byte larger to allow 0 termination */ (*size)++; } } if (flags) *flags=messagetrans_DIRECT_ACCESS; return perr; } extern void messagetrans_file_info (char const *file_name, messagetrans_file_flags *flags, int *size) { xmessagetrans_file_info (file_name, flags, size); } /* ------------------------------------------------------------------------ * Function: messagetrans_open_file() * * Description: Opens a message file * * Input: cb - value of R0 on entry * file_name - value of R1 on entry * buffer - value of R2 on entry * * Other notes: Calls SWI 0x41501. */ extern os_error *xmessagetrans_open_file (messagetrans_control_block *cb, char const *file_name, char *buffer) { os_error *perr = NULL; fileswitch_object_type obj_type; bits load_addr; bits exec_addr; int size; fileswitch_attr attr; if((perr = xosfile_load_stamped (file_name, (byte*)buffer, &obj_type, &load_addr, &exec_addr, &size, &attr))==NULL) { if(obj_type==osfile_NOT_FOUND) { perr = &oserr; oserr.errnum = error_MESSAGE_TRANS_FILE_OPEN; strcpy(oserr.errmess, "Unable to read Messagetrans file"); } else { s_msgtrans *m = NULL; s_msgtrans *om = NULL; char *s = buffer; int line = 1; /* * zero terminate buffer - size should be 1 bigger than file * as return from messagetrans_file_info */ buffer[size] = 0; cb->cb[0] = (int)buffer; cb->cb[1] = 0; do { /* skip comment or blank lines */ if(*s=='#' || *s==' ' || *s=='\r' || *s=='\n') { if(*s!='\n') s = strchr(s+1, '\n'); if(s) { s++; line++; if(*s=='\r') s++; } } else { /* make list entry */ if((m = malloc(sizeof(*m)))==NULL) { perr = &oserr; oserr.errnum = error_MESSAGE_TRANS_FILE_OPEN; strcpy(oserr.errmess, "No memory for Messagetrans list"); s = NULL; } else { m->next = NULL; m->token = s; /* find token value seperator */ s = strchr(s, ':'); if(s) { /* terminate token */ *s = 0; /* add to tail, or set head of list */ if(om) om->next = m; else cb->cb[1] = (int)m; om = m; m->value = ++s; if((s=strchr(s, '\n'))!=NULL) { /* terminate value string on NL/LF */ if(*(s-1)=='\r') *(s-1) = 0; *(s++) = 0; } else { /* end of file, so advance s to end */ s = buffer+size; } } else { free(m); } } /* endif if malloc */ } /* endelse '#' '\r' '\n' */ } while(s!=NULL && s<(buffer+size)); /* report and tidy up after invalid file */ if(s==NULL) { perr = &oserr; oserr.errnum = error_MESSAGE_TRANS_SYNTAX; sprintf(oserr.errmess, "Messagetrans syntax error at line %d", line); m = (s_msgtrans*)cb->cb[1]; while(m) { om = m->next; free(m); m = om; } cb->cb[1]=0; } } /* endelse osfile_NOT_FOUND */ } /* endif perr */ return perr; } void messagetrans_open_file (messagetrans_control_block *cb, char const *file_name, char *buffer) { xmessagetrans_open_file (cb, file_name, buffer); } /* ------------------------------------------------------------------------ * Function: messagetrans_lookup() * * Description: Translates a message token into a string * * Input: cb - value of R0 on entry * token - value of R1 on entry * buffer - value of R2 on entry * size - value of R3 on entry * arg0 - value of R4 on entry * arg1 - value of R5 on entry * arg2 - value of R6 on entry * arg3 - value of R7 on entry * * Output: result - value of R2 on exit (X version only) * used - value of R3 on exit * * Returns: R2 (non-X version only) * * Other notes: Calls SWI 0x41502. */ extern os_error *xmessagetrans_lookup (messagetrans_control_block const *cb, char const *token, char *buffer, int size, char const *arg0, char const *arg1, char const *arg2, char const *arg3, char **result, int *used) { osbool found = FALSE; NOT_USED(buffer); NOT_USED(arg0); NOT_USED(arg1); NOT_USED(arg2); NOT_USED(arg3); if(cb!=NULL && cb->cb[0]!=0 && cb->cb[1]!=0) { /* * #### non zero token termination, wild card and args not supported, * lookup horribly inefficent */ s_msgtrans *m = (s_msgtrans*)cb->cb[1]; while(m && !found) { if(strcmp(m->token, token)==0) { found = TRUE; *result = m->value; if(buffer) { *used = strlen(*result); if((*used) >= size) *used = size-1; strncpy(buffer, m->value, *used); buffer[*used] = 0; } else { *used = 0; } } else { m = m->next; } } } if(!found) { oserr.errnum = error_MESSAGE_TRANS_TOKEN_NOT_FOUND; sprintf(oserr.errmess, "Token '%s' not found", token); return &oserr; } else { return NULL; } } extern char *messagetrans_lookup (messagetrans_control_block const *cb, char const *token, char *buffer, int size, char const *arg0, char const *arg1, char const *arg2, char const *arg3, int *used) { char *result; if(xmessagetrans_lookup (cb, token, buffer, size, arg0, arg1, arg2, arg3, &result, used)) return NULL; else return result; } /* ------------------------------------------------------------------------ * Function: messagetrans_error_lookup() * * Description: Translates a message token within an error block * * Input: error - value of R0 on entry * cb - value of R1 on entry * buffer - value of R2 on entry * size - value of R3 on entry * arg0 - value of R4 on entry * arg1 - value of R5 on entry * arg2 - value of R6 on entry * arg3 - value of R7 on entry * * Other notes: Calls SWI 0x41506. */ /* ------------------------------------------------------------------------ * Function: messagetrans_close_file() * * Description: Closes a message file * * Input: cb - value of R0 on entry * * Other notes: Calls SWI 0x41504. */ extern os_error *xmessagetrans_close_file (messagetrans_control_block const *cb) { s_msgtrans *m = (s_msgtrans*)cb->cb[1]; s_msgtrans *om; while(m) { om = m->next; free(m); m = om; } return NULL; } void messagetrans_close_file (messagetrans_control_block const *cb) { xmessagetrans_close_file(cb); } --- NEW FILE: os.c --- /* * OS Lib very limited port */ #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "oslib/os.h" //#include "support/unix.h" #include <signal.h> #define SIGOSERROR 10 /* --- types ------------------------------------------------------------- */ typedef struct { char *name; int value; } s_table; /* --- gloabl data ------------------------------------------------------- */ os_error oserr; /* --- static data ------------------------------------------------------- */ static s_table swi_names[] = { {"OS_WriteC", 0x0}, {"OS_WriteS", 0x1}, {"OS_Write0", 0x2}, {"OS_NewLine", 0x3}, {"OS_ReadC", 0x4}, {"OS_CLI", 0x5}, {"OS_Byte", 0x6}, {"OS_Word", 0x7}, {"OS_File", 0x8}, {"OS_Args", 0x9}, {"OS_BGet", 0xA}, {"OS_BPut", 0xB}, {"OS_GBPB", 0xC}, {"OS_Find", 0xD}, {"OS_ReadLine", 0xE}, {"OS_Control", 0xF}, {"OS_GetEnv", 0x10}, {"OS_Exit", 0x11}, {"OS_SetEnv", 0x12}, {"OS_IntOn", 0x13}, {"OS_IntOff", 0x14}, {"OS_CallBack", 0x15}, {"OS_EnterOS", 0x16}, {"OS_BreakPt", 0x17}, {"OS_BreakCtrl", 0x18}, {"OS_UnusedSWI", 0x19}, {"OS_UpdateMEMC", 0x1A}, {"OS_SetCallBack", 0x1B}, {"OS_Mouse", 0x1C}, {"OS_Heap", 0x1D}, {"OS_Module", 0x1E}, {"OS_Claim", 0x1F}, {"OS_Release", 0x20}, {"OS_ReadUnsigned", 0x21}, {"OS_GenerateEvent", 0x22}, {"OS_ReadVarVal", 0x23}, {"OS_SetVarVal", 0x24}, {"OS_GSInit", 0x25}, {"OS_GSRead", 0x26}, {"OS_GSTrans", 0x27}, {"OS_BinaryToDecimal", 0x28}, {"OS_FSControl", 0x29}, {"OS_ChangeDynamicArea", 0x2A}, {"OS_GenerateError", 0x2B}, {"OS_ReadEscapeState", 0x2C}, {"OS_EvaluateExpression", 0x2D}, {"OS_SpriteOp", 0x2E}, {"OS_ReadPalette", 0x2F}, {"OS_ServiceCall", 0x30}, {"OS_ReadVduVariables", 0x31}, {"OS_ReadPoint", 0x32}, {"OS_UpCall", 0x33}, {"OS_CallAVector", 0x34}, {"OS_ReadModeVariable", 0x35}, {"OS_RemoveCursors", 0x36}, {"OS_RestoreCursors", 0x37}, {"OS_SWINumberToString", 0x38}, {"OS_SWINumberFromString", 0x39}, {"OS_ValidateAddress", 0x3A}, {"OS_CallAfter", 0x3B}, {"OS_CallEvery", 0x3C}, {"OS_RemoveTickerEvent", 0x3D}, {"OS_InstallKeyHandler", 0x3E}, {"OS_CheckModeValid", 0x3F}, {"OS_ChangeEnvironment", 0x40}, {"OS_ClaimScreenMemory", 0x41}, {"OS_ReadMonotonicTime", 0x42}, {"OS_SubstituteArgs", 0x43}, {"OS_PrettyPrint", 0x44}, {"OS_Plot", 0x45}, {"OS_WriteN", 0x46}, {"OS_AddToVector", 0x47}, {"OS_WriteEnv", 0x48}, {"OS_ReadArgs", 0x49}, {"OS_ReadRAMFsLimits", 0x4A}, {"OS_ClaimDeviceVector", 0x4B}, {"OS_ReleaseDeviceVector", 0x4C}, {"OS_DelinkApplication", 0x4D}, {"OS_RelinkApplication", 0x4E}, {"OS_HeapSort", 0x4F}, {"OS_ExitAndDie", 0x50}, {"OS_ReadMemMapInfo", 0x51}, {"OS_ReadMemMapEntries", 0x52}, {"OS_SetMemMapEntries", 0x53}, {"OS_AddCallBack", 0x54}, {"OS_ReadDefaultHandler", 0x55}, {"OS_SetECFOrigin", 0x56}, {"OS_SerialOp", 0x57}, {"OS_ReadSysInfo", 0x58}, {"OS_Confirm", 0x59}, {"OS_ChangedBox", 0x5A}, {"OS_CRC", 0x5B}, {"OS_ReadDynamicArea", 0x5C}, {"OS_PrintChar", 0x5D}, {"OS_ChangeRedirection", 0x5E}, {"OS_RemoveCallBack", 0x5F}, {"OS_FindMemMapEntries", 0x60}, {"OS_SetColour", 0x61}, {"OS_Pointer", 0x64}, {"OS_ScreenMode", 0x65}, {"OS_DynamicArea", 0x66}, {"OS_Memory", 0x68}, {"OS_ClaimProcessorVector", 0x69}, {"OS_Reset", 0x6A}, {"OS_MMUControl", 0x6B}, {"OS_PlatformFeatures", 0x6D}, {"OS_SynchroniseCodeAreas", 0x6E}, {"OS_CallASWI", 0x6F}, {"OS_AMBControl", 0x70}, {"OS_CallASWIR12", 0x71}, {"OS_EnterUSR32", 0x73}, {"OS_EnterUSR26", 0x74}, {"OS_Hardware", 0x7A}, {"OS_LeaveOS", 0x7C}, {"OS_ReadLine32", 0x7D}, {"OS_SubstituteArgs32", 0x7E}, {"OS_HeapSort32", 0x7F}, {"OS_ConvertStandardDateAndTime", 0xC0}, {"OS_ConvertDateAndTime", 0xC1}, {"OS_ConvertHex1", 0xD0}, {"OS_ConvertHex2", 0xD1}, {"OS_ConvertHex4", 0xD2}, {"OS_ConvertHex6", 0xD3}, {"OS_ConvertHex8", 0xD4}, {"OS_ConvertCardinal1", 0xD5}, {"OS_ConvertCardinal2", 0xD6}, {"OS_ConvertCardinal3", 0xD7}, {"OS_ConvertCardinal4", 0xD8}, {"OS_ConvertInteger1", 0xD9}, {"OS_ConvertInteger2", 0xDA}, {"OS_ConvertInteger3", 0xDB}, {"OS_ConvertInteger4", 0xDC}, {"OS_ConvertBinary1", 0xDD}, {"OS_ConvertBinary2", 0xDE}, {"OS_ConvertBinary3", 0xDF}, {"OS_ConvertBinary4", 0xE0}, {"OS_ConvertSpacedCardinal1", 0xE1}, {"OS_ConvertSpacedCardinal2", 0xE2}, {"OS_ConvertSpacedCardinal3", 0xE3}, {"OS_ConvertSpacedCardinal4", 0xE4}, {"OS_ConvertSpacedInteger1", 0xE5}, {"OS_ConvertSpacedInteger2", 0xE6}, {"OS_ConvertSpacedInteger3", 0xE7}, {"OS_ConvertSpacedInteger4", 0xE8}, {"OS_ConvertFixedNetStation", 0xE9}, {"OS_ConvertNetStation", 0xEA}, {"OS_ConvertFixedFileSize", 0xEB}, {"OS_ConvertFileSize", 0xEC}, {"OS_WriteI", 0x100}, {"Font_CacheAddr", 0x40080}, {"Font_FindFont", 0x40081}, {"Font_LoseFont", 0x40082}, {"Font_ReadDefn", 0x40083}, {"Font_ReadIdentifier", 0x40083}, {"Font_ReadInfo", 0x40084}, {"Font_StringWidth", 0x40085}, {"Font_Paint", 0x40086}, {"Font_Caret", 0x40087}, {"Font_ConverttoOS", 0x40088}, {"Font_Converttopoints", 0x40089}, {"Font_SetFont", 0x4008A}, {"Font_CurrentFont", 0x4008B}, {"Font_FutureFont", 0x4008C}, {"Font_FindCaret", 0x4008D}, {"Font_CharBBox", 0x4008E}, {"Font_ReadScaleFactor", 0x4008F}, {"Font_SetScaleFactor", 0x40090}, {"Font_ListFonts", 0x40091}, {"Font_SetFontColours", 0x40092}, {"Font_SetPalette", 0x40093}, {"Font_SetTruePalette", 0x40093}, {"Font_ReadThresholds", 0x40094}, {"Font_SetThresholds", 0x40095}, {"Font_FindCaretJ", 0x40096}, {"Font_StringBBox", 0x40097}, {"Font_ReadColourTable", 0x40098}, {"Font_MakeBitmap", 0x40099}, {"Font_UnCacheFile", 0x4009A}, {"Font_SetFontMax", 0x4009B}, {"Font_ReadFontMax", 0x4009C}, {"Font_ReadFontPrefix", 0x4009D}, {"Font_SwitchOutputToBuffer", 0x4009E}, {"Font_SwitchOutputToBufferFlags", 0x4009E}, {"Font_ReadFontMetrics", 0x4009F}, {"Font_DecodeMenu", 0x400A0}, {"Font_ScanString", 0x400A1}, {"Font_SetColourTable", 0x400A2}, {"Font_CurrentRGB", 0x400A3}, {"Font_FutureRGB", 0x400A4}, {"Font_ReadEncodingFilename", 0x400A5}, {"Font_FindField", 0x400A6}, {"Font_ApplyFields", 0x400A7}, {"Font_LookupFont", 0x400A8}, {"Wimp_Initialise", 0x400C0}, {"Wimp_CreateWindow", 0x400C1}, {"Wimp_CreateIcon", 0x400C2}, {"Wimp_CreateIconRelative", 0x400C2}, {"Wimp_CreateIconPrioritised", 0x400C2}, {"Wimp_DeleteWindow", 0x400C3}, {"Wimp_DeleteIcon", 0x400C4}, {"Wimp_OpenWindow", 0x400C5}, {"Wimp_OpenWindowNested", 0x400C5}, {"Wimp_OpenWindowNestedWithFlags", 0x400C5}, {"Wimp_CloseWindow", 0x400C6}, {"Wimp_Poll", 0x400C7}, {"Wimp_RedrawWindow", 0x400C8}, {"Wimp_UpdateWindow", 0x400C9}, {"Wimp_GetRectangle", 0x400CA}, {"Wimp_GetWindowState", 0x400CB}, {"Wimp_GetWindowStateAndNesting", 0x400CB}, {"Wimp_GetWindowInfo", 0x400CC}, {"Wimp_GetWindowInfoHeaderOnly", 0x400CC}, {"Wimp_SetIconState", 0x400CD}, {"Wimp_GetIconState", 0x400CE}, {"Wimp_GetPointerInfo", 0x400CF}, {"Wimp_DragBox", 0x400D0}, {"Wimp_DragBoxWithFlags", 0x400D0}, {"Wimp_ForceRedraw", 0x400D1}, {"Wimp_ForceRedrawFurniture", 0x400D1}, {"Wimp_ForceRedrawTitle", 0x400D1}, {"Wimp_SetCaretPosition", 0x400D2}, {"Wimp_GetCaretPosition", 0x400D3}, {"Wimp_CreateMenu", 0x400D4}, {"Wimp_DecodeMenu", 0x400D5}, {"Wimp_WhichIcon", 0x400D6}, {"Wimp_SetExtent", 0x400D7}, {"Wimp_SetPointerShape", 0x400D8}, {"Wimp_OpenTemplate", 0x400D9}, {"Wimp_CloseTemplate", 0x400DA}, {"Wimp_LoadTemplate", 0x400DB}, {"Wimp_ProcessKey", 0x400DC}, {"Wimp_CloseDown", 0x400DD}, {"Wimp_StartTask", 0x400DE}, {"Wimp_ReportError", 0x400DF}, {"Wimp_ReportErrorByCategory", 0x400DF}, {"Wimp_GetWindowOutline", 0x400E0}, {"Wimp_PollIdle", 0x400E1}, {"Wimp_PlotIcon", 0x400E2}, {"Wimp_SetMode", 0x400E3}, {"Wimp_SetPalette", 0x400E4}, {"Wimp_ReadPalette", 0x400E5}, {"Wimp_ReadTruePalette", 0x400E5}, {"Wimp_SetColour", 0x400E6}, {"Wimp_SendMessage", 0x400E7}, {"Wimp_SendMessageToWindow", 0x400E7}, {"Wimp_CreateSubMenu", 0x400E8}, {"Wimp_BaseOfSprites", 0x400EA}, {"Wimp_BlockCopy", 0x400EB}, {"Wimp_SlotSize", 0x400EC}, {"Wimp_ReadPixTrans", 0x400ED}, {"Wimp_ClaimFreeMemory", 0x400EE}, {"Wimp_CommandWindow", 0x400EF}, {"Wimp_TextColour", 0x400F0}, {"Wimp_TransferBlock", 0x400F1}, {"Wimp_SetFontColours", 0x400F3}, {"Wimp_GetMenuState", 0x400F4}, {"Wimp_RegisterFilter", 0x400F5}, {"Wimp_AddMessages", 0x400F6}, {"Wimp_RemoveMessages", 0x400F7}, {"Wimp_SetColourMapping", 0x400F8}, {"Wimp_TextOp", 0x400F9}, {"Wimp_SetWatchdogState", 0x400FA}, {"Wimp_ResizeIcon", 0x400FC}, {"Wimp_AutoScroll", 0x400FD}, {"Sound_Configure", 0x40140}, {"Sound_Enable", 0x40141}, {"Sound_Stereo", 0x40142}, {"Sound_Speaker", 0x40143}, {"Sound_Mode", 0x40144}, {"Sound_LinearHandler", 0x40145}, {"Sound_SampleRate", 0x40146}, {"Sound_Volume", 0x40180}, {"Sound_SoundLog", 0x40181}, {"Sound_LogScale", 0x40182}, {"Sound_InstallVoice", 0x40183}, {"Sound_RemoveVoice", 0x40184}, {"Sound_AttachVoice", 0x40185}, {"Sound_ControlPacked", 0x40186}, {"Sound_Tuning", 0x40187}, {"Sound_Pitch", 0x40188}, {"Sound_Control", 0x40189}, {"Sound_AttachNamedVoice", 0x4018A}, {"Sound_ReadControlBlock", 0x4018B}, {"Sound_WriteControlBlock", 0x4018C}, {"Sound_QInit", 0x401C0}, {"Sound_QSchedule", 0x401C1}, {"Sound_QRemove", 0x401C2}, {"Sound_QFree", 0x401C3}, {"Sound_QSDispatch", 0x401C4}, {"Sound_QTempo", 0x401C5}, {"Sound_QBeat", 0x401C6}, {"Sound_QInterface", 0x401C7}, {"Socket_Creat", 0x41200}, {"Socket_Bind", 0x41201}, {"Socket_Listen", 0x41202}, {"Socket_Accept", 0x41203}, {"Socket_Connect", 0x41204}, {"Socket_Recv", 0x41205}, {"Socket_Recvfrom", 0x41206}, {"Socket_Recvmsg", 0x41207}, {"Socket_Send", 0x41208}, {"Socket_Sendto", 0x41209}, {"Socket_Sendmsg", 0x4120A}, {"Socket_Shutdown", 0x4120B}, {"Socket_Setsockopt", 0x4120C}, {"Socket_Getsockopt", 0x4120D}, {"Socket_Getpeername", 0x4120E}, {"Socket_Getsockname", 0x4120F}, {"Socket_Close", 0x41210}, {"Socket_Select", 0x41211}, {"Socket_Ioctl", 0x41212}, {"Socket_Read", 0x41213}, {"Socket_Write", 0x41214}, {"Socket_Stat", 0x41215}, {"Socket_Readv", 0x41216}, {"Socket_Writev", 0x41217}, {"Socket_Gettsize", 0x41218}, {"Socket_Sendtosm", 0x41219}, {"Socket_Sysctl", 0x4121A}, {"Socket_Accept_1", 0x4121B}, {"Socket_Recvfrom_1", 0x4121C}, {"Socket_Recvmsg_1", 0x4121D}, {"Socket_Sendmsg_1", 0x4121E}, {"Socket_Getpeername_1", 0x4121F}, {"Socket_Getsockname_1", 0x41220}, {"Socket_InternalLookup", 0x41221}, {"Socket_Version", 0x41222}, {"MessageTrans_FileInfo", 0x41500}, {"MessageTrans_OpenFile", 0x41501}, {"MessageTrans_Lookup", 0x41502}, {"MessageTrans_MakeMenus", 0x41503}, {"MessageTrans_CloseFile", 0x41504}, {"MessageTrans_EnumerateTokens", 0x41505}, {"MessageTrans_ErrorLookup", 0x41506}, {"MessageTrans_GSLookup", 0x41507}, {"MessageTrans_CopyError", 0x41508}, {"MessageTrans_Dictionary", 0x41509}, {"ResourceFS_RegisterFiles", 0x41B40}, {"ResourceFS_DeregisterFiles", 0x41B41}, {"Filter_RegisterPreFilter", 0x42640}, {"Filter_RegisterPostFilter", 0x42641}, {"Filter_DeRegisterPreFilter", 0x42642}, {"Filter_DeRegisterPostFilter", 0x42643}, {"Filter_RegisterRectFilter", 0x42644}, {"Filter_DeRegisterRectFilter", 0x42645}, {"Filter_RegisterCopyFilter", 0x42646}, {"Filter_DeRegisterCopyFilter", 0x42647}, {"Filter_RegisterPostRectFilter", 0x42648}, {"Filter_DeRegisterPostRectFilter", 0x42649}, {"Filter_RegisterPostIconFilter", 0x4264A}, {"Filter_DeRegisterPostIconFilter", 0x4264B}, {"SharedCLibrary_LibInitAPCS_A", 0x80680}, {"SharedCLibrary_LibInitAPCS_R", 0x80681}, {"SharedCLibrary_LibInitModule", 0x80682}, {"SharedCLibrary_LibInitAPCS_32", 0x80683}, {"SharedCLibrary_LibInitModule32", 0x80684}, {NULL, 0} }; #if 0 /* in kernel.c */ static os_error const *last_error; const os_error *_kernel_last_oserror(void) { if (errno == 0) { last_error = NULL; } else { last_error = riscos_error_lookup(0, strerror(errno)); } return last_error; } #endif /* ------------------------------------------------------------------------ * Function: os_generate_error() * * Description: Generates an error and invokes the error handler * * Input: error - value of R0 on entry * * Other notes: Calls SWI 0x2B. */ void os_generate_error(os_error const *e) { last_error = (_kernel_oserror *)e; raise(SIGOSERROR); } /* ------------------------------------------------------------------------ * Function: os_cli() * * Description: Processes a supervisor command * * Input: command - value of R0 on entry * * Other notes: Calls SWI 0x5. */ extern os_error *xos_cli (char const *command) { NOT_USED(command); return NULL; } void os_cli (char const *command) { NOT_USED(command); } /* ------------------------------------------------------------------------ * Function: os_swi_number_to_string() * * Description: Converts a SWI number to a string containing its name * * Input: swi - value of R0 on entry * buffer - value of R1 on entry * size - value of R2 on entry * * Output: used - value of R2 on exit (X version only) * * Returns: R2 (non-X version only) * * Other notes: Calls SWI 0x38. */ os_error *xos_swi_number_to_string (int swi, char *buffer, int size, int *used_) { int index = -1; int nox_swi = swi & ~(1<<17); int used = 0; if( buffer ) { do { index++; } while(swi_names[index].value<nox_swi && swi_names[index].name!=NULL); if(swi_names[index].value==nox_swi) used = size - sprintf(buffer, swi & (1<<17) ? "X%s" : "%s", swi_names[index].name); else used = size - sprintf(buffer, swi & (1<<17) ? "XUser" : "User"); } if (used_) *used_=used; return NULL; } int os_swi_number_to_string (int swi, char *buffer, int size) { int used; xos_swi_number_to_string (swi, buffer, size, &used); return used; } /* ------------------------------------------------------------------------ * Function: os_swi_number_from_string() * * Description: Converts a string to a SWI number if valid * * Input: swi_name - value of R1 on entry * * Output: swi - value of R0 on exit (X version only) * * Returns: R0 (non-X version only) * * Other notes: Calls SWI 0x39. */ extern os_error *xos_swi_number_from_string (char const *swi_name, int *swi) { int index = -1; osbool x = swi_name[0]=='X'; const char *nonx_name = swi_name + (x ? 1:0); do { index++; } while(swi_names[index].name!=NULL && strcmp(nonx_name, swi_names[index].name)!=0); if(swi_names[index].name==NULL) { if (swi) *swi = 0xFFFFFFFF; oserr.errnum = 0x1E6; strcpy(oserr.errmess, "Unknown SWI"); return &oserr; } else { if (swi) *swi = swi_names[index].value + (x ? (1<<17) : 0); return NULL; } } extern int os_swi_number_from_string (char const *swi_name) { int swi; xos_swi_number_from_string (swi_name, &swi); return swi; } /* ------------------------------------------------------------------------ * Function: os_writen() * * Description: Writes a counted string to all of the active output * streams * * Input: s - value of R0 on entry * size - value of R1 on entry * * Other notes: Calls SWI 0x46. */ extern os_error *xos_writen (char const *s, int size) { char *temp = malloc( size + 1); if (temp) { strncpy( temp, s, size ); *(temp + size) = '\0'; fprintf( stderr, "%s\n", temp ); free( temp ); } return NULL; } extern void os_writen (char const *s, int size) { xos_writen( s, size ); } /* ------------------------------------------------------------------------ * Function: os_pretty_print() * * Description: Writes a string with some formatting to all of the active * output streams * * Input: string - value of R0 on entry * dictionary - value of R1 on entry * special - value of R2 on entry * * Other notes: Calls SWI 0x44. */ os_error *xos_pretty_print(char const *string, byte const *arg1, char const *arg2) { for (;;) { char *s = strchr(string, '\r'); if (!s) { puts(string); return NULL; } fwrite(string, s - string, 1, stdout); putc('\n', stdout); string = s + 1; } } void os_pretty_print(char const *string, byte const *arg1, char const *arg2) { xos_pretty_print( string, arg1, arg2 ); } --- NEW FILE: osargs.c --- /* * OS Lib very limited port */ #include <stdio.h> #include "oslib/osargs.h" /* ------------------------------------------------------------------------ * Function: osargs_set_ptrw() * * Description: Writes an open file's sequential file pointer * * Input: file - value of R1 on entry * ptr - value of R2 on entry * * Other notes: Calls SWI 0x9 with R0 = 0x1. */ extern os_error *xosargs_set_ptrw (os_fw file, int ptr) { fseek((FILE*)file, ptr, SEEK_SET); return NULL; } extern void osargs_set_ptrw (os_fw file, int ptr) { xosargs_set_ptrw(file, ptr); } /* ------------------------------------------------------------------------ * Function: osargs_read_extw() * * Description: Reads an open file's extent * * Input: file - value of R1 on entry * * Output: ext - value of R2 on exit (X version only) * * Returns: R2 (non-X version only) * * Other notes: Calls SWI 0x9 with R0 = 0x2. */ extern os_error *xosargs_read_extw (os_fw file, int *ext) { fseek((FILE*)file, 0, SEEK_END); if (ext) *ext = ftell((FILE*)file); return NULL; } extern int osargs_read_extw (os_fw file) { int ext; xosargs_read_extw(file, &ext); return ext; } /* ------------------------------------------------------------------------ * Function: osargs_read_eof_statusw() * * Description: Reads an open file's end-of-file (EOF) status * * Input: file - value of R1 on entry * * Output: eof_status - value of R2 on exit (X version only) * * Returns: R2 (non-X version only) * * Other notes: Calls SWI 0x9 with R0 = 0x5. */ extern os_error *xosargs_read_eof_statusw (os_fw file, osbool *eof_status) { if (eof_status) *eof_status = feof((FILE*)file); return NULL; } extern osbool osargs_read_eof_statusw (os_fw file) { osbool eof_status; xosargs_read_eof_statusw(file, &eof_status); return eof_status; } /* ------------------------------------------------------------------------ * Function: osargs_ensurew() * * Description: Ensures data has been written to a file, or to all files * on the temporary filing system. Uses 32-bit file handle. * * Input: file - value of R1 on entry * * Other notes: Calls SWI 0x9 with R0 = 0xFF. */ extern os_error *xosargs_ensurew (os_fw file) { fflush( (FILE*)file ); return NULL; } extern void osargs_ensurew (os_fw file) { xosargs_ensurew( file ); } --- NEW FILE: osfile.c --- /* * OS Lib very limited port */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <errno.h> #if defined(WIN32) && !defined(_WIN32_WCE) # include "direct.h" # define mkdir _mkdir #elif defined (UNIX) # include <sys/stat.h> /* for mkdir */ #endif #include "oslib/osfile.h" extern const char *uname(const char *file_name, bits load_addr, bits exec_addr); /* --- gloabl data ------------------------------------------------------- */ extern os_error oserr; /* ------------------------------------------------------------------------ * Function: osfile_set_type() * * Description: Writes the file type for an object * * Input: file_name - value of R1 on entry * file_type - value of R2 on entry * * Other notes: Calls SWI 0x8 with R0 = 0x12. */ extern os_error *xosfile_set_type (char const *file_name, bits file_type) { /* do nothing */ return NULL; } extern void osfile_set_type (char const *file_name, bits file_type) { xosfile_set_type (file_name, file_type); } /* ------------------------------------------------------------------------ * Function: osfile_create_dir() * * Description: Creates a directory * * Input: dir_name - value of R1 on entry * entry_count - value of R4 on entry * * Other notes: Calls SWI 0x8 with R0 = 0x8. */ extern os_error *xosfile_create_dir (char const *dir_name, int entry_count) { NOT_USED(entry_count); #if defined (UNIX) if ( mkdir( uname(dir_name,0,0), S_IRUSR | S_IWUSR | S_IXUSR | S_IROTH | S_IWOTH | S_IXOTH ) !=0 && errno!=17 ) #else if(mkdir(uname(dir_name,0,0))!=0 && errno!=17) #endif { oserr.errnum = 0x10001; sprintf(oserr.errmess, "Mkdir error %d", errno); return &oserr; } return NULL; } extern void osfile_create_dir (char const *dir_name, int entry_count) { xosfile_create_dir (dir_name, entry_count); } /* ------------------------------------------------------------------------ * Function: osfile_create() * * Description: Creates an empty untyped file - prefer * OSFile_CreateStamped * * Input: file_name - value of R1 on entry * load_addr - value of R2 on entry * exec_addr - value of R3 on entry * size - value of R5 on entry * * Other notes: Calls SWI 0x8 with R0 = 0x7, R4 = 0x0. */ extern os_error *xosfile_create (char const *file_name, bits load_addr, bits exec_addr, int size) { /* dont use load & exec or open file wont find it */ FILE *f = fopen(uname(file_name, 0, 0), "w"); if(f==NULL) { oserr.errnum=0x10001; strcpy(oserr.errmess, "Unable to create file"); return &oserr; } fseek(f, size-1, SEEK_SET); fputc(0, f); fclose(f); return NULL; } extern void osfile_create (char const *file_name, bits load_addr, bits exec_addr, int size) { xosfile_create (file_name, load_addr, exec_addr, size); } /* ------------------------------------------------------------------------ * Function: osfile_read_stamped() * * Description: Reads catalogue information and file type for an object * using the directory list in File$Path * * Input: file_name - value of R1 on entry * * Output: obj_type - value of R0 on exit (X version only) * load_addr - value of R2 on exit * exec_addr - value of R3 on exit * size - value of R4 on exit * attr - value of R5 on exit * file_type - value of R6 on exit * * Returns: R0 (non-X version only) * * Other notes: Calls SWI 0x8 with R0 = 0x14. */ os_error *xosfile_read_stamped (char const *file_name, fileswitch_object_type *obj_type, bits *load_addr, bits *exec_addr, int *size, fileswitch_attr *attr, bits *file_type) { FILE *f = fopen(uname(file_name,0,0), "rb"); char *s = strrchr(file_name, ','); NOT_USED(attr); if(f==NULL) { if (obj_type) *obj_type = osfile_NOT_FOUND; return(NULL); } fseek(f, 0, SEEK_END); if (size) *size = ftell(f); fclose(f); if (obj_type) *obj_type = osfile_IS_FILE; if (file_type) *file_type = osfile_TYPE_UNTYPED; if(s!=NULL) { sscanf(s, ",%x", file_type); if(*file_type==osfile_TYPE_ABSOLUTE) { if (load_addr) *load_addr = 0x8000; if (exec_addr) *exec_addr = 0x8000; } else if(*file_type==0xfd3) { if (load_addr) *load_addr = 0x8000; if (exec_addr) *exec_addr = 0x8000; } else { if (load_addr) *load_addr = 0; if (exec_addr) *exec_addr = 0; } } return NULL; } fileswitch_object_type osfile_read_stamped (char const *file_name, bits *load_addr, bits *exec_addr, int *size, fileswitch_attr *attr, bits *file_type) { fileswitch_object_type obj_type; xosfile_read_stamped (file_name, &obj_type, load_addr, exec_addr, size, attr, file_type); return obj_type; } /* ------------------------------------------------------------------------ * Function: osfile_load_stamped() * * Description: Loads a file using the directory list in File$Path * * Input: file_name - value of R1 on entry * addr - value of R2 on entry * * Output: obj_type - value of R0 on exit (X version only) * load_addr - value of R2 on exit * exec_addr - value of R3 on exit * size - value of R4 on exit * attr - value of R5 on exit * * Returns: R0 (non-X version only) * * Other notes: Calls SWI 0x8 with R0 = 0xFF, R3 = 0x0. */ os_error *xosfile_load_stamped (char const *file_name, byte *addr, fileswitch_object_type *obj_type, bits *load_addr, bits *exec_addr, int *size_, fileswitch_attr *attr) { FILE *f = fopen(uname(file_name,0,0), "rb"); os_error *perr = NULL; size_t size; NOT_USED(attr); NOT_USED(load_addr); NOT_USED(exec_addr); #if 0 /* no output after error */ if (obj_type) *obj_type = osfile_IS_FILE; #endif if(f==NULL) { #if 0 /* no output after error */ if (obj_type) *obj_type = osfile_NOT_FOUND; #endif oserr.errnum = 1; strcpy(oserr.errmess, "Unable to open file"); return(&oserr); } fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); if(fread(addr, (size_t)size, 1, f)!=1) { #if 0 /* no output after error */ *obj_type = osfile_NOT_FOUND; #endif perr = &oserr; oserr.errnum = 2; strcpy(oserr.errmess, "Unable to read file"); } fclose(f); if (obj_type) *obj_type = osfile_IS_FILE; if (size_) *size_ = size; return perr; } fileswitch_object_type osfile_load_stamped (char const *file_name, byte *addr, bits *load_addr, bits *exec_addr, int *size, fileswitch_attr *attr) { fileswitch_object_type obj_type; os_error *perr = xosfile_load_stamped(file_name, addr, &obj_type, load_addr, exec_addr, size, attr); if(perr) fprintf(stderr, "%s\r\n", perr->errmess); return obj_type; } #if 0 /* ------------------------------------------------------------------------ * Function: osfile_load_stamped_path() * * Description: Calls OS_File 12 to load a file using a specified * directory list * * Input: file_name - value of R1 on entry * addr - value of R2 on entry * path - value of R4 on entry * * Output: obj_type - value of R0 on exit (X version only) * load_addr - value of R2 on exit * exec_addr - value of R3 on exit * size - value of R4 on exit * attr - value of R5 on exit * * Returns: R0 (non-X version only) * * Other notes: Calls SWI 0x8 with R0 = 0xC, R3 = 0x0. */ extern os_error *xosfile_load_stamped_path (char const *file_name, byte *addr, char const *path, fileswitch_object_type *obj_type, bits *load_addr, bits *exec_addr, int *size, fileswitch_attr *attr); extern fileswitch_object_type osfile_load_stamped_path (char const *file_name, byte *addr, char const *path, bits *load_addr, bits *exec_addr, int *size, fileswitch_attr *attr); /* ------------------------------------------------------------------------ * Function: osfile_load_stamped_path_var() * * Description: Calls OS_File 14 to load a file using the directory list * in a specified variable * * Input: file_name - value of R1 on entry * addr - value of R2 on entry * var - value of R4 on entry * * Output: obj_type - value of R0 on exit (X version only) * load_addr - value of R2 on exit * exec_addr - value of R3 on exit * size - value of R4 on exit * attr - value of R5 on exit * * Returns: R0 (non-X version only) * * Other notes: Calls SWI 0x8 with R0 = 0xE, R3 = 0x0. */ extern os_error *xosfile_load_stamped_path_var (char const *file_name, byte *addr, char const *var, fileswitch_object_type *obj_type, bits *load_addr, bits *exec_addr, int *size, fileswitch_attr *attr); extern fileswitch_object_type osfile_load_stamped_path_var (char const *file_name, byte *addr, char const *var, bits *load_addr, bits *exec_addr, int *size, fileswitch_attr *attr); #endif /* ------------------------------------------------------------------------ * Function: osfile_load_stamped_no_path() * * Description: Calls OS_File 16 to load a file * * Input: file_name - value of R1 on entry * addr - value of R2 on entry * * Output: obj_type - value of R0 on exit (X version only) * load_addr - value of R2 on exit * exec_addr - value of R3 on exit * size - value of R4 on exit * attr - value of R5 on exit * * Returns: R0 (non-X version only) * * Other notes: Calls SWI 0x8 with R0 = 0x10, R3 = 0x0. */ extern os_error *xosfile_load_stamped_no_path (char const *file_name, byte *addr, fileswitch_object_type *obj_type, bits *load_addr, bits *exec_addr, int *size, fileswitch_attr *attr) { return xosfile_load_stamped( file_name, addr, obj_type, load_addr, exec_addr, size, attr ); } extern fileswitch_object_type osfile_load_stamped_no_path (char const *file_name, byte *addr, bits *load_addr, bits *exec_addr, int *size, fileswitch_attr *attr) { return osfile_load_stamped( file_name, addr, load_addr, exec_addr, size, attr ); } /* ------------------------------------------------------------------------ * Function: osfile_delete() * * Description: Calls OS_File 6 to delete an object * * Input: file_name - value of R1 on entry * * Output: obj_type - value of R0 on exit (X version only) * load_addr - value of R2 on exit * exec_addr - value of R3 on exit * size - value of R4 on exit * attr - value of R5 on exit * * Returns: R0 (non-X version only) * * Other notes: Calls SWI 0x8 with R0 = 0x6. */ extern os_error *xosfile_delete (char const *file_name, fileswitch_object_type *obj_type_, bits *load_addr_, bits *exec_addr_, int *size_, fileswitch_attr *attr_) { fileswitch_object_type obj_type; bits load_addr; bits exec_addr; int size; fileswitch_attr attr; os_error *err = xosfile_read_stamped( file_name, &obj_type, &load_addr, &exec_addr, &size, &attr, 0 ); if (!err) { if ( remove( file_name ) != 0 ) { // failed oserr.errnum = 1; sprintf( oserr.errmess, "%s", strerror(errno) ); err = &oserr; } else { if (obj_type_) *obj_type_ = obj_type; if (load_addr_) *load_addr_ = load_addr; if (exec_addr_) *exec_addr_ = exec_addr; if (size_) *size_ = size; if (attr_) *attr_ = attr; } } return err; } extern fileswitch_object_type osfile_delete (char const *file_name, bits *load_addr, bits *exec_addr, int *size, fileswitch_attr *attr) { fileswitch_object_type type; xosfile_delete( file_name, &type, load_addr, exec_addr, size, attr ); return type; } /* ------------------------------------------------------------------------ * Function: osfile_save() * * Description: Saves a block of memory as an untyped file - prefer * OSFile_SaveStamped * * Input: file_name - value of R1 on entry * load_addr - value of R2 on entry * exec_addr - value of R3 on entry * data - value of R4 on entry * end - value of R5 on entry * * Other notes: Calls SWI 0x8 with R0 = 0x0. */ extern os_error *xosfile_save (char const *file_name, bits load_addr, bits exec_addr, byte const *data, byte const *end) { FILE *f = fopen(uname(file_name,load_addr,exec_addr), "w"); if(f==NULL) { oserr.errnum=0x10001; strcpy(oserr.errmess, "Unable to save file"); return &oserr; } fwrite(data, (end-data), 1, f); fclose(f); return NULL; } extern void osfile_save (char const *file_name, bits load_addr, bits exec_addr, byte const *data, byte const *end) { xosfile_save (file_name, load_addr, exec_addr, data, end); } --- NEW FILE: osfind.c --- /* * OS Lib very limited port */ #include <stdio.h> #include <string.h> #include <ctype.h> #include "oslib/osfind.h" /* --- gloabl functoin --------------------------------------------------- */ /* * Function: uname * * Input: file_name - modified on exit * load_addr * exec_addr * * Output: static output buffer * * Description: Detects and converts a RISC OS filename to UNIX equivelent * Adds NFS style filetype extension from load & exec addresses * * Other notes: NOTE extremely primative implementation */ const char *uname(const char *file_name, bits load_addr, bits exec_addr) { static char buffer[1024]; char *s = strchr(file_name, '$'); char *d = buffer; if(!s) return file_name; while(*s) { switch(*s) { case '$': /* ignore */ break; case '.': *(d++) = '/'; break; case '/': *(d++) = '.'; break; case '^': *(d++) = '.'; *(d++) = '.'; break; default: *(d++) = *s; break; } s++; } *d = 0; NOT_USED(exec_addr) if((load_addr&0xFFF00000)==0xFFF00000) sprintf(d, ",%03X", (load_addr>>8) & 0xFFF); return buffer; } /* ------------------------------------------------------------------------ * Function: osfind_openinw() * * Description: Opens an existing file with read access only * * Input: flags - value of R0 on entry * file_name - value of R1 on entry * path - value of R2 on entry * * Output: file - value of R0 on exit (X version only) * * Returns: R0 (non-X version only) * * Other notes: Calls SWI 0xD with R0 |= 0x40. */ os_error *xosfind_openinw (osfind_flags flags, char const *file_name, char const *path, os_fw *file_) { os_fw file; NOT_USED(flags); NOT_USED(path); file = (os_fw)fopen(uname(file_name,0,0), "rb"); if (file_) *file_ = file; return NULL; } os_fw osfind_openinw (osfind_flags flags, char const *file_name, char const *path) { os_fw file; xosfind_openinw(flags, file_name, path, &file); return file; } /* ------------------------------------------------------------------------ * Function: osfind_openoutw() * * Description: Creates a new file with read/write access * * Input: flags - value of R0 on entry * file_name - value of R1 on entry * path - value of R2 on entry * * Output: file - value of R0 on exit (X version only) * * Returns: R0 (non-X version only) * * Other notes: Calls SWI 0xD with R0 |= 0x80. */ extern os_error *xosfind_openoutw (osfind_flags flags, char const *file_name, char const *path, os_fw *file_) { os_fw file; NOT_USED(flags); NOT_USED(path); file = (os_fw)fopen(uname(file_name,0,0), "w+b"); if (file_) *file_ = file; return NULL; } extern os_fw osfind_openoutw (osfind_flags flags, char const *file_name, char const *path) { os_fw file; xosfind_openoutw(flags, file_name, path, &file); return file; } /* ------------------------------------------------------------------------ * Function: osfind_openupw() * * Description: Opens an existing file with read/write access * * Input: flags - value of R0 on entry * file_name - value of R1 on entry * path - value of R2 on entry * * Output: file - value of R0 on exit (X version only) * * Returns: R0 (non-X version only) * * Other notes: Calls SWI 0xD with R0 |= 0xC0. */ extern os_error *xosfind_openupw (osfind_flags flags, char const *file_name, char const *path, os_fw *file_) { os_fw file; NOT_USED(flags); NOT_USED(path); file = (os_fw)fopen(uname(file_name,0,0), "r+b"); if (file_) *file_ = file; return NULL; } extern os_fw osfind_openupw (osfind_flags flags, char const *file_name, char const *path) { os_fw file; xosfind_openupw(flags, file_name, path, &file); return file; } /* ------------------------------------------------------------------------ * Function: osfind_closew() * * Description: Closes a file or files * * Input: file - value of R1 on entry * * Other notes: Calls SWI 0xD with R0 = 0x0. */ os_error *xosfind_closew (os_fw file) { fclose((FILE*)file); return NULL; } void osfind_closew (os_fw file) { xosfind_closew (file); } --- NEW FILE: osgbpb.c --- /* osgbpb.c * * OS Lib very limited port */ #include <ctype.h> #include <dirent.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "oslib/osfile.h" #include "oslib/osgbpb.h" extern os_error oserr; /* ------------------------------------------------------------------------ * Function: wild_strcoll() * * Description: Performs strcoll using RISC OS wildcards * * Input: s1 - pointer to search string * s2 - pointer to (wildcarded) reference string * * Output: * * Returns: zero if s1 == s2 * * Other notes: This implementation takes no account of the current locale */ static int wild_strcoll( const char *s1, const char* s2 ) { int stat = 0; if( s1 == 0 && s2 == 0 ) stat = 0; else if ( s1 == 0 && s2 != 0 ) stat = -1; else if ( s1 != 0 && s2 == 0 ) stat = 1; else { do { if( *s2 == '#' ) stat = 0; else if ( *s2 == '*' ) stat = wild_strcoll( strchr( s1, *(s2+1) ), s2+1 ); else stat = *s1 - *s2; } while ( (!stat) && (*++s1 != '\0') && (*++s2 != '\0') ); } return stat; } /* ------------------------------------------------------------------------ * Function: osgbpb_readw() * * Description: Reads bytes from an open file * * Input: file - value of R1 on entry * buffer - value of R2 on entry * size - value of R3 on entry * * Output: unread - value of R3 on exit (X version only) * * Returns: R3 (non-X version only) * * Other notes: Calls SWI 0xC with R0 = 0x4. */ os_error *xosgbpb_readw (os_fw file, byte *buffer, int size, int *unread_) { int unread = size; if (buffer) unread = size - fread(buffer, 1, size, (FILE*)file); if (unread_) *unread_ = unread; return NULL; /* should check for error */ } int osgbpb_readw (os_fw file, byte *buffer, int size) { int unread; xosgbpb_readw(file, buffer, size, &unread); return unread; } /* ------------------------------------------------------------------------ * Function: osgbpb_read_atw() * * Description: Reads bytes from an open file at the specified file * pointer * * Input: file - value of R1 on entry * buffer - value of R2 on entry * size - value of R3 on entry * ptr - value of R4 on entry * * Output: unread - value of R3 on exit (X version only) * * Returns: R3 (non-X version only) * * Other notes: Calls SWI 0xC with R0 = 0x3. */ os_error *xosgbpb_read_atw (os_fw file, byte *buffer, int size, int ptr, int *unread) { fseek((FILE*)file, ptr, SEEK_SET); return xosgbpb_readw(file, buffer, size, unread); } int osgbpb_read_atw (os_fw file, byte *buffer, int size, int ptr) { int unread; xosgbpb_read_atw(file, buffer, size, ptr, &unread); return unread; } /* ------------------------------------------------------------------------ * Function: osgbpb_writew() * * Description: Writes bytes to an open file * * Input: file - value of R1 on entry * data - value of R2 on entry * size - value of R3 on entry * * Output: unwritten - value of R3 on exit (X version only) * * Returns: R3 (non-X version only) * * Other notes: Calls SWI 0xC with R0 = 0x2. */ extern os_error *xosgbpb_writew (os_fw file, byte const *data, int size, int *unwritten_) { int unwritten = size; unwritten = size - fwrite(data, 1, size, (FILE*)file); if (unwritten_) *unwritten_ = unwritten; return NULL; } extern int osgbpb_writew (os_fw file, byte const *data, int size) { int unwritten; xosgbpb_writew(file, data, size, &unwritten); return unwritten; } /* ------------------------------------------------------------------------ * Function: osgbpb_write_atw() * * Description: Writes bytes to an open file at the specified file * pointer * * Input: file - value of R1 on entry * data - value of R2 on entry * size - value of R3 on entry * ptr - value of R4 on entry * * Output: unwritten - value of R3 on exit (X version only) * * Returns: R3 (non-X version only) * * Other notes: Calls SWI 0xC with R0 = 0x1. */ extern os_error *xosgbpb_write_atw (os_fw file, byte const *data, int size, int ptr, int *unwritten) { fseek((FILE*)file, ptr, SEEK_SET); return xosgbpb_writew(file, data, size, unwritten); } extern int osgbpb_write_atw (os_fw file, byte const *data, int size, int ptr) { int unwritten; xosgbpb_write_atw(file, data, size, ptr, &unwritten); return unwritten; } /* ------------------------------------------------------------------------ * Function: osgbpb_dir_entries_info() * * Description: Reads entries and file information from a specified * directory * * Input: dir_name - value of R1 on entry * info_list - value of R2 on entry * count - value of R3 on entry * context - value of R4 on entry * size - valu... [truncated message content] |