void display_load_default_sequence() { uint8_t default_load_buffer[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; display_current_buffer = 0; copy_to_buffer(predefined_sprites[DEFAULT_1], default_load_buffer); display_load_sprite(default_load_buffer); display_current_buffer = 1; copy_to_buffer(predefined_sprites[DEFAULT_2], default_load_buffer); display_load_sprite(default_load_buffer); display_current_buffer = 0; }
TraceStream& TraceStream::write(const char *ptr, size_t siz) { if ( (outBufCur + siz) > outBufEnd) { // We need to flush data in the buffer // do { size_t numBytes = outBufEnd - outBufCur; copy_to_buffer(ptr, numBytes); flush_nonemtpy(); ptr += numBytes; siz -= numBytes; } while ( (outBufCur + siz) > outBufEnd); } copy_to_buffer(ptr, siz); return *this; }
static void inline add_to_buffer(void* stream, unsigned int length){ // This shouldn't lose any data and works for any size unsigned int stream_offset = 0; // Length calculations are in samples (stereo (short) sample pairs) unsigned int lengthi, rlengthi; unsigned int lengthLeft = length >> 2; unsigned int rlengthLeft = ceilf(lengthLeft / freq_ratio); while(1){ rlengthi = (buffer_offset + (rlengthLeft << 2) <= buffer_size) ? rlengthLeft : ((buffer_size - buffer_offset) >> 2); lengthi = rlengthi * freq_ratio; #ifdef THREADED_AUDIO // Wait for a buffer we can copy into LWP_SemWait(buffer_empty); #endif copy_to_buffer(buffer[which_buffer] + buffer_offset, stream + stream_offset, rlengthi); if(buffer_offset + (rlengthLeft << 2) < buffer_size){ buffer_offset += rlengthi << 2; #ifdef THREADED_AUDIO // This is a little weird, but we didn't fill this buffer. // So it is still considered 'empty', but since we 'decremented' // buffer_empty coming in here, we want to set it back how // it was, so we don't cause a deadlock LWP_SemPost(buffer_empty); #endif return; } lengthLeft -= lengthi; stream_offset += lengthi << 2; rlengthLeft -= rlengthi; #ifdef THREADED_AUDIO // Start the thread if this is the first sample if(!thread_running){ thread_running = 1; LWP_SemPost(first_audio); } // Let the audio thread know that we've filled a new buffer LWP_SemPost(buffer_full); #else play_buffer(); #endif #ifdef AIDUMP if(AIdump) fwrite(&buffer[which_buffer][0],1,buffer_size,AIdump); #endif NEXT(which_buffer); buffer_offset = 0; } }
int http_set_res_payload(http_response_t* response, uint8_t* payload, uint16_t size) { response->payload = copy_to_buffer(payload, size); if (response->payload) { response->payload_len = size; return 1; } return 0; }
static PyObject * get_line_buffer(EditLineObject *self, PyObject *noarg) { const LineInfo *linfo; linfo = el_line(self->el); /* use the temporary store */ copy_to_buffer(self, linfo->buffer, (linfo->lastchar - linfo->buffer)); /* convert to 'str' */ return decode(self->buffer); }
void showmotd(char *source) { struct buffer_block *dyn = NULL; char buffer[512]; int fd, l; alarm(3); fd = open(MOTD_FILE, O_RDONLY); if (fd < 0) { notice(source, "MOTD is empty"); return; } if (CurrentSendQ > HIGHSENDQTHRESHOLD) { notice(source, "Cannot process your request at this time. Try again later."); return; } while ((l = read(fd, buffer, 511)) > 0) { copy_to_buffer(&dyn, buffer, l); } close(fd); alarm(0); while (dyn != NULL) { char *ptr; copy_from_buffer(&dyn, buffer, '\n', 199); if ((ptr = strchr(buffer, '\n')) != NULL) *ptr = '\0'; else continue; if (*buffer == '\0') strcpy(buffer, " "); notice(source, buffer); } }
//write data into interface void write_to_interface(char * buffer, int buffer_size) { if (!is_device_ready()) { return; } if (0 == buffer_size) { return; } PVERBOSE("write %d byte(s) buffer to cache now\n", buffer_size); if (down_interruptible(&sem)) { return; } //we will never let our buffer be full //note when cycle_buffer_size - get_used_size() = buffer_size, all buffer will be filled, then read_ptr = write_ptr //but we have no idea buffer size is 0 or full when read_ptr = write_ptr, so avoid this states if ((cycle_buffer_size - get_used_size()) > buffer_size) { //buffer is enough write_ptr = copy_to_buffer(write_ptr, buffer, buffer_size); PVERBOSE("write complete, read_ptr: 0x%08x, write_ptr: 0x%08x, used size: %d\n", read_ptr, write_ptr, get_used_size()); } else { PWARN("failed while write to interface, buffer is full, used size: %d, need: %d\n", get_used_size(), buffer_size); } up(&sem); }
/*-------------------------------------------------------------- Routine : undo Purpose : undo last edit operation switch ( last operation ) CUT : insert COPY buffer in tree put UNDO buffer back in COPY buffer set last edit to UNDO_CUT UNDO_CUT : record COPY buffer in UNDO buffer record item in COPY buffer delete item set last edit to CUT DELETE : insert UNDO buffer in tree set last edit to ADD ADD : delete the added subtree ( put in UNDO buffer ) set last edit to DELETE CHANGE : record fields of item in tmp copy to item from undo buffer item copy from tmp to undo buffer set last edit to CHANGE SHIFTR : do a shift left set last edit to SHIFTL SHIFTL : do a shift right set last edit to SHIFTR COPY : copy from UNDO buffer to COPY buffer set last edit to UNDO_COPY UNDO_COPY : copy item to COPY buffer ---------------------------------------------------------------*/ void undo() { ITEM *item; ITEM *copy; switch ( undo_buf.type ) { case CUT: /* undo the CUT */ /* copy COPY buffer back into tree */ insert_child( undo_buf.tree, undo_buf.item, copy = get_paste_item( undo_buf.tree ), undo_buf.sibling ); /* copy UNDO buffer into COPY buffer */ copy_to_buffer( undo_buf.tree, undo_buf.subtree ); /* record this edit */ record_edit( undo_buf.tree, UNDO_CUT, copy, NULL, NULL ); break; case UNDO_CUT: /* undo the UNDO_CUT */ item = undo_buf.item; /* record this edit */ record_edit( undo_buf.tree, CUT, undo_buf.item->parent, copy = get_paste_item( undo_buf.tree ), undo_buf.item->right_sib ); /* free unnecessary copy */ delete_subtree( copy ); /* copy item back into COPY buffer */ copy_to_buffer( undo_buf.tree, item ); /* delete item */ delete_child( undo_buf.tree, item ); break; case DELETE: /* put UNDO buffer back in tree */ insert_child( undo_buf.tree, undo_buf.item, copy = copy_subtree( undo_buf.subtree ), undo_buf.sibling ); /* record this edit */ record_edit( undo_buf.tree, ADD, copy, NULL, NULL ); break; case ADD: item = undo_buf.item; /* record this edit */ record_edit( undo_buf.tree, DELETE, undo_buf.item->parent, undo_buf.item, undo_buf.item->right_sib ); /* delete the item */ delete_child( undo_buf.tree, item ); break; case CHANGE: /* not implemented yet */ break; case SHIFTR: shift_item_left( undo_buf.tree, undo_buf.item ); record_edit( undo_buf.tree, SHIFTL, undo_buf.item, NULL, NULL ); break; case SHIFTL: shift_item_right( undo_buf.tree, undo_buf.item ); record_edit( undo_buf.tree, SHIFTR, undo_buf.item, NULL, NULL ); break; case COPY: /* copy from UNDO buffer to COPY buffer */ copy_to_buffer( undo_buf.tree, undo_buf.subtree ); /* record this edit */ record_edit( undo_buf.tree, UNDO_COPY, undo_buf.item, NULL, NULL ); break; case UNDO_COPY: /* record this edit */ record_edit( undo_buf.tree, COPY, undo_buf.item, copy = get_paste_item( undo_buf.tree ), /* save copy buffer */ NULL ); /* free unnecessary copy */ delete_subtree( copy ); /* do copy */ copy_to_buffer( undo_buf.tree, undo_buf.item ); break; case NONE: printf( "undo : nothing to undo\n" ); break; default: printf( "*** WARNING: undo: illegal operation type!\n" ); } }
void http_show_help(http_socket * hsock, char *command) { char buffer[512], buffer2[200]; struct buffer_block *dyn = NULL; register char *ptr, *ptr2; register int i, index = 0, found = 0; int file, l; listinit(); /* find the command index */ for (i = 0; i <= N; i++) { if (!strcasecmp(command, commands[i].name)) { found = 1; index = i; break; } else if (!strncasecmp(command, commands[i].name, strlen(command))) { found++; index = i; } } buffer[0] = '\0'; sendto_http(hsock, HTTP_HEADER, command); sendto_http(hsock, HTTP_BODY); sendto_http(hsock, "<H1>HELP ON %s</H1>\n", (*command) ? command : "COMMANDS"); sendto_http(hsock, "<PRE>\n"); if (found > 1) { if (*command) sendto_http(hsock, "%s is ambiguous\n", command); } else if (found == 0) { if (!strcasecmp(command, "INFO")) { sprintf(buffer, "%s/INFO", HELP_DIR); } else if (!strcasecmp(command, "FORM")) { sprintf(buffer, "%s/FORM", HELP_DIR); } else { sendto_http(hsock, "No help on %s.\n", command); } } else { sprintf(buffer, "%s/%s", HELP_DIR, commands[index].file); } if (buffer[0] != '\0') { alarm(2); file = open(buffer, O_RDONLY); if (file < 0) { alarm(0); if (found) sendto_http(hsock, "The help file for command %s " "is not available\n", commands[index].name); else sendto_http(hsock, "This help file is not available\n"); } else { alarm(2); while ((l = read(file, buffer, 511)) > 0) { copy_to_buffer(&dyn, buffer, l); } alarm(0); close(file); while (dyn != NULL) { copy_from_buffer(&dyn, buffer, '\n', 199); if ((ptr = strchr(buffer, '\n')) == NULL) continue; if ((ptr = strstr(buffer, "$NICK")) != NULL) { *ptr = '\0'; sprintf(buffer2, "%s%s%s", buffer, mynick, ptr + 5); strcpy(buffer, buffer2); } /* Some nasty char quoting required.. */ ptr = buffer; ptr2 = buffer2; do { if (*ptr == '<') { ptr2[0] = '&'; ptr2[1] = 'l'; ptr2[2] = 't'; ptr2[3] = ';'; ptr2 += 4; } else if (*ptr == '>') { ptr2[0] = '&'; ptr2[1] = 'g'; ptr2[2] = 't'; ptr2[3] = ';'; ptr2 += 4; } else { ptr2[0] = ptr[0]; ptr2++; } } while (*(ptr++) != '\0'); sendto_http(hsock, "%s", buffer2); } } sendto_http(hsock, "</PRE>\n"); } else { /* show list of commands */ sendto_http(hsock, "</PRE>\n<H2>List of commands:</H2>\n"); sendto_http(hsock, "<FONT SIZE=+1>\n"); for (i = 0; i < N + 1; i++) { if (commands[i].Access <= 500) sendto_http(hsock, "<A HREF=\"/HELP/%s\">%s</A>\n", commands[i].name, commands[i].name); } sendto_http(hsock, "</FONT><P>\n"); } sendto_http(hsock, "<HR>%s\n", HTTP_FOOTER); sendto_http(hsock, "</BODY></HTML>\n"); hsock->status = HTTP_ENDING; }
void showhelp(char *source, char *chan, char *args) { struct buffer_block *dyn = NULL; char buffer[512], word[80], *ptr; int i, l, index = 0, found = 0, file, linecount = 0; if (CurrentSendQ > HIGHSENDQTHRESHOLD) { notice(source, "Cannot process your request at this time. Try again later."); return; } GetWord(0, args, word); if (!*word) strcpy(word, "help"); listinit(); /* find the command index */ for (i = 0; i <= N; i++) { if (!strcasecmp(word, commands[i].name)) { found = 1; index = i; break; } else if (!strncasecmp(word, commands[i].name, strlen(word))) { found++; index = i; } } if (found > 1) { sprintf(buffer, "%s is ambiguous", word); notice(source, buffer); return; } else if (found == 0) { if (!strcasecmp(word, "INFO")) { sprintf(buffer, "%s/INFO", HELP_DIR); } else if (!strcasecmp(word, "FORM")) { sprintf(buffer, "%s/FORM", HELP_DIR); } else { sprintf(buffer, "No help on %s. Please use " "showcommands to get a list of commands " "available to you", word); notice(source, buffer); return; } } else { sprintf(buffer, "%s/%s", HELP_DIR, commands[index].file); } alarm(2); file = open(buffer, O_RDONLY); alarm(0); if (file < 0) { if (found) sprintf(buffer, "The help file for command %s " "is not available", commands[index].name); else sprintf(buffer, "This help file is not available"); notice(source, buffer); return; } if (found) { sprintf(buffer, " HELP on %-20s Minimum access: %4d ", commands[index].name, commands[index].Access); notice(source, buffer); } alarm(3); while ((l = read(file, buffer, 511)) > 0) { copy_to_buffer(&dyn, buffer, l); } alarm(0); close(file); while (dyn != NULL) { copy_from_buffer(&dyn, buffer, '\n', 199); if ((ptr = strchr(buffer, '\n')) != NULL) *ptr = '\0'; else continue; if (*buffer == '\0') strcpy(buffer, " "); string_swap(buffer, 512, "$NICK", mynick); string_swap(buffer, 512, "$SERVER", SERVERNAME); notice(source, buffer); linecount++; } if (linecount > 0) CheckFloodFlood(source, linecount); }
void LocalClient::KeystateTaskThread::post_keystate() { PTCLHEADERDATA KEYSTATE_HEADER = { PROTOCOL_ID, client.seq_number, client.info.id, C_KEYSTATE }; KEYSTATE_HEADER.cmd_arg_mask.ch[1] = client.keystate; copy_to_buffer(VAR_SZ(KEYSTATE_HEADER), 0); send_data_to_server(buffer, PTCL_HEADER_LENGTH); }
void LocalClient::PingmanagerTaskThread::ping() { PTCLHEADERDATA PING_HEADER = { PROTOCOL_ID, client.seq_number, client.info.id, C_PING }; copy_to_buffer(VAR_SZ(PING_HEADER), 0); _latest_ping_seq_number = client.seq_number; send_data_to_server(buffer, PTCL_HEADER_LENGTH); }
/* * Provides the mechanics of collecting a line from libedit * and managing the various supported features of line-completion * special commands, ... */ static char * common_line_interaction(EditLineObject *self) { char *p; const char *buf; PyObject *cmd = NULL; PyObject *ncmd = NULL; PyObject *method_name = NULL; int n, rv, remember = 0; HistEvent ev; /* collect the string */ buf = el_gets(self->el, &n); /* something went wrong ... not exactly sure how to manage this */ if (n < 0) { if (errno == EINTR) { printf("Snagged by an interrupt s=%d\n", PyErr_CheckSignals()); } else { printf("el_gets choked on: %s\n", strerror(errno)); } el_reset(self->el); return (char *) PyErr_SetFromErrno(PyExc_SystemError); } if (n == 0) { /* appears to be when you get ^D or EOF */ p = PyMem_RawMalloc(1); if (p != NULL) *p = '\0'; return p; } /* valid count returned, but buffer is weird? */ if (buf == NULL) { PyErr_SetString(PyExc_SystemError, "el_gets returned a bad buffer"); return NULL; } /* copy the data and null-terminate it */ rv = copy_to_buffer(self, buf, n); if (rv != 0) return NULL; /* routine sets PyErr_ */ /* run the custom command interface -- push up to Python code*/ #ifdef WITH_THREAD PyGILState_STATE gilstate = PyGILState_Ensure(); #endif /* create an object of the buf cmd */ cmd = Py_BuildValue("s#", self->buffer, n); if (cmd == NULL || cmd == Py_None) { /* hmm. bad string conversion some how... fight forward...*/ goto done; } /* create the method name as a python str */ method_name = Py_BuildValue("s", "_run_command"); /* this should call the overridden one too! */ ncmd = PyObject_CallMethodObjArgs((PyObject*)self, method_name, cmd, NULL); /* its useful life is over */ Py_DECREF(method_name); #ifdef WITH_THREAD PyGILState_Release(gilstate); #endif /* a response of None indicates the command is consumed */ if (ncmd == NULL || ncmd == Py_None) { buf = "\n"; /* truncate it to an "empty" */ n = 1; goto done; } /* is it just the same command we sent? */ if (ncmd == cmd) { remember = 1; goto done; } const char *nbuf = NULL; int nbuflen = -1; /* looks like we got something different back... */ rv = PyArg_Parse(ncmd, "s#", &nbuf, &nbuflen); if (rv < 0) { /* hmm. invalid return... cannot assume the command was consumed */ /* send the original buf to the parser -- come what may */ goto done; } /* conversion is successful, move ahead with it */ buf = nbuf; n = nbuflen; remember = 1; /* create a RawMalloc'd buffer */ done: p = PyMem_RawMalloc(n+1); if (p == NULL) { PyErr_NoMemory(); return NULL; } /* Copy the malloc'ed buffer into a PyMem_Malloc'ed one. */ strncpy(p, buf, n); p[n] = '\0'; /* snoop through the string */ const char *pp = p; while (*pp != '\0') { if (isspace(*pp++)) continue; break; } /* ignore "whitespace" only lines */ if (pp == p+n) remember = 0; /* remember cmds, but ignore "empty" lines */ if (remember && strlen(p) > 0) history(self->hist, &ev, H_ENTER, p); /* clean up the python objects */ if (cmd != NULL) Py_DECREF(cmd); /* this one I'm sure of */ if (ncmd != NULL && ncmd != cmd) Py_DECREF(ncmd); /* this one, not entirely */ return p; }
/* callback triggered from libedit on a completion-char request */ static unsigned char el_complete(EditLine *el, int ch) { const LineInfo *li = el_line(el); EditLineObject *self = NULL; int rv = CC_REFRESH; PyObject *r = NULL; PyObject *t; el_get(el, EL_CLIENTDATA, &self); if (self == NULL) { PyErr_BadInternalCall(); return CC_FATAL; } /*fprintf(stderr, "ch = %d", ch); fprintf(stderr, " > li `%.*s_%.*s'\n", (int)(li->cursor - li->buffer), li->buffer, (int)(li->lastchar - 1 - li->cursor), (li->cursor >= li->lastchar) ? "" : li->cursor); */ Py_XDECREF(self->begidx); Py_XDECREF(self->endidx); self->begidx = PyLong_FromLong((long) 0); self->endidx = PyLong_FromLong((long) (li->cursor - li->buffer)); /* tmp copy to do the decode */ copy_to_buffer(self, li->buffer, (li->cursor - li->buffer)); /* push up to the main routine in python -- better to manage strings */ #ifdef WITH_THREAD PyGILState_STATE gilstate; if (self == editline_module_state->global_instance) gilstate = PyGILState_Ensure(); #endif /* t is created here but deallocated in CallMethod */ t = decode(self->buffer); if (t == NULL || t == Py_None) { #ifdef WITH_THREAD if (self == editline_module_state->global_instance) PyGILState_Release(gilstate); #endif rv = CC_ERROR; goto error; } /* this should call the overridden one too! */ r = PyObject_CallMethod((PyObject*)self, "_completer", "N", t); #ifdef WITH_THREAD if (self == editline_module_state->global_instance) PyGILState_Release(gilstate); #endif if (r == NULL || r == Py_None) { rv = CC_ERROR; goto error; } /* should check to be sure it is a long */ if (!PyLong_Check(r)) { rv = CC_ERROR; goto error; } rv = PyLong_AsLong(r); error: Py_XDECREF(r); return rv; }