コード例 #1
0
ファイル: ProguardParser.cpp プロジェクト: facebook/redex
bool parse_keep(std::vector<unique_ptr<Token>>::iterator* it,
                token keep_kind,
                KeepSpecSet* spec,
                bool mark_classes,
                bool mark_conditionally,
                bool allowshrinking,
                const std::string& filename,
                uint32_t line,
                bool* ok) {
  if ((**it)->type == keep_kind) {
    ++(*it); // Consume the keep token
    auto keep = std::make_unique<KeepSpec>();
    keep->mark_classes = mark_classes;
    keep->mark_conditionally = mark_conditionally;
    keep->allowshrinking = allowshrinking;
    keep->source_filename = filename;
    keep->source_line = line;
    if (!parse_modifiers(it, &*keep)) {
      skip_to_next_command(it);
      return true;
    }
    keep->class_spec = parse_class_specification(it, ok);
    spec->emplace(std::move(keep));
    return true;
  }
  return false;
}
コード例 #2
0
ファイル: speckeysd.cpp プロジェクト: 007durgesh219/jessies
static void add_hot_key(const char* keyname, const char* command) {
    char* copy = strdup(keyname);
    char* unmodified = strrchr(copy, '-');
    unsigned int modifiers = 0;
    if (unmodified == NULL) {
        unmodified = copy;
    } else {
        *unmodified = 0;
        ++ unmodified;
        modifiers = parse_modifiers(copy, keyname);
    }
    
    HotKey* new_key = new HotKey;
    new_key->keysym = XStringToKeysym(unmodified);
    new_key->modifiers = modifiers;
    new_key->command = strdup(command);
    new_key->next = hotkeys;
    hotkeys = new_key;
    
    XSynchronize(dpy, True);
    attempting_to_grab = keyname;
    XSetErrorHandler(report_key_grab_error);
    for (int screen = 0; screen < screen_count; ++screen) {
        Window root = RootWindow(dpy, screen);
        XGrabKey(dpy, XKeysymToKeycode(dpy, new_key->keysym), modifiers, root, False, GrabModeAsync, GrabModeAsync);
    }
    XSetErrorHandler(NULL);
    
    free(copy);
}
コード例 #3
0
ファイル: ProguardParser.cpp プロジェクト: RyanFu/redex
bool parse_keep(std::vector<unique_ptr<Token>>::iterator* it,
                token keep_kind,
                std::vector<KeepSpec>* spec,
                bool mark_classes,
                bool mark_conditionally,
                bool allowshrinking,
                const std::string& filename,
                uint32_t line,
                bool* ok) {
  if ((**it)->type == keep_kind) {
    ++(*it); // Consume the keep token
    KeepSpec keep;
    keep.mark_classes = mark_classes;
    keep.mark_conditionally = mark_conditionally;
    keep.allowshrinking = allowshrinking;
    keep.source_filename = filename;
    keep.source_line = line;
    if (!parse_modifiers(it, &keep)) {
      skip_to_next_command(it);
      return true;
    }
    keep.class_spec = parse_class_specification(it, ok);
    spec->push_back(keep);
    return true;
  }
  return false;
}
コード例 #4
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_limit(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 4 || (argc - index + 1) > 5)
    {
        sharedq_help_limit();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "h");

    if (param.help)
    {
        sharedq_help_limit();
        return;
    }

    long nano = 0;
    if ((argc - index + 1) == 5) {
        nano = sharedq_atol(argv[index + 3], strlen(argv[index + 3]));
        if (nano < 0) {
            printf("sharedq:  invalid queue nanosecond timelimit argument\n");
            return;
        }
    }
    long sec = 0;
    if ((argc - index + 1) >= 4) {
        sec = sharedq_atol(argv[index + 2], strlen(argv[index + 2]));
        if (sec < 0) {
            printf("sharedq:  invalid queue seconds timelimit argument\n");
            return;
        }
    }
    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_READ_ONLY);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }

    shr_q_timelimit(q, sec, nano);

    shr_q_close(&q);
}
コード例 #5
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_listen(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 3 || (argc - index + 1) > 3)
    {
        sharedq_help_listen();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "h");

    if (param.help)
    {
        sharedq_help_listen();
        return;
    }

    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_READ_ONLY);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }

    shr_q_listen(q, SIGUSR1);

    while(running) {
        int rc = sem_wait(&adds);
        if (rc < 0) {
            if (errno == EINTR) {
                continue;
            }
            break;
        }
        printf("Item added to empty queue %s\n", argv[index + 1]);
    }

    shr_q_close(&q);
}
コード例 #6
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_list(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 2 || (argc - index + 1) > 2) {
        sharedq_help_list();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "hv");

    if (param.help) {
        sharedq_help_list();
        return;
    }

    struct dirent *entry;
    DIR *dir;

    dir = opendir(SHR_OBJ_DIR);
    if (dir == NULL) {
        printf("sharedq: path does not exist to shared memory directory\n");
        exit(1);
    }

    if (param.verbose) {
        printf("\n\t queues \t\t  depth \t\t   size \n");
        printf("\t--------\t\t---------\t\t----------\n");
    }
    char path[PATH_MAX];
    int offset = strlen(SHR_OBJ_DIR);
    memcpy(&path[0], SHR_OBJ_DIR, offset);
    shr_q_s *q = NULL;
    struct stat st;
    while((entry = readdir(dir))) {
        memcpy(&path[0] + offset, entry->d_name, strlen(entry->d_name) + 1);
        int rc = stat(path, &st);
        if (rc == 0 && S_ISREG(st.st_mode)) {
            if (shr_q_open(&q, entry->d_name, SQ_IMMUTABLE) == SH_OK) {
                if (param.verbose) {
                    printf("\t%-16s\t%9li\t\t %9li\n",
                        entry->d_name, shr_q_count(q), st.st_size);
                } else {
                    printf("%s\n", entry->d_name);
                }
                shr_q_close(&q);
            }
        }
    }

    if (param.verbose) {
        putchar('\n');
    }

    closedir(dir);
}
コード例 #7
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_level(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 4 || (argc - index + 1) > 4)
    {
        sharedq_help_level();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "h");

    if (param.help)
    {
        sharedq_help_level();
        return;
    }

    long depth = 0;
    if ((argc - index + 1) == 4) {
        depth = sharedq_atol(argv[index + 2], strlen(argv[index + 2]));
        if (depth < 0) {
            printf("sharedq:  invalid queue depth argument\n");
            return;
        }
    }
    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_READ_ONLY);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }

    shr_q_level(q, depth);

    shr_q_close(&q);
}
コード例 #8
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_add(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 3 || (argc - index + 1) > 4) {
        sharedq_help_add();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "h");


    if (param.help) {
        sharedq_help_add();
        return;
    }

    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_WRITE_ONLY);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }

    if ((argc - index + 1) == 4) {
        queue_from_file(q, argv[index + 2]);
    } else {
        queue_from_stdin(q);
    }

    shr_q_close(&q);
}
コード例 #9
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_destroy(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 3 || (argc - index + 1) > 3) {
        sharedq_help_destroy();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "h");

    if (param.help) {
        sharedq_help_destroy();
        return;
    }

    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_IMMUTABLE);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }
    status = shr_q_destroy(&q);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for destroy function\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }
}
コード例 #10
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_create(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 3 || (argc - index + 1) > 4) {
        sharedq_help_create();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "h");

    if (param.help) {
        sharedq_help_create();
        return;
    }

    long maxsize = 0;
    if ((argc - index + 1) == 4) {
        maxsize = sharedq_atol(argv[index + 2], strlen(argv[index + 2]));
        if (maxsize < 0) {
            printf("sharedq:  invalid queue maxsize argument\n");
            return;
        }
    }
    shr_q_s *q = NULL;
    sh_status_e status = shr_q_create(&q, argv[index + 1], maxsize, SQ_IMMUTABLE);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for create function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name already exists\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }
}
コード例 #11
0
ファイル: speckeysd.cpp プロジェクト: 007durgesh219/jessies
unsigned int parse_modifiers(char* name, const char* full_spec) {
    char* separator = strchr(name, '-');
    unsigned int modifiers = 0;
    if (separator != NULL) {
        *separator = 0;
        modifiers |= parse_modifiers(separator+1, full_spec);
    }
    if (!strcmp(name, "Shift")) {
        modifiers |= ShiftMask;
    } else if (!strcmp(name, "Control")) {
        modifiers |= ControlMask;
    } else if (!strcmp(name, "Alt") || !strcmp(name, "Mod1")) {
        modifiers |= Mod1Mask;
    } else if (!strcmp(name, "Mod2")) {
        modifiers |= Mod2Mask;
    } else if (!strcmp(name, "Mod3")) {
        modifiers |= Mod3Mask;
    } else if (!strcmp(name, "Super") || !strcmp(name, "Mod4")) {
        modifiers |= Mod4Mask;
    } else {
        fprintf(stderr, "%s: ignoring unknown modifier \"%s\" in \"%s\"\n", argv0, name, full_spec);
    }
    return modifiers;
}
コード例 #12
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_monitor(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 3 || (argc - index + 1) > 3)
    {
        sharedq_help_monitor();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "h");

    if (param.help)
    {
        sharedq_help_monitor();
        return;
    }

    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_READ_ONLY);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }

    shr_q_monitor(q, SIGUSR2);

    while(running) {
        int rc = sem_wait(&events);
        if (rc < 0) {
            if (errno == EINTR) {
                continue;
            }
            break;
        }
        sq_event_e event = SQ_EVNT_NONE;
        do {
            event = shr_q_event(q);
            switch(event) {
            case SQ_EVNT_INIT :
                printf("Event: initial add of item to queue\n");
                break;
            case SQ_EVNT_LIMIT :
                printf("Event: queue limit reached\n");
                break;
            case SQ_EVNT_LEVEL :
                printf("Event: depth level reached\n");
                break;
            case SQ_EVNT_TIME :
                printf("Event: time limit on queue reached\n");
                break;
            default :
                break;
            }
        } while (event != SQ_EVNT_NONE);
    }

    shr_q_close(&q);
}
コード例 #13
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_drain(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 3 || (argc - index + 1) > 3)
    {
        sharedq_help_drain();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "bhvx");

    if (param.help)
    {
        sharedq_help_drain();
        return;
    }
    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_READ_ONLY);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }

    pid_t pid = getpid();

    sq_item_s item = {0};

    struct timespec itm_intrvl;
    struct timespec call_intrvl;
    struct timespec call_start;
    struct timespec call_end;
    do {
        clock_gettime(CLOCK_REALTIME, &call_start);
        if (param.block) {
            item = shr_q_remove_wait(q, &item.buffer, &item.buf_size);
        } else {
            item = shr_q_remove(q, &item.buffer, &item.buf_size);
        }
        clock_gettime(CLOCK_REALTIME, &call_end);
        if (item.status == SH_ERR_ARG) {
            printf("sharedq:  invalid argument for remove function\n");
        } else if (item.status == SH_ERR_EMPTY) {
            if (param.block) {
                item.status = SH_OK;
            }
            printf("sharedq:  queue is empty\n");
        } else if (item.status == SH_ERR_NOMEM) {
            printf("sharedq:  not enough memory to complete remove\n");
        } else if (item.status == SH_OK) {
            timespecsub(&call_end, &call_start, &call_intrvl);
            if (param.hex) {
                hex_format(item.value, item.length);
            } else {
                timespecsub(&call_end, item.timestamp, &itm_intrvl);
                if (param.verbose) {
                    printf("%li.%09li--(%i)--%li.%09li--%li.%09li-->%s\n",
                        call_end.tv_sec, call_end.tv_nsec, pid,
                        itm_intrvl.tv_sec, itm_intrvl.tv_nsec,
                        call_intrvl.tv_sec, call_intrvl.tv_nsec,
                        (char *)item.value);
                } else {
                    printf("-->%s\n", (char *)item.value);
                }
            }
            if (param.block) {
                clock_gettime(CLOCK_REALTIME, &call_start);
                if (param.verbose) {
                    printf("%li.%09li--(%i) sleeping \n", call_start.tv_sec,
                        call_start.tv_nsec, pid);
                }
                struct timespec nano = {.tv_sec = 1, .tv_nsec = 0};
                while(nanosleep(&nano, &nano) < 0) {
                    if (errno != EINTR) {
                        break;
                    }
                }
                clock_gettime(CLOCK_REALTIME, &call_start);
                if (param.verbose) {
                    printf("%li.%09li--(%i) waking \n", call_start.tv_sec,
                        call_start.tv_nsec, pid);
                }
            }
        }
    } while (item.status == SH_OK);


    shr_q_close(&q);
}
コード例 #14
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_remove(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 3 || (argc - index + 1) > 3)
    {
        sharedq_help_remove();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "bhx");

    if (param.help) {
        sharedq_help_remove();
        return;
    }

    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_READ_ONLY);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }

    sq_item_s item = {0};

    if (param.block) {
        item = shr_q_remove_wait(q, &item.buffer, &item.buf_size);
    } else {
        item = shr_q_remove(q, &item.buffer, &item.buf_size);
    }

    if (item.status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for remove function\n");
    } else if (item.status == SH_ERR_EMPTY) {
        printf("sharedq:  queue is empty\n");
    } else if (item.status == SH_ERR_NOMEM) {
        printf("sharedq:  not enough memory to complete remove\n");
    } else {
        if (param.hex) {
            hex_format(item.value, item.length);
        } else {
            printf("%s\n", (char *)item.value);
        }
    }

    shr_q_close(&q);
}
コード例 #15
0
ファイル: main.c プロジェクト: bkarr/libshr
void sharedq_pull(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 3 || (argc - index + 1) > 4) {
        sharedq_help_pull();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "hv");


    if (param.help) {
        sharedq_help_pull();
        return;
    }

    sigset_t mask;
    int fd;

    // set up signalfd
    sigemptyset(&mask);
    sigaddset(&mask, SIGRTMIN + 1);
    if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) {
        printf("sharedq:  unable to set signal mask to block\n");
        return;
    }
    fd = signalfd(-1, &mask, 0);
    if (fd == -1) {
        printf("sharedq:  unable to create signal fd\n");
        return;
    }

    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_WRITE_ONLY);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }
    status = shr_q_call(q, SIGRTMIN + 1);
    if (status != SH_OK) {
        printf("sharedq:  unable to register call signal\n");
        return;
    }

    if ((argc - index + 1) == 4) {
        pull_from_file(q, argv[index + 2], fd, &param);
    } else {
        pull_from_stdin(q, fd);
    }

    shr_q_close(&q);
}
コード例 #16
0
/*
 * Set Power Management
 */
