Annotation of researchv9/jerq/sgs/libsdp/allot.c, revision 1.1

1.1     ! root        1: static char ID[] = "@(#) allot.c: 1.1 3/16/82";
        !             2: #include <stdio.h>
        !             3: #include "sdp.h"
        !             4: #include "define3.h"
        !             5: 
        !             6: #ifdef SHORT
        !             7: #define AL01   "AL01 "
        !             8: #define AL02   "AL02 "
        !             9: #define AL03   "AL03 "
        !            10: #define AL04   "AL04 "
        !            11: #define AL05   "AL05 "
        !            12: #define AL06   "AL06 "
        !            13: #define ALAU   "ALAU "
        !            14: #else
        !            15: #define AL01   "AL01 -- space not connected\n%o\n",sp
        !            16: #define AL02   "AL02 -- no permissions to allot\n"
        !            17: #define AL03   "AL03 -- fail to pop stack\n%o\n",sp
        !            18: #define AL04   "AL04 -- address space overflow\n%o\n",sp
        !            19: #define AL05   "AL05 -- fail to redeem fragment from multipage item\n%o\n",sp
        !            20: #define AL06   "AL06 -- fail to redeem fragment from old current page\n%o\n",sp
        !            21: #define ALAU   "%s","ALAU -- audit failed in sdp_allot\n"
        !            22: #endif
        !            23: 
        !            24: #ifdef SWEET
        !            25: #define PROLOG
        !            26: #define EPILOG
        !            27: #else
        !            28: #define PROLOG         if( (aud_flag == AUDITON) && (aud_check() == ERROR) )\
        !            29:                                ERR_RET(ALAU,IDERROR)\
        !            30:                        if(hist_fp != NULL)\
        !            31:                                fprintf(hist_fp,"AL\t%o\t%u\t",sp,howmuch) ;
        !            32: #define EPILOG         if(aud_flag == AUDITON)\
        !            33:                                aud_set() ;\
        !            34:                        if(hist_fp != NULL)\
        !            35:                                fprintf(hist_fp,"%ld\n",id) ;
        !            36: #endif
        !            37: 
        !            38: extern int aud_flag ;
        !            39: extern struct LIBFILE *Glib_file ;
        !            40: extern FILE *hist_fp ;
        !            41: extern struct LIBFILE lib_file ;
        !            42: 
        !            43: extern aud_set() ;
        !            44: extern int aud_check() ;
        !            45: extern FATAL() ;
        !            46: extern ITEMID pop_id() ;
        !            47: extern push_id() ;
        !            48: extern spsearch() ;
        !            49: 
        !            50: ITEMID                         /* itemid, IDNULL, IDERROR */
        !            51: sdp_allot(sp,howmuch)
        !            52: register struct SPACE  *sp ;
        !            53: register unsigned      howmuch ;
        !            54: {
        !            55:        register unsigned       page_size ;
        !            56:        register ITEMID         id ;
        !            57:        ITEMID                  increase ;
        !            58:        ITEMID                  redeem_id ;
        !            59:        int                     rationalize() ;
        !            60: 
        !            61:        PROLOG
        !            62:        if(spsearch(sp) == NOTFOUND)
        !            63:                ERR_RET(AL01,IDERROR)
        !            64: 
        !            65:        Glib_file = sp->lib_file ;
        !            66: 
        !            67:        if(sp->perms != WRTN)
        !            68:                ERR_RET(AL02,IDERROR)
        !            69: 
        !            70:        howmuch = (unsigned)ALIGNID((ITEMID)howmuch) ;
        !            71: 
        !            72:        page_size = sp->page_size ;
        !            73: 
        !            74:        id = IDNULL ;
        !            75:        if ( howmuch > 0 )
        !            76:                id = pop_id(sp,howmuch) ;                       /* fetch from stack */
        !            77:        switch( rationalize(id) )       /* cannot switch on long:  see NOTES */
        !            78:        {
        !            79:                case ERROR:
        !            80:                        ERR_RET(AL03,IDERROR)
        !            81:                        break ;
        !            82: 
        !            83:                case NOTFOUND:
        !            84: 
        !            85:                        if(howmuch == 0)
        !            86:                                id = IDNULL ;
        !            87:                        else if(howmuch >= page_size)           /* more than a page */
        !            88:                        {
        !            89:                                id = sp->maxpage ;
        !            90:                                increase = ((long)howmuch+page_size-1)/page_size * page_size ;
        !            91:                                sp->maxpage += increase ;
        !            92:                                if(sp->maxpage <= id)
        !            93:                                        ERR_RET(AL04,IDERROR)
        !            94:                                if(push_id(sp,id+howmuch,increase-howmuch) == ERROR)
        !            95:                                        ERR_RET(AL05,IDERROR)
        !            96:                        }
        !            97:                        else
        !            98:                                if(howmuch <= sp->curleft)      /* fits in current page */
        !            99:                                {
        !           100:                                        id = (sp->curpage) + (page_size - sp->curleft) ;
        !           101:                                        sp->curleft -= howmuch ;
        !           102:                                }
        !           103:                                else                            /* need new current page */
        !           104:                                {
        !           105:                                        redeem_id = (sp->curpage) + (page_size - sp->curleft) ;
        !           106:                                        if(push_id(sp,redeem_id,sp->curleft) == ERROR)
        !           107:                                                ERR_RET(AL06,IDERROR)
        !           108:                                        id = sp->curpage = sp->maxpage ;
        !           109:                                        sp->maxpage += page_size ;
        !           110:                                        sp->curleft = page_size - howmuch ;
        !           111:                                }
        !           112:                        break ;
        !           113: 
        !           114:                default:
        !           115:                        break ;
        !           116:        }
        !           117: 
        !           118: 
        !           119:        EPILOG
        !           120:        return(id) ;
        !           121: }
        !           122: 
        !           123: int                                    /* SUCCESS, ERROR, NOTFOUND */
        !           124: rationalize(id)
        !           125: ITEMID id ;
        !           126: {
        !           127: 
        !           128:        if(id == IDERROR)
        !           129:                return(ERROR) ;
        !           130:        else if(id == IDNOTFOUND)
        !           131:                return(NOTFOUND) ;
        !           132:        else
        !           133:                return(SUCCESS) ;
        !           134: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.