Beispiel #1
0
void Description::addGroup(int level, Tree t)
{
  Tree label, elements, varname, sig;
  const char* groupnames[] =
  {
    "vgroup", "hgroup", "tgroup"
  };

  if(isUiFolder(t, label, elements))
  {
    const int orient = tree2int(left(label));

    addLayoutLine(level, subst("<group type=\"$0\">", groupnames[orient]));
    addLayoutLine(level + 1, subst("<label>$0</label>", checkNullLabel(t, xmlize(tree2str(right(label))), false)));

    while(!isNil(elements))
    {
      addGroup(level + 1, right(hd(elements)));
      elements = tl(elements);
    }

    addLayoutLine(level, "</group>");
  }
  else if(isUiWidget(t, label, varname, sig))
  {
    int w = addWidget(label, varname, sig);
    addLayoutLine(level, subst("<widgetref id=\"$0\" />", T(w)));
  }
  else
  {
    fprintf(stderr, "error in user interface generation 2\n");
    exit(1);
  }
}
Beispiel #2
0
int Description::addWidget(Tree label, Tree varname, Tree sig)
{
  Tree path, c, x, y, z;

  // add an active widget description

  if(isSigButton(sig, path))
  {
    fWidgetID++;
    fActiveWidgetCount++;
    addActiveLine(subst("<widget type=\"button\" id=\"$0\">", T(fWidgetID)));
    addActiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true)));
    addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname)));
    addActiveLine("</widget>");
  }
  else if(isSigCheckbox(sig, path))
  {
    fWidgetID++;
    fActiveWidgetCount++;
    addActiveLine(subst("<widget type=\"checkbox\" id=\"$0\">", T(fWidgetID)));
    addActiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true)));
    addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname)));
    addActiveLine("</widget>");
  }
  else if(isSigVSlider(sig, path, c, x, y, z))
  {
    fWidgetID++;
    fActiveWidgetCount++;
    addActiveLine(subst("<widget type=\"vslider\" id=\"$0\">", T(fWidgetID)));
    addActiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true)));
    addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname)));
    addActiveLine(subst("\t<init>$0</init>", T(tree2double(c))));
    addActiveLine(subst("\t<min>$0</min>", T(tree2double(x))));
    addActiveLine(subst("\t<max>$0</max>", T(tree2double(y))));
    addActiveLine(subst("\t<step>$0</step>", T(tree2double(z))));
    addActiveLine("</widget>");
  }
  else if(isSigHSlider(sig, path, c, x, y, z))
  {
    fWidgetID++;
    fActiveWidgetCount++;
    addActiveLine(subst("<widget type=\"hslider\" id=\"$0\">", T(fWidgetID)));
    addActiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true)));
    addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname)));
    addActiveLine(subst("\t<init>$0</init>", T(tree2double(c))));
    addActiveLine(subst("\t<min>$0</min>", T(tree2double(x))));
    addActiveLine(subst("\t<max>$0</max>", T(tree2double(y))));
    addActiveLine(subst("\t<step>$0</step>", T(tree2double(z))));
    addActiveLine("</widget>");
  }
  else if(isSigNumEntry(sig, path, c, x, y, z))
  {
    fWidgetID++;
    fActiveWidgetCount++;
    addActiveLine(subst("<widget type=\"nentry\" id=\"$0\">", T(fWidgetID)));
    addActiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true)));
    addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname)));
    addActiveLine(subst("\t<init>$0</init>", T(tree2double(c))));
    addActiveLine(subst("\t<min>$0</min>", T(tree2double(x))));
    addActiveLine(subst("\t<max>$0</max>", T(tree2double(y))));
    addActiveLine(subst("\t<step>$0</step>", T(tree2double(z))));
    addActiveLine("</widget>");

    // add a passive widget description
  }
  else if(isSigVBargraph(sig, path, x, y, z))
  {
    fWidgetID++;
    fPassiveWidgetCount++;
    addPassiveLine(subst("<widget type=\"vbargraph\" id=\"$0\">", T(fWidgetID)));
    addPassiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true)));
    addPassiveLine(subst("\t<varname>$0</varname>", tree2str(varname)));
    addPassiveLine(subst("\t<min>$0</min>", T(tree2double(x))));
    addPassiveLine(subst("\t<max>$0</max>", T(tree2double(y))));
    addPassiveLine("</widget>");
  }
  else if(isSigHBargraph(sig, path, x, y, z))
  {
    fWidgetID++;
    fPassiveWidgetCount++;
    addPassiveLine(subst("<widget type=\"hbargraph\" id=\"$0\">", T(fWidgetID)));
    addPassiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true)));
    addPassiveLine(subst("\t<varname>$0</varname>", tree2str(varname)));
    addPassiveLine(subst("\t<min>$0</min>", T(tree2double(x))));
    addPassiveLine(subst("\t<max>$0</max>", T(tree2double(y))));
    addPassiveLine("</widget>");
  }
  else
  {
    fprintf(stderr, "Error describing widget : unrecognized expression\n");
    exit(1);
  }

  return fWidgetID;
}
Beispiel #3
0
void Description::print(int n, ostream& fout)
{
  list<string>::iterator s;
  list<int>::iterator t;

  tab(n, fout);
  fout << "<faust>";

  tab(n + 1, fout);
  fout << "<name>" << xmlize(fName) << "</name>";
  tab(n + 1, fout);
  fout << "<author>" << xmlize(fAuthor) << "</author>";
  tab(n + 1, fout);
  fout << "<copyright>" << xmlize(fCopyright) << "</copyright>";
  tab(n + 1, fout);
  fout << "<license>" << xmlize(fLicense) << "</license>";
  tab(n + 1, fout);
  fout << "<version>" << xmlize(fVersion) << "</version>";
  tab(n + 1, fout);
  fout << "<classname>" << xmlize(fClassName) << "</classname>";
  tab(n + 1, fout);
  fout << "<inputs>" << fInputs << "</inputs>";
  tab(n + 1, fout);
  fout << "<outputs>" << fOutputs << "</outputs>";

  tab(n + 1, fout);
  fout << "<ui>";

  // active widget list
  tab(n + 2, fout);
  fout << "<activewidgets>";
  tab(n + 3, fout);
  fout << "<count>" << fActiveWidgetCount << "</count>";

  for(s = fActiveLines.begin(); s != fActiveLines.end(); s++)
  {
    tab(n + 3, fout);
    fout << *s;
  }

  tab(n + 2, fout);
  fout << "</activewidgets>";

  tab(n + 2, fout);

  // passive widget list
  tab(n + 2, fout);
  fout << "<passivewidgets>";
  tab(n + 3, fout);
  fout << "<count>" << fPassiveWidgetCount << "</count>";

  for(s = fPassiveLines.begin(); s != fPassiveLines.end(); s++)
  {
    tab(n + 3, fout);
    fout << *s;
  }

  tab(n + 2, fout);
  fout << "</passivewidgets>";

  tab(n + 2, fout);

  // widget layout
  tab(n + 2, fout);
  fout << "<layout>";

  for(t = fLayoutTabs.begin(), s = fLayoutLines.begin();
      s != fLayoutLines.end(); t++, s++)
  {
    tab(n + 3 + *t, fout);
    fout << *s;
  }

  tab(n + 2, fout);
  fout << "</layout>";

  tab(n + 1, fout);
  fout << "</ui>";

  tab(n, fout);
  fout << "</faust>" << endl;
}
Beispiel #4
0
int main_XMLizer(int argc,char* const argv[]) {
if (argc==1) {
   usage();
   return SUCCESS_RETURN_CODE;
}

int output_style=TEI;
char output[FILENAME_MAX]="";
char alphabet[FILENAME_MAX]="";
char normalization[FILENAME_MAX]="";
char segmentation[FILENAME_MAX]="";
VersatileEncodingConfig vec=VEC_DEFAULT;
int convLFtoCRLF=1;
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_XMLizer,lopts_XMLizer,&index))) {
   switch(val) {
   case 'x': output_style=XML; break;
   case 't': output_style=TEI; break;
   case 'n': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty normalization grammar name\n");
                return USAGE_ERROR_CODE;
             }
             strcpy(normalization,options.vars()->optarg);
             break;
   case 'o': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty output file name\n");
                return USAGE_ERROR_CODE;
             }
             strcpy(output,options.vars()->optarg);
             break;
   case 'a': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty alphabet file name\n");
                return USAGE_ERROR_CODE;
             }
             strcpy(alphabet,options.vars()->optarg);
             break;
   case 's': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty segmentation grammar name\n");
                return USAGE_ERROR_CODE;
             }
             strcpy(segmentation,options.vars()->optarg);
             break;
   case 'V': only_verify_arguments = true;
             break;
   case 'h': usage(); 
             return SUCCESS_RETURN_CODE;
   case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
                         error("Missing argument for option --%s\n",lopts_XMLizer[index].name);
             return USAGE_ERROR_CODE;                         
   case 'k': if (options.vars()->optarg[0]=='\0') {
                error("Empty input_encoding argument\n");
                return USAGE_ERROR_CODE;
             }
             decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
             break;
   case 'q': if (options.vars()->optarg[0]=='\0') {
                error("Empty output_encoding argument\n");
                return USAGE_ERROR_CODE;
             }
             decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
             break;
   case '?': index==-1  ? error("Invalid option -%c\n",options.vars()->optopt) :
                          error("Invalid option --%s\n",options.vars()->optarg);
             return USAGE_ERROR_CODE;             
  
   }
   index=-1;
}

