Beispiel #1
0
static
void
dometer(int s)
{
	char buf[4096], *x;
	size_t bufpos=0;
	int r;

	while (1) {
		assert(bufpos<=sizeof(buf));
		if (bufpos==sizeof(buf)) {
			fprintf(stderr, "stat161: Input overrun\n");
			bufpos = 0;
		}
		r = read(s, buf+bufpos, sizeof(buf)-bufpos);
		if (r<0) {
			fprintf(stderr, "stat161: read: %s\n",
				strerror(errno));
			return;
		}
		else if (r==0) {
			return;
		}

		bufpos += r;
		
		while ((x = memchr(buf, '\n', bufpos))!=NULL) {
			*x = 0;
			x++;
			bufpos -= (x-buf);
			processline(buf);
			memmove(buf, x, bufpos);
		}
	}
}
Beispiel #2
0
void EUSART_Receive_ISR(void) // appelle automatiquement lorsqu'il y a un charactere qui arrive
{
    char incoming;
    
    if (1 == RC1STAbits.OERR) 
    {
        // EUSART error - restart
        RC1STAbits.CREN = 0;
        RC1STAbits.CREN = 1;
    }
    
    incoming = RC1REG;
    console[lines][charac]=incoming;
    
    if ((incoming == '\n')||(incoming == '\r')) //truc foireux pour remplir la console
    {  
        if(charac > 0)
        {
            //display the distance
           //display(lines) ;
            char str[9];
            strncpy(str, console[lines], 9);
                    
            processline(str);
            lines++;
            charac =0;
        }
    }  
    else
    {
        charac++;
    }    
}
Beispiel #3
0
int main(){
  char filename[50]; //filename
  FILE *p; //file pointer
  char line[90]; //line read from file

  fillranks(x);
  strcpy(filename,"data.txt");

  //open the file
  p=fopen(filename,"r");
  if(p==NULL){
    puts("Could not find file, exiting program\n");
    return -1;
  }

  while(!feof(p)){
    fgets(line,90,p); //read a line
    processline(line); //process it
  }

  printf("The total FTE so far is %f\n",FTE);
  printf("No of tenured faculty %d, with FTE %f\n",tenure,tenure_FTE);
  printf("No of non-tenured faculty %d, with FTE %f\n",non_tenure,nonten_FTE);

  printf("Pt tenured %f\n",PT_tenure_FTE);
  printf("Pt non-tensure %f\n",PT_nonten_FTE);
  printf("Ft tenured %f\n",FT_tenure_FTE);
  printf("Ft non-tenured %f\n",FT_nonten_FTE);

  fclose(p);
  return 0;
}
Beispiel #4
0
int main (void)
{
    char   buffer [LINELEN];
    int    len;

    while (1) {

        /* prompt and get line */
	fprintf (stderr, "%% ");
	if (fgets (buffer, LINELEN, stdin) != buffer)
            break;

        /* Get rid of \n at end of buffer. */
	len = strlen(buffer);
	if (buffer[len-1] == '\n')
	    buffer[len-1] = 0;

	/* Run it ... */
	processline (buffer);

    }

    if (!feof(stdin))
        perror ("read");

    return 0;		/* Also known as exit (0); */
}
//processing stdin line by line
int processStdin()
{
    for (string line; getline(cin, line) ;)
    {
        if (line[0] != '@')
        {
            processline(line);
        }
    }
    return 0;
}
Beispiel #6
0
int main (int argc, char **argv)
{
    FILE *script = stdin;
    char   buffer [LINELEN];
    int    len;
    mainargc = argc;
    mainargv = argv;
    shift_value = 0;
    int script_f = 0;

//    printf("%s\n", mainargv[0]);
//    printf("%s\n", mainargv[1]);
    //fprintf(stderr, mainargv[1]);
//    fprintf(stderr, '\n');

    // First, check to see if file exists, if so, run.
    if (argc > 1) {
        argv++;
        if((script = fopen(*argv, "r")) != 0) {
            // Script found, in script mode
            script_f = 1;
        }
        else {
            perror("Open file: ");
            return 127;
        }
    }
    while (1) {
        if (script_f == 1) {
            if(fgets(buffer, LINELEN, script) == 0) {
                fclose(script);
                return 0;
            }
        }
        else {
            /* prompt and get line */
            fprintf (stderr, "%% ");
            if (fgets (buffer, LINELEN, stdin) != buffer)
                break;
        }
        /* Get rid break of \n at end of buffer. */
        len = strlen(buffer);
        if (buffer[len-1] == '\n')
            buffer[len-1] = 0;

        /* Run it ... */
        processline (buffer);
    }

    if (!feof(stdin))
        perror ("read");

    return 0;	 /* Also known as exit (0); */
}
// processing file line by line
int processFile(const char * filename)
{
    ifstream samfile (filename);
    for (string line; getline(samfile, line);)
    {
        if (line[0] != '@')
        {
            processline(line);
        }
    }
    return 0;
}
Beispiel #8
0
main()
{
  char line[MAXWORD];
  struct tnode *root;

  root = NULL;
  while(pgetline(line, MAXLINE) > 0) {//while not EOF
    root = processline(line, root); //process line, keep track of binary tree
  }
  treeprint(root);
  return 0;
}
Beispiel #9
0
void getlatest(io *s)
{
	ssize_t sz;
	int code;
	int high;
	int i;
	char line[512], msgid[512];
	int m;
	int n;

	io_printf(s, "GROUP %s\r\n", group);

	sz = parse_response_line(s, &code, line);
	if(sz == -1)
		msg_fail("parse_response_line: %s", msg_get());

	switch(code) {
	case 211:
		break;
	case 411:
		msg_fail("No such newsgroup");
	default:
		msg_fail("Received unexpected response code %d", code);
	}

	m = sscanf(line, "%*d %*d %*d %d", &high);
	if(m == 0)
		msg_fail("Failed to parse latest article number from response line");

	io_printf(s, "STAT %d\r\n", high);
	processline(s);
	for(i = 1; i < max; i++)
		io_printf(s, "LAST\r\n");
	for(i = 1; i < max; i++)
		processline(s);
}
Beispiel #10
0
main()
{
char c;
    f1=fopen("mplusainput.txt","r");
    f2=fopen("macrooutput1.txt","w");
    while(!feof(f1))
    {
	getline();
	processline();
    }
    fclose(f1);
    fclose(f2);
scanf("%c",&c);
assemble();
}
Beispiel #11
0
void SetupPar(char* pararchivename)
{
  //Load par files, create analysis libraries
  //For testing, if par file already decompressed and modified
  //classes then do not decompress.
 
  TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; 
  TString parpar(Form("%s.par", pararchivename)) ; 
  if ( gSystem->AccessPathName(parpar.Data()) ) {
    gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
    TString processline(Form(".! make %s", parpar.Data())) ; 
    gROOT->ProcessLine(processline.Data()) ;
    gSystem->ChangeDirectory(cdir) ; 
    processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
    gROOT->ProcessLine(processline.Data()) ;
  } 
  if ( gSystem->AccessPathName(pararchivename) ) {  
    TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
    gROOT->ProcessLine(processline.Data());
  }
  
  TString ocwd = gSystem->WorkingDirectory();
  gSystem->ChangeDirectory(pararchivename);
  
  // check for BUILD.sh and execute
  if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
    printf("*******************************\n");
    printf("*** Building PAR archive    ***\n");
    cout<<pararchivename<<endl;
    printf("*******************************\n");
    
    if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
      Error("runProcess","Cannot Build the PAR Archive! - Abort!");
      return -1;
    }
  }
  // check for SETUP.C and execute
  if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
    printf("*******************************\n");
    printf("*** Setup PAR archive       ***\n");
    cout<<pararchivename<<endl;
    printf("*******************************\n");
    gROOT->Macro("PROOF-INF/SETUP.C");
  }
  
  gSystem->ChangeDirectory(ocwd.Data());
  printf("Current dir: %s\n", ocwd.Data());
}
Beispiel #12
0
int
main(int argc, char *argv[])
{
    unsigned char buf[10240];
    for (int i = 1; i < argc; ++i) {
        FILE *fp = fopen(argv[i], "r");
        while (fgets((char*)buf, sizeof(buf), fp) != NULL) {
            bool emptyline = processline(buf);
            if ((unsigned int)buf[0] == '#' || (unsigned int)buf[0] == '0')
                continue;
            if (emptyline)
                printf("\n");
            else
                printf("%s", buf);
        }
        fclose(fp);
        printf("\n");
    }
}
Beispiel #13
0
expand()
{
    char a[100],*t,tem[15],c,lab[15];
    int i=0,l,count=sindex,j=0,k;
    expanding=1;
    strcpy(a,deftab[sindex]);
    l=strlen(line);   
    while(line[i++]!='\t');
    while(line[i++]!='\t');
    k=0;
    for(;i<l;i++)
    {
	j=0;
	while(isalpha(line[i])||isdigit(line[i]))
	    tem[j++]=line[i++];
	i--;
	tem[j]='\0';
	strcpy(argtab[ni].a[k++],tem);
	i++;
    }
    c=0;
    i=0;
    while(c!='\t')
    {
	sscanf(line+i,"%c",&c);
	lab[i++]=c;
    }
    lab[i]='\0';
    fprintf(f2,".");
    fprintf(f2,"%s\n",line);
if(line[0]!='*')
     fprintf(f2,"%s\t*\n",lab);
    while(count++<dindex-2)
    {
	getline();
	processline();
    }
    expanding=0;
    }
