void allPermutations(ui32 array_size) { INextPermutatiomStruct * array = create<Type>(); for (ui32 i = 0; i < array_size; ++i) array->insert(i, i); printStruct(array); while (array->nextPermutation(0, array_size)) { printStruct(array); } delete array; }
void moreThanAllPermutations() { INextPermutatiomStruct * array = create<Type>(); for (int i = 0; i < 4; ++i) array->insert(i, i); printStruct(array); for (int i = 0; i < 1000; ++i) { array->nextPermutation(0, 4); printStruct(array); } delete array; }
int main() { struct Foo foo; foo.a = 12; printf("foo.a:\t%p\n", (void*)&foo.a); printStruct(&foo, 100); return 0; }
int main(void){ //populate the structure struct person amjed; strcpy(amjed.fname , "amjed"); strcpy(amjed.lname , "majid"); amjed.age = 33; // print the structure printStruct(amjed); return 0; }
std::string Variable::print(bool stdout, bool stderr) { std::ostringstream result; if(type == VariableType::tVoid) { result << "(void)" << std::endl; } else if(type == VariableType::tBoolean) { result << "(Boolean) " << booleanValue << std::endl; } else if(type == VariableType::tInteger) { result << "(Integer) " << integerValue << std::endl; } else if(type == VariableType::tInteger64) { result << "(Integer64) " << integerValue64 << std::endl; } else if(type == VariableType::tFloat) { result << "(Float) " << floatValue << std::endl; } else if(type == VariableType::tString) { result << "(String) " << stringValue << std::endl; } else if(type == VariableType::tBase64) { result << "(Base64) " << stringValue << std::endl; } else if(type == VariableType::tArray) { std::string indent(""); result << printArray(arrayValue, indent); } else if(type == VariableType::tStruct) { std::string indent(""); result << printStruct(structValue, indent); } else if(type == VariableType::tBinary) { result << "(Binary) " << HelperFunctions::getHexString(binaryValue) << std::endl; } else { result << "(unknown)" << std::endl; } std::string resultString = result.str(); if(stdout) std::cout << resultString; if(stderr) std::cerr << resultString; return resultString; }
void printFrom(char *tag) { uint8_t buf[100000]; for(int i=0;i<nEntFiles;i++) { printf("%s\n",entFileNames[i]); int len=readTag(i,tag,buf,sizeof(buf)); if(len>0) { uint8_t *pnt=buf; printStruct(&pnt); } } }
void printAll() { uint8_t buf[100000]; for(int i=0;i<nEntFiles;i++) { printf("%s\n",entFileNames[i]); FILE *fp = fopen(entFileNames[i],"rb"); int len = fread((void*)buf,1,sizeof(buf),fp); fclose(fp); uint8_t *pnt=buf+2; printStruct(&pnt); } }
std::string Variable::print(PVariable variable, std::string indent) { if(!variable) return ""; std::ostringstream result; if(variable->type == VariableType::tVoid) { result << indent << "(void)" << std::endl; } else if(variable->type == VariableType::tInteger) { result << indent << "(Integer) " << variable->integerValue << std::endl; } else if(variable->type == VariableType::tInteger64) { result << indent << "(Integer64) " << variable->integerValue64 << std::endl; } else if(variable->type == VariableType::tFloat) { result << indent << "(Float) " << variable->floatValue << std::endl; } else if(variable->type == VariableType::tBoolean) { result << indent << "(Boolean) " << variable->booleanValue << std::endl; } else if(variable->type == VariableType::tString) { result << indent << "(String) " << variable->stringValue << std::endl; } else if(type == VariableType::tBase64) { result << indent << "(Base64) " << variable->stringValue << std::endl; } else if(variable->type == VariableType::tArray) { return printArray(variable->arrayValue, indent); } else if(variable->type == VariableType::tStruct) { return printStruct(variable->structValue, indent); } else if(variable->type == VariableType::tBinary) { result << indent << "(Binary) " << HelperFunctions::getHexString(variable->binaryValue) << std::endl; } else { result << indent << "(Unknown)" << std::endl; } return result.str(); }
void process(FILE * outputFileC, FILE * outputFileH, SSUStruct& ssus) { fprintf(outputFileH, "#include \"SsuObject.h\"\n\n"); int namespaceLevel = 0; if(!ssus.packageName.empty()) { size_t start = 0, i = 0; while(i < ssus.packageName.length()) { char c = ssus.packageName[i]; if(c == '.') { if(i > start) { fprintf(outputFileH, "namespace %s {\n", std::string(ssus.packageName.begin() + start, ssus.packageName.begin() + i).c_str()); fprintf(outputFileC, "namespace %s {\n", std::string(ssus.packageName.begin() + start, ssus.packageName.begin() + i).c_str()); ++ namespaceLevel; } start = ++ i; continue; } else if(!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')) { c = '_'; } ++ i; } fprintf(outputFileH, "namespace %s {\n\n", std::string(ssus.packageName.begin() + start, ssus.packageName.end()).c_str()); fprintf(outputFileC, "namespace %s {\n\n", std::string(ssus.packageName.begin() + start, ssus.packageName.end()).c_str()); ++ namespaceLevel; } printEnum(outputFileH, ssus.enumList, 0); printStruct("", outputFileC, outputFileH, ssus.structList, 0); for(int i = 0; i < namespaceLevel; ++ i) { fprintf(outputFileH, "}\n"); fprintf(outputFileC, "}\n"); } fprintf(outputFileH, "\n"); }
int main (void) { printf("%d\n", 01777);// eight digit hex printf("%d\n", 0x1777); // 16 digit hex typeLength(); outputControllSymbol(); printf("%d\n", TOP); printf("%d\n", SINT_MAX); char* pDest; StrCpy(pDest, "hello world!"); printf("%s\n", pDest); printConst(); printf("%d\n", isNegative(200)); printf("%c\n", (char)300324); variableScope(); pointer(); printStruct(); return 0; }
int main(int argc, char **argv) { Dirt_Struct *strct; Dirt_FdBuffer fdbuffer; Dirt_Buffer *buffer = (Dirt_Buffer *) &fdbuffer; Dirt_Reader reader; int fd; if ((fd = open("ReaderTest.data", O_RDONLY)) < 0) { perror("Unable to open file"); exit(1); } if (!Dirt_FileBuffer_init(&fdbuffer, &Dirt_DebugSession, fd)) { Dirt_DebugSession.type->error(&Dirt_DebugSession, "Init", "Unable to initialize FileBuffer"); exit(1); } if (!Dirt_StandardReader_init(&reader, &Dirt_StructReader_Callbacks, buffer)) { Dirt_DebugSession.type->error(&Dirt_DebugSession, "Init", "Unable to initialize Reader"); printf("Unable to initialize Reader"); exit(1); } if (!(strct = (Dirt_Struct *) reader.type->read(&reader, 0))) { Dirt_DebugSession.type->error(&Dirt_DebugSession, "I/O error", "Unable to read data"); exit(1); } printStruct(strct); printf("\n"); strct->type->decref(&Dirt_DebugSession, strct); exit(0); }
void printStruct(const std::string& parent, FILE * outputFileC, FILE * outputFileH, std::vector<StructDef *>& sd, int indent) { for(auto it = sd.begin(); it != sd.end(); ++ it) { std::string publicString, protectedString, constructString, destructString, packString, unpackString, sizeString; fprintIndent(indent, outputFileH, "class %s: public ::ssu::Object\n", (*it)->name.c_str()); fprintIndent(indent, outputFileH, "{\n"); if(!(*it)->structList.empty() || !(*it)->enumList.empty()) { fprintIndent(indent, outputFileH, "public:\n"); printEnum(outputFileH, (*it)->enumList, indent + indentSize); printStruct(parent + (*it)->name + "::", outputFileC, outputFileH, (*it)->structList, indent + indentSize); } indent += indentSize; bool needFlag = false; int maxOrder = 0; for(auto it2 = (*it)->fields.begin(); it2 != (*it)->fields.end(); ++ it2) { int oldOrder = it2->second->order; if(it2->second->constraint == 2) { needFlag = true; it2->second->order = maxOrder ++; } printField(outputFileH, publicString, protectedString, constructString, destructString, packString, unpackString, sizeString, it2->second->constraint, oldOrder, it2->second->order, it2->second->type, it2->second->tname, it2->second->name, alterDefVal(it2->second->type, it2->second->defVal), indent); } indent -= indentSize; fprintIndent(indent, outputFileH, "public:\n"); if(!constructString.empty() || needFlag) { fprintIndent(indent + indentSize, outputFileH, "inline %s()", (*it)->name.c_str()); fputs(constructString.c_str(), outputFileH); if(needFlag) { fputs("\n", outputFileH); fprintIndent(indent + indentSize, outputFileH, "{ memset(_isSetFlag, 0, sizeof(_isSetFlag)); }\n\n"); } else fputs(" { }\n\n", outputFileH); } if(!destructString.empty()) { fprintIndent(indent + indentSize, outputFileH, "virtual ~%s();\n", (*it)->name.c_str()); fprintf(outputFileC, "%s%s::~%s()\n", parent.c_str(), (*it)->name.c_str(), (*it)->name.c_str()); fputs("{\n", outputFileC); fputs(destructString.c_str(), outputFileC); fputs("}\n\n", outputFileC); } else { fprintIndent(indent + indentSize, outputFileH, "virtual ~%s() { }\n\n", (*it)->name.c_str()); } fprintIndent(indent, outputFileH, "public:\n"); fprintIndent(indent + indentSize, outputFileH, "virtual unsigned char * packBuffer(unsigned char * buf);\n"); fprintIndent(indent + indentSize, outputFileH, "virtual bool unpackBuffer(const unsigned char *& buf, size_t& leftSize);\n"); fprintIndent(indent + indentSize, outputFileH, "virtual size_t size() const;\n\n"); if(!publicString.empty()) { fprintIndent(indent, outputFileH, "public:\n"); fputs(publicString.c_str(), outputFileH); } if(!protectedString.empty()) { fprintIndent(indent, outputFileH, "protected:\n"); fputs(protectedString.c_str(), outputFileH); } if(needFlag) { fprintf(outputFileH, "\n"); fprintIndent(indent + indentSize, outputFileH, "unsigned int _isSetFlag[%d];\n", (maxOrder + 31) / 32); } fprintf(outputFileH, "\n"); fprintIndent(indent, outputFileH, "};\n\n"); fprintIndent(0, outputFileC, "unsigned char * %s%s::packBuffer(unsigned char * buf)\n", parent.c_str(), (*it)->name.c_str()); fprintIndent(0, outputFileC, "{\n"); fputs(packString.c_str(), outputFileC); fprintIndent(indentSize, outputFileC, "return buf;\n"); fprintIndent(0, outputFileC, "}\n\n"); fprintIndent(0, outputFileC, "bool %s%s::unpackBuffer(const unsigned char *& buf, size_t& leftSize)\n", parent.c_str(), (*it)->name.c_str()); fprintIndent(0, outputFileC, "{\n"); if(!unpackString.empty()) { fprintIndent(indentSize, outputFileC, "unsigned int tag_; unsigned char type_;\n"); fprintIndent(indentSize, outputFileC, "while(leftSize > 0)\n"); fprintIndent(indentSize, outputFileC, "{\n"); fprintIndent(indentSize * 2, outputFileC, "if(!::ssu::Utils::unpackTag(buf, leftSize, tag_, type_)) return false;\n"); fprintIndent(indentSize * 2, outputFileC, "switch(tag_)\n"); fprintIndent(indentSize * 2, outputFileC, "{\n"); fputs(unpackString.c_str(), outputFileC); fprintIndent(indentSize * 2, outputFileC, "default: break;\n"); fprintIndent(indentSize * 2, outputFileC, "}\n"); fprintIndent(indentSize, outputFileC, "}\n"); } fprintIndent(indentSize, outputFileC, "return true;\n"); fprintIndent(0, outputFileC, "}\n\n"); fprintIndent(0, outputFileC, "size_t %s%s::size() const\n", parent.c_str(), (*it)->name.c_str()); fprintIndent(0, outputFileC, "{\n"); if(sizeString.empty()) fprintIndent(indentSize, outputFileC, "return 0;\n"); else fprintIndent(indentSize, outputFileC, "return %s;\n", sizeString.c_str()); fprintIndent(0, outputFileC, "}\n\n"); } }
void printStruct(Dirt_Struct *strct) { size_t pos; if (strct->type == &Dirt_StructType_Str) printf("'''%*s'''", ((Dirt_StringStruct *) strct)->len, ((Dirt_StringStruct *) strct)->str); else if (strct->type == &Dirt_StructType_UnicodeStr) printf("u'''%*s'''", ((Dirt_StringStruct *) strct)->len, ((Dirt_StringStruct *) strct)->str); else if (strct->type == &Dirt_StructType_Identifier) printf("%*s", ((Dirt_StringStruct *) strct)->len, ((Dirt_StringStruct *) strct)->str); else if (strct->type == &Dirt_StructType_Num_Float) printf("%f", ((Dirt_FloatStruct *) strct)->num_float); else if (strct->type == &Dirt_StructType_Num_Long) printf("%li", ((Dirt_LongStruct *) strct)->num_long); else if (strct->type == &Dirt_StructType_Num_Int) printf("%i", ((Dirt_IntStruct *) strct)->num_int); else if (strct->type == &Dirt_StructType_None) printf("None"); else if (strct->type == &Dirt_StructType_False) printf("False"); else if (strct->type == &Dirt_StructType_True) printf("True"); else if (strct->type == &Dirt_StructType_Structure) { printf("Structure("); for (pos = 0; pos < ((Dirt_StructureStruct *) strct)->len; pos++) { printStruct(((Dirt_StructureStruct *) strct)->items[pos]); if (pos < ((Dirt_StructureStruct *) strct)->len - 1) printf(", "); } printf(")"); } else if (strct->type == &Dirt_StructType_Structure_Tuple) { printf("("); for (pos = 0; pos < ((Dirt_StructureStruct *) strct)->len; pos++) { printStruct(((Dirt_StructureStruct *) strct)->items[pos]); if (pos < ((Dirt_StructureStruct *) strct)->len - 1) printf(", "); } printf(")"); } else if (strct->type == &Dirt_StructType_Structure_List) { printf("["); for (pos = 0; pos < ((Dirt_StructureStruct *) strct)->len; pos++) { printStruct(((Dirt_StructureStruct *) strct)->items[pos]); if (pos < ((Dirt_StructureStruct *) strct)->len - 1) printf(", "); } printf("]"); } else if (strct->type == &Dirt_StructType_Structure_Dictionary) { printf("{"); for (pos = 0; pos < ((Dirt_StructureStruct *) strct)->len; pos++) { printStruct(((Dirt_StructureStruct *) strct)->items[pos]); if (pos < ((Dirt_StructureStruct *) strct)->len - 1) printf(", "); } printf("}"); } else if (strct->type == &Dirt_StructType_Structure_Type) { printf("<"); for (pos = 0; pos < ((Dirt_StructureStruct *) strct)->len; pos++) { printStruct(((Dirt_StructureStruct *) strct)->items[pos]); if (pos < ((Dirt_StructureStruct *) strct)->len - 1) printf(", "); } printf(">"); } else if (strct->type == &Dirt_StructType_Keyvalue) { printStruct(((Dirt_KeyvalueStruct *) strct)->key); printf(":"); printStruct(((Dirt_KeyvalueStruct *) strct)->value); } else if (strct->type == &Dirt_StructType_Parameter) { printStruct(((Dirt_KeyvalueStruct *) strct)->key); printf("="); printStruct(((Dirt_KeyvalueStruct *) strct)->value); } else if (strct->type == &Dirt_StructType_Member) { printStruct(((Dirt_KeyvalueStruct *) strct)->key); printf("."); printStruct(((Dirt_KeyvalueStruct *) strct)->value); } else if (strct->type == &Dirt_StructType_Application) { printStruct(((Dirt_KeyvalueStruct *) strct)->key); printf("("); for (pos = 0; pos < ((Dirt_StructureStruct*) ((Dirt_KeyvalueStruct *) strct)->value)->len; pos++) { printStruct(((Dirt_StructureStruct*) ((Dirt_KeyvalueStruct *) strct)->value)->items[pos]); if (pos < ((Dirt_StructureStruct*) ((Dirt_KeyvalueStruct *) strct)->value)->len - 1) printf(", "); } printf(")"); } }
void server_teacherId(socket_t * client, http_request_t * req, int index) { char strbuf[10000]; if (strcmp(req->method, "GET") == 0) { for(int i=0;i<5;i++) { printStruct(&teachers[index]); printf("\n"); } char * teachJSON = teacher_parseToJSON(&teachers[index]); sprintf(strbuf, "HTTP/1.1 200 OK\n" "Content-Type: application/json\n" "Content-Length: %zu\n" "Connection: keep-alive\n" "\n%s", strlen(teachJSON), teachJSON); free(teachJSON); } else if (strcmp(req->method, "POST") == 0) { char * str = http_request_getArg(req, "firstName"); if(str==NULL) { server_error(client); return; } if (str != NULL && strlen(str) < 25) { strcpy(teachers[index].firstName,str); } str = http_request_getArg(req, "lastName"); if (str != NULL && strlen(str) < 25) { strcpy(teachers[index].lastName,str); } str = http_request_getArg(req, "id"); if (str != NULL && isdigit(str[0]) != 0 && strlen(str) < 7) { teachers[index].id = atof(str); } str = http_request_getArg(req, "lessonName"); if (str != NULL && strlen(str) < 25) { strcpy(teachers[index].teacher_lesson.lessonName,str); } str = http_request_getArg(req, "average"); if (str != NULL) { float p = atof(str); teachers[index].teacher_lesson.average = p; } str = http_request_getArg(req, "birthTown"); if (str != NULL && strlen(str) < 25) { strcpy(teachers[index].idCard.birthTown,str); } str = http_request_getArg(req, "birthday"); int size = 10; if(str!=NULL) size = strlen(str); const char tmp[size]; if(str!=NULL) strcpy(tmp,str); if (str != NULL) { if (str[5] != NULL && str[4] == '-' && atoi(str) > 1900 && atoi(str) < 2016) { str = strtok(str, "-"); str = strtok(NULL, "-"); if (str != NULL && (atoi(str) >= 1 && atoi(str) <= 12)) { str = strtok(NULL, "-"); if (str != NULL && (atoi(str) >= 1 && atoi(str) <= 31)) { str = http_request_getArg(req, "birthday"); teachers[index].idCard.birthday.tm_year = atoi(str); strcpy(str,tmp); str = strtok(str, "-"); str = strtok(NULL, "-"); teachers[index].idCard.birthday.tm_mon = atoi(str); str = strtok(NULL, "-"); teachers[index].idCard.birthday.tm_mday = atoi(str); } } } } printStruct(&teachers[index]); char * tJSON = teacher_parseToJSON(&teachers[index]); printf("New student with id %i , type /teachers/%i to get full info", teachers[index].id,teachers[index].id , tJSON); sprintf(strbuf, "HTTP/1.1 200 OK\n" "Content-Type: application/json\n" "Content-Length: %zu\n" "Connection: keep-alive\n" "\n%s", strlen(tJSON), tJSON); free(tJSON); } else if (strcmp(req->method, "DELETE") == 0) { teacher_init(&teachers[index]); for(int i=0;i<5;i++) { printStruct(&teachers[i]); } char * delTeachJSON = teacher_parseToJSON(&teachers[index]); printf("Deleted student (%i-th one):\n%s\n", index, delTeachJSON); char * delText = "Student deleted successfully!"; sprintf(strbuf, "HTTP/1.1 200 OK\n" "Content-Type: application/json\n" "Content-Length: %zu\n" "Connection: keep-alive\n" "\n%s", strlen(delText), delText); free(delTeachJSON); } else { char * errText = "Invalid command!"; sprintf(strbuf, "HTTP/1.1 404 \n" "Content-Type: text/html\n" "Content-Length: %zu\n" "\n%s", strlen(errText), errText); } socket_write_string(client, strbuf); socket_close(client); }