/* mqual - Qualify a variable name. It returns a pointer on * an atom containing the qualified name. */ char * mqual(char *x) { *id='.'; if (!copyto(id+1, x, x+strlen(x)+1)) exit(1); // FIXME return astrdup(qid, id-qid+1); }
/* mset - Set the current module by translating the file path * into a module hierarchy. If the call succeeds, 0 is returned, * in any other case, 1 is returned. * After calling this function (if 0 is returned) all calls to * mqual will return names qualified by the new current module. */ int mset(char *path) { char *p; id=qid; while ((p=strchr(path, DIRSEP))) { id=copyto(id, path, p); if (!id) return 1; *id++='.'; path=p+1; } p=strchr(path, '.'); if (!p || strcmp(p, ".dk")!=0) fprintf(stderr, "%s: Warning, path %s should end in '.dk'.\n" , __func__, path); if (!p) p=path+strlen(path); id=copyto(id, path, p); return !id; }
int main(int argc, char** argv) { shapevector* shapes = populate(5); wkshapevector* wrefshapes = copyto(shapes) ; show<shapevector> (shapes); show<wkshapevector> (wrefshapes); //shapes = move<shapevector>(3,2,shapes); wrefshapes = move<wkshapevector>(3,2,wrefshapes); //std::shared_ptr<Shape> shape3 = (*shapes)[3]; show<shapevector> (shapes); empty (shapes); show<shapevector> (shapes); //std::cout << s1->whatami() << std::endl; //std::cout << (shape3)->whatami() << " usecount = " << shape3.use_count() << std::endl; }
char *macro(char *as) { /* Strip "" and do $ substitution * Leaves result on top of stack */ register BOOL savqu = quoted; register CHAR savq = quote; FILEHDR fb; push((void *)&fb);/*FIXME*/ estabf(as); usestak(); quote = 0; quoted = 0; copyto(0); pop(); if (quoted && (stakbot == staktop)) { pushstak(QUOTE); } quote = savq; quoted = savqu; return (fixstak()); }
void iterate(int size, char arr[20][20], char arr2[20][20], char lines[108][200]) { printf("size is %d \n", size); if (size % 2 == 0) { printf("2->3 transform \n"); int x; int y; for (x=0;x<size/2;x++){ for(y=0;y<size/2;y++){ printf("x, y = %d, %d\n", x,y); //grab a 2x2 square into "two" copyfrom(20, 2, arr, x*2, y*2, a2); //looking for match int l; for (l=0; l<108; l++) { if (lines[l][6]=='=') { parse2(lines[l],b2, b3); if (match(2, a2, b2)==1) { printf("match found \n"); copyto(3,20, b3, arr2,x*3,y*3); break; } } } } } size = (size/2)*3; } else if (size % 3 == 0) { printf("3->4 transform \n"); int x; int y; for (x=0;x<size/3;x++){ for(y=0;y<size/3;y++){ printf("x, y = %d, %d\n", x,y); //grab a 3x3 square into "three" copyfrom(20, 3, arr, x*3, y*3, a3); printf("three:\n"); printarr(3, a3); //looking for match int l; for (l=0; l<108; l++) { if (lines[l][6]!='=') { parse3(lines[l],b3, b4); if (match(3, a3, b3)==1) { /* printf("line > "); printf(lines[l]); printf("three2:\n"); printarr(3, b3); printf("four2:\n"); printarr(4, b4); printf("----\n\n"); */ printf("match!\n"); copyto(4,20, b4, arr2,x*4,y*4); break; } } } } } size = (size/3)*4; } return; }
const char * vmsify (const char *name, int type) { /* max 255 device max 39 directory max 39 filename max 39 filetype max 5 version */ #define MAXPATHLEN 512 enum namestate nstate; static char vmsname[MAXPATHLEN+1]; const char *fptr; const char *t; char *vptr; int as_dir; int count; if (name == 0) return 0; fptr = name; vptr = vmsname; nstate = N_START; /* case 25a */ t = strpbrk (name, "$:"); if (t != 0) { const char *s1; const char *s2; if (type == 1) { s1 = strchr (t+1, '['); s2 = strchr (t+1, ']'); } if (*t == '$') { if (strchr (name, '/') == 0) { strcpy (vmsname, name); if ((type == 1) && (s1 != 0) && (s2 == 0)) strcat (vmsname, "]"); return vmsname; } } else { strcpy (vmsname, name); if ((type == 1) && (s1 != 0) && (s2 == 0)) strcat (vmsname, "]"); return vmsname; } } /* case 26 */ t = strchr (name, '['); if (t != 0) { const char *s; const char *s1 = strchr (t+1, '['); if (s1 == 0) { strcpy (vmsname, name); if ((type == 1) && (strchr (t+1, ']') == 0)) strcat (vmsname, "]"); return vmsname; } s1--; if (*s1 != ']') { strcpy (vmsname, name); return vmsname; /* not ][, keep unchanged */ } /* we have ][ */ s = name; /* s -> starting char s1 -> ending ']' */ do { strncpy (vptr, s, s1-s); /* copy up to but not including ']' */ vptr += s1-s; if (*s1 == 0) break; s = s1 + 1; /* s -> char behind ']' */ if (*s != '[') /* was '][' ? */ break; /* no, last ] found, exit */ s++; if (*s != '.') *vptr++ = '.'; s1 = strchr (s, ']'); if (s1 == 0) /* no closing ] */ s1 = s + strlen (s); } while (1); *vptr++ = ']'; fptr = s; } else /* no [ in name */ { int state = 0; int rooted = 1; /* flag if logical is rooted, else insert [000000] */ do { switch (state) { case 0: /* start of loop */ if (*fptr == '/') { fptr++; state = 1; } else if (*fptr == '.') { fptr++; state = 10; } else state = 2; break; case 1: /* '/' at start */ if (*fptr == '/') { fptr++; state = 3; } else state = 4; break; case 2: /* no '/' at start */ { const char *s = strchr (fptr, '/'); if (s == 0) /* no '/' (16) */ { if (type == 1) { strcpy (vptr, "[."); vptr += 2; } copyto (&vptr, &fptr, 0, (type==1)); if (type == 1) *vptr++ = ']'; state = -1; } else /* found '/' (17..21) */ { if ((type == 2) && (*(s+1) == 0)) /* 17(2) */ { copyto (&vptr, &fptr, '/', 1); state = 7; } else { strcpy (vptr, "[."); vptr += 2; copyto (&vptr, &fptr, '/', 1); nstate = N_OPEN; state = 9; } } break; } case 3: /* '//' at start */ { const char *s; const char *s1; char *vp; while (*fptr == '/') /* collapse all '/' */ fptr++; if (*fptr == 0) /* just // */ { char cwdbuf[MAXPATHLEN+1]; s1 = getcwd(cwdbuf, MAXPATHLEN); if (s1 == 0) { vmsname[0] = '\0'; return vmsname; /* FIXME, err getcwd */ } s = strchr (s1, ':'); if (s == 0) { vmsname[0] = '\0'; return vmsname; /* FIXME, err no device */ } strncpy (vptr, s1, s-s1+1); vptr += s-s1+1; state = -1; break; } s = vptr; if (copyto (&vptr, &fptr, '/', 1) == 0) /* copy device part */ { *vptr++ = ':'; state = -1; break; } *vptr = ':'; nstate = N_DEVICE; if (*fptr == 0) /* just '//a/' */ { strcpy (vptr+1, "[000000]"); vptr += 9; state = -1; break; } *vptr = 0; /* check logical for [000000] insertion */ vp = trnlog (s); if (*vp != '\0') { /* found translation */ for (;;) /* loop over all nested logicals */ { char *vp2 = vp + strlen (vp) - 1; if (*vp2 == ':') /* translation ends in ':' */ { vp2 = trnlog (vp); free (vp); if (*vp2 == 0) { rooted = 0; break; } vp = vp2; continue; /* next iteration */ } if (*vp2 == ']') /* translation ends in ']' */ { if (*(vp2-1) == '.') /* ends in '.]' */ { if (strncmp (fptr, "000000", 6) != 0) rooted = 0; } else { strcpy (vmsname, s1); vp = strchr (vmsname, ']'); *vp = '.'; nstate = N_DOT; vptr = vp; } } break; } free (vp); } else rooted = 0; if (*vptr == 0) { nstate = N_DEVICE; *vptr++ = ':'; } else vptr++; if (rooted == 0) { nstate = N_DOT; strcpy (vptr, "[000000."); vptr += 8; vp = vptr-1; } else vp = 0; /* vp-> '.' after 000000 or NULL */ s = strchr (fptr, '/'); if (s == 0) { /* no next '/' */ if (*(vptr-1) == '.') *(vptr-1) = ']'; else if (rooted == 0) *vptr++ = ']'; copyto (&vptr, &fptr, 0, (type == 1)); state = -1; break; } else { while (*(s+1) == '/') /* skip multiple '/' */ s++; } if ((rooted != 0) && (*(vptr-1) != '.')) { *vptr++ = '['; nstate = N_DOT; } else if ((nstate == N_DOT) && (vp != 0) && (*(s+1) == 0)) { if (type == 2) { *vp = ']'; nstate = N_CLOSED; } } state = 9; break; } case 4: /* single '/' at start (9..15) */ if (*fptr == 0) state = 5; else state = 6; break; case 5: /* just '/' at start (9) */ if (type != 2) { *vptr++ = '['; nstate = N_OPEN; } strcpy (vptr, "000000"); vptr += 6; if (type == 2) state = 7; else state = 8; break; case 6: /* chars following '/' at start 10..15 */ { const char *s; *vptr++ = '['; nstate = N_OPEN; s = strchr (fptr, '/'); if (s == 0) /* 10 */ { if (type != 1) { strcpy (vptr, "000000]"); vptr += 7; } copyto (&vptr, &fptr, 0, (type == 1)); if (type == 1) { *vptr++ = ']'; } state = -1; } else /* 11..15 */ { if ( (type == 2) && (*(s+1) == 0)) /* 11(2) */ { strcpy (vptr, "000000]"); nstate = N_CLOSED; vptr += 7; } copyto (&vptr, &fptr, '/', (*(vptr-1) != ']')); state = 9; } break; } case 7: /* add '.dir' and exit */ if ((nstate == N_OPEN) || (nstate == N_DOT)) { char *vp = vptr-1; while (vp > vmsname) { if (*vp == ']') { break; } if (*vp == '.') { *vp = ']'; break; } vp--; } } strcpy (vptr, ".dir"); vptr += 4; state = -1; break; case 8: /* add ']' and exit */ *vptr++ = ']'; state = -1; break; case 9: /* 17..21, fptr -> 1st '/' + 1 */ { const char *s; if (*fptr == 0) { if (type == 2) { state = 7; } else state = 8; break; } s = strchr (fptr, '/'); if (s == 0) { if (type != 1) { if (nstate == N_OPEN) { *vptr++ = ']'; nstate = N_CLOSED; } as_dir = 0; } else { if (nstate == N_OPEN) { *vptr++ = '.'; nstate = N_DOT; } as_dir = 1; } } else { while (*(s+1) == '/') s++; if ( (type == 2) && (*(s+1) == 0)) /* 19(2), 21(2)*/ { if (nstate != N_CLOSED) { *vptr++ = ']'; nstate = N_CLOSED; } as_dir = 1; } else { if (nstate == N_OPEN) { *vptr++ = '.'; nstate = N_DOT; } as_dir = 1; } } if ( (*fptr == '.') /* check for '..' or '../' */ && (*(fptr+1) == '.') && ((*(fptr+2) == '/') || (*(fptr+2) == 0)) ) { char *vp; fptr += 2; if (*fptr == '/') { do { fptr++; } while (*fptr == '/'); } else if (*fptr == 0) type = 1; vptr--; /* vptr -> '.' or ']' */ vp = vptr; for (;;) { vp--; if (*vp == '.') /* one back */ { vptr = vp; nstate = N_OPEN; break; } if (*vp == '[') /* top level reached */ { if (*fptr == 0) { strcpy (vp, "[000000]"); vptr = vp + 8; nstate = N_CLOSED; s = 0; break; } else { vptr = vp+1; nstate = N_OPEN; break; } } } } else { copyto (&vptr, &fptr, '/', as_dir); if (nstate == N_DOT) nstate = N_OPEN; } if (s == 0) { /* 18,20 */ if (type == 1) *vptr++ = ']'; state = -1; } else { if (*(s+1) == 0) { if (type == 2) /* 19,21 */ { state = 7; } else { *vptr++ = ']'; state = -1; } } } break; } case 10: /* 1,2 first is '.' */ if (*fptr == '.') { fptr++; state = 11; } else state = 12; break; case 11: /* 2, '..' at start */ count = 1; if (*fptr != 0) { if (*fptr != '/') /* got ..xxx */ { strcpy (vmsname, name); return vmsname; } do /* got ../ */ { fptr++; while (*fptr == '/') fptr++; if (*fptr != '.') break; if (*(fptr+1) != '.') break; fptr += 2; if ((*fptr == 0) || (*fptr == '/')) count++; } while (*fptr == '/'); } { /* got '..' or '../' */ char *vp; char cwdbuf[MAXPATHLEN+1]; vp = getcwd(cwdbuf, MAXPATHLEN); if (vp == 0) { vmsname[0] = '\0'; return vmsname; /* FIXME, err getcwd */ } strcpy (vptr, vp); vp = strchr (vptr, ']'); if (vp != 0) { nstate = N_OPEN; while (vp > vptr) { vp--; if (*vp == '[') { vp++; strcpy (vp, "000000]"); state = -1; break; } else if (*vp == '.') { if (--count == 0) { if (*fptr == 0) /* had '..' or '../' */ { *vp++ = ']'; state = -1; } else /* had '../xxx' */ { state = 9; } *vp = '\0'; break; } } } } vptr += strlen (vptr); } break; case 12: /* 1, '.' at start */ if (*fptr != 0) { if (*fptr != '/') { strcpy (vmsname, name); return vmsname; } while (*fptr == '/') fptr++; } { char *vp; char cwdbuf[MAXPATHLEN+1]; vp = getcwd(cwdbuf, MAXPATHLEN); if (vp == 0) { vmsname[0] = '\0'; return vmsname; /*FIXME, err getcwd */ } strcpy (vptr, vp); } if (*fptr == 0) { state = -1; break; } else { char *vp = strchr (vptr, ']'); if (vp == 0) { state = -1; break; } *vp = '\0'; nstate = N_OPEN; vptr += strlen (vptr); state = 9; } break; } } while (state > 0); } /* directory conversion done fptr -> filename part of input string vptr -> free space in vmsname */ *vptr++ = 0; return vmsname; }
/*===========================================================================* * block_transfer * *===========================================================================*/ static int block_transfer(dev_t minor, /* minor device number */ int do_write, /* read or write? */ u64_t position, /* offset on device to read or write */ endpoint_t endpt, /* process doing the request */ iovec_t * iov, /* pointer to read or write request vector */ unsigned int nr_req, /* length of request vector */ int flags /* transfer flags */ ) { unsigned long counter; iovec_t *ciov; /* Current IO Vector */ struct device *dev; /* The device used */ struct sd_slot *slot; /* The sd slot the requests is pointed to */ vir_bytes io_size; /* Size to read/write to/from the iov */ vir_bytes io_offset; /* Size to read/write to/from the iov */ vir_bytes bytes_written; int r, blk_size, i; /* Get the current "device" geometry */ dev = block_part(minor); if (dev == NULL) { mmc_log_warn(&log, "Transfer requested on unknown device minor(%d)\n", minor); /* Unknown device */ return ENXIO; } mmc_log_trace(&log, "I/O on minor(%d) %s at 0x%016llx\n", minor, (do_write) ? "Write" : "Read", position); slot = get_slot(minor); assert(slot); if (slot->card.blk_size == 0) { mmc_log_warn(&log, "Request on a card with block size of 0\n"); return EINVAL; } if (slot->card.blk_size > COPYBUFF_SIZE) { mmc_log_warn(&log, "Card block size (%d) exceeds internal buffer size %d\n", slot->card.blk_size, COPYBUFF_SIZE); return EINVAL; } /* It is fully up to the driver to decide on restrictions for the * parameters of transfers, in those cases we return EINVAL */ if (position % slot->card.blk_size != 0) { /* Starting at a block boundary */ mmc_log_warn(&log, "Requests must start at a block boundary" "(start,block size)=(%016llx,%08x)\n", position, slot->card.blk_size); return EINVAL; } blk_size = slot->card.blk_size; bytes_written = 0; /* Are we trying to start reading past the end */ if (position >= dev->dv_size) { mmc_log_warn(&log, "start reading past drive size\n"); return 0; }; ciov = iov; /* do some more validation */ for (counter = 0; counter < nr_req; counter++) { assert(ciov != NULL); if (ciov->iov_size % blk_size != 0) { /* transfer a multiple of blk_size */ mmc_log_warn(&log, "Requests must start at a block boundary " "(start,block size)=(%016llx,%08x)\n", position, slot->card.blk_size); return EINVAL; } if (ciov->iov_size <= 0) { mmc_log_warn(&log, "Invalid iov size for iov %d of %d size\n", counter, nr_req, ciov->iov_size); return EINVAL; } ciov++; } ciov = iov; for (counter = 0; counter < nr_req; counter++) { /* Assume we are to transfer the amount of data given in the * input/output vector but ensure we are not doing i/o past * our own boundaries */ io_size = ciov->iov_size; io_offset = position + bytes_written; /* Check we are not reading/writing past the end */ if (position + bytes_written + io_size > dev->dv_size) { io_size = dev->dv_size - (position + bytes_written); }; mmc_log_trace(&log, "I/O %s request(%d/%d) iov(grant,size,iosize," "offset)=(%d,%d,%d,%d)\n", (do_write) ? "write" : "read", counter + 1, nr_req, ciov->iov_addr, ciov->iov_size, io_size, io_offset); /* transfer max one block at the time */ for (i = 0; i < io_size / blk_size; i++) { if (do_write) { /* Read io_size bytes from i/o vector starting * at 0 and write it to out buffer at the * correct offset */ r = copyfrom(endpt, ciov->iov_addr, i * blk_size, (vir_bytes) copybuff, blk_size); if (r != OK) { mmc_log_warn(&log, "I/O write error: %s iov(base,size)=(%d,%d)" " at offset=%d\n", strerror(_SIGN r), ciov->iov_addr, ciov->iov_size, io_offset); return EINVAL; } /* write a single block */ slot->host->write(&slot->card, (dev->dv_base / blk_size) + (io_offset / blk_size) + i, 1, copybuff); bytes_written += blk_size; } else { /* read a single block info copybuff */ slot->host->read(&slot->card, (dev->dv_base / blk_size) + (io_offset / blk_size) + i, 1, copybuff); /* Read io_size bytes from our data at the * correct offset and write it to the output * buffer at 0 */ r = copyto(endpt, ciov->iov_addr, i * blk_size, (vir_bytes) copybuff, blk_size); if (r != OK) { mmc_log_warn(&log, "I/O read error: %s iov(base,size)=(%d,%d)" " at offset=%d\n", strerror(_SIGN r), ciov->iov_addr, ciov->iov_size, io_offset); return EINVAL; } bytes_written += blk_size; } } ciov++; } return bytes_written; }
static int getch(char endch) { register char d; retry: d = readc(); if (!subchar(d)) return (d); if (d == DOLLAR) { register int c; if ((c = readc(), dolchar(c))) { NAMPTR n = (NAMPTR) NIL; int dolg = 0; BOOL bra; register const char *argp; register const char *v; CHAR idb[2]; char *id = idb; if (bra = (c == BRACE)) c = readc(); if (letter(c)) { argp = (STRING) relstak(); while (alphanum(c)) { pushstak(c); c = readc(); } zerostak(); n = lookup(absstak(argp)); setstak(argp); v = n->namval; id = (char *)n->namid; peekc = c | MARK;; } else if (digchar(c)) { *id = c; idb[1] = 0; if (astchar(c)) { dolg = 1; c = '1'; } c -= '0'; v = ((c == 0) ? (const char *)cmdadr : (c <= dolc) ? dolv[c] : (dolg = 0, NULL)); } else if (c == '$') { v = pidadr; } else if (c == '!') { v = pcsadr; } else if (c == '#') { v = dolladr; } else if (c == '?') { v = exitadr; } else if (c == '-') { v = flagadr; } else if (bra) { error(badsub); } else { goto retry; } c = readc(); if (!defchar(c) && bra) error(badsub); argp = 0; if (bra) { if (c != '}') { argp = (STRING) relstak(); if ((v == 0) ^ (setchar(c))) copyto('}'); else skipto('}'); argp = absstak(argp); } } else { peekc = c | MARK; c = 0; } if (v) { if (c != '+') { for (;;) { while (c = *v++) pushstak(c | quote); if (dolg == 0 || (++dolg > dolc)) break; else { v = dolv[dolg]; pushstak(SP | (*id == '*' ? quote : 0)); } } } } else if (argp) { if (c == '?') { failed(id, *argp ? argp : badparam); } else if (c == '=') { if (n) assign(n, argp); else error(badsub); } } else if (flags & setflg) { failed(id, badparam); } goto retry; } else { peekc = c | MARK; } } else if (d == endch) { return (d); } else if (d == SQUOTE) { comsubst(); goto retry; } else if (d == DQUOTE) { quoted++; quote ^= QUOTE; goto retry; } return d; }
int main(int argc, char **argv) { int i, count = 0, self = FALSE; FILE *f, *fo; if (argc >= 2) { if ((argv[1][0] == '-') || (argv[1][0] == '/')) { if (strchr(argv[1], '?') != NULL) { about(); return 0; } if (strchr(argv[1], 's') != NULL) { silent = TRUE; } if (strchr(argv[1], 'i') != NULL) { ignorecase = TRUE; } if (strchr(argv[1], 'm') != NULL) { self = TRUE; } argv[1] = argv[0]; argv++; argc--; } } if (argc < 4) { fprintf(stderr, "frepl [-?sim] <src> <dest> <infile> [<outfile>]\n"); return 1; } else { if ((self == TRUE) || (argc >= 5)) { if ((fo = openx(0)) == NULL) { perror("error in opening temp file FREPLTMP.$$$"); return 10; } } else { fo = stdout; } } makestr(argv[1], s); makestr(argv[2], d); if (silent == FALSE) { fprintf(stderr, "Source string = \"%s\"\nDest string = \"%s\"\n", s, d); } if ((f = fopenx(argv[3], "rb")) == NULL) { if (silent == FALSE) { perror("error in opening source file"); } return 2; } for (;;) { if ((i = fgetc(f)) == EOF) { break; } if (charequal((char)i, s[0]) == TRUE) { /* 1st matched */ if (rmatch(f, s + 1) == TRUE) { if (silent == FALSE) { fprintf(stderr, "\rCount = %04d ", ++count); } fputs(d, fo); } else { fputc(i, fo); } } else { fputc(i, fo); } } fclose(f); fclose(fo); if (silent == FALSE) { fprintf(stderr, "\n"); } if ((self == TRUE) || (argc >= 5)) { if ((f = openx(1)) == NULL) { if (silent == FALSE) { perror("error in preparing to read temp file FREPLTMP.$$$"); } return 21; } if (silent == FALSE) { fprintf(stderr, "rewrite file...\n"); } if (self == TRUE) { copyto(f, argv[3], TRUE, "error in preparing to write infile"); } if (argc >= 5) { copyto(f, argv[4], FALSE, "error in preparing to write outfile"); } fclose(f); if (silent == FALSE) { fprintf(stderr, "deleting temp file...\n"); } remove("FREPLTMP.$$$"); } return 0; }