complete 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. .TH COMPLETE 2
  2. .SH NAME
  3. complete \- file name completion
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .br
  9. .B #include <complete.h>
  10. .PP
  11. .ft L
  12. .nf
  13. .ta \w' 'u +\w' 'u +\w' 'u +\w' 'u +\w' 'u
  14. typedef struct Completion Completion;
  15. struct Completion{
  16. uchar advance; /* whether forward progress has been made */
  17. uchar complete; /* whether the completion now represents a file or directory */
  18. char *string; /* the string to advance, suffixed " " or "/" for file or directory */
  19. int nmatch; /* number of files that matched */
  20. int nfile; /* number of files returned */
  21. char **filename; /* their names */
  22. };
  23. .fi
  24. .PP
  25. .B
  26. .ta \w'\fLchar* 'u
  27. .PP
  28. .B
  29. Completion* complete(char *dir, char *s);
  30. .PP
  31. .B
  32. void freecompletion(Completion *c);
  33. .SH DESCRIPTION
  34. The
  35. .I complete
  36. function implements file name completion.
  37. Given a directory
  38. .I dir
  39. and a string
  40. .IR s ,
  41. it returns an analysis of the file names in that directory that begin with the string
  42. .IR s .
  43. The fields
  44. .B nmatch
  45. and
  46. .B nfile
  47. will be set to the number of files that match the prefix and
  48. .B filename
  49. will be filled in with their names.
  50. If the file named is a directory, a slash character will be appended to it.
  51. .PP
  52. If no files match the string,
  53. .B nmatch
  54. will be zero, but
  55. .I complete
  56. will return the full set of files in the directory, with
  57. .I nfile
  58. set to their number.
  59. .PP
  60. The flag
  61. .B advance
  62. reports whether the string
  63. .I s
  64. can be extended without changing the set of files that match. If true,
  65. .B string
  66. will be set to the extension; that is, the value of
  67. .B string
  68. may be appended to
  69. .I s
  70. by the caller to extend the embryonic file name unambiguously.
  71. .PP
  72. The flag
  73. .B complete
  74. reports whether the extended file name uniquely identifies a file.
  75. If true,
  76. .B string
  77. will be suffixed with a blank, or a slash and a blank,
  78. depending on whether the resulting file name identifies a plain file or a directory.
  79. .PP
  80. The
  81. .I freecompletion
  82. function frees a
  83. .B Completion
  84. structure and its contents.
  85. .PP
  86. In
  87. .IR rio (1)
  88. and
  89. .IR acme (1),
  90. file name completion is triggered by a control-F character or an Insert character.
  91. .SH SOURCE
  92. .B /sys/src/libcomplete
  93. .SH SEE ALSO
  94. .IR rio (1),
  95. .IR acme (1)
  96. .SH DIAGNOSTICS
  97. The
  98. .I complete
  99. function returns a null pointer and sets
  100. .I errstr
  101. if the directory is unreadable or there is some other error.
  102. .SH BUGS
  103. The behavior of file name completion should be controlled by the plumber.