00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <dirent.h>
00026 #include <sys/stat.h>
00027 #include <sys/types.h>
00028 #include <errno.h>
00029 #include <string.h>
00030
00031 #include <glib.h>
00032
00033 #include <libermanifest/ermanifest.h>
00034
00035 #include "contentListerLog.h"
00036 #include "erMdsContent.h"
00037
00038 #define DISPLAY_ITEMS 6
00039
00040
00041 void usage()
00042 {
00043 fprintf(stderr, "Usage:\n");
00044 fprintf(stderr, " -r : search recursively\n");
00045 fprintf(stderr, " -d <dir1> [can be repeated multiple times]\n");
00046 fprintf(stderr, " -m <field-type> <pattern> : only include files that match pattern\n");
00047 fprintf(stderr, " [can be repeated multiple times]\n");
00048 fprintf(stderr,
00049 " -c : only include files that match all patterns (specified with -m option) (default = one pattern)\n");
00050 fprintf(stderr, " -s <field-type> : sort according to <field-type>\n");
00051 fprintf(stderr, " : i.e. one off author, date, description, file, title, fsname\n");
00052 fprintf(stderr, " -a : sort ascending (default = descending )\n");
00053 }
00054
00055
00056
00057
00058 int main(int argc, char *argv[])
00059 {
00060 GArray *contentItemArray = NULL;
00061
00062
00063 GArray *dirArray;
00064 mdsFsItem_t *pFsItem;
00065 mdsSortStruct_t sortStruct;
00066 mdsDirectory_t dirStruct;
00067 int i;
00068 FILE *pOutput = NULL;
00069 int nArg = 1;
00070 int nRetContentScan;
00071
00072 dirArray = g_array_new(FALSE, FALSE, sizeof(mdsDirectory_t));
00073 sortStruct.ascending = 0;
00074 sortStruct.ft = mdsFieldNone;
00075
00076
00077
00078
00079 if (argc > 1)
00080 {
00081 while (nArg < argc)
00082 {
00083 if (argv[nArg][0] == '-')
00084 {
00085 switch (argv[nArg][1])
00086 {
00087 case 'h':
00088 usage();
00089 return 0;
00090 break;
00091
00092 case 'a':
00093 sortStruct.ascending = 1;
00094 nArg++;
00095 break;
00096
00097 case 'd':
00098
00099 if (++nArg >= argc)
00100 {
00101
00102 fprintf(stderr, "Supply a directory name after option -d");
00103 usage();
00104 return -1;
00105 }
00106 else
00107 {
00108
00109 strcpy(dirStruct.szFilename, argv[nArg]);
00110 g_array_append_val(dirArray, dirStruct);
00111 nArg++;
00112 }
00113 break;
00114
00115 case 's':
00116
00117 if (++nArg >= argc)
00118 {
00119
00120 fprintf(stderr, "Supply a field type after option -s\n");
00121 usage();
00122 return -1;
00123 }
00124 else
00125 {
00126
00127 if (strcmp("author", argv[nArg]) == 0)
00128 sortStruct.ft = mdsFieldAuthor;
00129 else if (strcmp("date", argv[nArg]) == 0)
00130 sortStruct.ft = mdsFieldDate;
00131 else if (strcmp("description", argv[nArg]) == 0)
00132 sortStruct.ft = mdsFieldDescription;
00133 else if (strcmp("file", argv[nArg]) == 0)
00134 sortStruct.ft = mdsFieldFile;
00135 else if (strcmp("title", argv[nArg]) == 0)
00136 sortStruct.ft = mdsFieldTitle;
00137 else if (strcmp("fsname", argv[nArg]) == 0)
00138 sortStruct.ft = mdsFieldFsName;
00139 else
00140 {
00141
00142 fprintf(stderr, "Sort field type %s is unknown (after option -s)\n", argv[nArg]);
00143 usage();
00144 return -1;
00145 }
00146 nArg++;
00147 }
00148 break;
00149
00150 default:
00151 fprintf(stderr, "Option %s not known.\n", argv[nArg]);
00152 usage();
00153 return -1;
00154 }
00155 }
00156 else
00157 {
00158 fprintf(stderr, "Argument supplied not proceded by option.\n");
00159 usage();
00160 return -1;
00161 }
00162 }
00163 }
00164 else
00165 {
00166 usage();
00167 return -1;
00168 }
00169
00170 pOutput = fopen("testContentScan.txt", "w");
00171 if (pOutput == NULL)
00172 {
00173 CL_ERRORPRINTF("Could not open file testContentScan.txt");
00174 }
00175
00176
00177 contentItemArray = NULL;
00178
00179 CL_ERRORPRINTF("dirArray->len = %d", dirArray->len);
00180
00181 nRetContentScan = erMdsContentScan(dirArray, &contentItemArray);
00182
00183 CL_WARNPRINTF("Basic test of erMdsContentScan");
00184 for (i = 0; i < contentItemArray->len; i++)
00185 {
00186 pFsItem = &g_array_index(contentItemArray, mdsFsItem_t, i);
00187 printf("Filename: %s", pFsItem->szFilename);
00188 printf("\tFile Item Type: %d\n", (int) pFsItem->fit);
00189 }
00190
00191
00192
00193 if (sortStruct.ft != mdsFieldNone)
00194 {
00195 erMdsContentSort(contentItemArray, &sortStruct);
00196 }
00197
00198 CL_WARNPRINTF("Basic test of erClGetDisplayItems");
00199
00200 for (i = 0; i < contentItemArray->len; i += DISPLAY_ITEMS)
00201 {
00202 int nChunk = DISPLAY_ITEMS;
00203 clDisplayItem_t displayItemArray[DISPLAY_ITEMS];
00204 int nBegin = i;
00205 int nRet;
00206
00207 nRet = erClGetDisplayItems(contentItemArray, nBegin, &nChunk, displayItemArray);
00208 switch (nRet)
00209 {
00210 case ERCL_INVALID_ARGS:
00211 CL_ERRORPRINTF("ERCL_INVALID_ARGS");
00212 break;
00213
00214 case ERCL_OK:
00215 CL_ERRORPRINTF("ERCL_OK");
00216 {
00217 int j;
00218
00219 for (j = 0; j < nChunk; j++)
00220 {
00221 fprintf(stderr, "displayItemArray\n");
00222 fprintf(stderr, "fit:%d, ", displayItemArray[j].fit);
00223 fprintf(stderr, "fileName:%s, ", displayItemArray[j].szFilename);
00224 fprintf(stderr, "iconID:%d, ", displayItemArray[j].iconID);
00225 fprintf(stderr, "clIconURL:%s, ", displayItemArray[j].clIconURL);
00226 fprintf(stderr, "szFileExt:%s, ", displayItemArray[j].szFileExt);
00227 fprintf(stderr, "szTitle:%s, ", displayItemArray[j].szTitle);
00228 fprintf(stderr, "szSubTitle:%s, ", displayItemArray[j].szSubTitle);
00229 fprintf(stderr, "szDate:%s, ", displayItemArray[j].szDate);
00230 fprintf(stderr, "szDescription:%s, ", displayItemArray[j].szDescription);
00231
00232 fprintf(stderr, "szManifest:%s\n", displayItemArray[j].szManifest);
00233 if (pOutput != NULL)
00234 {
00235 fprintf(pOutput, "%d\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
00236 displayItemArray[j].fit,
00237 displayItemArray[j].szFilename,
00238 displayItemArray[j].iconID,
00239 displayItemArray[j].clIconURL,
00240 displayItemArray[j].szFileExt,
00241 displayItemArray[j].szTitle,
00242 displayItemArray[j].szSubTitle,
00243 displayItemArray[j].szDate, displayItemArray[j].szDescription,
00244 displayItemArray[j].szManifest);
00245 }
00246 }
00247 }
00248 break;
00249 }
00250 }
00251
00252 if (pOutput != NULL)
00253 fclose(pOutput);
00254
00255
00256 switch (nRetContentScan)
00257 {
00258 case ERMDS_CONTENT_SCAN_FAILED:
00259 fprintf(stderr, "Content Scan failed");
00260 break;
00261
00262 case ERMDS_CONTENT_SCAN_TOO_MANY_ITEMS:
00263 fprintf(stderr, "Content Scan File limit kicked in!\n");
00264 case ERMDS_CONTENT_SCAN_OK:
00265 fprintf(stderr, "Content Scan Retrieved %d items\n", contentItemArray->len);
00266 break;
00267 }
00268
00269 g_array_free(contentItemArray, TRUE);
00270 g_array_free(dirArray, TRUE);
00271 return 0;
00272 }