Exemple #1
0
void fstrncpy(char *dest, ucell src, unsigned int maxlen)
{
	int len = fstrlen(src);

	if (fstrlen(src) >= maxlen) len = maxlen - 1;
	memcpy(dest, cell2pointer(src), len);
	*(dest + len) = '\0';
} 
Exemple #2
0
void f2cstr(char *f, int max_f, char *c, int max_c)
{
    int i;

    i = min(fstrlen(f,max_f),max_c);
    strncpy(c,f,i);
    c[i]='\0';
}
Exemple #3
0
static int
compare0 (const char *s1, int s1_len, const char *s2)
{
  int len;

  /* Strip trailing blanks from the Fortran string.  */
  len = fstrlen (s1, s1_len);
  return strncasecmp (s1, s2, len) == 0;
}
Exemple #4
0
char *
fc_strdup (const char *src, gfc_charlen_type src_len)
{
  gfc_charlen_type n = fstrlen (src, src_len);
  char *p = strndup (src, n);
  if (!p)
    os_error ("Memory allocation failed in fc_strdup");
  return p;
}
Exemple #5
0
GFC_INTEGER_4
selected_char_kind (gfc_charlen_type name_len, char *name)
{
  gfc_charlen_type len = fstrlen (name, name_len);

  if ((len == 5 && strncasecmp (name, "ascii", 5) == 0)
      || (len == 7 && strncasecmp (name, "default", 7) == 0))
    return 1;
  else if (len == 9 && strncasecmp (name, "iso_10646", 9) == 0)
    return 4;
  else
    return -1;
}
Exemple #6
0
int
find_option (st_parameter_common *cmp, const char *s1, gfc_charlen_type s1_len,
	     const st_option * opts, const char *error_message)
{
  /* Strip trailing blanks from the Fortran string.  */
  size_t len = (size_t) fstrlen (s1, s1_len);

  for (; opts->name; opts++)
    if (len == strlen(opts->name) && strncasecmp (s1, opts->name, len) == 0)
      return opts->value;

  generate_error (cmp, LIBERROR_BAD_OPTION, error_message);

  return -1;
}
	fm::string FUStringConversion::ToString(const fchar* value)
	{
		FUSStringBuilder builder;
		if (value != NULL)
		{
			uint32 length = (uint32) fstrlen(value);
			builder.reserve(length + 1);
			for (uint32 i = 0; i < length; ++i)
			{
				if (value[i] < 0xFF || (value[i] & (~0xFF)) >= 32) builder.append((char)value[i]);
				else builder.append('_'); // some generic enough character
			}
		}
		return builder.ToString();
	}
