mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-20 16:51:03 +03:00
little fix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* cmdlnopts.c - the only function that parce cmdln args and returns glob parameters
|
||||
* cmdlnopts.c - the only function that parse cmdln args and returns glob parameters
|
||||
*
|
||||
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
||||
*
|
||||
@@ -93,13 +93,13 @@ myoption cmdlnopts[] = {
|
||||
|
||||
|
||||
/**
|
||||
* Parce command line options and return dynamically allocated structure
|
||||
* Parse command line options and return dynamically allocated structure
|
||||
* to global parameters
|
||||
* @param argc - copy of argc from main
|
||||
* @param argv - copy of argv from main
|
||||
* @return allocated structure with global parameters
|
||||
*/
|
||||
glob_pars *parce_args(int argc, char **argv){
|
||||
glob_pars *parse_args(int argc, char **argv){
|
||||
int i;
|
||||
void *ptr;
|
||||
ptr = memcpy(&G, &Gdefault, sizeof(G)); assert(ptr);
|
||||
@@ -107,7 +107,7 @@ glob_pars *parce_args(int argc, char **argv){
|
||||
/// "éÓÐÏÌØÚÏ×ÁÎÉÅ: %s [ÁÒÇÕÍÅÎÔÙ]\n\n\tçÄÅ ÁÒÇÕÍÅÎÔÙ:\n"
|
||||
change_helpstring(_("Usage: %s [args]\n\n\tWhere args are:\n"));
|
||||
// parse arguments
|
||||
parceargs(&argc, &argv, cmdlnopts);
|
||||
parseargs(&argc, &argv, cmdlnopts);
|
||||
if(help) showhelp(-1, cmdlnopts);
|
||||
if(argc > 0){
|
||||
/// "éÇÎÏÒÉÒÕÀ ÁÒÇÕÍÅÎÔ[Ù]:"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* cmdlnopts.h - comand line options for parceargs
|
||||
* cmdlnopts.h - comand line options for parseargs
|
||||
*
|
||||
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
||||
*
|
||||
@@ -23,7 +23,7 @@
|
||||
#ifndef __CMDLNOPTS_H__
|
||||
#define __CMDLNOPTS_H__
|
||||
|
||||
#include "parceargs.h"
|
||||
#include "parseargs.h"
|
||||
|
||||
/*
|
||||
* here are some typedef's for global data
|
||||
@@ -35,6 +35,6 @@ typedef struct{
|
||||
double relmove; // move relative current position
|
||||
}glob_pars;
|
||||
|
||||
glob_pars *parce_args(int argc, char **argv);
|
||||
glob_pars *parse_args(int argc, char **argv);
|
||||
|
||||
#endif // __CMDLNOPTS_H__
|
||||
|
||||
@@ -235,7 +235,7 @@ int main(int argc, char *argv[]){
|
||||
char buff[BUFLEN+1];
|
||||
pthread_t motor_thread;
|
||||
size_t L;
|
||||
Global_parameters = parce_args(argc, argv);
|
||||
Global_parameters = parse_args(argc, argv);
|
||||
assert(Global_parameters != NULL);
|
||||
if(!get_shm_block(&sdat, ClientSide) || !check_shm_block(&sdat)){
|
||||
fprintf(stderr, "Can't get SHM block!");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* parceargs.c - parcing command line arguments & print help
|
||||
* parseargs.c - parsing command line arguments & print help
|
||||
*
|
||||
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
||||
*
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <limits.h> // INT_MAX & so on
|
||||
#include <libintl.h>// gettext
|
||||
#include <ctype.h> // isalpha
|
||||
#include "parceargs.h"
|
||||
#include "parseargs.h"
|
||||
|
||||
// macro to print help messages
|
||||
#ifndef PRNT
|
||||
@@ -135,7 +135,7 @@ int get_optind(int opt, myoption *options){
|
||||
}
|
||||
|
||||
/**
|
||||
* Parce command line arguments
|
||||
* Parse command line arguments
|
||||
* ! If arg is string, then value will be strdup'ed!
|
||||
*
|
||||
* @param argc (io) - address of argc of main(), return value of argc stay after `getopt`
|
||||
@@ -146,7 +146,7 @@ int get_optind(int opt, myoption *options){
|
||||
*
|
||||
* @exit: in case of error this function show help & make `exit(-1)`
|
||||
*/
|
||||
void parceargs(int *argc, char ***argv, myoption *options){
|
||||
void parseargs(int *argc, char ***argv, myoption *options){
|
||||
char *short_options, *soptr;
|
||||
struct option *long_options, *loptr;
|
||||
size_t optsize, i;
|
||||
@@ -247,7 +247,7 @@ void parceargs(int *argc, char ***argv, myoption *options){
|
||||
*/
|
||||
void showhelp(int oindex, myoption *options){
|
||||
// ATTENTION: string `help` prints through macro PRNT(), by default it is gettext,
|
||||
// but you can redefine it before `#include "parceargs.h"`
|
||||
// but you can redefine it before `#include "parseargs.h"`
|
||||
int max_opt_len = 0; // max len of options substring - for right indentation
|
||||
const int bufsz = 255;
|
||||
char buf[bufsz+1];
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* parceargs.h - headers for parcing command line arguments
|
||||
* parseargs.h - headers for parcing command line arguments
|
||||
*
|
||||
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
||||
*
|
||||
@@ -19,8 +19,8 @@
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef __PARCEARGS_H__
|
||||
#define __PARCEARGS_H__
|
||||
#ifndef __PARSEARGS_H__
|
||||
#define __PARSEARGS_H__
|
||||
|
||||
#include <stdbool.h>// bool
|
||||
#include <stdlib.h>
|
||||
@@ -48,7 +48,7 @@ typedef bool(*argfn)(void *arg, int N);
|
||||
* int iarg;
|
||||
* myoption opts[] = {
|
||||
* {"value", 1, NULL, 'v', arg_int, &iarg, "char val"}, ..., end_option};
|
||||
* ..(parce args)..
|
||||
* ..(parse args)..
|
||||
* charg = (char) iarg;
|
||||
*/
|
||||
typedef enum {
|
||||
@@ -58,7 +58,7 @@ typedef enum {
|
||||
arg_double, // double
|
||||
arg_float, // float
|
||||
arg_string, // char *
|
||||
arg_function // parce_args will run function `bool (*fn)(char *optarg, int N)`
|
||||
arg_function // parse_args will run function `bool (*fn)(char *optarg, int N)`
|
||||
} argtype;
|
||||
|
||||
/*
|
||||
@@ -67,7 +67,7 @@ typedef enum {
|
||||
* conversion depends on .type
|
||||
*
|
||||
* ATTENTION: string `help` prints through macro PRNT(), bu default it is gettext,
|
||||
* but you can redefine it before `#include "parceargs.h"`
|
||||
* but you can redefine it before `#include "parseargs.h"`
|
||||
*
|
||||
* if arg is string, then value wil be strdup'ed like that:
|
||||
* char *str;
|
||||
@@ -99,8 +99,8 @@ typedef struct{
|
||||
extern const char *__progname;
|
||||
|
||||
void showhelp(int oindex, myoption *options);
|
||||
void parceargs(int *argc, char ***argv, myoption *options);
|
||||
void parseargs(int *argc, char ***argv, myoption *options);
|
||||
void change_helpstring(char *s);
|
||||
bool myatod(void *num, const char *str, argtype t);
|
||||
|
||||
#endif // __PARCEARGS_H__
|
||||
#endif // __PARSEARGS_H__
|
||||
@@ -53,9 +53,9 @@ int main(){
|
||||
while(1){
|
||||
usbd_poll(usbd_dev);
|
||||
if(usbdatalen){ // there's something in USB buffer
|
||||
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
|
||||
usbdatalen = parse_incoming_buf(usbdatabuf, usbdatalen);
|
||||
}
|
||||
//check_and_parce_UART(USART1); // also check data in UART buffers
|
||||
//check_and_parse_UART(USART1); // also check data in UART buffers
|
||||
if(Timer - Old_timer > 999){ // one-second cycle
|
||||
Old_timer += 1000;
|
||||
}else if(Timer < Old_timer){ // Timer overflow
|
||||
|
||||
@@ -51,10 +51,10 @@ void help(){
|
||||
|
||||
|
||||
/**
|
||||
* parce command buffer buf with length len
|
||||
* parse command buffer buf with length len
|
||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||
*/
|
||||
int parce_incoming_buf(char *buf, int len){
|
||||
int parse_incoming_buf(char *buf, int len){
|
||||
uint8_t command;
|
||||
//uint32_t utmp;
|
||||
int i = 0;
|
||||
|
||||
@@ -42,6 +42,6 @@ void prnt(uint8_t *wrd);
|
||||
void print_int(int32_t N);
|
||||
void print_hex(uint8_t *buff, uint8_t l);
|
||||
|
||||
int parce_incoming_buf(char *buf, int len);
|
||||
int parse_incoming_buf(char *buf, int len);
|
||||
|
||||
#endif // __USER_PROTO_H__
|
||||
|
||||
Reference in New Issue
Block a user