static int
set_power_info(int		skfd,
	       char *		ifname,
	       char *		args[],		/* Command line args */
	       int		count)		/* Args count */
{
  struct iwreq		wrq;
  int			i = 1;

  if(!strcasecmp(args[0], "off"))
    wrq.u.power.disabled = 1;	/* i.e. max size */
  else
    if(!strcasecmp(args[0], "on"))
      {
	/* Get old Power info */
	wrq.u.power.flags = 0;
	if(iw_get_ext(skfd, ifname, SIOCGIWPOWER, &wrq) < 0)
	  return(IWERR_GET_EXT);
	wrq.u.power.disabled = 0;
      }
    else
      {
	double		value;
	char *		unit;
	int		gotone = 0;

	/* Parse modifiers */
	i = parse_modifiers(args, count, &wrq.u.power.flags,
			    iwmod_power, IWMOD_POWER_NUM);
	if(i < 0)
	  return(i);

	wrq.u.power.disabled = 0;

	/* Is there any value to grab ? */
	value = strtod(args[0], &unit);
	if(unit != args[0])
	  {
	    struct iw_range	range;
	    int			flags;
	    /* Extract range info to handle properly 'relative' */
	    if(iw_get_range_info(skfd, ifname, &range) < 0)
	      memset(&range, 0, sizeof(range));

	    /* Get the flags to be able to do the proper conversion */
	    switch(wrq.u.power.flags & IW_POWER_TYPE)
	      {
	      case IW_POWER_SAVING:
		flags = range.pms_flags;
		break;
	      case IW_POWER_TIMEOUT:
		flags = range.pmt_flags;
		break;
	      default:
		flags = range.pmp_flags;
		break;
	      }
	    /* Check if time or relative */
	    if(flags & IW_POWER_RELATIVE)
	      {
		if(range.we_version_compiled < 21)
		  value *= MEGA;
		else
		  wrq.u.power.flags |= IW_POWER_RELATIVE;
	      }
	    else
	      {
		value *= MEGA;	/* default = s */
		if(unit[0] == 'u') value /= MEGA;
		if(unit[0] == 'm') value /= KILO;
	      }
	    wrq.u.power.value = (long) value;
	    /* Set some default type if none */
	    if((wrq.u.power.flags & IW_POWER_TYPE) == 0)
	      wrq.u.power.flags |= IW_POWER_PERIOD;
	    ++i;
	    gotone = 1;
	  }

	/* Now, check the mode */
	if(i < count)
	  {
	    if(!strcasecmp(args[i], "all"))
	      wrq.u.power.flags |= IW_POWER_ALL_R;
	    if(!strncasecmp(args[i], "unicast", 4))
	      wrq.u.power.flags |= IW_POWER_UNICAST_R;
	    if(!strncasecmp(args[i], "multicast", 5))
	      wrq.u.power.flags |= IW_POWER_MULTICAST_R;
	    if(!strncasecmp(args[i], "force", 5))
	      wrq.u.power.flags |= IW_POWER_FORCE_S;
	    if(!strcasecmp(args[i], "repeat"))
	      wrq.u.power.flags |= IW_POWER_REPEATER;
	    if(wrq.u.power.flags & IW_POWER_MODE)
	      {
		++i;
		gotone = 1;
	      }
	  }
	if(!gotone)
	  {
	    errarg = i;
	    return(IWERR_ARG_TYPE);
	  }
      }

  if(iw_set_ext(skfd, ifname, SIOCSIWPOWER, &wrq) < 0)
    return(IWERR_SET_EXT);

  /* Var args */
  return(i);
}
コード例 #17
0
/*
 * Set Retry Limit
 */
