mirror of
https://frontier.innolan.net/rainlance/amiga-tz.git
synced 2025-11-20 11:52:51 +00:00
100 lines
3.1 KiB
C
100 lines
3.1 KiB
C
/*
|
|
* Copyright (c) 2015 Carsten Larsen
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
*/
|
|
|
|
// NOTICE: This version does not yet work on Native Amiga Hardware.
|
|
// The code ends up in an infinitive loop in the infile function.
|
|
|
|
#include "amiga_tz.h"
|
|
#include "private.h"
|
|
#include "version.h"
|
|
const char *vers = "\0$VER: zic" AMIGA_VERSION;
|
|
/**********************************************************************/
|
|
/**
|
|
* Return 1 if NAME is a directory, 0 if it's something else,
|
|
* -1 if trouble.
|
|
*
|
|
*/
|
|
int itsdir(const char *name)
|
|
{
|
|
BPTR lock;
|
|
struct FileInfoBlock *fib;
|
|
int result = -1;
|
|
|
|
if ((lock = Lock(name, SHARED_LOCK))) {
|
|
if ((fib = AllocMem(sizeof(struct FileInfoBlock), MEMF_CLEAR | MEMF_ANY))) {
|
|
if ((Examine(lock, fib)) == DOSTRUE) {
|
|
if (fib->fib_DirEntryType > 0) {
|
|
result = 1;
|
|
} else {
|
|
result = 0;
|
|
}
|
|
}
|
|
FreeMem(fib, sizeof(struct FileInfoBlock));
|
|
}
|
|
UnLock(lock);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
/**********************************************************************/
|
|
bool mkdirs(char *argname)
|
|
{
|
|
register char *name;
|
|
register char *cp;
|
|
BPTR lock;
|
|
|
|
if (argname == NULL || *argname == '\0')
|
|
return true;
|
|
|
|
cp = name = strdup(argname);
|
|
|
|
// Skip Amiga DOS drives
|
|
if (!(cp = strchr(++cp, ':'))) {
|
|
cp = name;
|
|
}
|
|
|
|
while ((cp = strchr(cp + 1, '/')) != 0) {
|
|
*cp = '\0';
|
|
|
|
//printf("mkdir %s\n", name); // DEBUG INFO
|
|
if ((lock = CreateDir(name))) {
|
|
UnLock(lock);
|
|
} else {
|
|
if (itsdir(name) <= 0) {
|
|
fprintf(stderr, "Can't create directory %s", name);
|
|
free(name);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
*cp = '/';
|
|
}
|
|
|
|
free(name);
|
|
return true;
|
|
}
|
|
/**********************************************************************/
|