• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ readLine函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中readLine函数的典型用法代码示例。如果您正苦于以下问题:C++ readLine函数的具体用法?C++ readLine怎么用?C++ readLine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了readLine函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int main(char *argc, char *argv[])
{
    char l[1025], c = 0;
    int fd = 0, left = 0, n = 0, eof = 0;
    struct stat fs;
    write(2, "*****************\n\r", 19);
    write(2, "*** grep time ***\r\n", 19);
    write(2, "*****************\n\r", 19);

    reset(l, 1025);
    //getc();
    if(argc == 2)
    {
        fstat(0, &fs);
        if((fs.st_mode & 0010000)) //FIFO (it's a pipe!)
        {
            while(n = readLine(l, 256, 0, &eof))
            {

                if(l[0] == '~') {exit(0);}
                if(grep(l, argv[1]))
                {
                    write(1, l, n);
                    putc('\r');
                }
                reset(l, 1025);
                if(eof) {putc(0); break;}
            }
        }
        else
        {
            while(gets(l))
            {
                if(l[0] == '~') {exit(0);}
                if(grep(l, argv[1]))
                {
                    printf("%s\n", l);
                }
                reset(l, 256);
            }
        }
    }
    else 
    { 
        fd = open(argv[2], O_RDONLY); 
        if(fd < 0) { return -1; }
        fstat(fd, &fs);
        left = fs.st_size;
        while(left > 0)
        {
            if(left >= 1024)
            {
                n = readLine(l, 1024, fd, &eof);
            }
            else
            {
                    n = readLine(l, left, fd, &eof);
            }
            l[n+1] = 0;
            if(grep(l, argv[1]))
            {
                write(1, l, n);
                putc('\r');
            }
            reset(l, 1025);
            left -= n;
        }
        putc(0);
        close(fd);
    }
    //printf("\n");
    exit(1);
}
开发者ID:konorati,项目名称:cs460,代码行数:73,代码来源:grep.c


示例2: main

// usage: smp <IP address to connect to>
int main( int argc, char** argv )
{
    if ( argc != 2 ) /* argc should be 2 for correct execution */
    {
        printf( "usage:\n\tsmp <ipaddress>\n\tsmp server\n" );
        return EXIT_FAILURE;
    }
    
    int bServerMode = strstr( "server", argv[ 1 ] ) != 0;

    setup();
    
    unsigned char holder[ BUFFER_SIZE ];
    memset( holder, 0x00, BUFFER_SIZE );
    
    if ( !bServerMode )
    {
        // we are talking to the server at ip address argv[ 1 ]
        char input_string[ 256 ];
        printf( "Enter a shared secret: " );
        readLine( input_string, 256 );
        // TESTCODE: strcpy( input_string, "testme" );
        secret = binEncode( input_string, strlen( input_string ) );
        
        /*****************************************************/
        /*****************************************************/
        /*  Do Step 1 and send to other side */
        /*****************************************************/
        /*****************************************************/
        int len = step1( holder, BUFFER_SIZE );
        
        int serverfd = connect_to_server( argv[ 1 ] );
        if ( serverfd == 1 )
            return EXIT_FAILURE;
        
        write_to_server( serverfd, holder, len );
        // dumpBuff( holder, len );
        
        /*****************************************************/
        /*****************************************************/
        /*  Get results from other side. */
        /*  Other side performed Step 2. */
        /*****************************************************/
        /*****************************************************/
        memset( holder, 0x00, BUFFER_SIZE );
        len = revc_from_server( serverfd, holder, BUFFER_SIZE );
        // dumpBuff( holder, len );
        
        /*****************************************************/
        /*****************************************************/
        /*  Do Step 3 and send to the other side */
        /*****************************************************/
        /*****************************************************/
        step3( holder, BUFFER_SIZE );
        write_to_server( serverfd, holder, len );
        
        /*****************************************************/
        /*****************************************************/
        /*  Get bytes from other side and do Step 5 */
        /*****************************************************/
        /*****************************************************/
        memset( holder, 0x00, BUFFER_SIZE );
        len = revc_from_server( serverfd, holder, BUFFER_SIZE );
        // dumpBuff( holder, len );
        
        step5( holder, len );
        
        disconnect_from_server( serverfd );
    }
    else    // we are in server mode, other side will send us data first
    {
        int listenfd = listen_server();
        /*if ( listenfd == 1 )
            return EXIT_FAILURE;
        TODO: error checking
        */
        
        char input_string[ 256 ];
        printf( "Enter a shared secret: " );
        readLine( input_string, 256 );
        // TESTCODE: strcpy( input_string, "testme" );
        secret = binEncode( input_string, strlen( input_string ) );
        
        int len = revc_from_server( listenfd, holder, BUFFER_SIZE );
        // dumpBuff( holder, BUFFER_SIZE);
        
        /*****************************************************/
        /*****************************************************/
        /*  Do Step 2 and send to other side */
        /*****************************************************/
        /*****************************************************/
        len = step2( holder, BUFFER_SIZE  );
        write_to_server( listenfd, holder, len );

        len = revc_from_server( listenfd, holder, BUFFER_SIZE );
        // dumpBuff( holder, len );
        
        /*****************************************************/
        /*****************************************************/
//.........这里部分代码省略.........
开发者ID:jchrisweaver,项目名称:smp,代码行数:101,代码来源:smp.c


示例3: while

void rlSpawn::printAll()
{
  const char *cptr;
  while((cptr=readLine()) != NULL) ::printf("%s",cptr);
}
开发者ID:AugustXiao,项目名称:pvb,代码行数:5,代码来源:rlspawn.cpp


示例4: processMultiBulkItem

static int processMultiBulkItem(redisReader *r) {
    redisReadTask *cur = &(r->rstack[r->ridx]);
    void *obj;
    char *p;
    long elements;
    int root = 0;

    /* Set error for nested multi bulks with depth > 1 */
    if (r->ridx == 2) {
        __redisReaderSetError(r,REDIS_ERR_PROTOCOL,
            "No support for nested multi bulk replies with depth > 1");
        return REDIS_ERR;
    }

    if ((p = readLine(r,NULL)) != NULL) {
        elements = readLongLong(p);
        root = (r->ridx == 0);

        if (elements == -1) {
            if (r->fn && r->fn->createNil)
                obj = r->fn->createNil(cur);
            else
                obj = (void*)REDIS_REPLY_NIL;

            if (obj == NULL) {
                __redisReaderSetErrorOOM(r);
                return REDIS_ERR;
            }

            moveToNextTask(r);
        } else {
            if (r->fn && r->fn->createArray)
                obj = r->fn->createArray(cur,elements);
            else
                obj = (void*)REDIS_REPLY_ARRAY;

            if (obj == NULL) {
                __redisReaderSetErrorOOM(r);
                return REDIS_ERR;
            }

            /* Modify task stack when there are more than 0 elements. */
            if (elements > 0) {
                cur->elements = elements;
                cur->obj = obj;
                r->ridx++;
                r->rstack[r->ridx].type = -1;
                r->rstack[r->ridx].elements = -1;
                r->rstack[r->ridx].idx = 0;
                r->rstack[r->ridx].obj = NULL;
                r->rstack[r->ridx].parent = cur;
                r->rstack[r->ridx].privdata = r->privdata;
            } else {
                moveToNextTask(r);
            }
        }

        /* Set reply if this is the root object. */
        if (root) r->reply = obj;
        return REDIS_OK;
    }

    return REDIS_ERR;
}
开发者ID:mhowlett,项目名称:hiredis,代码行数:64,代码来源:hiredis.c


示例5: computeVariedScaleFactors

void computeVariedScaleFactors(const string& dataEfficienciesFileName, 
			       const string& MCEfficienciesFileName, const string& outputFile, 
			       const unsigned int numSigPars, const float nominalScaleFactor)
{
  //open data and MC efficiency text files
  ifstream dataEfficienciesFile(dataEfficienciesFileName.c_str());
  ifstream MCEfficienciesFile(MCEfficienciesFileName.c_str());
  if (!dataEfficienciesFile.is_open() || !MCEfficienciesFile.is_open()) {
    cerr << "Error opening file " << dataEfficienciesFileName << " and/or ";
    cerr << MCEfficienciesFileName << ".\n";
    return;
  }

  //quantities to be calculated and printed
  vector<float> scaleFactor;
  vector<float> error;
  vector<float> deviationFromNominal;

  //quantities to be read and re-printed
  vector<float> alphaPass;
  vector<float> nPass;
  vector<float> alphaFail;
  vector<float> nFail;
  vector<string> bkgShape;
  vector<float> dataEfficiency;
  vector<float> dataEfficiencyErrorHigh;
  vector<float> dataEfficiencyErrorLow;
  vector<float> dataEfficiencyError;
  vector<float> MCEfficiency;
  vector<float> MCEfficiencyErrorHigh;
  vector<float> MCEfficiencyErrorLow;
  vector<float> MCEfficiencyError;

  //read each file
  unsigned int lineNum = 0;
  unsigned int dataFail = 0;
  unsigned int MCFail = 0;
  while (!dataEfficienciesFile.eof() && !MCEfficienciesFile.eof()) {

    //check each line of the file to see if it is a comment
    string dataLine, MCLine;
    getline(dataEfficienciesFile, dataLine);
    getline(MCEfficienciesFile, MCLine);
    ++lineNum;
    if ((dataLine.find('#') == string::npos) && (dataLine.length() != 0) && 
	(MCLine.find('#') == string::npos) && (MCLine.length() != 0)) {

      /*grab all words  and check that signal and background shape parameters are equal for data 
	and MC*/
      vector<float> dataFloatPars, MCFloatPars;
      string dataBkgPar, MCBkgPar;
      readLine(dataFloatPars, dataBkgPar, dataLine);
      readLine(MCFloatPars, MCBkgPar, MCLine);
      if ((dataFloatPars.size() == MCFloatPars.size()) && (dataBkgPar == MCBkgPar)) {
	bool equal = true;
	unsigned int iFloatPar = 0;
	while ((iFloatPar < numSigPars) && equal) {
	  equal = equal && (dataFloatPars[iFloatPar] == MCFloatPars[iFloatPar]);
	  ++iFloatPar;
	}
	if (equal) {

	  /*if the error isn't -1, compute the scale factor, error, and deviation of scale factor 
	    from nominal*/
	  if (dataFloatPars[dataFloatPars.size() - 1] != -1.0) ++dataFail;
	  if (MCFloatPars[MCFloatPars.size() - 1] != -1.0) ++MCFail;
	  if ((dataFloatPars[dataFloatPars.size() - 1] != -1.0) && 
	      (MCFloatPars[MCFloatPars.size() - 1] != -1.0)) {
	    const unsigned int efficiencyIndex = numSigPars;
	    const unsigned int errorIndex = dataFloatPars.size() - 1;
	    scaleFactor.push_back(dataFloatPars[efficiencyIndex]/MCFloatPars[efficiencyIndex]);
	    error.push_back(scaleFactor[scaleFactor.size() - 1]*
			    sqrt(((dataFloatPars[errorIndex]*dataFloatPars[errorIndex])/
				  (dataFloatPars[efficiencyIndex]*dataFloatPars[efficiencyIndex])) 
				 + ((MCFloatPars[errorIndex]*MCFloatPars[errorIndex])/
				    (MCFloatPars[efficiencyIndex]*MCFloatPars[efficiencyIndex]))));
	    deviationFromNominal.push_back(scaleFactor[scaleFactor.size() - 1] - 
					   nominalScaleFactor);

	    //save other information
	    alphaPass.push_back(dataFloatPars[0]);
	    nPass.push_back(dataFloatPars[1]);
	    alphaFail.push_back(dataFloatPars[2]);
	    nFail.push_back(dataFloatPars[3]);
	    bkgShape.push_back(dataBkgPar);
	    dataEfficiency.push_back(dataFloatPars[4]);
	    dataEfficiencyErrorHigh.push_back(dataFloatPars[5]);
	    dataEfficiencyErrorLow.push_back(dataFloatPars[6]);
	    dataEfficiencyError.push_back(dataFloatPars[7]);
	    MCEfficiency.push_back(MCFloatPars[4]);
	    MCEfficiencyErrorHigh.push_back(MCFloatPars[5]);
	    MCEfficiencyErrorLow.push_back(MCFloatPars[6]);
	    MCEfficiencyError.push_back(MCFloatPars[7]);
	  }
	}
      }
      else {
	cerr << "Error processing " << dataEfficienciesFileName << " and ";
	cerr << MCEfficienciesFileName << " at line " << lineNum << ".\n";
      }
//.........这里部分代码省略.........
开发者ID:rpyohay,项目名称:physics-tools,代码行数:101,代码来源:computeVariedScaleFactors.C


示例6: spider


//.........这里部分代码省略.........
			line=rand_space(line);
			test_tamper=true;
		}


		if(test_tamper==false)
		{
			DEBUG("error at tamper argument\n");
			exit(0);
		}

		
	}


		

	memset(pathsource,0,sizeof(char)*1023);

	if(save_response==false)
	{
		strcat(pathsource,"0");
	}

// brute POST/GET/COOKIES/UserAgent
	if(arg[21]==NULL)
	{
		POST=(arg[4]==NULL)?0:1;
		counter=char_type_counter(POST?arg[4]:arg[0],'^');
		counter_cookie=char_type_counter(arg[13]!=NULL?arg[13]:"",'^');
		counter_agent=char_type_counter(arg[19]!=NULL?arg[19]:"",'^');
		old=counter;  
	} else {
		char *file_request=readLine(arg[21]);
		counter=char_type_counter(file_request,'^');
		old=counter;
		xfree((void**)&file_request);

	}
	chomp(line);

// goto to fix signal stop if user do ctrl+c
	try_again:

	while ( old > 0 || counter_cookie > 0  || counter_agent > 0 )
	{

		CURL *curl;  
//		curl_global_init(CURL_GLOBAL_ALL); 

		chunk.memory=NULL; 
		chunk.size = 0;  

		curl_socket_t sockfd; /* socket */
		long sockextr;
		size_t iolen;


		curl = curl_easy_init();
// DEBUG("counts ^ : %d \n",old);	
		

		if(arg[21]==NULL)
		{
			make=payload_injector( (POST?arg[4]:arg[0]),line,old);
		 		
开发者ID:borbelyau,项目名称:0d1n,代码行数:66,代码来源:spider.c


示例7: mexFunction

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  char *fileName;
  int fileNameLen;
  FILE *filePtr;
  char *line = NULL;
  int lineBufLength = 4;
  char *tok;
  char delims[] = " \t\n\r\f\v";
  double *vertices;
  int vi = 0;
  int vertBufSize = 3*10000;
  mxArray *vsArray;
  double *faces;
  int fi = 0;
  int faceBufSize = 3*10000;
  mxArray *trisArray;
  
  if (!mxIsChar(prhs[0]))
    mexErrMsgTxt("The first argument must be a character array.");
  
  fileNameLen = mxGetM(prhs[0])*mxGetN(prhs[0]) + 1;
  fileName = mxMalloc(fileNameLen*sizeof(char));
  mxGetString(prhs[0], fileName, fileNameLen);
  filePtr = fopen(fileName, "r");
  mxFree(fileName);
  
  if (filePtr == NULL) {
    mexErrMsgTxt("Couldn't open input file for reading.  Note that "
                 "tilde expansions are not supported.");
  }
  
  if (!readLine(&line, &lineBufLength, filePtr))
    mexErrMsgTxt("Empty file.");
  
  vertices = mxMalloc(vertBufSize*sizeof(double));
  faces = mxMalloc(faceBufSize*sizeof(double));
  
  do {
    int i;
    
    if ((tok = strtok(line, delims)) == NULL)
      continue;
    
    if (!strcmp(tok, "v")) {
      if (vi >= vertBufSize - 3) {
        vertBufSize += vertBufSize;
        vertices = mxRealloc(vertices, vertBufSize*sizeof(double));
      }
      
      for (i = 0; i < 3; ++i) {
        tok = strtok(NULL, delims);
        vertices[vi++] = atof(tok);
      }
    }
    else if (!strcmp(tok, "f")) {
      if (fi >= faceBufSize - 6) {
        faceBufSize += faceBufSize;
        faces = mxRealloc(faces, faceBufSize*sizeof(double));
      }
      
      // Read in a triangle
      for (i = 0; i < 3; ++i) {
        tok = strtok(NULL, delims);
        faces[fi++] = atof(tok);
      }
      
      // Check if it was actually a quad, and if so add another triangle
      if ((tok = strtok(NULL, delims)) != NULL) {
        faces[fi] = faces[fi - 3];
        faces[fi + 1] = faces[fi - 1];
        faces[fi + 2] = atof(tok);
        fi += 3;
      }
    }
  } while (readLine(&line, &lineBufLength, filePtr));
  
  fclose(filePtr);
  mxFree(line);
  
  vsArray = mxCreateDoubleMatrix(3, vi/3, mxREAL);
  trisArray = mxCreateDoubleMatrix(3, fi/3, mxREAL);
  
  mxFree(mxGetPr(vsArray));
  mxFree(mxGetPr(trisArray));
  
  mxSetPr(vsArray, vertices);
  mxSetPr(trisArray, faces);
  
  mexCallMATLAB(1, plhs, 1, &vsArray, "transpose");
  mexCallMATLAB(1, plhs + 1, 1, &trisArray, "transpose");
}
开发者ID:dhr,项目名称:matlab-tools,代码行数:91,代码来源:readObj.c


示例8: getNext

			std::vector<std::string>* getNext() {
				assert(hasNext());
				splitLine();
				readLine();
				return _cells.get();
			}
开发者ID:Wolff09,项目名称:RocketScience,代码行数:6,代码来源:SimpleCSVReader.hpp


示例9: return

ssize_t Socket::readData(void *Target, size_t Size, char Separator, timeout_t timeout)
{
    if ((Separator == 0x0D) || (Separator == 0x0A))
        return (readLine ((char *) Target, Size, timeout));

    if (Size < 1)
        return (0);

    ssize_t nstat;

    if (Separator == 0) {       // Flat-out read for a number of bytes.
        if (timeout) {
            if (!isPending (pendingInput, timeout)) {
                error(errTimeout);
                return (-1);
            }
        }
        nstat =::recv (so, (char *)Target, _IOLEN64 Size, 0);

        if (nstat < 0) {
            error (errInput);
            return (-1);
        }
        return (nstat);
    }
    /////////////////////////////////////////////////////////////
    // Otherwise, we have a special char separator to use
    /////////////////////////////////////////////////////////////
    bool found = false;
    size_t nleft = Size;
    int c;
    char *str = (char *) Target;

    memset (str, 0, Size);

    while (nleft && !found) {
        if (timeout) {
            if (!isPending (pendingInput, timeout)) {
                error(errTimeout);
                return (-1);
            }
        }
        nstat =::recv (so, str, _IOLEN64 nleft, MSG_PEEK);
        if (nstat <= 0) {
            error (errInput);
            return (-1);
        }

        for (c = 0; (c < nstat) && !found; ++c) {
            if (str[c] == Separator)
                found = true;
        }

        memset (str, 0, nleft);
        nstat =::recv (so, str, c, 0);
        if (nstat < 0)
            break;

        str += nstat;
        nleft -= nstat;
    }
    return (ssize_t)(Size - (ssize_t) nleft);
}
开发者ID:aberaud,项目名称:ucommon,代码行数:63,代码来源:socket.cpp


示例10: processTestFile

/* Process a specific test case. File name is provided.
 * Needs to return 0 if all is OK, something else otherwise.
 */
int
processTestFile(int fd, char *pszFileName)
{
	FILE *fp;
	char *testdata = NULL;
	char *expected = NULL;
	int ret = 0;
	size_t lenLn;
	char buf[4096];

	if((fp = fopen((char*)pszFileName, "r")) == NULL) {
		perror((char*)pszFileName);
		return(2);
	}

	/* skip comments at start of file */

	while(!feof(fp)) {
		getline(&testdata, &lenLn, fp);
		while(!feof(fp)) {
			if(*testdata == '#')
				getline(&testdata, &lenLn, fp);
			else
				break; /* first non-comment */
		}

		/* this is not perfect, but works ;) */
		if(feof(fp))
			break;

		++iTests; /* increment test count, we now do one! */

		testdata[strlen(testdata)-1] = '\0'; /* remove \n */
		/* now we have the test data to send (we could use function pointers here...) */
		unescapeTestdata(testdata);
		if(inputMode == inputUDP) {
			if(udpSend(testdata, strlen(testdata)) != 0)
				return(2);
		} else {
			if(tcpSend(testdata, strlen(testdata)) != 0)
				return(2);
		}

		/* next line is expected output 
		 * we do not care about EOF here, this will lead to a failure and thus
		 * draw enough attention. -- rgerhards, 2009-03-31
		 */
		getline(&expected, &lenLn, fp);
		expected[strlen(expected)-1] = '\0'; /* remove \n */

		/* pull response from server and then check if it meets our expectation */
		readLine(fd, buf);
		if(strcmp(expected, buf)) {
			++iFailed;
			printf("\nExpected Response:\n'%s'\nActual Response:\n'%s'\n",
				expected, buf);
				ret = 1;
		}
		/* we need to free buffers, as we have potentially modified them! */
		free(testdata);
		testdata = NULL;
		free(expected);
		expected = NULL;
	}

	free(expected);
	fclose(fp);
	return(ret);
}
开发者ID:ystk,项目名称:debian-rsyslog,代码行数:72,代码来源:nettester.c


示例11: main

/* Run the test suite. This must be called with exactly one parameter, the
 * name of the test suite. For details, see file header comment at the top
 * of this file.
 * rgerhards, 2009-04-03
 */
int main(int argc, char *argv[])
{
	int fd;
	int opt;
	int ret = 0;
	FILE *fp;
	char buf[4096];
	char testcases[4096];

	while((opt = getopt(argc, argv, "dc:i:p:t:v")) != EOF) {
		switch((char)opt) {
                case 'c':
			pszCustomConf = optarg;
			break;
                case 'd': 
			useDebugEnv = 1;
			break;
                case 'i':
			if(!strcmp(optarg, "udp"))
				inputMode = inputUDP;
			else if(!strcmp(optarg, "tcp"))
				inputMode = inputTCP;
			else {
				printf("error: unsupported input mode '%s'\n", optarg);
				exit(1);
			}
			break;
                case 'p':
			iPort = atoi(optarg);
			break;
                case 't':
			testSuite = optarg;
			break;
                case 'v':
			verbose = 1;
			break;
		default:printf("Invalid call of nettester, invalid option '%c'.\n", opt);
			printf("Usage: nettester -d -ttestsuite-name -iudp|tcp [-pport] [-ccustomConfFile] \n");
			exit(1);
		}
	}
	
	if(testSuite == NULL) {
		printf("error: no testsuite given, need to specify -t testsuite!\n");
		exit(1);
	}

	atexit(doAtExit);

	if((srcdir = getenv("srcdir")) == NULL)
		srcdir = ".";

	if(verbose) printf("Start of nettester run ($srcdir=%s, testsuite=%s, input=%s/%d)\n",
		srcdir, testSuite, inputMode2Str(inputMode), iPort);

	/* create input config file */
	if((fp = fopen(NETTEST_INPUT_CONF_FILE, "w")) == NULL) {
		perror(NETTEST_INPUT_CONF_FILE);
		printf("error opening input configuration file\n");
		exit(1);
	}
	if(inputMode == inputUDP) {
		fputs("$ModLoad ../plugins/imudp/.libs/imudp\n", fp);
		fprintf(fp, "$UDPServerRun %d\n", iPort);
	} else {
		fputs("$ModLoad ../plugins/imtcp/.libs/imtcp\n", fp);
		fprintf(fp, "$InputTCPServerRun %d\n", iPort);
	}
	fclose(fp);

	/* start to be tested rsyslogd */
	openPipe(testSuite, &rsyslogdPid, &fd);
	readLine(fd, buf);

	/* generate filename */
	sprintf(testcases, "%s/testsuites/*.%s", srcdir, testSuite);
	if(doTests(fd, testcases) != 0)
		ret = 1;

	if(verbose) printf("End of nettester run (%d).\n", ret);
	exit(ret);
}
开发者ID:ystk,项目名称:debian-rsyslog,代码行数:87,代码来源:nettester.c


示例12: Q_RETURN_ARG


//.........这里部分代码省略.........

            // Android doesn't suport GPU and PPD profiling (at leats not on my devices)
            //setProfiling(false, isProfilingCpu(), false);

            QString args = (retraceArguments() << m_androdiFileName).join(" ") + _("\n");
            stdoutSocket.write(args.toUtf8());
            if (!stdoutSocket.waitForBytesWritten()) {
                emit finished(tr("Can't send params."));
                return;
            }


            stderrSocket.connectToHost(QHostAddress::LocalHost, m_stderrPort);
            stderrSocket.waitForConnected(100);
            if (stderrSocket.state() != QAbstractSocket::ConnectedState) {
                emit finished(tr("Can't connect to stderr socket."));
                return;
            }
            wasStarted = true;
        }

        // We are going to read both channels at the same time

        // read stdout channel
        if (stdoutSocket.waitForReadyRead(100)) {
            if (captureState())
                ubjsonBuffer.append(stdoutSocket.readAll());
            else if (captureThumbnails()) {
                // read one image
                image::PNMInfo info;
                QByteArray header;
                int headerLines = 3; // assume no optional comment line
                for (int headerLine = 0; headerLine < headerLines; ++headerLine) {
                    QByteArray line = readLine(stdoutSocket);
                    if (line.isEmpty()) {
                        keepGoing = false;
                        break;
                    }
                    header += line;
                    // if header actually contains optional comment line, ...
                    if (headerLine == 1 && line[0] == '#') {
                        ++headerLines;
                    }
                }

                const char *headerEnd = image::readPNMHeader(header.constData(), header.size(), info);

                // if invalid PNM header was encountered, ...
                if (headerEnd == NULL ||
                    info.channelType != image::TYPE_UNORM8) {
                    qDebug() << "error: invalid snapshot stream encountered";
                    keepGoing = false;
                    break;
                }

                unsigned channels = info.channels;
                unsigned width = info.width;
                unsigned height = info.height;

                // qDebug() << "channels: " << channels << ", width: " << width << ", height: " << height";

                QImage snapshot = QImage(width, height, channels == 1 ? QImage::Format_Mono : QImage::Format_RGB888);

                int rowBytes = channels * width;
                for (int y = 0; y < height; ++y) {
                    unsigned char *scanLine = snapshot.scanLine(y);
开发者ID:ShuangxueBai,项目名称:apitrace,代码行数:67,代码来源:androidretracer.cpp


示例13: parseDescription

int parseDescription(Spec spec)
	/*@globals name, lang @*/
	/*@modifies name, lang @*/
{
    rpmParseState nextPart = (rpmParseState) RPMRC_FAIL; /* assume error */
    rpmiob iob = NULL;
    int flag = PART_SUBNAME;
    Package pkg;
    int rc, argc;
    int arg;
    const char **argv = NULL;
    poptContext optCon = NULL;
    spectag t = NULL;

    {	char * se = strchr(spec->line, '#');
	if (se) {
	    *se = '\0';
	    while (--se >= spec->line && strchr(" \t\n\r", *se) != NULL)
		*se = '\0';
	}
    }

    if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
	rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%description: %s\n"),
		 spec->lineNum, poptStrerror(rc));
	goto exit;
    }

    name = NULL;
    lang = RPMBUILD_DEFAULT_LANG;
    optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
    while ((arg = poptGetNextOpt(optCon)) > 0)
	{;}
    if (name != NULL)
	flag = PART_NAME;

    if (arg < -1) {
	rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
		 spec->lineNum,
		 poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
		 spec->line);
	goto exit;
    }

    if (poptPeekArg(optCon)) {
	if (name == NULL)
	    name = poptGetArg(optCon);
	if (poptPeekArg(optCon)) {
	    rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
		     spec->lineNum, spec->line);
	    goto exit;
	}
    }

    if (lookupPackage(spec, name, flag, &pkg) != RPMRC_OK) {
	rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"),
		 spec->lineNum, spec->line);
	goto exit;
    }

    /* Lose the inheirited %description (if present). */
    if (spec->packages->header != pkg->header) {
	HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
	int xx;
	he->tag = RPMTAG_DESCRIPTION;
	xx = headerGet(pkg->header, he, 0);
	he->p.ptr = _free(he->p.ptr);
	if (xx && he->t == RPM_STRING_TYPE)
	    xx = headerDel(pkg->header, he, 0);
    }
    
    t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang);
    
    iob = rpmiobNew(0);

    if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
	nextPart = PART_NONE;
	goto exit;
    }
    if (rc < 0) {
	    nextPart = (rpmParseState) RPMRC_FAIL;
	    goto exit;
	}

	while ((nextPart = isPart(spec)) == PART_NONE) {
	    iob = rpmiobAppend(iob, spec->line, 1);
	    if (t) t->t_nlines++;
	if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
		nextPart = PART_NONE;
		break;
	    }
	    if (rc) {
		nextPart = (rpmParseState) RPMRC_FAIL;
		goto exit;
	    }
	}
    
    iob = rpmiobRTrim(iob);
    if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) {
	const char * s = rpmiobStr(iob);
//.........这里部分代码省略.........
开发者ID:avokhmin,项目名称:RPM5,代码行数:101,代码来源:parseDescription.c


示例14: main

int main(int argc, char* argv[])
{
#ifdef Q_OS_WIN
    _setmode(1, _O_BINARY);
    _setmode(2, _O_BINARY);
#endif

#ifdef Q_WS_X11
    FcInit();
    WebCore::DumpRenderTree::initializeFonts();
#endif

    QApplication::setGraphicsSystem("raster");
    QApplication::setStyle(new QWindowsStyle);

    QFont f("Sans Serif");
    f.setPointSize(9);
    f.setWeight(QFont::Normal);
    f.setStyle(QFont::StyleNormal);
    QApplication::setFont(f);

    QApplication app(argc, argv);
#ifdef Q_WS_X11
    QX11Info::setAppDpiY(0, 96);
    QX11Info::setAppDpiX(0, 96);
#endif

#if HAVE(SIGNAL_H)
    signal(SIGILL, crashHandler);    /* 4:   illegal instruction (not reset when caught) */
    signal(SIGTRAP, crashHandler);   /* 5:   trace trap (not reset when caught) */
    signal(SIGFPE, crashHandler);    /* 8:   floating point exception */
    signal(SIGBUS, crashHandler);    /* 10:  bus error */
    signal(SIGSEGV, crashHandler);   /* 11:  segmentation violation */
    signal(SIGSYS, crashHandler);    /* 12:  bad argument to system call */
    signal(SIGPIPE, crashHandler);   /* 13:  write on a pipe with no reader */
    signal(SIGXCPU, crashHandler);   /* 24:  exceeded CPU time limit */
    signal(SIGXFSZ, crashHandler);   /* 25:  exceeded file size limit */
#endif

    QStringList args = app.arguments();
    if (args.count() < 2) {
        qDebug() << "Usage: DumpRenderTree [-v|--pixel-tests] filename [filename2..n]";
        qDebug() << "Or folder containing test files: DumpRenderTree [-v|--pixel-tests] dirpath";
        exit(0);
    }

    // Suppress debug output from Qt if not started with -v
    if (!args.contains(QLatin1String("-v")))
        qInstallMsgHandler(messageHandler);

    WebCore::DumpRenderTree dumper;

    if (args.contains(QLatin1String("--pixel-tests")))
        dumper.setDumpPixels(true);

    QWebDatabase::removeAllDatabases();

    if (args.contains(QLatin1String("-"))) {
        QObject::connect(&dumper, SIGNAL(ready()), &dumper, SLOT(readLine()), Qt::QueuedConnection);
        QTimer::singleShot(0, &dumper, SLOT(readLine()));
    } else
        dumper.processArgsLine(args);

    return app.exec();

#ifdef Q_WS_X11
    FcConfigSetCurrent(0);
#endif
}
开发者ID:mcgrawp,项目名称:webkit-webcl,代码行数:69,代码来源:main.cpp


示例15: readLine

char* MWiFi::readDataLn(uint8_t sk)
{
          return readLine(sk);          
}
开发者ID:kstirben,项目名称:Data-Streams,代码行数:4,代码来源:MWiFi.cpp


示例16: close


//.........这里部分代码省略.........
		size_t len = std::string::npos;
		pos = extra_headers.find('=', pos);
		if (pos != std::string::npos)
		{
			len = pos - start;
			pos++;
			name = extra_headers.substr(start, len);
			start = pos;
			len = std::string::npos;
			pos = extra_headers.find('&', pos);
			if (pos != std::string::npos)
			{
				len = pos - start;
				pos++;
			}
			value = extra_headers.substr(start, len);
		}
		if (!name.empty() && !value.empty())
		{
			eDebug("[eHttpStream] setting extra-header '%s:%s'", name.c_str(), value.c_str());
			request.append(name).append(": ").append(value).append("\r\n");
		}
		else
		{
			eDebug("[eHttpStream] Invalid header format %s", extra_headers.c_str());
			break;
		}
	}

	request.append("Accept: */*\r\n");
	request.append("Connection: close\r\n");
	request.append("\r\n");

	writeAll(streamSocket, request.c_str(), request.length());

	linebuf = (char*)malloc(buflen);

	result = readLine(streamSocket, &linebuf, &buflen);
	if (result <= 0)
		goto error;

	result = sscanf(linebuf, "%99s %d %99s", proto, &statuscode, statusmsg);
	if (result != 3 || (statuscode != 200 && statuscode != 206 && statuscode != 302))
	{
		eDebug("[eHttpStream] %s: wrong http response code: %d", __func__, statuscode);
		goto error;
	}

	while (1)
	{
		result = readLine(streamSocket, &linebuf, &buflen);
		if (!contenttypeparsed)
		{
			char contenttype[33];
			if (sscanf(linebuf, "Content-Type: %32s", contenttype) == 1)
			{
				contenttypeparsed = true;
				if (!strcasecmp(contenttype, "application/text")
				|| !strcasecmp(contenttype, "audio/x-mpegurl")
				|| !strcasecmp(contenttype, "audio/mpegurl")
				|| !strcasecmp(contenttype, "application/m3u"))
				{
					/* assume we'll get a playlist, some text file containing a stream url */
					playlist = true;
				}
				continue;
			}
		}
		if (playlist && !strncasecmp(linebuf, "http://", 7))
		{
			newurl = linebuf;
			eDebug("[eHttpStream] %s: playlist entry: %s", __func__, newurl.c_str());
			break;
		}
		if (((statuscode == 301) || (statuscode == 302) || (statuscode == 303) || (statuscode == 307) || (statuscode == 308)) &&
				strncasecmp(linebuf, "location: ", 10) == 0)
		{
			newurl = &linebuf[10];
			eDebug("[eHttpStream] %s: redirecting to: %s", __func__, newurl.c_str());
			break;
		}

		if (((statuscode == 200) || (statuscode == 206)) && !strncasecmp(linebuf, "transfer-encoding: chunked", strlen("transfer-encoding: chunked")))
		{
			isChunked = true;
		}
		if (!playlist && result == 0)
			break;
		if (result < 0)
			break;
	}

	free(linebuf);
	return 0;
error:
	eDebug("[eHttpStream] %s failed", __func__);
	free(linebuf);
	close();
	return -1;
}
开发者ID:kajgan,项目名称:e2,代码行数:101,代码来源:httpstream.cpp


示例17: scan

void scan(void *arguments)
{
	FILE *fp=NULL;
        int num1=0,num2=0;

	char **arg = (char **)arguments;
	char *pathtable=NULL,*pathhammer=NULL,*view=NULL,*template2=NULL,*template3=NULL;
	char line[2048]; 

	pid_t pid;

	if(arg[11]!=NULL)
		threadss=atoi(arg[11]);

	int old_thread=threadss;
	int status=-1;

 	int timeout=3;

	if(arg[8]!=NULL)
		timeout=atoi(arg[8]);
 
	pathtable=xmalloc(sizeof(char)*64);
	memset(pathtable,0, sizeof(char)*63);
	strncat(pathtable,"tables/",8);
	strncat(pathtable,arg[5],16);
	strncat(pathtable,".txt",5);
	fp = fopen(arg[1], "r");

 	if ( !fp )
	{ 
		DEBUG("error to open Payload list"); 
		exit(1);
	}

        num1=FileSize(TEMPLATE2);
        num2=FileSize(TEMPLATE3); 

	view=xmalloc(sizeof(char)*(num1+num2+42));
	memset(view,0,sizeof(char)*(num1+num2+1));

      //  template2=xmalloc(sizeof(char)*num1+1);
        template2=readLine(TEMPLATE2);
	strncat(view,template2,num1+1);
	strncat(view,"\"sAjaxSource\": \"",23);
	strncat(view,arg[5],16);
	strncat(view,".txt\" \n",9);

      //  template3=xmalloc(sizeof(char)*num2+1);
        template3=readLine(TEMPLATE3);

	strncat(view,template3,num2);

	pathhammer=xmalloc(sizeof(char)*64);
	memset(pathhammer,0,sizeof(char)*63);
	strncat(pathhammer,"tables/hammer_",15);
	strncat(pathhammer,arg[5],16);
	strncat(pathhammer,".html",6);
	WriteFile(pathhammer,view);
	WriteFile(pathtable,"{ \"aaData\": [ \n");

	puts("start...");

// TODO add my thread pool library
	while ( fgets(line,2047,fp) != NULL ) 
	{
		curl_global_cleanup();
		pid=fork();
		curl_global_init(CURL_GLOBAL_ALL);

 
		if(pid==-1)
		{
			DEBUG("error in fork()");
			exit(1);
		}

		if(!pid)
		{

//			curl_global_init(CURL_GLOBAL_ALL);
			threadss--;
			spider(arguments,line,pathtable);
//			curl_global_cleanup();
			exit(0);
		}
		
		if(threadss<=0)
		{
				while(1)
				{
					pid=wait(&status);	

						if (errno == ECHILD)
						{
							break;
						}
						
				}

//.........这里部分代码省略.........
开发者ID:borbelyau,项目名称:0d1n,代码行数:101,代码来源:spider.c


示例18: readFile

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int32_t VtkStructuredPointsReader:: readFile()
{
  int32_t err = 0;

  DataContainer::Pointer volDc = getDataContainerArray()->getDataContainer(getVolumeDataContainerName());
  AttributeMatrix::Pointer volAm = volDc->getAttributeMatrix(getCellAttributeMatrixName());

  DataContainer::Pointer vertDc = getDataContainerArray()->getDataContainer(getVertexDataContainerName());
  AttributeMatrix::Pointer vertAm = vertDc->getAttributeMatrix(getVertexAttributeMatrixName());

  std::ifstream in(getInputFile().toLatin1().constData(), std::ios_base::in | std::ios_base::binary);

  if (!in.is_open())
  {
    QString msg = QObject::tr("Error opening output file '%1'").arg(getInputFile());
    setErrorCondition(-61003);
    notifyErrorMessage(getHumanLabel(), msg, getErrorCondition());
    return -100;
  }

  QByteArray buf(kBufferSize, '\0');
  char* buffer = buf.data();

  err = readLine(in, buffer, kBufferSize); // Read Line 1 - VTK Version Info
  err = readLine(in, buffer, kBufferSize); // Read Line 2 - User Comment
  setComment(QString(buf));
  err = readLine(in, buffer, kBufferSize); // Read Line 3 - BINARY or ASCII
  QString fileType(buf);
  if (fileType.startsWith("BINARY") == true)
  {
    setFileIsBinary(true);
  }
  else if (fileType.startsWith("ASCII") == true)
  {
    setFileIsBinary(false);
  }
  else
  {
    QString ss = QObject::tr("The file type of the VTK legacy file could not be determined. It should be 'ASCII' or 'BINARY' and should appear on line 3 of the file");
    setErrorCondition(-61004);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return getErrorCondition();
  }

  // Read Line 4 - Type of Dataset
  err = readLine(in, buffer, kBufferSize);
  QList<QByteArray> words = buf.split(' ');
  if (words.size() != 2)
  {
    QString ss = QObject::tr("Error reading the type of data set. Was expecting 2 words but got %1").arg(QString(buf));
    setErrorCondition(-61005);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return getErrorCondition();
  }
  QString dataset(words.at(1));
  dataset = dataset.trimmed();
  setDatasetType(dataset); // Should be STRUCTURED_POINTS

  bool ok = false;
  err = readLine(in, buffer, kBufferSize);  // Read Line 5 which is the Dimension values
  // But we need the 'extents' which is one less in all directions (unless dim=1)
  QVector<size_t> dims(3, 0);
  QList<QByteArray> tokens = buf.split(' ');
  dims[0] = tokens[1].toInt(&ok, 10);
  dims[1] = tokens[2].toInt(&ok, 10);
  dims[2] = tokens[3].toInt(&ok, 10);
  QVector<size_t> tDims(3, 0);
  tDims[0] = dims[0];
  tDims[1] = dims[1];
  tDims[2] = dims[2];
  vertAm->setTupleDimensions(tDims);
  vertDc->getGeometryAs<ImageGeom>()->setDimensions(dims.data());

  tDims[0] = dims[0] - 1;
  tDims[1] = dims[1] - 1;
  tDims[2] = dims[2] - 1;
  volAm->setTupleDimensions(tDims);
  volDc->getGeometryAs<ImageGeom>()->setDimensions(tDims.data());

  err = readLine(in, buffer, kBufferSize); // Read Line 7 which is the Scaling values
  tokens = buf.split(' ');
  float resolution[3];
  resolution[0] = tokens[1].toFloat(&ok);
  resolution[1] = tokens[2].toFloat(&ok);
  resolution[2] = tokens[3].toFloat(&ok);

  volDc->getGeometryAs<ImageGeom>()->setResolution(resolution);
  vertDc->getGeometryAs<ImageGeom>()->setResolution(resolution);

  err = readLine(in, buffer, kBufferSize); // Read Line 6 which is the Origin values
  tokens = buf.split(' ');
  float origin[3];
  origin[0] = tokens[1].toFloat(&ok);
  origin[1] = tokens[2].toFloat(&ok);
  origin[2] = tokens[3].toFloat(&ok);

  volDc->getGeometryAs<ImageGeom>()->setOrigin(origin);
//.........这 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ readLock函数代码示例发布时间:2022-05-30
下一篇:
C++ readLabel函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap