static int _StartBatch(MessageHandler *handler, char *name, char *param) { int (*apl)(char *); int rc; ValueStruct *val; char *arg; OpenCOBOL_Conv = NewConvOpt(); ConvSetSize(OpenCOBOL_Conv, ThisBD->textsize, ThisBD->arraysize); ConvSetCodeset(OpenCOBOL_Conv, ConvCodeset(handler->conv)); if (handler->conv != NULL) { OpenCOBOL_Conv->fBigEndian = handler->conv->fBigEndian; } else { Error("handler->conv is NULL"); } InitMONFUNC(OpenCOBOL_Conv, OpenCOBOL_PackValue, OpenCOBOL_UnPackValue, OpenCOBOL_SizeValue); #ifdef DEBUG printf("starting [%s][%s]\n", name, param); #endif if ((apl = cob_resolve(name)) != NULL) { val = NewValue(GL_TYPE_CHAR); SetValueStringWithLength(val, param, ThisBD->textsize, NULL); arg = StrnDup(ValueToString(val, "euc-jisx0213"), ThisBD->textsize); StringC2Cobol(arg, ThisBD->textsize); rc = apl(arg); FreeValueStruct(val); xfree(arg); } else { Warning("%s - %s is not found.", cob_resolve_error(), name); rc = -1; } return (rc); }
void orcaccess (char *args) { int str_len,mode,access_mode; char *envname; char *in_filename; char buf_path[STR_LEN]; char filename[STR_LEN]; char *fullpath; char *out_dirname; char *out_filename; int *writable,*file_exists,*retcode; struct stat buf ; char *p; p = args; str_len = *(size_t *)(p); p += sizeof(int); mode = *(int *)(p); p += sizeof(int); envname=p; StringCobol2C(envname, str_len); p += str_len; in_filename=p; StringCobol2C(in_filename, str_len); p += str_len; fullpath=p; p += str_len; out_dirname=p; p += str_len; out_filename=p; p += str_len; writable = (int *)(p); p += sizeof(int); file_exists = (int *)(p); p += sizeof(int); retcode = (int *)(p); *writable=0; *file_exists=0; *file_exists=0; access_mode = F_OK; if ((mode & 1 ) > 0){ access_mode += X_OK; } if ((mode & 2 ) > 0){ access_mode += W_OK; } if ((mode & 4 ) > 0){ access_mode += R_OK; } if ( *envname != 0 && strchr(in_filename,'/') == 0 && (access_mode & X_OK)){ *retcode= search_file(str_len,access_mode,envname,in_filename,fullpath,out_dirname,out_filename,writable,file_exists); }else{ strncpy(filename,in_filename,str_len); if (strchr(in_filename,'/') == 0){ getcwd(filename,sizeof(filename)); sprintf(filename,"%s/%s",filename,in_filename); } strncpy(fullpath,filename,str_len); strncpy(buf_path,filename,str_len); strncpy(out_dirname,dirname(buf_path),str_len); strncpy(buf_path,filename,str_len); strncpy(out_filename,basename(buf_path),str_len); if (stat(out_dirname, &buf) == 0 && S_ISDIR(buf.st_mode) == 1 && access(out_dirname,W_OK) == 0){ if (access(filename,F_OK) == 0){ if (stat(filename, &buf) == 0 && S_ISDIR(buf.st_mode) == 0){ *writable = 1; } }else{ *writable = 1; } }; if (stat(filename, &buf) == 0 && S_ISREG(buf.st_mode) == 1){ if (access(filename,F_OK) == 0){ *file_exists = 1; }; *retcode= access(filename,access_mode); }else{ *retcode = -1; } } StringC2Cobol(envname, str_len); StringC2Cobol(in_filename, str_len); StringC2Cobol(fullpath, str_len); StringC2Cobol(out_dirname, str_len); StringC2Cobol(out_filename, str_len); }
extern size_t OpenCOBOL_PackValue(CONVOPT *opt, unsigned char *p, ValueStruct *value) { int i; size_t size; unsigned char *pp; pp = p; if (value != NULL) { switch (ValueType(value)) { case GL_TYPE_INT: *(int32_t *)p = (int32_t)ValueInteger(value); IntegerC2Cobol(opt, (int32_t *)p); p += sizeof(int32_t); break; case GL_TYPE_FLOAT: *(double *)p = ValueFloat(value); p += sizeof(double); break; case GL_TYPE_BOOL: *(char *)p = ValueBool(value) ? 'T' : 'F'; p++; break; case GL_TYPE_BYTE: memcpy(p, ValueByte(value), ValueByteLength(value)); p += ValueByteLength(value); break; case GL_TYPE_BINARY: memclear(p, opt->textsize); size = (opt->textsize < ValueByteLength(value)) ? opt->textsize : ValueByteLength(value); memcpy(p, ValueToBinary(value), size); p += opt->textsize; break; case GL_TYPE_TEXT: case GL_TYPE_SYMBOL: size = (opt->textsize < ValueStringLength(value)) ? opt->textsize : ValueStringLength(value); memcpy(p, ValueToString(value, ConvCodeset(opt)), size); StringC2Cobol(p, opt->textsize); p += opt->textsize; break; case GL_TYPE_CHAR: case GL_TYPE_VARCHAR: case GL_TYPE_DBCODE: if (IS_VALUE_NIL(value)) { memclear(p, ValueStringLength(value)); /* LOW-VALUE */ } else { strncpy(p, ValueToString(value, ConvCodeset(opt)), ValueStringLength(value)); StringC2Cobol(p, ValueStringLength(value)); } p += ValueStringLength(value); break; case GL_TYPE_NUMBER: memcpy(p, ValueFixedBody(value), ValueFixedLength(value)); FixedC2Cobol(p, ValueFixedLength(value)); p += ValueFixedLength(value); break; case GL_TYPE_OBJECT: memcpy(p, ValueBody(value), SIZE_UUID); StringC2Cobol(p, SIZE_UUID); p += SIZE_UUID; break; case GL_TYPE_TIMESTAMP: p += sprintf(p, "%04d%02d%02d%02d%02d%02d", ValueDateTimeYear(value), ValueDateTimeMon(value) + 1, ValueDateTimeMDay(value), ValueDateTimeHour(value), ValueDateTimeMin(value), ValueDateTimeSec(value)); break; case GL_TYPE_DATE: p += sprintf(p, "%04d%02d%02d", ValueDateTimeYear(value), ValueDateTimeMon(value) + 1, ValueDateTimeMDay(value)); break; case GL_TYPE_TIME: p += sprintf(p, "%02d%02d%02d", ValueDateTimeHour(value), ValueDateTimeMin(value), ValueDateTimeSec(value)); break; case GL_TYPE_ARRAY: for (i = 0; i < ValueArraySize(value); i++) { p += OpenCOBOL_PackValue(opt, p, ValueArrayItem(value, i)); } break; case GL_TYPE_ROOT_RECORD: case GL_TYPE_RECORD: for (i = 0; i < ValueRecordSize(value); i++) { p += OpenCOBOL_PackValue(opt, p, ValueRecordItem(value, i)); } break; default: break; } } return (p - pp); }