Beispiel #1
0
char *
YpNextLine(int context)
{
  p_file *file;
  char *line;

  /* In skip-includes mode, remember where each line begins for
   * use by YpStandby.  */
  if (ypSkipIncludes && nYpIncludes && ypIncludes[nYpIncludes-1].file)
    rememberLine = p_ftell(ypIncludes[nYpIncludes-1].file);
  else
    rememberLine = -1;

  /* If there is an alternate input source, use it.  */
  if (YaltNextLine) {
    line = YaltNextLine(context);
    if (!line) YaltNextLine = 0;  /* "close" alternate input source */
    return line;
  }

  /* get the current include file */
  if (nYpIncludes==0) {
    file = 0;
  } else for (;;) {
    if ((file=ypIncludes[nYpIncludes-1].file)) break;
    need_endif = 0;
    p_free(ypIncludes[nYpIncludes-1].filename);
    if (!(--nYpIncludes)) break;
  }
  if (!file && nYpInputs) do file = YpPop(); while (!file && nYpInputs);

  /* quit if input is not from include file.  */
  if (!file) return 0;

  for (;;) {
    if (p_signalling) p_abort();
    /* Get an arbitrary (okay, < MAX_LINE) length input line.  */
    if (!GetNextLine(file, context)) return 0;
    /* if first line of file begins with #! discard it
     * (allows yorick source files to be scripts on most UNIX systems) */
    if (nYpIncludes && ypIncludes[nYpIncludes-1].lastLineRead==1 &&
        ypBuffer.line[0]=='#' && ypBuffer.line[1]=='!') {
      if (!GetNextLine(file, context)) return 0;
    }

    line = ypBuffer.line;
    if (line && context<=NL_CONTINUE) {
      int flag = yp_chk_hash(file, context, line);
      if (flag&1) {
        file = ypIncludes[nYpIncludes-1].file;
        continue;
      }
    }
    break;
  }

  yImpossible = 0;  /* tell YError that a line has come in */
  return line;
}
Beispiel #2
0
static void test_fwprintf(void)
{
    static const char file_name[] = "fprintf.tst";
    static const WCHAR simple[] = {'s','i','m','p','l','e',' ','t','e','s','t','\n',0};
    static const WCHAR cont_fmt[] = {'c','o','n','t','a','i','n','s','%','c','n','u','l','l','\n',0};
    static const WCHAR cont[] = {'c','o','n','t','a','i','n','s','\0','n','u','l','l','\n',0};

    FILE *fp = p_fopen(file_name, "wb");
    wchar_t bufw[1024];
    char bufa[1024];
    int ret;

    ret = vfwprintf_wrapper(fp, simple);
    ok(ret == 12, "ret = %d\n", ret);
    ret = p_ftell(fp);
    ok(ret == 24, "ftell returned %d\n", ret);

    ret = vfwprintf_wrapper(fp, cont_fmt, '\0');
    ok(ret == 14, "ret = %d\n", ret);
    ret = p_ftell(fp);
    ok(ret == 52, "ftell returned %d\n", ret);

    p_fclose(fp);

    fp = p_fopen(file_name, "rb");
    p_fgetws(bufw, sizeof(bufw)/sizeof(bufw[0]), fp);
    ret = p_ftell(fp);
    ok(ret == 24, "ftell returned %d\n", ret);
    ok(!wcscmp(bufw, simple), "buf = %s\n", wine_dbgstr_w(bufw));

    p_fgetws(bufw, sizeof(bufw)/sizeof(bufw[0]), fp);
    ret = p_ftell(fp);
    ok(ret == 52, "ret = %d\n", ret);
    ok(!memcmp(bufw, cont, 28), "buf = %s\n", wine_dbgstr_w(bufw));

    p_fclose(fp);

    fp = p_fopen(file_name, "wt");

    ret = vfwprintf_wrapper(fp, simple);
    ok(ret == 12, "ret = %d\n", ret);
    ret = p_ftell(fp);
    ok(ret == 13, "ftell returned %d\n", ret);

    ret = vfwprintf_wrapper(fp, cont_fmt, '\0');
    ok(ret == 14, "ret = %d\n", ret);
    ret = p_ftell(fp);
    ok(ret == 28, "ftell returned %d\n", ret);

    p_fclose(fp);

    fp = p_fopen(file_name, "rb");
    p_fgets(bufa, sizeof(bufa), fp);
    ret = p_ftell(fp);
    ok(ret == 13, "ftell returned %d\n", ret);
    ok(!strcmp(bufa, "simple test\r\n"), "buf = %s\n", bufa);

    p_fgets(bufa, sizeof(bufa), fp);
    ret = p_ftell(fp);
    ok(ret == 28, "ret = %d\n", ret);
    ok(!memcmp(bufa, "contains\0null\r\n", 15), "buf = %s\n", bufa);

    p_fclose(fp);
    unlink(file_name);

    ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
            "Invalid parameter handler was already set\n");

    /* NULL format */
    errno = 0xdeadbeef;
    SET_EXPECT(invalid_parameter_handler);
    ret = vfwprintf_wrapper(fp, NULL);
    ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
    ok(ret == -1, "expected ret -1, got %d\n", ret);
    CHECK_CALLED(invalid_parameter_handler);

    /* NULL file */
    errno = 0xdeadbeef;
    SET_EXPECT(invalid_parameter_handler);
    ret = vfwprintf_wrapper(NULL, simple);
    ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
    ok(ret == -1, "expected ret -1, got %d\n", ret);
    CHECK_CALLED(invalid_parameter_handler);

    /* format using % with NULL arglist*/
    /* crashes on Windows */
    /* ret = p_vfwprintf(0, fp, cont_fmt, NULL, NULL); */

    ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
            "Cannot reset invalid parameter handler\n");
}
Beispiel #3
0
static void test_fprintf(void)
{
    static const char file_name[] = "fprintf.tst";

    FILE *fp = p_fopen(file_name, "wb");
    char buf[1024];
    int ret;

    ret = vfprintf_wrapper(fp, "simple test\n");
    ok(ret == 12, "ret = %d\n", ret);
    ret = p_ftell(fp);
    ok(ret == 12, "ftell returned %d\n", ret);

    ret = vfprintf_wrapper(fp, "contains%cnull\n", '\0');
    ok(ret == 14, "ret = %d\n", ret);
    ret = p_ftell(fp);
    ok(ret == 26, "ftell returned %d\n", ret);

    p_fclose(fp);

    fp = p_fopen(file_name, "rb");
    p_fgets(buf, sizeof(buf), fp);
    ret = p_ftell(fp);
    ok(ret == 12, "ftell returned %d\n", ret);
    ok(!strcmp(buf, "simple test\n"), "buf = %s\n", buf);

    p_fgets(buf, sizeof(buf), fp);
    ret = p_ftell(fp);
    ok(ret == 26, "ret = %d\n", ret);
    ok(!memcmp(buf, "contains\0null\n", 14), "buf = %s\n", buf);

    p_fclose(fp);

    fp = p_fopen(file_name, "wt");

    ret = vfprintf_wrapper(fp, "simple test\n");
    ok(ret == 12, "ret = %d\n", ret);
    ret = p_ftell(fp);
    ok(ret == 13, "ftell returned %d\n", ret);

    ret = vfprintf_wrapper(fp, "contains%cnull\n", '\0');
    ok(ret == 14, "ret = %d\n", ret);
    ret = p_ftell(fp);
    ok(ret == 28, "ftell returned %d\n", ret);

    p_fclose(fp);

    fp = p_fopen(file_name, "rb");
    p_fgets(buf, sizeof(buf), fp);
    ret = p_ftell(fp);
    ok(ret == 13, "ftell returned %d\n", ret);
    ok(!strcmp(buf, "simple test\r\n"), "buf = %s\n", buf);

    p_fgets(buf, sizeof(buf), fp);
    ret = p_ftell(fp);
    ok(ret == 28, "ret = %d\n", ret);
    ok(!memcmp(buf, "contains\0null\r\n", 15), "buf = %s\n", buf);

    p_fclose(fp);
    unlink(file_name);
}