Advertisement
Guest User

Untitled

a guest
Apr 12th, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.87 KB | None | 0 0
  1. /******************************
  2. **          STRING.H         **
  3. ******************************/
  4.  
  5. strcmp(char *pa, char *pb) {
  6.     while (*pa && *pb && *pa == *pb)
  7.         ++pa, ++pb;
  8.     return *pa - *pb;
  9. }
  10.  
  11. strlen(char *str) {
  12.     int pos;
  13.     pos = str;
  14.     while (*str++) ;
  15.     return (str - pos - 1);
  16. }
  17.  
  18. strcpy(char *dst, char *src) {
  19.     int *d;
  20.     d = dst;
  21.     while (*d++ = *src++) ;
  22.     return dst;
  23. }
  24.  
  25. strncpy(char *s1, char *s2, int n) {
  26.     int *os1;
  27.     os1 = s1;
  28.    
  29.     while (n-- && (*s1++ = *s2++)) ;
  30.    
  31.     if (n != 0) { *s1 = 0; }
  32.    
  33.     return os1;
  34. }
  35.  
  36. strcat(char *dst, char *src) {
  37.     int save;
  38.     save = dst;
  39.     for (; *dst; ++dst);
  40.     while (*dst++ = *src++) ;
  41.     return (save);
  42. }
  43.  
  44. strchr(char *str, char chr) {
  45.     int *p;
  46.     for(p = str; *p != 0; ++p) {
  47.         if (*p == chr)
  48.             return p;
  49.     }
  50.     return 0;
  51. }
  52.  
  53. strrev(char *szT) {
  54.     if (!szT)
  55.         return "";
  56.     int i, t, k, j, ch;
  57.     i = strlen(szT);
  58.     t = !(i%2)? 1 : 0;
  59.     for(j = i - 1, k = 0; j > (i/2 - t); j--) {
  60.         ch = szT[j];
  61.         szT[j] = szT[k];
  62.         szT[k++] = ch;
  63.     }
  64.    
  65.     return szT;
  66. }
  67.  
  68. /******************************
  69. **           STDIO.H         **
  70. ******************************/
  71.  
  72. char *ccp = 0x7600;
  73. int  *kbf = 0x75ff;
  74.  
  75. clrscr() {
  76.     char *i;
  77.     i = 0x7600;
  78.     while (i < 0x7800) {
  79.         *i++ = 0;
  80.     }
  81. }
  82.  
  83. gotoxy(int x, int y) {
  84.     ccp = 0x7600 + (x + y * 32);
  85. }
  86.  
  87. putc(char chr) {
  88.     if (chr == 13) {
  89.         ccp /= 32;
  90.         ccp *= 32;
  91.     } else if (chr == 10) {
  92.         ccp += 32;
  93.     } else {
  94.         *ccp++ = chr | 0x0f00;
  95.     }
  96. }
  97.  
  98. puts(char *ptr) {
  99.     while (*ptr) {
  100.         putc(*ptr++);
  101.     }
  102. }
  103.  
  104. putd(int num) {
  105.     int temp[5], i;
  106.     i = 0;
  107.  
  108.     do {
  109.         temp[i++] = num % 10 + 48;
  110.         num /= 10;
  111.     } while (num);
  112.  
  113.  
  114.     for(--i; i != 0xffff; --i) {
  115.         putc(temp[i]);
  116.     }
  117. }
  118.  
  119. putx(int xnm) {
  120.     int temp[4], i;
  121.     i = 3;
  122.  
  123.     do {
  124.         int mod;
  125.         mod = xnm % 16;
  126.         mod += mod < 10 ? 48 : 55;
  127.         temp[i--] = mod;
  128.         xnm /= 16;
  129.     } while (xnm);
  130.  
  131.     for(;i<3;) {
  132.         putc(temp[++i]);
  133.     }
  134. }
  135.  
  136. printf(char *fmt) {
  137.     int off, len;
  138.     off = 1;
  139.     len = strlen(fmt);
  140.    
  141.     int i;
  142.     for(i = 0; i < len; i++) {
  143.         if (fmt[i] == 37) {
  144.             if (fmt[i + 1] == 100)
  145.                 { putd(*(&fmt + off++)); ++i; }
  146.             if (fmt[i + 1] == 115)
  147.                 { puts(*(&fmt + off++)); ++i; }
  148.             if (fmt[i + 1] == 120)
  149.                 { putx(*(&fmt + off++)); ++i; }
  150.             continue;
  151.         }
  152.         if (fmt[i] == 92) {
  153.             if (fmt[i + 1] == 110)
  154.                 { putc(13); putc(10); ++i; }
  155.             continue;
  156.         }
  157.         putc(fmt[i]);
  158.     }
  159. }
  160.  
  161. kbhit() {
  162.     int tmp;
  163.     return (tmp = *kbf) ? *kbf = 0, tmp : 0;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement