void write_system_call( FILE *file, struct function *f ) { if( f->options->indirect ) { fprintf(file,"\t\t\t#ifdef SYS_%s\n",f->options->indirect->text); if(!is_void(f->type)) { fprintf(file,"\t\t\t\tresult = "); } else { fprintf(file,"\t\t\t\t"); } if(f->params) { fprintf(file,"syscall(SYS_%s,SYS_%s,%s);\n",f->options->indirect->text,upper_string(f->name->text),arg_string(f->params)); } else { fprintf(file,"syscall(SYS_%s,SYS_%s);\n",f->options->indirect->text,upper_string(f->name->text)); } } else { fprintf(file,"\t\t\t#ifdef SYS_%s\n",pattern_complete(f->options->local_name->text,f->name->text)); if(!is_void(f->type)) { fprintf(file,"\t\t\t\tresult = "); } else { fprintf(file,"\t\t\t\t"); } if(f->params) { fprintf(file,"syscall(SYS_%s,%s);\n",pattern_complete(f->options->local_name->text,f->name->text),arg_string(f->params)); } else { fprintf(file,"syscall(SYS_%s);\n",pattern_complete(f->options->local_name->text,f->name->text)); } } fprintf(file,"\t\t\t#else\n"); write_dynamic_call( file, f ); fprintf(file,"\t\t\t#endif\n"); }
void write_static_call( FILE *file, struct function *f ) { fprintf(file,"\t\t\textern %s %s (%s);\n",type_string(f->type),upper_string(pattern_complete(f->options->local_name->text,f->name->text)),param_string(f->params)); if(!is_void(f->type)) { fprintf(file,"\t\t\tresult = "); } else { fprintf(file,"\t\t\t"); } fprintf(file,"%s( %s );\n",upper_string(pattern_complete(f->options->local_name->text,f->name->text)),arg_string(f->params)); }
int convertToCase(char *string, CASE char_case) { if(char_case == UPPER) upper_string(string); else lower_string(string); return 0; }
int extract_rename( struct function *list, char *output_name ) { struct function *f; struct option *o; FILE *file; int count; file = fopen(output_name,"r+"); if(!file) { fprintf(stderr,"\tnothing to rename\n"); return 0; } for( f=list; f; f=f->next ) { o = f->options; fprintf(stderr,"\t%s\t",f->name->text); if(o->linkage==OPTION_LINKAGE_LIBCALL) { char *old_name = f->name->text; char *new_name = upper_string(f->name->text); fprintf(stderr,"%s\t%s -> %s\t",o->library->text,old_name,new_name); count = replace_in_file(file,old_name,new_name); fprintf(stderr,"(%d instances)",count); } fprintf(stderr,"\n"); } fclose(file); return 1; }
bool hasCIEnding(std::string const &fullString, std::string const &ending) { std::string newFullString = upper_string(fullString); std::string newEnding = upper_string(ending); unsigned int lastMatchPos = newFullString.rfind(newEnding); // Find the last occurrence of ending bool isEnding = lastMatchPos != std::string::npos; // Make sure it's found at least once // If the string was found, make sure that any characters that follow it are the ones we're trying to ignore for(int i = lastMatchPos + newEnding.length(); (i < newFullString.length()) && isEnding; i++) { if((newFullString[i] != '\n') && (newFullString[i] != '\r') ) { isEnding = false; } } return isEnding; }
int main() { char string[100]; printf("Enter a string to convert it into upper case\n"); gets(string); upper_string(string); printf("Entered string in upper case is \"%s\"\n", string); return 0; }
int main( int argc, char **argv, char **envp) { int i; unsigned long j; struct arch_flag *arch_flags; unsigned long narch_flags; enum bool all_archs; char **files; progname = argv[0]; arch_flags = NULL; narch_flags = 0; all_archs = FALSE; output = stdout; cmd_flags.nfiles = 0; cmd_flags.c = FALSE; cmd_flags.x = FALSE; cmd_flags.ofile_name = NULL; cmd_flags.ofile_path = NULL; files = allocate(sizeof(char *) * argc); for(i = 1; i < argc; i++){ if(argv[i][0] == '-'){ if(argv[i][1] == '\0'){ for( ; i < argc; i++) files[cmd_flags.nfiles++] = argv[i]; break; } if(strcmp(argv[i], "-arch") == 0){ if(i + 1 == argc){ error("missing argument(s) to %s option", argv[i]); usage(); } if(strcmp("all", argv[i+1]) == 0){ all_archs = TRUE; } else{ arch_flags = reallocate(arch_flags, (narch_flags + 1) * sizeof(struct arch_flag)); if(get_arch_from_flag(argv[i+1], arch_flags + narch_flags) == 0){ error("unknown architecture specification flag: " "%s %s", argv[i], argv[i+1]); arch_usage(); usage(); } narch_flags++; } i++; } else{ for(j = 1; argv[i][j] != '\0'; j++){ switch(argv[i][j]){ case 'c': cmd_flags.c = TRUE; break; case 'x': cmd_flags.x = TRUE; break; case 'n': cmd_flags.n = TRUE; break; case 'o': cmd_flags.o = TRUE; break; default: error("invalid argument -%c", argv[i][j]); usage(); } } if(cmd_flags.n == TRUE && cmd_flags.ofile_name == NULL){ if(i + 1 == argc){ error("missing arguments to -n"); usage(); } cmd_flags.ofile_name = upper_string(argv[i+1]); i += 1; } if(cmd_flags.o == TRUE && cmd_flags.ofile_path == NULL){ if(i + 1 == argc){ error("missing arguments to -o"); usage(); } cmd_flags.ofile_path = argv[i+1]; i += 1; } } continue; } files[cmd_flags.nfiles++] = argv[i]; } if (cmd_flags.ofile_name == NULL) { if (cmd_flags.nfiles == 0) cmd_flags.ofile_name = upper_string("a.out"); else cmd_flags.ofile_name = upper_string(files[0]); } if (cmd_flags.o == TRUE) { output = fopen(cmd_flags.ofile_path, "w"); if (output == NULL) { error("couldn't open output file %s\n",cmd_flags.ofile_path); output = stdout; } } for(j = 0; j < cmd_flags.nfiles; j++) ofile_process(files[j], arch_flags, narch_flags, all_archs, FALSE, FALSE, TRUE, nm, &cmd_flags); if(cmd_flags.nfiles == 0) ofile_process("a.out", arch_flags, narch_flags, all_archs, FALSE, FALSE, TRUE, nm, &cmd_flags); if (cmd_flags.ofile_name != NULL) free(cmd_flags.ofile_name); if(errors == 0) return(EXIT_SUCCESS); else return(EXIT_FAILURE); }
int main(int argc, char *argv[]) { clock_t start=clock(); //程序运行时需从cmd启动,后面两个参数依次为源字符串和待查询字符串的文件名(文件地址) char line[1024]; if (argc < 2) { fprintf(stderr, "ERROR: No word file specified\n"); return -1; } //获取时间 int big_count = 0; int count = 0; //bloom filter algorithm BF *bloomfilter = bloom_create(BIG_PRIME); freopen(argv[1], "r", stdin); while (scanf("%s", line) != EOF) { upper_string(line); if (check_string(line) == 1) { bloom_add(bloomfilter, line); big_count++; } } fclose(stdin); freopen(argv[2], "r", stdin); freopen("result_bf.dat", "w", stdout); while (scanf("%s", line) != EOF) { upper_string(line); if (check_string(line) == 1 && bloom_check(bloomfilter, line) == 1) { printf("yes\n"); count++; } else { printf("no\n"); } } fclose(stdin); fclose(stdout); freopen("/dev/stdin", "r", stdin); freopen("computer.time", "a", stdout); printf("%f\n",(double)(clock()-start)/CLOCKS_PER_SEC); bloom_destroy(bloomfilter); /*****************************************************************************/ /* //压缩trie树 trie_Node* root; root = trie_create(); //读文件,建立压缩trie树 freopen(argv[1], "r", stdin); while (scanf("%s", line) != EOF) { upper_string(line); if (check_string(line) == 1) { trie_add(line, root); } } fclose(stdin); //查询是否在树中 count = 0; freopen(argv[2], "r", stdin); freopen("result_trie.dat", "w", stdout); while (scanf("%s", line) != EOF) { upper_string(line); if (check_string(line) == 1 && trie_check(line, root) == 1) { printf("yes\n"); count++; } else { printf("no\n"); } } fclose(stdin); fclose(stdout); freopen("/dev/pts/3", "r", stdin); freopen("computer.time", "a", stdout); //printf("存在%d个\n", count); */ // trie_destroy(root);//运行完直接退出,自动释放内存,是否destroy不重要(取消注释可以运行destroy) return 0; }
string resolve_express_function(const string express) { if (!resolve_express_is_function(express)) return ""; split_result split(split_string(express,"|")); string function(split.first),next_function(split.second); left_move_string(next_function,1); string result; while (!function.empty()) { if (!resolve_express_is_function(function)) return function; split=split_string(function,"("); string function_name(upper_string(split.first)),function_arg(separate_string(function,"(",")")); if (function_rnd==function_name) { function_arg=separate_string(function_arg,"[","]"); string down,up; split=split_string(function_arg,"-"); if (1<count_string(function_arg,"-")) { left_move_string(split.second,1); if (resolve_express_is_function(split.second)) { down=split.first; up=split.second; left_move_string(up,1); } else { split=split_string(function_arg,")"); down=split.first; down+=")"; left_move_string(split.second,1); split=split_string(split.second,"-"); left_move_string(split.second,1); up=split.second; } } else { down=split.first; up=split.second; left_move_string(up,1); } if (down.empty() || up.empty()) return ""; if (resolve_express_is_function(down)) down=resolve_express_function(down); if (resolve_express_is_function(up)) up=resolve_express_function(up); long down_=string_to_number(down),up_=string_to_number(up); long rnd=ramdon(down_,up_); result+=number_to_string(rnd); } else if (function_time==function_name) { } else if (function_base64==function_name) { if (!resolve_express_is_function(function_arg)) { return base64_encode(function_arg.c_str(),function_arg.length()); } else { string encode_string(resolve_express_function(function_arg)); return base64_encode(encode_string.c_str(),encode_string.length()); } } else if (function_len==function_name) { unsigned int length=function_arg.length(); return number_to_string(length); } split=split_string(next_function,","); function=split.first; next_function=split.second; left_move_string(next_function,1); } return result; }
void main() { int i,j,ch,ch2,count,tmp,vowels,consonants,y=0,x=0,k=0,n,n2,minIndex=0,maxIndex=0,max=0,min=0,l; char s[200],s1[200],substr[100][100]= {0},str[25][25],temp[25],*ptr; for(;;) { printf("\nEnter the choice\n"); printf("0. Exit\n"); printf("1. Implement library functions on a string\n"); printf("2. Calculate string length in user defined function\n"); printf("3. concat using user defined function\n"); printf("4. lowercase conversion using user defined function\n"); printf("5. uppercase conversion using user defined function\n"); printf("6. count vowels and consonants using user defined function\n"); printf("7. substring search using user defined function\n"); printf("8. compare strings using user defined function\n"); printf("9. find the largest and smallest word in a string\n"); printf("10.check palindromic string using user defined function\n"); printf("11.reverse a string using user defined function\n"); printf("12.remove duplicate characters in a string using user defined function\n"); printf("13.copy one string into another string using user defined function\n"); printf("14.swap 2 string using user defined function\n"); printf("15.search for a string in a user given sentence\n"); printf("16.sort n number of words in alphabetical order\n"); printf("17.print abbreviations of an input string\n"); scanf("%d",&ch); if(ch==0) { printf("Terminated\n"); break; } else { switch(ch) { case 1: for(;;) { printf("0.Return to main menu\n"); printf("1.Length of string\n"); printf("2.Concate two strings\n"); printf("3.Convert string to lowercase\n"); printf("4.Convert string to uppercase\n"); scanf("%d",&ch2); if(ch2==0) break; else { printf("Enter the String\n"); scanf("%s",s); switch(ch2) { case 1: l=strlen(s); printf("String length of s = %d\n",l); break; case 2: printf("Enter 2nd string\n"); scanf("%s",s1); strcat(s,s1); printf("Concatenated String is --> %s\n",s); break; case 3: for(i=0; i<l; i++) { tmp=tolower(s[i]); s[i]=tmp; } printf("Lowercase string = %s\n",s); break; case 4: for(i=0; i<l; i++) { tmp=toupper(s[i]); s[i]=tmp; } printf("Uppercase string = %s\n",s); break; default: printf("Wrong Input\n"); break; } } } break; case 2: printf("Enter the string\n"); scanf("%s",s); y = length(s); printf("Length of %s= %d\n", s, y); break; case 3: printf("Enter the 1st string\n"); scanf("%s",s); printf("Enter the 2nd String\n"); scanf("%s",s1); concat(s, s1); printf("The concated string is --> %s", s); break; case 4: printf("Enter the string\n"); scanf("%s",s); lower_string(s); printf("String in lower case is \"%s\"\n",s); break; case 5: printf("Enter the string\n"); scanf("%s",s); upper_string(s); printf("String in upper case is \"%s\"\n",s); break; case 6: printf("Enter a string with a tab at the end\n"); scanf("%[^\t]",s); vowels=consonants=0; for(i=0; s[i]!='\0'; ++i) { if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]=='U') ++vowels; else if((s[i]>='a'&& s[i]<='z') || (s[i]>='A'&& s[i]<='Z')) ++consonants; } printf("Vowels: %d\n",vowels); printf("Consonants: %d\n",consonants); break; case 7: printf("Enter a string with a tab at the end\n"); scanf("%[^\t]",s); printf("Enter the substring to search\n"); scanf("%s",s1); for(i=0; s[i]!='\0'; i++) { j=0; if(s[i]==s1[j]) { tmp=i+1; while(s[i]==s1[j]) { i++; j++; } if(s1[j]=='\0') printf("The substring is present in given string at position %d\n",tmp); else { i=tmp; tmp=0; } } } if(tmp==0) printf("The substring is not present in given string\n"); break; case 8: printf("Enter the 1st string\n"); scanf("%s",s); printf("Enter the 2nd string\n"); scanf("%s",s1); n2 = compare(s, s1); if (n2 == 0) printf("Both are same\n"); else if (n2 > 0) printf("1st>2nd\n"); else printf("1st<2nd\n"); break; case 9: i=0; k=0; printf("Enter a string with a tab at the end\n"); scanf("%[^\t]",s); while(s[k]!='\0') { j=0; while(s[k]!=' '&&s[k]!='\0') { substr[i][j]=s[k]; k++; j++; } substr[i][j]='\0'; i++; if(s[k]!='\0') k++; } int len=i; max=length(substr[0]); min=length(substr[0]); for(i=0; i<len; i++) { y=length(substr[i]); if(y>max) { max=y; maxIndex=i; } if(y<min) { min=y; minIndex=i; } } printf("Largest Word is --> %s\nSmallest word is --> %s\n",substr[maxIndex],substr[minIndex]); break; case 10: printf("Enter the string\n"); scanf("%s",s); x = palindrome(s); if (x == 0) printf("\nNot a palindrome"); else printf("\nA palindrome"); break; case 11: printf("Enter the string\n"); scanf("%s",s); reverse(s); printf("The reversed string is --> %s", s); break; case 12: printf("Enter the string\n"); scanf("%s",s); removeDuplicates(s); printf("String after removing duplicates: %s\n", s); break; case 13: printf("Enter the 1st string\n"); scanf("%s",s); printf("Enter the 2nd string\n"); scanf("%s",s1); copy(s, s1); printf("\nResultant s = %s", s); break; case 14: printf("Enter the 1st string\n"); scanf("%s",s); printf("Enter the 2nd string\n"); scanf("%s",s1); swap(s, s1); printf("s is %s, s1 is %s\n", s, s1); break; case 15: printf("press 7 please\n"); break; case 16: printf("How many words do you want to enter?\n"); scanf("%d",&count); printf("Enter the sentence\n"); for(i=0; i<count; i++) scanf("%s",str[i]); for(i=0; i<=count; i++) for(j=i+1; j<=count; j++) { if(strcmp(str[i],str[j])>0) { strcpy(temp,str[i]); strcpy(str[i],str[j]); strcpy(str[j],temp); } } printf("The sentence sorted alphabetically is --> "); for(i=0; i<=count; i++) printf("%s ",str[i]); break; case 17: printf("Enter a string with a tab at the end\n"); scanf("%[^\t]",s); l=strlen(s); ptr=s; printf("%c",*(ptr+1)); for(i=1; i<l; i++) { if(*(ptr+i-1)==' ') printf("%c",*(ptr+i)); } break; default: printf("Invalid choice"); break; } } } }