INT16 CGEN_PROTECTED CCgen::OnMain() { char lpsProjectname[L_INPUTLINE+1]; GetNextDefToken(lpsProjectname); if (m_nAncestor > 0) return O_K; if (!dlp_strlen(lpsProjectname)) return IERROR(this,ERR_EXPECTAFTER,"name","MAIN:",0); if (m_bAppend) { if (dlp_strncmp(m_lpsProject,lpsProjectname,dlp_strlen(lpsProjectname)) != 0 || !m_bMainProject) { IERROR(this,ERR_APPEND,"MAIN:",lpsProjectname,0); if (!dlp_strlen(m_lpsProject)) EXIT(ERR_EXPPROJECT,"/append MAIN:",0,0); return NOT_EXEC; } } // Set project code SetCreating(CR_PROJECT,NULL); m_bMainProject = TRUE; dlp_strcpy(m_lpsProject,lpsProjectname); return O_K; }
/* * Manual page at function.def */ BOOL CGEN_PUBLIC CFunction::IsInstance(const char* sInstanceId, const char* sClassId) { if (!dlp_strlen(sInstanceId)) return FALSE; SWord* lpWord = FindWordAi(sInstanceId); if (!lpWord || lpWord->nWordType!=WL_TYPE_INSTANCE) return FALSE; if (!dlp_strlen(sClassId)) return TRUE; return ((CDlpObject*)lpWord->lpData)->IsKindOf(sClassId); }
/* * Manual page at process.def */ INT16 CGEN_PUBLIC CProcess::Status() { CData* d; char s[L_INPUTLINE]; INT32 i; printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); // Protocol printf("\n Status of instance"); // Protocol printf("\n process %s",BASEINST(_this)->m_lpInstanceName); // Protocol printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); // Protocol printf("\n State : 0x%04X",m_nState); // Protocol if (m_nState!=0) // In any but the maiden state { // >> BOOL b = 0; // Comma flag printf(" ("); // Protocol if (m_nState&PRC_DATASENT ) { if(b) printf(", "); printf("data sent" ); b=1; }//... if (m_nState&PRC_RUNNING ) { if(b) printf(", "); printf("running" ); b=1; }//... if (m_nState&PRC_COMPLETE ) { if(b) printf(", "); printf("complete" ); b=1; }//... if (m_nState&PRC_KILLED ) { if(b) printf(", "); printf("killed" ); b=1; }//... if (m_nState&PRC_DATARECEIVED) { if(b) printf(", "); printf("data received"); b=1; }//... printf(")"); // Protocol } // << printf("\n Return value: %ld",(long)m_nRetVal ); // Protocol if (dlp_strlen(m_psTmpFile)) printf("\n Temp. files : %s*",m_psTmpFile); // Protocol dlp_strcpy(s,m_psCmdLine); dlp_strreplace(s,m_psTmpFile,"<tmpfile>"); // Abbreviate command line if (dlp_strlen(m_psCmdLine)) printf("\n Command line: %s" ,s); // Protocol // Show transferred data // ------------------------------------ if (m_iDto) // Have data transfer object { // >> printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); // Protocol printf("\n Transferred data"); // Protocol d = (CData*)CDlpObject_FindInstanceWord(m_iDto,PRC_S_IDSIGN,NULL); // Get signature table printf("\n - function : %s",(char*)CData_XAddr(d,0,0)); // Protocol (job function name) for (i=1; i<CData_GetNRecs(d); i++) // Loop over function arguemnts printf("\n %13s %s",i==1?"- arguments :":"",(char*)CData_XAddr(d,i,0)); // Protocol (job function arg.) d = (CData*)CDlpObject_FindInstanceWord(m_iDto,PRC_S_IDGLOB,NULL); // Get list of global instances if (d) // Have one for (i=0; i<CData_GetNRecs(d); i++) // Loop over entries printf("\n %13s %-8s %s",i==0?"- globals :":"", // Protocol (global instance) (char*)CData_XAddr(d,i,0),(char*)CData_XAddr(d,i,1)); // | printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); // Protocol printf("\n Transferred program"); // Protocol for (i=0; dlp_strlen(__sSlaveScript[i]); i++) // Loop over slave script lines { // >> dlp_strcpy(s,__sSlaveScript[i]); // Get a line if (strstr(s,"##"))*(strstr(s,"##"))='\0'; // Truncate at comment printf("\n (%02ld) %s",i,dlp_strtrimright(s)); // Protocol (script line) } // << } // << printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); printf("\n"); // Protocol return O_K; // All done }
/** * Determines if the string lpsBuffer starts with the "key" string lpsKey and, * if this is the case, returns a pointer to the "value" string following the * key. * * @param lpsBuffer Pointer to a string to scan * @param lpsKey POinter to the key string * @return Pointer to value string */ const char* CGEN_PROTECTED CDgen::ScanKey(const char* lpsBuffer, const char* lpsKey) { if (!dlp_strlen(lpsKey) ) return NULL; if (!dlp_strlen(lpsBuffer) ) return NULL; if (strstr(lpsBuffer,lpsKey)!=lpsBuffer) return NULL; const char* tx = &lpsBuffer[strlen(lpsKey)]; while (*tx && iswspace(*tx)) tx++; if (*tx++!=':') return NULL; while (*tx && iswspace(*tx)) tx++; return tx; }
INT16 CGEN_PROTECTED CCgen::OnVersion() { const char* lpVersion = GetRestOfDefLine(); if (m_nAncestor) return O_K; if (!dlp_strlen(lpVersion)) ERRORRET(ERR_EXPECTAFTER,"version name","VERSION:",0,NOT_EXEC); if (dlp_strlen(lpVersion)>=sizeof(m_lpsVersion)) IERROR(this,ERR_TOOLONG,GetCurrentDefFile(),GetCurrentDefLine(),"Version name"); dlp_strncpy(m_lpsVersion,lpVersion,sizeof(m_lpsVersion)); m_lpsVersion[sizeof(m_lpsVersion)-1]='\0'; return O_K; }
/** * Initialize one record from a token list. * * @param lpsInit Null ('\0') separated list of tokens. A double null "\0\0" * is expected as list terminator! * @param nRec Record index of first cell to initialize * @param nComp Component index of first cell to initialize * @return O_K if successfull, a negative error code otherwise */ INT16 CGEN_PUBLIC CData_InitializeRecordEx ( CData* _this, const char* lpsInit, INT32 nRec, INT32 nComp ) { const char* lpsToken = NULL; INT32 nXC = 0; INT32 nC = 0; nXC = CData_GetNComps(_this); nC = nComp; if (nC<0 || nC>=nXC ) return NOT_EXEC; if (nRec<0 || nRec>=CData_GetNRecs(_this)) return NOT_EXEC; for (lpsToken=lpsInit; *lpsToken && nC<nXC; lpsToken+=dlp_strlen(lpsToken)+1, nC++) if (dlp_strcmp(lpsToken,"*")!=0) IF_NOK(dlp_sscanx(lpsToken,CData_GetCompType(_this,nC),CData_XAddr(_this,nRec,nC))) IERROR(_this,DATA_BADINITIALIZER,lpsToken,(int)nRec,(int)nC); if (*lpsToken) return IERROR(_this,DATA_INITIALIZERS,"many",0,0); if (nC<nXC ) IERROR(_this,DATA_INITIALIZERS,"few" ,0,0); return O_K; }
/** * Writes the data transfer file of this process. This method is called * immediately before starting the operating system process. */ INT16 CGEN_PUBLIC CProcess::SendData() { DLP_FILE* pfScr; // Slave script file pointer INT32 i; // Loop counter char sScrFn[L_PATH]; // Slave script file name char sDtoFn[L_PATH]; // Data transfer file name if (m_nState & PRC_DATASENT) return NOT_EXEC; // Data have already been sent if (m_iDto) // This process is a function call { // >> sprintf(sScrFn,"%s.xtp",m_psTmpFile); // Get slave script file name sprintf(sDtoFn,"%s.xml",m_psTmpFile); // Get data transfer fine name pfScr = dlp_fopen(sScrFn,"w"); // Open temporary script file for (i=0; dlp_strcmp(__sSlaveScript[i],"\0")!=0; i++) // Loop over slave script lines { // >> dlp_fwrite(__sSlaveScript[i],1,dlp_strlen(__sSlaveScript[i]),pfScr); // Write a line dlp_fwrite("\n",1,1,pfScr); // Write a line break } // << dlp_fclose(pfScr); // Close temporary script file CDlpObject_Save(m_iDto,sDtoFn,SV_XML|SV_ZIP); // Save data transfer object sprintf(m_psCmdLine,"%s %s %s",dlp_get_binary_path(),sScrFn,sDtoFn); // Change the command line // -- ???? --> IDESTROY(m_iDto); IFIELD_RESET(CDlpObject,"dto"); // Save memory! // <---------- } // << m_nState |= PRC_DATASENT; // Remember data have been sent return O_K; }
INT16 CGEN_PROTECTED CCgen::OnLpath() { char lpName[L_INPUTLINE+1]; GetNextDefToken(lpName); if (!dlp_strlen(lpName)) ERRORRET(ERR_EXPECTAFTER,"name","LPATH:",0,NOT_EXEC); switch(m_nCreating) { case CR_PROJECT: { if (m_nAncestor) return O_K; else dlp_convert_name(CN_XLATPATH,m_lpsLPath,lpName); break;} case CR_ERROR: return IERROR(this,ERR_INVALSUBKEY,"ERROR:","LPATH:",0); case CR_FIELD: return IERROR(this,ERR_INVALSUBKEY,"FIELD:","LPATH:",0); case CR_OPTION: return IERROR(this,ERR_INVALSUBKEY,"OPTION:","LPATH:",0); case CR_METHOD: return IERROR(this,ERR_INVALSUBKEY,"METHOD:","LPATH:",0); case CR_NOTE: return IERROR(this,ERR_INVALSUBKEY,"NOTE:","LPATH:",0); case CR_ICLS: { SCGIcl* s = m_lpCreatingIcl; DLPASSERT(s); dlp_strcpy(s->lpLPath,lpName); break; } default: return IERROR(this,ERR_EXPGLOBALKEY,"LPATH:",0,0); } return O_K; }
INT16 CGEN_PROTECTED CCgen::OnFile() { char lpFile[L_INPUTLINE]; GetNextDefToken(lpFile); dlp_strconvert(SC_UNESCAPE,lpFile,lpFile); dlp_strtrimleft(lpFile); dlp_strtrimright(lpFile); if (m_bMainProject) ERRORRET(ERR_INVALKEY,"FILE:","MAIN:",0,NOT_EXEC); if (m_nAncestor) return O_K; INT16 nFType = 0; if (!dlp_strlen(lpFile)) ERRORRET(ERR_EXPECTAFTER,"file name","FILE:",0,NOT_EXEC); if (m_files.FindItem(lpFile)) ERRORRET(ERR_DDEF_LIST,"FILE",lpFile,0,NOT_EXEC); char *ext = &lpFile[strlen(lpFile)-1]; while (*ext != '.' && ext != lpFile) ext--; if (dlp_strncmp(ext,".cpp",L_NAMES) ==0) nFType = FT_CPP; if (dlp_strncmp(ext,".c" ,L_NAMES) ==0) nFType = FT_C; if (dlp_strncmp(ext,".h" ,L_NAMES) ==0) nFType = FT_H; if (!nFType) ERRORRET(ERR_FILETYPE,ext,NULL,0,NOT_EXEC); SCGFile* nf = m_files.AddItem(lpFile); if (!nf) return NOT_EXEC; nf->nFType = nFType; return O_K; }
INT16 CGEN_PROTECTED CCgen::OnHfile() { char lpName[L_INPUTLINE+1]; GetNextDefToken(lpName); if (!dlp_strlen(lpName)) ERRORRET(ERR_EXPECTAFTER,"name","HFILE:",0,NOT_EXEC); switch(m_nCreating) { case CR_PROJECT: return IERROR(this,ERR_INVALSUBKEY,"PROJECT:","HFILE:",0); case CR_ERROR: return IERROR(this,ERR_INVALSUBKEY,"ERROR:","HFILE:",0); case CR_FIELD: return IERROR(this,ERR_INVALSUBKEY,"FIELD:","HFILE:",0); case CR_OPTION: return IERROR(this,ERR_INVALSUBKEY,"OPTION:","HFILE:",0); case CR_METHOD: return IERROR(this,ERR_INVALSUBKEY,"METHOD:","HFILE:",0); case CR_NOTE: return IERROR(this,ERR_INVALSUBKEY,"NOTE:","HFILE:",0); case CR_ICLS : { SCGIcl* s = m_lpCreatingIcl; DLPASSERT(s); dlp_strcpy(s->lpHFile,lpName); break; } default: return IERROR(this,ERR_EXPGLOBALKEY,"HFILE:",0,0); } return O_K; }
INT16 CGEN_PROTECTED CCgen::OnPlatform() { char lpPlatform[L_INPUTLINE+1]; GetNextDefToken(lpPlatform); if (m_nAncestor) return O_K; if (!dlp_strlen(lpPlatform)) ERRORRET(ERR_EXPECTAFTER,"platform name","PLATFORM:",0,NOT_EXEC); m_nPlatform = 0; if (dlp_strncmp(lpPlatform,"GNUC++",L_NAMES) ==0) m_nPlatform = PF_GNUCXX; if (dlp_strncmp(lpPlatform,"MSDEV4",L_NAMES) ==0) m_nPlatform = PF_MSDEV4; if (dlp_strncmp(lpPlatform,"MSDEV5",L_NAMES) ==0) m_nPlatform = PF_MSDEV5; if (dlp_strncmp(lpPlatform,"MSDEV6",L_NAMES) ==0) m_nPlatform = PF_MSDEV6; if (dlp_strncmp(lpPlatform,"MSDEV",L_NAMES) ==0) { ERRORMSG(ERR_OBSOLETEID,"MSDEV","MSDEV4",0); m_nPlatform = PF_MSDEV4; } if (dlp_strncmp(lpPlatform,"MSVC++",L_NAMES) ==0) { // Detect MSVC++ version m_nPlatform = QueryMSVCVersion(m_lpsMSDPath); if (!m_nPlatform) ERRORRET(ERR_NOMSVCFOUND,0,0,0,ERR_NOMSVCFOUND); } if (!m_nPlatform) ERRORRET(ERR_NOPLATFORM,lpPlatform,0,0,NOT_EXEC); return O_K; }
char* CDlpObject_GetFQName(CDlpObject* _this, char* lpName, BOOL bForceArray) { char lpBuf1[255]; char lpBuf2[255]; SWord* lpWord; CDlpObject* lpInst = _this; if (!_this) { dlp_strcpy(lpName,"(null)"); return lpName; } lpBuf2[0]='\0'; if (!_this->m_lpContainer) dlp_strcpy(lpName,_this->m_lpInstanceName); else { lpWord = _this->m_lpContainer; while (TRUE) { /* Do no include interpreter instance name */ if (dlp_strcmp(lpWord->lpContainer->m_lpClassName,"itp")==0) break; if (lpWord->nWordType==WL_TYPE_FIELD && lpWord->ex.fld.nType==T_INSTANCE && (lpWord->ex.fld.nArrlen!=1 || bForceArray)) { /* Seek instance in array */ INT32 i = 0; for (i=0; i<lpWord->ex.fld.nArrlen; i++) if (((CDlpObject**)lpWord->lpData)[i] == lpInst) break; if (i<lpWord->ex.fld.nArrlen) sprintf(lpBuf1,".%s[%ld]%s",lpWord->lpName,(long)i,lpBuf2); else /* MWX 2002-01-16: This is an error actually, but what should be done here ???? --> */ sprintf(lpBuf1,".%s%s",lpWord->lpName,lpBuf2); /* <-- */ } else sprintf(lpBuf1,".%s%s",lpWord->lpName,lpBuf2); strcpy(lpBuf2,lpBuf1); lpInst = (CDlpObject*)lpWord->lpContainer; DLPASSERT(lpInst); /* Word must belong to an instance! */ if (!lpInst->m_lpContainer) break; /* No parent --> stop */ lpWord = lpInst->m_lpContainer; } if (lpBuf2[0] == '.') dlp_memmove(lpBuf2,&lpBuf2[1],dlp_strlen(lpBuf2)); if (strlen(lpBuf2)>0) sprintf(lpName,"%s.%s",lpInst->m_lpInstanceName,lpBuf2); else strcpy(lpName,lpInst->m_lpInstanceName); } return lpName; }
INT16 CGEN_PROTECTED CCgen::OnMsvcFlags() { const char* lpFlags = GetRestOfDefLine(); if (m_nAncestor) return O_K; if (!dlp_strlen(lpFlags)) ERRORRET(ERR_EXPECTAFTER,"compiler options","MSVCFLAGS:",0,NOT_EXEC); dlp_strcpy(m_lpsMsvcFlags,lpFlags); return O_K; }
/*{{CGEN_CFCCF */ INT16 CDlpFile_OnExtChanged(CDlpObject* __this) { GET_THIS_VIRTUAL_RV(CDlpFile,NOT_EXEC); { /* Remove leading dots */ while (_this->m_lpsExt[0] == '.') memmove(_this->m_lpsExt,&_this->m_lpsExt[1],dlp_strlen(_this->m_lpsExt)); } return O_K; }
INT16 CHelloworld_OnGreetingGermanChanged(CDlpObject* __this) { GET_THIS_VIRTUAL_RV(CHelloworld,NOT_EXEC); { if (!dlp_strlen(_this->m_greetingGerman)) return IERROR(_this,PAR_ERROR,"greeting_german",0,0); } return O_K; }
/** * Get data initializer '{ ... }' from command line and store into token list * lpsInit. * <h3>Note</h3> * <p>You must setup the method invocation context <code>m_lpMic</code> (see * <a href="dlpinst.html"><code class="link">CDlpInstance</code></a>) before * calling this method. Otherwise it will do noting.</p> * * @param lpsInit Pointer to character buffer to store initializer in. The * tokens will be separated by nulls '\0', opening and closing * curly braces will not be included! The token list will be * terminated with a double null "\0\0". * @param nLen Maximal number of characters to place on lpsInit (including * the terminal double null) * @param bForce If TRUE the method does not seek for the opening curly brace * but starts reading initializers until it encounters a closing * curly brace '}'. A leading opening curly brace will, however, * be tolerated. If FALSE the method <i>expects</i> an opening * curly brace and does not read any initializers if no leading * opening brace is found. * @return The number of initializers read */ INT32 CGEN_PROTECTED CData_ReadInitializer ( CData* _this, char* lpsInit, INT32 nLen, BOOL bForce ) { const char* lpsToken; /* Current token */ INT32 nCnt; /* Token counter */ INT32 nPos; /* Position in output buffer */ BOOL bStor; /* Store next token */ /* Initialize */ /* --------------------------------- */ if (!CDlpObject_MicGet(BASEINST(_this))) return 0; /* Need invocation context */ if (!lpsInit) return 0; /* Need output buffer */ dlp_memset(lpsInit,0,nLen); /* Clear output buffer */ /* Do initializers follow? */ /* --------------------------------- */ lpsToken = MIC_NEXTTOKEN_FORCE; /* Ruthlessly get next token */ if (!lpsToken || dlp_strcmp(lpsToken,"{")!=0) /* No or not the "{" token */ { /* >> */ if (bForce) IERROR(_this,DATA_NOTFOUND,"Constant initializer ","'{'",0); /* If there should be some-> error */ if (lpsToken) MIC_REFUSETOKEN; /* Wrong token -> push it back */ return 0; /* Now get out'a here */ } /* << */ /* Get 'em tokens */ /* --------------------------------- */ for (nCnt=0,nPos=0,bStor=TRUE; ; nCnt++) /* Infinitely ... */ { /* >> */ lpsToken = MIC_NEXTTOKEN_FORCE; /* Ruthlessly get next token */ if (!lpsToken) return IERROR(_this,DATA_HERESCAN,"}",0,0); /* No more tokens -> forget it */ if (dlp_strcmp(lpsToken,"}")==0) break; /* End token -> get out'a here */ if (nLen<nPos+(INT32)dlp_strlen(lpsToken)+2) bStor = FALSE; /* Cannot store more tokens :( */ if (!bStor) continue; /* Ignore ALL following tokens */ dlp_strcpy(&lpsInit[nPos],lpsToken); /* Store token */ nPos+=(INT32)dlp_strlen(&lpsInit[nPos])+1; /* Set next token pointer */ } /* << */ return nCnt; /* Return number of tokens read */ }
INT16 CGEN_PROTECTED CCgen::OnAuthor() { const char* lpAuthor = GetRestOfDefLine(); if (m_nAncestor) return O_K; if (!dlp_strlen(lpAuthor)) ERRORRET(ERR_EXPECTAFTER,"author name","AUTHOR:",0,NOT_EXEC); dlp_strcpy(m_lpsAuthor,lpAuthor); return O_K; }
INT16 CGEN_PROTECTED CCgen::OnDefine() { const char* lpDefine = GetRestOfDefLine(); if (m_nAncestor) return O_K; if (!dlp_strlen(lpDefine)) ERRORRET(ERR_EXPECTAFTER,"directive","DEFINE:",0,NOT_EXEC); if (m_defines.FindItem(lpDefine)) ERRORRET(ERR_DDEF_LIST,"DEFINE",lpDefine,0,NOT_EXEC); if (m_defines.AddItem(lpDefine)) return O_K; else return NOT_EXEC; }
/* * Manual page at function.def */ INT16 CGEN_PUBLIC CFunction::Prompt(const char* lpsMessage) { char sBuf[L_SSTR+1]; printf(lpsMessage); printf("> "); if(fgets(sBuf,L_SSTR,stdin) == NULL) return NOT_EXEC; for (char* tx = &sBuf[dlp_strlen(sBuf)-1]; *tx; tx--) if (*tx=='\n' || *tx=='\r') *tx='\0'; else break; PushString(sBuf); return O_K; }
/** * Changes the current working directory. If <code>bCreate</code> is * <code>TRUE</code> and the directory does not exists, <code>dlp_chdir</code> * will create the directory. <code>dlp_chdir</code> is capable of creating a * tree of non-existing directories at once. * * @param lpsDirname Destination directory * @param bCreate Create directory if not exists * @return 0 if successful, an error code (or -1) if not sucessful */ INT16 dlp_chdir(const char* lpsDirname, BOOL bCreate) { char lpsDir[L_PATH]; char* tx; INT16 nError; if (dlp_strlen(lpsDirname)==0) return 0; nError = (INT16)chdir(lpsDirname); if (nError == 0 || !bCreate) return nError; /* Try to create path */ dlp_memset(lpsDir,0,L_PATH); dlp_strcpy(lpsDir,lpsDirname); /* Change into the furthest existing directory */ tx = &lpsDir[dlp_strlen(lpsDir)-1]; while (tx != lpsDir) { while (tx!=lpsDir && *tx != '\\' && *tx != '/') tx--; if (tx!=lpsDir) *tx=0; if (chdir(lpsDir) == 0) break; } if (tx!=lpsDir) tx++; /* Create remaining sub directories */ while (tx[1]) { #if (defined __MSOS || defined __WIN32) nError = (INT16)mkdir(tx); #else nError = (INT16)mkdir(tx,0xFFFF); #endif if (nError) return nError; nError = (INT16)chdir(tx); if (nError) return nError; while (*tx++); } /* Should have worked... */ return 0; }
INT16 CGEN_PROTECTED CCgen::OnInclude() { char lpInclude[L_INPUTLINE+1]; GetNextDefToken(lpInclude); if (m_nAncestor) return O_K; if (!dlp_strlen(lpInclude)) ERRORRET(ERR_EXPECTAFTER,"file name","INCLUDE:",0,NOT_EXEC); if (m_includes.FindItem(lpInclude)) ERRORRET(ERR_DDEF_LIST,"INCLUDE",lpInclude,0,NOT_EXEC); if (m_includes.AddItem(lpInclude)) return O_K; else return NOT_EXEC; }
INT16 CGEN_PROTECTED CCgen::OnFriend() { char lpFriend[L_INPUTLINE+1]; GetNextDefToken(lpFriend); if (m_nAncestor) return O_K; if (!dlp_strlen(lpFriend)) ERRORRET(ERR_EXPECTAFTER,"identifier","FRIEND:",0,NOT_EXEC); if (m_friends.FindItem(lpFriend)) ERRORRET(ERR_DDEF_LIST,"FRIEND",lpFriend,0,NOT_EXEC); if (m_friends.AddItem(lpFriend)) return O_K; else return NOT_EXEC; }
/** * Utility function for CData_PrintVectors; pads a string up to a given length * with spaces. */ char* __pad ( char* sStr, /* The string to pad */ INT32 nLen, /* The target length */ char nMode /* Alignment: 'l', 'r' or 'c' */ ) /* Returns sStr */ { char* tx = NULL; /* Current character in string */ if ((INT32)dlp_strlen(sStr)==nLen) return sStr; /* Nothing to be done */ if ((INT32)dlp_strlen(sStr)> nLen) /* String longer than nLen */ { /* >> */ for (tx=sStr;tx<sStr+nLen;tx++) *tx='#'; /* Make it "#######" */ *tx='\0'; /* Terminate it */ return sStr; /* Return it */ } /* << */ while ((INT32)dlp_strlen(sStr)<nLen) /* While string shorter than required*/ { /* >> */ if (nMode=='c' || nMode=='r') /* Padding at left side */ { /* >> */ dlp_memmove(&sStr[1],sStr,dlp_strlen(sStr)+1); /* Move data */ sStr[0]=' '; /* Write heading space */ if (nMode=='c') nMode='C'; /* Toggle centering flag */ } /* << */ else if (nMode=='C' || nMode=='l') /* Paddig at right side */ { /* >> */ sStr[dlp_strlen(sStr)+2]='\0'; /* Write second terminal 0 */ sStr[dlp_strlen(sStr)+1]=' '; /* Write trailing space */ if (nMode=='C') nMode='c'; /* Toggle centering flag */ } /* << */ } /* << */ return sStr; /* Return sStr */ }
/** * Packs a stack item into the data transfer object <code>iDto</code>. If the * stack item is an instance, the function will create a copy in * <code>iDto</code>. If the stack item is a boolean, numeric or string value, * the function will create a variable holding that value in <code>iDto</code>. * * @param iDto * the data transfer object (must not be <code>NULL</code>) * @param idSign * the signature table (may be <code>NULL</code>, if not * <code>NULL</code> the item will be added to the signature) * @param pStkItm * the stack item to pack (see documentation of <code>CFunction</code>) * @param psName * the object name (if <code>NULL</code> or empty, a default name will * be used ) */ void CGEN_PROTECTED CProcess::Pack ( CDlpObject* iDto, CData* idSign, StkItm* pStkItm, const char* psName ) { CDlpObject* iDst = 0; // Packed instance INT32 nArg = -1; // Argument index in signature char sBuf[L_NAMES]; // Packed instance name buffer // Validate and initialize // ------------------------------------ if (!iDto ) return; // Need data transfer object! if (!pStkItm) return; // Need stack item! dlp_strcpy(sBuf,psName); // Copy custom instance name if (idSign) nArg = CData_AddRecs(idSign,1,10); // Add element to signature // Pack // ------------------------------------ if (pStkItm->nType==T_INSTANCE && pStkItm->val.i!=NULL) // Pack an instance { // >> CDlpObject* iSrc = pStkItm->val.i; // Get pointer to instance if (dlp_strlen(sBuf)==0) dlp_strcpy(sBuf,iSrc->m_lpInstanceName); // No custom name -> use inst. name iDst = CDlpObject_Instantiate(iDto,iSrc->m_lpClassName,sBuf,FALSE); // Created packed instance iDst->Copy(iSrc); // Copy content } // << else // Pack a boolean, number or string { // >> if (dlp_strlen(sBuf)==0) sprintf(sBuf,"arg%ld",(long)nArg); // No custom name -> make a name iDst = CDlpObject_Instantiate(iDto,"var",sBuf,FALSE); // Create a variable to pack into switch (pStkItm->nType) // Branch for variable type { // | case T_BOOL : ((CVar*)iDst)->Bset(pStkItm->val.b); break; // Pack a boolean case T_COMPLEX: ((CVar*)iDst)->Vset(pStkItm->val.n); break; // Pack a number case T_STRING : ((CVar*)iDst)->Sset(pStkItm->val.s); break; // Pack a string } // | } // << if (idSign) CData_Sstore(idSign,sBuf,nArg,0); // Write signature }
/* * Manual page at function.def */ INT16 CGEN_PUBLIC CFunction::OnGet() { // Delegate to running function // ------------------------------------ FNC_DELEGATE OnGet(); // Use a weird macro (see function.def) // Initialize // ------------------------------------ CDlpObject* iCont = GetActiveInstance(); // Determine field container const char* lpsId = GetNextToken(TRUE); // Determine field name // Validate // ------------------------------------ DLPASSERT(iCont); // Check set target if (!dlp_strlen(lpsId)) // If no field name committed return IERROR(this,FNC_EXPECT,"field identifier after -get",0,0); // Error SWord* lpWrd = iCont->FindWord(lpsId,WL_TYPE_FIELD); // Find field in container if (!lpWrd) // If not found { // >> iCont = this; // Use this instance as container lpWrd = FindWord(lpsId,WL_TYPE_FIELD); // And seek again } // << if (!lpWrd) return IERROR(this,ERR_NOTFIELD,lpsId,0,0); // If still not found --> Error // Push field value // ------------------------------------ switch (lpWrd->ex.fld.nType) // Branch for field variable type { // >> case T_BOOL : { PushLogic ( *( BOOL*)lpWrd->lpData); break; }// - Boolean case T_UCHAR : { PushNumber (CMPLX(*( UINT8*)lpWrd->lpData)); break; }// - Unsigned character case T_CHAR : { PushNumber (CMPLX(*( INT8*)lpWrd->lpData)); break; }// - Signed character case T_USHORT : { PushNumber (CMPLX(*( UINT16*)lpWrd->lpData)); break; }// - Unsigned short integer case T_SHORT : { PushNumber (CMPLX(*( INT16*)lpWrd->lpData)); break; }// - Signed short integer case T_UINT : { PushNumber (CMPLX(*( UINT32*)lpWrd->lpData)); break; }// - Unsigned integer case T_INT : { PushNumber (CMPLX(*( INT32*)lpWrd->lpData)); break; }// - Signed integer case T_ULONG : { PushNumber (CMPLX(*( UINT64*)lpWrd->lpData)); break; }// - Unsigned long integer case T_LONG : { PushNumber (CMPLX(*( INT64*)lpWrd->lpData)); break; }// - Signed long integer case T_FLOAT : { PushNumber (CMPLX(*( FLOAT32*)lpWrd->lpData)); break; }// - Single precision floating point case T_DOUBLE : { PushNumber (CMPLX(*( FLOAT64*)lpWrd->lpData)); break; }// - Double precision floating point case T_COMPLEX : { PushNumber ( *(COMPLEX64*)lpWrd->lpData); break; }// - Double precision complex floating point case T_INSTANCE: { PushInstance(*(CDlpObject**) lpWrd->lpData); break; }// - Instance case T_TEXT : /* Fall through */ // - Text (deprecated type!) case T_CSTRING : /* Fall through */ // - Constant string case T_STRING : { PushString(*(char**) lpWrd->lpData); break; }// - String default : { // - Other types if (lpWrd->ex.fld.nType > 0 && lpWrd->ex.fld.nType <= 256) // Character array? PushString((char*)lpWrd->lpData); // Push value else // Type unknown! DLPASSERT(FMSG("Unknown field type")); // Error } // << } // << return O_K; // Done. }
/** * Create an absolute or full path name for the specified relative path name. * * @param lpsAbsPath * Pointer to a buffer to be filled with the absolute path. * @param lpsRelPath * Pointer to a null-terminated string containing the relative path. * @param nMaxLen * Maximum length of the absolute path name buffer * (<code>lpsAbsPath</code>). * @return <code>lpsAbsPath</code> if successful, <code>NULL</code> in case of * errors. */ char* dlp_fullpath(char* lpsAbsPath, const char* lpsRelPath, INT32 nMaxLen) { char lpsCwd [L_PATH+1]; /* Saved current working directory */ char lpsDir [L_PATH+1]; /* Directory part of lpsRelPath */ char lpsFile[L_PATH+1]; /* Filename part of lpsRelPath */ struct stat filestat; /* File status struct */ if (!lpsAbsPath || nMaxLen<=0) return NULL; /* No buffer, no service! */ *lpsAbsPath='\0'; /* Initialize result to empty string */ dlp_splitpath(lpsRelPath,lpsDir,lpsFile); /* Split relative path */ if (!dlp_strlen(lpsDir)) dlp_strcpy(lpsDir,"."); /* No directory -> use current one */ if(getcwd(lpsCwd,L_PATH)==NULL) return NULL; /* Save current working directory */ if (dlp_chdir(lpsDir,FALSE)!=0) { dlp_chdir(lpsCwd,FALSE); return NULL; } /* Change to relative directory ... */ if(getcwd(lpsDir,L_PATH)==NULL) return NULL; /* ... and determine its full path */ dlp_chdir(lpsCwd,FALSE); /* Change back to saved working dir. */ if (nMaxLen<(INT32)(dlp_strlen(lpsDir)+dlp_strlen(lpsFile)+2)) return NULL; /* Check return buffer size */ sprintf(lpsAbsPath,"%s%c%s",lpsDir,C_DIR,lpsFile); /* Create absolute path */ #ifdef _WINDOWS /* -- WINDOZE --> */ dlp_strreplace(lpsAbsPath,"\\","/"); /* Replace backslashes by slashes */ /* dlp_strlwr(lpsAbsPath); */ /* Convert to lower case */ #endif /* <-- */ if (stat(lpsAbsPath,&filestat)!=0) return NULL; /* Check file status (must exist) */ return lpsAbsPath; /* Return pointer to buffer */ }
INT32 CDlpFile_Getlen(CDlpFile* _this) { FILE* f = NULL; INT32 nCtr = 0; char lpsBuffer[L_INPUTLINE] = ""; if (!dlp_strlen(_this->m_lpsFlist)) { IERROR(_this,FIL_NEEDFL,0,0,0); return 0; } f = fopen(_this->m_lpsFlist,"r"); if (!f) { IERROR(_this,ERR_FILEOPEN,_this->m_lpsFlist,"reading",0); return 0; } while (fgets(lpsBuffer,L_INPUTLINE,f)) if(dlp_strlen(dlp_strtrimleft(dlp_strtrimright(lpsBuffer)))) nCtr++; fclose(f); return nCtr; return 0; }
INT16 CDlpFile_OnPathChanged(CDlpObject* __this) { GET_THIS_VIRTUAL_RV(CDlpFile,NOT_EXEC); { /* Remove tailing slashes/backslashes */ char* tx = &_this->m_lpsPath[dlp_strlen(_this->m_lpsPath)-1]; while (*tx == '\\' || *tx == '/') { *tx = 0; if (tx == _this->m_lpsPath) break; tx--; } } return O_K; }
INT16 CGEN_PROTECTED CCgen::OnAutoinstance() { char lpAutoname[L_INPUTLINE+1]; GetNextDefToken(lpAutoname); if (m_bMainProject) return IERROR(this,ERR_INVALKEY,"AUTOINSTANCE:","MAIN:",0); if (m_nAncestor) return O_K; if (!dlp_strlen(lpAutoname)) return IERROR(this,ERR_EXPECTIDAFTER,"name","AUTOINSTANCE:",0); dlp_strcpy(m_lpsAutoname,lpAutoname); m_nCSXXX |= CS_AUTOINSTANCE; return O_K; }
/* * Manual page at function.def */ INT16 CGEN_PUBLIC CFunction::OnSee() { // Delegate to running function // ------------------------------------ FNC_DELEGATE OnSee(); // Use a weird macro (see function.def) // Initialize // ------------------------------------ CDlpObject* iCont = GetActiveInstance(); // Determine field container const char* lpsId = GetNextToken(TRUE); // Determine field name // Validate // ------------------------------------ DLPASSERT(iCont); // Check set target if (!dlp_strlen(lpsId)) // If no field name committed return IERROR(this,FNC_EXPECT,"field identifier or * after -see",0,0); // Error // Print // ------------------------------------ return CDlpObject_PrintField(iCont,lpsId,FALSE); // Print selected field(s) }