Annotation of 42BSD/ingres/source/support/copydb.q, revision 1.1.1.1

1.1       root        1: # include      <stdio.h>
                      2: # include      <sccs.h>
                      3: 
                      4: SCCSID(@(#)copydb.q    7.2     3/11/82)
                      5: 
                      6: 
                      7: # define       MAXNAME 13      /* one more for the null */
                      8: # define       MAXKEYS 6       /* changing this is insuficient */
                      9: # define       MAXINDEX        10      /* change as needed */
                     10: # define       MAXREL  1000    /* can be increased as needed */
                     11: # define       MAXDOM  50
                     12: # define       INT     30
                     13: # define       FLOAT   31
                     14: # define       CHAR    32
                     15: ##char Usercode[100];
                     16: char   **Wanted;
                     17: int    Status;
                     18: 
                     19: FILE   *Ifile, *Ofile;
                     20: 
                     21: struct relation
                     22: {
                     23:        char    name[MAXNAME];
                     24:        char    indx;
                     25:        int     spec;
                     26:        int     atts;
                     27: };
                     28: 
                     29: struct attribute
                     30: {
                     31:        char    aname[MAXNAME];
                     32:        char    format;
                     33:        int     length;
                     34: };
                     35: 
                     36: struct index
                     37: {
                     38:        char    iname[MAXNAME];
                     39:        char    ispec;
                     40:        char    idom[MAXKEYS];
                     41: };
                     42: 
                     43: 
                     44: main(argc,argv)
                     45: int    argc;
                     46: char   **argv;
                     47: {
                     48: 
                     49: ##     char    *db;
                     50:        char    *path;
                     51: ##     char    name[MAXNAME];
                     52: ##     int     indx;
                     53: ##     int     atts;
                     54: ##     int     spec;
                     55: ##     char    iname[MAXNAME];
                     56: ##     int     idomv1, idomv2, idomv3, idomv4, idomv5, idomv6;
                     57: 
                     58: ##     int     n;
                     59: 
                     60:        register struct relation        *relptr;
                     61:        register struct attribute       *attptr;
                     62:        register int                    i;
                     63:        struct relation                 relations[MAXREL];
                     64:        struct attribute                attributes[MAXDOM], indatts[MAXKEYS];
                     65:        struct index                    indexes[MAXINDEX];
                     66:        struct index                    *indxptr;
                     67:        int                             attxtra[MAXDOM], indattx[MAXKEYS];
                     68:        int                             xcount;
                     69:        int                             j;
                     70:        char                            line[100];
                     71: ##     char                            *uover;
                     72: 
                     73:        umask(022);
                     74:        if (argc < 3)
                     75:                syserr(0,"usage: copydb database targetdir [relation] ...");
                     76: 
                     77:        uover = 0;
                     78:        if (bequal(*++argv, "-u", 2))
                     79:                uover = *argv++;
                     80:        db = *argv++;
                     81:        path = *argv++;
                     82:        Wanted = argv++;
                     83: 
                     84:        if(path[0] != '/')
                     85:                printf("Warning %s is not a full path name\n",path);
                     86: 
                     87: 
                     88:        if ((Ifile = fopen(ztack(path,"/copy.in"), "w")) == NULL)
                     89:                syserr(0,"Cannot create %s!",ztack(path,"/copy.in"));
                     90:        if ((Ofile = fopen(ztack(path,"/copy.out"), "w")) == NULL)
                     91:                syserr(0,"Cannot create %s!",ztack(path,"/copy.out"));
                     92: 
                     93: 
                     94: ##     ingres  db uover
                     95: 
                     96: ##     retrieve (Usercode = usercode)
                     97: 
                     98: ##     range of r is relation
                     99:        i = 0;
                    100: 
                    101:        /*
                    102:        **      Bring the relations into core
                    103:        */
                    104:        relptr = relations;
                    105: ##     retrieve (name = r.relid, spec = r.relspec, indx = r.relindxd,
                    106: ##             atts = r.relatts)
                    107: ##             where r.relowner = Usercode
                    108: ##             and mod(r.relstat,2) != 1 /* sys catalog */
                    109: ##             and r.relindxd >= 0
                    110: ##             and r.relid != "_SYS*" /* system temporaries */
                    111: ##     {
                    112:                if (notwanted(name))
                    113:                        continue;
                    114:                if(i++>=MAXREL)
                    115:                        syserr("Too many relations!!!");
                    116:                smove(name,(relptr->name));
                    117:                relptr->spec = spec;
                    118:                relptr->indx = indx;
                    119:                relptr++->atts = atts;
                    120: ##     }
                    121: 
                    122: 
                    123:        /*
                    124:        **      For each relation bring its attributes into core
                    125:        **      in domain order
                    126:        */
                    127: ##     range of a is attribute
                    128: ##     range of i is indexes
                    129:        n = i;
                    130:        printf("%d relations found\n",n);
                    131:        for (relptr = relations; relptr < &relations[n]; relptr++)
                    132:        {
                    133:                writein("create ");
                    134:                writeout("copy ");
                    135:                smove(relptr->name,name);
                    136:                writeboth(name);
                    137:                writeboth("(\n\t");
                    138: 
                    139:                xcount = retatts(name,attributes,attxtra);
                    140:                for(i = 0; i < relptr->atts; i++)
                    141:                {
                    142:                        attptr = &attributes[i];
                    143:                        if(i)
                    144:                                writeboth(",\n\t");
                    145:                        writeboth(attptr->aname);
                    146:                        putboth('=');
                    147:                        switch(attptr->format)
                    148:                        {
                    149: 
                    150:                          case 'i':
                    151:                                putboth('i');
                    152:                                break;
                    153: 
                    154:                          case 'f':
                    155:                                putboth('f');
                    156:                                break;
                    157: 
                    158:                          case 'c':
                    159:                                putboth('c');
                    160:                                break;
                    161: 
                    162:                          default:
                    163:                                syserr("Bad type: %d, in %c of %s!!",
                    164:                                        attptr->format,attptr->aname,
                    165:                                        name);
                    166: 
                    167:                        }
                    168:                                attptr->length &= 0377;
                    169:                                writeboth(iocv(attptr->length));
                    170:                }
                    171: 
                    172:                writeboth("\n)");
                    173:                writeout(" into \"");
                    174:                writein("\n\\p\\g\ncopy ");
                    175:                writein(name);
                    176:                writein("() from \"");
                    177:                writeboth(path);
                    178:                putboth('/');
                    179:                writeboth(name);
                    180:                writeboth(Usercode);
                    181:                writeboth("\"\n\\p\\g\n");
                    182: 
                    183: 
                    184:                if (relptr->spec != 5 && relptr->spec != 0)
                    185:                        modify(name,attributes,attxtra,relptr->spec,xcount);
                    186:                if (relptr->indx)
                    187:                {
                    188:                        indxptr = indexes;
                    189:                        i = 0;
                    190: 
                    191: ##                     retrieve (iname = i.irelidi, spec = i.irelspeci,
                    192: ##                             idomv1 = i.idom1, idomv2 = i.idom2, idomv3 = i.idom3,
                    193: ##                             idomv4 = i.idom4, idomv5 = i.idom5, idomv6 = i.idom6)
                    194: ##                     where i.irelidp = name and i.iownerp = Usercode
                    195: ##                     {
                    196: 
                    197:                                if (i++ >= MAXINDEX)
                    198:                                        syserr("Too many indexes on %s!!",name);
                    199:                                smove(iname,indxptr->iname);
                    200:                                indxptr->ispec = spec;
                    201:                                indxptr->idom[0] = idomv1;
                    202:                                indxptr->idom[1] = idomv2;
                    203:                                indxptr->idom[2] = idomv3;
                    204:                                indxptr->idom[3] = idomv4;
                    205:                                indxptr->idom[4] = idomv5;
                    206:                                indxptr->idom[5] = idomv6;
                    207:                                indxptr++;
                    208: ##                     }
                    209: 
                    210:                        while (--indxptr >= indexes)
                    211:                        {
                    212:        
                    213:                                writein("index on ");
                    214:                                writein(name);
                    215:                                writein(" is ");
                    216:                                writein(indxptr->iname);
                    217:                                writein("(\n\t");
                    218:        
                    219:                                for (i=0; indxptr->idom[i] && i < MAXKEYS; i++)
                    220:                                {
                    221:                                        if(i)
                    222:                                                writein(",\n\t");
                    223:                                        writein(attributes[indxptr->idom[i]-1].aname);
                    224:                                }
                    225:                                writein(")\n\\p\\g\n");
                    226:                                if(indxptr->ispec != 10 && indxptr->ispec != 11)
                    227:                                {
                    228:                                        xcount = retatts(indxptr->iname,indatts,indattx);
                    229:                                        modify(indxptr->iname,indatts,indattx,indxptr->ispec,xcount);
                    230:                                }
                    231:                        }
                    232:                }
                    233:        }
                    234:        fflush(Ifile);
                    235:        fflush(Ofile);
                    236:        printf("All done!\n\n");
                    237: }
                    238: exitfn()
                    239: {
                    240:        fflush(Ifile);
                    241:        fflush(Ofile);
                    242:        exit(-1);
                    243: }
                    244: 
                    245: 
                    246: modify(name, attributes, attxtra, spec, xcount)
                    247: char   *name;
                    248: struct attribute       *attributes;
                    249: int    *attxtra;
                    250: int    spec;
                    251: int    xcount;
                    252: {
                    253:        register        i,j;
                    254:        writein("modify ");
                    255:        writein(name);
                    256:        writein(" to ");
                    257:        switch(spec)
                    258:        {
                    259: 
                    260:          case -5:
                    261:                writein("cheap");
                    262:                goto nokeys;
                    263: 
                    264:          case -10:
                    265:          case -11:
                    266:                writein("c");
                    267:          case 10:
                    268:          case 11:
                    269:                writein("isam on ");
                    270:                break;
                    271: 
                    272:          case -20:
                    273:          case -21:
                    274:                writein("c");
                    275:          case 21:
                    276:          case 20:
                    277:                writein("hash on ");
                    278:                break;
                    279: 
                    280:          default:
                    281:                syserr("Unimplimented spec: %d on %s",
                    282:                        spec,name);
                    283: 
                    284:        }
                    285:        j = 0;
                    286:        for (i = 1; i <= xcount; i++)
                    287:        {
                    288:                if(j++)
                    289:                        writein(",\n\t");
                    290:                writein(attributes[attxtra[i]].aname);
                    291:        }
                    292:        if (!j)
                    293:                syserr("No keys found for %s!!!",name);
                    294: nokeys:
                    295:        writein("\n\\p\\g\n");
                    296: }
                    297: retatts(name,attributes,attxtra)
                    298: char   *name;
                    299: struct attribute       *attributes;
                    300: int    attxtra[];
                    301: {
                    302:        register        xcount, i;
                    303:        register struct attribute       *attptr;
                    304: 
                    305: ##     char    aname[MAXNAME];
                    306: ##     int     domain, length, extra;
                    307: ##     char    format[1];
                    308:        i = xcount = 0;
                    309: ##     retrieve (aname = a.attname,domain = a.attid, format = a.attfrmt,
                    310: ##              length = a.attfrml, extra = a.attxtra)
                    311: ##
                    312: ##     where a.attrelid = name and a.attowner = Usercode
                    313: ##     {
                    314:                if (i++ >= MAXDOM)
                    315:                        syserr("Too many attributes!!!");
                    316:                attptr = &attributes[domain-1];
                    317:                smove(aname,attptr->aname);
                    318:                attptr->format = format[0];
                    319:                attptr->length = length;
                    320:                if(extra)
                    321:                {
                    322:                        attxtra[extra] = domain - 1;
                    323:                        xcount++;
                    324:                }
                    325: ##     }
                    326:        return(xcount);
                    327: }
                    328: 
                    329: 
                    330: writeboth(string)
                    331: char   *string;
                    332: {
                    333:        register char   *sp;
                    334: 
                    335:        sp = string;
                    336: 
                    337:        while(*sp)
                    338:        {
                    339:                putc(*sp, Ofile);
                    340:                putc(*sp++, Ifile);
                    341:        }
                    342: }
                    343: 
                    344: putboth(ch)
                    345: char   ch;
                    346: {
                    347:        putc(ch, Ofile);
                    348:        putc(ch, Ifile);
                    349: }
                    350: 
                    351: 
                    352: writeout(string)
                    353: char   *string;
                    354: {
                    355:        register char   *sp;
                    356: 
                    357:        sp = string;
                    358:        while (*sp)
                    359:                putc(*sp++,Ofile);
                    360: }
                    361: 
                    362: 
                    363: writein(string)
                    364: char   *string;
                    365: {
                    366:        register char   *sp;
                    367: 
                    368:        sp = string;
                    369:        while (*sp)
                    370:                putc(*sp++,Ifile);
                    371: }
                    372: 
                    373: 
                    374: 
                    375: 
                    376: /*
                    377: ** Check to see if relation is wanted.
                    378: */
                    379: 
                    380: 
                    381: notwanted(relname)
                    382: char   *relname;
                    383: 
                    384: {
                    385: 
                    386:        register char   **wantlist;
                    387:        register char   *nptr;
                    388: 
                    389:        if (*(wantlist = Wanted) == (char *) 0)
                    390:                return (0);
                    391: 
                    392:        nptr = relname;
                    393:        do
                    394:                if (!scompare(nptr, 0, *wantlist++, 0))
                    395:                        return (0);
                    396:        while (*wantlist != (char *) 0);
                    397:        return (1);
                    398: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.