/[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.6 by sysadm, Sat Oct 23 18:41:41 2004 UTC Revision 1.11 by sysadm, Sun Mar 20 17:37:14 2005 UTC
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18    #include "bbs.h"
19  #include "common.h"  #include "common.h"
20  #include "io.h"  #include "io.h"
21  #include <sys/types.h>  #include <sys/types.h>
22  #include <sys/stat.h>  #include <sys/stat.h>
23  #include <unistd.h>  #include <unistd.h>
24    
25    #define ACTIVE_BOARD_HEIGHT     8
26    
27  int screen_lines = 24;  int screen_lines = 24;
28    
29  void  void
# Line 78  press_any_key () Line 81  press_any_key ()
81    return igetch ();    return igetch ();
82  }  }
83    
84    void
85    set_input_echo (int echo)
86    {
87      char temp[256];
88    
89      if (echo)
90        {
91          outc ('\x83');            // ASCII code 131
92          iflush ();
93        }
94      else
95        {
96    //    outc ('\x85'); // ASCII code 133
97          prints ("\xff\xfb\x01\xff\xfb\x03");
98          iflush ();
99          igetch ();
100          igetch ();
101        }
102    }
103    
104  int  int
105  str_input (char *buffer, int buffer_length, int echo_mode)  str_input (char *buffer, int buffer_length, int echo_mode)
106  {  {
# Line 88  str_input (char *buffer, int buffer_leng Line 111  str_input (char *buffer, int buffer_leng
111    
112    while (c = igetch ())    while (c = igetch ())
113      {      {
114        if (c == CR || c == LF)        if (c == CR)
115          break;          break;
116          if (c == LF)
117            continue;
118        if (c == BACKSPACE)        if (c == BACKSPACE)
119          {          {
120            if (offset > 0)            if (offset > 0)
# Line 144  display_file (const char *filename) Line 169  display_file (const char *filename)
169    FILE *fin;    FILE *fin;
170    int i;    int i;
171    
172    if ((fin = fopen (filename, "r")) != NULL)    if ((fin = fopen (filename, "r")) == NULL)
173    {      {
174      while (fgets (buffer, 255, fin))        return -1;
175        {      }
176          i = strlen (buffer);  
177          if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')    while (fgets (buffer, 255, fin))
178            {      {
179              buffer[i - 1] = '\r';        i = strlen (buffer);
180              buffer[i] = '\n';        if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')
181              buffer[i + 1] = '\0';          {
182            }            buffer[i - 1] = '\r';
183          prints (buffer);            buffer[i] = '\n';
184          iflush ();            buffer[i + 1] = '\0';
185        }          }
186      fclose(fin);        prints (buffer);
187      return 0;        iflush ();
188    }      }
189        fclose (fin);
190    return -1;  
191      return 0;
192  }  }
193    
194  int  int
# Line 170  display_file_ex (const char *filename, i Line 196  display_file_ex (const char *filename, i
196  {  {
197    char buffer[260], temp[256];    char buffer[260], temp[256];
198    int i, ch, input_ok;    int i, ch, input_ok;
199    long int line, c_line_begin = 0, c_line_total=0;    long int line, c_line_begin = 0, c_line_total = 0;
200    long int f_line, f_size, f_offset;    long int f_line, f_size, f_offset;
201    FILE *fin;    FILE *fin;
202    struct stat f_stat;    struct stat f_stat;
# Line 189  display_file_ex (const char *filename, i Line 215  display_file_ex (const char *filename, i
215        f_size = f_stat.st_size;        f_size = f_stat.st_size;
216    
217        while (fgets (buffer, 255, fin))        while (fgets (buffer, 255, fin))
218          c_line_total ++;          c_line_total++;
219        rewind (fin);        rewind (fin);
220    
221        while (fgets (buffer, 255, fin))        while (fgets (buffer, 255, fin))
# Line 201  display_file_ex (const char *filename, i Line 227  display_file_ex (const char *filename, i
227                moveto (screen_lines, 0);                moveto (screen_lines, 0);
228                prints                prints
229                  ("\033[1;44;32m下面还有喔 (%d%%)\033[33m   │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",                  ("\033[1;44;32m下面还有喔 (%d%%)\033[33m   │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",
230                   (f_offset-strlen(buffer)) * 100 / f_size);                   (f_offset - strlen (buffer)) * 100 / f_size);
231                iflush ();                iflush ();
232    
233                input_ok = 0;                input_ok = 0;
# Line 257  display_file_ex (const char *filename, i Line 283  display_file_ex (const char *filename, i
283                      case Ctrl ('F'):                      case Ctrl ('F'):
284                      case KEY_SPACE:                      case KEY_SPACE:
285                        c_line_begin += (screen_lines - begin_line - 1);                        c_line_begin += (screen_lines - begin_line - 1);
286                        if (c_line_begin + (screen_lines - begin_line) > c_line_total)                        if (c_line_begin + (screen_lines - begin_line) >
287                          c_line_begin = c_line_total - (screen_lines - begin_line);                            c_line_total)
288                            c_line_begin =
289                              c_line_total - (screen_lines - begin_line);
290                        rewind (fin);                        rewind (fin);
291                        for (f_line = 0; f_line < c_line_begin; f_line++)                        for (f_line = 0; f_line < c_line_begin; f_line++)
292                          {                          {
# Line 313  display_file_ex (const char *filename, i Line 341  display_file_ex (const char *filename, i
341            line++;            line++;
342          }          }
343        if (wait)        if (wait)
344          ch = press_any_key();          ch = press_any_key ();
345        else        else
346          ch = 0;          ch = 0;
347    
348      exit:      exit:
349        fclose (fin);        fclose (fin);
# Line 327  display_file_ex (const char *filename, i Line 355  display_file_ex (const char *filename, i
355  }  }
356    
357  int  int
358  show_top ()  show_top (char *status)
359    {
360      char buffer[256];
361    
362      str_space (buffer, 20 - strlen (BBS_current_section_name));
363    
364      moveto (1, 0);
365      prints ("\033[1;44;33m%-20s \033[37m%20s"
366              "         %s\033[33m讨论区 [%s]\033[m",
367              status, BBS_name, buffer, BBS_current_section_name);
368      iflush ();
369    
370      return 0;
371    }
372    
373    int
374    show_bottom (char *msg)
375  {  {
376      char str_time[256], str_time_onine[20], buffer[256];
377      time_t time_online;
378      struct tm *tm_online;
379    
380      get_time_str (str_time, 256);
381      str_space (buffer, 33 - strlen (BBS_username));
382    
383      time_online = time (0) - BBS_login_tm;
384      tm_online = gmtime (&time_online);
385    
386      moveto (screen_lines, 0);
387      prints ("\033[1;44;33m[\033[36m%s\033[33m]"
388              "%s帐号[\033[36m%s\033[33m]"
389              "[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m",
390              str_time, buffer, BBS_username, tm_online->tm_mday - 1,
391              tm_online->tm_hour, tm_online->tm_min);
392      iflush ();
393    
394    return 0;    return 0;
395  }  }
396    
397  int  int
398  show_bottom ()  show_active_board ()
399  {  {
400      char filename[256], buffer[260];
401      FILE *fin;
402      int i, j;
403      static long int line;
404    
405      sprintf (filename, "%sdata/active_board.txt", app_home_dir);
406    
407      clrline (3, 2 + ACTIVE_BOARD_HEIGHT);
408    
409      moveto (3, 0);
410    
411      if ((fin = fopen (filename, "r")) != NULL)
412        {
413          for (j = 0; j < line; j++)
414            {
415              if (fgets (buffer, 255, fin) == NULL)
416                {
417                  line = 0;
418                  rewind (fin);
419                  break;
420                }
421            }
422    
423          for (j = 0; j < ACTIVE_BOARD_HEIGHT; j++)
424            {
425              if (fgets (buffer, 255, fin) == NULL)
426                {
427                  line = 0;
428                  if (j == 0)
429                    {
430                      rewind (fin);
431                      if (fgets (buffer, 255, fin) == NULL)
432                        {
433                          break;
434                        }
435                    }
436                  else
437                    {
438                      break;
439                    }
440                }
441              line++;
442              i = strlen (buffer);
443              if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')
444                {
445                  buffer[i - 1] = '\r';
446                  buffer[i] = '\n';
447                  buffer[i + 1] = '\0';
448                }
449              prints (buffer);
450              iflush ();
451            }
452          fclose (fin);
453        }
454    
455    return 0;    return 0;
456  }  }


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

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