{"id":137,"date":"2023-11-23T00:09:58","date_gmt":"2023-11-23T00:09:58","guid":{"rendered":"http:\/\/10.1.250.135\/ozus\/?page_id=137"},"modified":"2023-11-23T16:44:52","modified_gmt":"2023-11-23T16:44:52","slug":"ksh-aix-historyconv-c-3","status":"publish","type":"page","link":"https:\/\/ozus.com\/index.php\/ksh-aix-historyconv-c-3\/","title":{"rendered":"KSH (AIX)-HistoryConv.c"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/*\n * File Name: HistoryConv.c\n * File Creation Date: 19980104\n * Copyright 1998 by OZUS LLC       Auth0r: Lance Lenz\n * Copyright 2009 by TriParadigm LLC\n * Copyright 2009 by MtXia Inc.     Author: Dana French\n * Copyright 2009 by Edgetec Inc.   Author: Joseph Stephens\n * \n * Permission to use, copy, modify, distribute, and sell this software and its\n * documentation for any purpose is hereby Restricted,\n * the above copyright notice must appear in all copies and that both the\n * copyright notice and this permission notice appear in supporting\n * documentation, and that the names of \n * OZUS LLC, TriParadigm LLC, MtXia Inc., Edgetec Inc.\n * not be used in advertising or publicity pertaining to distribution of the\n * software without specific, written prior permission.  \n *  makes no representations about the OZUS LLC, TriParadigm LLC, \n *  MtXia Inc., Edgetec Inc. suitability of this software for any purpose.\n * It is provided \"as is\" without express or implied warranty.\n * \n * Users Restricted Rights - Use, duplication or disclosure restricted\n * Restricted License: 2000      Company Name Here\n * \n * Update Log:\n * 20091231: Lance Lenz:\n *\n * Compile cc user.c -lpq\n*\/\n#include &lt;stdio.h>\n#include &lt;stdlib.h>\n#include &lt;string.h>\n#include &lt;time.h>\n\n#define NUL '\\x00'\t\/\/ Start of Line\n#define SOH '\\x01'\t\/\/ Start of Record\n#define CTRL_B '\\x02'\t\/\/ CTRL_B  \n#define DE '\\xde'\t\/\/ Start of Time\n#define DF '\\xdf'\t\/\/ End of Time\n#define LF '\\x0a'\t\/\/ Line Feed  \n#define CR '\\x0d'\t\/\/ Line Feed  \n#define MAXDATA 20480\n\n\n\/\/ Global Counts\nint usCnt = 0, secCnt = 0;\nint ServerNumber = 0;\n\n\/\/ Time Conversion\nconvertTime(char *timeEpoch, char *rtnBuf)\n{\n\tstruct tm *t;\n\ttime_t seconds;\n\tsscanf (timeEpoch, \"%ld\", &amp;seconds);\n\tt = localtime(&amp;seconds);\n\tsprintf(rtnBuf,\"%4d-%02d-%02d %02d:%02d:%02d\"\n\t\t, t->tm_year+1900\n\t\t, t->tm_mon+1\n\t\t, t->tm_mday\n\t\t, t->tm_hour\n\t\t, t->tm_min\n\t\t, t->tm_sec\n\t);\n}\n\nint main(int argc, char * *argv)\n{\n\tFILE *in_file, *out_file;  \/* input data file            *\/\n\t\/\/struct tm *t;\n\t\/\/time_t seconds;\n\tint i = 0;\n\tint vl_1 = 0;             \/* Used in for loop read in from OCC         *\/\n\tint vl_2 = 0;             \/* Used in for loop read in from OCC         *\/\n\tint startLine = 0;        \/* Starting point of good data               *\/\n\tint startTime = 0;        \/* Starting point of ephoc                   *\/\n\tint endLine = 0;          \/* Ending point of good data                 *\/\n\tint c;                    \/* Used as a char to read in from OCC        *\/\n\tchar buf1&#91;MAXDATA];\n\tchar hold_buf&#91;MAXDATA];\n\tchar commandText&#91;MAXDATA];\n\tchar commandTextBuf&#91;MAXDATA];\n\tchar epoch&#91;20];\n\tchar convertedEpoch&#91;20];\n\n\n\tif (argc != 2)\n\t{\n\t\tfprintf(stderr,\"Usage: HistoryConv FileName\\n\");\n\t\tfprintf(stderr,\"Usage: HistoryConv \/OZUS\/History\/odcapmdm00-bmcaddm-sh_history.20120415.015741.bmcaddm.bmcaddm.146.61.182.59.pts-3\\n\");\n\t\texit(1);\n\t}\n\n\t\/* Open the password file and read into x array the user names *\/\n\t\/\/strcpy(buf1,\"\/home\/infosec\/OZUS_Infosec\/TestText\");\n\t\/\/strcat(buf1,\"\/odcapmdm00-bmcaddm-sh_history.20120415.015741.bmcaddm.bmcaddm.146.61.182.59.pts-3\");\n\tstrcat(buf1,argv&#91;1]);\n\tif (!(in_file = fopen(buf1, \"r\"))) {\n\t\tprintf(\"error opening input file; %s\\n\", buf1);\n\t\texit(1);\n\t}\n        printf(\"\\n&lt;TABLE Border=\\\"2\\\" Width=\\\"100%%\\\" Cellspacing=\\\"2\\\" Cellpadding=\\\"2\\\">&lt;TR>&lt;TD Bgcolor=\\\"#B0C4DE\\\" width=\\\"10%%\\\">****** History File ******&lt;\/TD> &lt;TD Bgcolor=\\\"#B0C4DE\\\" width=\\\"95%%\\\"> %s&lt;\/TD>&lt;\/TR>\\n\",buf1);\n\t\/*\n \t* Read in char-x-char to look for CTRL and NewLine to determin where the line breaks are\n \t* A line ends just after the EPOCH with a 0x0A or something like #df#\\n\n \t*\/\n        vl_1 = 0;\n        vl_2 = 0;\n\tmemset(&amp;commandText,'\\0', sizeof(commandText));\n\tmemset(&amp;hold_buf,'\\0', sizeof(hold_buf));\n\tstartLine = 0;\n\tstartTime = 0;\n\tendLine = 0;\n\n\twhile (( c = getc(in_file)) != EOF)  \/* read in record *\/\n\t{\n\t\t\/\/ if for some reason we miss a counter reset everyting to keep the buffer from over flowing\n\t\tif((vl_1 >= MAXDATA) || (vl_2 >= MAXDATA))\n\t\t{\n\t\t\tprintf(\"Error MAXDATA: read exceeded %d chars for vl_1 %d or vl_2 %d.\\n File Name: %s\\n\",MAXDATA, vl_1, vl_2, buf1);\n\t\t\tfclose(in_file); \/\/ Close the input file\n\t\t\texit(2);\n\t\t}\n\n\t\t\/\/ Load the buffer on char at a time\n\t\thold_buf&#91;vl_1] = c; \n\t\t\/\/printf(\"VL= %d %s\\n\",vl_1, hold_buf);\n\n\n\t\t\/\/ Setting the buffer to NULL and the vl_1 counter to -1 for the else statment that does a vl_1++\n\t\t\/\/ this is a port way to make it Zero after the while loop\n\t\tif(hold_buf&#91;vl_1] == SOH)\n\t\t{\n\t\t\tvl_1 = -1;\n\t\t\tvl_2 = 0;\n\t\t\tmemset(&amp;commandText,'\\0', sizeof(commandText));\n\t\t\tmemset(&amp;hold_buf,'\\0', sizeof(hold_buf));\n\t\t\tstartLine = 0;\n\t\t\tstartTime = 0;\n\t\t\tendLine = 0;\n\t\t}\n\t\t\/\/ Conver to lower ascii value on the chart\n\t\tif(hold_buf&#91;vl_1] == CTRL_B)\n\t\t\thold_buf&#91;vl_1] = ' '; \n\t\tif(hold_buf&#91;vl_1] == DE)\n\t\t\thold_buf&#91;vl_1] = '^'; \n\t\t\/\/ Conver to lower ascii value on the chart\n\t\tif(hold_buf&#91;vl_1] == DF)\n\t\t\thold_buf&#91;vl_1] = '_'; \n\t\t\/\/ Conver to a different char to test with\n\t\tif(hold_buf&#91;vl_1] == LF)\n\t\t{\n\t\t\thold_buf&#91;vl_1] = ';'; \n\t\t}\n\n\t\t\/\/ Setting the buffer to NULL and the vl_1 counter to -1 for the else statment that does a vl_1++\n\t\t\/\/ this is a port way to make it Zero after the while loop\n\t\tif(hold_buf&#91;vl_1] == NUL)\n\t\t{\n\t\t\tvl_1 = -1;\n\t\t\tvl_2 = 0;\n\t\t\tmemset(&amp;commandText,'\\0', sizeof(commandText));\n\t\t\tmemset(&amp;hold_buf,'\\0', sizeof(hold_buf));\n\t\t\tstartLine = 0;\n\t\t\tstartTime = 0;\n\t\t\tendLine = 0;\n\t\t}\n\n\t\t\/\/ Test for the start location of epoch\n\t\tif((strncmp(&amp;hold_buf&#91;vl_1 -2],\"#^#\", 3)) == 0)\n\t\t\t\tstartTime= vl_1 -2;\n\n\t\t\/\/ Test for the end location of epoch and end of the record we want to capture\n\t\tif((strncmp(&amp;hold_buf&#91;vl_1 -3],\"#_#;\", 4)) == 0)\n\t\t{\n\t\t\tendLine = (vl_1 - startTime);\n\t\t\tstrncpy(epoch,&amp;hold_buf&#91;startTime+3],endLine-6);\n\t\t\tconvertTime(epoch,convertedEpoch);\n\n\t\t\t\/\/strncpy(commandText,&amp;hold_buf&#91;0],startTime - 4);\n\t\t\tstrncpy(commandText,&amp;hold_buf&#91;0],startTime);\n\n\t\t\t\/\/ This is a good place to put a function call to parce the commandText for chars that cannot go into the database\n\t\t\t\/\/ or wrap escape chars around before the insert into the DB\n\t\t\t\/\/\n\t\t\tvl_2 = 0;\n\t\t\tmemset(&amp;commandTextBuf,'\\0', sizeof(commandTextBuf));\n\t\t\t for(i = 0; i&lt;= sizeof(commandText);i++)\n\t\t\t {\n\t\t\t\tcommandTextBuf&#91;vl_2] =  commandText&#91;i]; \n\n\t\t\t\tif(commandTextBuf&#91;vl_2] == '\\'')\n\t\t\t\t{\n\t\t\t\t\tcommandTextBuf&#91;vl_2] = '\\\\'; \n\t\t\t\t\tvl_2++;\n\t\t\t\t\tcommandTextBuf&#91;vl_2] = '\\''; \n\t\t\t\t\tvl_2++;\n\t\t\t\t}\n\t\t\t\telse if(commandTextBuf&#91;vl_2] == '\\\"')\n\t\t\t\t{\n\t\t\t\t\tcommandTextBuf&#91;vl_2] = '\\\\'; \n\t\t\t\t\tvl_2++;\n\t\t\t\t\tcommandTextBuf&#91;vl_2] = '\\\"'; \n\t\t\t\t\tvl_2++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tvl_2++;\n\t\t\t}\n\t\t\t\/\/printf(\"\\n********StartLine=%d StartTime=%d EndTime=%d Epoc %s Time=%s********\\n\",startLine,startTime,endLine,epoch,convertedEpoch);\n\t\t\t\/\/printf(\"\\n------------First--Totalcount=%d -----Text=%s ---------------\\n\",vl_1,hold_buf);\n                        printf(\"&lt;TR>&lt;TD>%s&lt;\/TD>&lt;TD>%s&lt;\/TD>&lt;\/TR>\\n\",convertedEpoch,commandTextBuf);\n\n\t\t\t\/\/ Reset all the buffers back to zero and keep reading in the next X chars.\n\t\t\tvl_1 = 0;\n\t\t\tvl_2 = 0;\n\t\t\tmemset(&amp;commandText,'\\0', sizeof(commandText));\n\t\t\tmemset(&amp;hold_buf,'\\0', sizeof(hold_buf));\n\t\t\tstartLine = 0;\n\t\t\tstartTime = 0;\n\t\t\tendLine = 0;\n\t\t}\n\t\telse\n\t\t\tvl_1++;\n\t}\n\tprintf(\"&lt;\/TABLE>\\n\");\n\n\tfclose(in_file); \/\/ Close the input file\n\texit(0);\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-137","page","type-page","status-publish"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ozus.com\/index.php\/wp-json\/wp\/v2\/pages\/137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ozus.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ozus.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ozus.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ozus.com\/index.php\/wp-json\/wp\/v2\/comments?post=137"}],"version-history":[{"count":2,"href":"https:\/\/ozus.com\/index.php\/wp-json\/wp\/v2\/pages\/137\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/ozus.com\/index.php\/wp-json\/wp\/v2\/pages\/137\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/ozus.com\/index.php\/wp-json\/wp\/v2\/media?parent=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}