void listAll(const Class* c, string path) // two-parameter overload { // Base case if(path == "") { cout << c->name() << endl; listAll(c, c->name() + "=>"); return; } // end if for(int i=0; i<c->subclasses().size(); i++) { Class* temp=c->subclasses().at(i); cout << path + temp->name() << endl; listAll(temp, path+ temp->name() + "=>"); } // end for } // end listAll
int processCommand(char* str, SSL* ssl ) { char *cmd[10]; int i = 0; char stcpy[5]; cmd[i] =strtok(str," "); while (cmd[i] != NULL && i <10) { cmd[++i] =strtok(NULL, " "); } if (strcmp(cmd[0], "-a")== 0){ printf("Server: Client would like to add %s file to the server.. : \n", cmd[1]); addFile(cmd[1] , ssl); } else if (strcmp(cmd[0], "-f")== 0){ printf("Server: Client would like to fetch %s file from the server.. : \n", cmd[1]); if( sendFile(cmd[1] ,ssl) == -1 ) printf("Server: Send Failed"); } else if (strcmp(cmd[0], "-u")== 0){ printf("Client would like to upload a certificate. : \n"); addCert(cmd[1],ssl); } else if (strcmp(cmd[0], "-v")== 0){ printf("Client would like to Vouch for file: %s on the server.. : \n", cmd[1]); //vouchforfile(FileName, certificate); } else if (strcmp(cmd[0], "-h")== 0){ printf("HostName: PortNumber: %s \n", cmd[1]); } else if (strcmp(cmd[0], "-l")== 0){ printf("List Files.. \n"); listAll(ssl); } else { return -1; } //HANDLE EXIT COMMAND --No Longer Needed? strncpy(stcpy, str, 4); stcpy[4] = '\0' ; if (strcmp(stcpy, "exit")== 0) return 9; return 0; }
void listAll(const Class* c, string path) // two-parameter overload { if (c == nullptr) return; // cout << path << c->name() << endl; path += c->name(); cout << path << endl; // Path includes the classes that come before it for (vector<Class*>::const_iterator it = c->subclasses().begin(); it != c->subclasses().end(); it++) listAll((*it), path + "=>"); }
int main(int argc, const char * argv[]) { Node *node1 = initListItem(1); Node *node2 = initListItem(2); Node *node3 = initListItem(3); Node *node4 = initListItem(4); Node *node5 = initListItem(5); Node *newNode = initListItem(6); insertToTheEnd(node1, node2); insertToTheEnd(node1, node3); insertToTheEnd(node1, node4); insertToTheEnd(node1, node5); printf("All values in the list: "); listAll(node1); int valueUserInput; printf("Input the value to find:"); scanf("%d", &valueUserInput); Node *searchResult = searchValue(node1, valueUserInput); if (searchResult == NULL) { printf("%d is not found in this list!\n", valueUserInput); } else { printf("Search result %d found at %p\n", searchResult->value, searchResult); printf("%p\n", node2); } insertToTheEnd(node1, newNode); listAll(node1); removeListItem(node1, node2); listAll(node1); deallocation(node1); return 0; }
int runFunctionMenu(int menu, Product *article, Suplier *provider, int lenght) { int ret = 1; if(article!=NULL && provider!=NULL && lenght>0) { switch(menu) { case ADD : cleanScreen(); addArticle(article, provider, lenght); pauseScreen(); break; case MODIFY : cleanScreen(); modifyArticle(article, provider, lenght); pauseScreen(); break; case DEL : cleanScreen(); delArticle(article, lenght); pauseScreen(); break; case LS_PRODUCT : cleanScreen(); listArticle(article, lenght); pauseScreen(); break; case LS_ALL : cleanScreen(); listAll(article, provider, lenght); pauseScreen(); break; case EXIT : ret = 0; break; } } else { ret = -1; } return ret; }
void listAll(const Class* c, string path) // two-parameter overload { path += c->name(); cout<<path<<endl; vector<Class*> subclasses = c->subclasses(); if(subclasses.size() == 0){ return; } path += "=>"; for(vector<Class*>::const_iterator it = subclasses.begin(); it != subclasses.end(); it++){ listAll((*it), path); } }
void listAll(const MenuItem* m, string path) // two-parameter overload { if (m == nullptr) return; path += m->name(); if (path != "") cout << path << endl; if (m->menuItems() == nullptr) return; if (path != "") path += "/"; const vector<MenuItem*>* ptr = m->menuItems(); for (int k = 0; k < ptr->size(); k++) listAll((*ptr)[k], path); }
int main(){ char choice = 's'; int input; startFileRead(); while(choice != EXIT){ scanf("%c", &choice); switch(choice){ case INSERT: insertReg(); break; case SEARCH: scanf("%d", &input); search(input); break; case REMOVE: scanf("%d", &input); removeRegister(input); break; case LISTALL: listAll(); break; case ACCESS: counterAccess(); break; case EXIT: break; default: printf("Entrada Inválida\n"); break; } getchar(); } return 0; }
int main(int argc, char *argv[]) /* Process command line. */ { char *command; optionInit(&argc, argv, options); if (argc < 2) usage(); port = optionInt("port", port); host = optionVal("host", host); penalty = optionInt("penalty", penalty); recovery = optionInt("recovery", recovery); subnet = optionVal("subnet", subnet); command = argv[1]; if (sameString(command, "start")) { if (argc != 2) usage(); forkOffServer(); } else if (sameString(command, "query")) { int count = 1; if (argc > 3) count = atoi(argv[3]); queryServer(argv[2], count); } else if (sameString(command, "list")) { listAll(); } else if (sameString(command, "set")) { if (argc != 4) usage(); setUser(argv[2], argv[3]); } else { usage(); } return 0; }
//----------------------------- // Name : processCmd() //----------------------------- void PoetryGen::processCmd( int cmd_ind ) { switch ( cmd_ind ) { case help: printHelp(); break; case clr: clearAll(); break; case ac: addWrdToCat(); break; case at: addTemplate(); break; case gen: printPoem(); break; case ln: setLinesNumber(); break; case ls: listAll(); break; case inv: default: WARNING( UNKNOWN_COMMAND ); break; } printf("\n"); }
void socketMode(tArvoreBB **tree, FILE **arq) { WSADATA wsaData; WSAStartup(MAKEWORD(2,2), &wsaData); SOCKET sock = socket(AF_INET, SOCK_STREAM, 0); char buf[32] = {0}, op = 1; if(sock != INVALID_SOCKET) { struct sockaddr_in serv_addr = {0}; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(PORT); if(bind(sock, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) == 0) { int len; struct sockaddr_in cli_addr; SOCKET newsock; listen(sock, BACKLOG); len = sizeof(struct sockaddr_in); newsock = accept(sock, (struct sockaddr *) &cli_addr, &len); // if (newsock != INVALID_SOCKET) // printf("Nova conexao: %s:%d\n", inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port)); while(op != 0) { if (newsock != INVALID_SOCKET) { while(recv(newsock, buf, sizeof(buf)-1, 0) <=0); //printf("received: %s\n", buf); op = buf[strlen(buf)-1] - 48; tfunc func; char buffer[30]={0}; strncpy(buffer, buf, 3); buffer[3] = '\0'; func.mat = atoi(buffer); strncpy(func.nome,buf+3,20); func.nome[20] = '\0'; strncpy(buffer,buf+23,7); buffer[7] = '\0'; func.sal = atof(buffer); switch(op) { case 1: { insertFunc(*arq, tree, func); break; } case 2: { alterSalary(arq, *tree, func.mat, func.sal); break; } case 3: { deleteFunc(tree,func.mat); break; } case 4: { listFunc(*arq, *tree, func.mat); break; } case 5: listAll(*arq, *tree); break; case 6: listStruct(*tree); break; case 7: reindex(arq, tree); break; case 8: deleteAll(tree, arq); break; } } else { printf("Erro ao conectar\n"); } } } else { printf("Erro no bind()\n"); } } }
int processCommand(char* str, SSL* ssl ) { char *cmd[10]; int i = 0; char stcpy[5]; cmd[i] =strtok(str," "); while (cmd[i] != NULL && i <10) { cmd[++i] =strtok(NULL, " "); } //HANDLE COMMANDS .. PASS SSL TO SEPERATE METHODS IF NEEDED. PRINTF JUST FOR TESTING UNTIL METHODS ARE IMPLEMENTED //HANDLE EXIT COMMAND...btw string manipulation in c is bullshit! :D strncpy(stcpy, str, 4); stcpy[4] = '\0' ; if (strcmp(stcpy, "exit")== 0) return 9; if (strcmp(cmd[0], "-a")== 0){ printf("Server: Client would like to add %s file to the server.. : \n", cmd[1]); addFile(cmd[1] , ssl); } else if (strcmp(cmd[0], "-c")== 0){ printf("Server: Client requires circle of trust change....%s: \n", cmd[1]); //setTrust(); -handle in client } else if (strcmp(cmd[0], "-f")== 0){ printf("Server: Client would like to fetch %s file from the server.. : \n", cmd[1]); if ( sendFile(cmd[1] ,ssl) == -1 ) printf("Server: Send Failed"); } else if (strcmp(cmd[0], "-n")== 0){ printf("Circle of trust requires %s To be in the circle\n", cmd[1]); //incNameintrust(char* name); --client?? } else if (strcmp(cmd[0], "-u")== 0){ printf("Client would like to upload a certificate. : \n"); //addCert(); } else if (strcmp(cmd[0], "-v")== 0){ printf("Client would like to Vouch for file: %s on the server.. : \n", cmd[1]); //vouchforfile(FileName, certificate); } else if (strcmp(cmd[0], "-h")== 0){ printf("HostName: PortNumber: %s \n", cmd[1]); //vouchforfile(FileName, certificate); } else if (strcmp(cmd[0], "-l")== 0){ printf("List Files.. \n"); listAll(ssl); } //Default Error Message (Non Supported Commands). else { return -1; } return 0; }