Example #1
0
void time_to_words_2(Language lang, int hours, int minutes, int seconds, char* words, size_t length) {
  size_t remaining = length;
  memset(words, 0, length);

  if (hours == 0 && minutes == 0) {
    remaining -= append_string(words, remaining, STR_MIDNIGHT);
    remaining -= append_string(words, remaining, " ");
    return;
  } else if (hours == 12 && minutes == 0) {
    remaining -= append_string(words, remaining, STR_MIDDAY);
    remaining -= append_string(words, remaining, " ");
    return;
  } else if ((hours == 12 || hours ==0) && minutes != 0) {
    remaining -= append_string(words, remaining, "*");
    remaining -= append_number(words, 12, 0);
  } else {
    //strcpy(words, "*");
    remaining -= append_string(words, remaining, "*");
    remaining -= append_number(words, hours % 12,0);
  }

  remaining -= append_string(words, remaining, " ");
  if(minutes > 0 && minutes <10) {
    remaining -= append_string(words, remaining, "oh ");
  }
  remaining -= append_number(words, minutes, 1);
  remaining -= append_string(words, remaining, " ");
}
Example #2
0
/** Print formated file name. If fmt is NULL the default format %a - %t will used
 *
 * %% the % sign
 * %a author of song
 * %t song title
 * %y year
 * %f song from
 * %T Tracker
 * %C Comment
 * %s stereo type (ABC, BCA, ...)
 * %l 'looped' or 'non-looped'
 * %c chip type: 'AY' or 'YM'
 * %F chip Freq
 * %P player freq
 */
