📄 int_parser.c
字号:
/* If escaped or in between quotes and no dollars --> just the bracket */ if (flagEscape || (quote && (line == theLine || *(line-1) != '$'))) { Parse1Char(line); flagEscape = 0; break; } /* We look for the matching ']' */ bracket = LookForBracketScript(theLine,line); if (bracket == NULL) return(-1); /* * if the character before is a valid variable character then it means that this is an extraction type of [] */ if (line != theLine && IsValidSymbolChar(*(line-1))) { /* We parse the [ */ Parse1Char(line); /* We set the matching bracket */ bracketExt[nBracketExt] = bracket; nBracketExt++; break; } /* * Otherwise it is a script type of [] */ /* We just copy all the characters in between the [] */ i = bracket-line+1; TestAlloc(i); strncpy(newLine,line,i); nNewLine += i; newLine += i; /* Should we remember the position of the brackets ? */ if (flagDollars == NO) { /* Case of a regular [] */ if (nPtr >= MaxNPtrs-2) Errorf("ParseScriptLineBegEnd() : Too many '[...]' in script line"); thePtrs[nPtr] = newLine-i; nPtr++; thePtrs[nPtr] = newLine-1; nPtr++; } else if (line != theLine && *(line-1) == '$' && flagSubst) { /* Case of a $[] -> the opening brcket has already been stored */ if (nPtr >= MaxNPtrs-1) Errorf("ParseScriptLineBegEnd() : Too many '$' in script line"); thePtrs[nPtr] = newLine-1; nPtr++; } /* Jump to the character right after the closing ] */ line = bracket+1; break; case ']' : /* If escaped or quoted --> just the bracket */ if (flagEscape || quote) { Parse1Char(line); flagEscape = 0; break; } /* If it is the closing bracketExt --> just parse it */ if (nBracketExt != 0 && bracketExt[nBracketExt-1] == line) { Parse1Char(line); nBracketExt--; break; } /* Maybe it is the endBracket */ if (flagEndIsBracket) {flagStop = YES; continue;} /* Otherwise --> error */ SyntaxError("Missing the corresponding [",theLine,lineError); return(-1); /*************************************** * {} Signs ***************************************/ case '{' : /* If escaped or quote --> just the brace */ if (flagEscape || quote) { Parse1Char(line); flagEscape = 0; break; } /* We look for the matching '}' */ bracket = LookForBracketScript(theLine,line); if (bracket == NULL) return(-1); /* We just copy all the characters in between */ i = bracket-line+1; TestAlloc(i); strncpy(newLine,line,i); nNewLine += i; newLine += i; line = bracket+1; break; case '}' : /* If escaped --> just the brace */ if (flagEscape || quote) { Parse1Char(line); flagEscape = 0; break; } /* If surrounding brace --> just skip it */ else if (line == braceEnd) { line++; break; } /* Otherwise --> error */ else { SyntaxError("Missing the corresponding {",theLine,lineError); return(-1); } break; /*************************************** * ` Sign ***************************************/ case '`' : /* If escaped OR if within quote --> just the ( */ if (flagEscape || quote) { Parse1Char(line); flagEscape = 0; break; } /* If it is the closing bquote --> just skip it */ if (bquote == line) { line++; bquote = NULL; break; } /* Otherwise we just set the matching bquote */ bracket = LookForBracketScript(theLine,line); if (bracket == NULL) return(-1); bquote = bracket; line++; break; /*************************************** * () Sign ***************************************/ case '(' : /* We parse it */ Parse1Char(line); /* If escaped OR if within quote --> just the ( */ if (flagEscape || quote) { flagEscape = 0; break; } /* Otherwise we just set the matching parenthesis */ bracket = LookForBracketScript(theLine,line-1); if (bracket == NULL) return(-1); par[nPar] = bracket; nPar++; break; case ')' : /* If escaped OR if within quote --> just the ) */ if (flagEscape || quote) { Parse1Char(line); flagEscape = 0; break; } /* If it is the closing par --> just parse it */ if (nPar != 0 && par[nPar-1] == line) { Parse1Char(line); nPar--; break; } /* Otherwise --> error */ else { SyntaxError("Missing the corresponding (",theLine,lineError); return(-1); } break; /*************************************** * " or ' Signs ***************************************/ case '"' : case '\'' : /* If escaped --> just the quote */ if (flagEscape) { Parse1Char(line); flagEscape = 0; break; } /* If it is the closing quote --> just the quote and close it */ if (quote == line) { Parse1Char(line); quote = NULL; break; } /* if within a different quote --> just the quote */ if (quote != NULL) { Parse1Char(line); break; } /* Otherwise we just set the matching quote */ bracket = LookForBracketScript(theLine,line); if (bracket == NULL) return(-1); quote = bracket; Parse1Char(line); break; /*************************************** * $ Sign ***************************************/ case '$' : /* If escaped OR or no substitution --> just the dollar */ if (flagEscape || !flagSubst) { Parse1Char(line); flagEscape = 0; break; } /* Set the dollar mode if not set */ if (flagDollars == NO) { flagDollars = YES; nPtr = 0; } /* Store the new dollar sign */ if (nPtr >= MaxNPtrs-1) Errorf("ParseScriptLineBegEnd() : Too many '$' signs in script line"); thePtrs[nPtr] = newLine; nPtr++; *newLine = '$'; nNewLine += 1; line += 1; newLine += 1; break; /*************************************** * Word/line separators : '\n', '\r', ' ', '\t' ***************************************/ case '\n': case '\r' : /* If escaped --> just skip it */ if (flagEscape) { flagEscape = 0; if (line[0] == '\n' && line[1] == '\r' || line[0] == '\r' && line[1] == '\n') line+=2; else line++; break; } /* If within (b)quotes or parenthesis --> just the character */ if (nBracketExt != 0 || nPar!=0 || bquote || quote) { Parse1Char(line); break; } /* Otherwise, let's end the word */ flagCreateWord = YES; break; case ' ': case '\t' : /* the ' ' and '\t' caharacters cannot be escaped */ if (flagEscape) { SyntaxError("A space or a tabulation character cannot be escaped",theLine,lineError); return(-2); } /* If within (b)quotes or parenthesis or setv --> just the character */ if (nBracketExt != 0 || nPar!=0 || bquote || quote || flagSetv1) { Parse1Char(line); break; } /* Otherwise, let's end the word */ flagCreateWord = YES; break; case ';': /* Case it is escaped */ if (flagEscape || line[1] != ';') { Parse1Char(line); flagEscape = 0; break; } /* If within (b)quotes or parenthesis --> just the character */ if (nBracketExt != 0 || nPar!=0 || bquote || quote) { Parse1Char(line); break; } flagCreateWord = YES; break; /*************************************** * \ character ***************************************/ case '\\': /* If escaped --> just the \ */ if (flagEscape) { Parse1Char(line); flagEscape = 0; break; } /* If within quotes --> just the \ and the next char */ if (quote) { Parse1Char(line); Parse1Char(line); flagEscape = 0; break; } /* The escape character */ flagEscape = 1; line++; break; /*************************************** * :: character ***************************************/ case ':': /* Case it is escaped or there is no '=' afterwards */ if (flagEscape || line[1] != '=') { /* If escaped OR if no ':' after or if not a whole word then just the character */ if (nBracketExt != 0 || nPar!=0 || quote || bquote || flagEscape || line == theLine || *(line-1) != ' ' || *(line+1) != ':' || (*(line+1) != '\0' && *(line+2) != ' ' && *(line+2) != '\0')) { Parse1Char(line); flagEscape = 0; break; } if (redirectChar != NULL) { SyntaxError("You cannot use the redirection symbols '::' twice",theLine,lineError); return(-2); } /* The redirect word number */ redirectChar = line; theRedirectWord = nWord; Parse1Char(line); Parse1Char(line); flagRedirect = 2; continue; } /* If an '=' afterwards we just execute the following code */ /*************************************** * = Character ***************************************/ case '+' : case '-' : case '*' : case '/' : case '^' : case '%' : if (flagEscape) { i = GetCharFromEscapeScript(*line); if (i == -1) { SyntaxError("This character cannot be escaped",theLine,lineError+1); return(-2); } else { Parse1Char(line); *(newLine-1) = i; } flagEscape = 0; } /* * If there is an '=' after the '+' and the '+' is the first character of the line or in the first word or at the begining of the second word * this is a setv command. Otherwise it is a regular character */ if (line[1] != '=' || line[0] == '/' && line[1] == '/' && line[2] != '=' || nWord!=0 && nWord>=2 && (nWord!=1 || (theEndWords[0]-theBegWords[0]+1 != nNewLine && theEndWords[0]-theBegWords[0]+2 != nNewLine))) { Parse1Char(line); break; } /* We set the setv flag */ flagSetv1 = YES; /* * In case this is the begining of the 2nd word, we parse the 2 characters and create a world * If it is in the 1st word, we just ask to create a word and wait for the second pass in this code */ if (nWord == 1) { if (line[0] == '/' && line[1] == '/') {Parse1Char(line);} Parse1Char(line); Parse1Char(line); } flagCreateWord = YES; break; case '=' : /* If escaped OR if within braces --> just the = */ if (nBracketExt != 0 || flagEscape || nPar!=0 || quote || *(line+1) == '=' || (line != theLine && (*(line-1) == '=' || *(line-1) == '!' || *(line-1) == '<' || *(line-1) == '>'))) { Parse1Char(line); flagEscape = 0; break; } /* * If the '=' is the first character of the line or in the first word or at the begining (or the right after the begining) of the second word * this is a setv command. Otherwise it is a regular character */ if (nWord!=0 && nWord>=2 || (nWord==1 && (theEndWords[0]-theBegWords[0]+1 != nNewLine && theEndWords[0]-theBegWords[0]+2 != nNewLine))) { Parse1Char(line); break; } /* Error if the word starts with a number ----> NON on peut faire 1+2= */ /* if (isdigit(*(theBegWords[0])) || *(theBegWords[0]) == '-') { SyntaxError("Bad name for variable",theLine,start); return(-2); } */ /* We set the setv flag */ flagSetv1 = YES; /* * In case this is the begining of the 2nd word, we parse the character and create a world * If it is in the 1st word, we just ask to create a word and wait for the second pass in this code */ if (nWord == 1) {Parse1Char(line);} flagCreateWord = YES;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -