Esempio n. 1
0
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;
}
Esempio n. 2
0
/**
 * Create a name for a temporary file. The function calls <code>mkstemp</code>.
 * mktemp is used if no mkstemp is available (see platform dependent define
 * <code>HAVE_NO_MKSTEMP</code> in dlp_base.h).
 * The filename is returned in an internal static buffer. Thus any subsequent
 * calls destroy the value.<code>free</code> does not need to be called to
 * deallocate this pointer.
 *
 * @param lpsDir
 *          Target directory to be used. If lpsDir is NULL, the function tries
 *       to determine the temporary directory by evaluation of the environment
 *       variables TEMP and TMP in this order. If none of these is set then
 *       the current directory is used.
 * @param lpsPfx
 *          Filename prefix
 * @return A pointer to the generated name or <code>NULL</code> if no temporary
 *         name could be created.
 */
char* dlp_tempnam(const char* lpsDir, const char* lpsPfx)
{
  static const char *lpsTempDir = NULL;
  char         lpsBuf[L_PATH];
  static char  lpsTemname[L_PATH];

  sprintf(lpsBuf, "%sXXXXXX",lpsPfx);
  if(lpsDir==NULL)
  {
    if(!lpsTempDir) lpsTempDir = getenv("TEMP");
    if(!lpsTempDir) lpsTempDir = getenv("TMP");
#ifdef __LINUX
#ifndef __TMS
    if(!lpsTempDir)
    {
      if(getcwd(lpsTemname,L_PATH) == NULL) return NULL;
      if(chdir("/var/tmp")==0) lpsTempDir = "/var/tmp";
      else if(chdir("/tmp")==0) lpsTempDir = "/tmp";
      if(chdir(lpsTemname)!=0) return NULL;
    }
#endif
#endif
    if(!lpsTempDir) lpsTempDir = ".";
    sprintf(lpsTemname,"%s%c%s",lpsTempDir,C_DIR,lpsBuf);
  }
  else sprintf(lpsTemname,"%s%c%s",lpsDir,C_DIR,lpsBuf);

#ifndef __TMS
#ifdef HAVE_NO_MKSTEMP
  dlp_strncpy(lpsTemname,_mktemp(lpsTemname),L_PATH-1);
#else
  close(mkstemp(lpsTemname));  /* mkstemp opens the file and returns the file descriptor. */
                                             /* Lets close it immediately, since we just need the name. */
#endif
#endif
  return lpsTemname;
}
Esempio n. 3
0
INT16 CGEN_PROTECTED CCgen::OnParent()
{
  const char* lpParent = GetRestOfDefLine();

  if (m_bMainProject)
    return IERROR(this,ERR_INVALKEY,"PARENT:","MAIN:",0);
  if (m_nAncestor) return O_K;

  if (!dlp_strlen(lpParent))
    return IERROR(this,ERR_EXPECTAFTER,"name list","PARENT:",0);

  char* tx = (char*)strstr(lpParent,"C(");
  if (tx)
  {
    tx+=2;
    char* ty = strstr(tx,")");
    if (ty) *ty = 0;
    char lpBuf[100]; dlp_strncpy(lpBuf,tx,100);
    do dlp_strtrimleft(lpBuf); while (lpBuf[0] == ',');
    sprintf(m_lpsCxxMoreParents,", %s",lpBuf);
  }

  return O_K;
}
Esempio n. 4
0
/**
 * Retrieves source file name and line of last interpreter error.
 *
 * @param lpInFile
 *          Pointer to buffer to be filled with the file name. The buffer is
 *          expected to be at least <code>_L_PATH</code> bytes large.
 * @param lpInLine
 *          Pointer to a long to be filled with the line number.
 */
void CDlpObject_GetErrorPos(char* lpInFile, INT32* lpInLine)
{
  dlp_strncpy(lpInFile,__lpInFile,L_PATH);
  if (lpInLine) *lpInLine = __nInLine;
}
Esempio n. 5
0
/**
 * Stores source file name and line of last interpreter error.
 *
 * @param lpInFile Pointer to buffer containing the file name
 * @param nInLine  The line number
 */
void CDlpObject_SetErrorPos(const char* lpInFile, INT32 nInLine)
{
  dlp_strncpy(__lpInFile,lpInFile,L_PATH);
  __nInLine = nInLine;
}
Esempio n. 6
0
/**
 * Retrieves the current error tracing identifier.
 *
 * @param lpsBuffer  A pointer to the character buffer to fill
 * @param nBufferLen The size of the committed buffer (in bytes)
 * @see CDlpObject_SetTraceError
 */
