getfields 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. .TH GETFIELDS 2
  2. .SH NAME
  3. getfields, gettokens, tokenize \- break a string into fields
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .ta \w'\fLchar* \fP'u
  10. .B
  11. int getfields(char *str, char **args, int maxargs, int multiflag,
  12. .br
  13. .B
  14. char *delims)
  15. .PP
  16. .B
  17. int gettokens(char *str, char **args, int maxargs, char *delims)
  18. .PP
  19. .B
  20. int tokenize(char *str, char **args, int maxargs)
  21. .SH DESCRIPTION
  22. .I Getfields
  23. breaks the null-terminated
  24. .SM UTF
  25. string
  26. .I str
  27. into at most
  28. .I maxargs
  29. null-terminated fields and places pointers to the start of these fields in the array
  30. .IR args .
  31. Some of the bytes in
  32. .I str
  33. are overwritten.
  34. If there are more than
  35. .I maxargs
  36. fields,
  37. only the first
  38. .I maxargs
  39. fields will be set.
  40. .I Delims
  41. is a
  42. .SM UTF
  43. string defining a set of delimiters.
  44. .PP
  45. If
  46. .I multiflag
  47. is zero,
  48. adjacent fields are separated by exactly one delimiter.
  49. A string containing
  50. .I n
  51. delimiter characters
  52. contains
  53. .IR n +1
  54. fields.
  55. If the
  56. .I multiflag
  57. argument is not zero,
  58. a field is a non-empty string of non-delimiters.
  59. .PP
  60. Getfields
  61. returns the number of tokens processed.
  62. .PP
  63. .I Gettokens
  64. is the same as
  65. .I getfields
  66. with
  67. .I multiflag
  68. non-zero,
  69. except that fields may be quoted using single quotes, in the manner
  70. of
  71. .IR rc (1).
  72. See
  73. .IR quote (2)
  74. for related quote-handling software.
  75. .PP
  76. .I Tokenize
  77. is
  78. .I gettokens
  79. with
  80. .I delims
  81. set to \f5"\et\er\en "\fP.
  82. .SH SOURCE
  83. .B /sys/src/libc/port/tokenize.c
  84. .SH SEE ALSO
  85. .I strtok
  86. in
  87. .IR strcat (2),
  88. .IR quote (2).