Subversion Repositories SvarDOS

Rev

Rev 1024 | Rev 1074 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1024 Rev 1070
Line 53... Line 53...
53
 *
53
 *
54
 * This file only provides the help screen of FOR, as well as the FOR-context
54
 * This file only provides the help screen of FOR, as well as the FOR-context
55
 * initialization. Actual execution happens within command.c.
55
 * initialization. Actual execution happens within command.c.
56
 */
56
 */
57
 
57
 
-
 
58
 
-
 
59
/* normalizing for-loop pattern-list separators.
-
 
60
 * returns a space char if c is a for-pattern separator, c otherwise */
-
 
61
static char cmd_for_sepnorm(char c) {
-
 
62
  /* the list of valid delimiters has been researched and kindly shared by Robert
-
 
63
   * Riebisch via the ticket at https://osdn.net/projects/svardos/ticket/44058 */
-
 
64
  switch (c) {
-
 
65
    case ' ':
-
 
66
    case '\t':
-
 
67
    case ';':
-
 
68
    case ',':
-
 
69
    case '/':
-
 
70
    case '=':
-
 
71
      return(' '); /* normalize FOR-loop separators to a space */
-
 
72
    default: /* anything else is kept as-is */
-
 
73
      return(c);
-
 
74
  }
-
 
75
}
-
 
76
 
-
 
77
 
58
static enum cmd_result cmd_for(struct cmd_funcparam *p) {
78
static enum cmd_result cmd_for(struct cmd_funcparam *p) {
59
  struct forctx *f = (void *)(p->BUFFER);
79
  struct forctx *f = (void *)(p->BUFFER);
60
  unsigned short i;
80
  unsigned short i;
61
 
81
 
62
  /* forbid nested FORs */
82
  /* forbid nested FORs */
Line 98... Line 118...
98
 
118
 
99
  /* look for patterns start */
119
  /* look for patterns start */
100
  while (f->cmd[i] == ' ') i++;
120
  while (f->cmd[i] == ' ') i++;
101
  if (f->cmd[i] != '(') goto INVALID_SYNTAX;
121
  if (f->cmd[i] != '(') goto INVALID_SYNTAX;
102
  i++;
122
  i++;
103
  while (f->cmd[i] == ' ') i++;
123
  while (cmd_for_sepnorm(f->cmd[i]) == ' ') i++;
104
  f->nextpat = i;
124
  f->nextpat = i;
105
  /* look for patterns end */
125
  /* look for patterns end and normalize all separators to a space */
106
  while ((f->cmd[i] != ')') && (f->cmd[i] != 0)) i++;
126
  while ((f->cmd[i] != ')') && (f->cmd[i] != 0)) {
-
 
127
    f->cmd[i] = cmd_for_sepnorm(f->cmd[i]);
-
 
128
    i++;
-
 
129
  }
107
  if (f->cmd[i] != ')') goto INVALID_SYNTAX;
130
  if (f->cmd[i] != ')') goto INVALID_SYNTAX;
108
  f->cmd[i++] = 0; /* terminate patterns and move to next field */
131
  f->cmd[i++] = 0; /* terminate patterns and move to next field */
109
 
132
 
110
  /* look (and skip) the "DO" part */
133
  /* look (and skip) the "DO" part */
111
  while (f->cmd[i] == ' ') i++;
134
  while (f->cmd[i] == ' ') i++;