[BACK]Return to mandoc.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/mandoc.c between version 1.65 and 1.75

version 1.65, 2012/05/31 22:38:16 version 1.75, 2013/12/31 23:23:10
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 93  mandoc_escape(const char **end, const char **start, in
Line 93  mandoc_escape(const char **end, const char **start, in
         case ('C'):          case ('C'):
                 if ('\'' != **start)                  if ('\'' != **start)
                         return(ESCAPE_ERROR);                          return(ESCAPE_ERROR);
                 gly = ESCAPE_SPECIAL;  
                 *start = ++*end;                  *start = ++*end;
                   if ('u' == (*start)[0] && '\'' != (*start)[1])
                           gly = ESCAPE_UNICODE;
                   else
                           gly = ESCAPE_SPECIAL;
                 term = '\'';                  term = '\'';
                 break;                  break;
   
         /*          /*
            * Escapes taking no arguments at all.
            */
           case ('d'):
                   /* FALLTHROUGH */
           case ('u'):
                   return(ESCAPE_IGNORE);
   
           /*
          * The \z escape is supposed to output the following           * The \z escape is supposed to output the following
          * character without advancing the cursor position.           * character without advancing the cursor position.
          * Since we are mostly dealing with terminal mode,           * Since we are mostly dealing with terminal mode,
Line 154  mandoc_escape(const char **end, const char **start, in
Line 165  mandoc_escape(const char **end, const char **start, in
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('b'):          case ('b'):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
           case ('B'):
                   /* FALLTHROUGH */
         case ('D'):          case ('D'):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('o'):          case ('o'):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('R'):          case ('R'):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
           case ('w'):
                   /* FALLTHROUGH */
         case ('X'):          case ('X'):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('Z'):          case ('Z'):
Line 174  mandoc_escape(const char **end, const char **start, in
Line 189  mandoc_escape(const char **end, const char **start, in
          * These escapes are of the form \X'N', where 'X' is the trigger           * These escapes are of the form \X'N', where 'X' is the trigger
          * and 'N' resolves to a numerical expression.           * and 'N' resolves to a numerical expression.
          */           */
         case ('B'):  
                 /* FALLTHROUGH */  
         case ('h'):          case ('h'):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('H'):          case ('H'):
Line 183  mandoc_escape(const char **end, const char **start, in
Line 196  mandoc_escape(const char **end, const char **start, in
         case ('L'):          case ('L'):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('l'):          case ('l'):
                 gly = ESCAPE_NUMBERED;  
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('S'):          case ('S'):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('v'):          case ('v'):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('w'):  
                 /* FALLTHROUGH */  
         case ('x'):          case ('x'):
                 if ('\'' != **start)                  if ('\'' != **start)
                         return(ESCAPE_ERROR);                          return(ESCAPE_ERROR);
                 if (ESCAPE_ERROR == gly)                  gly = ESCAPE_IGNORE;
                         gly = ESCAPE_IGNORE;  
                 *start = ++*end;                  *start = ++*end;
                 term = '\'';                  term = '\'';
                 break;                  break;
Line 296  mandoc_escape(const char **end, const char **start, in
Line 305  mandoc_escape(const char **end, const char **start, in
   
         switch (gly) {          switch (gly) {
         case (ESCAPE_FONT):          case (ESCAPE_FONT):
                 /*                  if (2 == *sz) {
                  * Pretend that the constant-width font modes are the                          if ('C' == **start) {
                  * same as the regular font modes.                                  /*
                  */                                   * Treat constant-width font modes
                 if (2 == *sz && 'C' == **start) {                                   * just like regular font modes.
                         (*start)++;                                   */
                         (*sz)--;                                  (*start)++;
                                   (*sz)--;
                           } else {
                                   if ('B' == (*start)[0] && 'I' == (*start)[1])
                                           gly = ESCAPE_FONTBI;
                                   break;
                           }
                 } else if (1 != *sz)                  } else if (1 != *sz)
                         break;                          break;
   
Line 410  mandoc_strdup(const char *ptr)
Line 425  mandoc_strdup(const char *ptr)
  * Parse a quoted or unquoted roff-style request or macro argument.   * Parse a quoted or unquoted roff-style request or macro argument.
  * Return a pointer to the parsed argument, which is either the original   * Return a pointer to the parsed argument, which is either the original
  * pointer or advanced by one byte in case the argument is quoted.   * pointer or advanced by one byte in case the argument is quoted.
  * Null-terminate the argument in place.   * NUL-terminate the argument in place.
  * Collapse pairs of quotes inside quoted arguments.   * Collapse pairs of quotes inside quoted arguments.
  * Advance the argument pointer to the next argument,   * Advance the argument pointer to the next argument,
  * or to the null byte terminating the argument line.   * or to the NUL byte terminating the argument line.
  */   */
 char *  char *
 mandoc_getarg(struct mparse *parse, char **cpp, int ln, int *pos)  mandoc_getarg(struct mparse *parse, char **cpp, int ln, int *pos)
Line 432  mandoc_getarg(struct mparse *parse, char **cpp, int ln
Line 447  mandoc_getarg(struct mparse *parse, char **cpp, int ln
         pairs = 0;          pairs = 0;
         white = 0;          white = 0;
         for (cp = start; '\0' != *cp; cp++) {          for (cp = start; '\0' != *cp; cp++) {
                 /* Move left after quoted quotes and escaped backslashes. */  
                   /*
                    * Move the following text left
                    * after quoted quotes and after "\\" and "\t".
                    */
                 if (pairs)                  if (pairs)
                         cp[-pairs] = cp[0];                          cp[-pairs] = cp[0];
   
                 if ('\\' == cp[0]) {                  if ('\\' == cp[0]) {
                         if ('\\' == cp[1]) {                          /*
                                 /* Poor man's copy mode. */                           * In copy mode, translate double to single
                            * backslashes and backslash-t to literal tabs.
                            */
                           switch (cp[1]) {
                           case ('t'):
                                   cp[0] = '\t';
                                   /* FALLTHROUGH */
                           case ('\\'):
                                 pairs++;                                  pairs++;
                                 cp++;                                  cp++;
                         } else if (0 == quoted && ' ' == cp[1])                                  break;
                           case (' '):
                                 /* Skip escaped blanks. */                                  /* Skip escaped blanks. */
                                 cp++;                                  if (0 == quoted)
                                           cp++;
                                   break;
                           default:
                                   break;
                           }
                 } else if (0 == quoted) {                  } else if (0 == quoted) {
                         if (' ' == cp[0]) {                          if (' ' == cp[0]) {
                                 /* Unescaped blanks end unquoted args. */                                  /* Unescaped blanks end unquoted args. */
Line 466  mandoc_getarg(struct mparse *parse, char **cpp, int ln
Line 499  mandoc_getarg(struct mparse *parse, char **cpp, int ln
         if (1 == quoted)          if (1 == quoted)
                 mandoc_msg(MANDOCERR_BADQUOTE, parse, ln, *pos, NULL);                  mandoc_msg(MANDOCERR_BADQUOTE, parse, ln, *pos, NULL);
   
         /* Null-terminate this argument and move to the next one. */          /* NUL-terminate this argument and move to the next one. */
         if (pairs)          if (pairs)
                 cp[-pairs] = '\0';                  cp[-pairs] = '\0';
         if ('\0' != *cp) {          if ('\0' != *cp) {
Line 561  mandoc_normdate(struct mparse *parse, char *in, int ln
Line 594  mandoc_normdate(struct mparse *parse, char *in, int ln
 }  }
   
 int  int
 mandoc_eos(const char *p, size_t sz, int enclosed)  mandoc_eos(const char *p, size_t sz)
 {  {
         const char *q;          const char      *q;
         int found;          int              enclosed, found;
   
         if (0 == sz)          if (0 == sz)
                 return(0);                  return(0);
Line 575  mandoc_eos(const char *p, size_t sz, int enclosed)
Line 608  mandoc_eos(const char *p, size_t sz, int enclosed)
          * propagate outward.           * propagate outward.
          */           */
   
         found = 0;          enclosed = found = 0;
         for (q = p + (int)sz - 1; q >= p; q--) {          for (q = p + (int)sz - 1; q >= p; q--) {
                 switch (*q) {                  switch (*q) {
                 case ('\"'):                  case ('\"'):
Line 601  mandoc_eos(const char *p, size_t sz, int enclosed)
Line 634  mandoc_eos(const char *p, size_t sz, int enclosed)
         }          }
   
         return(found && !enclosed);          return(found && !enclosed);
 }  
   
 /*  
  * Find out whether a line is a macro line or not.  If it is, adjust the  
  * current position and return one; if it isn't, return zero and don't  
  * change the current position.  
  */  
 int  
 mandoc_getcontrol(const char *cp, int *ppos)  
 {  
         int             pos;  
   
         pos = *ppos;  
   
         if ('\\' == cp[pos] && '.' == cp[pos + 1])  
                 pos += 2;  
         else if ('.' == cp[pos] || '\'' == cp[pos])  
                 pos++;  
         else  
                 return(0);  
   
         while (' ' == cp[pos] || '\t' == cp[pos])  
                 pos++;  
   
         *ppos = pos;  
         return(1);  
 }  }
   
 /*  /*

Legend:
Removed from v.1.65  
changed lines
  Added in v.1.75

CVSweb