示例#1
0
/**
 * @brief Parses in the block context for the given node
 * 
 * The block context parses comments and data identifiers, any other
 * data is invalid in this context.
 * 
 * The block context ends when a closing hash marker is found.
 */
void NepParser::genCtxBlock(Nepeta::Node &node)
{
	size_t stLine = getCurLine(), stCol = getCurCol();
	
	while( notEof() ) {
		char ch = getCurRaw();
		
		// Skip whitespace
		if( isWhite(ch) ) {
			iterCur();
		// Check for data block marker
		} else if( checkIdentifier(ch) || checkHash(ch) ) {
			// Parse the data block.
			// If an end marker is found, this returns false
			if(!genCtxData(node))
				return;
		// Check for comment marker
		} else if( checkComment(ch) ) {
			helpSkipComment();
		// Any other character is invalid, skip to the next line
		} else {
			mScript.addError( Nepeta::ErrIllegalCharacter, std::string(1,ch),
				getCurLine(), getCurCol()
			);
			helpSeekNewline(false);
		}
	}
	
	if(node.getParent()) {
		mScript.addError( Nepeta::ErrPrematureEnd, "",
		stLine, stCol, getCurLine(), getCurCol());
	}
}
示例#2
0
文件: c.c 项目: LucasAbreu/c
// Prints all the files in either ascending or descending order
void printAllOrder(char newpath[], bool desc) {
    printCurrentComment(newpath);
    printf("\n");

    FILE *fp;
    int status;
    char path[1035];

    /* Open the command for reading. */
    if (desc) {
        fp = popen("/bin/ls -tr  ", "r");
    } else {
        fp = popen("/bin/ls -t  ", "r");
    }
    if (fp == NULL) {
        printf("Failed to run command\n" );
        exit;
    }

    /* Read the output a line at a time - output it. */
    while (fgets(path, sizeof(path)-1, fp) != NULL) {
        strip(path);
        // printf("%s", path);
        checkComment(path, newpath);
    }
    /* close */
    pclose(fp);
}
示例#3
0
文件: c.c 项目: AlwaysLately/c
// Prints all the files in the current directory
void printFiles(const char *path) {
	// Print the current directories comment
	printCurrentComment(path);
	printf("\n");

	DIR *mydir = opendir(path);
	struct dirent *entry = NULL;

	while((entry = readdir(mydir))) { // If we get EOF, the expression is NULL and the loop stops
		// We will not show the dot files
		if (entry->d_name[0] == '.') {
			continue;
		}
		checkComment(entry->d_name, path);
	}
	closedir(mydir);
}
示例#4
0
/**
* @brief analyseLine
* @param line Zeile für analyse
*/
void FileReport::analyseLine(string& line){
	int length = line.length();
	checkComment(line);
	for (int i = 0; i < length; ++i) {
		if (checkUpperCase(line[i])){
			continue;
		}
		if (checkLowerCase(line[i])){
			continue;
		}
		if (checkDigit(line[i])){
			continue;
		}
		checkSpecialCharacter(line[i]);
	}
	computeCommentDensity();
	lines++;
}
示例#5
0
 inline void FileParse::getBody(std::ifstream& fin) {
   // Look for heads
   char c;
   bool end = false;
   while (!fin.eof() && !end) {
     passWhiteSpaces(fin);
     if (!fin.eof()) fin.get(c);
     else return;
     if (c=='}') // End of a body
       return;
     else if (c=='/') { // Could be the start of a comment
       checkComment(fin);
     }
     else {
       fin.putback(c);
       getHead(fin);
     }
   }
 }
