/* * scalar initializer * */ long scalar_initializer (long typ, long id, long stor) { long i; if (stor == CONST) new_const(); if (match("=")) { if (stor != CONST) error("can't initialize non-const scalars"); blanks(); if (ch() == ';') { error("value missing"); return (-1); } if (ch() == '\"' && id == POINTER) i = get_string_ptr(typ); else i = get_raw_value(';'); if (const_val_idx < MAX_CONST_VALUE) const_val[const_val_idx++] = i; blanks(); if (ch() != ';') { error("syntax error"); return (-1); } } return (1); }
/* Get the next string on the stream. This function sets s to a * freshly mallocated string, or NULL. The caller should free s. * When a message has not been received, its behaviour is dependent on * the current value of 'timeout', which can be set by * 'timeout(int)'. If 'timeout' is 0, it blocks until a message is * ready at the port, otherwise, it returns FALSE after waiting that * amount of time. * */ int Stream::get( char *&s) { char const *ptr = NULL; // This function used to be defined with two different calling // semantics. One was where s != NULL, in which case the // string was copied into the memory pointed to by s, with no // bounds checking. This latter case is no longer allowed. ASSERT( s == NULL ); int result = get_string_ptr(ptr); if( result == TRUE ) { if( ptr ) { s = strdup(ptr); } else { s = NULL; } } else { s = NULL; } return result; }
int Stream::get( std::string &s) { char const *ptr = NULL; int result = get_string_ptr(ptr); if( result == TRUE ) { if( ptr ) { s = ptr; } else { s = ""; } } else { s = ""; } return result; }
int Stream::get( char *s, int l) { char const *ptr = NULL; ASSERT( s != NULL && l > 0 ); int result = get_string_ptr(ptr); if( result != TRUE || !ptr ) { ptr = ""; } int len = strlen(ptr); if( len + 1 > l ) { strncpy(s,ptr,l-1); s[l] = '\0'; result = FALSE; } else { strncpy(s,ptr,l); } return result; }
/* * array initializer * */ long array_initializer (long typ, long id, long stor) { long nb; long k; long i; nb = 0; k = needsub(); if (stor == CONST) new_const(); if (match("=")) { if (stor != CONST) error("can't initialize non-const arrays"); if (!match("{")) { error("syntax error"); return (-1); } if (!match("}")) { for (;;) { if (match("}")) { error("value missing"); break; } if (match(",")) { error("value missing"); continue; } if ((ch() == '\"') && (id == POINTER)) i = get_string_ptr(typ); else i = get_raw_value(','); nb++; blanks(); if (const_val_idx < MAX_CONST_VALUE) const_val[const_val_idx++] = i; if ((ch() != ',') && (ch() != '}')) { error("syntax error"); return (-1); } if (match("}")) break; gch(); } } if (k == 0) k = nb; if (nb > k) { nb = k; error("excess elements in array initializer"); } } if (stor == CONST) { while (nb < k) { nb++; if (const_val_idx < MAX_CONST_VALUE) const_val[const_val_idx++] = -1; } } return (k); }