void LLCCEP_tools::commandLineParametersParser::parse(int argn, char **argv)
{
	for (int i = 1; i < argn; i++) {
		auto param = isParam(argv[i]);

		if (param != flags.end()) {
			bool follow = followed(argv[i]);

			if (follow && i == argn - 1) {
				throw RUNTIME_EXCEPTION(CONSTRUCT_MSG(
					"Sudden end after '%s'",
					argv[i]));
			} else if (follow) {
				param->following = argv[++i];
			} else if (!follow) {
				param->following = "1";
			}
		} else if (maxFreeParams != (static_cast<size_t>(-1)) &&
		           freeParams.size() > maxFreeParams) {
			throw RUNTIME_EXCEPTION(CONSTRUCT_MSG(
				"Too many free parameters"));
		} else {
			freeParams.push_back(argv[i]);
		}
	}
}
Exemple #2
0
bool Segment::operator==(const Segment& rhs) const
{
    if (isParam() || rhs.isParam())
    {
        return true;
    }
    return value_ == rhs.value();
}
Exemple #3
0
/* instrucciones posibles: (getDisps), (disp_id opc val) */
main(int argc, char *argv[]) {
   /* Validaciones */
   /* 1: validar cantidad de argumentos */
   checkError(!( ((argc>1)&&(strcmp(argv[1],"getDisps")==0)) || (argc>=4) ), "Faltan argumentos");
   if ((argc > 4) && (CVERBOSE)){
      printf("Exceso de argumentos. Se ignorarán los argumentos extra\n");
   }
   /* 2: validar valores */
   /* 2.0: validar si es petición de nombres de dispositivos */
   char getDisps=0;
   if (strcmp(argv[1],"getDisps")==0)
      getDisps=1;
   /* 2.1: validar número de dispositivo */
   int disp_id, param_index;
   char *value;
   if (!getDisps){
      disp_id=(int)strtol(argv[1],NULL,10);
      checkError((errno==EINVAL)||(errno==ERANGE), "Id de dispositivo inválida");
      checkError(disp_id>=NDISP, "No existe el dispositivo");
      /* 2.2: validar parámetro a configurar */
      char *param=argv[2];
      param_index=isParam(param);
      printf("param_index es %d\n",param_index);
      checkError((param_index==-1),"Opción inválida");
      /* 2.3: validar valor del parametro */
      value=argv[3];
      checkError(isValue(value, param_index)==0, "Valor inválido para el parámetro");
      /* Pasó las validaciones. A partir de ahora, todos los datos son totalmente limpios */
   }
   int s;
   int cnt, n;
   char input[BUF_SIZE];
   char output[BUF_SIZE];
   int port=1818;
   /* Concatenar parámetros en un string entendible por el raspberry */
   if (getDisps)
      sprintf(input, "getDisps");
   else
      sprintf(input, "%d-%d-%s", disp_id, param_index, value);
   s = j_socket();

   checkError(j_connect(s, "localhost", port) < 0, "Servidor no responde");
   //write(a,b,c) escribe hasta c bytes en el fd a, lo que está en el buffer b. Retorna cantidad de bytes escritos.
   int cuantos = write(s, input, strlen(input) +1);
   if (CVERBOSE) printf("%d bytes enviados al servidor\n", cuantos);
   //read(a,b,c) lee desde a, hasta c bytes y los guarda en buffer b. Retorna cantidad de bytes leidos, hasta EOF (0, '\0').
   cnt=read(s, output, BUF_SIZE);
   if (CVERBOSE) printf("Respuesta del server: ");
   if (strcmp(output,"OK")==0)
      printf("OK\n");
   else
      printf("%s\n",output);
   if (CVERBOSE) printf("%d bytes leidos del servidor\n",cnt);
   close(s);
}
bool LLCCEP_tools::commandLineParametersParser::followed(::std::string mnem)
{
	auto param = isParam(mnem);
	if (param == flags.end()) {
		throw RUNTIME_EXCEPTION(CONSTRUCT_MSG(
			"Not param '%s'",
			mnem.c_str()));
	}

	return param->followed;
}
Exemple #5
0
int main(int argc, char *argv[])
{
  char *cdfile = NULL;
  char *ctfile = NULL;
  char *pofile = NULL;
  char *newctfile = NULL;
  char *catalog = NULL;
  char *source;
  char *template;
  int makenewct = FALSE;
  int makecatalog = FALSE;
  int i;

  if(argc == 0)      /* Aztec's entry point for workbench programs */
  {
    fprintf(stderr, "FlexCat can't be run from Workbench!\n" \
            "\n"
            "Open a Shell session and type FlexCat ?\n" \
            "for more information\n");
    exit(5);
  }

  if(OpenLibs() == FALSE)
    exit(20);

  OpenFlexCatCatalog();

  /* Big Endian vs. Little Endian (both supported ;-) */

  if(!SwapChoose())
  {
    fprintf(stderr, "FlexCat is unable to determine\n" \
            "the byte order used by your system.\n" \
            "It's neither Little nor Big Endian?!.\n");
    exit(5);
  }
#ifdef AMIGA
  ReadPrefs();
#endif
  if(argc == 1)
  {
    Usage();
  }

  for(i = 1; i < argc; i++)
  {
    if(Strnicmp(argv[i], "catalog=", 8) == 0)
    {
      catalog = argv[i] + 8;
      makecatalog = TRUE;
    }
    else if(Stricmp(argv[i], "catalog") == 0)
    {
      if(i == argc - 1)
      {
        catalog = NULL;
        makecatalog = TRUE;
      }
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          catalog = argv[i + 1];
          i++;
          makecatalog = TRUE;
        }
        else
        {
          catalog = NULL;
          makecatalog = TRUE;
        }
      }
    }
    else if(Strnicmp(argv[i], "pofile=", 7) == 0)
    {
      pofile = argv[i] + 7;
    }
    else if(Stricmp(argv[i], "pofile") == 0)
    {
      if(i == argc - 1)
        pofile = NULL;
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          pofile = argv[i + 1];
          i++;
        }
        else
          pofile = NULL;
      }
    }
    else if(Strnicmp(argv[i], "codeset=", 8) == 0)
    {
      strcpy(DestCodeset, argv[i] + 8);
    }
    else if(Stricmp(argv[i], "codeset") == 0)
    {
      if(i == argc - 1)
        DestCodeset[0] = '\0';
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          strcpy(DestCodeset, argv[i + 1]);
          i++;
        }
        else
          DestCodeset[0] = '\0';
      }
    }
    else if(Strnicmp(argv[i], "version=", 8) == 0)
    {
      CatVersion = strtol(argv[i]+8, NULL, 10);
    }
    else if(Stricmp(argv[i], "version") == 0)
    {
      if(i == argc - 1)
        CatVersion = -1;
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          CatVersion = strtol(argv[i + 1], NULL, 10);
          i++;
        }
        else
          CatVersion = -1;
      }
    }
    else if(Strnicmp(argv[i], "revision=", 9) == 0)
    {
      CatRevision = strtol(argv[i]+9, NULL, 10);
    }
    else if(Stricmp(argv[i], "revision") == 0)
    {
      if(i == argc - 1)
        CatRevision = -1;
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          CatRevision = strtol(argv[i + 1], NULL, 10);
          i++;
        }
        else
          CatRevision = -1;
      }
    }
    else if(Stricmp(argv[i], "nooptim") == 0)
    {
      NoOptim = TRUE;
    }
    else if(Stricmp(argv[i], "fill") == 0)
    {
      Fill = TRUE;
    }
    else if(Stricmp(argv[i], "quiet") == 0)
    {
      Quiet = TRUE;
    }
    else if(Stricmp(argv[i], "flush") == 0)
    {
      DoExpunge = TRUE;
    }
    else if(Stricmp(argv[i], "nobeep") == 0)
    {
      NoBeep = TRUE;
    }
    else if(Stricmp(argv[i], "nobufferedio") == 0)
    {
      NoBufferedIO = TRUE;
    }
    else if(Strnicmp(argv[i], "newctfile=", 10) == 0)
    {
      newctfile = argv[i] + 10;
      makenewct = TRUE;
    }
    else if(Stricmp(argv[i], "newctfile") == 0)
    {
      if(i == argc - 1)
      {
        newctfile = NULL;
        makenewct = TRUE;
      }
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          newctfile = argv[i + 1];
          i++;
          makenewct = TRUE;
        }
        else
        {
          newctfile = NULL;
          makenewct = TRUE;
        }
      }
    }
    else if(Stricmp(argv[i], "nolangtolower") == 0)
    {
      LANGToLower = FALSE;
    }
    else if(Stricmp(argv[i], "modified") == 0)
    {
      Modified = TRUE;
    }
    else if(Stricmp(argv[i], "warnctgaps") == 0)
    {
      WarnCTGaps = TRUE;
    }
    else if(Stricmp(argv[i], "copymsgnew") == 0)
    {
      CopyNEWs = TRUE;
    }
    else if(Stricmp(argv[i], "oldmsgnew") == 0)
    {
      snprintf(Old_Msg_New, sizeof(Old_Msg_New), "; %s", argv[++i]);
    }
    else if(Stricmp(argv[i], "noautodate") == 0 || Stricmp(argv[i], "nospaces") == 0)
    {
      // just swallow some no longer supported options to
      // keep old scripts alive and happy
    }
    else if(cdfile == NULL)
    {
      if(Stricmp(argv[i], "?") == 0 ||
         Stricmp(argv[i], "-h") == 0 ||
         Stricmp(argv[i], "help") == 0 ||
         Stricmp(argv[i], "--help") == 0)
      {
        Usage();
      }

      cdfile = argv[i];

      // find out file extension and depending on it
      // we eiterh scan a CD file or the supplied pot file
      if(strstr(cdfile, ".pot") != NULL)
      {
        if(!ScanPOFile(cdfile, FALSE))
          MyExit(10);
      }
      else
      {
        if(!ScanCDFile(cdfile))
          MyExit(10);
      }
    }
    else if(strchr(argv[i], '=') != NULL)
    {
      /* Determine basename. */
      if(BaseName == NULL && cdfile != NULL)
      {
        char *lslash = strrchr(cdfile, '/');
        char  *ldot = strrchr(cdfile, '.');

        if(lslash == NULL)
          lslash = cdfile;
        else
          lslash++;

        if(ldot == NULL)
          ldot = cdfile + strlen(cdfile);

        if(ldot - lslash > 0)
        {
          BaseName = calloc(ldot - lslash + 3, 1);
          strncpy(BaseName, lslash, ldot - lslash);
        }
      }

      source =AllocString(argv[i]);
      template = strchr(source, '=');
      *template++ = '\0';