source: trunk/athena/bin/olc/clients/tty/t_topic.c @ 2072

Revision 2072, 4.4 KB checked in by tjcoppet, 35 years ago (diff)
*** empty log message ***
Line 
1/*
2 * This file is part of the OLC On-Line Consulting System.
3 * It contains procedures for exectuting olc commands.
4 *
5 *      Win Treese
6 *      Dan Morgan
7 *      Bill Saphir
8 *      MIT Project Athena
9 *
10 *      Ken Raeburn
11 *      MIT Information Systems
12 *
13 *      Tom Coppeto
14 *      MIT Project Athena
15 *
16 *      Copyright (c) 1989 by the Massachusetts Institute of Technology
17 *
18 *      $Source: /afs/dev.mit.edu/source/repository/athena/bin/olc/clients/tty/t_topic.c,v $
19 *      $Author: tjcoppet $
20 */
21
22
23#ifndef lint
24static char rcsid[]= "$Header: /afs/dev.mit.edu/source/repository/athena/bin/olc/clients/tty/t_topic.c,v 1.3 1989-08-22 13:55:55 tjcoppet Exp $";
25#endif
26
27#include <olc/olc.h>
28#include <olc/olc_tty.h>
29
30/*
31 * Function:    input_topic() reads a question topic from the standard input.
32 * Arguments:   topic:  Space to put the topic.
33 * Returns:     ERRCODE
34 */
35
36ERRCODE
37t_input_topic(Request,topic,flags)
38     REQUEST *Request;
39     char *topic;
40     int flags;
41{
42  char buf[LINE_LENGTH];       
43  char file[NAME_LENGTH];
44  char *bufP;                   
45  int loop = 0;
46  int status;
47  int fudge = 0;
48
49  *buf = '\0';
50 
51  if(flags)
52    {
53      printf("Please type a one-word topic for your question.");
54      printf(" Type ? for a list of\n");
55      printf("available topics or ^D to exit.\n\n");
56    }
57
58  if(*topic != '\0');
59     fudge = 1;
60
61  while(loop < 5)
62    {
63      *buf = '\0';
64      while (*buf == '\0')
65        {
66          bufP = buf;
67          if(!fudge)
68             (void) get_prompted_input("Topic: ", buf);
69          else
70           {
71             strcpy(buf,topic);
72             fudge = 0;
73           }
74
75          if (*bufP == '\0')
76            {
77              *buf = '\0';
78              continue;
79            }
80          while(*bufP == '\\')
81            ++bufP;
82          (void) strcpy(topic, bufP);
83          uncase(topic);
84        }
85     
86      if(string_eq(topic,"?"))
87        {
88          make_temp_name(file);
89          t_list_topics(Request,file,TRUE);
90          unlink(file);
91          continue;
92        }
93
94      if(string_eq(topic,"help"))
95        {
96          printf("Choose a topic, type '?' for a list of available topics.\n");
97          continue;
98        }
99
100      if((status = t_verify_topic(Request,topic)) == SUCCESS)
101        return(SUCCESS);
102     
103      if(status == INVALID_TOPIC)
104        printf("Type '?' for a list of topics.\n");
105      else
106        return(ERROR);
107     
108      ++loop;
109    }
110
111  return(ERROR);
112}
113
114
115ERRCODE
116t_list_topics(Request, file, display)
117     REQUEST *Request;
118     char *file;
119     int display;
120{
121  int status;
122
123  status = OListTopics(Request,file);
124  switch(status)
125    {
126    case SUCCESS:
127      if(display)
128        display_file(file,TRUE);
129      break;
130
131    case ERROR:
132      fprintf(stderr,"Cannot list OLC topics\n");
133      status = ERROR;
134      break;
135
136    default:
137      status = handle_response(status, Request);
138      break;
139    }
140  return(status);
141}
142
143ERRCODE
144t_verify_topic(Request, topic)
145     REQUEST *Request;
146     char *topic;
147{
148  int status;
149
150  status = OVerifyTopic(Request,topic);
151  switch(status)
152    {
153    case SUCCESS:
154      break;
155
156    case INVALID_TOPIC:
157      printf("%s is not a valid topic.\n",topic);
158      break;
159
160    default:
161      status = handle_response(status, Request);
162      break;
163    }
164  return(status);
165}
166
167
168ERRCODE
169t_get_topic(Request, topic)
170     REQUEST *Request;
171     char *topic;
172{
173  int status;
174
175  status = OGetTopic(Request,topic);
176 
177  switch(status)
178    {
179    case SUCCESS:
180      printf("Current topic is \"%s\".\n", topic);
181      status = SUCCESS;
182      break;
183
184    case PERMISSION_DENIED:
185      fprintf(stderr, "You are not allowed to see %s's (%d) topic.\n",
186              Request->target.username, Request->target.instance);
187      status = ERROR;
188      break;
189
190    case FAILURE:
191      fprintf(stderr, "Unable to get topic.\n");
192      status = ERROR;
193      break;
194
195    default:
196      status = handle_response(status, Request);
197      break;
198    }
199 
200  return(status);
201}
202
203
204ERRCODE
205t_change_topic(Request,topic)
206     REQUEST *Request;
207     char *topic;
208{
209  int status;
210
211  status = OChangeTopic(Request,topic);
212  switch(status)
213    {
214    case SUCCESS:
215      printf("Topic changed to %s\n",topic);
216      break;
217
218    case PERMISSION_DENIED:
219      fprintf(stderr, "You are not allowed to change %s's (%d) topic.\n",
220              Request->target.username, Request->target.instance);
221      status = ERROR;
222      break;
223
224    case ERROR:
225      fprintf(stderr,
226              "Topic \"%s\" is not defined. Try 'topic ?' (it won't bite)\n",
227              topic);
228      break;
229
230    default:
231      status = handle_response(status, Request);
232      break;
233    }
234 
235  return(status);
236}
Note: See TracBrowser for help on using the repository browser.