Ejemplo n.º 1
0
    bool Preprocessor::HandleSection(size_t line_no, Tokenizer & tok){
        if (tok.next_token().get_type() != Tokenizer::Type::String){
            throw Exception::Error("Section name must be a quoted string; got `" + tok.get_string() + "`.");
        }
        size_t file_number = push_file(filenames, filedata.name());
        std::string version;
        std::string prefix;
        if (Defined(currentSection, "__INTERNAL VERSION", version) && defines.size() == 1){
            prefix += "#version " + version + "\n";
        }
        if (currentSection == ""){
            prefix += "#line 1 " + std::to_string(file_number) + "\n";
        }
        sections[currentSection].data = prefix + currentData;
        currentData = "";

        currentData += "#line " + std::to_string(line_no) + " " + std::to_string(file_number) + "\n";
        std::string section = tok;
        section.pop_back();
        section.erase(section.begin(), section.begin() + 1);
        currentSection = section;
        if (currentSection == "__END"){
            return true;
        }
        return true;
    }
Ejemplo n.º 2
0
Archivo: ancc.c Proyecto: AeanSR/ancc
int main(int argc, char** argv) {
    int i;
    for(i = 0; i < NAL; i++)
        keylist[i].name = strpool(keylist[i].name);
    printf(
        "ancc: another noobish C compiler.\n"
        "    Aean, 2014 <*****@*****.**>\n"
        "ancc project is licensed under the terms of the MIT License. You should have    "
        "recieved a copy of the license. If not, please visit <http://mit-license.org/>. "
        "\n\n"
    );
    if (argc < 2) {
        char* p = argv[0];
        while(*p)p++;
        while(p > argv[0] && *p!='\\')p--;
        if(*p=='\\')p++;

        printf(
            "ancc CLI Format:\n"
            "%s <sourcename>\n",
            p);
        return 0;
    }
    push_file(argv[1]);
    preprocess();
    read_source();
    lr1();
    printf("%d errors, %d warnings\n", error_occured, warning_occured);
    return 0;
}
Ejemplo n.º 3
0
int		main(int argc, char **argv)
{
  t_options	*options;
  t_list_file	*list_file;
  int		check_option;
  int		i;

  i = 1;
  check_option = 0;
  list_file = NULL;
  if ((init_options(&options)) == 1)
    return (1);
  while (i < argc)
  {
    if (argv[i][0] == '-')
      check_option = get_option(argv[i], &options);
    else
      check_option += push_file(options, &list_file, argv[i], 0);
    if (check_option != 0)
      return (1);
    i = i + 1;
  }
  if ((my_ls(options, list_file)) == -1)
    return (1);
  free_list_file(&list_file);
  free(options);
  return (0);
}
Ejemplo n.º 4
0
int		read_file(char *filename, t_file **file)
{
  int		fd;
  char		*str;

  *file = NULL;
  if ((fd = open(filename, O_RDONLY)) == -1)
    return (my_putstr("error: open\n", 2));
  while ((str = get_next_line(fd)))
  {
    if (push_file(file, str) == -1)
      return (-1);
  }
  close(fd);
  if (*file == NULL)
    return (my_putstr("error: file empty\n", 2));
  return (0);
}
Ejemplo n.º 5
0
//Creates a request to send a file
int send_file_request(char **argv, char *filename, int op_type)
{
	int namenode_socket = connect_to_nn(argv[1], atoi(argv[2]));
	if (namenode_socket < 0)
	{
		return -1;
	}

	int result = 1;
	switch (op_type)
	{
		case 0:
			result = pull_file(namenode_socket, filename);
			break;
		case 1:
			result = push_file(namenode_socket, filename);
			break;
	}
	close(namenode_socket);
	return result;
}
Ejemplo n.º 6
0
 bool Preprocessor::HandleInclude(size_t line_no, Tokenizer & tok){
     bool issection = false;
     if (tok.next_token() == "section"){
         issection = true;
         tok.next_token();
     }
     if (tok.get_type() != Tokenizer::Type::String){
         throw Exception::Error("Include name must be quoted string; got `" + tok.get_string() + "`.");
     }
     MappedFile mfile;
     std::string section = "";
     if (issection){
         section = tok.get_string();
         trim_ends(section);
         mfile = filedata;
     }
     else{
         std::string file = tok;
         trim_ends(file);
         size_t pos = file.find_first_of("?");
         if (pos != std::string::npos){
             section = file.substr(pos + 1);
             file.erase(file.begin() + pos, file.end());
         }
         else{
             if (tok.next_token()){
                 if (tok == "section"){
                     if (tok.next_token().get_type() == Tokenizer::Type::String){
                         section = tok.get_string();
                         trim_ends(section);
                     }
                     else{
                         throw Exception::Error("String expected after `section`; got `" + tok.get_string() + "`.");
                     }
                 }
                 else{
                     throw Exception::Error("Unknown include specifier `" + tok.get_string() + "`. Did you mean to use `section`?");
                 }
             }
         }
         mfile = MappedFile(file, include_paths);
     }
     size_t file_number;// = push_file(filenames, mfile.name());
     std::string test_name = "___ONCE_INCLUDE " + section + "?" + mfile.name();
     if (Defined(section, test_name)){
         currentData.push_back('\n');
         return true;
     }
     //currentData += "#line 1 " + std::to_string(file_number) + "\n";
     defines.push_back(&sections[currentSection].defines);
     Preprocessor p = Preprocessor(mfile, include_paths, defines, filenames, section);
     auto newSections = p.Preprocess();
     auto& back = *defines.back();
     defines.pop_back();
     for (auto & def : back){
         Define(def.first, def.second);
     }
     file_number = push_file(filenames, filedata.name());
     currentData += newSections.at(section).data;
     currentData.push_back('\n');
     currentData += "#line " + std::to_string(line_no) + " " + std::to_string(file_number) + "\n";
     return true;
 }
