static void expand(const char *as) { const char *cs; const char *oldcs; char *sgpathp; struct stat stb; sgpathp = gpathp; cs = as; if (*cs == '~' && gpathp == gpath) { addpath('~'); for (cs++; letter(*cs) || digit(*cs) || *cs == '-';) addpath(*cs++); if (!*cs || *cs == '/') { if (gpathp != gpath + 1) { *gpathp = 0; if (gethdir(gpath + 1)) globerr = "Unknown user name after ~"; /* * Was: strcpy(gpath, gpath + 1); * but that's WRONG */ memmove(gpath, gpath+1, strlen(gpath+1)+1); } else { (void) strcpy(gpath, home); } gpathp = strend(gpath); } } while (!any(*cs, globchars)) { if (*cs == 0) { if (!globbed) Gcat(gpath, ""); else if (stat(gpath, &stb) >= 0) { Gcat(gpath, ""); globcnt++; } goto endit; } addpath(*cs++); } oldcs = cs; while (cs > as && *cs != '/') cs--, gpathp--; if (*cs == '/') cs++, gpathp++; *gpathp = 0; if (*oldcs == '{') { (void) execbrc(cs, ((char *)0)); return; } matchdir(cs); endit: gpathp = sgpathp; *gpathp = 0; }
void init_labels(char* filename) { if (filename) { addpath(mon_labels.userfile, filename); color(CONSCLR_DEFAULT); printf("lbl: "); color(CONSCLR_INFO); printf("%s\n", mon_labels.userfile); } else addpath(mon_labels.userfile, "user.l"); }
static void expand(char *as) { char *cs; char *sgpathp, *oldcs; struct stat stb; sgpathp = gpathp; cs = as; if (*cs == '~' && gpathp == gpath) { addpath('~'); for (cs++; letter(*cs) || digit(*cs) || *cs == '-';) addpath(*cs++); if (!*cs || *cs == '/') { if (gpathp != gpath + 1) { *gpathp = 0; if (gethdir(gpath + 1)) { (void)sprintf(errstring = errbuf, "Unknown user name: %s after '~'", gpath+1); globerr = IPS; } strcpy(gpath, gpath + 1); } else strcpy(gpath, home); gpathp = strend(gpath); } } while (!any(*cs, globchars) && globerr == 0) { if (*cs == 0) { if (!globbed) Gcat(gpath, ""); else if (stat(gpath, &stb) >= 0) { Gcat(gpath, ""); globcnt++; } goto endit; } addpath(*cs++); } oldcs = cs; while (cs > as && *cs != '/') cs--, gpathp--; if (*cs == '/') cs++, gpathp++; *gpathp = 0; if (*oldcs == '{') { (void)execbrc(cs, ((char *)0)); return; } matchdir(cs); endit: gpathp = sgpathp; *gpathp = 0; }
static void qsave(const char *fname) { char xx[0x200]; addpath(xx, fname); FILE *ff = fopen(xx, "wb"); if (ff) { if (writeSNA(ff)) sprintf(statusline, "Quick save to %s", fname), statcnt = 30; fclose(ff); } }
int main () { scanf("%d", &tcase); for (fcase = 1;fcase <= tcase;fcase++) { scanf("%d", &n); for (i = 1;i <= 26;i++)//初始化 { in[i] = out[i] = 0; f[i] = i; node[i].next = -1; } totnode = 26; totans = 0; for (i = 1; i <= n; i++) { scanf("%s", s); addpath(s[0] - 'a'+1, s[strlen(s) - 1] - 'a'+1, s); } if (!check(26))//如果不是一个欧拉图 { output(false);//输出。 continue;//继续上面的for循环(直接处理下一组数据了) } int flag; flag = false; for (i = 1; i <= 26; i++)//首先判断是否存在欧拉路 { if (out[i] == in[i] + 1)//如果哪个点的出度比入度多1,那么从这个点开始找 { euler(i, -1); flag = true;//标记 break; } } if (flag == false)//如果没有欧拉路,那么找欧拉回路 { for (i = 1; i <= 26; i++) if (out[i])//随便从一个点开始 { euler(i, -1);//找 break; } } output(true);//输出 } }
/* Break a string down into path components, store them into a queue */ static void parsepath(struct pathhead *pathq, char *path, int uniq) { char *p; struct pathentry *pe; while ((p = strsep(&path, ";")) != NULL) if (!uniq) { if (((pe = malloc(sizeof(*pe))) == NULL) || ((pe->path = strdup(p)) == NULL)) { errno = ENOMEM; err(1, "allocating path element"); } TAILQ_INSERT_TAIL(pathq, pe, next); } else { addpath(pathq, p, 1, 0); } }
void init_bpx(char* file) { addpath(BpxFileName, file ? file : "bpx.ini"); FILE *BpxFile = fopen(BpxFileName, "rt"); if (!BpxFile) return; if (file) { color(CONSCLR_DEFAULT); printf("bpx: "); color(CONSCLR_INFO); printf("%s\n", BpxFileName); } char Line[100]; while (!feof(BpxFile)) { fgets(Line, sizeof(Line), BpxFile); Line[sizeof(Line)-1] = 0; char Type = -1; int Start = -1, End = -1, CpuIdx = -1; int n = sscanf(Line, "%c%1d=%i-%i", &Type, &CpuIdx, &Start, &End); if (n < 3 || CpuIdx < 0 || CpuIdx >= (int)CpuMgr.GetCount() || Start < 0) continue; if (End < 0) End = Start; unsigned mask = 0; switch(Type) { case 'r': mask |= MEMBITS_BPR; break; case 'w': mask |= MEMBITS_BPW; break; case 'x': mask |= MEMBITS_BPX; break; default: continue; } Z80 &cpu = CpuMgr.Cpu(CpuIdx); for (unsigned i = unsigned(Start); i <= unsigned(End); i++) cpu.membits[i] |= mask; cpu.dbgchk = isbrk(cpu); } fclose(BpxFile); }
/* * If there are any Shell meta characters in the name, * expand into a list, after searching directory */ static void expsh(char *s) { char *cp; char *spathp, *oldcp; struct stat stb; spathp = pathp; cp = s; while (!any(*cp, shchars)) { if (*cp == '\0') { if (!expany || stat(path, &stb) >= 0) { if (which & E_TILDE) Cat(path, ""); else Cat(tilde, tpathp); } goto endit; } addpath(*cp++); } oldcp = cp; while (cp > s && *cp != '/') cp--, pathp--; if (*cp == '/') cp++, pathp++; *pathp = '\0'; if (*oldcp == '{') { execbrc(cp, NULL); return; } matchdir(cp); endit: pathp = spathp; *pathp = '\0'; }
static void qload(const char *fname) { char xx[0x200]; addpath(xx, fname); if (loadsnap(xx)) sprintf(statusline, "Quick load from %s", fname), statcnt = 30; }
static int amatch(char *s, char *p) { register int scc; int ok, lc; char *sgpathp; struct stat stb; int c, cc; globbed = 1; for (;;) { scc = *s++ & TRIM; switch (c = *p++) { case '{': return (execbrc(p - 1, s - 1)); case '[': ok = 0; lc = 077777; while ((cc = *p++)) { if (cc == ']') { if (ok) break; return (0); } if (cc == '-') { if (lc <= scc && scc <= *p++) ok++; } else if (scc == (lc = cc)) ok++; } if (cc == 0) { globerr = "Missing ]"; return (0); } continue; case '*': if (!*p) return (1); if (*p == '/') { p++; goto slash; } s--; do { if (amatch(s, p)) return (1); } while (*s++); return (0); case 0: return (scc == 0); default: if (c != scc) return (0); continue; case '?': if (scc == 0) return (0); continue; case '/': if (scc) return (0); slash: s = entp; sgpathp = gpathp; while (*s) addpath(*s++); addpath('/'); if (stat(gpath, &stb) == 0 && isdir(stb)) if (*p == 0) { Gcat(gpath, ""); globcnt++; } else expand(p); gpathp = sgpathp; *gpathp = 0; return (0); } } }
int __getcwd(char *path, size_t size) { struct stat above, current, tmp; struct dirent *entry; DIR *d; char *p, *up; const char *dotdot = ".."; int cycle; if (path == NULL || size <= 1) { errno= EINVAL; return -1; } p= path + size; *--p = 0; if (stat(".", ¤t) < 0) return -1; while (1) { if (stat(dotdot, &above) < 0) { recover(p); return -1; } if (above.st_dev == current.st_dev && above.st_ino == current.st_ino) break; /* Root dir found */ if ((d= opendir(dotdot)) == NULL) { recover(p); return -1; } /* Cycle is 0 for a simple inode nr search, or 1 for a search * for inode *and* device nr. */ cycle= above.st_dev == current.st_dev ? 0 : 1; do { char name[3 + NAME_MAX + 1]; tmp.st_ino= 0; if ((entry= readdir(d)) == NULL) { switch (++cycle) { case 1: rewinddir(d); continue; case 2: closedir(d); errno= ENOENT; recover(p); return -1; } } if (strcmp(entry->d_name, ".") == 0) continue; if (strcmp(entry->d_name, "..") == 0) continue; switch (cycle) { case 0: /* Simple test on inode nr. */ if (entry->d_ino != current.st_ino) continue; /*FALL THROUGH*/ case 1: /* Current is mounted. */ strcpy(name, "../"); strcpy(name+3, entry->d_name); if (stat(name, &tmp) < 0) continue; break; } } while (tmp.st_ino != current.st_ino || tmp.st_dev != current.st_dev); up= p; if (addpath(path, &up, entry->d_name) < 0) { closedir(d); errno = ERANGE; recover(p); return -1; } closedir(d); if (chdir(dotdot) < 0) { recover(p); return -1; } p= up; current= above; } if (recover(p) < 0) return -1; /* Undo all those chdir("..")'s. */ if (*p == 0) *--p = '/'; /* Cwd is "/" if nothing added */ if (p > path) strcpy(path, p); /* Move string to start of path. */ return 0; }
static int amatch(char *s, char *p) { int scc; int ok, lc, c, cc; char *spathp; struct stat stb; expany = 1; for (;;) { scc = *s++ & TRIM; switch (c = *p++) { case '{': return (execbrc(p - 1, s - 1)); case '[': ok = 0; lc = 077777; while ((cc = *p++)) { if (cc == ']') { if (ok) break; return (0); } if (cc == '-') { if (lc <= scc && scc <= *p++) ok++; } else if (scc == (lc = cc)) ok++; } if (cc == 0) { yyerror("Missing ']'"); return (0); } continue; case '*': if (!*p) return (1); if (*p == '/') { p++; goto slash; } for (s--; *s; s++) if (amatch(s, p)) return (1); return (0); case '\0': return (scc == '\0'); default: if ((c & TRIM) != scc) return (0); continue; case '?': if (scc == '\0') return (0); continue; case '/': if (scc) return (0); slash: s = entp; spathp = pathp; while (*s) addpath(*s++); addpath('/'); if (stat(path, &stb) == 0 && ISDIR(stb.st_mode)) { if (*p == '\0') { if (which & E_TILDE) Cat(path, ""); else Cat(tilde, tpathp); } else expsh(p); } pathp = spathp; *pathp = '\0'; return (0); } } }