00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #include <stdlib.h>
00073 #include <stdio.h>
00074 #include <strings.h>
00075 #include <ctype.h>
00076 #include "soi_key.h"
00077 #include "soi_names.h"
00078
00079 #include "soi_error.h"
00080
00081 #define VERSION_NUM (0.8)
00082
00083
00084 static KEY *__collection_list;
00085 static char __tailfmt[MAX_STRLEN];
00086 static char __keyfmt[MAX_STRLEN];
00087
00088 static int add_env_template (KEY **tolist, char *root) {
00089
00090
00091
00092
00093
00094
00095
00096 char *pro;
00097 static char key[MAX_STRLEN];
00098 static char pro_key[MAX_STRLEN];
00099
00100 soi_errno = NO_ERROR;
00101 if (!root) {soi_errno = MISSING_ROOT_KEY; return soi_errno;}
00102
00103 sprintf (key, "%s_rule", root);
00104 if (getkeytype (*tolist, key) == KEYTYP_STRING)
00105 return NO_ERROR;
00106
00107 sprintf (pro_key, "%s_proj", root);
00108 if (pro = GETKEY_str (*tolist, pro_key))
00109 setkey_str (tolist, key, getenv (pro));
00110
00111 if (getkeytype (*tolist, key) == KEYTYP_STRING)
00112 return NO_ERROR;
00113
00114 sprintf (pro_key, "%s_prog", root);
00115 if (pro = GETKEY_str (*tolist, pro_key))
00116 setkey_str (tolist, key, getenv (pro));
00117 return NO_ERROR;
00118 }
00119
00120 static int add_basename (KEY **tolist, char *root) {
00121
00122
00123
00124
00125
00126
00127
00128 char *buffer, *charptr;
00129 static char key[MAX_STRLEN];
00130 char *template = NULL;
00131
00132 soi_errno = NO_ERROR;
00133 if (!root) {soi_errno = MISSING_ROOT_KEY; return soi_errno;}
00134
00135 add_env_template (tolist, root);
00136
00137 sprintf (key, "%s_rule", root);
00138 if (template = getkey_str (*tolist, key)) {
00139 if (charptr=(char*)strstr(template,"bn:")) {
00140 template=(char*)strchr(charptr,':'); template++;
00141 }
00142 else template=NULL;
00143 }
00144
00145
00146 sprintf (key, "%s_basename", root);
00147 if (!template)
00148 setkey_str (tolist, key, "");
00149 else {
00150 if (!(buffer=fill_template(template, *tolist, root))) return soi_errno;
00151 str_collapse(buffer,'/');
00152 setkey_str (tolist, key, buffer);
00153 }
00154
00155 return NO_ERROR;
00156 }
00157
00158 static int add_directory (KEY **tolist, char *root) {
00159
00160
00161
00162
00163
00164
00165
00166
00167 char *buffer, *charptr;
00168 static char key[MAX_STRLEN];
00169 char *template = NULL;
00170
00171 soi_errno = NO_ERROR;
00172 if (!root) {soi_errno = MISSING_ROOT_KEY; return soi_errno;}
00173
00174 sprintf (key, "%s_wd", root);
00175 if (getkeytype (*tolist, key) == KEYTYP_STRING) return NO_ERROR;
00176
00177 add_env_template (tolist, root);
00178
00179 sprintf (key, "%s_rule", root);
00180 if (template = getkey_str (*tolist, key)) {
00181 if (charptr=(char*)strstr(template,"wd:")) {
00182 template=(char*)strchr(template,':'); template++;
00183 }
00184 if (charptr=(char*)strstr(template,"bn:")) {
00185 *(--charptr)= 0;
00186 }
00187 }
00188
00189 sprintf (key, "%s_wd", root);
00190 if (!template)
00191 setkey_str (tolist, key, ".");
00192 else {
00193 if (!(buffer=fill_template(template, *tolist, root))) return soi_errno;
00194 str_collapse(buffer,'/');
00195 setkey_str (tolist, key, buffer);
00196 }
00197
00198 return NO_ERROR;
00199 }
00200
00201 static int add_paths (KEY **tolist, char *root) {
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 static char key[MAX_STRLEN];
00213 static char root_n[MAX_STRLEN];
00214 int nsets = 1;
00215 int n, status;
00216
00217 soi_errno = NO_ERROR;
00218 if (!root) {soi_errno = MISSING_ROOT_KEY; return soi_errno;}
00219
00220 sprintf (key, "%s_nsets", root);
00221 if (getkeytype (*tolist, key) == KEYTYP_INT)
00222 nsets = getkey_int (*tolist, key);
00223
00224 if (nsets == 1){
00225 if (status = add_directory(tolist, root)) return status;
00226 if (status = add_basename(tolist, root)) return status;
00227 }
00228
00229 for (n=0; n<nsets; n++) {
00230 sprintf (root_n,"%s_%d",root,n);
00231 if (status = add_directory(tolist, root_n)) return status;
00232 if (status = add_basename(tolist, root_n)) return status;
00233 }
00234 return NO_ERROR;
00235 }
00236
00237 static void add_member (KEY *member) {
00238
00239
00240
00241
00242
00243
00244 static char tail[MAX_STRLEN];
00245 static char key[MAX_STRLEN];
00246
00247 soi_errno = NO_ERROR;
00248 sscanf (member->name, __tailfmt, tail);
00249 sprintf (key, __keyfmt, tail);
00250 setkey_any (&__collection_list, key, member->val, member->type);
00251 }
00252
00253 static char *expand_range (char *member_range) {
00254
00255
00256
00257
00258
00259
00260
00261 static char expanded_range[MAX_STRLEN];
00262 static char local[MAX_STRLEN];
00263 static char lsnstr[MAX_STRLEN];
00264 char *charptr=local;
00265 char *range;
00266 int range_limit;
00267 int n, sn, fsn, lsn;
00268
00269 soi_errno = NO_ERROR;
00270 if (!member_range) {soi_errno = MISSING_DATA_NAME; return NULL;}
00271 if (strlen (member_range) >= MAX_STRLEN) {
00272 soi_errno=NAME_TOO_LONG; return NULL;
00273 }
00274 strcpy (local, member_range);
00275 expanded_range[0] = 0;
00276
00277 while (charptr) {
00278 range = charptr;
00279 if (charptr = (char*)strchr (range,',')) {
00280 *charptr = 0; charptr++;
00281 }
00282 if ((n = sscanf (range, "%d-%d", &fsn, &lsn)) == 1) lsn = fsn;
00283 else if (n !=2) {soi_errno = RANGE_SYNTAX_ERROR; return NULL;}
00284
00285 sprintf (lsnstr, "%d,", lsn);
00286 range_limit = MAX_STRLEN - strlen (lsnstr);
00287 for (sn = fsn; sn <= lsn; sn++) {
00288 if (strlen (expanded_range) >= range_limit) {
00289 errstk ("error in parse_list:expand_range(): strlen (range list) > %d\n probably too many indices\n",
00290 range_limit);
00291 soi_errno = NAME_TOO_LONG;
00292 return NULL;
00293 }
00294 sprintf (expanded_range, "%s%d,", expanded_range, sn);
00295 }
00296 }
00297 *((char*)strrchr (expanded_range, ',')) = 0;
00298 return expanded_range;
00299 }
00300
00301 static KEY *parse_class (char *collector, char *root) {
00302
00303
00304
00305
00306
00307
00308 static char local[MAX_STRLEN];
00309 static char key[MAX_STRLEN];
00310 KEY *return_list = newkeylist();
00311 char *range, *rightbracket;
00312 char *expanded_range = NULL;
00313
00314 soi_errno = NO_ERROR;
00315 if (!root) {soi_errno = MISSING_ROOT_KEY; return NULL;}
00316 if (!collector) {soi_errno = MISSING_DATA_NAME; return NULL;}
00317 if (strlen(collector)>=MAX_STRLEN) {soi_errno=NAME_TOO_LONG; return NULL;}
00318 strcpy (local, collector);
00319
00320 if (range = (char*)strchr (local, '[')) {
00321 *range = 0; range ++;
00322 if (!(rightbracket = (char*)strchr (range, ']'))) {
00323 soi_errno = CLASS_SYNTAX_ERROR;
00324 return NULL;
00325 }
00326 *rightbracket = 0;
00327 if (!(expanded_range = expand_range(range))) return NULL;
00328 sprintf (key, "%s_range", root);
00329 setkey_str (&return_list, key, expanded_range);
00330 if (!(strchr (expanded_range,','))) {
00331 sprintf(key, "%s_sn", root);
00332 setkey_int (&return_list, key, atoi(expanded_range));
00333 }
00334 }
00335 setkey_str (&return_list, root, local);
00336 return return_list;
00337 }
00338
00339 static KEY *parse_range (char *range, char *root) {
00340
00341
00342
00343
00344
00345
00346
00347
00348 KEY *return_list = newkeylist();
00349 static char key[MAX_STRLEN];
00350 int n, fsn, lsn, incr=1;
00351
00352 soi_errno = NO_ERROR;
00353 if (!root) {soi_errno = MISSING_ROOT_KEY; return NULL;}
00354 if (!range) {soi_errno = MISSING_DATA_NAME; return NULL;}
00355
00356 if ((n=sscanf (range, "%d-%d,%d", &fsn, &lsn, &incr)) == 1) lsn = fsn;
00357 else if (n == 3) ;
00358 else if (n != 2) {soi_errno = RANGE_SYNTAX_ERROR; return NULL;}
00359
00360 sprintf (key, "%s_fsn", root);
00361 setkey_int (&return_list, key, fsn);
00362
00363 sprintf (key, "%s_lsn", root);
00364 setkey_int (&return_list, key, lsn);
00365
00366 sprintf (key, "%s_incr", root);
00367 setkey_int (&return_list, key, incr);
00368
00369 return (return_list);
00370 }
00371
00372 static KEY *parse_data_selector (char *selector, char *root) {
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 KEY *return_list = newkeylist();
00386 KEY *range_list;
00387 static char local[MAX_STRLEN];
00388 static char key[MAX_STRLEN];
00389 static char default_range[] = "0--1";
00390 char *fmt, *records;
00391 char *charptr = local;
00392
00393 soi_errno = NO_ERROR;
00394 if (!root) {soi_errno = MISSING_ROOT_KEY; return NULL;}
00395
00396 if (!selector) {
00397 sprintf (key, "%s_fmt", root);
00398 setkey_str (&return_list, key, DEFAULT_SN_FMT);
00399 range_list = parse_range (default_range, root);
00400 add_keys (range_list, &return_list);
00401 freekeylist (&range_list);
00402 return return_list;
00403 }
00404
00405 if (strlen(selector)>=MAX_STRLEN) {soi_errno=NAME_TOO_LONG; return NULL;}
00406 strcpy (local, selector);
00407
00408 sprintf(key,"%s_selector", root);
00409 setkey_str (&return_list, key, selector);
00410
00411 sprintf (key, "%s_fmt", root);
00412 if (fmt=(char*)strstr (local,",fmt:")) {
00413 *fmt=0; fmt++; fmt=(char*)strchr(fmt,':'); fmt++;
00414 setkey_str (&return_list, key, fmt);
00415 }
00416 else setkey_str (&return_list, key, DEFAULT_SN_FMT);
00417
00418 if (records = (char*)strchr (local, '[')) {
00419 *records=0; records++;
00420 if (charptr = (char*)strchr(records,']')) {*charptr=0; charptr++;}
00421 else {soi_errno = DATA_SELECTOR_SYNTAX_ERROR; return NULL;}
00422
00423 if (strlen(records)) range_list = parse_range (records, root);
00424 else range_list = parse_range (default_range, root);
00425 if (range_list) {
00426 add_keys (range_list, &return_list);
00427 freekeylist (&range_list);
00428 }
00429 else return NULL;
00430
00431 if (*(charptr) == '[') {
00432 sprintf (key, "%s_slice", root);
00433 setkey_str (&return_list, key, charptr);
00434 }
00435 }
00436 else {
00437 range_list = parse_range (default_range, root);
00438 add_keys (range_list, &return_list);
00439 freekeylist (&range_list);
00440 }
00441
00442 sprintf (key, "%s_select", root);
00443 if (charptr=(char*)strrchr(local,'/')) {
00444 charptr++; setkey_str (&return_list, key, charptr); *charptr=0;
00445 sprintf (key, "%s_wd", root);
00446 setkey_str (&return_list, key, local);
00447 }
00448 else setkey_str (&return_list, key, local);
00449
00450 return return_list;
00451 }
00452
00453 static KEY *parse_datasuperset (char *superset, char *root) {
00454
00455
00456
00457
00458
00459 static char local[MAX_STRLEN];
00460 static char key[MAX_STRLEN];
00461
00462 KEY *return_list = newkeylist();
00463 KEY *sublist;
00464 char *classname, *selector;
00465 char *nextptr = local;
00466
00467 soi_errno = NO_ERROR;
00468 if (!root) {soi_errno = MISSING_ROOT_KEY; return NULL;}
00469 if (!superset) {soi_errno = MISSING_DATA_NAME; return NULL;}
00470 if (strlen(superset)>=MAX_STRLEN) {soi_errno=NAME_TOO_LONG; return NULL;}
00471 strcpy (local, superset);
00472
00473 sprintf (key, "%s_data", root);
00474 setkey_str (&return_list, key, local);
00475
00476 while (nextptr) {
00477 classname = nextptr;
00478 if (nextptr = (char*)strchr (classname, ':')) {
00479 *nextptr = 0;
00480 nextptr++;
00481 } else {
00482 soi_errno = DATASUPERSET_SYNTAX_ERROR;
00483 return NULL;
00484 }
00485
00486 if (!strlen (classname)) {
00487 soi_errno = CLASS_SYNTAX_ERROR;
00488 return NULL;
00489 }
00490 sprintf (key, "%s_%s", root, classname);
00491
00492 selector = nextptr;
00493 if (strcmp (classname, "series")) {
00494 if (nextptr = (char*)strchr(selector, ',')) {*nextptr = 0; nextptr++;}
00495 }
00496 else
00497
00498 nextptr = NULL;
00499
00500 if (!(sublist = parse_class (selector, key))) return NULL;
00501 add_keys (sublist, &return_list);
00502 freekeylist (&sublist);
00503 }
00504 return return_list;
00505 }
00506
00507 KEY *parse_dataname (char *data, char *root) {
00508
00509
00510
00511
00512
00513
00514
00515 KEY *return_list = newkeylist();
00516 KEY *sublist;
00517 static char local[MAX_STRLEN];
00518 char *selector;
00519
00520 soi_errno = NO_ERROR;
00521 if (!root) {soi_errno = MISSING_ROOT_KEY; return NULL;}
00522 if (!data) {soi_errno = MISSING_DATA_NAME; return NULL;}
00523 if (strlen(data)>=MAX_STRLEN) {soi_errno=NAME_TOO_LONG; return NULL;}
00524 strcpy (local, data);
00525
00526 if ((local == (char*)strstr(local, "proj:")) ||
00527 (local == (char*)strstr(local, "prog:"))) {
00528 if (selector = (char*)strstr(local, ",sel:")) {
00529 *selector=0;
00530 selector++;
00531 selector=(char*)strchr(selector,':');
00532 selector++;
00533 }
00534
00535 if (sublist = parse_datasuperset (local, root)) {
00536 add_keys (sublist, &return_list);
00537 freekeylist (&sublist);
00538 } else return NULL;
00539 }
00540 else selector = local;
00541
00542 if (sublist = parse_data_selector(selector,root)) {
00543 add_keys (sublist, &return_list);
00544 freekeylist (&sublist);
00545 } else return NULL;
00546
00547 return return_list;
00548 }
00549
00550 #define MAXXLEN (16384)
00551
00552
00553
00554
00555
00556
00557
00558 static KEY * parse_datacollection (char *collection, char *root) {
00559
00560
00561
00562
00563
00564
00565 int nsets = 0;
00566 static char local[MAXXLEN];
00567 static char key[MAXXLEN];
00568 static char sn_key[MAXXLEN];
00569 static char range_key[MAXXLEN];
00570 char *nextptr, *nptr, *datasubset, *range;
00571 char *charptr = local;
00572 KEY *data_list;
00573
00574 soi_errno = NO_ERROR;
00575 if (!root) {soi_errno = MISSING_ROOT_KEY; return NULL;}
00576 if (!collection) {soi_errno = MISSING_DATA_NAME; return NULL;}
00577
00578
00579 __collection_list=newkeylist();
00580 sprintf (__tailfmt, "%s_%s", root, "%s");
00581
00582 if (strlen (collection) >= MAXXLEN) {
00583 soi_errno = NAME_TOO_LONG;
00584 return NULL;
00585 }
00586 strcpy (local, collection);
00587 sprintf (range_key, "%s_series_range", root);
00588
00589 while (charptr) {
00590 datasubset = charptr;
00591 if (charptr = (char*)strchr (datasubset,';')) {
00592 *charptr = 0;
00593 charptr++;
00594 }
00595
00596 if (!strlen (datasubset)) {
00597 soi_errno = DATACOLLECTION_SYNTAX_ERROR;
00598 return NULL;
00599 }
00600
00601 if(!(data_list = parse_dataname (datasubset, root))) return NULL;
00602
00603 if (range=getkey_str (data_list, range_key)) {
00604
00605 nextptr = range;
00606 while (nextptr) {
00607 nptr = nextptr;
00608 if (nextptr = (char*)strchr (nptr, ',')) {
00609 *nextptr = 0; nextptr++;
00610 }
00611
00612 sprintf(__keyfmt,"%s_%d_%s", root, nsets, "%s");
00613 sprintf(sn_key, __keyfmt, "series_sn");
00614 setkey_int (&__collection_list, sn_key, atoi(nptr));
00615 keyiterate (add_member, data_list);
00616 nsets++;
00617 }
00618 free (range);
00619 }
00620 else {
00621 sprintf(__keyfmt,"%s_%d_%s", root, nsets, "%s");
00622 keyiterate (add_member, data_list);
00623 nsets++;
00624 }
00625 if (nsets==1) add_keys (data_list, &__collection_list);
00626 freekeylist (&data_list);
00627 }
00628
00629 sprintf (key, "%s_nsets", root);
00630 setkey_int (&__collection_list, key, nsets);
00631
00632 return __collection_list;
00633 }
00634
00635 static void replicate_name (char *name, KEY **inlist, char *root) {
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648 static char key[MAX_STRLEN];
00649 int n, nsets, keytype, intval;
00650 char *stringval;
00651
00652 soi_errno = NO_ERROR;
00653 if (!root) {soi_errno = MISSING_ROOT_KEY; return;}
00654 if (!name) return;
00655
00656 sprintf (key, "%s_nsets", root);
00657 if (KEYTYP_INT != getkeytype (*inlist, key)) return;
00658 nsets = getkey_int (*inlist, key);
00659
00660 sprintf (key, "%s_%s", root, name);
00661 if (KEYTYP_VOID == (keytype = getkeytype (*inlist, key))) return;
00662
00663 if (keytype == KEYTYP_STRING) {
00664 stringval = getkey_str(*inlist, key);
00665 for (n=0; n<nsets; n++) {
00666 sprintf (key, "%s_%d_%s", root, n, name);
00667 setkey_str (inlist, key, stringval);
00668 }
00669 free (stringval);
00670 }
00671 else if (keytype == KEYTYP_INT) {
00672 intval = getkey_int (*inlist, key);
00673 for (n=0; n<nsets; n++) {
00674 sprintf (key, "%s_%d_%s", root, n, name);
00675 setkey_int (inlist, key, intval);
00676 }
00677 }
00678 else return;
00679 }
00680
00681 void str_compress (char *s) {
00682 char *source, *dest;
00683 source = dest = s;
00684 while (*source) {
00685 if (!isspace (*source)) {
00686 *dest = *source;
00687 dest++;
00688 }
00689 source++;
00690 }
00691 *dest = 0;
00692 }
00693
00694 void str_collapse (char *s, char c) {
00695
00696 char *source, *dest;
00697 int skipit=0;
00698 source = dest = s;
00699 while (*source) {
00700 if (*source!=c) {
00701 skipit=0;
00702 *dest = *source;
00703 dest++;
00704 }
00705 else if (!skipit) {
00706 skipit=1;
00707 *dest = *source;
00708 dest++;
00709 }
00710 source++;
00711 }
00712 *dest = 0;
00713 }
00714
00715 void int2numstr (char *numstr, char *fmt, int num) {
00716
00717
00718
00719 int nchars;
00720 char c;
00721
00722 numstr[0] = '\0';
00723 if (2==sscanf(fmt,"%*c%d%c",&nchars,&c) && (c=='T')) {
00724 TIME t = MISSION_EPOCH;
00725 if (num<3624) t += 86400*num;
00726 else if (num>219150) t += 60*num;
00727 else t += 3600*num;
00728 sprint_at(numstr, t);
00729 if (nchars<strlen(numstr)) numstr[nchars] = '\0';
00730 }
00731 else
00732 sprintf(numstr,fmt,num);
00733 }
00734
00735 int parse_list (KEY **params, char *root) {
00736
00737
00738
00739
00740
00741 char *dataname;
00742 KEY *data_list = NULL;
00743 soi_errno = NO_ERROR;
00744
00745 if (!(dataname = getkey_str (*params, root)))
00746 {soi_errno = MISSING_DATA_NAME; return soi_errno;}
00747
00748
00749 str_compress (dataname);
00750 if (!strlen(dataname))
00751 {soi_errno = MISSING_DATA_NAME; return soi_errno;}
00752
00753 if (!(data_list = parse_datacollection (dataname, root))) return soi_errno;
00754 free (dataname);
00755
00756 add_keys (data_list, params);
00757 freekeylist (&data_list);
00758
00759 replicate_name ("dbase", params, root);
00760 return add_paths (params, root);
00761 }
00762
00763 char *fill_template (char *template, KEY *fromlist, char *root){
00764
00765
00766
00767
00768
00769
00770 static char local[MAX_STRLEN];
00771 static char buffer[MAX_STRLEN];
00772 static char key[MAX_STRLEN];
00773 static char fmt[MAX_STRLEN];
00774 static char member_number[MAX_STRLEN];
00775 char *tmp = local;
00776 char *another, *member_name, *left, *right;
00777
00778 soi_errno = NO_ERROR;
00779 if (!root) {soi_errno = MISSING_ROOT_KEY; return NULL;}
00780 if (template)
00781 if (strlen(template)<MAX_STRLEN) strcpy (local,template);
00782 else {soi_errno = NAME_TOO_LONG; return NULL;}
00783 else tmp=NULL;
00784 buffer[0] = 0;
00785
00786
00787 while (tmp) {
00788 left = index (tmp, '{');
00789 if (left) {
00790 *left = 0;
00791 if (strlen(buffer)+strlen(tmp) >= MAX_STRLEN)
00792 {soi_errno = NAME_TOO_LONG; return NULL;}
00793 strcat (buffer, tmp);
00794 tmp = ++left;
00795 right = index (tmp, '}');
00796 if (right) {
00797 *right = 0;
00798 if (tmp[0] == '#') {
00799
00800 if (another = (char*)strchr (++tmp, '#')) {
00801 *another = 0;
00802 sprintf (fmt, "%s", tmp);
00803 tmp = ++another;
00804 }
00805 else {
00806 sprintf (fmt, "%s", "%d");
00807 }
00808
00809 sprintf (key, "%s_%s_sn", root, tmp);
00810 if (getkeytype (fromlist, key) == KEYTYP_INT) {
00811 int2numstr (member_number, fmt, getkey_int (fromlist, key));
00812 if (strlen(buffer)+strlen(member_number) >= MAX_STRLEN)
00813 {soi_errno = NAME_TOO_LONG; return NULL;}
00814 strcat (buffer,member_number);
00815 }
00816 else {
00817 soi_errno = CANNOT_FILL_TEMPLATE;
00818 return NULL;
00819 }
00820 }
00821 else {
00822 sprintf (key, "%s_%s", root, tmp);
00823 if (member_name = getkey_str(fromlist, key)) {
00824 if (strlen(buffer)+strlen(member_name) >= MAX_STRLEN)
00825 {soi_errno = NAME_TOO_LONG; return NULL;}
00826 strcat (buffer, member_name);
00827 free (member_name);
00828 }
00829 else {
00830 soi_errno = CANNOT_FILL_TEMPLATE;
00831 return NULL;
00832 }
00833 }
00834 tmp = ++right;
00835 }
00836 else {
00837 soi_errno = TEMPLATE_SYNTAX_ERROR;
00838 return NULL;
00839 }
00840 }
00841 else {
00842 if (strlen(buffer)+strlen(tmp) >= MAX_STRLEN)
00843 {soi_errno = NAME_TOO_LONG; return NULL;}
00844 strcat (buffer, tmp);
00845 tmp = NULL;
00846 }
00847 }
00848 return buffer;
00849 }
00850
00851 char *logname (KEY *params, char *root) {
00852
00853
00854
00855
00856 static char tmp[MAX_STRLEN];
00857 static char key[MAX_STRLEN];
00858 char *extension;
00859 char *name;
00860
00861 sprintf (key, "%s_select", root);
00862 if (getkeytype (params, key) == KEYTYP_STRING) {
00863 sprintf (tmp, "%s", getkey_str(params, key));
00864 if (((extension = (char *)strrchr (tmp, '.')) != 0) &&
00865 (strcmp (extension, ".log") == 0)) {
00866 ;
00867 } else {
00868 soi_errno = CANNOT_MAKE_NAME;
00869 return NULL;
00870 }
00871 } else {
00872 sprintf (key, "%s_wd", root);
00873 if (getkeytype (params, key) == KEYTYP_STRING)
00874 sprintf (tmp, "%s", getkey_str(params, key));
00875 else
00876 tmp[0] = 0;
00877
00878 sprintf (key, "%s_basename", root);
00879 if (getkeytype (params, key) == KEYTYP_STRING)
00880 if (strlen (getkey_str (params, key)))
00881 sprintf (tmp, "%s%s", tmp, getkey_str(params, key));
00882
00883 if (strlen (tmp)) {
00884 sprintf (tmp, "%s.log", tmp);
00885 } else {
00886 soi_errno = CANNOT_MAKE_NAME;
00887 return NULL;
00888 }
00889 }
00890
00891 if (name = (char *)malloc (2*(strlen(tmp) + 1)))
00892 strcpy (name, tmp);
00893 return name;
00894 }
00895
00896 char *fitsname (KEY *params, char *root, int sn) {
00897
00898
00899
00900
00901 static char tmp[MAX_STRLEN];
00902 static char key[MAX_STRLEN];
00903 static char format[MAX_STRLEN];
00904 char *name;
00905 char *fmt;
00906 char *extension;
00907 char *lastslash;
00908
00909 sprintf (key, "%s_wd", root);
00910 if (getkeytype (params, key) == KEYTYP_STRING)
00911 if (strlen (getkey_str (params, key)))
00912 sprintf (tmp, "%s/", getkey_str(params, key));
00913 else tmp[0] = 0;
00914
00915 sprintf (key, "%s_basename", root);
00916 if (getkeytype (params, key) == KEYTYP_STRING)
00917 if (strlen (getkey_str (params, key)))
00918 sprintf (tmp, "%s%s.", tmp, getkey_str(params, key));
00919
00920 sprintf (key, "%s_select", root);
00921 if (getkeytype (params, key) == KEYTYP_STRING)
00922 if (strlen (getkey_str (params, key)))
00923 sprintf (tmp, "%s%s", tmp, getkey_str(params, key));
00924
00925 sprintf (key, "%s_fmt", root);
00926 if (getkeytype (params, key) == KEYTYP_STRING)
00927 fmt = getkey_str (params, key);
00928 else
00929 fmt = DEFAULT_SN_FMT;
00930
00931 extension = (char *)strrchr (tmp, '.');
00932 lastslash = (char *)strrchr (tmp, '/');
00933
00934 if ((extension != NULL) && (strcmp (extension, ".fits") == 0)) {
00935
00936 ;
00937 } else if (
00938 ((extension != NULL) && (strcmp (extension, ".") == 0)) ||
00939
00940 ((lastslash != NULL) && (strcmp (lastslash, "/") == 0))) {
00941
00942 sprintf (format, "%s%s.fits", "%s", fmt);
00943 sprintf (tmp, format, tmp, sn);
00944 } else if (strlen (tmp)) {
00945 sprintf (format, "%s.%s.fits", "%s", fmt);
00946 sprintf (tmp, format, tmp, sn);
00947 } else {
00948 sprintf (format, "%s.fits", fmt);
00949 sprintf (tmp, format, sn);
00950 }
00951
00952 if (name = (char *)malloc (2*(strlen(tmp) + 1)));
00953 strcpy (name, tmp);
00954 return name;
00955 }
00956
00957 char *fitsname_nopath (KEY *params, char *root, int sn) {
00958
00959
00960
00961 static char tmp[MAX_STRLEN], key[MAX_STRLEN], format[MAX_STRLEN];
00962 char *name, *fmt, *extension, *lastslash;
00963
00964 sprintf (key, "%s_basename", root);
00965 if (getkeytype (params, key) == KEYTYP_STRING)
00966 if (strlen (getkey_str (params, key)))
00967 sprintf (tmp, "%s.", getkey_str(params, key));
00968 else tmp[0] = '\0';
00969
00970 sprintf (key, "%s_select", root);
00971 if (getkeytype (params, key) == KEYTYP_STRING)
00972 strcat (tmp, getkey_str (params, key));
00973
00974 sprintf (key, "%s_fmt", root);
00975 fmt = (getkeytype (params, key) == KEYTYP_STRING) ?
00976 getkey_str (params, key) : DEFAULT_SN_FMT;
00977
00978 extension = (char *)strrchr (tmp, '.');
00979 lastslash = (char *)strrchr (tmp, '/');
00980
00981 if ((extension != NULL) && (strcmp (extension, ".fits") == 0)) {
00982 ;
00983 } else if (((extension != NULL) && (strcmp (extension, ".") == 0)) ||
00984 ((lastslash != NULL) && (strcmp (lastslash, "/") == 0))) {
00985 sprintf (format, "%s%s.fits", "%s", fmt);
00986 sprintf (tmp, format, tmp, sn);
00987 } else if (strlen (tmp)) {
00988 sprintf (format, "%s.%s.fits", "%s", fmt);
00989 sprintf (tmp, format, tmp, sn);
00990 } else {
00991 sprintf (format, "%s.fits", fmt);
00992 sprintf (tmp, format, sn);
00993 }
00994
00995 if (name = (char *)malloc (2*(strlen (tmp) + 1)));
00996 strcpy (name, tmp);
00997 return name;
00998 }
00999
01000 char *fitsname_noseries (KEY *params, char *root, int sn)
01001
01002
01003
01004
01005
01006
01007
01008 {
01009 static char tmp[MAX_STRLEN];
01010 static char key[MAX_STRLEN];
01011 static char format[MAX_STRLEN];
01012 char *name;
01013 char *fmt;
01014 char *extension;
01015 char *lastslash;
01016
01017 sprintf (key, "%s_wd", root);
01018 if (getkeytype (params, key) == KEYTYP_STRING)
01019 if (strlen (getkey_str (params, key)))
01020 sprintf (tmp, "%s/", getkey_str(params, key));
01021 else tmp[0] = 0;
01022
01023 sprintf (key, "%s_select", root);
01024 if (getkeytype (params, key) == KEYTYP_STRING)
01025 if (strlen (getkey_str (params, key)))
01026 sprintf (tmp, "%s%s", tmp, getkey_str(params, key));
01027
01028 sprintf (key, "%s_fmt", root);
01029 if (getkeytype (params, key) == KEYTYP_STRING)
01030 fmt = getkey_str (params, key);
01031 else
01032 fmt = DEFAULT_SN_FMT;
01033
01034 extension = (char *)strrchr (tmp, '.');
01035 lastslash = (char *)strrchr (tmp, '/');
01036
01037 if ((extension != NULL) && (strcmp (extension, ".fits") == 0))
01038
01039 {
01040 ;
01041 }
01042 else if (
01043 ((extension != NULL) && (strcmp (extension, ".") == 0)) ||
01044
01045 ((lastslash != NULL) && (strcmp (lastslash, "/") == 0))
01046
01047 )
01048
01049 {
01050 sprintf (format, "%s%s.fits", "%s", fmt);
01051 sprintf (tmp, format, tmp, sn);
01052 }
01053 else if (strlen (tmp))
01054
01055 {
01056 sprintf (format, "%s.%s.fits", "%s", fmt);
01057 sprintf (tmp, format, tmp, sn);
01058 }
01059 else
01060
01061 {
01062 sprintf (format, "%s.fits", fmt);
01063 sprintf (tmp, format, sn);
01064 }
01065
01066 if (name = (char *)malloc (2*(strlen(tmp) + 1)));
01067 strcpy (name, tmp);
01068 return name;
01069 }
01070
01071
01072 char *tlmname (KEY *params, char *root)
01073
01074
01075
01076
01077
01078
01079 {
01080 static char tmp[MAX_STRLEN];
01081 static char key[MAX_STRLEN];
01082 char *name;
01083
01084 sprintf (key, "%s_prog", root);
01085 if (getkeytype (params, key) == KEYTYP_STRING)
01086 {if (strlen (getkey_str (params, key)))
01087 {
01088 sprintf (key, "%s_wd", root);
01089 if (getkeytype (params, key) == KEYTYP_STRING)
01090 if (strlen (getkey_str (params, key)))
01091 sprintf (tmp, "%s/tfr", getkey_str(params, key));
01092 else tmp[0] = 0;
01093 }
01094 }
01095 else
01096 {
01097 sprintf (key, "%s_selector", root);
01098 if (getkeytype (params, key) == KEYTYP_STRING)
01099 if (strlen (getkey_str (params, key)))
01100 sprintf (tmp, "%s", getkey_str(params, key));
01101 else tmp[0] = 0;
01102 }
01103 if (name = (char *)malloc (2*(strlen(tmp) + 1)));
01104 strcpy (name, tmp);
01105
01106 return name;
01107 }
01108
01109
01110 char *datasetname (KEY *params, char *root)
01111 {
01112
01113
01114
01115
01116
01117
01118 static char key[MAX_STRLEN];
01119 char *name, *tmp;
01120
01121 sprintf (key, "%s_fmt", root);
01122 if (getkeytype (params, key) == KEYTYP_STRING)
01123 {
01124 tmp = getkey_str (params, root);
01125 if (name = (char *)malloc (2 * (strlen (tmp) + 1)))
01126 {
01127 strcpy (name, tmp);
01128 tmp = (char*)strstr (name, ",fmt:");
01129 if (tmp)
01130 tmp[0] = 0;
01131 }
01132 return (name);
01133 }
01134 else
01135 return (getkey_str (params, root));
01136 }