Annotation of 43BSDTahoe/new/notes/src/note.c, revision 1.1

1.1     ! root        1: #ifdef RCSIDENT
        !             2: static char rcsid[] = "$Header: note.c,v 1.7 85/01/18 15:32:57 notes Rel $";
        !             3: #endif RCSIDENT
        !             4: 
        !             5: /*
        !             6:  *     Putnote
        !             7:  *
        !             8:  *     Take the given text, and make put it into the note file.
        !             9:  *     following algorithm:
        !            10:  *     reserve space for text
        !            11:  *     write the text
        !            12:  *     make the note header record
        !            13:  *     lock the index file
        !            14:  *     write the note header info
        !            15:  *     unlock the index file
        !            16:  *     rewrite the correct text header info
        !            17:  *
        !            18:  *
        !            19:  *     Delnote(io, noteno):  marks the status word as deleted.
        !            20:  *
        !            21:  *     Original authors:       Rob Kolstad and Ray Essick      Winter 1980
        !            22:  *     modified;       Ray Essick      December 1981
        !            23:  */
        !            24: 
        !            25: #include "parms.h"
        !            26: #include "structs.h"
        !            27: 
        !            28: putnote (io, where, title, status, note, auth, policy, lockit, addid, fromsys, addtime)
        !            29: struct io_f *io;
        !            30: struct daddr_f *where;
        !            31: char   *title;
        !            32: struct note_f  *note;
        !            33: struct auth_f  *auth;
        !            34: /* policy = true if this is the policy note */
        !            35: /* addid = fales if we already have an id for the note */
        !            36: /* addtime = false if we already have a time for the note */
        !            37: char   *fromsys;                                       /* whom we recieved it from (routing) */
        !            38: {
        !            39:     int     count;
        !            40:     char   *p;
        !            41:     int     notenum;
        !            42: 
        !            43:     note -> n_nresp = 0;                               /* no responses yet */
        !            44:     if (addtime)                                       /* dont if compressing... */
        !            45:     {
        !            46:        gettime (&note -> n_rcvd);
        !            47:        gettime (&note -> n_lmod);                      /* date of last mod is same */
        !            48:     }
        !            49:     note -> n_auth = *auth;                            /* move author over */
        !            50:     strcpy (note -> n_from, fromsys);                  /* who gave it to us */
        !            51:     note -> n_rindx = (-1);                            /* no place for responses yet */
        !            52:     note -> n_stat = status;                           /* director message, deleted, etc */
        !            53:     note -> n_addr = *where;                           /* where on disk */
        !            54:     strncpy (note -> ntitle, title, TITLEN);           /* copy */
        !            55:     note -> ntitle[TITLEN - 1] = '\0';                 /* stop for sure */
        !            56: 
        !            57:     if (lockit)
        !            58:        locknf (io, DSCRLOCK);                          /* BEGIN CRITICAL SECTION */
        !            59:     getdscr (io, &io -> descr);                                /* grab notesfile header */
        !            60:     if (io -> descr.d_stat & NFINVALID)
        !            61:     {
        !            62:        if (lockit)
        !            63:            unlocknf (io, DSCRLOCK);
        !            64:        closenf (io);
        !            65:        opennf (io, 0);                                 /* get new links */
        !            66:        printf ("Sorry, your note has been lost in a compression");
        !            67: /*
        !            68:  *     Should give the user a chance to recover his text somewhere
        !            69:  *     in here 
        !            70:  */
        !            71:        fflush (stdout);
        !            72:        sleep (1);
        !            73:        return (-1);
        !            74:     }
        !            75:     if (addid)
        !            76:     {
        !            77: #ifdef SHAREDATA
        !            78:        strmove (System, note -> n_id.sys);             /* copy sys name */
        !            79: #else  ! SHAREDATA
        !            80:        strmove (io -> descr.d_id.sys, note -> n_id.sys);
        !            81: #endif SHAREDATA
        !            82:        note -> n_id.uniqid = ++(io -> descr.d_id.uniqid);
        !            83:                                                        /* and unique id num */
        !            84: #ifdef UNIQPLEX
        !            85:        note -> n_id.uniqid += UNIQPLEX * io -> descr.d_nfnum;
        !            86:                                                        /* mpx in nf num */
        !            87: #endif
        !            88:     }
        !            89: 
        !            90:     if (policy)
        !            91:     {
        !            92:        io -> descr.d_plcy = 1;                         /* mark as having a policy note */
        !            93:        notenum = 0;
        !            94:     }
        !            95:     else
        !            96:        notenum = ++io -> descr.d_nnote;                /* this note's number */
        !            97:     if (addtime)                                       /* see if want timestamp */
        !            98:        gettime (&io -> descr.d_lastm);                 /* last time file modified */
        !            99:     putnrec (io, notenum, note);                       /* write note info */
        !           100:     putdscr (io, &io -> descr);                                /* rewrite header info */
        !           101:     if (lockit)
        !           102:        unlocknf (io, DSCRLOCK);                        /* END CRITICAL SECTION */
        !           103:     io -> nnotwrit++;                                  /* bump count of writes */
        !           104:     return (io -> descr.d_nnote);                      /* tell which slot it is in */
        !           105: }
        !           106: 
        !           107: 
        !           108: delnote (io, noteno, lockit)
        !           109: struct io_f *io;
        !           110: {
        !           111:     struct note_f   note;
        !           112: 
        !           113:     if (lockit)
        !           114:        locknf (io, DSCRLOCK);                          /* CRITICAL */
        !           115:     getnrec (io, noteno, &note);                       /* get the note */
        !           116:     note.n_stat |= DELETED;                            /* deleted */
        !           117:     putnrec (io, noteno, &note);
        !           118:     getdscr (io, &io -> descr);                                /* update delete count */
        !           119:     io -> descr.d_delnote++;
        !           120:     io -> descr.d_delresp += note.n_nresp;             /* count resps */
        !           121:     putdscr (io, &io -> descr);
        !           122:     if (lockit)
        !           123:        unlocknf (io, DSCRLOCK);                        /* END CRITICAL */
        !           124: }

unix.superglobalmegacorp.com

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