int DefaultExtn (char *input, int maxch) { extern int status; int dotlocn; /* location of '.' in input name */ dotlocn = FindExtn (input); if (dotlocn < 0) { if (strcatN (input, FITS_EXTN, maxch)) return (status); } return (status); }
int MkOutName (char *input, char **isuffix, char **osuffix, int nsuffix, char *output, int maxch) { /* arguments: char *input i: name of input FITS file char *isuffix[] i: suffixes expected for input, e.g. "_raw" char *osuffix[] i: suffixes to append for output, e.g. "_flt" int nsuffix i: length of isuffix and osuffix arrays char *output io: name of output FITS file int maxch i: maximum size of output */ extern int status; char *extn; /* extension on input (or default) */ int is_len; /* length of current isuffix */ int tr_len; /* length of truncated input name */ int i; /* loop index */ int dotlocn; /* location of '.' in input name */ if (output[0] == '\0') { extn = calloc (1 + strlen(input) + strlen(FITS_EXTN), sizeof(char)); if (extn == NULL) return (status = OUT_OF_MEMORY); /* Find the extension (if any) on the input name. */ dotlocn = FindExtn (input); if (strcatN (output, input, maxch)) { free (extn); return (status); } if (dotlocn >= 0) { strcpy (extn, &input[dotlocn]); /* save extension from input */ output[dotlocn] = '\0'; /* truncate at '.' */ } else { strcpy (extn, FITS_EXTN); /* default extension */ } /* If the input name ends in one of the expected suffixes, chop it off of the output name before appending the output suffix and extension. */ for (i = 0; i < nsuffix; i++) { is_len = strlen (isuffix[i]); tr_len = strlen (output); /* length of truncated name */ if (tr_len >= is_len) { if (strcmp (output+tr_len-is_len, isuffix[i]) == 0) { output[tr_len-is_len] = '\0'; if (strcatN (output, osuffix[i], maxch)) { free (extn); return (status); } break; } } } /* Append first output suffix if none of the input suffixes was found. */ if (i >= nsuffix) { if (strcatN (output, osuffix[0], maxch)) { free (extn); return (status); } } if (strcatN (output, extn, maxch)) { free (extn); return (status); } free (extn); } else { /* An output name was specified. Check that it includes an extension, and if not, append the default extension. */ dotlocn = FindExtn (output); if (dotlocn < 0) { if (strcatN (output, FITS_EXTN, maxch)) return (status); } /* else the output name is OK as is */ } return (status); }
int main() { init(); FILE *fp = fopen("home.css","r"); if(fp == NULL) { printf("%s","打开文件失败"); return 1; } char buf[10000]; char value[10000]; char keys[100000]; int line_number = 0; int desciption_type = END_DESCIRP; bool desciption_begin = false; int bracket_type = END_DESCIRP; int latst_bracket_type = RIGHT_BRACKET; int count = 0; while(fgets(buf,sizeof(buf),fp)!=NULL) { line_number++; bool has_key = false; bool has_value = false; str_trim(buf); if(strlen(buf) ==0) { continue; } desciption_type = is_desciption(buf); if(desciption_type == BEGIN_DESCIRP) { desciption_begin = true; continue; } else if(desciption_type == END_DESCIRP ) { desciption_begin = false; continue; } else { if(desciption_begin) { continue; } } bracket_type = deal_bracket(buf); if(bracket_type == LEFT_BRACKET) { if(strlen(buf) <= 1) { latst_bracket_type = LEFT_BRACKET; continue; } else { strcatN(keys, buf, strlen(buf)-1); } } else if(bracket_type == RIGHT_BRACKET) { count++; deal_keys_value(keys, value,count, line_number); memset(keys,0,10000); memset(value,0,10000); } else { if(latst_bracket_type == RIGHT_BRACKET) { strcatN(keys, buf, strlen(buf)); } else if(latst_bracket_type == LEFT_BRACKET) { strcatN(value, buf, strlen(buf)); } } if(bracket_type != NO_BRACKET) { latst_bracket_type = bracket_type; } } sort_value(); print_css(); printf("_______________%s_______________","处理完毕"); system("pause"); return 0; }