root/tags/5.4.pre05/wxis_src/xis_comp.c

Revision 1, 39.4 kB (checked in by heitor.barbieri, 4 years ago)

Criação do svn para Cisis.

Line 
1/* -------------------------------------------------------------- XIS_COMP.C */
2
3/* ---------------------------------------------------------- C HEADER FILES */
4#include <stdlib.h>
5#include <stdio.h>
6#include <string.h>
7/* ------------------------------------------------------------ HEADER FILES */
8/* include "cisis.h" */
9#include "easyfc.h"
10#include "xis_comp.h"
11/* ----------------------------------------------------------------- defines */
12#define CPL_CMD_BEGIN           '<'
13#define CPL_CMD_END                     '>'
14#define CPL_ASSIGN                      '='
15#define CPL_2QUOTE                      '\"'
16
17#define CPL_CMD_CLOSE           '/'
18/* ------------------------------------------------------------------ global */
19char *cplSpace = " \t\r\n";                                                             /* space list */
20char *cplSeparator = "<>=\"";                                                           /* separator list */
21CPL_IDENTIFIER cplElement[ELEMENT_LIST_QTT];                    /* element list */
22CPL_IDENTIFIER cplAttribute[ATTRIBUTE_LIST_QTT];        /* attribute list */
23CPL_IDENTIFIER cplAtValue[ATVALUE_LIST_QTT];                    /* attribute value list */
24CPL_IDENTIFIER cplCommentBegin[COMMENT_LIST_QTT];       /* comment begin list */
25CPL_IDENTIFIER cplCommentEnd[COMMENT_LIST_QTT];         /* comment end list */
26
27/* ============================================================== cplIsSpace */
28char cplIsSpace(char ch)                /* character */
29{
30        char *find;             /* auxiliary find pointer */
31
32   /* Check if the character is considered a space */
33        find = strchr(cplSpace,ch);
34        if (find) return *find;
35        return '\0';
36
37} /* cplIsSpace */
38
39/* ================================================================ cplError */
40CPL_ERROR cplError(CPL_STRUCT *program, /* program structure */
41                                                 CPL_ERROR errorCode,   /* error code */
42                   char *text)                          /* complement message text */
43{
44        char *p;                /* auxiliary string loop pointer */
45
46   /* Set error code and complement text information */
47        program->error.code = errorCode;
48        sprintf(program->error.info,"%-.*s",EFC_ERROR_INFO_MAX,text);
49
50   /* Set end of command with string terminator */
51   for (p = program->error.info; *p; p++) {
52        if (*p == CPL_CMD_END) *(p+1) = '\0';
53      if (!cplIsSpace(*p)) continue;
54        *p = '\0';
55        break;
56   }
57
58   /* Return error code */
59   return errorCode;
60
61} /* cplError */
62
63/* =========================================================== cplSkipSpaces */
64char *cplSkipSpaces(char *p)            /* character pointer */
65{
66
67   /* Skip space characters, return next non-space character */
68        while (cplIsSpace(*p)) p++;
69   return p;
70
71} /* cplSkipSpaces */
72
73/* ======================================================== cplSeparatorFind */
74char cplSeparatorFind(char ch)          /* current script position */
75{
76        char *find;             /* auxiliary find pointer */
77
78   /* Find separator */
79   find = strchr(cplSeparator,ch);
80   if (!find) return '\0';
81   return *find;
82
83} /* cplSeparatorFind */
84
85/* ================================================================ cplIsEoi */
86BOOLEAN cplIsEoi(char *p)               /* current script position */
87{
88
89   /* Check if it is end of identifier */
90   return (BOOLEAN)(!*p || cplIsSpace(*p) || cplSeparatorFind(*p));
91
92} /* cplIsEoi */
93
94/* ============================================================== cplStrNDup */
95char *cplStrNDup(char *from,            /* source string buffer */
96                                          int len)                      /* quantity of characters to copy */
97{
98        char *dupl;             /* new string buffer pointer */
99
100   /* Allocate a new string buffer, copy len bytes of source buffer */
101//printf("cplStrNDup/antes do efc_new [%s]\n", from);
102        dupl = (char *)efc_new(len+1);
103//printf("cplStrNDup/depois do efc_new\n");
104   if (dupl) {
105        memcpy(dupl,from,len);
106      dupl[len] = '\0';
107        }
108
109   /* Return the new string */
110   return dupl;
111
112} /* cplStrNDup */
113
114/* ========================================================== cplSkipComment */
115char *cplSkipComment(char *p,                                                           /* script instructions */
116                                                        CPL_IDENTIFIER *commentEnd)     /* coment end identifier */
117{
118
119        /* Find comment end */
120        for ( ; *p; p++) {
121        if (*p != *(commentEnd->text)) continue;
122                if (strncmp(p,commentEnd->text,commentEnd->len) != 0) continue;
123                p += commentEnd->len;
124        break;
125   }
126
127        /* Return next character after comment */
128   return p;
129
130} /* cplSkipComment */
131
132/* =========================================================== cplIdentifier */
133int cplIdentifier(CPL_IDENTIFIER identList[],   /* identifier list */
134                                                int listQtt,
135                                           char *p)                                             /* current script position */
136{
137        int ident;              /* Identifier index */
138
139   /* Find element, skip first undefined element identList[0] */
140        for (ident = 1; ident < listQtt; ident++) {
141                if (strncmp(p,identList[ident].text,identList[ident].len) != 0) continue;
142      if (cplIsEoi(p+identList[ident].len)) break;
143        }
144
145   /* Return element index, index==listQtt means not found */
146   return ident;
147
148} /* cplIdentifier */
149
150/* ================================================================ cplToken */
151char *cplToken(char *p,                                                 /* current script position */
152                                        CPL_TOKEN_STRU *token)          /* token struct return */
153{
154        char separator;
155   CPL_COMMENT i;
156
157        /* Skip space characters to find next token */
158        token->statment = token->text = p;
159        p = cplSkipSpaces(p);
160   if (!*p) {
161                token->type = TOKEN_END;
162        return p;
163   }
164        token->text = p;
165
166   /* Check if it is a separator */
167   separator = cplSeparatorFind(*p);
168
169   switch (separator) {
170
171   case CPL_CMD_BEGIN:
172           /* Skip spaces */
173                p = cplSkipSpaces(++p);
174           if (!*p) {
175                        token->type = TOKEN_END;
176                return p;
177           }
178
179        /* Check if it is an element */
180        token->index.element = cplIdentifier(cplElement,ELEMENT_LIST_QTT,p);
181           if (token->index.element < ELEMENT_LIST_QTT) {
182                        token->type = TOKEN_ELEMENT;
183                        return p+cplElement[token->index.element].len;
184           }
185
186        /* Check if it is an element close */
187                if (*p == CPL_CMD_CLOSE) {
188                   token->index.element = cplIdentifier(cplElement,ELEMENT_LIST_QTT,++p);
189                if (token->index.element < ELEMENT_LIST_QTT) {
190                                token->type = TOKEN_ELCLOSE;
191                                return p+cplElement[token->index.element].len;
192                }
193           }
194
195           /* Check if it is a comment */
196      for (i = 0; i < COMMENT_LIST_QTT; i++) {
197                        if (strncmp(p,cplCommentBegin[i].text,cplCommentBegin[i].len) == 0) {
198              p = cplSkipComment(p+cplCommentBegin[i].len,&(cplCommentEnd[i]));
199                        return cplToken(p,token);
200                }
201      }
202        break;
203
204   case CPL_CMD_END:
205        token->type = TOKEN_ELEND;
206      return ++p;
207
208   case CPL_ASSIGN:
209        token->type = TOKEN_ASSIGN;
210      return ++p;
211
212   } /* switch */
213
214   /* Check if it is an attribute */
215   token->index.attribute = cplIdentifier(cplAttribute,ATTRIBUTE_LIST_QTT,p);
216   if (token->index.attribute < ATTRIBUTE_LIST_QTT) {
217                token->type = TOKEN_ATTRIBUTE;
218                return p+cplAttribute[token->index.attribute].len;
219   }
220
221   /* Return no token found */
222        token->type = TOKEN_LIST_QTT;
223   return p;
224}
225
226/* ============================================================= cplStatment */
227char *cplStatment(char *p,                                      /* current script position */
228                                                CPL_COMMAND *cmd)               /* command structure */
229{
230        char *text;                                     /* statment begin */
231   int len;                                             /* statment lenght */
232   CPL_TOKEN_STRU token;        /* token structure */
233
234   /* Find end of statment, count number of characters */
235        for (text = p,len = 0; *p; p++,len++) {
236                if (*p != CPL_CMD_BEGIN) continue;
237                cplToken(p,&token);
238                if (token.type == TOKEN_ELCLOSE && token.index.element == cmd->element) break;
239        }
240
241   /* Allocate statment, copy text */
242        cmd->text = cplStrNDup(text,len);
243
244   /* Return next script position */
245   return p;
246
247} /* cplStatment */
248
249/* ================================================================= cplWord */
250char *cplWord(char *p,                                                                  /* current script position */
251                                  CMD_ATTRIBUTE_STRU *attribute)                /* command structure */
252{
253        char *text;                                     /* statment begin */
254   int len;                                             /* statment lenght */
255
256   /* Find end of word, count number of characters */
257        for (text = p,len = 0; !cplIsEoi(p); p++,len++);
258
259   /* Allocate statment, copy text */
260        attribute->text = efc_strrepl(attribute->text,cplStrNDup(text,len));
261
262   /* Return next script position */
263   return p;
264
265} /* cplWord */
266
267/* ========================================================== cplDoubleQuote */
268char *cplDoubleQuote(char *p,                                                                           /* current script position */
269                                                        CMD_ATTRIBUTE_STRU *attribute)          /* command structure */
270{
271        char *text;                                     /* statment begin */
272    char *dup;
273   int len;                                             /* statment lenght */
274
275   /* Find end of work, count number of characters */
276        for (text = p,len = 0; *p && *p != CPL_2QUOTE; p++,len++);
277
278   /* Allocate statment, copy text */
279   dup = cplStrNDup(text,len);   /* Code Guard */
280        attribute->text = efc_strrepl(attribute->text,dup);
281    efc_free(dup);
282
283   /* Return next script position */
284   return *p ? ++p : p;
285
286} /* cplDoubleQuote */
287
288/* ======================================================== cplPrintCmdBegin */
289void cplPrintCmdBegin(BOOLEAN convLT)           /* convert less than character */
290{
291
292        /* Print less than character or related HTML entity */
293        if (convLT) printf("&lt;");
294   else printf("%c",CPL_CMD_BEGIN);
295
296} /* cplPrintCmdBegin */
297
298/* =========================================================== cplPrintScope */
299void cplPrintScope(int scope)           /* command scope */
300{
301        int i;          /* auxiliary loop index */
302
303   /* Print scope spaces */
304        for (i = 0; i < scope; i++) printf("  ");
305
306} /* cplPrintScope */
307
308/* ========================================================= cplPrintCommand */
309void cplPrintCommand(CPL_COMMAND *cmd,          /* command structure */
310                                                        BOOLEAN convLT)         /* convert less than character */
311{
312        CPL_ATTRIBUTE i;                /* attribute index */
313
314   /* Show command information */
315        cplPrintCmdBegin(convLT);
316   printf("%s",cplElement[cmd->element].text);
317        for (i = 0; i < ATTRIBUTE_LIST_QTT; i++)
318        if (cmd->attributeList[i].text)
319                printf(" %s%c%c%s%c",cplAttribute[i].text,CPL_ASSIGN,CPL_2QUOTE,cmd->attributeList[i].text,CPL_2QUOTE);
320   printf("%c",CPL_CMD_END);
321   if (cmd->text) printf("%s",cmd->text);
322
323} /* cplPrintCommand */
324
325/* ==================================================== cplPrintCommandClose */
326void cplPrintCommandClose(CPL_COMMAND *cmd,             /* command structure */
327                                                                  BOOLEAN convLT)                       /* convert less than character */
328{
329
330   /* Show command close */
331        cplPrintCmdBegin(convLT);
332   printf("%c%s%c\n",CPL_CMD_CLOSE,cplElement[cmd->element].text,CPL_CMD_END);
333
334} /* cplPrintCommandClose */
335
336/* ================================================================ cplPrint */
337void cplPrint(CPL_COMMAND *cmd,         /* command structure */
338                                  int scope)            /* scope counter */
339{
340
341        /* Loop all commands, call sub-command */
342   printf("\n");
343        for ( ; cmd; cmd = cmd->next) {
344        cplPrintScope(scope);
345                cplPrintCommand(cmd,FALSE);
346        if (cmd->sub) {
347        cplPrint(cmd->sub,scope+1);
348                cplPrintScope(scope);
349      }
350                cplPrintCommandClose(cmd,FALSE);
351   }
352
353} /* cplPrint */
354
355/* ========================================================== cplIncludeFile */
356char *cplIncludeFile(CPL_STRUCT *program,                               /* program structure */
357                                                CPL_COMMAND *cmd,                                       /* list first command */
358                     CPL_ERROR *errorCode)                      /* error code */
359{
360        char *p;
361        char includeName[PATH_NAME_LEN+1];      /* auxiliary file name string */
362   EFC_ERROR errorFile;
363
364        /* Load include file content, original file name */
365        p = efc_std_filecontent(&errorFile,cmd->text);
366        if (p) {
367                return p;
368        }
369
370        /* Verify path lenght + file name lenght */
371   if (strlen(program->pathSource) + strlen(cmd->text) > PATH_NAME_LEN) {
372                *errorCode = cplError(program,CPL_ERROR_PATHNAMELEN,cmd->text);
373                return NULL;
374   }
375
376        /* Load include file content, source path */
377   sprintf(includeName,"%s%s",program->pathSource,cmd->text);
378        p = efc_std_filecontent(&errorFile,includeName);
379        if (!p) {
380                *errorCode = cplError(program,CPL_ERROR_NOTFOUND,includeName);
381                return NULL;
382        }
383
384        /* Return allocated content file buffer */
385   return p;
386
387} /* cplIncludeFile */
388
389/* =========================================================== cplIsCompiled */
390BOOLEAN cplIsCompiled
391(
392        CPL_STRUCT *program,            /* program structure */
393        char *scriptName                        /* script name */
394)
395{
396        int lenDiff;            /* lenght difference */
397
398   /* script name minus compiled extension, it can't compare the string tail */
399        lenDiff = strlen(scriptName) - strlen(program->compiledExt);
400        if (lenDiff < 0) return FALSE;
401
402   /* compare the script name tail with the default compiled extension */
403   return (BOOLEAN)(strcmp(scriptName+lenDiff,program->compiledExt) == 0);
404
405} /* cplIsCompiled */
406
407/* ========================================================== cplLoadCommand */
408CPL_COMMAND *cplLoadCommand(CPL_COMMAND *add_cmd,               /* command to be added */
409                                                                         CPL_CMD_LIST *cmdList)         /* command list */
410{
411   CPL_COMMAND *cmd;            /* new allocated area */
412
413   /* Allocate area */
414//printf("cplLoadCommand/antes do efc_new\n");
415   cmd = (CPL_COMMAND *)efc_new(sizeof(CPL_COMMAND));
416//printf("cplLoadCommand/antes do efc_new\n");
417   if (!cmd) return NULL;
418
419   /* Copy command data */
420   memcpy(cmd,add_cmd,sizeof(CPL_COMMAND));
421
422   /* Append on the list of commands */
423   if (!cmdList->first) cmdList->first = cmd;
424   if (cmdList->last) cmdList->last->next = cmd;
425   cmd->prev = cmdList->last;
426   cmdList->last = cmd;
427
428   /* Return allocated area pointer */
429   return cmd;
430
431} /* cplLoadCommand */
432
433/* ======================================================== cplLoadAttribute */
434char *cplLoadAttribute(char *p,                                                         /* instructions to be compiled */
435                                                          CPL_STRUCT *program,                          /* program structure */
436                                                  CPL_COMMAND *cmd,                                     /* list first command */
437                                                  CPL_ATTRIBUTE attributeIndex, /* attribute index */
438                                  CPL_ERROR *errorCode)                         /* error code */
439{
440   CPL_TOKEN_STRU token;                        /* token structure */
441
442        /* Get assign token */
443   p = cplToken(p,&token);
444        if (token.type != TOKEN_ASSIGN) {
445                *errorCode = cplError(program,CPL_ERROR_INVALID,token.text);
446                return p;
447        }
448
449        /* Get next token */
450   p = cplToken(p,&token);
451        if (*p == CPL_2QUOTE) {
452        token.text = ++p;
453                p = cplDoubleQuote(p,&(cmd->attributeList[attributeIndex]));
454   } else
455                p = cplWord(token.text,&(cmd->attributeList[attributeIndex]));
456
457        /* Set attribute value */
458   cmd->attributeList[attributeIndex].atValue = cplIdentifier(cplAtValue,ATVALUE_LIST_QTT,token.text);
459
460   return p;
461
462} /* cplLoadAttribute */
463
464/* ================================================================= cplLoad */
465char *cplLoad(char *script,                                             /* instructions to be compiled */
466              CPL_STRUCT *program,                              /* program structure */
467              CPL_ELEMENT headerElement,                /* caller command */
468              CPL_COMMAND **first,                              /* list first command */
469              CPL_CMD_LIST *cmdList,                    /* command list */
470              CPL_ERROR *errorCode)                             /* error code */
471{
472        char *p;                                                                /* auxiliary loop pointer */
473        char *includeText;                              /* the include file content */
474        char *pInclude;                                 /* auxiliary text pointer */
475   CPL_TOKEN_STRU token;                        /* token structure */
476   CPL_TOKEN_STRU prevToken;            /* previous token */
477   CPL_COMMAND cmd;                                     /* command structure */
478   CPL_CMD_LIST subCmdList;             /* sub-command list */
479
480   /* Start variables */
481   *errorCode = CPL_ERROR_OK;
482   *first = NULL;
483        memset(&prevToken,0x00,sizeof(CPL_TOKEN_STRU));
484   prevToken.type = TOKEN_ELCLOSE;
485        memset(&cmd,0x00,sizeof(CPL_COMMAND));
486        memset(cmdList,0x00,sizeof(CPL_CMD_LIST));
487
488   /* Loop all script characters */
489        for (p = script; *p; prevToken = token) {
490
491        /* Get token, index and skip token lenght */
492 //printf("cplLoad/antes do cplToken\n");
493      p = cplToken(p,&token);
494//printf("cplLoad/antes do cplToken\n");
495        /* Evaluate token */
496                switch (token.type) {
497
498      case TOKEN_ATTRIBUTE:
499                /* Check previous token */
500                if (prevToken.type == TOKEN_ELEND) goto LABEL_TOKEN_STATMENT;
501        if (prevToken.type != TOKEN_ELEMENT && prevToken.type != TOKEN_ATTRIBUTE) {
502                *errorCode = cplError(program,CPL_ERROR_INVALID,prevToken.text);
503            return p;
504         }
505
506                /* Load attribute */
507         p = cplLoadAttribute(p,program,&cmd,token.index.attribute,errorCode);
508         if (*errorCode) return p;
509         break;
510
511      case TOKEN_ELCLOSE:
512
513                /* Load command instruction */
514        if (cmd.element) cplLoadCommand(&cmd,cmdList);
515
516                /* Check sub-command end */
517        if (token.index.element == headerElement) {
518                           *first = cmdList->first;
519                return cmd.element ? p : token.text;
520         }
521
522                /* [0.8] Check element close couple */
523        if (token.index.element != cmd.element) {
524                *errorCode = cplError(program,CPL_ERROR_INVALID,token.text);
525            return p;
526         }
527
528                /* [4.1] Include element */
529                        if (cmd.element == ELEMENT_INCLUDE && *(cmd.text)) {
530
531                        /* Not compiled */
532                if (!cplIsCompiled(program,cmd.text))
533            {
534                                /* Load include file content */
535//printf("cplLoad/ntes do cplIncludeFile\n");
536                        includeText = cplIncludeFile(program,&cmd,errorCode);
537//printf("cplLoad/depois do cplIncludeFile\n");
538                if (!includeText) return p;
539
540                                /* Load include file instructions, use sub-command as an auxiliar list */
541                                        pInclude = cplLoad(includeText,program,ELEMENT_LIST_QTT,&(cmd.sub),&subCmdList,errorCode);
542                if (*errorCode) return pInclude;
543//printf("cplLoad/antes do efc_free\n");
544                                /* Garbage collector */
545#ifndef XIS_SERVER
546                 efc_free(includeText);
547#endif
548//printf("cplLoad/depois do efc_free\n");
549                        }
550                        /* Compiled */
551            else
552            {
553                                   /* Load compiled instructions, use sub-command as an auxiliar list */
554                                        *errorCode = cplLoadCompiled(cmd.text,program,&(cmd.sub),&subCmdList);
555                                        if (*errorCode)
556               {
557                                        return p;
558                         }
559            }
560
561                        /* Append include commands in current command list */
562            if (subCmdList.first) {
563                cmdList->last->next = subCmdList.first;
564                subCmdList.first->prev = cmdList->last;
565               cmdList->last = subCmdList.last;
566            }
567
568         }
569
570                /* Reset command container */
571                        memset(&cmd,0x00,sizeof(CPL_COMMAND));
572//printf("cplLoad/break\n");
573        break;
574
575      case TOKEN_ELEMENT:
576                /* Check previous token */
577        if (prevToken.type != TOKEN_ELEND && prevToken.type != TOKEN_ELCLOSE) {
578                *errorCode = cplError(program,CPL_ERROR_INVALID,prevToken.text);
579            return p;
580         }
581
582        if (prevToken.type == TOKEN_ELEND) {
583                                p = cplLoad(token.text,program,cmd.element,&(cmd.sub),&subCmdList,errorCode);
584              if (*errorCode) return p;
585         } else
586                cmd.element = token.index.element;
587
588         break;
589
590      case TOKEN_ELEND:
591                /* End of element */
592         if (prevToken.type == TOKEN_ELCLOSE) token = prevToken;
593        break;
594
595      case TOKEN_END:
596                /* End of script */
597         break;
598
599      default:
600
601                        LABEL_TOKEN_STATMENT:
602
603                /* Check if it is a statment */
604        if (prevToken.type == TOKEN_ELEND &&
605                cmd.element != ELEMENT_DO &&
606            cmd.element != ELEMENT_FUNCTION &&
607            cmd.element != ELEMENT_HL &&
608            cmd.element != ELEMENT_ISISSCRIPT &&
609            cmd.element != ELEMENT_LOOP &&
610            cmd.element != ELEMENT_SECTION &&
611            cmd.element != ELEMENT_UPDATE) {
612                p = cplStatment(token.statment,&cmd);
613                                break;
614                        }
615
616                /* Invalid token */
617        *errorCode = cplError(program,CPL_ERROR_INVALID,token.text);
618        return p;
619
620      } /* switch */
621//printf("cplLoad/proximo laco do loop\n");
622   } /* for */
623//printf("cplLoad/sai do loop xxx\n");
624        /* Return no error */
625   *first = cmdList->first;
626   return p;
627
628} /* cplLoad */
629
630/* =========================================================== cplStartIdent */
631void cplStartIdent(CPL_IDENTIFIER *ident,       /* identifier structure */
632                                                 char *text)                            /* identifier text */
633{
634
635   /* Set identifier values: text and text lenght */
636   ident->text = text;
637   ident->len = strlen(text);
638
639} /* cplStartIdent */
640
641/* ================================================================ cplStart */
642void cplStart
643(
644        CPL_STRUCT *program             /* program structure */
645)
646{
647   /* Check if it is the first call */
648        if (program->cplStarted) return;
649
650   /* Reset program structure */
651   memset(&cplElement,  0x00,sizeof(CPL_IDENTIFIER)*ELEMENT_LIST_QTT);
652   memset(&cplAttribute,0x00,sizeof(CPL_IDENTIFIER)*ATTRIBUTE_LIST_QTT);
653   memset(&cplAtValue,  0x00,sizeof(CPL_IDENTIFIER)*ATVALUE_LIST_QTT);
654
655   /* Set compiler elements */
656        cplStartIdent(&(cplElement[ELEMENT_0]),                         "");
657        cplStartIdent(&(cplElement[ELEMENT_CALL]),                      "call");
658        cplStartIdent(&(cplElement[ELEMENT_CGITABLE]),          "cgitable");
659        cplStartIdent(&(cplElement[ELEMENT_DEFINE]),                    "define");
660        cplStartIdent(&(cplElement[ELEMENT_DISPLAY]),           "display");
661        cplStartIdent(&(cplElement[ELEMENT_DISPL]),                     "displ");
662        cplStartIdent(&(cplElement[ELEMENT_DO]),                                "do");
663        cplStartIdent(&(cplElement[ELEMENT_EXPORT]),                    "export");
664        cplStartIdent(&(cplElement[ELEMENT_EXTRACT]),           "extract");
665        cplStartIdent(&(cplElement[ELEMENT_FIELD]),                     "field");
666        cplStartIdent(&(cplElement[ELEMENT_FILE]),                      "file");
667        cplStartIdent(&(cplElement[ELEMENT_FLOW]),                      "flow");
668        cplStartIdent(&(cplElement[ELEMENT_FUNCTION]),          "function");
669        cplStartIdent(&(cplElement[ELEMENT_HL]),                                "hl");
670        cplStartIdent(&(cplElement[ELEMENT_HTMLPFT]),           "htmlpft");
671        cplStartIdent(&(cplElement[ELEMENT_INCLUDE]),           "include");
672        cplStartIdent(&(cplElement[ELEMENT_ISISSCRIPT]),        "IsisScript");
673        cplStartIdent(&(cplElement[ELEMENT_LABEL]),                     "label");
674        cplStartIdent(&(cplElement[ELEMENT_LIST]),                      "list");
675        cplStartIdent(&(cplElement[ELEMENT_LOOP]),                      "loop");
676        cplStartIdent(&(cplElement[ELEMENT_PARM]),                      "parm");
677        cplStartIdent(&(cplElement[ELEMENT_PFT]),                               "pft");
678        cplStartIdent(&(cplElement[ELEMENT_PROC]),              "proc");
679        cplStartIdent(&(cplElement[ELEMENT_RETURN]),                    "return");
680        cplStartIdent(&(cplElement[ELEMENT_SECTION]),           "section");
681        cplStartIdent(&(cplElement[ELEMENT_TRACE]),                     "trace");
682        cplStartIdent(&(cplElement[ELEMENT_UPDATE]),                    "update");
683        cplStartIdent(&(cplElement[ELEMENT_WRITE]),                     "write");
684        /* 22.Feb.2001 */
685        cplStartIdent(&(cplElement[ELEMENT_ISISXML]),           "isisxml");
686
687   /* Set compiler attributes */
688        cplStartIdent(&(cplAttribute[ATTRIBUTE_0]),                     "");
689        cplStartIdent(&(cplAttribute[ATTRIBUTE_ACTION]),        "action");
690        cplStartIdent(&(cplAttribute[ATTRIBUTE_FROM]),          "from");
691        cplStartIdent(&(cplAttribute[ATTRIBUTE_NAME]),          "name");
692        cplStartIdent(&(cplAttribute[ATTRIBUTE_PREVIOUS]),      "previous");
693        cplStartIdent(&(cplAttribute[ATTRIBUTE_SPLIT]),         "split");
694        cplStartIdent(&(cplAttribute[ATTRIBUTE_TAG]),           "tag");
695        cplStartIdent(&(cplAttribute[ATTRIBUTE_TASK]),          "task");
696        cplStartIdent(&(cplAttribute[ATTRIBUTE_TYPE]),          "type");
697
698   /* Set compiler attributes values */
699        cplStartIdent(&(cplAtValue[ATVALUE_0]),                         "");
700        cplStartIdent(&(cplAtValue[ATVALUE_ACTAB]),                     "actab");
701        cplStartIdent(&(cplAtValue[ATVALUE_ADD]),                               "add");
702        cplStartIdent(&(cplAtValue[ATVALUE_APPEND]),                    "append");
703        cplStartIdent(&(cplAtValue[ATVALUE_BUFFERSIZE]),        "buffersize");
704        cplStartIdent(&(cplAtValue[ATVALUE_CGI]),                               "cgi");
705        cplStartIdent(&(cplAtValue[ATVALUE_CGISFT]),                    "^t");
706        cplStartIdent(&(cplAtValue[ATVALUE_CGISFU]),                    "^u");
707        cplStartIdent(&(cplAtValue[ATVALUE_CGISFW]),                    "^w");
708        cplStartIdent(&(cplAtValue[ATVALUE_CHECK]),                     "check");
709        cplStartIdent(&(cplAtValue[ATVALUE_CIPAR]),                     "cipar");
710        cplStartIdent(&(cplAtValue[ATVALUE_CLOSE]),                     "close");
711        cplStartIdent(&(cplAtValue[ATVALUE_CONVERT]),           "convert");
712        cplStartIdent(&(cplAtValue[ATVALUE_COPY]),                      "copy");
713        cplStartIdent(&(cplAtValue[ATVALUE_COUNT]),                     "count");
714        cplStartIdent(&(cplAtValue[ATVALUE_CREATE]),                    "create");
715        cplStartIdent(&(cplAtValue[ATVALUE_DATABASE]),          "database");
716        cplStartIdent(&(cplAtValue[ATVALUE_DB]),                                "db");
717        cplStartIdent(&(cplAtValue[ATVALUE_DECOD]),                     "decod");
718        cplStartIdent(&(cplAtValue[ATVALUE_DEFINE]),                    "define");
719        cplStartIdent(&(cplAtValue[ATVALUE_DELETE]),                    "delete");
720        cplStartIdent(&(cplAtValue[ATVALUE_DELIMITER]),         "delimiter");
721        cplStartIdent(&(cplAtValue[ATVALUE_DISPLAY]),           "display");
722        cplStartIdent(&(cplAtValue[ATVALUE_EXIT]),                      "exit");
723        cplStartIdent(&(cplAtValue[ATVALUE_EXPIRE]),                    "expire");
724        cplStartIdent(&(cplAtValue[ATVALUE_EXPORT]),                    "export");
725        cplStartIdent(&(cplAtValue[ATVALUE_EXPRESSION]),        "expression");
726        cplStartIdent(&(cplAtValue[ATVALUE_EXTRACT]),           "extract");
727        cplStartIdent(&(cplAtValue[ATVALUE_FILE]),                      "file");
728        cplStartIdent(&(cplAtValue[ATVALUE_FLAG]),                      "flag");
729        cplStartIdent(&(cplAtValue[ATVALUE_FLDDIR]),                    "flddir");
730        cplStartIdent(&(cplAtValue[ATVALUE_FREQ]),                      "freq");
731        cplStartIdent(&(cplAtValue[ATVALUE_FREQSUM]),           "freqsum");
732        cplStartIdent(&(cplAtValue[ATVALUE_FROM]),              "from");
733        cplStartIdent(&(cplAtValue[ATVALUE_FST]),                               "fst");
734        cplStartIdent(&(cplAtValue[ATVALUE_FULLINV]),           "fullinvertion");
735        cplStartIdent(&(cplAtValue[ATVALUE_GIZMO]),                     "gizmo");
736        cplStartIdent(&(cplAtValue[ATVALUE_HL]),                                "hl");
737        cplStartIdent(&(cplAtValue[ATVALUE_IMPORT]),                    "import");
738        cplStartIdent(&(cplAtValue[ATVALUE_INDEXLIST]),         "indexlist");
739        cplStartIdent(&(cplAtValue[ATVALUE_INVERTED]),          "inverted");
740        cplStartIdent(&(cplAtValue[ATVALUE_INVLOAD]),           "invertedload");
741        cplStartIdent(&(cplAtValue[ATVALUE_JUMP]),              "jump");
742        cplStartIdent(&(cplAtValue[ATVALUE_KEY]),                       "key");
743        cplStartIdent(&(cplAtValue[ATVALUE_KEYFIELD]),          "keyfield");
744        cplStartIdent(&(cplAtValue[ATVALUE_KEYLENGTH]),         "keylength");
745        cplStartIdent(&(cplAtValue[ATVALUE_KEYRANGE]),          "keyrange");
746        cplStartIdent(&(cplAtValue[ATVALUE_KEYS]),                      "keys");
747        cplStartIdent(&(cplAtValue[ATVALUE_KEYSDB]),                    "keysdb");
748        cplStartIdent(&(cplAtValue[ATVALUE_LIST]),                      "list");
749        cplStartIdent(&(cplAtValue[ATVALUE_LOAD]),                      "load");
750        cplStartIdent(&(cplAtValue[ATVALUE_LOCKID]),                    "lockid");
751        cplStartIdent(&(cplAtValue[ATVALUE_MASTER]),                    "master");
752        cplStartIdent(&(cplAtValue[ATVALUE_MAXLK]),                     "maxlk");
753        cplStartIdent(&(cplAtValue[ATVALUE_MFN]),                               "mfn");
754        cplStartIdent(&(cplAtValue[ATVALUE_MFNRANGE]),          "mfnrange");
755        cplStartIdent(&(cplAtValue[ATVALUE_MSTSORT]),           "mastersort");
756        cplStartIdent(&(cplAtValue[ATVALUE_OCC]),                               "occ");
757        cplStartIdent(&(cplAtValue[ATVALUE_OUTPUT]),                    "output");
758        cplStartIdent(&(cplAtValue[ATVALUE_POSTING]),           "posting");
759        cplStartIdent(&(cplAtValue[ATVALUE_POSTTAG]),           "posttag");
760        cplStartIdent(&(cplAtValue[ATVALUE_PREFIX]),            "prefix");
761        cplStartIdent(&(cplAtValue[ATVALUE_RELOAD]),                    "reload");
762        cplStartIdent(&(cplAtValue[ATVALUE_REPLACE]),           "replace");
763        cplStartIdent(&(cplAtValue[ATVALUE_RESET]),                     "reset");
764        cplStartIdent(&(cplAtValue[ATVALUE_REVERSE]),           "reverse");
765        cplStartIdent(&(cplAtValue[ATVALUE_SEARCH]),                    "search");
766        cplStartIdent(&(cplAtValue[ATVALUE_SKIP]),                      "skip");
767        cplStartIdent(&(cplAtValue[ATVALUE_SORT]),                      "sort");
768        cplStartIdent(&(cplAtValue[ATVALUE_STATUSDB]),          "statusdb");
769        cplStartIdent(&(cplAtValue[ATVALUE_STATUSFILE]),        "statusfile");
770        cplStartIdent(&(cplAtValue[ATVALUE_STW]),                               "stw");
771        cplStartIdent(&(cplAtValue[ATVALUE_SUFFIX]),            "suffix");
772        cplStartIdent(&(cplAtValue[ATVALUE_TEMPFILE]),          "tempfile");
773        cplStartIdent(&(cplAtValue[ATVALUE_TASK]),              "task");
774        cplStartIdent(&(cplAtValue[ATVALUE_TO]),                "to");
775        cplStartIdent(&(cplAtValue[ATVALUE_TYPE]),                      "type");
776        cplStartIdent(&(cplAtValue[ATVALUE_UCTAB]),                     "uctab");
777        cplStartIdent(&(cplAtValue[ATVALUE_UNLOCK]),                    "unlock");
778        cplStartIdent(&(cplAtValue[ATVALUE_UPDATE]),                    "update");
779        cplStartIdent(&(cplAtValue[ATVALUE_WRITE]),             "write");
780        /* 27.Nov.2000 */
781        cplStartIdent(&(cplAtValue[ATVALUE_PREFIX_HTMLPFT]),"prefix htmlpft");
782        cplStartIdent(&(cplAtValue[ATVALUE_SUFFIX_HTMLPFT]),"suffix htmlpft");
783        /* 28.Nov.2000 */
784        cplStartIdent(&(cplAtValue[ATVALUE_FIRST_LINE]),        "first line");
785        /* 22.Feb.2001 */
786        cplStartIdent(&(cplAtValue[ATVALUE_ISISXML_STYLE]),"isisxml style");
787        cplStartIdent(&(cplAtValue[ATVALUE_ISISXML_TABLE]),"isisxml table");
788        /* 05.Apr.2001 */
789        cplStartIdent(&(cplAtValue[ATVALUE_LOG]),                               "log");
790
791   /* Set compiler comment */
792        cplStartIdent(&(cplCommentBegin[COMMENT_NORMAL]),       "!--");
793        cplStartIdent(&(cplCommentEnd[COMMENT_NORMAL]),         "-->");
794        cplStartIdent(&(cplCommentBegin[COMMENT_PROCESS]),      "?");
795        cplStartIdent(&(cplCommentEnd[COMMENT_PROCESS]),        "?>");
796        cplStartIdent(&(cplCommentBegin[COMMENT_DECLARE]),      "!");
797        cplStartIdent(&(cplCommentEnd[COMMENT_DECLARE]),        ">");
798
799   /* Set as started */
800        program->cplStarted = TRUE;
801
802} /* cplStart */
803
804/* ============================================================== cplCompile */
805CPL_ERROR cplCompile(char *script,                              /* instructions to be compiled */
806                                                        CPL_STRUCT *program)            /* program structure */
807{
808        char *p;                                                /* script instruction pointer */
809   CPL_CMD_LIST cmdList;        /* command list */
810        CPL_ERROR errorCode;            /* error code */
811
812   /* Start compiler variables */
813        cplStart(program);
814//printf("antes do cplLoad\n");
815   /* Load script */
816   p = cplLoad(script,program,ELEMENT_LIST_QTT,&(program->cmd),&cmdList,&errorCode);
817
818   /* Print compiled */
819        if (program->printSource)
820        if (errorCode) {
821        *p = '\0';
822        printf("%s",script);
823      } else
824        cplPrint(program->cmd,0);
825
826   /* Return error code */
827   return errorCode;
828
829}  /* cplCompile */
830
831/* ============================================================ cplWriteText */
832CPL_ERROR cplWriteText(CPL_STRUCT *program,     /* program structure */
833                                                          FILE *saveFile,                       /* save file pointer */
834                       char *text)                              /* write text */
835{
836   long writeTextLen;           /* write text lenght */
837
838   /* write the text lenght */
839        writeTextLen = (long)strlen(text);
840        if (fwrite(&writeTextLen,sizeof(long),1,saveFile) != 1) {
841                return cplError(program,CPL_ERROR_WRITE,text);
842   }
843
844   /* write the text string */
845   if (fwrite(text,writeTextLen,1,saveFile) != 1) {
846                return cplError(program,CPL_ERROR_WRITE,text);
847        }
848
849   /* return no error */
850   return CPL_ERROR_OK;
851
852} /* cplWriteText */
853
854/* ========================================================= cplWriteCommand */
855CPL_ERROR cplWriteCommand(CPL_STRUCT *program,          /* program structure */
856                                                                  FILE *saveFile,                               /* save file pointer */
857                                  CPL_COMMAND *cmd,                     /* command instruction */
858                          CPL_COMPILED_PART part)       /* write part */
859{
860   CPL_COMPILED_HEADER compiledHeader;          /* compiled header information */
861   CPL_COMMAND cmdCompiled;                             /* command save compiled area */
862        CPL_ATTRIBUTE attrIndex;                                        /* attribute index */
863        CPL_ERROR errorCode;                                                    /* error code */
864
865   /* select which part is to written */
866        switch (part) {
867
868   case PART_HEADER:
869        /* write compiled file header */
870        compiledHeader.versionNumber = 0L;              /* 0L - first compiled version */
871      compiledHeader.aux1 = 0L;                                 /* reserved for any future use */
872      compiledHeader.aux2 = 0L;                                 /* reserved for any future use */
873        if (fwrite(&compiledHeader,sizeof(CPL_COMPILED_HEADER),1,saveFile) != 1) {
874                        return cplError(program,CPL_ERROR_WRITE,cplElement[cmd->element].text);
875           }
876      break;
877
878   case PART_COMMAND:
879        /* write command instruction */
880      memcpy(&cmdCompiled,cmd,sizeof(CPL_CMD_COMPILED));
881        if (fwrite(&cmdCompiled,sizeof(CPL_COMMAND),1,saveFile) != 1) {
882                        return cplError(program,CPL_ERROR_WRITE,cplElement[cmd->element].text);
883           }
884      break;
885
886   case PART_TEXT:
887        /* write attribute texts */
888        for (attrIndex = 0; attrIndex < ATTRIBUTE_LIST_QTT; attrIndex++) {
889                if (cmd->attributeList[attrIndex].text) {
890                errorCode = cplWriteText(program,saveFile,cmd->attributeList[attrIndex].text);
891                if (errorCode) return errorCode;
892        }
893      }
894        /* write command text */
895        if (cmd->text) {
896        errorCode = cplWriteText(program,saveFile,cmd->text);
897         if (errorCode) return errorCode;
898      }
899                break;
900
901   } /* switch */
902
903   /* Return no error */
904   return CPL_ERROR_OK;
905
906} /* cplWriteCommand */
907
908/* ================================================================ cplWrite */
909CPL_ERROR cplWrite(CPL_STRUCT *program,         /* program structure */
910                   FILE *saveFile,                              /* save file pointer */
911                   CPL_COMMAND *cmd,                    /* command instruction */
912                   CPL_COMPILED_PART part)      /* write part */
913{
914        CPL_ERROR errorCode;            /* error code */
915
916   /* All command list */
917        for ( ; cmd; cmd = cmd->next) {
918
919        /* Write command */
920        errorCode = cplWriteCommand(program,saveFile,cmd,part);
921      if (errorCode) return errorCode;
922
923        /* Write sub-command */
924        if (cmd->sub) {
925        errorCode = cplWrite(program,saveFile,cmd->sub,part);
926         if (errorCode) return errorCode;
927      }
928
929   } /* for */
930
931   /* Return no error */
932        return CPL_ERROR_OK;
933
934} /* cplWrite */
935
936/* ========================================================= cplSaveCompiled */
937CPL_ERROR cplSaveCompiled(CPL_STRUCT *program,  /* program structure */
938                          char *saveFileName)   /* save file name */
939{
940   FILE *saveFile;                      /* file pointer */
941        CPL_ERROR errorCode;            /* error code */
942
943   /* Open for binary write */
944        saveFile = fopen(saveFileName,"wb");
945        if (!saveFile) return cplError(program,CPL_ERROR_FILE,saveFileName);
946
947   /* Write compiled header */
948        errorCode = cplWriteCommand(program,saveFile,NULL,PART_HEADER);
949
950   /* Write command instructions */
951   if (!errorCode) {
952        errorCode = cplWrite(program,saveFile,program->cmd,PART_COMMAND);
953   }
954
955   /* Write text string list */
956   if (!errorCode) {
957        errorCode = cplWrite(program,saveFile,program->cmd,PART_TEXT);
958   }
959
960   /* Close written file */
961        fclose(saveFile);
962
963   /* Return error code */
964   return errorCode;
965
966}  /* cplSaveCompiled */
967
968/* ============================================================= cplReadText */
969CPL_ERROR cplReadText(CPL_STRUCT *program,      /* program structure */
970                                                         FILE *loadFile,                        /* load file pointer */
971                         char **readText,                       /* read text return pointer */
972                      BOOLEAN *readEOF)         /* enf of file flag */
973{
974   long loadTextLen;            /* text lenght */
975   char *text;                          /* text string pointer */
976
977        /* read text lenght */
978   *readEOF = (fread(&loadTextLen,sizeof(long),1,loadFile) != 1);
979        if (*readEOF) {
980                return CPL_ERROR_OK;
981   }
982
983        /* read text string */
984//printf("cplReadText/antes do efc_new\n");
985        text = (char *)efc_new(loadTextLen+1);
986//printf("cplReadText/antes do efc_new\n");
987   if (!text) return cplError(program,CPL_ERROR_ALLOC,"cplReadText");
988   if (loadTextLen) *readEOF = (fread(text,loadTextLen,1,loadFile) != 1);
989   *(text+loadTextLen) = '\0';
990        if (*readEOF) {
991                return CPL_ERROR_OK;
992        }
993
994   /* Return text pointer */
995        *readText = text;
996
997   /* Return no error */
998   return CPL_ERROR_OK;
999
1000} /* cplReadText */
1001
1002/* ========================================================== cplReadCommand */
1003CPL_ERROR cplReadCommand(CPL_STRUCT *program,           /* program structure */
1004                                                                 FILE *loadFile,                                /* load file pointer */
1005                         CPL_COMPILED_PART part,        /* write part */
1006                                 CPL_COMMAND *cmd,                      /* command instruction */
1007                         BOOLEAN *readEOF)                      /* enf of file flag */
1008{
1009   CPL_COMPILED_HEADER compiledHeader;          /* compiled header information */
1010   CPL_COMMAND cmdCompiled;                             /* command save compiled area */
1011        CPL_ATTRIBUTE attrIndex;                                        /* attribute index */
1012        CPL_ERROR errorCode;                                                    /* error code */
1013
1014   /* select which part is to read */
1015        switch (part) {
1016
1017   case PART_HEADER:
1018        /* read compiled header */
1019           *readEOF = (fread(&compiledHeader,sizeof(CPL_COMPILED_HEADER),1,loadFile) != 1);
1020        if (*readEOF) {
1021                        return CPL_ERROR_OK;
1022           }
1023      break;
1024
1025   case PART_COMMAND:
1026        /* read command instruction */
1027           *readEOF = (fread(&cmdCompiled,sizeof(CPL_COMMAND),1,loadFile) != 1);
1028      memset(cmd,0x00,sizeof(CPL_COMMAND));
1029      memcpy(cmd,&cmdCompiled,sizeof(CPL_CMD_COMPILED));
1030      cmd->isCompiled = TRUE;
1031        if (*readEOF) {
1032                        return CPL_ERROR_OK;
1033           }
1034      break;
1035
1036   case PART_TEXT:
1037        /* read attribute text list */
1038        for (attrIndex = 0; attrIndex < ATTRIBUTE_LIST_QTT; attrIndex++) {
1039                if (cmd->attributeList[attrIndex].text) {
1040                errorCode = cplReadText(program,loadFile,&(cmd->attributeList[attrIndex].text),readEOF);
1041                if (errorCode) return errorCode;
1042        }
1043      }
1044        /* read command text */
1045      if (cmd->text) {
1046                        errorCode = cplReadText(program,loadFile,&(cmd->text),readEOF);
1047                if (errorCode) return errorCode;
1048      }
1049                break;
1050
1051   } /* switch */
1052
1053   /* Return no error */
1054   return CPL_ERROR_OK;
1055
1056} /* cplReadCommand */
1057
1058/* ================================================================= cplRead */
1059CPL_ERROR cplRead(CPL_STRUCT *program,          /* program structure */
1060                                                FILE *loadFile,                 /* load file pointer */
1061                                        CPL_COMMAND **first,            /* first command of the list */
1062                                                CPL_CMD_LIST *cmdList,  /* command list */
1063                  BOOLEAN *readEOF)                     /* enf of file flag */
1064{
1065   CPL_COMMAND cmd;                                     /* command structure */
1066   CPL_CMD_LIST subCmdList;             /* sub-command list */
1067   CPL_COMMAND *loadedCmd;                      /* loaded command structure pointer */
1068        CPL_ERROR errorCode;                            /* error code */
1069
1070   /* Start variables */
1071   *first = NULL;
1072        memset(&cmd,0x00,sizeof(CPL_COMMAND));
1073        memset(cmdList,0x00,sizeof(CPL_CMD_LIST));
1074
1075   /* All list commands */
1076        do {
1077
1078        /* Read command */
1079        errorCode = cplReadCommand(program,loadFile,1,&cmd,readEOF);
1080      if (errorCode) return errorCode;
1081      if (*readEOF) break;
1082
1083        /* Load command */
1084      loadedCmd = cplLoadCommand(&cmd,cmdList);
1085                if (errorCode) return errorCode;
1086
1087                /* Load sub-command */
1088      if (loadedCmd->sub) {
1089                        errorCode = cplRead(program,loadFile,&(loadedCmd->sub),&subCmdList,readEOF);
1090                if (errorCode) return errorCode;
1091      }
1092
1093   } while (!(*readEOF) && loadedCmd->next);
1094
1095   /* Set return command */
1096   *first = cmdList->first;
1097
1098   /* Return no error */
1099        return CPL_ERROR_OK;
1100
1101} /* cplRead */
1102
1103/* ========================================================= cplReadTextList */
1104CPL_ERROR cplReadTextList(CPL_STRUCT *program,  /* program structure */
1105                                                                  FILE *loadFile,                       /* load file pointer */
1106                          CPL_COMMAND *cmd,             /* command structure */
1107                          BOOLEAN *readEOF)             /* enf of file flag */
1108{
1109        CPL_ERROR errorCode;                            /* error code */
1110
1111   /* All list commands */
1112        for ( ; cmd; cmd = cmd->next) {
1113
1114        /* Read command */
1115        errorCode = cplReadCommand(program,loadFile,PART_TEXT,cmd,readEOF);
1116      if (errorCode) return errorCode;
1117      if (*readEOF) break;
1118
1119        /* Load sub-command */
1120      if (cmd->sub) {
1121                errorCode = cplReadTextList(program,loadFile,cmd->sub,readEOF);
1122        if (errorCode) return errorCode;
1123        if (*readEOF) break;
1124      }
1125
1126   } /* for */
1127
1128   /* Return no error */
1129        return CPL_ERROR_OK;
1130
1131} /* cplReadTextList */
1132
1133/* ========================================================= cplLoadCompiled */
1134CPL_ERROR cplLoadCompiled
1135(
1136        char *loadFileName,             /* load file name */
1137        CPL_STRUCT *program,            /* program structure */
1138        CPL_COMMAND **cmd,              /* command structure */
1139        CPL_CMD_LIST *cmdList   /* command list */
1140)
1141{
1142   FILE *loadFile;                      /* file pointer */
1143        BOOLEAN readEOF;                        /* enf of file flag */
1144        CPL_ERROR errorCode;            /* error code */
1145
1146   /* Open for binary read */
1147        loadFile = fopen(loadFileName,"rb");
1148        if (!loadFile) return cplError(program,CPL_ERROR_FILE,loadFileName);
1149
1150   /* Start compiler variables */
1151        cplStart(program);
1152
1153   /* Read compiled header */
1154        errorCode = cplReadCommand(program,loadFile,PART_HEADER,NULL,&readEOF);
1155   if (!errorCode && readEOF) errorCode = cplError(program,CPL_ERROR_INVALID,loadFileName);
1156
1157   /* Read command instructions */
1158   if (!errorCode) {
1159           errorCode = cplRead(program,loadFile,cmd,cmdList,&readEOF);
1160        if (!errorCode && readEOF) errorCode = cplError(program,CPL_ERROR_INVALID,loadFileName);
1161        }
1162
1163   /* Read text strings */
1164   if (!errorCode) {
1165           errorCode = cplReadTextList(program,loadFile,*cmd,&readEOF);
1166   }
1167
1168   /* Close writed file */
1169        fclose(loadFile);
1170
1171   /* Return error code */
1172   return errorCode;
1173
1174}  /* cplLoadCompiled */
1175
1176/* ================================================================= cplFree */
1177void cplFree(CPL_COMMAND *first)                /* first command */
1178{
1179   CPL_COMMAND *cmd;            /* current command */
1180   CPL_COMMAND *next;   /* next command */
1181   CPL_ATTRIBUTE i;             /* auxiliary loop index */
1182
1183   /* Garbage collector */
1184        for (cmd = first; cmd; cmd = next) {
1185                next = cmd->next;
1186      for (i = 0; i < ATTRIBUTE_LIST_QTT; i++)
1187        efc_free(cmd->attributeList[i].text);
1188      efc_free(cmd->text);
1189      if (cmd->sub) cplFree(cmd->sub);
1190      efc_free(cmd);
1191   } /* for */
1192
1193} /* cplFree */
Note: See TracBrowser for help on using the browser.