/** * Handle a call to fopen() made by JavaScript. * * fopen expects 2 parameters: * 0: the path of the file to open * 1: the mode string * on success, fopen returns a result in |output|: * 0: "fopen" * 1: the filename opened * 2: the file index * on failure, fopen returns an error string in |out_error|. */ int HandleFopen(struct PP_Var params, struct PP_Var* output, const char** out_error) { CHECK_PARAM_COUNT(fopen, 2); PARAM_STRING(0, filename); PARAM_STRING(1, mode); FILE* file = fopen(filename, mode); if (!file) { *out_error = PrintfToNewString("fopen returned a NULL FILE*"); return 1; } int file_index = AddFileToMap(file); if (file_index == -1) { *out_error = PrintfToNewString("Example only allows %d open file handles", MAX_OPEN_FILES); return 1; } CREATE_RESPONSE(fopen); RESPONSE_STRING(filename); RESPONSE_INT(file_index); return 0; }
DEFINE_ACTION_FUNCTION(FString, Replace) { PARAM_SELF_STRUCT_PROLOGUE(FString); PARAM_STRING(s1); PARAM_STRING(s2); self->Substitute(*s1, *s2); return 0; }
/** * Handle a call to getaddrinfo() made by JavaScript. * * getaddrinfo expects 1 parameter: * 0: The name of the host to look up. * on success, getaddrinfo returns a result in |output|: * 0: "getaddrinfo" * 1: The canonical name * 2*n+2: Host name * 2*n+3: Address type (either "AF_INET" or "AF_INET6") * on failure, getaddrinfo returns an error string in |out_error|. */ int HandleGetaddrinfo(struct PP_Var params, struct PP_Var* output, const char** out_error) { CHECK_PARAM_COUNT(getaddrinfo, 2); PARAM_STRING(0, name); PARAM_STRING(1, family); struct addrinfo hints; memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME; if (!strcmp(family, "AF_INET")) hints.ai_family = AF_INET; else if (!strcmp(family, "AF_INET6")) hints.ai_family = AF_INET6; else if (!strcmp(family, "AF_UNSPEC")) hints.ai_family = AF_UNSPEC; else { *out_error = PrintfToNewString("getaddrinfo uknown family: %s", family); return 1; } struct addrinfo* ai; int rtn = getaddrinfo(name, NULL, &hints, &ai); if (rtn != 0) { *out_error = PrintfToNewString("getaddrinfo failed, error is \"%s\"", gai_strerror(rtn)); return 2; } CREATE_RESPONSE(getaddrinfo); RESPONSE_STRING(ai->ai_canonname); struct addrinfo* current = ai; while (current) { char addr_str[INET6_ADDRSTRLEN]; if (ai->ai_family == AF_INET6) { struct sockaddr_in6* in6 = (struct sockaddr_in6*)current->ai_addr; inet_ntop( ai->ai_family, &in6->sin6_addr.s6_addr, addr_str, sizeof(addr_str)); } else if (ai->ai_family == AF_INET) { struct sockaddr_in* in = (struct sockaddr_in*)current->ai_addr; inet_ntop(ai->ai_family, &in->sin_addr, addr_str, sizeof(addr_str)); } RESPONSE_STRING(addr_str); RESPONSE_STRING(ai->ai_family == AF_INET ? "AF_INET" : "AF_INET6"); current = current->ai_next; } freeaddrinfo(ai); return 0; }
/** * Handle a call to gethostbyname() made by JavaScript. * * gethostbyname expects 1 parameter: * 0: The name of the host to look up. * on success, gethostbyname returns a result in |output|: * 0: "gethostbyname" * 1: Host name * 2: Address type (either "AF_INET" or "AF_INET6") * 3: The first address. * 4+ The second, third, etc. addresses. * on failure, gethostbyname returns an error string in |out_error|. */ int HandleGethostbyname(struct PP_Var params, struct PP_Var* output, const char** out_error) { CHECK_PARAM_COUNT(gethostbyname, 1); PARAM_STRING(0, name); struct hostent* info = gethostbyname(name); if (!info) { *out_error = PrintfToNewString("gethostbyname failed, error is \"%s\"", hstrerror(h_errno)); return 1; } CREATE_RESPONSE(gethostbyname); RESPONSE_STRING(info->h_name); RESPONSE_STRING(info->h_addrtype == AF_INET ? "AF_INET" : "AF_INET6"); struct in_addr** addr_list = (struct in_addr**)info->h_addr_list; int i; for (i = 0; addr_list[i] != NULL; i++) { if (info->h_addrtype == AF_INET) { RESPONSE_STRING(inet_ntoa(*addr_list[i])); } else { // IPv6 char addr_str[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, addr_list[i], addr_str, sizeof(addr_str)); RESPONSE_STRING(addr_str); } } return 0; }
/** * Handle a call to opendir() made by JavaScript. * * opendir expects 1 parameter: * 0: The name of the directory * on success, opendir returns a result in |output|: * 0: "opendir" * 1: the directory name * 2: the index of the directory * on failure, opendir returns an error string in |out_error|. */ int HandleOpendir(struct PP_Var params, struct PP_Var* output, const char** out_error) { #if defined(WIN32) *out_error = PrintfToNewString("Win32 does not support opendir"); return 1; #else CHECK_PARAM_COUNT(opendir, 1); PARAM_STRING(0, dirname); DIR* dir = opendir(dirname); if (!dir) { *out_error = PrintfToNewString("opendir returned a NULL DIR*"); return 1; } int dir_index = AddDirToMap(dir); if (dir_index == -1) { *out_error = PrintfToNewString("Example only allows %d open dir handles", MAX_OPEN_DIRS); return 1; } CREATE_RESPONSE(opendir); RESPONSE_STRING(dirname); RESPONSE_INT(dir_index); return 0; #endif }
int HandleJS(struct PP_Var params, struct PP_Var* output, const char** out_error) { PostMessage("JS?"); CHECK_PARAM_COUNT(js, 2); PARAM_STRING(0, jsonstr); PARAM_STRING(1, ptr); int64_t nptr = strtoll(ptr, NULL, 10); char * addr = (char *)nptr; strcpy(addr, jsonstr); CREATE_RESPONSE(js); RESPONSE_STRING(ptr); return 0; }
static int L_readini( lua_State* L ) { const char* filename; inifile_t* inifile = NULL; inireader_iterator_t* iter = NULL; inireader_entry_t* current = NULL; btree_element_t* root = NULL; btree_element_t* groupelement = NULL; btree_element_t* grouproot = NULL; PARAM_STRING( filename ); if ( ( inifile = inireader_open( filename ) ) == NULL ) { return_error(); } // Add every entry into a btree to get the arrays and groups in one piece later DEBUGLOG( "Creating btree" ); root = btree_create(); iter = inireader_get_iterator( inifile, 0, 0, 0, 0 ); DEBUGLOG( "Filling up btree" ); for ( current = inireader_iterate( iter ); current != NULL; current = inireader_iterate( iter ) ) { DEBUGLOG( "Searching for or adding group: %s", current->group ); // Find group element groupelement = btree_find( root, current->group ); if ( groupelement == NULL ) { // A new grouproot needs to be created DEBUGLOG( "Creating new grouproot" ); grouproot = btree_create(); btree_add( &root, current->group, grouproot ); } else { // Retrieve the already added grouproot DEBUGLOG( "Setting grouproot" ); grouproot = ( btree_element_t* )groupelement->data; } // Add the new element to the grouptree btree_add( &grouproot, current->identifier, current ); } // Traverse the tree and put our inivalues onto the lua stack DEBUGLOG( "Creating initial lua table" ); lua_newtable( L ); readini_tree_traverse( L, root ); DEBUGLOG( "Freeing the btree data" ); // Free the group trees readini_tree_free( root ); // Free the main tree btree_free( root ); // Close the inifile inireader_close( inifile ); return 1; }
DEFINE_ACTION_FUNCTION(FSavegameManager, DoSave) { PARAM_SELF_STRUCT_PROLOGUE(FSavegameManager); PARAM_INT(sel); PARAM_STRING(name); self->DoSave(sel, name); return 0; }
DEFINE_ACTION_FUNCTION(FDynArray_String, Insert) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_String); PARAM_INT(index); PARAM_STRING(val); self->Insert(index, val); return 0; }
DEFINE_ACTION_FUNCTION(_Wads, FindLump) { PARAM_PROLOGUE; PARAM_STRING(name); PARAM_INT_DEF(startlump); PARAM_INT_DEF(ns); const bool isLumpValid = startlump >= 0 && startlump < Wads.GetNumLumps(); ACTION_RETURN_INT(isLumpValid ? Wads.FindLump(name, &startlump, 0 != ns) : -1); }
DEFINE_ACTION_FUNCTION(_Wads, CheckNumForName) { PARAM_PROLOGUE; PARAM_STRING(name); PARAM_INT(ns); PARAM_INT_DEF(wadnum); PARAM_BOOL_DEF(exact); ACTION_RETURN_INT(Wads.CheckNumForName(name, ns, wadnum, exact)); }
static int L_urldecode( lua_State* L ) { const char* param; char* data; PARAM_STRING( param ); data = strdup( param ); urldecode( data ); RETURN_STRING( data ); free( data ); return 1; }
int Handle_iguana(struct PP_Var params,struct PP_Var *output,const char **out_error) { char *iguana_JSON(char *); char *retstr; PostMessage("inside Handle_iguana\n"); CHECK_PARAM_COUNT(iguana, 1); PARAM_STRING(0,jsonstr); retstr = iguana_JSON(jsonstr); CREATE_RESPONSE(iguana); RESPONSE_STRING(retstr); return 0; }
int HandleSuperNET(struct PP_Var params,struct PP_Var *output,const char **out_error) { char *SuperNET_JSON(char *); char *retstr; //PostMessage("inside handle SuperNET\n"); CHECK_PARAM_COUNT(SuperNET, 1); PARAM_STRING(0,jsonstr); retstr = SuperNET_JSON(jsonstr); CREATE_RESPONSE(SuperNET); //RESPONSE_INT(0); RESPONSE_STRING(retstr); return 0; }
int CreateDenseMatrixGeneral(int argc, char *argv[]) { FILE *output; unsigned long int numRows, numCols, seed, i, j; char * outputpath; double value; MM_typecode outputmatcode; int verbose; struct st_option options[] = { FLAG_BOOL('v', "verbose", "Show more info when executing", &verbose, NULL), PARAM_INT("rows", "Number of rows of the matrix", &numRows, NULL), PARAM_INT("cols", "Number of columns of the matrix", &numCols, NULL), PARAM_STRING("outputfilename", "Filename to write the matrix into", &outputpath, NULL), PARAM_INT("seed", "Seed of the random number generator", &seed, "0"), OPTIONS_END, }; if (options_parse(options, argc, argv)) { options_usage(options, "./MM-Suite CreateDenseMatrixGeneral"); puts(option_err_msg); return 0; }; if ((output = fopen(outputpath, "w")) == NULL){ return 0; } mm_initialize_typecode(&outputmatcode); mm_set_matrix(&outputmatcode); mm_set_coordinate(&outputmatcode); mm_set_real(&outputmatcode); mm_set_general(&outputmatcode); srand(seed); mm_write_banner(output, outputmatcode); mm_write_mtx_crd_size(output, numRows, numCols, numRows*numCols); for (i = 0; i < numRows; i++) { for (j = 0; j < numCols; j++) { value = ((double) rand() / (double) RAND_MAX) / 100; fprintf(output, "%lu %lu %lg\n", i + 1, j + 1, value); } } fclose(output); return 1; };
/** * Handle a call to send() made by JavaScript. * * send expects 2 parameters: * 0: The socket file descriptor to send using. * 1: The NULL terminated string to send. * on success, send returns a result in |output|: * 0: "send" * 1: The number of bytes sent. * on failure, send returns an error string in |out_error|. */ int HandleSend(struct PP_Var params, struct PP_Var* output, const char** out_error) { CHECK_PARAM_COUNT(send, 2); PARAM_INT(0, sock); PARAM_STRING(1, buffer); int result = (int32_t)send(sock, buffer, strlen(buffer), 0); if (result <= 0) { *out_error = PrintfToNewString("send failed: %s", strerror(errno)); return 1; } CREATE_RESPONSE(send); RESPONSE_INT(result); return 0; }
/** * Handle a call to chdir() made by JavaScript. * * chdir expects 1 parameter: * 0: The name of the directory * on success, chdir returns a result in |output|: * 0: "chdir" * 1: the name of the directory * on failure, chdir returns an error string in |out_error|. */ int HandleChdir(struct PP_Var params, struct PP_Var* output, const char** out_error) { CHECK_PARAM_COUNT(chdir, 1); PARAM_STRING(0, dirname); int result = chdir(dirname); if (result != 0) { *out_error = PrintfToNewString("chdir returned error: %d", errno); return 1; } CREATE_RESPONSE(chdir); RESPONSE_STRING(dirname); return 0; }
/** * Handle a call to fwrite() made by JavaScript. * * fwrite expects 2 parameters: * 0: The index of the file (which is mapped to a FILE*) * 1: A string to write to the file * on success, fwrite returns a result in |output|: * 0: "fwrite" * 1: the file index * 2: the number of bytes written * on failure, fwrite returns an error string in |out_error|. */ int HandleFwrite(struct PP_Var params, struct PP_Var* output, const char** out_error) { CHECK_PARAM_COUNT(fwrite, 2); PARAM_FILE(0, file); PARAM_STRING(1, data); size_t bytes_written = fwrite(data, 1, data_len, file); if (ferror(file)) { *out_error = PrintfToNewString( "Wrote %" PRIuS " bytes, but ferror() returns true", bytes_written); return 1; } CREATE_RESPONSE(fwrite); RESPONSE_INT(file_index); RESPONSE_INT((int32_t)bytes_written); return 0; }
/** * Handle a call to stat() made by JavaScript. * * stat expects 1 parameter: * 0: The name of the file * on success, stat returns a result in |output|: * 0: "stat" * 1: the file name * 2: the size of the file * on failure, stat returns an error string in |out_error|. */ int HandleStat(struct PP_Var params, struct PP_Var* output, const char** out_error) { CHECK_PARAM_COUNT(stat, 1); PARAM_STRING(0, filename); struct stat buf; memset(&buf, 0, sizeof(buf)); int result = stat(filename, &buf); if (result == -1) { *out_error = PrintfToNewString("stat returned error %d", errno); return 1; } CREATE_RESPONSE(stat); RESPONSE_STRING(filename); RESPONSE_INT((int32_t)buf.st_size); return 0; }
/** * Handle a call to connect() made by JavaScript. * * connect expects 2 parameters: * 0: The hostname to connect to. * 1: The port number to connect to. * on success, connect returns a result in |output|: * 0: "connect" * 1: The socket file descriptor. * on failure, connect returns an error string in |out_error|. */ int HandleConnect(struct PP_Var params, struct PP_Var* output, const char** out_error) { CHECK_PARAM_COUNT(connect, 2); PARAM_STRING(0, hostname); PARAM_INT(1, port); // Lookup host struct hostent* hostent = gethostbyname(hostname); if (hostent == NULL) { *out_error = PrintfToNewString("gethostbyname() returned error: %d", errno); return 1; } struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); addr.sin_family = AF_INET; addr.sin_port = htons(port); memcpy(&addr.sin_addr.s_addr, hostent->h_addr_list[0], hostent->h_length); int sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { *out_error = PrintfToNewString("socket() failed: %s", strerror(errno)); return 1; } int result = connect(sock, (struct sockaddr*)&addr, addrlen); if (result != 0) { *out_error = PrintfToNewString("connect() failed: %s", strerror(errno)); close(sock); return 1; } CREATE_RESPONSE(connect); RESPONSE_INT(sock); return 0; }
DEFINE_ACTION_FUNCTION(FDynArray_String, Push) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_String); PARAM_STRING(val); ACTION_RETURN_INT(self->Push(val)); }
DEFINE_ACTION_FUNCTION(_Wads, CheckNumForFullName) { PARAM_PROLOGUE; PARAM_STRING(name); ACTION_RETURN_INT(Wads.CheckNumForFullName(name)); }
static unsigned long long split; static unsigned long long start_pfn; static unsigned long long end_pfn; static struct data_block vmcoreinfo; static struct data_block notes; static struct data_block eraseinfo; static char *vmcoreinfo_file; static char *note_file; static char *eraseinfo_file; static char *data_file; static const struct param param_array[] = { /* meta-data */ PARAM_STRING("arch_name", arch_name), PARAM_NUMBER("compression", compression), /* header */ PARAM_STRING("signature", signature), PARAM_NUMBER("version", header_version), PARAM_STRING("uts.sysname", uts_sysname), PARAM_STRING("uts.nodename", uts_nodename), PARAM_STRING("uts.release", uts_release), PARAM_STRING("uts.version", uts_version), PARAM_STRING("uts.machine", uts_machine), PARAM_STRING("uts.domainname", uts_domainname), PARAM_NUMBER("status", status), PARAM_NUMBER("block_size", block_size),
} /* buid ring */ for (br1 = br_lst; br1; br1 = br1->next) { br2 = br1->next; if (!br2) br2 = br_lst; _link_two_ports (br1, br1->ports + 1, 2, br2, br2->ports + 0, 1); } return 0; } static CMD_DSCR_T lang[] = { THE_COMMAND ("show", "get bridge[s] connuctivity") PARAM_STRING ("bridge name", "all") THE_FUNC (show_bridge) THE_COMMAND ("link", "link two bridges") PARAM_STRING ("first bridge name", NULL) PARAM_NUMBER ("port number on first bridge", 1, MAX_NUMBER_OF_PORTS, NULL) PARAM_STRING ("second bridge name", NULL) PARAM_NUMBER ("port number on second bridge", 1, MAX_NUMBER_OF_PORTS, NULL) THE_FUNC (link_bridges) THE_COMMAND ("unlink", "unlink the port of the bridge") PARAM_STRING ("bridge name", NULL) PARAM_NUMBER ("port number on bridge", 1, MAX_NUMBER_OF_PORTS, NULL) THE_FUNC (unlink_port) THE_COMMAND ("ring", "link all bridges into a ring")
DEFINE_ACTION_FUNCTION(FStringTable, Localize) { PARAM_PROLOGUE; PARAM_STRING(label); ACTION_RETURN_STRING(GStrings(label)); }
{ "adjust_dt_to_cycles" , VAR(prm.adjust_dt_to_cycles), PARAM_BOOL(0) }, { "gdims_in_terms_of_cells" , VAR(prm.gdims_in_terms_of_cells), PARAM_BOOL(false), .help = "if set, the given global dimensions (gdims) will be used for " "setting the number of cells, rather than the number of nodes in the grid." }, { "initial_particle_shift" , VAR(prm.initial_particle_shift), PARAM_DOUBLE(0.) }, { "wallclock_limit" , VAR(prm.wallclock_limit) , PARAM_DOUBLE(0.) }, { "write_checkpoint" , VAR(prm.write_checkpoint) , PARAM_BOOL(false) }, { "write_checkpoint_every_step" , VAR(prm.write_checkpoint_every_step), PARAM_INT(-1) }, { "fields_base" , VAR(prm.fields_base) , PARAM_STRING("c") }, { "particles_base", VAR(prm.particles_base) , PARAM_STRING("c") }, { "particles_base_flags" , VAR(prm.particles_base_flags) , PARAM_INT(0) }, { "stats_every" , VAR(prm.stats_every) , PARAM_INT(1), .help = "sets every how many steps we log timing and other stats." }, { "detailed_profiling" , VAR(prm.detailed_profiling) , PARAM_BOOL(false), .help = "output profiling information by MPI process rather than aggregated." }, { "theta_xz" , VAR(prm.theta_xz) , PARAM_DOUBLE(0.), .help = "rotate initial particle shifted Maxwellian in x-z plane." }, { "push_particles" , VAR(push_particles) , MRC_VAR_OBJ(psc_push_particles) }, { "push_fields" , VAR(push_fields) , MRC_VAR_OBJ(psc_push_fields) }, { "bnd" , VAR(bnd) , MRC_VAR_OBJ(psc_bnd) },