home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Meeting Pearls 3
/
Meeting_Pearls_III.iso
/
Pearls
/
arc
/
XPK
/
XpkDisk
/
name.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-08
|
2KB
|
92 lines
/*-
* NAME.C
*
* The knowledge of the file names used for tracks.
*
* $Id: name.c,v 1.3 1995/04/08 20:23:48 Rhialto Exp $
* $Log: name.c,v $
* Revision 1.3 1995/04/08 20:23:48 Rhialto
* Add/correct version strings.
*
* Revision 1.2 1993/11/08 13:18:19 Rhialto
* Add RCS tags.
*
*
* This code is (C) Copyright 1993 by Olaf Seibert. All rights reserved.
* May not be used or copied without a licence.
-*/
#include "xpkdisk.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
extern struct DosLibrary *DOSBase;
static const char rcsId[] = "$Id: name.c,v 1.3 1995/04/08 20:23:48 Rhialto Exp $";
static const char Subdir[] = "Group_%04x_%c%c";
static const char File[] = "Track_%04x_%c%c";
#define HASHTABLESIZE 72 /* Must be less than 13*13 */
Prototype int Hash(unsigned char *name);
int
Hash(unsigned char *name)
{
int val, len, i;
val = len = strlen(name);
for (i=0; i<len; i++)
val = ((val*13) + (int)toupper(*name++)) & 0x7ff;
return val;
}
int
HashName(char *filename, char *pattern, int number, int hash)
{
int hh;
int len;
len = sprintf(filename, pattern, number, 'M', 'M');
hh = (Hash(filename) - hash) % HASHTABLESIZE;
filename[--len] -= hh % 13;
filename[--len] -= hh / 13;
return len + 2;
}
Prototype void NewName(char *filename, int track);
void
NewName(char *filename, int track)
{
int groupd = track / HASHTABLESIZE;
int group = groupd * HASHTABLESIZE;
int len;
len = HashName(filename, Subdir, group, groupd % HASHTABLESIZE);
filename += len;
*filename++ = '/';
HashName(filename, File, track, track % HASHTABLESIZE);
}
Prototype void MakeSubDirs(int mintrack, int maxtrack);
void
MakeSubDirs(int mintrack, int maxtrack)
{
char dirname[40];
BPTR fl;
int g;
int gd;
for (gd = mintrack / HASHTABLESIZE, g = gd * HASHTABLESIZE;
g <= maxtrack;
gd++, g += HASHTABLESIZE) {
HashName(dirname, Subdir, g, gd % HASHTABLESIZE);
if (fl = CreateDir(dirname))
UnLock(fl);
}
}