diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2008-01-27 11:37:44 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2008-01-27 11:37:44 +0100 |
commit | 7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch) | |
tree | b1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/C/CONTRIB/SNIP/pmerge.c |
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/CONTRIB/SNIP/pmerge.c')
-rwxr-xr-x | reference/C/CONTRIB/SNIP/pmerge.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/reference/C/CONTRIB/SNIP/pmerge.c b/reference/C/CONTRIB/SNIP/pmerge.c new file mode 100755 index 0000000..3b219b1 --- /dev/null +++ b/reference/C/CONTRIB/SNIP/pmerge.c @@ -0,0 +1,69 @@ +/*
+** pmerge() - Portable replacement for fnmerge(), _makepath(), etc.
+**
+** Forms a full DOS pathname from drive, path, file, and extension
+** specifications.
+**
+** Arguments: 1 - Buffer to receive full pathname
+** 2 - Drive
+** 3 - Path
+** 4 - Name
+** 5 - Extension
+**
+** Returns: Nothing
+**
+** public domain by Bob Stout
+*/
+
+#include <string.h>
+
+#define LAST_CHAR(s) ((s)[strlen(s) - 1])
+
+void pmerge(char *path, char *drive, char *dir, char *fname, char *ext)
+{
+ *path = '\0';
+
+ if (drive && *drive)
+ {
+ strcat(path, drive);
+ if (':' != LAST_CHAR(path))
+ strcat(path, ":");
+ }
+
+ if (dir && *dir)
+ {
+ char *p;
+
+ strcat(path, dir);
+ for (p = path; *p; ++p)
+ if ('/' == *p)
+ *p = '\\';
+ if ('\\' != LAST_CHAR(path))
+ strcat(path, "\\");
+ }
+
+ if (fname && *fname)
+ {
+ strcat(path, fname);
+
+ if (ext && *ext)
+ {
+ if ('.' != *ext)
+ strcat(path, ".");
+ strcat(path, ext);
+ }
+ }
+}
+
+#ifdef TEST
+
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ char pathname[FILENAME_MAX];
+
+ pmerge(pathname, argv[1], argv[2], argv[3], argv[4]);
+ printf("pmerge (%s, %s, %s, %s) returned:\n %s\n",
+ argv[1], argv[2], argv[3], argv[4], pathname);
+}
|