void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { char *a; char *b; char *res; char *hold; char *another; int nleft; if( nrhs < 2 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! mtlb_get_string( prhs[0], &a ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! mtlb_get_string( prhs[1], &b ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } res = concatpaths( a, b, NULL ); nleft = nrhs - 2; while( nleft > 0 ) { nleft--; hold = res; if( ! mtlb_get_string( prhs[nrhs-1-nleft], &another ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } res = concatpaths( hold, another, NULL ); free( hold ); } plhs[0] = mxCreateString( res ); if( res != (char *) NULL ) { free( res ); } }
static Pf * orbdatabases2pf( Pf *pfanalyze ) { Pf *pf; Pf *pfdatabases; Pf *pfdatabase; Pf *pfclients; Pf *pfclient; double atime; Tbl *client_keys; int ikey; char *client_key; char *what; char *serverhost; char *clientid; char *clientaddress; char *serveraddress; char *serverport; char dbprogram[STRSZ]; char dbpath[STRSZ]; char dir[STRSZ]; char dfile[STRSZ]; char formal_name[STRSZ]; int formal_count = 0; char *delim = ":"; char *hostdir; char *serverhostcopy; char *abspath; pf = pfnew( PFFILE ); pfdatabases = pfnew( PFTBL ); atime = pfget_time( pfanalyze, "client_when" ); pfput_time( pf, "databases_when", atime ); pfeval( pfanalyze, "server{address}", &serveraddress ); pfeval( pfanalyze, "server{port}", &serverport ); pfeval( pfanalyze, "server{host}", &serverhost ); serverhostcopy = strdup( serverhost ); strtok_r( serverhostcopy, delim, &hostdir ); pfget( pfanalyze, "clients", (void **) &pfclients ); client_keys = pfkeys( pfclients ); for( ikey = 0; ikey < maxtbl( client_keys ); ikey++ ) { client_key = gettbl( client_keys, ikey ); pfget( pfclients, client_key, (void **) &pfclient ); what = pfget_string( pfclient, "what" ); clientaddress = pfget_string( pfclient, "address" ); clientid = pfget_string( pfclient, "clientid" ); if( is_dbprogram( what, dbprogram, dbpath ) ) { pfdatabase = pfnew( PFARR ); pfput_string( pfdatabase, "clientid", clientid ); pfput_string( pfdatabase, "serveraddress", serveraddress ); pfput_string( pfdatabase, "serverport", serverport ); pfput_string( pfdatabase, "dbprogram", dbprogram ); if( is_localhost( clientaddress ) ) { pfput_string( pfdatabase, "dbmachine", serveraddress ); abspath = concatpaths( hostdir, dbpath, 0 ); parsepath( abspath, dir, dfile, 0 ); free( abspath ); } else { pfput_string( pfdatabase, "dbmachine", clientaddress ); abspath = concatpaths( "", dbpath, 0 ); parsepath( abspath, dir, dfile, 0 ); free( abspath ); } pfput_string( pfdatabase, "dir", dir ); pfput_string( pfdatabase, "dfile", dfile ); sprintf( formal_name, "client%03d", ++formal_count ); pfput( pfdatabases, formal_name, pfdatabase, PFPF ); } } free( serverhostcopy ); pfput( pf, "databases", pfdatabases, PFPF ); return pf; }