2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: parser.c /main/8 1996/03/25 09:14:08 rswiston $ */
24 /***************************************************************************/
28 /***************************************************************************/
41 /***************************************************************************
43 * Local procedure declarations
45 ***************************************************************************/
48 char ** GetKeywordValuePairs(char *, int *, int);
49 FiletypeData ** GetFiletypeData(FILE *, char *, short *);
50 char ** ProcessExecString(char *);
51 int ProcessContents(FiletypeData *);
52 Boolean IsLastSingle(char *);
55 /***************************************************************************
57 * Extern variable declarations
59 ***************************************************************************/
62 /***************************************************************************
64 * Global variable declarations
66 ***************************************************************************/
68 /* Action Keyword Table */
69 char keywordDB[][30] = { "ACTION" ,
80 /* Max Number of fields in Action Keyword Table */
81 #define MAX_NUM_ACTION_FIELDS 8
83 /* Filetype Keyword Table */
84 char FiletypekeywordDB[][30] = { "DATA_ATTRIBUTES" ,
93 "DATA_ATTRIBUTES_NAME" ,
104 /* Max Number of fields in Filetype Keyword Table */
105 #define MAX_NUM_FILETYPE_FIELDS 17
108 char *args[3],*fline;
110 static int state = 0;
113 /*****************************************************************
115 ** GetActionData(FILE *fp, ActionData *) **
117 ** Description: Parses the action file and fills the data in the**
118 ** pointer pointing to the ActionData structure **
119 ** passed as input. **
121 ** Input : Filepointer that points to the ActionFile and, **
122 ** a pointer to the ActionData structure. **
124 ** Output : 0 (No error). **
127 ** references : dtcreate.h, parser.h, and dtcreate spec. **
129 ******************************************************************/
133 GetActionData(FILE *fp, ActionData *ActionDataptr)
135 int rc,manflds=0,len,first=TRUE,lastfld=0,fldid=-1;
136 char linebuf[1024],**wordPairs,**execstr;
139 /* reset the read pointer to zero byte for fp */
141 /* Initialize the ActionData structure passed */
143 memset(ActionDataptr,
144 0,sizeof(ActionData));
147 printf("ActionDataptr is NULL\n");
152 /* initialize the linebuf with NULL's */
153 bzero(linebuf,sizeof(linebuf));
154 while (fgets (linebuf, sizeof (linebuf)-1, fp))
156 /* skip the complete line if it starts with a '{' or a comment ('#') */
157 if(linebuf[0] == '{' || linebuf[0] == '#') continue;
158 /* If the first character is '}' reached the end of Action Stanza so quit */
159 if(linebuf[0] == '}')
161 len = strlen (linebuf);
162 if (linebuf[len-1] == '\n')
163 linebuf[len-1] = '\0';
164 /* Get the keyword and value pair from the string linebuf */
165 /* On return, wordPairs[0] = keyword like ICON
166 and wordPairs[1] = value for the keyword
168 if( (wordPairs = GetKeywordValuePairs(linebuf,&fldid,ACTION_TABLE)) != NULL)
170 if( first && strcmp(wordPairs[0],"ACTION") )
173 printf("first && strcmp(wordPairs[0],ACTION)\n");
179 /* Update the mandatory fields counter */
180 if( !strcmp(wordPairs[0],"TYPE") ||
181 !strcmp(wordPairs[0],"EXEC_STRING") ||
182 !strcmp(wordPairs[0],"WINDOW_TYPE") )
184 if( !strcmp(wordPairs[0],"WINDOW_TYPE") )
186 if( !strcmp(wordPairs[1],"PERM_TERMINAL") )
187 ActionDataptr->fsFlags |= CA_WT_PERMTERM;
188 if( !strcmp(wordPairs[1],"TERMINAL") )
189 ActionDataptr->fsFlags |= CA_WT_TERM;
190 if( !strcmp(wordPairs[1],"NO_STDIO") )
191 ActionDataptr->fsFlags |= CA_WT_XWINDOWS;
193 if( !strcmp(wordPairs[0],"ARG_TYPE") )
194 ActionDataptr->fsFlags |= CA_DF_ONLYFTFILES;
196 /* if linebuf does not contain the keyword then everything
197 in wordPairs[0],else, wordPairs[0] contains the keyword
198 and wordpairs[1] contains the value.
200 if( wordPairs && wordPairs[0] && !wordPairs[1])
202 /* fldid is returned by the GetKeywordValuePairs function.
203 This id determines which field of the ActionDataptr will
204 have the value. Please see KeywordDB array in parser.h
209 case 7: /* next line for action_name */
210 ActionDataptr->pszName=wordPairs[0];
213 case 1: /* next line for action_icon_name */
214 ActionDataptr->pszIcon=wordPairs[0];
217 case 2 : /* next line for exec_string */
218 ActionDataptr->pszCmd=wordPairs[0];
221 case 3: /* next line for action_help_text */
222 ActionDataptr->pszHelp=wordPairs[0];
228 else if(wordPairs && wordPairs[1])
230 if(fldid >= 0 && fldid <=2)
232 /* for fldid see the comments above */
235 case 7: /* first line for action_name */
236 ActionDataptr->pszName=wordPairs[1];
239 case 1: /* first line for action_icon_name */
240 ActionDataptr->pszIcon=wordPairs[1];
243 case 2 : /* first line for exec_string */
244 ActionDataptr->pszCmd=wordPairs[1];
247 case 3: /* first line for action_help_text */
249 ActionDataptr->pszHelp=wordPairs[1];
252 default: state=0;break;
256 /* reset the linebuf to NULL's */
257 bzero(linebuf,sizeof(linebuf));
262 /* Done with retrieving Action Data */
263 /* Check if we got all the mandatory fields data */
266 printf("if(manflds != 3)\n");
271 /* Everything looks right so process the exec_string */
272 if( !(execstr = ProcessExecString(ActionDataptr->pszCmd)) )
274 ActionDataptr->pszCmd = NULL;
275 ActionDataptr->pszPrompt = 0;
279 ActionDataptr->pszCmd = execstr[0];
280 ActionDataptr->pszPrompt = execstr[1];
283 /* Got the ActionData,so, go get the FiletypeData */
284 ActionDataptr->papFiletypes =
285 (FiletypeData **) GetFiletypeData(fp,(char *)(ActionDataptr->pszCmd),
286 (short *)&(ActionDataptr->cFiletypes) );
287 if( !ActionDataptr->papFiletypes && ActionDataptr->cFiletypes > 0) {
289 printf("!ActionDataptr->papFiletypes && ActionDataptr->cFiletypes > 0)\n");
291 return(1); /* return 1 if error */
293 return(0); /* return 0 if no error */
299 /*****************************************************************
301 ** GetFiletypeData(FILE *fp, char *pszOpenCmd) **
303 ** Description: Parses the action file and returns a pointer **
304 ** that points to the data in the form of **
305 ** FiletypeData structure (defined in dtcreate.h). **
307 ** Input : Filepointer that points to the ActionFile, and, **
308 ** a char pointer to the exec_string of the **
309 ** ActionData structure as obtained in the GetAc- **
310 ** -tionData function call. **
312 ** Output : Pointer to an array of FiletypeData structures **
313 ** containing data for all the Filetypes,and,no of **
316 ** references : dtcreate.h, parser.h, and dtcreate spec. **
318 ******************************************************************/
321 GetFiletypeData(FILE *fp, char *pszOpenCmd, short *nftypes)
323 int manflds=0,len,nfiletypes,previous=0,lastfld=0,fldid;
324 char linebuf[1024],**wordPairs,**execstr;
325 FiletypeData **ppFiletypeData,**ppnewFiletypeData;
331 /* Initialize the linebuf */
332 bzero(linebuf,sizeof(linebuf));
333 while (fgets (linebuf, sizeof (linebuf)-1, fp))
335 /* If begin of a stanza skip and continue */
336 if(linebuf[0] == '{')
341 /* skip the rest of the line if a comment found */
342 if(linebuf[0] == '#') continue;
344 /* If end of a stanza check if all the mandatory fields are there */
345 if( linebuf[0] == '}' )
347 /* Check for atleast one field in DATA_ATTRIBUTES stanza */
348 if( previous == DATA_ATTRIBUTES && manflds != 1 )
350 printf("Error in DATA_ATTR stanza of the FiletypeData\n");
353 /* Check for atleast one field in DATA_CRITERIA stanza */
354 else if( previous == DATA_CRITERIA && manflds != 1 )
356 printf("Error in DATA_CRITERIA stanza of the FiletypeData\n");
359 /* Check for atleast two fields in ACTION_OPEN or ACTION_PRINT stanza */
360 else if( (previous == ACTION_OPEN || previous == ACTION_PRINT) )
364 printf("Error in ACTION_OPEN/PRINT stanza of the FiletypeData\n");
368 /* Check for atleast three fields in ACTION_PRINT_FTYPE stanza */
369 else if( previous == ACTION_PRINT_FTYPE && manflds != 3 )
371 printf("Error in ACTION_PRINT_FTYPE stanza of the FiletypeData\n");
376 len = strlen (linebuf);
377 if (linebuf[len-1] == '\n')
378 linebuf[len-1] = '\0';
380 if( (wordPairs = GetKeywordValuePairs(linebuf,&fldid,FILETYPE_TABLE)) != NULL)
382 if( !strcmp(wordPairs[0],"DATA_ATTRIBUTES") )
387 /* Allocate a filetypedata pointer to an array of filetypedata records */
390 if( (ppFiletypeData = (FiletypeData **)calloc(1,sizeof(FiletypeData *)))
393 printf("\n Cannot allocate memory\n");
396 /* Allocate a filetypedata record */
399 if( (ppFiletypeData[nfiletypes] =
400 (FiletypeData *)calloc(1,sizeof(FiletypeData)) )
403 printf("\n Cannot allocate memory\n");
409 ppFiletypeData[nfiletypes]->pszOpenCmd = pszOpenCmd;
410 previous = DATA_ATTRIBUTES;
413 else if(previous == ACTION_OPEN || previous == ACTION_PRINT)
415 /* New filetypedata started so allocate a new filetypedata ptr */
416 if( (ppnewFiletypeData =
417 (FiletypeData **)realloc((FiletypeData *)ppFiletypeData,
418 nfiletypes+2 * sizeof(FiletypeData *)))
421 printf("\n Cannot allocate memory\n");
424 else if(ppFiletypeData)
426 ppFiletypeData=ppnewFiletypeData;
427 /* Process the contents field if any */
428 if(ProcessContents((FiletypeData *)ppFiletypeData[nfiletypes]) < 0 )
430 printf("\n Error in Contents Data\n");
433 /* Everything looks right so process the exec_string */
434 if( !(execstr = ProcessExecString((char *)ppFiletypeData[nfiletypes]->pszPrintCmd)) )
435 ppFiletypeData[nfiletypes]->pszPrintCmd=NULL;
437 ppFiletypeData[nfiletypes]->pszPrintCmd=execstr[0];
441 /* Allocate a new filetypedata record */
442 if( (ppFiletypeData[nfiletypes] =
443 (FiletypeData *)calloc(1,sizeof(FiletypeData)) )
446 printf("\n Cannot allocate memory\n");
449 ppFiletypeData[nfiletypes]->pszOpenCmd = pszOpenCmd;
450 previous = DATA_ATTRIBUTES;
457 printf("Error in filetypedata \n");
461 else if( !strcmp(wordPairs[0],"DATA_CRITERIA") )
463 if( previous == DATA_ATTRIBUTES )
465 previous = DATA_CRITERIA;
470 printf("Error in filetypedata \n");
474 else if( !strcmp(wordPairs[0],"ACTION") && !strcmp(wordPairs[1],"Open") )
476 if( previous == DATA_CRITERIA )
478 previous = ACTION_OPEN;
483 printf("Error in filetypedata \n");
487 else if( !strcmp(wordPairs[0],"ACTION") && strcmp(wordPairs[1],"Open") &&
488 strcmp(wordPairs[1], "Print") )
490 if( previous == ACTION_OPEN )
492 previous = ACTION_PRINT_FTYPE;
497 printf("Error in filetypedata \n");
501 else if( !strcmp(wordPairs[0],"ACTION") && !strcmp(wordPairs[1],"Print") )
503 if( previous == ACTION_PRINT_FTYPE )
505 previous = ACTION_PRINT;
510 printf("Error in filetypedata \n");
516 /* update mandatory fields counter */
517 if( previous == DATA_ATTRIBUTES && strcmp(wordPairs[0],"DATA_ATTRIBUTES") )
519 if( !strcmp(wordPairs[0],"ACTIONS") )
522 else if( previous == DATA_CRITERIA )
524 if( !strcmp(wordPairs[0],"DATA_ATTRIBUTES_NAME") )
527 else if( previous == ACTION_OPEN || previous == ACTION_PRINT )
529 if( !strcmp(wordPairs[0],"ARG_TYPE") ||
530 !strcmp(wordPairs[0],"TYPE") ||
531 !strcmp(wordPairs[0],"MAP_ACTION") ||
532 !strcmp(wordPairs[0],"LABEL") )
535 else if( previous == ACTION_PRINT_FTYPE )
537 if( !strcmp(wordPairs[0],"TYPE") ||
538 !strcmp(wordPairs[0],"WINDOW_TYPE") )
546 if( wordPairs && !wordPairs[1] && wordPairs[0])
550 case 0: /* next line for filetype_name */
551 ppFiletypeData[nfiletypes]->pszName=wordPairs[0];
554 case 1: /* next line for icon_name */
555 ppFiletypeData[nfiletypes]->pszIcon=wordPairs[0];
558 case 2 : /* next line for help_text */
559 ppFiletypeData[nfiletypes]->pszHelp=wordPairs[0];
562 case 3: /* next line for print_cmd */
563 ppFiletypeData[nfiletypes]->pszPrintCmd=wordPairs[0];
566 case 4: /* next line for name_pattern or path_pattern */
567 ppFiletypeData[nfiletypes]->pszPattern=wordPairs[0];
569 case 5: /* next line for name_pattern or path_pattern */
570 ppFiletypeData[nfiletypes]->pszPattern=wordPairs[0];
572 case 6: /* next line for mode */
573 ppFiletypeData[nfiletypes]->pszPermissions=wordPairs[0];
575 case 7: /* next line for contents */
576 ppFiletypeData[nfiletypes]->pszContents=wordPairs[0];
582 else if(wordPairs && wordPairs[1])
586 case 0: /* first line for filetype_name */
587 ppFiletypeData[nfiletypes]->pszName = wordPairs[1];
590 case 1: /* first line for icon_name */
591 ppFiletypeData[nfiletypes]->pszIcon=wordPairs[1];
594 case 2 : /* first line for help_text */
595 ppFiletypeData[nfiletypes]->pszHelp=wordPairs[1];
598 case 3: /* first line for print_cmd */
599 ppFiletypeData[nfiletypes]->pszPrintCmd=wordPairs[1];
603 case 4: /* first line for name_pattern or path_pattern */
604 ppFiletypeData[nfiletypes]->pszPattern=wordPairs[1];
607 case 5: /* first line for name_pattern or path_pattern */
608 ppFiletypeData[nfiletypes]->pszPattern=wordPairs[1];
611 case 6: /* first line for mode */
612 ppFiletypeData[nfiletypes]->pszPermissions=wordPairs[1];
615 case 7: /* first line for contents */
616 ppFiletypeData[nfiletypes]->pszContents=wordPairs[1];
624 bzero(linebuf,sizeof(linebuf));
625 } /* end of while fgets */
627 /* Done with retrieving FiletypeData */
628 /* Check if we got all the mandatory fields data */
629 if( (previous == ACTION_OPEN && manflds != 4) ||
630 (previous == ACTION_PRINT && manflds != 4) )
632 else if(ppFiletypeData)
634 /* Process Contents for the last file filetype if any */
635 if(ProcessContents((FiletypeData *)ppFiletypeData[nfiletypes]) < 0)
637 printf("\n Error in Contents Data\n");
640 /* Everything looks right so process the exec_string */
642 ProcessExecString((char *)ppFiletypeData[nfiletypes]->pszPrintCmd)) )
643 ppFiletypeData[nfiletypes]->pszPrintCmd=NULL;
645 ppFiletypeData[nfiletypes]->pszPrintCmd=execstr[0];
646 if( !ppFiletypeData[nfiletypes])
647 ppFiletypeData[nfiletypes] = 0;
648 /* return number of filetypes */
649 *nftypes = nfiletypes+1;
650 return ppFiletypeData;
658 /*****************************************************************
660 ** GetKeywordValuePairs(char *s, int *id, int table) **
662 ** Description: Parses the text string in *s and returns a **
663 ** pointer to two strings that are Keyword and **
664 ** values.However, it returns the complete string **
665 ** in the first pointer if keyword not found. **
667 ** Input : A character pointer pointing to text string. **
668 ** An integer pointer to return the field id. **
669 ** An integer value that determines which table to **
670 ** use (either ACTION_TABLE of FILETYPE_TABLE). **
671 ** see definitions in parser.h **
673 ** Output : pointer to two pointers pointing to text strings**
674 ** fieldid in the id parameter. **
676 ** references : dtcreate.h, parser.h, and dtcreate spec. **
678 ******************************************************************/
681 GetKeywordValuePairs(char *s, int *id, int table)
687 args[0] = args[1] = args[2] = NULL;
688 /* Skip all leading spaces */
689 while (*s && isspace (*s))
691 /* Skip the complete line if a '#' character is found (comments) */
692 if (!*s || *s == '#')
695 while (*s && *s != '#' && !isspace (*s))
699 int szArgs0 = s - wordStart + 1;
700 args[0] = (char *)malloc (szArgs0);
703 memset(args[0],0,szArgs0);
705 strncpy (args[0], wordStart, s - wordStart);
706 args[0][s-wordStart] = '\0';
709 int szArgs1 = strlen(s) + 1;
711 args[1] = (char *)malloc (szArgs1);
718 memset(args[1],0,szArgs1);
720 /* Skip all leading spaces */
721 while (*s && isspace (*s))
725 /* Check for whether args[0] is a keyword or not */
727 if( table == ACTION_TABLE )
729 /* Check for keyword in keywordDB defined in parser.h */
730 while((strcmp(keywordDB[idx],"")) && (strcmp(args[0],keywordDB[idx])) ) idx++;
731 if(idx >= 0 && idx < MAX_NUM_ACTION_FIELDS)
734 else if( table == FILETYPE_TABLE )
736 /* Check for keyword in FiletypekeywordDB defined in parser.h */
737 while((strcmp(FiletypekeywordDB[idx],"")) && (strcmp(args[0],FiletypekeywordDB[idx])) ) idx++;
738 if(idx >= 0 && idx < MAX_NUM_FILETYPE_FIELDS)
741 /* If no keyword found then keep the complete string
744 if( (idx == MAX_NUM_ACTION_FIELDS && table == ACTION_TABLE) ||
745 (idx == MAX_NUM_FILETYPE_FIELDS && table == FILETYPE_TABLE) )
749 if( (temp4 = (char *)realloc(args[0],strlen(args[0])+strlen(args[1])+2) ) == NULL )
751 printf("Cannot Allocate memory\n");
756 strcat(args[0],args[1]);
763 if( IsLastSingle(args[0]) && args[0][strlen(args[0])-1] == '\\' )
764 args[0][strlen(args[0])-1] = '\0';
765 if( (temp4 = (char *)realloc(fline,flinesize+strlen(args[0])+1)) == NULL)
767 printf("Cannot Allocate memory\n");
770 strcat(temp4,args[0]);
775 *id = fldid; /* return field id */
776 if(args[1] && IsLastSingle(args[1]) && args[1][strlen(args[1])-1] == '\\')
777 args[1][strlen(args[1])-1] = '\0';
779 args[0][strlen(args[0])] = '\0';
781 args[1][strlen(args[1])] = '\0';
782 if(args[0] && args[1])
785 flinesize=strlen(fline);
787 if(!args[1] && args[0])
790 flinesize=strlen(fline);
796 /*****************************************************************
798 ** ProcessExecString(char *) **
800 ** Description: Parses the text string and returns two pointers,**
801 ** the first pointing to cmd part (if any) **
802 ** the second pointing to prompt part (if any) **
803 ** of either the ActionData structure type or **
804 ** FiletypeData structure type. Please see **
805 ** dtcreate.h for the above mentioned datastructure**
806 ** definitions and for the cmd and prompt fields **
808 ** Input : A character pointer that points to the complete **
809 ** text string comprising the command and arguments**
810 ** and prompt (if any). **
812 ** Limitation : Supports only ONE prompt. **
814 ** Output : Pointer to 3-element result array from malloc, **
815 ** or NULL on error **
817 ** Assumptions: a) Arg fields start with a '%' character. **
818 ** b) Prompt string start and end with '"' chara- **
819 ** cter. Also, the prompt string comes after **
820 ** the Arg strings if any. **
822 ** references : dtcreate.h, parser.h, and dtcreate spec. **
824 ******************************************************************/
827 ProcessExecString(char *cmd)
830 char *s1, *s2,*s3,*s4,*argbuf,**exec_args;
831 int done=FALSE, argfound=FALSE,promptfound=FALSE;
834 return((char **)NULL);
836 s1=s2=s3=s4=argbuf=NULL;
837 exec_args = calloc(3, sizeof(char*));
838 if (!exec_args) return NULL;
839 /* Allocate buffer for the cmd string */
840 exec_args[0] = (char *)calloc(1,strlen(cmd)+1);
841 exec_args[1] = exec_args[2] = NULL;
842 /* check if any Args present */
848 s4 = strstr(s1,"%Arg");
853 strncat(exec_args[0],s1,(s4-s1));
854 exec_args[0][strlen(exec_args[0])] = '\0';
857 s2 = strchr(s1+1,'%'); /* at this point we got s1 to s2
858 covers the complete string
861 if(argbuf) { free(argbuf); argbuf = NULL; }
864 argbuf = (char *)calloc(1,(s2-s1)+2);
865 strncpy(argbuf,s1,(s2-s1)+1);
869 strcat(exec_args[0],s1);
873 argbuf[strlen(argbuf)]='\0';
874 if( strncmp(argbuf,"%Arg_",5) &&
875 strncmp(argbuf,"%Args%",6) &&
876 strncmp(argbuf,"%Args\"",6) )
878 strncat(exec_args[0],argbuf,strlen(argbuf)-1);
879 exec_args[0][strlen(exec_args[0])] = '\0';
886 strcat(exec_args[0],s1);
887 if(argbuf) { free(argbuf); argbuf = NULL; }
897 /* move s1 until a '_' or 's' */
898 tmp = strchr(argbuf,'_');
900 tmp= strchr(argbuf,'s');
901 strcat(exec_args[0],"$");
903 /* start of Arg processing */
904 while (*tmp != '%' && *tmp != '"' )
908 strcat(exec_args[0],"*");
911 if( *tmp > '0' && *tmp <= '9')
913 strncat(exec_args[0],tmp,1);
914 exec_args[0][strlen(exec_args[0])] = '\0';
918 /* end of Arg processing */
920 /* Get Prompt string if any */
921 s3 = strchr(argbuf,'"');
922 if(s3 && *(s3+1) != '"')
927 if( (tmp = strchr(s3,'"')) )
930 exec_args[1] = (char *)calloc(1,(tmp-s3)+1);
931 strncpy(exec_args[1],s3,(tmp-s3));
932 exec_args[1][strlen(exec_args[1])] = '\0';
937 /* see if there is some stuff between the last '%'
938 and the next first '%' of another Arg
944 if(argbuf) { free(argbuf); argbuf = NULL; }
948 /*****************************************************************
950 ** ProcessContents(FiletypeData *) **
952 ** Description: Parses the text string in pszContents field and **
953 ** fills the sStart,fsFlags and pszContents fields **
954 ** of the filetypeData datastructure that is passed**
957 ** Input : A pointer of type FiletypeData defined in **
960 ** Output : Fills the sStart, fsFlags and pszContents fields**
961 ** of the FiletypeData pointer and returns 0 (No **
962 ** error or >0 (error) values. **
964 ** Assumptions: Fields are separated by atleast one blank **
967 ** references : dtcreate.h, parser.h, and dtcreate spec. **
969 ******************************************************************/
972 ProcessContents(FiletypeData *pFtD)
975 char *s1,*tmp,*s2,buf[10],*cts;
978 bzero(buf,sizeof(buf));
979 /* simply return if there is no data in contents field */
980 if(!pFtD->pszContents)
982 cts = (char *)calloc(1,strlen(pFtD->pszContents)+1);
983 strcpy(cts,pFtD->pszContents);
985 free(pFtD->pszContents);
986 pFtD->pszContents=NULL;
987 /* Skip all leading spaces */
988 while( *s1 && isspace(*s1) ) s1++;
989 /* Get the sStart value if any */
991 if( (s1 = strchr(cts,' ')) )
993 while( *s1 && !isspace(*s1) && *s1 != '\n') s1++;
996 strncpy(buf,cts,(s1-cts));
998 pFtD->sStart=atoi(buf);
1000 while( *s1 && isspace(*s1) ) s1++;
1002 /* Get the fsFlags value if any */
1004 bzero(buf,sizeof(buf));
1006 if ( (tmp = strchr(s1,' ')) )
1008 while( *tmp && !isspace(*tmp) && *tmp != '\n') tmp++;
1011 strncpy(buf,s1,(tmp-s1));
1013 if ( !strcmp(buf,"byte") )
1014 pFtD->fsFlags|=CA_FT_CNTBYTE;
1015 else if ( !strcmp(buf,"string") )
1016 pFtD->fsFlags|=CA_FT_CNTSTRING;
1017 else if ( !strcmp(buf,"long") )
1018 pFtD->fsFlags|=CA_FT_CNTLONG;
1019 else if ( !strcmp(buf,"short") )
1020 pFtD->fsFlags|=CA_FT_CNTSHORT;
1024 while( *tmp && isspace(*tmp) ) tmp++;
1026 /* Get the contents if any */
1029 pFtD->pszContents = (char *)calloc(1,strlen(s2)+1);
1030 strcpy(pFtD->pszContents,s2);
1039 /*****************************************************************
1041 ** IsLastSingle(char *str) **
1043 ** Description: returns TRUE if the last character of the **
1044 ** string str is a single-byte character, returns **
1045 ** FALSE if it is a multi-byte character. **
1047 ******************************************************************/
1050 IsLastSingle(char *str)
1058 n = mblen(str, MB_CUR_MAX);