/*
- * $Id: headers.c,v 1.9.10.1.2.2 2005-09-27 10:40:41 didg Exp $
+ * $Id: headers.c,v 1.9.10.1.2.3 2008-08-14 19:58:27 didg Exp $
*
* Copyright (c) 1990,1994 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
#include <sys/param.h>
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#include <netatalk/at.h>
#include <atalk/logger.h>
int ch_title( struct papfile *, struct papfile * );
int ch_for( struct papfile *, struct papfile * );
-
-int ch_for( in, out )
- struct papfile *in, *out _U_;
+static char *get_text(char *start, int linelength)
{
- char *start, *stop, *p, *q, c;
- int linelength, crlflength;
+ char *p, *q;
+ char *t, *ret;
+ char *stop;
+
+ /* 1023 is arbitrary 255 max for comment but some may be escape \xxx and space and keyword */
- switch ( markline( in, &start, &linelength, &crlflength )) {
- case 0 :
- return( 0 );
+ if (linelength > 1023)
+ return NULL;
- case -1 :
- return( CH_MORE );
- }
+ t = ret = calloc(1, linelength +1);
+
+ if (!ret)
+ return NULL;
stop = start + linelength;
for ( p = start; p < stop; p++ ) {
if ( *p == ':' ) {
+ p++;
break;
}
}
-
+
for ( ; p < stop; p++ ) {
- if ( *p == '(' ) {
+ if (*p != ' ' && *p != '\t') {
break;
}
}
- for ( q = p; q < stop; q++ ) {
- if ( *q == ')' ) {
- break;
+ if ( p < stop && *p == '(' ) {
+ int count;
+ /* start with ( then it's a <text> */
+ p++;
+ for ( q = p, count = 1; q < stop; q++, t++ ) {
+ if (*q == '(') {
+ count++;
+ }
+ else if ( *q == ')' ) {
+ count--;
+ if (!count) {
+ break;
+ }
+ }
+ *t = *q;
+ }
+ }
+ else {
+ /* it's a textline */
+ for ( q = p; q < stop; q++, t++ ) {
+ *t = *q;
}
}
+ return ret;
+}
- if ( q < stop && p < stop ) {
- p++;
- c = *q;
- *q = '\0';
- lp_for ( p );
- *q = c;
+int ch_for( in, out )
+ struct papfile *in, *out _U_;
+{
+ char *start, *cmt;
+ int linelength, crlflength;
+
+ switch ( markline( in, &start, &linelength, &crlflength )) {
+ case 0 :
+ return( 0 );
+
+ case -1 :
+ return( CH_MORE );
+ }
+
+ cmt = get_text(start, linelength);
+
+ if ( cmt ) {
+ lp_for ( cmt );
+ free(cmt);
}
in->pf_state |= PF_TRANSLATE;
int ch_title( in, out )
struct papfile *in, *out _U_;
{
- char *start, *stop, *p, *q, c;
+ char *start, *cmt;
int linelength, crlflength;
switch ( markline( in, &start, &linelength, &crlflength )) {
LOG(log_debug, logtype_papd, "Parsing %%Title");
#endif
- stop = start + linelength;
- for ( p = start; p < stop; p++ ) {
- if ( *p == ':' ) {
- break;
- }
- }
-
- for ( ; p < stop; p++ ) {
- if ( *p == '(' ) {
- break;
- }
- }
-
- for ( q = p; q < stop; q++ ) {
- if ( *q == ')' ) {
- break;
- }
- }
+ cmt = get_text(start, linelength);
- if ( q < stop && p < stop ) {
- p++;
- c = *q;
- *q = '\0';
- lp_job( p );
- *q = c;
+ if ( cmt ) {
+ lp_job( cmt );
+ free(cmt);
}
in->pf_state |= PF_TRANSLATE;
int ch_creator( in, out )
struct papfile *in, *out _U_;
{
- char *start, *stop, *p, *q, c;
+ char *start, *cmt;
int linelength, crlflength;
switch ( markline( in, &start, &linelength, &crlflength )) {
return( CH_MORE );
}
- stop = start + linelength;
- for ( p = start; p < stop; p++ ) {
- if ( *p == ':' ) {
- break;
- }
- }
-
- for ( ; p < stop; p++ ) {
- if ( *p == '(' ) {
- break;
- }
- }
-
- for ( q = p; q < stop; q++ ) {
- if ( *q == ')' ) {
- break;
- }
- }
+ cmt = get_text(start, linelength);
- if ( q < stop && p < stop ) {
- p++;
- c = *q;
- *q = '\0';
- in->origin = guess_creator ( p );
+ if ( cmt ) {
+ in->origin = guess_creator ( cmt );
+ free(cmt);
lp_origin(in->origin);
- *q = c;
}
in->pf_state |= PF_TRANSLATE;