home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / z32.c < prev    next >
Text File  |  1994-01-23  |  5KB  |  138 lines

  1. /*@z32.c:Counter Service:Next()@**********************************************/
  2. /*                                                                           */
  3. /*  LOUT: A HIGH-LEVEL LANGUAGE FOR DOCUMENT FORMATTING (VERSION 2.05)       */
  4. /*  COPYRIGHT (C) 1993 Jeffrey H. Kingston                                   */
  5. /*                                                                           */
  6. /*  Jeffrey H. Kingston (jeff@cs.su.oz.au)                                   */
  7. /*  Basser Department of Computer Science                                    */
  8. /*  The University of Sydney 2006                                            */
  9. /*  AUSTRALIA                                                                */
  10. /*                                                                           */
  11. /*  This program is free software; you can redistribute it and/or modify     */
  12. /*  it under the terms of the GNU General Public License as published by     */
  13. /*  the Free Software Foundation; either version 1, or (at your option)      */
  14. /*  any later version.                                                       */
  15. /*                                                                           */
  16. /*  This program is distributed in the hope that it will be useful,          */
  17. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of           */
  18. /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
  19. /*  GNU General Public License for more details.                             */
  20. /*                                                                           */
  21. /*  You should have received a copy of the GNU General Public License        */
  22. /*  along with this program; if not, write to the Free Software              */
  23. /*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
  24. /*                                                                           */
  25. /*  FILE:         z32.c                                                      */
  26. /*  MODULE:       Counter Service                                            */
  27. /*  EXTERNS:      Next()                                                     */
  28. /*                                                                           */
  29. /*****************************************************************************/
  30. #include "externs"
  31.  
  32. /*****************************************************************************/
  33. /*                                                                           */
  34. /*  OBJECT Next(x, inc, done)                                                */
  35. /*                                                                           */
  36. /*  Return x with its value incremented by inc (if possible).                */
  37. /*  Set *done to TRUE if successful, leave *done unchanged otherwise.        */
  38. /*                                                                           */
  39. /*****************************************************************************/
  40.  
  41. OBJECT Next(x, inc, done)
  42. OBJECT x; int inc; BOOLEAN *done;
  43. { OBJECT y, link;  int l, r, n, len;
  44.   FULL_CHAR buff[MAX_LINE + 1];
  45.   debug3(DCS, DD, "Next( %s, %d, %s )", EchoObject(x), inc, bool(*done));
  46.   switch( type(x) )
  47.   {
  48.     case WORD:
  49.     case QWORD:
  50.     
  51.       len = StringLength(string(x));
  52.       for( r = len - 1;  r >= 0 && !decimaldigit(string(x)[r]);  r--);
  53.       if( r < 0 ) break;
  54.       for( l = r-1;  l >= 0 && decimaldigit(string(x)[l]);  l-- );
  55.       sscanf( (char *) &string(x)[l+1], "%d", &n);
  56.       string(x)[l+1] = '\0';
  57.       StringCopy(buff, string(x));
  58.       StringCat(buff, StringInt(n+inc));
  59.       StringCat(buff, &string(x)[r+1]);
  60.       if( StringLength(buff) >= MAX_LINE )
  61.     Error(FATAL, &fpos(x), "word %s is too long", buff);
  62.       y = MakeWord(type(x), buff, &fpos(x));
  63.       word_font(y) = word_font(x);
  64.       MergeNode(y, x);  x = y;
  65.       *done = TRUE;
  66.       break;
  67.  
  68.  
  69.     case INCGRAPHIC:
  70.     case SINCGRAPHIC:
  71.     case GAP_OBJ:
  72.     case CLOSURE:
  73.     case NULL_CLOS:
  74.     case CROSS:
  75.     
  76.       break;
  77.  
  78.  
  79.     case ONE_COL:
  80.     case ONE_ROW:
  81.     case WIDE:
  82.     case HIGH:
  83.     case HCONTRACT:
  84.     case VCONTRACT:
  85.     case HEXPAND:
  86.     case VEXPAND:
  87.     case PADJUST:
  88.     case HADJUST:
  89.     case VADJUST:
  90.     case HSCALE:
  91.     case VSCALE:
  92.     case ROTATE:
  93.     case SCALE:
  94.     case SPLIT:
  95.     case GRAPHIC:
  96.     
  97.       Child(y, LastDown(x));
  98.       y = Next(y, inc, done);
  99.       break;
  100.  
  101.  
  102.     case ACAT:
  103.     
  104.       link = LastDown(x);
  105.       while( link != x && !*done )
  106.       {    Child(y, link);
  107.     if( is_index(type(y)) )  continue;
  108.     y = Next(y, inc, done);
  109.     if( !*done )  link = PrevDown(link);
  110.       }
  111.       break;
  112.  
  113.  
  114.     case COL_THR:
  115.     case ROW_THR:
  116.     case HCAT:
  117.     case VCAT:
  118.     
  119.       link = LastDown(x);
  120.       while( link != x && !*done )
  121.       {    Child(y, link);
  122.     if( is_index(type(y)) )  continue;
  123.     y = Next(y, inc, done);
  124.     if( !*done )  link = PrevDown(link);
  125.       }
  126.       break;
  127.  
  128.  
  129.     default:
  130.     
  131.       Error(INTERN,&fpos(x), "Next: type(x) = %s", Image(type(x)));
  132.       break;
  133.  
  134.   } /* end switch */
  135.   debug1(DCS, DD, "Next returning %s", EchoObject(x));
  136.   return x;
  137. } /* end Next */
  138.