Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / wm / tview.c
blob9a4cc0f20cd2632a50a83b3c13cb4f14d3705890
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <fcntl.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <time.h>
26 #include <libx/base.h>
27 #include <libx/object.h>
28 #include <libx/image.h>
29 #include <libx/cursor.h>
30 #include <libx/text.h>
31 #include "window.h"
32 #include "cursor.h"
33 #include "button.h"
34 #include "menu.h"
35 #include "dialog.h"
36 #include "filemanager.h"
37 #include "config.h"
39 wmwindow *tview;
40 unsigned tview_act = 0;
42 char *file;
43 unsigned len;
45 unsigned tview_open (char *name)
47 if (tview_act || !name)
48 return 0;
50 file = (char *) malloc (sizeof (char) * 2049);
52 if (!file)
53 return 0;
55 // html web page
56 int fd = open (name, O_RDONLY);
58 if (!fd) {
59 return 0;
62 int ret = 2048;
63 len = 0;
65 //while (1) {
66 ret = read (fd, file+len, 2048);
68 if (!ret)
69 return 0;
71 len += ret;
73 file[len] = '\0';
75 /* if (ret != 512)
76 break;
78 if (ret == 512)
79 file = (char *) realloc ((void *) file, sizeof (char) * len + 512);
81 if (!file) {
82 free (file);
83 return 0;
85 }*/
87 tview = window_create (name);
89 if (!tview)
90 return 0;
92 tview_act = 1;
94 return 1;
97 void tview_draw ()
99 if (!tview_act || !tview)
100 return;
102 unsigned i = 0;
103 unsigned k = 0;
104 unsigned j = 0;
106 for (i = 0; i < len; i ++) {
107 if (file[i] == '\n') {
108 k ++;
109 j = 0;
112 xtext_putch (tview->x+1+(j*5), tview->y+11+(k*9), 0, file[i]);
114 if ((j*5+1) > tview->size_x)
115 tview->size_x += 5;
117 if ((11+(k*9)) > tview->size_y)
118 tview->size_y += 9;
120 j ++;
124 unsigned init_tview ()
126 tview = 0;
127 tview_act = 0;
128 len = 0;
130 return 1;