/* * Parse the line and execute the given command. * * Returns true/false depending on if the cmd line * passed in was successfully processed and can * be freed by the caller * * TODO: Handle commands of any size more gracefully * by actually using the len option */ cmd_status cli_proc_cmd(cli_ctx *ctx, char *line, size_t len) { char cmd[READBUFF_SIZE]; char args[READBUFF_SIZE], byte, *line2; size_t pos = 0, line_max; bool has_args = false; cmd[0] = '\0'; args[0] = '\0'; /* split the line into the cmd & args */ byte = line[0]; line_max = strlen(line); while ((! IS_WORD_END(byte)) && (pos < line_max)) { pos ++; byte = line[pos]; } if (IS_WORD_END(line[pos])) { line[pos] = '\0'; line2 = &(line[pos+1]); strncpy(args, line2, 254); has_args = true; } strncpy(cmd, line, (READBUFF_SIZE-1)); /* execute the cmd based on the current context */ pos = 0; while (COMMANDS[pos].state != NONE) { if ((COMMANDS[pos].state == ctx->state) && (strcmp(COMMANDS[pos].cmd, cmd) == 0) && (COMMANDS[pos].has_args == has_args)) { return COMMANDS[pos].fh(ctx, args); } pos++; } return E_CMD_NOT_FOUND; }
UINT16 OSD_GetWordLen(UINT8* pText, UINT8 font,UINT16* wordwidth,UINT16* wordheight ,UINT16 width) { UINT16 wc,wordlen = 0; UINT16 w,h,mh = 0,ww = 0; UINT32 cnt; UINT16 font_w = 0, font_h = 0; while( (wc = ComMB16ToWord(pText)) != 0) { if(IS_NEWLINE(wc)) { *wordwidth = ww; *wordheight = mh; return wordlen; } else if((wc > 0x4e00 && wc < 0x9f45)|| (wc > 0x3000 && wc < 0x303f)|| (wc > 0xff00 && wc < 0xffef)|| (wc > 0x2e80 && wc < 0x2eff))//chinese { if(font_w == 0) { font_w = 36; font_h = 36; OSD_GetCharWidthHeight(wc, font, &font_w, &font_h); //libc_printf("font_w = %d,font_h = %d\n",font_w,font_h); } ww += font_w; mh = font_h; wordlen += 1; pText += 2; break; } else if(IS_WORD_END(wc) && wordlen>0) break; w = 10; h = 0; cnt = 2; if(is_thai_unicode(wc)) { struct thai_cell cell; cnt = thai_get_cell(pText, &cell); if(cnt == 0) break; OSD_GetThaiCellWidthHeight(&cell, font,&w,&h); } else { OSD_GetCharWidthHeight(wc ,font, &w, &h); } if(mh < h) mh = h; if((ww+w)<=width) ww += w; else break; wordlen += cnt/2; pText += cnt; if(IS_WORD_END(wc)) break; } *wordwidth = ww; *wordheight = mh; return wordlen; }
/************************************************************************************************************* ** @brief : parser word form cp and save it to #words ** #cp : will parser string pointer ** #words : save words ** #size : words array size ** @return : return words size in cp *************************************************************************************************************/ int conf_get_words(const char *cp, char (*words)[32], unsigned int size) { unsigned int i, j, idx, start, end; unsigned int str_size = strlen(cp); /* Nothing */ if (str_size == 0){ return 0; } /* String trip */ for (i = 0; i < str_size; i++){ if (!IS_WORD_END(cp[i])){ start = i; break; } } for (i = str_size - 1; i > start; i--){ if (!IS_WORD_END(cp[i])){ end = i; break; } } #if 0 fprintf(stderr, "[%u]%s\n", str_size, cp); fprintf(stderr, "%u[%c]-%u[%c]\n", start, cp[start], end, cp[end]); #endif /* Parser string */ for (i = start, j = 0, idx = 0; i <= end && j < 32 && idx < size; i++){ switch (cp[i]){ /* Words end */ case ' ' : case ',' : case '\t': case '\n': if (!IS_WORD_END(cp[i + 1])){ /* Restart */ j = 0; /* Move to next word */ idx++; }break; /* Words */ default : words[idx][j++] = cp[i]; break; } /* end of switch */ } /* end of for */ return idx + 1; }