Beispiel #14
0
int main(int argc, char **argv)
{
	char filename[255],*ret,buffer[100];
	FILE * fd,*fw;

	if(argc==1)
	{
		printf("\nGive the filename as the argument");
		return EXIT_SUCCESS;
	}
	else
		strcpy(filename,argv[1]);


	fd=fopen(filename,"r");
	fw=fopen("output.txt","w");

	if (fd==NULL || fw ==NULL)
	{
		fprintf(stderr,"\nCannot Create files");
		exit(EXIT_FAILURE);
	}

	while(1)
	{
		fgets(buffer,80,fd);
		ret=strstr(buffer,"END");
		if(ret!=NULL)
			break;
		processline(buffer,fd,fw);
	}
	fclose(fd);
	fclose(fw);
	return EXIT_SUCCESS;

}
Beispiel #15
0
int ReadConfig() {
	FILE *FP;
	char buf[1024];
	char cfn[80];


	memset( &pc, 0, sizeof pc );

	/* Set nonzero config defaults */
	pc.asteriskwritetimeout = 100;
	pc.clientwritetimeout = 100;
	pc.sslclhellotimeout = 500;

	sprintf(cfn, "%s/%s", CDIR, CFILE);
	FP = fopen( cfn, "r" );

	if ( !FP ) {
		fprintf(stderr, "Unable to open config file: %s/%s!\n", CDIR, CFILE);
		exit( 1 );
	}

	if (debug)
		debugmsg("config: parsing configuration file: %s", cfn);

	while ( fgets( buf, sizeof buf, FP ) ) {
		if (*buf == ';' || *buf == '\r' || *buf == '\n' || *buf == '#') continue;
		processline(buf);
	}

	fclose(FP);

	/* initialize SSL layer with our server certfile */
	init_secure(pc.certfile);

	return 0;
}
Beispiel #16
0
int main(int argc, char **argv) {
#ifndef THREADED
    fd_set rfds, wfds, efds;
    int processed=0;
#endif
    char buffer[4096];
    char p[2048];
#ifdef YCA  
    char *cert=0;
    char appId[64];
#endif
    int bufoff = 0;
    FILE *fh;

    if (argc < 2) {
        fprintf(stderr,
                "USAGE %s zookeeper_host_list [clientid_file|cmd:(ls|ls2|create|od|...)]\n", 
                argv[0]);
        fprintf(stderr,
                "Version: ZooKeeper cli (c client) version %d.%d.%d\n", 
                ZOO_MAJOR_VERSION,
                ZOO_MINOR_VERSION,
                ZOO_PATCH_VERSION);
        return 2;
    }
    if (argc > 2) {
      if(strncmp("cmd:",argv[2],4)==0){
        size_t cmdlen = strlen(argv[2]);
        if (cmdlen > sizeof(cmd)) {
          fprintf(stderr,
                  "Command length %zu exceeds max length of %zu\n",
                  cmdlen,
                  sizeof(cmd));
          return 2;
        }
        strncpy(cmd, argv[2]+4, sizeof(cmd));
        batchMode=1;
        fprintf(stderr,"Batch mode: %s\n",cmd);
      }else{
        clientIdFile = argv[2];
        fh = fopen(clientIdFile, "r");
        if (fh) {
            if (fread(&myid, sizeof(myid), 1, fh) != sizeof(myid)) {
                memset(&myid, 0, sizeof(myid));
            }
            fclose(fh);
        }
      }
    }
#ifdef YCA
    strcpy(appId,"yahoo.example.yca_test");
    cert = yca_get_cert_once(appId);
    if(cert!=0) {
        fprintf(stderr,"Certificate for appid [%s] is [%s]\n",appId,cert);
        strncpy(p,cert,sizeof(p)-1);
        free(cert);
    } else {
      fprintf(stderr,"Certificate for appid [%s] not found\n",appId);
      strcpy(p,"dummy");
    }
#else
    strcpy(p, "dummy");
#endif
    verbose = 0;
    zoo_set_debug_level(ZOO_LOG_LEVEL_WARN);
    zoo_deterministic_conn_order(1); // enable deterministic order
    hostPort = argv[1];
    zh = zookeeper_init(hostPort, watcher, 30000, &myid, 0, 0);
    if (!zh) {
        return errno;
    }

#ifdef YCA
    if(zoo_add_auth(zh,"yca",p,strlen(p),0,0)!=ZOK)
    return 2;
#endif

#ifdef THREADED
    while(!shutdownThisThing) {
        int rc;
        int len = sizeof(buffer) - bufoff -1;
        if (len <= 0) {
            fprintf(stderr, "Can't handle lines that long!\n");
            exit(2);
        }
        rc = read(0, buffer+bufoff, len);
        if (rc <= 0) {
            fprintf(stderr, "bye\n");
            shutdownThisThing=1;
            break;
        }
        bufoff += rc;
        buffer[bufoff] = '\0';
        while (strchr(buffer, '\n')) {
            char *ptr = strchr(buffer, '\n');
            *ptr = '\0';
            processline(buffer);
            ptr++;
            memmove(buffer, ptr, strlen(ptr)+1);
            bufoff = 0;
        }
    }
#else
    FD_ZERO(&rfds);
    FD_ZERO(&wfds);
    FD_ZERO(&efds);
    while (!shutdownThisThing) {
        int fd;
        int interest;
        int events;
        struct timeval tv;
        int rc;
        zookeeper_interest(zh, &fd, &interest, &tv);
        if (fd != -1) {
            if (interest&ZOOKEEPER_READ) {
                FD_SET(fd, &rfds);
            } else {
                FD_CLR(fd, &rfds);
            }
            if (interest&ZOOKEEPER_WRITE) {
                FD_SET(fd, &wfds);
            } else {
                FD_CLR(fd, &wfds);
            }
        } else {
            fd = 0;
        }
        FD_SET(0, &rfds);
        rc = select(fd+1, &rfds, &wfds, &efds, &tv);
        events = 0;
        if (rc > 0) {
            if (FD_ISSET(fd, &rfds)) {
                events |= ZOOKEEPER_READ;
            }
            if (FD_ISSET(fd, &wfds)) {
                events |= ZOOKEEPER_WRITE;
            }
        }
        if(batchMode && processed==0){
          //batch mode
          processline(cmd);
          processed=1;
        }
        if (FD_ISSET(0, &rfds)) {
            int rc;
            int len = sizeof(buffer) - bufoff -1;
            if (len <= 0) {
                fprintf(stderr, "Can't handle lines that long!\n");
                exit(2);
            }
            rc = read(0, buffer+bufoff, len);
            if (rc <= 0) {
                fprintf(stderr, "bye\n");
                break;
            }
            bufoff += rc;
            buffer[bufoff] = '\0';
            while (strchr(buffer, '\n')) {
                char *ptr = strchr(buffer, '\n');
                *ptr = '\0';
                processline(buffer);
                ptr++;
                memmove(buffer, ptr, strlen(ptr)+1);
                bufoff = 0;
            }
        }
        zookeeper_process(zh, events);
    }
#endif
    if (to_send!=0)
        fprintf(stderr,"Recvd %d responses for %d requests sent\n",recvd,sent);
    zookeeper_close(zh);
    return 0;
}
Beispiel #17
0
/* dependency calculator for c/c++ preprocessor */
static int dependency_cpp_run(struct CONTEXT *context, struct NODE *node,
		int (*callback)(struct NODE *, void *, const char *, int), void *userdata)
{
	char *linestart;
	char *includestart;
	char *includeend;
	int systemheader;
	int errorcode = 0;
	int linecount = 0;

	/* open file */
	long filesize;
	long readitems;
	char *filebuf;
	char *filebufcur;
	char *filebufend;
	FILE *file;
	struct CACHERUNINFO cacheinfo;

	/* don't run depcheck twice */
	if(node->depchecked)
		return 0;
		
	/* mark the node for caching */
	node_cached(node);
	
	/* check if we have the dependencies in the cache frist */
	cacheinfo.context = context;
	cacheinfo.callback = callback;
	cacheinfo.userdata = userdata;
	if(cache_do_dependency(context, node, cachehit_callback, &cacheinfo))
		return 0;

	/* mark the node as checked */
	node->depchecked = 1;

	file = fopen(node->filename, "rb");
	if(!file)
		return 0;
	
	/* read the whole file */
	fseek(file, 0, SEEK_END);
	filesize = ftell(file);
	fseek(file, 0, SEEK_SET);
	
	filebuf = malloc(filesize+1); /* +1 for null termination */
	
	if(!filebuf)
	{
		printf("cpp-dep: %s: error allocating %ld bytes\n", node->filename, filesize);
		fclose(file);
		return 1;
	}
		
	/* read the file and close it */
	readitems = fread(filebuf, 1, filesize, file);
	fclose(file);

	if(readitems != filesize)
	{
		printf("cpp-dep: %s: error reading. %ld of %ld bytes read\n", node->filename, readitems, filesize);
		free(filebuf);
		return 1;
	}
	
	filebufcur = filebuf;
	filebufend = filebuf+filesize;
	
	while(filebufcur < filebufend)
	{
		/* search for next line */
		linestart = filebufcur;
		while(filebufcur != filebufend && *filebufcur != '\n' && *filebufcur != '\r')
			filebufcur++;
		*filebufcur = 0;
		filebufcur++;
		linecount++;

		if(processline(linestart, &includestart, &includeend, &systemheader))
		{
			*includeend = 0;
			/* run callback */
			errorcode = callback(node, userdata, includestart, systemheader);
			if(errorcode)
				break;
		}
	}

	/* clean up and return*/
	free(filebuf);
	return errorcode;
}