Exemple #1
0
String eval_sys(Mapping *m, Statement *source, Queue *repQueue) {
	String prepare = copy_string(m->sys->prepare);
	String eval = copy_string(m->sys->eval);
	Mapping *mapping = NULL;

	String* array = NULL;
	String* arraySource = NULL;
	String* arrayTarget = NULL;

	String prepareSource;
	String prepareTarget;
	String sourceFuncMacro;
	String sourceMacro;
	String targetFuncMacro;
	String targetMacro;

	if (!equals_string(prepare, "NIL")) {
		mapping = alloc_mapping();
		mapping->sys = NULL;
		if (strcmp(m->sys->name, DEF_MACRO) == 0) {
			mapping->isMacro = TRUE;
		} else {
			mapping->isMacro = FALSE;
		}

		array = split_string_once(prepare, '>');
		prepareSource = array[0];
		prepareTarget = array[1];

		arraySource = split_string_once(prepareSource, ',');
		sourceFuncMacro = trim_string(arraySource[0]);
		sourceMacro = trim_string(arraySource[1]);

		mapping->source = parse_macro(repQueue, sourceMacro);
		mapping->sourceFunc = parse_macro(repQueue, sourceFuncMacro);
		mapping->sourceStatement = parse(mapping->source);
		mapping->starter = to_dfa(mapping->sourceStatement);

		arrayTarget = split_string_once(prepareTarget, ',');
		targetFuncMacro = trim_string(arrayTarget[0]);
		targetMacro = trim_string(arrayTarget[1]);

		mapping->target = parse_macro(repQueue, targetMacro);
		mapping->targetFunc = parse_macro(repQueue, targetFuncMacro);
		mapping->targetStatement = parse(mapping->target);

		//enqueue(get_mappings(), mapping);
		add_mapping_to_trie(mapping);
	}

	if (!equals_string(eval, "NIL")) {
		return parse_macro(repQueue, eval);
	} else {
		return "";
	}
}
Exemple #2
0
/**
	слово:
		список в скобках {}
		подстановка выражения в скобках []
*/
int
parse_word(char *text,char **endptr,Tag *toptag) {
	char *p,*s;
	Tag *tag;
	tag=NULL;
	s=text;

	if (s==NULL || isblank(*s)||strchr(EXPTERM,*s)) return 1;
	if (toptag) tag=mark(WORD,text,text,toptag);

	while(*s) {
		p=s;
		switch(*s) {
			case '{' : parse_list(s,&s,tag);break;
			case '[' : parse_command(s,&s,tag);break;
			case '\'': parse_string(s,&s,tag);break;
			case '\"': parse_subst(s,&s,tag);break;
			case '$' : parse_variable(s,&s,tag);break;
			default:
				if (s[0]=='#' && s[1]!='#' && s[1]!='!') {
					parse_macro(s,&s,tag);
				} else if (s[0]=='#' && s[1]=='?' && s[2]=='>') {
					parse_print(s,&s,tag);
				} else if ((s[0]=='-' && isdigit(s[1])) || isdigit(*s))
					parse_numeric(s,&s,tag);
				else
					mark_cspn(CHARS,BLANK EXPTERM "(",s,&s,tag);
		}
		if (strchr(BLANK EXPTERM,*s)) break;
		if (p==s) break;
	}
	if (endptr) *endptr=s;
	return 0;
}
static struct Code *parse_fortran(struct TestFile *tf, int *need_array_it)
{
    struct Code *code = NEW0(struct Code);
    char *start = tf->read_pos, *tok, *save_pos;
    enum MacroType mtype;
    size_t len;

    code->type = FORTRAN_CODE;
    code->lineno = tf->lineno;