if (options.vars()->optind!=argc-1) {
   error("Invalid arguments: rerun with --help\n");
   return USAGE_ERROR_CODE;
}

if (segmentation[0]=='\0') {
   error("You must specify the segmentation grammar to use\n");
   return USAGE_ERROR_CODE;
}

if (only_verify_arguments) {
  // freeing all allocated memory
  return SUCCESS_RETURN_CODE;
}

char input[FILENAME_MAX];
strcpy(input,argv[options.vars()->optind]);
char snt[FILENAME_MAX];
remove_extension(input,snt);
strcat(snt,"_tmp.snt");
char tmp[FILENAME_MAX];
remove_extension(input,tmp);
strcat(tmp,".tmp");
normalize(input,snt,&vec,KEEP_CARRIAGE_RETURN,convLFtoCRLF,normalization,NULL,1);
struct fst2txt_parameters* p=new_fst2txt_parameters();
p->vec=vec;
p->input_text_file=strdup(snt);
if (p->input_text_file ==NULL) {
   alloc_error("main_XMLizer");
   free_fst2txt_parameters(p);
   return ALLOC_ERROR_CODE;
}

p->output_text_file_is_temp=1;
p->output_text_file=strdup(tmp);
if (p->output_text_file==NULL) {
   alloc_error("main_XMLizer");
   free_fst2txt_parameters(p);
   return ALLOC_ERROR_CODE;
}
p->fst_file=strdup(segmentation);
if (p->fst_file==NULL) {
   alloc_error("main_XMLizer");
   free_fst2txt_parameters(p);
   return ALLOC_ERROR_CODE;
}
p->alphabet_file=strdup(alphabet);
if (p->alphabet_file==NULL) {
   alloc_error("main_XMLizer");
   free_fst2txt_parameters(p);
   return ALLOC_ERROR_CODE;
}

p->output_policy=MERGE_OUTPUTS;
p->tokenization_policy=WORD_BY_WORD_TOKENIZATION;
p->space_policy=DONT_START_WITH_SPACE;

main_fst2txt(p);

free_fst2txt_parameters(p);

if (output[0]=='\0') {
  remove_extension(input,output);
	strcat(output,".xml");
}

int return_value = xmlize(&vec,snt,output,output_style);

af_remove(snt);
af_remove(tmp);

return return_value;
}