2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: sfputr.c /main/3 1995/11/01 18:34:20 rswiston $ */
24 /***************************************************************
26 * AT&T - PROPRIETARY *
28 * THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
31 * Copyright (c) 1995 AT&T Corp. *
32 * All Rights Reserved *
34 * This software is licensed by AT&T Corp. *
35 * under the terms and conditions of the license in *
36 * http://www.research.att.com/orgs/ssr/book/reuse *
38 * This software was created by the *
39 * Software Engineering Research Department *
40 * AT&T Bell Laboratories *
42 * For further information contact *
43 * gsf@research.att.com *
45 ***************************************************************/
48 /* Put out a nul-terminated string
49 ** Note that the reg declarations below must be kept in
50 ** their relative order so that the code will configured
51 ** correctly on Vaxes to use "asm()".
53 ** Written by Kiem-Phong Vo
56 sfputr(reg Sfio_t* f, const char* s, reg int rc)
59 reg Sfio_t* f; /* write to this stream. r11 on Vax */
60 char* s; /* string to write */
61 reg int rc; /* record separator. r10 on Vax */
64 reg int p; /* r9 on Vax */
65 reg uchar *os, *ps; /* r8, r7 on Vax */
66 reg int n; /* r6 on Vax */
68 if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)
74 { /* unbuffered stream */
75 n = strlen((char*)os);
76 if((p = SFWRITE(f,(Void_t*)os,n)) > 0)
82 { /* peek buffer for space */
83 if(SFWPEEK(f,ps,p) <= 0)
86 #if _vax_asm /* p is r9, os is r8, and ps is r7 */
87 0; /* avoid if() branching bug */
88 asm( "locc $0,r9,(r8)" ); /* look for the \0 */
89 asm( "subl2 r0,r9" ); /* length of data to copy */
90 asm( "movc3 r9,(r8),(r7)" ); /* copy data */
95 if((ps = (uchar*)memccpy(ps,os,'\0',p)) != NIL(uchar*))
101 while((*ps++ = *os++) != '\0' && --p > 0)
112 p = (char*)os - (char*)s;
114 { if(f->next >= f->endb)
115 (void)SFFLSBUF(f,(int)((uchar)rc));
116 else *f->next++ = (uchar)rc;
120 /* sync unseekable shared streams */
121 if(f->extent < 0 && (f->flags&SF_SHARE) )
122 (void)SFFLSBUF(f,-1);
124 /* check for line buffering */
125 else if((f->flags&SF_LINE) && !(f->flags&SF_STRING) && (n = f->next-f->data) > 0)
129 (void)SFWRITE(f,(Void_t*)f->next,n);