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

Diff for /mandoc/roff_escape.c between version 1.6 and 1.7

version 1.6, 2022/06/01 23:20:26 version 1.7, 2022/06/02 11:29:07
Line 41  mandoc_escape(const char **rendarg, const char **rarg,
Line 41  mandoc_escape(const char **rendarg, const char **rarg,
         int              iarg, iendarg, iend;          int              iarg, iendarg, iend;
         enum mandoc_esc  rval;          enum mandoc_esc  rval;
   
         rval = roff_escape(--*rendarg, 0, 0, NULL, &iarg, &iendarg, &iend);          rval = roff_escape(--*rendarg, 0, 0,
               NULL, NULL, &iarg, &iendarg, &iend);
         assert(rval != ESCAPE_EXPAND);          assert(rval != ESCAPE_EXPAND);
         if (rarg != NULL)          if (rarg != NULL)
                *rarg = *rendarg + iarg;                 *rarg = *rendarg + iarg;
Line 63  mandoc_escape(const char **rendarg, const char **rarg,
Line 64  mandoc_escape(const char **rendarg, const char **rarg,
  */   */
 enum mandoc_esc  enum mandoc_esc
 roff_escape(const char *buf, const int ln, const int aesc,  roff_escape(const char *buf, const int ln, const int aesc,
     int *resc, int *rarg, int *rendarg, int *rend)      int *resc, int *rnam, int *rarg, int *rendarg, int *rend)
 {  {
         int              iesc;          /* index of leading escape char */          int              iesc;          /* index of leading escape char */
           int              inam;          /* index of escape name */
         int              iarg;          /* index beginning the argument */          int              iarg;          /* index beginning the argument */
         int              iendarg;       /* index right after the argument */          int              iendarg;       /* index right after the argument */
         int              iend;          /* index right after the sequence */          int              iend;          /* index right after the sequence */
         int              sesc, sarg, sendarg, send; /* for sub-escape */          int              sesc, snam, sarg, sendarg, send; /* for sub-escape */
         int              maxl;          /* expected length of the argument */          int              maxl;          /* expected length of the argument */
         int              argl;          /* actual length of the argument */          int              argl;          /* actual length of the argument */
         int              c, i;          /* for \[char...] parsing */          int              c, i;          /* for \[char...] parsing */
         int              valid_A;       /* for \A parsing */          int              valid_A;       /* for \A parsing */
         enum mandoc_esc  rval;          /* return value */          enum mandoc_esc  rval;          /* return value */
         enum mandocerr   err;           /* diagnostic code */          enum mandocerr   err;           /* diagnostic code */
         char             esc_name;  
         char             term;          /* byte terminating the argument */          char             term;          /* byte terminating the argument */
   
         /*          /*
Line 84  roff_escape(const char *buf, const int ln, const int a
Line 85  roff_escape(const char *buf, const int ln, const int a
          * it only makes a difference in copy mode.           * it only makes a difference in copy mode.
          */           */
   
         iesc = iarg = aesc;          iesc = inam = aesc;
         do {          do {
                 iarg++;                  inam++;
         } while (buf[iarg] == 'E');          } while (buf[inam] == 'E');
   
         /*          /*
          * Sort the following cases first by syntax category,           * Sort the following cases first by syntax category,
          * then by escape sequence type, and finally by ASCII code.           * then by escape sequence type, and finally by ASCII code.
          */           */
   
         esc_name = buf[iarg];          iarg = iendarg = iend = inam + 1;
         iendarg = iend = ++iarg;  
         maxl = INT_MAX;          maxl = INT_MAX;
         term = '\0';          term = '\0';
         switch (esc_name) {          switch (buf[inam]) {
   
         /* Escape sequences taking no arguments at all. */          /* Escape sequences taking no arguments at all. */
   
Line 269  roff_escape(const char *buf, const int ln, const int a
Line 269  roff_escape(const char *buf, const int ln, const int a
   
         if ((term == '\b' || (term == '\0' && maxl == INT_MAX)) &&          if ((term == '\b' || (term == '\0' && maxl == INT_MAX)) &&
             buf[iarg] == buf[iesc] && roff_escape(buf, ln, iendarg,              buf[iarg] == buf[iesc] && roff_escape(buf, ln, iendarg,
             &sesc, &sarg, &sendarg, &send) == ESCAPE_EXPAND)              &sesc, &snam, &sarg, &sendarg, &send) == ESCAPE_EXPAND)
                 goto out_sub;                  goto out_sub;
   
         if (term == '\b') {          if (term == '\b') {
                 if ((esc_name == 'N' && isdigit((unsigned char)buf[iarg])) ||                  if ((buf[inam] == 'N' && isdigit((unsigned char)buf[iarg])) ||
                     (esc_name == 'h' && strchr(" %&()*+-./0123456789:<=>",                      (buf[inam] == 'h' && strchr(" %&()*+-./0123456789:<=>",
                      buf[iarg]) != NULL)) {                       buf[iarg]) != NULL)) {
                         iendarg = iend = iarg + 1;                          iendarg = iend = iarg + 1;
                         rval = ESCAPE_ERROR;                          rval = ESCAPE_ERROR;
Line 282  roff_escape(const char *buf, const int ln, const int a
Line 282  roff_escape(const char *buf, const int ln, const int a
                 }                  }
                 term = buf[iarg++];                  term = buf[iarg++];
         } else if (term == '\0' && maxl == INT_MAX) {          } else if (term == '\0' && maxl == INT_MAX) {
                 if (esc_name == 'n' && (buf[iarg] == '+' || buf[iarg] == '-'))                  if (buf[inam] == 'n' && (buf[iarg] == '+' || buf[iarg] == '-'))
                         iarg++;                          iarg++;
                 switch (buf[iarg]) {                  switch (buf[iarg]) {
                 case '(':                  case '(':
Line 310  roff_escape(const char *buf, const int ln, const int a
Line 310  roff_escape(const char *buf, const int ln, const int a
         while (maxl > 0) {          while (maxl > 0) {
                 if (buf[iendarg] == '\0') {                  if (buf[iendarg] == '\0') {
                         /* Ignore an incomplete argument except for \w. */                          /* Ignore an incomplete argument except for \w. */
                         if (esc_name != 'w')                          if (buf[inam] != 'w')
                                 iendarg = iarg;                                  iendarg = iarg;
                         break;                          break;
                 }                  }
Line 318  roff_escape(const char *buf, const int ln, const int a
Line 318  roff_escape(const char *buf, const int ln, const int a
                         iend = iendarg + 1;                          iend = iendarg + 1;
                         break;                          break;
                 }                  }
                 if (esc_name == 'N' &&                  if (buf[inam] == 'N' &&
                     isdigit((unsigned char)buf[iendarg]) == 0) {                      isdigit((unsigned char)buf[iendarg]) == 0) {
                         iend = iendarg + 1;                          iend = iendarg + 1;
                         break;                          break;
                 }                  }
                 if (buf[iendarg] == buf[iesc]) {                  if (buf[iendarg] == buf[iesc]) {
                         switch (roff_escape(buf, ln, iendarg,                          switch (roff_escape(buf, ln, iendarg,
                             &sesc, &sarg, &sendarg, &send)) {                              &sesc, &snam, &sarg, &sendarg, &send)) {
                         case ESCAPE_EXPAND:                          case ESCAPE_EXPAND:
                                 goto out_sub;                                  goto out_sub;
                         case ESCAPE_UNDEF:                          case ESCAPE_UNDEF:
Line 350  roff_escape(const char *buf, const int ln, const int a
Line 350  roff_escape(const char *buf, const int ln, const int a
         /* Post-process depending on the content of the argument. */          /* Post-process depending on the content of the argument. */
   
         argl = iendarg - iarg;          argl = iendarg - iarg;
         switch (esc_name) {          switch (buf[inam]) {
         case '*':          case '*':
                 if (resc == NULL && argl == 2 &&                  if (resc == NULL && argl == 2 &&
                     buf[iarg] == '.' && buf[iarg + 1] == 'T')                      buf[iarg] == '.' && buf[iarg + 1] == 'T')
Line 449  roff_escape(const char *buf, const int ln, const int a
Line 449  roff_escape(const char *buf, const int ln, const int a
   
 out_sub:  out_sub:
         iesc = sesc;          iesc = sesc;
           inam = snam;
         iarg = sarg;          iarg = sarg;
         iendarg = sendarg;          iendarg = sendarg;
         iend = send;          iend = send;
         rval = ESCAPE_EXPAND;          rval = ESCAPE_EXPAND;
   
 out:  out:
           if (rnam != NULL)
                   *rnam = inam;
         if (rarg != NULL)          if (rarg != NULL)
                 *rarg = iarg;                  *rarg = iarg;
         if (rendarg != NULL)          if (rendarg != NULL)
Line 478  out:
Line 481  out:
                 err = MANDOCERR_ESC_UNSUPP;                  err = MANDOCERR_ESC_UNSUPP;
                 break;                  break;
         case ESCAPE_UNDEF:          case ESCAPE_UNDEF:
                 if (esc_name == '\\')                  if (buf[inam] == '\\')
                         return rval;                          return rval;
                 err = MANDOCERR_ESC_UNDEF;                  err = MANDOCERR_ESC_UNDEF;
                 break;                  break;

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

CVSweb