예제 #1
0
파일: cli.c 프로젝트: Hmaal/slash
static void
process_arguments(sl_vm_t* vm, int argc, char** argv)
{
    int i = 1;
    for(; i < argc; i++) {
        if(strcmp(argv[i], "-I") == 0) {
            if(i + 1 == argc) {
                fprintf(stderr, "Expected <path> after -I\n");
                shutdown_vm(vm, 1);
            }
            sl_require_path_prepend(vm, argv[++i]);
            continue;
        }
        if(strcmp(argv[i], "-i") == 0) {
            opt_interactive = true;
            continue;
        }
        if(strcmp(argv[i], "-h") == 0) {
            print_help(argv[0]);
            shutdown_vm(vm, 0);
        }
        if(strcmp(argv[i], "--") == 0) {
            i++;
            break;
        }
        if(argv[i][0] == '-') {
            fprintf(stderr, "Unknown option '%s'\n", argv[i]);
            shutdown_vm(vm, 1);
        }
        break;
    }
    if(!opt_interactive) {
        if(i == argc || strcmp(argv[i], "-") == 0) {
            opt_source_file = stdin;
            opt_source_file_name = "(stdin)";
        } else {
            opt_source_file = fopen(argv[i], "rb");
            opt_source_file_name = argv[i];
            if(!opt_source_file) {
                perror("Could not open source file");
                shutdown_vm(vm, 1);
            }
        }
        i++;
    }
    SLVAL vargv = sl_make_array(vm, 0, NULL);
    for(; i < argc; i++) {
        SLVAL varg = sl_make_cstring(vm, argv[i]);
        sl_array_push(vm, vargv, 1, &varg);
    }
    sl_class_set_const(vm, vm->lib.Object, "ARGV", vargv);
}
예제 #2
0
파일: cgi.c 프로젝트: PatrickFang/slash
static void 
load_cgi_options(sl_vm_t* vm, cgi_options* options) 
{
    int i = 0;
    for(; options->incpaths && i < options->incpaths_count; i++) {
        sl_require_path_prepend(vm, options->incpaths[i]);
    }

    SLVAL vargv = sl_make_array(vm, 0, NULL);
    for(i = 0; i < options->arg_script_options_count; i++) {
        SLVAL varg = sl_make_cstring(vm, options->arg_script_options[i]);
        sl_array_push(vm, vargv, 1, &varg);
    }
    sl_class_set_const(vm, vm->lib.Object, "ARGV", vargv);
}