Esempio n. 1
0
/**
 * parse_command takes as input the send_message from the client and then
 * parses it into the appropriate query. Stores into send_message the
 * status to send back.
 * Returns a db_operator.
 **/
db_operator* parse_command(message* recv_message, message* send_message, status* parse_status) {
    send_message->status = OK_WAIT_FOR_RESPONSE;
    // check load flags here
    db_operator *dbo = init_dbo();
    // Here you parse the message and fill in the proper db_operator fields for
    // now we just log the payload
    cs165_log(stdout, recv_message->payload);

    // Here, we give you a default parser, you are welcome to replace it with anything you want
    *parse_status = parse_command_string(recv_message->payload, dsl_commands, dbo);

    return dbo;
}
Esempio n. 2
0
int main(int argc, const char *argv[]) {
	int fd = open(*++argv, O_RDONLY);
	struct _test *test_p;
	char *dummy_main;
	if (search_for_special(fd)) {
		fprintf(stderr, "Couldn't find special character. Exiting\n");
		exit(1);
	}
	test_p = parse_command_string(fd);
	create_dummy_main(dummy_main, test_p);
	create_file_for_compiling(fd, dummy_main, SP_NEWFILE_NAME_AND_LOC);
	free(dummy_main);
	exec_gxx(SP_NEWFILE_NAME_AND_LOC, "");
	exec("./a.out");
return 0;
}
Esempio n. 3
0
File: main.c Progetto: shalvin/itsh
void shell_main_loop(char **cmdString, FILE *stream,
        bool doPrompt) {
    size_t cmdLen = 0;
    char *commandArgs;
    parse_status status;

    if (doPrompt) {
        prompt();
    }
    while(getline(cmdString, &cmdLen, stream) > 0) {
        // Ignore if line is larger than maximum length.
        if (cmdLen >= MAX_COMMAND_LENGTH) {
            fprintf(stderr, "Command exceeds maximum allowed command " 
                    "length (%d)\n", MAX_COMMAND_LENGTH);
            free(*cmdString);
            cmdLen = 0;
            prompt();
            continue;
        }
        
        // Parse command string.
        status = parse_command_string(*cmdString, &commandArgs);
        
        // Handle statuses after parsing.
        if (status == CMD_EXIT) {
            break;
        } else if (status == CMD_NOCMD) {
            // Print error
        } else if (status == CMD_EXEC_ERR) {
            fprintf(stderr, "Error executing command.\n");
        }
        
        if (doPrompt) {
            prompt();
        }
    }
}
Esempio n. 4
0
command_stream_t
stringsToStream(char **commandStrings, int *line_nums, int count)
{
  int ii = 0;


  command_t *commandArray = checked_malloc(sizeof(command_t) * count);


  for (ii = 0; ii < count; ii++) 
  {
    if (commandStrings[ii] == 0)
      continue;
    commandArray[ii] = parse_command_string(commandStrings[ii], line_nums[ii]);
  }

  command_stream_t commandStream = (command_stream_t) checked_malloc(sizeof(struct command_stream));

  commandStream->commands = commandArray;
  commandStream->curCommand = 0;
  commandStream->numCommands = count;

  return commandStream;
}
Esempio n. 5
0
//*********************************************************************
static int read_ini_file(char *ini_str)
{
   FILE *ofile ;
   int slen ;
   char *strptr ;
   static char line[PATH_MAX] ;

// printf("reading %s\n", ini_str) ;
   ofile = fopen(ini_str, "rt") ;
   if (ofile == 0) 
      return errno ;

   while (fgets(line, sizeof(line), ofile) != 0) {
      //  strip off newline char
      slen = strlen(line) ;
      strptr = &line[slen-1] ;
      if (*strptr == '\n') {
         *strptr-- = 0 ;   //  strip off newline
         // slen-- ;
      }

      //  next, find and strip off comments
      strptr = strchr(line, ';') ;
      if (strptr != 0)
         *strptr-- = 0 ;

      //  skip blank lines
      slen = strlen(line) ;
      if (slen == 0)
         continue;
      strptr = &line[slen-1] ;

      //  then strip off tailing spaces
      while (slen > 0  &&  *strptr == ' ') {
         *strptr-- = 0 ;
         slen-- ;
      }
      if (slen == 0)
         continue;

      //  now we should have a simple line in field=value format.
      //  See if we can parse it...

      //  see whether we're dealing with an extention-color entry,
      //  or a flags entry
      if (line[0] == '!') {
         parse_command_string(line) ;
      } else if (line[0] == '.') {
         parse_color_entry(line) ;
      } else if (line[0] >= '0'  &&  line[0] <= '9') {
         parse_color_entry(line) ;
      } else if (line[0] == ':') {
         parse_dir_color_entry(line) ;
      } else {
// printf("line=%s", line) ;
         parse_ini_line(line) ;
      }
   }
   
   fclose(ofile) ;
   return 0;
}
Esempio n. 6
0
/*
 * This function reads aliases and default module options from a configuration file
 * (/etc/modprobe.conf syntax). It supports includes (only files, no directories).
 */