    // read lines until a recognized end sequence appears
    while (tf->read_pos < tf->file_end) {
        // look for end sequence
        save_pos = tf->read_pos;
        tok = next_token(tf, &len);
        assert(tok != NULL);
        if (is_test_token(tok, len) ||
            (same_token("end", 3, tok, len) && next_is_test_end_token(tf))) {
            break;
        } else if (tf->read_pos == tf->file_end) {
            break;
        } else { // not found, this is fortran
            tf->read_pos = save_pos;
        }

        if (find_macro(tf, &mtype, need_array_it)) {
            //  record initial fortran code
            code->u.c.str = start;
            code->u.c.len = tf->read_pos - start;
            // parse the macro
            tf->read_pos = tf->next_pos;
            code->next = parse_macro(tf, mtype, need_array_it);
            // parse_macro recurses to parse more code, so just return here
            if (!code->next)
                goto error;
            return code;
        } else {
            next_line(tf);
        }
    }
    if (tf->line_pos < tf->file_end) { // found non-fortran code
        // record bounds of fortran code
        code->u.c.str = start;
        code->u.c.len = tf->line_pos - start;
        tf->next_pos = tf->read_pos = tf->line_pos;
        return code;
    }
    syntax_error(tf);
 error:
    free_code(code);
    return NULL;
}
Exemple #4
0
static void _pascal parseconfig(FILE *fp)

