void initPhoneBookEntry(phoneBookEntry* entry) { initString(entry->firstName); initString(entry->lastName); initString(entry->mInitial); initString(entry->mobileNumber); }
void addEntryPhoneBook(phoneBookEntry entry, phoneBook* simpon) { stdclrscr(); printf("Adding a new Contact Entry for Entry Slot #%d", (simpon->count + 1)); newline(); printlnPhoneBookEntry(entry); newline(); if (hasEntrySlot(*simpon)) { char msg[MAXSTR]; char intStr[MAXSTR]; /* initialize strings before using them */ initString(msg); initString(intStr); copyPhoneBookEntry (entry, &simpon->entry[simpon->count++]); strcat(msg, "Added Contact Entry Slot #"); itoa(simpon->count, intStr, 10); strcat(msg, intStr); printlnInfoMessage(msg); } else { printlnInfoMessage("[simpon] is FULL . . ."); printlnInfoMessage("Cannot add a new Contact Entry . . ."); } }
/*Create a new String *invoked by:OPC_LDC */ O createJstring(char *s) { if (java_lang_String == NULL) java_lang_String = loadClass("java/lang/String"); ClassBlock_t *cb = CLASS_CB(java_lang_String); if (!inited) initString(); O char_obj, string_obj; FieldBlock_t *fb; int length, offset; length = strlen(s); char_obj = char2Char(s); short *data = (short *) char_obj->data; unsigned char *ss = (unsigned char *) s; convertUtf8(ss, data); string_obj = allocObject(java_lang_String); string_obj->type = OBJECT_STRING; OBJECT_DATA(string_obj, value_offset - 1, O) = char_obj; OBJECT_DATA(string_obj, count_offset - 1, int) = length; //*(((Object**)string_obj->data)+offset-1) = char_obj; string_obj->cb = cb; string_obj->el_size = sizeof(int); return string_obj; }
void toUpperCaseFirstOnly(char src[MAXSTR], char dst[MAXSTR]) { int len = strlen(src); int i; initString(dst); if (len <= 0) { strcpy(dst, "<empty>"); } else { if (len <= 1) { dst[0] = toupper(src[0]); dst[1] = '\0'; } else { boolean isBeforeSpace = False; dst[0] = toupper(src[0]); for (i = 1; i < len; i++) { if (isBeforeSpace) { dst[i] = toupper(src[i]); isBeforeSpace = False; } else dst[i] = tolower(src[i]); if (isspace(src[i])) isBeforeSpace = True; } dst[i] = '\0'; } } }
static void process_buffer_acsint(struct synth_t *s, char *buf, ssize_t length) { int start = 0; int i; int flushIt = 0; while (start < length) { for (i = start; i < length; i++) { if (buf[i] == '\r' || buf[i] == '\n') flushIt = 1; if (buf[i] >= 0 && buf[i] < ' ') break; } if (i > start) stringAndBytes(&textAccumulator, &textAccumulator_l, buf + start, i - start); if (flushIt) { if (textAccumulator != EMPTYSTRING) { queue_add_text(textAccumulator, textAccumulator_l); free(textAccumulator); textAccumulator = initString(&textAccumulator_l); } flushIt = 0; } if (i < length) start = i = i + process_command(s, buf, i); else start = length; } }
String toPrefix (String postfix) { STACK_p_t stack = initStack(); int l = (int)strlen(postfix), i; for (i = 0; i < l; ++i) { char z = *(postfix + i); if (isOperand(z)) { String tempString = initString(2); snprintf(tempString, 2, "%c", z); push(stack, tempString); } else if (isOperator(z)) { String tempString = (char *)malloc(SIZE * sizeof(char)); snprintf(tempString, SIZE, "%s%s%c", pop(stack), pop(stack), z); push(stack, tempString); } } reverse(*(stack->arr)); return *(stack->arr); }
void initMutableString() { initString(); if ( ! MutableStringClass ) MutableStringClass = new(StringClass, "MutableStringClass", StringClass, sizeof(struct MutableStringClass), constructor, MutableStringClass_constructor, NULL); if ( ! MutableString ) MutableString = new(MutableStringClass, "MutableString", String, sizeof(struct MutableString), constructor, MutableString_constructor, destructor, MutableString_destructor, /* Overrides */ copy, MutableString_copy, equals, MutableString_equals, getStringLength, MutableString_getStringLength, /* new */ appendString, MutableString_appendString, appendFormat, MutableString_appendFormat, setString, MutableString_setString, setMutableStringLength, MutableString_setMutableStringLength, insertStringAtMutableStringIndex, MutableString_insertStringAtMutableStringIndex, deleteMutableStringCharactersInRange, MutableString_deleteMutableStringCharactersInRange, NULL); }
/* start a document.write */ void dwStart(void) { if (cw->dw) return; cw->dw = initString(&cw->dw_l); stringAndString(&cw->dw, &cw->dw_l, "<!DOCTYPE public><body>"); } /* dwStart */
TNODE_p_t initNode (String data) { TNODE_p_t node = (TNODE_p_t)malloc(sizeof(TNODE_t)); node->data = initString(SIZE); strcpy(node->data, data); node->left = NULL; node->right = NULL; return node; }
void ByteArray::empty() { if (m_stringLength) { s_memoryPool->get(m_dataCapacity)->deallocate(m_data); initString(); } }
NODE_p_t initNode (String data) { NODE_p_t node = (NODE_p_t)malloc(sizeof(NODE_t)); node->data = initString(SIZE); strcpy(node->data, data); node->next = node; node->prev = node; return node; }
/** * An example of input, considering an enter is is valid and empty string. */ void getline(char str[MAXSTR]) { initString(str); /* flush the buffer to get an empty buffer to avoid error. */ fflush(stdin); fgets(str, MAXSTR, stdin); str[strlen(str)-1] = '\0'; }
void toUpperCase(char src[MAXSTR], char dst[MAXSTR]) { int len = strlen(src); int i; initString(dst); if (len <= 0) { strcpy(dst, "<empty>"); } else { for (i = 0; i < len; i++) dst[i] = toupper(src[i]); dst[i] = '\0'; } }
OSCData::OSCData(char type, const char* data) : _type(type) { switch (_type) { case 'i': _length = 4; _buffer = new char[4]; memcpy(_buffer, data, 4); break; case 's': initString(data); break; } }
int main() { myString *fat, *son; char in; int result = 0; initString( &fat ); initString( &son ); printf("请输入父串(以#号结束):"); scanf("%c", &in); while( '#'!=in && fat->lenght < MAXSIZE) { fat->data[fat->lenght++] = in; scanf("%c", &in); } printf("请输入子串(以#号结束):"); scanf("%c", &in); scanf("%c", &in); while( '#'!=in && son->lenght < MAXSIZE ) { son->data[son->lenght++] = in; scanf("%c", &in); } result = compareString( *fat, *son ); if( result ) printf("父串包含子串。"); else printf("不包含。"); return 0; }
int main (int argc, const char * argv []) { char ch; String string = initString(SIZE); String substring = initString(SIZE); do { printf("\n\tEnter the string: "); scanf(" %s", string); printf("\tEnter the substring: "); scanf(" %s", substring); if (containsString(string, substring)) printf("\n\t'%s' is contained in '%s'.", substring, string); else printf("\n\t'%s' is not present in '%s'.", substring, string); printf("\n\tContinue (y/n): "); scanf(" %c", &ch); } while (ch == 'y'); printf("\n\n"); }
bool showTables(void) { char tabname[40]; char tabtype[40]; char tabowner[40]; SQLLEN tabnameOut, tabtypeOut, tabownerOut; char *buf; int buflen, cx; int truevalue = SQL_TRUE; /* SQLSetConnectAttr(hdbc, SQL_ATTR_METADATA_ID, &truevalue, SQL_IS_INTEGER); */ newStatement(); stmt_text = "get tables"; debugStatement(); rc = SQLTables(hstmt, NULL, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS); if(rc) goto abort; SQLBindCol(hstmt, 2, SQL_CHAR, (SQLPOINTER) tabowner, sizeof (tabowner), &tabownerOut); SQLBindCol(hstmt, 3, SQL_CHAR, (SQLPOINTER) tabname, sizeof (tabname), &tabnameOut); SQLBindCol(hstmt, 4, SQL_CHAR, (SQLPOINTER) tabtype, sizeof (tabtype), &tabtypeOut); buf = initString(&buflen); while(SQLFetch(hstmt) == SQL_SUCCESS) { char tabline[140]; sprintf(tabline, "%s.%s|%s\n", tabowner, tabname, tabtype); stringAndString(&buf, &buflen, tabline); } cx = sideBuffer(0, buf, buflen, 0, false); nzFree(buf); i_printf(MSG_ShowTables, cx); SQLFreeHandle(SQL_HANDLE_STMT, hstmt); return true; abort: SQLFreeHandle(SQL_HANDLE_STMT, hstmt); return false; } /* showTables */
// *********************************************** // ****** Inverter as letras ****** // *********************************************** void inverteFrase(Lista S) { char frase[40]; char c; int pos,i = 0; if ( S.inicio == NULL) printf("Lista Vazia\n"); else { tNo* posAtual = S.inicio; do { frase[i] = posAtual->caractere; posAtual = posAtual->prox; i++; pos++; }while(posAtual != NULL); pos=S.tam; initString(&S); do { c = frase[pos]; if(c == 91) { inserirItem(&S,' '); }else { inserirItem(&S,c); } //printf("%c",c); pos--; }while((pos >= 0 )||( c >= 48)&&(c <= 125)); } printf("\n"); imprimeLista(S); }
/** * Will replace invalid value as X */ void toMobileNumberFormat(char src[12], char dst[14]) { int i, j; if (strlen(src) == 0) { strcpy(dst, "<empty>"); return; } initString(dst); /* dddd-ddd-dddd */ for (i = 0, j = 0; i < 4; i++) dst[j++] = src[i] == ' ' ? '0' : src[i]; dst[j++] = '-'; for (i = 0; i < 3; i++) { switch (src[i+4]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { dst[j++] = src[i+4]; break; } default: { dst[j++] = 'X'; break; } } } dst[j++] = '-'; for (i = 0 ; i < 4; i++) switch (src[i+7]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { dst[j++] = src[i+7]; break; } default: { dst[j++] = 'X'; break; } } dst[j] = '\0'; }
/* call javascript function with arguments, but all args must be objects */ static int run_function(jsobjtype obj, const char *name, int argc, const jsobjtype * argv) { int rc; propval = 0; /* should already be 0 */ if (!allowJS || !cw->winobj || !obj) return -1; debugPrint(5, "> call %s(%d)", name, argc); if (argc) { int i, l; char oval[20]; propval = initString(&l); for (i = 0; i < argc; ++i) { sprintf(oval, "%p|", argv[i]); stringAndString(&propval, &l, oval); } } head.cmd = EJ_CMD_CALL; head.n = strlen(name); head.obj = obj; head.proplength = 0; if (propval) head.proplength = strlen(propval); if (writeHeader()) return -1; if (writeToJS(name, head.n)) return -1; if (propval) { rc = writeToJS(propval, head.proplength); nzFree(propval); propval = 0; if (rc) return -1; } if (readMessage()) return -1; ack5(); return 0; } /* run_function */
static char *qpEncode(const char *line) { char *newbuf; int l; const char *s; char c; newbuf = initString(&l); for (s = line; (c = *s); ++s) { if (c < '\n' && c != '\t' || c == '=') { char expand[4]; sprintf(expand, "=%02X", (uchar) c); stringAndString(&newbuf, &l, expand); } else { stringAndChar(&newbuf, &l, c); } } return newbuf; } /* qpEncode */
TNODE_p_t createNode () { TNODE_p_t root; String data = initString(SIZE); printf("\tEnter data (# for break): "); scanf(" %s", data); if (*data == '#') return NULL; root = initNode(data); printf("\t Left of '%s' | ", root->data); root->left = createNode(); printf("\tRight of '%s' | ", root->data); root->right = createNode(); return root; }
int main (int argc, const char * argv []) { NODE_p_t stack = initNode("<HEAD>"); int choice; do { printf("\n\t1. Push\n\t2. Pop\n\t3. Display\n\t4. Display (with address)\n\tChoice: "); scanf(" %d", &choice); if (choice == 1) { String data = initString(SIZE); printf("\n\tEnter item to be pushed: "); scanf(" %s", data); push(&stack, data); } else if (choice == 2) { if (!isEmpty(stack)) { NODE_p_t temp = pop(&stack); printf("\n\tPopped item: %s (%p)\n", temp->data, temp); } else printf("\n\tSTACK UNDERFLOW!"); } else if (choice == 4) { if (!isEmpty(stack)) { printf("\n\tCurrent Stack: "); displayWithAddress(stack); } } if (!isEmpty(stack)) { printf("\n\tCurrent Stack: "); display(stack); } } while (choice >= 1 && choice <= 4); }
char *tidyPreprocess(const char *h) { char *ns; /* the new string */ int l; char *inside, *expanded; const char *lg, *s = strstrCI(h, "<textarea"); /* most web pages don't have textareas */ if (!s) return NULL; ns = initString(&l); stringAndBytes(&ns, &l, h, s - h); h = s; while (true) { /* next textarea */ s = strstrCI(h, "<textarea"); if (!s) break; s = strchr(s, '>'); if (!s) break; ++s; stringAndBytes(&ns, &l, h, s - h); h = s; s = strstrCI(h, "</textarea"); if (!s) break; lg = strpbrk(h, "<>"); /* lg is at most s */ if (lg == s) continue; inside = pullString1(h, s); expanded = htmlEscapeTextarea(inside); stringAndString(&ns, &l, expanded); nzFree(inside); nzFree(expanded); h = s; } stringAndString(&ns, &l, h); return ns; } /* tidyPreprocess */
bool srdf::Model::initFile(const urdf::ModelInterface &urdf_model, const std::string& filename) { // get the entire file std::string xml_string; std::fstream xml_file(filename.c_str(), std::fstream::in); if (xml_file.is_open()) { while (xml_file.good()) { std::string line; std::getline(xml_file, line); xml_string += (line + "\n"); } xml_file.close(); return initString(urdf_model, xml_string); } else { logError("Could not open file [%s] for parsing.", filename.c_str()); return false; } }
/* If debug is at least 5, show a simple acknowledgement or error * from the js process. */ static void ack5(void) { char *a; int a_l; char buf[32]; if (debugLevel < 5) return; a = initString(&a_l); stringAndChar(&a, &a_l, '<'); if (head.highstat) { sprintf(buf, " error %d|%d", head.highstat, head.lowstat); stringAndString(&a, &a_l, buf); } stringAndChar(&a, &a_l, ' '); if (propval) stringAndString(&a, &a_l, debugString(propval)); else if (head.cmd == EJ_CMD_HASPROP) stringAndNum(&a, &a_l, head.proptype); else stringAndString(&a, &a_l, "ok"); debugPrint(5, "%s", a); nzFree(a); } /* ack5 */
/* set document.cookie to the cookies relevant to this url */ static void docCookie(jsobjtype d) { int cook_l; char *cook = initString(&cook_l); const char *url = cw->fileName; bool secure = false; const char *proto; char *s; if (url) { proto = getProtURL(url); if (proto && stringEqualCI(proto, "https")) secure = true; sendCookies(&cook, &cook_l, url, secure); if (memEqualCI(cook, "cookie: ", 8)) { /* should often happen */ strmove(cook, cook + 8); } if (s = strstr(cook, "\r\n")) *s = 0; } set_property_string(d, "cookie", cook); nzFree(cook); } /* docCookie */
OSCData::OSCData(const char* value) : _type('s'), _length(0), _buffer(NULL) { initString(value); }
TToken* get_token() { if(token_buffer != NULL) { token = token_buffer; token_buffer = NULL; return token; } TString buffer; States state = S_START; char a[2]; // array for hex number int c, i=0; initString(&buffer, STR_DEFAULT_SIZE); token->data = buffer.data; while(1) { c = fgetc(fp); switch(state) { case S_START: switch (c) { case EOF: token->type = TOKEN_EOF; return token; case '+': token->type = TOKEN_ADD; return token; case '-': token->type = TOKEN_SUB; return token; case '*': token->type = TOKEN_MUL; return token; case '/': state = S_DIV; break; case '=': state = S_ASSIGN; break; case '!': state = S_EXCM; break; case '<': state = S_LESS; break; case '>': state = S_GREAT; break; case '(': token->type = TOKEN_LROUND_BRACKET; return token; case ')': token->type = TOKEN_RROUND_BRACKET; return token; case '{': token->type = TOKEN_LCURLY_BRACKET; return token; case '}': token->type = TOKEN_RCURLY_BRACKET; return token; case ',': token->type = TOKEN_COMMA; return token; case ';': token->type = TOKEN_SEMICOLON; return token; case '"': state = S_QUOT; break; default: if(isdigit(c)) { state = S_INT; insertIntoString(&buffer, c); } else if (isalpha(c) || c == '_') { state = S_IDENT; insertIntoString(&buffer, c); } else if (isspace(c)) break; else state = S_ERROR; } break; //********************************************** case S_INT: // INTEGER if (isdigit(c)) { insertIntoString(&buffer, c); } else if(c == '.') { insertIntoString(&buffer, c); state = S_DOT; } else if(c == 'E' || c == 'e') { insertIntoString(&buffer, c); state = S_EXPO_E; } else { insertIntoString(&buffer, 0); ungetc(c,fp); token->type = TOKEN_INT_VALUE; token->data = buffer.data; return token; } break; //************************************************* case S_DOT: // number DOT if (isdigit(c)) { insertIntoString(&buffer, c); state = S_DBL; } else { state = S_ERROR; } break; //************************************************* case S_DBL: // DOUBLE if (isdigit(c)) { insertIntoString(&buffer, c); } else if(c == 'E' || c == 'e') { insertIntoString(&buffer, c); state = S_EXPO_E; } else { insertIntoString(&buffer, 0); ungetc(c,fp); token->type = TOKEN_DOUBLE_VALUE; token->data = buffer.data; return token; } break; //****************************************************** case S_EXPO_E: // state S_EXPO_E if (isdigit(c)) { insertIntoString(&buffer, c); state = S_EXPO; } else if (c == '+' || c == '-') { insertIntoString(&buffer, c); state= S_EXPO_M; } else { state = S_ERROR; } break; //***************************************************** case S_EXPO_M: // state S_EXPO_M if (isdigit(c)) { insertIntoString(&buffer, c); state= S_EXPO; } else { state=S_ERROR; } break; //***************************************************** case S_EXPO: // state S_EXPO if (isdigit(c)) insertIntoString(&buffer, c); else { insertIntoString(&buffer, 0); ungetc(c,fp); token->type = TOKEN_DOUBLE_VALUE; token->data = buffer.data; return token; } break; //*************************************************** case S_IDENT: //STATE IDENTIFIER if (isalnum(c) || c == '_') { insertIntoString(&buffer, c); } else { insertIntoString(&buffer, 0); token->type = TOKEN_IDENTIFIER; token->data = buffer.data; keyword_check(); ungetc(c,fp); return token; } break; //************************************************************* case S_DIV: // DIVIDE if (c == '/') state = S_LCOM; else if (c == '*') state = S_LBC; else { ungetc(c,fp); token->type = TOKEN_DIV; return token; } break; //*************************************************** case S_LCOM: // LINE COMMENT if (c == '\n') state = S_START; break; //**************************************************** case S_LBC: // LEFT BLOCK COMMENT if (c == '*') state = S_RBC; if(c == EOF) state = S_ERROR; break; //**************************************************** case S_RBC: //RIGHT BLOCK COMMENT if (c == '/') state = S_START; else if (c == EOF) state = S_ERROR; else if (c == '*'); else state = S_LBC; break; //**************************************************** case S_ASSIGN: // ASSIGNMENT if (c == '=') { token->type = TOKEN_EQUAL; return token; } else { ungetc(c,fp); token->type = TOKEN_ASSIGN; return token; } break; //**************************************************** case S_EXCM: // EXCLAMATION MARK if (c == '=') { token->type = TOKEN_NOT_EQUAL; return token; } else state = S_ERROR; break; //**************************************************** case S_LESS: // LESS THAN if (c=='=') { token->type=TOKEN_LESS_EQUAL; return token; } else if (c == '<') { token->type=TOKEN_COUT_BRACKET; return token; } else { ungetc(c,fp); token->type = TOKEN_LESS; return token; } break; //**************************************************** case S_GREAT: //GREATER THAN if (c=='=') { token->type = TOKEN_GREATER_EQUAL; return token; } else if (c == '>') { token->type = TOKEN_CIN_BRACKET; return token; } else { ungetc(c,fp); token->type = TOKEN_GREATER; return token; } break; //**************************************************** case S_QUOT: //QUOTATION if (c == '"') { insertIntoString(&buffer, 0); token->type = TOKEN_STRING_VALUE; token->data = buffer.data; return token; } else if(c == EOF) { state = S_ERROR; } else if(c == '\\') { state = S_ESCAPE; } else if(c > 31) { insertIntoString(&buffer, c); } else state = S_ERROR; break; //**************************************************** case S_ESCAPE: //ESCAPE SEQUENCES if (c == 't') { insertIntoString(&buffer, '\t'); state = S_QUOT; } else if (c == '"') { insertIntoString(&buffer, '"'); state = S_QUOT; } else if (c == '\\') { insertIntoString(&buffer, '\\'); state = S_QUOT; } else if (c == 'n') { insertIntoString(&buffer, '\n'); state = S_QUOT; } else if (c == 'x') { state = S_HEX_NUMBER; } else { state=S_ERROR; } break; //**************************************************** case S_HEX_NUMBER: // HEXADECIMAL NUMBER if (isxdigit(c) && (i < 2)) // if is hexadigit and i<2 { a[i]=c; i++; if (i == 2) { if ((a[0] == '0') && (a[1] == '0')) state=S_ERROR; else { char hta = hex_to_ascii(a[0], a[1]); insertIntoString(&buffer, hta); state = S_QUOT; i = 0; } } } else { state=S_ERROR; } break; //**************************************************** case S_ERROR: // ERROR exit_error(E_LEX); } } }
static int process_command(struct synth_t *s, char *buf, int start) { char *cp; int value; enum adjust_t adj; enum command_t cmd; cp = buf + start; switch (*cp) { case 1: cp++; switch (*cp) { case '+': adj = ADJ_INC; cp++; break; case '-': adj = ADJ_DEC; cp++; break; default: adj = ADJ_SET; break; } value = 0; while (isdigit(*cp)) { value = value * 10 + (*cp - '0'); cp++; } switch (*cp) { case 'b': cmd = CMD_SET_PUNCTUATION; break; case 'f': cmd = CMD_SET_FREQUENCY; break; case 'p': cmd = CMD_SET_PITCH; break; case 's': cmd = CMD_SET_RATE; break; case 'v': cmd = CMD_SET_VOLUME; break; default: cmd = CMD_UNKNOWN; break; } cp++; break; default: cmd = CMD_UNKNOWN; cp++; break; } if (cmd != CMD_FLUSH && cmd != CMD_UNKNOWN) { if (espeakup_mode == ESPEAKUP_MODE_ACSINT && textAccumulator_l != 0) { queue_add_text(textAccumulator, textAccumulator_l); free(textAccumulator); textAccumulator = initString(&textAccumulator_l); } queue_add_cmd(cmd, adj, value); } return cp - (buf + start); }