Ejemplo n.º 1
0
int
parse_negative_option(char *opt, struct option_data *data)
{
    size_t i;
    const char *name = strprefix(opt, negative_prefix);
    if (!name) return 0;

    for (i = 0; i < count_of(categories_info); i++) {
        struct extension_category_info *category = &categories_info[i];
        if (strcmp(name, category->option_name)==0) {
            data->extensions &= ~(category->flags);
            return 1;
        }
    }

    for (i = 0; i < count_of(extensions_info); i++) {
        struct extension_info *extension = &extensions_info[i];
        if (strcmp(name, extension->option_name)==0) {
            data->extensions &= ~(extension->flag);
            return 1;
        }
    }

    for (i = 0; i < count_of(html_flags_info); i++) {
        struct html_flag_info *html_flag = &html_flags_info[i];
        if (strcmp(name, html_flag->option_name)==0) {
            data->html_flags &= ~(html_flag->flag);
            return 1;
        }
    }

    return 0;
}
Ejemplo n.º 2
0
static void
ChangeQuote(char **args)
{
    if (args != 0) {
	new_quote(&leftquote, count_of(args) > 0 ? args[0] : L_QUOTE);
	new_quote(&rightquote, count_of(args) > 1 ? args[1] : R_QUOTE);
    }
}
Ejemplo n.º 3
0
static void
ChangeComment(char **args)
{
    if (args != 0) {
	new_quote(&leftcmt, count_of(args) > 0 ? args[0] : L_CMT);
	new_quote(&rightcmt, count_of(args) > 1 ? args[1] : R_CMT);
    }
}
Ejemplo n.º 4
0
void
print_help(const char *basename)
{
    size_t i;
    size_t e;

    /* usage */
    printf("Usage: %s [OPTION]... [FILE]\n\n", basename);

    /* description */
    printf("Process the Markdown in FILE (or standard input) and render it to standard output, using the Hoedown library. "
           "Parsing and rendering can be customized through the options below. The default is to parse pure markdown and output HTML.\n\n");

    /* main options */
    printf("Main options:\n");
    print_option('n', "max-nesting=N", "Maximum level of block nesting parsed. Default is " str(DEF_MAX_NESTING) ".");
    print_option('t', "toc-level=N", "Maximum level for headers included in the TOC. Zero disables TOC (the default).");
    print_option(  0, "html", "Render (X)HTML. The default.");
    print_option(  0, "html-toc", "Render the Table of Contents in (X)HTML.");
    print_option('T', "time", "Show time spent in rendering.");
    print_option('i', "input-unit=N", "Reading block size. Default is " str(DEF_IUNIT) ".");
    print_option('o', "output-unit=N", "Writing block size. Default is " str(DEF_OUNIT) ".");
    print_option('h', "help", "Print this help text.");
    print_option('v', "version", "Print Hoedown version.");
    printf("\n");

    /* extensions */
    for (i = 0; i < count_of(categories_info); i++) {
        struct extension_category_info *category = categories_info+i;
        printf("%s (--%s%s):\n", category->label, category_prefix, category->option_name);
        for (e = 0; e < count_of(extensions_info); e++) {
            struct extension_info *extension = extensions_info+e;
            if (extension->flag & category->flags) {
                print_option(  0, extension->option_name, extension->description);
            }
        }
        printf("\n");
    }

    /* html-specific */
    printf("HTML-specific options:\n");
    for (i = 0; i < count_of(html_flags_info); i++) {
        struct html_flag_info *html_flag = html_flags_info+i;
        print_option(  0, html_flag->option_name, html_flag->description);
    }
    printf("\n");

    /* ending */
    printf("Flags and extensions can be negated by prepending 'no' to them, as in '--no-tables', '--no-span' or '--no-escape'. "
           "Options are processed in order, so in case of contradictory options the last specified stands.\n\n");

    printf("When FILE is '-', read standard input. If no FILE was given, read standard input. Use '--' to signal end of option parsing. "
           "Exit status is 0 if no errors occurred, 1 with option parsing errors, 4 with memory allocation errors or 5 with I/O errors.\n\n");
}
Ejemplo n.º 5
0
Archivo: llist.c Proyecto: jbauer5/labs
/* Run some simple test cases */
int main () {
  llnodep lstA = EMPTY_LIST,
          lstB = EMPTY_LIST;

  // Build a simple list with push
  push(&lstA, 2); push(&lstA, 3); push(&lstA, 1); push(&lstA, 5);

  // Check out print_list
  print_list(lstA);
  print_list(lstB);

  // Check the length implementation
  printf("Length: %d\n", length(lstA));
  printf("Length: %d\n", length(lstB));

  // Try adding to and building a list with append
  append(&lstA, 9); append(&lstA, 3);
  append(&lstB, 20); append(&lstB, 30); append(&lstB, 40); append(&lstB, 50);
  print_list(lstA);
  print_list(lstB);

  // Check count_of
  printf("Count of 3: %d\n", count_of(lstA, 3));
  printf("Count of 0: %d\n", count_of(lstA, 0));
  printf("Count of 20: %d\n", count_of(lstB, 20));
  printf("Count of 50: %d\n", count_of(lstB, 50));

  // Try freeing up a list
  freelist(&lstA);
  printf("Length: %d\n", length(lstA));

  // Try popping off a few values
  printf("Popped: %d\n", pop(&lstB));
  printf("Popped: %d\n", pop(&lstB));
  printf("Popped: %d\n", pop(&lstB));

  // Check out reverse
  push(&lstA, -4); push(&lstA, 8); push(&lstA, 1); push(&lstA, 9);
  reverse(&lstA);
  print_list(lstA);

  // And finally, sort
  sort(&lstA);
  sort(&lstB);
  print_list(lstA);
  print_list(lstB);

  return 0;
}
Ejemplo n.º 6
0
 string string_()
 {
  check(!is_empty());
  check(get()<count_of(literal_map));
  
  return literal_map[get()];
 }
Ejemplo n.º 7
0
static char* classify_adr_init(void)
{
    unsigned i;
    if (!adr_classes[0].init)
        adr_classes[0].init = malloc(1);
    for (i = 0; i < count_of(adr_classes); ++i)
        classify_adr_init_1(&adr_classes[i]);
}
Ejemplo n.º 8
0
static const char* classify_adr(void* a)
{
    unsigned i;
    classify_adr_init();
    for (i = 0; i < count_of(adr_classes); ++i)
        if (classify_adr_1(a, &adr_classes[i]))
            return adr_classes[i].name;
    return "";
}
Ejemplo n.º 9
0
/*
 * ESC * b # M
 *
 * Set compresson method.
 *
 * This command is unique among PCL commands in that it is interpreted both
 * inside and outside of graphics mode, and its execution neither starts nor
 * ends graphic mode.
 *
 * It is not possible to use adaptive compression (mode 5) with mutliple plane
 * pixel encodings, but it is not possible to check for a conflict at this
 * point as the pixel encoding may be changed before any raster data is
 * transfered. Hence, the transfer raster data command must perform the required
 * check.
 */
  static int