示例#6
0
文件: c.c 项目: LucasAbreu/c
int main (int argc, const char * argv[]) {

    // Get the current directory
    char cwd[1024];
    if (getcwd(cwd, sizeof(cwd)) != NULL)
        ;
    else
        perror("getcwd() error");

    int numargs, all=0, asc=0, desc=0, push=0, uk=0, help=0, current=0, clean=0;
    const char *c;

    numargs = argc;

    while (--numargs > 0) {
        c = argv[numargs];

        if (!strcmp(argv[numargs], "all"))
            all = 1;
        else if (!strcmp(argv[numargs], "-h") || !strcmp(argv[numargs], "--help"))
            help = 1;
        else if (!strcmp(argv[numargs], "."))
            current = 1;
        else if (!strcmp(argv[numargs], "-p") || !strcmp(argv[numargs], "--push"))
            push = 1;
        else if (!strcmp(argv[numargs], "-"))
            desc = 1;
        else if (!strcmp(argv[numargs], "+"))
            asc = 1;
        else if (!strcmp(argv[numargs], "clean"))
            clean = 1;
        else
            uk++;
    }

    int args;
    args = argc;

    if (uk > 2) {
        printUsage();
        return 1;
    }

    switch(args) {
        // Show the comment for the current directory
        case 1: printUsage();
                return 1;
                break;
        case 2:
                // Show the help menu
                if (help) {
                    printUsage();
                    return 1;
                }
                // Show all the files
                else if (all) {
                    makeDir(cwd);
                    printFiles(cwd);
                }
                // Show comment for the current directory
                else if (current) {
                    // checkComment(argv[1], cwd);
                    printCurrentComment(cwd);
                }
                // Show comment for the entered file
                else {
                    // char *file = argv[1];
                    makeDir(cwd);
                    checkComment(argv[1], cwd);
                }
                break;
        case 3:

                if ( current && !clean ) {										// Add comment to the current directory
                    // char *file;
                    // file = "CURRENT";
                    addComment(argv[1], cwd, argv[2], false);
                } else if (all && desc) {					// Print all files in descending order
                    makeDir(cwd);
                    printAllOrder(cwd, true);
                } else if (all && asc) {					// Print all files in ascending order
                    makeDir(cwd);
                    printAllOrder(cwd, false);
                } else if ( clean ){
                    cleanComment( argv[1] );                 // Clean file comment
                }
                else {														// Add comment to to given file
                    makeDir(cwd);
                    addComment(argv[1], cwd, argv[2], false);
                }
                break;

        case 4:
                // Push comment to the current directory
                if (current && push) {
                    addComment(argv[1], cwd, argv[3], true);
                    // Add a comment to the given filename
                }
                // Push comment to given file
                else	if ( push) {
                    makeDir(cwd);
                    addComment(argv[1], cwd, argv[3], true);
                }
                break;

                // Not certain
        default: printUsage();
    }
    return 0;
}
示例#7
0
int load_pgn(const char* filename, Board *p_board) {
    int turn, newturn, color = NONE;
    int result = 0, ret = 0;
    Move m;
    char periodstr[4], movestr[16], temp;
    periodstr[3] = 0;
    movestr[15] = 0;

    FILE* file = fopen(filename, "r");
    if (!file) {
        fprintf(stderr, "load_pgn: unable to open %s\n", filename);
        return 1;
    }

    do result = fscanf(file, "[%*[^]]%c ", &temp);
    while (result > 0 && result != EOF);

    while (1) {

        if (checkComment(file)) break;

        do result = fscanf(file, "{%*[^}]%c ", &temp);
        while (result > 0 && result != EOF);

        if (checkComment(file)) break;

        result = fscanf(file, "%d%3s ", &newturn, periodstr);
        if (result == EOF) break;
        else if (result == 0) {
            if (color == NONE) {
                fprintf(stderr, "load_pgn: expected turn number\n");
                ret = 1;
                break;
            }
        } else {
            if (!strcmp(periodstr, "."))
                color = W;
            else if (!strcmp(periodstr, "..."))
                color = B;
            else if (periodstr[0] == '/' || periodstr[0] == '-')
                break;
            else {
                fprintf(stderr, "load_pgn: expected 1 or 3 periods following turn number\n");
                ret = 1;
                break;
            }
            turn = newturn;
        }

        if (checkComment(file)) break;

        result = fscanf(file, "%15s ", movestr);
        if (result == EOF) {
            if (turn != newturn) {
                fprintf(stderr, "load_pgn: unexpected EOF after turn number\n");
                ret = 1;
            }
            break;
        }
        if (!isalpha(movestr[0])) {
            fprintf(stderr, "load_pgn: unexpected character in move string\n");
            ret = 1;
            break;
        }

        // TODO get m and make_move(p_board, m);
        printf("Turn %d color %s string %s\n", turn, (color == W)? "white" :
            (color == B)? "black" : "none", movestr);
        m = notation_to_move(p_board, movestr);
        print_move(m);
        make_move(p_board, m);
        display_board(p_board);
        if (color == W) color = B;
        else color = NONE;

    }
    fclose(file);
    return ret;
}
示例#8
0
void Control::interpretator(string line)
{

  /*** Transforms to lower case ***/
  //transform(line.begin(), line.end(), line.begin(),::tolower);

  /*** check for commentation ***/
  string checkComment(line,0,1);
  if(checkComment == "#" || line.size()<2)
    return;

  /*** replaces '{' and '}' with ' { ' and ' } ' ***/
  for(unsigned int i=0; i<line.size(); i++)
    {
      if(string(line,i,1) =="{")
	{
	  line.replace(i, 1, string(" { "),0,3);
	  i++;
	}
      else if(string(line,i,1)=="}")
	{
	  line.replace(i, 1, string(" } "),0,3);
	  i++;
	}
    }  

  /*** break command into words ***/
  vector<string> words;
  words.clear();
  char temp[300];
  istringstream stream(line.c_str());
  while(stream>>temp)
    words.push_back(removeWhite(string(temp)));

  /*** check for lines with only white space ***/
  if(words.size() < 1)
    return;
  /*
  printf("Control has the words:\n");
  for(int i=0;i<words.size();i++)
    printf("'%s' ",words[i].c_str());
  printf("\n");
  */
  
  try
    {
      string com = words.at(0);

      if(com == "load")
	{
	if(words.size() > 2)
	  load(words.at(1), words.at(2));
	else
	  {
	    char no[6];
	    sprintf(no, "%d", soups.size());	 
	    load(words.at(1), string("AutoSoup") + string(no));
	  }
	}
      else if(com == "loadtosoup")
	{
	  if(words.size() > 3)
	    loadToSoup(atoi(words.at(1).c_str()), words.at(2), words.at(3));
	  else
	    {
	      char no[6];
	      sprintf(no, "%d", soups.size());	 
	      load(words.at(1), string("AutoSoup") + string(no));
	    }
	}
      else if(com == "stat")
	stat();
      else if(com == "list")
	list();
      else if(com == "clear")
	clear();
      else if(com == "task")
	doTask(words);
      else if(com == "script")
	do_script(words);
      else if(com == "exit")
	return;
      else
	printf("Don't understand the command '%s'!\n",words.at(0).c_str());
    }
  catch (...)
    {
      printf("The command %s caused a critical error!\n",line.c_str());
    }


}
示例#9
0
/**Generalized parsing function.
 * Processes the file stream character-by-character and
 * returns a pointer to a PDFToken.
 * Used by the parser for the majority of situations.
 */
