int open_smag(const char *devfile) { if((dev_fd = smag_open_device(devfile)) == -1) { return -1; } smag_set_port_magellan(dev_fd); smag_init_device(dev_fd); clean_input(); return 0; }
int agi_deinit() { int ec; clean_input(); /* remove all words from memory */ agi_unload_resources(); /* unload resources in memory */ loader->unload_resource(rLOGIC, 0); ec = loader->deinit(); unload_objects(); unload_words(); clear_image_stack(); return ec; }
void get_version_string(int fd, char *buf, int sz) { int bytesrd; char tmpbuf[MAXREADSIZE]; smag_write(fd, "\r\rm0", 4); smag_write(fd, "", 0); smag_write(fd, "\r\rm0", 4); smag_write(fd, "c03", 3); smag_write(fd, "z", 1); smag_write(fd, "Z", 1); smag_write(fd, "l000", 4); usleep(SMAG_DELAY_USEC); tcflush(fd, TCIOFLUSH); clean_input(); smag_write(fd, "vQ", 2); bytesrd = smag_read(fd, tmpbuf, MAXREADSIZE); if(bytesrd > 0 && bytesrd < sz) { strcpy(buf, tmpbuf); } clean_input(); }
char* recv_input(int client_fd) { int n; char* b; b = calloc(1, sizeof(buffer)); memset(b, 0, BUFFER_LENGTH); n = recv(client_fd, b, BUFFER_LENGTH, 0); // printf("Original: %s\n\n", b); b = clean_input(b); return b; }
void smag_init_device(int fd) { smag_write(fd, "", 0); smag_write(fd, "\r\rm0", 4); smag_write(fd, "pAA", 3); smag_write(fd, "q00", 3); /*default translation and rotation */ smag_write(fd, "nM", 2); /*zero radius. 0-15 defaults to 13 */ smag_write(fd, "z", 1); /*zero device */ smag_write(fd, "c33", 3); /*set translation, rotation on and dominant axis off */ smag_write(fd, "l2\r\0", 4); smag_write(fd, "\r\r", 2); smag_write(fd, "l300", 4); smag_write(fd, "b9", 2); /*these are beeps */ smag_write(fd, "b9", 2); usleep(SMAG_DELAY_USEC); tcflush(fd, TCIOFLUSH); clean_input(); }
void Py(char *input) { PyObject *code_obj; clean_input(input); // Compile the user input as an expression. code_obj = Py_CompileString(input, "User Input", Py_eval_input); if(code_obj) { // If the compilation was successful, the resulting code // object is evaluated. DEBUG("execute_input: evaluating eval_input") mat_eval_compiled_code(code_obj, Py_eval_input); Py_DECREF(code_obj); return; } else { DEBUG("execute_input: evaluating file_input") // If the compilation did not succeed probably the // code was not an expression. Subsequently it will now // be compiled as a statement or group of statements. // The error is therefore cleared. If it triggers again // after this compilation then there will be a syntax // or other kind or error in the user's input. PyErr_Clear(); code_obj = Py_CompileString(input, "User Input", Py_file_input); if(code_obj) { mat_eval_compiled_code(code_obj, Py_file_input); Py_DECREF(code_obj); return; } } handle_error(); return; }
int start_server( char *err ) { // our username char *uname = "server"; // First call to socket() function sockfd = socket( AF_INET, SOCK_STREAM, 0 ); if( sockfd < 0 ) { sprintf( err, "ERROR opening socket" ); return 1; } // Initialize socket structure bzero((char*) &serv_addr, sizeof( serv_addr ) ); portno = SERVER_PORT; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons( portno ); // Now bind the host address using bind() call if( bind( sockfd, (struct sockaddr *) &serv_addr, sizeof( serv_addr ) ) < 0 ) { sprintf( err, "ERROR on binding" ); return 1; } // Now start listening for the clients, here process will // go into sleep mode and will wait for the incoming connection listen( sockfd, 5 ); while( 1 ) { clilen = sizeof( cli_addr ); // Accept actual connection from the client newsockfd = accept( sockfd, (struct sockaddr *)&cli_addr, &clilen ); if( newsockfd < 0 ) { sprintf( err, "ERROR on accept" ); return 1; } ipa = (char *)inet_ntoa( cli_addr.sin_addr ); // get the name of the user that connected, and send ours send( newsockfd, uname, strlen(uname), 0 ); int n = recv( newsockfd, oname, 1024, 0 ); // store length of my name and other user's name oname_len = strlen(oname); uname_len = strlen( uname ); //init_win(); start_thread(); line++; mvwprintw( chatw, line, 1, "Connection from %s [%s]\n", oname, ipa ); wrefresh(chatw); while( 1 ) { mvwgetstr( inputw, 1, 1, send_data ); wrefresh( inputw ); if( strcmp( send_data, "Q" ) == 0 ) { quit = true; send( newsockfd, send_data, strlen( send_data ), 0 ); close( newsockfd ); break; } else { line++; wattron( chatw, COLOR_PAIR(1) ); mvwprintw( chatw, line, 1, "%s: ", uname ); wattroff( chatw, COLOR_PAIR(1) ); mvwprintw( chatw, line, uname_len+3, "%s", send_data ); wrefresh( chatw ); refresh(); clean_input(); send( newsockfd, send_data, strlen( send_data ), 0 ); } } //shutdown_win(); } pthread_exit( NULL ); close( sockfd ); return 0; }
int load_game(char* s) { int i, ver, vt_entries = MAX_VIEWTABLE; UINT8 t; SINT16 parm[7]; char sig[8]; char id[8]; char description[256]; FILE *f = fopen(s, "rb"); if(!f) return err_BadFileOpen; read_bytes(f, sig, 8); if (strncmp (sig, strSig, 8)) { fclose(f); return err_BadFileOpen; } read_string (f, description); ver = read_uint8(f); if (ver == 0) vt_entries = 64; game.state = read_uint8(f); /* game.name - not saved */ read_string(f, id); if(strcmp(id, game.id)) { fclose(f); return err_BadFileOpen; } /* game.crc - not saved */ for (i = 0; i < MAX_FLAGS; i++) game.flags[i] = read_uint8(f); for (i = 0; i < MAX_VARS; i++) game.vars[i] = read_uint8(f); game.horizon = read_sint16(f); game.line_status = read_sint16(f); game.line_user_input = read_sint16(f); game.line_min_print = read_sint16(f); /* These are never saved */ game.cursor_pos = 0; game.input_buffer[0] = 0; game.echo_buffer[0] = 0; game.keypress = 0; game.input_mode = read_sint16(f); game.lognum = read_sint16(f); game.player_control = read_sint16(f); game.quit_prog_now = read_sint16(f); game.status_line = read_sint16(f); game.clock_enabled = read_sint16(f); game.exit_all_logics = read_sint16(f); game.picture_shown = read_sint16(f); game.has_prompt = read_sint16(f); game.game_flags = read_sint16(f); game.input_enabled = !read_sint16(f); for (i = 0; i < _HEIGHT; i++) game.pri_table[i] = read_uint8(f); if(game.has_window) close_window(); game.msg_box_ticks = 0; game.block.active = FALSE; /* game.window - fixed by close_window() */ /* game.has_window - fixed by close_window() */ game.gfx_mode = read_sint16(f); game.cursor_char = read_uint8(f); game.color_fg = read_sint16(f); game.color_bg = read_sint16(f); /* game.hires (#ifdef USE_HIRES) - rebuilt from image stack */ /* game.sbuf - rebuilt from image stack */ /* game.ego_words - fixed by clean_input */ /* game.num_ego_words - fixed by clean_input */ game.num_objects = read_sint16(f); for(i = 0; i < (SINT16)game.num_objects; i++) object_set_location(i, read_sint16(f)); /* Those are not serialized */ for (i = 0; i < MAX_DIRS; i++) { game.ev_keyp[i].occured = FALSE; } for (i = 0; i < MAX_STRINGS; i++) read_string (f, game.strings[i]); for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource (rLOGIC, i); else agi_unload_resource (rLOGIC, i); game.logics[i].sIP = read_sint16(f); game.logics[i].cIP = read_sint16(f); } for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rPICTURE, i); else agi_unload_resource(rPICTURE, i); } for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rVIEW, i); else agi_unload_resource(rVIEW, i); } for(i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rSOUND, i); else agi_unload_resource(rSOUND, i); } /* game.pictures - loaded above */ /* game.logics - loaded above */ /* game.views - loaded above */ /* game.sounds - loaded above */ for (i = 0; i < vt_entries; i++) { struct vt_entry* v = &game.view_table[i]; v->step_time = read_uint8(f); v->step_time_count = read_uint8(f); v->entry = read_uint8(f); v->x_pos = read_sint16(f); v->y_pos = read_sint16(f); v->current_view = read_uint8(f); /* v->view_data - fixed below */ v->current_loop = read_uint8(f); v->num_loops = read_uint8(f); /* v->loop_data - fixed below */ v->current_cel = read_uint8(f); v->num_cels = read_uint8(f); /* v->cel_data - fixed below */ /* v->cel_data_2 - fixed below */ v->x_pos2 = read_sint16(f); v->y_pos2 = read_sint16(f); /* v->s - fixed below */ v->x_size = read_sint16(f); v->y_size = read_sint16(f); v->step_size = read_uint8(f); v->cycle_time = read_uint8(f); v->cycle_time_count = read_uint8(f); v->direction = read_uint8(f); v->motion = read_uint8(f); v->cycle = read_uint8(f); v->priority = read_uint8(f); v->flags = read_uint16(f); v->parm1 = read_uint8(f); v->parm2 = read_uint8(f); v->parm3 = read_uint8(f); v->parm4 = read_uint8(f); } for (i = vt_entries; i < MAX_VIEWTABLE; i++) { memset (&game.view_table[i], 0, sizeof (struct vt_entry)); } /* Fix some pointers in viewtable */ for (i = 0; i < MAX_VIEWTABLE; i++) { struct vt_entry* v = &game.view_table[i]; if(game.dir_view[v->current_view].offset == _EMPTY) continue; if(!(game.dir_view[v->current_view].flags & RES_LOADED)) agi_load_resource(rVIEW, v->current_view); set_view(v, v->current_view); /* Fix v->view_data */ set_loop(v, v->current_loop); /* Fix v->loop_data */ set_cel(v, v->current_cel); /* Fix v->cel_data */ v->cel_data_2 = v->cel_data; v->s = NULL; /* not sure if it is used... */ } erase_both(); /* Clear input line */ clear_screen(0); write_status(); /* Recreate background from saved image stack */ clear_image_stack(); while ((t = read_uint8(f)) != 0) { for (i = 0; i < 7; i++) parm[i] = read_sint16(f); replay_image_stack_call (t, parm[0], parm[1], parm[2], parm[3], parm[4], parm[5], parm[6]); } fclose(f); setflag(F_restore_just_ran, TRUE); game.has_prompt = 0; /* force input line repaint if necessary*/ clean_input(); erase_both(); blit_both(); commit_both(); show_pic(); do_update(); return err_OK; }
void dictionary_words (char *msg) { char *p = NULL; char *q = NULL; int wid, wlen; _D ("msg = \"%s\"", msg); clean_input (); for (p = msg; p && *p && getvar (V_word_not_found) == 0; ) { if (*p == 0x20) p++; if (*p == 0) break; wid = find_word(p, &wlen); _D ("find_word(p) == %d", wid); switch (wid) { case -1: _D (_D_WARN "unknown word"); game.ego_words[game.num_ego_words].word = strdup(p); q = game.ego_words[game.num_ego_words].word; game.ego_words[game.num_ego_words].id = 19999; setvar(V_word_not_found, 1 + game.num_ego_words); game.num_ego_words++; p += strlen (p); break; case 0: /* ignore this word */ _D (_D_WARN "ignore word"); p += wlen; q = NULL; break; default: /* an OK word */ /* _D (_D_WARN "ok word (%d)", wc1); */ game.ego_words[game.num_ego_words].id = wid; game.ego_words[game.num_ego_words].word = my_strndup(p, wlen); game.num_ego_words++; p += wlen; break; } if (p != NULL && *p) { _D ("p = %s", p); *p = 0; p++; } if (q != NULL) { for (; (*q!=0 && *q!=0x20); q++); if (*q) { *q=0; q++; } } } _D (_D_WARN "num_ego_words = %d", game.num_ego_words); if (game.num_ego_words > 0) { setflag (F_entered_cli, TRUE); setflag (F_said_accepted_input, FALSE); } }
void getInput(char *result) { int num =0; char count[3]; char v,m,c; do { printf("\nEnter server (vm1 - vm10): "); } while (((scanf("%c%c%d%c", &v, &m, &num, &c)!=4 || v!='v' || m!='m' || c!='\n') && clean_input()) || num<1 || num>10); sprintf(count, "%d", num); sprintf(result, "vm"); strcat(result + strlen(result), count); }