Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
help.c
Go to the documentation of this file.
1 /*
2 Copyright 2021 Arizona Board of Regents on behalf of the University of Arizona.
3 
4 For commercial uses, to obtain a license to sell and or sublicense copies of
5 the Software please contact the University of Arizona at Tech Launch Arizona:
6 lewish@tla.arizona.edu.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction for non-commercial use educational and
11 research purposes, including without limitation the rights to use, copy,
12 modify, merge, publish, distribute, and to permit persons to whom the Software
13 is furnished to do so, subject to the following conditions:
14 
15 The entire above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25 
26 1. Additional Required Provisions
27 
28 1.1. Arbitration. The parties agree that if a dispute arises between them
29 concerning this Agreement, the parties may be required to submit the matter to
30 arbitration pursuant to Arizona law.
31 
32 1.2. Applicable Law and Venue. This Agreement shall be interpreted pursuant
33 to the laws of the State of Arizona. Any arbitration or litigation between the
34 Parties shall be conducted in Pima County, ARIZONA, and LICENSEE hereby
35 submits to venue and jurisdiction in Pima County, ARIZONA.
36 
37 1.3. Non-Discrimination. The Parties agree to be bound by state and federal
38 laws and regulations governing equal opportunity and non-discrimination and
39 immigration.
40 
41 1.4. Appropriation of Funds. The Parties recognize that performance by
42 ARIZONA may depend upon appropriation of funds by the State Legislature of
43 ARIZONA. If the Legislature fails to appropriate the necessary funds, or if
44 ARIZONA’S appropriation is reduced during the fiscal year, ARIZONA may cancel
45 this Agreement without further duty or obligation. ARIZONA will notify
46 LICENSEE as soon as reasonably possible after it knows of the loss of funds.
47 
48 1.5. Conflict of Interest. This Agreement is subject to the provisions of
49 A.R.S. 38-511 and other conflict of interest regulations. Within three years
50 of the EFFECTIVE DATE, ARIZONA may cancel this Agreement if any person
51 significantly involved in initiating, negotiating, drafting, securing, or
52 creating this Agreement for or on behalf of ARIZONA becomes an employee or
53 consultant in any capacity of LICENSEE with respect to the subject matter of
54 this Agreement.
55 
56  */
57 
58 
59 #include "extern.h"
60 
62 
63 char highlightBuf[32], normalBuf[32];
64 
65 
67 {
68  int i, l;
69  char tbuf[256];
70  struct COMMANDS *p;
71 
72  sprintf(highlightBuf, "%c[1m%c[33m", 0x1b, 0x1b);
73  sprintf(normalBuf, "%c[0m%c[37m", 0x1b, 0x1b);
74 
75  bzero((char *)&letter_help, sizeof(letter_help));
76 
77  p = &commands[0];
78 
79  for(i=0;p->cmd;i++,p++) /* For each command */
80  {
81  for(l=0;l<26;l++) /* For each letter possible */
82  {
83  if(p->ntoken == -1)
84  {
85  continue;
86  }
87 
88  if(p->mode == MODE_ALL || p->mode == env->mode)
89  {
90  strcpy(tbuf, p->cmd);
91  strcmprs(tbuf);
92  strlwr(tbuf);
93 
94  if(tbuf[0] == l+97)
95  {
97  letter_help.commands[l].n++;
98  }
99  }
100  }
101  }
102 
103  return(0);
104 }
105 
106 
107 
109 char *h;
110 {
111  int i, k, ih;
112  char tbuf[256];
113  struct HELP_COMMANDS *p;
114 
115 // st_report("Parsing help request %s", h);
116 
117  p = &letter_help.commands[0];
118 
119  strcpy(tbuf, h);
120  strlwr(tbuf);
121  ih = h[0] - 97;
122 
123  for(i=0;i<26;i++,p++)
124  {
125  if(i == ih)
126  {
127  if(p->n == 0)
128  {
129  st_report("No help for the letter %1.1s", h);
130  return(1);
131  }
132 
133  st_report("There are %d commands starting with %1.1s", p->n, h);
134 
135  for(k=0;k<p->n;k++)
136  {
137  st_print("%s ", p->commands[k]);
138 
139  if(k == 7 || k == 15 || k == 23 || k == 31) /* Start newline */
140  {
141  st_print("\n");
142  }
143  }
144 
145  if(k != 8 && k != 16 && k != 24 && k != 32) /* Don't add another newline */
146  {
147  st_print("\n");
148  }
149 
150  return(0);
151  }
152  }
153 
154  st_report("No help for the letter %1.1s", h);
155 
156  return(1);
157 }
158 
159 
160 
161 int showPartHelp(help)
162 char *help;
163 {
164  st_warn("Ambiguous Command: Possible Commands:\n\n %s", help);
165 
166  return(0);
167 }
168 
169 
170 
171 int showSpecHelp(buf)
172 char *buf;
173 {
174  char sysbuf[256];
175 
176  sprintf(sysbuf, "less -e %s/linuxpops/%s.hlp", help_home, buf);
177 
178  system(sysbuf);
179 
180  return(0);
181 }
182 
183 
184 
185 int showAllHelp(all)
186 int all;
187 {
188  struct COMMANDS *p;
189  int i, j=0, hi, wd;
190  char *mStrs[] = { "A", "C", "S", "O", "?" };
191 
192  getTerminalSize(&wd, &hi);
193 
194  st_print("\n");
195  st_print("Command Args Mode nArgs Help\n");
196  st_print("\n");
197 
198  p = &commands[0];
199  for(i=0;p->cmd;i++,p++)
200  {
201  /* Only show help for current mode */
202  if(!all && p->mode && p->mode != env->mode)
203  {
204  continue;
205  }
206 
207  if(isSet(PF_P_FLAG) && j > 0 && !(j%hi))
208  {
209  if(getYesNoQuit("\nHit 'Return' to continue; 'q' to quit help") == 2)
210  {
211  return(1);
212  }
213  st_print("\n");
214  }
215 
216  if(p->ntoken >= 0) /* Ignore all those Partial Help elements */
217  {
218  if((p->ntoken-1) < 0)
219  {
220  st_print("%s: %-50.50s %1s [*] %s\n", p->cmd, p->args, mStrs[p->mode], p->help);
221  }
222  else
223  {
224  st_print("%s: %-50.50s %1s [%d] %s\n", p->cmd, p->args, mStrs[p->mode], p->ntoken-1, p->help);
225  }
226  }
227 
228  j++;
229  }
230 
231  return(0);
232 }
233 
234 
236 {
237  struct COMMANDS *p;
238  int i, j=0, hi, wd, first=1;
239  char *mStrs[] = { "A", "C", "S", "O", "?" };
240  char hstr[256];
241 
242  getTerminalSize(&wd, &hi);
243 
244  if(!strlen(args->secondArg))
245  {
246  st_fail("Not secondArg");
247 
248  printH_FlagHelp("help");
249 
250  return(1);
251  }
252 
253  strcpy(hstr, args->secondArg);
254 
255  p = &commands[0];
256  for(i=0;p->cmd;i++,p++)
257  {
258  /* Only show help for current mode */
259  if(p->mode && p->mode != env->mode)
260  {
261  continue;
262  }
263 
264  if(j > 0 && !(j%hi))
265  {
266  if(getYesNoQuit("\nHit 'Return' to continue; 'q' to quit help") == 2)
267  {
268  return(1);
269  }
270  st_print("\n");
271  }
272 
273  if(strcasestr(p->help, hstr))
274  {
275  if(first)
276  {
277  st_print("\n");
278  st_print("Command Args Mode nArgs Help\n");
279  st_print("\n");
280 
281  first = 0;
282  }
283 
284  if(p->ntoken >= 0) /* Ignore all those Partial Help elements */
285  {
286  if((p->ntoken-1) < 0)
287  {
288  st_print("%s: %-50.50s %1s [*] %s\n", p->cmd, p->args, mStrs[p->mode], p->help);
289  }
290  else
291  {
292  st_print("%s: %-50.50s %1s [%d] %s\n", p->cmd, p->args, mStrs[p->mode], p->ntoken-1, p->help);
293  }
294  }
295 
296  j++;
297  }
298  }
299 
300  if(first)
301  {
302  st_print("No commands matching %s\n", hstr);
303  }
304 
305  return(0);
306 }
307 
308 
309 int showHelp()
310 {
311  if(isSet(PF_K_FLAG))
312  {
313  showKhelp();
314  return(0);
315  }
316 
317  if(isSet(PF_A_FLAG) == 1)
318  {
319  showAllHelp(0);
320  return(0);
321  }
322 
323  if(isSet(PF_A_FLAG) > 1)
324  {
325  showAllHelp(1);
326  return(0);
327  }
328 
329  if(strlen(args->secondArg)) /* Help for specific topic?? */
330  {
332  return(0);
333  }
334 
335  printH_FlagHelp("help");
336 
337  return(0);
338 }
339 
340 
342 char *cmd;
343 FILE *fp;
344 {
345  char tbuf[256], fname[5122], *string, line[512];
346  FILE *sfp;
347 
348  strcpy(tbuf, cmd);
349  strcmprs(tbuf);
350 
351  sprintf(fname, "%s/supplemental/%s.sup", help_home, tbuf);
352 
353 // fprintf(stdout, "Looking for Supplemental Helpfile: %s\n", fname);
354 
355  if((sfp = fopen(fname, "r") ) <= (FILE *)0)
356  {
357  return(1);
358  }
359 
360 // fprintf(stdout, "Found Supplemental Helpfile: %s\n", fname);
361 
362  while((string = fgets(line, sizeof(line), sfp)) != NULL)
363  {
364  fprintf(fp, "%s", line);
365  }
366 
367  fclose(sfp);
368 
369  return(0);
370 }
371 
372 
373 int makeHelp()
374 {
375  int saveStq;
376  char tbuf[256], fname[512], *user;
377  struct COMMANDS *p;
378  FILE *fp, *saveFp;
379 
380  user = getenv("USER");
381 
382  if(strcmp(user, "tfolkers"))
383  {
384  st_report("Nope!");
385 
386  return(0);
387  }
388 
389  saveFp = errPrint_fp;
390  saveStq = stquiet;
391 
392  stquiet = 1;
393 
394  p = &commands[0];
395  for(;p->cmd;p++)
396  {
397  if(p->ntoken == -1)
398  {
399  continue;
400  }
401 
402  strcpy(tbuf, p->cmd);
403  strcmprs(tbuf);
404 
405  sprintf(fname, "%s/linuxpops/%s.hlp", help_home, tbuf);
406 
407  if((fp = fopen(fname, "w")) == NULL)
408  {
409  fprintf(stderr, "Unable to open %s\n", fname);
410  continue;
411  }
412 
413  errPrint_fp = fp;
414 
415  printH_FlagHelp(tbuf);
416 
417  addSupplemental(p->cmd, fp);
418 
419  fclose(fp);
420 
421  errPrint_fp = saveFp;
422  }
423 
424  stquiet = saveStq;
425 
426  return(0);
427 }
428 
429 
431 char *cmd;
432 {
433  int i, len;
434  char *cp, tbuf[256];
435  struct HELP_H_FLAG *p;
436 
437  strcpy(tbuf, cmd);
438  strcmprs(tbuf);
439 
440  len = strlen(tbuf);
441 
442  for(p=&help_h_flag[0]; p->cmd; p++)
443  {
444  if(!strncmp(p->cmd, tbuf, len))
445  {
446  st_print("********************************************************************************\n");
447 
448  for(i=0;i<MAX_HELP_STRINGS;i++)
449  {
450  cp = p->help[i];
451  if(cp /* && (strlen(cp) > 1) */)
452  {
453  if(strstr(cp, "CAUTION"))
454  {
455  st_print("*\t%s%s%s\n", highlightBuf, cp, normalBuf);
456  }
457  else
458  {
459  st_print("*\t%s\n", cp);
460  }
461  }
462  }
463  st_print("********************************************************************************\n");
464 
465  return(0);
466  }
467  }
468 
469  st_fail("No /h help for cmd: %s", tbuf);
470 
471  return(1);
472 }
473 
474 
476 {
477  char sysbuf[256];
478 
479  st_report("Starting Document Viewer");
480 
481  sprintf(sysbuf, "okular %s/docs/LP_Changes.pdf 1> /dev/null 2>&1 &", pkg_home);
482 
483  system(sysbuf);
484 
485  return(0);
486 }
487 
char pkg_home[256]
Definition: makemem.c:97
char highlightBuf[32]
Definition: help.c:63
char * strcmprs(char *str)
int first
Definition: dbase.c:106
struct PARSE_STACK * args
Definition: parse.h:196
struct COMMANDS commands[]
Definition: commands.c:76
int n
Definition: help.h:10
Definition: parse.h:8
char * args
Definition: commands.h:7
char * cmd
Definition: commands.h:5
char commands[128][80]
Definition: help.h:11
FILE * fp
Definition: linuxpops.c:70
int printH_FlagHelp(char *cmd)
Definition: help.c:430
int ntoken
Definition: commands.h:6
int showKhelp()
Definition: help.c:235
char normalBuf[32]
Definition: help.c:63
int stquiet
Definition: env.c:90
char * strlwr(char *str)
char * help
Definition: commands.h:11
int showPartHelp(char *help)
Definition: help.c:161
int addSupplemental(char *cmd, FILE *fp)
Definition: help.c:341
int getYesNoQuit()
struct ENVIRONMENT * env
Definition: linuxpops.c:71
int letterHelp(char *h)
Definition: help.c:108
char * help[MAX_HELP_STRINGS]
Definition: help.h:26
struct HELP_H_FLAG help_h_flag[]
Definition: help_table.c:73
int initLetterHelp()
Definition: help.c:66
int isSet(int flag)
Definition: parse.c:646
int showChanges()
Definition: help.c:475
void st_warn()
struct HELP_STRUCT letter_help
Definition: help.c:61
void st_fail()
int strcmp()
int showAllHelp(int all)
Definition: help.c:185
int showHelp()
Definition: help.c:309
int makeHelp()
Definition: help.c:373
#define MAX_HELP_STRINGS
Definition: help.h:22
int showSpecHelp(char *buf)
Definition: help.c:171
char * cmd
Definition: help.h:25
int mode
Definition: commands.h:10
int mode
Definition: env.h:75
void st_report()
int getTerminalSize(int *cols, int *rows)
Definition: io.c:1015
char help_home[256]
Definition: makemem.c:97
struct HELP_COMMANDS commands[MAX_LETTERS]
Definition: help.h:19
char * secondArg
Definition: parse.h:181
void st_print()
#define MODE_ALL
Definition: defines.h:85
FILE * errPrint_fp
Definition: linuxpops.c:70