const char* kstrstr(const char* cmp, const char* srch) { int i,n; for(n=0; n<=kstrlen(cmp); n++) for(i=0; srch[i]==cmp[n+i] && cmp[n+i]!='\0'; i++) if(i==kstrlen(srch)-1) return &cmp[n]; return 0; }
char* kstrcat(char *str1, const char *str2) { uint64_t len1 = kstrlen(str1); uint64_t len2 = kstrlen(str2); uint64_t i = 0; for(i = 0; i < len2 ; i++) str1[len1 + i] = str2[i]; str1[len1 + i] = '\0'; return str1; }
void prepareValue(int value, char* s, int padding) { int i,len,size; itoa(value, s); len = padding - kstrlen(s); size = kstrlen(s); for(i=size; i<len+size; i++) *(s+i) = ' '; *(s+i) = '\0'; }
int kstrcat(char* str, char* str_cn) { int i = 0; char* new_string = 0; int str2_len = kstrlen(str_cn); if(!str || !str_cn) return 0; new_string = &str[kstrlen(str)+1]; while(str2_len--) { new_string[i] = str_cn[i]; i++; } new_string[i] = 0; return 1; }
// successful: 0 !error: -1 int kstrcmp(char* pstr, char* pstr_cmp) { int i = 0; int k = 0; if (pstr==0 || pstr_cmp==0) return -1; if (kstrlen(pstr) != kstrlen(pstr_cmp)) return -1; k = kstrlen(pstr); while(k--) { if (pstr[i] != pstr_cmp[i]) return -1; i++; } return 0; }
int MediaSrvGetName(HANDLE hmedia, char *name, int max) #endif { PMEDIA_OBJECT obj; int ret; kMutexWait(hMediaMutex); obj = (PMEDIA_OBJECT)HandleGet(hmedia, MEDIA_MAGIC); if(obj == NULL) { kMutexRelease(hMediaMutex); return -1; } ret = kstrlen(obj->MediaInfo); if(ret <= max) { kstrcpy(name, obj->MediaInfo); } else { kmemcpy(name, obj->MediaInfo, max); ret = max; } kMutexRelease(hMediaMutex); return ret; }
char* kstrcat(char *dest,char *src) { int i,j; for(i=kstrlen(dest),j=0;src[j];i++,j++) dest[i]=src[j]; dest[i]=0; return dest; }
void kcadvalor(char far *s, int n) { char cadena[80], far * p = cadena; kstrcpy(p, s); kitoa(p + kstrlen(s), n); kstrcat(p, "\n\r"); kputs(p); }
void dict_add(dict *d, const char* name, void* value, int size) { dict_ensure_size(d, d->count+1); d->items[d->count].name = kmalloc(kstrlen(name)+1); d->items[d->count].value = kmalloc(size); kstrcpy(d->items[d->count].name, name); kmemcpy(d->items[d->count].value, value, size); d->count++; }
char* toLowA(char* s) { int i; for(i=kstrlen(s); i>=0; i--) if('A'<=s[i] && s[i]<='Z') s[i] = s[i] - 'A' + 'a'; return s; }
char *kstrcpy( char *dest, const char *src ) { uint32 len = kstrlen(src); memcpy( dest, src, len ); dest[len] = '\0'; return dest; }
/* kstrcat * will return a string that is the concatination of the two given strings * * param a: the first string * param b: the second string * return: either the concatination of the strings else NULL * NULL indicates insufficient memory */ const char *kstrcat(const char *a, const char *b) { char *ret; size_t len, alen; assert(a && b); len = (alen = kstrlen(a)) + kstrlen(b); ret = malloc(MAGIC_LEN + LEN_LEN + len + 1); if(!ret) return NULL; KSTR_GET_MAGIC(ret) = MAGICFY(len); KSTR_GET_LEN(ret) = len; strncpy(KSTR_GET_STR(ret), a, alen); strncpy(KSTR_GET_STR(ret) + alen, b, len - alen); KSTR_GET_STR(ret)[len] = '\0'; return KSTR_GET_STR(ret); }/* end: kstrcat */
int kstrcmp_Aa(char* str1, char* str2) { int k = 0,i; char posChar = 0; if (str1==0 || str2==0) return -1; if ((k = kstrlen(str1)) != kstrlen(str2)) return -1; for(i=0; i<k; i++) if (str1[i] != str2[i]){ if(('A'<=str1[i] && str1[i]<='Z') && ('a'<=str2[i] && str2[i]<='z')){ posChar = str1[i] - 'A' + 'a'; if(posChar == str2[i]) continue; } else if(('a'<=str1[i] && str1[i]<='z') && ('A'<=str2[i] && str2[i]<='Z')){ posChar = str1[i] - 'a' + 'A'; if(posChar == str2[i]) continue; } return -1; } return 0; }
void kreverse(char s[]) { int i, j; char c; for (i = 0, j = kstrlen(s)-1; i<j; i++, j--) { c = s[i]; s[i] = s[j]; s[j] = c; } }
int kstrncpy(char* pstr_to, char* pstr_out, int ncopy) { int i = 0 ; if (!pstr_to || !pstr_out) return 0; if (kstrlen(pstr_out) > ncopy) return 0; do{ pstr_to[i] = pstr_out[i]; }while((ncopy--) && pstr_out[i++]); pstr_to[i] = '\0'; return 1; }
char* kstrrchr(char* str, char ch) { int len = 0; if (!str) return 0; len = kstrlen(str); while(len--) if (str[len] == ch) return &str[len]; return 0; }
void dump(Logger& logger) const { unsigned int actual_base = base_; if (base_ < 1 || base_ >= kstrlen(base_char)) { actual_base = logger.getDefaultNumberBase(); } const char* prefix = logger.getBasePrefix(actual_base); print_integer(logger, actual_base, i_, prefix); }
//////////////////////////////////////////////////// // 功能: 为音频任务申请并初始化节点 // 输入: // 输出: // 返回: // 说明: //////////////////////////////////////////////////// static PMEDIA_OBJECT MediaSrvObjCreate(void *media, char *name, int type) { PMEDIA_OBJECT obj; // 输入参数检查 if(!media) return NULL; // 申请节点,并初始化 obj = kmalloc(sizeof(MEDIA_OBJECT)); if(obj == NULL) return NULL; kmemset(obj, 0x00, sizeof(MEDIA_OBJECT)); ListInit(&obj->Link); if(MediaSrvGetCallback(type, &obj->Cb) < 0) { kdebug(mod_media, PRINT_ERROR, "MediaSrvGetCallback error\n"); kfree(obj); return NULL; } if(((PMEDIA_TASK)media)->ExterdType == 1 && JzSrvUseMplayer() < 0) { kdebug(mod_media, PRINT_ERROR, "MediaSrvGetCallback error: mplayer already exist\n"); kfree(obj); return NULL; } // 创建媒体任务 obj->Media = obj->Cb.MediaCreate(media); if(obj->Media == NULL) { kfree(obj); return NULL; } // 保存媒体名称 if(name) { obj->MediaInfo = kmalloc(kstrlen(name)+1); if(obj->MediaInfo) kstrcpy(obj->MediaInfo, name); } // 设置媒体任务 #if defined(STC_EXP) obj->hTask = sTaskSelf(); #else obj->hTask = TaskSelf(); #endif // 返回媒体对象 return obj; }
int kstrncmp_Aa(char* pstr, char* pstr_cmp, int length) { int k = 0,i; char posChar = 0; if (pstr==0 || pstr_cmp==0) return -1; if ((k = kstrlen(pstr)) != kstrlen(pstr_cmp)) return -1; for(i=0;/*k-- && */i<length;i++) { if (pstr[i] != pstr_cmp[i]){ if(('A'<=pstr[i] && pstr[i]<='Z') && ('a'<=pstr_cmp[i] && pstr_cmp[i]<='z')){ posChar = pstr[i] - 'A' + 'a'; if(posChar == pstr_cmp[i]){continue;} } else if(('a'<=pstr[i] && pstr[i]<='z') && ('A'<=pstr_cmp[i] && pstr_cmp[i]<='Z')){ posChar = pstr[i] - 'a' + 'A'; if(posChar == pstr_cmp[i]){continue;} } return -1; } } return 0; }
int kstrcpy(char* pstr_to, char* pstr_out) { int k = 0; int i = 0; if (!pstr_to || !pstr_out) return 0; k = kstrlen(pstr_out); while(k--) { pstr_to[i] = pstr_out[i]; i++; } pstr_to[i] = 0; return 1; }
int kstrncat(char* str, char* str_cn, int count) { int i = 0; char* new_string = 0; if(!str || !str_cn) return 0; new_string = &str[kstrlen(str)+1]; while(count--) { new_string[i] = str_cn[i]; i++; } new_string[i] = 0; return 1; }
char* kstrchr(char* str, char ch) { int i = 0; int len = 0; if (!str) return 0; len = kstrlen(str); while (len--) { if (str[i] == ch) return &str[i]; i++; } return 0; }
int kstrcspn(char* str1, char* str2) { int i = 0; int len = 0; if (!str1 || !str2) return -1; len = kstrlen(str1); while (len--) { if (kstrchr(str2, str1[i])) return i; i++; } return -1; }
int kstrncmp(char* pstr, char* pstr_cmp, int count) { int i = 0; int len = 0; if (!pstr || !pstr_cmp) return 0; if (len = kstrlen(pstr) < count) count = len; while(count--) { if (pstr[i] != pstr_cmp[i]) return 0; i++; } return 1; }
char* kstrpbrk(char* str1, char* str2) { int i = 0; int len = 0; if (!str1 || !str2) return 0; len = kstrlen(str1); while(len--) { if (kstrchr(str2, str1[i])) return &str1[i]; i++; } return 0; }
/* "abcd, uol. " ", ." */ char* kstrtok(char* str, char* lex) { int i = 0; char* look_up = 0; if (!lex) return 0; if (str) pstrtok = str; if (!kstrlen(pstrtok)) return 0; i = kstrspn(pstrtok, lex); if (i == -1) return 0; /* offset word */ pstrtok += i; look_up = pstrtok; if (pstrtok = kstrpbrk(look_up, lex)) { pstrtok[0] = 0; pstrtok++; } return look_up; }
void* file_lookup(char *dir_path) { char* file_path = (char *)dir_path; fnode_t *aux_node, *currnode = root_node; char *temp = NULL; int i; char *path = (char *)kmalloc(sizeof(char) * kstrlen(file_path)); kstrcpy(path, file_path); temp = kstrtok(path, "/"); if (temp == NULL) return NULL; //kprintf("\n step1 %s", temp); while (temp != NULL) { aux_node = currnode; for (i = 2; i < currnode->end; ++i) { if (kstrcmp(temp, currnode->f_child[i]->f_name) == 0) { currnode = (fnode_t *)currnode->f_child[i]; break; } } if (i == aux_node->end) { return NULL; } temp = kstrtok(NULL, "/"); } if (currnode->f_type == FILE) return (void *)currnode->start; else return NULL; }
void parse(char *dir_path, int type, uint64_t start, uint64_t end) { fnode_t *temp_node, *aux_node, *currnode = root_node->f_child[2]; char *temp; int i = 0; char *path = (char *)kmalloc(sizeof(char) * kstrlen(dir_path)); kstrcpy(path, dir_path); temp = kstrtok(path, "/"); while (temp != NULL) { aux_node = currnode; //kprintf("%s \n", temp); //iterate through all childrens of currnode for(i = 2; i < currnode->end; ++i){ if(kstrcmp(temp, currnode->f_child[i]->f_name) == 0) { currnode = (fnode_t *)currnode->f_child[i]; break; } } //kprintf("\n....%s...%s...", currnode->f_name, temp); //if no child has been found //add this as child of current if (i == aux_node->end) { temp_node = (fnode_t *)kmalloc(sizeof(struct file)); make_node(temp_node, currnode, temp, start, end, type, 0); currnode->f_child[currnode->end] = temp_node; currnode->end += 1; } //kprintf("....%d...%s...", currnode->end, temp); //while(1); temp = kstrtok(NULL, "/"); } }
int stoi(char *snum,unsigned int *result) { int i,first,slen; unsigned int dig,base,mul=1; if(snum==0 || result==0) return -1; *result=0; if((slen=kstrlen(snum))==0) return -1; switch(slen){ case 1: base=10;first=0;break; case 2: if(snum[0]=='0'){first=1;base=8;} else{first=0;base=10;} break; default: if(snum[0]=='0') { if(snum[1]=='x' || snum[1]=='X'){first=2;base=0x10;} else{first=1;base=010;} } else{first=0;base=10;} } for(i=slen-1;i>=first;i--) { dig=(unsigned int)snum[i]; if(dig>='0' && dig<='9') dig-='0'; else if(dig>='A' && dig<='F') dig-='A'-10; else if(dig>='a' && dig<='f') dig-='a'-10; else return -1; if(dig>=base) return -1; *result+=dig*mul; mul*=base; } return 0; }
int main() { clearFullScreen(); klog("Loading IDT\n"); init_IDT(); klog("Setting up keyboard\n"); init_keyboard(); // Set screen for userland memcpy(&sbar.str, &START_LOGO, kstrlen(START_LOGO)); clearFullScreen(); setFullBackgroundColor(BACKGROUND_COLOR_BLACK); setCharacterColor(CHAR_COLOR_LIGHT_GREY); set_vga_size(3, 25); updateStartBar(); while(1){ ((EntryPoint)(sampleCodeModuleAddress))(); } return 0; }