void check(Str... r){ if(!checkexist(r...)){ std::cerr<<checkstr(r...)<<" must be specified."<<std::endl; std::exit(1); } }
void test_cmsg_nexthdr() { struct msghdr mh; struct cmsghdr cmh; struct cmsghdr *cmhp, *cmhnextp; char ancbuf[10240]; char magic[] = "MAGIC"; set_funcname("test_cmsg_nexthdr", sizeof("test_cmsg_nexthdr")); /* * Test: More than one cmsghdr */ init_hdrs(&mh, &cmh, ancbuf, sizeof(ancbuf)); mh.msg_control = (caddr_t)ancbuf; mh.msg_controllen = CMSG_SPACE(0) * 2; /* 2 cmsghdr with no data */ cmh.cmsg_len = CMSG_LEN(0); /* * Copy the same instance of cmsghdr twice. Use a magic value * to id the second copy. */ bcopy((void *)&cmh, (void *)ancbuf, sizeof(cmh)); strlcpy((char *)&cmh, (const char *)&magic, sizeof(magic)); bcopy((void *)&cmh, (void *)((caddr_t)ancbuf + CMSG_SPACE(0)), sizeof(cmh)); cmhp = CMSG_FIRSTHDR(&mh); cmhnextp = CMSG_NXTHDR(&mh, cmhp); checkstr((const char *)&magic, (const char *)cmhnextp, sizeof(magic), "more than one cmsghdr\0"); /* * Test: only one cmsghdr */ init_hdrs(&mh, &cmh, ancbuf, sizeof(ancbuf)); mh.msg_control = (caddr_t)ancbuf; mh.msg_controllen = CMSG_SPACE(0); cmh.cmsg_len = CMSG_LEN(0); bcopy((void *)&cmh, (void *)ancbuf, sizeof(cmh)); cmhp = CMSG_FIRSTHDR(&mh); cmhnextp = CMSG_NXTHDR(&mh, cmhp); checkptr(NULL, (caddr_t)cmhnextp, "only one cmsghdr\0"); /* * Test: NULL cmsg pointer */ init_hdrs(&mh, &cmh, ancbuf, sizeof(ancbuf)); mh.msg_control = (caddr_t)ancbuf; mh.msg_controllen = sizeof(ancbuf); cmh.cmsg_len = sizeof(ancbuf); bcopy((void *)&cmh, (void *)ancbuf, sizeof(cmh)); cmhp = CMSG_FIRSTHDR(&mh); cmhnextp = CMSG_NXTHDR(&mh, NULL); checkptr((caddr_t)cmhp, (caddr_t)cmhnextp, "null second argument\0"); }
int main() { char* s[40]; printf(">>>"); gets(s); if (checkstr(s) == 1) printf("+"); else printf("-"); return 0; }
int ft_atoi_base(char *str, char *base) { if (!checkbase(base)) return (-506); if (!find(base, '-') && !find(base, '+')) return (-505); if (ft_strlen(str) == 0) return (-504); if(ft_strlen(base) <= 1) return (-503); if(!checkstr(str, base)) return (-502); return ft_atoi_base_r(str, base); }
void ProtoSendMode(void* uv, TargetTypeFlags, void*, const std::vector<std::string>& result, const std::vector<TranslateType>&) { User* user = (User*)uv; std::string checkstr(":"); checkstr.append(ServerInstance->Config->ServerName); checkstr.append(" 304 "); checkstr.append(user->nick); checkstr.append(" :CHECK modelist"); for(unsigned int i=0; i < result.size(); i++) { checkstr.append(" "); checkstr.append(result[i]); } user->SendText(checkstr); }
void test_cmsg_firsthdr() { struct msghdr mh; struct cmsghdr cmh; struct cmsghdr *cmhp; char ancbuf[1024]; char magic[] = "MAGIC"; set_funcname("test_cmsg_firsthdr", sizeof("test_cmsg_firsthdr")); /* CMSG_FIRSTHDR() where msg_control is NULL */ init_hdrs(&mh, NULL, NULL, 0); mh.msg_control = NULL; cmhp = CMSG_FIRSTHDR(&mh); checkptr(NULL, (caddr_t)cmhp, "msg_control is NULL\0"); /* - where msg_controllen < sizeof cmsghdr */ init_hdrs(&mh, NULL, NULL, 0); mh.msg_control = (caddr_t)&cmh; mh.msg_controllen = sizeof(cmh) - 1; cmhp = CMSG_FIRSTHDR(&mh); checkptr(NULL, (caddr_t)cmhp, "msg_controllen < sizeof cmsghdr\0"); /* - where msg_controllen == 0 */ init_hdrs(&mh, NULL, NULL, 0); mh.msg_control = (caddr_t)&cmh; mh.msg_controllen = 0; cmhp = CMSG_FIRSTHDR(&mh); checkptr(NULL, (caddr_t)cmhp, "msg_controllen == 0\0"); /* no errors */ init_hdrs(&mh, &cmh, ancbuf, sizeof(ancbuf)); memset((void *)ancbuf, 0, sizeof(ancbuf)); mh.msg_control = (caddr_t)ancbuf; mh.msg_controllen = sizeof(ancbuf); strlcpy((char *)&cmh, (const char *)&magic, sizeof(magic)); bcopy((void *)&cmh, (void *)ancbuf, sizeof(cmh)); cmhp = CMSG_FIRSTHDR(&mh); checkstr((const char *)&magic, (const char *)cmhp, sizeof(magic), "with payload\0"); }
std::string checkstr(First f,Second s,Rest...r){ return std::string(f)+" and "+checkstr(s,r...); }
int main(void) { int ii,iii; char temp='\0'; char *symbl = "+-*/^qQ1234567890()ehH .E"; // All the characters that will be used in the future char *symbl3 = "1234567890."; printf("Simple Calculator\n"); /* Start the while loop which will end only if q is entered. */ while(1) { double result1=0.000000; int i4,i5=0,times,marker=0,tt=0,emarker=0,divide_zero=0; char message[255],message2[255],message3[255],p[255]; printf(">>> ");fflush(stdout); // Print the prompt and flush it out (needed on Windows system). /* Start cleaning the string */ for (ii=0;ii<255;ii++){ message2[ii]=temp; message3[ii]=temp; message[ii]=temp; p[ii]=temp; } /* End cleaning the string */ // Read from user using fgets fgets(message2, sizeof(message2), stdin); /* Start deleting whitespace*/ message2[strlen(message2)-1]=temp; for (i4=0;i4<(strlen(message2));i4++){ if ((message2[i4]!=symbl[22])&&(message2[i4]!=temp)){ message3[i5]=message2[i4]; i5=i5+1; } } /* End deleting whitespace*/ /* Start replacing enotation with normal decimal */ if (strcmp(message3,enotation(message3))){// check if there is e notation emarker=1; } else{ emarker=0; }; strcpy(message3,enotation(message3)); /* End replacing enotation with normal decimal */ strcpy(message,message3); strcpy(p,message); /* Messages that responding the command q and h */ if (((p[0]==symbl[6])||(p[0]==symbl[5]))&&(strlen(message)==1)){ printerr(1); exit(0); } if (((p[0]==symbl[20])||(p[0]==symbl[21]))&&(strlen(message)==1)){ marker=1; printerr(2); for (ii=0;ii<255;ii++){ message2[ii]=temp; message[ii]=temp; p[ii]=temp; } continue; } /* Start using functions checkstr and checkstr4 to detect error inputs and print error message */ if (!checkstr(message)||checkstr4(message,emarker) ||((message[0]==symbl[5])||(message[0]==symbl[6]))||(((message[0]==symbl[20])||(message[0]==symbl[21]))&&(marker!=1))){ printerr(3); for (ii=0;ii<255;ii++){ // Clean up the string message2[ii]=temp; message[ii]=temp; p[ii]=temp; } continue; } /* End using functions checkstr and checkstr4 to detect error inputs and print error message */ // Find how many loops does it need to eliminate all the () times=checkstr3(message); { for (iii=0;iii<=times;iii++){ int i1=0,i2,z=0,z2=0,pos1=0,pos2=-1; int j1=0; int k=0,k1=0,k2=0; double n[255]; char str3[255],temp1[255],temp2[255],temp3[255]; tt=0; /* Start finding the inner () pair */ for (i1=0;i1<(strlen(message));i1++){ if ((message[i1]==symbl[17])&&(pos2==-1)){pos1=i1;} if ((message[i1]==symbl[18])&&(pos2==-1)){pos2=i1;} } /* End finding the inner () pair */ strcpy(temp1,message); /* Start putting the content inside the () to message */ for (i1=0;i1<255;i1++){ // Clean up the string message[i1]=temp;n[i1]=temp;str3[i1]=temp;} for (i1=0;i1<=(pos2-pos1-2);i1++) {message[i1]=temp1[pos1+i1+1]; } if (iii==times){strcpy(message,temp1);} k1=-1; k2=-1; for (i1=0;i1<(strlen(message));i1++){ k=0; for (j1=0;j1<strlen(symbl3);j1++){ if (message[i1]==symbl3[j1]){ k=1; } } /* End putting the content inside the () to message */ // Start getting the number from the string char str2[255]; if (i1==(strlen(message)-1)){k2=i1; if (k1==-1){k1=k2;} for (i2=k1;i2<=k2;i2++){ str2[i2-k1]=message[i2]; } sscanf(str2, "%lf", &n[z]); // Put characters to decimal numbers if ((message[0]==symbl[1])&&(tt==0)){ tt=1;n[0]=(-1)*n[0]; } z=z+1; k=0; k1=-1; k2=-1; for (i2=0;i2<255;i2++){ str2[i2]=temp; } continue; } if ((k1!=-1)&&(k!=1)){ k2=i1-1; for (i2=k1;i2<=k2;i2++){ str2[i2-k1]=message[i2]; } str3[z2]=message[i1]; z2=z2+1; sscanf(str2, "%lf", &n[z]); // Put characters to decimal numbers // End getting the number from the string // Clear the string and other variables. z=z+1; k=0; k1=-1; k2=-1; for (i2=0;i2<255;i2++){ str2[i2]='\0'; } continue;} if ((k==1)&&(k1==-1)){k1=i1;} } {long int length,i5,i6,count=0; int b[255]; length=strlen(str3); /* Start checking if there is a subtraction operator followed by a negative sign */ for (i6=0;i6<(strlen(message)-1);i6++){ if (strlen(message)!=0){ if ((message[i6]==symbl[0])||(message[i6]==symbl[1])||(message[i6]==symbl[2])||(message[i6]==symbl[3])||(message[i6]==symbl[4])){ b[count]=0; if ((message[i6]==symbl[1])&&(message[i6+1]==symbl[1])){ b[count]=1; } count=count+1; }}} /* End checking if there is a subtraction operator followed by a negative sign */ /* Start computing the value of the expression */ while (str3[0]!=temp){ int pos; pos=priority(str3); // Find which operation in the expression goes first if (b[pos]==1) { n[pos+1]=(-1.0)*n[pos+1]; } // if divide by zero, the print the error message as below and break if (n[pos+1]==0){ printerr(4); fflush(stdout); divide_zero=1; break; } n[pos]=compute(str3[pos],n[pos],n[pos+1]); // Store the result in n[pos] for (i5=pos+1;i5<length;i5++){ n[i5]=n[i5+1]; } for (i5=pos;i5<(length-1);i5++){ str3[i5]=str3[i5+1]; } str3[length-1]=temp; length=length-1; } /* End computing the value of the expression */ if (divide_zero==1){break;} result1=n[0]; snprintf(temp2,255,"%f",n[0]); // Put decimal numbers to string } /* Start cleaning up the string and put all the parts back to a string */ for (i1=0;i1<255;i1++){ message[i1]=temp; } for (i1=0;i1<pos1;i1++){ message[i1]=temp1[i1]; } strcat(message,temp2); for (i1=0;i1<((strlen(temp1)-pos2));i1++){ if ((strlen(temp1)-pos2)!=1){ temp3[i1]=temp1[i1+pos2+1]; } } temp3[(strlen(temp1)-pos2)]=temp; strcat(message,temp3); for (i1=0;i1<255;i1++){ temp3[i1]=temp; temp2[i1]=temp; } /* End cleaning up the string and put all the parts back to a string */ if (divide_zero==1){break;} }} if (divide_zero==1){continue;} // Print out the result printf("%.6f\n",result1); // Clear the variables for (ii=0;ii<255;ii++){ message2[ii]=temp; message[ii]=temp; p[ii]=temp;} fflush(stdout); } /* End of the while loop */ return 0; }
int main(void) { int ii,iii; char temp='\0'; char *symbl = "+-*/^qQ1234567890()ehH ."; char *symbl3 = "1234567890"; printf("Advanced Calculator\n"); while(1) { double result1=0.000000; int i4,i5=0,times; long int z33=0; char message[255]; char message2[255]; char num[255]; char p[255]; // int *p2; // for future numbers function use // int length; printf(">>> ");fflush(stdout); for (ii=0;ii<=255;ii++){ message2[ii]=temp; message[ii]=temp; num[ii]=temp; p[ii]=temp;} fgets(message2, sizeof(message2), stdin); /* start deleting whitespace*/ message2[strlen(message2)-1]=temp; printf("M2 %s stelen %d\n",message2,strlen(message2));fflush(stdout); for (i4=0;i4<(strlen(message2));i4++){ printf("%d ",i4); // -1?? if ((message2[i4]!=symbl[22])&&(message2[i4]!=temp)){ message[i5]=message2[i4]; printf("%c\n",message[i5]); i5=i5+1; } } //message2[strlen()]=temp; /* end deleting whitespace*/ printf("M %s strlen M %d\n",message,strlen(message));fflush(stdout); strcpy(p,message); if (((p[0]==symbl[6])||(p[0]==symbl[5]))&&(strlen(message)==1)){printf("Goodbye!\n");exit(0);} //\n needed? if (((p[0]==symbl[20])||(p[0]==symbl[21]))&&(strlen(message)==1)){printf("Simple Calculator understands the following arithmetic operations:\n^ exponentiation\n+ addition\n- subtraction\n* multiplication\n/ division\n");for (ii=0;ii<=255;ii++){ message2[ii]=temp; message[ii]=temp; num[ii]=temp; p[ii]=temp;}continue;} //\n needed? if (!checkstr(message)){printf("Error: Illegal input!\n");for (ii=0;ii<=255;ii++){ message2[ii]=temp; message[ii]=temp; num[ii]=temp; p[ii]=temp;}continue;} // \n needed? times=checkstr3(message); // length=strlen(message); { for (iii=0;iii<=times+1;iii++){ int i1=0,i2,z=0,z2=0,pos1=0,pos2=-1; int j1=0; int k=0,k1=0,k2=0; int n[255]; char str3[255]; char temp1[255]; char temp2[255]; char temp3[255]; for (i1=0;i1<(strlen(message));i1++){ if ((message[i1]==symbl[17])&&(pos2=-1)){pos1=i1;}// -1?? printf("leng%d\n",strlen(message)); if ((message[i1]==symbl[18])&&(pos2=-1)){pos2=i1;} } strcpy(temp1,message); for (i1=0;i1<=255;i1++){ message[i1]=temp;} for (i1=0;i1<=(pos2-pos1-2);i1++) {message[i1]=temp1[pos1+i1+1]; } if (iii==times){strcpy(message,temp1);} // printf("temp %s message %s\n",temp1,message); k1=-1; k2=-1; for (i1=0;i1<(strlen(message));i1++){ // strlen(message)-1 ?? k=0; //printf("%d %d %d\n",i,j,k); for (j1=0;j1<strlen(symbl3);j1++){ //-1 or not depends on what is inside the strlen if (message[i1]==symbl3[j1]){ k=1; } } // printf("%d %d %d\n",i1,k,k1); char str2[255]; if (i1==(strlen(message)-1)){k2=i1; if (k1==-1){k1=k2;}//printf("k2 %d k1 %d\n",k2,k1); //i1 or i1-1? strlen(message)-2 ?? for (i2=k1;i2<=k2;i2++){ str2[i2-k1]=message[i2]; } n[z]=atoi(str2); // printf("%c\n",str2[0]); // printf("%d\n",n[z]); z=z+1; k=0; k1=-1; k2=-1; for (i2=0;i2<=255;i2++){ str2[i2]=temp; } continue; } // printf("i1 %d k %d \n",i1,k); if ((k1!=-1)&&(k!=1)){k2=i1-1; // printf("here1\n"); // i1 or i1-1? for (i2=k1;i2<=k2;i2++){ str2[i2-k1]=message[i2]; } str3[z2]=message[i1]; z2=z2+1; n[z]=atoi(str2); // printf("%d %c\n",n[z],str3[z2-1]); z=z+1; k=0; k1=-1; k2=-1; for (i2=0;i2<=255;i2++){ str2[i2]=temp; } continue;} //atoi need to be replaced by atof if ((k==1)&&(k1==-1)){k1=i1;} //printf("k1 %d\n",k1); // if ((k1!=-1)&&(k==1)){} } {long int length,i5; double result; length=strlen(str3); // printf("length %d",length); while (str3[0]!=temp){int pos; printf("This point 1\n");fflush(stdout); pos=priority(str3); printf("This point 3\n");fflush(stdout); //printf("pri %d\n",pos); n[pos]=compute(str3[pos],n[pos],n[pos+1]); if (n[pos]==2315793) {z33=2315793;} // incorrect! // printf("n[pos] %d\n",n[pos]); for (i5=pos+1;i5<length;i5++){ n[i5]=n[i5+1]; } for (i5=pos;i5<(length-1);i5++){ str3[i5]=str3[i5+1]; } str3[length-1]=temp; length=length-1; // printf("z33 %d\n",z33); }result1=n[0];result=n[0];//z33=z3; //if (z3!=2315793){printf("result1 %d\n",n[0]);} sprintf(temp2,"%d",n[0]);// incorrect! fcvt!! } for (i1=0;i1<=255;i1++){ message[i1]=temp;} /*for (i1=0;i1<=(strlen(temp1)+strlen(temp2)-1-(pos2-pos1));i1++){//printf("i1 %d\n",i1); if (i1<pos1){message[i1]=temp1[i1];} if (((i1+1)>pos1)&&((i1+1)<(pos1+strlen(temp2)))){message[i1]=temp2[i1-pos1];} if ((i1+1)>=(pos1+strlen(temp2))){message[i1]=temp1[pos2+1-((i1+1)-(pos1+strlen(temp2)))];} }*/ for (i1=0;i1<pos1;i1++){ message[i1]=temp1[i1]; } strcat(message,temp2); for (i1=0;i1<(strlen(temp1)-pos2);i1++) {temp3[i1]=temp1[i1+pos2+1];} strcat(message,temp3); // printf("%s\n",message); for (i1=0;i1<=255;i1++){ temp3[i1]=temp; temp2[i1]=temp;} } }if (z33!=2315793){printf("%.6f\n",result1);}z33=0; /* int i=0; int j=0; while ((p[i]!=symbl[0])&&(p[i]!=symbl[1])&&(p[i]!=symbl[2])&&(p[i]!=symbl[3])) {num[i]=message[i];i=i+1;} //num[i-1]=temp; for (j=0;j<i;j++){ // printf("%c",num[j]); } //%.6f printf("\n");*/ for (ii=0;ii<=255;ii++){ message2[ii]=temp; message[ii]=temp; num[ii]=temp; p[ii]=temp;}fflush(stdout); } return 0; }
zysst() { IATYPE whence, temp; FILEPOS offset; register struct fcblk *fcb = WA (struct fcblk *); register struct ioblk *iob = MK_MP(fcb->iob, struct ioblk *); register struct icblk *icp; /* ensure iob is open, fail if unsuccessful */ if ( !(iob->flg1 & IO_OPN) ) return EXIT_3; #if PIPES /* not allowed to do a set of a pipe */ if ( iob->flg2 & IO_PIP ) return EXIT_4; #endif /* PIPES */ /* whence may come in either integer or string form */ icp = WC( struct icblk * ); if ( !getint(icp,&whence) ) return EXIT_1; #if SETREAL /* offset comes in as a real in RA */ offset = RA(FILEPOS); #else /* offset may come in either integer or string form */ icp = WB( struct icblk * ); if ( !getint(icp,&temp) ) { struct scblk *scp; scp = (struct scblk *)icp; if (!checkstr(scp) || scp->len != 1) return EXIT_1; temp = whence; switch (uppercase(scp->str[0])) { case 'P': whence = 0; break; case 'H': temp = (whence << 15) + ((int)doset(iob,0,1) & 0x7FFFL); whence = 0; break; case 'R': whence = 1; break; case 'E': whence = 2; break; case 'C': if ( fcb->mode == 0 && temp > 0 && temp <= (word)maxsize ) { fcb->rsz = temp; temp = 0; whence = 1; /* return current position */ break; } else { if (temp < 0 || temp > (word)maxsize) return EXIT_2; else return EXIT_1; } default: return EXIT_1; /* Unrecognised control */ } } offset = (FILEPOS)temp; #endif /* finally, set the file position */ offset = doset( iob, offset, (int)whence ); /* test for error. 01.02 */ if ( offset < (FILEPOS)0 ) return EXIT_5; #if SETREAL /* return resulting position in RA. 01.07 */ SET_RA( offset ); #else /* return resulting position in IA. 01.02 */ SET_IA( (IATYPE)offset ); #endif /* normal return */ return NORMAL_RETURN; }