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 #include "mark.hpp"
00027 #include "uti.h"
00028 #include "wrkbuff.h"
00029
00030
00031
00032
00033 PRIVATE const CHAR * strjumpstart( const CHAR * s )
00034 {
00035 while ((*s==' ')||(*s=='\t')) s++;
00036 if (*s=='"') s++;
00037 return s;
00038 }
00039
00040
00041
00042
00043
00044 PRIVATE const CHAR * strjumpend( const CHAR * s )
00045 {
00046 const CHAR *ss=s+strlen(s);
00047 while (ss>s) {
00048 CHAR ch=*(--ss);
00049 if ((ch==' ')||(ch=='\t')) continue;
00050 if (ch!='\"') ss++;
00051 break;
00052 }
00053 return ss;
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 BOOL Mark1DList::foutput( FILE *f, BOOL indent, BOOL rangespan, BOOL ms )
00084
00085 {
00086 BOOL ret=TRUE;
00087
00088 for (Lix p=first(); p!=0; p=next(p)) {
00089 if (indent) ret=ret&&EOF!=fprintf(f," ");
00090 if (ms) ret=ret&&EOF!=fprintf(f,"%g",(double)getpos_ms(p));
00091 else ret=ret&&EOF!=fprintf(f,"%li",(long)pos(p));
00092 if (span(p)!=0) {
00093 if (rangespan) {
00094 if (ms) ret=ret&&EOF!=fprintf(f,",%g",(double)(getpos_ms(p)+getspan_ms(p)));
00095 else ret=ret&&EOF!=fprintf(f,",%li",(long)(pos(p)+span(p)));
00096 }
00097 else {
00098 if (ms) ret=ret&&EOF!=fprintf(f,"/%g",(double)getspan_ms(p));
00099 else ret=ret&&EOF!=fprintf(f,"/%li",(long)span(p));
00100 }
00101 }
00102 if (label(p)!="") {
00103 const CHAR *s=label(p);
00104 BOOL quote=(s!=strjumpstart(s))||(s+strlen(s)!=strjumpend(s));
00105 ret=ret&&EOF!=fprintf(f," : %s%s%s",
00106 quote ? "\"" : "",s, quote ? "\"" : "");
00107 }
00108 ret=ret&&EOF!=fprintf(f,"\n");
00109 }
00110 return ret;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 VOID Mark1DList::finput( FILE* f, BOOL ms, const CHAR *fileName, LONG &line, CHAR*buf, INT buflen, INT eofch )
00148
00149 {
00150 int tl;
00151
00152 while (xfgetln_filt(buf,buflen,f,TRUE,0,FALSE,&tl)) {
00153 line++;
00154 cdie_beep(tl,"Mark1DList: line to long in %s (%ld)", fileName, (long)line);
00155 CHAR *s=buf;
00156 while ((*s==' ')||(*s=='\t')) s++;
00157 if (*s=='\0') continue;
00158
00159 if (eofch && (*s==eofch)) return;
00160
00161 long int mpos, mspan=0;
00162 double mpos_ms, mspan_ms=0;
00163 int n;
00164 if (ms) n = str2d(s,&mpos_ms);
00165 else n = str2li(s,&mpos);
00166 cdie_beep(n<0,"Mark1DList: error reading marks from %s (%ld), invalid value (%s)",fileName,line,s);
00167 if (!n) n=strlen(s);
00168 s+=n; while ((*s==' ')||(*s=='\t')) s++;
00169 if ((*s==',')||(*s=='/')) {
00170 BOOL range=(*s==',');
00171 s++; while ((*s==' ')||(*s=='\t')) s++;
00172 if (ms) n = str2d(s,&mspan_ms);
00173 else n = str2li(s,&mspan);
00174 cdie_beep(n<0,"Mark1DList: error reading marks from %s (%ld), invalid span value (%s)",fileName,line,s+1);
00175 if (!n) n=strlen(s);
00176 if (range) {
00177 if (ms) mspan_ms=mspan_ms-mpos_ms;
00178 else mspan=mspan-mpos;
00179 }
00180 s+=n; while ((*s==' ')||(*s=='\t')) s++;
00181 if (*s==':') {
00182 s=(char*)strjumpstart(s+1);
00183 *(char*)strjumpend(s)='\0';
00184 if (ms) append_ms(mpos_ms,mspan_ms,s); else append(mpos,mspan,s);
00185 }
00186 else {
00187 cdie_beep(*s,"Mark1DList: error reading marks from %s (%ld), invalid info (%s)",fileName,line,s);
00188 if (ms) append_ms(mpos_ms,mspan_ms); else append(mpos,mspan);
00189 }
00190 }
00191 else if (*s==':') {
00192 s=(char*)strjumpstart(s+1);
00193 *(char*)strjumpend(s)='\0';
00194 if (ms) append_ms(mpos_ms,s); else append(mpos,s);
00195 }
00196 else {
00197 cdie_beep(*s,"Mark1DList: error reading marks from %s (%ld), invalid info (%s)",fileName,line,s);
00198 if (ms) append_ms(mpos_ms); else append(mpos);
00199 }
00200 }
00201
00202 cdie_beep(eofch,"Mark1DList: unspected EOF in %s (%ld)", fileName, line);
00203 }
00204
00205
00206
00207 VOID Mark1DList::finput( FILE* f, BOOL ms )
00208 {
00209 #define MAXLEN 4096
00210 WRKBUFF(MAXLEN);
00211 LONG line=0;
00212 finput(f,ms,"file",line,_wrkbuff,MAXLEN,0);
00213 WRKBUFF_FREE();
00214 #undef MAXLEN
00215 }
00216
00217