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
00047 #include <stdio.h>
00048 #include <stdlib.h>
00049 #include <stdbool.h>
00050 #include <string.h>
00051 #include <stdarg.h>
00052 #include "qDecoder.h"
00053 #include "qInternal.h"
00054
00055 #define SSI_INCLUDE_START "<!--#include file=\""
00056 #define SSI_INCLUDE_END "\"-->"
00057
00075 bool qSedStr(Q_ENTRY *entry, const char *srcstr, FILE *fpout) {
00076 if (srcstr == NULL) return false;
00077
00078
00079 char *sp = (char *)srcstr;
00080 while (*sp != '\0') {
00081
00082 if (!strncmp(sp, SSI_INCLUDE_START, strlen(SSI_INCLUDE_START))) {
00083 char ssi_inc_file[MAX_LINEBUF], *endp;
00084 if ((endp = strstr(sp, SSI_INCLUDE_END)) != NULL) {
00085 sp += strlen(SSI_INCLUDE_START);
00086 qStrCpy(ssi_inc_file, sizeof(ssi_inc_file), sp, endp - sp);
00087 sp = (endp + strlen(SSI_INCLUDE_END));
00088
00089 if (qFileExist(ssi_inc_file) == true) qSedFile(entry, ssi_inc_file, fpout);
00090 else fprintf(fpout, "[qSedStr: an error occurred while processing 'include' directive - file(%s) open fail]", ssi_inc_file);
00091 } else fprintf(fpout, "[qSedStr: an error occurred while processing 'include' directive - ending tag not found]");
00092 continue;
00093 }
00094
00095
00096 int flag;
00097 const Q_NLOBJ *obj;
00098 for (obj = (Q_NLOBJ*)qEntryFirst(entry), flag = 0; obj && flag == 0; obj = (Q_NLOBJ*)qEntryNext(entry)) {
00099 if (!strncmp(sp, obj->name, strlen(obj->name))) {
00100 fprintf(fpout, "%s", (char *)obj->object);
00101 sp += strlen(obj->name);
00102 flag = 1;
00103 break;
00104 }
00105 }
00106 if (flag == 0) {
00107 fprintf(fpout, "%c", *sp);
00108 sp++;
00109 }
00110 }
00111
00112 return true;
00113 }
00114
00141 bool qSedFile(Q_ENTRY *entry, const char *filepath, FILE *fpout) {
00142 char *sp;
00143 int flag;
00144
00145 if ((sp = qFileLoad(filepath, NULL)) == NULL) return false;
00146 flag = qSedStr(entry, sp, fpout);
00147 free(sp);
00148
00149 return flag;
00150 }