PDFToken *getNextToken(FILE *file) {
	
	char c;
	uint32_t charCount = 0;
    PDFToken *token;
	PDFTokenizeState state;
	
	if ((token = newPDFToken()) == NULL) {
		foxLog(FATAL, "%s: Could not allocate space for new token.\n", __func__);
		return NULL;
	}
	
	state = START;

#ifdef PDF_FOX_SHOW_DEBUG
    foxLog(PRINT, "\n\t\tFile bytes: ");
#endif


	while ((c = fgetc(file)) != EOF) {

#ifdef PDF_FOX_SHOW_DEBUG
        foxLog(PRINT, "%c", c);
#endif

		switch (state) {
			case START:

				switch (c) {
					case '/':
						state = INNAME;
						charCount++;
						break;

				    case '<':
						state = INANGLE;
						break;

					case '>':
						state = INCLOSEANGLE;
						break;

					case '%':
						state = INCOMMENT;
					    charCount++;	
						break;

					case '+':
					case '-':
						state = INREAL;
						charCount++;
						break;

					case '[':
						token->type = OPENARRAY;
						goto ACCEPT;

					case ']':
						token->type = CLOSEARRAY;
						goto ACCEPT;

					case '(':
						token->type = OPENPAREN;
						goto ACCEPT;

					case ')':
						token->type = CLOSEPAREN;
						goto ACCEPT;

                    case EOF:
						token->type = ENDOFFILE;
						goto ACCEPT;

					default:
						if (!isWhitespace(c)) {
			    			if (isalpha(c)) {
				    			state = INIDENT;
					    		charCount++;
				    		}
						    else if (isdigit(c)) {
							    state = INNUMBER;	
    							charCount++;
	    					}
		    				else {
			    				foxLog(NONFATAL, "%s: Unrecognized starting character.\n", __func__);
                                goto GNT_ERROR;
					    	}
						}
						break;

				}
				break;

			case INCOMMENT:
				if (c == '\r' || c == '\n') {
					if (!backupChar(file, charCount+1)) {
						goto GNT_FATAL;
					}
                    if (!consumeToken(file, charCount, token)) {
						goto GNT_FATAL;
					}
				    checkComment(token);
					if (token->type == TOK_ERROR) {
						token->type = COMMENT;
					}	
				    
				    c = fgetc(file);
                    if (c != '\n') {
						if (!backupChar(file, 1)) {
							goto GNT_FATAL;
						}
					}
					goto ACCEPT;
				}

				charCount++;
				break;

			case INANGLE:
				if (c == '<') {
					token->type = OPENDICT;
				}
				else {
					token->type = OPENANGLE;
                    if (!backupChar(file, 1)) {
						goto GNT_FATAL;
					}
				}
				goto ACCEPT;

            case INCLOSEANGLE:
				if (c == '>') {
					token->type = CLOSEDICT;
				}
				else {
					token->type = CLOSEANGLE;
	                if (!backupChar(file, 1)) {
						goto GNT_FATAL;
					}
				}
				goto ACCEPT;

            case INNAME:
                if (!isWhitespace(c) && !isDelimiter(c)) {
                    charCount++; 
                }
                else {
					if (!backupChar(file, charCount+1)) {
						goto GNT_FATAL;
					}
					if (!consumeToken(file, charCount, token)) {
						goto GNT_FATAL;
					}
                    //checkNameKeyword(token);
                    //if (token->type == ERROR) {
                        token->type = NAME;
                    //}

                    goto ACCEPT;
                }
                break;

            case INIDENT:
				if (!isWhitespace(c) && !isDelimiter(c)) {
				    charCount++;
				}
				else {
					if (!backupChar(file, charCount+1)) {
						goto GNT_FATAL;
					}
					if (!consumeToken(file, charCount, token)) {
						goto GNT_FATAL;
					}
                    checkIdentKeyword(token);
					if (token->type == STREAM) {
						do {
							c = fgetc(file);
						} while (c != '\n');
					}
					else {
    					if (token->type == TOK_ERROR) {
                            token->type = IDENT;
                        }
					}
                    goto ACCEPT;
				}
				break;

			case INNUMBER:
				if (isdigit(c)) {
				    charCount++;
				}
				else if (c == '.') {
					charCount++;
					state = INREAL;
				}
				else {
                    if (!backupChar(file, charCount+1)) {
						goto GNT_FATAL;
					}
					if (!consumeToken(file, charCount, token)) {
						goto GNT_FATAL;
					}

                    token->type = INTEGER;

                    goto ACCEPT;
				}
				break;

			case INREAL:
                if (isdigit(c) || c == '.') {
                    charCount++;
                }
                else {
                    if (!backupChar(file, charCount+1)) {
						goto GNT_FATAL;	
					}
                    if (!consumeToken(file, charCount, token)) {
						goto GNT_FATAL;
					}

                    token->type = REAL;

                    goto ACCEPT;
                }
				break;

			default:
				foxLog(FATAL, "%s: Could not identify token.\n", __func__);
				goto GNT_FATAL;
				break;
		}
	}

if (c == EOF) {
	foxLog(PDF_DEBUG, "%s: End of file.\n", __func__);
    token->type = ENDOFFILE;
    return token;
}

GNT_FATAL:
    foxLog(FATAL, "%s: GNT_FATAL\n", __func__);
    destroyPDFToken(token);
	return NULL;

GNT_ERROR:
	foxLog(NONFATAL, "%s: GNT_ERROR\n", __func__);
    token->type = TOK_ERROR;

ACCEPT:
#ifdef PDF_FOX_SHOW_DEBUG
    foxLog(PRINT, "\n");
#endif
	return token;

}
示例#10
0
文件: c.c 项目: AlwaysLately/c
int main (int argc, const char *argv[]) {
	// Get the current directory
	char cwd[1024];
	if (!getcwd(cwd, sizeof(cwd))) {
		perror("getcwd() error");
	}

	int numargs, all = 0, asc = 0, desc = 0, push = 0, uk = 0, help = 0, current = 0;
	const char *c;

	numargs = argc;

	// TODO: Convert to getopt
	while (--numargs > 0) {
		c = argv[numargs];

		if (!strcmp(argv[numargs], "all"))
			all = 1;
		else if (!strcmp(argv[numargs], "-h") || !strcmp(argv[numargs], "--help"))
			help = 1;
		else if (!strcmp(argv[numargs], "."))
			current = 1;
		else if (!strcmp(argv[numargs], "-p") || !strcmp(argv[numargs], "--push"))
			push = 1;
		else if (!strcmp(argv[numargs], "-"))
			desc = 1;
		else if (!strcmp(argv[numargs], "+"))
			asc = 1;
		else
			uk++;
	}

	int args;
	args = argc;

	if (uk > 2) {
		printUsage();
		return EXIT_FAILURE;
	}

	if (args == 1) {
			printUsage();
			return EXIT_FAILURE;
	} else if (args == 2) {
		// Show the help menu
		if (help) {
			printUsage();
			return EXIT_FAILURE;
		}
		// Show all the files
		else if (all) {
			makeDir(cwd);
			printFiles(cwd);
		}
		// Show comment for the current directory
		else if (current) {
			// checkComment(argv[1], cwd);
			printCurrentComment(cwd);
		}
		// Show comment for the entered file
		else {
			// char *file = argv[1];
			makeDir(cwd);
			checkComment(argv[1], cwd);
		}
	} else if (args == 3) {
		if (current) {                               // Add comment to the current directory
			// char *file;
			// file = "CURRENT";
			addComment(argv[1], cwd, argv[2], false);
		} else if (all && desc) {                    // Print all files in descending order
			makeDir(cwd);
			printAllOrder(cwd, true);
		} else if (all && asc) {                     // Print all files in ascending order
			makeDir(cwd);
			printAllOrder(cwd, false);
		} else {                                     // Add comment to to given file
			makeDir(cwd);
			addComment(argv[1], cwd, argv[2], false);
		}
	} else if (args == 4) {
		if (current && push) { // Push comment to the current directory
			// Add a comment to the given filename
			addComment(argv[1], cwd, argv[3], true);
		} else if (push) {       // Push comment to given file
			makeDir(cwd);
			addComment(argv[1], cwd, argv[3], true);
		}
	} else {
		// Not certain
		printUsage();
	}
	return EXIT_SUCCESS;
}
示例#11
0
  inline void FileParse::getParam(std::ifstream& fin, bool& more, bool& body) {
    // If this is here, we can get stuck forever!!
    if (fin.eof()) {
      more = false;
      return;
    }
    // Get parameters
    char c;
    bool end = false, a_part = true;
    fin.get(c);
    string a(""), b("");
    while (!fin.eof()) {
      if (c=='/') {
        // Check if this is really a comment
        char d = fin.peek();
        if (d=='*' || d=='/') checkComment(fin);
        // If not, it is a division sign.
        else if (a_part) a.push_back(c);
        else             b.push_back(c);
      }
      else if (c=='=') {
        a_part = false;
      }
      else if (c==',') {
        more = true;
        break;
      }
      else if (c=='{') {
        more = false;
        body = true;
        break;
      }
      else if (c=='\n' || c=='\r') {
        body = false;
        more = false;
        break;
      }
      else if (c==' ');
      else if (c=='\n' || c=='\r') {
        more = false;
        body = false;
        break;
      }
      else {
        if (a_part) a.push_back(c);
        else        b.push_back(c);
      }

      // Get next character
      if (!fin.eof()) fin.get(c);
    }
    // Set param
    if (!a.empty() || !b.empty()) {
      // Message
      message += (tabs() + "*> Param: [" + a + "]");
      if (!b.empty()) message += (", [" + b + "]");
      message += "\n";
      // Push nodes
      currentHead->params.push_back(new ParamNode(a, b));
    }
  }