Beispiel #1
0
int add_splinekey(PARAM_CONTROL *pc,SPLINE_KEY **nsk,int x,int y)
{
	int result=FALSE;
	EnterCriticalSection(&mutex);
	if(pc){
		if(pc->control.type==CSPLINE){
			SPLINE_CONTROL *sc=pc->control.data;
			if(sc){
				int i=sc->selected;
				ANIMATE_DATA *a=sc->anim;
				if(a){
					SPLINE_KEY *sk=0;
					alloc_key(&sk);
					if(sk){
						SPLINE_KEY_CONTROL *skc=0;
						add_splinekey_control(sc,sk,&skc);
						if(skc){
							skc->x=x;
							skc->y=y;
							init_skc_pos(sc,skc);
						}
						insert_keylist(&a[i],sk);
						if(nsk)
							*nsk=sk;

						result=TRUE;
					}
				}
			}
		}
	}
	LeaveCriticalSection(&mutex);
	return result;
}
Beispiel #2
0
int x_insert( int argc, char *argv[] )
{
    const char *status = NULL,
                *out_fname = NULL,
                 *list1_fname = NULL,
                  *list2_fname = NULL;

    for( ; argc ; --argc, ++argv )
    {
        if( '-' != argv[0][0] )
            break;
        for( char *p = argv[0] + 1 ; '\0' != *p ; ++p )
        {
            switch( *p )
            {
            case 'o':
            {
                if( '\0' != *(p+1) || !(--argc) )
                {
                    fprintf( stderr, "%s: -o must be followed by a file name\n", __func__ );
                    return 1;
                }
                out_fname = *(++argv);
            }
            break;
            case 'i':
                ignore_missing = 1;
                break;
            case 'f':
            {
                if( '\0' != *(p+1) || !(--argc) )
                {
                    fprintf( stderr, "%s: -f must be followed by a file name\n", __func__ );
                    return 1;
                }
                list1_fname = *(++argv);
            }
            break;
            case 'F':
            {
                if( '\0' != *(p+1) || !(--argc) )
                {
                    fprintf( stderr, "%s: -F must be followed by a file name\n", __func__ );
                    return 1;
                }
                list2_fname = *(++argv);
            }
            break;
            default:
            {
                fprintf( stderr, "%s: unknown parameter -%c\n",
                         __func__, *p );
                return 1;
            }
            }
        }
    }
    if( NULL != list1_fname && NULL != list2_fname &&
            0 == strcmp( list1_fname, "-" ) && 0 == strcmp( list2_fname, "-" ) )
    {
        fprintf( stderr, "%s: both pre- and post-list cannot be '-'(stdin)\n",
                 __func__ );
        return 1;
    }
    if( NULL == out_fname )
    {
        fprintf( stderr, "%s: output file name must be specified; try 'lhpc-aff help insert'\n",
                 __func__ );
        return 1;
    }
    if( argc % 3 )
    {
        fprintf( stderr, "%s: unpaired aff-file and keypath; "
                 "try 'lhpc-aff help insert'\n", __func__ );
        return 1;
    }
    char *tmp_fname;
    if( NULL == ( tmp_fname = mk_tmp_filename( ".aff-tmp.", out_fname ) ) )
    {
        fprintf( stderr, "%s: cannot create a unique writable file\n", __func__ );
        perror( __func__ );
        return 1;
    }
    struct AffWriter_s *w;
    if (NULL == (w = aff_writer( tmp_fname )))
    {
        fprintf(stderr, "%s: not enough memory\n", __func__);
        goto errclean_free;
    }
    if( NULL != aff_writer_errstr( w ) )
    {
        fprintf( stderr, "%s: %s: %s\n", __func__, tmp_fname, aff_writer_errstr( w ) );
        goto errclean_w;
    }
    // insert data from pre-list
    if( NULL != list1_fname )
    {
        if( insert_keylist( w, list1_fname ) )
            goto errclean_w;
    }
    // insert data from cmdline key list
    for( ; argc ; argc -= 3, argv += 3 ) {
        if(insert_data( w, argv[1], argv[2], argv[0]))
            goto errclean_w;
    }
    // insert data from post-list
    if( NULL != list2_fname )
    {
        if( insert_keylist( w, list2_fname ) )
            goto errclean_w;
    }

    if( NULL != ( status = aff_writer_close( w ) ) )
    {
        fprintf( stderr, "%s: %s\n", __func__, status );
        goto errclean_file;
    }
    if( rename( tmp_fname, out_fname ) )
    {
        perror( __func__ );
        fprintf( stderr, "%s: output is saved to %s\n", __func__, tmp_fname );
        goto errclean_free;
    }
    free( tmp_fname );
    return 0;

errclean_w:
    aff_writer_close( w );
errclean_file:
    if( remove( tmp_fname ) )
        perror( __func__ );
errclean_free:
    free(tmp_fname);
    return 1;
}