Commit 228d8073 authored by Guido van Rossum's avatar Guido van Rossum

RISCOS files by dschwertberger

parent c92cdf7a
"""A more or less complete user-defined wrapper around dictionary objects."""
import riscos
class _Environ:
def __init__(self):
pass
def __repr__(self):
return repr(riscos.getenvdict())
def __cmp__(self, dict):
if isinstance(dict, UserDict):
return cmp(riscos.getenvdict(), dict)
def __len__(self):
return len(riscos.getenvdict())
def __getitem__(self, key):
ret = riscos.getenv(key)
if ret<>None:
return ret
else:
raise KeyError
def __setitem__(self, key, item):
riscos.setenv(key, item)
def __delitem__(self, key):
riscos.delenv(key)
def clear(self):
# too dangerous on RISC OS
pass
def copy(self):
return riscos.getenvdict()
def keys(self): return riscos.getenvdict().keys()
def items(self): return riscos.getenvdict().items()
def values(self): return riscos.getenvdict().values()
def has_key(self, key):
value = riscos.getenv(key)
return value<>None
def update(self, dict):
for k, v in dict.items():
riscos.putenv(k, v)
def get(self, key, failobj=None):
value = riscos.getenv(key)
if value<>None:
return value
else:
return failobj
environ = _Environ()
# Module 'riscospath' -- common operations on RISC OS pathnames.
# contributed by Andrew Clover ( andrew@oaktree.co.uk )
# The "os.path" name is an alias for this module on RISC OS systems;
# on other systems (e.g. Mac, Windows), os.path provides the same
# operations in a manner specific to that platform, and is an alias
# to another module (e.g. macpath, ntpath).
"""
Instead of importing this module directly, import os and refer to this module
as os.path.
"""
# Imports - make an error-generating swi object if the swi module is not
# available (ie. we are not running on RISC OS Python)
import os, stat, string
try:
import swi
except ImportError:
class _swi:
def swi(*a):
raise AttributeError, 'This function only available under RISC OS'
block= swi
swi= _swi()
[_false, _true]= range(2)
_roots= ['$', '&', '%', '@', '\\']
# _allowMOSFSNames
# After importing riscospath, set _allowMOSFSNames true if you want the module
# to understand the "-SomeFS-" notation left over from the old BBC Master MOS,
# as well as the standard "SomeFS:" notation. Set this to be fully backwards
# compatible but remember that "-SomeFS-" can also be a perfectly valid file
# name so care must be taken when splitting and joining paths.
_allowMOSFSNames= _false
## Path manipulation, RISC OS stylee.
def _split(p):
"""
split filing system name (including special field) and drive specifier from rest
of path. This is needed by many riscospath functions.
"""
dash= _allowMOSFSNames and p[:1]=='-'
if dash:
q= string.find(p, '-', 1)+1
else:
if p[:1]==':':
q= 0
else:
q= string.find(p, ':')+1 # q= index of start of non-FS portion of path
s= string.find(p, '#')
if s==-1 or s>q:
s= q # find end of main FS name, not including special field
else:
for c in p[dash:s]:
if c not in string.letters:
q= 0
break # disallow invalid non-special-field characters in FS name
r= q
if p[q:q+1]==':':
r= string.find(p, '.', q+1)+1
if r==0:
r= len(p) # find end of drive name (if any) following FS name (if any)
return (p[:q], p[q:r], p[r:])
def normcase(p):
"""
Normalize the case of a pathname. This converts to lowercase as the native RISC
OS filesystems are case-insensitive. However, not all filesystems have to be,
and there's no simple way to find out what type an FS is argh.
"""
return string.lower(p)
def isabs(p):
"""
Return whether a path is absolute. Under RISC OS, a file system specifier does
not make a path absolute, but a drive name or number does, and so does using the
symbol for root, URD, library, CSD or PSD. This means it is perfectly possible
to have an "absolute" URL dependent on the current working directory, and
equally you can have a "relative" URL that's on a completely different device to
the current one argh.
"""
(fs, drive, path)= _split(p)
return drive!='' or path[:1] in _roots
def join(a, *p):
"""
Join path elements with the directory separator, replacing the entire path when
an absolute or FS-changing path part is found.
"""
j= a
for b in p:
(fs, drive, path)= _split(b)
if fs!='' or drive!='' or path[:1] in _roots:
j= b
else:
j= j+'.'+b
return j
def split(p):
"""
Split a path in head (everything up to the last '.') and tail (the rest). FS
name must still be dealt with separately since special field may contain '.'.
"""
(fs, drive, path)= _split(p)
q= string.rfind(path, '.')
if q!=-1:
return (fs+drive+path[:q], path[q+1:])
return ('', p)
def splitext(p):
"""
Split a path in root and extension. This assumes the 'using slash for dot and
dot for slash with foreign files' convention common in RISC OS is in force.
"""
(tail, head)= split(p)
if '/' in head:
q= len(head)-string.rfind(head, '/')
return (p[:-q], p[-q:])
return (p, '')
def splitdrive(p):
"""
Split a pathname into a drive specification (including FS name) and the rest of
the path. The terminating dot of the drive name is included in the drive
specification.
"""
(fs, drive, path)= _split(p)
return (fs+drive, p)
def basename(p):
"""
Return the tail (basename) part of a path.
"""
return split(p)[1]
def dirname(p):
"""
Return the head (dirname) part of a path.
"""
return split(p)[0]
def commonprefix(ps):
"""
Return the longest prefix of all list elements. Purely string-based; does not
separate any path parts. Why am I in os.path?
"""
if len(ps)==0:
return ''
prefix= ps[0]
for p in ps[1:]:
prefix= prefix[:len(p)]
for i in range(len(prefix)):
if prefix[i] <> p[i]:
prefix= prefix[:i]
if i==0:
return ''
break
return prefix
## File access functions. Why are we in os.path?
def getsize(p):
"""
Return the size of a file, reported by os.stat().
"""
st= os.stat(p)
return st[stat.ST_SIZE]
def getmtime(p):
"""
Return the last modification time of a file, reported by os.stat().
"""
st = os.stat(p)
return st[stat.ST_MTIME]
getatime= getmtime
# RISC OS-specific file access functions
def exists(p):
"""
Test whether a path exists.
"""
return swi.swi('OS_File', '5s;i', p)!=0
def isdir(p):
"""
Is a path a directory? Includes image files.
"""
return swi.swi('OS_File', '5s;i', p) in [2, 3]
def isfile(p):
"""
Test whether a path is a file, including image files.
"""
return swi.swi('OS_File', '5s;i', p) in [1, 3]
def islink(p):
"""
RISC OS has no links or mounts.
"""
return _false
ismount= islink
# Same-file testing.
# samefile works on filename comparison since there is no ST_DEV and ST_INO is
# not reliably unique (esp. directories). First it has to normalise the
# pathnames, which it can do 'properly' using OS_FSControl since samefile can
# assume it's running on RISC OS (unlike normpath).
def samefile(fa, fb):
"""
Test whether two pathnames reference the same actual file.
"""
l= 512
b= swi.block(l)
swi.swi('OS_FSControl', 'isb..i', 37, fa, b, l)
fa= b.ctrlstring()
swi.swi('OS_FSControl', 'isb..i', 37, fb, b, l)
fb= b.ctrlstring()
return fa==fb
def sameopenfile(a, b):
"""
Test whether two open file objects reference the same file.
"""
return os.fstat(a)[stat.ST_INO]==os.fstat(b)[stat.ST_INO]
## Path canonicalisation
# 'user directory' is taken as meaning the User Root Directory, which is in
# practice never used, for anything.
def expanduser(p):
(fs, drive, path)= _split(p)
l= 512
b= swi.block(l)
if path[:1]!='@':
return p
if fs=='':
fsno= swi.swi('OS_Args', '00;i')
swi.swi('OS_FSControl', 'iibi', 33, fsno, b, l)
fsname= b.ctrlstring()
else:
if fs[:1]=='-':
fsname= fs[1:-1]
else:
fsname= fs[:-1]
fsname= string.split(fsname, '#', 1)[0] # remove special field from fs
x= swi.swi('OS_FSControl', 'ib2s.i;.....i', 54, b, fsname, l)
if x<l:
urd= b.tostring(0, l-x-1)
else: # no URD! try CSD
x= swi.swi('OS_FSControl', 'ib0s.i;.....i', 54, b, fsname, l)
if x<l:
urd= b.tostring(0, l-x-1)
else: # no CSD! use root
urd= '$'
return fsname+':'+urd+path[1:]
# Environment variables are in angle brackets.
def expandvars(p):
"""
Expand environment variables using OS_GSTrans.
"""
l= 512
b= swi.block(l)
return b.tostring(0, swi.swi('OS_GSTrans', 'sbi;..i', p, b, l))
# Return an absolute path.
def abspath(p):
return normpath(join(os.getcwd(), p))
# Normalize a path. Only special path element under RISC OS is "^" for "..".
def normpath(p):
"""
Normalize path, eliminating up-directory ^s.
"""
(fs, drive, path)= _split(p)
rhs= ''
ups= 0
while path!='':
(path, el)= split(path)
if el=='^':
ups= ups+1
else:
if ups>0:
ups= ups-1
else:
if rhs=='':
rhs= el
else:
rhs= el+'.'+rhs
while ups>0:
ups= ups-1
rhs= '^.'+rhs
return fs+drive+rhs
# Directory tree walk.
# Independent of host system. Why am I in os.path?
def walk(top, func, arg):
"""
walk(top,func,args) calls func(arg, d, files) for each directory "d" in the tree
rooted at "top" (including "top" itself). "files" is a list of all the files and
subdirs in directory "d".
"""
try:
names= os.listdir(top)
except os.error:
return
func(arg, top, names)
for name in names:
name= join(top, name)
if isdir(name) and not islink(name):
walk(name, func, arg)
"""riscos specific module for conversion between pathnames and URLs.
Based on macurl2path.
Do not import directly, use urllib instead."""
import string
import urllib
import os
def url2pathname(pathname):
"Convert /-delimited pathname to mac pathname"
#
# XXXX The .. handling should be fixed...
#
tp = urllib.splittype(pathname)[0]
if tp and tp <> 'file':
raise RuntimeError, 'Cannot convert non-local URL to pathname'
components = string.split(pathname, '/')
# Remove . and embedded ..
i = 0
while i < len(components):
if components[i] == '.':
del components[i]
elif components[i] == '..' and i > 0 and \
components[i-1] not in ('', '..'):
del components[i-1:i+1]
i = i-1
elif components[i] == '' and i > 0 and components[i-1] <> '':
del components[i]
else:
if components[i]<>'..' and string.find(components[i], '.')<>-1 :
components[i] = string.join(string.split(components[i],'.'),'/')
i = i+1
if not components[0]:
# Absolute unix path, don't start with colon
return string.join(components[1:], '.')
else:
# relative unix path, start with colon. First replace
# leading .. by empty strings (giving ::file)
i = 0
while i < len(components) and components[i] == '..':
components[i] = '^'
i = i + 1
return string.join(components, '.')
def pathname2url(pathname):
"convert mac pathname to /-delimited pathname"
if '/' in pathname:
raise RuntimeError, "Cannot convert pathname containing slashes"
components = string.split(pathname, ':')
# Replace empty string ('::') by .. (will result in '/../' later)
for i in range(1, len(components)):
if components[i] == '':
components[i] = '..'
# Truncate names longer than 31 bytes
components = map(lambda x: x[:31], components)
if os.path.isabs(pathname):
return '/' + string.join(components, '/')
else:
return string.join(components, '/')
def test():
for url in ["index.html",
"/SCSI::SCSI4/$/Anwendung/Comm/Apps/!Fresco/Welcome",
"../index.html",
"bar/index.html",
"/foo/bar/index.html",
"/foo/bar/",
"/"]:
print `url`, '->', `url2pathname(url)`
for path in ["drive:",
"drive:dir:",
"drive:dir:file",
"drive:file",
"file",
":file",
":dir:",
":dir:file"]:
print `path`, '->', `pathname2url(path)`
if __name__ == '__main__':
test()
This diff is collapsed.
/* -*- C -*- ***********************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI or Corporation for National Research Initiatives or
CNRI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* Module configuration */
/* !!! !!! !!! This file is edited by the makesetup script !!! !!! !!! */
/* This file contains the table of built-in modules.
See init_builtin() in import.c. */
#include "Python.h"
/* -- ADDMODULE MARKER 1 -- */
extern void PyMarshal_Init();
extern void initimp();
extern void initriscos();
extern void initswi();
struct _inittab _PyImport_Inittab[] = {
{"riscos", initriscos},
/* -- ADDMODULE MARKER 2 -- */
/* This module "lives in" with marshal.c */
{"marshal", PyMarshal_Init},
/* This lives it with import.c */
{"imp", initimp},
/* These entries are here for sys.builtin_module_names */
{"__main__", NULL},
{"__builtin__", NULL},
{"sys", NULL},
/* Sentinel */
{0, 0}
};
This diff is collapsed.
#include "Python.h"
#include "osdefs.h"
static char *prefix,*exec_prefix,*progpath,*module_search_path=0;
static void
calculate_path()
{ char *pypath=getenv("Python$Path");
if(pypath)
{ module_search_path=malloc(strlen(pypath)+1);
if (module_search_path) sprintf(module_search_path,"%s",pypath);
else
{ /* We can't exit, so print a warning and limp along */
fprintf(stderr, "Not enough memory for dynamic PYTHONPATH.\n");
fprintf(stderr, "Using default static PYTHONPATH.\n");
}
}
if(!module_search_path) module_search_path = "<Python$Dir>.Lib";
prefix="";
exec_prefix=prefix;
progpath="<Python$Dir>";
}
/* External interface */
char *
Py_GetPath()
{
if (!module_search_path)
calculate_path();
return module_search_path;
}
char *
Py_GetPrefix()
{
if (!module_search_path)
calculate_path();
return prefix;
}
char *
Py_GetExecPrefix()
{
if (!module_search_path)
calculate_path();
return exec_prefix;
}
char *
Py_GetProgramFullPath()
{
if (!module_search_path)
calculate_path();
return progpath;
}
/* RISCOS module implementation */
#include "h.osfscontrol"
#include "h.osgbpb"
#include "h.os"
#include "h.osfile"
#include "Python.h"
#include <errno.h>
static os_error *e;
static PyObject *RiscosError; /* Exception riscos.error */
static PyObject *riscos_oserror(void)
{ PyErr_SetString(RiscosError,e->errmess);
return 0;
}
static PyObject *riscos_error(char *s) { PyErr_SetString(RiscosError,s);return 0;}
/* RISCOS file commands */
static PyObject *riscos_remove(PyObject *self,PyObject *args)
{ char *path1;
if (!PyArg_Parse(args, "s", &path1)) return NULL;
if (remove(path1)) return PyErr_SetFromErrno(RiscosError);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *riscos_rename(PyObject *self,PyObject *args)
{ char *path1, *path2;
if (!PyArg_Parse(args, "(ss)", &path1, &path2)) return NULL;
if (rename(path1,path2)) return PyErr_SetFromErrno(RiscosError);;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *riscos_system(PyObject *self,PyObject *args)
{ char *command;
if (!PyArg_Parse(args, "s", &command)) return NULL;
return PyInt_FromLong(system(command));
}
static PyObject *riscos_chdir(PyObject *self,PyObject *args)
{ char *path;
if (!PyArg_Parse(args, "s", &path)) return NULL;
e=xosfscontrol_dir(path);
if(e) return riscos_oserror();
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *canon(char *path)
{ int len;
PyObject *obj;
char *buf;
e=xosfscontrol_canonicalise_path(path,0,0,0,0,&len);
if(e) return riscos_oserror();
obj=PyString_FromStringAndSize(NULL,-len);
if(obj==NULL) return NULL;
buf=PyString_AsString(obj);
e=xosfscontrol_canonicalise_path(path,buf,0,0,1-len,&len);
if(len!=1) return riscos_error("Error expanding path");
if(!e) return obj;
Py_DECREF(obj);
return riscos_oserror();
}
static PyObject *riscos_getcwd(PyObject *self,PyObject *args)
{ if(!PyArg_NoArgs(args)) return NULL;
return canon("@");
}
static PyObject *riscos_expand(PyObject *self,PyObject *args)
{ char *path;
if (!PyArg_Parse(args, "s", &path)) return NULL;
return canon(path);
}
static PyObject *riscos_mkdir(PyObject *self,PyObject *args)
{ char *path;
int mode;
if (!PyArg_ParseTuple(args, "s|i", &path, &mode)) return NULL;
e=xosfile_create_dir(path,0);
if(e) return riscos_oserror();
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *riscos_listdir(PyObject *self,PyObject *args)
{ char *path,buf[256];
PyObject *d, *v;
int c=0,count;
if (!PyArg_Parse(args, "s", &path)) return NULL;
d=PyList_New(0);
if(!d) return NULL;
for(;;)
{ e=xosgbpb_dir_entries(path,(osgbpb_string_list*)buf,
1,c,256,0,&count,&c);
if(e)
{ Py_DECREF(d);return riscos_oserror();
}
if(count)
{ v=PyString_FromString(buf);
if(!v) { Py_DECREF(d);return 0;}
if(PyList_Append(d,v)) {Py_DECREF(d);Py_DECREF(v);return 0;}
}
if(c==-1) break;
}
return d;
}
static PyObject *riscos_stat(PyObject *self,PyObject *args)
{ char *path;
int ob,len;
bits t=0;
bits ld,ex,at,ft,mode;
if (!PyArg_Parse(args, "s", &path)) return NULL;
e=xosfile_read_stamped_no_path(path,&ob,&ld,&ex,&len,&at,&ft);
if(e) return riscos_oserror();
switch (ob)
{ case osfile_IS_FILE:mode=0100000;break; /* OCTAL */
case osfile_IS_DIR:mode=040000;break;
case osfile_IS_IMAGE:mode=0140000;break;
default:return riscos_error("Not found");
}
if(ft!=-1) t=unixtime(ld,ex);
mode|=(at&7)<<6;
mode|=((at&112)*9)>>4;
return Py_BuildValue("(lllllllllllll)",
(long)mode,/*st_mode*/
0,/*st_ino*/
0,/*st_dev*/
0,/*st_nlink*/
0,/*st_uid*/
0,/*st_gid*/
(long)len,/*st_size*/
(long)t,/*st_atime*/
(long)t,/*st_mtime*/
(long)t,/*st_ctime*/
(long)ft,/*file type*/
(long)at,/*attributes*/
(long)ob/*object type*/
);
}
static PyObject *riscos_chmod(PyObject *self,PyObject *args)
{ char *path;
bits mode;
bits attr;
attr=(mode&0x700)>>8;
attr|=(mode&7)<<4;
if (!PyArg_Parse(args, "(si)", &path,(int*)&mode)) return NULL;
e=xosfile_write_attr(path,attr);
if(e) return riscos_oserror();
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *riscos_utime(PyObject *self,PyObject *args)
{ char *path;
int x,y;
if (!PyArg_Parse(args, "(s(ii))", &path,&x,&y)) return NULL;
e=xosfile_stamp(path);
if(e) return riscos_oserror();
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *riscos_settype(PyObject *self,PyObject *args)
{ char *path,*name;
int type;
if (!PyArg_Parse(args, "(si)", &path,&type))
{ PyErr_Clear();
if (!PyArg_Parse(args, "(ss)", &path,&name)) return NULL;
e=xosfscontrol_file_type_from_string(name,(bits*)&type);
if(e) return riscos_oserror();
}
e=xosfile_set_type(path,type);
if(e) return riscos_oserror();
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *riscos_getenv(PyObject *self,PyObject *args)
{ char *name,*value;
if(!PyArg_Parse(args,"s",&name)) return NULL;
value=getenv(name);
if(value) return PyString_FromString(value);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *riscos_putenv(PyObject *self,PyObject *args)
{ char *name,*value;
int len;
os_var_type type=os_VARTYPE_LITERAL_STRING;
if(!PyArg_ParseTuple(args,"ss|i",&name,&value,&type)) return NULL;
if(type!=os_VARTYPE_STRING&&type!=os_VARTYPE_MACRO&&type!=os_VARTYPE_EXPANDED
&&type!=os_VARTYPE_LITERAL_STRING)
return riscos_error("Bad putenv type");
len=strlen(value);
if(type!=os_VARTYPE_LITERAL_STRING) len++;
/* Other types need null terminator! */
e=xos_set_var_val(name,(byte*)value,len,0,type,0,0);
if(e) return riscos_oserror();
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *riscos_delenv(PyObject *self,PyObject *args)
{ char *name;
if(!PyArg_Parse(args,"s",&name)) return NULL;
e=xos_set_var_val(name,NULL,-1,0,0,0,0);
if(e) return riscos_oserror();
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *riscos_getenvdict(PyObject *self,PyObject *args)
{ PyObject *dict;
char value[257];
char *which="*";
int size;
char *context=NULL;
if(!PyArg_ParseTuple(args,"|s",&which)) return NULL;
dict = PyDict_New();
if (!dict) return NULL;
/* XXX This part ignores errors */
while(!xos_read_var_val(which,value,sizeof(value)-1,(int)context,
os_VARTYPE_EXPANDED,&size,(int *)&context,0))
{ PyObject *v;
value[size]='\0';
v = PyString_FromString(value);
if (v == NULL) continue;
PyDict_SetItemString(dict, context, v);
Py_DECREF(v);
}
return dict;
}
static PyMethodDef riscos_methods[] = {
{"unlink", riscos_remove},
{"remove", riscos_remove},
{"rename", riscos_rename},
{"system", riscos_system},
{"rmdir", riscos_remove},
{"chdir", riscos_chdir},
{"getcwd", riscos_getcwd},
{"expand", riscos_expand},
{"mkdir", riscos_mkdir,1},
{"listdir", riscos_listdir},
{"stat", riscos_stat},
{"lstat", riscos_stat},
{"chmod", riscos_chmod},
{"utime", riscos_utime},
{"settype", riscos_settype},
{"getenv", riscos_getenv},
{"putenv", riscos_putenv},
{"delenv", riscos_delenv},
{"getenvdict", riscos_getenvdict,1},
{NULL, NULL} /* Sentinel */
};
void
initriscos()
{
PyObject *m, *d;
m = Py_InitModule("riscos", riscos_methods);
d = PyModule_GetDict(m);
/* Initialize riscos.error exception */
RiscosError = PyString_FromString("riscos.error");
if (RiscosError == NULL || PyDict_SetItemString(d, "error", RiscosError) != 0)
Py_FatalError("can't define riscos.error");
}
This diff is collapsed.
/***********************************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI or Corporation for National Research Initiatives or
CNRI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* This module provides the necessary stubs for when dynamic loading is
not present. */
#include "Python.h"
#include "importdl.h"
#include "dlk.h"
const struct filedescr _PyImport_DynLoadFiletab[] = {
{"/pyd", "rb", C_EXTENSION},
{0, 0}
};
void dynload_init_dummy()
{
}
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
char *pathname, FILE *fp)
{
int err;
char errstr[256];
err = dlk_load(pathname);
if (err)
{
sprintf(errstr, "dlk failure %d", err);
PyErr_SetString(PyExc_ImportError, errstr);
}
return dynload_init_dummy;
}
char *getcwd(char *buf, int size)
{
buf[0] = '\0';
return buf;
}
#include <stdio.h>
#define __swi
#include "osfile.h"
long PyOS_GetLastModificationTime(char *path, FILE *fp)
{
int obj;
bits load, exec, ftype;
if (xosfile_read_stamped_no_path(path, &obj, &load, &exec, 0, 0, &ftype)) return -1;
if (obj != osfile_IS_FILE) return -1;
if (ftype == osfile_TYPE_UNTYPED) return -1;
load &= 0xFF;
load -= 51;
if (exec < 1855548004U) load--;
exec -= 1855548004U;
return exec/100+42949672*load+(95*load)/100;
}
This directory contains files for the RISC OS port of Python.
For more information about RISC OS see http://www.riscos.com/ .
This port is currently being maintained by Dietmar Schwertberger,
dietmar@schwertberger.de .
On http://www.schwertberger.de you may find compiled versions and libraries
as well as RISC OS specific documentation and extensions.
==========================================================================
Compiling:
1. Extract Files from archive directory 'Python-...' to a directory named
'!Python'.
2. Use a tool like Rename to change filenames from '*/[ch]' into '[ch].*'.
3. Create missing directories with 'amu cdirs'.
4. Build with 'amu'.
I've only tested Acorn C/C++ 5.06 and amu.
You will also need some additional libraries:
DLK
ftp://ftp.infc.ulst.ac.uk/pub/users/chris/
OSLib
http://www.mk-net.demon.co.uk/oslib
zlib (optional)
ftp://ftp.freesoftware.com/pub/infozip/zlib/
sockets (optional)
http://www.mirror.ac.uk/sites/ftp.acorn.co.uk/pub/riscos/releases/networking/tcpip/sockets.arc
expat (optional)
http://sourceforge.net/projects/expat/
(makefile and config.h available from http://www.schwertberger.de/riscos_expat.zip
This diff is collapsed.
/* Fudge unix isatty and fileno for RISCOS */
#include "h.unixstuff"
#include <math.h>
#include "h.osfile"
int fileno(FILE *f)
{ return (int)f;
}
int isatty(int fn)
{ return (fn==fileno(stdin));
}
bits unixtime(bits ld,bits ex)
{ ld&=0xFF;
ld-=51;
if(ex<1855548004U) ld--;
ex-=1855548004U;
return ex/100+42949672*ld+(95*ld)/100;
}
int unlink(char *fname)
{ remove(fname);
return 0;
}
/*#define RET(k) {printf(" %d\n",k);return k;}*/
#define RET(k) return k
int isdir(char *fn)
{ int ob;
/* printf("isdir %s",fn);*/
if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) RET(0);
switch (ob)
{ case osfile_IS_DIR:RET(1);
case osfile_IS_IMAGE:RET(1);
}
RET(0);
}
int isfile(char *fn)
{ int ob; /*printf("isfile %s",fn);*/
if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) RET(0);
switch (ob)
{ case osfile_IS_FILE:RET(1);
case osfile_IS_IMAGE:RET(1);
}
RET(0);
}
int exists(char *fn)
{ int ob; /*printf("exists %s",fn);*/
if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) RET(0);
switch (ob)
{ case osfile_IS_FILE:RET(1);
case osfile_IS_DIR:RET(1);
case osfile_IS_IMAGE:RET(1);
}
RET(0);
}
/* Fudge unix isatty and fileno for RISCOS */
#include <stdio.h>
int fileno(FILE *f);
int isatty(int fn);
unsigned int unixtime(unsigned int ld,unsigned int ex);
/*long PyOS_GetLastModificationTime(char *name);*/
int unlink(char *fname);
int isdir(char *fn);
int isfile(char *fn);
int exists(char *fn);
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