/[LeafOK_CVS]/lbbs/src/screen.c
ViewVC logotype

Diff of /lbbs/src/screen.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.11 by sysadm, Sun Mar 20 17:37:14 2005 UTC Revision 1.60 by sysadm, Sat May 17 12:28:47 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            screen.c  -  description                                                    screen.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Mon Oct 18 2004          Copyright            : (C) 2004-2025 by Leaflet
5      copyright            : (C) 2004 by Leaflet          Email                : leaflet@leafok.com
     email                : leaflet@leafok.com  
6   ***************************************************************************/   ***************************************************************************/
7    
8  /***************************************************************************  /***************************************************************************
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
12   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 3 of the License, or     *
13   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #include "screen.h"
18  #include "bbs.h"  #include "bbs.h"
19  #include "common.h"  #include "common.h"
20    #include "str_process.h"
21    #include "log.h"
22  #include "io.h"  #include "io.h"
23    #include "file_loader.h"
24    #include <fcntl.h>
25    #include <string.h>
26    #include <ctype.h>
27    #include <unistd.h>
28    #include <stdlib.h>
29    #include <errno.h>
30  #include <sys/types.h>  #include <sys/types.h>
31  #include <sys/stat.h>  #include <sys/stat.h>
32  #include <unistd.h>  #include <sys/param.h>
33    #include <sys/shm.h>
34    
35  #define ACTIVE_BOARD_HEIGHT     8  #define ACTIVE_BOARD_HEIGHT 8
36    
37  int screen_lines = 24;  void moveto(int row, int col)
   
 void  
 moveto (int row, int col)  
38  {  {
39    if (row >= 0)          if (row >= 0)
40      {          {
41        prints ("\033[%d;%dH", row, col);                  prints("\033[%d;%dH", row, col);
42      }          }
43    else          else
44      {          {
45        prints ("\r");                  prints("\r");
46      }          }
   iflush ();  
47  }  }
48    
49  void  void clrtoeol()
 clrtoeol ()  
50  {  {
51    prints ("\033[K");          prints("\033[K");
   iflush ();  
52  }  }
53    
54  void  void clrline(int line_begin, int line_end)
 clrline (int line_begin, int line_end)  
55  {  {
56    int i;          int i;
57    
58    for (i = line_begin; i <= line_end; i++)          for (i = line_begin; i <= line_end; i++)
59      {          {
60        moveto (i, 0);                  moveto(i, 0);
61        prints ("\033[K");                  prints("\033[K");
62      }          }
   
   iflush ();  
63  }  }
64    
65  void  void clrtobot(int line_begin)
 clearscr ()  
66  {  {
67    prints ("\33[2J");          moveto(line_begin, 0);
68    moveto (0, 0);          prints("\033[J");
69    iflush ();          moveto(line_begin, 0);
70  }  }
71    
72  int  void clearscr()
 press_any_key ()  
73  {  {
74    moveto (screen_lines, 0);          prints("\033[2J");
75    clrtoeol ();          moveto(0, 0);
   
   prints ("                           \033[1;33m按任意键继续...\033[0;37m");  
   iflush ();  
   
   return igetch ();  
76  }  }
77    
78  void  int press_any_key()
 set_input_echo (int echo)  
79  {  {
80    char temp[256];          moveto(SCREEN_ROWS, 0);
81            clrtoeol();
82    
83            prints("                           \033[1;33m按任意键继续...\033[0;37m");
84            iflush();
85    
86    if (echo)          return igetch_t(MIN(MAX_DELAY_TIME, 60));
     {  
       outc ('\x83');            // ASCII code 131  
       iflush ();  
     }  
   else  
     {  
 //    outc ('\x85'); // ASCII code 133  
       prints ("\xff\xfb\x01\xff\xfb\x03");  
       iflush ();  
       igetch ();  
       igetch ();  
     }  
87  }  }
88    
89  int  void set_input_echo(int echo)
 str_input (char *buffer, int buffer_length, int echo_mode)  
90  {  {
91    char buf[256], ch;          if (echo)
   int c, offset = 0, len, loop = 1, i, hz = 0;  
   
   memset (buffer, '\0', buffer_length);  
   
   while (c = igetch ())  
     {  
       if (c == CR)  
         break;  
       if (c == LF)  
         continue;  
       if (c == BACKSPACE)  
         {  
           if (offset > 0)  
             {  
               buffer[--offset] = '\0';  
               prints ("\b \b");  
 //            clrtoeol ();  
               iflush ();  
             }  
           continue;  
         }  
       if (c > 255 || iscntrl (c))  
92          {          {
93            continue;                  outc('\x83'); // ASCII code 131
94                    iflush();
95          }          }
96        if (c > 127 && c <= 255)          else
97          {          {
98            hz = (!hz);                  //    outc ('\x85'); // ASCII code 133
99                    prints("\xff\xfb\x01\xff\xfb\x03");
100                    iflush();
101                    igetch(0);
102                    igetch_reset();
103          }          }
       if (offset >= buffer_length)  
         {  
           outc ('\a');  
           continue;  
         }  
       buffer[offset++] = (char) c;  
       buffer[offset] = '\0';  
       switch (echo_mode)  
         {  
         case 0:  
           outc ((char) c);  
           break;  
         case 1:  
           outc ('*');  
           break;  
         }  
       if (!hz)  
         {  
           iflush ();  
         }  
     }  
   
   prints ("\r\n");  
   iflush ();  
   
   return offset;  
104  }  }
105    
106  int  static int _str_input(char *buffer, int buf_size, int echo_mode)
 display_file (const char *filename)  
107  {  {
108    char buffer[260];          int c;
109    FILE *fin;          int offset = 0;
110    int i;          int hz = 0;
111    
112            buffer[buf_size - 1] = '\0';
113            for (offset = 0; offset < buf_size - 1 && buffer[offset] != '\0'; offset++)
114                    ;
115    
116    if ((fin = fopen (filename, "r")) == NULL)          igetch_reset();
     {  
       return -1;  
     }  
117    
118    while (fgets (buffer, 255, fin))          while (!SYS_server_exit)
     {  
       i = strlen (buffer);  
       if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')  
119          {          {
120            buffer[i - 1] = '\r';                  c = igetch_t(MIN(MAX_DELAY_TIME, 60));
121            buffer[i] = '\n';  
122            buffer[i + 1] = '\0';                  if (c == CR)
123                    {
124                            igetch_reset();
125                            break;
126                    }
127                    else if (c == KEY_TIMEOUT || c == KEY_NULL) // timeout or broken pipe
128                    {
129                            return -1;
130                    }
131                    else if (c == LF || c == '\0')
132                    {
133                            continue;
134                    }
135                    else if (c == BACKSPACE)
136                    {
137                            if (offset > 0)
138                            {
139                                    offset--;
140                                    if (buffer[offset] < 0 || buffer[offset] > 127)
141                                    {
142                                            prints("\033[D \033[D");
143                                            offset--;
144                                            if (offset < 0) // should not happen
145                                            {
146                                                    log_error("Offset of buffer is negative\n");
147                                                    offset = 0;
148                                            }
149                                    }
150                                    buffer[offset] = '\0';
151                                    prints("\033[D \033[D");
152                                    iflush();
153                            }
154                            continue;
155                    }
156                    else if (c > 255 || iscntrl(c))
157                    {
158                            continue;
159                    }
160                    else if (c > 127 && c <= 255)
161                    {
162                            if (!hz && offset + 2 > buf_size - 1) // No enough space for Chinese character
163                            {
164                                    igetch(0); // Ignore 1 character
165                                    outc('\a');
166                                    iflush();
167                                    continue;
168                            }
169                            hz = (!hz);
170                    }
171    
172                    if (offset + 1 > buf_size - 1)
173                    {
174                            outc('\a');
175                            iflush();
176                            continue;
177                    }
178    
179                    buffer[offset++] = (char)c;
180                    buffer[offset] = '\0';
181    
182                    switch (echo_mode)
183                    {
184                    case DOECHO:
185                            outc((char)c);
186                            break;
187                    case NOECHO:
188                            outc('*');
189                            break;
190                    }
191                    if (!hz)
192                    {
193                            iflush();
194                    }
195          }          }
       prints (buffer);  
       iflush ();  
     }  
   fclose (fin);  
196    
197    return 0;          return offset;
198  }  }
199    
200  int  int str_input(char *buffer, int buf_size, int echo_mode)
 display_file_ex (const char *filename, int begin_line, int wait)  
201  {  {
202    char buffer[260], temp[256];          int len;
   int i, ch, input_ok;  
   long int line, c_line_begin = 0, c_line_total = 0;  
   long int f_line, f_size, f_offset;  
   FILE *fin;  
   struct stat f_stat;  
203    
204    clrline (begin_line, screen_lines);          buffer[0] = '\0';
   line = begin_line;  
   moveto (line, 0);  
205    
206    if ((fin = fopen (filename, "r")) != NULL)          len = _str_input(buffer, buf_size, echo_mode);
207      {  
208        if (fstat (fileno (fin), &f_stat) != 0)          prints("\r\n");
209          {          iflush();
210            log_error ("Get file stat failed\n");  
211            return -1;          return len;
212          }  };
213        f_size = f_stat.st_size;  
214    int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int echo_mode)
215    {
216            int len;
217    
218        while (fgets (buffer, 255, fin))          moveto(row, col);
219          c_line_total++;          prints(prompt);
220        rewind (fin);          prints(buffer);
221            iflush();
222    
223        while (fgets (buffer, 255, fin))          len = _str_input(buffer, buf_size, echo_mode);
224    
225            return len;
226    }
227    
228    int display_file_ex(const char *filename, int begin_line, int wait)
229    {
230            static int show_help = 1;
231            char buffer[LINE_BUFFER_LEN];
232            int ch = KEY_NULL;
233            int input_ok, line, max_lines;
234            long int line_current = 0;
235            const void *p_file_shm;
236            const void *p_data;
237            size_t data_len;
238            long line_total;
239            const long *p_line_offsets;
240            long int len;
241            long int percentile;
242            int loop;
243    
244            if ((p_file_shm = get_file_shm(filename)) == NULL)
245          {          {
246            if (line >= screen_lines)                  log_error("get_file_shm(%s) error\n", filename);
247              {                  return KEY_NULL;
248                f_offset = ftell (fin);          }
249    
250                moveto (screen_lines, 0);          data_len = *((size_t *)p_file_shm);
251                prints          line_total = *((long *)(p_file_shm + sizeof(size_t)));
252                  ("\033[1;44;32m下面还有喔 (%d%%)\033[33m   │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",          p_data = p_file_shm + sizeof(data_len) + sizeof(line_total);
253                   (f_offset - strlen (buffer)) * 100 / f_size);          p_line_offsets = p_data + data_len + 1;
               iflush ();  
254    
255                input_ok = 0;          clrline(begin_line, SCREEN_ROWS);
256                while (!input_ok)          line = begin_line;
257            max_lines = SCREEN_ROWS - 1;
258    
259            loop = 1;
260            while (!SYS_server_exit && loop)
261            {
262                    if (line_current >= line_total && line_total <= SCREEN_ROWS - 2)
263                  {                  {
264                    ch = igetch ();                          if (wait)
                   input_ok = 1;  
                   switch (ch)  
                     {  
                     case KEY_UP:  
                       c_line_begin--;  
                       if (c_line_begin >= 0)  
                         {  
                           rewind (fin);  
                           for (f_line = 0; f_line < c_line_begin; f_line++)  
                             {  
                               if (fgets (buffer, 255, fin) == NULL)  
                                 goto exit;  
                             }  
                         }  
                       else  
265                          {                          {
266                            goto exit;                                  ch = press_any_key();
267                          }                          }
268                        break;                          else
                     case KEY_DOWN:  
                     case CR:  
                       c_line_begin++;  
                       rewind (fin);  
                       for (f_line = 0; f_line < c_line_begin; f_line++)  
269                          {                          {
270                            if (fgets (buffer, 255, fin) == NULL)                                  iflush();
                             goto exit;  
271                          }                          }
272                        break;  
273                      case KEY_PGUP:                          loop = 0;
274                      case Ctrl ('B'):                          break;
275                        if (c_line_begin > 0)                  }
276                          c_line_begin -= (screen_lines - begin_line - 1);  
277                        else                  if (line_current >= line_total || line >= max_lines)
278                          goto exit;                  {
279                        if (c_line_begin < 0)                          if (line_current - (line - 1) + (SCREEN_ROWS - 2) < line_total)
                         c_line_begin = 0;  
                       rewind (fin);  
                       for (f_line = 0; f_line < c_line_begin; f_line++)  
280                          {                          {
281                            if (fgets (buffer, 255, fin) == NULL)                                  percentile = (line_current - (line - 1) + (SCREEN_ROWS - 2)) * 100 / line_total;
                             goto exit;  
282                          }                          }
283                        break;                          else
                     case KEY_RIGHT:  
                     case KEY_PGDOWN:  
                     case Ctrl ('F'):  
                     case KEY_SPACE:  
                       c_line_begin += (screen_lines - begin_line - 1);  
                       if (c_line_begin + (screen_lines - begin_line) >  
                           c_line_total)  
                         c_line_begin =  
                           c_line_total - (screen_lines - begin_line);  
                       rewind (fin);  
                       for (f_line = 0; f_line < c_line_begin; f_line++)  
284                          {                          {
285                            if (fgets (buffer, 255, fin) == NULL)                                  percentile = 100;
                             goto exit;  
286                          }                          }
287                        break;  
288                      case KEY_LEFT:                          moveto(SCREEN_ROWS, 0);
289                      case 'q':                          prints("\033[1;44;32m%s (%d%%)%s\033[33m          │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",
290                      case 'Q':                                     (percentile < 100 ? "下面还有喔" : "没有更多了"), percentile,
291                        goto exit;                                     (percentile < 10 ? "  " : (percentile < 100 ? " " : "")));
292                        break;                          iflush();
293                      case '?':  
294                      case 'h':                          input_ok = 0;
295                      case 'H':                          while (!SYS_server_exit && !input_ok)
                       //Display help information  
                       strcpy (temp, app_home_dir);  
                       strcat (temp, "data/read_help.txt");  
                       display_file_ex (temp, begin_line, 1);  
   
                       //Refresh after display help information  
                       rewind (fin);  
                       for (f_line = 0; f_line < c_line_begin; f_line++)  
296                          {                          {
297                            if (fgets (buffer, 255, fin) == NULL)                                  ch = igetch_t(MAX_DELAY_TIME);
298                              goto exit;                                  input_ok = 1;
299                                    switch (ch)
300                                    {
301                                    // case KEY_NULL:
302                                    case KEY_TIMEOUT:
303                                            goto cleanup;
304                                    case KEY_HOME:
305                                            line_current = 0;
306                                            line = begin_line;
307                                            max_lines = SCREEN_ROWS - 1;
308                                            clrline(begin_line, SCREEN_ROWS);
309                                            break;
310                                    case KEY_END:
311                                            line_current = line_total - (SCREEN_ROWS - 2);
312                                            line = begin_line;
313                                            max_lines = SCREEN_ROWS - 1;
314                                            clrline(begin_line, SCREEN_ROWS);
315                                            break;
316                                    case KEY_UP:
317                                            if (line_current - line < 0) // Reach top
318                                            {
319                                                    break;
320                                            }
321                                            line_current -= line;
322                                            line = begin_line;
323                                            // max_lines = begin_line + 1;
324                                            // prints("\033[T"); // Scroll down 1 line
325                                            max_lines = SCREEN_ROWS - 1; // Legacy Fterm only works with this line
326                                            break;
327                                    case CR:
328                                            igetch_reset();
329                                    case KEY_DOWN:
330                                            if (line_current + ((SCREEN_ROWS - 2) - (line - 1)) >= line_total) // Reach bottom
331                                            {
332                                                    break;
333                                            }
334                                            line_current += ((SCREEN_ROWS - 2) - (line - 1));
335                                            line = SCREEN_ROWS - 2;
336                                            max_lines = SCREEN_ROWS - 1;
337                                            moveto(SCREEN_ROWS, 0);
338                                            clrtoeol();
339                                            prints("\033[S"); // Scroll up 1 line
340                                            break;
341                                    case KEY_PGUP:
342                                    case Ctrl('B'):
343                                            if (line_current - line < 0) // Reach top
344                                            {
345                                                    break;
346                                            }
347                                            line_current -= ((SCREEN_ROWS - 3) + (line - 1));
348                                            if (line_current < 0)
349                                            {
350                                                    line_current = 0;
351                                            }
352                                            line = begin_line;
353                                            max_lines = SCREEN_ROWS - 1;
354                                            clrline(begin_line, SCREEN_ROWS);
355                                            break;
356                                    case KEY_RIGHT:
357                                    case KEY_PGDN:
358                                    case Ctrl('F'):
359                                    case KEY_SPACE:
360                                            if (line_current + (SCREEN_ROWS - 2) - (line - 1) >= line_total) // Reach bottom
361                                            {
362                                                    break;
363                                            }
364                                            line_current += (SCREEN_ROWS - 3) - (line - 1);
365                                            if (line_current + SCREEN_ROWS - 2 > line_total) // No enough lines to display
366                                            {
367                                                    line_current = line_total - (SCREEN_ROWS - 2);
368                                            }
369                                            line = begin_line;
370                                            max_lines = SCREEN_ROWS - 1;
371                                            clrline(begin_line, SCREEN_ROWS);
372                                            break;
373                                    case KEY_LEFT:
374                                    case 'q':
375                                    case 'Q':
376                                            loop = 0;
377                                            break;
378                                    case '?':
379                                    case 'h':
380                                    case 'H':
381                                            if (!show_help)
382                                            {
383                                                    break;
384                                            }
385    
386                                            // Display help information
387                                            show_help = 0;
388                                            display_file_ex(DATA_READ_HELP, begin_line, 1);
389                                            show_help = 1;
390    
391                                            // Refresh after display help information
392                                            line_current -= (line - 1);
393                                            line = begin_line;
394                                            max_lines = SCREEN_ROWS - 1;
395                                            clrline(begin_line, SCREEN_ROWS);
396                                            break;
397                                    default:
398                                            input_ok = 0;
399                                            break;
400                                    }
401    
402                                    BBS_last_access_tm = time(0);
403                          }                          }
                       break;  
                     default:  
                       input_ok = 0;  
                       break;  
                     }  
                 }  
404    
405                clrline (begin_line, screen_lines);                          continue;
406                line = begin_line;                  }
               moveto (line, 0);  
407    
408                continue;                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
409              }                  if (len >= LINE_BUFFER_LEN)
410                    {
411                            log_error("Error length exceeds buffer size: %d\n", len);
412                            len = LINE_BUFFER_LEN - 1;
413                    }
414    
415            i = strlen (buffer);                  memcpy(buffer, (const char *)p_data + p_line_offsets[line_current], (size_t)len);
416            if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')                  buffer[len] = '\0';
             {  
               buffer[i - 1] = '\r';  
               buffer[i] = '\n';  
               buffer[i + 1] = '\0';  
             }  
           prints (buffer);  
           iflush ();  
417    
418            line++;                  moveto(line, 0);
419                    clrtoeol();
420                    prints("%s", buffer);
421                    line_current++;
422                    line++;
423          }          }
       if (wait)  
         ch = press_any_key ();  
       else  
         ch = 0;  
424    
425      exit:  cleanup:
426        fclose (fin);          if (shmdt(p_file_shm) == -1)
427            {
428        return ch;                  log_error("shmdt() error (%d)\n", errno);
429      }          }
430    
431    return -1;          return ch;
432  }  }
433    
434  int  int show_top(const char *status)
 show_top (char *status)  
435  {  {
436    char buffer[256];          char status_f[21];
437            int truncate;
438            int status_len;
439            int section_name_len;
440            int len;
441    
442    str_space (buffer, 20 - strlen (BBS_current_section_name));          strncpy(status_f, status, sizeof(status_f) - 1);
443            status_f[sizeof(status_f) - 1] = '\0';
444    
445    moveto (1, 0);          len = split_line(status_f, 20, &truncate, &status_len);
446    prints ("\033[1;44;33m%-20s \033[37m%20s"          if (truncate)
447            "         %s\033[33m讨论区 [%s]\033[m",          {
448            status, BBS_name, buffer, BBS_current_section_name);                  log_error("Status string is truncated\n");
449    iflush ();                  status_f[len] = '\0';
450            }
451    
452    return 0;          len = split_line(BBS_current_section_name, 20, &truncate, &section_name_len);
453            if (truncate)
454            {
455                    log_error("Section name is truncated\n");
456            }
457    
458            moveto(1, 0);
459            clrtoeol();
460            prints("\033[1;44;33m%s\033[37m%*s%*s\033[33m 讨论区 [%s]\033[m",
461                       status_f, 32, BBS_name, 26, "", BBS_current_section_name);
462            iflush();
463    
464            return 0;
465  }  }
466    
467  int  int show_bottom(const char *msg)
 show_bottom (char *msg)  
468  {  {
469    char str_time[256], str_time_onine[20], buffer[256];          char str_time[LINE_BUFFER_LEN];
470    time_t time_online;          time_t time_online;
471    struct tm *tm_online;          struct tm *tm_online;
472            char msg_f[21];
473            int truncate;
474            int msg_len;
475            int len;
476            int len_username;
477    
478    get_time_str (str_time, 256);          get_time_str(str_time, sizeof(str_time));
   str_space (buffer, 33 - strlen (BBS_username));  
479    
480    time_online = time (0) - BBS_login_tm;          strncpy(msg_f, msg, sizeof(msg_f) - 1);
481    tm_online = gmtime (&time_online);          msg_f[sizeof(msg_f) - 1] = '\0';
482    
483    moveto (screen_lines, 0);          len = split_line(msg_f, 20, &truncate, &msg_len);
484    prints ("\033[1;44;33m[\033[36m%s\033[33m]"          if (truncate)
485            "%s帐号[\033[36m%s\033[33m]"          {
486            "[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m",                  log_error("Status string is truncated\n");
487            str_time, buffer, BBS_username, tm_online->tm_mday - 1,                  msg_f[len] = '\0';
488            tm_online->tm_hour, tm_online->tm_min);          }
   iflush ();  
489    
490    return 0;          len_username = (int)strnlen(BBS_username, sizeof(BBS_username));
 }  
491    
492  int          time_online = time(0) - BBS_login_tm;
493  show_active_board ()          tm_online = gmtime(&time_online);
494  {  
495    char filename[256], buffer[260];          moveto(SCREEN_ROWS, 0);
496    FILE *fin;          clrtoeol();
497    int i, j;          prints("\033[1;44;33m[\033[36m%s\033[33m]%*s%*s帐号[\033[36m%s\033[33m]"
498    static long int line;                     "[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m",
499                       str_time, 21, msg_f, 13 - len_username, "", BBS_username,
500                       tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);
501            iflush();
502    
503    sprintf (filename, "%sdata/active_board.txt", app_home_dir);          return 0;
504    }
505    
506    clrline (3, 2 + ACTIVE_BOARD_HEIGHT);  int show_active_board()
507    {
508            static int line_current = 0;
509            static const void *p_file_shm = NULL;
510            static const void *p_data;
511            static size_t data_len;
512            static long line_total;
513            static const long *p_line_offsets;
514    
515    moveto (3, 0);          char buffer[LINE_BUFFER_LEN];
516            long int len;
517    
518    if ((fin = fopen (filename, "r")) != NULL)          if (p_file_shm == NULL)
     {  
       for (j = 0; j < line; j++)  
519          {          {
520            if (fgets (buffer, 255, fin) == NULL)                  if ((p_file_shm = get_file_shm(DATA_ACTIVE_BOARD)) == NULL)
521              {                  {
522                line = 0;                          log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD);
523                rewind (fin);                          return KEY_NULL;
524                break;                  }
525              }  
526                    data_len = *((size_t *)p_file_shm);
527                    line_total = *((long *)(p_file_shm + sizeof(size_t)));
528                    p_data = p_file_shm + sizeof(data_len) + sizeof(line_total);
529                    p_line_offsets = p_data + data_len + 1;
530          }          }
531    
532        for (j = 0; j < ACTIVE_BOARD_HEIGHT; j++)          clrline(3, 2 + ACTIVE_BOARD_HEIGHT);
533    
534            for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)
535          {          {
536            if (fgets (buffer, 255, fin) == NULL)                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
537              {                  if (len >= LINE_BUFFER_LEN)
               line = 0;  
               if (j == 0)  
538                  {                  {
539                    rewind (fin);                          log_error("Error length exceeds buffer size: %d\n", len);
540                    if (fgets (buffer, 255, fin) == NULL)                          len = LINE_BUFFER_LEN - 1;
                     {  
                       break;  
                     }  
541                  }                  }
542                else  
543                    memcpy(buffer, (const char *)p_data + p_line_offsets[line_current], (size_t)len);
544                    buffer[len] = '\0';
545    
546                    moveto(3 + i, 0);
547                    prints("%s", buffer);
548    
549                    line_current++;
550                    if (line_current >= line_total)
551                  {                  {
552                    break;                          line_current = 0;
553                            break;
554                  }                  }
             }  
           line++;  
           i = strlen (buffer);  
           if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')  
             {  
               buffer[i - 1] = '\r';  
               buffer[i] = '\n';  
               buffer[i + 1] = '\0';  
             }  
           prints (buffer);  
           iflush ();  
555          }          }
556        fclose (fin);          iflush();
     }  
557    
558    return 0;          return 0;
559  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1