static void include_conf ( struct dep_t **first, struct dep_t **current, char *buffer, int buflen, int fd )
{
	int continuation_line = 0;

	// alias parsing is not 100% correct (no correct handling of continuation lines within an alias) !

	while ( reads ( fd, buffer, buflen)) {
		int l;
		char *p;

		p = strchr ( buffer, '#' );
		if ( p )
			*p = 0;

		l = strlen ( buffer );

		while ( l && isspace ( buffer [l-1] )) {
			buffer [l-1] = 0;
			l--;
		}

		if ( l == 0 ) {
			continuation_line = 0;
			continue;
		}

		if ( !continuation_line ) {
			if (( strncmp ( buffer, "alias", 5 ) == 0 ) && isspace ( buffer [5] )) {
				char *alias, *mod;

				if ( parse_tag_value ( buffer + 6, &alias, &mod )) {
					/* handle alias as a module dependent on the aliased module */
					if ( !*current ) {
						(*first) = (*current) = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t ));
					}
					else {
						(*current)-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t ));
						(*current) = (*current)-> m_next;
					}
					(*current)-> m_name  = bb_xstrdup ( alias );
					(*current)-> m_isalias = 1;

					if (( strcmp ( mod, "off" ) == 0 ) || ( strcmp ( mod, "null" ) == 0 )) {
						(*current)-> m_depcnt = 0;
						(*current)-> m_deparr = 0;
					}
					else {
						(*current)-> m_depcnt  = 1;
						(*current)-> m_deparr  = xmalloc ( 1 * sizeof( char * ));
						(*current)-> m_deparr[0] = bb_xstrdup ( mod );
					}
					(*current)-> m_next    = 0;
				}
			}
			else if (( strncmp ( buffer, "options", 7 ) == 0 ) && isspace ( buffer [7] )) {
				char *mod, *opt;

				/* split the line in the module/alias name, and options */
				if ( parse_tag_value ( buffer + 8, &mod, &opt )) {
					struct dep_t *dt;

					/* find the corresponding module */
					for ( dt = *first; dt; dt = dt-> m_next ) {
						if ( strcmp ( dt-> m_name, mod ) == 0 )
							break;
					}
					if ( dt ) {
						if ( ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS ) {
							char* new_opt = NULL;
							while( ( opt = parse_command_string( opt, &new_opt ) ) ) {
								dt-> m_options = append_option( dt-> m_options, new_opt );
							}
						} else {
							dt-> m_options = append_option( dt-> m_options, opt );
						}
					}
				}
			}
			else if (( strncmp ( buffer, "include", 7 ) == 0 ) && isspace ( buffer [7] )) {

				int fdi; char *filename = buffer + 8;

				while ( isspace ( *filename ))
					filename++;

				if (( fdi = open ( filename, O_RDONLY )) >= 0 ) {
					include_conf(first, current, buffer, buflen, fdi);
					close(fdi);
				}
			}
		}
	}
}
Esempio n. 7
0
/*
 * This function reads aliases and default module options from a configuration file
 * (/etc/modprobe.conf syntax). It supports includes (only files, no directories).
 */
static void include_conf(struct dep_t **first, struct dep_t **current, char *buffer, int buflen, int fd)
{
	int continuation_line = 0;

	// alias parsing is not 100% correct (no correct handling of continuation lines within an alias)!

	while (reads(fd, buffer, buflen)) {
		int l;

		*strchrnul(buffer, '#') = '\0';

		l = strlen(buffer);

		while (l && isspace(buffer[l-1])) {
			buffer[l-1] = '\0';
			l--;
		}

		if (l == 0) {
			continuation_line = 0;
			continue;
		}

		if (continuation_line)
			continue;

		if (is_conf_command(buffer, "alias")) {
			char *alias, *mod;

			if (parse_tag_value(buffer + 6, &alias, &mod)) {
				/* handle alias as a module dependent on the aliased module */
				if (!*current) {
					(*first) = (*current) = xzalloc(sizeof(struct dep_t));
				} else {
					(*current)->m_next = xzalloc(sizeof(struct dep_t));
					(*current) = (*current)->m_next;
				}
				(*current)->m_name = xstrdup(alias);
				(*current)->m_isalias = 1;

				if ((strcmp(mod, "off") == 0) || (strcmp(mod, "null") == 0)) {
					/*(*current)->m_depcnt = 0; - done by xzalloc */
					/*(*current)->m_deparr = 0;*/
				} else {
					(*current)->m_depcnt = 1;
					(*current)->m_deparr = xmalloc(sizeof(char *));
					(*current)->m_deparr[0] = xstrdup(mod);
				}
				/*(*current)->m_next = NULL; - done by xzalloc */
			}
		} else if (is_conf_command(buffer, "options")) {
			char *mod, *opt;

			/* split the line in the module/alias name, and options */
			if (parse_tag_value(buffer + 8, &mod, &opt)) {
				struct dep_t *dt;

				/* find the corresponding module */
				for (dt = *first; dt; dt = dt->m_next) {
					if (strcmp(dt->m_name, mod) == 0)
						break;
				}
				if (dt) {
					if (ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS) {
						char* new_opt = NULL;
						while ((opt = parse_command_string(opt, &new_opt))) {
							dt->m_options = append_option(dt->m_options, new_opt);
						}
					} else {
						dt->m_options = append_option(dt->m_options, opt);
					}
				}
			}
		} else if (is_conf_command(buffer, "include")) {
			int fdi;
			char *filename;

			filename = skip_whitespace(buffer + 8);
			fdi = open(filename, O_RDONLY);
			if (fdi >= 0) {
				include_conf(first, current, buffer, buflen, fdi);
				close(fdi);
			}
		} else if (ENABLE_FEATURE_MODPROBE_BLACKLIST &&
				(is_conf_command(buffer, "blacklist"))) {
			char *mod;
			struct dep_t *dt;

			mod = skip_whitespace(buffer + 10);
			for (dt = *first; dt; dt = dt->m_next) {
				if (strcmp(dt->m_name, mod) == 0)
					break;
			}
			if (dt)
				dt->m_isblacklisted = 1;
		}
	} /* while (reads(...)) */
}