Ejemplo n.º 7
0
file_stream_t
get_file_depends (command_t c)
{
  file_stream_t depends = checked_malloc(sizeof(struct file_stream));
  depends->head = NULL;
  depends->curr = NULL;
  depends->tail = NULL;
  // Complete command is just a simple command
  switch (c->type)
  {
    case SIMPLE_COMMAND:
    {
      if (c->input != NULL)
        push_file(depends, c->input, 'r');

      if (c->output != NULL)
        push_file(depends, c->output, 'w');
      
      char* word = *c->u.word;
      if (word != NULL)
      {
        int word_size = strlen(word);
        int i = 0;
        int beg = 0;
        // Tokenize word
        while (i < word_size)
        {
          char temp_ch = word[i];
          // Found end of token
          if (temp_ch == ' ' || temp_ch == '\n')
          {
            char* token = checked_malloc((i-beg)*sizeof(char));
            int t = beg;
            int index = 0;
            while (t < i)
            {
              token[index] = word[t];
              ++index;
              ++t;
            }
            push_file (depends, token, 'r');
            beg = i + 1;
          } 
          ++i;
        }
        
        int index = 0;
        // Finish last token
        if (beg < i)
        {
          char* token = checked_malloc((i-beg)*sizeof(char));
          while (beg < i)
          {
            token[index] = word[beg];
            ++index;
            ++beg;
          }
          push_file (depends, token, 'r');
        }
      }
      break;
    }
    case SUBSHELL_COMMAND:
    {
      depends = get_file_depends (c->u.subshell_command);
      break;
    }
    case AND_COMMAND:
    case OR_COMMAND:
    case SEQUENCE_COMMAND:
    case PIPE_COMMAND:
    {
      // Set depends to left dependency list
      depends = get_file_depends (c->u.command[0]);
      // Append right depedency list to tail of current list
      if (depends->curr != NULL)
      {
        depends->tail->next = (get_file_depends(c->u.command[1]))->head;
        // Update tail
        depends->curr = depends->tail;
        while(depends->curr->next != NULL)
        {
          depends->curr = depends->curr->next;
        }
        depends->tail = depends->curr;
        break;
      }
      else
        depends = get_file_depends(c->u.command[1]);
    }
  }
  depends->curr = depends->head;
  return depends;
}