× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I orignally posted an issue that a program would not convert to V6R1 from an
earlier release even though all "creation" data was there.

I've came across this code below which is some where down in the bowels of
it all. I know what it is doing, but I'm not comfortable that I really
understand the "how", and I see a reference to QUSRTOOL and MI Instruction.

The person who wrote this had a reasonable grip on the 400 in 1993 and a
huge knowledge years later. He hated doing a "hack" but would do so if need
be. Later on through networking he obtained lots more knowledge of the 400.

Is this a hack and is it likely to be something that V6R1 under level 40
would not approve off?

BTW, the cross platform stuff for PC_DOS is not longer supported so it could
be removed if somehow it might be hanging around to confuse V6R1.

Steve Moland

===================================

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "trerror.h"
#include "strutil.h"
#if defined(AS400)
#include <signal.h>
#include <setjmp.h>
#include <miptrnam.h>
#include "qusrtool/qattsysc(opusapi)"
#elif defined(PC_DOS)
#include <io.h>
#endif

/********************************************************************
* Program.....: GETINVAR
* Date........: August 1993
* Copyright...: Copyright (c) 1993 Access Paths Inc
* Version.....: ILE C/400, Watcom C/C++
* Modified....:
* Description.:
*
* This program reads the *LIBL/TRECSINI User Space or or %path%\TRECS.INI,
* looks up the variable name passed, and returns the value assigned to the
* variable as a NULL terminated string.
*
* Parameters passed are 1. INI user space name defaults to *LIBL/TRECSINI
* 2. Variable name
* 3. Variable value returned to caller
#if defined(AS400)
* 4. (optional) length of target area
#endif
********************************************************************/

#define TRUE 1
#define FALSE 0

int givcfghex(char *, int);
char *givcfgvar(char *);
int givcfgint(char *);
double givcfgflt(char *);
char *givcfgstr(char *);
char *stpblk(char *);
extern char *Errwrk;
#if defined(AS400)

#define BADPTR 0 /* CMPPTRT (MI Instruction) operand 2 type
*/
#define SYSPTR 1
#define SPCPTR 2
#define DTAPTR 3
#define INSPTR 4
#define _MAX_PATH 45

typedef struct error_code_t {
int byte_provided;
int byte_available;
char exception_id[7];
char reserve;
char exception_data[256];
} ERROR_CODE_T;

int main(int argc, char *argv[])
{
char uspname[21],usplib[11],uspfile[11],uspmbr[11],uspfmt[11];
char uspextattr[11]="USP ";
char *uspptr;
char *cfgbuf=NULL, *vptr, *p1, scmd[40];
int rc,val,w1, libele, varele, valele, varlen;
char cfgpath[_MAX_PATH],var[81];
D0100FMT d0100;
ERROR_CODE_T e0100;

if (argc >= 4)
{
libele = 1;
varele = 2;
valele = 3;
if (argc >=5)
varlen = atoi(argv[4]);
else
varlen = 0;
if (cmpptrt(argv[libele],SPCPTR)==TRUE)
{
for (w1=0;argv[libele][w1] !='\0' && w1<80;w1++)
{
if (argv[libele][w1] == ' ')
{
argv[libele][w1] = '\0';
break;
}
}
if (strlen(argv[libele])==0 || strlen(argv[libele])>_MAX_PATH)
strcpy(cfgpath,"*LIBL/TRECSINI");
else
strcpy(cfgpath,argv[libele]);
}
else
strcpy(cfgpath,"*LIBL/TRECSINI");
lfnsplit(cfgpath,usplib,uspfile,uspmbr,uspfmt);
sprintf(scmd,"%-10.10s%-10.10s",uspfile,usplib);
memset(&e0100,0,sizeof(e0100));
e0100.byte_provided = sizeof(e0100);
QUSROBJD(&d0100,sizeof(d0100),"OBJD0100",scmd,"*USRSPC ",&e0100);
if (e0100.byte_available == 0)
{
strcpy(usplib,d0100.return_library);
sprintf(scmd,"%-10.10s%-10.10s",uspfile,usplib);
QUSPTRUS(scmd,&cfgbuf);
}
else
{
if (varlen > 0)
memset(argv[valele],' ',varlen);
else
strcpy(argv[valele],"");
exit(1);
}
if (cfgbuf == NULL)
{
if (varlen > 0)
memset(argv[valele],' ',varlen);
else
strcpy(argv[valele],"");
exit(2);
}
memset(var,0,sizeof(var));
for (w1=0;argv[varele][w1] !='\0' && w1<80;w1++)
{
if ((*(var+w1) = toupper(argv[varele][w1])) == ' ')
{
*(var+w1) = '\0';
break;
}
}
if (varlen > 0)
memset(argv[valele],' ',varlen);
else
strcpy(argv[valele],"");
while (*cfgbuf != '\0')
{
if (*(stpblk(cfgbuf)) != '*')
{
vptr=givcfgvar(cfgbuf);
strupr(vptr);
if (strcmp(var,vptr)==0)
{
vptr = givcfgstr(vptr+strlen(vptr)+1);
if (varlen > 0)
strncpy(argv[valele],vptr,strlen(vptr));
else
strcpy(argv[valele],vptr);
break;
}
}
cfgbuf = strchr(cfgbuf,'\0') + 1;
}
if (*cfgbuf == '\0')
rc = 3;
else
rc = 0;
}
return(rc);
}

