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

Diff for /pod2mdoc/pod2mdoc.c between version 1.4 and 1.5

version 1.4, 2014/03/20 15:29:57 version 1.5, 2014/03/23 13:00:24
Line 154  formatescape(const char *buf, size_t *start, size_t en
Line 154  formatescape(const char *buf, size_t *start, size_t en
 /*  /*
  * Skip space characters.   * Skip space characters.
  */   */
 static void  static int
 skipspace(const char *buf, size_t *start, size_t end)  skipspace(const char *buf, size_t *start, size_t end)
 {  {
           size_t           sv = *start;
   
         while (*start < end && ' ' == buf[*start])          while (*start < end && ' ' == buf[*start])
                 (*start)++;                  (*start)++;
   
           return(*start > sv);
 }  }
   
 /*  /*
Line 178  formatcode(const char *buf, size_t *start, 
Line 181  formatcode(const char *buf, size_t *start, 
         size_t end, int reentrant, int last, int nomacro)          size_t end, int reentrant, int last, int nomacro)
 {  {
         enum fmt         fmt;          enum fmt         fmt;
           size_t           i, j, dsz;
   
         assert(*start + 1 < end);          assert(*start + 1 < end);
         assert('<' == buf[*start + 1]);          assert('<' == buf[*start + 1]);
   
           /*
            * Determine whether we're overriding our delimiter.
            * According to POD, if we have more than one '<' followed by a
            * space, then we need a space followed by matching '>' to close
            * the expression.
            * Otherwise we use the usual '<' and '>' matched pair.
            */
           i = *start + 1;
           while (i < end && '<' == buf[i])
                   i++;
           assert(i > *start + 1);
           dsz = i - (*start + 1);
           if (dsz > 1 && (i >= end || ' ' != buf[i]))
                   dsz = 1;
   
         for (fmt = 0; fmt < FMT__MAX; fmt++)          for (fmt = 0; fmt < FMT__MAX; fmt++)
                 if (buf[*start] == fmts[fmt])                  if (buf[*start] == fmts[fmt])
                         break;                          break;
Line 194  formatcode(const char *buf, size_t *start, 
Line 213  formatcode(const char *buf, size_t *start, 
                 return(0);                  return(0);
         }          }
   
         *start += 2;          /* Remember, if dsz>1, to jump the trailing space. */
           *start += dsz + 1 + (dsz > 1 ? 1 : 0);
   
         /*          /*
          * Escapes don't print macro sequences, so just output them like           * Escapes don't print macro sequences, so just output them like
Line 204  formatcode(const char *buf, size_t *start, 
Line 224  formatcode(const char *buf, size_t *start, 
                 formatescape(buf, start, end);                  formatescape(buf, start, end);
                 return(0);                  return(0);
         } else if (FMT_NULL == fmt || FMT_INDEX == fmt) {          } else if (FMT_NULL == fmt || FMT_INDEX == fmt) {
                 /* For indices and nulls, just consume. */                  /*
                 while (*start < end && '>' != buf[*start])                   * For indices and nulls, just consume.
                         (*start)++;                   * Be wary of encountering custom delimiters (dsz>1),
                 if (*start < end)                   * which require special handling.
                         (*start)++;                   */
                   for ( ; *start < end; (*start)++) {
                           if ('>' != buf[*start])
                                   continue;
                           else if (dsz == 1)
                                   break;
                           assert(*start > 0);
                           if (' ' != buf[*start - 1])
                                   continue;
                           i = *start;
                           for (j = 0; i < end && j < dsz; j++)
                                   if ('>' != buf[i++])
                                           break;
                           if (dsz != j)
                                   continue;
                           (*start) += dsz;
                           break;
                   }
                 return(0);                  return(0);
         }          }
   
Line 259  formatcode(const char *buf, size_t *start, 
Line 296  formatcode(const char *buf, size_t *start, 
         }          }
   
         /*          /*
          * Read until we reach the end market ('>') or until we find a           * Read until we reach the end market (e.g., '>') or until we
          * nested format code.           * find a nested format code.
          * Don't emit any newlines: since we're on a macro line, we           * Don't emit any newlines: since we're on a macro line, we
          * don't want to break the line.           * don't want to break the line.
          */           */
         while (*start < end) {          while (*start < end) {
                 if ('>' == buf[*start]) {                  if ('>' == buf[*start] && 1 == dsz) {
                         (*start)++;                          (*start)++;
                         break;                          break;
                   } else if ('>' == buf[*start] &&
                                   ' ' == buf[*start - 1]) {
                           /*
                            * Handle custom delimiters.
                            * These require a certain number of
                            * space-preceded carrots before we're really at
                            * the end.
                            */
                           i = *start;
                           for (j = 0; i < end && j < dsz; j++)
                                   if ('>' != buf[i++])
                                           break;
                           if (dsz == j) {
                                   *start += dsz;
                                   break;
                           }
                 }                  }
                 if (*start + 1 < end && '<' == buf[*start + 1]) {                  if (*start + 1 < end && '<' == buf[*start + 1]) {
                         formatcode(buf, start, end, 1, last, nomacro);                          formatcode(buf, start, end, 1, last, nomacro);
Line 302  formatcode(const char *buf, size_t *start, 
Line 355  formatcode(const char *buf, size_t *start, 
         if (reentrant)          if (reentrant)
                 return(1);                  return(1);
   
           /* FIXME: with the "Qc", this doens't work good. */
   
         /*          /*
          * If we're not reentrant, we want to put ending punctuation on           * If we're not reentrant, we want to put ending punctuation on
          * the macro line so that it's properly handled by being           * the macro line so that it's properly handled by being
          * smooshed against the terminal word.           * smooshed against the terminal word.
          */           */
         skipspace(buf, start, end);          skipspace(buf, start, end);
   
         if (',' != buf[*start] && '.' != buf[*start] &&          if (',' != buf[*start] && '.' != buf[*start] &&
                 '!' != buf[*start] && '?' != buf[*start] &&                  '!' != buf[*start] && '?' != buf[*start] &&
                 ')' != buf[*start])                  ')' != buf[*start])
Line 601  ordinary(struct state *st, const char *buf, size_t sta
Line 657  ordinary(struct state *st, const char *buf, size_t sta
                         for ( ; i > start; i--)                          for ( ; i > start; i--)
                                 if ('-' != buf[i])                                  if ('-' != buf[i])
                                         break;                                          break;
                         /* FIXME: escape macro-like words etc. */                          printf(".Nm ");
                         printf(".Nm %.*s\n",                          formatcodeln(buf, &start, i + 1, 1);
                                 (int)((i + 1) - start), &buf[start]);                          putchar('\n');
                         printf(".Nd %.*s\n",                          start = j + 1;
                                 (int)(end - (j + 1)), &buf[j + 1]);                          printf(".Nd ");
                           formatcodeln(buf, &start, end, 1);
                           putchar('\n');
                         return;                          return;
                 }                  }
         }          }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

CVSweb