static bool active_board_add(const char *content) { char buffer[ACTIVE_BOARD_BUFSIZE * ACTIVE_BOARD_LINES]; const char *ptr = content, *end = content + strlen(content); for (int i = 0; i < 4; ++i) { ptr = get_line_end(ptr, end); } bool finished = false; char *buf = buffer; size_t size = sizeof(buffer); for (int i = 0; i < ACTIVE_BOARD_LINES; ++i) { char *lend = (char *) get_line_end(ptr, end); if (strneq2(ptr, "--\n")) finished = true; if (!finished) { char line[ACTIVE_BOARD_BUFSIZE]; convert(CONVERT_U2G, ptr, lend - ptr, line, sizeof(line), NULL, NULL); strappend(&buf, &size, line); } else { strappend(&buf, &size, "\n"); } strappend(&buf, &size, "\033[K"); ptr = lend; } return mdb_cmd_safe("SADD", "%s %s", ACTIVE_BOARD_KEY, buffer); }
int get_next_line(int const fd, char **line) { int line_end; int can_read; t_fd *fdatas; static t_fd *flst; fdatas = get_fdatas(&flst, fd); if (fdatas == NULL) return (-1); if (fdatas->start == -1) { free(fdatas->lst); fdatas->lst = NULL; fdatas->start = 0; return (0); } line_end = get_line_end(fdatas, &can_read); *line = make_str(fdatas, line_end); if (can_read == 0) fdatas->start = -1; if (can_read == -1) return (-1); if (line == NULL) return (-1); return (1); }
void active_board_show(void) { if (!DEFINE(DEF_ACBOARD)) return; mdb_res_t *res = mdb_res("SRANDMEMBER", ACTIVE_BOARD_KEY); size_t size; const char *str = mdb_string_and_size(res, &size); if (str) { const char *end = str + size; for (int i = 0; i < ACTIVE_BOARD_LINES && str < end; ++i) { char line[ACTIVE_BOARD_BUFSIZE]; const char *lend = get_line_end(str, end); if (lend && lend - str < sizeof(line) - 1) { memcpy(line, str, lend - str); line[lend - str] = '\0'; screen_move(i + 2, 0); showstuff(line); } str = lend; } } mdb_clear(res); }
int ft_readline(int fd, char **line) { int line_end; int can_read; t_fd *fdatas; static t_fd *flst; if (!(fdatas = get_fdatas(&flst, fd))) return (-1); if (fdatas->start == -1) { free(fdatas->lst); fdatas->lst = NULL; fdatas->start = 0; return (0); } line_end = get_line_end(fdatas, &can_read); *line = make_str(fdatas, line_end); if (line_end < FILE_BUFF_SIZE && can_read == 0) fdatas->start = -1; if (line_end == FILE_BUFF_SIZE && can_read == 0) return (0); if (can_read == -1 || line == NULL) return (-1); return (1); }
static gboolean inside_define(ScintillaObject *sci, gint line, gboolean newline) { gint lexer; gint start_pos; gint end_pos; gchar end_char; lexer = sci_get_lexer(sci); if(lexer != SCLEX_CPP) return FALSE; end_pos = get_line_end(sci, line); end_char = sci_get_char_at(sci, end_pos - 1); if(end_char != '\\') { dprintf("End char is not \\, exit\n"); return FALSE; } if(newline) line--; do { line--; end_pos = get_line_end(sci, line); end_char = sci_get_char_at(sci, end_pos - 1); } while(end_char == '\\' && line >= 0); line++; dprintf("Expecting define on line %d\n", line + 1); start_pos = (gint)SSM(sci, SCI_GETLINEINDENTPOSITION, (uptr_t)line, 0); end_pos = sci_get_line_end_position(sci, line); if(start_pos == end_pos) { dprintf("line empty, exit\n"); return FALSE; } const gchar *start_line = get_char_range(sci, start_pos, 7); g_return_val_if_fail(NULL != start_line, FALSE); if(0 != strncmp(start_line, "#define ", strlen("#define "))) { dprintf("Start line is not \"#define\", exit\n"); return FALSE; } return TRUE; }
static void define_format_line(ScintillaObject *sci, gint current_line) { gint length; gint first_line; gint first_end; gint max = geany_data->editor_prefs->long_line_column; if(!inside_define(sci, current_line, FALSE)) return; first_line = current_line; first_end = get_line_end(sci, first_line); for (first_end--; sci_get_char_at(sci, first_end - 1) == ' '; first_end--) {} SSM(sci, SCI_DELETERANGE, first_end, sci_get_line_end_position(sci, first_line) - first_end); length = first_end - get_indent_pos(sci, first_line) + sci_get_line_indentation(sci, first_line); for(; length < max - 1; length++, first_end++) sci_insert_text(sci, first_end, " "); sci_insert_text(sci, first_end, "\\"); }
static gint multipart_parse_header (GstMultipartDemux * multipart) { const guint8 *data; const guint8 *dataend; gchar *boundary; int boundary_len; int datalen; guint8 *pos; guint8 *end, *next; datalen = gst_adapter_available (multipart->adapter); data = gst_adapter_map (multipart->adapter, datalen); dataend = data + datalen; /* Skip leading whitespace, pos endposition should at least leave space for * the boundary and a \n */ for (pos = (guint8 *) data; pos < dataend - 4 && g_ascii_isspace (*pos); pos++); if (pos >= dataend - 4) goto need_more_data; if (G_UNLIKELY (pos[0] != '-' || pos[1] != '-')) { GST_DEBUG_OBJECT (multipart, "No boundary available"); goto wrong_header; } /* First the boundary */ if (!get_line_end (pos, dataend, &end, &next)) goto need_more_data; /* Ignore the leading -- */ boundary_len = end - pos - 2; boundary = (gchar *) pos + 2; if (boundary_len < 1) { GST_DEBUG_OBJECT (multipart, "No boundary available"); goto wrong_header; } if (G_UNLIKELY (multipart->boundary == NULL)) { /* First time we see the boundary, copy it */ multipart->boundary = g_strndup (boundary, boundary_len); multipart->boundary_len = boundary_len; } else if (G_UNLIKELY (boundary_len != multipart->boundary_len)) { /* Something odd is going on, either the boundary indicated EOS or it's * invalid */ if (G_UNLIKELY (boundary_len == multipart->boundary_len + 2 && !strncmp (boundary, multipart->boundary, multipart->boundary_len) && !strncmp (boundary + multipart->boundary_len, "--", 2))) goto eos; GST_DEBUG_OBJECT (multipart, "Boundary length doesn't match detected boundary (%d <> %d", boundary_len, multipart->boundary_len); goto wrong_header; } else if (G_UNLIKELY (strncmp (boundary, multipart->boundary, boundary_len))) { GST_DEBUG_OBJECT (multipart, "Boundary doesn't match previous boundary"); goto wrong_header; } pos = next; while (get_line_end (pos, dataend, &end, &next)) { guint len = end - pos; if (len == 0) { /* empty line, data starts behind us */ GST_DEBUG_OBJECT (multipart, "Parsed the header - boundary: %s, mime-type: %s, content-length: %d", multipart->boundary, multipart->mime_type, multipart->content_length); gst_adapter_unmap (multipart->adapter); return next - data; } if (len >= 14 && !g_ascii_strncasecmp ("content-type:", (gchar *) pos, 13)) { guint mime_len; /* only take the mime type up to the first ; if any. After ; there can be * properties that we don't handle yet. */ mime_len = get_mime_len (pos + 14, len - 14); g_free (multipart->mime_type); multipart->mime_type = g_ascii_strdown ((gchar *) pos + 14, mime_len); } else if (len >= 15 && !g_ascii_strncasecmp ("content-length:", (gchar *) pos, 15)) { multipart->content_length = g_ascii_strtoull ((gchar *) pos + 15, NULL, 10); } pos = next; } need_more_data: GST_DEBUG_OBJECT (multipart, "Need more data for the header"); gst_adapter_unmap (multipart->adapter); return MULTIPART_NEED_MORE_DATA; wrong_header: { GST_ELEMENT_ERROR (multipart, STREAM, DEMUX, (NULL), ("Boundary not found in the multipart header")); gst_adapter_unmap (multipart->adapter); return MULTIPART_DATA_ERROR; } eos: { GST_DEBUG_OBJECT (multipart, "we are EOS"); gst_adapter_unmap (multipart->adapter); return MULTIPART_DATA_EOS; } }
int process_menu(uint8_t scancode) { static union _modifier_state modifier_state; static uint8_t last_scancode; uint8_t ret=0; //Nur Flanke auswerten if(last_scancode==0xff && scancode!=0xff) { //Taste gedrückt? if(scancode!=0xff) { #ifndef AVR caca_printf(cv,1,4,"8x8 scancode(0..63) = %i ",scancode); #endif //Wandlung von 8x8 Keycode auf ASCII oder Modifier uint8_t c=characters[scancode]; uint8_t printable_char=0; //Prüfen ob ASCII Zeichen if(c) { //printf("%c %i\n",c,c); if(modifier_state.SHIFT || modifier_state.CAPS) { //alternative Belegung switch(c) { case '1': c='!'; break; case '2': c='"'; break; case '3': c='^'; break; case '4': c='$'; break; case '5': c='%'; break; case '6': c='&'; break; case '7': c='/'; break; case '8': c='('; break; case '9': c=')'; break; case '0': c='='; break; case '\\': c='?'; break; case '+': c='*'; break; case '#': c='\''; break; case '<': c='>'; break; case ',': c=';'; break; case '.': c=':'; break; case '@': c='|'; break; default: c = toupper(c); break; } } //Ist es auf dem LCD anzeigbar? if(isprint(c)) { //Shift zurücksetzen modifier_state.SHIFT=0; printable_char=c; } else { //Andere Funktion mit ASCII Zeichen wie \b, \r, \t if(c=='\b') { if(cursor_x>0) { cursor_viewport_calc(_LEFT, &cursor_x,&cursor_y,&viewport_x,&viewport_y, 0); delete_ch(cursor_x, cursor_y); } } else if(c=='\r') { cursor_viewport_calc(_DOWN, &cursor_x,&cursor_y,&viewport_x,&viewport_y, 0); cursor_x=get_line_end(cursor_y); cursor_viewport_calc(0, &cursor_x,&cursor_y,&viewport_x,&viewport_y, 0); } //else if(c=='\t') // TODO? ; } } else /*muss ein Modifier, Cursor, Funktionstaste oder ähnlich sein*/ { //printf("Not an ASCII char. scancode=%i\n",scancode); switch(scancode) { case _SHIFT: modifier_state.SHIFT=1; break; case _CAPS : modifier_state.CAPS=!modifier_state.CAPS; break; case _ALT : modifier_state.ALT=!modifier_state.ALT; break; case _STRG : modifier_state.STRG=1; break; case _ENTF :if(modifier_state.SHIFT) modifier_state.OVERWRITE=!modifier_state.OVERWRITE; else delete_ch(cursor_x, cursor_y); break; case _ENDE : cursor_x=(modifier_state.SHIFT)?0:get_line_end(cursor_y); modifier_state.SHIFT=0; break; case _ESC : clr_text_buffer(); cursor_x=0; cursor_y=0; break; default: break; } //Nur wenn nicht SHIFT, sonst könnten es //Cursortasten -_{} oder F3, F4 [] sein if(!modifier_state.SHIFT) { switch(scancode) { case _F1: if(font_size>3) font_size--; updated_settings=1; break; case _F2: if(font_size<9) font_size++; updated_settings=1; break; case _F4: strncpy(font_name,strcmp(font_name,"rowmans")? "rowmans": "scripts", 10); updated_settings=1; break; default: break; } cursor_viewport_calc(scancode, &cursor_x,&cursor_y,&viewport_x,&viewport_y, modifier_state.ALT); } else switch(scancode) { case _DOWN: printable_char='-'; break; case _LEFT: printable_char='_'; break; case _UP: printable_char='{'; break; case _RIGHT: printable_char='}'; break; case _F3: printable_char='['; break; case _F4: printable_char=']'; break; default: break; } if(printable_char) //Shift zurücksetzen modifier_state.SHIFT=0; } if(isprint(printable_char)) { //Einfügen oder Überschreiben? if(modifier_state.OVERWRITE) text_buffer[cursor_y][cursor_x]=printable_char; else insert_ch(cursor_x, cursor_y, printable_char); //Ein Zeichen weiter rechts cursor_viewport_calc(_RIGHT, &cursor_x,&cursor_y,&viewport_x,&viewport_y, 0); } ret=1; } } last_scancode=scancode; #ifndef AVR if(scancode!=0xff) { char line0[LCD_WIDTH+1]; char line1[LCD_WIDTH+1]; strncpy(line0,text_buffer[viewport_y]+viewport_x,LCD_WIDTH); strncpy(line1,text_buffer[viewport_y+1]+viewport_x,LCD_WIDTH); line0[LCD_WIDTH]=0; line1[LCD_WIDTH]=0; draw_lcd(line0, line1, viewport_x, viewport_y, cursor_x, cursor_y); } #endif return ret; }
static gboolean editor_notify_cb(GObject *object, GeanyEditor *editor, SCNotification *nt, gpointer data) { gint i = 0, val; gint old_position = 0; gint old_lposition = 0; gint old_line = 0; gint pos; if(NULL == editor || NULL == editor->sci) return FALSE; if(nt->nmhdr.code == SCN_CHARADDED) { if('\n' == nt->ch) define_format_newline(editor->sci); } if(nt->nmhdr.code == SCN_UPDATEUI) { if(g_array_index(lines_stack, gint, 0)) { /* save current position */ old_line = sci_get_current_line(editor->sci); old_lposition = sci_get_line_end_position(editor->sci, old_line) - sci_get_line_length(editor->sci, old_line); old_position = sci_get_current_position(editor->sci); sci_start_undo_action(editor->sci); } while((val = g_array_index(lines_stack, gint, i))) { i++; define_format_line(editor->sci, val - 1); dprintf("Removed from stack: %d\n", val); } if(i > 0) { sci_end_undo_action(editor->sci); g_array_remove_range(lines_stack, 0, i); /* restore current position */ pos = sci_get_line_end_position(editor->sci, old_line) - sci_get_line_length(editor->sci, old_line); sci_set_current_position(editor->sci, old_position + pos - old_lposition, FALSE); } } if(nt->nmhdr.code == SCN_MODIFIED) { if(nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT)) { if(nt->modificationType & (SC_PERFORMED_UNDO | SC_PERFORMED_REDO)) return FALSE; gint line = sci_get_line_from_position(editor->sci, nt->position) + 1; if(sci_get_char_at(editor->sci, get_line_end(editor->sci, line - 1) - 1) == '\\') { gboolean found = FALSE; while((val = g_array_index(lines_stack, gint, i))) { if(val == line) { found = TRUE; break; } i++; } if(!found) { dprintf("Added line: %d\n", line); g_array_append_val(lines_stack, line); } } } } return FALSE; }