예제 #1
0
파일: mails.c 프로젝트: diegocr/YGRip
void FreeGroupFolder(struct ClassData * data, struct GroupFolder ** grp )
{
	DBG_POINTER(grp);
	
	if(data->disposing == TRUE)
		return;
	
	if(grp && *grp)
	{
		FreeIndex( data, grp );
		free((*grp)->YahooGroup);
		free((*grp)->index);
		free((*grp)->unixf);
		free((*grp)->folder);
		free((*grp));
		
		(*grp) = NULL;
	}
}
예제 #2
0
파일: main.c 프로젝트: JimR21/OS-Project1
int main (int argc, char** argv)
{
    int a, pop, sum, k;
    int l, o, c;
    int fd, val;

    MyRecord temprec, r;
    char ch;
    char phoneno[20];
    char town[20];
    char min[20], max[20];
    char word[20];
    l = 0;
    o = 0;
    c = 0;
    char loadFile[20], opFile[20], configFile[20];

    /* Diabasma orismatwn */

    opterr = 0;

    while ((a = getopt (argc, argv, "l:o:c:")) != -1)
        switch (a)
        {
           case 'l':
             strcpy(loadFile, optarg);
             l = 1;
             break;
           case 'o':
             strcpy(opFile, optarg);
             o = 1;
             break;
           case 'c':
             strcpy(configFile, optarg);
             c = 1;
             break;
           case '?':
             if (optopt == 'p' || optopt == 'i' || optopt == 'd')
               fprintf (stderr, "Option -%c requires an argument.\n", optopt);
             else if (isprint (optopt))
               fprintf (stderr, "Unknown option `-%c'.\n", optopt);
             else
               fprintf (stderr,
                        "Unknown option character `\\x%x'.\n",
                        optopt);
             return 1;
           default:
             abort ();
        }

   InitializeI(&start_town);

   /* Xrhsh orismatwn */
    if(c == 1)
    {
        FILE* con;
        con = fopen(configFile,"r");
        if (con == NULL)
        {
            printf("Cannot open configuration file\n");
        }
        else
            while(!feof(con))
            {
                if(fscanf(con, "%s %d", word, &val) == 2)
                    if(strcmp(word, "Hash_Table_Size") == 0)
                    {
                        hashtsize = val;
                        hashtable = malloc(hashtsize*(sizeof(pnode)));
                    }
            }
    }
    if(l == 1)
    {
        Load_file(loadFile);
        l = 0;
    }
     if(o == 1)                     // An uparxei operation file tote to stdin anakateuthunetai sto arxeio ayto k diabazontai oi entoles kanonika mexri na teleiwsei
    {
        if(hashtsize == 0)
        {
            hashtsize = primes(DEFAULT_HASH_SIZE);
            hashtable = malloc(hashtsize*(sizeof(pnode)));
        }
        if( access(opFile, F_OK ) != -1 )
        {
            fd = dup(fileno(stdin));
            freopen(opFile, "r", stdin);
        }
        else
            printf("Cannot open operation file\n");

    }
    memset(max, '0', 20);
    memset(min, '0', 20);
    if(hashtsize == 0)
        {
            hashtsize = primes(DEFAULT_HASH_SIZE);
            hashtable = malloc(hashtsize*(sizeof(pnode)));
        }
    if(o == 0)
        printf("Give input\n");

    /* Epanalipsh gia thn eisagwgh entolwn. Diavasma prwtou xarakthra kai elegxos periptwsewn */
    while(1)
    {


        ch = getchar();
        if(ch == 'i')
        {
            ReadValue(&temprec);
            if(SearchL(temprec.phone, hashtable, hashtsize, &r) == 0)
                InsertL(temprec, hashtable, hashtsize, start_town);
            else
                printf("Number %s already exists. Cannot add the same number twice.\n", temprec.phone);
            //temp_town = start_town;
		}
		else if(ch == 'q')
		{
            scanf("%10s", phoneno);
            if(SearchL(phoneno, hashtable, hashtsize, &r) == 1)
                WriteValue(r);
            else
                printf("Number %s not found.\n", phoneno);
            memset(phoneno, '\0', 20);
		}
		else if(ch == 'd')
		{
            scanf("%10s", phoneno);
            DeleteL(phoneno, hashtable, hashtsize, start_town);
            memset(phoneno, '\0', 20);
		}
		else if(ch == 'l')
        {
            scanf("%s", loadFile);
            Load_file(loadFile);
        }
		else if(ch == 'e')
		{
            FreeIndex(start_town);
            free(start_town);
            free(hashtable);
            return 0;
		}
		else if(ch == 'p')
		{
            scanf("%s", town);
            pop = PopulationI(start_town, town);
            if(pop > 0)
                printf("%s: %d\n", town, pop);
            else
                printf("Town %s not found.\n", town);
            memset(town, '\0', 20);
		}
		else if(ch == 's')
		{
            scanf("%s", town);
            sum = SummaryI(start_town, town);
            if(sum > 0)
                printf("%s: %d\n", town, sum);
            else
                printf("Town %s not found.\n", town);
            memset(town, '\0', 20);
		}
		else if(ch == 't')
		{
            scanf("%d", &k);
            Top(start_town, k);
		}
		else if(ch == 'f')
		{
            ch = getchar();
            if(ch == 't')
            {
                ch = getchar();
                if(ch == ' ')
                {
                    scanf("%s %d", town, &k);
                    TopKSpenders(start_town, town, k);
                }
                else if(ch == 's')
                    TopTownSpenders(start_town);
            }
		}
		else if(ch == 'm')
		{
            ch = getchar();
            if(ch == 'a')
            {
                ch = getchar();
                if(ch == 'x')
                {
                    //if(max[0] == '0')
                        Max(start_town);
                }
            }
            else if(ch == 'i')
            {
                ch = getchar();
                if(ch == 'n')
                {
                   // if(min[0] == '0')
                        Min(start_town);
                }
            }
		}
		//scanf("%20s", junk);
		if(o == 1 && ch == EOF)     // An yparxei operation file san orisma kai exei teleiwsei h anagnwsh epanafora tou stdin.
        {
            fflush(stdin);
            dup2(fd, fileno(stdin));
            close(fd);
            clearerr(stdin);
            o = 0;
            printf("Operation file finished succesfully.\n");
        }
        fflush(stdin);
    }

    return 0;

    }