void ayemu_vtx_sprintname (const ayemu_vtx_t *vtx, char *const buf, const int sz, const char *fmt)
{
  static char *stereo_types[] = { "MONO", "ABC", "ACB", "BAC", "BCA", "CAB", "CBA" };

  if (fmt == NULL)
    fmt = "%a - %t";

  buf[0] = '\0';

  while (*fmt != '\0') {
    if (*fmt == '%') {
      switch(*++fmt) {
      case 'a':
	append_string(buf, sz, vtx->hdr.author);
	break;
      case 't':
	append_string(buf, sz, vtx->hdr.title);
	break;
      case 'y':
	append_number(buf, sz, vtx->hdr.year);
	break;
      case 'f':
	append_string(buf, sz, vtx->hdr.from);
	break;
      case 'T':
	append_string(buf, sz, vtx->hdr.tracker);
	break;
      case 'C':
	append_string(buf, sz, vtx->hdr.comment);
	break;
      case 's':
	append_string(buf, sz, stereo_types[vtx->hdr.stereo]);
	break;
      case 'l':
	append_string(buf, sz, (vtx->hdr.loop)? "looped" : "non-looped" );
	break;
      case 'c':
	append_string(buf, sz, (vtx->hdr.chiptype == AYEMU_AY)? "AY" : "YM" );
	break;
      case 'F':
	append_number(buf, sz, vtx->hdr.chipFreq);
	break;
      case 'P':
	append_number(buf, sz, vtx->hdr.playerFreq);
	break;
      default:
	append_char(buf, sz, *fmt);
      }
      fmt++;
    } else {
      append_char(buf, sz, *fmt++);
    }
  }
}
static void setup_interleaved(void) {
    JournalFile *one, *two;
    one = test_open("one.journal");
    two = test_open("two.journal");
    append_number(one, 1, NULL);
    append_number(two, 2, NULL);
    append_number(one, 3, NULL);
    append_number(two, 4, NULL);
    test_close(one);
    test_close(two);
}
void time_to_words(int hours, int minutes, char* words, size_t length, o_setting_t o_setting) {
  size_t remaining = length;
  memset(words, 0, length);

  if (hours == 0 || hours == 12) {
    remaining -= append_string(words, remaining, TEENS[2]);
  } else {
    remaining -= append_number(words, hours % 12, O_SETTING_NONE); // no leading O on hours
  }

  remaining -= append_string(words, remaining, " ");
  remaining -= append_number(words, minutes, o_setting);
  remaining -= append_string(words, remaining, " ");
}
Example #5
0
void time_to_words(int hours, int minutes, char* words, size_t length) {
  size_t remaining = length;
  memset(words, 0, length);

  if (hours == 0 || hours == 12) {
    remaining -= append_string(words, remaining, TEENS[2]);
  } else {
    remaining -= append_number(words, hours % 12);
  }

  remaining -= append_string(words, remaining, " ");
  remaining -= append_number(words, minutes);
  remaining -= append_string(words, remaining, " ");
}
Example #6
0
void fuzzy_time_to_words(uint8_t hours, uint8_t minutes, char* words, size_t length, uint8_t showPrefix) {
  uint8_t fuzzy_hours = hours;
  uint8_t fuzzy_minutes = minutes;

  size_t remaining = length;
  memset(words, 0, length);

  if (showPrefix == 1) {
    remaining -= append_string(words, remaining, "Klokken er ");
  }
  if (fuzzy_minutes != 0) {
    if (fuzzy_minutes == 15) {
      remaining -= append_string(words, remaining, "kvart over ");
    } else if (fuzzy_minutes == 45) {
      remaining -= append_string(words, remaining, "kvart på ");
      fuzzy_hours = (fuzzy_hours + 1) % 24;
    } else if (fuzzy_minutes == 30) {
      remaining -= append_string(words, remaining, "halv ");
      fuzzy_hours = (fuzzy_hours + 1) % 24;
    } else if (fuzzy_minutes < 20) {
      remaining -= append_number(words, fuzzy_minutes);
      remaining -= append_string(words, remaining, " over ");
    } else if (fuzzy_minutes < 30) {
      remaining -= append_number(words, 30 - fuzzy_minutes);
      remaining -= append_string(words, remaining, " på halv ");
      fuzzy_hours = (fuzzy_hours + 1) % 24;
    } else if (fuzzy_minutes < 45) {
      remaining -= append_number(words, fuzzy_minutes - 30);
      remaining -= append_string(words, remaining, " over halv ");
      fuzzy_hours = (fuzzy_hours + 1) % 24;
    } else {
      remaining -= append_number(words, 60 - fuzzy_minutes);
      remaining -= append_string(words, remaining, " på ");
      fuzzy_hours = (fuzzy_hours + 1) % 24;
    }
  }

    remaining -= append_number(words, fuzzy_hours % 12);
  if (showPrefix == 0) {
    int firstChar = words[0];
    int secondChar = words[1];
    if(firstChar == 195 && secondChar == 165) {
        words[1] = 133;
    } else {
        words[0] = words[0] - 32;
    }
  }
}
Example #7
0
void hour_to_24h_word(int hours, char *words) {
  // PBL_ASSERT(hours >= 0 && hours < 24, "Invalid number of hours");

  hours = hours % 24;

  strcpy(words, "");

  append_number(words, hours);
}
Example #8
0
// returns number of lines written
void time_to_common_words(int hours, int minutes, char *words) {
  // TODO: make an app-safe assert
  // PBL_ASSERT(hours >= 0 && hours < 24, "Invalid number of hours");
  // PBL_ASSERT(minutes >= 0 && minutes < 60, "Invalid number of minutes");

  size_t written = 0;
  strcpy(words, "");

  if (minutes != 0 && (minutes >= 10 || minutes == 5 || hours == 0 || hours == 12)) {
    if (minutes == 15) {
      written += sprintf(words, "%s %s ", STR_QUARTER, STR_AFTER);
    } else if (minutes == 45) {
      written += sprintf(words, "%s %s ", STR_QUARTER, STR_TO);
      hours = (hours + 1) % 24;
    } else if (minutes == 30) {
      written += sprintf(words, "%s %s ", STR_HALF, STR_PAST);
    } else if (minutes < 30) {
      written += append_number(words, minutes);
      written += sprintf(words + written, " %s ", STR_AFTER);
    } else {
      written += append_number(words, 60 - minutes);
      written += sprintf(words + written, " %s ", STR_TO);
      hours = (hours + 1) % 24;
    }
  }

  if (hours == 0) {
    written += sprintf(words + written, "%s", STR_MIDNIGHT);
  } else if (hours == 12) {
    strcat(words, STR_NOON);
    written += sprintf(words + written, "%s", STR_NOON);
  } else {
    written += append_number(words, hours % 12);
  }

  if (minutes < 10 && minutes != 5 && !(hours == 0 || hours == 12)) {
    if (minutes == 0) {
      sprintf(words + written, " %s%s", STR_OH_TICK, STR_CLOCK);
    } else {
      sprintf(words + written, " %s%s", STR_OH_TICK, ONES[minutes]);
    }
  }
}
Example #9
0
void fuzzy_hours_to_words(struct tm *t, char* words) {
    int fuzzy_hours = t->tm_hour;
    int fuzzy_minutes = t->tm_min;

    size_t remaining = BUFFER_SIZE;
    memset(words, 0, BUFFER_SIZE);

    //Is it midnight?
    if (fuzzy_hours == 0 && fuzzy_minutes == 0) {
        remaining -= append_string(words, remaining, STR_MID);
        //is it noon?
    } else if (fuzzy_hours == 12 && fuzzy_minutes == 0) {
        remaining -= append_string(words, remaining, STR_NOON);
    } else if (fuzzy_hours == 0 || fuzzy_hours == 12 || fuzzy_hours == 24) {
        remaining -= append_number(words, 12);
    } else {
        //get hour
        remaining -= append_number(words, fuzzy_hours % 12);
    }
}
Example #10
0
static size_t append_hour(char* words, const size_t length, int fuzzy_hours) {
  size_t remaining = length;
  if (fuzzy_hours == 0) {
    remaining = append_string(words, remaining, STR_MIDNIGHT);
  } else if (fuzzy_hours == 12) {
    remaining = append_string(words, remaining, STR_NOON);
  } else {
    remaining = append_number(words, fuzzy_hours % 12);
  }
  return (remaining);
}
Example #11
0
void fuzzy_sminutes_to_words(PblTm *t, char* words) {
  int fuzzy_minutes = t->tm_min;

  size_t remaining = BUFFER_SIZE;
  memset(words, 0, BUFFER_SIZE);

  if (fuzzy_minutes > 20)
  {
    remaining -= append_number(words,fuzzy_minutes%10);
  }
}
void fuzzy_sminutes_to_words(PblTm *t, char* words) {
  int fuzzy_hours = t->tm_hour;
  int fuzzy_minutes = t->tm_min;

  size_t remaining = BUFFER_SIZE;
  memset(words, 0, BUFFER_SIZE);

#if DAY
  if (fuzzy_minutes < 20) {
#else
  if (10 < fuzzy_minutes && fuzzy_minutes < 20) {
#endif
    if (fuzzy_minutes > 13 && 15 != fuzzy_minutes) {
        strcat(words, STR_TEEN);
      }
  } else if (fuzzy_minutes != 0 || (fuzzy_hours != 12 && fuzzy_hours != 0)) {
      remaining -= append_minutes_number(words, fuzzy_minutes);
  }
}

void fuzzy_hours_to_words(PblTm *t, char* words) {
  int fuzzy_hours = t->tm_hour;
  int fuzzy_minutes = t->tm_min;

  size_t remaining = BUFFER_SIZE;
  memset(words, 0, BUFFER_SIZE);

  //Is it midnight?
  if (fuzzy_hours == 0 && fuzzy_minutes == 0) {
    remaining -= append_string(words, remaining, STR_MID);
  //is it noon?
  } else if (fuzzy_hours == 12 && fuzzy_minutes == 0) {
    remaining -= append_string(words, remaining, STR_NOON);

  } else if (fuzzy_hours == 0  || fuzzy_hours == 12){
    remaining -= append_number(words, 12);
  } else {
    //get hour
    remaining -= append_number(words, fuzzy_hours % 12);
  }
}
Example #13
0
void hour_to_12h_word(int hours, char *word) {
  // PBL_ASSERT(hours >= 0 && hours < 24, "Invalid number of hours");
  hours = hours % 12;

  if (hours == 0) {
    hours = 12;
  }

  strcpy(word, "");

  append_number(word, hours);
}
static int consumerir_transmit(struct consumerir_device *dev,
   int carrier_freq, int pattern[], int pattern_len)
{
    int buffer_len = 0;
    int buffer_size = 128;
    int i;
    char *buffer;

    if ((buffer = malloc(buffer_size)) == NULL) {
        return -ENOMEM;
    }

    /* write the header */
    if (! append_number(&buffer, &buffer_len, &buffer_size, carrier_freq)) {
        goto error;
    }

    /* calculate factor of conversion from microseconds to pulses */
    float factor = 1000000 / carrier_freq;

    /* write out the timing pattern */
    for (i = 0; i < pattern_len; i++)
    {
        if (! append_number(&buffer, &buffer_len, &buffer_size, (int) (pattern[i]/factor))) {
            goto error;
        }
    }

    buffer[buffer_len - 1] = 0;
    write(fd, buffer, buffer_len - 1);

    free(buffer);

    return 0;

error:
    free(buffer);
    return -ENOMEM;
}
Example #15
0
static gchar const*
gog_polynom_reg_curve_get_equation (GogRegCurve *curve)
{
	if (!curve->equation) {
		GogLinRegCurve *lin = GOG_LIN_REG_CURVE (curve);
		GString *str = g_string_new ("y =");
		int i, lasti = (lin->affine ? 0 : 1), j = 0;

		for (i = lin->dims; i >= lasti; i--) {
			double c_i = curve->a[i];

			if (c_i == 0.) /* a very rare event */
				continue;

			/* Break after every three terms present.  */
			if (j > 0 && j % 3 == 0)
				g_string_append_c (str, '\n');
			j++;

			g_string_append_c (str, ' ');
			if (j != 1) {
				if (c_i >= 0)
					g_string_append_c (str, '+');
				else {
					g_string_append_len (str, minus_utf8, minus_utf8_len);
					c_i = -c_i;
				}
				g_string_append_c (str, ' ');
			}

			append_number (str, c_i, i >= 1);

			if (i >= 1) {
				g_string_append_c (str, 'x');
				if (i > 1)
					append_exponent (str, i);
			}
		}
		if (j == 0) {
			/* Nothing whatsoever.  */
			g_string_append (str, " 0");
		}

		curve->equation = g_string_free (str, FALSE);
	}
	return curve->equation;
}
Example #16
0
void fuzzy_minutes_to_words(struct tm *t, char* words) {
    int fuzzy_hours = t->tm_hour;
    int fuzzy_minutes = t->tm_min;

    size_t remaining = BUFFER_SIZE;
    memset(words, 0, BUFFER_SIZE);

    //Is it midnight? or noon
    if (fuzzy_minutes != 0 || (fuzzy_hours != 12 && fuzzy_hours != 0)) {
        //is it the top of the hour?
        if(fuzzy_minutes == 0) {
            remaining -= append_string(words, remaining, STR_OH_CLOCK);
        } else if(fuzzy_minutes < 10) {
            //is it before ten minutes into the hour
            remaining -= append_string(words, remaining, STR_OH);
        } else {
            remaining -= append_number(words, fuzzy_minutes);
        }
    } else if (fuzzy_hours == 0) {
        remaining -= append_string(words, remaining, STR_NIGHT);
    }
}
Example #17
0
void fuzzy_minutes_to_words(PblTm *t, char* words) {
  int fuzzy_hours = t->tm_hour;
  int fuzzy_minutes = t->tm_min;

  size_t remaining = BUFFER_SIZE;
  memset(words, 0, BUFFER_SIZE);

  if (fuzzy_minutes != 0 ) 
  {
    if(fuzzy_minutes == 0)
    {
      remaining -= append_string(words, remaining, STR_OH_CLOCK);
    } 
    else if(fuzzy_minutes == 30)
    {     
      remaining -= append_string(words, remaining, STR_MID);
    } 
    else 
    {
      remaining -= append_number(words, fuzzy_minutes);
    }
  }
}
static void test_sequence_numbers(void) {

    char t[] = "/tmp/journal-seq-XXXXXX";
    JournalFile *one, *two;
    uint64_t seqnum = 0;
    sd_id128_t seqnum_id;

    assert_se(mkdtemp(t));
    assert_se(chdir(t) >= 0);

    assert_se(journal_file_open("one.journal", O_RDWR|O_CREAT, 0644,
                                true, false, NULL, NULL, NULL, &one) == 0);

    append_number(one, 1, &seqnum);
    printf("seqnum=%"PRIu64"\n", seqnum);
    assert(seqnum == 1);
    append_number(one, 2, &seqnum);
    printf("seqnum=%"PRIu64"\n", seqnum);
    assert(seqnum == 2);

    assert(one->header->state == STATE_ONLINE);
    assert(!sd_id128_equal(one->header->file_id, one->header->machine_id));
    assert(!sd_id128_equal(one->header->file_id, one->header->boot_id));
    assert(sd_id128_equal(one->header->file_id, one->header->seqnum_id));

    memcpy(&seqnum_id, &one->header->seqnum_id, sizeof(sd_id128_t));

    assert_se(journal_file_open("two.journal", O_RDWR|O_CREAT, 0644,
                                true, false, NULL, NULL, one, &two) == 0);

    assert(two->header->state == STATE_ONLINE);
    assert(!sd_id128_equal(two->header->file_id, one->header->file_id));
    assert(sd_id128_equal(one->header->machine_id, one->header->machine_id));
    assert(sd_id128_equal(one->header->boot_id, one->header->boot_id));
    assert(sd_id128_equal(one->header->seqnum_id, one->header->seqnum_id));

    append_number(two, 3, &seqnum);
    printf("seqnum=%"PRIu64"\n", seqnum);
    assert(seqnum == 3);
    append_number(two, 4, &seqnum);
    printf("seqnum=%"PRIu64"\n", seqnum);
    assert(seqnum == 4);

    test_close(two);

    append_number(one, 5, &seqnum);
    printf("seqnum=%"PRIu64"\n", seqnum);
    assert(seqnum == 5);

    append_number(one, 6, &seqnum);
    printf("seqnum=%"PRIu64"\n", seqnum);
    assert(seqnum == 6);

    test_close(one);

    /* restart server */
    seqnum = 0;

    assert_se(journal_file_open("two.journal", O_RDWR, 0,
                                true, false, NULL, NULL, NULL, &two) == 0);

    assert(sd_id128_equal(two->header->seqnum_id, seqnum_id));

    append_number(two, 7, &seqnum);
    printf("seqnum=%"PRIu64"\n", seqnum);
    assert(seqnum == 5);

    /* So..., here we have the same seqnum in two files with the
     * same seqnum_id. */

    test_close(two);

    log_info("Done...");

    if (arg_keep)
        log_info("Not removing %s", t);
    else {
        journal_directory_vacuum(".", 3000000, 0, 0, NULL);

        assert_se(rm_rf_dangerous(t, false, true, false) >= 0);
    }
}
Example #19
0
/**
 * gtk_gradient_to_string:
 * @gradient: the gradient to print
 *
 * Creates a string representation for @gradient that is suitable
 * for using in GTK CSS files.
 *
 * Returns: A string representation for @gradient
 *
 * Deprecated: 3.8: #GtkGradient is deprecated.
 **/
char *
gtk_gradient_to_string (GtkGradient *gradient)
{
  GString *str;
  guint i;

  g_return_val_if_fail (gradient != NULL, NULL);

  str = g_string_new ("-gtk-gradient (");

  if (gradient->radius0 == 0 && gradient->radius1 == 0)
    {
      g_string_append (str, "linear, ");
      append_number (str, gradient->x0, "left", "center", "right");
      g_string_append_c (str, ' ');
      append_number (str, gradient->y0, "top", "center", "bottom");
      g_string_append (str, ", ");
      append_number (str, gradient->x1, "left", "center", "right");
      g_string_append_c (str, ' ');
      append_number (str, gradient->y1, "top", "center", "bottom");
    }
  else
    {
      g_string_append (str, "radial, ");
      append_number (str, gradient->x0, "left", "center", "right");
      g_string_append_c (str, ' ');
      append_number (str, gradient->y0, "top", "center", "bottom");
      g_string_append (str, ", ");
      append_number (str, gradient->radius0, NULL, NULL, NULL);
      g_string_append (str, ", ");
      append_number (str, gradient->x1, "left", "center", "right");
      g_string_append_c (str, ' ');
      append_number (str, gradient->y1, "top", "center", "bottom");
      g_string_append (str, ", ");
      append_number (str, gradient->radius1, NULL, NULL, NULL);
    }
  
  for (i = 0; i < gradient->stops->len; i++)
    {
      ColorStop *stop;
      char *s;

      stop = &g_array_index (gradient->stops, ColorStop, i);

      g_string_append (str, ", ");

      if (stop->offset == 0.0)
        g_string_append (str, "from (");
      else if (stop->offset == 1.0)
        g_string_append (str, "to (");
      else
        {
          g_string_append (str, "color-stop (");
          append_number (str, stop->offset, NULL, NULL, NULL);
          g_string_append (str, ", ");
        }

      s = gtk_symbolic_color_to_string (stop->color);
      g_string_append (str, s);
      g_free (s);

      g_string_append (str, ")");
    }

  g_string_append (str, ")");

  return g_string_free (str, FALSE);
}
Example #20
0
void fuzzy_time_to_words(int hours, int minutes, char* words, size_t length) {
  int fuzzy_hours = hours;
  int fuzzy_minutes = ((minutes + 2) / 5) * 5;

  // Handle hour & minute roll-over.
  if (fuzzy_minutes > 55) {
    fuzzy_minutes = 0;
    fuzzy_hours += 1;
    if (fuzzy_hours > 23) {
      fuzzy_hours = 0;
    }
  }

  size_t remaining = length;
  memset(words, 0, length);

  if (fuzzy_minutes != 0 && (fuzzy_minutes >= 10 || fuzzy_minutes == 5 || fuzzy_hours == 0 || fuzzy_hours == 12)) {
    if (fuzzy_minutes == 15) {
      remaining -= append_hour(words, remaining, fuzzy_hours);

      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, STR_AND);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, STR_QUARTER);
    } else if (fuzzy_minutes == 45) {
      remaining -= append_string(words, remaining, STR_QUARTER);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, STR_TO);
      remaining -= append_string(words, remaining, " ");

      fuzzy_hours = (fuzzy_hours + 1) % 24;
      remaining -= append_hour(words, remaining, fuzzy_hours);
    } else if (fuzzy_minutes == 30) {
      remaining -= append_string(words, remaining, STR_HALF);
      remaining -= append_string(words, remaining, " ");

      fuzzy_hours = (fuzzy_hours + 1) % 24;
      remaining -= append_hour(words, remaining, fuzzy_hours);
    } else if (fuzzy_minutes < 30) {
      remaining -= append_hour(words, remaining, fuzzy_hours);

      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, STR_AND);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_number(words, fuzzy_minutes);
    } else {
      remaining -= append_number(words, 60 - fuzzy_minutes);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, STR_TO);
      remaining -= append_string(words, remaining, " ");

      fuzzy_hours = (fuzzy_hours + 1) % 24;
      remaining -= append_hour(words, remaining, fuzzy_hours);
    }
  }

  if (fuzzy_minutes == 0 && (fuzzy_hours == 0 || fuzzy_hours == 12)) {
    remaining -= append_hour(words, remaining, fuzzy_hours);
  }

  if (fuzzy_minutes == 0 && !(fuzzy_hours == 0 || fuzzy_hours == 12)) {
    fuzzy_hours = fuzzy_hours;
    remaining -= append_number(words, fuzzy_hours);
    remaining -= append_string(words, remaining, " ");
    if (fuzzy_hours==1) {
       remaining -= append_string(words, remaining, STR_OH_CLOCK);
    } else if (fuzzy_hours<5) {
       remaining -= append_string(words, remaining, STR_OH_MCLOCK);
    } else {
       remaining -= append_string(words, remaining, STR_OH_PCLOCK);
    }

  }
}
Example #21
0
	void new_copy()
	{
		uint8_t count = 0;
		while ( mokoi::directories[count] != NULL )
		{
			path_create( mokoi::path + "/" + mokoi::directories[count] );
			count++;
		}

		count = 0;
		while ( mokoi::files[count] != NULL)
		{
			file_write( mokoi::path + "/" + mokoi::files[count++], mokoi::files[count], strlen(mokoi::files[count]) );
			count++;
		}

		std::string config = "[Mokoi]\n";
		config.append("project.title=" + mokoi::name + "\n");

		/* User Name */
		config.append("project.author=");
		config.append( get_username() );
		config.append("\n");



		time_t now = time(NULL);

		config.append("project.creation=");
		append_number(config, now);
		config.append("\n");

#ifdef WIN32
		UUID Uuid;
		UuidCreate( &Uuid );

		config.append("project.id=");
		append_number(config, Uuid.Data1);
		config.append("\n");
#else
		char * uuid_text = new char[36];
		uuid_t Uuid;
		uuid_generate(Uuid);

		uuid_unparse(Uuid, uuid_text);
		config.append("project.id=");
		config.append( uuid_text );
		config.append("\n");

		delete [] uuid_text;
#endif


		config.append("map.width=640\n");
		config.append("map.height=480\n");
		config.append("screen.width=640\n");
		config.append("screen.height=480\n");
		config.append("display.width=640\n");
		config.append("display.height=480\n");
		config.append("display.height=480\n");
		config.append("sprite.shortname=true\n");


		file_write( mokoi::path + "/game.mokoi", (char*)config.c_str(), config.length() );
		file_write( mokoi::path + "/edit.zelda", (char*)config.c_str(), config.length() );
	}
