Ejemplo n.º 1
0
bool InputCommandTemplateUnitTests::test1(const tstring& str, int n, ...)
{
    InputPlainCommands cmds(str);
    InputTemplateParameters p; 
    p.separator = L';';
    p.prefix = L'#';

    InputTemplateCommands t;
    t.init(cmds, p);
    InputPlainCommands out;
    t.extract(&out);

    std::vector<tstring>* cs = out.ptr();

    if (cs->size() != n)
        return false;

    bool result = true;
    va_list args;
    va_start(args, n);
    for (int i = 0; i < n; ++i)
    {
        const wchar_t* s = va_arg(args, wchar_t*);
        if (wcscmp(cs->at(i).c_str(), s))
            { result = false; break; }
    }
    va_end(args); 
    return result;
}
Ejemplo n.º 2
0
bool InputCommandTemplateUnitTests::test2(const tstring& str, int params, InputCommands *ref)
{
    InputPlainCommands cmds(str);
    InputTemplateParameters p;
    p.separator = L';';
    p.prefix = L'#';

    InputTemplateCommands t;
    t.init(cmds, p);
    t.makeTemplates();

    InputTestsParameters tp(params);
    InputCommands tcmds;
    t.makeCommands(&tcmds, &tp);

    if (tcmds.size() != ref->size())
        return false;

    for (int i=0, e=tcmds.size(); i<e; ++i)
    {
        InputCommand c1 = tcmds[i];
        InputCommand c2 = ref->operator[](i);
        if (c1->srccmd != c2->srccmd)
            return false;
        if (c1->srcparameters != c2->srcparameters)
            return false;
        if (c1->command != c2->command)
            return false;
        if (c1->system != c2->system)
            return false;
    }
    return true;
}
void K3bExternalEncoderSettingsWidget::fillEncoderView( const QList<K3bExternalEncoderCommand>& commands )
{
    m_commands.clear();
    m_viewEncoders->clear();

    QList<K3bExternalEncoderCommand> cmds( commands );
    for( QList<K3bExternalEncoderCommand>::iterator it = cmds.begin();
         it != cmds.end(); ++it ) {
        K3bExternalEncoderCommand& cmd = *it;
        createItem( cmd );
    }
}
Ejemplo n.º 4
0
int callback(struct filetransfer *ft, enum ftstate ftst,
		size_t bytessent, size_t bytestotal)
{
	const double fraction = (double)bytessent / (double)bytestotal;

	switch(ftst){
		case FT_WAIT:
			break; /* skip straight to return */

		case FT_SENT:
		case FT_RECEIVED:
		{
			char *stat;

			if(ftst == FT_SENT)
				stat = g_strdup_printf("Sent %s", ft_basename(ft));
			else
				stat = g_strdup_printf("Received %s", ft_basename(ft));
			status("%s", stat);
			gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressft), 1.0f);
			transfers_add(listDone, ft_basename(ft), ft_fname(ft), ftst == FT_RECEIVED);

			tray_balloon("Transfer complete", stat);
			g_free(stat);
			break;
		}

		case FT_BEGIN_SEND:
		case FT_BEGIN_RECV:
			cancelled = 0;
			gstate = STATE_TRANSFER;
			cmds();
			/* fall */

		case FT_RECEIVING:
		case FT_SENDING:
			gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressft), fraction);
			status("%s: %ldK/%ldK (%2.2f%%)", ft_basename(ft),
					(long)bytessent  / 1024,
					(long)bytestotal / 1024,
					100.0f * fraction);
	}

	while(gtk_events_pending())
		gtk_main_iteration();

	return cancelled;
}
Ejemplo n.º 5
0
bool DummyInterface::sendJointTargets()
{
	std::vector<double> cmds(m_model->numJoints());
	for(size_t i = 0; i < m_model->numJoints(); ++i)
	{
		const boost::shared_ptr<DummyJoint>& joint = boost::reinterpret_pointer_cast<DummyJoint>(m_model->joint(i));

		if(joint->velocityMode())
			cmds[i] = joint->cmd.vel;
		else
		{
			double cmd = joint->cmd.pos;

			// Enforce urdf position limits
			if(joint->modelJoint->type == urdf::Joint::REVOLUTE)
			{
				const boost::shared_ptr<urdf::JointLimits>& limits = joint->modelJoint->limits;
				if(limits)
				{
					if(cmd > limits->upper)
					{
						ROS_ERROR("Position controlled joint '%s' out of bounds! Constraining position %f to upper limit %f!",
							joint->name.c_str(),
							cmd, limits->upper
						);
						cmd = limits->upper;
					}
					else if(cmd < limits->lower)
					{
						ROS_ERROR("Position controlled joint '%s' out of bounds! Constraining position %f to lower limit %f!",
							joint->name.c_str(),
							cmd, limits->lower
						);
						cmd = limits->lower;
					}
				}
			}
			cmds[i] = cmd;
		}

		joint->cmd.rawPos = joint->cmd.pos;
	}

	m_dataBuf.push_back(cmds);

	return true;
}
Ejemplo n.º 6
0
void History::AddToHistory(wxString cmd)
{
  wxString lineends = wxT(";$");
  if (cmd.StartsWith(wxT(":lisp")))
    lineends = wxT(";");

  wxStringTokenizer cmds(cmd, lineends);

  while (cmds.HasMoreTokens())
  {
    wxString curr = cmds.GetNextToken().Trim(false).Trim(true);

    if (curr != wxEmptyString)
      commands.Insert(curr, 0);
  }

  m_current = commands.GetCount();

  UpdateDisplay();
}
Ejemplo n.º 7
0
G_MODULE_EXPORT gboolean
on_btnConnect_clicked(void)
{
	char *host, *port;

	settimeout(0);

	/* alloced */
	host = gtk_combo_box_get_active_text(GTK_COMBO_BOX(cboHost));

	if(!host){
		status("Couldn't get host");
		return FALSE;
	}else if(!*host){
		status("To where am I to connect? Timbuktu?");
		return FALSE;
	}

	if(cfg_add(host))
		gtk_combo_box_insert_text(GTK_COMBO_BOX(cboHost), 0, host);

	port = strchr(host, ':');
	if(port)
		*port++ = '\0';

	if(ft_connect(&ft, host, port, callback)){
		status("Couldn't connect: %s", ft_lasterr(&ft));
		CLOSE();
	}else{
		status("Connected to %s", host);
		gstate = STATE_CONNECTED;
		settimeout(1);
	}
	URGENT(1);
	cmds();

	g_free(host);

	return FALSE;
}
Ejemplo n.º 8
0
void Application::readClients() {
	for (ClientSockets::iterator i = clients.begin(), e = clients.end(); i != e; ++i) {
		i->second.append(i->first->readAll());
		if (i->second.size()) {
			QString cmds(i->second);
			int32 from = 0, l = cmds.length();
			for (int32 to = cmds.indexOf(QChar(';'), from); to >= from; to = (from < l) ? cmds.indexOf(QChar(';'), from) : -1) {
				QStringRef cmd(&cmds, from, to - from);
				if (cmd.indexOf("CMD:") == 0) {
					execExternal(cmds.mid(from + 4, to - from - 4));
					QByteArray response(QString("RES:%1;").arg(QCoreApplication::applicationPid()).toUtf8());
					i->first->write(response.data(), response.size());
				} else {
					LOG(("Application Error: unknown command %1 passed in local socket").arg(QString(cmd.constData(), cmd.length())));
				}
				from = to + 1;
			}
			if (from > 0) {
				i->second = i->second.mid(from);
			}
		}
	}
}
Ejemplo n.º 9
0
G_MODULE_EXPORT gboolean
on_btnListen_clicked(void)
{
	char *hostret, *port;
	int iport;

	settimeout(0);

#ifdef USING_GTK_2
	hostret = gtk_combo_box_get_active_text(GTK_COMBO_BOX(cboHost));
#else
	hostret = gtk_com
#endif

	port = strchr(hostret, ':');
	if(!port)
		port = FT_DEFAULT_PORT;
	else
		port++;

	if(sscanf(port, "%d", &iport) != 1)
		status("Port _number_ ya fool...");
	else{
		if(ft_listen(&ft, iport)){
			status("Couldn't listen: %s", ft_lasterr(&ft));
			CLOSE();
		}else{
			status("Awaiting connection...");
			settimeout(1);
			gstate = STATE_LISTEN;
		}
		cmds();
	}

	g_free(hostret);
	return FALSE;
}
Ejemplo n.º 10
0
int help(int argc, char* argv[]) {
  auto helpmsg = R"(
  ===============

  Please invoke sailfish with one of the following commands {index, quant, sf}.
  For more inforation on the options for theses particular methods, use the -h
  flag along with the method name.  For example:

  sailfish index -h

  will give you detailed help information about the index command.
  )";

  std::cerr << "  Sailfish v" << sailfish::version << helpmsg << "\n";
  return 1;
}

