void GameManager::endGame(Bike *winner) { GameOverScreen *gos = new GameOverScreen(winner?QString::fromStdString(winner->getName()):"Draw"); MainFrame::showOverlay(gos); //connect cleanup connect(gos, SIGNAL(exit()), this, SLOT(cleanGame())); connect(gos, SIGNAL(rematch()), this, SLOT(cleanGame())); //connect action connect(gos, SIGNAL(exit()), this, SLOT(showMainMenu())); connect(gos, SIGNAL(rematch()), this, SLOT(startGame())); }
int t_extract( char * in, float * temp ) { char re[] = "^(-?[0-9]+\\.?[0-9]*) *([cCfF])$"; size_t nmatch = 3; regmatch_t pmatch[ nmatch ]; char * temp_type, * temp_val; int value; if( rematch( in, re, nmatch, pmatch ) ) { temp_val = substring( in, pmatch[ 1 ].rm_so, pmatch[ 1 ].rm_eo - 1 ); // In order to free up at the end. *temp = ( float )str2num( temp_val ); temp_type = substring( in, pmatch[ 2 ].rm_so, pmatch[ 2 ].rm_eo - 1 ); if( *temp_type == 'c' || *temp_type == 'C' ) value = CELS; if( *temp_type == 'f' || *temp_type == 'F' ) value = FAHR; } else { fprintf( stderr, "t_extract: Bad temperature entry.\n" ); exit( 1 ); } free( temp_type ); free( temp_val ); return value; }
int main() { size_t nm = 2; regmatch_t pm[ nm ]; char * s; printf( "Enter string: " ); s = d_s( s ); char * re; printf( "Enter regex with parenthesized subexpression: " ); re = d_s( re ); if( rematch( s, re, nm, pm ) ) printf( "Subexpression = [%s]\n", substring( s, pm[ 1 ].rm_so, pm[ 1 ].rm_eo - 1 ) ); else printf( "Couldn't extract substring.\n" ); free( s ); return 0; }
int qsearch_main(int argc, char **argv) { FILE *fp; char *ebuild = NULL; char last[126] = ""; char *p, *q, *str; char *search_me = NULL; char show_homepage = 0, show_name_only = 0; char search_desc = 0, search_all = 0, search_name = 1, search_cache = CACHE_EBUILD; const char *search_vars[] = { "DESCRIPTION=", "HOMEPAGE=" }; size_t search_len, ebuild_len; int i, idx=0; DBG("argc=%d argv[0]=%s argv[1]=%s", argc, argv[0], argc > 1 ? argv[1] : "NULL?"); while ((i = GETOPT_LONG(QSEARCH, qsearch, "")) != -1) { switch (i) { COMMON_GETOPTS_CASES(qsearch) case 'a': search_all = 1; break; case 'c': search_cache = CACHE_METADATA; break; case 'e': search_cache = CACHE_EBUILD; break; case 's': search_desc = 0; search_name = 1; break; case 'S': search_desc = 1; search_name = 0; break; case 'N': show_name_only = 1; break; case 'H': show_homepage = 1, idx = 1; break; } } if (search_all) { search_desc = 1; search_name = 0; } else { if (argc == optind) qsearch_usage(EXIT_FAILURE); search_me = argv[optind]; } #ifdef TESTING /* FIXME: hardcoded */ if ((search_cache == CACHE_EBUILD) && (access("/usr/portage/.qsearch.x", R_OK) == 0)) { if ((fp = fopen("/usr/portage/.qsearch.x", "r")) != NULL) { search_len = strlen(search_me); while (fgets(buf, sizeof(buf), fp) != NULL) { if (strlen(buf) <= search_len) continue; /* add regexp, color highlighting and basename checks */ if (strncmp(buf, search_me, search_len) == 0) { fputs(buf, stdout); } } fclose(fp); return 0; } } #endif last[0] = 0; fp = fopen(initialize_flat(search_cache, false), "r"); if (!fp) return 1; int portdir_fd = open(portdir, O_RDONLY|O_CLOEXEC|O_PATH); if (portdir_fd < 0) errp("open(%s) failed", portdir); q = NULL; /* Silence a gcc warning. */ search_len = strlen(search_vars[idx]); while (getline(&ebuild, &ebuild_len, fp) != -1) { if ((p = strchr(ebuild, '\n')) != NULL) *p = 0; if (!ebuild[0]) continue; switch (search_cache) { case CACHE_METADATA: { portage_cache *pcache; if ((pcache = cache_read_file(ebuild)) != NULL) { if (strcmp(pcache->atom->PN, last) != 0) { strncpy(last, pcache->atom->PN, sizeof(last)); if ((rematch(search_me, (search_desc ? pcache->DESCRIPTION : ebuild), REG_EXTENDED | REG_ICASE) == 0) || search_all) printf("%s%s/%s%s%s %s\n", BOLD, pcache->atom->CATEGORY, BLUE, pcache->atom->PN, NORM, (show_name_only ? "" : (show_homepage ? pcache->HOMEPAGE : pcache->DESCRIPTION))); } cache_free(pcache); } else { if (!reinitialize) warnf("(cache update pending) %s", ebuild); reinitialize = 1; } break; } case CACHE_EBUILD: { FILE *ebuildfp; str = xstrdup(ebuild); p = dirname(str); if (strcmp(p, last) != 0) { bool show_it = false; strncpy(last, p, sizeof(last)); if (search_name) { if (rematch(search_me, basename(last), REG_EXTENDED | REG_ICASE) != 0) { goto no_cache_ebuild_match; } else { q = NULL; show_it = true; } } int fd = openat(portdir_fd, ebuild, O_RDONLY|O_CLOEXEC); if (fd != -1) { ebuildfp = fdopen(fd, "r"); if (ebuildfp == NULL) { close(fd); continue; } } else { if (!reinitialize) warnfp("(cache update pending) %s", ebuild); reinitialize = 1; goto no_cache_ebuild_match; } char *buf = NULL; size_t buflen; while (getline(&buf, &buflen, ebuildfp) != -1) { if (strlen(buf) <= search_len) continue; if (strncmp(buf, search_vars[idx], search_len) != 0) continue; if ((q = strrchr(buf, '"')) != NULL) *q = 0; if (strlen(buf) <= search_len) break; q = buf + search_len + 1; if (!search_all && !search_name && rematch(search_me, q, REG_EXTENDED | REG_ICASE) != 0) break; show_it = true; break; } if (show_it) { printf("%s%s/%s%s%s %s\n", BOLD, dirname(p), BLUE, basename(p), NORM, (show_name_only ? "" : q ? : "<no DESCRIPTION found>")); } free(buf); fclose(ebuildfp); } no_cache_ebuild_match: free(str); break; } /* case CACHE_EBUILD */ } /* switch (search_cache) */ }
bool vendorIsElementMappable (ElementType *element) { int i; int noskip; if (vendorMapEnable == false) return false; noskip = 1; for (i = 0; i < n_refdes; i++) { if ((NSTRCMP (UNKNOWN (NAMEONPCB_NAME (element)), ignore_refdes[i]) == 0) || rematch (ignore_refdes[i], UNKNOWN (NAMEONPCB_NAME (element)))) { Message (_ ("Vendor mapping skipped because refdes = %s matches %s\n"), UNKNOWN (NAMEONPCB_NAME (element)), ignore_refdes[i]); noskip = 0; } } if (noskip) for (i = 0; i < n_value; i++) { if ((NSTRCMP (UNKNOWN (VALUE_NAME (element)), ignore_value[i]) == 0) || rematch (ignore_value[i], UNKNOWN (VALUE_NAME (element)))) { Message (_ ("Vendor mapping skipped because value = %s matches %s\n"), UNKNOWN (VALUE_NAME (element)), ignore_value[i]); noskip = 0; } } if (noskip) for (i = 0; i < n_descr; i++) { if ((NSTRCMP (UNKNOWN (DESCRIPTION_NAME (element)), ignore_descr[i]) == 0) || rematch (ignore_descr[i], UNKNOWN (DESCRIPTION_NAME (element)))) { Message (_ ("Vendor mapping skipped because descr = %s matches %s\n"), UNKNOWN (DESCRIPTION_NAME (element)), ignore_descr[i]); noskip = 0; } } if (noskip && TEST_FLAG (LOCKFLAG, element)) { Message (_("Vendor mapping skipped because element %s is locked\n"), UNKNOWN (NAMEONPCB_NAME (element))); noskip = 0; } if (noskip) return true; else return false; }
//joblist_t *BuildJoblist(char *fname) joblist_t *BuildJoblist(config_t *config, dictionary *dict, joblist_t *badjob) { //dictionary *dict; char *k, **res, *section, *token, *val; charlist_t *keys; char entry[BUFSIZE+1]; char module[BUFSIZE+1]; int jobid=1; int nsect; int i=0, n=0, badjobid=-1; joblist_t *joblist=NULL, *joblist_head=NULL; if (badjob) badjobid=badjob->id; // dict = iniparser_load(fname); /* Get all the sections */ nsect = iniparser_getnsec(dict); for (n=0; n<nsect; n++) { // Each Section section = iniparser_getsecname(dict, n); if (strcmp(section, "main")==0) { // Set global parameters continue; } if (! section ) exit(-1); if (!joblist) { if (! (joblist = (joblist_t *) malloc( sizeof(joblist_t))) ) { exception(MODULE_NAME, EXCEPTION_PRIORITY_FATAL, "Failed to allocate memory"); return(NULL); } joblist_head = joblist; } else { if (! (joblist->next = (joblist_t *) malloc( sizeof(joblist_t))) ) { exception(MODULE_NAME, EXCEPTION_PRIORITY_FATAL, "Failed to allocate memory"); return(NULL); } joblist= joblist->next; } joblist->valid=TRUE; joblist->id=0; joblist->timestamp=0; joblist->activecount=0; joblist->prefix=NULL; joblist->jobname=strdup(section); joblist->modname=NULL; joblist->modpath=NULL; joblist->modhandle=NULL; joblist->runmin=NULL; joblist->runhr=NULL; joblist->targetlist[0]=NULL; joblist->next=NULL; snprintf(entry,BUFSIZE, "%s: %s", section, CONF_PREFIX); val = iniparser_getstring(dict, entry, "null"); if (strncmp(val, "null", strlen("null"))==0) { joblist->valid=FALSE; va_exception(MODULE_NAME, EXCEPTION_PRIORITY_WARNING, "Section=%s, key not found %s",section,CONF_PREFIX); } else { va_exception(MODULE_NAME, EXCEPTION_PRIORITY_DEBUG, "Section=%s, Key=%s, Val=%s",section, CONF_PREFIX, val); joblist->prefix=strdup(val); } snprintf(entry,BUFSIZE, "%s: %s", section, CONF_RUNTIME); val = iniparser_getstring(dict, entry, "null"); if (strncmp(val, "null", strlen("null"))==0) { joblist->valid=FALSE; va_exception(MODULE_NAME, EXCEPTION_PRIORITY_WARNING, "Section=%s, key not found %s",section,CONF_RUNTIME); } else { res = rematch(CONF_RUNPAT, val); if (!res) { va_exception(MODULE_NAME, EXCEPTION_PRIORITY_WARNING, "Section=%s, Key=%s, incorrect runtime format",section, CONF_RUNTIME); joblist->valid=FALSE; } else { if (badjob && (jobid == badjob->id)) joblist->valid=FALSE; joblist->id=jobid++; joblist->runmin=strdup(res[1]); // group 1 joblist->runhr=strdup(res[2]); // group 2 for (i=0; res[i]!=NULL;i++) free(res[i]); va_exception(MODULE_NAME, EXCEPTION_PRIORITY_DEBUG, "Section=%s, min=%s hr=%s",section, joblist->runmin, joblist->runhr); } } snprintf(entry,BUFSIZE, "%s: %s", section, CONF_TARGETS); // printf("Targets=%s\n", entry); val = iniparser_getstring(dict, entry, "null"); if (strncmp(val, "null", strlen("null"))==0) { va_exception(MODULE_NAME, EXCEPTION_PRIORITY_WARNING, "Section=%s, key not found %s",section,CONF_TARGETS); joblist->valid=FALSE; continue; } /* Can load targetlist by file also */ if ( strncmp(val,TARGET_FROM_FILE,strlen(TARGET_FROM_FILE))==0) { if (joblist->targetlist[0]) free_targetlist(joblist->targetlist); if (!( load_targets_from_file(val+strlen(TARGET_FROM_FILE), joblist->targetlist))) { va_exception(MODULE_NAME, EXCEPTION_PRIORITY_WARNING, "Section=%s, No targets found in file: %s",section, val+strlen(TARGET_FROM_FILE)); continue; } } else {