void FUDebug::DebugOutV(uint8 verbosity, const fchar* message, va_list& vars)
{
	uint32 length = (uint32) fstrlen(message);
	fchar* buffer = new fchar[length + 256];
	fvsnprintf(buffer, length + 256, message, vars);
	length = (uint32) min(wcslen(buffer), (size_t) length + 253);
	buffer[length] = '\n';
	buffer[length+1] = '\r';
	buffer[length+2] = 0;

	DebugString(buffer);
	FUError::SetCustomErrorString(TO_STRING((const fchar*) buffer));
	FUError::Error((FUError::Level) verbosity, FUError::ERROR_CUSTOM_STRING, 5000);

	SAFE_DELETE_ARRAY(buffer);
}
Exemple #9
0
xt_t findword(const char *s1)
{
	ucell tmplfa, len;

	if (!last)
		return 0;

	tmplfa = read_ucell(last);

	len = strlen(s1);

	while (tmplfa) {
		ucell nfa = lfa2nfa(tmplfa);

		if (len == fstrlen(nfa) && !fstrcmp(s1, nfa)) {
			return lfa2cfa(tmplfa);
		}

		tmplfa = read_ucell(cell2pointer(tmplfa));
	}

	return 0;
}
Exemple #10
0
extern int _vsnprintf(char *pszOutput, size_t uSize, const char *pszFormat, va_list pArgs)
    {
    int *pparms;	    // Pointer to the optional arguments following the format
    char c;
    char cFill;
    char szTempBuf[80];
    char far *lpszTemp;
    char *pszOutput0 = pszOutput;
    int iRequested;	    // Requested width for an output field
    int iAvailable;	    // Number of characters available for output
    int iLong;		    // TRUE if the %l modifier has been provided

    pparms = (int *)pArgs;

    while (c = *(pszFormat++))
	{
	if (c == '%')	  // If c is the format escape character.
	    {
	    cFill = ' ';   // Default filler for the left side of output fields
	    if (*pszFormat == '0')
		{
		cFill = '0';		// Optional filler
		pszFormat += 1; 	// Skip the 0
		}

	    if (*pszFormat == '*')	// If variable length format
		{
		iRequested = *(pparms++); // Get the size from the argument list
		pszFormat += 1; 	  // Skip the *
		}
	    else			// Else fixed length format
		{
		// Convert the field size to an int, and advance past the size in format.
		pszFormat += stcd_i(pszFormat, &iRequested);
		}

	    iLong = FALSE;
test_format:
	    switch (*(pszFormat++))    // The next char is the format ID.
		{
		case 'd':
		    if (!iLong)
			iAvailable = stci_d(szTempBuf, *(pparms++)); // Convert int to string
		    else
			iAvailable = stcli_d(szTempBuf, *(((long *)pparms)++)); // Convert int to string
		    pszOutput += strcpyform(pszOutput, szTempBuf, iRequested, iAvailable, cFill);
		    break;
		case 'u':
		    iAvailable = stcu_d(szTempBuf, *(pparms++)); // Convert uint to string
		    pszOutput += strcpyform(pszOutput, szTempBuf, iRequested, iAvailable, cFill);
		    break;
		case 'p':
		    if (iLong)
			pszOutput += sprintf(pszOutput, "%04X:", pparms[1]);
		    pszOutput += sprintf(pszOutput, "%04X", pparms[0]);
		    pparms += iLong+1;
		    break;
		case 'x':   // Incompatible! Processed as %X to save space.
		case 'X':
		    if (!iLong)
			iAvailable = stci_h(szTempBuf, *(pparms++)); // Convert uint to hex. string
		    else
			iAvailable = stcli_h(szTempBuf, *(((long *)pparms)++)); // Convert uint to hex. string
		    pszOutput += strcpyform(pszOutput, szTempBuf, iRequested, iAvailable, cFill);
		    break;
		case 's':
		    if (!iLong)
			lpszTemp = *(((char **)pparms)++);		 // Pointer on the given string
		    else
			lpszTemp = *(((char far **)pparms)++);		 // Pointer on the given string
		    pszOutput += strcpyform(pszOutput, lpszTemp, iRequested, fstrlen(lpszTemp), cFill);
		    break;
		case 'c':
		    *pparms &= 0x00FF;	 // Make sure the char is followed by a NUL.
		    pszOutput += strcpyform(pszOutput, (char *)(pparms++), iRequested, 1, ' ');
		    break;
		case '%':
		    *(pszOutput++) = '%';
		    break;
		case 'l':
		case 'F':
		    iLong = TRUE;
		    goto test_format;	 // Ignore long integer specifications
		default:    // Unsupported format. Just output question marks
		    pszOutput += strcpyform(pszOutput, "", iRequested, 0, '?');
		    break;
		}
	    }
	else		  // Else c is a normal character
	    {
	    *(pszOutput++) = c;  // Just copy it to the output
	    }
	}
    *pszOutput = '\0';
    return pszOutput - pszOutput0;   // Number of characters written
    }
