static int process_objectinfo(OBJECTINFO *oi, char *arg, const char *prompt) { char *tok; tok = strsep(&arg, "/"); if (!tok) return FALSE; oi->server = strdup(tok); tok = strsep(&arg, "/"); if (!tok) return FALSE; oi->user = strdup(tok); tok = strsep(&arg, "/"); if (!tok) return FALSE; if (strcmp(tok,"-") == 0) { printf("%s", prompt); oi->pass = gets_alloc(); } else { oi->pass = strdup(tok); memset(tok, '*', strlen(tok)); } tok = strsep(&arg, "/"); if (!tok) return FALSE; oi->db = strdup(tok); tok = strsep(&arg, "/"); if (!tok) return FALSE; oi->dbobject = strdup(tok); return TRUE; }
static int process_parameters(int argc, char **argv, BCPPARAMDATA * pdata) { int state; int i; char arg[FILENAME_MAX + 1]; char connection[256]; char owner[256]; char *tok; /* set some defaults */ pdata->batchsize = 1000; /* get the rest of the arguments */ state = GET_NEXTARG; for (i = 1; i < argc; i++) { strcpy(arg, argv[i]); switch (state) { case GET_NEXTARG: if (arg[0] != '-') return FALSE; switch (arg[1]) { case 'b': pdata->bflag++; if (strlen(arg) > 2) pdata->batchsize = atoi(&arg[2]); else state = GET_BATCHSIZE; break; case 'p': pdata->pflag++; if (strlen(arg) > 2) pdata->packetsize = atoi(&arg[2]); else state = GET_PACKETSIZE; break; case 't': pdata->tflag++; break; case 'a': pdata->aflag++; break; case 'c': pdata->cflag++; if (strlen(arg) > 2) { strcpy(owner, &arg[2]); pdata->owner = strdup(owner); } else state = GET_OWNER; break; case 'd': tdsdump_open(NULL); break; case 'S': pdata->Sflag++; if (strlen(arg) > 2) { strcpy(connection, &arg[2]); tok = strtok(connection, "/"); if (!tok) return FALSE; pdata->sserver = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->suser = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->spass = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->sdb = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->sdbobject = strdup(tok); } else state = GET_SOURCE; break; case 'D': pdata->Dflag++; if (strlen(arg) > 2) { strcpy(connection, &arg[2]); tok = strtok(connection, "/"); if (!tok) return FALSE; pdata->dserver = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->duser = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->dpass = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->ddb = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->ddbobject = strdup(tok); } else state = GET_DEST; break; case 'v': pdata->vflag++; break; default: return FALSE; } break; case GET_BATCHSIZE: pdata->batchsize = atoi(arg); state = GET_NEXTARG; break; case GET_PACKETSIZE: pdata->packetsize = atoi(arg); state = GET_NEXTARG; break; case GET_OWNER: if (arg[0] == '-') { fprintf(stderr, "If -c is specified an owner for the table must be provided.\n"); return FALSE; } strcpy(owner, arg); pdata->owner = strdup(owner); state = GET_NEXTARG; break; case GET_SOURCE: strcpy(connection, arg); tok = strtok(connection, "/"); if (!tok) return FALSE; pdata->sserver = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->suser = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->spass = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->sdb = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->sdbobject = strdup(tok); state = GET_NEXTARG; break; case GET_DEST: strcpy(connection, arg); tok = strtok(connection, "/"); if (!tok) return FALSE; pdata->dserver = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->duser = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->dpass = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->ddb = strdup(tok); tok = strtok(NULL, "/"); if (!tok) return FALSE; pdata->ddbobject = strdup(tok); state = GET_NEXTARG; break; default: break; } } /* one of these must be specified */ if ((pdata->tflag + pdata->aflag + pdata->cflag) != 1) { fprintf(stderr, "one (and only one) of -t, -a or -c must be specified\n"); return FALSE; } if (!pdata->Sflag) { printf("\nNo [-S]ource information supplied.\n\n"); printf("Enter Server : "); pdata->sserver = gets_alloc(); printf("Enter Login : "******"Enter Password : "******"Enter Database : "); pdata->sdb = gets_alloc(); printf("Enter Table : "); pdata->sdbobject = gets_alloc(); } if (!pdata->Dflag) { printf("\nNo [-D]estination information supplied.\n\n"); printf("Enter Server : "); pdata->dserver = gets_alloc(); printf("Enter Login : "******"Enter Password : "******"Enter Database : "); pdata->ddb = gets_alloc(); printf("Enter Table : "); pdata->ddbobject = gets_alloc(); } return TRUE; }
static int process_parameters(int argc, char **argv, BCPPARAMDATA * pdata) { int opt; /* set some defaults */ pdata->batchsize = 1000; /* get the rest of the arguments */ while ((opt = getopt(argc, argv, "b:p:tacdS:D:v")) != -1) { switch (opt) { case 'b': pdata->bflag++; pdata->batchsize = atoi(optarg); break; case 'p': pdata->pflag++; pdata->packetsize = atoi(optarg); break; case 't': pdata->tflag++; break; case 'a': pdata->aflag++; break; case 'c': pdata->cflag++; if (optarg[0] == '-') { fprintf(stderr, "Invalid owner specified.\n"); return FALSE; } pdata->owner = strdup(optarg); break; case 'd': tdsdump_open(NULL); break; case 'S': pdata->Sflag++; if (process_objectinfo(&pdata->src, optarg, "Enter Source Password: "******"Enter Destination Password: "******"one (and only one) of -t, -a or -c must be specified\n"); return FALSE; } if (!pdata->Sflag) { printf("\nNo [-S]ource information supplied.\n\n"); printf("Enter Server : "); pdata->src.server = gets_alloc(); printf("Enter Login : "******"Enter Password : "******"Enter Database : "); pdata->src.db = gets_alloc(); printf("Enter Table : "); pdata->src.dbobject = gets_alloc(); } if (!pdata->Dflag) { printf("\nNo [-D]estination information supplied.\n\n"); printf("Enter Server : "); pdata->dest.server = gets_alloc(); printf("Enter Login : "******"Enter Password : "******"Enter Database : "); pdata->dest.db = gets_alloc(); printf("Enter Table : "); pdata->dest.dbobject = gets_alloc(); } return TRUE; }