[comp.unix.programmer] What does index

tore@bibsyst.UUCP (Tore Morkemo) (03/27/91)

Could anyone please tell me what rindex() and index() are supposed to do ??

I found these in a bsd-source and since I'm on a SYSV I can't find them.

Tore.

+------------------------------ saw here ------------------------------+
!   Tore Morkemo, Bibliotek-Systemer A/S, N-3250 Larvik, Norway        !
!   uucp: ...nuug!bibsyst.no!tore    Tel: +47 34 82 202                !
!            tore@bibsyst.uucp       Fax: +47 34 85 185                !
+----------------------------------------------------------------------+

bamford@cbnewsd.att.com (harold.e.bamford) (03/28/91)

In article <375@bibsyst.UUCP> tore@bibsyst.UUCP (Tore Morkemo) writes:
>Could anyone please tell me what rindex() and index() are supposed to do ??
>
>I found these in a bsd-source and since I'm on a SYSV I can't find them.

#define  index(a,b) strchr(a,b)
#define rindex(a,b) strrchr(a,b)

Good luck.

-- Harold

tim@mismpc.dal.fsd.mot.com (Tim Dawson) (03/28/91)

tore@bibsyst.UUCP (Tore Morkemo) writes:

>Could anyone please tell me what rindex() and index() are supposed to do ??

On System V, strchr and strrchr perform the same functions - typically if you:

#define index strchr
#define rindex strrchr

everything will work OK.

niklas@appli.se (Niklas Hallqvist) (03/28/91)

tore@bibsyst.UUCP (Tore Morkemo) writes:

>Could anyone please tell me what rindex() and index() are supposed to do ??

index == strchr
rindex == strrchr

Well, I would have mailed this if it hadn't triggered a question that's
been floating in the back of my head for the last five years.

Is there something like a porting guide for C-programs under Unix?
This guide would present the differences between all the main variants
of Unix.  Specifically differences in library functions and ioctl commands
are interesting.  I know the knowledge is out there, has anyone written
it down?

					Niklas

-- 
Niklas Hallqvist	Phone: +46-(0)31-40 75 00
Applitron Datasystem	Fax:   +46-(0)31-83 39 50
Molndalsvagen 95	Email: niklas@appli.se
S-412 63  GOTEBORG, Sweden     mcsun!sunic!chalmers!appli!niklas

jpm@logixwi.uucp (Jan-Piet Mens @ Logix GmbH, Wiesbaden) (03/28/91)

In article <375@bibsyst.UUCP> tore@bibsyst.UUCP (Tore Morkemo) writes:
>Could anyone please tell me what rindex() and index() are supposed to do ??

Index() does the same as strchr() on SYS5, and rindex() is strrchr().
	
	#define rindex strrchr
	#define index strchr

Regards,
	JP
-- 
Jan-Piet Mens, Logix GmbH				    jpm@logixwi.UUCP
Moritzstr. 50, D-6200 Wiesbaden            ...!uunet!mcsun!unido!logixwi!jpm

decot@hpisod2.cup.hp.com (Dave Decot) (03/29/91)

> Could anyone please tell me what rindex() and index() are supposed to do ??
> 
> I found these in a bsd-source and since I'm on a SYSV I can't find them.

They are supposed to do precisely what strrchr() and strchr() do,
respectively.

You can solve the problem by adding this:

#define index	strchr
#define rindex	strrchr

to all the source files that use them (or to a global header file), or
by adding:

   -Dindex=strchr -Drindex=strrchr

to your CFLAGS environment variable, either directly or in the Makefile.

Dave Decot

robtu@itx.isc.com (Rob Tulloh) (03/29/91)

niklas@appli.se (Niklas Hallqvist) writes:

>tore@bibsyst.UUCP (Tore Morkemo) writes:


>Well, I would have mailed this if it hadn't triggered a question that's
>been floating in the back of my head for the last five years.

>Is there something like a porting guide for C-programs under Unix?
>This guide would present the differences between all the main variants
>of Unix.  Specifically differences in library functions and ioctl commands
>are interesting.  I know the knowledge is out there, has anyone written
>it down?

In answer to this query, may I suggest 'Using C on the Unix System'. It
is one of the NutShell books and I have found it to be of great use when
trying to figure out what's what between System V and BSD. I will point
out that it mostly addresses the system level calls though, so if you
are looking for strchr == index, it's not going to help. However, signals,
i/o, and other such stuff is very well represented from both points of
view.


>					Niklas

>-- 
>Niklas Hallqvist	Phone: +46-(0)31-40 75 00
>Applitron Datasystem	Fax:   +46-(0)31-83 39 50
>Molndalsvagen 95	Email: niklas@appli.se
>S-412 63  GOTEBORG, Sweden     mcsun!sunic!chalmers!appli!niklas

Rob Tulloh
--
INTERACTIVE Systems Corp.         Tel: (512) 343 0376 Ext. 116
9442 Capital of Texas Hwy. North  Fax: (512) 343 0376 Ext. 161 (not a typo!)
Arboretum Plaza One, Suite 700    Net: robertt@isc.com (polled daily)
Austin, Texas 78759               GEnie: R.TULLOH (polled monthly)

stan@Dixie.Com (Stan Brown) (03/31/91)

niklas@appli.se (Niklas Hallqvist) writes:

=>tore@bibsyst.UUCP (Tore Morkemo) writes:

=>>Could anyone please tell me what rindex() and index() are supposed to do ??

=>index == strchr
=>rindex == strrchr

=>Well, I would have mailed this if it hadn't triggered a question that's
=>been floating in the back of my head for the last five years.

=>Is there something like a porting guide for C-programs under Unix?
=>This guide would present the differences between all the main variants
=>of Unix.  Specifically differences in library functions and ioctl commands
=>are interesting.  I know the knowledge is out there, has anyone written
=>it down?

	One source is _Portable_C_And_UNIX_Porgraming_  By J. E Lapin


-- 
Stan Brown	P. C. Design 	404-363-2303	Ataanta Ga.
(emory|gatech|uunet) rsiatl!sdba!stan           	"vi forever"
"Operating Systems, Like Editors Are Religions" -- Armando Stettner

scs@adam.mit.edu (Steve Summit) (04/01/91)

In article <1311@appli.se> niklas@appli.se (Niklas Hallqvist) writes:
>Is there something like a porting guide for C-programs under Unix?
>This guide would present the differences between all the main variants
>of Unix.  Specifically differences in library functions and ioctl commands
>are interesting.

Portable C Software, by Mark R. Horton, published in 1990 by
Prentice Hall, ISBN 0-13-868050-7, has much of what you're
looking for.

I have a historical question: can someone tell me when and why
strchr and strrchr were first introduced, replacing the V7 index
and rindex?  I presume it was in PWB or System III or something.
(I'm also curious about the other "new" str routines such as
strcspn, strpbrk, strspn, and strtok; I suspect they appeared at
about the same time.)  Please reply by mail.

                                            Steve Summit
                                            scs@adam.mit.edu