예제 #3
0
int main( int argc, char **argv )
	{
	char	*args;
	int		i = 0;
	FILE	*op;
	char	filename[MAX_PATH];

	if (argc >= 2)
		{
		for(int i=1; i<argc; i++)
			{
			args = argv[i];
			switch ( args[1] )
				{
				case 'd':
					sprintf(gBaseDir,args + 2);
					break;
				case 'l':
					sprintf(gLangDir,args + 2);
					sprintf(gBaseDir,"D:\\falcon4\\%s\\campaign\\save",gLangDir);
					break;
				default:
					break;
				}
			}
		}
	else
		{
		sprintf(gBaseDir,"D:\\falcon4\\campaign\\save");
		sprintf(gLangDir,"output");
		printf("Working directory: %s",gBaseDir);
//		scanf("%s",baseDir);
		}

	ReadIndex("strings");
	LoadNames("Korea");
	BuildExampleNames();
	sprintf(filename,"%s\\%s.txt",gBaseDir,gLangDir);
	op = fopen(filename,"w");

	while (FilesToRead[i][0])
		{
		ClearTokenList();
		fprintf(op,"\n==============================\n");
		fprintf(op,"FILENAME: %s\n",FilesToRead[i]);
		fprintf(op,"==============================\n");
		printf("\n==============================\n");
		printf("FILENAME: %s\n",FilesToRead[i]);
		printf("==============================\n");
		AnalyseFile(FilesToRead[i]);
		DoFile(FilesToRead[i],op);
		i++;
		}

	FreeIndex();
	FreeNames();
	fclose(op);
	printf("Done! - press <return> to exit\n");
	getchar();

	return 1;
	}