Example #22
0
	bool save(std::string path, std::string name)
	{
		mokoi::path = path;
		mokoi::name = name;
		std::cout << "mokoi::save: " << mokoi::path << " - " << mokoi::name << std::endl;
		mokoi::new_copy();

		std::stringstream world_buffer;
		if ( oz::hasMaps() )
		{
			std::list<object> objects;
			uint32_t x,y,w,h;
			uint32_t c = 0;
			while ( oz::mapDetails( objects, x, y, w, h) )
			{
				if (x > 63 || y > 63)
				{
					std::cout << "mokoi::save: mokoi games only support 64x64 section." << std::endl;
				}
				else
				{
					world_buffer << c << "\t" << x << "\t" << y << "\t" << 1 << "\t" << 1 << std::endl;
				}


				std::stringstream map_buffer;
				map_buffer << "<map xmlns=\"http://mokoi.info/projects/mokoi\">" << std::endl;
				map_buffer << "\t<settings>" << std::endl;
				map_buffer << "\t\t<dimensions width=\"" << w << "\" height=\"" << h << "\" />" << std::endl;
				map_buffer << "\t\t<color red=\"0\" blue=\"0\" green=\"0\" mode=\"0\" />" << std::endl;
				map_buffer << "\t</settings>" << std::endl;
				if ( objects.size() )
				{
					for( std::list<object>::iterator objects_iter = objects.begin(); objects_iter != objects.end();objects_iter++ )
					{
						object o = (*objects_iter);
						map_buffer << "\t<object value=\"" << rename_sheet(o._sheet) << ":" <<  rename_sprite(o._sprite) << "\" type=\"sprite\">" << std::endl;
						map_buffer << "\t\t<color red=\"255\" blue=\"255\" green=\"255\" alpha=\"255\" />" << std::endl;
						map_buffer << "\t\t<position x=\"" << o.rect.x << "\" y=\"" << o.rect.y << "\" ";
						map_buffer << "w=\"" << o.rect.w << "\" h=\"" << o.rect.h << "\" z=\"" << o.rect.z*1000 << "\" l=\"" << o.rect.z << "\" />" << std::endl;
						if ( (*objects_iter).entity.length() )
						{
							/* <entity value="%s" language="%s" global="%s"/> */
							map_buffer << "\t\t<entity value=\"" << o.entity << "\" language=\"mps\" global=\"false\"/>" << std::endl;
						}
						map_buffer << "\t</object>" << std::endl;
					}
				}
				map_buffer << "</map>";

				std::stringstream name_buffer;
				name_buffer << mokoi::path << "/maps/" << c << ".xml";
				file_write( name_buffer.str(), (char*)map_buffer.str().c_str(), map_buffer.str().length() );

				c++;
			}
			file_write( mokoi::path + "/sections/Converted.txt", (char*)world_buffer.str().c_str(), world_buffer.str().length() );
		}


		if ( oz::sprites.size() )
		{
			/*
			struct sprite
			{
				std::string name;
				std::string mask;
				std::string parent;
				double timer;
				uint32_t flag;
				position rect;
			};
			*/

			std::map<std::string, sheet*> sheet_listing;
			std::map<std::string, sheet*>::iterator current_sheet_iter;

			for( std::list<sprite>::iterator sprite_iter = oz::sprites.begin(); sprite_iter != oz::sprites.end(); sprite_iter++ )
			{
				/*
				 *	<sheet xmlns="http://mokoi.info/format/sheet">
					<sprite name="process_0" hidden="hidden" mask="" entity="">
						<position x="74" y="38" w="16" h="16" />
					</sprite>
					<sprite name="process_1" mask="" entity="">
						<position x="74" y="38" w="16" h="16" />
						<child name="process_0" position="0" repeat="0"/>
						<collision id="0" x="0" y="0" w="16" h="16"/>
					</sprite>
					<animation name="process_0" hidden="hidden" mask="" entity="">
						<frame sprite="process_0" x="0" y="0" ms="100"/>
						<frame sprite="process_1" x="0" y="0" ms="100"/>
						<frame sprite="process_2" x="0" y="0" ms="100"/>
					</animation>
				</sheet>
				*/
				sheet * current_sheet = NULL;

				current_sheet_iter = sheet_listing.find( (*sprite_iter).parent  );
				if ( current_sheet_iter == sheet_listing.end() )
				{
					current_sheet = new sheet();
					current_sheet->name = (*sprite_iter).parent;

					sheet_listing[current_sheet->name] = current_sheet;
				}
				else
				{
					current_sheet = current_sheet_iter->second;
				}

				if ( (*sprite_iter).timer )
				{

				}
				else
				{
					std::string m = (*sprite_iter).mask;
					if ( m == "0" )
					{
						m.clear();
					}
					else
					{
						int mask_w = 0, mask_h= 0, mask_value = 0;
						if ( sscanf( m.c_str(), "%dx%dx%d", &mask_w, &mask_h, &mask_value ) == 3 )
						{

							m.clear();
							append_number(m, 255 - mask_value);
							std::cout << (*sprite_iter).mask << " > " << m << std::endl;
						}
					}




					current_sheet->contents << "\t<sprite name=\"" << rename_sprite((*sprite_iter).name) << "\" mask=\"" << m << "\"" << ((*sprite_iter).flag == 1 ? "entity=\""+(*sprite_iter).name+"\"" : "") << ">" << std::endl;
					current_sheet->contents << "\t\t<position x=\"" << (*sprite_iter).rect.x << "\" y=\"" << (*sprite_iter).rect.y << "\" w=\"" << (*sprite_iter).rect.w << "\" h=\"" << (*sprite_iter).rect.h << "\" />" << std::endl;
					current_sheet->contents << "\t</sprite>" << std::endl;
				}
			}

			for( current_sheet_iter = sheet_listing.begin(); current_sheet_iter != sheet_listing.end(); current_sheet_iter++ )
			{
				sheet * current_sheet = current_sheet_iter->second;

				std::string content;


				content.append( "<sheet xmlns=\"http://mokoi.info/format/sheet\">\n" );
				content.append( current_sheet->contents.str() );
				content.append( "</sheet>" );

				saveImage( current_sheet->name );
				file_write( mokoi::path + "/sprites/" + rename_sheet( current_sheet->name ) + ".png.xml", (char*)content.c_str(), content.length() );

			}

		}
		copyEntities();
		return true;
	}
