Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.7 KiB

  1. // Copyright (c) 1993-1999 Microsoft Corporation
  2. #include "y3.h"
  3. /*
  4. * yapack.3c
  5. *
  6. * Modified to make debug code conditionally compile.
  7. * 28-Aug-81
  8. * Bob Denny
  9. */
  10. int
  11. apack(SSIZE_T *p, int n )
  12. {
  13. /* pack state i from temp1 into amem */
  14. int off;
  15. SSIZE_T *pp, *qq, *rr;
  16. SSIZE_T *q, *r;
  17. /* we don't need to worry about checking because we
  18. we will only look entries known to be there... */
  19. /* eliminate leading and trailing 0's */
  20. q = p+n;
  21. for( pp=p,off=0 ; *pp==0 && pp<=q; ++pp,--off ) /* VOID */ ;
  22. if( pp > q ) return(0); /* no actions */
  23. p = pp;
  24. /* now, find a place for the elements from p to q, inclusive */
  25. r = &amem[ACTSIZE-1];
  26. for( rr=amem; rr<=r; ++rr,++off )
  27. {
  28. /* try rr */
  29. for( qq=rr,pp=p ; pp<=q ; ++pp,++qq)
  30. {
  31. if( *pp != 0 )
  32. {
  33. if( *pp != *qq && *qq != 0 ) goto nextk;
  34. }
  35. }
  36. /* we have found an acceptable k */
  37. #ifdef debug
  38. if(foutput!=NULL) fprintf(foutput,"off = %d, k = %d\n",off,rr-amem);
  39. #endif
  40. for( qq=rr,pp=p; pp<=q; ++pp,++qq )
  41. {
  42. if( *pp )
  43. {
  44. if( qq > r ) error( "action table overflow" );
  45. if( qq>memp ) memp = qq;
  46. *qq = *pp;
  47. }
  48. }
  49. #ifdef debug
  50. if( foutput!=NULL )
  51. {
  52. for( pp=amem; pp<= memp; pp+=10 )
  53. {
  54. fprintf( foutput, "\t");
  55. for( qq=pp; qq<=pp+9; ++qq ) fprintf( foutput, "%d ", *qq );
  56. fprintf( foutput, "\n");
  57. }
  58. }
  59. #endif
  60. return( off );
  61. nextk:
  62. ;
  63. }
  64. error("no space in action table" );
  65. return off; /* NOTREACHED */
  66. }