set_compression_method(
    pcl_args_t *    pargs,
    pcl_state_t *   pcs
)
{
    uint            mode = uint_arg(pargs);

    if ( (mode < count_of(pcl_decomp_proc))                                 &&
         ((pcl_decomp_proc[mode] != 0) || (mode == (uint)ADAPTIVE_COMPRESS))  )
        pcs->raster_state.compression_mode = mode;
    return 0;
}
Ejemplo n.º 10
0
int
parse_flag_option(char *opt, struct option_data *data)
{
    size_t i;

    for (i = 0; i < count_of(extensions_info); i++) {
        struct extension_info *extension = &extensions_info[i];
        if (strcmp(opt, extension->option_name)==0) {
            data->extensions |= extension->flag;
            return 1;
        }
    }

    for (i = 0; i < count_of(html_flags_info); i++) {
        struct html_flag_info *html_flag = &html_flags_info[i];
        if (strcmp(opt, html_flag->option_name)==0) {
            data->html_flags |= html_flag->flag;
            return 1;
        }
    }

    return 0;
}
Ejemplo n.º 11
0
int init_grid()
{
  grid_width_multiple = (float)GRID_MAX_WIDTH / (float)MAX_WIDTH;
  grid_height_multiple = (float)GRID_MAX_HEIGHT / (float)MAX_HEIGHT;

  printf("Grid scale: %f x %f\n", grid_width_multiple, grid_height_multiple);

  int i = 0;
  for (i = 0; i < count_of(grid); ++i) {
    grid[i] = (char*)malloc((size_t)(sizeof(char) * (3+GRID_MAX_WIDTH)));
    memset(grid[i], ' ', sizeof(char) * (2+GRID_MAX_WIDTH));
    grid[i][GRID_MAX_WIDTH] = 0;
  }
}
Ejemplo n.º 12
0
int
parse_category_option(char *opt, struct option_data *data)
{
    size_t i;
    const char *name = strprefix(opt, category_prefix);
    if (!name) return 0;

    for (i = 0; i < count_of(categories_info); i++) {
        struct extension_category_info *category = &categories_info[i];
        if (strcmp(name, category->option_name)==0) {
            data->extensions |= category->flags;
            return 1;
        }
    }

    return 0;
}
Ejemplo n.º 13
0
int clear_grid()
{
  int i = 0;
  for (i = 0; i < count_of(grid); ++i) {
    memset(grid[i], ' ', GRID_MAX_WIDTH * sizeof(char));
    //grid[i][GRID_MAX_WIDTH] = 0;
  }

  // Put a ruler across the middle
  memset(grid[GRID_MAX_HEIGHT/2], '-', GRID_MAX_WIDTH * sizeof(char));

  // Show the width and a vertical ruler across the middle
  for (i = 0; i < GRID_MAX_HEIGHT; ++i) {
    grid[i][GRID_MAX_WIDTH/2] = '|';
    grid[i][GRID_MAX_WIDTH] = '|';
  }
}
Ejemplo n.º 14
0
/*
 * Check if we want to use the PANTONE color processing logic for the given
 * Separation color space.
 */
