예제 #1
0
파일: mdbdump.c 프로젝트: jonrangel/mdb
int
main (int   argc,
      char *argv[])
{
   const bson_t *b;
   extent_t extent;
   record_t record;
   char *str;
   db_t db;
   ns_t ns;

   if (argc != 3) {
      fprintf(stderr, "usage: mdbdump DBPATH DBNAME\n");
      return ARGC_FAILURE;
   }

   errno = 0;
   if (!!db_init(&db, argv[1], argv[2])) {
      perror("Failed to load database");
      return DB_FAILURE;
   }

   errno = 0;
   if (!!db_namespaces(&db, &ns)) {
      perror("Failed to load namespaces");
      return NS_FAILURE;
   }

   do {
      //fprintf(stdout, "\nNamespace \"%s\"\n\n", ns_name(&ns));
      if (!!ns_extents(&ns, &extent)) {
         perror("Failed to load extent");
         return EXTENT_FAILURE;
      }
      do {
         if (!extent_records(&extent, &record)) {
            do {
               b = record_bson(&record);
               if ((str = bson_as_json(b, NULL))) {
                  puts(str);
               }
               bson_free(str);
            } while (!record_next(&record));
         }
      } while (!extent_next(&extent));
   } while (ns_next(&ns));

   db_destroy(&db);

   return 0;
}
예제 #2
0
static void update_pbring(void *arg, long l)
{
    pbring_inst_t *p = (pbring_inst_t *) arg;

    ring_size_t cmdsize = record_next_size(&p->to_rt_rb);
    if (cmdsize < 0) {
        // command ring empty
        *(p->underrun) += 1;
        return;
    }
    const void *cmdbuffer = record_next(&p->to_rt_rb);
    pb_istream_t stream = pb_istream_from_buffer((void *) cmdbuffer, cmdsize);
    int retval;

    if (!decode_msg(p, &stream)) {

        // process command here
        // prepare reply
        tx.has_motstat = true;
        tx.type =  pb_ContainerType_MT_MOTSTATUS;
        tx.note.funcs.encode = npb_encode_string;
        tx.note.arg = "hi there!";

        tx.motstat = (pb_MotionStatus) {
            .commandEcho = rx.motcmd.command,
             .commandNumEcho = rx.motcmd.commandNum,
              .commandStatus = pb_cmd_status_t_EMCMOT_COMMAND_OK,
               .has_carte_pos_fb = true,
            .carte_pos_fb = {
                .tran = {
                    .has_x = true,
                    .x = 42.0,
                    .has_y = true,
                    .y = 13.56,
                    .has_z = true,
                    .z = 27.12
                },
                .has_a = true,
                .a = 3.14
            }
        };
예제 #3
0
파일: hfsp_fs.c 프로젝트: 3a9LL/panda
static int
search_files( record *par, int recursive, match_proc_t proc, const void *match_data, hfsp_file_t *pt )
{
	hfsp_file_t t;
	record r;
	int ret = 1;

	t.path = NULL;

	record_init_parent( &r, par );
	do{
		if( r.record.type == HFSP_FOLDER || r.record.type == HFSP_FILE )
			ret = (*proc)( &r, par, match_data, &t );

		if( ret && r.record.type == HFSP_FOLDER && recursive )
			ret = search_files( &r, 1, proc, match_data, &t );

	} while( ret && !record_next(&r) );

	if( !ret && pt ) {
                char name[256];
                const char *s2 = t.path ? t.path : "";

		unicode_uni2asc( name, &r.key.name, sizeof(name));

		pt->rec = t.rec;
		pt->path = malloc( strlen(name) + strlen(s2) + 2 );
		strcpy( pt->path, name );
		if( strlen(s2) ) {
			strcat( pt->path, "\\" );
			strcat( pt->path, s2 );
		}
	}

	if( t.path )
		free( t.path );

	return ret;
}