home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- *
- * getfname.c -- prompt user for name of existing file.
- *
- */
-
- #include "cbtree.h"
- /* btfio.h *must* be included when bt_open() is used */
- #include "btfio.h"
-
- getfname(argc, argv, ext, filename)
- int argc;
- char *argv[];
- char *ext; /* default extension to add */
- char *filename; /* where to put copy of valid filename */
- {
- int fdidx, i;
-
- if (argc > 1)
- strcpy(filename, argv[1]);
- else
- {
- printf("\n\n %s","Enter File Name (xxxxxxxx.xxx) ==> ");
-
- gets(filename);
- }
-
- repeat
- {
- for (i = 0; filename[i] != '\0'; ++i)
- {
- if (filename[i] == '.') /* if extension was specified, use it */
- break;
- }
- if (filename[i] == '\0')
- {
- *(filename + i) = '.'; /* give it the default */
- strcpy(filename + i + 1, ext); /* give it the default */
- }
-
- if((fdidx = bt_open(filename,O_RDWR)) == ERR)
- {
- printf("\nLOOKHDR: can't open file '%s'", filename);
- printf("\n\n %s","Enter File Name (xxxxxxxx.xxx) ==> ");
- gets(filename);
- if (*filename == NUL || toupper(*filename) == 'X')
- exit(0);
- }
- }
- until(fdidx != ERR);
- return (fdidx);
- }
-