179 lines
3.2 KiB
C
179 lines
3.2 KiB
C
/*
|
|
* Date manipulations functions for tsmpipe
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "dsmapitd.h"
|
|
|
|
/*
|
|
* This function will take a string date entered and convert that to a TSM
|
|
* date
|
|
*
|
|
* The date is passed to this function in the format mmddYYYY
|
|
*/
|
|
dsmDate dsmStrToDate(char *s) {
|
|
extern int verbose;
|
|
dsmDate *date;
|
|
dsUint32_t d,t;
|
|
char *x=NULL, *y=NULL;
|
|
|
|
date = (dsmDate*)malloc(sizeof(dsmDate));
|
|
x = (char *)malloc(sizeof(s));
|
|
y = (char *)malloc(sizeof(s));
|
|
|
|
if (date==NULL) {
|
|
perror("Arg, out of memory?");
|
|
exit(255);
|
|
}
|
|
|
|
memset(date,0x00,sizeof(dsmDate));
|
|
|
|
if (verbose)
|
|
printf("dsmStrToDate: Date String: %s\n", s);
|
|
|
|
/* if user key in some inputs */
|
|
if (s[0] != '\0') {
|
|
y=strchr(s,':');
|
|
|
|
if (y != NULL) {
|
|
strncpy(x,s,strlen(s)-strlen(y));
|
|
x[strlen(s)-strlen(y)] = '\0';
|
|
y = strchr(s,':')+1;
|
|
} else
|
|
x = s;
|
|
|
|
d = atol(x);
|
|
date->month = d / 1000000;
|
|
|
|
d %= 1000000;
|
|
date->day = d / 10000;
|
|
date->year = d % 10000;
|
|
|
|
if (y != NULL) {
|
|
t = atol(y);
|
|
date->hour = t / 10000;
|
|
|
|
t %= 10000;
|
|
date->minute = t / 100;
|
|
date->second = t % 100;
|
|
}
|
|
}
|
|
|
|
if (verbose)
|
|
printf("dsmStrToDate: date = %d, month = %d, year = %d, hour = %d, minute = %d, second = %d\n", date->day, date->month, date->year, date->hour, date->minute, date->second);
|
|
|
|
return *date;
|
|
}
|
|
|
|
/* Display the dsmDate value as a string */
|
|
char *dsmDateToStr(dsmDate date) {
|
|
char *s;
|
|
|
|
s = malloc(19);
|
|
|
|
if (s==NULL) {
|
|
perror("Arg, out of memory?");
|
|
exit(255);
|
|
}
|
|
|
|
memset(s,0x00,sizeof(s));
|
|
|
|
sprintf(s,"%02i/%02i/%04i %02i:%02i:%02i",
|
|
(dsInt16_t)date.day,
|
|
(dsInt16_t)date.month,
|
|
date.year,
|
|
(dsInt16_t)date.hour,
|
|
(dsInt16_t)date.minute,
|
|
(dsInt16_t)date.second);
|
|
|
|
return s;
|
|
}
|
|
|
|
dsmObjName dsmNameToObjname(char *fsname, char *filename) {
|
|
extern int verbose;
|
|
dsmObjName *objname;
|
|
char *p;
|
|
|
|
objname = (dsmObjName*)malloc(sizeof(dsmObjName));
|
|
|
|
if (objname==NULL) {
|
|
perror("Arg, out of memory?");
|
|
exit(255);
|
|
}
|
|
|
|
memset(objname,0x00,sizeof(dsmObjName));
|
|
|
|
if (verbose)
|
|
fprintf(stderr,"dsmNameToObjname: FS: %s Filename: %s\n",fsname,filename);
|
|
|
|
/* fs == "/filesystem", hl == "/directory/path", ll == "/filename" */
|
|
strcpy(objname->fs,fsname);
|
|
|
|
p = strrchr(filename, '/');
|
|
|
|
if (p) {
|
|
*p = '\0';
|
|
|
|
if (*filename && *filename != '/')
|
|
strcpy(objname->hl, "/");
|
|
|
|
strcpy(objname->hl,filename);
|
|
sprintf(objname->ll,"/%s",p+1);
|
|
|
|
} else {
|
|
if (*filename && *filename != '/')
|
|
strcpy(objname->ll, "/");
|
|
|
|
strcat(objname->ll,filename);
|
|
}
|
|
|
|
objname->objType = DSM_OBJ_FILE;
|
|
|
|
return *objname;
|
|
}
|
|
|
|
char *dsmObjnameToStr(dsmObjName objName) {
|
|
char *s;
|
|
|
|
s = malloc(sizeof(dsmObjName));
|
|
|
|
if (s==NULL) {
|
|
perror("Arg, out of memory?");
|
|
exit(255);
|
|
}
|
|
|
|
memset(s,0x00,sizeof(s));
|
|
|
|
sprintf(s,"%s%s%s",objName.fs,objName.hl,objName.ll);
|
|
|
|
return s;
|
|
}
|
|
|
|
double dsmSizeToNum(dsStruct64_t dsStruct64) {
|
|
unsigned long long filesize=0;
|
|
|
|
filesize = 0x00;
|
|
|
|
filesize = dsStruct64.hi;
|
|
filesize <<= 32;
|
|
filesize |= dsStruct64.lo;
|
|
|
|
// Return number in MB
|
|
return (float)filesize/1024/1024;
|
|
}
|
|
|
|
void debugLog(int level, _IO_FILE *output, char *message, int die) {
|
|
extern int verbose;
|
|
|
|
if (level > verbose)
|
|
return;
|
|
|
|
fprintf(output,"%s\n",message);
|
|
|
|
if (die)
|
|
exit(die);
|
|
}
|