1 /* babel_ifiction_functions.c babel top-level operations for ifiction
\r
2 * (c) 2006 By L. Ross Raszewski
\r
4 * This code is freely usable for all purposes.
\r
6 * This work is licensed under the Creative Commons Attribution2.5 License.
\r
7 * To view a copy of this license, visit
\r
8 * http://creativecommons.org/licenses/by/2.5/ or send a letter to
\r
10 * 543 Howard Street, 5th Floor,
\r
11 * San Francisco, California, 94105, USA.
\r
13 * This file depends upon babel.c (for rv), babel.h, misc.c and ifiction.c
\r
22 #ifndef THREE_LETTER_EXTENSIONS
\r
23 #define IFICTION_EXT ".iFiction"
\r
25 #define IFICTION_EXT ".ifi"
\r
28 void *my_malloc(int, char *);
\r
30 struct IFiction_Info
\r
36 static void write_story_to_disk(struct XMLTag *xtg, void *ctx)
\r
40 char buffer[TREATY_MINIMUM_EXTENT];
\r
44 if (strcmp(xtg->tag,"story")==0)
\r
49 b=(char *)my_malloc(l,"XML buffer");
\r
50 memcpy(b,begin,l-1);
\r
52 j=ifiction_get_IFID(b,buffer,TREATY_MINIMUM_EXTENT);
\r
55 fprintf(stderr,"No IFID found for this story\n");
\r
59 ep=strtok(buffer,",");
\r
64 sprintf(buf2,"%s%s",ep,IFICTION_EXT);
\r
68 fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
\r
69 "<!-- Metadata extracted by Babel -->"
\r
70 "<ifindex version=\"1.0\" xmlns=\"http://babel.ifarchive.org/protocol/iFiction/\">\n"
\r
74 fputs("/<story>\n</ifindex>\n",f)==EOF
\r
77 fprintf(stderr,"Error writing to file %s\n",buf2);
\r
79 printf("Extracted %s\n",buf2);
\r
82 ep=strtok(NULL,",");
\r
89 void babel_ifiction_ifid(char *md)
\r
91 char output[TREATY_MINIMUM_EXTENT];
\r
94 i=ifiction_get_IFID(md,output,TREATY_MINIMUM_EXTENT);
\r
98 fprintf(stderr,"Error: No IFIDs found in iFiction file\n");
\r
101 ep=strtok(output,",");
\r
104 printf("IFID: %s\n",ep);
\r
105 ep=strtok(NULL,",");
\r
112 static void examine_tag(struct XMLTag *xtg, void *ctx)
\r
114 struct IFiction_Info *xti=(struct IFiction_Info *)ctx;
\r
116 if (strcmp("ifid",xtg->tag)==0 && strcmp(xti->ifid,"UNKNOWN")==0)
\r
118 memcpy(xti->ifid,xtg->begin,xtg->end-xtg->begin);
\r
119 xti->ifid[xtg->end-xtg->begin]=0;
\r
123 static void verify_eh(char *e, void *ctx)
\r
125 if (*((int *)ctx) < 0) return;
\r
126 if (*((int *)ctx) || strncmp(e,"Warning",7))
\r
128 fprintf(stderr, "%s\n",e);
\r
134 void babel_ifiction_fish(char *md)
\r
137 ifiction_parse(md,write_story_to_disk,NULL,verify_eh,&i);
\r
140 void deep_ifiction_verify(char *md, int f)
\r
142 struct IFiction_Info ii;
\r
146 strcpy(ii.ifid,"UNKNOWN");
\r
147 ifiction_parse(md,examine_tag,&ii,verify_eh,&i);
\r
148 if (f&& isok) printf("Verified %s\n",ii.ifid);
\r
150 void babel_ifiction_verify(char *md)
\r
152 deep_ifiction_verify(md,1);
\r
157 void babel_ifiction_lint(char *md)
\r
159 struct IFiction_Info ii;
\r
163 strcpy(ii.ifid,"UNKNOWN");
\r
164 ifiction_parse(md,examine_tag,&ii,verify_eh,&i);
\r
165 if (isok) printf("%s conforms to iFiction style guidelines\n",ii.ifid);
\r