Exemple #1
0
char *test_getlines()
{
  bstring str = bfromcstr("one\ntwo\nthree\nfour\nfive\n");
  struct bstrList *file = bsplit(str, '\n');

  DArray *lines = getlines(file, 2, 4);

  bstring two = bfromcstr("two");
  bstring three = bfromcstr("three");
  bstring four = bfromcstr("four");

  mu_assert(DArray_count(lines) == 3, "Wrong number of lines.");
  mu_assert(bstrcmp((bstring)DArray_at(lines, 0), two) == 0, "First line is wrong.");
  mu_assert(bstrcmp((bstring)DArray_at(lines, 1), three) == 0, "Second line is wrong.");
  mu_assert(bstrcmp((bstring)DArray_at(lines, 2), four) == 0, "Third line is wrong.");

  bstrListDestroy(file);
  bdestroy(str);
  bdestroy(two);
  bdestroy(three);
  bdestroy(four);
  DArray_destroy(lines);

  return NULL;
}
Exemple #2
0
int main() {
	int len;
	// int max;

	char line[MAXLINE];
	char withoutTBlanks[MAXLINE];
	/* current line length */
	/* maximum length seen so far */
	/* current input line */
	/* longest line saved here */
	// max = 0;
	while ((len = getlines(line, MAXLINE)) > 0) {
		// if (len > max) {
		// 	max = len;
		copy(withoutTBlanks, line, len);
		// }
		printf("%s\n", withoutTBlanks);
	}

	// if (max > 0) {
	// 	printf("%s %d\n", longest, max);	
	// }
	return 0;

}
Exemple #3
0
int _record(Buf *b, Undo **stk, int type, int lo, int hi, uint64_t timestamp) {
	
	Undo	*u, *tmp;
	int	i;
	
	if (hi<lo) {
		int tmp=hi;
		hi=lo;
		lo=tmp;
	}
	
	u=push(stk, malloc(sizeof *u));
	u->type=type;
	u->dat=0;
	u->lo=lo;
	u->hi=hi;
	u->car=CAR;
	u->grp=0;
	u->timestamp=timestamp;
	
	
	switch (type) {
	
	case UndoSwap:
		u->dat=getlines(b, lo, hi);
		break;
	
	case UndoDelete:
		u->dat=getlines(b, lo, hi);
		break;
	
	case UndoInsert:
		break;
	
	case UndoGroup:
		pop(stk);
		move(&u->grp, stk, hi);
		tmp = u->grp;
		for (i = 0; i < hi - lo - 1; i++)
			tmp = tmp->next;
		u->car = tmp->car;
		push(stk, u);
		break;
	
	}
	return 1;
}
Exemple #4
0
void main() {
  int len, i;
  char line[MAXLINE];
    while((len = getlines(line, MAXLINE)) > 0) {
      if(len >= LIM) {
        for(i = 0; i < len; i++) putchar(line[i]);
      }
    }
}
Exemple #5
0
main()
{
    char line[LINE_MAX];
    int len;

    while ((len = getlines(line, LINE_MAX)) > 0) {
        reverse(line);
        printf("%s\n", line);
    }
}
Exemple #6
0
main()
{
    char in_line[MAXLINE];
    int len;

    while ((len = getlines(in_line, MAXLINE)) > 0)
        printf("%s", in_line);

    return 0;
}
/* reverse input lines a line at a time */
int main(void) {
    char line[MAXLINE];         /* current input line */

    while (getlines(line, MAXLINE) > 0) {
        reverse(line);
        printf("%s", line);
    }

    return 0;
}
Exemple #8
0
main()
{
    char in_line[LINE_MAX];
    char out_line[LINE_MAX];
    int len;

    while ((len = getlines(in_line, LINE_MAX)) > 0) {
        entab(in_line, out_line); 
        printf("%s", out_line);
    }
}       
Exemple #9
0
main()
{
	int len,i;
	char s[MAXLINE];
	while ((len = getlines(s, MAXLINE)) > 0)
	if (len >0) 
	{
		for(i=len;i>=0;i--)
		printf("%c",s[i]);
	}
	return 0;
}
Exemple #10
0
int main() {

	int len;
	extern char result[];

	if ((len = getlines()) > 0) {
		replaceAndCopy(len);
	}

	printf("%s\n", result);

	return 0;
}
Exemple #11
0
// 打印最长输入行
main() {
    int len, max; //len是当前输入行长度,max最长输入行长度
    char line[MAXLINE], longest[MAXLINE]; //line用于存储当前行,longest用于存储最长行

    max = 0;
    while ((len = getlines(line, MAXLINE)) > 0)
        if (len > max) {
            max = len;
            copy(longest, line);
        }
    if (max > 0)
        printf("%s", longest);
    return 0;
}
Exemple #12
0
int main() {
	int len;

	extern char result[];

	if ((len = getlines()) > 0) {
		removeComments(len);
	}

	printf("\n%s\n%s\n", "Result:",result);

	return 0;

}
Exemple #13
0
main(){
  int len, max=0;
  char line[MAXLINE], longest[MAXLINE];
  
  while((len=getlines(line, MAXLINE))>0) {
    if(len > max){
      max = len;
      copy(longest, line);
    }
  }
  
  if(max > 0 ){
    printf("%s", longest);
  }
  return;
}
Exemple #14
0
/*readlines:read input lines*/
int readlines(char *lineptr[], int maxlines)
{
	int len, nlines;
	char *p, line[MAXLEN];

	nlines = 0;
	while((len = getlines(line, MAXLEN)) > 0)
		if(nlines >= maxlines || (p = alloc(len)) == NULL)
		   return -1;
	       else { 
		  line[len-1] = '\0'; /*delete newline*/
		  strcpy(p, line);
		  lineptr[nlines++] = p;
		  }
		return nlines;
}
Exemple #15
0
char * chars_fgets(chars p, size_t size,  FILE *stream) {
    char * buf = (char *)Malloc(MAXLINE);
    if (stream == NULL)
        return NULL;
    if (stream != stdin){
        size_t lines = getlines(stream, MAXLINE);
        while (lines--){
            fgets(buf, MAXLINE, stream);
            chars_append(p, buf);
        }
    } else {
        fgets(buf, MAXLINE, stream);
        chars_append(p, buf);
    }
    free(buf); 
    return p->s;
}
Exemple #16
0
int readlines(char *lineptr[],int max){				
	int len,nlines=0,i;
	char *p;
	char line[MAXLENTH];
	p=calloc(MAXLINE,MAXLENTH);				
	for(i=0;i<=MAXLINE;i++)
		lineptr[i]=NULL;
		i=0;
	while((len=getlines(line,MAXLENTH))>0){
		lineptr[i]=p;
		strcpy(lineptr[i],line);
		p+=1+len;
		nlines++;	
		i++;
	}
	return nlines;
}
int main()
{
  int len;                //current line length
  int max;                //max line length seen so far
  char line[MAXLINE];     //current input line
  char longest[MAXLINE];  //longest line saved here

  max = 0;
  while((len = getlines(line, MAXLINE)) > 0)
    if (len > max)
    {
    max = len;
    copy(longest, line);
    }
  if (max > 0)
    printf("%s", longest);
  return 0;
}
Exemple #18
0
main(){	

	int len;		/* CURRENT LINE LENGTH */
	int max; 		/* MAXIMUM LENGTH SEEN SO FAR */
	char line[MAXLINE];	/* CURRENT INPUT LINE */
	char longest[MAXLINE];	/* LONGEST LINE SAVED HERE */
	

	max = 0;
	while ((len = getlines(line, MAXLINE)) > 0)
		if (len > max){
		   max = len;
		   copy(longest, line);
		}
	if (max > 0)   /*there was a line */
		printf("%s", longest);
	return 0;
	}
Exemple #19
0
int main(int argc, char const *argv[])
{
    int len;   //当前行的长度
    int max;   //已处理行的最大长度
    char line[MAXLINE];	//当前输入行
    char longest[MAXLINE];	//所保存的最长行

    max = 0;
    while ((len = getlines(line,MAXLINE)) > 0)
        if (len > max)
        {
            max = len;
            copy(longest,line);
        }
    if (max > 0)
    {
        printf("%s\n", longest);
    }
    return 0;
}
int main(int argc, char *argv[])
{
    int nlines = 0;
    int numeric = 0;

    if (argc > 1 && strcmp(argv[1], "-n") == 0) {
        numeric = 1;
    }

    if ((nlines = getlines(lineptr, MAXLINES)) >= 0) {
        qsort1((void **) lineptr, 0, nlines-1, 
              (int (*)(void *, void *)) (numeric ? numcmp : strcmp) );
        printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
        printlines(lineptr, nlines);
        printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
    } else {
        printf("error in reading lines \n");
    }

    return 0;
}
main()
{
        int len;
        int max;
        char line[MAX];
        char longest[MAX];

        max = 0;
        while((len = getlines(line, MAX)) > 0)
        {
                printf("the line's long is %d\n",len);
                if (len > max){
                        max = len;
                        copy(longest, line);
                }

                if (len > 80){
                        printf("%s\n", longest);
                }
        }
        return 0;
}
Exemple #22
0
main () {
    int length;
    int limit = 100;
    char line[limit];

    while ((length = getlines(line, limit)) > 0) {
        print_line(line);
        printf("length: %d\n", len(line));
        char reversed_line[limit];
        reverse(line, reversed_line);
        print_line(reversed_line);

        int i;
        int index = rstrip_index(line);
        char array[index + 1];
        for (i = 0; i <= index; ++i) {
            array[i] = line[i];
        }
        array[index + 1] = '\0';
        printf("\nrstrip: ");
        print_line(array);
    }
}
Exemple #23
0
/* print longest input line; specialized version	*/
int main()
{
	int len;
	//extern int max;
	//extern char longest[];

	max = 0;
	while ( ( len = getlines() ) > 0 ) {

		if (len > max ) {

			max = len;
			copy();
		}
	}

	if ( max > 0 ) {			/* there was a line		*/
	
		printf("%s", longest);

	}
	
	return 0;
}
Exemple #24
0
int main()
{
	int len;
	int max = 0;
	char line[MAXLINE];
	char longest[MAXLINE];

	while((len = getlines(line,MAXLINE)) > 0)
	{
		// if(len > max)
		// {
		// 	max = len;
		// 	copy(longest,line);
		// }
		printf("%s\n",line);

	}

	// if(max > 0)
	// {
	// 	printf("%s",longest);
	// }
	return 0;
}
Exemple #25
0
main()
{
	double s[1],z[26];
	int flag[26];
	double a;
	double b,op;
	int op1,op2,n,xp;
	int type,i=0,j;
	for(j=0;j<26;++j)
		flag[j]='\0';
l: printf("start");
	while((type=getlines(s))!=EOF){
		if(type=='~'){loo: printf("exiting");goto l;break;}
		b=s[i];
		int v=b;
printf("returnop=%d\t%f",opr,b);
		if(type>='a'&&type<='z'){
			if(flag[type-'a']!=1){
				z[type-'a']=save();
				flag[type-'a']=1;
//				printf("%f\n",z[type-'a']);
			}
			else 
				push(z[type-'a']);
}
if(type==0)push(b);
/*if(opr=='+') push(pop()+pop()); if(opr=='\n')printf("\nSUM=%f\n",pop());*/
		switch(opr){
			
			case 0:
				push(b);
				break;
			case '+':
				push(pop()+pop());
				break;
			case '#':
				op1=pop();
                                op=sin(op1);
				push(op);
                                break;
                        case '!':
                                op1=pop();
                                op=cos(op1);
                                push(op);
                                break;
			case '@':
                                op1=pop();
                                op=exp(op1);
                                push(op);
                                break;
                        case '$':
                                op1=pop();
                                op=tan(op1);
                                push(op);
                                break;
			case '^':
                                op1=pop();
				op2=pop();
				xp=op2;
                                op=op1;
				op=pow(xp,op);
                                push(op);
                                break;


			case '*': 
                                push(pop()*pop());
                                break;
			case '/': 
				op=pop();
                                push(pop()/op);
                                break;
			case '-': 
				op=pop();
                                push(pop()-op);
                                break;
			case '%': 
				op1=pop();
				op2=pop();
				op=op2%op1;
//printf("%d",op1);
                                push(op);
                                break;
			case '\n':
				printf("\nSUM=%f\n",pop());
//				swap();
				printf("clear satck?");
				scanf("%d",&n);
				if(n==1){
					clear();
					type=EOF;
					n=0;
					for(j=0;j<26;++j){
                				flag[j]='\0';
						z[j]='\0';
					}
					while(getchar()!='\n');
					goto loo;
				}
				else{
					while(getchar()!='\n');
					goto loo;
				}
				break;
			default:
				break;
		}	
	}
}
Exemple #26
0
int dpf(int argc, char *argv[], int retc, char *retv[])
/*************/
{ int groups;
  int noisemult_p = 0;
  int numlines,maxlines;
  int i;
  int donll = TRUE;
  int noneg = FALSE;
  int top = FALSE;
  char command[128];
  char name[64];

  (void) retc;
  (void) retv;
  Wturnoff_buttons();
  leader_len = 20.0;
  axish = FALSE;
  axisp = FALSE;
  axisp_freq = 1.0;
  if (argc > 1)
  {
    for (i=1; i<argc; i++)
    {
      if (strcmp(argv[i],"off") == 0) {
	set_dpf_flag(0,"");
        redo_dpf_dpir();
	RETURN;
      } else if (strcmp(argv[i],"turnoff") == 0) {
        set_dpf_flag(0,"");
        RETURN;
      } else if (strcmp(argv[i],"noll") == 0) donll = FALSE;
      else if (strcmp(argv[i],"pos") == 0) noneg = TRUE;
      else if (strcmp(argv[i],"top") == 0) top = TRUE;
      else if (strcmp(argv[i],"axish") == 0) axish = TRUE;
      else if (strcmp(argv[i],"axisp") == 0)
      {
         axisp = TRUE;
         P_getreal(PROCESSED,"sfrq",&axisp_freq,1);
      }
      else if (strcmp(argv[i],"leader") == 0)
      {
         if (((i+1) < argc) && isReal(argv[i+1]) )
         {
            i++;
            leader_len = stringReal(argv[i]);
         }
      }
      else if (isReal(argv[i])) noisemult_p = i;
    }
  }
  if (donll) /* if not donll, dpf uses last previous line listing */
  {
    if (noisemult_p != 0)
    {
      if (noneg)
	strcpy(command,"nll('dpf','pos',");
      else
	strcpy(command,"nll('dpf',");
      strcat(command,argv[noisemult_p]);
      strcat(command,")\n");
    }
    else
    {
      if (noneg)
	strcpy(command,"nll('dpf','pos')\n");
      else
	strcpy(command,"nll('dpf')\n");
    }
    execString(command);
  }

  if(P_getreal(CURRENT, "dpf_sc2",&dpf_sc2,1)) dpf_sc2=sc2;
  if(P_getreal(CURRENT, "dpf_wc2",&dpf_wc2,1)) dpf_wc2=wc2;
  if(dpf_wc2>wc2) dpf_wc2=wc2;
  if(dpf_sc2<sc2) dpf_sc2=sc2;

  /* if (init2d(1,1)) return(ERROR); */
  scale = vs;
  if (normflag)
    scale *= normalize;
  /*   Wscrprintf("normflag=%d normalize=%g\n",normflag,normalize); */
  plot = (argv[0][0] == 'p');

/*select_init(get_rev, dis_setup, fdimname, doheaders, docheck2d, dospecpars,
            	doblockpars, dophasefile)*/
/*if (init2d(0,plot + 1)) return(ERROR); */
  if (select_init(
	0,
	plot+1,
	NO_FREQ_DIM,
	NO_HEADERS,
	DO_CHECK2D,
	DO_SPECPARS,
	NO_BLOCKPARS,
	NO_PHASEFILE
     ))
      return(ERROR);
  if ((numlines = getlines(noneg)) == 0) RETURN;
  if (!plot)
  {
    setwindows();
    dispcalib = (float) (mnumypnts-ymin) / (float) wc2max;

    getOptName(PEAK_MARK,name);
    set_line_thickness(name);
    getOptName(PEAK_NUM,name);
    set_graphics_font(name);
    
  }
  else
  { 
    double size = G_getCharSize("PeakNum");
    charsize(size);
    //charsize((double)0.7);
    dispcalib = ppmm / ymultiplier;
  }
  CharSize = ycharpixels + ycharpixels / 5;
  maxlines = dnpnt / CharSize;

  if (maxlines < numlines)
    remove_lines(maxlines,&numlines);
  if (numlines > 0)
  {
    //color(PARAM_COLOR);
    color(PEAK_MARK_COLOR);
    groups = groupcheck(numlines);
    if (debug1)
    {
      Wscrprintf("index high low newhigh newlow highlimit lowlimit\n");
      for (i = 1; i <= groups; i++)
        Wscrprintf("%d %d %d %d %d %d %d\n",i,ga[i].high,ga[i].low,
                   ga[i].newhigh,ga[i].newlow,ga[i].highlimit,ga[i].lowlimit);
    }
    label_proc = (top) ? (PFV) label_top : (PFV) label_bot;
    for (i = 1; i <= groups; i++)
      label_group(i);

    if (!plot) { // construct the command, and set the flag and command
      char cmd[64];
      if(argc > 1) {
        if (isReal(argv[1]) ) sprintf(cmd,"%s(%s",argv[0],argv[1]);
	else sprintf(cmd,"%s('%s'",argv[0],argv[1]);
	for(i=2;i<argc;i++)
        {
           if (isReal(argv[i]) )
           {
	      strcat(cmd,",");
              strcat(cmd,argv[i]);
           }
	   else
           {
	      strcat(cmd,",'");
              strcat(cmd,argv[i]);
	      strcat(cmd,"'");
           }
	}
	strcat(cmd,")\n");
      } else sprintf(cmd,"%s\n",argv[0]);
      Wsetgraphicsdisplay("ds");
      set_dpf_flag(1, cmd);
    }
  }
  releaseAllWithId("dpf");
  endgraphics();
  disp_status("        ");
  set_graphics_font("Default");
  RETURN;
}
Exemple #27
0
int main(void) {
  getlines();
  print_summary();
  return 0;
}
Exemple #28
0
main(){
FILE *fp;
fp=fopen("all_callisto4.txt", "r");
if (fp==NULL){
    printf("failed to open file \n");
    return -1;
}


    int counter=0;
    int c;
    while((c=fgetc(fp))!=EOF){
    if (c=='\n'){
        counter++;
    }
    }

    rewind(fp);
    printf("there are %d+1 lines \n",counter);

    int max_lines=counter+1;
    int max_char=2808;
    char **all_lines;
    all_lines=malloc(sizeof(char*)*max_lines);

    int i=0;
    for (i;i<max_lines;i++){
        all_lines[i]=malloc(sizeof(char)*max_char);
    }
    int n_lines=getlines(all_lines, max_lines, max_char, fp);

    printf("n_lines is %d \n", n_lines);


    titles ** titles_head=malloc(sizeof(titles*));
    *titles_head=NULL;
    int n_titles=title_find(all_lines,n_lines,titles_head, max_title_length);
    printf("%d titles\n",n_titles);

    FILE *text_file;
    text_file=fopen("titles_callisto", "wb");
    print_titles(*titles_head, text_file);
    fclose(text_file);

    int n_posts=line_find(all_lines,n_lines,job_id,job_id_len);
    printf("there are %d job posts\n",n_posts);

    counter=line_find(all_lines,n_lines,"Location:",9);
    printf("there are %d Locations\n",counter);
    counter=line_find(all_lines,n_lines,"Job Location(s):",16);
    printf("there are %d Location(s)\n",counter);
    counter=line_find(all_lines,n_lines,"Description:",12);
    printf("there are %d Descriptions\n",counter);
    counter=line_find(all_lines,n_lines,"Job Function:",13);
    printf("there are %d Job Functions\n",counter);
    counter=line_find(all_lines,n_lines,"Job Functions:",16);
    printf("there are %d Job Functions\n",counter);

    title_lists *all_titles=sep_titles("titles_callisto",n_titles,max_title_length);

    job_posts * head_post=parse_posts(all_lines, all_titles, n_lines);

    filter_posts(head_post,all_lines,n_posts);

    return 0;

}
Exemple #29
0
int main(int argc,char *argv[]){
	FILE *file;
	int lines,i;
	char *pos;
	int split=':';
	char buf[512];
	float alpha=0.5;
	float mean;
	float sv;
	int *lset,*sset,*ka;
	//socket part variable statement
	struct sockaddr_in serv;
	int sd;
	if(argc<2)
	{
		printf("usage:./a.out servaddr\n");
		return -1;
	}
	if((file=fopen(PATH,"r"))==NULL)	
	{
		printf("open file error\n");
		return -1;
	}
	lines=getlines(file);	
	int *h=malloc(lines*sizeof(int));
	//int *h=malloc(8000*sizeof(int));
	int line=0;
	if(h==NULL)
	{
		printf("malloc h error\n");
		return -1;
	}
	//reset the file point
	fseek(file,0L,SEEK_SET);
	//printf("current file offset:%d\n",(int)ftello(file));
	while(fgets(buf,sizeof(buf),file)){
		pos=strrchr(buf,split);
		if(pos==NULL)
		{
			printf("wrong format\n");
			return -1;
		}
		buf[strlen(buf)-3]='\0';
		pos+=2;
		h[line++]=atoi(pos);
		printf("%d\n",h[line-1]);
	}
	mean=c_mean(h,lines);
	sv=c_sig(h,lines,mean);	
	printf("%.2f\n",mean);
	printf("%.2f\n",sv);
	qp=mean+alpha*sv;
	qs=mean-alpha*sv;
	printf("%.2f\n",qp);
	printf("%.2f\n",qs);
	if(seq(h,lines,&lset)<0)
	{
		printf("seq error\n");
		return -1;
	}
	//test lset
	printf("lset size:%d\n",lset[0]);
	for(i=1;i<=lset[0];i++)
	{
		printf("%d ",lset[i]);	
	}
	//socket logic to send L,so you had better check forward logic;
	//sockaddr init
	bzero(&serv,sizeof(struct sockaddr_in));	
	serv.sin_family=AF_INET;
	serv.sin_port=htons(PORT);
	serv.sin_addr.s_addr=inet_addr(argv[1]);
	if((sd=socket(AF_INET,SOCK_STREAM,0))<0)
	{
		printf("socket error\n");
		return -1;
	}
	if(connect(sd,(const struct sockaddr *)&serv,sizeof(struct sockaddr))<0)
	{
		printf("connect error\n");
		return -1;
	}
	//send lset,the algorithm select a random subset of lset,we set lset directly here 
	write(sd,lset,(lset[0]+1)*sizeof(int));
	int len;
	printf("wait for sset from bob\n");
	read(sd,&len,sizeof(int));
	printf("sset from bob comes\n");
	printf("sset len:%d\n",len);
	sset=malloc((len+1)*sizeof(int));
	sset[0]=len;
	if(sset==NULL){
		printf("malloc sset error\n");
		return -1;
	}
	read(sd,sset+1,len*sizeof(int));
	//sset test
	for(i=1;i<=len;i++)
	{
		printf("%d ",sset[i]);
	}
	printf("\n");
	close(sd);
	//generate key
	if(key_gen(h,sset,&ka)==-1)
	{
		printf("key_gen error\n");
		return -1;
	}
	for(i=0;i<sset[0];i++){
		printf("%d",ka[i]);
	}
	printf("\n");
	return 0;
}