chiark / gitweb /
Remove some obsolete code
[disorder] / lib / filepart.c
index 575cbc5eec2b226fc317d2010a6f62e4e87a10ba..c080b4d033beb914f22a433e177b05d0b4aa774a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder
- * Copyright (C) 2005 Richard Kettlewell
+ * Copyright (C) 2005, 2007 Richard Kettlewell
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,6 +17,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  * USA
  */
+/** @file lib/filepart.c
+ * @brief Filename parsing
+ */
 
 #include <config.h>
 #include "types.h"
 #include "filepart.h"
 #include "mem.h"
 
+/** @brief Return the directory part of @p path
+ * @param path Path to parse
+ * @return Directory part of @p path
+ *
+ * Extracts the directory part of @p path.  This is a simple lexical
+ * transformation and no canonicalization is performed.  The result will only
+ * ever end "/" if it is the root directory.
+ */
 char *d_dirname(const char *path) {
   const char *s;
 
   if((s = strrchr(path, '/'))) {
+    while(s > path && s[-1] == '/')
+      --s;
     if(s == path)
       return xstrdup("/");
     else
@@ -38,6 +51,16 @@ char *d_dirname(const char *path) {
     return xstrdup(".");
 }
 
+/** @brief Find the extension part of @p path
+ * @param path Path to parse
+ * @return Start of extension in @p path, or NULL
+ *
+ * The return value points into @p path and points at the "." at the start of
+ * the path.  If the basename has no extension the result is NULL.  Extensions
+ * are assumed to only contain the ASCII digits and letters.
+ *
+ * See also extension().
+ */
 static const char *find_extension(const char *path) {
   const char *q = path + strlen(path);
   
@@ -48,12 +71,29 @@ static const char *find_extension(const char *path) {
   return *q == '.' ? q : 0;
 }
 
+/** @brief Strip the extension from @p path
+ * @param path Path to parse
+ * @return @p path with extension removed, or @p path
+ *
+ * The extension is defined exactly as for find_extension().  The result might
+ * or might not point into @p path.
+ */
 const char *strip_extension(const char *path) {
   const char *q = find_extension(path);
 
   return q ? xstrndup(path, q - path) : path;
 }
 
+/** @brief Find the extension part of @p path
+ * @param path Path to parse
+ * @return Start of extension in @p path, or ""
+ *
+ * The return value may points into @p path and if so points at the "." at the
+ * start of the path.  If the basename has no extension the result is "".
+ * Extensions are assumed to only contain the ASCII digits and letters.
+ *
+ * See also find_extension().
+ */
 const char *extension(const char *path) {
   const char *q = find_extension(path);
 
@@ -68,4 +108,3 @@ fill-column:79
 indent-tabs-mode:nil
 End:
 */
-/* arch-tag:4WKGtvPyLNQ6h3I0n2cMIg */