Initial import of the CDE 2.1.30 sources from the Open Group.
This commit is contained in:
122
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdgets.c
Normal file
122
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdgets.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/* $XConsortium: stdgets.c /main/3 1995/11/01 18:39:28 rswiston $ */
|
||||
/***************************************************************
|
||||
* *
|
||||
* AT&T - PROPRIETARY *
|
||||
* *
|
||||
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
|
||||
* AT&T CORP. *
|
||||
* *
|
||||
* Copyright (c) 1995 AT&T Corp. *
|
||||
* All Rights Reserved *
|
||||
* *
|
||||
* This software is licensed by AT&T Corp. *
|
||||
* under the terms and conditions of the license in *
|
||||
* http://www.research.att.com/orgs/ssr/book/reuse *
|
||||
* *
|
||||
* This software was created by the *
|
||||
* Software Engineering Research Department *
|
||||
* AT&T Bell Laboratories *
|
||||
* *
|
||||
* For further information contact *
|
||||
* gsf@research.att.com *
|
||||
* *
|
||||
***************************************************************/
|
||||
#include "sfhdr.h"
|
||||
#include "stdio.h"
|
||||
|
||||
/* Read a line into a buffer.
|
||||
**
|
||||
** Written by Kiem-Phong Vo (10/15/91)
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
char *_stdgets(reg Sfio_t *f, char* us, reg int n, int isgets)
|
||||
#else
|
||||
char *_stdgets(f,us,n,isgets)
|
||||
reg Sfio_t *f; /* stream to read from */
|
||||
char *us; /* space to read into */
|
||||
reg int n; /* max number of bytes to read */
|
||||
int isgets; /* gets(), not fgets() */
|
||||
#endif
|
||||
{
|
||||
reg int p;
|
||||
reg uchar *is, *ps;
|
||||
|
||||
if(n <= 0 || !us || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0))
|
||||
return NIL(char*);
|
||||
|
||||
SFLOCK(f,0);
|
||||
|
||||
n -= 1;
|
||||
is = (uchar*)us;
|
||||
|
||||
while(n)
|
||||
{ /* peek the read buffer for data */
|
||||
if((p = f->endb - (ps = f->next)) <= 0 )
|
||||
{ f->getr = '\n';
|
||||
f->mode |= SF_RC;
|
||||
if(SFRPEEK(f,ps,p) <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if(p > n)
|
||||
p = n;
|
||||
|
||||
#if _vax_asm /* p is r9, is is r8, ps is r7 */
|
||||
{ reg int q;
|
||||
q = p; /* save data length */
|
||||
asm( "locc $0xa,r9,(r7)" ); /* look for \n */
|
||||
asm( "subl2 r0,r9" ); /* copy length */
|
||||
if(++p > q) /* if \n found, copy it too */
|
||||
--p;
|
||||
0; /* avoid if branching bug */
|
||||
asm( "movc3 r9,(r7),(r8)" ); /* copy data */
|
||||
ps += p;
|
||||
is += p;
|
||||
}
|
||||
#else
|
||||
#if _lib_memccpy
|
||||
if((ps = (uchar*)memccpy((char*)is,(char*)ps,'\n',p)) != NIL(uchar*))
|
||||
p = ps-is;
|
||||
is += p;
|
||||
ps = f->next+p;
|
||||
#else
|
||||
if(!(f->flags&(SF_BOTH|SF_MALLOC)))
|
||||
{ while(p-- && (*is++ = *ps++) != '\n')
|
||||
;
|
||||
p = ps-f->next;
|
||||
}
|
||||
else
|
||||
{ reg int c = ps[p-1];
|
||||
if(c != '\n')
|
||||
ps[p-1] = '\n';
|
||||
while((*is++ = *ps++) != '\n')
|
||||
;
|
||||
if(c != '\n')
|
||||
{ f->next[p-1] = c;
|
||||
if((ps-f->next) >= p)
|
||||
is[-1] = c;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* gobble up read data and continue */
|
||||
f->next = ps;
|
||||
if(is[-1] == '\n')
|
||||
break;
|
||||
else if(n > 0)
|
||||
n -= p;
|
||||
}
|
||||
|
||||
if((_Sfi = is - ((uchar*)us)) <= 0)
|
||||
us = NIL(char*);
|
||||
else if(isgets && is[-1] == '\n')
|
||||
{ is[-1] = '\0';
|
||||
_Sfi -= 1;
|
||||
}
|
||||
else *is = '\0';
|
||||
|
||||
SFOPEN(f,0);
|
||||
return us;
|
||||
}
|
||||
44
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdopen.c
Normal file
44
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdopen.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* $XConsortium: stdopen.c /main/3 1995/11/01 18:39:42 rswiston $ */
|
||||
/***************************************************************
|
||||
* *
|
||||
* AT&T - PROPRIETARY *
|
||||
* *
|
||||
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
|
||||
* AT&T CORP. *
|
||||
* *
|
||||
* Copyright (c) 1995 AT&T Corp. *
|
||||
* All Rights Reserved *
|
||||
* *
|
||||
* This software is licensed by AT&T Corp. *
|
||||
* under the terms and conditions of the license in *
|
||||
* http://www.research.att.com/orgs/ssr/book/reuse *
|
||||
* *
|
||||
* This software was created by the *
|
||||
* Software Engineering Research Department *
|
||||
* AT&T Bell Laboratories *
|
||||
* *
|
||||
* For further information contact *
|
||||
* gsf@research.att.com *
|
||||
* *
|
||||
***************************************************************/
|
||||
#include "sfhdr.h"
|
||||
|
||||
/* Open a stream given a file descriptor.
|
||||
**
|
||||
** Written by Kiem-Phong Vo (06/27/90).
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
Sfio_t *_stdopen(reg int fd, reg const char* mode)
|
||||
#else
|
||||
Sfio_t *_stdopen(fd,mode)
|
||||
reg int fd;
|
||||
reg char *mode;
|
||||
#endif
|
||||
{
|
||||
int sflags;
|
||||
|
||||
if(fd < 0 || (sflags = _sftype(mode,NIL(int*))) == 0)
|
||||
return NIL(Sfio_t*);
|
||||
else return sfnew(NIL(Sfio_t*),NIL(Void_t*),-1,fd,sflags);
|
||||
}
|
||||
55
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdprintf.c
Normal file
55
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdprintf.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/* $XConsortium: stdprintf.c /main/3 1995/11/01 18:39:55 rswiston $ */
|
||||
/***************************************************************
|
||||
* *
|
||||
* AT&T - PROPRIETARY *
|
||||
* *
|
||||
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
|
||||
* AT&T CORP. *
|
||||
* *
|
||||
* Copyright (c) 1995 AT&T Corp. *
|
||||
* All Rights Reserved *
|
||||
* *
|
||||
* This software is licensed by AT&T Corp. *
|
||||
* under the terms and conditions of the license in *
|
||||
* http://www.research.att.com/orgs/ssr/book/reuse *
|
||||
* *
|
||||
* This software was created by the *
|
||||
* Software Engineering Research Department *
|
||||
* AT&T Bell Laboratories *
|
||||
* *
|
||||
* For further information contact *
|
||||
* gsf@research.att.com *
|
||||
* *
|
||||
***************************************************************/
|
||||
#include "sfhdr.h"
|
||||
#include "stdio.h"
|
||||
|
||||
|
||||
/* printf function
|
||||
**
|
||||
** Written by Kiem-Phong Vo (12/10/90)
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
_stdprintf(const char *form, ...)
|
||||
#else
|
||||
_stdprintf(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
reg int rv;
|
||||
|
||||
#if __STD_C
|
||||
va_start(args,form);
|
||||
#else
|
||||
reg char *form;
|
||||
va_start(args);
|
||||
form = va_arg(args,char*);
|
||||
#endif
|
||||
|
||||
rv = sfvprintf(sfstdout,form,args);
|
||||
|
||||
va_end(args);
|
||||
return rv;
|
||||
}
|
||||
53
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdscanf.c
Normal file
53
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdscanf.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* $XConsortium: stdscanf.c /main/3 1995/11/01 18:40:07 rswiston $ */
|
||||
/***************************************************************
|
||||
* *
|
||||
* AT&T - PROPRIETARY *
|
||||
* *
|
||||
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
|
||||
* AT&T CORP. *
|
||||
* *
|
||||
* Copyright (c) 1995 AT&T Corp. *
|
||||
* All Rights Reserved *
|
||||
* *
|
||||
* This software is licensed by AT&T Corp. *
|
||||
* under the terms and conditions of the license in *
|
||||
* http://www.research.att.com/orgs/ssr/book/reuse *
|
||||
* *
|
||||
* This software was created by the *
|
||||
* Software Engineering Research Department *
|
||||
* AT&T Bell Laboratories *
|
||||
* *
|
||||
* For further information contact *
|
||||
* gsf@research.att.com *
|
||||
* *
|
||||
***************************************************************/
|
||||
#include "sfhdr.h"
|
||||
#include "stdio.h"
|
||||
|
||||
/* Read formatted data from a stream
|
||||
**
|
||||
** Written by Kiem-Phong Vo (06/27/90)
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
_stdscanf(const char *form, ...)
|
||||
#else
|
||||
_stdscanf(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
reg int rv;
|
||||
|
||||
#if __STD_C
|
||||
va_start(args,form);
|
||||
#else
|
||||
reg char *form; /* scanning format */
|
||||
va_start(args);
|
||||
form = va_arg(args,char*);
|
||||
#endif
|
||||
|
||||
rv = sfvscanf(sfstdin,form,args);
|
||||
va_end(args);
|
||||
return rv;
|
||||
}
|
||||
73
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdsprnt.c
Normal file
73
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdsprnt.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/* $XConsortium: stdsprnt.c /main/3 1995/11/01 18:40:19 rswiston $ */
|
||||
/***************************************************************
|
||||
* *
|
||||
* AT&T - PROPRIETARY *
|
||||
* *
|
||||
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
|
||||
* AT&T CORP. *
|
||||
* *
|
||||
* Copyright (c) 1995 AT&T Corp. *
|
||||
* All Rights Reserved *
|
||||
* *
|
||||
* This software is licensed by AT&T Corp. *
|
||||
* under the terms and conditions of the license in *
|
||||
* http://www.research.att.com/orgs/ssr/book/reuse *
|
||||
* *
|
||||
* This software was created by the *
|
||||
* Software Engineering Research Department *
|
||||
* AT&T Bell Laboratories *
|
||||
* *
|
||||
* For further information contact *
|
||||
* gsf@research.att.com *
|
||||
* *
|
||||
***************************************************************/
|
||||
#include "sfhdr.h"
|
||||
#include "stdio.h"
|
||||
|
||||
|
||||
/* sprintf function
|
||||
**
|
||||
** Written by Kiem-Phong Vo (12/10/90)
|
||||
*/
|
||||
|
||||
|
||||
#if __STD_C
|
||||
_stdsprintf(char *s, const char *form, ...)
|
||||
#else
|
||||
_stdsprintf(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
Sfio_t f;
|
||||
reg int rv;
|
||||
|
||||
#if __STD_C
|
||||
va_start(args,form);
|
||||
#else
|
||||
reg char *s;
|
||||
reg char *form;
|
||||
va_start(args);
|
||||
s = va_arg(args,char*);
|
||||
form = va_arg(args,char*);
|
||||
#endif
|
||||
|
||||
if(!s)
|
||||
return -1;
|
||||
|
||||
/* make a fake stream */
|
||||
SFCLEAR(&f);
|
||||
f.flags = SF_STRING|SF_WRITE;
|
||||
f.mode = SF_WRITE;
|
||||
f.size = 4*SF_BUFSIZE;
|
||||
f.data = f.next = f.endr = (uchar*)s;
|
||||
f.endb = f.endw = f.data+f.size;
|
||||
|
||||
rv = sfvprintf(&f,form,args);
|
||||
*f.next = '\0';
|
||||
_Sfi = f.next - f.data;
|
||||
|
||||
va_end(args);
|
||||
|
||||
return rv;
|
||||
}
|
||||
58
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdvbuf.c
Normal file
58
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdvbuf.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/* $XConsortium: stdvbuf.c /main/3 1995/11/01 18:40:31 rswiston $ */
|
||||
/***************************************************************
|
||||
* *
|
||||
* AT&T - PROPRIETARY *
|
||||
* *
|
||||
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
|
||||
* AT&T CORP. *
|
||||
* *
|
||||
* Copyright (c) 1995 AT&T Corp. *
|
||||
* All Rights Reserved *
|
||||
* *
|
||||
* This software is licensed by AT&T Corp. *
|
||||
* under the terms and conditions of the license in *
|
||||
* http://www.research.att.com/orgs/ssr/book/reuse *
|
||||
* *
|
||||
* This software was created by the *
|
||||
* Software Engineering Research Department *
|
||||
* AT&T Bell Laboratories *
|
||||
* *
|
||||
* For further information contact *
|
||||
* gsf@research.att.com *
|
||||
* *
|
||||
***************************************************************/
|
||||
#include "sfhdr.h"
|
||||
#include "stdio.h"
|
||||
|
||||
/* Stdio function setvbuf()
|
||||
**
|
||||
** Written by Kiem-Phong Vo (12/10/90)
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
_stdsetvbuf(Sfio_t* f, char *buf, int type, int size)
|
||||
#else
|
||||
_stdsetvbuf(f,buf,type,size)
|
||||
Sfio_t *f;
|
||||
char *buf;
|
||||
int type;
|
||||
int size;
|
||||
#endif
|
||||
{
|
||||
if(type == _IOLBF)
|
||||
sfset(f,SF_LINE,1);
|
||||
else if((f->flags&SF_STRING))
|
||||
return -1;
|
||||
else if(type == _IONBF)
|
||||
{ sfsync(f);
|
||||
sfsetbuf(f,NIL(Void_t*),0);
|
||||
}
|
||||
else if(type == _IOFBF)
|
||||
{ if(size == 0)
|
||||
size = SF_BUFSIZE;
|
||||
sfsync(f);
|
||||
sfsetbuf(f,(Void_t*)buf,size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
55
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdvsnprnt.c
Normal file
55
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdvsnprnt.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/* $XConsortium: stdvsnprnt.c /main/3 1995/11/01 18:40:43 rswiston $ */
|
||||
/***************************************************************
|
||||
* *
|
||||
* AT&T - PROPRIETARY *
|
||||
* *
|
||||
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
|
||||
* AT&T CORP. *
|
||||
* *
|
||||
* Copyright (c) 1995 AT&T Corp. *
|
||||
* All Rights Reserved *
|
||||
* *
|
||||
* This software is licensed by AT&T Corp. *
|
||||
* under the terms and conditions of the license in *
|
||||
* http://www.research.att.com/orgs/ssr/book/reuse *
|
||||
* *
|
||||
* This software was created by the *
|
||||
* Software Engineering Research Department *
|
||||
* AT&T Bell Laboratories *
|
||||
* *
|
||||
* For further information contact *
|
||||
* gsf@research.att.com *
|
||||
* *
|
||||
***************************************************************/
|
||||
#include "sfhdr.h"
|
||||
|
||||
#if __STD_C
|
||||
_stdvsnprintf(char* s, int n, const char* form, va_list args)
|
||||
#else
|
||||
_stdvsnprintf(s,n,form,args)
|
||||
reg char* s;
|
||||
reg int n;
|
||||
reg char* form;
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
Sfio_t f;
|
||||
reg int rv;
|
||||
|
||||
if(!s)
|
||||
return -1;
|
||||
|
||||
/* make a fake stream */
|
||||
SFCLEAR(&f);
|
||||
f.flags = SF_STRING|SF_WRITE;
|
||||
f.mode = SF_WRITE;
|
||||
f.size = n;
|
||||
f.data = f.next = f.endr = (uchar*)s;
|
||||
f.endb = f.endw = f.data+f.size;
|
||||
|
||||
rv = sfvprintf(&f,form,args);
|
||||
*f.next = '\0';
|
||||
_Sfi = f.next - f.data;
|
||||
|
||||
return rv;
|
||||
}
|
||||
54
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdvsprnt.c
Normal file
54
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdvsprnt.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/* $XConsortium: stdvsprnt.c /main/3 1995/11/01 18:40:54 rswiston $ */
|
||||
/***************************************************************
|
||||
* *
|
||||
* AT&T - PROPRIETARY *
|
||||
* *
|
||||
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
|
||||
* AT&T CORP. *
|
||||
* *
|
||||
* Copyright (c) 1995 AT&T Corp. *
|
||||
* All Rights Reserved *
|
||||
* *
|
||||
* This software is licensed by AT&T Corp. *
|
||||
* under the terms and conditions of the license in *
|
||||
* http://www.research.att.com/orgs/ssr/book/reuse *
|
||||
* *
|
||||
* This software was created by the *
|
||||
* Software Engineering Research Department *
|
||||
* AT&T Bell Laboratories *
|
||||
* *
|
||||
* For further information contact *
|
||||
* gsf@research.att.com *
|
||||
* *
|
||||
***************************************************************/
|
||||
#include "sfhdr.h"
|
||||
|
||||
#if __STD_C
|
||||
_stdvsprintf(char *s, const char *form, va_list args)
|
||||
#else
|
||||
_stdvsprintf(s,form,args)
|
||||
register char *s;
|
||||
register char *form;
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
Sfio_t f;
|
||||
reg int rv;
|
||||
|
||||
if(!s)
|
||||
return -1;
|
||||
|
||||
/* make a fake stream */
|
||||
SFCLEAR(&f);
|
||||
f.flags = SF_STRING|SF_WRITE;
|
||||
f.mode = SF_WRITE;
|
||||
f.size = 4*SF_BUFSIZE;
|
||||
f.data = f.next = f.endr = (uchar*)s;
|
||||
f.endb = f.endw = f.data+f.size;
|
||||
|
||||
rv = sfvprintf(&f,form,args);
|
||||
*f.next = '\0';
|
||||
_Sfi = f.next - f.data;
|
||||
|
||||
return rv;
|
||||
}
|
||||
49
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdvsscn.c
Normal file
49
cde/programs/dtksh/ksh93/src/lib/libast/stdio/stdvsscn.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/* $XConsortium: stdvsscn.c /main/3 1995/11/01 18:41:06 rswiston $ */
|
||||
/***************************************************************
|
||||
* *
|
||||
* AT&T - PROPRIETARY *
|
||||
* *
|
||||
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
|
||||
* AT&T CORP. *
|
||||
* *
|
||||
* Copyright (c) 1995 AT&T Corp. *
|
||||
* All Rights Reserved *
|
||||
* *
|
||||
* This software is licensed by AT&T Corp. *
|
||||
* under the terms and conditions of the license in *
|
||||
* http://www.research.att.com/orgs/ssr/book/reuse *
|
||||
* *
|
||||
* This software was created by the *
|
||||
* Software Engineering Research Department *
|
||||
* AT&T Bell Laboratories *
|
||||
* *
|
||||
* For further information contact *
|
||||
* gsf@research.att.com *
|
||||
* *
|
||||
***************************************************************/
|
||||
#include "sfhdr.h"
|
||||
|
||||
#if __STD_C
|
||||
_stdvsscanf(char *s, const char *form, va_list args)
|
||||
#else
|
||||
_stdvsscanf(s,form,args)
|
||||
register char *s;
|
||||
register char *form;
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
Sfio_t f;
|
||||
|
||||
if(!s)
|
||||
return -1;
|
||||
|
||||
/* make a fake stream */
|
||||
SFCLEAR(&f);
|
||||
f.flags = SF_STRING|SF_READ;
|
||||
f.mode = SF_READ;
|
||||
f.size = strlen((char*)s);
|
||||
f.data = f.next = f.endr = (uchar*)s;
|
||||
f.endb = f.endw = f.data+f.size;
|
||||
|
||||
return sfvscanf(&f,form,args);
|
||||
}
|
||||
Reference in New Issue
Block a user