134f9b3eeSRoland Mainz /***********************************************************************
234f9b3eeSRoland Mainz * *
334f9b3eeSRoland Mainz * This software is part of the ast package *
4*3e14f97fSRoger A. Faulkner * Copyright (c) 1985-2010 AT&T Intellectual Property *
534f9b3eeSRoland Mainz * and is licensed under the *
634f9b3eeSRoland Mainz * Common Public License, Version 1.0 *
734f9b3eeSRoland Mainz * by AT&T Intellectual Property *
834f9b3eeSRoland Mainz * *
934f9b3eeSRoland Mainz * A copy of the License is available at *
1034f9b3eeSRoland Mainz * http://www.opensource.org/licenses/cpl1.0.txt *
1134f9b3eeSRoland Mainz * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1234f9b3eeSRoland Mainz * *
1334f9b3eeSRoland Mainz * Information and Software Systems Research *
1434f9b3eeSRoland Mainz * AT&T Research *
1534f9b3eeSRoland Mainz * Florham Park NJ *
1634f9b3eeSRoland Mainz * *
1734f9b3eeSRoland Mainz * Glenn Fowler <gsf@research.att.com> *
1834f9b3eeSRoland Mainz * David Korn <dgk@research.att.com> *
1934f9b3eeSRoland Mainz * Phong Vo <kpv@research.att.com> *
2034f9b3eeSRoland Mainz * *
2134f9b3eeSRoland Mainz ***********************************************************************/
2234f9b3eeSRoland Mainz #include "sfhdr.h"
2334f9b3eeSRoland Mainz
2434f9b3eeSRoland Mainz /* Walk streams and run operations on them
2534f9b3eeSRoland Mainz **
2634f9b3eeSRoland Mainz ** Written by Kiem-Phong Vo.
2734f9b3eeSRoland Mainz */
2834f9b3eeSRoland Mainz
2934f9b3eeSRoland Mainz #if __STD_C
sfwalk(Sfwalk_f walkf,Void_t * data,int type)3034f9b3eeSRoland Mainz int sfwalk(Sfwalk_f walkf, Void_t* data, int type)
3134f9b3eeSRoland Mainz #else
3234f9b3eeSRoland Mainz int sfwalk(walkf, data, type)
3334f9b3eeSRoland Mainz Sfwalk_f walkf; /* return <0: stop, >=0: continue */
3434f9b3eeSRoland Mainz Void_t* data;
3534f9b3eeSRoland Mainz int type; /* walk streams with all given flags */
3634f9b3eeSRoland Mainz #endif
3734f9b3eeSRoland Mainz {
3834f9b3eeSRoland Mainz Sfpool_t *p;
3934f9b3eeSRoland Mainz Sfio_t *f;
4034f9b3eeSRoland Mainz int n, rv;
4134f9b3eeSRoland Mainz
4234f9b3eeSRoland Mainz /* truly initializing std-streams before walking */
4334f9b3eeSRoland Mainz if(sfstdin->mode & SF_INIT)
4434f9b3eeSRoland Mainz _sfmode(sfstdin, (sfstdin->mode & SF_RDWR), 0);
4534f9b3eeSRoland Mainz if(sfstdout->mode & SF_INIT)
4634f9b3eeSRoland Mainz _sfmode(sfstdout, (sfstdout->mode & SF_RDWR), 0);
4734f9b3eeSRoland Mainz if(sfstderr->mode & SF_INIT)
4834f9b3eeSRoland Mainz _sfmode(sfstderr, (sfstderr->mode & SF_RDWR), 0);
4934f9b3eeSRoland Mainz
5034f9b3eeSRoland Mainz for(rv = 0, p = &_Sfpool; p; p = p->next)
5134f9b3eeSRoland Mainz { for(n = 0; n < p->n_sf; )
5234f9b3eeSRoland Mainz { f = p->sf[n];
5334f9b3eeSRoland Mainz
5434f9b3eeSRoland Mainz if(type != 0 && (f->_flags&type) != type )
5534f9b3eeSRoland Mainz continue; /* not in the interested set */
5634f9b3eeSRoland Mainz
5734f9b3eeSRoland Mainz if((rv = (*walkf)(f, data)) < 0)
5834f9b3eeSRoland Mainz return rv;
5934f9b3eeSRoland Mainz
6034f9b3eeSRoland Mainz if(p->sf[n] == f) /* move forward to next stream */
6134f9b3eeSRoland Mainz n += 1;
6234f9b3eeSRoland Mainz /* else - a sfclose() was done on current stream */
6334f9b3eeSRoland Mainz }
6434f9b3eeSRoland Mainz }
6534f9b3eeSRoland Mainz
6634f9b3eeSRoland Mainz return rv;
6734f9b3eeSRoland Mainz }
68