コード例 #1
0
ファイル: tosql.cpp プロジェクト: Daniel1892/tora
bool toSQL::deleteSQL(QString const& name,
                      QString const& ver,
                      QString const& provider)
{
    allocCheck();
    sqlMap::iterator i = Definitions->find(name);
    if (i == Definitions->end())
    {
        return false;
    }
    else
    {
        std::list<version> &cl = (*i).second.Versions;
        for (std::list<version>::iterator j = cl.begin(); j != cl.end(); j++)
        {
            if (j->Version == ver && j->Provider == provider)
            {
                cl.erase(j);
                if ( cl.empty() )
                    Definitions->erase(i);
                return true;
            }
            else if (j->Provider > provider ||
                     (j->Provider == provider && ! j->Version.isNull()))
            {
                return false;
            }
        }
        return false;
    }
}
コード例 #2
0
ファイル: tosql.cpp プロジェクト: Daniel1892/tora
QString toSQL::description(const QString &name)
{
    allocCheck();
    sqlMap::iterator i = Definitions->find(name);
    if (i != Definitions->end())
        return (*i).second.Description;
    throw qApp->translate("toSQL", "03: Tried to get unknown SQL (%1)").arg(QString(name));
}
コード例 #3
0
ファイル: tosql.cpp プロジェクト: Daniel1892/tora
toSQL toSQL::sql(const QString &name)
{
    allocCheck();
    sqlMap::iterator i = Definitions->find(name);
    if (i != Definitions->end())
        return name;
    throw qApp->translate("toSQL", "01: Tried to get unknown SQL (%1)").arg(QString(name));
}
コード例 #4
0
ファイル: josh.c プロジェクト: sbeef/josh
int main() {
  child = 0;
  int c, i;
  struct args *arguments;
  char *input;
  char *usrname = getenv("LOGNAME");
  i = 0;
  input = malloc(sizeof(char) * MAX_INPUT);
  allocCheck(input);
  printf("%s%s",usrname,josh_prompt);
  signal(SIGINT, sigHandler);
  signal(SIGTSTP, sigHandler);
  //c = 0;
  while (1) {
    errno = 0;
    if (EOF == (c = fgetc(stdin))) {
      if (ferror(stdin) && errno == EINTR) {
        continue;
      }
      if (ferror(stdin)) {
        perror("reading input");
        free(input);
        exit(EXIT_FAILURE);
      }
      if (feof(stdin)) {
        fprintf(stderr, "No More input\n");
        free(input);
        exit(EXIT_SUCCESS);
       }
    }
    if (i == MAX_INPUT) {
    // handle overflow
    } else if ('\n' == c) {
      input[i] = '\0';
      if(strcmp("exit",input) == 0){
	free(input);
        freeArgs(arguments);
        break;
      } 
      arguments = parse(input);
      if (NULL != arguments)
        p2(arguments);
      //allocCheck(input);
      i = 0;
      //free(input);
      printf("%s%s",usrname,josh_prompt);
    } else {
      input[i] = c;
      i++;
    }
  }
  if (EOF == c)
    freeArgs(arguments);
    free(input);
}
コード例 #5
0
ファイル: josh.c プロジェクト: sbeef/josh
struct args * arginit() {
  struct args *arguments = malloc(sizeof(struct args));
  allocCheck(arguments);
  arguments->program = NULL;
  arguments->program_args = NULL;
  arguments->out_redir = 0;
  arguments->in_redir = 0;
  arguments->in_file = NULL;
  arguments->out_file = NULL;
  arguments->background = 0; 
  arguments->pipe_args = NULL;
  return arguments;
}
コード例 #6
0
ファイル: tosql.cpp プロジェクト: Daniel1892/tora
bool toSQL::saveSQL(const QString &filename, bool all)
{
    allocCheck();
    QString data;

    QRegExp backslash(QString::fromLatin1("\\"));
    QRegExp newline(QString::fromLatin1("\n"));
    for (sqlMap::iterator i = Definitions->begin(); i != Definitions->end(); i++)
    {
        QString str;
        definition &def = (*i).second;
        QString name = (*i).first;
        if (def.Modified || all)
        {
            QString line = name;
            line += "=";
            QString t = def.Description;
            t.replace(backslash, QString::fromLatin1("\\\\"));
            t.replace(newline, QString::fromLatin1("\\n"));
            line += t;
            str = line;
            str += "\n";
        }
        for (std::list<version>::iterator j = def.Versions.begin(); j != def.Versions.end(); j++)
        {
            version &ver = (*j);
            if (ver.Modified || all)
            {
                QString line = name;
                line += "[";
                line += ver.Version;
                line += "][";
                line += ver.Provider;
                line += "]=";
                QString t(ver.SQL);
                t.replace(backslash, QString::fromLatin1("\\\\"));
                t.replace(newline, QString::fromLatin1("\\n"));
                line += t;
                str += line;
                str += "\n";
            }
        }
        data += str;
    }

    // TODO: data shouldn't be a QString
    //       if we use QByteArray, there would be no need to re-encode

    // save as UTF8 encoded file
    return Utils::toWriteFile(filename, data.toUtf8());
}
コード例 #7
0
ファイル: tosql.cpp プロジェクト: Daniel1892/tora
QString toSQL::string(const QString &name, const toConnection &conn)
{
    allocCheck();
    QString SessionVersion = conn.version();
    QString SessionProvider = conn.provider();

    bool quit = false;

    sqlMap::iterator i = Definitions->find(name);
    if (i == Definitions->end())
        goto fail;

    // Loop over our connections' provider queries, if nothing is found also loop over "ANY" providers' queries
    do
    {
    	if (SessionProvider == "Any")
    		quit = true;
    	QString retval;
    	QString SqlVersion = defaultVersion;
    	std::list<version> &cl = (*i).second.Versions;
    	for (std::list<version>::iterator j = cl.begin(); j != cl.end(); j++)
    	{
    		if (j->Provider != SessionProvider)
    			continue;

    		QString const& QueryVersion = j->Version;
    		QString const& QueryProvider = j->Provider;
    		if (SqlVersion <= QueryVersion && QueryVersion <= SessionVersion)
    		{
    			retval = j->SQL;
    			SqlVersion = QueryVersion;
    		}
    	}
    	if (!retval.isEmpty())
    		return retval;

    	SessionProvider = "Any";
    }
    while (!quit);

fail:
    throw qApp->translate("toSQL", "02: Tried to get unknown SQL (%1)").arg(QString(name));
}
コード例 #8
0
ファイル: tosql.cpp プロジェクト: Daniel1892/tora
bool toSQL::updateSQL(char const *_name,
                      char const *_sql,
                      char const *_description,
                      char const *_ver,
                      char const *_provider,
                      bool modified)
{
	QString description(_description);
	version def(_provider, _ver, _sql, modified);

    allocCheck();
    sqlMap::iterator i = Definitions->find(_name);
    if (i == Definitions->end())
    {
        if (description.isEmpty())
        {
            fprintf(stderr, "ERROR:Tried add new version to unknown SQL (%s)\n", _name);
            return false;
        }
        definition newDef;
        newDef.Modified = modified;
        newDef.Description = _description;
        if (!def.SQL.isNull())
        {
            std::list<version> &cl = newDef.Versions;
            cl.insert(cl.end(), def);
        }
        (*Definitions)[_name] = newDef;
        return true;
    }

    if (!description.isEmpty())
    {
    	if ((*i).second.Description != description)
    	{
    		(*i).second.Description = description;
    		(*i).second.Modified = modified;
    	}
    	if (!modified)
    		fprintf(stderr, "ERROR:Overwrite description of nonmodified (%s)\n", _name);
    }

    std::list<version> &cl = (*i).second.Versions;
    for (std::list<version>::iterator j = cl.begin(); j != cl.end(); j++)
    {
    	if (j->Provider == def.Provider && j->Version == def.Version)
    	{
    		if (!def.SQL.isNull())
    		{
    			if (def.SQL != j->SQL)
    				def.Modified = modified;
    			(*j) = def;
    		}
    		return false;
    	}
    	else if (j->Provider > def.Provider || (j->Provider == def.Provider && j->Version > def.Version))
    	{
    		if (!def.SQL.isNull())
    			cl.insert(j, def);
    		return true;
    	}
    }
    cl.insert(cl.end(), def);
    return true;
}
コード例 #9
0
ファイル: tosql.cpp プロジェクト: Daniel1892/tora
void toSQL::loadSQL(const QString &filename)
{
    allocCheck();
    // read UTF8 encoded file as byte array
    QByteArray data = Utils::toReadFileB(filename);

    int size = data.length();
    int pos = 0;
    int bol = 0;
    int endtag = -1;
    int provtag = -1;
    int vertag = -1;
    int wpos = 0;
    while (pos < size)
    {
        switch (data[pos])
        {
            case '\n':
                if (endtag == -1)
                    throw QT_TRANSLATE_NOOP("toSQL", "Malformed tag in config file. Missing = on row.");
                data[wpos] = 0;
                {
                    char const* nam = ((const char *)data) + bol;
					char const* val = ((const char *)data) + endtag + 1;
					char const* ver;
					char const* prov(NULL);
                    if (vertag >= 0)
                    {
                        ver = ((const char *)data) + vertag + 1;
                        if (provtag >= 0)
                            prov = ((const char *)data) + provtag + 1;
                        updateSQL(nam, val, "", ver, prov, true);
                    }
                    else
                        updateSQL(nam, "", val, "", "", true);
                }
                bol = pos + 1;
                provtag = vertag = endtag = -1;
                wpos = pos;
                break;
            case '=':
                if (endtag == -1)
                {
                    endtag = pos;
                    data[wpos] = 0;
                    wpos = pos;
                }
                else
                    data[wpos] = data[pos];
                break;
            case '[':
                if (endtag == -1)
                {
                    if (vertag >= 0)
                    {
                        if (provtag >= 0)
                            throw QT_TRANSLATE_NOOP("toSQL", "Malformed line in SQL dictionary file. Two '[' before '='");
                        provtag = pos;
                    }
                    else
                        vertag = pos;
                    data[wpos] = 0;
                    wpos = pos;
                }
                else
                    data[wpos] = data[pos];
                break;
            case ']':
                if (endtag == -1)
                {
                    data[wpos] = 0;
                    wpos = pos;
                }
                else
                    data[wpos] = data[pos];
                break;
            case '\\':
                pos++;
                switch (data[pos])
                {
                    case 'n':
                        data[wpos] = '\n';
                        break;
                    case '\\':
                        if (endtag >= 0)
                            data[wpos] = '\\';
                        else
                            data[wpos] = ':';
                        break;
                    default:
                        throw QT_TRANSLATE_NOOP("toSQL", "Unknown escape character in string (Only \\\\ and \\n recognised)");
                }
                break;
            default:
                data[wpos] = data[pos];
                break;
        }
        wpos++;
        pos++;
    }
}
コード例 #10
0
ファイル: josh.c プロジェクト: sbeef/josh
/* figures out what's what*/
struct args * parse(char *input) {
  // the arguements will go here
  struct args *arguments = arginit();
  allocCheck(arguments); //did malloc work?
  int i = 1; //this will be important in the later day
  char **args;// the tokenized input
  args = malloc(sizeof(char *) * MAX_INPUT);
  allocCheck(args);
  /*TOKENIZE THAT!  YEA*/
  for (args[0] = strtok(input, DELIM); NULL != args[i-1]; i++)
    args[i] = strtok(NULL, DELIM);
  args[i] = NULL;
  //shrink it down to size
  args = realloc(args, sizeof(char *) * (i+1));
  allocCheck(args);
  /* alrighty, what's the program we should run */
  arguments->program = malloc(sizeof(char) * MAX_INPUT);
  allocCheck(args);
  strncpy(arguments->program, args[0], strlen(args[0]) + 1);
  int j, len, size;
  i = j = 0;
  char c;
  /* how many arguments apply to this specific program? */
  while (NULL != args[i]) {
    c = args[i][0];
    if ('|' == c || '<' == c || '>' == c || '&' == c)
      break;
    i++;
  }
  arguments->program_args = malloc(sizeof(char *) * (i + 1));
  /* now fill program_args with the arguments for that program */
  for (j = 0; j < i; j++) {
    len = strlen(args[j]) + 1;
    arguments->program_args[j] = malloc(sizeof(char) * len);
    allocCheck(arguments->program_args[j]);
    strncpy(arguments->program_args[j], args[j], len);
  }
  arguments->program_args[j] = NULL;
  /* now figure out how many arguments are left */
  //i = i-1;
  size = 0;
  while (NULL != args[i+size]) {
    size ++;
  }
  /* stick the remaining arguments in the pipe_args */
  //arguments->pipe_args = malloc(sizeof(char *) * (size + 1));
  for (j = 0; j < (size); j++) {
    if (args[j+i][0] == '|')
      break;
    else if (args[j+i][0] == '&') 
      arguments->background = 1;
    else if (args[j+i][0] == '<' && arguments->in_redir == 0) {
      arguments->in_redir = 1;
      j++;
      len = strlen(args[j+i]) + 1;
      arguments->in_file = malloc(sizeof(char) * len);
      allocCheck(arguments->in_file);
      strncpy(arguments->in_file, args[j+i], len);
    } else if (args[j+i][0] == '>' && arguments->out_redir == 0) {
      arguments->out_redir = 1;
      j++;
      len = strlen(args[j+i]) + 1;
      arguments->out_file = malloc(sizeof(char) * len);
      allocCheck(arguments->out_file);
      strncpy(arguments->out_file, args[j+i], len);
    }
  }
  arguments->pipe_args = malloc(sizeof(char *) * (size + 1));
  //arguments->background = 0; 
  int s = 0;
  for (; j < (size); j++) {
    len = strlen(args[j+i]) + 1;
    arguments->pipe_args[s] = malloc(sizeof(char) * len);
    allocCheck(arguments->pipe_args[s]);
    strncpy(arguments->pipe_args[s], args[j+i], len);
    s++;
  }
  arguments->pipe_args[s] = NULL;
  arguments->pipe_args = realloc(arguments->pipe_args, sizeof(char *) * (j+1));
  allocCheck(arguments->pipe_args);
  // you're done!
  i = 0;
  /*while(NULL != arguments->pipe_args[i]) {
    printf("arg[%d]: %s\n", i, arguments->pipe_args[i]);
    i++;
  }*/
  //string_array_free(args);
  free(args);
  return arguments;
}