char* getSeqDescr(char* seqid) { static char charbuf[128]; if (seqinfo.Count()==0) return NULL; char* suf=rstrchr(seqid, '.'); if (suf!=NULL) *suf=0; SeqInfo* seqd=seqinfo.Find(seqid); if (suf!=NULL) *suf='.'; if (seqd!=NULL) { GStr s(seqd->descr); //cleanup some Uniref gunk if (s[0]=='[') { int r=s.index(']'); if (r>=0 && r<8 && isdigit(s[1])) s.remove(0,r+1); } if (s.length()>80) { int r=s.index(';'); if (r>5) s.cut(r); } if (s.length()>127) { s.cut(127); int r=s.rindex(' '); if (r>0) s.cut(r); } strcpy(charbuf, s.chars()); return charbuf; } else return NULL; }
char* getSeqName(char* seqid) { static char charbuf[128]; char* suf=rstrchr(seqid, '.'); if (suf!=NULL) *suf=0; strcpy(charbuf, seqid); if (suf!=NULL) *suf='.'; return charbuf; }
char * normalize_path(const char *path) { size_t nslashes; char *buf, *dotdot, *p; int do_loop; const char *dotdot_str = "..", *slash_dotdot_str = "/.."; const size_t dotdot_str_len = sizeof(dotdot_str) - 1, slash_dotdot_str_len = sizeof(slash_dotdot_str) - 1; assert(path); buf = strip_space(path); if (*buf == '\0') { free(buf); return strdup("/"); } do { do_loop = 0; /* first, get rid of slases in the end, * as well as repeating slashes */ p = strrchr(buf, '\0'); while (*--p == '/' && p > buf) /* we handled the "" case above, so it's ok to *--p */ *p = '\0'; for (p = buf; p = strchr(p, '/'); ++p) { for (nslashes = 1; *(p + nslashes) == '/'; ++nslashes) /* empty */; if (nslashes > 1) memmove(p, p + nslashes - 1, strlen(p + nslashes - 1) + 1); } /* now take care of ".." */ while (dotdot = strstr(buf, slash_dotdot_str)) { /* while dealing with .. we might introduce * repeating slashes, so loop the outer loop * once more... */ do_loop = 1; if (dotdot == buf) { free(buf); return strdup("/"); } else if (p = rstrchr(buf, dotdot - 1, '/')) { memmove(p, dotdot + slash_dotdot_str_len, strlen(dotdot + slash_dotdot_str_len) + 1); } else { free(buf); return strdup("/"); } } for (dotdot = buf; dotdot = strstr(dotdot, dotdot_str); dotdot += dotdot_str_len) { if (dotdot == buf || *(dotdot - 1) != '/') { free(buf); return strdup("/"); } } if (!strchr(buf, '/')) { free(buf); return strdup("/"); } } while (do_loop); return buf; }