utility
|
cmd_head.c,
count_tokens.c,
cp_file.c,
errmsg.c,
file_opened.c,
find_line.c,
find_string.c,
fn_base.c,
fn_dir.c,
fn_ext.c,
fn_root.c,
gchoice.c,
gdata_line.c,
gdouble.c,
gfield.c,
gint.c,
gntoken.c,
graphics_ok.c,
gstring.c,
lock.c,
lower.c,
mat_multiply.c,
mat_transform.c,
mat_transpose.c,
mv_file.c,
new_extension.c,
nolead.c,
notrail.c,
ordinal.c,
pfield.c,
squish_blanks.c,
test.c,
unlock.c,
upper.c,
utility.h,
utility.make,
valchars.c,
vec_angle.c,
vec_crossprod.c,
vec_diff.c,
vec_dotprod.c,
vec_length.c,
vec_norm.c,
|
|
|
#include "utility.h"
char *gntoken(ntoken,line,delimiters,token)
/*============================================================================*/
/* PURPOSE: RETURN THE SPECIFIED TOKEN (0..N) FROM THE LINE. LINE MUST HAVE
/* AT LEAST NTOKEN TOKENS IN IT, OR NULL WILL BE RETURNED.
/* INPUTS:
/* NTOKEN WHICH TOKEN (0..N) IS DESIRED FROM LINE.
/* LINE LINE CONTAINING TOKENS.
/* DELIMITERS LIST OF POSSIBLE TOKEN DELIMITERS.
/* OUTPUTS:
/* TOKEN NTOKEN-TH TOKEN FROM LINE.
/* RETURN VALUE POINTER TO TOKEN.
/* WRITTEN: M.V.GRIESHABER
/* LAST MODIFICATION: 11 JUNE 1991 MVG
*/
int ntoken; /* WHICH TOKEN IS DESIRED (0..N). */
char *line; /* LINE CONTAINING TOKENS. */
char *delimiters; /* POSSIBLE TOKEN DELIMITERS TO USE. */
char *token; /* RETURNED COPY OF TOKEN. */
{
char *working_line; /* WORKING COPY OF LINE. */
int ntokens; /* WHICH TOKEN IS BEING PROCESSED. */
char *strtok_ptr; /* POINTER FOR STRTOK. */
strtok_ptr= working_line= strdup(line);
ntokens=0;
while (strcpy(token,strtok(strtok_ptr,delimiters))!=NULL)
{
if (ntoken==ntokens)
{
/* THIS IS THE REQUESTED TOKEN. */
free(working_line);
return(token);
}
strtok_ptr=NULL;
ntokens++;
}
/* NO SUCH TOKEN (ILLEGAL TOKEN NUMBER REQUESTED). */
strcpy(token,"");
free(working_line);
return(NULL);
}
|