Annotation of coherent/g/usr/bin/vi/atari.c, revision 1.1.1.1

1.1       root        1: /* atari.c */
                      2: 
                      3: /* Author:
                      4:  *     Guntram Blohm
                      5:  *     Buchenstrasse 19
                      6:  *     7904 Erbach, West Germany
                      7:  *     Tel. ++49-7305-6997
                      8:  *     sorry - no regular network connection
                      9:  */
                     10: 
                     11: /*
                     12:  * This file contains the 'standard' functions which are not supported
                     13:  * by Atari/Mark Williams, and some other TOS-only requirements.
                     14:  */
                     15:  
                     16: #include "config.h"
                     17: #include "vi.h"
                     18: 
                     19: #if TOS
                     20: #include <osbind.h>
                     21: 
                     22: /* vi uses mode==0 only ... */
                     23: int access(file, mode)
                     24:        char *file;
                     25: {
                     26:        int fd=Fopen(file, 0);
                     27:        if (fd<0)
                     28:                return -1;
                     29:        Fclose(fd);
                     30:        return 0;
                     31: }
                     32: 
                     33: char *mktemp(template)
                     34:        char *template;
                     35: {
                     36:        return template;
                     37: }
                     38: 
                     39: #ifndef __GNUC__
                     40: char *getcwd(buf, size)
                     41:        char *buf;
                     42: {
                     43:        if (size < 2 + 64)
                     44:                return (char *)0;
                     45:        buf[0] = Dgetdrv() + 'A';
                     46:        buf[1] = ':';
                     47:        Dgetpath(buf + 2, 0);
                     48:        return buf;
                     49: }
                     50: #endif
                     51: 
                     52: /* read -- text mode, compress \r\n to \n
                     53:  * warning: might fail when maxlen==1 and at eol
                     54:  */
                     55: 
                     56: int tread(fd, buf, maxlen)
                     57:        int fd;
                     58:        char *buf;
                     59:        int maxlen;
                     60: {
                     61:        int i, j, nread=read(fd, buf, (unsigned)maxlen);
                     62: 
                     63:        if (nread && buf[nread-1]=='\r')
                     64:        {       nread--;
                     65:                lseek(fd, -1l, 1);
                     66:        }
                     67:        for (i=j=0; j<nread; i++,j++)
                     68:        {       if (buf[j]=='\r' && buf[j+1]=='\n')
                     69:                        j++;
                     70:                buf[i]=buf[j];
                     71:        }
                     72:        return i;
                     73: }
                     74: 
                     75: int twrite(fd, buf, maxlen)
                     76:        int fd;
                     77:        char *buf;
                     78:        int maxlen;
                     79: {
                     80:        int i, j, nwritten=0, hadnl=0;
                     81:        char writbuf[BLKSIZE];
                     82: 
                     83:        for (i=j=0; j<maxlen; )
                     84:        {
                     85:                if ((writbuf[i++]=buf[j++])=='\n')
                     86:                {       writbuf[i-1]='\r';
                     87:                        if (i<BLKSIZE)
                     88:                                writbuf[i++]='\n';
                     89:                        else
                     90:                                hadnl=1;
                     91:                }
                     92:                if (i==BLKSIZE)
                     93:                {
                     94:                        write(fd, writbuf, (unsigned)i);
                     95:                        i=0;
                     96:                }
                     97:                if (hadnl)
                     98:                {
                     99:                        writbuf[i++]='\n';
                    100:                        hadnl=0;
                    101:                }
                    102:        }
                    103:        if (i)
                    104:                write(fd, writbuf, (unsigned)i);
                    105:        return j;
                    106: }
                    107: 
                    108: 
                    109: /* The "timer" variable is used as a shadow of the system's timer.  Since the
                    110:  * system's timer can only be accessed in Supervisor mode, we are forced to
                    111:  * do a Supexec(gettime) to copy the system's timer in to the User-mode "timer"
                    112:  * variable.
                    113:  */
                    114: static int timer;
                    115: static gettime()
                    116: {
                    117:        timer = *(long *)(0x4ba);
                    118: }
                    119: 
                    120: /* This function implements a read-with-timeout from the keyboard. */
                    121: /*ARGSUSED*/
                    122: int ttyread(buf, len, time)
                    123:        char    *buf;   /* where to store the gotten characters */
                    124:        int     len;    /* maximum number of characters to get -- ignored */
                    125:        int     time;   /* maximum time to allow for reading */
                    126: {
                    127:        int     pos=0;
                    128:        long    l;
                    129:        long    endtime;
                    130: 
                    131:        /* compute the ending time, in increments of 1/200th seconds */
                    132:        Supexec(gettime);
                    133:        endtime = time * 20 + timer;
                    134: 
                    135:        /* wait until time runs out, or we get a keystroke */
                    136:        while (!pos && (!time || timer < endtime))
                    137:        {
                    138:                if (Bconstat(2))
                    139:                {
                    140:                        l = Bconin(2);
                    141:                        buf[pos] = l;
                    142:                        if (buf[pos++] == '\0')
                    143:                        {
                    144:                                buf[pos - 1] = '#';
                    145:                                buf[pos++] = l >> 16;
                    146:                        }
                    147:                }
                    148:                Supexec(gettime);
                    149:        }
                    150:        return pos;
                    151: }
                    152: 
                    153: /* This function writes characters to the screen */
                    154: ttywrite(buf, len)
                    155:        char *buf;
                    156:        int len;
                    157: {
                    158:        while (len--)
                    159:                Bconout(2, *buf++);
                    160: }
                    161: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.