27 Feb, 2010, arholly wrote in the 1st comment:
Votes: 0
Hello. I'm getting this line when I go to install OLC and do the compile. It's in string.c and not sure what gives.

I'm running Rom2.4b on Ubuntu 9.10. GCC Version is gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9).

Here is the error message.
gcc -c -Wall -O -ggdb  string.c
string.c:628: error: conflicting types for getline
/usr/include/stdio.h:651: note: previous declaration of getline was here
make: *** [string.o] Error 1


Here is line 628 (starting line) and all the ones after it for that block.
char *getline( char *str, char *buf )

{

int tmp = 0;

bool found = FALSE;



while ( *str )

{

if ( *str == '\n' )

{

found = TRUE;

break;

}



buf[tmp++] = *(str++);

}



if ( found )

{

if ( *(str + 1) == '\r' )

str += 2;

else

str += 1;

} /* para que quedemos en el inicio de la prox linea */



buf[tmp] = '\0';



return str;

}
27 Feb, 2010, jurdendurden wrote in the 2nd comment:
Votes: 0
Conflicting types usually means that you've used a function before you've declared it. Try putting the getline func above the first call to it in string.c
27 Feb, 2010, jurdendurden wrote in the 3rd comment:
Votes: 0
By the way if you get a newer version of Rom (ie 2.4b6 or QuickMUD), you generally have features like OLC already built in and (somewhat) debugged.
27 Feb, 2010, arholly wrote in the 4th comment:
Votes: 0
I am using 2.4b. It's just that I've got gcc 4 and I know that it has problems. Besides, I don't mind learning what the problem is so I can try and deal with these things myself later.

It is the first call to it in string.c The call to it later is in the function below it. I've done a search of it and what I posted above is the first time it is mentioned in string.c
27 Feb, 2010, jurdendurden wrote in the 5th comment:
Votes: 0
Ok make sure your call and the function prototype use the same arguments.
27 Feb, 2010, jurdendurden wrote in the 6th comment:
Votes: 0
Also it's possible you've declared the function in multiple places with different types. Check your other .c/.h files (specifically merc.h) for another place you might have declared getline.
27 Feb, 2010, arholly wrote in the 7th comment:
Votes: 0
jurdendurden said:
Ok make sure your call and the function prototype use the same arguments.

Could you please elaborate on this one?

Also, I've greped it and it's only used in string.c, so on that aspect, we should be fine. Here is the whole of it where it's used.
char *getline( char *str, char *buf )

{

int tmp = 0;

bool found = FALSE;



while ( *str )

{

if ( *str == '\n' )

{

found = TRUE;

break;

}



buf[tmp++] = *(str++);

}



if ( found )

{

if ( *(str + 1) == '\r' )

str += 2;

else

str += 1;

} /* para que quedemos en el inicio de la prox linea */



buf[tmp] = '\0';



return str;

}



char *numlineas( char *string )

{

int cnt = 1;

static char buf[MAX_STRING_LENGTH*2];

char buf2[MAX_STRING_LENGTH], tmpb[MAX_STRING_LENGTH];



buf[0] = '\0';



while ( *string )

{

string = getline( string, tmpb );

sprintf( buf2, "%2d. %s\n\r", cnt++, tmpb );

strcat( buf, buf2 );

}



return buf;

}
27 Feb, 2010, Kline wrote in the 8th comment:
Votes: 0
getline() is being provided to you in the standard system libraries. ROM, however, has its own function also named getline. You have two options.

A. Remove the getline() function and it's prototype, and rely on the system provided function (best choice).
B. Rename getline to _getline() or get_line() or something.
27 Feb, 2010, arholly wrote in the 9th comment:
Votes: 0
Ok, I'd like to use getline() for obvious reasons, but when I remove getline, I get the following errors.
gcc -c -Wall -O -ggdb  string.c
string.c: In function numlineas:
string.c:637: warning: passing argument 1 of getline from incompatible pointer type
/usr/include/stdio.h:651: note: expected char ** __restrict__ but argument is of type char *
string.c:637: warning: passing argument 2 of getline from incompatible pointer type
/usr/include/stdio.h:651: note: expected size_t * __restrict__ but argument is of type char *
string.c:637: error: too few arguments to function getline


So, I see two problems. One is that I've got incompatible pointer types and the second is I got too few arguments. How many arguments should getline have. From what I've read, it should have 2 or three, and from my code, it has two, but obviously, that ain't right.
27 Feb, 2010, Kline wrote in the 10th comment:
Votes: 0
On closer review of the code you posted previously, ROM's getline is not an attempt to do what the system getline does – sorry; should have actually read the code sample not being too familiar with ROM :).

Go with option B, rename it to get_line or something and just update calls as needed. ROM's looks to want to pull a line out of a buffer, the GNU function however pulls a line out of a file.
27 Feb, 2010, Tyche wrote in the 11th comment:
Votes: 0
Kline said:
Go with option B, rename it to get_line or something and just update calls as needed.


Agreed.
27 Feb, 2010, Runter wrote in the 12th comment:
Votes: 0
Actually, I'd rename it something completely different.

It's a fairly bad practice to reinvent common standard library functions with somewhat completely different purposes. Such as strstr becoming str_str, strdup becoming str_dup etc etc. It's mitigated somewhat if it is interchangable (However defeating the purpose.)

I would rename this to get_line_from_buffer or something similar.
27 Feb, 2010, Tyche wrote in the 13th comment:
Votes: 0
It's bad practice except in this case getline() is a GNU extension. ROM wasn't written on a machine with a GNU compiler.

Edit: I believe GNU getline() originated somewhere between 1995 and 1997. So even if the OLC authors were using GNU c they wouldn't have been aware of it.
0.0/13