static int keycrunch_sha1(char *result, char *seed, char *passwd) { char *buf; SHA1_CTX sha; unsigned int buflen; int i, j; /* * If seed and passwd are defined we are in keycrunch() mode, * else we are in f() mode. */ if (seed && passwd) { buflen = strlen(seed) + strlen(passwd); if ((buf = malloc(buflen + 1)) == NULL) return(-1); (void)strlcpy(buf, seed, buflen + 1); lowcase(buf); (void)strlcat(buf, passwd, buflen + 1); sevenbit(buf); } else { buf = result; buflen = SKEY_BINKEY_SIZE; } /* Crunch the key through SHA1 */ SHA1Init(&sha); SHA1Update(&sha, (unsigned char *)buf, buflen); SHA1Pad(&sha); /* Fold 160 to 64 bits */ sha.state[0] ^= sha.state[2]; sha.state[1] ^= sha.state[3]; sha.state[0] ^= sha.state[4]; /* * SHA1 is a big endian algorithm but RFC2289 mandates that * the result be in little endian form, so we copy to the * result buffer manually. */ for (i = 0, j = 0; j < 8; i++, j += 4) { result[j] = (u_char)(sha.state[i] & 0xff); result[j+1] = (u_char)((sha.state[i] >> 8) & 0xff); result[j+2] = (u_char)((sha.state[i] >> 16) & 0xff); result[j+3] = (u_char)((sha.state[i] >> 24) & 0xff); } if (buf != result) (void)free(buf); return(0); }
int id(char *name) { int t; char c, *p = token; d("id",token,name); if (type(*p++) != LETTER) return 0; while ((c = *p++)) { t = type(c); if (t != NUMBER && t != LETTER) return(0); } lowcase(token); enter(name,token); gettoken(); return(1); }
FILE * OpenCaptureFile(const char * type,const char * ext) { if(capturedir.empty()) { LOG_MSG("Please specify a capture directory"); return 0; } Bitu last=0; char file_start[16]; dir_information * dir; /* Find a filename to open */ dir = open_directory(capturedir.c_str()); if (!dir) { //Try creating it first Cross::CreateDir(capturedir); dir=open_directory(capturedir.c_str()); if(!dir) { LOG_MSG("Can't open dir %s for capturing %s",capturedir.c_str(),type); return 0; } } strcpy(file_start,RunningProgram); lowcase(file_start); strcat(file_start,"_"); bool is_directory; char tempname[CROSS_LEN]; bool testRead = read_directory_first(dir, tempname, is_directory ); for ( ; testRead; testRead = read_directory_next(dir, tempname, is_directory) ) { char * test=strstr(tempname,ext); if (!test || strlen(test)!=strlen(ext)) continue; *test=0; if (strncasecmp(tempname,file_start,strlen(file_start))!=0) continue; Bitu num=atoi(&tempname[strlen(file_start)]); if (num>=last) last=num+1; } close_directory( dir ); char file_name[CROSS_LEN]; sprintf(file_name,"%s%c%s%03d%s",capturedir.c_str(),CROSS_FILESPLIT,file_start,last,ext); /* Open the actual file */ FILE * handle=fopen(file_name,"wb"); if (handle) { LOG_MSG("Capturing %s to %s",type,file_name); } else { LOG_MSG("Failed to open %s for capturing %s",file_name,type); } return handle; }
static int keycrunch_rmd160(char *result, char *seed, char *passwd) { char *buf; RMD160_CTX rmd; u_int32_t results[5]; unsigned int buflen; /* * If seed and passwd are defined we are in keycrunch() mode, * else we are in f() mode. */ if (seed && passwd) { buflen = strlen(seed) + strlen(passwd); if ((buf = malloc(buflen + 1)) == NULL) return(-1); (void)strlcpy(buf, seed, buflen + 1); lowcase(buf); (void)strlcat(buf, passwd, buflen + 1); sevenbit(buf); } else { buf = result; buflen = SKEY_BINKEY_SIZE; } /* Crunch the key through RMD-160 */ RMD160Init(&rmd); RMD160Update(&rmd, (unsigned char *)buf, buflen); RMD160Final((unsigned char *)results, &rmd); /* Fold 160 to 64 bits */ results[0] ^= results[2]; results[1] ^= results[3]; results[0] ^= results[4]; (void)memcpy((void *)result, (void *)results, SKEY_BINKEY_SIZE); if (buf != result) (void)free(buf); return(0); }
int GetAsnTable (AsnInfo *asn) { /* Arguments: ** asn o: Association info structure */ extern int status; /* Local variables */ int i; /* loop index */ int nrows; /* number of rows in ASNTAB */ int col, row; /* loop indexes */ IRAFPointer tp; /* ASNTAB table pointer */ IRAFPointer colptr[NCOLS]; /* ASNTAB column pointers */ int numsp; /* number of sub-products in asn */ int posid; /* id of sub-product */ RowInfo *exp; /* Internal structure for table information */ int *spmems, *expmem; /* number of EXP for each sub-product */ int poslen; /* Length of memtype string minus POSID */ int prodid; /* id of product */ int expid; int defid; /* default position id for exposures */ int procprod; int maxspmems; /* max number of sub-product members */ char *word; Bool proddth; char spname_ext[SZ_CBUF+1]; /* Extension for sub-product */ char spname_ext_cte[SZ_CBUF+1]; /* Extension for sub-product */ char memtype[SZ_COLNAME+1]; char memsubtype[SZ_COLNAME+1]; /* ASNTAB column names */ char colname[NCOLS][SZ_COLNAME+1] = { "MEMNAME", "MEMTYPE", "MEMPRSNT" }; /* Function definitions */ void freeAsnInfo (AsnInfo *); int allocAsnInfo (AsnInfo *, int, int *); void trlopenerr (char *); void trlwarn (char *); char *lowcase (char *, char *); int MkName (char *, char *, char *, char *, char *, int); void initRowInfo (RowInfo *); int streq_ic (char *, char *); /* strings equal? (case insensitive) */ if (asn->debug) { sprintf (MsgText, "GetAsnTable: ASN_TABLE is %s",asn->asn_table); trlmessage (MsgText); } /* Open the ASN table */ tp = c_tbtopn (asn->asn_table, IRAF_READ_ONLY, 0); if (c_iraferr()) { trlopenerr (asn->asn_table); return (status = TABLE_ERROR); } /* Get pointers to columns in ASNTAB */ for (col=0; col < NCOLS; col++) { c_tbcfnd1 (tp, colname[col], &(colptr[col])); if (c_iraferr() || colptr[col] == 0) { sprintf (MsgText, "Can't find column %s in %s", colname[col], asn->asn_table); trlerror (MsgText); c_tbtclo (tp); return (status = COLUMN_NOT_FOUND); } } /* Find out how many rows are in ASNTAB */ nrows = 0; nrows = c_tbpsta (tp, TBL_NROWS); if (nrows <= 0) { sprintf (MsgText, "Invalid number of rows in %s", asn->asn_table); trlerror (MsgText); c_tbtclo (tp); return (status = TABLE_ERROR); } /* Initialize total number of members based on number of ** rows in table */ asn->numasn = nrows; poslen = 0; /* Allocate space for internal variables */ exp = NULL; exp = (RowInfo *)calloc(nrows, sizeof(RowInfo)); for (row = 0; row < nrows; row++) initRowInfo (&(exp[row])); /* Read each row of ASNTAB into a local structure */ for (row = 0; row < nrows; row++) { /* Get the MEMBER NAME in this row */ c_tbegtt (tp, colptr[0], row+1, exp[row].memname, SZ_CBUF); if (c_iraferr()) { sprintf (MsgText, "Can't read %s in row %d in %s", colname[0], row+1, asn->asn_table); trlerror (MsgText); c_tbtclo (tp); free (exp); return (status = ELEMENT_NOT_FOUND); } /* Convert to lowercase for use as a file name */ for (i = 0; i < strlen(exp[row].memname); i++) exp[row].memname[i] = tolower(exp[row].memname[i]); /* Get the TYPE in this row */ c_tbegtt (tp, colptr[1], row+1, exp[row].mtype, SZ_CBUF); if (c_iraferr()) { sprintf (MsgText, "Can't read %s in row %d in %s", colname[1], row+1, asn->asn_table); trlerror (MsgText); c_tbtclo (tp); free (exp); return (status = ELEMENT_NOT_FOUND); } /* Convert to lowercase for use later in routine. ** Also, if a value of MEMTYPE contains a UNDERLINE, then ** record conversion to DASH in trailer file and warn ** user to correct the value. */ lowcase (exp[row].type, exp[row].mtype); for (i = 0; i < strlen(exp[row].type); i++) { if (exp[row].type[i] == UNDERLINE_CHAR) { exp[row].type[i] = DASH_CHAR; sprintf(MsgText, "MEMTYPE %s in row %d was INVALID and needs to be corrected.", exp[row].mtype, row+1); trlwarn(MsgText); } } /* Get the STATUS in this row */ c_tbegtb (tp, colptr[2], row+1, &(exp[row].prsnt)); if (c_iraferr()) { sprintf (MsgText, "Can't read %s in row %d in %s", colname[2], row+1, asn->asn_table); trlerror (MsgText); c_tbtclo (tp); free (exp); return (status = ELEMENT_NOT_FOUND); } if (asn->debug) { sprintf (MsgText, "GetAsnTable: Read in row %d from ASN table", row); trlmessage (MsgText); } } /* ** Determine whether CRCORR or RPTOBS processing will be required ** by searching for MEMTYPE of EXP_CR* or EXP_RPT*, respectively. ** Once it is determined, go on to next step... */ for (row = 0; row < nrows; row++) { /* Check to see if we need to do CR-SPLIT combination ... */ if (strstr (exp[row].type, "-cr") != NULL) { asn->crcorr = PERFORM; asn->rptcorr = OMIT; poslen = CRLEN; break; /* ... or REPEAT-OBS combination ... */ } else if (strstr (exp[row].type, "-rp") != NULL) { asn->rptcorr = PERFORM; asn->crcorr = OMIT; poslen = RPTLEN; break; /* ... or neither at all */ } else { asn->rptcorr = OMIT; asn->crcorr = OMIT; poslen = DTHLEN; } } /* Default to always perform DRIZCORR step */ asn->dthcorr = PERFORM; if (asn->debug) { sprintf (MsgText, "GetAsnTable: CRCORR = %d, RPTCORR = %d", asn->crcorr,asn->rptcorr); trlmessage (MsgText); } /* Sort through the list figuring out which are input vs. output ** files, and see if any input files are missing. */ /* Initialize local variables */ numsp = 0; posid = 0; prodid = 0; proddth = False; defid = 1; /* Find out how many products/sub-products are in the association ** and determine the posid for each member. */ for (row = 0; row < nrows; row++) { memtype[0] = '\0'; memsubtype[0] = '\0'; /* As long as this is not the final product, ** count number of members in each product/sub-product...*/ if (strstr(exp[row].type,"prod-dth") != NULL) { exp[row].posid = 0; posid = 0; /* If we have a dither product listed, we want to eventually ** perform dither combining step... */ prodid++; proddth = True; /* We always want to produce a product, but if ** not set to PERFORM, then create an empty product... */ if (asn->dthcorr == OMIT) asn->dthcorr = DUMMY; } else { strcpy(memtype,exp[row].type); /* Let's start by breaking up the MEMTYPE string */ word = strtok(memtype,"-"); strcpy(memsubtype,word); /* The end of this second part of MEMTYPE has the POSID */ word = strtok(NULL,"\n"); /* If the last character of the memtype is a number or letter, ** convert to an integer value... */ if (streq_ic(word,"crj") || streq_ic(word,"rpt") || streq_ic(word,"crc") ) { posid = 1; } else { if (exp[row].prsnt || streq_ic(memsubtype,"prod")) { if (isalnum(word[poslen])) { /* Interpret the POSID from the second part ** of MEMTYPE */ posid=(int)strtol(&word[poslen],(char **)NULL,10); } else { /* Otherwise, assume it is a different pointing ** and assign an incremented position ID. After ** all, it is NOT a CR-SPLIT or RPT-OBS exposure.*/ posid = defid; defid++; } } } /* Keep track of how many sub-products there are based on ** POSID from MEMTYPE values */ if (posid > numsp) { if ((exp[row].prsnt && (strstr(memtype,"exp") != NULL)) || strstr(memtype,"prod") != NULL) { numsp++; } } exp[row].posid = posid; } if (asn->debug) { sprintf (MsgText, "GetAsnTable: Posid = %d for row %d",posid, row); trlmessage (MsgText); } /* If the member is missing, give a warning */ /* This implies that MEMPRSNT must be set to YES for EXP_* ** This is not fatal for WF3. Simply decrement tmembers. */ if (!exp[row].prsnt && strncmp(exp[row].type, "prod-",5) != 0) { sprintf (MsgText, "Member \"%s\" is not present", exp[row].memname); trlwarn (MsgText); asn->numasn--; /* Now flag row as being absent so it doesn't get passed ** along for further processing... */ exp[row].posid = MEMABSENT; } } if (asn->debug) { sprintf (MsgText, "GetAsnTable: NUMSP = %d, PRODID = %d",numsp, prodid); trlmessage (MsgText); } /* Check for existence of enough data to process */ if (asn->numasn < 1) { trlerror ("No data available for given assoc. table"); freeAsnInfo (asn); return (status = ERROR_RETURN); } /* Record the number of products found in association */ if (proddth) { asn->numprod = prodid; } else { /* If there are no PROD-DTH entries in ASN table, set ** numprod to 1 */ asn->numprod = prodid + 1; } /* Determine what elements should be processed based on ** initial input, either FULL or PARTIAL processing. */ procprod = 0; if (asn->process != FULL) { for (row=0; row < nrows; row++){ /* Look for entry with same name as input */ if (streq_ic(exp[row].memname, asn->rootname)) { /* We only want to process this product */ procprod = exp[row].posid; numsp = 1; } } } /* Allocate space to count number of exposures per sub-product ** with spmems[0] being reserved for final output product ** since POSID starts indexing at 1. */ spmems = (int *)calloc(numsp+1,sizeof(int)); expmem = (int *)calloc(numsp+1,sizeof(int)); /* Initialize arrays */ for (i=0; i <= numsp; i++) { spmems[i] = 0; expmem[i] = 0; } /* For each sub-product, ** identify each EXP that belongs to that posid and ** is present to be processed. */ for (row=0; row < nrows; row++) { if (strstr(exp[row].type, "exp-") && exp[row].posid > MEMABSENT) { if ((asn->process != FULL && exp[row].posid == procprod) || asn->process == FULL) { spmems[exp[row].posid]++; /* Exposure IDs will start at 1 to be consistent ** with POSID numbering. Initialize here, count later. */ expmem[exp[row].posid] = 1; } } } /* Allocate slots for all members in ASN info structure */ if (allocAsnInfo (asn, numsp, spmems)) { return (status = TABLE_ERROR); } asn->product[prodid].prodid = prodid; /* Reset prodid for filling ASN table */ prodid = 0; /* Copy summary information about ASN relationships to ASN structure. */ maxspmems = 0; asn->numsp = numsp; for (i=0; i <= numsp; i++) { asn->spmems[i] = spmems[i]; if (spmems[i] > maxspmems) maxspmems = spmems[i]; } /* If there aren't any sub-products with more than 1 member, then ** omit crcorr/rptcorr processing */ if ((maxspmems < 2) && asn->crcorr == PERFORM) { sprintf (MsgText, "No sub-product with more than 1 member; CRCORR will be skipped"); trlwarn (MsgText); asn->crcorr = DUMMY; } else if ((maxspmems < 2) && asn->rptcorr == PERFORM) { sprintf (MsgText, "No sub-product with more than 1 member; RPTCORR will be skipped"); trlwarn (MsgText); asn->rptcorr = DUMMY; } /* Copy information read-in into ASN structure now... */ for (row = 0; row < nrows; row++) { if (exp[row].posid != MEMABSENT) { if ((asn->process != FULL && exp[row].posid == procprod) || asn->process == FULL) { posid = exp[row].posid; /* Is this row the final product entry? */ if (strstr(exp[row].type, "prod-dth") != NULL) { strcpy (asn->product[prodid].name, exp[row].memname); strcpy (asn->product[prodid].mtype, exp[row].type); asn->product[prodid].prsnt = exp[row].prsnt; asn->product[prodid].numsp = numsp; asn->product[prodid].asnrow = row+1; /* Create full file name for this image */ if (MkName (exp[row].memname, "_raw", "_drz", "", asn->product[prodid].prodname, SZ_LINE)){ strcpy(asn->product[prodid].prodname, exp[row].memname); strcat (asn->product[prodid].prodname, "_drz.fits"); } /* Create full file name for this CTE image */ if (MkName (exp[row].memname, "_rac_tmp", "_drc", "", asn->product[prodid].prodname_cte, SZ_LINE)){ strcpy(asn->product[prodid].prodname_cte, exp[row].memname); strcat (asn->product[prodid].prodname_cte, "_drc.fits"); } /* Or, is this row an input exposure? */ } else if (strstr(exp[row].type, "exp-") != NULL) { if (exp[row].posid > MEMABSENT) { /* Internal counter for which exposure we want for ** a position */ expid = expmem[posid]; strcpy(asn->product[prodid].subprod[posid].exp[expid].name, exp[row].memname); strcpy(asn->product[prodid].subprod[posid].exp[expid].mtype, exp[row].type); asn->product[prodid].subprod[posid].exp[expid].prsnt = exp[row].prsnt; asn->product[prodid].subprod[posid].exp[expid].asnrow= row+1; /* Create full file name for this image */ if (MkName (exp[row].memname, "_raw", "_raw", "", asn->product[prodid].subprod[posid].exp[expid].expname, SZ_LINE)) { strcpy(asn->product[prodid].subprod[posid].exp[expid].expname, exp[row].memname); strcat(asn->product[prodid].subprod[posid].exp[expid].expname, "_raw.fits"); } /* Fill-in sub-product information for EXP-DTH ** exposures which don't create sub-products */ if (strstr(exp[row].type, "exp-dth") != NULL) { if (!MkName (exp[row].memname, "_raw", "_flt", "", asn->product[prodid].subprod[posid].spname, SZ_LINE) ) { strcpy(asn->product[prodid].subprod[posid].name, exp[row].memname); strcpy(asn->product[prodid].subprod[posid].mtype, exp[row].type); asn->product[prodid].subprod[posid].posid = exp[row].posid; } } /* Increment that counter for next exposure's id ** for this posid */ expmem[posid]++; } /* If neither, it must be a sub-product */ } else { if (spmems[posid] > 0) { strcpy(asn->product[prodid].subprod[posid].name, exp[row].memname); strcpy(asn->product[prodid].subprod[posid].mtype, exp[row].type); asn->product[prodid].subprod[posid].prsnt = exp[row].prsnt; asn->product[prodid].subprod[posid].asnrow = row+1; /* Create full file name for this image for ** DTHCORR input */ spname_ext[0] = '\0'; spname_ext_cte[0] = '\0'; if (asn->crcorr || asn->rptcorr) { strcpy (spname_ext, "_crj"); strcpy (spname_ext_cte,"_crc"); } else { strcpy (spname_ext, "_sfl"); strcpy (spname_ext_cte, "_sfl"); } if (MkName (exp[row].memname, "_raw", spname_ext, "", asn->product[prodid].subprod[posid].spname, SZ_LINE)) { strcpy(asn->product[prodid].subprod[posid].spname, exp[row].memname); strcat(asn->product[prodid].subprod[posid].spname, spname_ext); strcat(asn->product[prodid].subprod[posid].spname, ".fits"); } if (MkName (exp[row].memname, "_raw", spname_ext_cte, "", asn->product[prodid].subprod[posid].spname_cte, SZ_LINE)) { strcpy(asn->product[prodid].subprod[posid].spname_cte, exp[row].memname); strcat(asn->product[prodid].subprod[posid].spname_cte, spname_ext_cte); strcat(asn->product[prodid].subprod[posid].spname_cte, ".fits"); } asn->product[prodid].subprod[posid].numexp = spmems[posid]; asn->product[prodid].subprod[posid].posid = posid; } } } } /* Process only those exposures where MEMPRSNT == YES */ } /* Close the ASN table. We are done reading it in. */ c_tbtclo (tp); /* Clean up memory usage as well. */ free (spmems); free (expmem); free (exp); if (asn->debug) { trlmessage ("GetAsnTable: Info from ASN read into memory."); } /* Successful return */ return (status); }
int SetInput (AsnInfo *asn) { /* Arguments: ** asn io: Association info structure */ extern int status; /* Local Variables */ char filename[SZ_FNAME+1]; int exist; /* EXISTS_YES or EXISTS_NO */ int in_dot; char linput[SZ_FNAME+1]; /* Lower case version of input */ int incase; /* What kind of input do we have? */ int DoesFileExist (char *); char *lowcase (char *, char *); int GetAsnName (char *, char *); void FindAsnRoot (char *, char *); /* Initialize internal variables here... */ filename[0] = '\0'; /* convert input to lowercase for use only in looking for extensions */ lowcase (linput, asn->input); /* Determine what kind of input: root only, ** root + suffix, or ** root + suffix + extension ** We will look for '.fit' or '.fits' extensions. */ /* First, let's complete the input filename with a FITS extension.*/ if (strstr(linput, ".fit") == NULL) { strcpy (filename, asn->input); strcat (filename, ".fits"); } else { strcpy (filename, asn->input); strcat (filename, "\0"); } /* Initialize local variable */ incase = 0; /* Now, we find out what kind of input name was provided... */ if (strstr(linput, "_asn") != NULL){ incase = 0; } else if (strstr(linput, "_raw") != NULL ) { incase = 1; } else if (!IsProduct (linput)) { /* Not a sub-product/intermediate product... */ incase = 2; } else { /* treat as if it was only a rootname (plus '.fits') */ incase = 3; } if (asn->debug) { sprintf (MsgText, "GetAsnTable: incase = %d",incase); trlmessage (MsgText); } /* Given this full filename for a file which exists, ** copy out just the rootname. */ FindAsnRoot(filename, asn->rootname); /* Can we find the file as it is input? */ exist = DoesFileExist(filename); /* Treat filename according to what was input... */ switch (incase) { case 0: /* We have an ASN file explicitly specified */ if (exist == EXISTS_YES) { /* Found an ASN file: Set values in ASN structure */ asn->process = FULL; strcpy(asn->asn_table, filename); strcpy(asn->filename, filename); if (asn->verbose) { trlmessage ("Processing FULL ASN table..."); } } else { /* Couldn't find specified ASN file... */ sprintf (MsgText, "File %s not found for processing", filename); trlerror (MsgText); return (status = OPEN_FAILED); } break; case 1: /* We have a RAW file explicitly specified */ if (exist == EXISTS_YES) { /* Found a RAW file: Set values in ASN structure */ strcpy (asn->filename, filename); strcpy (asn->asn_table, filename); strcat (asn->asn_table, "\0"); if (asn->verbose) { sprintf (MsgText, "Processing SINGLE image %s...", asn->filename); trlmessage (MsgText); } asn->process = SINGLE; } else { /* Couldn't find specified RAW file... */ sprintf (MsgText,"File %s not found for processing", filename); trlerror (MsgText); return (status = OPEN_FAILED); } break; case 2: /* We have a sub-product/intermediate file specified ** for re-processing. They should really just run the ** stand-alone tasks separately by hand, but... */ if (exist == EXISTS_YES) { strcpy (asn->filename, filename); /* Look for ASN_TAB in file's header, and copy to ** ASN->asn_table if it is found. */ if (!GetAsnName (filename, asn->asn_table) ) { /* No ASN table listed, process as a ** SINGLE exposure */ asn->process = SINGLE; if (asn->verbose) { trlmessage ("Re-Processing a SINGLE image from ASN table..."); } } else { /* ASN table given in file, PARTIALLY process ** table */ asn->process = PARTIAL; if (asn->verbose) { trlmessage ("Re-Processing PART of ASN table..."); } } } else { /* Couldn't find specified file... */ sprintf (MsgText,"File %s not found for re-processing", filename); trlerror (MsgText); return (status = OPEN_FAILED); } break; case 3: /* We only have a rootname (with .fits extension) ** specified */ default: if (exist == EXISTS_YES) { strcpy (asn->filename, filename); /* Look for ASN_TAB in file's header, and copy to ** ASN->asn_table if it is found. */ if (!GetAsnName (filename, asn->asn_table)) { /* No ASN table listed, process as a SINGLE ** exposure */ asn->process = SINGLE; if (asn->verbose) { trlmessage ("Processing a SINGLE image from ASN table..."); } } else { /* ASN table given in file, PARTIALLY process ** table */ asn->process = PARTIAL; if (asn->verbose) { trlmessage ("Processing PART of ASN table..."); } } } else { /* Let's start fresh, shall we? At this point we only ** have as rootname and (maybe) a .fits extension... in_dot = strcspn (filename, ".fit"); */ in_dot = strlen(filename) - strlen(strstr (filename, ".fit")); if (asn->debug){ sprintf (MsgText, "For file %s, in_dot = %d", filename, in_dot); trlmessage (MsgText); } /* Truncate extension off of filename */ filename[in_dot] = '\0'; /* Create full ASN table name from input rootname */ strcat (filename, "_asn.fits"); exist = DoesFileExist (filename); if (exist == EXISTS_YES) { strcat (filename, "\0"); /* If a name was specified, the file must exist. */ strcpy (asn->asn_table, filename); if (asn->verbose) { trlmessage ("Found and processing FULL ASN table..."); } asn->process = FULL; } else { /* Couldn't find ASN file, so ** trim off suffix previously tested. */ in_dot = strlen (filename) - strlen (strstr(filename, "_asn")) ; filename[in_dot] = '\0'; /* ... and look for RAW file */ strcat (filename, "_raw.fits"); exist = DoesFileExist (filename); if (exist == EXISTS_YES) { /* Found a RAW file; ** Set values in ASN structure */ strcat (filename, "\0"); strcpy (asn->asn_table, filename); if (asn->verbose) { trlmessage ("Processing a SINGLE image from ASN table..."); } asn->process = SINGLE; } else { /* Is INPUT the rootname of a product which ** hasn't been created yet? */ /* Extract just the rootname plus last character ** of rootname (which may be the subproduct ID*/ in_dot = strlen (filename) - strlen (strstr (filename, "_raw")); filename[in_dot -1] = '\0'; /* Replace last character of filename with ** 0_asn.fits */ strcat (filename, "0_asn.fits"); exist = DoesFileExist (filename); if (exist == EXISTS_YES) { strcpy (asn->asn_table, filename); if (asn->verbose) { trlmessage ("PARTIAL processing of ASN table..."); } asn->process = PARTIAL; } else { /* We can't find a matching file or ASN ** table to process */ sprintf (MsgText, "File %s not found for processing", filename); trlerror (MsgText); return (status = OPEN_FAILED); } } } } /* End of Exists ELSE statement for this case */ break; /* End of Case 3 and DEFAULT case */ } /* End of switch statement */ if (asn->debug) { trlmessage ("SetInput: Determined what ASN table to process and how."); } return (status); }
/*! * \param word Word to be saved * \param pattern Capitalization pattern * \param prestrip No. chars stripped from front * \param preadd No. chars added to front of root * \param sufstrip No. chars stripped from back * \param sufadd No. chars added to back of root * \param firstdent First dent for root * \param pfxent Pfx-flag entry for word * \param sufent Sfx-flag entry for word * \param savearea Room to save words * \param nsaved Number saved so far (updated) */ void ISpellChecker::save_root_cap (ichar_t *word, ichar_t *pattern, int prestrip, int preadd, int sufstrip, int sufadd, struct dent *firstdent, struct flagent *pfxent, struct flagent *sufent, ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN], int * nsaved) { #ifndef NO_CAPITALIZATION_SUPPORT register struct dent * dent; #endif /* NO_CAPITALIZATION_SUPPORT */ int firstisupper; ichar_t newword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4]; #ifndef NO_CAPITALIZATION_SUPPORT register ichar_t * p; int len; int i; int limit; #endif /* NO_CAPITALIZATION_SUPPORT */ if (*nsaved >= MAX_CAPS) return; icharcpy (newword, word); firstisupper = myupper (pattern[0]); #ifdef NO_CAPITALIZATION_SUPPORT /* ** Apply the old, simple-minded capitalization rules. */ if (firstisupper) { if (myupper (pattern[1])) upcase (newword); else { lowcase (newword); newword[0] = mytoupper (newword[0]); } } else lowcase (newword); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; #else /* NO_CAPITALIZATION_SUPPORT */ #define flagsareok(dent) \ ((pfxent == NULL \ || TSTMASKBIT (dent->mask, pfxent->flagbit)) \ && (sufent == NULL \ || TSTMASKBIT (dent->mask, sufent->flagbit))) dent = firstdent; if ((dent->flagfield & (CAPTYPEMASK | MOREVARIANTS)) == ALLCAPS) { upcase (newword); /* Uppercase required */ icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } for (p = pattern; *p; p++) { if (mylower (*p)) break; } if (*p == 0) { upcase (newword); /* Pattern was all caps */ icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } for (p = pattern + 1; *p; p++) { if (myupper (*p)) break; } if (*p == 0) { /* ** The pattern was all-lower or capitalized. If that's ** legal, insert only that version. */ if (firstisupper) { if (captype (dent->flagfield) == CAPITALIZED || captype (dent->flagfield) == ANYCASE) { lowcase (newword); newword[0] = mytoupper (newword[0]); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } else { if (captype (dent->flagfield) == ANYCASE) { lowcase (newword); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } while (dent->flagfield & MOREVARIANTS) { dent = dent->next; if (captype (dent->flagfield) == FOLLOWCASE || !flagsareok (dent)) continue; if (firstisupper) { if (captype (dent->flagfield) == CAPITALIZED) { lowcase (newword); newword[0] = mytoupper (newword[0]); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } else { if (captype (dent->flagfield) == ANYCASE) { lowcase (newword); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } } } /* ** Either the sample had complex capitalization, or the simple ** capitalizations (all-lower or capitalized) are illegal. ** Insert all legal capitalizations, including those that are ** all-lower or capitalized. If the prototype is capitalized, ** capitalized all-lower samples. Watch out for affixes. */ dent = firstdent; p = strtosichar (dent->word, 1); len = icharlen (p); if (dent->flagfield & MOREVARIANTS) dent = dent->next; /* Skip place-holder entry */ for ( ; ; ) { if (flagsareok (dent)) { if (captype (dent->flagfield) != FOLLOWCASE) { lowcase (newword); if (firstisupper || captype (dent->flagfield) == CAPITALIZED) newword[0] = mytoupper (newword[0]); icharcpy (savearea[*nsaved], newword); (*nsaved)++; if (*nsaved >= MAX_CAPS) return; } else { /* Followcase is the tough one. */ p = strtosichar (dent->word, 1); memmove ( reinterpret_cast<char *>(newword + preadd), reinterpret_cast<char *>(p + prestrip), (len - prestrip - sufstrip) * sizeof (ichar_t)); if (myupper (p[prestrip])) { for (i = 0; i < preadd; i++) newword[i] = mytoupper (newword[i]); } else { for (i = 0; i < preadd; i++) newword[i] = mytolower (newword[i]); } limit = len + preadd + sufadd - prestrip - sufstrip; i = len + preadd - prestrip - sufstrip; p += len - sufstrip - 1; if (myupper (*p)) { for (p = newword + i; i < limit; i++, p++) *p = mytoupper (*p); } else { for (p = newword + i; i < limit; i++, p++) *p = mytolower (*p); } icharcpy (savearea[*nsaved], newword); (*nsaved)++; if (*nsaved >= MAX_CAPS) return; } } if ((dent->flagfield & MOREVARIANTS) == 0) break; /* End of the line */ dent = dent->next; } return; #endif /* NO_CAPITALIZATION_SUPPORT */ }
int main( ) { /* upcase() && lowcase() */ { char foo[64]; sprintf(foo, "foobar"); printf("Before case-conversion: '%s'\n", foo); upcase(foo); printf("After upcase: '%s'\n", foo); lowcase(foo); printf("After lowcase: '%s'\n", foo); sprintf(foo, "unicode öä ¹²³"); printf("Before case-conversion: '%s'\n", foo); upcase(foo); printf("After upcase: '%s'\n", foo); lowcase(foo); printf("After lowcase: '%s'\n", foo); } /* randname() */ { char foo[64]; int i, j; #define LEN 8 for (i = 0; i < 2; i++) { switch (i) { case 0: sprintf(foo, "user"); break; case 1: sprintf(foo, "username"); break; } printf("randname: starting with '%s' (len = %d)\n", foo, LEN); for (j = 0; j < LEN * 2; j++) { randname(foo, LEN, '#'); printf("round %02d: '%s'\n", j, foo); } } printf("Generating random stuff:\n"); for (i = 0; i < 4; i++) { foo[0] = '\0'; randname(foo, LEN, '#'); printf("round %d: '%s'\n", i, foo); } } /* pos() && lastpos() */ { char foo[64]; sprintf(foo, "There is no greater power in the universe than " "the need for freedom."); printf("String: '%s'\n", foo); printf("First occurance of 'o' is at %d\n", pos(foo, 'o')); printf("Last occurance of 'o' is at %d\n", lastpos(foo, 'o')); } /* nextword() && lastword() */ { char foo[64]; char *ptr; sprintf(foo, "There is no greater power in the universe than " "the need for freedom."); printf("Words (after the first one):\n"); ptr = nextword(foo); while (ptr != NULL) { printf("'%s'\n", ptr); ptr = nextword(ptr); } printf("Last word: '%s'\n", lastword(foo)); } /* get_short_localtime() && get_timestamp() */ { time_t t; t = rand(); printf("Some timestamps:\n"); printf("Localtime: '%s'\n", get_short_localtime()); printf("Long: '%s'\n", get_timestamp(NULL, TIMESTAMP_LONG)); printf("Short: '%s'\n", get_timestamp(NULL, TIMESTAMP_SHORT)); printf("Abritary: '%s'\n", get_timestamp(&t, TIMESTAMP_LONG)); } return 0; }
static inline bool isEqual(char c1, char c2) { return (lowcase(c1) == lowcase(c2) ? true : false); }
int match(char *s) { d("match",token,s); lowcase(token); if (strcmp(s,token)) return 0; gettoken(); return 1; }