home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <memory.h>
- #include <stdlib.h>
- #include "fexpand.h"
-
- /*
- * File Template Expander - Example.
- */
-
- void main(int argc, char *argv[]);
- int Filter_It(char *p);
-
- #ifndef TRUE
- #define TRUE 1
- #endif
-
- #ifndef FALSE
- #define FALSE 0
- #endif
-
-
- void main(argc, argv)
- /****************************************************************************/
- /* This program takes the command line (argc/argv) and expands it using FTE */
- /* or it prompts for a string to be used instead. See the usage section. */
- /****************************************************************************/
- int argc;
- char *argv[];
- {
- int i;
-
- int merge = FALSE, filter = FALSE, use_string = FALSE;
- int new_argc;
- char **new_argv;
- char string[256];
-
- /*
- * Look for command line switches.
- */
- for(i=0; i < argc; i++)
- {
- if (*argv[i] == '-')
- {
- if (*(argv[i]+1) == 'm')
- merge = TRUE;
- else
- if (*(argv[i]+1) == 'f')
- filter = TRUE;
- else
- if (*(argv[i]+1) == 's')
- use_string = TRUE;
- else
- {
- printf("Usage: example [-m] [-f] [-s] file_template1\n\t\t[file_template2 ... file_templateN]\n");
- printf("-m Merge across all templates\n");
- printf("-f Use the filter function\n");
- printf("-s Prompt for a string instead of using argc/argv\n");
- exit(-1);
- }
- }
- }
-
- /*
- * String Functions
- */
- if (use_string)
- {
- printf("Enter string: ");
- (void)gets(string);
- if (filter)
- new_argv = FileTemplateExpandFilterString(Filter_It, string,
- FALSE, merge, &new_argc);
- else
- new_argv = FileTemplateExpandString(string, FALSE, merge,
- &new_argc);
- }
-
- /*
- * Array Functions
- */
- else
- {
- if (filter)
- new_argv = FileTemplateExpandFilter(Filter_It, argc, argv,
- TRUE, merge, &new_argc);
- else
- new_argv = FileTemplateExpand(argc, argv, TRUE, merge, &new_argc);
- }
-
-
- /*
- * Print out the result.
- */
- for(i=0; i < new_argc; i++)
- printf("%d\t\"%s\"\n", i, new_argv[i]);
-
- /*
- * Free up the memory
- */
- for(i=0; i < new_argc; i++)
- free(new_argv[i]);
- free(new_argv);
- }
-
-
- /****************************************************************************/
- int Filter_It(char *p)
- /****************************************************************************/
- {
- short int k;
-
- printf("Keep \"%s\" ", p);
- scanf("%d", &k);
-
- return k;
- }
-