[BACK]Return to optfunc.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

Diff for /src/usr.bin/less/optfunc.c between version 1.6 and 1.7

version 1.6, 2010/07/03 16:29:46 version 1.7, 2011/09/16 18:12:09
Line 1 
Line 1 
 /*  /*
  * Copyright (C) 1984-2002  Mark Nudelman   * Copyright (C) 1984-2011  Mark Nudelman
  *   *
  * You may distribute under the terms of either the GNU General Public   * You may distribute under the terms of either the GNU General Public
  * License or the Less License, as specified in the README file.   * License or the Less License, as specified in the README file.
Line 28 
Line 28 
 #include "less.h"  #include "less.h"
 #include "option.h"  #include "option.h"
   
 #ifndef SMALL_PROGRAM  
 extern int nbufs;  extern int nbufs;
 #endif  
 extern int bufspace;  extern int bufspace;
 extern int pr_type;  extern int pr_type;
 extern int nohelp;  
 extern int plusoption;  extern int plusoption;
 extern int swindow;  extern int swindow;
   extern int sc_width;
 extern int sc_height;  extern int sc_height;
 extern int secure;  extern int secure;
   extern int dohelp;
 extern int any_display;  extern int any_display;
 extern char openquote;  extern char openquote;
 extern char closequote;  extern char closequote;
Line 47 
Line 46 
 extern char *wproto;  extern char *wproto;
 extern IFILE curr_ifile;  extern IFILE curr_ifile;
 extern char version[];  extern char version[];
   extern int jump_sline;
   extern int jump_sline_fraction;
   extern int shift_count;
   extern int shift_count_fraction;
   extern int less_is_more;
 #if LOGFILE  #if LOGFILE
 extern char *namelogfile;  extern char *namelogfile;
 extern int force_logfile;  extern int force_logfile;
Line 55 
Line 59 
 #if TAGS  #if TAGS
 public char *tagoption = NULL;  public char *tagoption = NULL;
 extern char *tags;  extern char *tags;
 extern int jump_sline;  
 #endif  #endif
 #if MSDOS_COMPILER  #if MSDOS_COMPILER
 extern int nm_fg_color, nm_bg_color;  extern int nm_fg_color, nm_bg_color;
Line 129 
Line 132 
 #endif  #endif
   
 /*  /*
  * Handlers for -l option.   * Handlers for -j option.
  */   */
         public void          public void
 opt_l(type, s)  opt_j(type, s)
         int type;          int type;
         char *s;          char *s;
 {  {
           PARG parg;
           char buf[16];
           int len;
         int err;          int err;
         int n;  
         char *t;  
   
         switch (type)          switch (type)
         {          {
         case INIT:          case INIT:
                 t = s;          case TOGGLE:
                 n = getnum(&t, "l", &err);                  if (*s == '.')
                 if (err || n <= 0)  
                 {                  {
                         error("Line number is required after -l", NULL_PARG);                          s++;
                         return;                          jump_sline_fraction = getfraction(&s, "j", &err);
                           if (err)
                                   error("Invalid line fraction", NULL_PARG);
                           else
                                   calc_jump_sline();
                   } else
                   {
                           int sline = getnum(&s, "j", &err);
                           if (err)
                                   error("Invalid line number", NULL_PARG);
                           else
                           {
                                   jump_sline = sline;
                                   jump_sline_fraction = -1;
                           }
                 }                  }
                 plusoption = TRUE;  
                 ungetsc(s);  
                 break;                  break;
           case QUERY:
                   if (jump_sline_fraction < 0)
                   {
                           parg.p_int =  jump_sline;
                           error("Position target at screen line %d", &parg);
                   } else
                   {
   
                           snprintf(buf, sizeof(buf), ".%06d", jump_sline_fraction);
                           len = strlen(buf);
                           while (len > 2 && buf[len-1] == '0')
                                   len--;
                           buf[len] = '\0';
                           parg.p_string = buf;
                           error("Position target at screen position %s", &parg);
                   }
                   break;
         }          }
 }  }
   
           public void
   calc_jump_sline()
   {
           if (jump_sline_fraction < 0)
                   return;
           jump_sline = sc_height * jump_sline_fraction / NUM_FRAC_DENOM;
   }
   
   /*
    * Handlers for -# option.
    */
           public void
   opt_shift(type, s)
           int type;
           char *s;
   {
           PARG parg;
           char buf[16];
           int len;
           int err;
   
           switch (type)
           {
           case INIT:
           case TOGGLE:
                   if (*s == '.')
                   {
                           s++;
                           shift_count_fraction = getfraction(&s, "#", &err);
                           if (err)
                                   error("Invalid column fraction", NULL_PARG);
                           else
                                   calc_shift_count();
                   } else
                   {
                           int hs = getnum(&s, "#", &err);
                           if (err)
                                   error("Invalid column number", NULL_PARG);
                           else
                           {
                                   shift_count = hs;
                                   shift_count_fraction = -1;
                           }
                   }
                   break;
           case QUERY:
                   if (shift_count_fraction < 0)
                   {
                           parg.p_int = shift_count;
                           error("Horizontal shift %d columns", &parg);
                   } else
                   {
   
                           snprintf(buf, sizeof(buf), ".%06d", shift_count_fraction);
                           len = strlen(buf);
                           while (len > 2 && buf[len-1] == '0')
                                   len--;
                           buf[len] = '\0';
                           parg.p_string = buf;
                           error("Horizontal shift %s of screen width", &parg);
                   }
                   break;
           }
   }
           public void
   calc_shift_count()
   {
           if (shift_count_fraction < 0)
                   return;
           shift_count = sc_width * shift_count_fraction / NUM_FRAC_DENOM;
   }
   
 #if USERFILE  #if USERFILE
         public void          public void
 opt_k(type, s)  opt_k(type, s)
