Commit | Line | Data |
---|---|---|
0f4556f1 C |
1 | static char *sccsid = "@(#)note.c 1.2 2/2/83"; |
2 | ||
3 | #include "parms.h" | |
4 | #include "structs.h" | |
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 | putnote (io, where, title, status, note, auth, policy, lockit, addid, fromsys, addtime) | |
26 | struct io_f *io; | |
27 | struct daddr_f *where; | |
28 | char *title; | |
29 | struct note_f *note; | |
30 | struct auth_f *auth; | |
31 | /* policy = true if this is the policy note */ | |
32 | /* addid = fales if we already have an id for the note */ | |
33 | /* addtime = false if we already have a time for the note */ | |
34 | char *fromsys; /* whom we recieved it from (routing) */ | |
35 | { | |
36 | int count; | |
37 | char *p; | |
38 | int notenum; | |
39 | ||
40 | note->n_nresp = 0; /* no responses yet */ | |
41 | if (addtime) { /* dont if compressing... */ | |
42 | gettime(¬e->n_rcvd); | |
43 | gettime(¬e->n_lmod); /* date of last mod is same */ | |
44 | } | |
45 | copyauth(auth, ¬e->n_auth); /* move author over */ | |
46 | strmove(fromsys, note->n_from); /* who gave it to us */ | |
47 | note->n_rindx = -1; /* no place for responses yet */ | |
48 | note->n_stat = status; /* director message, deleted, etc */ | |
49 | note->n_addr.addr = where->addr; /* where on disk */ | |
50 | p = note->ntitle; | |
51 | count = TITLEN; | |
52 | while (count--) { | |
53 | *p++ = *title++; /* move title over */ | |
54 | } | |
55 | ||
56 | if (lockit) { | |
57 | lock(io, 'n'); /* CRITICAL */ | |
58 | } | |
59 | getdscr(io, &io->descr); /* grab notesfile header */ | |
60 | if (io->descr.d_stat & NFINVALID) { | |
61 | if (lockit) { | |
62 | unlock(io, 'n'); /* CRITICAL */ | |
63 | } | |
64 | closenf(io); | |
65 | opennf(io, io->nf); /* get new links */ | |
66 | printf("Sorry, your note has been lost in a compression"); | |
67 | fflush(stdout); | |
68 | sleep (2); | |
69 | return(-1); | |
70 | } | |
71 | if (addid) { | |
72 | strmove(io->descr.d_id.sys, note->n_id.sys); | |
73 | /* copy over sys name */ | |
74 | note->n_id.uniqid = ++(io->descr.d_id.uniqid); | |
75 | /* and unique id num */ | |
76 | #ifdef UNIQPLEX | |
77 | note->n_id.uniqid += UNIQPLEX * io->descr.d_nfnum; | |
78 | /* mpx in nf num */ | |
79 | #endif | |
80 | } | |
81 | ||
82 | if (policy) { | |
83 | io->descr.d_plcy = 1; /* mark as having a policy note */ | |
84 | notenum = 0; | |
85 | } else { | |
86 | notenum = ++io->descr.d_nnote; /* this note's number */ | |
87 | } | |
88 | if (addtime) { /* see if want timestamp */ | |
89 | gettime(&io->descr.d_lastm); /* last time file modified */ | |
90 | } | |
91 | putnrec(io, notenum, note); /* write note info */ | |
92 | putdscr(io, &io->descr); /* rewrite header info */ | |
93 | if (lockit) { | |
94 | unlock(io, 'n'); /* CRITICAL */ | |
95 | } | |
96 | io->nnotwrit++; /* bump count of writes */ | |
97 | return(io->descr.d_nnote); /* tell which slot it is in */ | |
98 | } | |
99 | ||
100 | ||
101 | delnote (io, noteno, lockit) | |
102 | struct io_f *io; | |
103 | { | |
104 | struct note_f note; | |
105 | ||
106 | if (lockit) { | |
107 | lock(io, 'n'); /* CRITICAL */ | |
108 | } | |
109 | getnrec(io, noteno, ¬e); /* get the note */ | |
110 | note.n_stat |= DELETED; /* deleted */ | |
111 | putnrec(io, noteno, ¬e); | |
112 | if (lockit) { | |
113 | unlock(io, 'n'); /* CRITICAL */ | |
114 | } | |
115 | } |