コード例 #1
0
ファイル: loadList.cpp プロジェクト: RainVector/VegaFEM
int LoadList::load(const char * filename, int * numListEntries, int ** listEntries, int offset)
{
   // comma-separated text file of fixed vertices
  FILE * fin;
  fin = fopen(filename,"r");
  if (!fin)
  {
    printf("Error: could not open file %s.\n",filename);
    return 1;
  }

  *numListEntries = 0;

  char s[4096];
  while (fgets(s,4096,fin) != NULL)
  { 
    stripBlanks(s);

    char * pch;
    pch = strtok (s,",");
    while ((pch != NULL) && (isdigit(*pch)))
    {
      (*numListEntries)++;
      pch = strtok (NULL, ",");
    } 
  }

  *listEntries = (int*) malloc (sizeof(int) * (*numListEntries));

  rewind(fin);

  (*numListEntries) = 0;

  while (fgets(s,4096,fin) != NULL)
  {
    stripBlanks(s);
    char * pch;
    pch = strtok (s,",");
    while ((pch != NULL) && (isdigit(*pch)))
    {
      (*listEntries)[*numListEntries] = atoi(pch) - offset;
      (*numListEntries)++;
      pch = strtok (NULL, ",");
    }
  }

  // sort the list entries
  qsort ((*listEntries), *numListEntries, sizeof(int), compareLoadList);

  fclose(fin);

  return 0;
}
コード例 #2
0
ファイル: xparam.cpp プロジェクト: pdnsoft/PParam
XParam& XSingleParam::operator =(const XmlNode* node) throw (Exception)
{
	XParam* vparam = this;
	if (!is_myNode(node))
		return (*this);

	XmlNode::NodeList nlist = node->get_children();
	for (XmlNode::NodeList::iterator iter = nlist.begin();
			iter != nlist.end(); ++iter) {
		/* If node is comment, ignore it */
		const xmlpp::CommentNode* nComment =
			dynamic_cast<const xmlpp::CommentNode*>(*iter);
		if (nComment)
			continue;

		/* Read text or CData nodes */
		const xmlpp::ContentNode* nContent =
			dynamic_cast<const xmlpp::ContentNode*>(*iter);
		if (nContent)
			(*vparam) = stripBlanks(nContent->get_content());
	}

	return (*this);
}
コード例 #3
0
/*------------------------------------------------------------------
 * socket()
 *------------------------------------------------------------------*/
RexxRoutine3(int, SockSocket, CSTRING, domainArg, CSTRING, typeArg, CSTRING, protocolArg)
{
    int domain;
    int type;
    int protocol;
    char *pszDomain;
    char *pszType;
    char *pszProtocol;

    /*---------------------------------------------------------------
     * get parms
     *---------------------------------------------------------------*/
    pszDomain   = strdup(domainArg);
    pszType     = strdup(typeArg);
    pszProtocol = strdup(protocolArg);

    stripBlanks(pszDomain);
    stripBlanks(pszType);
    stripBlanks(pszProtocol);

    if (!caselessCompare(pszDomain,"AF_INET"))
    {
        domain = AF_INET;
    }
    else
    {
        context->InvalidRoutine();
        return 0;
    }

    if (!caselessCompare(pszType,"SOCK_STREAM")) type = SOCK_STREAM;
    else if (!caselessCompare(pszType,"SOCK_DGRAM" )) type = SOCK_DGRAM;
    else if (!caselessCompare(pszType,"SOCK_RAW"   )) type = SOCK_RAW;
    else
    {
        context->InvalidRoutine();
        return 0;
    }

    if (!caselessCompare(pszProtocol,"IPPROTO_UDP"))
        protocol = IPPROTO_UDP;
    else if (!caselessCompare(pszProtocol,"IPPROTO_TCP"))
        protocol = IPPROTO_TCP;
    else if (!caselessCompare(pszProtocol,"0"          ))
        protocol = 0;
    else
    {
        context->InvalidRoutine();
        return 0;
    }

    /*---------------------------------------------------------------
     * call function
     *---------------------------------------------------------------*/
    int rc = socket(domain,type,protocol);
    // set the errno information
    cleanup(context);

    /*---------------------------------------------------------------
     * set return code
     *---------------------------------------------------------------*/
    return rc;
}