Skip to content

Commit 5e2bdd9

Browse files
committed
Minor corrections to QJST headings.
Deal with STCK values that don't map to valid times. Deal with compile warnings on VS2012.
1 parent 7485cb7 commit 5e2bdd9

File tree

8 files changed

+108
-11
lines changed

8 files changed

+108
-11
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
/.project
2+
*.mp4
3+
/src/*.exe
4+
/src/*.obj
5+
mqsmfstruc.h
6+
csq*

src/Makefile.gcc.win

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
CC=i686-w64-mingw32-gcc
3+
CFLAGS= -I. -m32
4+
PLATFLAGS=
5+
SRC = mqsmf.c \
6+
smfDate.c \
7+
smfConv.c \
8+
printDEBUG.c \
9+
printQ5ST.c \
10+
printQCST.c \
11+
printQCTADP.c \
12+
printQCTDNS.c \
13+
printQCTDSP.c \
14+
printQCTSSL.c \
15+
printQCCT.c \
16+
printQESD.c \
17+
printQEST.c \
18+
printQIST.c \
19+
printQJST.c \
20+
printQLST.c \
21+
printQMAC.c \
22+
printQMST.c \
23+
printQPST.c \
24+
printQSGM.c \
25+
printQSPH.c \
26+
printQSRS.c \
27+
printQSST.c \
28+
printQTST.c \
29+
printWQ.c \
30+
printWTAS.c \
31+
printWTID.c
32+
33+
HDR = mqsmfstruc.h \
34+
mqsmf.h
35+
36+
mqsmfcsv.exe: $(SRC) $(HDR) Makefile.gcc.win dummy
37+
$(CC) $(PLATFLAGS) -o $@ $(SRC) $(CFLAGS)
38+
-rm -f out/*
39+
-rm -f SMF-*
40+
-mkdir out >/dev/null 2>&1 || true
41+
# dbx ./$@
42+
43+
mqsmfstruc.h: csqdsmfc.h convH.exe
44+
./convH.exe < csqdsmfc.h > $@
45+
46+
convH.exe: convH.c
47+
$(CC) -o $@ convH.c
48+
49+
50+
dummy:

src/mqsmf.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
#include <time.h>
6161
#include <ctype.h>
6262

63+
#ifdef _WIN32
64+
#include <io.h>
65+
#include <fcntl.h>
66+
#endif
67+
6368
#include "mqsmf.h"
6469

6570
static void Usage();
@@ -209,8 +214,12 @@ int main( int argc, char *argv[] )
209214
/* Open the input file */
210215
/* If this fails, then put out an error message and quit. If no */
211216
/* filename was given on command line, use stdin. */
212-
/* Windows requires the "b" option for binary input. */
217+
/* Windows requires the "b" option for binary input. And force */
218+
/* stdin to binary in case we need to read from that too. */
213219
/*********************************************************************/
220+
#ifdef _WIN32
221+
setmode(fileno(stdin), O_BINARY);
222+
#endif
214223
fp = inputFile?fopen(inputFile, "rb" ):stdin;
215224
if (!fp)
216225
{
@@ -718,7 +727,6 @@ FILE * fopenext(const char * basename, const char *ext, BOOL *newFile)
718727
{
719728
FILE * fp = NULL;
720729
char filename[256] = {0};
721-
char *filetype;
722730
char *mode = (append)?"a":"w";
723731

724732
snprintf(filename,sizeof(filename)-1,
@@ -727,7 +735,11 @@ FILE * fopenext(const char * basename, const char *ext, BOOL *newFile)
727735
fp = fopen(filename, mode);
728736
if (fp)
729737
{
730-
long pos = ftell(fp);
738+
long pos;
739+
740+
fseek(fp,0,SEEK_END);
741+
pos = ftell(fp);
742+
731743
if (pos == 0) /* Have we just created the file, even for "append" mode */
732744
*newFile = TRUE;
733745
else

src/mqsmf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ extern char *strMQCHLD (int v);
297297
ADDDATA("%s,",convDate(v))
298298

299299
#define ADDTIMEIDX(h,idx,v) \
300-
sprintf(tmpHead,"%s[%s] (S),%s[%s](US)",h,idx,h,idx); \
300+
sprintf(tmpHead,"%s[%s] (DATE),%s[%s](TIME)",h,idx,h,idx); \
301301
ADDHEAD(tmpHead); \
302302
ADDDATA("%s,",convDate(v))
303303

@@ -362,8 +362,8 @@ extern char *strMQCHLD (int v);
362362
{ \
363363
fprintf(fp,"%s",headings);\
364364
fprintf(fp,"\n"); \
365-
first=FALSE; \
366365
} \
366+
first=FALSE; \
367367
fprintf(fp,"%s",dataline);\
368368
fprintf(fp,"\n")
369369

src/printQJST.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ void printQJST(qjst *p)
4949

5050
if (conv32(p->qjstll)>=offsetof(qjst,qjstio))
5151
{
52-
for (i=0;i<3;i++)
52+
/* Array of 1 entry! Reserved space follows for 2 more, but they */
53+
/* are not currently used. */
54+
for (i=0;i<1;i++)
5355
{
5456
if (first)
5557
sprintf(index,"%d",i+1);

src/printWTAS.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SMFPRINTGLOB;
66

77
void printWTAS(wtas *p)
88
{
9-
int i,j;
9+
int i;
1010
char index[64];
1111

1212
SMFPRINTSTART("WTAS",p,conv16(p->wtaslen));

src/smfDate.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static unsigned long long int EPOCH1970 = (STCK1972 - (2*STCKYR365));
5353
/* This formatter for strftime */
5454
/********************************************************************/
5555
static char *fmt = "\"%Y/%m/%d\",\"%H:%M:%S";
56+
static char *epochTime = "\"1970/01/01\",\"00:00:00,000000\"";
57+
static char *emptyTime = "\"\",\"\"";
5658
static char stckTime[64] = {0};
5759

5860
/********************************************************************/
@@ -63,16 +65,26 @@ static char stckTime[64] = {0};
6365
/* This routine does not cope with dates before 1970, but */
6466
/* that's not likely to be a concern for processing MQ SMF. */
6567
/********************************************************************/
66-
char * convDate(unsigned long long stck)
68+
char * convDate(unsigned long long stcki)
6769
{
6870
time_t sec;
71+
unsigned long long stck;
6972
unsigned int usec;
7073
unsigned long long int s;
7174
struct tm *t;
7275
size_t offset;
7376

74-
stck = conv64(stck); /* Always passed in z/OS endian; ensure converted */
77+
stck = conv64(stcki); /* Always passed in z/OS endian; ensure converted */
7578

79+
if (stck == 0)
80+
{
81+
/***********************************************************************/
82+
/* Put a hardcoded value
83+
/***********************************************************************/
84+
strcpy(stckTime,emptyTime);
85+
}
86+
else
87+
{
7688
s = stck - EPOCH1970; /* Make relative to our epoch instead of z/OS 1900*/
7789
s = s / 4096; /* Convert stck to microsecs*/
7890
sec = (time_t)(s / 1000000); /* Split into two parts*/
@@ -81,8 +93,19 @@ char * convDate(unsigned long long stck)
8193
t = localtime(&sec); /* Turn seconds into tm structure...*/
8294

8395
offset = strftime(stckTime,sizeof(stckTime)-1,fmt,t); /* ...and format it*/
84-
sprintf(&stckTime[offset],",%6.6d\"",usec); /* Add on usec value*/
85-
96+
if (offset == 0)
97+
{
98+
/***********************************************************************/
99+
/* There seem to be occasions where the timestamp is not a proper */
100+
/* value - perhaps when there has been no work done for the activity */
101+
/* being recorded. So we put a hardcoded value into the string to make */
102+
/* those times easy to recognise. */
103+
/***********************************************************************/
104+
strcpy(stckTime,epochTime);
105+
}
106+
else
107+
sprintf(&stckTime[offset],",%6.6d\"",usec); /* Add on usec value*/
108+
}
86109
return stckTime;
87110
}
88111

src/t

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
make -f *gcc*
2+
rm -f c:/tmp/smf/out/*
3+
./mqsmfcsv -i ../testing/data/TESTCHL.dat -o c:/temp/smf/out -d2
4+
./mqsmfcsv -i ../testing/data/TEST115.dat -o c:/temp/smf/out -d2 -a
5+
./mqsmfcsv -i c:/temp/smf/data/SMF115.test.bin -m 200 -o c:/temp/smf/out -d2 -a

0 commit comments

Comments
 (0)