Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
alias.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 #include "extern.h"
59 
61 
63 char aliastbuf[4096];
64 
68 int alias_get_tok(edit)
69 char *edit;
70 {
71  int c = 0;
72  char *token;
73 
74  bzero((char *)&alias_tok, sizeof(alias_tok));
75 
76  token = strtok(edit, "\n\t\r\n ");
77  while(token != (char *)NULL)
78  {
79  sprintf(alias_tok[c++], "%s", token);
80  token = strtok((char *)NULL, "\n\t\r\n ");
81  }
82 
83  return(c);
84 }
85 
86 
87 int doAlias()
88 {
89  int i, j, ndx, first = 1;
90  char buf[512], tbuf[256];
91 
93  {
94  st_report("Alias(): ntokens = %d", args->ntokens);
95  }
96 
97  if(isSet(PF_L_FLAG)) /* Show listing */
98  {
99  j = 0;
100  for(i=0;i<MAX_ALIAS;i++)
101  {
102  if(aliases[i].used)
103  {
104  if(first)
105  {
106  st_print(" Alias : Substitute\n\n");
107  first = 0;
108  }
109 
110  st_print("%-12.12s: %s\n", aliases[i].keyword, aliases[i].alias);
111 
112  j++;
113  }
114  }
115 
116  st_report("%d aliases defines out of %d", j, MAX_ALIAS);
117 
118  return(0);
119  }
120 
121  if(args->ntokens > 2)
122  {
123  bzero(tbuf, sizeof(tbuf));
124 
125  for(i=0;i<MAX_ALIAS;i++) /* Find an empty alias slot */
126  {
127  if(!aliases[i].used)
128  {
129  ndx = i;
130  break;
131  }
132  }
133 
134  if(i == MAX_ALIAS)
135  {
136  st_fail("Too many aliases defined");
137  return(1);
138  }
139 
140  strcpy(aliases[ndx].keyword, args->secondArg);
141 
142  for(i=2;i<args->ntokens;i++)
143  {
144 
145  if(strstr(args->tok[i], "\\/")) /* Look for excaped flags in alias; need to gig it \\ to stop compiler warns */
146  {
147  sprintf(buf, "%s ", args->tok[i]+1);
148  }
149  else
150  {
151  sprintf(buf, "%s ", args->tok[i]);
152  }
153 
154  strcat(tbuf, buf);
155  }
156 
157  strcpy(aliases[ndx].alias, tbuf);
158  aliases[ndx].used = 1;
159  }
160  else
161  {
162  printH_FlagHelp("alias");
163  return(1);
164  }
165 
166  return(0);
167 }
168 
169 
171 {
172  int i;
173 
174  if(args->ntokens > 1)
175  {
176  for(i=0;i<MAX_ALIAS;i++)
177  {
178  if(aliases[i].used)
179  {
180  if(!strcmp(args->secondArg, aliases[i].keyword))
181  {
182  st_report("Alias(): Zapping alias %s", args->secondArg);
183 
184  aliases[i].used = 0;
185  aliases[i].keyword[0] = '\0';
186  aliases[i].alias[0] = '\0';
187  }
188  }
189  }
190  }
191 
192  return(0);
193 }
194 
195 
196 struct ALIAS *isAlias(buf)
197 char *buf;
198 {
199  int i;
200 
201  for(i=0;i<MAX_ALIAS;i++)
202  {
203  if(aliases[i].used)
204  {
205  if(!strcmp(aliases[i].keyword, buf))
206  {
207  return(&aliases[i]);
208  }
209  }
210  }
211 
212  return((struct ALIAS *)0);
213 }
214 
215 
224 char *buf;
225 {
226  int i, n;
227  char tbuf[512];
228  struct ALIAS *a;
229 
231  {
232  st_report("Alias(): Starting command: %s", buf);
233  }
234 
235  strcpy(aliastbuf, buf); /* Make a local copy */
236 
238 
239  if(!n)
240  {
241  if(verboseLevel & VERBOSE_ALIAS)
242  {
243  st_report("Alias(): No args");
244  }
245  return(1);
246  }
247 
248  /* substitute aliases here */
249  for(i=0;i<n;i++)
250  {
251  if((a = isAlias(alias_tok[i])))
252  {
253  strcpy(alias_tok[i], a->alias);
254  }
255  else
256  {
257  if(verboseLevel & VERBOSE_ALIAS)
258  {
259  st_report("Alias(): Skipping %s", alias_tok[i]);
260  }
261  }
262  }
263 
264  /* reconsitute original buffer here */
265  buf[0] = '\0';
266 
267  for(i=0;i<n;i++)
268  {
269  sprintf(tbuf, "%s ", alias_tok[i]);
270 
271  strcat(buf, tbuf);
272  }
273 
274  strcmprs(buf);
275 
276  if(verboseLevel & VERBOSE_ALIAS)
277  {
278  st_report("Alias(): Final command: %s", buf);
279  }
280 
281  return(0);
282 }
char alias_tok[MAX_TOKENS][MAX_TOKENS]
Definition: alias.c:62
char * strcmprs(char *str)
int first
Definition: dbase.c:106
struct PARSE_STACK * args
Definition: parse.h:196
struct ALIAS * isAlias(char *buf)
Definition: alias.c:196
#define MAX_TOKENS
Definition: defines.h:40
char keyword[64]
Definition: alias.h:8
Definition: alias.h:6
int printH_FlagHelp(char *cmd)
Definition: help.c:430
#define VERBOSE_ALIAS
Definition: defines.h:75
char tok[MAX_TOKENS][MAX_TOKENS]
Definition: parse.h:176
int isSet(int flag)
Definition: parse.c:646
struct ALIAS aliases[MAX_ALIAS]
Definition: alias.c:60
void st_fail()
int alias_get_tok(char *edit)
Definition: alias.c:68
int strcmp()
void st_report()
#define MAX_ALIAS
Definition: alias.h:4
char alias[MAX_ALIAS]
Definition: alias.h:9
int used
Definition: alias.h:7
char * secondArg
Definition: parse.h:181
void st_print()
int ntokens
Definition: parse.h:173
int substituteAliases(char *buf)
Definition: alias.c:223
char aliastbuf[4096]
Definition: alias.c:63
int doUnalias()
Definition: alias.c:170
int verboseLevel
Definition: linuxpops.c:80
int doAlias()
Definition: alias.c:87