void CDlpObject_GetTraceError(char* lpsBuffer, INT16 nBufferLen)
{
  dlp_strncpy(lpsBuffer,__lpsTraceError,nBufferLen);
}
Esempio n. 7
0
/**
 * Sets the error identifier for the error tracing mechanism. If the
 * spefied error occurs during a dLabPro session, the error management
 * system will interrupt the session through a debug assertion. This
 * feature is not available in release mode.
 *
 * @param lpsTraceError Identifier of error to be traced
 * @see CDlpObject_GetTraceError
 */
void CDlpObject_SetTraceError(const char* lpsTraceError)
{
  dlp_strncpy(__lpsTraceError,lpsTraceError,255);
}
Esempio n. 8
0
/**
 * Import and export of non-native file formats.
 *
 * @param _this       This instance.
 * @param sFilename   Name of file to import.
 * @param sFilter     Filter to use for import.
 * @param iInst       Instance where to save imported data.
 * @param nMode       Import or export mode.
 * @return <code>O_K</code> if successful, a (negative) error code otherwise
 */
INT16 CGEN_PROTECTED CDlpFile_ImportExport
(
  CDlpFile*   _this,
  const char* sFilename,
  const char* sFilter,
  CDlpObject* iInst,
  INT16 nMode
)
{
  INT16    retVal     = O_K;
  lnode_t* lpNode     = NULL;
  CFILE_FTYPE* lpType = NULL;
  FILE* lpFile        = NULL;
  char lpsFilenameLoc[L_PATH];
  char lpsCmd[L_PATH*2];

  CHECK_THIS_RV(FALSE);

  if(!dlp_strlen(sFilename)) return IERROR(_this,FIL_FILENAME,0     ,0,0);
  if(!iInst                ) return IERROR(_this,ERR_NULLARG,"iInst",0,0);

  dlp_strcpy(lpsFilenameLoc,sFilename);

  /* create target directory if necessary */
  if(nMode==EXPORT_FILE)
  {
    char lpNewDir[L_PATH] = "";
    char lpCurDir[L_PATH] = "";

#ifndef __TMS
    if(!_this->m_bExecute)
    {
      if(getcwd(lpCurDir,L_PATH) == NULL) return IERROR(_this,ERR_GETCWD,0,0,0);
      dlp_splitpath(lpsFilenameLoc,lpNewDir,NULL);
      if(0<dlp_strlen(lpNewDir))
      {
        if(dlp_chdir(lpNewDir,TRUE))
        {
          dlp_chdir(lpCurDir,FALSE);
          return
          IERROR(_this,ERR_FILEOPEN,lpsFilenameLoc,
              "writing (failed to create directory)",0);
        }
        dlp_chdir(lpCurDir,FALSE);
      }
    }
#endif
  }

#ifndef __TMS
  /* Execute lpsFilenameLoc (initialization & execute if import) */
  if(_this->m_bExecute)
  {
    char lpsBase[L_PATH];
    char *lpsTmp;
    dlp_splitpath(lpsFilenameLoc,NULL,lpsBase);
    if(strchr(lpsBase,' ')) *strchr(lpsBase,' ')='\0';
    lpsTmp=dlp_tempnam(NULL,lpsBase);
    snprintf(lpsCmd, L_PATH*2-1, "%s %c %s", lpsFilenameLoc, nMode==EXPORT_FILE?'<':'>', lpsTmp);
    dlp_strcpy(lpsFilenameLoc,lpsTmp);
    if(nMode==IMPORT_FILE) if(dlp_system(lpsCmd)!=0) return IERROR(_this,ERR_FILEOPEN,lpsCmd,"executing",0);
  }
#endif

  /* test if file is readable/writable */
  if(nMode==IMPORT_FILE)
    lpFile = fopen(lpsFilenameLoc,"r");
  else if(nMode==EXPORT_FILE)
    lpFile = fopen(lpsFilenameLoc,"a");
  else DLPASSERT(FMSG("Unknown operation mode."));

  if(!lpFile)
  {
    if (nMode==IMPORT_FILE)
      return IERROR(_this,ERR_FILEOPEN,sFilename,"reading",0);
    else if (nMode==EXPORT_FILE)
      return IERROR(_this,ERR_FILEOPEN,sFilename,"writing",0);
  }
  fclose(lpFile);

  /* lookup filter function from list */
  lpType = (CFILE_FTYPE*)dlp_calloc(1,sizeof(CFILE_FTYPE));
  if(!lpType) return IERROR(_this,ERR_NOMEM,0,0,0);

  dlp_strncpy(lpType->lpName,sFilter,L_NAMES);
  dlp_strncpy(lpType->lpClassName,iInst->m_lpClassName,L_NAMES);
  lpType->nMode = nMode;

  lpNode = list_find(_this->m_lpFtypes,lpType,CDlpFile_CompareFTypeList);
  if(!lpNode)
  {
    dlp_free(lpType);
    return
      IERROR(_this,FIL_NOIMEX,nMode==IMPORT_FILE?"import":"export",sFilter,
        iInst->m_lpClassName);
  }
  dlp_free(lpType);
  lpType = NULL;

  /* Invoke import function */
  lpType = (CFILE_FTYPE*)lnode_get(lpNode);
  retVal = lpType->FilterFunc(_this,lpsFilenameLoc,iInst,lpType->lpName);

#ifndef __TMS
  /* Execute lpsFilenameLoc (execute if export & finalization) */
  if(_this->m_bExecute)
  {
    if(nMode==EXPORT_FILE) dlp_system(lpsCmd);
    unlink(lpsFilenameLoc);
  }else
#endif
  if(nMode==EXPORT_FILE && _this->m_bZip) dlp_fzip(lpsFilenameLoc,"wb6");

  if(retVal != O_K)
  {
    if(nMode==IMPORT_FILE) return IERROR(_this,FIL_IMPORT,lpsFilenameLoc,sFilter,0);
    else                   return IERROR(_this,FIL_EXPORT,lpsFilenameLoc,sFilter,0);
  }

  return O_K;
}
Esempio n. 9
0
INT16 CGEN_PROTECTED CCgen::OnProject()
{
  char lpProjectname[L_INPUTLINE+1];
  GetNextDefToken(lpProjectname);

  if (!dlp_strlen(lpProjectname))
	return IERROR(this,ERR_EXPECTAFTER,"name","PROJECT:",0);
    
  // Add current def script to list of processed files
  char lpBuf[L_INPUTLINE+1];
  dlp_strcpy(lpBuf,GetCurrentDefFile());
  dlp_splitpath(lpBuf,NULL,lpBuf);
  m_defList.AddItem(lpBuf);

  if (m_bAppend)
  {
    if (dlp_strncmp(m_lpsProject,lpProjectname,dlp_strlen(lpProjectname)) != 0) 
    {
      IERROR(this,ERR_APPEND,"PROJECT:",lpProjectname,0);
      if (!dlp_strlen(m_lpsProject)) EXIT(ERR_EXPPROJECT,"/append PROJECT:",0,0);
      return NOT_EXEC;
    }
    SetCreating(CR_PROJECT,NULL);
    m_bMainProject = FALSE;
  }
  
  if (m_nAncestor >  1) return O_K;
  if (m_nAncestor == 1)
  {
    // Include base class' header file
    char lpBuf[255];
    dlp_convert_name(CN_HFILE,lpBuf,lpProjectname);
    dlp_convert_name(CN_QUOTE,lpBuf,lpBuf);
    m_includes.AddItem(lpBuf);

    dlp_convert_name(CN_DLP2CXX_CLSN,m_lpsCxxParent,lpProjectname);             // Store C++ base class name
    dlp_strcpy(m_lpsParentProject,lpProjectname);                               // Store parent project name
    return O_K;
  }

  // Set project code
  SetCreating(CR_PROJECT,NULL);
  m_bMainProject = FALSE;
  dlp_strcpy(m_lpsProject,lpProjectname);  

  // Get package name
  // TODO: Make a more educated guess
  if (!m_bAppend && dlp_strlen(GetCurrentDefFile())>0)
  {
    dlp_strcpy(lpBuf,GetCurrentDefFile());
    char* tx;
    int   n;
    for (n=0,tx=&lpBuf[dlp_strlen(lpBuf)-1]; tx>=lpBuf; tx--)
    {
      if (*tx=='\\') *tx='/';
      if (*tx=='/')
      {
        n++;
        if (n==2) *tx='\0';
        if (n==4) { tx++; break; }
      }
    }
    dlp_strcpy(m_lpsPackage,tx);
    if (dlp_strnicmp(m_lpsPackage,"dlabpro/",8)==0)                             // Normalize heading "dlabpro"
      dlp_strncpy(m_lpsPackage,"dLabPro",7);                                    // ...
  }

  return O_K;
}