Пример #1
0
File*
fileopen(void)
{
	File *f;

	f = emalloc(sizeof(File));
	f->dot.f = f;
	f->ndot.f = f;
	f->seq = 0;
	f->mod = FALSE;
	f->unread = TRUE;
	Strinit0(&f->name);
	return f;
}
Пример #2
0
Файл: sam.c Проект: deadpixi/sam
int
main(int argc, char *argv[])
{
    int i, o;
    String *t;
    char *arg[argc + 1], **ap;
    int targc = 1;

    ap = &arg[argc];
    arg[0] = "samterm";
    setlocale(LC_ALL, "");

    while ((o = getopt(argc, argv, "efdRr:t:s:")) != -1) {
        switch (o) {
        case 'e':
            arg[targc++] = "-e";
            break;

        case 'f':
            arg[targc++] = "-f";
            break;

        case 'd':
            dflag = true;
            break;

        case 'r':
            machine = optarg;
            rsamname = "rsam";
            arg[targc++] = "-r";
            arg[targc++] = optarg;
            break;

        case 'R':
            Rflag = true;
            break;

        case 't':
            samterm = optarg;
            break;

        case 's':
            rsamname = optarg;
            break;

        default:
            usage();
        }
    }
    argv += optind;
    argc -= optind;
    arg[targc] = NULL;

    Strinit(&cmdstr);
    Strinit0(&lastpat);
    Strinit0(&lastregexp);
    Strinit0(&genstr);
    Strinit0(&rhs);
    Strinit0(&wd);
    Strinit0(&plan9cmd);

    tempfile.listptr = emalloc(0);
    home = getenv("HOME") ? getenv("HOME") : "/";
    shpath = getenv("SHELL") ? getenv("SHELL") : shpath;
    sh = basename(shpath);
    if(!dflag)
        startup(machine, Rflag, arg, ap);
    Fstart();

    signal(SIGINT, SIG_IGN);
    signal(SIGHUP, hup);
    signal(SIGPIPE, SIG_IGN);

    if(argc > 0) {
        for(i=0; i<argc; i++)
            if(!setjmp(mainloop)) {
                t = tmpcstr(argv[i]);
                Straddc(t, '\0');
                Strduplstr(&genstr, t);
                freetmpstr(t);
                Fsetname(newfile(), &genstr);
            }
    } else if(!downloaded)
        newfile()->state = Clean;
    modnum++;
    if(file.nused)
        current(file.filepptr[0]);

    atexit(shutdown);
    setjmp(mainloop);
    cmdloop();

    trytoquit();    /* if we already q'ed, quitok will be true */

    exit(EXIT_SUCCESS);
}
Пример #3
0
void main(int argc, char *argv[])
{
    int i;
    String *t;
    char *termargs[10], **ap;

    ap = termargs;
    *ap++ = "samterm";
    ARGBEGIN{
    case 'd':
        dflag++;
        break;
    case 'r':
        machine = EARGF(usage());
        break;
    case 'R':
        Rflag++;
        break;
    case 't':
        samterm = EARGF(usage());
        break;
    case 's':
        rsamname = EARGF(usage());
        break;
    default:
        dprint("sam: unknown flag %c\n", ARGC());
        usage();
        /* options for samterm */
    case 'a':
        *ap++ = "-a";
        break;
    } ARGEND
    *ap = nil;

    Strinit(&cmdstr);
    Strinit0(&lastpat);
    Strinit0(&lastregexp);
    Strinit0(&genstr);
    Strinit0(&rhs);
    Strinit0(&curwd);
    Strinit0(&plan9cmd);
    home = getenv(HOME);
    disk = diskinit();
    if(home == 0)
        home = "/";
    if(!dflag)
        startup(machine, Rflag, termargs, argv);
    notify(notifyf);
    getcurwd();
    if(argc>0) {
        for(i=0; i<argc; i++) {
            if(!setjmp(mainloop)) {
                t = tmpcstr(argv[i]);
                Straddc(t, '\0');
                Strduplstr(&genstr, t);
                freetmpstr(t);
                fixname(&genstr);
                logsetname(newfile(), &genstr);
            }
        }
    } else if(!downloaded)
        newfile();
    seq++;
    if(file.nused)
        current(file.filepptr[0]);
    setjmp(mainloop);
    cmdloop();
    trytoquit();	/* if we already q'ed, quitok will be TRUE */
    exits(0);
}
Пример #4
0
int
sammain(int argc, char *argv[])
{
    bool trylock = true;
    int i, o;
    String *t;
    char *arg[argc + 1], **ap;

    ap = &arg[argc];
    arg[0] = "samterm";
    setlocale(LC_ALL, "");

    while ((o = getopt(argc, argv, "SedR:r:t:s:")) != -1){
        switch (o){
            case 'd':
                dflag = true;
                break;

            case 'r':
                machine = optarg;
                break;

            case 'R':
                rmsocketname = optarg;
                atexit(rmsocket);
                break;

            case 't':
                samterm = optarg;
                break;

            case 's':
                rsamname = optarg;
                break;

            case 'S':
                trylock = false;
                break;

            default:
                usage();
        }
    }

    if (trylock && !canlocksocket(machine) && !dflag)
        return bmain(argc, argv);

    argv += optind;
    argc -= optind;

    Strinit(&cmdstr);
    Strinit0(&lastpat);
    Strinit0(&lastregexp);
    Strinit0(&genstr);
    Strinit0(&rhs);
    Strinit0(&wd);
    Strinit0(&plan9cmd);

    tempfile.listptr = emalloc(0);
    home = getenv("HOME") ? getenv("HOME") : "/";
    shpath = getenv("SHELL") ? getenv("SHELL") : shpath;
    sh = basename(shpath);
    if(!dflag)
        startup(machine, rmsocketname != NULL, trylock);
    Fstart();

    signal(SIGINT, SIG_IGN);
    signal(SIGHUP, hup);
    signal(SIGPIPE, SIG_IGN);

    if(argc > 0){
        for(i=0; i<argc; i++)
            if(!setjmp(mainloop)){
                t = tmpcstr(argv[i]);
                Straddc(t, '\0');
                Strduplstr(&genstr, t);
                freetmpstr(t);
                Fsetname(newfile(), &genstr);
            }
    }else if(!downloaded)
        newfile()->state = Clean;
    modnum++;
    if(file.nused)
        current(file.filepptr[0]);

    atexit(scram);
    setjmp(mainloop);
    cmdloop();

    trytoquit();    /* if we already q'ed, quitok will be true */

    exit(EXIT_SUCCESS);
}