summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/pmerge.c
diff options
context:
space:
mode:
Diffstat (limited to 'reference/C/CONTRIB/SNIP/pmerge.c')
-rwxr-xr-xreference/C/CONTRIB/SNIP/pmerge.c69
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);
+}