{
	char	buffer[TEXTLEN];
	char   *keyword = NULL;
	char   *value = NULL;
	char   *s = NULL;

	memset(buffer, 0, TEXTLEN);

	while (!feof(fp)) {

		if (fgets(buffer, TEXTLEN, fp) == NULL)
			return;

		keyword = strtok(buffer, " \t\n\r");
		if (keyword) strlwr(keyword); else continue;
		if ((*keyword) == ';')
			continue;

		value = strtok(NULL, ";\n\r");

		if (value != NULL) {
			s = value + strlen(value) - 1;
			while ((s > value) && isspace(*s))
				*s-- = '\0';
		}

		while (value && *value && isspace(*value))
			if ((*value == '\n') || (*value == ';'))
				break;
			else
				value++;

		if (strcmp("attribution", keyword) == 0) {
			free(attribline);
			if (value)
				attribline = strdup(value);
			else
				attribline = NULL;
			continue;
		}

		if (!value) continue;

		if (strcmp("name",keyword) == 0) {
			check(value);
			username = strdup(value);
			check(username);
		}

		else if (strcmp("include", keyword) == 0) {
			FILE *ifp;
			if ((ifp = fopen(value,"rt")) != NULL) {
				parseconfig(ifp);
				fclose(ifp);
			}
		}

		else if (strcmp("outfile", keyword) == 0) {
			free(outfile);
			outfile = strdup(value);
		}

		else if (strcmp("uucp", keyword) == 0) {
			uucp_gate = parsenode(value);
			uucp_gate.notfound = 0;
		}

		else if (strcmp("lastread", keyword) == 0) {
			free(lastread);
			lastread = strdup(value);
		}

		else if (strcmp("tosslog", keyword) == 0) {
			free(confmail);
			confmail = strdup(value);
		}
#ifndef NOSPELL
		else if (strcmp("speller", keyword) == 0) {
			free(speller);
			speller = strdup(value);
		}
#endif

		else if (strcmp("quickbbs", keyword) == 0) {
			int i;
			if (quickbbs != NULL)
				free(quickbbs);
			quickbbs = strdup(value);
			i = strlen(quickbbs);
			if ((*(quickbbs + i - 1) != '\\') && 
			    (*(quickbbs + i - 1) != '/')) {
				char *s = calloc(1,i+2);
				strcat(strcpy(s,quickbbs),"/");
				free(quickbbs);
				quickbbs = strdup(s);
				free(s);
			}
		}

		else if (strcmp("video",keyword) == 0) {
			if (value) strlwr(value);
			if (strncmp(value,"direct",6) == 0)
				videomethod = DIRECT;
			else if (strncmp(value,"bios",4) == 0)
				videomethod = BIOS;
			else if (strncmp(value,"fossil",6) == 0)
				videomethod = FOSSIL;
			else if (strncmp(value,"ansi",4) == 0)
				videomethod = ANSI;
		}

		else if (strcmp("gate",keyword) == 0) {
			if (gate == 7)
				gate = 0;
			if (value) strlwr(value);
			if (strncmp(value,"zones",5) == 0)
				gate |= GZONES;
			else if (strncmp(value,"domains",7) == 0)
				gate |= GDOMAINS;
			else if (strncmp(value,"both",4) == 0)
				gate = GDOMAINS | GZONES;
			else if (strncmp(value,"none",4) == 0)
				gate = 0;
		}

		else if (strcmp("function",keyword) == 0) {
			int i;
			char *s;

			i = (int) strtol(value,&s,0);
			s = striplwhite(s);

			if ((i >= 0) && (i <= 40))
				macros[i] = parse_macro(s);
		}

		else if (strcmp("userlist", keyword) == 0) {
			fidolist = strdup(strtok(value,",\n"));
			if ((userlist = strtok(NULL,",\n")) != NULL)
				userlist = strdup(userlist);
		}

		else if (strcmp("address", keyword) == 0) {
			if (alias == NULL) {
				alias = (ADDRESS *) calloc(1, sizeof(ADDRESS));
				aliascount = 1;
			}
			else
				alias = (ADDRESS *) realloc(alias,++aliascount * sizeof(ADDRESS));
			alias[aliascount - 1] = parsenode(value);
		}

		else if (strcmp("videoseg", keyword) == 0)
			vbase = (int) strtol(value,NULL,0);

		else if (strcmp("privatenet", keyword) == 0)
			pointnet = (int) strtol(value,NULL,0);

		else if (strcmp("maxx", keyword) == 0)
			maxx = (int) strtol(value,NULL,0);

		else if (strcmp("maxy", keyword) == 0)
			maxy = (int) strtol(value,NULL,0);

		else if (strcmp("tabsize", keyword) == 0)
			tabsize = (int) strtol(value,NULL,0);

		else if (strcmp("right", keyword) == 0)
			rm = (int) strtol(value,NULL,0);

		else if (strcmp("quoteright", keyword) == 0)
			qm = (int) strtol(value,NULL,0);

		else if (strcmp("no",keyword) == 0) {
			if (value) strlwr(value);
			softcr ^=		 (strcmp("softcr", value) == 0);
			seenbys ^=		 (strcmp("seen-bys", value) == 0);
			tearline ^= 	 (strcmp("tearline", value) == 0);
			shownotes ^=	 (strcmp("shownotes", value) == 0);
			confirmations ^= (strcmp("confirm", value) == 0);
			msgids ^=		 (strcmp("msgids",value) == 0);
			stripnotes ^=	 (strcmp("strip",value) == 0);
			opusdate ^=      (strcmp("opusdate",value) == 0);
			swapping ^= (strcmp("swapping",value) == 0);
		}

		else if (!(strcmp("editkey", keyword))||!(strcmp("readkey",keyword))) { /*WRA*/
			int scancode;

			if (value) {
				strlwr(value);
				scancode = (int) strtol(value,&value,0);
				value = striplwhite(value);
			}
			if (*keyword == 'e')
				e_assignkey(scancode,value);
			else
				r_assignkey(scancode,value);
		}

		else if (strcmp("quote", keyword) == 0) {
			char *s;
			if (quotestr != NULL)
				free(quotestr);
			s = quotestr = strdup(value);
			while (*s) {
				*s = (*s == (char) '_')?(char)' ':*s;
				s++;
			}
		}

		else if (strcmp("origin", keyword) == 0) {
			if (origin != NULL)
				free(origin);
			origin = strdup(value);
		}

		else if ((strcmp("quick", keyword) == 0) ||
			 (strcmp("fido", keyword) == 0)) {
			parsemail(keyword,value);
		}

		else if (strcmp("color", keyword) == 0) {
			keyword = strtok(value," \t");
			value	= strtok(NULL,"\0");
			set_colors(keyword,value);
		}

		memset(buffer, 0, TEXTLEN);
	}
}
Exemple #5
0
/*
 * Name:    parse_line
 * Purpose: real work horse of the configuration utility, figure out what
 *          we need to do with each line of the config file.
 * Date:    June 5, 1992
 * Passed:  line:  line that contains the text to parse
 */
