Lines Matching refs:obj

34     DIALOG_CALLBACK obj;
53 lseek_obj(MY_OBJ * obj, long offset, int mode)
56 if ((fpos = (long) lseek(obj->fd, (off_t) offset, mode)) == -1) {
74 ftell_obj(MY_OBJ * obj)
76 return lseek_obj(obj, 0L, SEEK_CUR);
80 lseek_set(MY_OBJ * obj, long offset)
82 long actual = lseek_obj(obj, offset, SEEK_SET);
91 lseek_end(MY_OBJ * obj, long offset)
93 long actual = lseek_obj(obj, offset, SEEK_END);
96 obj->file_size = actual;
101 lseek_cur(MY_OBJ * obj, long offset)
103 long actual = lseek_obj(obj, offset, SEEK_CUR);
128 read_high(MY_OBJ * obj, size_t size_read)
137 if ((obj->fd_bytes_read = read(obj->fd, buftab, size_read)) != -1) {
139 buftab[obj->fd_bytes_read] = '\0'; /* mark end of valid data */
144 obj->bytes_read = begin_line = 0;
145 for (j = 0; j < obj->fd_bytes_read; j++)
147 obj->bytes_read += dialog_state.tab_len
148 - ((obj->bytes_read - begin_line)
151 obj->bytes_read++;
152 begin_line = obj->bytes_read;
154 obj->bytes_read++;
156 if (obj->bytes_read > obj->buffer_len) {
157 if (obj->buffer_first)
158 obj->buffer_first = FALSE; /* disp = 0 */
160 free(obj->buf);
163 obj->buffer_len = obj->bytes_read;
166 obj->buf = xalloc((size_t) obj->buffer_len + 1);
170 if (obj->buffer_first) {
171 obj->buffer_first = FALSE;
174 obj->buf = xalloc(size_read + 1);
177 obj->bytes_read = obj->fd_bytes_read;
182 while (j < obj->fd_bytes_read)
187 obj->buf[i++] = ' ';
191 obj->buf[i++] = ch;
194 obj->buf[i] = '\0'; /* mark end of valid data */
197 if (obj->bytes_read == -1)
203 find_first(MY_OBJ * obj, char *buffer, long length)
205 long recount = obj->page_length;
221 tabize(MY_OBJ * obj, long val, long *first_pos)
230 fpos = ftell_obj(obj);
232 lseek_set(obj, fpos - obj->fd_bytes_read);
237 if ((read(obj->fd, buftab, (size_t) val)) == -1)
246 *first_pos = find_first(obj, buftab, i);
259 lseek_set(obj, fpos);
269 get_line(MY_OBJ * obj)
274 obj->end_reached = FALSE;
275 while (obj->buf[obj->in_buf] != '\n') {
276 if (obj->buf[obj->in_buf] == '\0') { /* Either end of file or end of buffer reached */
277 fpos = ftell_obj(obj);
279 if (fpos < obj->file_size) { /* Not end of file yet */
283 read_high(obj, BUF_SIZE);
284 obj->in_buf = 0;
286 if (!obj->end_reached)
287 obj->end_reached = TRUE;
291 obj->line[i++] = obj->buf[obj->in_buf++];
294 obj->line[i++] = '\0';
295 obj->in_buf++;
299 obj->line[i] = '\0';
300 if (!obj->end_reached)
301 obj->in_buf++; /* move past '\n' */
303 return obj->line;
307 match_string(MY_OBJ * obj, char *string)
309 char *match = get_line(obj);
318 back_lines(MY_OBJ * obj, long n)
324 obj->begin_reached = FALSE;
329 if (!obj->end_reached) {
332 if (obj->in_buf == 0) {
333 fpos = ftell_obj(obj);
335 if (fpos > obj->fd_bytes_read) { /* Not beginning of file yet */
342 if (fpos < BUF_SIZE / 2 + obj->fd_bytes_read) {
344 lseek_set(obj, 0L);
345 val_to_tabize = fpos - obj->fd_bytes_read;
347 lseek_cur(obj, -(BUF_SIZE / 2 + obj->fd_bytes_read));
350 read_high(obj, BUF_SIZE);
352 obj->in_buf = tabize(obj, val_to_tabize, (long *) 0);
355 obj->begin_reached = TRUE;
359 obj->in_buf--;
360 if (obj->buf[obj->in_buf] != '\n')
368 if (obj->in_buf == 0) {
369 fpos = ftell_obj(obj);
371 if (fpos > obj->fd_bytes_read) {
373 if (fpos < BUF_SIZE / 2 + obj->fd_bytes_read) {
375 lseek_set(obj, 0L);
376 val_to_tabize = fpos - obj->fd_bytes_read;
378 lseek_cur(obj, -(BUF_SIZE / 2 + obj->fd_bytes_read));
381 read_high(obj, BUF_SIZE);
383 obj->in_buf = tabize(obj, val_to_tabize, (long *) 0);
386 obj->begin_reached = TRUE;
390 } while (obj->buf[--(obj->in_buf)] != '\n');
392 obj->in_buf++;
399 print_line(MY_OBJ * obj, int row, int width)
401 if (wmove(obj->text, row, 0) != ERR) {
403 char *line = get_line(obj);
410 if (width > getmaxx(obj->text))
411 width = getmaxx(obj->text);
414 for (i = 0; i <= limit && cols[i] < obj->hscroll; ++i)
420 (void) waddch(obj->text, ' ');
421 (void) waddnstr(obj->text, line + indx[first], indx[last] - indx[first]);
423 getyx(obj->text, y, x);
426 (void) waddch(obj->text, ' ');
436 print_page(MY_OBJ * obj, int height, int width)
440 obj->page_length = 0;
442 print_line(obj, i, width);
444 obj->page_length++;
445 if (obj->end_reached && !passed_end)
448 (void) wnoutrefresh(obj->text);
449 dlg_trace_win(obj->text);
456 print_position(MY_OBJ * obj, WINDOW *win, int height, int width)
462 fpos = ftell_obj(obj);
464 size = tabize(obj, obj->in_buf, &first);
466 first = find_first(obj, obj->buf, size = obj->in_buf);
470 fpos - obj->fd_bytes_read + size,
471 fpos - obj->fd_bytes_read + size,
472 obj->file_size,
571 perform_search(MY_OBJ * obj, int height, int width, int key, char *search_term)
583 if (dir ? !obj->end_reached : !obj->begin_reached) {
590 } else if ((result = get_search_term(obj->text, search_term,
602 (void) wattrset(obj->text, dialog_attr);
603 back_lines(obj, obj->page_length);
607 tempinx = obj->in_buf;
608 temp = obj->begin_reached;
609 temp1 = obj->end_reached;
610 fpos = ftell_obj(obj) - obj->fd_bytes_read;
613 back_lines(obj, (dir
614 ? obj->page_length - 1
615 : obj->page_length + 1));
617 while ((found = match_string(obj, search_term)) == FALSE) {
618 if (obj->end_reached)
622 while ((found = match_string(obj, search_term)) == FALSE) {
623 if (obj->begin_reached)
625 back_lines(obj, 2L);
631 lseek_set(obj, fpos);
633 read_high(obj, BUF_SIZE);
635 obj->in_buf = tempinx;
636 obj->begin_reached = temp;
637 obj->end_reached = temp1;
642 back_lines(obj, obj->page_length);
644 back_lines(obj, 1L);
647 (void) wattrset(obj->text, dialog_attr);
705 MY_OBJ obj;
714 memset(&obj, 0, sizeof(obj));
716 obj.begin_reached = TRUE;
717 obj.buffer_first = TRUE;
718 obj.end_reached = FALSE;
719 obj.buttons = dlg_exit_label();
722 if ((obj.fd = open(file, O_RDONLY)) == -1)
727 lseek_end(&obj, 0L);
730 lseek_set(&obj, 0L);
732 read_high(&obj, BUF_SIZE);
734 dlg_button_layout(obj.buttons, &min_width);
750 dlg_register_buttons(dialog, "textbox", obj.buttons);
755 obj.text = dlg_sub_window(dialog, PAGE_LENGTH, PAGE_WIDTH, y + 1, x + 1);
763 dlg_draw_buttons(dialog, PAGE_LENGTH + 2, 0, obj.buttons, button, FALSE, width);
767 dlg_attr_clear(obj.text, PAGE_LENGTH, PAGE_WIDTH, dialog_attr);
777 (void) scrollok(obj.text, TRUE);
778 (void) scroll(obj.text); /* Scroll text region up one line */
779 (void) scrollok(obj.text, FALSE);
780 print_line(&obj, PAGE_LENGTH - 1, PAGE_WIDTH);
781 (void) wnoutrefresh(obj.text);
790 (void) scrollok(obj.text, TRUE);
791 (void) wscrl(obj.text, -1); /* Scroll text region down one line */
792 (void) scrollok(obj.text, FALSE);
793 obj.page_length = 0;
797 print_line(&obj, 0, PAGE_WIDTH); /* print first line of page */
798 (void) wnoutrefresh(obj.text);
800 (void) get_line(&obj); /* Called to update 'end_reached' and 'in_buf' */
802 obj.page_length++;
803 if (obj.end_reached && !passed_end)
807 print_page(&obj, PAGE_LENGTH, PAGE_WIDTH);
809 print_position(&obj, dialog, height, width);
820 if (!fkey && (code = dlg_char_to_button(key, obj.buttons)) >= 0) {
837 button = dlg_next_button(obj.buttons, button);
842 obj.buttons, button,
846 button = dlg_prev_button(obj.buttons, button);
851 obj.buttons, button,
861 if (!obj.begin_reached) {
862 obj.begin_reached = 1;
864 fpos = ftell_obj(&obj);
866 if (fpos > obj.fd_bytes_read) {
868 lseek_set(&obj, 0L);
870 read_high(&obj, BUF_SIZE);
872 obj.in_buf = 0;
877 obj.end_reached = TRUE;
879 fpos = ftell_obj(&obj);
881 if (fpos < obj.file_size) {
883 lseek_end(&obj, -BUF_SIZE);
885 read_high(&obj, BUF_SIZE);
887 obj.in_buf = obj.bytes_read;
888 back_lines(&obj, (long) PAGE_LENGTH);
892 if (!obj.begin_reached) {
893 back_lines(&obj, obj.page_length + 1);
900 if (!obj.begin_reached) {
901 back_lines(&obj, obj.page_length + PAGE_LENGTH);
906 if (!obj.end_reached) {
907 obj.begin_reached = 0;
914 if (!obj.end_reached) {
915 obj.begin_reached = 0;
920 if (obj.hscroll > 0) {
921 obj.hscroll = 0;
923 back_lines(&obj, obj.page_length);
928 if (obj.hscroll > 0) {
929 obj.hscroll--;
931 back_lines(&obj, obj.page_length);
936 if (obj.hscroll < MAX_LEN) {
937 obj.hscroll++;
939 back_lines(&obj, obj.page_length);
948 back_lines(&obj, obj.page_length);
963 moved = perform_search(&obj, height, width, key, search_term);
974 free(obj.buf);
975 (void) close(obj.fd);