+// CL_Video interface functions
+
+/*
+========================
+VM_cin_open
+
+float cin_open(string file, string name)
+========================
+*/
+void VM_cin_open( void )
+{
+ char *file;
+ char *name;
+
+ VM_SAFEPARMCOUNT( 2, VM_cin_open );
+
+ file = PRVM_G_STRING( OFS_PARM0 );
+ name = PRVM_G_STRING( OFS_PARM1 );
+
+ VM_CheckEmptyString( file );
+ VM_CheckEmptyString( name );
+
+ if( CL_OpenVideo( file, name, MENUOWNER ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = 1;
+ else
+ PRVM_G_FLOAT( OFS_RETURN ) = 0;
+}
+
+/*
+========================
+VM_cin_close
+
+void cin_close(string name)
+========================
+*/
+void VM_cin_close( void )
+{
+ char *name;
+
+ VM_SAFEPARMCOUNT( 1, VM_cin_close );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+
+ CL_CloseVideo( CL_GetVideo( name ) );
+}
+
+/*
+========================
+VM_cin_setstate
+void cin_setstate(string name, float type)
+========================
+*/
+void VM_cin_setstate( void )
+{
+ char *name;
+ clvideostate_t state;
+ clvideo_t *video;
+
+ VM_SAFEPARMCOUNT( 2, VM_cin_netstate );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+
+ state = PRVM_G_FLOAT( OFS_PARM1 );
+
+ video = CL_GetVideo( name );
+ if( video && state > CLVIDEO_UNUSED && state < CLVIDEO_STATECOUNT )
+ CL_SetVideoState( video, state );
+}
+
+/*
+========================
+VM_cin_getstate
+
+float cin_getstate(string name)
+========================
+*/
+void VM_cin_getstate( void )
+{
+ char *name;
+ clvideo_t *video;
+
+ VM_SAFEPARMCOUNT( 1, VM_cin_getstate );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+
+ video = CL_GetVideo( name );
+ if( video )
+ PRVM_G_FLOAT( OFS_RETURN ) = (int)video->state;
+ else
+ PRVM_G_FLOAT( OFS_RETURN ) = 0;
+}
+
+/*
+========================
+VM_cin_restart
+
+void cin_restart(string name)
+========================
+*/
+void VM_cin_restart( void )
+{
+ char *name;
+ clvideo_t *video;
+
+ VM_SAFEPARMCOUNT( 1, VM_cin_restart );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+
+ video = CL_GetVideo( name );
+ if( video )
+ CL_RestartVideo( video );
+}
+
+////////////////////////////////////////
+// AltString functions
+////////////////////////////////////////
+
+/*
+========================
+VM_altstr_count
+
+float altstr_count(string)
+========================
+*/
+void VM_altstr_count( void )
+{
+ char *altstr, *pos;
+ int count;
+
+ VM_SAFEPARMCOUNT( 1, VM_altstr_count );
+
+ altstr = PRVM_G_STRING( OFS_PARM0 );
+ //VM_CheckEmptyString( altstr );
+
+ for( count = 0, pos = altstr ; *pos ; pos++ )
+ if( *pos == '\\' && !*++pos )
+ break;
+ else if( *pos == '\'' )
+ count++;
+
+ PRVM_G_FLOAT( OFS_RETURN ) = (float) (count / 2);
+}
+
+/*
+========================
+VM_altstr_prepare
+
+string altstr_prepare(string)
+========================
+*/
+void VM_altstr_prepare( void )
+{
+ char *outstr, *out;
+ char *instr, *in;
+ int size;
+
+ VM_SAFEPARMCOUNT( 1, VM_altstr_prepare );
+
+ instr = PRVM_G_STRING( OFS_PARM0 );
+ //VM_CheckEmptyString( instr );
+ outstr = VM_GetTempString();
+
+ for( out = outstr, in = instr, size = VM_STRINGTEMP_LENGTH - 1 ; size && *in ; size--, in++, out++ )
+ if( *in == '\'' ) {
+ *out++ = '\\';
+ *out = '\'';
+ size--;
+ } else
+ *out = *in;
+ *out = 0;
+
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( outstr );
+}
+
+/*
+========================
+VM_altstr_get
+
+string altstr_get(string, float)
+========================
+*/
+void VM_altstr_get( void )
+{
+ char *altstr, *pos, *outstr, *out;
+ int count, size;
+
+ VM_SAFEPARMCOUNT( 2, VM_altstr_get );
+
+ altstr = PRVM_G_STRING( OFS_PARM0 );
+ //VM_CheckEmptyString( altstr );
+
+ count = PRVM_G_FLOAT( OFS_PARM1 );
+ count = count * 2 + 1;
+
+ for( pos = altstr ; *pos && count ; pos++ )
+ if( *pos == '\\' && !*++pos )
+ break;
+ else if( *pos == '\'' )
+ count--;
+
+ if( !*pos ) {
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( "" );
+ return;
+ }
+
+ outstr = VM_GetTempString();
+ for( out = outstr, size = VM_STRINGTEMP_LENGTH - 1 ; size && *pos ; size--, pos++, out++ )
+ if( *pos == '\\' ) {
+ if( !*++pos )
+ break;
+ *out = *pos;
+ size--;
+ } else if( *pos == '\'' )
+ break;
+ else
+ *out = *pos;
+
+ *out = 0;
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( outstr );
+}
+
+/*
+========================
+VM_altstr_set
+
+string altstr_set(string altstr, float num, string set)
+========================
+*/
+void VM_altstr_set( void )
+{
+ int num;
+ char *altstr, *str;
+ char *in;
+ char *outstr, *out;
+
+ VM_SAFEPARMCOUNT( 3, VM_altstr_set );
+
+ altstr = PRVM_G_STRING( OFS_PARM0 );
+ //VM_CheckEmptyString( altstr );
+
+ num = PRVM_G_FLOAT( OFS_PARM1 );
+
+ str = PRVM_G_STRING( OFS_PARM2 );
+ //VM_CheckEmptyString( str );
+
+ outstr = out = VM_GetTempString();
+ for( num = num * 2 + 1, in = altstr; *in && num; *out++ = *in++ )
+ if( *in == '\\' && !*++in )
+ break;
+ else if( *in == '\'' )
+ num--;
+
+ if( !in ) {
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( "" );
+ return;
+ }
+ // copy set in
+ for( ; *str; *out++ = *str++ );
+ // now jump over the old contents
+ for( ; *in ; in++ )
+ if( *in == '\'' || (*in == '\\' && !*++in) )
+ break;
+
+ if( !in ) {
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( "" );
+ return;
+ }
+
+ strcpy( out, in );
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( outstr );
+}
+