/***************
*
* txm\txmfile.c
*/
#include "txm.h"

char *makenewextname(char *org, char *new, char *ext)
{
	char *tmp;

/*	printf("makenewextname()\n");	*/
	strcpy(new, org);
	if ((tmp = jstrrchr(new, '\\')) == NULL) {
		tmp = new;
	}
	if ((tmp = strchr(tmp, '.')) == NULL) {
		tmp = strchr(new, NUL);
	}
	strcpy(tmp, ext);
	return (new);
}

int accessdir(char *path)
{
	char *tmp = work;

/*	printf("accessdir()\n");	*/
	if (access(path, 0) == 0) {
		return TRUE;
	}

	strcpy(work, path);
	for (;;) {
		if (*tmp == NUL) {
			*tmp = '\\';
		}
		tmp = jstrchr(tmp+1, '\\');
		if (work < tmp) {
			if (*(tmp - 1) == ':') {
				continue;
			}
		}
		if (tmp != NULL) {
			*tmp = NUL;
		}
/*		printf("try(%s)\n", work);	*/

		if (access(work, 0)) { /* != 0 : 存在しない */
			if (mkdir(work)) { /* != 0 : 作れない   */
				return FALSE;
			}
		}
		if (tmp == NULL) break;
	}
	return TRUE;
}