static bool
client_pantone_install_Separation(client_custom_color_params_t * pparam,
			gs_color_space * pcs, gs_state * pgs)
{
    const gs_separation_name name = pcs->params.separation.sep_name;
    int pan_index;
    byte * pname;
    uint name_size;
    gx_device * dev = pgs->device;
    int num_pantone_colors = count_of(pantone_list);
    bool use_custom_color_callback = false;

    /* Exit if we have already installed this color space. */
    if (pcs->pclient_color_space_data != NULL)
		return true;

    /*
     * Get the character string and length for the component name.
     */
    pcs->params.separation.get_colorname_string(dev->memory, name,
						&pname, &name_size);
    /*
    * Compare the colorant name to those in our PANTONE color list.
    */
    for (pan_index = 0; pan_index < num_pantone_colors ; pan_index++) {
	const char * pan_name = pantone_list[pan_index].name;

	if (compare_names(pname, name_size, pan_name, strlen(pan_name))) {
	    use_custom_color_callback = true;
	    break;
	}
    }

    if (use_custom_color_callback) {
        demo_color_space_data_t * pclient_data =
		allocate_client_data_block(1, pcs->rc.memory->stable_memory);

	if (pclient_data == NULL)
		return false;
	pclient_data->color_index[0] = pan_index;
        pcs->pclient_color_space_data =
	       (client_color_space_data_t *) pclient_data;
    }
    return use_custom_color_callback;
}
Ejemplo n.º 15
0
bool WordFilterManager::doFilter(char* text, unsigned int len)
{
    zRegex regex;
    bool ret = true;

    char copy[MAX_CHATINFO+1];
    bzero(copy, sizeof(copy));
    strncpy(copy, text, MAX_CHATINFO);
    for(DWORD i=0; i<strlen(copy) && i<(count_of(copy)-1); i++)
    {
	copy[i] = tolower(copy[i]);
    }
    std::string content(text);
    std::string content_copy(copy);
    std::string::size_type pos = 0;
    std::map<std::string, std::string>::iterator it=forbidMaps.begin();
    for(; it!= forbidMaps.end(); ++it)
    {
	pos = content_copy.find(it->first.c_str(), 0);
	while(pos != std::string::npos)
	{
	    BYTE val = 0;
	    if(pos)
	    {
		val = content_copy.c_str()[pos-1]; //是否是汉子后面的一半
	    }

	    if(val >= 0x80)
	    {
		pos = content_copy.find(it->first.c_str(), pos+1);
	    }
	    else
	    {
		content.replace(pos, it->first.length(), it->second.c_str());
		content_copy.replace(pos, it->first.length(), it->second.c_str());

		pos = content_copy.find(it->first.c_str(), pos+it->first.length());
		ret = false;
	    }
	}
    }
    strncpy(text, content.c_str(), len);
    return ret;
}
Ejemplo n.º 16
0
bool WordFilterManager::loadFile()
{
    std::string f = Zebra::global["forbidWords"];
    if("" == f)
	f = "Config/forbidWords.txt";
    std::ifstream src(f.c_str());
    if(!src)
    {
	Zebra::logger->error("[forbidWords]打开屏蔽词文件失败");
	return false;
    }
    char buf[256];
    bzero(buf, sizeof(buf));
    std::vector<std::string> vs;
    std::vector<std::string>::iterator word, replacer;
    while(src.getline(buf, sizeof(buf)))
    {
	vs.clear();
	Zebra::stringtok(vs, buf, "\t\r");
	if(vs.size() == 3)
	{
	    replacer = vs.begin();
	    replacer++;
	    word = replacer++;

	    bzero(buf, sizeof(buf));
	    word->copy(buf, word->length(), 0);
	    for(DWORD i=0; i<word->length() && i<(count_of(buf)-1); i++)
	    {
		buf[i] = tolower(buf[i]);
	    }
	    word->assign(buf);

	    forbidMaps[*word] = *replacer;
	}
    }
    Zebra::logger->debug("[forbidWords]加载屏蔽词 %u 个",forbidMaps.size());
    return true;
}
Ejemplo n.º 17
0
/* Serialize. */
int
fn_common_serialize(const gs_function_t * pfn, stream *s)
{
    uint n;
    const gs_function_params_t * p = &pfn->params;
    int code = sputs(s, (const byte *)&pfn->head.type, sizeof(pfn->head.type), &n);
    const float dummy[8] = {0, 0, 0, 0,  0, 0, 0, 0};

    if (code < 0)
        return code;
    code = sputs(s, (const byte *)&p->m, sizeof(p->m), &n);
    if (code < 0)
        return code;
    code = sputs(s, (const byte *)&p->Domain[0], sizeof(p->Domain[0]) * p->m * 2, &n);
    if (code < 0)
        return code;
    code = sputs(s, (const byte *)&p->n, sizeof(p->n), &n);
    if (code < 0)
        return code;
    if (p->Range == NULL && p->n * 2 > count_of(dummy))
        return_error(gs_error_unregistered); /* Unimplemented. */
    return sputs(s, (const byte *)(p->Range != NULL ? &p->Range[0] : dummy),
            sizeof(p->Range[0]) * p->n * 2, &n);
}
Ejemplo n.º 18
0
int main(int argc, char *argv[])
{
  int blob_count = 0, i = 0;
  int main_channel = 2; /* red - botguy */
  double time_of_snapshot = 0.0;
  double start = 0.0;

  printf("args: %d\n", argc);
  if (argc > 1)
  {
    if (argv[1][0] == '0') main_channel = 0;
    else if (argv[1][0] == '1') main_channel = 1;
    else if (argv[1][0] == '2') main_channel = 2;
    else if (argv[1][0] == '3') main_channel = 3;
  }
  for (i = 0; i < argc; i++) {
    printf("arg[%d] = %s\n", i, argv[i]);
  }
  printf("\n");
  
  int area[NUM_TRACKING];
  point2 center[NUM_TRACKING];
  rectangle blob[NUM_TRACKING];
  //int area1 = 0, areaX = 0;
  //point2 center;

  init_grid();

  //wait_for_light(0);

  camera_open();
  printf("Num channels: %d", get_channel_count());
  camera_update();
  time_of_snapshot = seconds();
  msleep(300);
  
  start = seconds();
  do {
    // Initialize
    memset(center, 0, sizeof(center));
    memset(area, 0, sizeof(area));
    clear_grid();

    // Begin

    // Do not do anything with the camera until enough time has passed
    if (seconds() - time_of_snapshot >= 0.1) {
      camera_update();
      time_of_snapshot = seconds();
      blob_count = get_object_count(main_channel);
      //sprintf(msg, "#:%2d", blob_count); diag();
      printf("#:%-2d ", blob_count);
      if (blob_count > count_of(area)) {
        blob_count = count_of(area);
      }

      if (blob_count > 0) {
        for (i = 0; i < blob_count; ++i) {
          area[i]   = get_object_area(main_channel, i);
          center[i] = get_object_center(main_channel, i);
          blob[i] = get_object_bbox(main_channel, i);
          plot(&blob[i], i + '0');
        }

        for (i = 0; i < blob_count; ++i) {
          printf(" %3d", blob[i].width * blob[i].height);
        }

        for (; i < count_of(blob); ++i) {
          printf("    ");
        }

        printf("        ");
        for (i = 0; i < blob_count; ++i) {
          printf(" %2dx%2d", blob[i].width, blob[i].height);
        }

        //show_xy(center[0].x, center[0].y);
      }

      //printf(" |%3d %4d <-> %4d %3d|  %s\n", delta_left, left, right, delta_right, message);
      printf("%s\n", message);
      message[0] = 0;
      diag();

      show_grid();
    }

    //printf("The time is: %f   %f\n", seconds(), seconds() - start);
  } while (seconds() - start <= 4.0);

  camera_close();

  return 0;
}
Ejemplo n.º 19
0
int
main(int argc, char **argv)
{
	int show_time = 0;
	//struct timespec start, end;

	/* buffers */
	hoedown_buffer *ib, *ob;
	size_t iunit = DEF_IUNIT, ounit = DEF_OUNIT;

	/* files */
	FILE *in = NULL;

	/* renderer */
	int toc_level = 0;
	int renderer_type = RENDERER_HTML;

	/* document */
	hoedown_document *document;
	unsigned int extensions = 0;
	size_t max_nesting = DEF_MAX_NESTING;

	/* HTML renderer-specific */
	unsigned int html_flags = 0;


	/* option parsing */
	int just_args = 0;
	int i, j;
	for (i = 1; i < argc; i++) {
		char *arg = argv[i];
		if (!arg[0]) continue;

		if (just_args || arg[0] != '-') {
			/* regular argument */
			in = fopen(arg, "r");
			if (!in) {
				fprintf(stderr, "Unable to open input file \"%s\": %s\n", arg, strerror(errno));
				return 5;
			}
			continue;
		}

		if (!arg[1]) {
			/* arg is "-" */
			in = stdin;
			continue;
		}

		if (arg[1] != '-') {
			/* parse short options */
			char opt;
			const char *val;
			for (j = 1; (opt = arg[j]); j++) {
				if (opt == 'h') {
					print_help(argv[0]);
					return 1;
				}

				if (opt == 'v') {
					print_version();
					return 1;
				}

				if (opt == 'T') {
					show_time = 1;
					continue;
				}

				/* options requiring value */
				if (arg[++j]) val = arg+j;
				else if (argv[++i]) val = argv[i];
				else {
					fprintf(stderr, "Wrong option '-%c' found.\n", opt);
					return 1;
				}

				long int num;
				int isNum = parseint(val, &num);

				if (opt == 'n' && isNum) {
					max_nesting = num;
					break;
				}

				if (opt == 't' && isNum) {
					toc_level = num;
					break;
				}

				if (opt == 'i' && isNum) {
					iunit = num;
					break;
				}

				if (opt == 'o' && isNum) {
					ounit = num;
					break;
				}

				fprintf(stderr, "Wrong option '-%c' found.\n", opt);
				return 1;
			}
			continue;
		}

		if (!arg[2]) {
			/* arg is "--" */
			just_args = 1;
			continue;
		}

		/* parse long option */
		char opt [100];
		strncpy(opt, arg+2, 100);
		opt[99] = 0;

		char *val = strchr(opt, '=');

		long int num = 0;
		int isNum = 0;

		if (val) {
			*val = 0;
			val++;

			if (*val)
				isNum = parseint(val, &num);
		}

		int opt_parsed = 0;

		if (strcmp(opt, "help")==0) {
			print_help(argv[0]);
			return 1;
		}

		if (strcmp(opt, "version")==0) {
			print_version();
			return 1;
		}

		if (strcmp(opt, "max-nesting")==0 && isNum) {
			opt_parsed = 1;
			max_nesting = num;
		}
		if (strcmp(opt, "toc-level")==0 && isNum) {
			opt_parsed = 1;
			toc_level = num;
		}
		if (strcmp(opt, "input-unit")==0 && isNum) {
			opt_parsed = 1;
			iunit = num;
		}
		if (strcmp(opt, "output-unit")==0 && isNum) {
			opt_parsed = 1;
			ounit = num;
		}

		if (strcmp(opt, "html")==0) {
			opt_parsed = 1;
			renderer_type = RENDERER_HTML;
		}
		if (strcmp(opt, "html-toc")==0) {
			opt_parsed = 1;
			renderer_type = RENDERER_HTML_TOC;
		}
		if (strcmp(opt, "null")==0) {
			opt_parsed = 1;
			renderer_type = RENDERER_NULL;
		}

		const char *name;
		size_t i;

		/* extension categories */
		if ((name = strprefix(opt, category_prefix))) {
			for (i = 0; i < count_of(categories_info); i++) {
				struct extension_category_info *category = categories_info+i;
				if (strcmp(name, category->option_name)==0) {
					opt_parsed = 1;
					extensions |= category->flags;
					break;
				}
			}
		}

		/* extensions */
		for (i = 0; i < count_of(extensions_info); i++) {
			struct extension_info *extension = extensions_info+i;
			if (strcmp(opt, extension->option_name)==0) {
				opt_parsed = 1;
				extensions |= extension->flag;
				break;
			}
		}

		/* html flags */
		for (i = 0; i < count_of(html_flags_info); i++) {
			struct html_flag_info *html_flag = html_flags_info+i;
			if (strcmp(opt, html_flag->option_name)==0) {
				opt_parsed = 1;
				html_flags |= html_flag->flag;
				break;
			}
		}

		/* negations */
		if ((name = strprefix(opt, negative_prefix))) {
			for (i = 0; i < count_of(categories_info); i++) {
				struct extension_category_info *category = categories_info+i;
				if (strcmp(name, category->option_name)==0) {
					opt_parsed = 1;
					extensions &= ~(category->flags);
					break;
				}
			}
			for (i = 0; i < count_of(extensions_info); i++) {
				struct extension_info *extension = extensions_info+i;
				if (strcmp(name, extension->option_name)==0) {
					opt_parsed = 1;
					extensions &= ~(extension->flag);
					break;
				}
			}
			for (i = 0; i < count_of(html_flags_info); i++) {
				struct html_flag_info *html_flag = html_flags_info+i;
				if (strcmp(name, html_flag->option_name)==0) {
					opt_parsed = 1;
					html_flags &= ~(html_flag->flag);
					break;
				}
			}
		}

		if (strcmp(opt, "time")==0) {
			opt_parsed = 1;
			show_time = 1;
		}

		if (!opt_parsed) {
			fprintf(stderr, "Wrong option '%s' found.\n", arg);
			return 1;
		}
	}

	if (!in)
		in = stdin;


	/* reading everything */
	ib = hoedown_buffer_new(iunit);

	while (!feof(in)) {
		if (ferror(in)) {
			fprintf(stderr, "I/O errors found while reading input.\n");
			return 5;
		}
		hoedown_buffer_grow(ib, ib->size + iunit);
		ib->size += fread(ib->data + ib->size, 1, iunit, in);
	}

	if (in != stdin)
		fclose(in);


	/* creating the renderer */
	hoedown_renderer *renderer = NULL;
	void (*renderer_free)(hoedown_renderer*) = NULL;

	switch (renderer_type) {
		case RENDERER_HTML:
			renderer = hoedown_html_renderer_new(html_flags, toc_level);
			renderer_free = hoedown_html_renderer_free;
			break;
		case RENDERER_HTML_TOC:
			renderer = hoedown_html_toc_renderer_new(toc_level);
			renderer_free = hoedown_html_renderer_free;
			break;
		case RENDERER_NULL:
			renderer = null_renderer_new();
			renderer_free = null_renderer_free;
			break;
	};


	/* performing markdown rendering */
	ob = hoedown_buffer_new(ounit);
	document = hoedown_document_new(renderer, extensions, max_nesting);

	//clock_gettime(CLOCK_MONOTONIC, &start);
	hoedown_document_render(document, ob, ib->data, ib->size);
	//clock_gettime(CLOCK_MONOTONIC, &end);


	/* writing the result to stdout */
	(void)fwrite(ob->data, 1, ob->size, stdout);


	/* showing rendering time */
	if (show_time) {
		//TODO: enable this
		//long long elapsed = (  end.tv_sec*1000000000 +   end.tv_nsec)
		//                  - (start.tv_sec*1000000000 + start.tv_nsec);
		//if (elapsed < 1000000000)
		//	fprintf(stderr, "Time spent on rendering: %.2f ms.\n", ((double)elapsed)/1000000);
		//else
		//	fprintf(stderr, "Time spent on rendering: %.3f s.\n", ((double)elapsed)/1000000000);
	}


	/* cleanup */
	hoedown_buffer_free(ib);
	hoedown_buffer_free(ob);

	hoedown_document_free(document);
	renderer_free(renderer);

	if (ferror(stdout)) {
		fprintf(stderr, "I/O errors found while writing output.\n");
		return 5;
	}

	return 0;
}
Ejemplo n.º 20
0
/*
 * Check if we want to use the PANTONE color processing logic for the given
 * DeviceN color space.
 */
