void overloaded_call() { one overloaded(int); two overloaded(double); static_assert(sizeof(overloaded({0})) == sizeof(one), "bad overload"); // expected-warning {{braces around scalar init}} static_assert(sizeof(overloaded({0.0})) == sizeof(two), "bad overload"); // expected-warning {{braces around scalar init}} void ambiguous(int, double); // expected-note {{candidate}} void ambiguous(double, int); // expected-note {{candidate}} ambiguous({0}, {0}); // expected-error {{ambiguous}} void emptylist(int); void emptylist(int, int, int); emptylist({}); emptylist({}, {}, {}); }
void PlaylistManager::load() { Q_D(PlaylistManager); for (auto &playlistmeta : MediaDatabase::instance()->allPlaylistMeta()) { PlaylistPtr emptylist(new Playlist(playlistmeta)); emptylist->load(); insertPlaylist(playlistmeta.uuid, emptylist); } QMap<uint, QString> sortUUIDs; for (auto playlist : d->playlists) { sortUUIDs.insert(playlist->sortID(), playlist->id()); } QSqlDatabase::database().transaction(); if (sortUUIDs.size() != d->playlists.size()) { qWarning() << "playlist order crash, restrot"; d->sortUUIDs.clear(); d->sortUUIDs << SearchMusicListID << AllMusicListID << FavMusicListID; QStringList sortUUIDs; for (auto playlist : d->playlists.values()) { sortUUIDs << playlist->id(); } sortUUIDs.removeAll(SearchMusicListID); sortUUIDs.removeAll(AllMusicListID); sortUUIDs.removeAll(FavMusicListID); d->sortUUIDs << sortUUIDs; saveSortOrder(); } else { for (auto sortID = 0; sortID < sortUUIDs.size(); ++sortID) { d->sortUUIDs << sortUUIDs.value(static_cast<uint>(sortID)); } } auto all = playlist(AllMusicListID); auto trAllName = tr("All Music"); if (!all.isNull() && all->displayName() != trAllName) { all->setDisplayName(trAllName); } auto fav = playlist(FavMusicListID); auto trFavName = tr("My favorites"); if (!fav.isNull() && fav->displayName() != trFavName) { fav->setDisplayName(trFavName); } auto search = playlist(SearchMusicListID); auto searchName = tr("Search result"); if (!search.isNull() && search->displayName() != searchName) { search->setDisplayName(searchName); } QSqlDatabase::database().commit(); }
/** * Simple oblivious Routing (TOR). */ route_t* TOrouting (long src, long dst) { long lvl; route_t *aux, *aux2, *res; long sc,dc; // cluster (ficonn) the source and destination belong to. long pren, postn; // ids of the nodes connecting the two ficonns if(src==dst) { // printf("should not be trying to route a packet that is at its destination (curr: %ld, dst: %ld)!\n", current, destination); aux=emptylist(); // empty set return aux; // just in case, let's abort the routing } // DEBUG for (lvl=param_k; lvl>0; lvl--) if(src/fic_size[lvl-1]!=dst/fic_size[lvl-1]) break; if(lvl==0) // Easy, just traverse the switch; return concat_nn(0, dst%param_n); // port 0 goes to the switch sc=(src%fic_size[lvl])/fic_size[lvl-1]; dc=(dst%fic_size[lvl])/fic_size[lvl-1]; #ifdef DEBUG if(sc==dc) { printf("should not be in the same ficonn at this level (curr: %ld, dst: %ld)!\n", sc, dc); } #endif // DEBUG if(sc<dc) dc--; else sc--; pren = ((src/fic_size[lvl-1])*fic_size[lvl-1]) // first node in cluster sc + (dc*two_pow[lvl])+two_pow[lvl-1]-1; // node in cluster sc connected to cluster dc postn = ((dst/fic_size[lvl-1])*fic_size[lvl-1]) // same as above + (sc*two_pow[lvl])+two_pow[lvl-1]-1; aux=newlist(1); res=aux; //printf ("lvl %ld: src %ld (%ld,%ld), dst %ld (%ld,%ld), pren %ld, postn %ld\n",lvl,src,sc,sn,dst,dc,dn,pren,postn); if (pren!=src) { res=concat_ll(TOrouting(src,pren),aux); free(aux); // rfree++; aux=res; } if (postn!=dst) { aux2=TOrouting(postn,dst); res=concat_ll(aux,aux2); free(aux2); // rfree++; } return res; }
int main(int argc, char** argv) { list l1 = emptylist(); int el; do { printf("\n Introdurre valore:\t"); el=getElement(); l1 = insord2(el, l1); } while (el!=0); /* condiz. arbitraria */ showlist(l1); getchar(); return 0; }
int main(int argc, char *argv[]) { printf("main method running %d argc", argc); int i, j, k; count = 0; struct hostent *server; int sync = 0; //if (argc < 2) //{ //fprintf(stderr,"ERROR, no host provided\n"); //} /*Initialize socket*/ sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error1("ERROR opening socket"); bzero((char *) &serv_addr, sizeof(serv_addr)); port_num = 51717; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = inet_addr(argv[1]); serv_addr.sin_port = htons(port_num); if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) { error1("Error on connect(), exitting"); exit(-1); } //Synchronization fprintf(stderr, "Syncing... "); n = read(sockfd, &header, sizeof(struct fft_header)); if( n == 0) { printf("Sender has closed connection1\n"); exit(0); } else if( n > 0) { printf("Read %d bytes from header, header.constSync is %X\n", n, header.constSync); } do { for(i = 0; i < sizeof(struct fft_header)-7; i++) { if(header.constSync != 0xACFDFFBC) { memcpy(&tempHeader, ((char*)(&header))+ 1, sizeof(struct fft_header) - 1 - i); memcpy(&header, &tempHeader, sizeof(struct fft_header)); } else { sync = 1; i++; break; } memset(&tempHeader, 0, sizeof(struct fft_header)); printf("%0x\n", header.constSync); } if(i > 1) { n = read(sockfd, &header + sizeof(struct fft_header) - 1- i,i - 1); if( n == 0) { printf("Sender has closed connection1\n"); exit(0); } } }while(!sync); if(header.constSync != 0xACFDFFBC) error1("ERROR reading from socket, incorrect header placement\n"); fprintf(stderr, "Synced... \n"); /* //First Header fprintf(stderr, "Reading header... "); n = read(sockfd, &header, sizeof(struct fft_header)); if (n < 0) error1("ERROR reading from socket"); else if (n > 0) { printf("header.constSync is %X\n", header.constSync); if(header.constSync != 0xACFDFFBC) error1("ERROR reading from socket, incorrect header placement\n"); } else if( n == 0) { printf("Sender has closed connection\n"); exit(0); } */ //Initializing structures samp_rate = header.ptsPerFFT; buffer = malloc(sizeof(double) * samp_rate); bufSize = sizeof(double)* samp_rate; length = (sizeof(struct fft_header) + sizeof(double)* samp_rate); size = length* 2 + 1; tempBuf = malloc(length); //First Data fprintf(stderr, "Reading data... "); n = read(sockfd, (char *) buffer, header.ptsPerFFT * sizeof(double)); if (n < 0) error1("ERROR reading from socket"); else if( n == 0) { printf("Sender has closed connection\n"); exit(0); } else { printf("Read %d bytes data\n", n); printf("checkpoint 1\n"); } /*End*/ // socket for server // socket setup printf("Setting up server\n"); // if (argc < 2) // { // if(debug)fprintf(stderr,"ERROR, no host provided\n"); // exit(1); // } portno1 = 51718; sockfd1 = socket(AF_INET, SOCK_STREAM, 0); if (sockfd1 < 0) err("ERROR opening socket"); //server = gethostbyname(argv[1]); bzero((char *) &serv_addr1, sizeof(serv_addr1)); serv_addr1.sin_family = AF_INET; serv_addr1.sin_addr.s_addr = INADDR_ANY; serv_addr1.sin_port = htons(portno1); if (bind(sockfd1, (struct sockaddr *) &serv_addr1, sizeof(serv_addr1)) < 0) err("ERROR on binding"); printf("Listening for connections..\n"); listen(sockfd1,5); clilen1 = sizeof(cli_addr1); int flags = fcntl(sockfd1, F_GETFL, 0);//set the new socket to non blocking fcntl(sockfd1, F_SETFL, flags | O_NONBLOCK); list = emptylist(); // initialize the linked list that will contain the client types while(1){ //listen(sockfd1,5); //printf("Listening....\n"); clilen1 = sizeof(cli_addr1); newsockfd1 = accept(sockfd1, (struct sockaddr *) &cli_addr1, &clilen1); printf(" file descriptor value %d \n",newsockfd1); if (newsockfd1 < 0) printf("No connection to client\n"); if(newsockfd1 != EAGAIN && newsockfd1 !=EWOULDBLOCK && newsockfd1 >= 0){ printf("Accepted a connection..\n"); printf(" file descriptor value %d \n",newsockfd1); add(newsockfd1,list); printf("Added a client file descriptor value %d \n",newsockfd1); } getData(); } //newsocket for client, tempbuffer, length //n = write(newsockfd, out, (N/2+1) * sizeof(double)); //loadeImage function //call shift every 50msec return 0; }
int putprinter(char *name, PRINTER *prbufp) { register char * path; register char * stty; register char * speed; int fdin, fdout; int fld; char buf[BUFSIZ]; struct stat statbuf1, statbuf2; badprinter = 0; if (!name || !*name) { errno = EINVAL; return (-1); } if (STREQU(NAME_ALL, name)) { errno = EINVAL; return (-1); } /* * First go through the structure and see if we have * anything strange. */ if (!okprinter(name, prbufp, 1)) { errno = EINVAL; return (-1); } if (!Lp_A_Printers || !Lp_A_Interfaces) { getadminpaths (LPUSER); if (!Lp_A_Printers || !Lp_A_Interfaces) return (0); } /* * Create the parent directory for this printer * if it doesn't yet exist. */ if (!(path = getprinterfile(name, (char *)0))) return (-1); if (Stat(path, &statbuf1) == 0) { if (!S_ISDIR(statbuf1.st_mode)) { Free (path); errno = ENOTDIR; return (-1); } } else if (errno != ENOENT || mkdir_lpdir(path, MODE_DIR) == -1) { Free (path); return (-1); } Free (path); /* * Create the copy of the interface program, unless * that would be silly or not desired. * Conversely, make sure the interface program doesn't * exist for a remote printer. */ if (prbufp->remote) { if (!(path = makepath(Lp_A_Interfaces, name, (char *)0))) return (-1); (void)rmfile (path); Free (path); } if (prbufp->interface && (ignprinter & BAD_INTERFACE) == 0) { if (Stat(prbufp->interface, &statbuf1) == -1) return (-1); if (!(path = makepath(Lp_A_Interfaces, name, (char *)0))) return (-1); if ( Stat(path, &statbuf2) == -1 || statbuf1.st_dev != statbuf2.st_dev || statbuf1.st_ino != statbuf2.st_ino ) { register int n; if ((fdin = open_locked(prbufp->interface, "r", 0)) < 0) { Free (path); return (-1); } if ((fdout = open_locked(path, "w", MODE_EXEC)) < 0) { Free (path); close(fdin); return (-1); } while ((n = read(fdin, buf, BUFSIZ)) > 0) write (fdout, buf, n); close(fdout); close(fdin); } Free (path); } #ifdef LP_USE_PAPI_ATTR /* * Handle PPD (Postscript Printer Definition) file for printer * if this printer has been configured with one */ if ((prbufp->ppd != NULL) && (ppdopt)) { if (addPrintersPPD(name, prbufp) != 0) { /* failed to added the printers PPD file */ return (-1); } } #endif /* * If this printer is dialed up, remove any baud rates * from the stty option list and move the last one to * the ".speed" member if the ".speed" member isn't already * set. Conversely, if this printer is directly connected, * move any value from the ".speed" member to the stty list. */ stty = (prbufp->stty? Strdup(prbufp->stty) : 0); if (prbufp->speed) speed = Strdup(prbufp->speed); else speed = 0; if (prbufp->dial_info && stty) { register char *newstty, *p, *q; register int len; if (!(q = newstty = Malloc(strlen(stty) + 1))) { Free (stty); errno = ENOMEM; return (-1); } newstty[0] = 0; /* start with empty copy */ for ( p = strtok(stty, " "); p; p = strtok((char *)0, " ") ) { len = strlen(p); if (strspn(p, "0123456789") == len) { /* * If "prbufp->speed" isn't set, then * use the speed we just found. Don't * check "speed", because if more than * one speed was given in the list, we * want the last one. */ if (!prbufp->speed) { if (speed) Free (speed); speed = Strdup(p); } } else { /* * Not a speed, so copy it to the * new stty string. */ if (q != newstty) *q++ = ' '; strcpy (q, p); q += len; } } Free (stty); stty = newstty; } else if (!prbufp->dial_info && speed) { register char *newstty; newstty = Malloc(strlen(stty) + 1 + strlen(speed) + 1); if (!newstty) { if (stty) Free (stty); errno = ENOMEM; return (-1); } if (stty) { strcpy (newstty, stty); strcat (newstty, " "); strcat (newstty, speed); Free (stty); } else strcpy (newstty, speed); Free (speed); speed = 0; stty = newstty; } /* * Open the configuration file and write out the printer * configuration. */ if (!(path = getprinterfile(name, CONFIGFILE))) { if (stty) Free (stty); if (speed) Free (speed); return (-1); } if ((fdout = open_locked(path, "w", MODE_READ)) < 0) { Free (path); if (stty) Free (stty); if (speed) Free (speed); return (-1); } Free (path); errno = 0; for (fld = 0; fld < PR_MAX; fld++) { if (prbufp->remote && !prtrheadings[fld].okremote) continue; switch (fld) { #define HEAD prtrheadings[fld].v case PR_BAN: { char *ptr = NAME_ON; switch (prbufp->banner) { case BAN_ALWAYS: ptr = NAME_ON; break; case BAN_NEVER: ptr = NAME_OFF; break; case BAN_OPTIONAL: ptr = NAME_OPTIONAL; break; } (void)fdprintf(fdout, "%s %s\n", HEAD, ptr); } break; case PR_CPI: print_sdn(fdout, HEAD, prbufp->cpi); break; case PR_CS: if (!emptylist(prbufp->char_sets)) print_l(fdout, HEAD, prbufp->char_sets); break; case PR_ITYPES: /* * Put out the header even if the list is empty, * to distinguish no input types from the default. */ print_l(fdout, HEAD, prbufp->input_types); break; case PR_DEV: print_str(fdout, HEAD, prbufp->device); break; case PR_DIAL: print_str(fdout, HEAD, prbufp->dial_info); break; case PR_RECOV: print_str(fdout, HEAD, prbufp->fault_rec); break; case PR_INTFC: print_str(fdout, HEAD, prbufp->interface); break; case PR_LPI: print_sdn(fdout, HEAD, prbufp->lpi); break; case PR_LEN: print_sdn(fdout, HEAD, prbufp->plen); break; case PR_LOGIN: if (prbufp->login & LOG_IN) (void)fdprintf(fdout, "%s\n", HEAD); break; case PR_PTYPE: { char **printer_types; /* * For backward compatibility for those who * use only "->printer_type", we have to play * some games here. */ if (prbufp->printer_type && !prbufp->printer_types) printer_types = getlist( prbufp->printer_type, LP_WS, LP_SEP ); else printer_types = prbufp->printer_types; if (!printer_types || !*printer_types) print_str(fdout, HEAD, NAME_UNKNOWN); else print_l(fdout, HEAD, printer_types); if (printer_types != prbufp->printer_types) freelist (printer_types); break; } case PR_REMOTE: print_str(fdout, HEAD, prbufp->remote); break; case PR_SPEED: print_str(fdout, HEAD, speed); break; case PR_STTY: print_str(fdout, HEAD, stty); break; case PR_WIDTH: print_sdn(fdout, HEAD, prbufp->pwid); break; #if defined(CAN_DO_MODULES) case PR_MODULES: /* * Put out the header even if the list is empty, * to distinguish no modules from the default. */ print_l(fdout, HEAD, prbufp->modules); break; #endif case PR_OPTIONS: print_l(fdout, HEAD, prbufp->options); break; case PR_PPD: { print_str(fdout, HEAD, prbufp->ppd); break; } } } if (stty) Free (stty); if (speed) Free (speed); if (errno != 0) { close(fdout); return (-1); } close(fdout); /* * If we have a description of the printer, * write it out to a separate file. */ if (prbufp->description) { if (!(path = getprinterfile(name, COMMENTFILE))) return (-1); if (dumpstring(path, prbufp->description) == -1) { Free (path); return (-1); } Free (path); } /* * Now write out the alert condition. */ if ( prbufp->fault_alert.shcmd && putalert(Lp_A_Printers, name, &(prbufp->fault_alert)) == -1 ) return (-1); return (0); }