/* return: the strlen(string), that is, not include the '\0' */ PUBLIC int vsnprintf(char *buf, u32 size, const char *fmt, va_list args) { u32 i, offset, len; u8 c; u32 d, x; char *s, *b; char num[11]; /* 2^32 = 4294967296 + '\0' */ offset = 0; memset(buf, 0, size); memset(num, 0, sizeof(num)); len = strlen(fmt); for(i=0;i<len;i++) { if (fmt[i] == '%') { if ((i+1) == len) { /* % is the last char of the string */ buf_putc(buf, size, &offset, fmt[i]); break; } else { switch (fmt[i+1]) { case ('c'): c = va_arg(args, u32); buf_putc(buf, size, &offset, c); i++; break; case ('d'): d = va_arg(args, u32); b = itoa(num, d, 10); buf_puts(buf, size, &offset, b); i++; break; case ('x'): case ('X'): x = va_arg(args, u32); b = itoa(num, x, 16); if (fmt[i+1] == 'X') { b = &num[2]; }; buf_puts(buf, size, &offset, b); i++; break; case ('s'): s = va_arg(args, char *); b = s; if (b == NULL) { buf_puts(buf, size, &offset, "(null)"); } else { buf_puts(buf, size, &offset, b); } i++; break; default: buf_putc(buf, size, &offset, fmt[i]); /* the '%' */ break; } } } else { /* ordinary character */ buf_putc(buf, size, &offset, fmt[i]); } }
void case_buf_puts() { struct buf *buf = buf(NULL); assert(buf_puts(buf, "abc") == BUF_OK); assert(strcmp(str(buf), "abc") == 0); assert(buf_puts(buf, "efg") == BUF_OK); assert(strcmp(str(buf), "abcefg") == 0); buf_free(buf); }
void cvs_trigger_loginfo_header(BUF *buf, char *repo) { char *dir, pwd[PATH_MAX]; char hostname[HOST_NAME_MAX+1]; if (gethostname(hostname, sizeof(hostname)) == -1) { fatal("cvs_trigger_loginfo_header: gethostname failed %s", strerror(errno)); } if (getcwd(pwd, sizeof(pwd)) == NULL) fatal("cvs_trigger_loginfo_header: Cannot get working " "directory"); if ((dir = dirname(pwd)) == NULL) { fatal("cvs_trigger_loginfo_header: dirname failed %s", strerror(errno)); } buf_puts(buf, "Update of "); buf_puts(buf, current_cvsroot->cr_dir); buf_putc(buf, '/'); buf_puts(buf, repo); buf_putc(buf, '\n'); buf_puts(buf, "In directory "); buf_puts(buf, hostname); buf_puts(buf, ":"); buf_puts(buf, dir); buf_putc(buf, '/'); buf_puts(buf, repo); buf_putc(buf, '\n'); buf_putc(buf, '\n'); }
static void import_loginfo(char *repo) { int i; char pwd[MAXPATHLEN]; if (getcwd(pwd, sizeof(pwd)) == NULL) fatal("Can't get working directory"); logbuf = buf_alloc(1024); cvs_trigger_loginfo_header(logbuf, repo); buf_puts(logbuf, "Log Message:\n"); buf_puts(logbuf, logmsg); if (logmsg[0] != '\0' && logmsg[strlen(logmsg) - 1] != '\n') buf_putc(logbuf, '\n'); buf_putc(logbuf, '\n'); buf_puts(logbuf, "Status:\n\n"); buf_puts(logbuf, "Vendor Tag:\t"); buf_puts(logbuf, vendor_tag); buf_putc(logbuf, '\n'); buf_puts(logbuf, "Release Tags:\t"); for (i = 0; i < tagcount ; i++) { buf_puts(logbuf, "\t\t"); buf_puts(logbuf, release_tags[i]); buf_putc(logbuf, '\n'); } buf_putc(logbuf, '\n'); buf_putc(logbuf, '\n'); }
inline char* tvf_toString(TagValueFunction* tvf,TNFA* tnfa){ StringBuffer* sb = buf_createDefault(); char* result; int i; buf_puts(sb,"<"); for(i=0;i<tnfa->tagcount;i++){ buf_printf(sb,"%d%s",tvf[i],i==tnfa->tagcount-1?"":","); } buf_puts(sb,">"); result = buf_toString(sb); buf_free(sb); return result; }
/* The 'channel_open' function opens the channel. It sets 'localwindow' and maxpacket, values obtained from from SSH_MSG_CHANNEL_OPEN message. Function also obtaines connection information and sets environment variables PATH, SSH_CONNECTION and MAIL. */ int channel_open(const char *user, crypto_uint32 id, crypto_uint32 remotewindow, crypto_uint32 maxpacket, crypto_uint32 *localwindow) { struct buf b = { channel.buf0, 0, CHANNEL_BUFSIZE }; if (!localwindow) bug_inval(); if (!maxpacket) bug_inval(); if (!remotewindow) bug_inval(); if (channel.maxpacket != 0) bug_proto(); if (channel.pid != 0) bug_proto(); /* copy user-name */ if (!str_copyn(channel.user, sizeof channel.user, user)) bug_nomem(); /* set id, maxpacket, remotewindow, localwindow */ channel.id = id; channel.maxpacket = maxpacket; channel.remotewindow = remotewindow; channel.localwindow = *localwindow = CHANNEL_BUFSIZE; /* copy PATH */ if (!newenv_copyenv("PATH")) if (!newenv_env("PATH", "/bin:/usr/bin")) return 0; /* create env. SSH_CONNECTION */ connectioninfo(channel.localip, channel.localport, channel.remoteip, channel.remoteport); buf_purge(&b); buf_puts(&b, channel.remoteip); buf_puts(&b, " "); buf_puts(&b, channel.remoteport); buf_puts(&b, " "); buf_puts(&b, channel.localip); buf_puts(&b, " "); buf_puts(&b, channel.localport); buf_putnum8(&b, 0); if (!newenv_env("SSH_CONNECTION", (char *)b.buf)) return 0; /* create env. MAIL */ #ifdef _PATH_MAILDIR buf_purge(&b); buf_puts(&b, _PATH_MAILDIR); buf_puts(&b, "/"); buf_puts(&b, user); buf_putnum8(&b, 0); if (!newenv_env("MAIL", (char *)b.buf)) return 0; #endif purge(channel.buf0, sizeof channel.buf0); return 1; }
char *ihtab_toString(IntHashtable *p) { char *result = NULL; StringBuffer *buf = buf_createDefault(); IntEnumeration *e; int i = 0; buf_putc(buf, '{'); for(e = ihtab_getKeys(p); ienum_hasNext(e); ) { int curkey = ienum_next(e); void *curval = ihtab_get(p, curkey); if (i > 0) { buf_puts(buf, ", "); } buf_printf(buf, "%d", curkey); buf_putc(buf, '='); buf_putp(buf, curval); i++; } buf_putc(buf, '}'); result = buf_toString(buf); free(e); return result; }
void moto_emitCGlobals(MotoEnv *env, StringBuffer *out) { Enumeration* e; buf_puts(out, "/* BEGIN GENERATED GLOBAL DECLARATIONS */\n\n"); e = stab_getKeys(env->globals); while (enum_hasNext(e)) { char* n = (char*)enum_next(e); MotoVar* mv = stab_get(env->globals,n); buf_printf(out,"static %s _G_%s=%s;\n", moto_valToCType(mv->vs), n,moto_defaultValForCType(mv->vs)); } enum_free(e); buf_puts(out, "/* END GENERATED GLOBAL DECLARATIONS */\n\n"); }
void moto_emitCImplicitConstructors(MotoEnv *env, StringBuffer *out) { Enumeration* e; buf_puts(out, "/* BEGIN GENERATED IMPLICIT CONSTRUCTORS */\n\n"); /* Foreach MotoClassDefinition */ e = stab_getValues(env->cdefs); while(enum_hasNext(e)) { MotoClassDefinition* mcd = (MotoClassDefinition*)enum_next(e); Enumeration* ve; /* Output the implicit constructor prototype for this MotoClassDefinition */ buf_printf(out, "static %s* _%s_%s___(){\n",mcd->classn,mcd->classn,mcd->classn); /* Allocate the space for the type being constructed and set ÔthisÕ */ buf_printf(out, " %s* this = (%s*)mman_track(rtime_getMPool(),emalloc(sizeof(%s)));\n", mcd->classn,mcd->classn,mcd->classn); /* Foreach var in the MotoClassDefinition */ ve = vec_elements(mcd->memberVarNames); while(enum_hasNext(ve)) { char* varn = (char*)enum_next(ve); MotoVar* mv = moto_createVar(env,varn,mcd_getMemberType(mcd,varn),0,'\0',NULL); buf_printf(out," this->%s=%s;\n", mv->n,moto_defaultValForCType(mv->vs) ); moto_freeVar(env,mv); } enum_free(ve); /* Output the mcd->code */ buf_puts(out,mcd->code); /* Output 'return this\n}\n\nÕ */ buf_puts(out," return this;\n}\n\n"); } enum_free(e); buf_puts(out, "/* END GENERATED IMPLICIT CONSTRUCTORS */\n\n"); }
void case_buf_cap() { struct buf *buf = buf("abcdef"); assert(buf_cap(buf) == 6); buf_puts(buf, "abc"); assert(buf_cap(buf) == 12); buf_free(buf); }
void case_buf_str() { struct buf *buf = buf(NULL); assert(strcmp(str(buf), "") == 0); buf_puts(buf, "abcdef"); assert(strcmp(str(buf), "abcdef") == 0); buf_free(buf); }
void case_buf_puts(struct bench_ctx *ctx) { struct buf *buf = buf(NULL); int i; bench_ctx_reset_start_at(ctx); for (i = 0; i < ctx->n; i++) { buf_puts(buf, "abcdefg"); } bench_ctx_reset_end_at(ctx); buf_free(buf); }
void moto_emitCImplicitConstructorPrototypes(MotoEnv *env, StringBuffer *out) { Enumeration* e; buf_puts(out, "/* BEGIN GENERATED IMPLICIT CONSTRUCTOR PROTOTYPES */\n\n"); /* Foreach MotoClassDefinition */ e = stab_getValues(env->cdefs); while(enum_hasNext(e)) { MotoClassDefinition* mcd = (MotoClassDefinition*)enum_next(e); /* output an implicit constructor prototype */ buf_printf(out, "static %s* _%s_%s___();\n", mcd->classn,mcd->classn,mcd->classn); } enum_free(e); buf_puts(out, "/* END GENERATED IMPLICIT CONSTRUCTOR PROTOTYPES */\n\n"); }
void moto_emitCStructures(MotoEnv *env, StringBuffer *out) { Enumeration* e; buf_puts(out, "/* BEGIN GENERATED STRUCTURES */\n\n"); /* Foreach MotoClassDefinition */ e = stab_getValues(env->cdefs); while(enum_hasNext(e)) { MotoClassDefinition* mcd = (MotoClassDefinition*)enum_next(e); Enumeration* ve; /* Output Ôtypedef struct _<typename> {Ô */ buf_printf(out, "typedef struct _%s {\n",mcd->classn); /* Foreach var in the MotoClassDefinition */ ve = vec_elements(mcd->memberVarNames); while(enum_hasNext(ve)) { char* varn = (char*)enum_next(ve); MotoVar* mv = moto_createVar(env,varn,mcd_getMemberType(mcd,varn),0,'\0',NULL); /* if the var is another MotoClassDefinition */ /* output Ôstruct _<var typename> *Õ */ /* else */ /* output <typename> */ /* output varname */ /* output Ô;\nÕ */ buf_printf(out," %s %s;\n", moto_valToCType(mv->vs), mv->n); moto_freeVar(env,mv); } enum_free(ve); /* output Ô} <typename>;Õ */ buf_printf(out, "} %s;\n\n",mcd->classn); } enum_free(e); buf_puts(out, "/* END GENERATED STRUCTURES */\n\n"); }
char* plist_toString(PriorityList* p){ StringBuffer* sb=buf_createDefault(); char* result; int i; if (p==NULL) p=&defaultPList; for(i=0;i<p->length;i++){ buf_putc(sb,p->priority[i]); if(i<p->length-1) buf_puts(sb,"<-"); } result = buf_toString(sb); buf_free(sb); return result; }
char* moto_createMotonameForFn(char* classn, char* fn) { StringBuffer* buf = buf_createDefault(); char *r; /* If we are dealing with a method and not a function we must prepend the class name and '::' to the generated motoname */ if(classn != NULL) { buf_puts(buf,classn); buf_puts(buf,"::"); } /* Print the function name */ buf_puts(buf,fn); r = buf_toString(buf); buf_free(buf); return r; }
char *hset_toString(HashSet *p) { char *result = NULL; StringBuffer *buf = buf_createDefault(); Enumeration *e; int i = 0; for(e = hset_elements(p); enum_hasNext(e); ) { void *curkey = (void *)enum_next(e); if (i > 0) { buf_puts(buf, ", "); } buf_putc(buf, '{'); buf_puts(buf, curkey); buf_putc(buf, '}'); i++; } result = buf_toString(buf); free(e); return result; }
static void buf_putc_careful(struct buffer *bs, int c) { if (isprint(c) || c == '\a' || c == '\t' || c == '\r' || c == '\n') { buf_enlarge(bs, 1); bs->data[bs->used++] = c; } else if (!isascii(c)) buf_printf(bs, "\\%3o", (unsigned char)c); else { char tmp[] = { '^', c ^ 0x40, '\0' }; buf_puts(bs, tmp); } }
char* escapeStrConst(char* s){ StringBuffer *tmp = buf_createDefault(); char* r; int i, size = strlen(s); for (i = 0; i < size; i++) { char c = s[i]; switch (c) { case '\t': buf_puts(tmp, "\\t"); break; case '\n': buf_puts(tmp, "\\n"); break; case '\r': buf_puts(tmp, "\\r"); break; case '\f': buf_puts(tmp, "\\f"); break; case '"': buf_putc(tmp, '\\'); buf_putc(tmp, c); break; case '\\': buf_puts(tmp, "\\\\"); break; default: buf_putc(tmp, c); break; } } r = buf_toString(tmp); buf_free(tmp); return r; }
static int expand_var(BUF *buf, const char *var) { struct passwd *pw; const char *val; if (*var == '=') { if ((val = cvs_var_get(++var)) == NULL) { cvs_log(LP_ERR, "no such user variable ${=%s}", var); return (1); } buf_puts(buf, val); } else { if (strcmp(var, "CVSEDITOR") == 0 || strcmp(var, "EDITOR") == 0 || strcmp(var, "VISUAL") == 0) buf_puts(buf, cvs_editor); else if (strcmp(var, "CVSROOT") == 0) buf_puts(buf, current_cvsroot->cr_dir); else if (strcmp(var, "USER") == 0) { pw = getpwuid(geteuid()); if (pw == NULL) { cvs_log(LP_ERR, "unable to retrieve " "caller ID"); return (1); } buf_puts(buf, pw->pw_name); } else if (strcmp(var, "RCSBIN") == 0) { cvs_log(LP_ERR, "RCSBIN internal variable is no " "longer supported"); return (1); } else { cvs_log(LP_ERR, "no such internal variable $%s", var); return (1); } } return (0); }
void cvs_add_loginfo(char *repo) { BUF *buf; char pwd[MAXPATHLEN]; if (getcwd(pwd, sizeof(pwd)) == NULL) fatal("Can't get working directory"); buf = buf_alloc(1024); cvs_trigger_loginfo_header(buf, repo); buf_puts(buf, "Log Message:\nDirectory "); buf_puts(buf, current_cvsroot->cr_dir); buf_putc(buf, '/'); buf_puts(buf, repo); buf_puts(buf, " added to the repository\n"); buf_putc(buf, '\0'); loginfo = buf_release(buf); }
void sshcrypto_key_put(struct buf *b) { crypto_uint32 len = 0; long long i, j, start; j = 0; for (i = 0; sshcrypto_keys[i].name; ++i) { if (!sshcrypto_keys[i].sign_flagserver) continue; if (j++) ++len; len += str_len(sshcrypto_keys[i].name); } buf_putnum32(b, len); start = b->len; j = 0; for (i = 0; sshcrypto_keys[i].name; ++i) { if (!sshcrypto_keys[i].sign_flagserver) continue; if (j++) buf_puts(b, ","); buf_puts(b, sshcrypto_keys[i].name); } b->buf[b->len] = 0; log_d2("kex: server: key algorithms: ", (char *)b->buf + start); }
static void import_printf(const char *fmt, ...) { char *str; va_list vap; va_start(vap, fmt); if (vasprintf(&str, fmt, vap) == -1) fatal("import_printf: could not allocate memory"); va_end(vap); cvs_printf("%s", str); buf_puts(logbuf, str); xfree(str); }
/* Create new buffer and init it with a C null-terminated * string if `s` is not NULL. */ struct buf * buf_new(const char *s) { struct buf *buf = malloc(sizeof(struct buf)); if (buf != NULL) { buf->len = 0; buf->cap = 0; buf->data = NULL; if (s != NULL) { if (buf_puts(buf, s) != BUF_OK) return NULL; } } return buf; }
void moto_emitCPrototypes(MotoEnv *env, StringBuffer *out) { Enumeration* e; buf_puts(out, "/* BEGIN GENERATED FUNCTION PROTOTYPES */\n\n"); e = htab_getKeys(env->fdefs); while (enum_hasNext(e)) { MotoFunction *f = (MotoFunction*)enum_next(e); buf_puts(out, mfn_cprototype(f)); buf_puts(out, ";\n"); } buf_puts(out, "/* END GENERATED FUNCTION PROTOTYPES */\n\n"); buf_puts(out, "/* BEGIN GENERATED ANONYMOUS FUNCTION PROTOTYPES */\n\n"); e = htab_getKeys(env->adefs); while (enum_hasNext(e)) { MotoFunction *f = (MotoFunction*)enum_next(e); buf_puts(out, mfn_cprototype(f)); buf_puts(out, ";\n"); } buf_puts(out, "/* END GENERATED ANONYMOUS FUNCTION PROTOTYPES */\n\n"); }
char* unescapeStrConst(char* s){ StringBuffer *tmp = buf_createDefault(); char* r; int i, size = strlen(s); for (i = 1; i < size - 1; i++) { char c = s[i]; if(s[i]=='\\') { c = s[++i]; switch (c) { case 't': buf_puts(tmp, "\t"); break; case 'n': buf_puts(tmp, "\n"); break; case 'r': buf_puts(tmp, "\r"); break; case 'f': buf_puts(tmp, "\f"); break; case '"': buf_puts(tmp, "\""); break; case '\\': buf_puts(tmp, "\\"); break; default: buf_putc(tmp, c); break; } } else { buf_putc(tmp, c); } } r = buf_toString(tmp); buf_free (tmp); return r; }
static int expand_args(BUF *buf, struct file_info_list *file_info, const char *repo, const char *allowed_args, char *format) { int oldstyle, quote; struct file_info *fi = NULL; char *p, valbuf[2] = { '\0', '\0' }; const char *val; if (file_info != NULL && !TAILQ_EMPTY(file_info)) fi = TAILQ_FIRST(file_info); quote = oldstyle = 0; /* Why does GNU cvs print something if it encounters %{}? */ if (*format == '\0') oldstyle = 1; for (p = format; *p != '\0'; p++) { if (*p != '%' && strchr(allowed_args, *p) == NULL) return 1; switch (*p) { case 's': case 'V': case 'v': quote = 1; oldstyle = 1; break; default: break; } } if (quote) buf_putc(buf, '"'); if (oldstyle) { buf_puts(buf, repo); buf_putc(buf, ' '); } if (*format == '\0') return 0; /* * check like this, add only uses loginfo for directories anyway */ if (cvs_cmdop == CVS_OP_ADD) { buf_puts(buf, "- New directory"); if (quote) buf_putc(buf, '"'); return (0); } if (cvs_cmdop == CVS_OP_IMPORT) { buf_puts(buf, "- Imported sources"); if (quote) buf_putc(buf, '"'); return (0); } for (;;) { for (p = format; *p != '\0';) { val = NULL; switch (*p) { case '%': val = "%"; break; case 'b': if (fi != NULL) { valbuf[0] = fi->tag_type; val = valbuf; } break; case 'o': if (fi != NULL) val = fi->tag_op; break; case 'p': val = current_cvsroot->cr_dir; break; case 'r': val = repo; break; case 'l': case 'S': case 's': if (fi != NULL) val = fi->file_path; break; case 't': if (fi != NULL) val = fi->tag_new; break; case 'V': if (fi != NULL) { if (fi->crevstr != NULL && !strcmp(fi->crevstr, "Non-existent")) val = "NONE"; else val = fi->crevstr; } break; case 'v': if (fi != NULL) { if (fi->nrevstr != NULL && !strcmp(fi->nrevstr, "Removed")) val = "NONE"; else val = fi->nrevstr; } break; default: return 1; } if (val != NULL) buf_puts(buf, val); if (*(++p) != '\0') buf_putc(buf, ','); } if (fi != NULL) fi = TAILQ_NEXT(fi, flist); if (fi == NULL) break; if (strlen(format) == 1 && (*format == '%' || *format == 'o' || *format == 'p' || *format == 'r' || *format == 't')) break; buf_putc(buf, ' '); } if (quote) buf_putc(buf, '"'); return 0; }
char *motopp_uncomment(const char *s) { StringBuffer *buf = buf_createDefault(); char *result; int len; char c1; char c2; log_debug(__FILE__, ">>> motopp_uncomment: %s\n", s); len = strlen(s); if (len <= 2) { buf_puts(buf, s); } else { int state = 0; int addchar = 1; int i = 0; c1 = c2 = 0; while (i < len) { c1 = c2; c2 = s[i++]; if (c1 == '$') { state = '$'; } else if (c1 == '*') { state = '*'; } else if (c1 == '>') { state = '>'; } else if (c1 == '<') { state = '<'; } else { state = 0; } switch (c2) { case '*': case '>': case '<': if (state == '$') { addchar = 0; } break; case '$': if (state == '*' || state == '>' || state == '<') { addchar = 1; if (i < len) { c2 = s[i]; } } break; default: if (addchar) { if (state == '$') { buf_putc(buf, '$'); } else if (state == '*') { buf_putc(buf, '*'); } else if (state == '>') { buf_putc(buf, '>'); } else if (state == '<') { buf_putc(buf, '<'); } buf_putc(buf, c2); } break; } } } log_debug(__FILE__, "<<< motopp_uncomment: %s\n", buf_data(buf)); result = buf_toString(buf); buf_free(buf); return result; }
TabularData * pgrset_store(PGResultSet *rset) { int i, j, columns, rows; StringBuffer *colnames; StringBuffer *coltypes; TabularData *tdata; char *pgtype; columns = rset->columns; rows = rset->row_count; colnames = buf_createDefault(); coltypes = buf_createDefault(); for (i = 0; i < columns; i++){ pgtype = ihtab_get(pgTypes, rset->column_types[i]); if( estrcmp(pgtype, "int2") == 0 || estrcmp(pgtype, "int4") == 0 || estrcmp(pgtype, "oid") == 0 ) buf_puts(coltypes, "int"); else if ( estrcmp(pgtype, "double") == 0 ) buf_puts(coltypes, "double"); else if ( estrcmp(pgtype, "float4") == 0 || estrcmp(pgtype, "float8") == 0 ) buf_puts(coltypes, "float"); else if ( estrcmp(pgtype, "name") == 0 || estrcmp(pgtype, "text") == 0 || estrcmp(pgtype, "varchar") == 0 ) buf_puts(coltypes, "String"); else { buf_free(coltypes); buf_free(colnames); THROW("SQLException", "Cannot store field '%s'", rset->column_names[i]); } buf_puts(colnames, rset->column_names[i]); if(i < columns-1){ buf_putc(colnames, ','); buf_putc(coltypes, ','); } } tdata = tdata_create(rows, columns, buf_data(colnames), buf_data(coltypes)); buf_free(coltypes); buf_free(colnames); rset->row=-1; for (i = 0, pgrset_next(rset); i < rows; i++, pgrset_next(rset)){ for (j = 0; j < columns; j++){ pgtype = ihtab_get(pgTypes, rset->column_types[j]); if( estrcmp(pgtype, "int2") == 0 || estrcmp(pgtype, "int4") == 0 || estrcmp(pgtype, "oid") == 0 ) tdata_setInt(tdata, i, j, pgrset_getInt(rset, j)); else if ( estrcmp(pgtype, "float4") == 0 || estrcmp(pgtype, "float8") == 0 ) tdata_setFloat(tdata, i, j, pgrset_getFloat(rset, j)); else if ( estrcmp(pgtype, "double") == 0 ) tdata_setDouble(tdata, i, j, pgrset_getDouble(rset, j)); else if ( estrcmp(pgtype, "name") == 0 || estrcmp(pgtype, "text") == 0 || estrcmp(pgtype, "varchar") == 0 ) tdata_setString(tdata,i,j,pgrset_getString(rset,j)); else { THROW_D("Exception"); } } } rset->row = -1; tdata_optimize(tdata); return tdata; }
char * mxdl_find(char *usename) { char *result = NULL; char *libname = NULL; int len; int trlen; char *tr_usename; char *tr_pathname; char *mxpath = mxdl_getMXPath(); StringBuffer *d; /* translate the usename */ trlen = len = strlen(usename); tr_usename = emalloc(len + 1); tr_usename[len] = '\0'; while (--len >= 0) { if (*(usename + len) == '.') { *(tr_usename + len) = '_'; } else { *(tr_usename + len) = *(usename + len); } } if (index(tr_usename, '_') == NULL) { /* leave name alone */ } /* translate the tr_usename to a path */ len = strlen(tr_usename); tr_pathname = emalloc(len + 1); tr_pathname[len] = '\0'; while (--len >= 0) { if (*(tr_usename + len) == '_') { *(tr_pathname + len) = '/'; } else { *(tr_pathname + len) = *(tr_usename + len); } } /* look in all path directories for the library */ d = buf_createDefault(); if (mxpath != NULL) { char *dupmxpath = estrdup(mxpath); char *dir = strtok(dupmxpath, ":"); while (dir != NULL) { buf_clear(d); buf_puts(d, dir); if (dir[strlen(dir) - 1] != '/') { buf_putc(d, '/'); } buf_puts(d, tr_pathname); buf_putc(d, '/'); buf_puts(d, "libmx_"); buf_puts(d, tr_usename); buf_puts(d, ".so"); libname = buf_data(d); if (stat_file(libname) == 0) { result = buf_toString(d); //mman_track(rtime_getRuntime()->mpool, result); buf_free(d); d = NULL; break; } dir = strtok(NULL, ":"); } free(dupmxpath); } else { buf_printf(d, "libmx_%s.so", tr_usename); libname = buf_toString(d); buf_free(d); d = NULL; if (stat_file(libname) == 0) { result = libname; } } if (d != NULL) { buf_free(d); } free(tr_usename); free(tr_pathname); return result; }