void parse_line( char *line )
{
char key[1042];         /* buffer to hold any token that we parse */
char *residue;          /* pointer to next item in line, if it exists */
int key_no;             /* index into key array */
int parent_key;         /* 1st of two-combination keys */
int color;              /* color field */
int mode_index;         /* index in mode array */
int func_no;            /* function number we want to assign to a key */
int color_no;           /* attribute we want to assign to a color field */
int mode_no;            /* mode number we want to assign to a mode */
int found;              /* boolean, did we find a valid key, color, or mode? */
int i;

   /*
    * find the first token and put it in key.  residue points to next token.
    */
   residue = parse_token( line, key );
   if (*key != '\0' && *key != ';') {
      if (strlen( key ) > 1) {
         /*
          * try to find a valid key
          */
         found = FALSE;
         key_no = search( key, valid_keys, AVAIL_KEYS-1 );
         if (key_no != ERROR) {
            /*
             * find the function assignment
             */
            found = TRUE;
            if (residue != NULL) {
               residue = parse_token( residue, key );

               /*
                * if this is not a comment, find the function to assign
                *   to key.  clear any previous macro or key assignment.
                */
               if (*key != '\0' && *key != ';') {
                  func_no = search( key, valid_func, NUM_FUNC );
                  if (func_no != ERROR) {
                     clear_previous_twokey( key_no );
                     clear_previous_macro( key_no );
                     key_func.key[key_no] = func_no;
                     if (func_no == PlayBack)
                        parse_macro( key_no, residue );
                  } else {
                     parent_key = key_no;

                     /*
                      * was the second key one letter?
                      */
                     if (strlen( key ) == 1) {
                        key_no = *key;
                        residue = parse_token( residue, key );
                        if (*key != '\0' && *key != ';') {
                           func_no = search( key, valid_func, NUM_FUNC );
                           if (func_no != ERROR && func_no != PlayBack) {
                              if (insert_twokey( parent_key+256, key_no,
                                                          func_no ) == ERROR) {
                                 printf( "==> %s", line_in );
                                 printf( "Out of room for two-key: line %u  : function %s\n",
                                      line_no, key );
                              }
                           } else {
                              printf( "==> %s", line_in );
                              if ( func_no == ERROR)
                                 printf( "Unrecognized function: line %u  : function %s\n",
                                         line_no, key );
                              else
                                 printf( "Cannot assign a macro to two-keys: line %u  : function %s\n",
                                         line_no, key );
                           }
                        }
                     } else {
                        residue = parse_token( residue, key );
                        key_no = search( key, valid_keys, AVAIL_KEYS-1 );
                        if (key_no != ERROR && *key != '\0' && *key != ';') {
                           func_no = search( key, valid_func, NUM_FUNC );
                           if (func_no != ERROR && func_no != PlayBack) {
                              if (insert_twokey( parent_key+256, key_no+256,
                                                        func_no )  == ERROR) {
                                 printf( "==> %s", line_in );
                                 printf( "Out of room for two-key: line %u  : function %s\n",
                                      line_no, key );
                              }
                           } else {
                              printf( "==> %s", line_in );
                              if ( func_no == ERROR)
                                 printf( "Unrecognized function: line %u  : function %s\n",
                                         line_no, key );
                              else
                                 printf( "Cannot assign a macro to two-keys: line %u  : function %s\n",
                                         line_no, key );
                           }
                        } else {
                           printf( "==> %s", line_in );
                           printf( "Unrecognized function: line %u  : function %s\n",
                                   line_no, key );
                        }
                     }
                  }
               }
            }
         }

         /*
          * valid key not found, now try a valid color
          */
         if (!found) {
            color = search( key, valid_colors, (NUM_COLORS * 2) - 1 );
            if (color != ERROR) {
               if (*key == 'm')
                  i = 0;
               else
                  i = 1;
               found = TRUE;
               if (residue != NULL) {
                  residue = parse_token( residue, key );

                  /*
                   * we found a color field and attribute.  now, make sure
                   *   everything is everything before we assign the attribute
                   *   to the color field.
                   */
                  if (*key != '\0' && *key != ';') {
                     color_no = atoi( key );
                     if (color_no >= 0 && color_no <= 127)
                        temp_colours.clr[i][color] = color_no;
                     else {
                        printf( "==> %s", line_in );
                        printf( "Color number out of range: line %u  : number %s\n",
                                 line_no, key );
                     }
                  }
               }
            }
         }

         /*
          * valid color not found, now try a valid mode
          */
         if (!found) {
            mode_index = search( key, valid_modes, NUM_MODES-1 );
            if (mode_index != ERROR) {
               found = TRUE;

               /*
                * if we find a valid mode, we need to search different
                *   option arrays before we find a valid assignment.
                */
               if (residue != NULL) {
                  residue = parse_token( residue, key );
                  if (*key != '\0' && *key != ';') {
                     switch ( mode_index ) {
                        case Ins         :
                        case Ind         :
                        case Smart       :
                        case Trim        :
                        case Eol         :
                        case Backup      :
                        case Ruler       :
                        case InflateTabs :
                        case JustRM      :
                           mode_no = search( key, off_on, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Off/On error: " );
                           }
                           break;
                        case LTAB     :
                        case PTAB     :
                           mode_no = atoi( key );
                           if (mode_no > 520 || mode_no < 1) {
                              mode_no = ERROR;
                              printf( "==> %s", line_in );
                              printf( "Tab error: " );
                           }
                           break;
                        case Left    :
                           mode_no = atoi( key );
                           if (mode_no < 1 || mode_no > modes[Right]) {
                              mode_no = ERROR;
                              printf( "==> %s", line_in );
                              printf( "Left margin error: " );
                           } else
                              --mode_no;
                           break;
                        case Para    :
                           mode_no = atoi( key );
                           if (mode_no < 1 || mode_no > modes[Right]) {
                              mode_no = ERROR;
                              printf( "==> %s", line_in );
                              printf( "Paragraph margin error: " );
                           } else
                              --mode_no;
                           break;
                        case Right   :
                           mode_no = atoi( key );
                           if (mode_no < modes[Left] || mode_no > 1040) {
                              mode_no = ERROR;
                              printf( "==> %s", line_in );
                              printf( "Right margin error: " );
                           } else
                              --mode_no;
                           break;
                        case Crlf    :
                           mode_no = search( key, valid_crlf, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "CRLF or LF error: " );
                           }
                           break;
                        case WW      :
                           mode_no = search( key, valid_wraps, 2 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Word wrap error: " );
                           }
                           break;
                        case Size    :
                           mode_no = search( key, valid_cursor, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Cursor size error: " );
                           }
                           break;
                        case Write_Z :
                           mode_no = search( key, valid_z, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Control Z error: " );
                           }
                           break;
                        case Date    :
                           mode_no = search( key, valid_dates, 5 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Date format error: " );
                           }
                           break;
                        case Time    :
                           mode_no = search( key, valid_times, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Time format error: " );
                           }
                           break;
                        case Initcase    :
                           mode_no = search( key, init_case_modes, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Initial Case Mode error: " );
                           }
                           break;
                        case Match   :
                           for (i=0; i<256; i++)
                              sort_order.match[i] = (char)i;
                           new_sort_order( key, sort_order.match );
                           break;
                        case Ignore  :
                           for (i=0; i<256; i++)
                              sort_order.ignore[i] = (char)i;
                           for (i=65; i<91; i++)
                              sort_order.ignore[i] = (char)(i + 32);
                           new_sort_order( key, sort_order.ignore );
                           break;
                     }
                     if (mode_no != ERROR)
                        modes[mode_index] = mode_no;
                     else
                        printf( " line = %u  :  unknown mode = %s\n",
                              line_no, key );
                  }
               }
            }
         }
         if (!found) {
            printf( "==> %s", line_in );
            printf( "Unrecognized editor setting: line %u  :  %s\n", line_no, key );
         }
      }
   }
}