static gint c_server_request(lua_State *ls) { XmlTag *tag; const gchar *str; gint ecode; arg_check(ls, 1, 1); lua_getglobal(ls, "tostring"); lua_pushvalue(ls, 1); ecode = lua_pcall(ls, 1, 1, 0); if (ecode != 0) lua_error(ls); str = luaL_checkstring(ls, -1); if (str == NULL) luaL_argerror(ls, 1, "nil value"); tag = talk_half_say((gchar *) str); lua_pop(ls, 1); lua_push_xml_tag(ls, tag); return 1; }
static gint c_dofile(lua_State *ls) { const gchar *file; const gchar *dir; gchar *path; gint ecode; arg_check(ls, 1, 1); file = luaL_checkstring(ls, 1); if (strchr(file, '/') != NULL) luaL_error(ls, "invalid arg"); lua_getfield(ls, LUA_REGISTRYINDEX, "__lua_init_dir"); dir = luaL_checkstring(ls, -1); lua_pop(ls, 1); path = g_strdup_printf("%s/%s.lua", dir, file); ecode = luaL_dofile(ls, path); g_free(path); if (ecode != 0) lua_error(ls); return 0; }
int main(int argc, char const **argv) { arg_check(argc); int socket_fd, recv, len; char msg[6] = "hello"; char response[MSG_SIZE_CLIENT], server_port[6], server_ip[40]; struct timeval times[3]; struct sockaddr_storage server_addr; struct addrinfo hints, *res; fd_set read_set; bzero(response, sizeof response); resolve(server_ip, argv[1]); setup(&socket_fd, &hints, res, server_ip, server_port, &server_addr, &len); fd_clear_set(&socket_fd, &read_set); sendmessage(&socket_fd, &msg[0], (struct sockaddr *) &server_addr, len, times); recv = waitresponse(socket_fd, &read_set, times[2]); getresults1(recv, socket_fd, &response[0], times); close(socket_fd); }
int main(int argc,char **argv) { int sockfd,newsockfd; arg_check(argc); sockfd=set_server(NULL,argv[1]); newsockfd=make_connection(sockfd); GET(newsockfd); }
static gint c_xml_tag_get_body(lua_State *ls) { XmlTag *tag; arg_check(ls, 1, 1); tag = c_get_xml_tag(ls); lua_push_variant(ls, xml_tag_get_body(tag)); return 1; }
static gint c_xml_tag_get_attr(lua_State *ls) { XmlTag *tag; gchar *name; arg_check(ls, 2, 2); tag = c_get_xml_tag(ls); name = (gchar *) luaL_checkstring(ls, 2); lua_push_variant(ls, xml_tag_get_attr(tag, name)); return 1; }
static gint c_markup_escape(lua_State *ls) { const gchar *str; gchar *text; arg_check(ls, 1, 1); str = luaL_checkstring(ls, 1); text = g_markup_escape_text(str, -1); lua_pushstring(ls, text); g_free(text); return 1; }
static gint c_xml_tag_next(lua_State *ls) { XmlTag *tag; arg_check(ls, 1, 1); tag = c_get_xml_tag(ls); if (tag->next == NULL) lua_pushnil(ls); else lua_push_xml_tag(ls, tag->next); return 1; }
int main(int argc, char *argv[]) { srand(time(NULL)); int SDL = 0; // SDL flag maze_entrance entrance; // Stores coords of entrance to maze maze_dimensions dimensions; // Stores width and height of the maze as given in file max_maze mazeArray; // Char array of maximum size arg_check(argc); // Initalise to spaces. In case the user has entered a newline early. initialiseArray(mazeArray, MAX_SIZE); // Inspect and act on argv[1]. Get maze from file or generate it. dimensions = get_maze(argv, mazeArray); // If argv[2] is given, set/don't set graphics flag. Will ignore further arguements. if (argc >= 3) { SDL = initialise_SDL(argv); } entrance = findEntrance(mazeArray,dimensions); if(explore(entrance.x, entrance.y, mazeArray, dimensions)){ printf("Route found!\n\n"); if(SDL){ display_SDL(mazeArray, dimensions); // Display solution with SDL GUI } else { display_Terminal(mazeArray, dimensions); // Use the terminal unless told otherwise } return 0; } else { // If unsuccessful, show the scanned maze in terminal regardless of SDL flag: printf("No path found through the maze!\nThe maze was scanned as:\n"); display_Terminal(mazeArray, dimensions); if(SDL){ display_SDL(mazeArray, dimensions); } return 1; } }
static gint c_xml_tag_get_child(lua_State *ls) { XmlTag *tag; gchar *name; arg_check(ls, 2, 2); tag = c_get_xml_tag(ls); name = (gchar *) luaL_checkstring(ls, 2); tag = xml_tag_get_child(tag, name); if (tag == NULL) lua_pushnil(ls); else lua_push_xml_tag(ls, tag); return 1; }
//コマンドラインオプションを読み込むーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー int mode_check(char *argv[], commandline_t *commandline,int argc){ // ループ毎に1つずつコマンドラインオプションを取得する:arg_check(argv[i]) if ( argc > 2 ){ //引数は最大2個まで return ERROR_ARG_TOO_MANY; } for(int i = 1; i < argc; i++){ //1つ目のパラメータは実行ファイルなので弾く switch ( arg_check(argv[i]) ) { case 's': commandline->server = i; break; case 'c': commandline->client = i; break; default: return ERROR_ARG_UNKNOWN; break; } } return NO_ERROR; }
static gint c_cmd_register(lua_State *ls) { struct lua_cmd_entry entry; const gchar *handler; const gchar *method; const gchar *str; gint min, max; gint nargs; nargs = lua_gettop(ls); arg_check(ls, 2, 5); min = max = 0; if (nargs >= 4) { if (lua_isnil(ls, 4)) min = -1; else { min = luaL_checkinteger(ls, 4); luaL_argcheck(ls, min >= 0, 4, "negative value"); } max = min; if (nargs > 4) { if (min < 0) luaL_error(ls, "argument #5 is unnecessary if #4 = nil"); if (lua_isnil(ls, 5)) max = 0; else { gint n; n = luaL_checkinteger(ls, 5); luaL_argcheck(ls, n >= 0, 5, "negative value"); max += n; } } } str = luaL_checkstring(ls, 1); if (lua_isnil(ls, 2)) method = NULL; else method = luaL_checkstring(ls, 2); if (lua_isnoneornil(ls, 3)) handler = NULL; else { handler = luaL_checkstring(ls, 3); lua_getglobal(ls, handler); if (lua_isfunction(ls, -1) == 0) { lua_pop(ls, 1); luaL_error(ls, "argument #3 is not a lua function"); } } entry.cmdv = g_strsplit(str, " ", 0); entry.method = g_strdup(method); entry.handler = g_strdup(handler); entry.arg_min = min; entry.arg_max = max; lua_cmd_push(g_memdup(&entry, sizeof(entry))); return 0; }