static int
set_retry_info(int		skfd,
	       char *		ifname,
	       char *		args[],		/* Command line args */
	       int		count)		/* Args count */
{
  struct iwreq		wrq;
  int			i = 0;
  double		value;
  char *		unit;

  /* Parse modifiers */
  i = parse_modifiers(args, count, &wrq.u.retry.flags,
		      iwmod_retry, IWMOD_RETRY_NUM);
  if(i < 0)
    return(i);

  /* Add default type if none */
  if((wrq.u.retry.flags & IW_RETRY_TYPE) == 0)
    wrq.u.retry.flags |= IW_RETRY_LIMIT;

  wrq.u.retry.disabled = 0;

  /* Is there any value to grab ? */
  value = strtod(args[0], &unit);
  if(unit == args[0])
    {
      errarg = i;
      return(IWERR_ARG_TYPE);
    }

  /* Limit is absolute, on the other hand lifetime is seconds */
  if(wrq.u.retry.flags & IW_RETRY_LIFETIME)
    {
      struct iw_range	range;
      /* Extract range info to handle properly 'relative' */
      if(iw_get_range_info(skfd, ifname, &range) < 0)
	memset(&range, 0, sizeof(range));

      if(range.r_time_flags & IW_RETRY_RELATIVE)
	{
	  if(range.we_version_compiled < 21)
	    value *= MEGA;
	  else
	    wrq.u.retry.flags |= IW_RETRY_RELATIVE;
	}
      else
	{
	  /* Normalise lifetime */
	  value *= MEGA;	/* default = s */
	  if(unit[0] == 'u') value /= MEGA;
	  if(unit[0] == 'm') value /= KILO;
	}
    }
  wrq.u.retry.value = (long) value;
  ++i;

  if(iw_set_ext(skfd, ifname, SIOCSIWRETRY, &wrq) < 0)
    return(IWERR_SET_EXT);

  /* Var args */
  return(i);
}
コード例 #18
0
ファイル: main.c プロジェクト: yugecin/evilwm
int main(int argc, char *argv[]) {
	struct sigaction act;
	int argn = 1, ret;

	{
		const char *home = getenv("HOME");
		if (home) {
			char *conffile = xmalloc(strlen(home) + sizeof(CONFIG_FILE) + 2);
			strcpy(conffile, home);
			strcat(conffile, "/" CONFIG_FILE);
			xconfig_parse_file(evilwm_options, conffile);
			free(conffile);
		}
	}
	ret = xconfig_parse_cli(evilwm_options, argc, argv, &argn);
	if (ret == XCONFIG_MISSING_ARG) {
		fprintf(stderr, "%s: missing argument to `%s'\n", argv[0], argv[argn]);
		exit(1);
	} else if (ret == XCONFIG_BAD_OPTION) {
		if (0 == strcmp(argv[argn], "-h")
				|| 0 == strcmp(argv[argn], "--help")) {
			helptext();
			exit(0);
#ifdef STDIO
		} else if (0 == strcmp(argv[argn], "-V")
				|| 0 == strcmp(argv[argn], "--version")) {
			LOG_INFO("evilwm version " VERSION "\n");
			exit(0);
#endif
		} else {
			helptext();
			exit(1);
		}
	}

	if (opt_grabmask1) grabmask1 = parse_modifiers(opt_grabmask1);
	if (opt_grabmask2) grabmask2 = parse_modifiers(opt_grabmask2);
	if (opt_altmask) altmask = parse_modifiers(opt_altmask);

	wm_exit = 0;
	act.sa_handler = handle_signal;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	sigaction(SIGTERM, &act, NULL);
	sigaction(SIGINT, &act, NULL);
	sigaction(SIGHUP, &act, NULL);

	setup_display();

	event_main_loop();

	/* Quit Nicely */
	while (clients_stacking_order)
		remove_client(clients_stacking_order->data);
	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
	if (font) XFreeFont(dpy, font);
	{
		int i;
		for (i = 0; i < num_screens; i++) {
			ewmh_deinit_screen(&screens[i]);
			XFreeGC(dpy, screens[i].invert_gc);
			XInstallColormap(dpy, DefaultColormap(dpy, i));
		}
	}
	free(screens);
	XCloseDisplay(dpy);

	return 0;
}