コード例 #1
0
ファイル: gen-layerdef.c プロジェクト: mpw/p2
void
gen_layerdef (void)
{
  int i;
  FILE *rfp;
  char rfp_name[MAX_IDENT_LEN];

  sprintf(rfp_name,"%s-ref.h", layer_name);
  if (!(rfp = fopen(rfp_name,"w"))) {
    error("Cannot open file %s", rfp_name);
  }
  
  print_forward_refs(rfp);
  fprintf(rfp, "\nLAYER_DEF P2_%s_ = { \"%s\", %s, %d, ",
          layer_name, layer_name,
          rclass_str(layer_realm), count_params(params_rlist));
  fprintf(rfp, " %s, ", (indirect_only) ? "TRUE" : "FALSE");
  fprintf(rfp, " %s, ", (d2u) ? "TRUE" : "FALSE");
  fprintf(rfp, " %s, ", (stable) ? "TRUE" : "FALSE");
  fprintf(rfp, " %d, ", annotations);
  fprintf(rfp, " %d, ", retrieval);
  fprintf(rfp, "{");
  print_realm_list(rfp, params_rlist);
  fprintf(rfp, "}, {");
  print_ops(rfp);
  fprintf(rfp, "} };\n");

  /* For each of the digits '2' thuough '9' */
  for (i=2; i<=9; i++) {
    fprintf(rfp,"static CURS_ARG c_verbatim%d;",i);
    fprintf(rfp,"static CONT_ARG k_verbatim%d;",i); 
    fprintf(rfp,"static CURS_ARG *cursor%d = &c_verbatim%d;", i,i);
    fprintf(rfp,"static CONT_ARG *container%d = &k_verbatim%d;", i,i);
    fprintf(rfp,"static vptr vp%d;\n",i);
  }

  fclose(rfp);
}
コード例 #2
0
int main(int argc, char *argv[])
{
  struct deltacloud_api api;
  struct deltacloud_api zeroapi;
  struct deltacloud_realm realm;
  struct deltacloud_realm *realms;
  int ret = 3;

  if (argc != 4) {
    fprintf(stderr, "Usage: %s <url> <user> <password>\n", argv[0]);
    return 1;
  }

  if (deltacloud_initialize(&api, argv[1], argv[2], argv[3]) < 0) {
    fprintf(stderr, "Failed to find links for the API: %s\n",
	    deltacloud_get_last_error_string());
    return 2;
  }

  memset(&zeroapi, 0, sizeof(struct deltacloud_api));

  /* test out deltacloud_supports_realms */
  if (deltacloud_supports_realms(NULL) >= 0) {
    fprintf(stderr, "Expected deltacloud_supports_realms to fail with NULL api, but succeeded\n");
    goto cleanup;
  }

  if (deltacloud_supports_realms(&zeroapi) >= 0) {
    fprintf(stderr, "Expected deltacloud_supports_realms to fail with uninitialized api, but succeeded\n");
    goto cleanup;
  }

  if (deltacloud_supports_realms(&api)) {

    /* test out deltacloud_get_realms */
    if (deltacloud_get_realms(NULL, &realms) >= 0) {
      fprintf(stderr, "Expected deltacloud_get_realms to fail with NULL api, but succeeded\n");
      goto cleanup;
    }

    if (deltacloud_get_realms(&api, NULL) >= 0) {
      fprintf(stderr, "Expected deltacloud_get_realms to fail with NULL realms, but succeeded\n");
      goto cleanup;
    }

    if (deltacloud_get_realms(&zeroapi, &realms) >= 0) {
      fprintf(stderr, "Expected deltacloud_get_realms to fail with unintialized api, but succeeded\n");
      goto cleanup;
    }

    if (deltacloud_get_realms(&api, &realms) < 0) {
      fprintf(stderr, "Failed to get_realms: %s\n",
	      deltacloud_get_last_error_string());
      goto cleanup;
    }
    print_realm_list(realms);

    if (realms != NULL) {

      /* test out deltacloud_get_realm_by_id */
      if (deltacloud_get_realm_by_id(NULL, realms->id, &realm) >= 0) {
	fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with NULL api, but succeeded\n");
	goto cleanup;
      }

      if (deltacloud_get_realm_by_id(&api, NULL, &realm) >= 0) {
	fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with NULL id, but succeeded\n");
	goto cleanup;
      }

      if (deltacloud_get_realm_by_id(&api, realms->id, NULL) >= 0) {
	fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with NULL realm, but succeeded\n");
	goto cleanup;
      }

      if (deltacloud_get_realm_by_id(&api, "bogus_id", &realm) >= 0) {
	fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with bogus id, but succeeded\n");
	goto cleanup;
      }

      if (deltacloud_get_realm_by_id(&zeroapi, realms->id, &realm) >= 0) {
	fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with unintialized api, but succeeded\n");
	goto cleanup;
      }

      /* here we use the first realm from the list above */
      if (deltacloud_get_realm_by_id(&api, realms->id, &realm) < 0) {
	fprintf(stderr, "Failed to get realm by id: %s\n",
		deltacloud_get_last_error_string());
	goto cleanup;
      }
      print_realm(&realm);
      deltacloud_free_realm(&realm);
    }
  }
  else
    fprintf(stderr, "Realms are not supported\n");

  ret = 0;

 cleanup:
  deltacloud_free_realm_list(&realms);

  deltacloud_free(&api);

  return ret;
}