void dfs_resolve_path(const char *fname, char *path) { char *ptr; char *ptr1; if (!strcmp(fname, ".")) fname++; else if (!strncmp(fname, "./",2) || !strncmp(fname, ".\\",2)) fname += 2; if (fname[0] == '/' || fname[0] == '\\') strcpy(path, fname); else if (fname[0] == 0) strcpy(path, dfs_currdir); else { strcpy(path, dfs_currdir); int pathLen = strlen(path); if (path[pathLen-1] != '/' && path[pathLen-1] != '\\') strcat(path, "/"); strcat(path, fname); } // Whack DOS paths to UNIX paths for (ptr = path; *ptr; ptr++) if (*ptr == '\\') *ptr = '/'; // Process .. ptr = path; while (*ptr) { if (!strncmp(ptr, "/..", 3) && (ptr[3] == 0 || ptr[3] == '/')) { if (ptr == path) { movestr(ptr, ptr+3); } else { ptr1 = ptr - 1; while (ptr1 != path) { if (*ptr1 == '/') break; ptr1--; } movestr(ptr1, ptr+3); ptr = ptr1; } } else { ptr++; while (*ptr) { if (*ptr == '/') break; ptr++; } } } if (path[0] == 0) strcpy(path, "/"); }
void rmspace(char *str,int n) { int i; for(i=0;i<n;i++) if(str[i]==' ')movestr(str,i,n); }
void imcsplay(int argc, char **argv) { setlinebuf(stdout); if (argc < 5 || argc > 7) usage(); char mecolor = '?'; int megame = 0; switch(argv[2][0]) { case 'O': switch(argv[2][1]) { case 'W': case 'B': case '?': mecolor = argv[2][1]; break; default: usage(); } break; case 'A': { char ch = argv[2][1]; if (isdigit(ch)) { megame = atoi(&argv[2][1]); } else if (ch == 'W' || ch == 'B') { mecolor = ch; megame = atoi(&argv[2][2]); } else { usage(); } if (megame <= 0) usage(); break; } default: usage(); } char *meuser = argv[3]; char *mepassword = argv[4]; char *host = "imcs.svcs.cs.pdx.edu"; if (argc > 5) host = argv[5]; int port = 3589; if (argc > 6) { port = atoi(argv[6]); if (port <= 0) usage(); } FILE *nf = netopen(host, port); setlinebuf(nf); startlog(); char *greeting = expectcmd(nf, 1, 100, 0); (void) strtok(greeting, " "); char *pgm = strtok(0, " "); assert(!strcmp(pgm, "imcs")); char *version = strtok(0, " \r\n"); if(strcmp(version, "2.5")) { fprintf(stderr, "got unexpected imcs version %s\n", version); exit(1); } sendcmd(nf, "me %s %s", meuser, mepassword); (void) expectcmd(nf, 1, 201, 0); if (megame != 0) { if (mecolor == '?') sendcmd(nf, "accept %d", megame); else sendcmd(nf, "accept %d %c", megame, mecolor); (void) expectcmd(nf, 1, 105, 106, 0); } else { if (mecolor == '?') sendcmd(nf, "offer"); else sendcmd(nf, "offer %c", mecolor); (void) expectcmd(nf, 1, 103, 0); logmsg("waiting for opponent"); (void) expectcmd(nf, 1, 105, 106, 0); logmsg("opponent found"); } struct state s = s0; s.cureval = eval(&s); if (nttable > 0) s.curzhash = zhash(&s); while (1) { int ch = fgetc(nf); int r = ungetc(ch, nf); assert(r != EOF); if (isdigit(ch)) { s = readstate(nf, 1); s.cureval = eval(&s); if (nttable > 0) s.curzhash = zhash(&s); continue; } switch (ch) { case '?': { char *r = getnet(nf, "?"); char *q = strtok(r, " "); assert(!strcmp(q, "?")); char *tl = strtok(0, " "); char *tr = strtok(0, " "); assert(tl && tr); int t = readtimems(tl); t = 95 * t / (100 * ((81 - s.ply) / 2)); struct move m = idnegamax(&s, t, 0); logmsg("value %d at time %d depth %d for %s\n\n", v0, t, d0, movestr(&m)); move(&s, &m, 0); sendcmd(nf, "%s", movestr(&m)); printstate(&s, 1); if (ponder) (void) idnegamax(&s, 0, nf); continue; } case '!': assert(fgetc(nf) == '!'); int ch; do ch = fgetc(nf); while (isspace(ch)); ungetc(ch, nf); struct move m = getmove(nf, &s); move(&s, &m, 0); continue; case '=': (void) getnet(nf, "="); break; case 'X': (void) getnet(nf, "X"); break; default: (void) getnet(nf, "..."); continue; } break; } fclose(nf); }
toktype yylex() { register ptrall bufptr; register toktype val; register struct exp *locxp; bufptr = tokptr; /*copy in the global value*/ top: if (bufptr < tokub){ gtoken(val, bufptr); switch(yylval = val){ case PARSEEOF : yylval = val = PARSEEOF; break; case INT: locxp = xp++; glong(locxp->xvalue, bufptr); makevalue: locxp->xtype = XABS; locxp->xloc = 0; locxp->xname = NULL; yylval = (int)locxp; break; case FLTNUM: /*case patched on 3-Jan-80*/ locxp = xp++; gdouble(locxp->doubval.dvalue, bufptr); /* * We make sure that locxp->xvalue * is not in the range suitable for * a short literal. The field * xvalue is only used for * integers, not doubles, but when * we test for short literals * in ascode.c, we look * at the field xvalue when * it encounters an in line * floating number. Ergo, * give it a bad value. */ locxp->xvalue = -1; goto makevalue; case NAME: gptr(yylval, bufptr); lastnam = (struct symtab *)yylval; break; case SIZESPEC: case REG: case INSTn: case INST0: gchar(yylval, bufptr); break; case IJXXX: gchar(yylval, bufptr); gptr(lastjxxx, bufptr); break; case ILINESKIP: gint(yylval, bufptr); lineno += yylval; goto top; case SKIP: eatskiplg(bufptr); goto top; case VOID: goto top; case STRING: strptr = &strbuf[strno ^= 1]; strptr->str_lg = *((lgtype *)bufptr); movestr(&strptr->str[0], (char *)bufptr + sizeof(lgtype), strptr->str_lg); eatstrlg(bufptr); yylval = (int)strptr; break; case ISTAB: case ISTABSTR: case ISTABNONE: case ISTABDOT: case IALIGN: gptr(yylval, bufptr); break; } /*end of the switch*/ #ifdef DEBUG if (toktrace) switch(val){ case INT: printf("Class integer val %d\n", ((struct exp *)yylval)->xvalue); break; case FLTNUM: printf("Class floating point num value %4.3f\n", ((struct exp *)yylval) -> doubval.dvalue); break; case NAME: printf("Class name, \"%.8s\"\n", ((struct symtab *)yylval)->name); break; case REG: printf("Class register, number %d\n", yylval); break; case INSTn: printf("Class INSTn, %.8s\n", itab[0xFF &yylval]->name); break; case IJXXX: printf("Class IJXXX, %.8s\n", itab[0xFF &yylval]->name); break; case INST0: printf("Class INST0, %.8s\n", itab[0xFF &yylval]->name); break; case STRING: printf("Class string, length %d\n", ((struct strdesc *)yylval)->str_lg); break; default: printf("Pass: %d Tok: %d Other class: %d, 0%o, '%c'\n", passno, bufptr - firsttoken, val,val, val); break; } /*end of the debug switch*/ #endif } /*end of this buffer*/ else { if (useVM){ bufno += 1; emptybuf = emptybuf->tok_next; if (emptybuf == 0){ struct tokbufdesc *newdallop; int i; if (passno == 2) goto badread; emptybuf = newdallop = (struct tokbufdesc *)sbrk( TOKDALLOP*sizeof (struct tokbufdesc)); if (emptybuf == (struct tokbufdesc *)-1) goto badwrite; for (i=0; i < TOKDALLOP; i++){ buftail->tok_next = newdallop; buftail = newdallop; newdallop += 1; } buftail->tok_next = 0; } /*end of need to get more buffers*/ (toktype *)bufptr = &(emptybuf->toks[0]); if (passno == 1) scan_dot_s(emptybuf); } else { /*don't use VM*/ bufno ^= 1; emptybuf = &tokbuf[bufno]; ((toktype *)bufptr) = &(emptybuf->toks[0]); if (passno == 1){ /* * First check if there are things to write * out at all */ if (emptybuf->tok_count >= 0){ if (fwrite(emptybuf, sizeof *emptybuf, 1, tmpfil) != 1){ badwrite: yyerror("Unexpected end of file writing the interpass tmp file"); exit(2); } } scan_dot_s(emptybuf); } else { /*pass 2*/ if (fread(emptybuf, sizeof *emptybuf, 1, tmpfil) != 1){ badread: yyerror("Unexpected end of file while reading the interpass tmp file"); exit(1); } } /*end of pass2*/ } /*end of using a real live file*/ (char *)tokub = (char *)bufptr + emptybuf->tok_count; #ifdef DEBUG firsttoken = bufptr; if (debug) printf("created buffernumber %d with %d tokens\n", bufno, emptybuf->tok_count); #endif goto top; } /*end of reading/creating a new buffer*/ tokptr = bufptr; /*copy back the global value*/ return(val); } /*end of yylex*/