+int Coke_int_GetSlotStatus(char *Buffer, int Slot)
+{
+ regmatch_t matches[4];
+ int ret;
+ char *status;
+
+ // Parse status response
+ ret = RunRegex(&gCoke_StatusRegex, Buffer, sizeof(matches)/sizeof(matches[0]), matches, "Bad Response");
+ if( ret ) {
+ return -1;
+ }
+
+ // Get slot status
+ Buffer[ matches[3].rm_eo ] = '\0';
+ status = &Buffer[ matches[3].rm_so ];
+
+ #if TRACE_COKE
+ printf("Coke_CanDispense: Machine responded slot status '%s'\n", status);
+ #endif
+
+ if( strcmp(status, "full") == 0 ) {
+ gaCoke_CachedStatus[Slot] = 0; // 0: Avaliiable
+ return 0;
+ }
+ else {
+ gaCoke_CachedStatus[Slot] = 1; // 1: Empty
+ return 1;
+ }
+}
+
+void Coke_int_UpdateSlotStatuses(void)
+{
+ int i;
+ int len;
+ char tmp[40];
+
+ pthread_mutex_lock(&gCoke_Mutex);
+
+ if( WaitForColon() ) return ;
+ Writef("d7\r\n"); // Update slot statuses
+ WaitForColon();
+ Writef("s\n");
+ ReadLine(sizeof tmp, tmp); // Read back what we just said
+
+ for( i = 0; i <= 6; i ++ )
+ {
+ len = ReadLine(sizeof tmp, tmp);
+ if( len == -1 ) return ; // I give up :(
+ Coke_int_GetSlotStatus(tmp, i);
+ }
+ pthread_mutex_unlock(&gCoke_Mutex);
+}
+