Ejemplo n.º 1
0
void fxBufferFunctionName(txMachine* the, txString buffer, txSize size, txSlot* function, txString suffix)
{
	txSlot* slot = fxGetProperty(the, function, mxID(_name));
	if (slot && ((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND))) {
		c_strncat(buffer, slot->value.string, size - c_strlen(buffer) - 1);
		c_strncat(buffer, suffix, size - c_strlen(buffer) - 1);
	}
}
Ejemplo n.º 2
0
void fxBufferObjectName(txMachine* the, txString buffer, txSize size, txSlot* object, txString suffix)
{
	txSlot* slot = fxGetProperty(the, object, mxID(_Symbol_toStringTag));
	if (slot && ((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND))) {
		c_strncat(buffer, slot->value.string, size - c_strlen(buffer) - 1);
		c_strncat(buffer, suffix, size - c_strlen(buffer) - 1);
	}
}
Ejemplo n.º 3
0
void luaO_chunkid (char *out, const char *source, size_t bufflen) {
  if (*source == '=') {
    c_strncpy(out, source+1, bufflen);  /* remove first char */
    out[bufflen-1] = '\0';  /* ensures null termination */
  }
  else {  /* out = "source", or "...source" */
    if (*source == '@') {
      size_t l;
      source++;  /* skip the `@' */
      bufflen -= sizeof(" '...' ");
      l = c_strlen(source);
      c_strcpy(out, "");
      if (l > bufflen) {
        source += (l-bufflen);  /* get last part of file name */
        c_strcat(out, "...");
      }
      c_strcat(out, source);
    }
    else {  /* out = [string "string"] */
      size_t len = c_strcspn(source, "\n\r");  /* stop at first newline */
      bufflen -= sizeof(" [string \"...\"] ");
      if (len > bufflen) len = bufflen;
      c_strcpy(out, "[string \"");
      if (source[len] != '\0') {  /* must truncate? */
        c_strncat(out, source, len);
        c_strcat(out, "...");
      }
      else
        c_strcat(out, source);
      c_strcat(out, "\"]");
    }
  }
}
Ejemplo n.º 4
0
void fxBufferFrameName(txMachine* the, txString buffer, txSize size, txSlot* frame, txString suffix)
{
	txSlot* target = frame + 2; 
	txSlot* function = frame + 3; 
	txSlot* _this = frame + 4;
	if (function->kind == XS_REFERENCE_KIND) {
		function = function->value.reference;
		if (mxIsFunction(function)) {
			if (target->kind == XS_UNDEFINED_KIND) {
				txSlot* home = mxFunctionInstanceHome(function);
				if (home->kind == XS_REFERENCE_KIND) {
					home = home->value.reference;
					if (mxIsFunction(home)) {
						fxBufferFunctionName(the, buffer, size, home, ".");
					}
					else {
						txSlot* constructor = fxGetOwnProperty(the, home, mxID(_constructor));
						if (constructor) {
							if (constructor->kind == XS_REFERENCE_KIND) {
								constructor = constructor->value.reference;
								if (mxIsFunction(constructor))
									fxBufferFunctionName(the, buffer, size, constructor, ".prototype.");
							}
						}
						else if (_this->kind == XS_REFERENCE_KIND) {
							fxBufferObjectName(the, buffer, size, _this->value.reference, ".");
						}
					}
				}
			}
			fxBufferFunctionName(the, buffer, size, function, "");
		}
	}
	else
		c_strncat(buffer, "(host)", size - c_strlen(buffer) - 1);
	c_strncat(buffer, suffix, size - c_strlen(buffer) - 1);
}
Ejemplo n.º 5
0
void build_well_known_rsp(char *rsp, uint16_t rsplen)
{
    const coap_endpoint_t *ep = endpoints;
    int i;
    uint16_t len = rsplen;

    c_memset(rsp, 0, len);

    len--; // Null-terminated string

    while(NULL != ep->handler)
    {
        if (NULL == ep->core_attr) {
            ep++;
            continue;
        }
        if (NULL == ep->user_entry){
            if (0 < c_strlen(rsp)) {
                c_strncat(rsp, ",", len);
                len--;
            }
        
            c_strncat(rsp, "<", len);
            len--;

            for (i = 0; i < ep->path->count; i++) {
                c_strncat(rsp, "/", len);
                len--;

                c_strncat(rsp, ep->path->elems[i], len);
                len -= c_strlen(ep->path->elems[i]);
            }

            c_strncat(rsp, ">;", len);
            len -= 2;

            c_strncat(rsp, ep->core_attr, len);
            len -= c_strlen(ep->core_attr);
        } else {
            coap_luser_entry *h = ep->user_entry->next;     // ->next: skip the first entry(head)
            while(NULL != h){
                if (0 < c_strlen(rsp)) {
                    c_strncat(rsp, ",", len);
                    len--;
                }
            
                c_strncat(rsp, "<", len);
                len--;

                for (i = 0; i < ep->path->count; i++) {
                    c_strncat(rsp, "/", len);
                    len--;

                    c_strncat(rsp, ep->path->elems[i], len);
                    len -= c_strlen(ep->path->elems[i]);
                }

                c_strncat(rsp, "/", len);
                len--;

                c_strncat(rsp, h->name, len);
                len -= c_strlen(h->name);

                c_strncat(rsp, ">;", len);
                len -= 2;

                c_strncat(rsp, ep->core_attr, len);
                len -= c_strlen(ep->core_attr);  

                h = h->next;
            }
        }
        ep++;
    }
}