source: PSPA/madxPSPA/src/mad_cmdin.c @ 478

Last change on this file since 478 was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 3.8 KB
Line 
1#include "madx.h"
2
3// public debug
4
5void
6dump_in_cmd(struct in_cmd* p_inp)
7{
8  fprintf(prt_file, "%s: type =%d, sub_type = %d, decl_start = %d\n",
9          p_inp->label, p_inp->type, p_inp->sub_type, p_inp->decl_start);
10  if (p_inp->cmd_def != NULL)
11  {
12    fprintf(prt_file, "defining command: %s\n", p_inp->cmd_def->name);
13    dump_command(p_inp->cmd_def);
14  }
15}
16
17// public interface
18
19struct in_cmd*
20buffered_cmd(struct in_cmd* cmd)
21  /* returns a buffered command if found */
22{
23  int k;
24  if ((k = name_list_pos(cmd->tok_list->p[cmd->decl_start],
25                         buffered_cmds->labels)) > -1)
26    return buffered_cmds->in_cmds[k];
27  else return cmd;
28}
29
30void
31buffer_in_cmd(struct in_cmd* cmd)
32  /* stores an input command in a buffer */
33{
34  int i;
35  if (buffered_cmds->curr == buffered_cmds->max)
36    grow_in_cmd_list(buffered_cmds);
37  cmd->label = permbuff(cmd->label);
38  add_to_name_list(cmd->label, 0, buffered_cmds->labels);
39  buffered_cmds->in_cmds[buffered_cmds->curr++] = cmd;
40  for (i = 0; i < cmd->tok_list->curr; i++)
41    cmd->tok_list->p[i] = permbuff(cmd->tok_list->p[i]);
42}
43
44struct in_cmd*
45new_in_cmd(int length)
46{
47  char rout_name[] = "new_in_cmd";
48  struct in_cmd* new = mycalloc(rout_name,1, sizeof(struct in_cmd));
49  strcpy(new->name, "in_cmd");
50  new->stamp = 123456;
51  if (watch_flag) fprintf(debug_file, "creating ++> %s\n", new->name);
52  new->tok_list = new_char_p_array(length);
53  return new;
54}
55
56struct in_cmd_list*
57new_in_cmd_list(int length)
58{
59  char rout_name[] = "new_in_cmd_list";
60  struct in_cmd_list* il = mycalloc(rout_name,1, sizeof(struct in_cmd_list));
61  strcpy(il->name, "in_cmd_list");
62  il->stamp = 123456;
63  if (watch_flag) fprintf(debug_file, "creating ++> %s\n", il->name);
64  il->curr = 0;
65  il->max = length;
66  il->labels = new_name_list(il->name, length);
67  il->in_cmds = mycalloc(rout_name,length, sizeof(struct in_cmd*));
68  return il;
69}
70
71struct in_cmd*
72delete_in_cmd(struct in_cmd* cmd)
73{
74  char rout_name[] = "delete_in_cmd";
75  if (cmd == NULL) return NULL;
76  if (stamp_flag && cmd->stamp != 123456)
77    fprintf(stamp_file, "d_i_c double delete --> %s\n", cmd->name);
78  if (watch_flag) fprintf(debug_file, "deleting --> %s\n", cmd->name);
79  if (cmd->tok_list != NULL)
80    cmd->tok_list = delete_char_p_array(cmd->tok_list, 0);
81  myfree(rout_name, cmd);
82  return NULL;
83}
84
85void
86grow_in_cmd_list(struct in_cmd_list* p)
87{
88  char rout_name[] = "grow_in_cmd_list";
89  struct in_cmd** c_loc = p->in_cmds;
90  int j, new = 2*p->max;
91
92  p->max = new;
93  p->in_cmds
94    = (struct in_cmd**) mycalloc(rout_name,new, sizeof(struct in_cmd*));
95  for (j = 0; j < p->curr; j++) p->in_cmds[j] = c_loc[j];
96  myfree(rout_name, c_loc);
97}
98
99void
100scan_in_cmd(struct in_cmd* cmd)
101  /* reads a command into a clone of the original */
102{
103  int cnt = 0, /* gives position in command (from 1) */
104      i, k, log, n;
105  struct name_list* nl = cmd->clone->par_names;
106  for (i = 0; i < nl->curr; i++) nl->inform[i] = 0; /* set when read */
107  n = cmd->tok_list->curr;
108  i = cmd->decl_start;
109  cmd->tok_list->p[n] = blank;
110
111  while (i < n) {
112    log = 0;
113
114    if (i+1 < n && *cmd->tok_list->p[i] == '-') {
115      log = 1; i++;
116    }
117
118    if (*cmd->tok_list->p[i] != ',') {
119      if ((k = name_list_pos(cmd->tok_list->p[i], cmd->cmd_def->par_names)) < 0) { /* try alias */
120        if ((k = name_list_pos(alias(cmd->tok_list->p[i]), cmd->cmd_def->par_names)) < 0)
121          fatal_error("illegal keyword:", cmd->tok_list->p[i]);
122        break;
123      }
124      else if ((i = decode_par(cmd, i, n, k, log)) < 0) {
125        fatal_error("illegal format near:", cmd->tok_list->p[-i]);
126        break;
127      }
128
129      cmd->clone->par_names->inform[k] = ++cnt; /* mark parameter as read */
130      if (strcmp(cmd->tok_list->p[i], "true_") == 0 || strcmp(cmd->tok_list->p[i], "false_") == 0)
131        cmd->cmd_def->par->parameters[k]->double_value = cmd->clone->par->parameters[k]->double_value;
132    }
133    i++;
134  }
135}
136
Note: See TracBrowser for help on using the repository browser.