Example #23
0
void time_to_words(int hours, int minutes, char* words, size_t length) {

  size_t remaining = length;
  memset(words, 0, length);

  // Fuzzy time
  minutes = (minutes + 3) / 5 * 5;

  // Handle minute wrapping
  if (minutes > 55)
  {
    minutes -= 60;
    hours++;
  }

  
  switch (minutes)
  {
    case 0:
      break;
    case 20:
      remaining -= append_number(words, minutes);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, PAST);
      remaining -= append_string(words, remaining, " ");
      break;
    case 15:
      //remaining -= append_string(words, remaining, QUART);
      //remaining -= append_string(words, remaining, " ");
      //remaining -= append_string(words, remaining, PAST);
      //remaining -= append_string(words, remaining, " ");
		remaining -= append_string(words, remaining, QUART);
		remaining -= append_string(words, remaining, " de ");
		hours++;
      break;
    case 25:
		remaining -= append_number(words, 2);
		remaining -= append_string(words, remaining, " ");
		remaining -= append_string(words, remaining, QUARTS);
		remaining -= append_string(words, remaining, " ");    
		remaining -= append_string(words, remaining, MENYS);
		remaining -= append_string(words, remaining, " ");   
		remaining -= append_number(words, 5);
		remaining -= append_string(words, remaining, " de ");	  
		hours++;		
		break;
    case 30:
		remaining -= append_number(words, 2);
		remaining -= append_string(words, remaining, " ");
		remaining -= append_string(words, remaining, QUARTS);
		remaining -= append_string(words, remaining, " de ");
		hours++;
		break;
    case 35:
      remaining -= append_number(words, 20);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_number(words, 5);
      remaining -= append_string(words, remaining, " ");    
      remaining -= append_string(words, remaining, TO);
      remaining -= append_string(words, remaining, " ");    
      hours++;
      break;
    case 40:
		remaining -= append_number(words, 3);
		remaining -= append_string(words, remaining, " ");
		remaining -= append_string(words, remaining, QUARTS);
		remaining -= append_string(words, remaining, " ");    
		remaining -= append_string(words, remaining, MENYS);
		remaining -= append_string(words, remaining, " ");   
		remaining -= append_number(words, 5);
		remaining -= append_string(words, remaining, " de ");	
		hours++;
		break;
    case 50:
		remaining -= append_number(words, 3);
		remaining -= append_string(words, remaining, " ");
		remaining -= append_string(words, remaining, QUARTS);
		remaining -= append_string(words, remaining, " i ");    
		remaining -= append_number(words, 5);
		remaining -= append_string(words, remaining, " de ");	
		hours++;
		break;	
    case 55:
      remaining -= append_number(words, 60 - minutes);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, TO);
      remaining -= append_string(words, remaining, " ");
      hours++;
      break;
    case 45:
		remaining -= append_number(words, 3);
		remaining -= append_string(words, remaining, " ");
		remaining -= append_string(words, remaining, QUARTS);
		remaining -= append_string(words, remaining, " de ");
		hours++;
		break;	
  }

  // Handle hour wrapping
  hours += 12; // If hours == 0
  while (hours > 12)
  {
    hours -= 12;
  }

  
  // Singular o Plural depenent de la hora
  if (hours == 13 || hours == 1)
  {
	remaining -= append_string(words, remaining, SINGULAR);
	remaining -= append_string(words, remaining, " ");	
  }  
  else
  {
	//remaining -= append_string(words, remaining, PLURAL);
	//remaining -= append_string(words, remaining, " ");	
  }

  remaining -= append_string(words, remaining, "*"); // Make hours bold
  
  remaining -= append_number(words, hours);
  remaining -= append_string(words, remaining, " ");

  
  switch(minutes)
  {
  case 0:
	// Add o'clock to whole hours
	remaining -= append_string(words, remaining, ENPUNT);
	remaining -= append_string(words, remaining, " ");
    
	case 5:
	case 10:
		remaining -= append_number(words, minutes);
		break;
  }

  
}
Example #24
0
void fuzzy_time_to_words(int hours, int minutes, char* words, char* words_b, size_t length) {
  int fuzzy_hours = hours;
  int fuzzy_minutes = ((minutes + 2) / 5) * 5;

  // Handle hour & minute roll-over.
  if (fuzzy_minutes > 55) {
    fuzzy_minutes = 0;
    fuzzy_hours += 1;
    if (fuzzy_hours > 23) {
      fuzzy_hours = 0;
    }
  }


  // light text 
  
  size_t remaining = length;
  memset(words, 0, length);


  if (fuzzy_minutes != 0 && (fuzzy_minutes >= 10 || fuzzy_minutes == 5 || fuzzy_hours == 0 || fuzzy_hours == 12)) {
    if (fuzzy_minutes == 15) {
      remaining -= append_string(words, remaining, STR_QUARTER);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, STR_AFTER);
      remaining -= append_string(words, remaining, " ");
    } else if (fuzzy_minutes == 45) {
      remaining -= append_string(words, remaining, STR_QUARTER);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, STR_TO);
      remaining -= append_string(words, remaining, " ");

      fuzzy_hours = (fuzzy_hours + 1) % 24;
    } else if (fuzzy_minutes == 30) {
      remaining -= append_string(words, remaining, STR_HALF);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, STR_PAST);
      remaining -= append_string(words, remaining, " ");
    } else if (fuzzy_minutes < 30) {
      remaining -= append_number(words, fuzzy_minutes);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, STR_AFTER);
      remaining -= append_string(words, remaining, " ");
    } else {
      remaining -= append_number(words, 60 - fuzzy_minutes);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_string(words, remaining, STR_TO);
      remaining -= append_string(words, remaining, " ");

      fuzzy_hours = (fuzzy_hours + 1) % 24;
    }
  }


  // bold text
  // reset
  remaining = length;
  memset(words_b, 0, length);
  
  if (fuzzy_hours == 0) {
    remaining -= append_string(words_b, remaining, STR_MIDNIGHT);
  } else if (fuzzy_hours == 12) {
    remaining -= append_string(words_b, remaining, STR_NOON);
  } else {
    remaining -= append_number(words_b, fuzzy_hours % 12);
  }

  if (fuzzy_minutes == 0 && !(fuzzy_hours == 0 || fuzzy_hours == 12)) {
    remaining -= append_string(words_b, remaining, " ");
    remaining -= append_string(words_b, remaining, STR_OH_CLOCK);
  }
}
Example #25
0
void time_to_words_1(Language lang, int hours, int minutes, int seconds, char* words, size_t length) {
  static char past_to[5];
  size_t remaining = length;
  memset(words, 0, length);
  //APP_LOG(APP_LOG_LEVEL_DEBUG, "INITIAL minutes: %d", minutes);

  //O'clock
  if (minutes ==0) {
    if (hours == 0) {
      remaining -= append_string(words, remaining, STR_MIDNIGHT);
      remaining -= append_string(words, remaining, " ");
      return;
    } else if (hours == 12) {
      remaining -= append_string(words, remaining, STR_MIDDAY);
      remaining -= append_string(words, remaining, " ");
      return;
    }
    else {
      remaining -= append_string(words, remaining, "*");
      remaining -= append_number(words, hours % 12,0);
      remaining -= append_string(words, remaining, " ");
      remaining -= append_number(words, 0, 1);
      remaining -= append_string(words, remaining, " ");
      return;
    }
  }
  //Past
  else if (minutes > 0 && minutes <= 30) {
    strcpy (past_to, "past ");
    //APP_LOG(APP_LOG_LEVEL_DEBUG, "PAST called: %s", past_to);
  }
  //To
  else if (minutes > 30 && minutes <=59) {
    strcpy (past_to, "to ");
    minutes = 60 - minutes;
    hours += 1;
    //APP_LOG(APP_LOG_LEVEL_DEBUG, "TO called: %s", past_to);
  }
  //APP_LOG(APP_LOG_LEVEL_DEBUG, "FIXEDUP minutes: %d", minutes);

  if (minutes == 15) {
    remaining -= append_string(words, remaining, "quarter");
  }
  else if (minutes == 30 ) {
    remaining -= append_string(words, remaining, "half");
  }
  else {
    remaining -= append_number(words, minutes, 1);
  }
  
  remaining -= append_string(words, remaining, " ");
  remaining -= append_string(words, remaining, past_to);
  
  if ((hours == 12 || hours ==0) && minutes != 0) {
    remaining -= append_string(words, remaining, "*");
    remaining -= append_number(words, 12, 0);
  } else {
    //strcpy(words, "*");
    remaining -= append_string(words, remaining, "*");
    remaining -= append_number(words, hours % 12,0);
  }

  remaining -= append_string(words, remaining, " ");
}