static bool
client_pantone_install_DeviceN(client_custom_color_params_t * pparam,
			gs_color_space * pcs, gs_state * pgs)
{
    const gs_separation_name *names = pcs->params.device_n.names;
    int num_comp = pcs->params.device_n.num_components;
    int i;
    int pan_index;
    byte * pname;
    uint name_size;
    gx_device * dev = pgs->device;
    int num_pantone_colors = count_of(pantone_list);
    bool pantone_found = false;
    bool other_separation_found = false;
    bool use_pantone;
    const char none_str[] = "None";
    const uint none_size = strlen(none_str);
    const char cyan_str[] = "Cyan";
    const uint cyan_size = strlen(cyan_str);
    const char magenta_str[] = "Magenta";
    const uint magenta_size = strlen(magenta_str);
    const char yellow_str[] = "Yellow";
    const uint yellow_size = strlen(yellow_str);
    const char black_str[] = "Black";
    const uint black_size = strlen(black_str);
    int pantone_color_index[GS_CLIENT_COLOR_MAX_COMPONENTS];

    /* Exit if we have already installed this color space. */
    if (pcs->pclient_color_space_data != NULL)
		return true;

    /*
     * Now check the names of the color components.
     */
    for(i = 0; i < num_comp; i++ ) {
	bool match = false;

	/*
	 * Get the character string and length for the component name.
	 */
	pcs->params.device_n.get_colorname_string(dev->memory, names[i],
							&pname, &name_size);
	/*
         * Postscript does not include /None as a color component but it is
         * allowed in PDF so we accept it.  We simply skip components named
	 * 'None'.
         */
	if (compare_names(none_str, none_size, pname, name_size)) {
	    pantone_color_index[i] = PANTONE_NONE;
	    continue;
	}
	/*
	 * Check if our color space includes the CMYK process colors.
	 */
	if (compare_names(cyan_str, cyan_size, pname, name_size)) {
	    pantone_color_index[i] = PANTONE_CYAN;
	    continue;
	}
	if (compare_names(magenta_str, magenta_size, pname, name_size)) {
	    pantone_color_index[i] = PANTONE_MAGENTA;
	    continue;
	}
	if (compare_names(yellow_str, yellow_size, pname, name_size)) {
	    pantone_color_index[i] = PANTONE_YELLOW;
	    continue;
	}
	if (compare_names(black_str, black_size, pname, name_size)) {
	    pantone_color_index[i] = PANTONE_BLACK;
	    continue;
	}
	/*
	 * Compare the colorant name to those in our Pantone color list.
	 */
	for (pan_index = 0; pan_index < num_pantone_colors ; pan_index++) {
	    const char * pan_name = pantone_list[pan_index].name;

	    if (compare_names(pname, name_size, pan_name, strlen(pan_name))) {
	        pantone_color_index[i] = pan_index;
		match = pantone_found = true;
		break;
	    }
	}
	if (!match) {		/* Exit if we find a non Pantone color */
	    other_separation_found = true;
	    break;
	}
    }
    /*
     * Handle this color space as a 'pantone color space' if we have only
     * PANTONE colors and CMYK.  Any other separations will force us to
     * use the normal Ghostscript processing for a DeviceN color space.
     */
    use_pantone = pantone_found && !other_separation_found;
    if (use_pantone) {
        demo_color_space_data_t * pclient_data =
		allocate_client_data_block(1, pcs->rc.memory->stable_memory);

        if (pclient_data == NULL)
	    return false;
        for(i = 0; i < num_comp; i++ )
	    pclient_data->color_index[i] = pantone_color_index[i];
        pcs->pclient_color_space_data =
	       (client_color_space_data_t *) pclient_data;
    }
    return use_pantone;
}
Ejemplo n.º 21
0
/* Do per-instance interpreter allocation/init. No device is set yet */
static int   /* ret 0 ok, else -ve error code */
ps_impl_allocate_interp_instance(
  pl_interp_instance_t   **instance,     /* RETURNS instance struct */
  pl_interp_t            *interp,        /* dummy interpreter */
  gs_memory_t            *mem            /* allocator to allocate instance from */
)
{
#ifdef DEBUG_WITH_EXPERIMENTAL_GSOPTIONS_FILE
#   define MAX_ARGS 40
#else
#   define MAX_ARGS /* unspecified */
#endif
	int code = 0, exit_code;
	const char *argv[MAX_ARGS] = { 
	    "",
	    "-dNOPAUSE",
#ifndef DEBUG
	    "-dQUIET",
#else
	    "-dOSTACKPRINT", // NB: debuggging postscript Needs to be removed. 
	    "-dESTACKPRINT", // NB: debuggging postscript Needs to be removed. 
#endif
#if UFST_BRIDGE==1
	    "-dJOBSERVER", 
	    "-sUFST_PlugIn=" UFSTFONTDIR "mtfonts/pcl45/mt3/plug__xi.fco",
            "-sFCOfontfile=" UFSTFONTDIR "mtfonts/pclps2/mt3/pclp2_xj.fco",
            "-sFCOfontfile2=" UFSTFONTDIR "mtfonts/pcl45/mt3/wd____xh.fco",
	    "-sFAPIfontmap=FCOfontmap-PCLPS2",
	    "-sFAPIconfig=FAPIconfig-FCO",
#endif
	    0
	};
#ifndef DEBUG
	int argc = 9;
#else
	int argc = 10;
#endif
#ifdef DEBUG_WITH_EXPERIMENTAL_GSOPTIONS_FILE
	char argbuf[1024];
#endif
#   undef MAX_ARGS
	ps_interp_instance_t *psi  /****** SHOULD HAVE A STRUCT DESCRIPTOR ******/
	    = (ps_interp_instance_t *)
	    gs_alloc_bytes( mem,
			    sizeof(ps_interp_instance_t),
			    "ps_allocate_interp_instance(ps_interp_instance_t)"	
			    );

#if UFST_BRIDGE!=1
    argc -= 6;
#endif


	/* If allocation error, deallocate & return */
	if (!psi) {
	  return gs_error_VMerror;
	}
	/* Initialize for pl_main_universe_dnit/pl_deallocate_interp_instance
	   in case of gs_main_init_with_args returns with error code. */
	psi->pl.interp = interp;
	/* Setup pointer to mem used by PostScript */
	psi->plmemory = mem;
	psi->minst = gs_main_alloc_instance(mem->non_gc_memory);

#ifdef DEBUG_WITH_EXPERIMENTAL_GSOPTIONS_FILE
	{   /* Fetch more GS arguments (debug purposes only).
	       Pulling debugging arguments from a file allows easy additions
	       of postscript arguments to a debug system, it is not recommended for 
	       production systems since some options will conflict with commandline 
	       arguments in unpleasant ways.  
	    */
	    FILE *f = fopen("gsoptions", "rb"); /* Sorry we handle 
					          the current directory only.
						  Assuming it always fails with no crash
						  in a real embedded system. */

	    if (f != NULL) {
		int i;
		int l = fread(argbuf, 1, sizeof(argbuf) - 1, f);

		if (l >= sizeof(argbuf) - 1)
		    errprintf("The gsoptions file is too big. Truncated to the buffer length %d.\n", l - 1);
		if (l > 0) {
		    argbuf[l] = 0;
		    if (argbuf[0] && argbuf[0] != '\r' && argbuf[0] != '\n') /* Silently skip empty lines. */
			argv[argc++] = argbuf;
		    for (i = 0; i < l; i++)
			if (argbuf[i] == '\r' || argbuf[i] == '\n') {
			    argbuf[i] = 0;
			    if (argbuf[i + 1] == 0 || argbuf[i + 1] == '\r' || argbuf[i + 1] == '\n')
				continue; /* Silently skip empty lines. */
			    if (argc >= count_of(argv)) {
				errprintf("The gsoptions file contains too many options. "
					  "Truncated to the buffer length %d.\n", argc);
				break;
			    }
			    argv[argc++] = argbuf + i + 1;
			}
		}
		fclose(f);
	    }
	}
#endif

	*instance = (pl_interp_instance_t *)psi;
	code = gs_main_init_with_args(psi->minst, argc, (char**)argv);
	if (code<0)
	    return code;

	/* General init of PS interp instance */
	
	if ((code = gs_main_run_string_begin(psi->minst, 0, &exit_code, &psi->minst->error_object)) < 0)
	    return exit_code;

        {    
            gs_state *pgs = psi->minst->i_ctx_p->pgs;
            gsicc_init_iccmanager(pgs);
        }
        /* inialize fresh job to false so that we can check for a pdf
           file next job. */
        psi->fresh_job = true;
        /* default is a postscript stream */
        psi->pdf_stream = false;

	/* Return success */
	return 0;
}
Ejemplo n.º 22
0
void CMap::Init()
{
	m_vecBackLine.reserve((GRID_X_NUM + 1) * 2 + (GRID_Y_NUM + 1) * 2);
	//back line  x
	for (int i = 0; i < GRID_X_NUM + 1; ++i)
	{
		Vec2F pt;
		pt.x = i * GRID_WIDTH;
		pt.y = 0;
		m_vecBackLine.push_back(pt);

		pt.x = i * GRID_WIDTH;
		pt.y = GRID_Y_NUM * GRID_HEIGHT;
		m_vecBackLine.push_back(pt);
	}
	//back line  y
	for (int i = 0; i < GRID_Y_NUM + 1; ++i)
	{
		Vec2F pt;
		pt.x = 0;
		pt.y = i * GRID_HEIGHT;
		m_vecBackLine.push_back(pt);

		pt.x = GRID_X_NUM * GRID_WIDTH;
		pt.y = i * GRID_HEIGHT ;
		m_vecBackLine.push_back(pt);
	}

	m_vecGrid.reserve(GRID_X_NUM * GRID_Y_NUM);
	m_vecRect.reserve(GRID_X_NUM * GRID_Y_NUM);
	// grid
	for (int i = 0; i < GRID_X_NUM; ++i)
	{
		for (int j = 0; j < GRID_Y_NUM; ++j)
		{
			stGrid grid;
			grid.pt.Set(i, j);
			grid.bBlock = false;
			m_vecGrid.push_back(grid);

			RectF rect;
			rect.SetRect(i * GRID_WIDTH, j * GRID_HEIGHT, (i + 1) * GRID_WIDTH, (j + 1) * GRID_HEIGHT);
			m_vecRect.push_back(rect);
		}
	}

	// block grid
	m_vecBlock.reserve(BLOCK_NUM);

	// BLOCK_NUM 个随机数,范围 num = [1 - GRID_X_NUM * GRID_Y_NUM)
	// 输出到坐标:row = num / GRID_X_NUM, col = num % GRID_X_NUM
	int grid_num[GRID_X_NUM * GRID_Y_NUM];
	int size = count_of(grid_num);
	for (int i = 0; i < size; ++i)
	{
		grid_num[i] = i;
	}

	// 打乱前BLOCK_NUM数
	for (int i = 0; i < BLOCK_NUM; ++i)
	{
		int index = random<int>(i, size - 1);
		rd_swap(grid_num[i], grid_num[index]);

		int num = grid_num[i];
		int row = num / GRID_X_NUM;
		int col = num % GRID_X_NUM;
		m_vecGrid[num].bBlock = true;

		RectF rect;
		rect.SetRect(col * GRID_WIDTH, row * GRID_HEIGHT, (col + 1) * GRID_WIDTH, (row + 1) * GRID_HEIGHT);
		m_vecBlock.push_back(rect);
	}

	//随机生成人物的位置,在红色格子上
	while (true)
	{
		int index = rand() % m_vecGrid.size();
		if (! m_vecGrid[index].bBlock)
		{
			m_pos = m_vecGrid[index].pt;
			m_rect.SetRect(m_pos.x * GRID_WIDTH, m_pos.y * GRID_HEIGHT, (m_pos.x + 1) * GRID_WIDTH, (m_pos.y + 1) * GRID_HEIGHT);
			break;
		}
	}

	m_Astar.SetTileJudge(this);
}
Ejemplo n.º 23
0
    namespace antenna
    {
        /**
         * @addtogroup mission_atenna
         * @{
         */
        /**
         * @brief Type definition of the specific deployment step handler.
         *
         * @param[in] state Reference to global satellite state.
         * @param[in] stateDescriptor Reference to deployment process state.
         * @param[in] driver Reference to current antenna driver instance
         */
        typedef void DeploymentProcedure(const SystemState& state, //
            AntennaMissionState& stateDescriptor,
            AntennaDriver& driver //
            );

        /**
         * @brief This deployment step performs regular deployment operation.
         *
         * @param[in] state Reference to global satellite state.
         * @param[in] stateDescriptor Reference to the deployment process state object.
         * @param[in] driver Reference to current antenna driver instance.
         */
        static void RegularDeploymentStep(const SystemState& state, //
            AntennaMissionState& stateDescriptor,
            AntennaDriver& driver //
            );

        /**
         * @brief This deployment step resets current hardware channel.
         *
         * @param[in] state Reference to global satellite state.
         * @param[in] stateDescriptor Reference to the deployment process state object.
         * @param[in] driver Reference to current antenna driver instance.
         */
        static void ResetDriverStep(const SystemState& state, //
            AntennaMissionState& stateDescriptor,
            AntennaDriver& driver //
            );

        /**
         * @brief This deployment step finalizes antenna deployment process.
         *
         * @param[in] state Reference to global satellite state.
         * @param[in] stateDescriptor Reference to the deployment process state object.
         * @param[in] driver Reference to current antenna driver instance.
         */
        static void FinishDeploymentStep(const SystemState& state, //
            AntennaMissionState& stateDescriptor,
            AntennaDriver& driver //
            );

        /**
         * @brief Deployment step retry limit.
         *
         * This value controls how many times each deployment step will be repeated
         * in case of errors before process can advance further.
         */
        static constexpr std::uint8_t StepRetryLimit = 3;

        /**
         * @brief Hardware operation retry limit.
         *
         * This value controls how many times each hardware operation will be issued
         * in case of errors before declaring it as a failure.
         */
        static constexpr std::uint8_t RetryLimit = 3;

        /**
         * @brief Class that describes single deployment step.
         *
         * The entire process is driven by the array of steps, each described by the object of this type.
         */
        struct AntennaDeploymentStep final
        {
            /**
             * @brief Pointer to the procedure the performs current step.
             */
            DeploymentProcedure* procedure;

            /**
             * @brief Hardware channel that should be used to perform this step.
             */
            AntennaChannel channel;

            /**
             * @brief Identifier of the antenna that should be used/affected by this step.
             */
            AntennaId antennaId;

            /**
             * @brief Antenna deployment process timeout in seconds.
             */
            uint8_t deploymentTimeout;

            /**
             * @brief Flag indicating whether hardware deployment switches should be overriden.
             */
            bool overrideSwitches;
        };

        /**
         * @brief Default timeout value that should be enough in case there are no problems.
         */
        constexpr std::uint8_t DefaultTimeout = 9;

        /**
         * @brief Extended timeout that should take care of the most of the problems.
         */
        constexpr std::uint8_t MediumTimeout = 19;

        /**
         * @brief Long timeouts for heating problems.
         */
        constexpr std::uint8_t LongTimeout = 39;

        /**
         * @brief Last resort timeout in case everything else fails.
         */
        constexpr std::uint8_t EmergencyTimeout = 59;

        /**
         * @brief Array of antenna deployment steps.
         *
         * The entire process is composed of steps that are run in sequence from the beginning. Steps themselves are
         * grouped into series that together form logical variant of the antenna deployment process.
         *
         * Following is the list of the deployment stages that are defined in this array:
         * - Automatic deployment (primary hardware channel)
         * - Automatic deployment (backup hardware channel)
         * - Manual deployment (primary hardware channel)
         * - Manual deployment (backup hardware channel)
         * - Manual deployment with increased deployment timeout (primary hardware channel)
         * - Manual deployment with increased deployment timeout (backup hardware channel)
         * - Manual deployment with overridden deployment switches (primary hardware channel)
         * - Manual deployment with overridden deployment switches (backup hardware channel)
         * - Deployment finalization (primary hardware channel)
         * - Deployment finalization (backup hardware channel)
         */
        static const AntennaDeploymentStep deploymentSteps[] = {
            {ResetDriverStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA_AUTO_ID, 0, false},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA_AUTO_ID, DefaultTimeout, false},

            {ResetDriverStep, ANTENNA_BACKUP_CHANNEL, ANTENNA_AUTO_ID, 0, false},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA_AUTO_ID, DefaultTimeout, false},

            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA1_ID, DefaultTimeout, false},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA2_ID, DefaultTimeout, false},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA3_ID, DefaultTimeout, false},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA4_ID, DefaultTimeout, false},

            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA1_ID, DefaultTimeout, false},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA2_ID, DefaultTimeout, false},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA3_ID, DefaultTimeout, false},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA4_ID, DefaultTimeout, false},

            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA1_ID, MediumTimeout, false},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA2_ID, MediumTimeout, false},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA3_ID, MediumTimeout, false},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA4_ID, MediumTimeout, false},

            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA1_ID, MediumTimeout, false},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA2_ID, MediumTimeout, false},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA3_ID, MediumTimeout, false},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA4_ID, MediumTimeout, false},

            {ResetDriverStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA_AUTO_ID, 0, false},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA1_ID, LongTimeout, true},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA2_ID, LongTimeout, true},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA3_ID, LongTimeout, true},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA4_ID, LongTimeout, true},

            {ResetDriverStep, ANTENNA_BACKUP_CHANNEL, ANTENNA_AUTO_ID, 0, false},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA1_ID, LongTimeout, true},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA2_ID, LongTimeout, true},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA3_ID, LongTimeout, true},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA4_ID, LongTimeout, true},

            {ResetDriverStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA_AUTO_ID, 0, false},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA1_ID, EmergencyTimeout, true},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA2_ID, EmergencyTimeout, true},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA3_ID, EmergencyTimeout, true},
            {RegularDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA4_ID, EmergencyTimeout, true},

            {ResetDriverStep, ANTENNA_BACKUP_CHANNEL, ANTENNA_AUTO_ID, 0, false},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA1_ID, EmergencyTimeout, true},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA2_ID, EmergencyTimeout, true},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA3_ID, EmergencyTimeout, true},
            {RegularDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA4_ID, EmergencyTimeout, true},
            {FinishDeploymentStep, ANTENNA_PRIMARY_CHANNEL, ANTENNA_AUTO_ID, 0, false},
            {FinishDeploymentStep, ANTENNA_BACKUP_CHANNEL, ANTENNA_AUTO_ID, 0, false},
        };

        /**
         * @brief Number of steps in the antenna deployment process.
         */
        static constexpr uint8_t DeploymentStepLimit = count_of(deploymentSteps);

        /**
         * @brief Number of the first step in the deployment finalization phase.
         */
        static constexpr uint8_t FinalizationStepIndex = count_of(deploymentSteps) - 2;

        static_assert(DeploymentStepLimit > FinalizationStepIndex, "There should be at least one finalization step");

        AntennaMissionState::AntennaMissionState(AntennaDriver& antennaDriver)
            : _overrideState(false), //
              _inProgress(false),    //
              _stepNumber(0),        //
              _retryCount(0),        //
              _driver(antennaDriver)
        {
        }

        void AntennaMissionState::Retry(std::uint8_t limit)
        {
            if ((this->_retryCount + 1) == limit)
            {
                NextStep();
            }
            else
            {
                ++this->_retryCount;
            }
        }

        bool AntennaMissionState::IsFinished() const
        {
            return this->_stepNumber >= DeploymentStepLimit;
        }

        bool AntennaMissionState::IsDeploymentPartFinished() const
        {
            return this->_stepNumber >= FinalizationStepIndex;
        }

        void AntennaMissionState::Update(const AntennaDeploymentStatus& status)
        {
            this->_inProgress = status.IsDeploymentActive[0] | //
                status.IsDeploymentActive[1] |                 //
                status.IsDeploymentActive[2] |                 //
                status.IsDeploymentActive[3];
        }

        std::uint8_t AntennaMissionState::StepCount()
        {
            return DeploymentStepLimit;
        }

        std::uint8_t AntennaMissionState::DeploymentStepCount()
        {
            return FinalizationStepIndex;
        }

        /**
         * @brief This procedure is supposed to stop any deployment process that may currently be active on the
         * passed hardware channel.
         *
         * @param[in] driver Reference to current antenna driver instance.
         * @param[in] channel Hardware channel that should be used for current operation.
         * @param[in] retryCount Number of step retry attempts in case of errors.
         * @return True if operation has been successfully completed, false otherwise.
         */
        static bool EndDeployment(AntennaDriver& driver, AntennaChannel channel, std::uint8_t retryCount)
        {
            while (retryCount-- > 0)
            {
                const OSResult status = driver.FinishDeployment(&driver, channel);
                if (OS_RESULT_SUCCEEDED(status))
                {
                    return true;
                }
            }

            return false;
        }

        /**
         * @brief This procedure is supposed to stop any deployment process that may currently be active on the
         * hardware channel used in the previous step.
         *
         * @param[in] state Reference to global satellite state.
         * @param[in] stateDescriptor Reference to the deployment process state object.
         * @param[in] driver Reference to current antenna driver instance.
         */
        static void StopDeployment(const SystemState& state,
            AntennaMissionState& stateDescriptor,
            AntennaDriver& driver //
            )
        {
            UNREFERENCED_PARAMETER(state);
            if (stateDescriptor.StepNumber() == 0)
            {
                return;
            }

            const AntennaDeploymentStep& step = deploymentSteps[stateDescriptor.StepNumber() - 1];
            EndDeployment(driver, step.channel, RetryLimit);
        }

        /**
         * @brief This procedure is supposed to start deployment process described by the current step.
         *
         * @param[in] state Reference to global satellite state.
         * @param[in] stateDescriptor Reference to the deployment process state object.
         * @param[in] driver Reference to current antenna driver instance.
         */
        static void BeginDeployment(const SystemState& state,
            AntennaMissionState& stateDescriptor,
            AntennaDriver& driver //
            )
        {
            UNREFERENCED_PARAMETER(state);
            const AntennaDeploymentStep& step = deploymentSteps[stateDescriptor.StepNumber()];
            std::uint8_t counter = RetryLimit;
            while (counter-- > 0)
            {
                const OSResult result = driver.DeployAntenna(&driver,
                    step.channel,
                    step.antennaId,
                    TimeSpanFromSeconds(step.deploymentTimeout),
                    step.overrideSwitches //
                    );

                if (OS_RESULT_SUCCEEDED(result))
                {
                    stateDescriptor.NextStep();
                    return;
                }
            }

            stateDescriptor.Retry(StepRetryLimit);
        }

        void RegularDeploymentStep(const SystemState& state,
            AntennaMissionState& stateDescriptor,
            AntennaDriver& driver //
            )
        {
            StopDeployment(state, stateDescriptor, driver);
            BeginDeployment(state, stateDescriptor, driver);
        }

        void ResetDriverStep(const SystemState& state,
            AntennaMissionState& stateDescriptor,
            AntennaDriver& driver //
            )
        {
            UNREFERENCED_PARAMETER(state);
            const AntennaDeploymentStep& step = deploymentSteps[stateDescriptor.StepNumber()];

            std::uint8_t counter = RetryLimit;
            while (counter-- > 0)
            {
                const OSResult result = driver.Reset(&driver, step.channel);
                if (OS_RESULT_SUCCEEDED(result))
                {
                    stateDescriptor.NextStep();
                    return;
                }
            }

            stateDescriptor.Retry(StepRetryLimit);
        }

        void FinishDeploymentStep(const SystemState& state,
            AntennaMissionState& stateDescriptor,
            AntennaDriver& driver //
            )
        {
            UNREFERENCED_PARAMETER(state);
            const AntennaDeploymentStep& step = deploymentSteps[stateDescriptor.StepNumber()];
            if (EndDeployment(driver, step.channel, RetryLimit))
            {
                stateDescriptor.NextStep();
            }
            else
            {
                stateDescriptor.Retry(StepRetryLimit);
            }
        }

        /**
         * @brief This procedure is deployment action entry point.
         *
         * This procedure runs the antenna deployment process.
         * @param[in] state Pointer to global satellite state.
         * @param[in] param Pointer to the deployment condition private context. This pointer should point
         * at the object of AntennaMissionState type.
         */
        static void AntennaDeploymentAction(const SystemState& state, void* param)
        {
            AntennaMissionState* stateDescriptor = (AntennaMissionState*)param;
            const AntennaDeploymentStep& step = deploymentSteps[stateDescriptor->StepNumber()];
            DeploymentProcedure* procedure = step.procedure;
            procedure(state, *stateDescriptor, stateDescriptor->Driver());
        }

        /**
         * @brief This procedure checks whether there is currently antenna deployment process in progress.
         * @param[in] deploymentState Current driver deployment state
         * @return True if at least one antenna is being deployed, false otherwise.
         */
        static bool AreAllAntennasDeployed(const AntennaDeploymentStatus& deploymentState)
        {
            return deploymentState.DeploymentStatus[0] & //
                deploymentState.DeploymentStatus[1] &    //
                deploymentState.DeploymentStatus[2] &    //
                deploymentState.DeploymentStatus[3];
        }

        /**
         * @brief Procedure that verifies whether the antenna deployment process should be executed.
         * @param[in] state Pointer to global satellite state.
         * @param[in] param Pointer to the deployment condition private context. This pointer should point
         * at the object of AntennaMissionState type.
         *
         * @return True if the deployment action should be performed, false otherwise.
         */
        static bool AntennaDeploymentCondition(const SystemState& state, void* param)
        {
            AntennaMissionState* stateDescriptor = (AntennaMissionState*)param;
            const TimeSpan t = TimeSpanFromMinutes(40);
            if (TimeSpanLessThan(state.Time, t))
            {
                return false;
            }

            if (stateDescriptor->IsDeploymentInProgress())
            {
                return false;
            }

            return !stateDescriptor->IsFinished();
        }

        /**
         * @brief This procedure is antenna deployment update descriptor entry point.
         *
         * This procedure updates the global satellite state as well as deployemnt process private state.
         * @param[in] state Pointer to global satellite state.
         * @param[in] param Pointer to the deployment condition private context. This pointer should point
         * at the object of AntennaMissionState type.
         * @return Operation status.
         */
        static UpdateResult AntennaDeploymentUpdate(SystemState& state, void* param)
        {
            UNREFERENCED_PARAMETER(state);
            AntennaMissionState* stateDescriptor = (AntennaMissionState*)param;
            if (stateDescriptor->IsFinished())
            {
                return UpdateResult::Ok;
            }

            AntennaDeploymentStatus deploymentStatus;
            AntennaDriver& driver = stateDescriptor->Driver();
            const OSResult result = driver.GetDeploymentStatus(&driver,
                deploymentSteps[stateDescriptor->StepNumber()].channel,
                &deploymentStatus //
                );

            if (OS_RESULT_FAILED(result))
            {
                return UpdateResult::Failure;
            }

            for (int i = 0; i < 4; ++i)
            {
                state.Antenna.DeploymentState[i] = deploymentStatus.DeploymentStatus[i] || state.Antenna.DeploymentState[i];
            }

            stateDescriptor->Update(deploymentStatus);

            if (                                                //
                !stateDescriptor->IsDeploymentPartFinished() && //
                !stateDescriptor->OverrideState() &&            //
                AreAllAntennasDeployed(deploymentStatus)        //
                )
            {
                stateDescriptor->OverrideStep(FinalizationStepIndex);
            }

            state.Antenna.Deployed = stateDescriptor->IsFinished();
            return UpdateResult::Ok;
        }

        AntennaTask::AntennaTask(AntennaDriver& driver) : state(driver)
        {
        }

        ActionDescriptor<SystemState> AntennaTask::BuildAction()
        {
            ActionDescriptor<SystemState> descriptor;
            descriptor.name = "Deploy Antenna Action";
            descriptor.param = &this->state;
            descriptor.condition = AntennaDeploymentCondition;
            descriptor.actionProc = AntennaDeploymentAction;
            return descriptor;
        }

        UpdateDescriptor<SystemState> AntennaTask::BuildUpdate()
        {
            UpdateDescriptor<SystemState> descriptor;
            descriptor.name = "Deploy Antenna Update";
            descriptor.param = &this->state;
            descriptor.updateProc = AntennaDeploymentUpdate;
            return descriptor;
        }

        /** @}*/
    }