#elif defined(PC_DOS)

void GETINVAR(char *cfgfile, char *varname, char *valname)
/**************************************************************************
* PC version of GETINVAR
**************************************************************************/
{
FILE *cf;
char cfgbuf[323], *vptr, *p1;
char cfgpath[_MAX_PATH],sp[_MAX_PATH];
char fdrive[_MAX_DRIVE], fdir[_MAX_DIR], fname[_MAX_FNAME],
fext[_MAX_EXT];

strcpy(valname,"");
if (cfgfile == NULL || strlen(cfgfile)==0)
strcpy(cfgpath,"TRECS.INI");
else
strcpy(cfgpath,cfgfile);
if (access(cfgpath,0)!=0)
{
vptr = getenv("INIPATH");
if (vptr != NULL)
strcpy(cfgpath,vptr);
else
{
_splitpath(cfgpath, fdrive, fdir, fname, fext);
_makepath(cfgpath, NULL, NULL, fname, fext);
_searchenv(cfgpath, "PATH", sp);
if (strlen(sp)>0)
strcpy(cfgpath,sp);
else
return;
}
}
if ((cf=fopen(cfgpath,"r"))==NULL)
{
prerrmsg(FATNOCFG,getmsgtext(FATNOCFG)); /* unable to open cfg file
*/
return;
}
while (fgets(cfgbuf,256,cf)!=NULL)
{
if (ferror(cf))
{
prerrmsg(FATCFGIO,getmsgtext(FATCFGIO)); /* Error reading
configuration file */
return;
}
if (*(stpblk(cfgbuf)) != '*')
{
vptr=givcfgvar(cfgbuf);
if (stricmp(varname,vptr)==0)
{
vptr = givcfgstr(vptr+strlen(vptr)+1);
if ((p1=strchr(vptr,'\n'))!=NULL)
*p1 = '\0';
strcpy(valname,vptr);
break;
}
}
}
fclose(cf);
return;
}
#endif

char *givcfgvar(char *s1)
{
char *p1, *p2;

for (p1=p2=stpblk(s1);(*p2 && !(isspace(*p2) || *p2 == '='));p2++);
*p2='\0';
strupr(p1);
return(p1);
}

int givcfgint(char *s1)
{
while (!isdigit(*s1))
s1++;
return(atoi(s1));
}

double givcfgflt(char *s1)
{
while (!isdigit(*s1))
s1++;
return(atof(s1));
}

char *givcfgstr(char *s1)
{
char *p1, *p2;

for (p1=p2=stpblk(s1);(isspace(*p2) || *p2 == '=');p2++);
p1 = p2;
while(*p2 && *p2 != '\r')
p2++;
*p2='\0';
return(p1);
}

int givcfghex(char *s1, int size)
{
int val, w1;

for (val = w1 = 0;w1<size && *(s1+w1);w1++)
{
val = val * 16;
if (*(s1+w1) & 0xF0 == 0x30)
val = val + (*(s1+w1) - 0x30);
else
val = val + (toupper(*(s1+w1)-'A'+10));
}
return(val);
}




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.