Exemple #11
0
VOID DosUpFString(char FAR * str)
/* upcase a string for file names */
{
  DosUpFMem(str, fstrlen(str));
}
Exemple #12
0
VOID DosUpString(char FAR * str)
/* upcase a string */
{
  DosUpMem(str, fstrlen(str));
}
Exemple #13
0
/* not necessary anymore because of truename */
COUNT ParseDosPath(BYTE * lpszFileName,
                   COUNT * pnDrive,
                   BYTE * pszDir,
                   BYTE * pszCurPath)
{
    COUNT nDirCnt,
          nPathCnt;
    BYTE *lpszLclDir,
         *pszBase = pszDir;

    /* Initialize the users data fields                             */
    *pszDir = '\0';
    lpszLclDir = 0;
    nDirCnt = nPathCnt = 0;

    /* Start by cheking for a drive specifier ...                   */
    if (DriveChar(*lpszFileName) && ':' == lpszFileName[1])
    {
        /* found a drive, fetch it and bump pointer past drive  */
        /* NB: this code assumes ASCII                          */
        if (pnDrive)
        {
            *pnDrive = *lpszFileName - 'A';
            if (*pnDrive > 26)
                *pnDrive -= ('a' - 'A');
        }
        lpszFileName += 2;
    }
    else
    {
        if (pnDrive)
        {
            *pnDrive = -1;
        }
    }

    lpszLclDir = lpszFileName;
    if (!PathSep(*lpszLclDir))
    {
        fstrncpy(pszDir, pszCurPath, PARSE_MAX - 1);        /*TE*/
        nPathCnt = fstrlen(pszCurPath);
        if (!PathSep(pszDir[nPathCnt - 1]) && nPathCnt < PARSE_MAX - 1) /*TE*/
            pszDir[nPathCnt++] = '\\';
        if (nPathCnt > PARSE_MAX)
            nPathCnt = PARSE_MAX;
        pszDir += nPathCnt;
    }

    /* Now see how long a directory component we have.              */
    while (NameChar(*lpszFileName)
            || PathSep(*lpszFileName)
            || '.' == *lpszFileName)
    {
        ++nDirCnt;
        ++lpszFileName;
    }

    /* Fix lengths to maximums allowed by MS-DOS.                   */
    if ((nDirCnt + nPathCnt) > PARSE_MAX - 1)     /*TE*/
        nDirCnt = PARSE_MAX - 1 - nPathCnt;

    /* Finally copy whatever the user wants extracted to the user's */
    /* buffers.                                                     */
    if (pszDir)
    {
        bcopy(lpszLclDir, pszDir, nDirCnt);
        pszDir[nDirCnt] = '\0';
    }

    /* Clean up before leaving                              */
    DosTrimPath(pszBase);

    /* Before returning to the user, eliminate any useless          */
    /* trailing "\\." since the path prior to this is sufficient.   */
    nPathCnt = strlen(pszBase);
    if (2 == nPathCnt)            /* Special case, root           */
    {
        if (!strcmp(pszBase, "\\."))
            pszBase[1] = '\0';
    }
    else if (2 < nPathCnt)
    {
        if (!strcmp(&pszBase[nPathCnt - 2], "\\."))
            pszBase[nPathCnt - 2] = '\0';
    }

    return SUCCESS;
}
Exemple #14
0
/*
ULONG FAR retcs(int i)
{
    char *p = (char*)&i;
    
    p -= 4;
    return *(ULONG *)p;
}
*/
COUNT do_printf(CONST BYTE * fmt, BYTE ** arg)
{
  int base;
  BYTE s[11], FAR * p;
  int c, flag, size, fill;
  int longarg;
  long currentArg;

/*  
  long cs = retcs(1);
  put_console("0123456789ABCDEF"[(cs >> 28) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >> 24) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >> 20) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >> 16) & 0x0f]);
  put_console(':');
  put_console("0123456789ABCDEF"[(cs >> 12) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >>  8) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >>  4) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >>  0) & 0x0f]);
*/
  while ((c = *fmt++) != '\0')
  {
    if (c != '%')
    {
      handle_char(c);
      continue;
    }

    longarg = FALSE;
    size = 0;
    flag = RIGHT;
    fill = ' ';

    if (*fmt == '-')
    {
      flag = LEFT;
      fmt++;
    }

    if (*fmt == '0')
    {
      fill = '0';
      fmt++;
    }

    while (*fmt >= '0' && *fmt <= '9')
    {
      size = size * 10 + (*fmt++ - '0');
    }

    if (*fmt == 'l')
    {
      longarg = TRUE;
      fmt++;
    }

    c = *fmt++;
    switch (c)
    {
      case '\0':
        return 0;

      case 'c':
        handle_char(*(COUNT *) arg++);
        continue;

      case 'p':
        {
          UWORD w[2];
          w[1] = *((UWORD *) arg);
          arg += sizeof(UWORD) / sizeof(BYTE *);
          w[0] = *((UWORD *) arg);
          arg += sizeof(UWORD) / sizeof(BYTE *);
          do_printf("%04x:%04x", (BYTE **) & w);
          continue;
        }

      case 's':
        p = *arg++;
        goto do_outputstring;

      case 'F':
        fmt++;
        /* we assume %Fs here */
      case 'S':
        p = *((BYTE FAR **) arg);
        arg += sizeof(BYTE FAR *) / sizeof(BYTE *);
        goto do_outputstring;

      case 'i':
      case 'd':
        base = -10;
        goto lprt;

      case 'o':
        base = 8;
        goto lprt;

      case 'u':
        base = 10;
        goto lprt;

      case 'X':
      case 'x':
        base = 16;

      lprt:
        if (longarg)
        {
          currentArg = *((LONG *) arg);
          arg += sizeof(LONG) / sizeof(BYTE *);
        }
        else
        {
          if (base < 0)
          {
            currentArg = *((int *)arg);
            arg += sizeof(int) / sizeof(BYTE *);
          }
          else
          {
            currentArg = *((unsigned int *)arg);
            arg += sizeof(unsigned int) / sizeof(BYTE *);
          }
        }

        ltob(currentArg, s, base);

        p = s;
      do_outputstring:

        size -= fstrlen(p);

        if (flag == RIGHT)
        {
          for (; size > 0; size--)
            handle_char(fill);
        }
        for (; *p != '\0'; p++)
          handle_char(*p);

        for (; size > 0; size--)
          handle_char(fill);

        continue;

      default:
        handle_char('?');

        handle_char(c);
        break;

    }
  }
  return 0;
}
void FUPluginManager::LoadPluginsInFolderName(const fstring& folderName, const fchar* _filter)
{
	// Append the wanted extension for the plugins.
	FUStringBuilder pluginFolder(folderName);
	fchar lastChar = folderName[pluginFolder.length() - 1];
	if (lastChar != '\\' && lastChar != '/') pluginFolder.append((fchar) '/');
	pluginFolder.append(FC("Plugins/"));
	pluginFolderName = pluginFolder.ToString();

	if (_filter == NULL || _filter[0] == 0) _filter = FC("*.*");
	do
	{
		const fchar* nextFilter = fstrchr(_filter, '|');
		fstring filter(_filter);
		if (nextFilter != NULL)
		{
			filter.erase(nextFilter - _filter);
			++nextFilter; // skip the pipe.
		}
		_filter = nextFilter;

		// Windows-only for now.
#if defined(WIN32)
		size_t filterLength = filter.length();
		// Iterate over all the filtered files within the given folder.
		ffinddata folderIterator;
		fstring searchString = pluginFolderName + filter;
		intptr_t folderHandle = ffindfirst(searchString.c_str(), &folderIterator);
		if (folderHandle != -1L)
		{
			int32 isDone = FALSE;
			while (isDone == FALSE)
			{
				bool keep = false;
				PluginLibrary* library = new PluginLibrary();
				library->filename = pluginFolderName + folderIterator.name;

				// work around for wildcards and 3 letter extensions that pick up 3+ letter extensions
				// e.g. "dir *.fvp" in command prompt on a directory with "a.fvp", "a.fvpa", and "a.dll" returns 
				// "a.fvp" and "a.fvpa"
				bool checkModule = true;
				if (filterLength > 3)
				{
					if ((filter.at(filterLength-4) == FC('.')) && (filter.at(filterLength-3) != FC('*')) &&
							(filter.at(filterLength-2) != FC('*')) && (filter.at(filterLength-1) != FC('*')))
					{
						size_t filepathLength = fstrlen(folderIterator.name);
						checkModule = (folderIterator.name[filepathLength-4] == filter.at(filterLength-4)) &&
								(folderIterator.name[filepathLength-3] == filter.at(filterLength-3)) &&
								(folderIterator.name[filepathLength-2] == filter.at(filterLength-2)) &&
								(folderIterator.name[filepathLength-1] == filter.at(filterLength-1));
					}
				}

				library->module = LoadLibrary(library->filename.c_str());
				if (checkModule && (library->module != NULL))
				{
					// Retrieve the necessary callbacks
					library->getPluginCount = (GetPluginCount) GetProcAddress(library->module, "GetPluginCount");
					library->getPluginType = (GetPluginType) GetProcAddress(library->module, "GetPluginType");
					library->createPlugin = (CreatePlugin) GetProcAddress(library->module, "CreatePlugin");
					keep = library->createPlugin != NULL && library->getPluginType != NULL && library->getPluginCount != NULL;
				}

				// This is a valid library.
				if (keep) loadedLibraries.push_back(library);
				else { SAFE_DELETE(library); }
				isDone = ffindnext(folderHandle, &folderIterator);
			}
			ffindclose(folderHandle);
		}

#elif defined(__APPLE__) || defined(LINUX)
		fm::string s_filter = TO_STRING(filter);
		if (s_filter.length() > 0 && s_filter.front() == '*') s_filter.erase(0, 1);
		if (s_filter.length() > 0 && s_filter.back() == '*') s_filter.pop_back();

		DIR* directory = opendir(TO_STRING(pluginFolderName).c_str());
		if (directory == NULL) continue;

		dirent* directoryEntry;
		while ((directoryEntry = readdir(directory)) != NULL)
		{
			if (directoryEntry->d_type == DT_DIR) continue; // skip sub-folders.
			if (strstr((const char*) directoryEntry->d_name, s_filter.c_str()) != NULL)
			{
				// We have a match.
				bool keep = false;
				PluginLibrary* library = new PluginLibrary();
				library->filename = pluginFolderName + TO_FSTRING((const char*) directoryEntry->d_name);
				fm::string libraryModuleFilename = TO_STRING(library->filename);
				DEBUG_OUT("Found dynamic library: %s\n", libraryModuleFilename.c_str());
				library->module = dlopen(libraryModuleFilename.c_str(), RTLD_NOW);
				if (library->module != NULL)
				{
					// Retrieve the necessary callbacks
					library->getPluginCount = (GetPluginCount) dlsym(library->module, "GetPluginCount");
					library->getPluginType = (GetPluginType) dlsym(library->module, "GetPluginType");
					library->createPlugin = (CreatePlugin) dlsym(library->module, "CreatePlugin");
					keep = library->createPlugin != NULL && library->getPluginType != NULL && library->getPluginCount != NULL;
				}

				// This is a valid library.
				if (keep) loadedLibraries.push_back(library);
				else { SAFE_DELETE(library); }
			}
		}
		closedir(directory);

#endif // WIN32
	} while (_filter != NULL);
}