optional<expr> apply_strategy() { std::string s_name(get_config().m_strategy); if (s_name == "preprocess") { return apply_preprocess(); } else if (s_name == "simp") { return apply_simp(); } else if (s_name == "simp_nohyps") { return apply_simp_nohyps(); } else if (s_name == "simple") { return apply_simple(); } else if (s_name == "all") { // TODO(Leo): return apply_simple(); } else if (s_name == "cc") { return apply_cc(); } else if (s_name == "grind") { return apply_grind(); } else if (s_name == "grind_simp") { return apply_grind_simp(); } else if (s_name == "core_grind") { return apply_core_grind(); } else if (s_name == "ematch") { return apply_ematch(); } else if (s_name == "ematch_simp") { return apply_ematch_simp(); } else if (s_name == "rec_ematch_simp") { return apply_rec_ematch_simp(); } else if (s_name == "rec_simp") { return apply_rec_simp(); } else if (s_name == "constructor") { return apply_constructor(); } else if (s_name == "unit") { return apply_unit(); } else if (s_name == "backward") { return apply_backward(); } else { throw exception(sstream() << "unknown blast strategy '" << s_name << "'"); } }
String M2MDevice::resource_value_string(DeviceResource resource, uint16_t instance_id) const { String value = ""; M2MResourceInstance* res = get_resource_instance(resource,instance_id); if(res) { if(M2MDevice::Manufacturer == resource || M2MDevice::ModelNumber == resource || M2MDevice::DeviceType == resource || M2MDevice::SerialNumber == resource || M2MDevice::HardwareVersion == resource || M2MDevice::FirmwareVersion == resource || M2MDevice::SoftwareVersion == resource || M2MDevice::UTCOffset == resource || M2MDevice::Timezone == resource) { uint8_t* buffer = NULL; uint32_t length = 0; res->get_value(buffer,length); char *char_buffer = (char*)malloc(length+1); if(char_buffer) { memset(char_buffer,0,length+1); memcpy(char_buffer,(char*)buffer,length); String s_name(char_buffer); value = s_name; if(char_buffer) { free(char_buffer); } } if(buffer) { free(buffer); } } } return value; }
void reduceFunction::getMapInfo(){ for(std::map<int,mapNode>::iterator it=mapAddress.begin(); it!=mapAddress.end(); ++it){ int fd; //int cound=0; while(true){ fd=open_clientfd(it->second.mapIp, it->second.mapPort); if(fd<0){ /*if(cound==3){ NodeInfo newNode("8080", "10.0.2.15"); changeInfo(1, newNode); }*/ printf("Node is missing.\n"); sleep(1); //cound++; continue; } else{ //break; std::cout<<"geting map info"<<std::endl; char buf_s[80]; sprintf(buf_s,"GETMAP %d\n",it->first); Rio_writep(fd, buf_s, strlen(buf_s)); char buf_r[80]; char * saveptr=NULL; int numBytes; rio_t t; Rio_readinitb( &t,fd); bool finished=false; std::map<std::string, int> tempMap; while(numBytes = Rio_readlineb(&t, buf_r, MAXLINE)>0){ if(numBytes<=0){ std::cout<<"close fd"<<std::endl; break; } printf("numBytes is %d\n", numBytes); char* r1 = strtok_r(buf_r, "*",&saveptr); char r_name[80]; strcpy(r_name,r1); std::string s_name(r_name); if(s_name=="FINISH"){ finished=true; break; } char* r2 = strtok_r(NULL, "*",&saveptr); int r_num=atoi(r2); tempMap[s_name]+=r_num; //std::cout<<r_num<<std::endl; } if(finished){ for(std::map<std::string,int>::iterator tempit=tempMap.begin(); tempit!=tempMap.end(); ++tempit){ myMap[tempit->first]=tempit->second; } break; } continue; } } } }
bool ParserAlterQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) { Pos begin = pos; ParserKeyword s_alter_table("ALTER TABLE"); ParserKeyword s_add_column("ADD COLUMN"); ParserKeyword s_drop_column("DROP COLUMN"); ParserKeyword s_modify_column("MODIFY COLUMN"); ParserKeyword s_modify_primary_key("MODIFY PRIMARY KEY"); ParserKeyword s_attach_partition("ATTACH PARTITION"); ParserKeyword s_detach_partition("DETACH PARTITION"); ParserKeyword s_drop_partition("DROP PARTITION"); ParserKeyword s_attach_part("ATTACH PART"); ParserKeyword s_fetch_partition("FETCH PARTITION"); ParserKeyword s_freeze_partition("FREEZE PARTITION"); ParserKeyword s_reshard("RESHARD"); ParserKeyword s_partition("PARTITION"); ParserKeyword s_after("AFTER"); ParserKeyword s_from("FROM"); ParserKeyword s_from_partition("FROM PARTITION"); ParserKeyword s_copy("COPY"); ParserKeyword s_to("TO"); ParserKeyword s_using("USING"); ParserKeyword s_coordinate("COORDINATE"); ParserKeyword s_with("WITH"); ParserKeyword s_name("NAME"); ParserString s_dot("."); ParserString s_comma(","); ParserString s_doubledot(".."); ParserWhitespaceOrComments ws; ParserIdentifier table_parser; ParserCompoundIdentifier parser_name; ParserCompoundColumnDeclaration parser_col_decl; ParserLiteral parser_literal; ParserUnsignedInteger parser_uint; ParserStringLiteral parser_string_literal; ASTPtr table; ASTPtr database; String cluster_str; ASTPtr col_type; ASTPtr col_after; ASTPtr col_drop; auto query = std::make_shared<ASTAlterQuery>(); ws.ignore(pos, end); if (!s_alter_table.ignore(pos, end, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!table_parser.parse(pos, end, database, max_parsed_pos, expected)) return false; /// Parse [db].name if (s_dot.ignore(pos, end)) { if (!table_parser.parse(pos, end, table, max_parsed_pos, expected)) return false; query->table = typeid_cast<ASTIdentifier &>(*table).name; query->database = typeid_cast<ASTIdentifier &>(*database).name; } else { table = database; query->table = typeid_cast<ASTIdentifier &>(*table).name; } ws.ignore(pos, end); if (ParserKeyword{"ON"}.ignore(pos, end, max_parsed_pos, expected)) { if (!ASTQueryWithOnCluster::parse(pos, end, cluster_str, max_parsed_pos, expected)) return false; } bool parsing_finished = false; do { ASTAlterQuery::Parameters params; ws.ignore(pos, end); if (s_add_column.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_col_decl.parse(pos, end, params.col_decl, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (s_after.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if(!parser_name.parse(pos, end, params.column, max_parsed_pos, expected)) return false; } params.type = ASTAlterQuery::ADD_COLUMN; } else if (s_drop_partition.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_literal.parse(pos, end, params.partition, max_parsed_pos, expected)) return false; params.type = ASTAlterQuery::DROP_PARTITION; } else if (s_drop_column.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_name.parse(pos, end, params.column, max_parsed_pos, expected)) return false; params.type = ASTAlterQuery::DROP_COLUMN; params.detach = false; if (s_from_partition.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_literal.parse(pos, end, params.partition, max_parsed_pos, expected)) return false; } } else if (s_detach_partition.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_literal.parse(pos, end, params.partition, max_parsed_pos, expected)) return false; params.type = ASTAlterQuery::DROP_PARTITION; params.detach = true; } else if (s_attach_partition.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_literal.parse(pos, end, params.partition, max_parsed_pos, expected)) return false; params.type = ASTAlterQuery::ATTACH_PARTITION; } else if (s_attach_part.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_literal.parse(pos, end, params.partition, max_parsed_pos, expected)) return false; params.part = true; params.type = ASTAlterQuery::ATTACH_PARTITION; } else if (s_fetch_partition.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_literal.parse(pos, end, params.partition, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!s_from.ignore(pos, end, max_parsed_pos, expected)) return false; ws.ignore(pos, end); ASTPtr ast_from; if (!parser_string_literal.parse(pos, end, ast_from, max_parsed_pos, expected)) return false; params.from = typeid_cast<const ASTLiteral &>(*ast_from).value.get<const String &>(); params.type = ASTAlterQuery::FETCH_PARTITION; } else if (s_freeze_partition.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_literal.parse(pos, end, params.partition, max_parsed_pos, expected)) return false; ws.ignore(pos, end); /// WITH NAME 'name' - place local backup to directory with specified name if (s_with.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!s_name.ignore(pos, end, max_parsed_pos, expected)) return false; ws.ignore(pos, end); ASTPtr ast_with_name; if (!parser_string_literal.parse(pos, end, ast_with_name, max_parsed_pos, expected)) return false; params.with_name = typeid_cast<const ASTLiteral &>(*ast_with_name).value.get<const String &>(); ws.ignore(pos, end); } params.type = ASTAlterQuery::FREEZE_PARTITION; } else if (s_modify_column.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_col_decl.parse(pos, end, params.col_decl, max_parsed_pos, expected)) return false; ws.ignore(pos, end); params.type = ASTAlterQuery::MODIFY_COLUMN; } else if (s_modify_primary_key.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!ParserString("(").ignore(pos, end, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!ParserNotEmptyExpressionList(false).parse(pos, end, params.primary_key, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!ParserString(")").ignore(pos, end, max_parsed_pos, expected)) return false; ws.ignore(pos, end); params.type = ASTAlterQuery::MODIFY_PRIMARY_KEY; } else if (s_reshard.ignore(pos, end, max_parsed_pos, expected)) { ParserList weighted_zookeeper_paths_p(std::make_unique<ParserWeightedZooKeeperPath>(), std::make_unique<ParserString>(","), false); ParserExpressionWithOptionalAlias parser_sharding_key_expr(false); ParserStringLiteral parser_coordinator; ws.ignore(pos, end); if (s_copy.ignore(pos, end, max_parsed_pos, expected)) params.do_copy = true; ws.ignore(pos, end); if (s_partition.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_uint.parse(pos, end, params.partition, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (s_doubledot.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!parser_uint.parse(pos, end, params.last_partition, max_parsed_pos, expected)) return false; } } ws.ignore(pos, end); if (!s_to.ignore(pos, end, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!weighted_zookeeper_paths_p.parse(pos, end, params.weighted_zookeeper_paths, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!s_using.ignore(pos, end, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!parser_sharding_key_expr.parse(pos, end, params.sharding_key_expr, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (s_coordinate.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!s_with.ignore(pos, end, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!parser_coordinator.parse(pos, end, params.coordinator, max_parsed_pos, expected)) return false; ws.ignore(pos, end); } params.type = ASTAlterQuery::RESHARD_PARTITION; } else return false; ws.ignore(pos, end); if (!s_comma.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); parsing_finished = true; } query->addParameters(params); } while (!parsing_finished); query->range = StringRange(begin, end); query->cluster = cluster_str; node = query; return true; }
// 解密PNG图片 void DecryptPNG(const std::vector<std::string> &filelist, const aes_key &key) { for (auto &filename : filelist) { std::ifstream in_file(filename, std::ios::binary | std::ios::ate); if (!in_file.is_open()) { std::cerr << "打开" << filename << " 失败!" << std::endl; return; } // 读取数据块位置 uint64_t end_pos = in_file.tellg(); in_file.seekg(end_pos - sizeof(uint64_t)); uint64_t block_start_pos = *reinterpret_cast<uint64_t *>(&(ReadSome<sizeof(uint64_t)>(in_file)[0])); in_file.seekg(block_start_pos); // 解密数据块信息 auto block_info = ReadLarge(in_file, uint32_t(end_pos - sizeof(uint64_t) - block_start_pos)); DecryptBlock(block_info, key); // 验证数据块内容 auto block_head = ReadSome<sizeof(BLOCK_HEAD)>(block_info); for (unsigned int i = 0; i < block_head.size(); ++i) { if (block_head[i] != BLOCK_HEAD[i]) { std::cerr << "密钥错误,解密" << filename << " 失败!" << std::endl; return; } } std::ofstream out_file(path::splitext(filename)[0] + ".png", std::ios::binary); if (!out_file.is_open()) { std::cerr << "创建" << path::splitext(filename)[1] << ".png" << " 失败!" << std::endl; continue; } // 写入文件头 WriteToSteam(HEAD_DATA, sizeof(HEAD_DATA), out_file); // 读取数据块 uint64_t read_size = 0; while (true) { // 读取数据块信息 Block block; memcpy(&block, &ReadSome<sizeof(Block)>(block_info)[0], sizeof(Block)); if (block_info.eof()) { out_file.clear(); std::cerr << "the %s file format error!" << std::endl; break; } // 写入数据块长度 char reverse_size[sizeof(block.size)]; memcpy(reverse_size, &block.size, sizeof(reverse_size)); std::reverse(reverse_size, reverse_size + sizeof(reverse_size)); WriteToSteam(reverse_size, sizeof(reverse_size), out_file); // 写入数据块名称 WriteToSteam(&block.name, sizeof(block.name), out_file); // 写入数据块内容 std::string s_name(block.name, sizeof(block.name)); if (strcmp(s_name.c_str(), "IHDR") == 0) { IHDRBlock ihdr; memcpy(&ihdr, &block, sizeof(Block)); memcpy(((char *)&ihdr) + sizeof(Block), &ReadSome<sizeof(IHDRBlock) - sizeof(Block)>(block_info)[0], sizeof(IHDRBlock) - sizeof(Block)); WriteToSteam(ihdr.data, sizeof(ihdr.data), out_file); } else if (strcmp(s_name.c_str(), "IEND") == 0) { WriteToSteam(IEND_DATA, sizeof(IEND_DATA), out_file); std::cout << "成功解密:" << filename << std::endl; break; } else { in_file.seekg(read_size); StreamMove(out_file, in_file, block.size + CRC_SIZE); read_size += block.size + CRC_SIZE; } } } }
/* going out of the node ). */ int s_build_VCS( INDEX strm, enum Object type, double Temp, int add ) { int i, j, ii, k; int error_code = NO_ERR; int num_el, found; INDEX current_comp, current_opcode; struct Stream *ptr; struct Element_array el; ptr = &stream_array[strm]; if ( (type==PIPE) || ((type==NODE) && add) ) { s_reset_uni_elem( strm ); /* reset the unique element array and counter */ #if defined(DEBUG) /* Lets print the incoming compounds */ fprintf(debug_prn_file,"\n %25.25s", s_name( strm ) ); for(i=0; i<ptr->no_of_comp; i++) { current_comp = ptr->comp[i]; /* get the index to the compound */ fprintf(debug_prn_file,"\n %25.25s %f", c_name(current_comp), c_get_mole( current_comp ) ); } #endif /* we have to determine if the streams unique elements are already specified */ /* If they are specified, add the number of the unique element to the abundance */ /* array. Else add the name of the unique element to the list VCS_elem and add */ /* the number to the abundance */ for(i=0; i<MAX_UNI_ELEM; i++) { if (s_uni_mat[i] == 0.0) continue; found = FALSE; for(j=0; j<MAXELEMENT; j++) { if (VCS_elem[j+1] == Nil) break; if ( VCS_elem[j+1] == i ) { found = TRUE; gai[j+1] += s_uni_mat[i]; } } if ( !found ) { if ( j<MAXELEMENT ) { VCS_elem[j+1] = i; gai[j+1] += s_uni_mat[i]; ne++; /* increase the number of elements */ } else { sprintf( error, "Exceeded maximum elements for VCS in stream %s", s_name(strm) ); return error_code = VCS_ELEM_OVFLOW; } } } } if ( (type==PIPE) || ((type==NODE) && !add) ) { for(i=0; i<ptr->no_of_comp; i++) { /* first we have to find a empty space to add the compound */ k=1; /* start at one */ while ( VCS_specie[k] != MARKER && k < MAXSPECIE) k++; if ( k >= MAXSPECIE ) { sprintf( error, "Exceeded maximum species for VCS in stream %s", s_name(strm) ); return error_code = VCS_SPECIE_OVFLOW; } VCS_specie[k] = current_comp = ptr->comp[i]; /* assign the compound */ w[k] = c_get_mole( current_comp ); /* get the number of moles of the compound */ ff[k] = c_delta_G( current_comp, Temp )/1e3; /* get the chemical potential */ /* and convert to kJ/kmole */ m++; /* increase the number of species */ /* ----------- The following phase assignment (see invoke_VCS)could be a problem ---------- */ si[k] = ptr->s_phase; /* get the phase type for the compound */ /* now we have to build the formula array for this compound */ num_el = c_num_uni_elemts( current_comp ); /* get the number of unique elements for this compound */ c_uni_elemts( current_comp, &el ); /* get the unique elements */ for(j=0; j<num_el; j++) { ii = 1; /* start at one */ /* does the compound element name correspond to the already defined elemental abundance */ while ( VCS_elem[ii] != el.element[j] && ii < MAXELEMENT ) ii++; if ( ii >= MAXELEMENT ) { sprintf( error, "Could not find a place in VCS for element %s of compound %s in stream %s", Elem_txt[el.element[j]], c_name(current_comp), s_name(strm) ); return error_code = FATAL_ERR; } bm[k][ii] = (double)el.no_of_element[j]; /* enter the number of the element into the formula mat */ } /* now we must enter the activity formalism */ if (ptr->s_alpha != 0.0) /* only do this for non_ideal cases */ { VCS_act[k] = current_opcode = ptr->act_c[i]; /* assign the index into the opcode_array */ if ( current_opcode != MARKER ) { /* this compound must have a activity formalism */ /* now we must go through our local copy of the opcodes and adjust the references */ while ( opcode[current_opcode++].mnem != RTN ) { if ( opcode[current_opcode].mnem == GET ) opcode[current_opcode].x.entry += (INDEX)(k - i); /* now the opcode will point to the correct specie in VCS_specie */ } } } } } return error_code; }
int main(const carg, const char *varg[]) { char *s; int i; s = NULL; i = 0; fprintf(stdout, "s_strcpy(NULL, \"\") == FALSE: "); if (s_strcpy(NULL, "") == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strncpy(NULL, \"\", 10) == FALSE: "); if (s_strncpy(NULL, "", 10) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strcat(NULL, \"\") == FALSE: "); if (s_strcat(NULL, "") == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strncat(NULL, \"\", 10) == FALSE: "); if (s_strncat(NULL, "", 10) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strcpy(&s, NULL) == FALSE: "); if (s_strcpy(&s, NULL) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strncpy(&s, NULL, 10) == FALSE: "); if (s_strncpy(&s, NULL, 10) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strcat(&s, NULL) == FALSE: "); if (s_strcat(&s, NULL) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strncat(&s, NULL, 10) == FALSE: "); if (s_strncat(&s, NULL, 10) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strcpy(&s, \"ab\"), strcmp(s, \"ab\") == 0: "); s_strcpy(&s, "ab"); if (strcmp(s, "ab") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strncpy(&s, \"ab\", 1), strcmp(s, \"a\") == 0: "); s_strncpy(&s, "ab", 1); if (strcmp(s, "a") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strcat(&s, \"ab\"), strcmp(s, \"aab\") == 0: "); s_strcat(&s, "ab"); if (strcmp(s, "aab") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strncat(&s, \"ab\", 1), strcmp(s, \"aaba\") == 0: "); s_strncat(&s, "ab", 1); if (strcmp(s, "aaba") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strcpy(&s, \"abcdefghij klmnop\"), s_strcpy(&s, s), strcmp(s, \"abcdefghij klmnop\") == 0: "); s_strcpy(&s, "abcdefghij klmnop"); s_strcpy(&s, s); if (strcmp(s, "abcdefghij klmnop") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strncpy(&s, s, 10), strcmp(s, \"abcdefghij\") == 0: "); s_strncpy(&s, s, 10); if (strcmp(s, "abcdefghij") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strcat(&s, s), strcmp(s, \"abcdefghijabcdefghij\") == 0: "); s_strcat(&s, s); if (strcmp(s, "abcdefghijabcdefghij") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_strncat(&s, s, 10), strcmp(s, \"abcdefghijabcdefghijabcdefghij\") == 0: "); s_strncat(&s, s, 10); if (strcmp(s, "abcdefghijabcdefghijabcdefghij") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_path(NULL, \"\", SYS_PATH_DELIM) == FALSE: "); if (s_path(NULL, "", SYS_PATH_DELIM) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_pathname(NULL, \"\", SYS_PATH_DELIM) == FALSE: "); if (s_pathname(NULL, "", SYS_PATH_DELIM) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_name(NULL, \"\", SYS_PATH_DELIM) == FALSE: "); if (s_name(NULL, "", SYS_PATH_DELIM) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_nameext(NULL, \"\", SYS_PATH_DELIM) == FALSE: "); if (s_nameext(NULL, "", SYS_PATH_DELIM) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_ext(NULL, \"\", SYS_PATH_DELIM) == FALSE: "); if (s_ext(NULL, "", SYS_PATH_DELIM) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_path(&s, NULL, SYS_PATH_DELIM) == FALSE: "); if (s_path(&s, NULL, SYS_PATH_DELIM) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_pathname(&s, NULL, SYS_PATH_DELIM) == FALSE: "); if (s_pathname(&s, NULL, SYS_PATH_DELIM) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_name(&s, NULL, SYS_PATH_DELIM) == FALSE: "); if (s_name(&s, NULL, SYS_PATH_DELIM) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_nameext(&s, NULL, SYS_PATH_DELIM) == FALSE: "); if (s_nameext(&s, NULL, SYS_PATH_DELIM) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_ext(&s, NULL, SYS_PATH_DELIM) == FALSE: "); if (s_ext(&s, NULL, SYS_PATH_DELIM) == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } s_strcpy(&s, "/path/name.ext"); s_path(&s, s, SYS_PATH_DELIM); fprintf(stdout, "s_strcpy(&s, \"/path/name.ext\"), s_path(&s, s, SYS_PATH_DELIM), strcmp(s, \"/path/\") == 0: "); if (strcmp(s, "/path/") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } s_strcpy(&s, "/path/name.ext"); s_pathname(&s, s, SYS_PATH_DELIM); fprintf(stdout, "s_strcpy(&s, \"/path/name.ext\"), s_pathname(&s, s, SYS_PATH_DELIM), strcmp(s, \"/path/name\") == 0: "); if (strcmp(s, "/path/name") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } s_strcpy(&s, "/path/name.ext"); s_name(&s, s, SYS_PATH_DELIM); fprintf(stdout, "s_strcpy(&s, \"/path/name.ext\"), s_name(&s, s, SYS_PATH_DELIM), strcmp(s, \"name\") == 0: "); if (strcmp(s, "name") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } s_strcpy(&s, "/path/name.ext"); s_nameext(&s, s, SYS_PATH_DELIM); fprintf(stdout, "s_strcpy(&s, \"/path/name.ext\"), s_nameext(&s, s, SYS_PATH_DELIM), strcmp(s, \"name.ext\") == 0: "); if (strcmp(s, "name.ext") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } s_strcpy(&s, "/path/name.ext"); s_ext(&s, s, SYS_PATH_DELIM); fprintf(stdout, "s_strcpy(&s, \"/path/name.ext\"), s_ext(&s, s, SYS_PATH_DELIM), strcmp(s, \".ext\") == 0: "); if (strcmp(s, ".ext") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } i += check_pathnameext("", "", "", "", "", ""); i += check_pathnameext("/", "/", "/", "", "", ""); i += check_pathnameext("path/", "path/", "path/", "", "", ""); i += check_pathnameext("name", "", "name", "name", "name", ""); i += check_pathnameext(".ext", "", "", "", ".ext", ".ext"); i += check_pathnameext("path/name", "path/", "path/name", "name", "name", ""); i += check_pathnameext("path/.ext", "path/", "path/", "", ".ext", ".ext"); i += check_pathnameext("name.ext", "", "name", "name", "name.ext", ".ext"); i += check_pathnameext("path/name.ext", "path/", "path/name", "name", "name.ext", ".ext"); i += check_pathnameext("path.e/", "path.e/", "path.e/", "", "", ""); i += check_pathnameext("path.e/name", "path.e/", "path.e/name", "name", "name", ""); i += check_pathnameext("path.e/.ext", "path.e/", "path.e/", "", ".ext", ".ext"); i += check_pathnameext("path.e/name.ext", "path.e/", "path.e/name", "name", "name.ext", ".ext"); fprintf(stdout, "s_sprintf(NULL, \"%%d abc %%s\", -2147483648, \"def\") == FALSE: "); if (s_sprintf(NULL, "%d abc %s", -2147483648, "def") == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "s_sprintf(&s, NULL, -2147483648, \"def\") == FALSE: "); if (s_sprintf(&s, NULL, -2147483648, "def") == FALSE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } s_sprintf(&s, "%d abc %s", -2147483648, "def"); fprintf(stdout, "s_sprintf(&s, \"%%d abc %%s\", -2147483648, \"def\"), strcmp(s, \"-2147483648 abc def\") == 0: "); if (strcmp(s, "-2147483648 abc def") == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } fprintf(stdout, "is_equal_files(\"%s\", \"%s\") == TRUE: ", varg[0], varg[0]); if (is_equal_files(varg[0], varg[0]) == TRUE) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed.\n"); i++; } s_free(&s); fprintf(stderr, "Found %d errors.\n", i); return i; }
int check_pathnameext(const char *pathnameext, const char *must_path, const char *must_pathname, const char *must_name, const char *must_nameext, const char *must_ext) { char *path; char *pathname; char *name; char *nameext; char *ext; int i; path = NULL; pathname = NULL; name = NULL; nameext = NULL; ext = NULL; i = 0; fprintf(stdout, "s_path(&path, \"%s\", SYS_PATH_DELIM), strcmp(path, \"%s\") == 0: ", pathnameext, must_path); s_path(&path, pathnameext, SYS_PATH_DELIM); if (strcmp(path, must_path) == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed\n"); i++; } fprintf(stdout, "s_pathname(&pathname, \"%s\", SYS_PATH_DELIM), strcmp(pathname, \"%s\") == 0: ", pathnameext, must_pathname); s_pathname(&pathname, pathnameext, SYS_PATH_DELIM); if (strcmp(pathname, must_pathname) == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed\n"); i++; } fprintf(stdout, "s_name(&name, \"%s\", SYS_PATH_DELIM), strcmp(name, \"%s\") == 0: ", pathnameext, must_name); s_name(&name, pathnameext, SYS_PATH_DELIM); if (strcmp(name, must_name) == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed\n"); i++; } fprintf(stdout, "s_nameext(&name, \"%s\", SYS_PATH_DELIM), strcmp(nameext, \"%s\") == 0: ", pathnameext, must_nameext); s_nameext(&nameext, pathnameext, SYS_PATH_DELIM); if (strcmp(nameext, must_nameext) == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed\n"); i++; } fprintf(stdout, "s_ext(&ext, \"%s\", SYS_PATH_DELIM), strcmp(ext, \"%s\") == 0: ", pathnameext, must_ext); s_ext(&ext, pathnameext, SYS_PATH_DELIM); if (strcmp(ext, must_ext) == 0) fprintf(stdout, "OK\n"); else { fprintf(stdout, "failed\n"); i++; } s_free(&path); s_free(&pathname); s_free(&name); s_free(&nameext); s_free(&ext); return i; }