Esempio n. 1
0
/*
 *  cleandic(): Passe en revue toutes les lignes du dictionnaire, et
 *              elimine les lignes de commentaires ainsi que les retour-                  
 *              charriot eventuels provenant de DOS, pour gagner de la
 *              place entre autres sous ce systeme.
 */
 cleandic()
 {
    char fname[127];
    char tmpfile[127];
    char buf[90];
    char ch, letter ;
    FILE *fp,*ftmp ;


    sprintf(tmpfile,"%s/cleantmp.%d", TMPPATH, getpid() );

    for( letter = 'a' ; letter <= 'z' ; letter++ )
    {
        sprintf(fname, "%s%s%c%s",dict_path, sep, letter, DICT_EXT );
        if(( fp = fopen(fname,READ_TEXT)) == NULL )
        {
            fprintf(stderr,"Impossible de lire fichier %s\n",fname );
            file_usage();
            return ERROR;
        }

#ifdef MUST_HAVE_BUF
        setvbuf( fp, NULL, _IOFBF, MYVBUF );
#endif

        if(( ftmp = fopen(tmpfile,WRITE_BINARY)) == NULL ) /* BINARY for DOS!*/
        {
            fprintf(stderr,"Fichier temporaire %s impossible !\n",fname );
            return ERROR;
        }

#ifdef MUST_HAVE_BUF
        setvbuf( ftmp, NULL, _IOFBF, MYVBUF );
#endif

        printf("Traite la lettre %c...\n", letter );
	putheader( letter, ftmp);
        while( fgets(buf,88,fp) )
        {
            nocrlf( buf );
            if((byte) *buf == COMMENT_CHAR || *buf == '\0'  ) 
                   continue;
            fprintf(ftmp,"%s\n",buf);
        }
	putfooter( letter, ftmp);
        fclose( fp );
        fclose( ftmp);
                              /* ensuite, on recopie. C'est tres lent mais */
                              /* ca marche a coup sur sous DOS avec des    */
                              /* drives differents, ce serait mieux avec   */
                              /* un link ou un rename... Pas me casser :-) */

        if(( ftmp = fopen(tmpfile,READ_BINARY)) == NULL ) /* BINARY for DOS!*/
        {
            fprintf(stderr,"Fichier temporaire %s inacessible !\n",fname );
            return ERROR;
        }

#ifdef MUST_HAVE_BUF
        setvbuf( ftmp, NULL, _IOFBF, MYVBUF );
#endif
 

        if(( fp = fopen(fname,WRITE_BINARY)) == NULL )
        {
            fprintf(stderr,"Impossible de reecrire fichier %s\n",fname );
            return ERROR;
        }

#ifdef MUST_HAVE_BUF
        setvbuf( fp, NULL, _IOFBF, MYVBUF );
#endif

        while( fread( &ch, 1, 1, ftmp ) ) 
               fwrite( &ch, 1,1, fp ) ; 
 
        fclose( fp );
        fclose( ftmp);
    }

    unlink( tmpfile );
    printf("Hop, j'ai fini.\n");
    return OK ;
 }
Esempio n. 2
0
/* The function usage is only informative - it prints this program's usage and
   command-line options. */
static int usage(FILE *f, int argc, char *argv[])
{
	int i;
	int all = 0;

	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "all")) {
			all = 1;
			break;
		}
	}

	/* Don't print general options if specific help was requested */
	if (all || argc == -1)
		fprintf(f, _("Usage:\n"
			     "	gnokii [CONFIG OPTIONS] OPTIONS\n"
			     "\nCONFIG OPTIONS\n"
			     "		--config filename\n"
			     "		--phone phone_section\n"
			     "\nOPTIONS\n"
			     "Use just one option at a time.\n"
			     "General options:\n"
			     "          --help [all] [monitor] [sms] [mms] [phonebook] [calendar] [todo]\n"
			     "                 [dial] [profile] [settings] [wap] [logo] [ringtone]\n"
			     "                 [security] [file] [other]\n"
			     "          --version\n"
			     "          --shell\n"
			     "          --ping\n"));

	/* FIXME? throw an error if argv[i] is duplicated or unknown */
	for (i = 1; i < argc; i++) {
		if (all || !strcmp(argv[i], "monitor"))
			monitor_usage(f);
		if (all || !strcmp(argv[i], "sms"))
			sms_usage(f);
		if (all || !strcmp(argv[i], "mms"))
			mms_usage(f);
		if (all || !strcmp(argv[i], "phonebook"))
			phonebook_usage(f);
		if (all || !strcmp(argv[i], "calendar"))
			calendar_usage(f);
		if (all || !strcmp(argv[i], "todo"))
			todo_usage(f);
		if (all || !strcmp(argv[i], "dial"))
			dial_usage(f);
		if (all || !strcmp(argv[i], "profile"))
			profile_usage(f);
		if (all || !strcmp(argv[i], "settings"))
			settings_usage(f);
		if (all || !strcmp(argv[i], "wap"))
			wap_usage(f);
		if (all || !strcmp(argv[i], "logo"))
			logo_usage(f);
		if (all || !strcmp(argv[i], "ringtone"))
			ringtone_usage(f);
		/* Unconditional compile here because security_usage() has its own conditional */
		if (all || !strcmp(argv[i], "security"))
			security_usage(f);
		if (all || !strcmp(argv[i], "file"))
			file_usage(f);
		if (all || !strcmp(argv[i], "other"))
			other_usage(f);
		if (all)
			break;
	}

	return 0;
}