Line 203 
Line 307 
                 }                  }
                 findtag(skipsp(s));                  findtag(skipsp(s));
                 save_ifile = save_curr_ifile();                  save_ifile = save_curr_ifile();
                 if (edit_tagfile())                  /*
                         break;                   * Try to open the file containing the tag
                 if ((pos = tagsearch()) == NULL_POSITION)                   * and search for the tag in that file.
                    */
                   if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION)
                 {                  {
                           /* Failed: reopen the old file. */
                         reedit_ifile(save_ifile);                          reedit_ifile(save_ifile);
                         break;                          break;
                 }                  }
Line 261 
Line 368 
                  */                   */
                 plusoption = TRUE;                  plusoption = TRUE;
                 ungetsc(s);                  ungetsc(s);
                 ungetsc("/");                  /*
                    * In "more" mode, the -p argument is a command,
                    * not a search string, so we don't need a slash.
                    */
                   if (!less_is_more)
                           ungetsc("/");
                 break;                  break;
         }          }
 }  }
Line 369 
Line 481 
                 any_display = 1;                  any_display = 1;
                 putstr("less ");                  putstr("less ");
                 putstr(version);                  putstr(version);
                 putstr("\nCopyright (C) 2002 Mark Nudelman\n\n");                  putstr("\nCopyright (C) 1984-2009 Mark Nudelman\n\n");
                 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");                  putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
                 putstr("For information about the terms of redistribution,\n");                  putstr("For information about the terms of redistribution,\n");
                 putstr("see the file named README in the less distribution.\n");                  putstr("see the file named README in the less distribution.\n");
Line 399 
Line 511 
                 return;                  return;
         }          }
         if (*s != '.')          if (*s != '.')
                 bg = 0;                  bg = nm_bg_color;
         else          else
         {          {
                 s++;                  s++;
                 bg = getnum(&s, "D", &err);                  bg = getnum(&s, "D", &err);
                 if (err)                  if (err)
                 {                  {
                         error("Missing fg color in -D", NULL_PARG);                          error("Missing bg color in -D", NULL_PARG);
                         return;                          return;
                 }                  }
         }          }
Line 452 
Line 564 
                 }                  }
                 if (type == TOGGLE)                  if (type == TOGGLE)
                 {                  {
                         so_enter();                          at_enter(AT_STANDOUT);
                         so_exit();                          at_exit();
                 }                  }
                 break;                  break;
         case QUERY:          case QUERY:
Line 514 
Line 626 
                             " and then ");                              " and then ");
                 }                  }
                 snprintf(msg+strlen(msg), sizeof(msg)-strlen(msg),                  snprintf(msg+strlen(msg), sizeof(msg)-strlen(msg),
                     "every %d spaces",                      "every %d spaces", tabdefault);
                         tabdefault);  
                 p.p_string = msg;                  p.p_string = msg;
                 error("%s", &p);                  error("%s", &p);
                 break;                  break;
Line 574 
Line 685 
         int type;          int type;
         char *s;          char *s;
 {  {
         if (nohelp)  
                 return;  
         switch (type)          switch (type)
         {          {
         case QUERY:          case QUERY:
Line 583 
Line 692 
                 error("Use \"h\" for help", NULL_PARG);                  error("Use \"h\" for help", NULL_PARG);
                 break;                  break;
         case INIT:          case INIT:
                 /*                  dohelp = 1;
                  * This is "less -?".  
                  * It rather ungracefully grabs control,  
                  * does the initializations normally done in main,  
                  * shows the help file and exits.  
                  */  
                 raw_mode(1);  
                 get_term();  
                 open_getchr();  
                 init();  
                 any_display = TRUE;  
                 help(1);  
                 quit(QUIT_OK);  
                 /*NOTREACHED*/  
         }          }
 }  }
   

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7