Go to the documentation of this file.00001 #include "copyright.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include "prototypes.h"
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 char *ath_fname(const char *path, const char *basename,
00042 const char *levstr, const char *domstr,
00043 const int dlen, const int idump,
00044 const char *id, const char *ext)
00045 {
00046 char fmt[80];
00047 size_t size,slen=0;
00048 char *cp, *fname;
00049
00050
00051 size = 2 + strlen(basename) + strlen(ext);
00052 if(path != NULL) size += 1 + strlen(path);
00053 if(levstr != NULL) size += 1 + strlen(levstr);
00054 if(domstr != NULL) size += 1 + strlen(domstr);
00055 if(dlen > 0) size += (dlen > 10 ? dlen : 10) + 1;
00056 if(id != NULL) size += 1 + strlen(id);
00057
00058 if((fname = (char*)malloc(size*sizeof(char))) == NULL){
00059 printf("[ath_fname]: malloc returned a NULL pointer\n");
00060 return NULL;
00061 }
00062
00063
00064
00065 cp = fname;
00066 if(path != NULL){
00067 slen = strlen(path);
00068 strcpy(cp, path);
00069 cp = &(cp[slen]);
00070
00071
00072 if(cp[-1] != '/'){
00073 cp[0] = '/';
00074 cp[1] = '\0';
00075 cp = &(cp[1]);
00076 }
00077 }
00078
00079
00080
00081 slen = strlen(basename);
00082 strcpy(cp,basename);
00083 cp = &(cp[slen]);
00084
00085
00086
00087 if (levstr != NULL){
00088 slen = strlen(levstr);
00089 cp[0] = '-';
00090 cp[1] = '\0';
00091 cp = &(cp[1]);
00092 strcpy(cp,levstr);
00093 cp = &(cp[slen]);
00094 }
00095
00096
00097
00098 if (domstr != NULL){
00099 slen = strlen(domstr);
00100 cp[0] = '-';
00101 cp[1] = '\0';
00102 cp = &(cp[1]);
00103 strcpy(cp,domstr);
00104 cp = &(cp[slen]);
00105 }
00106
00107
00108
00109
00110 if(id){
00111 if(dlen > 0 && idump >= 0){
00112 sprintf(fmt,".%%0%dd.%%s.%%s",dlen);
00113 sprintf(cp,fmt,idump,id,ext);
00114 }
00115 else sprintf(cp,".%s.%s",id,ext);
00116 }
00117
00118 else{
00119 if(dlen > 0 && idump >= 0){
00120 sprintf(fmt,".%%0%dd.%%s",dlen);
00121 sprintf(cp,fmt,idump,ext);
00122 }
00123 else sprintf(cp,".%s",ext);
00124 }
00125
00126 return fname;
00127 }