/**
 * Bonus!
 */
int mainSailfish(int argc, char* argv[]) {

  std::cerr << R"(
   _____       _ _______      __
  / ___/____ _(_) / __(_)____/ /_
  \__ \/ __ `/ / / /_/ / ___/ __ \
 ___/ / /_/ / / / __/ (__  ) / / /
/____/\__,_/_/_/_/ /_/____/_/ /_/
)";

  return 0;

}

int mainIndex(int argc, char* argv[]);
int mainQuantify(int argc, char* argv[]);

bool verbose = false;

int main( int argc, char* argv[] ) {
  using std::string;
  namespace po = boost::program_options;

  try {

    po::options_description hidden("hidden");
    hidden.add_options()
    ("command", po::value<string>(), "command to run {index, quant, sf}");

    po::options_description sfopts("Allowed Options");
    sfopts.add_options()
    ("version,v", "print version string")
    ("no-version-check", "don't check with the server to see if this is the latest version")
    ("help,h", "produce help message")
    ;

    po::options_description all("Allowed Options");
    all.add(sfopts).add(hidden);

    // po::options_description sfopts("Command");
    // sfopts.add_options()

    po::positional_options_description pd;
    pd.add("command", 1);

    size_t topLevelArgc = argc;
    for (size_t i : boost::irange(size_t{1}, static_cast<size_t>(argc))) {
      if (argv[i][0] != '-') {
        topLevelArgc = i+1;
        break;
      }
    }

    po::variables_map vm;
    po::parsed_options parsed = po::command_line_parser(topLevelArgc, argv).options(all).positional(pd).allow_unregistered().run();
    po::store(parsed, vm);

/*    std::vector<string> subcommand_options = po::collect_unrecognized(parsed.options, po::include_positional);
    for (auto& s : subcommand_options) {
        std::cerr << "option: " << s << "\n";
    }
*/

    if (vm.count("version")) {
      std::cerr << "version : " << sailfish::version << "\n";
      std::exit(0);
    }

    if (vm.count("help") and !vm.count("command")) {
        std::cout << sfopts << std::endl;
        help(argc, argv);
        std::exit(0);
    }

    if (!vm.count("no-version-check")){
      std::string versionMessage = getVersionMessage();
      std::cerr << versionMessage;
    }

    po::notify(vm);

    std::unordered_map<string, std::function<int(int, char*[])>> cmds({
      {"index", mainIndex},
      {"quant", mainQuantify},
      {"sf", mainSailfish}
    });

    string cmd = vm["command"].as<string>();

    int subCommandArgc = argc - topLevelArgc + 1;
    char** argv2 = new char*[subCommandArgc];
    argv2[0] = argv[0];
    std::copy_n( &argv[topLevelArgc], argc-topLevelArgc, &argv2[1] );

    auto cmdMain = cmds.find(cmd);
    if (cmdMain == cmds.end()) {
      help(subCommandArgc, argv2);
    } else {
      cmdMain->second(subCommandArgc, argv2);
    }
    delete[] argv2;

  } catch (po::error &e) {
Ejemplo n.º 11
0
int main(int argc, char **argv) {

#line 3047 "ifupdown.nw"
    int (*cmds)(interface_defn *) = NULL;
#line 3141 "ifupdown.nw"
    struct option long_opts[] = {
        {"help",        no_argument,       NULL, 'h'},
        {"version",     no_argument,       NULL, 'V'},
        {"verbose",     no_argument,       NULL, 'v'},
        {"all",         no_argument,       NULL, 'a'},
        {"allow",	required_argument, NULL,  3 },
        {"interfaces",  required_argument, NULL, 'i'},
        {"exclude",     required_argument, NULL, 'e'},
        {"no-act",      no_argument,       NULL, 'n'},
        {"no-mappings", no_argument,       NULL,  1 },
        {"force",       no_argument,       NULL,  2 },
        {0,0,0,0}
    };
#line 3171 "ifupdown.nw"
    int do_all = 0;
    int run_mappings = 1;
    int force = 0;
    char *allow_class = NULL;
    char *interfaces = "/etc/network/interfaces";
    char *statefile = "/etc/network/run/ifstate";
    char *excludeint = NULL ;
#line 3338 "ifupdown.nw"
    interfaces_file *defn;
#line 3497 "ifupdown.nw"
    int n_target_ifaces;
    char **target_iface;
#line 3554 "ifupdown.nw"
    char **state = NULL; /* list of iface=liface */
    int n_state = 0;
    int max_state = 0;
#line 3628 "ifupdown.nw"
    static FILE *state_fp = NULL;

#line 2992 "ifupdown.nw"

#line 3016 "ifupdown.nw"
    {
        int i;
        for (i = 0; i <= 2; i++) {
            if (fcntl(i, F_GETFD) == -1) {
                if (errno == EBADF && open("/dev/null", 0) == -1) {
                    fprintf(stderr,
                            "%s: fd %d not available; aborting\n",
                            argv[0], i);
                    exit(2);
                } else if (errno == EBADF) {
                    errno = 0; /* no more problems */
                } else {
                    /* some other problem -- eeek */
                    perror(argv[0]);
                    exit(2);
                }
            }
        }
    }

#line 2994 "ifupdown.nw"

#line 3053 "ifupdown.nw"
    {
        char *command;


#line 3064 "ifupdown.nw"
        if ((command = strrchr(argv[0],'/'))) {
            command++; /* first char after / */
        } else {
            command = argv[0]; /* no /'s in argv[0] */
        }
#line 3057 "ifupdown.nw"

#line 3072 "ifupdown.nw"
        if (strcmp(command, "ifup")==0) {
            cmds = iface_up;
        } else if (strcmp(command, "ifdown")==0) {
            cmds = iface_down;
        } else {
            fprintf(stderr,"This command should be called as ifup or ifdown\n");
            exit(1);
        }
#line 3058 "ifupdown.nw"
    }
#line 2995 "ifupdown.nw"

#line 3234 "ifupdown.nw"
    for(;;) {
        int c;
        c = getopt_long(argc, argv, "e:s:i:hVvna", long_opts, NULL);
        if (c == EOF) break;

        switch(c) {

#line 3252 "ifupdown.nw"
        case 'i':
            interfaces = strdup(optarg);
            break;
#line 3257 "ifupdown.nw"
        case 'v':
            verbose = 1;
            break;
#line 3262 "ifupdown.nw"
        case 'a':
            do_all = 1;
            break;
#line 3267 "ifupdown.nw"
        case 3:
            allow_class = strdup(optarg);
            break;
#line 3272 "ifupdown.nw"
        case 'n':
            no_act = 1;
            break;
#line 3277 "ifupdown.nw"
        case 1:
            run_mappings = 0;
            break;
#line 3282 "ifupdown.nw"
        case 2:
            force = 1;
            break;
#line 3287 "ifupdown.nw"
        case 'e':
            excludeint = strdup(optarg);
            break;
#line 3295 "ifupdown.nw"
        case 'h':
            help(argv[0]);
            break;
#line 3300 "ifupdown.nw"
        case 'V':
            version(argv[0]);
            break;
#line 3309 "ifupdown.nw"
        default:
            usage(argv[0]);
            break;
#line 3241 "ifupdown.nw"
        }
    }

#line 3321 "ifupdown.nw"
    if (argc - optind > 0 && do_all) {
        usage(argv[0]);
    }
#line 3327 "ifupdown.nw"
    if (argc - optind == 0 && !do_all) {
        usage(argv[0]);
    }

#line 2997 "ifupdown.nw"

#line 3342 "ifupdown.nw"
    defn = read_interfaces(interfaces);
    if ( !defn ) {
        fprintf(stderr, "%s: couldn't read interfaces file \"%s\"\n",
                argv[0], interfaces);
        exit(1);
    }

#line 2999 "ifupdown.nw"

#line 3632 "ifupdown.nw"
    {
        state_fp = fopen(statefile, no_act ? "r" : "a+");
        if (state_fp == NULL && !no_act) {
            fprintf(stderr,
                    "%s: failed to open statefile %s: %s\n",
                    argv[0], statefile, strerror(errno));
            exit (1);
        }

        if (state_fp != NULL) {
            char buf[80];
            char *p;

            if (!no_act) {
                int flags;

                if ((flags = fcntl(fileno(state_fp), F_GETFD)) < 0
                        || fcntl(fileno(state_fp), F_SETFD, flags | FD_CLOEXEC) < 0) {
                    fprintf(stderr,
                            "%s: failed to set FD_CLOEXEC on statefile %s: %s\n",
                            argv[0], statefile, strerror(errno));
                    exit(1);
                }

                if (lock_fd (fileno(state_fp)) < 0) {
                    fprintf(stderr,
                            "%s: failed to lock statefile %s: %s\n",
                            argv[0], statefile, strerror(errno));
                    exit(1);
                }

            }

            rewind (state_fp);
            while((p = fgets(buf, sizeof buf, state_fp)) != NULL) {
                char *pch;

                pch = buf + strlen(buf) - 1;
                while(pch > buf && isspace(*pch)) pch--;
                *(pch+1) = '\0';

                pch = buf;
                while(isspace(*pch)) pch++;

                add_to_state(&state, &n_state, &max_state, strdup(pch));
            }
        }
    }
#line 3508 "ifupdown.nw"
    if (do_all) {
        if (
#line 3087 "ifupdown.nw"
            (cmds == iface_up)
#line 3509 "ifupdown.nw"
        ) {
            allowup_defn *autos = find_allowup(defn, "auto");
            target_iface = autos ? autos->interfaces : NULL;
            n_target_ifaces = autos ? autos->n_interfaces : 0;
        } else if (
#line 3091 "ifupdown.nw"
            (cmds == iface_down)
#line 3513 "ifupdown.nw"
        ) {
            target_iface = state;
            n_target_ifaces = n_state;
        } else {
            assert(0);
        }
    } else {
        target_iface = argv + optind;
        n_target_ifaces = argc - optind;
    }
#line 3357 "ifupdown.nw"
    {
        int i;
        for (
#line 3502 "ifupdown.nw"
            i = 0; i < n_target_ifaces; i++
#line 3359 "ifupdown.nw"
        ) {
            char iface[80], liface[80];


#line 3526 "ifupdown.nw"
            strncpy(iface, target_iface[i], sizeof(iface));
            iface[sizeof(iface)-1] = '\0';

            {
                char *pch;
                if ((pch = strchr(iface, '='))) {
                    *pch = '\0';
                    strncpy(liface, pch+1, sizeof(liface));
                    liface[sizeof(liface)-1] = '\0';
                } else {
                    strncpy(liface, iface, sizeof(liface));
                    liface[sizeof(liface)-1] = '\0';
                }
            }
#line 3363 "ifupdown.nw"
            if (!force) {

#line 3715 "ifupdown.nw"
                {
                    int already_up = lookfor_iface(state, n_state, iface);;

                    if (
#line 3087 "ifupdown.nw"
                        (cmds == iface_up)
#line 3718 "ifupdown.nw"
                    ) {
                        if (already_up != -1) {
                            fprintf(stderr,
                                    "%s: interface %s already configured\n",
                                    argv[0], iface);
                            continue;
                        }
                    } else if (
#line 3091 "ifupdown.nw"
                        (cmds == iface_down)
#line 3725 "ifupdown.nw"
                    ) {
                        if (already_up == -1) {
                            fprintf(stderr, "%s: interface %s not configured\n",
                                    argv[0], iface);
                            continue;
                        }
                        strncpy(liface, strchr(state[already_up], '=') + 1, 80);
                        liface[79] = 0;
                    } else {
                        assert(0);
                    }
                }
#line 3365 "ifupdown.nw"
            }

            if (
#line 3100 "ifupdown.nw"
                (allow_class != NULL)

#line 3367 "ifupdown.nw"
            ) {

#line 3103 "ifupdown.nw"
                {
                    int i;
                    allowup_defn *allowup = find_allowup(defn, allow_class);
                    if (allowup == NULL)
                        continue;

                    for (i = 0; i < allowup->n_interfaces; i++) {
                        if (strcmp(allowup->interfaces[i], iface) == 0)
                            break;
                    }
                    if (i >= allowup->n_interfaces)
                        continue;
                }
#line 3369 "ifupdown.nw"
            }

            if (
#line 3125 "ifupdown.nw"
                (excludeint != NULL && strstr(iface,excludeint) != NULL)
#line 3371 "ifupdown.nw"
            )
                continue;

            if (
#line 3087 "ifupdown.nw"
                (cmds == iface_up)
#line 3374 "ifupdown.nw"
                && run_mappings) {

#line 3392 "ifupdown.nw"
                {
                    mapping_defn *currmap;
                    for (currmap = defn->mappings; currmap; currmap = currmap->next) {
                        int i;
                        for (i = 0; i < currmap->n_matches; i++) {

#line 3413 "ifupdown.nw"
                            if (fnmatch(currmap->match[i], liface, 0) != 0)
                                continue;
#line 3398 "ifupdown.nw"

#line 3421 "ifupdown.nw"
                            if (verbose) {
                                fprintf(stderr, "Running mapping script %s on %s\n",
                                        currmap->script, liface);
                            }
                            run_mapping(iface, liface, sizeof(liface), currmap);
#line 3399 "ifupdown.nw"
                            break;
                        }
                    }
                }
#line 3376 "ifupdown.nw"
            }


#line 3431 "ifupdown.nw"
            {
                interface_defn *currif;
                int okay = 0;
                int failed = 0;
                for (currif = defn->ifaces; currif; currif = currif->next) {
                    if (strcmp(liface, currif->logical_iface) == 0) {
                        okay = 1;


#line 3457 "ifupdown.nw"
                        {
                            currif->real_iface = iface;

                            if (verbose) {
                                fprintf(stderr, "Configuring interface %s=%s (%s)\n",
                                        iface, liface, currif->address_family->name);
                            }

                            switch(cmds(currif)) {
                            case -1:
                                printf("Don't seem to be have all the variables for %s/%s.\n",
                                       liface, currif->address_family->name);
                                failed = 1;
                                break;
                            case 0:
                                failed = 1;
                                break;
                            /* not entirely successful */
                            case 1:
                                failed = 0;
                                break;
                            /* successful */
                            default:
                                printf("Internal error while configuring interface %s/%s (assuming it failed)\n",
                                       liface, currif->address_family->name);
                                failed = 1;
                                /* what happened here? */
                            }
                            currif->real_iface = NULL;
                        }

#line 3441 "ifupdown.nw"
                        if (failed) break;
                        /* Otherwise keep going: this interface may have
                         * match with other address families */
                    }
                }

                if (!okay && !force) {
                    fprintf(stderr, "Ignoring unknown interface %s=%s.\n",
                            iface, liface);
                } else {

#line 3743 "ifupdown.nw"
                    {
                        int already_up = lookfor_iface(state, n_state, iface);

                        if (
#line 3087 "ifupdown.nw"
                            (cmds == iface_up)
#line 3746 "ifupdown.nw"
                        ) {
                            char *newiface =
                                malloc(strlen(iface) + 1 + strlen(liface) + 1);
                            sprintf(newiface, "%s=%s", iface, liface);

                            if (already_up == -1) {
                                if (failed == 1) {
                                    printf("Failed to bring up %s.\n", liface);
                                } else {
                                    add_to_state(&state, &n_state, &max_state, newiface);
                                }
                            } else {
                                free(state[already_up]);
                                state[already_up] = newiface;
                            }
                        } else if (
#line 3091 "ifupdown.nw"
                            (cmds == iface_down)
#line 3761 "ifupdown.nw"
                        ) {
                            if (already_up != -1) {
                                state[already_up] = state[--n_state];
                            }
                        } else {
                            assert(0);
                        }
                    }
#line 3452 "ifupdown.nw"
                }
            }
#line 3379 "ifupdown.nw"

#line 3691 "ifupdown.nw"
            if (state_fp != NULL && !no_act) {
                int i;

                if (ftruncate(fileno(state_fp), 0) < 0)
                {
                    fprintf(stderr,
                            "%s: failed to truncate statefile %s: %s\n",
                            argv[0], statefile, strerror(errno));
                    exit(1);
                }

                rewind(state_fp);
                for (i = 0; i < n_state; i++) {
                    fprintf(state_fp, "%s\n", state[i]);
                }
                fflush(state_fp);
            }
#line 3380 "ifupdown.nw"
        }
    }
#line 3683 "ifupdown.nw"
    if (state_fp != NULL) {
        fclose(state_fp);
        state_fp = NULL;
    }

#line 3001 "ifupdown.nw"
    return 0;
}
Ejemplo n.º 12
0
G_MODULE_EXPORT gboolean
timeout(gpointer data)
{
	(void)data;

	if(gstate == STATE_CONNECTED){
		switch(ft_gotaction(&ft)){
			case FT_YES:
				/*
				 * state = STATE_TRANSFER;
				 * cmds();
				 * no need for this - set in the callback straight away
				 */

				if(!ft_connected(&ft)){
					/* connection closed */
					status("Connection closed");
					CLOSE();
					return FALSE; /* timer death */
				}

				if(ft_recv(&ft, callback, queryback, fnameback, inputback)){
					status("Couldn't receive incoming data: %s", ft_lasterr(&ft));
					CLOSE();
				}else{
					/*
					 * status("Received %s", ft_truncname(&ft, 32));
					 * don't do ^ here, it's done in the callback
					 */
					STAY_OPEN();
				}
				return FALSE; /* kill timer */

			case FT_ERR:
				status("ft_poll() error: %s", ft_lasterr(&ft));
				CLOSE();
				return FALSE;

			case FT_NO:
				return TRUE; /* keep looking */
		}
		/* unreachable */
	}else{
		enum ftret ftr = ft_accept(&ft);

		if(cancelled){
			status("Cancelled");
			cancelled = 0;
			return FALSE;
		}else
			switch(ftr){
				case FT_ERR:
					status("Couldn't accept connection: %s", ft_lasterr(&ft));
					return FALSE; /* kill timer */

				case FT_YES:
					status("Got connection from %s", ft_remoteaddr(&ft));
					gstate = STATE_CONNECTED;
					URGENT(1);
					cmds();
					/* fall */
				case FT_NO:
					return TRUE; /* make sure timeout keeps getting called */
			}
		/* unreachable */
	}
	/* unreachable (unless bogus enum value) */
	return TRUE;
}
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
	GError     *error = NULL;
	GtkBuilder *builder;

#if defined(_WIN32) && defined(GFT_USE_MANIFEST)
	{
		INITCOMMONCONTROLSEX tim;
		memset(&tim, 0, sizeof tim);
		tim.dwSize = sizeof tim;
		tim.dwICC = ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES |
								ICC_DATE_CLASSES | ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES |
								ICC_LISTVIEW_CLASSES | ICC_NATIVEFNTCTL_CLASS |
								ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
								ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES |
								ICC_UPDOWN_CLASS | ICC_USEREX_CLASSES | ICC_STANDARD_CLASSES;

		if(InitCommonControlsEx(&tim) == FALSE)
			fputs("warning: InitCommomControlsEx() failed\n", stderr);
	}
#endif

#ifndef _WIN32
	if(signal(SIGCHLD, SIG_IGN) == SIG_ERR)
		perror("signal(SIGCHLD)");
#endif

	ft_zero(&ft);
	ft_async(&ft) = 1;
	gtk_init(&argc, &argv); /* bail here if !$DISPLAY */

#ifdef _WIN32
	{
		int debug = 0;

		if(argc == 2){
			if(!strcmp(argv[1], "-d")){
				debug = 1;
				fprintf(stderr, "%s: debug on\n",
						*argv);
			}else{
usage:
				fprintf(stderr, "Usage: %s [-d]\n",
						*argv);
				return 1;
			}
		}else if(argc != 1)
			goto usage;

		if(!debug){
			fputs("gft: debug off\n", stderr);
			FreeConsole();
		}
	}
#else
	if(argc != 1){
		fprintf(stderr, "Usage: %s\n", *argv);
		return 1;
	}
#endif

	builder = gtk_builder_new();

	if(gladegen_init())
		return 1;

	if(!gtk_builder_add_from_file(builder, GLADE_XML_FILE, &error)){
		g_warning("%s", error->message);
		/*g_free(error);*/
		return 1;
	}
	gladegen_term();

	if(getobjects(builder))
		return 1;

	gtk_builder_connect_signals(builder, NULL);

	glist_init(&listTransfers, treeTransfers);

	/* don't need it anymore */
	g_object_unref(G_OBJECT(builder));

	/* signal setup */
	g_signal_connect(G_OBJECT(winMain), "delete-event" ,       G_CALLBACK(on_winMain_delete_event),    NULL);
	g_signal_connect(G_OBJECT(winMain), "destroy",             G_CALLBACK(on_winMain_destroy),         NULL);

	cfg_read(cboHost);
	tray_init(winMain, *argv);
	transfers_init(&listDone, treeDone);

	gtk_widget_set_sensitive(btnSend, FALSE);
	drag_init();

	cmds();
	gtk_widget_show_all(winMain);
	gtk_main();

	tray_term();

	return 0;
}
Ejemplo n.º 14
0
 MgSelection* getSelection() { return cmds()->getSelection(); }
Ejemplo n.º 15
0
 CmdSubject* getCmdSubject() { return cmds()->getCmdSubject(); }
Ejemplo n.º 16
0
void pfunction::compile_postfix(const std::vector<pstring> &inputs, const pstring &expr)
{
	std::vector<pstring> cmds(plib::psplit(expr, " "));
	compile_postfix(inputs, cmds, expr);
}
Ejemplo n.º 17
0
static bool parsecmdl(const wchar_t *cmdl)
{
    ts::wstr_c wd;
    ts::set_work_dir(wd);

    ts::token<wchar_t> cmds(cmdl, ' ');
    bool wait_cmd = false;
    bool installto = false;
    bool conf = false;
    uint processwait = 0;
    for (; cmds; ++cmds)
    {
        if (wait_cmd)
        {
            processwait = cmds->as_uint();
            wait_cmd = false;
            continue;
        }

        if (installto)
        {
            if (ts::is_admin_mode())
            {
                ts::wstr_c installto_path(*cmds);
                installto_path.replace_all('*', ' ');
                install_to(installto_path, false);
            }
            return false;
        }

        if (conf)
        {
            if (!g_commandline.alternative_config_path.is_empty()) g_commandline.alternative_config_path.append_char(' ');
            g_commandline.alternative_config_path.append(*cmds);
            if ( g_commandline.alternative_config_path.get_char(0) != '\"' || g_commandline.alternative_config_path.get_last_char() == '\"' )
            {
                conf = false;
                g_commandline.alternative_config_path.trunc_char('\"');
                if (g_commandline.alternative_config_path.get_char(0) == '\"')
                    g_commandline.alternative_config_path.cut(0);
            }
            continue;
        }

        if (cmds->equals(CONSTWSTR("wait")))
        {
            wait_cmd = true;
            continue;
        }

        if (cmds->equals(CONSTWSTR("multi")))
        {
            g_commandline.checkinstance = false;
            continue;
        }

        if (cmds->equals(CONSTWSTR("minimize")))
        {
            g_commandline.minimize = true;
            continue;
        }

        if (cmds->equals(CONSTWSTR("readonly")))
        {
            g_commandline.readonlymode = true;
            continue;
        }

        if (cmds->equals(CONSTWSTR("installto")))
        {
            installto = true;
            continue;
        }

        if (cmds->equals(CONSTWSTR("config")))
        {
            conf = true;
            continue;
        }

    }

    if (processwait)
    {
        HANDLE h = OpenProcess(SYNCHRONIZE,FALSE,processwait);
        if (h)
        {
            DWORD r = WaitForSingleObject(h, 10000);
            CloseHandle(h);
            if (r == WAIT_TIMEOUT ) return false;
        }
    }

    return true;
}