FLAMCLE/P-API
Command Line Executor/Parser Application Programming Interface
CLEPUTL.h
Go to the documentation of this file.
1 
791 #ifdef __cplusplus
792  extern "C" {
793 #endif
794 #ifndef INC_CLEPUTL_H
795 #define INC_CLEPUTL_H
796 
798 #include <stdio.h>
799 #include <stdlib.h>
800 
802 #ifndef TRUE
803 # define TRUE (1)
804 #endif
805 
806 #ifndef FALSE
807 # define FALSE (0)
808 #endif
809 
810 #ifndef EOS
811  #define EOS (0x00)
812 #endif
813 
814 #ifndef __PRINTF_CHECK__
815 # define __PRINTF_CHECK__(A,B)
816 #endif
817 
819 #define CLEP_DEFAULT_CCSID_ASCII 819 // "ISO8859-1" Latin-1
820 #define CLEP_DEFAULT_CCSID_EBCDIC 1047 // "IBM-1047" Open Systems Latin-1
821 
823 #define SAFE_FREE(x) do { if ((x) != NULL) {free((void*)(x)); (x)=NULL;} } while(0)
824 
825 typedef struct EnVarList {
829  char* pcName;
830  char* pcValue;
831  struct EnVarList* psNext;
833 
834 #ifdef __WIN__
835 # ifndef __FL5__
836 # ifndef localtime_r
837 # define localtime_r(t,s) localtime(t)
838 # endif
839 # ifndef gmtime_r
840 # define gmtime_r(t,s) gmtime(t)
841 # endif
842 # ifndef asctime_r
843 # define asctime_r(s,b) asctime(s)
844 # endif
845 # ifndef ctime_r
846 # define ctime_r(t,b) ctime(t)
847 # endif
848 # endif
849 extern char* windowsversionstring(char** vstr, size_t* size);
850 extern int win_setenv(const char* name, const char* value);
851 extern int win_unsetenv(const char* name);
852 # define GETENV(name) getenv((name))
853 # define SETENV(name, value) win_setenv((name), (value))
854 # define UNSETENV(name) win_unsetenv((name))
855 #elif defined (__ZOS__) || defined (__ZOS__)
856 # define GETENV(name) __getenv((name))
857 # define SETENV(name, value) setenv((name), (value), 1)
858 # define UNSETENV(name) unsetenv((name))
859 #else
860 # define GETENV(name) getenv((name))
861 # define SETENV(name, value) setenv((name), (value), 1)
862 # define UNSETENV(name) unsetenv((name))
863 #endif
864 
865 #define isStr(c) (isprint(c) || (c)==C_TLD || (c)==C_DLR || (c)==C_ATS || (c)==C_BSL || (c)==C_CRT || (c)==C_EXC)
866 #define isKyw(c) (isalnum(c) || (c)=='_')
867 #define isCon(c) (isKyw(c) || (c)=='-' || (c)=='/')
868 
869 #define ISDDNAME(p) (strlen(p)>3 && toupper((p)[0])=='D' && toupper((p)[1])=='D' && (p)[2]==':')
870 #define ISPATHNAME(p) (strchr((p),'/')!=NULL)
871 #define ISDSNAME(p) (strlen(p)>2 && toupper((p)[0])=='/' && toupper((p)[1])=='/')
872 #define ISGDGMBR(m) ((m)[0]=='0' || (m)[0]=='+' || (m)[0]=='-')
873 #define ISDDN(c) (isalnum(c) || (c)==C_DLR || (c)==C_HSH || (c)==C_ATS)
874 
875 extern FILE* fopen_hfq(const char* name, const char* mode);
876 extern FILE* fopen_hfq_nowarn(const char* name, const char* mode);
877 extern FILE* freopen_hfq(const char* name, const char* mode, FILE* stream);
878 extern long long getFileSize(const char* name);
879 #ifdef __ZOS__
880  extern FILE* fopen_tmp(void);
881  extern int fclose_tmp(FILE* fp);
882  extern int remove_hfq(const char* name);
883 #else
884 # define fopen_tmp() tmpfile()
885 # define fclose_tmp(fp) fclose((fp))
886 # define remove_hfq(n) remove(n)
887 #endif
888 
889 /* Definition of return/condition/exit codes **************************/
890 
892 #define CLERTC_OK 0
893 
895 #define CLERTC_INF 1
896 
898 #define CLERTC_FIN 2
899 
901 #define CLERTC_WRN 4
902 
904 #define CLERTC_RUN 8
905 
907 #define CLERTC_MAP 12
908 
910 #define CLERTC_SYN 16
911 
913 #define CLERTC_CMD 20
914 
916 #define CLERTC_INI 24
917 
919 #define CLERTC_CFG 28
920 
922 #define CLERTC_TAB 32
923 
925 #define CLERTC_SYS 36
926 
928 #define CLERTC_ACS 40
929 
931 #define CLERTC_ITF 44
932 
934 #define CLERTC_MEM 48
935 
937 #define CLERTC_FAT 64
938 
940 #define CLERTC_MAX 64
941 
942 /**********************************************************************/
943 
944 static inline unsigned int fnvHash(const unsigned int uiLen, const unsigned char* pcDat) {
945  unsigned int uiHsh=0x811C9DC5U;
946  const unsigned char* pcEnd=pcDat+uiLen;
947  while(pcDat<pcEnd) {
948  uiHsh=(((*pcDat) ^ (uiHsh)) * 0x01000193U);
949  pcDat++;
950  }
951  return(uiHsh);
952 }
953 
960 extern char* userid(const int size, char* buffer);
961 
969 extern char* homedir(const int flag, const int size, char* buffer);
970 
975 extern char* duserid(void);
976 
982 extern char* dhomedir(const int flag);
983 
993 extern char* safe_getenv(const char* name, char* buffer, size_t bufsiz);
994 
1001 extern char* unEscape(const char* input, char* output);
1002 
1008 extern char* dynUnEscape(const char* input);
1009 
1015 extern int printd(const char* format,...) __PRINTF_CHECK__(1, 2);
1016 
1024 extern int snprintc(char* buffer,const size_t size,const char* format,...) __PRINTF_CHECK__(3, 4);
1025 
1034 extern int srprintc(char** buffer,size_t* size,const size_t expansion,const char* format,...) __PRINTF_CHECK__(4, 5);
1035 
1044 extern int srprintf(char** buffer,size_t* size,const size_t expansion,const char* format,...) __PRINTF_CHECK__(4, 5);
1045 
1055 extern void fprintm(FILE* file,const char* own, const char* pgm, const char* bld, const char* man, const int cnt);
1056 
1068 extern int snprintm(char* buffer, size_t size, const char* own, const char* pgm, const char* bld, const char* man, const int cnt);
1069 
1070 
1083 extern const char* prsdstr(const char** hdl, const char* str, int len);
1084 
1085 #ifndef __WIN__
1086 /* Force the use of strlcpy instead of strncpy, but not on Windows because it causes trouble with MinGW headers */
1087 #ifdef strncpy
1088 #undef strncpy
1089 #endif
1090 #define strncpy(...) Error: Do not use strncpy! Use strlcpy instead!
1091 #endif
1092 
1100 extern size_t strlcpy(char *dest, const char *src, size_t n);
1101 
1110 extern char* getenvar(const char* name,const size_t length,const size_t size,char* string);
1111 
1118 extern char* mapstr(char* string,int size);
1119 
1126 extern char* dmapstr(const char* string,int method);
1127 
1134 extern char* dmapxml(const char* string,int method);
1135 
1142 extern char* mapfil(char* file,int size);
1143 
1150 extern char* dmapfil(const char* file, int method);
1151 
1159 extern char* maplab(char* label,int size,int toUpper);
1160 
1167 extern char* dmaplab(const char* label, int method);
1168 
1176 extern char* cpmapfil(char* dest, int size,const char* source);
1177 
1183 extern char* dcpmapfil(const char* file);
1184 
1194 extern char* cpmaplab(char* label, int size,const char* templ, const char* values, int toUpper);
1195 
1203 extern char* dcpmaplab(const char* templ, const char* values, int method);
1204 
1212 extern unsigned int localccsid(void);
1213 
1219 extern const char* mapl2c(unsigned isEBCDIC);
1220 
1227 extern const char* lng2ccsd(const char* pcLang, unsigned isEbcdic);
1228 
1234 extern const char* mapccsid(const unsigned int uiCcsId);
1235 
1241 extern unsigned int mapcdstr(const char* p);
1242 
1243 /**********************************************************************/
1244 
1252 extern unsigned int bin2hex(
1253  const unsigned char* bin,
1254  char* hex,
1255  const unsigned int len);
1256 
1264 extern unsigned int hex2bin(
1265  const char* hex,
1266  unsigned char* bin,
1267  const unsigned int len);
1268 
1276 extern unsigned int chr2asc(
1277  const char* chr,
1278  char* asc,
1279  const unsigned int len);
1280 
1288 extern unsigned int chr2ebc(
1289  const char* chr,
1290  char* ebc,
1291  const unsigned int len);
1292 
1300 extern unsigned int asc2chr(
1301  const char* asc,
1302  char* chr,
1303  const unsigned int len);
1304 
1311 extern void asc_chr(
1312  const char* asc,
1313  char* chr,
1314  const unsigned int len);
1315 
1322 extern void chr_asc(
1323  const char* chr,
1324  char* asc,
1325  const unsigned int len);
1326 
1334 extern unsigned int ebc2chr(
1335  const char* ebc,
1336  char* chr,
1337  const unsigned int len);
1338 
1345 extern void ebc_chr(
1346  const char* ebc,
1347  char* chr,
1348  const unsigned int len);
1349 
1356 extern void chr_ebc(
1357  const char* chr,
1358  char* ebc,
1359  const unsigned int len);
1360 
1383 extern int file2str(void* hdl, const char* filename, char** buf, int* bufsize, char* errmsg, const int msgsiz);
1384 
1401 extern int arry2str(char* array[], const int count, const char* separ, const int separLen, char** out, int* outlen);
1402 
1417 extern int strxcmp(
1418  const int ca,
1419  const char* s1,
1420  const char* s2,
1421  const int n,
1422  const int c,
1423  const int f);
1424 
1436 #define CSTIME_BUFSIZ 24
1437 
1438 extern char* cstime(signed long long t, char* p);
1439 
1451 extern int loadEnvars(const unsigned int uiLen, const char* pcBuf, FILE* pfOut, FILE* pfErr, TsEnVarList** ppList);
1452 
1463 extern int readEnvars(const char* pcFil, FILE* pfOut, FILE* pfErr, TsEnVarList** ppList);
1464 
1472 extern int envarInsert(TsEnVarList** ppList,const char* pcName,const char* pcValue);
1473 
1480 extern int resetEnvars(TsEnVarList** ppList);
1481 
1482 
1483 /**********************************************************************/
1484 
1485 typedef struct DiaChr {
1489  char exc[4];
1490  char hsh[4];
1491  char dlr[4];
1492  char ats[4];
1493  char sbo[4];
1494  char bsl[4];
1495  char sbc[4];
1496  char crt[4];
1497  char grv[4];
1498  char cbo[4];
1499  char vbr[4];
1500  char cbc[4];
1501  char tld[4];
1502  char svb[4];
1503  char sbs[4];
1504  char idt[4];
1506 
1507 extern void init_diachr(TsDiaChr* psDiaChr,const unsigned int uiCcsId);
1508 
1509 #ifdef __EBCDIC__
1510 
1511 extern TsDiaChr gsDiaChr;
1512 
1513 extern int ebcdic_srprintc(char** buffer, size_t* size, const size_t expansion, const char* format, ...);
1514 extern int ebcdic_snprintf(char* string, size_t size, const char* format, ...);
1515 extern int ebcdic_sprintf(char* string, const char* format, ...);
1516 extern int ebcdic_fprintf(FILE* file, const char* format, ...);
1517 
1518 extern char init_char(char* p);
1519 extern char* init_string(char* p);
1520 
1521 # define HSH_PBRK "\x7B\x4A\x63\xB1\x69"
1522 # define ATS_PBRK "\x7C\xB5\x80\xEC\x44\xAC"
1523 
1524 # define C_EXC ((gsDiaChr.exc[0])?gsDiaChr.exc[0]:init_char(gsDiaChr.exc))
1525 # define C_HSH ((gsDiaChr.hsh[0])?gsDiaChr.hsh[0]:init_char(gsDiaChr.hsh))
1526 # define C_DLR ((gsDiaChr.dlr[0])?gsDiaChr.dlr[0]:init_char(gsDiaChr.dlr))
1527 # define C_ATS ((gsDiaChr.ats[0])?gsDiaChr.ats[0]:init_char(gsDiaChr.ats))
1528 # define C_SBO ((gsDiaChr.sbo[0])?gsDiaChr.sbo[0]:init_char(gsDiaChr.sbo))
1529 # define C_BSL ((gsDiaChr.bsl[0])?gsDiaChr.bsl[0]:init_char(gsDiaChr.bsl))
1530 # define C_SBC ((gsDiaChr.sbc[0])?gsDiaChr.sbc[0]:init_char(gsDiaChr.sbc))
1531 # define C_CRT ((gsDiaChr.sbo[0])?gsDiaChr.crt[0]:init_char(gsDiaChr.crt))
1532 # define C_GRV ((gsDiaChr.grv[0])?gsDiaChr.grv[0]:init_char(gsDiaChr.grv))
1533 # define C_CBO ((gsDiaChr.cbo[0])?gsDiaChr.cbo[0]:init_char(gsDiaChr.cbo))
1534 # define C_VBR ((gsDiaChr.vbr[0])?gsDiaChr.vbr[0]:init_char(gsDiaChr.vbr))
1535 # define C_CBC ((gsDiaChr.cbc[0])?gsDiaChr.cbc[0]:init_char(gsDiaChr.cbc))
1536 # define C_TLD ((gsDiaChr.tld[0])?gsDiaChr.tld[0]:init_char(gsDiaChr.tld))
1537 # define S_EXC ((gsDiaChr.exc[0])?gsDiaChr.exc:init_string(gsDiaChr.exc))
1538 # define S_HSH ((gsDiaChr.hsh[0])?gsDiaChr.hsh:init_string(gsDiaChr.hsh))
1539 # define S_DLR ((gsDiaChr.dlr[0])?gsDiaChr.dlr:init_string(gsDiaChr.dlr))
1540 # define S_ATS ((gsDiaChr.ats[0])?gsDiaChr.ats:init_string(gsDiaChr.ats))
1541 # define S_SBO ((gsDiaChr.sbo[0])?gsDiaChr.sbo:init_string(gsDiaChr.sbo))
1542 # define S_BSL ((gsDiaChr.bsl[0])?gsDiaChr.bsl:init_string(gsDiaChr.bsl))
1543 # define S_SBC ((gsDiaChr.sbc[0])?gsDiaChr.sbc:init_string(gsDiaChr.sbc))
1544 # define S_CRT ((gsDiaChr.sbo[0])?gsDiaChr.crt:init_string(gsDiaChr.crt))
1545 # define S_GRV ((gsDiaChr.grv[0])?gsDiaChr.grv:init_string(gsDiaChr.grv))
1546 # define S_CBO ((gsDiaChr.cbo[0])?gsDiaChr.cbo:init_string(gsDiaChr.cbo))
1547 # define S_VBR ((gsDiaChr.vbr[0])?gsDiaChr.vbr:init_string(gsDiaChr.vbr))
1548 # define S_CBC ((gsDiaChr.cbc[0])?gsDiaChr.cbc:init_string(gsDiaChr.cbc))
1549 # define S_TLD ((gsDiaChr.tld[0])?gsDiaChr.tld:init_string(gsDiaChr.tld))
1550 # define S_SVB ((gsDiaChr.svb[0])?gsDiaChr.svb:init_string(gsDiaChr.svb))
1551 # define S_SBS ((gsDiaChr.sbs[0])?gsDiaChr.sbs:init_string(gsDiaChr.sbs))
1552 # define S_IDT ((gsDiaChr.idt[0])?gsDiaChr.idt:init_string(gsDiaChr.idt))
1553 
1554 # define esrprintc ebcdic_srprintc
1555 # define esnprintf ebcdic_snprintf
1556 # define esprintf ebcdic_sprintf
1557 # define efprintf ebcdic_fprintf
1558 
1559 #else
1560 
1561 # define HSH_PBRK "#" /*nodiac*/
1562 # define ATS_PBRK "@" /*nodiac*/
1563 
1564 # define C_EXC '!' /*nodiac*/
1565 # define C_HSH '#' /*nodiac*/
1566 # define C_DLR '$' /*nodiac*/
1567 # define C_ATS '@' /*nodiac*/
1568 # define C_SBO '[' /*nodiac*/
1569 # define C_BSL '\\' /*nodiac*/
1570 # define C_SBC ']' /*nodiac*/
1571 # define C_CRT '^' /*nodiac*/
1572 # define C_GRV '`' /*nodiac*/
1573 # define C_CBO '{' /*nodiac*/
1574 # define C_VBR '|' /*nodiac*/
1575 # define C_CBC '}' /*nodiac*/
1576 # define C_TLD '~' /*nodiac*/
1577 # define S_EXC "!" /*nodiac*/
1578 # define S_HSH "#" /*nodiac*/
1579 # define S_DLR "$" /*nodiac*/
1580 # define S_ATS "@" /*nodiac*/
1581 # define S_SBO "[" /*nodiac*/
1582 # define S_BSL "\\" /*nodiac*/
1583 # define S_SBC "]" /*nodiac*/
1584 # define S_CRT "^" /*nodiac*/
1585 # define S_GRV "`" /*nodiac*/
1586 # define S_CBO "{" /*nodiac*/
1587 # define S_VBR "|" /*nodiac*/
1588 # define S_CBC "}" /*nodiac*/
1589 # define S_TLD "~" /*nodiac*/
1590 # define S_SVB "=|" /*nodiac*/
1591 # define S_SBS "/\\" /*nodiac*/
1592 # define S_IDT "--|" /*nodiac*/
1593 
1594 # define esrprintc srprintc
1595 # define esnprintf snprintf
1596 # define esprintf sprintf
1597 # define efprintf fprintf
1598 
1599 #endif
1600 
1601 /**********************************************************************/
1602 
1604 #endif /* INC_CLEPUTL_H */
1605 
1606 #ifdef __cplusplus
1607  }
1608 #endif
1609 
TsEnVarList
struct EnVarList TsEnVarList
asc2chr
unsigned int asc2chr(const char *asc, char *chr, const unsigned int len)
printd
int printd(const char *format,...) __PRINTF_CHECK__(1
cstime
char * cstime(signed long long t, char *p)
strxcmp
int strxcmp(const int ca, const char *s1, const char *s2, const int n, const int c, const int f)
DiaChr::exc
char exc[4]
Reset list structure of environment variables .
Definition: CLEPUTL.h:1489
init_diachr
void init_diachr(TsDiaChr *psDiaChr, const unsigned int uiCcsId)
duserid
char * duserid(void)
maplab
char * maplab(char *label, int size, int toUpper)
fopen_hfq_nowarn
FILE * fopen_hfq_nowarn(const char *name, const char *mode)
ebc2chr
unsigned int ebc2chr(const char *ebc, char *chr, const unsigned int len)
fprintm
int int int int void fprintm(FILE *file, const char *own, const char *pgm, const char *bld, const char *man, const int cnt)
homedir
char * homedir(const int flag, const int size, char *buffer)
readEnvars
int readEnvars(const char *pcFil, FILE *pfOut, FILE *pfErr, TsEnVarList **ppList)
envarInsert
int envarInsert(TsEnVarList **ppList, const char *pcName, const char *pcValue)
dmapfil
char * dmapfil(const char *file, int method)
fclose_tmp
#define fclose_tmp(fp)
Definition: CLEPUTL.h:885
DiaChr::dlr
char dlr[4]
Definition: CLEPUTL.h:1491
remove_hfq
#define remove_hfq(n)
Definition: CLEPUTL.h:886
fopen_tmp
#define fopen_tmp()
Definition: CLEPUTL.h:884
resetEnvars
int resetEnvars(TsEnVarList **ppList)
TsDiaChr
struct DiaChr TsDiaChr
EnVarList::psNext
struct EnVarList * psNext
Definition: CLEPUTL.h:831
mapccsid
const char * mapccsid(const unsigned int uiCcsId)
EnVarList
Definition: CLEPUTL.h:825
freopen_hfq
FILE * freopen_hfq(const char *name, const char *mode, FILE *stream)
DiaChr::idt
char idt[4]
Definition: CLEPUTL.h:1504
DiaChr::sbc
char sbc[4]
Definition: CLEPUTL.h:1495
dcpmaplab
char * dcpmaplab(const char *templ, const char *values, int method)
mapcdstr
unsigned int mapcdstr(const char *p)
DiaChr::hsh
char hsh[4]
Definition: CLEPUTL.h:1490
hex2bin
unsigned int hex2bin(const char *hex, unsigned char *bin, const unsigned int len)
mapfil
char * mapfil(char *file, int size)
strlcpy
size_t strlcpy(char *dest, const char *src, size_t n)
asc_chr
void asc_chr(const char *asc, char *chr, const unsigned int len)
safe_getenv
char * safe_getenv(const char *name, char *buffer, size_t bufsiz)
DiaChr::cbo
char cbo[4]
Definition: CLEPUTL.h:1498
dynUnEscape
char * dynUnEscape(const char *input)
DiaChr::vbr
char vbr[4]
Definition: CLEPUTL.h:1499
mapl2c
const char * mapl2c(unsigned isEBCDIC)
DiaChr::sbo
char sbo[4]
Definition: CLEPUTL.h:1493
dmaplab
char * dmaplab(const char *label, int method)
userid
char * userid(const int size, char *buffer)
mapstr
char * mapstr(char *string, int size)
dmapxml
char * dmapxml(const char *string, int method)
chr2asc
unsigned int chr2asc(const char *chr, char *asc, const unsigned int len)
chr_asc
void chr_asc(const char *chr, char *asc, const unsigned int len)
arry2str
int arry2str(char *array[], const int count, const char *separ, const int separLen, char **out, int *outlen)
DiaChr::tld
char tld[4]
Definition: CLEPUTL.h:1501
DiaChr
Definition: CLEPUTL.h:1485
EnVarList::pcName
char * pcName
Environment variable list .
Definition: CLEPUTL.h:829
loadEnvars
int loadEnvars(const unsigned int uiLen, const char *pcBuf, FILE *pfOut, FILE *pfErr, TsEnVarList **ppList)
file2str
int file2str(void *hdl, const char *filename, char **buf, int *bufsize, char *errmsg, const int msgsiz)
chr2ebc
unsigned int chr2ebc(const char *chr, char *ebc, const unsigned int len)
ebc_chr
void ebc_chr(const char *ebc, char *chr, const unsigned int len)
srprintc
int int int srprintc(char **buffer, size_t *size, const size_t expansion, const char *format,...) __PRINTF_CHECK__(4
bin2hex
unsigned int bin2hex(const unsigned char *bin, char *hex, const unsigned int len)
localccsid
unsigned int localccsid(void)
prsdstr
const char * prsdstr(const char **hdl, const char *str, int len)
getFileSize
long long getFileSize(const char *name)
DiaChr::cbc
char cbc[4]
Definition: CLEPUTL.h:1500
dhomedir
char * dhomedir(const int flag)
dmapstr
char * dmapstr(const char *string, int method)
chr_ebc
void chr_ebc(const char *chr, char *ebc, const unsigned int len)
dcpmapfil
char * dcpmapfil(const char *file)
DiaChr::bsl
char bsl[4]
Definition: CLEPUTL.h:1494
DiaChr::sbs
char sbs[4]
Definition: CLEPUTL.h:1503
snprintm
int snprintm(char *buffer, size_t size, const char *own, const char *pgm, const char *bld, const char *man, const int cnt)
cpmaplab
char * cpmaplab(char *label, int size, const char *templ, const char *values, int toUpper)
unEscape
char * unEscape(const char *input, char *output)
DiaChr::crt
char crt[4]
Definition: CLEPUTL.h:1496
DiaChr::grv
char grv[4]
Definition: CLEPUTL.h:1497
cpmapfil
char * cpmapfil(char *dest, int size, const char *source)
DiaChr::ats
char ats[4]
Definition: CLEPUTL.h:1492
fopen_hfq
FILE * fopen_hfq(const char *name, const char *mode)
DiaChr::svb
char svb[4]
Definition: CLEPUTL.h:1502
getenvar
char * getenvar(const char *name, const size_t length, const size_t size, char *string)
srprintf
int int int int srprintf(char **buffer, size_t *size, const size_t expansion, const char *format,...) __PRINTF_CHECK__(4
EnVarList::pcValue
char * pcValue
Definition: CLEPUTL.h:830
lng2ccsd
const char * lng2ccsd(const char *pcLang, unsigned isEbcdic)
snprintc
int int snprintc(char *buffer, const size_t size, const char *format,...) __PRINTF_CHECK__(3