Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <limits.h>
  3.  
  4. typedef struct {
  5.     char match;
  6.     int length;
  7. } glob_ret;
  8.  
  9. int stricmp(const char *s1, const char *s2) {
  10.    
  11.     for (;; s1++, s2++) {
  12.  
  13.         if (!*s1 || !*s2)
  14.             return 0;
  15.  
  16.         if (*s1 == *s2)
  17.             continue;
  18.  
  19.         if ((*s1) + 32 == *s2)
  20.             continue;
  21.  
  22.         if ((*s2) + 32 == *s1)
  23.             continue;
  24.  
  25.         return 0;
  26.     }
  27.  
  28.     return 1;
  29. }
  30.  
  31. int a_strlen(const char *s1) {
  32.     int len = 0;
  33.  
  34.     while (*s1++)
  35.         len++;
  36.  
  37.     return len;
  38. }
  39.  
  40. char a_toLower(const char s1) {
  41.     return s1 > 96 ? s1 : s1 + 32;
  42. }
  43.  
  44. void a_memcpy(char* c1, char* c2, int len) {
  45.     for (; len; c1++, c2++, len--)
  46.         *c1 = *c2;
  47. }
  48.  
  49. glob_ret match_glob(char seq[], char* pat) {
  50.  
  51.     const int seqLen = a_strlen(seq);
  52.     const int patLen = a_strlen(pat);
  53.  
  54.     if (strcmp(pat, "*") == 0)
  55.         return (glob_ret){ 1, seq };
  56.  
  57.     if(stricmp(pat, seq))
  58.         return (glob_ret) { 1, 0 };
  59.  
  60.     if((!(seqLen?1:0) != !(patLen?1:0)))
  61.         return (glob_ret) { 0, 0 };
  62.  
  63.     if (a_toLower(seq[0]) == a_toLower(pat[0])) {
  64.         memcpy(seq, seq+1, seqLen);
  65.         memcpy(pat, pat+1, patLen);
  66.         return match_glob(seq, pat);
  67.     }
  68. }
  69.  
  70. char* save_perm(char* dst, char* seq)
  71. {
  72.     int counter = 0;
  73.     for (; *seq; counter++, seq++) {
  74.        
  75.         if (counter == 2) {
  76.             counter = 0;
  77.             *dst = '-';
  78.             dst++;
  79.         }
  80.  
  81.         *dst = *seq;
  82.         dst++;
  83.     }
  84.  
  85.     *dst = '\n';
  86.     dst++;
  87. }
  88.  
  89. int main() {
  90.     char* test = malloc(16);
  91.     char* seq = "ATGCCGTA\0";
  92.  
  93.     save_perm(test, seq);
  94.  
  95.     getchar();
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement