Exemple #1
0
Fichier : ui.c Projet : ab/pwman
char *
ui_statusline_ask_str_with_autogen(char *msg, char *input, int len, char *(*autogen)(char *), int ch)
{
	int i = 0;
	int c;
	char *text[2], *s;
	int x;

	if(input == NULL){
		input = malloc(len);
	}
	text[0] = malloc(STRING_MEDIUM);
	text[1] = malloc(STRING_SHORT);
	
	strncpy(text[1], msg, STRING_SHORT);
	if(s = strrchr(text[1], ':')){
		*s = 0;
	}
	snprintf(text[0], STRING_MEDIUM, "%s(%c for autogen):\t", text[1],ch);
	x = strlen(text[0]) + 5;

	ui_statusline_clear();
	ui_statusline_msg(text[0]);

	show_cursor();
	noecho();

	wmove(bottom, 1, x);

	while(i < len){
		c = wgetch(bottom);
		if(c == 0x7f){
			if(i){
				i--;
				mvwaddch(bottom, 1, x+i, ' ');
				wmove(bottom, 1, x+i);
			}
		} else if(c == 0xd){
			input[i] = 0;
			break;
		} else if(c == ch){
			input = autogen(input);
			break;
		} else {
			input[i] = c;
			mvwaddch(bottom, 1, x + i, c);
			i++;
		}
	}
	
	hide_cursor();
	
	ui_statusline_clear();

	free(text[0]);
	free(text[1]);

	return input;
}
  void
  xml_compiler::remapclasses_initialize_vector_loader::traverse_autogen_(const extracted_ptree& pt,
                                                                         const std::string& identifier,
                                                                         const std::string& raw_identifier)
  {
    // Add passthrough filter.
    if (filter_vector_.empty() &&
        ! boost::starts_with(identifier, "passthrough_")) {
      filter_vector_.push_back(2); // count
      filter_vector_.push_back(BRIDGE_FILTERTYPE_CONFIG_NOT);
      filter_vector_.push_back(symbol_map_cache_configindex_notsave_passthrough_);
    }

    filter_vector_.traverse(pt);

    // ----------------------------------------
    for (const auto& it : pt) {
      if (it.get_tag_name() == "item") {
        xml_compiler_.error_information_.set(boost::format("You should not write <identifier> in <item> which has child <item> nodes.\nRemove <identifier>%1%</identifier>.") % raw_identifier);

      } else if (it.get_tag_name() != "autogen") {
        size_t s = filter_vector_.size();
        traverse_autogen_(it.children_extracted_ptree(), identifier, raw_identifier);
        filter_vector_.resize(s);

      } else {
        std::string raw_autogen = boost::trim_left_copy(it.get_data());

        // ----------------------------------------
        std::string autogen(raw_autogen);

        // Replacing -- with __ for compatibility.
        // * --KeyToKey-- before version 8.0.0.
        // * __KeyToKey__ since version 8.0.0.
        if (boost::starts_with(autogen, "--")) {
          autogen[0] = '_';
          autogen[1] = '_';
          boost::replace_first(autogen, "--", "__");
        }

        // drop whitespaces for preprocessor. (for FROMKEYCODE_HOME, etc)
        // Note: preserve space when __ShowStatusMessage__.
        if (! boost::starts_with(autogen, "__ShowStatusMessage__")) {
          pqrs::string::remove_whitespaces(autogen);
        }

        handle_autogen(autogen, raw_autogen);
      }
    }
  }
Exemple #3
0
int main(int agrc, char* agrv[]) {
	FILE* out_file = NULL;
	if (agrc == 2) out_file = fopen(agrv[1], "a"); // agrc = total num of para + 1; agrv[0] = the address of the program itself;
	else printf("usage: tfgen <filename>\n");

	if (out_file == NULL) { printf("Cannot create file. Program abort.\n"); exit(1); }

	int numOfCases = 0;
	printf("How many test cases? "); scanf("%d", &numOfCases); getchar();
	if 	(numOfCases > 0) fprintf(out_file, "%d\n", numOfCases);
	else if (numOfCases < 0) numOfCases*=-1;   // ignore test case number
	else exit(1);

	int i;
	for (i = 1; i <= numOfCases; i++) {
		printf("Case#%d auto-generate?(y/n) ", i);
		if ('y' == getchar() & '\n' == getchar()) autogen(out_file, i);
		
		/* manual input */
		else {
			printf("The input for test case#%d: ($ for the end of input)\n", i);
			while (1) {
				char c = getchar();
				if (c == '$') { 
					if (getchar() == '$') fprintf(out_file, "%c", c);
					else { fprintf(out_file, "%c", '\n'); setbuf(stdin, NULL); break; } // end of line & clear input buffer
				} else fprintf(out_file, "%c", c);
			}
		}
	}

	if (out_file) {}


	fclose(out_file); out_file = NULL;
	return 0;
}