From bf4ea0c4932f02dcb4ada286f0215271a31c0884 Mon Sep 17 00:00:00 2001 From: eddyem Date: Fri, 5 May 2017 16:47:02 +0300 Subject: [PATCH] Fixed a lot of bugs in HSFV_management --- HSFW_management/Readme.md | 57 ++ HSFW_management/hidmanage.c | 128 +-- HSFW_management/hidmanage.h | 10 +- HSFW_management/hsfw.c | 899 +++++++++--------- HSFW_management/hsfw.h | 42 +- .../locale/ru/LC_MESSAGES/HSFW_manage.mo | Bin 4781 -> 5334 bytes HSFW_management/locale/ru/messages.po | 469 ++++----- HSFW_management/locale/ru/ru.po | 100 +- HSFW_management/parseargs.c | 754 +++++++-------- HSFW_management/parseargs.h | 72 +- HSFW_management/usefull_macros.c | 354 +++---- HSFW_management/usefull_macros.h | 34 +- getopt/cmdlnopts/parseargs.c | 4 +- sockmsgs.c | 2 - 14 files changed, 1529 insertions(+), 1396 deletions(-) diff --git a/HSFW_management/Readme.md b/HSFW_management/Readme.md index 9c73f76..d84857d 100644 --- a/HSFW_management/Readme.md +++ b/HSFW_management/Readme.md @@ -1,3 +1,60 @@ Edmund Optics high-speed filter wheel management ================================================ +This command-line utility allows you to manage with HSFW turrets: check and change their positions, +list connected devices and their property, rename wheels' and filters' names stored in EEPROM of +given turret. + +## Command line options: + + + -H, --home move to home position + -N, --wheel-name=arg wheel name + -W, --wheel-id=arg letter wheel identificator + -h, --help show this help + -i, --filter-id=arg filter identificator like "A3" + -n, --filter-name=arg filter name + -p, --f-position=arg filter position number + -s, --serial=arg turret serial (with leading zeros) + --list list only present devices' names + --list-all list all stored names + --rename rename stored wheels/filters names + --resetnames reset all names to default values + +## Usage examples + +#### List all devices connected + Свойства подключенного колеса + Wheel ID 'A', name 'UBVRI', serial '00000563', 5 filters: + 1: 'U' + 2: 'B' + 3: 'V' + 4: 'R' + 5: 'I' + current position: 1 + + Свойства подключенного колеса + Wheel ID 'B', name 'Sloan', serial '00000532', 5 filters: + 1: '1' + 2: '2' + 3: '3' + 4: '4' + 5: '5' + current position: 1 + +#### Move wheel by turret's serial and position number + HSFW_manage -s 00000563 -p 3 + +Will move first turret (wheel 'A' named 'UBVRI') into third position (filter 'V'). + +#### Move wheel by filter name + HSFW_manage -nV + +Is equivalent of previous. + +#### Rename wheel 'B' of first turret + HSFW_manage --rename -s00000563 -WB -N "New name" + +Assigns "New name" to wheel 'B' of first turret in spite of its absence in current moment. +You can control all changes by `HSFV_manage --list` (show only wheels presents) or +`HSFV_manage --list-all` (show all EEPROM information). diff --git a/HSFW_management/hidmanage.c b/HSFW_management/hidmanage.c index 0c48f9b..8da920c 100644 --- a/HSFW_management/hidmanage.c +++ b/HSFW_management/hidmanage.c @@ -32,68 +32,68 @@ * access by wheel ID could lead undefined behaviour! */ int find_wheels(wheel_descr **wheels){ - struct udev *udev; - struct udev_enumerate *enumerate; - struct udev_list_entry *devices, *dev_list_entry; - wheel_descr *founded = NULL; - // Create the udev object - udev = udev_new(); - int N = 0; - if(!udev){ - ERR("Can't create udev"); - } - // Create a list of the devices in the 'hidraw' subsystem. - enumerate = udev_enumerate_new(udev); - udev_enumerate_add_match_subsystem(enumerate, "hidraw"); - udev_enumerate_scan_devices(enumerate); - devices = udev_enumerate_get_list_entry(enumerate); - // Check out each device found - udev_list_entry_foreach(dev_list_entry, devices){ - const char *path; - struct udev_device *dev; - path = udev_list_entry_get_name(dev_list_entry); - dev = udev_device_new_from_syspath(udev, path); - const char *devpath = udev_device_get_devnode(dev); - DBG("Device Node Path: %s", devpath); - dev = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_device"); - if(!dev){ - WARNX("Unable to find parent usb device for %s", devpath); - udev_device_unref(dev); - continue; - } - const char *vid, *pid; - vid = udev_device_get_sysattr_value(dev,"idVendor"); - pid = udev_device_get_sysattr_value(dev, "idProduct"); - DBG(" VID/PID: %s/%s", vid, pid); - if(strcmp(vid, W_VID) == 0 && strcmp(pid, W_PID) == 0){ - ++N; - if(!founded){ - founded = MALLOC(wheel_descr, 1); - }else{ - founded = realloc(founded, sizeof(wheel_descr)*N); - if(!founded) ERR("realloc"); - } - wheel_descr *curdev = &founded[N-1]; - int fd = open(devpath, O_RDWR|O_NONBLOCK); - if(fd < 0){ - /// " %s" - WARN(_("Can't open %s"), devpath); - curdev->fd = -1; - }else - curdev->fd = fd; - DBG("%s %s", - udev_device_get_sysattr_value(dev,"manufacturer"), - udev_device_get_sysattr_value(dev,"product")); - curdev->serial = strdup(udev_device_get_sysattr_value(dev, "serial")); - DBG("serial: %s\n", curdev->serial); - } - udev_device_unref(dev); - } - // Free the enumerator object - udev_enumerate_unref(enumerate); - if(wheels){ - *wheels = founded; - }else - free(founded); - return N; + struct udev *udev; + struct udev_enumerate *enumerate; + struct udev_list_entry *devices, *dev_list_entry; + wheel_descr *Found = NULL; + // Create the udev object + udev = udev_new(); + int N = 0; + if(!udev){ + ERR("Can't create udev"); + } + // Create a list of the devices in the 'hidraw' subsystem. + enumerate = udev_enumerate_new(udev); + udev_enumerate_add_match_subsystem(enumerate, "hidraw"); + udev_enumerate_scan_devices(enumerate); + devices = udev_enumerate_get_list_entry(enumerate); + // Check out each device found + udev_list_entry_foreach(dev_list_entry, devices){ + const char *path; + struct udev_device *dev; + path = udev_list_entry_get_name(dev_list_entry); + dev = udev_device_new_from_syspath(udev, path); + const char *devpath = udev_device_get_devnode(dev); + DBG("Device Node Path: %s", devpath); + dev = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_device"); + if(!dev){ + WARNX("Unable to find parent usb device for %s", devpath); + udev_device_unref(dev); + continue; + } + const char *vid, *pid; + vid = udev_device_get_sysattr_value(dev,"idVendor"); + pid = udev_device_get_sysattr_value(dev, "idProduct"); + DBG(" VID/PID: %s/%s", vid, pid); + if(strcmp(vid, W_VID) == 0 && strcmp(pid, W_PID) == 0){ + ++N; + if(!Found){ + Found = MALLOC(wheel_descr, 1); + }else{ + Found = realloc(Found, sizeof(wheel_descr)*N); + if(!Found) ERR("realloc"); + } + wheel_descr *curdev = &Found[N-1]; + int fd = open(devpath, O_RDWR|O_NONBLOCK); + if(fd < 0){ + /// " %s" + WARN(_("Can't open %s"), devpath); + curdev->fd = -1; + }else + curdev->fd = fd; + DBG("%s %s", + udev_device_get_sysattr_value(dev,"manufacturer"), + udev_device_get_sysattr_value(dev,"product")); + curdev->serial = strdup(udev_device_get_sysattr_value(dev, "serial")); + DBG("serial: %s\n", curdev->serial); + } + udev_device_unref(dev); + } + // Free the enumerator object + udev_enumerate_unref(enumerate); + if(wheels){ + *wheels = Found; + }else + free(Found); + return N; } diff --git a/HSFW_management/hidmanage.h b/HSFW_management/hidmanage.h index 5cb2295..629a2c6 100644 --- a/HSFW_management/hidmanage.h +++ b/HSFW_management/hidmanage.h @@ -26,11 +26,11 @@ #define W_PID "82cd" typedef struct{ - int fd; - char *serial; - char ID; - char name[9]; - int maxpos; + int fd; + char *serial; + char ID; + char name[9]; + int maxpos; } wheel_descr; int find_wheels(wheel_descr **wheels); diff --git a/HSFW_management/hsfw.c b/HSFW_management/hsfw.c index f342011..31f37cd 100644 --- a/HSFW_management/hsfw.c +++ b/HSFW_management/hsfw.c @@ -30,10 +30,10 @@ // wheel Id & filter position given (if given by name - check names stored) static int wheel_id = -1 // wheel ID given or found by name - ,filter_pos = -1 // filter position given or found by name - ,max_pos = -1 // max filter position allowed - ,wheel_fd = -1 // file descriptor of active wheel - ,HW_found = 0 // amount of wheels found + ,filter_pos = -1 // filter position given or found by name + ,max_pos = -1 // max filter position allowed + ,wheel_fd = -1 // file descriptor of active wheel + ,HW_found = 0 // amount of wheels found ; static wheel_descr *wheel_chosen = NULL; // pointer to chosen wheel @@ -56,121 +56,133 @@ int poll_regstatus(int fd, int msg); * set variables pointing current wheel to wheels[idx] */ void set_cur_wheel(int idx){ - wheel_chosen = &wheels[idx]; - wheel_id = wheel_chosen->ID; - wheel_fd = wheel_chosen->fd; - max_pos = wheel_chosen->maxpos; + wheel_chosen = &wheels[idx]; + wheel_id = wheel_chosen->ID; + wheel_fd = wheel_chosen->fd; + max_pos = wheel_chosen->maxpos; } /** * Check command line arguments, find filters/wheels by name, find max positions & so on */ void check_args(){ - // here we fill value of wheel_id if no given and present only one turret - list_hw(listNms); // also exit if no HW found - if(listNms) return; - int i; - if(G.wheelID || G.filterId){ - char wID = (G.wheelID) ? *G.wheelID : *G.filterId; - if((wID < 'A' || wID > POS_B_END) || (G.wheelID && strlen(G.wheelID) != 1)){ - /// " \"A\" \"H\"!" - ERRX(_("Wheel ID should be a letter from \"A\" to \"H\"!")); - } - wheel_id = wID; - DBG("wheel given by id: %c", wheel_id); - for(i = 0; i < HW_found; ++i){ - if(wheels[i].ID == wheel_id){ - /// " '%c'!" - if(wheel_fd > 0) ERRX(_("More than one wheel with ID '%c' found!"), wheel_id); - set_cur_wheel(i); - } - } - } - char oldid = wheel_id; - if(G.wheelName && (!reName || (G.filterPos || G.filterName))){ // find wheel by name given - if(G.wheelID && !reName){ - /// " , ; - !" - ERRX(_("You give both wheel ID and wheel name, try something one!")); - } - for(i = 0; i < HW_found; ++i){ - if(strcmp(wheels[i].name, G.wheelName) == 0){ - set_cur_wheel(i); - break; - } - } - if(reName) wheel_id = oldid; - } - void setWid(){ - if(oldid > 0) wheel_id = oldid; - if(!G.wheelID){ - G.wheelID = calloc(2, 1); - *G.wheelID = wheel_id; - } - } - if(G.serial){ // HW given by its serial - for(i = 0; i < HW_found; ++i){ - if(strcmp(wheels[i].serial, G.serial) == 0){ - set_cur_wheel(i); - if(reName) setWid(); - break; - } - } - if(i == HW_found) wheel_id = 0; // make an error message later - } - // if there's only one turret, fill wheel_id - if(HW_found == 1 && (wheel_id < 0 || (wheel_fd < 0 && reName))){ - set_cur_wheel(0); - if(reName) setWid(); - } - if((wheel_fd < 0 || !wheel_chosen) && !G.filterName){ - /// " !" - ERRX(_("Given wheel not found!")); - } - if(showpos || setdef) return; - if(G.filterId){ // filter given by its id like "B3" - char *fid = G.filterId; - /// " () ()" - if(strlen(G.filterId) != 2 || fid[1] > '9' || fid[1] < '0') - /// " - () ()" - ERRX(_("Filter ID is letter (wheel) and number (position)")); - filter_pos = fid[1] - '0'; - }else if(G.filterPos){ // filter given by numerical position - filter_pos = G.filterPos; - }else if(G.filterName){ // filter given by name - search it - int search_f(int N){ - int i, m = wheels[N].maxpos; - for(i = 1; i <= m; ++i){ - DBG("Search filter %s in pos %d (%s)", G.filterName, i, get_filter_name(&wheels[N], i)); - if(strcmp(G.filterName, get_filter_name(&wheels[N], i)) == 0){ - filter_pos = i; - if(!wheel_chosen){ - set_cur_wheel(N); - } - break; - } - } - if(i > m) return 1; - return 0; - } - int not_found = 1; - if(wheel_chosen) not_found = search_f(wheel_id); - else for(i = 0; i < HW_found && not_found; ++i){ - not_found = search_f(i); - } - if(not_found){ - /// " %s " - ERRX(_("Filter %s not found!"), G.filterName); - } - }else{ - if(!gohome) showpos = 1; // no action given - just show position - return; - } - if(reName) max_pos = get_max_pos(wheel_id); - if(filter_pos < 1 || filter_pos > max_pos){ - /// " 1 %d!" - ERRX(_("Filter position should be a number from 1 to %d!"), max_pos); - } - DBG("filter given by position: %d", filter_pos); + // here we fill value of wheel_id if no given and present only one turret + list_hw(listNms); // also exit if no HW found + if(listNms) return; + int i; + // add wheel ID to global parameters if there was nothing + if(G.serial){ // HW given by its serial + DBG("User give serial: %s", G.serial); + for(i = 0; i < HW_found; ++i){ + if(strcmp(wheels[i].serial, G.serial) == 0){ + /// " '%s'!" + if(wheel_fd > 0) ERRX(_("More than one turret with serial '%s' found!"), G.serial); + set_cur_wheel(i); + DBG("Find given serial @ wheel %d", i); + } + } + if(wheel_fd < 0){ + /// " '%s' " + ERRX(_("Turret with serial '%s' not found"), G.serial); + } + } + if(G.wheelID || G.filterId){ // HW by wheel or filter ID or ID 2 rename + char wID = (G.wheelID) ? *G.wheelID : *G.filterId; + DBG("wID=%c", wID); + if((wID < 'A' || wID > POS_B_END) || (G.wheelID && strlen(G.wheelID) != 1)){ + /// " \"A\" \"H\"!" + ERRX(_("Wheel ID should be a letter from \"A\" to \"H\"!")); + }else if(G.filterId && strlen(G.filterId) != 2){ + /// " : " + ERRX(_("Filter ID should have two symbols: wheel ID and filter position")); + } + wheel_id = wID; + DBG("wheel given by id: %c", wheel_id); + if(!reName){ + for(i = 0; i < HW_found; ++i){ + if(wheels[i].ID == wheel_id){ + /// " '%c'!" + if(wheel_fd > 0) ERRX(_("More than one wheel with ID '%c' found!"), wheel_id); + set_cur_wheel(i); + DBG("Find given ID @ wheel %d", i); + } + } + } + if(wheel_fd < 0){ + /// " '%c' " + ERRX(_("Wheel with ID '%c' not found"), wheel_id); + } + if(G.filterId) filter_pos = G.filterId[1] - '0'; + } else if(G.wheelName){ // find wheel by name given + for(i = 0; i < HW_found; ++i){ + if(strcmp(wheels[i].name, G.wheelName) == 0){ + /// " '%s'!" + if(wheel_fd > 0) ERRX(_("More than one wheel with name '%s' found!"), G.wheelName); + set_cur_wheel(i); + DBG("Find given name @ wheel %d", i); + } + } + if(wheel_fd < 0 && !reName){ + /// " '%s' " + ERRX(_("Wheel with name '%s' not found"), G.wheelName); + } + } + // if there's only one turret, choose it + if(HW_found == 1 && wheel_id < 0){ + set_cur_wheel(0); + DBG("No specific options with only turret, choose it"); + } + if(G.filterPos){ // filter given by numerical position + filter_pos = G.filterPos; + } + DBG("filter_pos=%d", filter_pos); + // Check if user ask to find filter with given name + if(filter_pos < 1 && G.filterName && !reName){ // filter given by name - search it + int search_f(wheel_descr *wheel){ + int i, m = wheel->maxpos; + for(i = 1; i <= m; ++i){ + DBG("Search filter %s in pos %d (%s)", G.filterName, i, get_filter_name(wheel, i)); + DBG("len1: %zd, len2: %zd", strlen(G.filterName), strlen(get_filter_name(wheel, i))); + if(strcmp(G.filterName, get_filter_name(wheel, i)) == 0){ + filter_pos = i; + break; + } + } + if(i > m) return 1; + return 0; + } + int not_found = 1; + if(wheel_chosen) not_found = search_f(wheel_chosen); + else for(i = 0; i < HW_found; ++i){ + if(!search_f(&wheels[i])){ + not_found = 0; + /// " '%s'!" + if(wheel_fd > 0) ERRX(_("More than one wheel with filter name '%s' found!"), G.filterName); + set_cur_wheel(i); + } + } + if(not_found){ + /// " %s " + ERRX(_("Filter %s not found!"), G.filterName); + } + } + if(wheel_fd < 0){ + /// " !" + ERRX(_("Given wheel not found!")); + } + if(reName && !G.wheelID){ + G.wheelID = calloc(2, 1); + *G.wheelID = wheel_id; + } + if(filter_pos < 1 && !gohome) showpos = 1; // no action given - just show position + if(showpos || setdef || gohome) return; + // now check if filter position right + if(reName) max_pos = get_max_pos(wheel_id); + if(filter_pos < 1 || filter_pos > max_pos){ + /// " 1 %d!" + ERRX(_("Filter position should be a number from 1 to %d!"), max_pos); + } + DBG("filter given by position: %d", filter_pos); } /** @@ -178,20 +190,20 @@ void check_args(){ * return 0 if all OK */ int writereg(int fd, uint8_t *buf, int l){ - uint8_t reg = buf[0]; - //#if 0// - #ifdef EBUG - int i; - printf("Write reg %d:", reg); - for(i = 0; i < l; ++i) printf(" %02hhx", buf[i]); - printf("\n"); - #endif - if(ioctl(fd, HIDIOCSFEATURE(l), buf) < 0 || buf[0] != reg){ - /// " " - WARNX(_("Error sending data")); - return 1; - } - return 0; + uint8_t reg = buf[0]; + #if 0 + // #ifdef EBUG + int i; + printf("Write reg %d:", reg); + for(i = 0; i < l; ++i) printf(" %02hhx", buf[i]); + printf("\n"); + #endif + if(ioctl(fd, HIDIOCSFEATURE(l), buf) < 0 || buf[0] != reg){ + /// " " + WARNX(_("Error sending data")); + return 1; + } + return 0; } /** @@ -199,57 +211,57 @@ int writereg(int fd, uint8_t *buf, int l){ * return 0 if all OK */ int readreg(int fd, uint8_t *buf, int reg, int l){ - memset(buf, 0, l); - buf[0] = reg; - if(ioctl(fd, HIDIOCGFEATURE(l), buf) < 0 || buf[0] != reg){ - /// " " - WARNX(_("Error reading data")); - return 1; - } - //#if 0// - #ifdef EBUG - int i; - printf("Read reg %d:", reg); - for(i = 0; i < l; ++i) printf(" %02hhx", buf[i]); - printf("\n"); - #endif - return 0; + memset(buf, 0, l); + buf[0] = reg; + if(ioctl(fd, HIDIOCGFEATURE(l), buf) < 0 || buf[0] != reg){ + /// " " + WARNX(_("Error reading data")); + return 1; + } + #if 0 + //#ifdef EBUG + int i; + printf("Read reg %d:", reg); + for(i = 0; i < l; ++i) printf(" %02hhx", buf[i]); + printf("\n"); + #endif + return 0; } /** * Check error state and clear it if need */ void check_and_clear_err(int fd){ - int i, stat = 1; - uint8_t buf[REG_STATUS_LEN]; - for(i = 0; i < 10 && stat; ++i){ - stat = readreg(fd, buf, REG_STATUS, REG_STATUS_LEN); - if(stat) usleep(100000); - } - /// ", " - if(i == 10) ERRX(_("Error, tries amount exceed")); - if(buf[1] != 0xff){ - if(buf[5]){ - /// " No %d, " - //red(_("Error No %d, clear it"), buf[5]); - stat = 1; - for(i = 0; i < 10 && stat; ++i){ - memset(buf, 0, sizeof(buf)); - buf[0] = REG_CLERR; - stat = writereg(fd, buf, REG_CLERR_LEN); - usleep(100000); - if(!stat) stat = readreg(fd, buf, REG_STATUS, REG_STATUS_LEN); - if(!stat && buf[5]) stat = 1; - } - } - readreg(fd, buf, REG_STATUS, REG_STATUS_LEN); - if(buf[1] != 0xff){ - /// " , \"\"" - red(_("Turret isn't initialized, move home...")); - go_home(fd); - readreg(fd, buf, REG_STATUS, REG_STATUS_LEN); - } - } + int i, stat = 1; + uint8_t buf[REG_STATUS_LEN]; + for(i = 0; i < 10 && stat; ++i){ + stat = readreg(fd, buf, REG_STATUS, REG_STATUS_LEN); + if(stat) usleep(100000); + } + /// ", " + if(i == 10) ERRX(_("Error, tries amount exceed")); + if(buf[1] != 0xff){ + if(buf[5]){ + /// " No %d, " + //red(_("Error No %d, clear it"), buf[5]); + stat = 1; + for(i = 0; i < 10 && stat; ++i){ + memset(buf, 0, sizeof(buf)); + buf[0] = REG_CLERR; + stat = writereg(fd, buf, REG_CLERR_LEN); + usleep(100000); + if(!stat) stat = readreg(fd, buf, REG_STATUS, REG_STATUS_LEN); + if(!stat && buf[5]) stat = 1; + } + } + readreg(fd, buf, REG_STATUS, REG_STATUS_LEN); + if(buf[1] != 0xff){ + /// " , \"\"" + red(_("Turret isn't initialized, move home...")); + go_home(fd); + readreg(fd, buf, REG_STATUS, REG_STATUS_LEN); + } + } } /** @@ -259,25 +271,25 @@ void check_and_clear_err(int fd){ * @return current position */ int poll_regstatus(int fd, int msg){ - uint8_t buf[REG_STATUS_LEN]; - int i, stat = 1; - /// " " - if(msg) printf(_("Wait for end of moving ")); - for(i = 0; i < 300 && stat; ++i){ - stat = readreg(fd, buf, REG_STATUS, REG_STATUS_LEN); - if(!stat){ - if(buf[2] == 0xff || buf[3] == 0xff) stat = 1; - } - if(buf[5]){ - if(msg) printf("\n"); - /// " , " - ERRX(_("Error ocured, repeat again")); - } - usleep(50000); - if(msg) printf("."); fflush(stdout); - } - if(msg) printf("\n"); - return buf[4]; + uint8_t buf[REG_STATUS_LEN]; + int i, stat = 1; + /// " " + if(msg) printf(_("Wait for end of moving ")); + for(i = 0; i < 300 && stat; ++i){ + stat = readreg(fd, buf, REG_STATUS, REG_STATUS_LEN); + if(!stat){ + if(buf[2] == 0xff || buf[3] == 0xff) stat = 1; + } + if(buf[5]){ + if(msg) printf("\n"); + /// " , " + ERRX(_("Error ocured, repeat again")); + } + usleep(50000); + if(msg) printf("."); fflush(stdout); + } + if(msg) printf("\n"); + return buf[4]; } /** @@ -286,117 +298,118 @@ int poll_regstatus(int fd, int msg){ * @param pos - filter position (starts from 1) */ char *get_filter_name(wheel_descr *wheel, int pos){ - static uint8_t buf[REG_NAME_LEN]; - int fd = wheel->fd; - if(fd < 0) return NULL; - if(pos < 1 || pos > wheel->maxpos){ - /// " 1..%d" - WARNX(_("Given position out of range 1..%d"), wheel->maxpos); - return NULL; - } - memset(buf, 0, sizeof(buf)); - buf[0] = REG_NAME; - buf[1] = FILTER_NAME; - buf[2] = wheel->ID; - buf[3] = pos; - if(writereg(fd, buf, REG_NAME_LEN)) return NULL; - if(readreg(fd, buf, REG_NAME, REG_NAME_LEN)) return NULL; - if(buf[2]) return NULL; - if(buf[6]){ - char *x = strchr((char*)&buf[6], ' '); - if(x) *x = 0; - return (char*) &buf[6]; - } - else return NULL; + static uint8_t buf[REG_NAME_LEN]; + int fd = wheel->fd; + if(fd < 0) return NULL; + if(pos < 1 || pos > wheel->maxpos){ + /// " 1..%d" + WARNX(_("Given position out of range 1..%d"), wheel->maxpos); + return NULL; + } + memset(buf, 0, sizeof(buf)); + buf[0] = REG_NAME; + buf[1] = FILTER_NAME; + buf[2] = wheel->ID; + buf[3] = pos; + if(writereg(fd, buf, REG_NAME_LEN)) return NULL; + if(readreg(fd, buf, REG_NAME, REG_NAME_LEN)) return NULL; + if(buf[2]) return NULL; + if(buf[6]){ + char *x = strchr((char*)&buf[6], ' '); + if(x) *x = 0; + return (char*) &buf[6]; + } + else return NULL; } /** * list properties of wheels & fill remain fields of struct wheel_descr */ -void list_props(_U_ int verblevl, wheel_descr *wheel){ - uint8_t buf[REG_NAME_LEN+1]; - int fd = wheel->fd; - if(fd < 0){ - /// " " - WARNX(_("Can't open device")); - return; - } - check_and_clear_err(fd); - // get status of wheel - if(readreg(fd, buf, REG_INFO, REG_INFO_LEN)) return; - wheel->ID = buf[5]; - wheel->maxpos = buf[4]; - DBG("Wheel with id '%c' and maxpos %d", wheel->ID, wheel->maxpos); - char *getwname(int id){ - memset(buf, 0, sizeof(buf)); - buf[0] = REG_NAME; - buf[1] = WHEEL_NAME; - buf[2] = id; - if(writereg(fd, buf, REG_NAME_LEN)) return NULL; - if(readreg(fd, buf, REG_NAME, REG_NAME_LEN)) return NULL; - if(buf[6]){ - char *x = strchr((char*)&buf[6], ' '); - if(x) *x = 0; - return (char*)&buf[6]; - } - else return NULL; - } - if(verblevl == LIST_PRES || !verblevl){ // list only presented devices or not list - char *nm; - /// "\n \n" - if(verblevl) green(_("\nConnected wheel properties\n")); - if(verblevl) printf("Wheel ID '%c'", wheel->ID); - nm = getwname(wheel->ID); - if(nm){ - strncpy(wheel->name, nm, 9); - if(verblevl) printf(", name '%s'", wheel->name); - } - if(wheel->serial && verblevl){ - printf(", serial '%s'", wheel->serial); - } - if(verblevl) printf(", %d filters:\n", wheel->maxpos); - else return; - int i, m = wheel->maxpos + 1; - // now get filter names - for(i = 1; i < m; ++i){ - nm = get_filter_name(wheel, i); - printf("\t%d", i); - if(nm) printf(": '%s'", nm); - printf("\n"); - } - if(verblevl){ - printf("current position: %d\n", poll_regstatus(wheel->fd, 0)); - } - } - if(verblevl != LIST_ALL) return; - // now list all things stored in memory of turret driver - int w; - /// "\n EEPROM\n" - green(_("\nAll records from EEPROM\n")); - wheel_descr wl; - wl.fd = fd; - if(wheel->serial) printf("Turret with serial '%s'\n", wheel->serial); - for(w = 'A'; w < 'I'; ++w){ - char *nm = getwname(w); - int f; - printf("Wheel ID '%c'", w); - wl.maxpos = get_max_pos(w); - if(nm) printf(", name '%s'", nm); - printf(", %d filters:\n", wl.maxpos ); - wl.ID = w; - for(f = 1; f <= wl.maxpos; ++f){ - nm = get_filter_name(&wl, f); - if(!nm){ - check_and_clear_err(fd); - memset(buf, 0, sizeof(buf)); - buf[0] = REG_NAME; - writereg(fd, buf, REG_NAME_LEN); - readreg(fd, buf, REG_NAME, REG_NAME_LEN); - break; - } - printf("\t%d: '%s'\n", f, nm); - } - } +void list_props(int verblevl, wheel_descr *wheel){ + uint8_t buf[REG_NAME_LEN+1]; + int fd = wheel->fd; + if(fd < 0){ + /// " " + WARNX(_("Can't open device")); + return; + } + check_and_clear_err(fd); + // get status of wheel + if(readreg(fd, buf, REG_INFO, REG_INFO_LEN)) return; + wheel->ID = buf[5]; + wheel->maxpos = buf[4]; + DBG("Wheel with id '%c' and maxpos %d", wheel->ID, wheel->maxpos); + char *getwname(int id){ + memset(buf, 0, sizeof(buf)); + buf[0] = REG_NAME; + buf[1] = WHEEL_NAME; + buf[2] = id; + if(writereg(fd, buf, REG_NAME_LEN)) return NULL; + if(readreg(fd, buf, REG_NAME, REG_NAME_LEN)) return NULL; + if(buf[6]){ + char *x = strchr((char*)&buf[6], ' '); + if(x) *x = 0; + return (char*)&buf[6]; + } + else return NULL; + } + if(verblevl == LIST_PRES || !verblevl){ // list only presented devices or not list + char *nm; + /// "\n \n" + if(verblevl) green(_("\nConnected wheel properties\n")); + if(verblevl) printf("Wheel ID '%c'", wheel->ID); + nm = getwname(wheel->ID); + if(nm){ + strncpy(wheel->name, nm, 9); + if(verblevl) printf(", name '%s'", wheel->name); + DBG("Wheel name: %s", wheel->name); + } + if(wheel->serial && verblevl){ + printf(", serial '%s'", wheel->serial); + } + if(verblevl) printf(", %d filters:\n", wheel->maxpos); + else return; + int i, m = wheel->maxpos + 1; + // now get filter names + for(i = 1; i < m; ++i){ + nm = get_filter_name(wheel, i); + printf("\t%d", i); + if(nm) printf(": '%s'", nm); + printf("\n"); + } + if(verblevl){ + printf("current position: %d\n", poll_regstatus(wheel->fd, 0)); + } + } + if(verblevl != LIST_ALL) return; + // now list all things stored in memory of turret driver + int w; + /// "\n EEPROM\n" + green(_("\nAll records from EEPROM\n")); + wheel_descr wl; + wl.fd = fd; + if(wheel->serial) printf("Turret with serial '%s'\n", wheel->serial); + for(w = 'A'; w < 'I'; ++w){ + char *nm = getwname(w); + int f; + printf("Wheel ID '%c'", w); + wl.maxpos = get_max_pos(w); + if(nm) printf(", name '%s'", nm); + printf(", %d filters:\n", wl.maxpos ); + wl.ID = w; + for(f = 1; f <= wl.maxpos; ++f){ + nm = get_filter_name(&wl, f); + if(!nm){ + check_and_clear_err(fd); + memset(buf, 0, sizeof(buf)); + buf[0] = REG_NAME; + writereg(fd, buf, REG_NAME_LEN); + readreg(fd, buf, REG_NAME, REG_NAME_LEN); + break; + } + printf("\t%d: '%s'\n", f, nm); + } + } } /** @@ -404,117 +417,117 @@ void list_props(_U_ int verblevl, wheel_descr *wheel){ * if 'show' != 0 show names found */ void list_hw(int show){ - int i; - if(show) DBG("show"); - HW_found = find_wheels(&wheels); - DBG("Found %d dev[s]", HW_found); - if(HW_found == 0){ - /// " " - ERRX(_("No turrets found")); - } - for(i = 0; i < HW_found; ++i) - if(wheels[i].fd > 0) break; - if(i == HW_found){ - /// " %d , " - ERRX(_("Found %d turrets but have no access rights to any"), HW_found); - } - // read other wheel properties & list if show!=0 - for(i = 0; i < HW_found; ++i){ - list_props(show, &wheels[i]); - } + int i; + if(show) DBG("show"); + HW_found = find_wheels(&wheels); // get list of wheels with therir file descriptors and serial numbers + DBG("Found %d dev[s]", HW_found); + if(HW_found == 0){ + /// " " + ERRX(_("No turrets found")); + } + for(i = 0; i < HW_found; ++i) + if(wheels[i].fd > 0) break; + if(i == HW_found){ + /// " %d , " + ERRX(_("Found %d turrets but have no access rights to any"), HW_found); + } + // read other wheel properties & list if show!=0 + for(i = 0; i < HW_found; ++i){ + list_props(show, &wheels[i]); + } } /** * Rename wheels or filters */ void rename_hw(){ - FNAME(); - check_and_clear_err(wheel_fd); - char *newname = NULL; - size_t L = 0; - uint8_t buf[REG_NAME_LEN]; - void checknm(char *nm){ - newname = nm; - /// " " - if((L = strlen(nm)) > 8) ERRX(_("Name should be not longer than 8 symbols")); - } - memset(buf, 0, sizeof(buf)); - uint8_t cmd = 0; - // now check what user wants to rename - if(setdef){ - DBG("Reset names to default"); - cmd = RESTORE_DEFVALS; - }else if(G.filterName && (G.filterId || G.filterPos)){ // user wants to rename filter - checknm(G.filterName); - DBG("Rename filter %d to %s", filter_pos, newname); - cmd = RENAME_FILTER; - }else if(G.wheelName && (G.wheelID || G.filterId)){ // rename wheel - checknm(G.wheelName); - DBG("Rename wheel '%c' to %s", wheel_id, newname); - cmd = RENAME_WHEEL; - } - if(!cmd){ - /// " , / /!" - ERRX(_("You should give new filter/wheel name and its POS/ID to rename!")); - } + FNAME(); + check_and_clear_err(wheel_fd); + char *newname = NULL; + size_t L = 0; + uint8_t buf[REG_NAME_LEN]; + void checknm(char *nm){ + newname = nm; + /// " " + if((L = strlen(nm)) > 8) ERRX(_("Name should be not longer than 8 symbols")); + } + memset(buf, 0, sizeof(buf)); + uint8_t cmd = 0; + // now check what user wants to rename + if(setdef){ + DBG("Reset names to default"); + cmd = RESTORE_DEFVALS; + }else if(G.filterName && (G.filterId || G.filterPos)){ // user wants to rename filter + checknm(G.filterName); + DBG("Rename filter %d to %s", filter_pos, newname); + cmd = RENAME_FILTER; + }else if(G.wheelName && (G.wheelID || G.filterId)){ // rename wheel + checknm(G.wheelName); + DBG("Rename wheel '%c' to %s", wheel_id, newname); + cmd = RENAME_WHEEL; + } + if(!cmd){ + /// " , / /!" + ERRX(_("You should give new filter/wheel name and its POS/ID to rename!")); + } - int i, stat = 1; - for(i = 0; i < 10 && stat; ++i){ - buf[0] = REG_NAME; - buf[1] = cmd; - if(cmd != RESTORE_DEFVALS){ - buf[2] = wheel_id; - memcpy(&buf[4], newname, L); - } - if(cmd == RENAME_FILTER) buf[3] = filter_pos; - if((stat = writereg(wheel_fd, buf, REG_NAME_LEN))) continue; - if((stat = readreg(wheel_fd, buf, REG_NAME, REG_NAME_LEN))) continue; - if(buf[2]){ // err not empty - DBG("ER: %d", buf[2]); - check_and_clear_err(wheel_fd); - stat = 1; continue; - } - if(memcmp(&buf[6], newname, L)){ - DBG("Names not match!"); - stat = 1; - continue; - } - break; - } - /// " " - if(i == 10) ERRX(_("Can't rename")); - /// " !" - green(_("Succesfully renamed!\n")); + int i, stat = 1; + for(i = 0; i < 10 && stat; ++i){ + buf[0] = REG_NAME; + buf[1] = cmd; + if(cmd != RESTORE_DEFVALS){ + buf[2] = wheel_id; + memcpy(&buf[4], newname, L); + } + if(cmd == RENAME_FILTER) buf[3] = filter_pos; + if((stat = writereg(wheel_fd, buf, REG_NAME_LEN))) continue; + if((stat = readreg(wheel_fd, buf, REG_NAME, REG_NAME_LEN))) continue; + if(buf[2]){ // err not empty + DBG("ER: %d", buf[2]); + check_and_clear_err(wheel_fd); + stat = 1; continue; + } + if(memcmp(&buf[6], newname, L)){ + DBG("Names not match!"); + stat = 1; + continue; + } + break; + } + /// " " + if(i == 10) ERRX(_("Can't rename")); + /// " !" + green(_("Succesfully renamed!\n")); } /** * move wheel home */ void go_home(int fd){ - static int Nruns = 0; - /// ", " - if(++Nruns > 10) ERRX(_("Cycling detected, try again")); - DBG("Wheel go home"); - poll_regstatus(fd, 0); // wait for last moving - uint8_t buf[REG_HOME_LEN]; - int i, stat = 1; - for(i = 0; i < 10 && stat; ++i){ - memset(buf, 0, REG_HOME_LEN); - buf[0] = REG_HOME; - stat = writereg(fd, buf, REG_HOME_LEN); - if(stat){usleep(100000); continue;} - if((stat = readreg(fd, buf, REG_HOME, REG_HOME_LEN))) continue; - if(buf[1] != 0xff){ - stat = 1; continue; - }else{ - readreg(fd, buf, REG_HOME, REG_HOME_LEN); - break; - } - } - if(i == 10) exit(1); - // now poll REG_STATUS - poll_regstatus(fd, 1); - check_and_clear_err(fd); + static int Nruns = 0; + /// ", " + if(++Nruns > 10) ERRX(_("Cycling detected, try again")); + DBG("Wheel go home"); + poll_regstatus(fd, 0); // wait for last moving + uint8_t buf[REG_HOME_LEN]; + int i, stat = 1; + for(i = 0; i < 10 && stat; ++i){ + memset(buf, 0, REG_HOME_LEN); + buf[0] = REG_HOME; + stat = writereg(fd, buf, REG_HOME_LEN); + if(stat){usleep(100000); continue;} + if((stat = readreg(fd, buf, REG_HOME, REG_HOME_LEN))) continue; + if(buf[1] != 0xff){ + stat = 1; continue; + }else{ + readreg(fd, buf, REG_HOME, REG_HOME_LEN); + break; + } + } + if(i == 10) exit(1); + // now poll REG_STATUS + poll_regstatus(fd, 1); + check_and_clear_err(fd); } /** @@ -522,35 +535,35 @@ void go_home(int fd){ * @return 0 if all OK */ int move_wheel(){ - DBG("Move wheel %c to pos %d", wheel_id, filter_pos); - if(wheel_fd < 0) return 1; - if(filter_pos == poll_regstatus(wheel_fd, 0)){ - /// " " - WARNX(_("Already at position")); - return 0; - } - uint8_t buf[REG_GOTO_LEN]; - int i, stat = 1; - for(i = 0; i < 10 && stat; ++i){ - DBG("i=%d",i); - memset(buf, 0, REG_GOTO_LEN); - buf[0] = REG_GOTO; - buf[1] = filter_pos; - stat = writereg(wheel_fd, buf, REG_GOTO_LEN); - usleep(100000); - if(stat) continue; - if((stat = readreg(wheel_fd, buf, REG_GOTO, REG_GOTO_LEN))) continue; - if(buf[1] != 0xff){ - stat = 1; continue; - }else{ - readreg(wheel_fd, buf, REG_GOTO, REG_HOME_LEN); - break; - } - } - if(i == 10) return 1; - poll_regstatus(wheel_fd, 1); - check_and_clear_err(wheel_fd); - return 0; + DBG("Move wheel %c to pos %d", wheel_id, filter_pos); + if(wheel_fd < 0) return 1; + if(filter_pos == poll_regstatus(wheel_fd, 0)){ + /// " " + WARNX(_("Already at position")); + return 0; + } + uint8_t buf[REG_GOTO_LEN]; + int i, stat = 1; + for(i = 0; i < 10 && stat; ++i){ + DBG("i=%d",i); + memset(buf, 0, REG_GOTO_LEN); + buf[0] = REG_GOTO; + buf[1] = filter_pos; + stat = writereg(wheel_fd, buf, REG_GOTO_LEN); + usleep(100000); + if(stat) continue; + if((stat = readreg(wheel_fd, buf, REG_GOTO, REG_GOTO_LEN))) continue; + if(buf[1] != 0xff){ + stat = 1; continue; + }else{ + readreg(wheel_fd, buf, REG_GOTO, REG_HOME_LEN); + break; + } + } + if(i == 10) return 1; + poll_regstatus(wheel_fd, 1); + check_and_clear_err(wheel_fd); + return 0; } /** @@ -558,27 +571,27 @@ int move_wheel(){ * @return 0 if all OK */ int process_args(){ - FNAME(); - if(wheel_id < 0) return 1; - if(showpos){ - printf("%d\n", poll_regstatus(wheel_fd, 0)); - return 0; - } - if(gohome){ - go_home(wheel_fd); - return 0; - } - if(reName || setdef){ - rename_hw(); - return 0; - } - if(filter_pos < 0) return 1; - return move_wheel(); + FNAME(); + if(wheel_id < 0) return 1; + if(reName || setdef){ + rename_hw(); + return 0; + } + if(showpos){ + printf("%d\n", poll_regstatus(wheel_fd, 0)); + return 0; + } + if(gohome){ + go_home(wheel_fd); + return 0; + } + if(filter_pos < 0) return 1; + return move_wheel(); } // check max position allowed for given filter id int get_max_pos(char id){ - if(id >= 'A' && id <= POS_A_END) return ABS_MAX_POS_A; - else if(id > POS_A_END && id <= POS_B_END) return ABS_MAX_POS_B; - return 0; + if(id >= 'A' && id <= POS_A_END) return ABS_MAX_POS_A; + else if(id > POS_A_END && id <= POS_B_END) return ABS_MAX_POS_B; + return 0; } diff --git a/HSFW_management/hsfw.h b/HSFW_management/hsfw.h index f0f9fc5..6bac269 100644 --- a/HSFW_management/hsfw.h +++ b/HSFW_management/hsfw.h @@ -22,33 +22,33 @@ #ifndef __HSFW_H__ #define __HSFW_H__ -#define REG_CLERR (0x02) -#define REG_CLERR_LEN (2) -#define REG_STATUS (0x0a) -#define REG_STATUS_LEN (6) -#define REG_INFO (0x0b) -#define REG_INFO_LEN (7) -#define REG_GOTO (0x14) -#define REG_GOTO_LEN (3) -#define REG_HOME (0x15) -#define REG_HOME_LEN (3) -#define REG_NAME (0x16) -#define REG_NAME_LEN (14) +#define REG_CLERR (0x02) +#define REG_CLERR_LEN (2) +#define REG_STATUS (0x0a) +#define REG_STATUS_LEN (6) +#define REG_INFO (0x0b) +#define REG_INFO_LEN (7) +#define REG_GOTO (0x14) +#define REG_GOTO_LEN (3) +#define REG_HOME (0x15) +#define REG_HOME_LEN (3) +#define REG_NAME (0x16) +#define REG_NAME_LEN (14) // absolute max position (5 for wheels 'A'..'E' & 8 for wheels 'F'..'G') -#define ABS_MAX_POS_A (5) -#define ABS_MAX_POS_B (8) +#define ABS_MAX_POS_A (5) +#define ABS_MAX_POS_B (8) // end of 5-position wheel descriptor range -#define POS_A_END ('E') +#define POS_A_END ('E') // end of 8-pos range -#define POS_B_END ('H') +#define POS_B_END ('H') enum name_cmd{ - RESTORE_DEFVALS = 1, - RENAME_FILTER, - FILTER_NAME, - RENAME_WHEEL, - WHEEL_NAME + RESTORE_DEFVALS = 1, + RENAME_FILTER, + FILTER_NAME, + RENAME_WHEEL, + WHEEL_NAME }; void check_args(); diff --git a/HSFW_management/locale/ru/LC_MESSAGES/HSFW_manage.mo b/HSFW_management/locale/ru/LC_MESSAGES/HSFW_manage.mo index 6acdb5ef792ac5ff4f8ba483d9b84eab6496a098..331f67bff8b83e795ad690e68c86feb2f80fb5b8 100644 GIT binary patch delta 1917 zcmZ|PO-!6c9LMoNke5E7_5Cwa32-R*ovFV3j^)N5YMk*8=gW9@Ez9TEY{;MxD)?E zP1smr%ocncHSR%FJ@QIFbD2-RT#EAa$sC#O)6`4Y8& zDYSScc>V|P=6N%nw4g4m#)GK(W5_G!Jxo4PWXx#_I?F{4?k>EF+Ce4fp$VH&^^TpGVz^S=7#dN8N!^I!TKb!_}O>R`dcDI+M3h6FR8+FM{VR9_D!& z@5g;L#&qHc?!eDbk;>X&YZ$^Y)Fr)$8h9Douz_%B;{B-i`cOyke&9J&1m^GvUQ1HYWq5}8vj&quo$0%% z9esid;kS4%E};f2VU>!+PSggTLoM`e)O#NxK`>Lu3Hzy?-*8YCYESOwhl}fX)POJ z6#ai33ZIfLmd=U@`iVc-EOoGa>#^+ywfeYU^%^@xp+Ms4hkp(D}3SlEvCMHW5MxX&IP7>q|o?5ok(KztxN>>MxstudY$8HvR0=s>*R#v&sFy@R&3CDv+>Miaw* zP0ovDA?I+})-6HT;ohOh|Jt{euT?s4mN`v5HyLj@8ZV6L)RaFJ_E+W4$tvpUN+71tasVH;JV{0RmDY3 z({_GgE}e00-saPD?sV?QY~ejG>&KwUS*+gE^~XdmHMhXDo}KVAOFyNpH<|Ok_twVF zTQ{4|rL%U*%`D9`hr+9_%@u`uo}G;~W1&Aa+0xA>v$?d*rKVYa%K5ye=fG91+~e*4 e?8sjk(OiGoGuK~SpYFzXXSL?!_=Vb)qJIHj>wrN3 delta 1477 zcmY+^Uu=_A7{~EbH(a+l_J=>hP&gZIYoUb=_D9sAq9K{#LM0kvqRA#Ntbw(-6_lXq zh0YMdjlMHp5V_I|iDttlDi@G+Y>TyX?_fm*lO=dHvxLNOVPdj`@9*tM#noC!B0^Wj$<88;yPTwR{RGa$GWgFF^pgf zzJW^o3~Hrcq89co?!l}0JpPB9v8U3QYUVd@a-j?dP%A!-ns5v)UJC9D*v$Q1)XK`M zj9HDXsQxbG&m7|8MauXtDuHjRjoE@%P>J70&G#>6^dL;ZG;stq;7h0-cpaZaCwTrb zs@4}#XW=JQZHs~T&~hK9j!Gzs+Uf(S3HyWo4}$v(HPruU9{fPZ4qV1AY$S`P@Kw}S zokV3mhD!K5BzZH7-S{WQu(q}|;d6nnp(Z|pdj1irM3+$S&D660Q7%^K(3ZAQaM_1i z*)ip|hYxK0@0{Q)m|` zLAPI5b!a;{*v8TnZ8X(Pp_)Au*_Krkp|-?`J?^B_&ajQVKj=8eqqaYJ*d|X74XEox zY9x_Pq>@p$s$$9A5^i+I!spxUO|pN;iP`k< zX*-e{a?*o|U9($Of5H8w{-Arf;cV~!xvAXTZN8nKnw~4> vXYz$y(YqN_$8R^RKUnTrJMYck^d@ipTAa3vMK50TtT#31HD#9@mO~E!Z2`|J diff --git a/HSFW_management/locale/ru/messages.po b/HSFW_management/locale/ru/messages.po index 3c52070..cbd81a7 100644 --- a/HSFW_management/locale/ru/messages.po +++ b/HSFW_management/locale/ru/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-05-16 14:08+0300\n" +"POT-Creation-Date: 2017-05-05 16:16+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,224 +17,6 @@ msgstr "" "Content-Type: text/plain; charset=koi8-r\n" "Content-Transfer-Encoding: 8bit\n" -#. amount of pcount and/or scount wrong -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:56 -msgid "Wrong helpstring!" -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:86 -msgid "Integer out of range" -msgstr "" - -#. / " : %s" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:480 -#, c-format -msgid "Wrong parameter: %s" -msgstr "" - -#. / "%s: !" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:485 -#, c-format -msgid "%s: argument needed!" -msgstr "" - -#. / " \"%s\" \"%s\"" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:490 -#, c-format -msgid "Wrong argument \"%s\" of parameter \"%s\"" -msgstr "" - -#. / " %s" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hidmanage.c:80 -#, c-format -msgid "Can't open %s" -msgstr "" - -#. / " !" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:174 -msgid "No filename given!" -msgstr "" - -#. / " %s " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:177 -#, c-format -msgid "Can't open %s for reading" -msgstr "" - -#. / " stat %s" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:180 -#, c-format -msgid "Can't stat %s" -msgstr "" - -#. / " mmap" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:184 -msgid "Mmap error for input" -msgstr "" - -#. / " mmap' " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:186 -msgid "Can't close mmap'ed file" -msgstr "" - -#. / " munmap" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:196 -msgid "Can't munmap" -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:221 -msgid "Can't setup console" -msgstr "" - -#. Get settings -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:291 -msgid "Can't get settings" -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:302 -msgid "Can't set settings" -msgstr "" - -#. / " \"A\" \"H\"!" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:77 -msgid "Wheel ID should be a letter from \"A\" to \"H\"!" -msgstr "" - -#. / " '%c'!" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:84 -#, c-format -msgid "More than one wheel with ID '%c' found!" -msgstr "" - -#. / " , ; - !" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:93 -msgid "You give both wheel ID and wheel name, try something one!" -msgstr "" - -#. / " !" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:127 -msgid "Given wheel not found!" -msgstr "" - -#. / " - () ()" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:135 -msgid "Filter ID is letter (wheel) and number (position)" -msgstr "" - -#. / " %s " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:162 -#, c-format -msgid "Filter %s not found!" -msgstr "" - -#. / " 1 %d!" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:171 -#, c-format -msgid "Filter position should be a number from 1 to %d!" -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:191 -msgid "Error sending data" -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:206 -msgid "Error reading data" -msgstr "" - -#. / ", " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:230 -msgid "Error, tries amount exceed" -msgstr "" - -#. / " , \"\"" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:248 -msgid "Turret isn't initialized, move home..." -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:265 -#, c-format -msgid "Wait for end of moving " -msgstr "" - -#. / " , " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:274 -msgid "Error ocured, repeat again" -msgstr "" - -#. / " 1..%d" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:294 -#, c-format -msgid "Given position out of range 1..%d" -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:321 -msgid "Can't open device" -msgstr "" - -#. / "\n \n" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:347 -msgid "" -"\n" -"Connected wheel properties\n" -msgstr "" - -#. / "\n EEPROM\n" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:375 -msgid "" -"\n" -"All records from EEPROM\n" -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:413 -msgid "No turrets found" -msgstr "" - -#. / " %d , " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:419 -#, c-format -msgid "Found %d turrets but have no access rights to any" -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:439 -msgid "Name should be not longer than 8 symbols" -msgstr "" - -#. / " , / /!" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:458 -msgid "You should give new filter/wheel name and its POS/ID to rename!" -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:485 -msgid "Can't rename" -msgstr "" - -#. / " !" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:487 -msgid "Succesfully renamed!\n" -msgstr "" - -#. / ", " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:496 -msgid "Cycling detected, try again" -msgstr "" - -#. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:529 -msgid "Already at position" -msgstr "" - #. / " " #: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/cmdlnopts.c:64 msgid "show this help" @@ -303,3 +85,252 @@ msgstr "" #: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/cmdlnopts.c:128 msgid "Ignore parameters:" msgstr "" + +#. / " %s" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hidmanage.c:80 +#, c-format +msgid "Can't open %s" +msgstr "" + +#. / " '%s'!" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:79 +#, c-format +msgid "More than one turret with serial '%s' found!" +msgstr "" + +#. / " '%s' " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:86 +#, c-format +msgid "Turret with serial '%s' not found" +msgstr "" + +#. / " \"A\" \"H\"!" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:94 +msgid "Wheel ID should be a letter from \"A\" to \"H\"!" +msgstr "" + +#. / " : " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:97 +msgid "Filter ID should have two symbols: wheel ID and filter position" +msgstr "" + +#. / " '%c'!" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:105 +#, c-format +msgid "More than one wheel with ID '%c' found!" +msgstr "" + +#. / " '%c' " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:113 +#, c-format +msgid "Wheel with ID '%c' not found" +msgstr "" + +#. / " '%s'!" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:120 +#, c-format +msgid "More than one wheel with name '%s' found!" +msgstr "" + +#. / " '%s' " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:127 +#, c-format +msgid "Wheel with name '%s' not found" +msgstr "" + +#. / " '%s'!" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:160 +#, c-format +msgid "More than one wheel with filter name '%s' found!" +msgstr "" + +#. / " %s " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:166 +#, c-format +msgid "Filter %s not found!" +msgstr "" + +#. / " !" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:171 +msgid "Given wheel not found!" +msgstr "" + +#. / " 1 %d!" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:183 +#, c-format +msgid "Filter position should be a number from 1 to %d!" +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:203 +msgid "Error sending data" +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:218 +msgid "Error reading data" +msgstr "" + +#. / ", " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:242 +msgid "Error, tries amount exceed" +msgstr "" + +#. / " , \"\"" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:260 +msgid "Turret isn't initialized, move home..." +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:277 +#, c-format +msgid "Wait for end of moving " +msgstr "" + +#. / " , " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:286 +msgid "Error ocured, repeat again" +msgstr "" + +#. / " 1..%d" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:306 +#, c-format +msgid "Given position out of range 1..%d" +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:333 +msgid "Can't open device" +msgstr "" + +#. / "\n \n" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:359 +msgid "" +"\n" +"Connected wheel properties\n" +msgstr "" + +#. / "\n EEPROM\n" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:388 +msgid "" +"\n" +"All records from EEPROM\n" +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:426 +msgid "No turrets found" +msgstr "" + +#. / " %d , " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:432 +#, c-format +msgid "Found %d turrets but have no access rights to any" +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:452 +msgid "Name should be not longer than 8 symbols" +msgstr "" + +#. / " , / /!" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:471 +msgid "You should give new filter/wheel name and its POS/ID to rename!" +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:498 +msgid "Can't rename" +msgstr "" + +#. / " !" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:500 +msgid "Succesfully renamed!\n" +msgstr "" + +#. / ", " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:509 +msgid "Cycling detected, try again" +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:542 +msgid "Already at position" +msgstr "" + +#. amount of pcount and/or scount wrong +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:56 +msgid "Wrong helpstring!" +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:86 +msgid "Integer out of range" +msgstr "" + +#. / " : %s" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:480 +#, c-format +msgid "Wrong parameter: %s" +msgstr "" + +#. / "%s: !" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:485 +#, c-format +msgid "%s: argument needed!" +msgstr "" + +#. / " \"%s\" \"%s\"" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:490 +#, c-format +msgid "Wrong argument \"%s\" of parameter \"%s\"" +msgstr "" + +#. / " !" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:174 +msgid "No filename given!" +msgstr "" + +#. / " %s " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:177 +#, c-format +msgid "Can't open %s for reading" +msgstr "" + +#. / " stat %s" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:180 +#, c-format +msgid "Can't stat %s" +msgstr "" + +#. / " mmap" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:184 +msgid "Mmap error for input" +msgstr "" + +#. / " mmap' " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:186 +msgid "Can't close mmap'ed file" +msgstr "" + +#. / " munmap" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:196 +msgid "Can't munmap" +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:221 +msgid "Can't setup console" +msgstr "" + +#. Get settings +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:291 +msgid "Can't get settings" +msgstr "" + +#. / " " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/usefull_macros.c:302 +msgid "Can't set settings" +msgstr "" diff --git a/HSFW_management/locale/ru/ru.po b/HSFW_management/locale/ru/ru.po index a9fe6cd..f256e1c 100644 --- a/HSFW_management/locale/ru/ru.po +++ b/HSFW_management/locale/ru/ru.po @@ -7,7 +7,7 @@ msgid "" msgstr "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" - "POT-Creation-Date: 2016-05-16 14:03+0300\n" + "POT-Creation-Date: 2017-05-05 16:16+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,14 +17,14 @@ msgstr "Project-Id-Version: PACKAGE VERSION\n" "Content-Transfer-Encoding: 8bit\n" #. / "\n EEPROM\n" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:375 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:388 msgid "\n" "All records from EEPROM\n" msgstr "\n" " EEPROM\n" #. / "\n \n" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:347 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:359 msgid "\n" "Connected wheel properties\n" msgstr "\n" @@ -37,7 +37,7 @@ msgid "%s: argument needed!" msgstr "%s: !" #. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:529 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:542 msgid "Already at position" msgstr " " @@ -70,12 +70,12 @@ msgid "Can't open %s for reading" msgstr " %s " #. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:321 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:333 msgid "Can't open device" msgstr " " #. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:485 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:498 msgid "Can't rename" msgstr " " @@ -96,61 +96,61 @@ msgid "Can't stat %s" msgstr " stat %s" #. / ", " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:496 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:509 msgid "Cycling detected, try again" msgstr ", " #. / " , " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:274 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:286 msgid "Error ocured, repeat again" msgstr " , " #. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:206 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:218 msgid "Error reading data" msgstr " " #. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:191 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:203 msgid "Error sending data" msgstr " " #. / ", " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:230 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:242 msgid "Error, tries amount exceed" msgstr ", " #. / " %s " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:162 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:166 #, c-format msgid "Filter %s not found!" msgstr " %s " -#. / " - () ()" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:135 -msgid "Filter ID is letter (wheel) and number (position)" -msgstr " - () ()" +#. / " : " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:97 +msgid "Filter ID should have two symbols: wheel ID and filter position" +msgstr " : " #. / " 1 %d!" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:171 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:183 #, c-format msgid "Filter position should be a number from 1 to %d!" msgstr " 1 %d!" #. / " %d , " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:419 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:432 #, c-format msgid "Found %d turrets but have no access rights to any" msgstr " %d , " #. / " 1..%d" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:294 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:306 #, c-format msgid "Given position out of range 1..%d" msgstr " 1..%d" #. / " !" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:127 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:171 msgid "Given wheel not found!" msgstr " !" @@ -169,14 +169,32 @@ msgstr " msgid "Mmap error for input" msgstr " mmap" +#. / " '%s'!" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:79 +#, c-format +msgid "More than one turret with serial '%s' found!" +msgstr " '%s'!" + #. / " '%c'!" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:84 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:105 #, c-format msgid "More than one wheel with ID '%c' found!" msgstr " '%c'!" +#. / " '%s'!" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:160 +#, c-format +msgid "More than one wheel with filter name '%s' found!" +msgstr " '%s'!" + +#. / " '%s'!" +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:120 +#, c-format +msgid "More than one wheel with name '%s' found!" +msgstr " '%s'!" + #. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:439 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:452 msgid "Name should be not longer than 8 symbols" msgstr " " @@ -186,31 +204,49 @@ msgid "No filename given!" msgstr " !" #. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:413 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:426 msgid "No turrets found" msgstr " " #. / " !" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:487 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:500 msgid "Succesfully renamed!\n" msgstr " !\n" #. / " , \"\"" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:248 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:260 msgid "Turret isn't initialized, move home..." msgstr " , \"\"" +#. / " '%s' " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:86 +#, c-format +msgid "Turret with serial '%s' not found" +msgstr " '%s' " + #. / " " -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:265 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:277 #, c-format msgid "Wait for end of moving " msgstr " " #. / " \"A\" \"H\"!" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:77 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:94 msgid "Wheel ID should be a letter from \"A\" to \"H\"!" msgstr " \"A\" \"H\"!" +#. / " '%c' " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:113 +#, c-format +msgid "Wheel with ID '%c' not found" +msgstr " '%c' " + +#. / " '%s' " +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:127 +#, c-format +msgid "Wheel with name '%s' not found" +msgstr " '%s' " + #. / " \"%s\" \"%s\"" #: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/parseargs.c:490 #, c-format @@ -234,13 +270,8 @@ msgstr " msgid "Wrong parameter: %s" msgstr " : %s" -#. / " , ; - !" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:93 -msgid "You give both wheel ID and wheel name, try something one!" -msgstr " , ; - !" - #. / " , / /!" -#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:458 +#: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/hsfw.c:471 msgid "You should give new filter/wheel name and its POS/ID to rename!" msgstr " , /" " /!" @@ -303,3 +334,6 @@ msgstr " #: /home/eddy/Docs/SAO/Edmund_optics/HSFW_management/cmdlnopts.c:68 msgid "wheel name" msgstr " " + +#~ msgid "You give both wheel ID and wheel name, try something one!" +#~ msgstr " , ; - !" diff --git a/HSFW_management/parseargs.c b/HSFW_management/parseargs.c index 2f57be9..7f9758a 100644 --- a/HSFW_management/parseargs.c +++ b/HSFW_management/parseargs.c @@ -19,15 +19,15 @@ * MA 02110-1301, USA. */ -#include // printf -#include // getopt_long -#include // calloc, exit, strtoll -#include // assert +#include // printf +#include // getopt_long +#include // calloc, exit, strtoll +#include // assert #include // strdup, strchr, strlen #include // strcasecmp #include // INT_MAX & so on #include // gettext -#include // isalpha +#include // isalpha #include "parseargs.h" #include "usefull_macros.h" @@ -39,23 +39,23 @@ char *helpstring = "%s\n"; * @param str (i) - new format */ void change_helpstring(char *s){ - int pcount = 0, scount = 0; - char *str = s; - // check `helpstring` and set it to default in case of error - for(; pcount < 2; str += 2){ - if(!(str = strchr(str, '%'))) break; - if(str[1] != '%') pcount++; // increment '%' counter if it isn't "%%" - else{ - str += 2; // pass next '%' - continue; - } - if(str[1] == 's') scount++; // increment "%s" counter - }; - if(pcount > 1 || pcount != scount){ // amount of pcount and/or scount wrong - /// " " - ERRX(_("Wrong helpstring!")); - } - helpstring = s; + int pcount = 0, scount = 0; + char *str = s; + // check `helpstring` and set it to default in case of error + for(; pcount < 2; str += 2){ + if(!(str = strchr(str, '%'))) break; + if(str[1] != '%') pcount++; // increment '%' counter if it isn't "%%" + else{ + str += 2; // pass next '%' + continue; + } + if(str[1] == 's') scount++; // increment "%s" counter + }; + if(pcount > 1 || pcount != scount){ // amount of pcount and/or scount wrong + /// " " + ERRX(_("Wrong helpstring!")); + } + helpstring = s; } /** @@ -66,54 +66,54 @@ void change_helpstring(char *s){ * @return TRUE if conversion sone without errors, FALSE otherwise */ static bool myatoll(void *num, char *str, argtype t){ - long long tmp, *llptr; - int *iptr; - char *endptr; - assert(str); - assert(num); - tmp = strtoll(str, &endptr, 0); - if(endptr == str || *str == '\0' || *endptr != '\0') - return FALSE; - switch(t){ - case arg_longlong: - llptr = (long long*) num; - *llptr = tmp; - break; - case arg_int: - default: - if(tmp < INT_MIN || tmp > INT_MAX){ - /// " " - WARNX(_("Integer out of range")); - return FALSE; - } - iptr = (int*)num; - *iptr = (int)tmp; - } - return TRUE; + long long tmp, *llptr; + int *iptr; + char *endptr; + assert(str); + assert(num); + tmp = strtoll(str, &endptr, 0); + if(endptr == str || *str == '\0' || *endptr != '\0') + return FALSE; + switch(t){ + case arg_longlong: + llptr = (long long*) num; + *llptr = tmp; + break; + case arg_int: + default: + if(tmp < INT_MIN || tmp > INT_MAX){ + /// " " + WARNX(_("Integer out of range")); + return FALSE; + } + iptr = (int*)num; + *iptr = (int)tmp; + } + return TRUE; } // the same as myatoll but for double // There's no NAN & INF checking here (what if they would be needed?) static bool myatod(void *num, const char *str, argtype t){ - double tmp, *dptr; - float *fptr; - char *endptr; - assert(str); - tmp = strtod(str, &endptr); - if(endptr == str || *str == '\0' || *endptr != '\0') - return FALSE; - switch(t){ - case arg_double: - dptr = (double *) num; - *dptr = tmp; - break; - case arg_float: - default: - fptr = (float *) num; - *fptr = (float)tmp; - break; - } - return TRUE; + double tmp, *dptr; + float *fptr; + char *endptr; + assert(str); + tmp = strtod(str, &endptr); + if(endptr == str || *str == '\0' || *endptr != '\0') + return FALSE; + switch(t){ + case arg_double: + dptr = (double *) num; + *dptr = tmp; + break; + case arg_float: + default: + fptr = (float *) num; + *fptr = (float)tmp; + break; + } + return TRUE; } /** @@ -123,13 +123,13 @@ static bool myatod(void *num, const char *str, argtype t){ * @return index in array */ static int get_optind(int opt, myoption *options){ - int oind; - myoption *opts = options; - assert(opts); - for(oind = 0; opts->name && opts->val != opt; oind++, opts++); - if(!opts->name || opts->val != opt) // no such parameter - showhelp(-1, options); - return oind; + int oind; + myoption *opts = options; + assert(opts); + for(oind = 0; opts->name && opts->val != opt; oind++, opts++); + if(!opts->name || opts->val != opt) // no such parameter + showhelp(-1, options); + return oind; } /** @@ -139,46 +139,46 @@ static int get_optind(int opt, myoption *options){ * @return pointer to new (next) value */ void *get_aptr(void *paptr, argtype type){ - int i = 1; - void **aptr = *((void***)paptr); - if(aptr){ // there's something in array - void **p = aptr; - while(*p++) ++i; - } - size_t sz = 0; - switch(type){ - default: - case arg_none: - /// " !" - ERRX("Can't use multiple args with arg_none!"); - break; - case arg_int: - sz = sizeof(int); - break; - case arg_longlong: - sz = sizeof(long long); - break; - case arg_double: - sz = sizeof(double); - break; - case arg_float: - sz = sizeof(float); - break; - case arg_string: - sz = 0; - break; - /* case arg_function: - sz = sizeof(argfn *); - break;*/ - } - aptr = realloc(aptr, (i + 1) * sizeof(void*)); - *((void***)paptr) = aptr; - aptr[i] = NULL; - if(sz){ - aptr[i - 1] = malloc(sz); - }else - aptr[i - 1] = &aptr[i - 1]; - return aptr[i - 1]; + int i = 1; + void **aptr = *((void***)paptr); + if(aptr){ // there's something in array + void **p = aptr; + while(*p++) ++i; + } + size_t sz = 0; + switch(type){ + default: + case arg_none: + /// " !" + ERRX("Can't use multiple args with arg_none!"); + break; + case arg_int: + sz = sizeof(int); + break; + case arg_longlong: + sz = sizeof(long long); + break; + case arg_double: + sz = sizeof(double); + break; + case arg_float: + sz = sizeof(float); + break; + case arg_string: + sz = 0; + break; + /* case arg_function: + sz = sizeof(argfn *); + break;*/ + } + aptr = realloc(aptr, (i + 1) * sizeof(void*)); + *((void***)paptr) = aptr; + aptr[i] = NULL; + if(sz){ + aptr[i - 1] = malloc(sz); + }else + aptr[i - 1] = &aptr[i - 1]; + return aptr[i - 1]; } @@ -189,145 +189,145 @@ void *get_aptr(void *paptr, argtype type){ * @param argc (io) - address of argc of main(), return value of argc stay after `getopt` * @param argv (io) - address of argv of main(), return pointer to argv stay after `getopt` * BE CAREFUL! if you wanna use full argc & argv, save their original values before - * calling this function + * calling this function * @param options (i) - array of `myoption` for arguments parcing * * @exit: in case of error this function show help & make `exit(-1)` */ void parseargs(int *argc, char ***argv, myoption *options){ - char *short_options, *soptr; - struct option *long_options, *loptr; - size_t optsize, i; - myoption *opts = options; - // check whether there is at least one options - assert(opts); - assert(opts[0].name); - // first we count how much values are in opts - for(optsize = 0; opts->name; optsize++, opts++); - // now we can allocate memory - short_options = calloc(optsize * 3 + 1, 1); // multiply by three for '::' in case of args in opts - long_options = calloc(optsize + 1, sizeof(struct option)); - opts = options; loptr = long_options; soptr = short_options; - // in debug mode check the parameters are not repeated + char *short_options, *soptr; + struct option *long_options, *loptr; + size_t optsize, i; + myoption *opts = options; + // check whether there is at least one options + assert(opts); + assert(opts[0].name); + // first we count how much values are in opts + for(optsize = 0; opts->name; optsize++, opts++); + // now we can allocate memory + short_options = calloc(optsize * 3 + 1, 1); // multiply by three for '::' in case of args in opts + long_options = calloc(optsize + 1, sizeof(struct option)); + opts = options; loptr = long_options; soptr = short_options; + // in debug mode check the parameters are not repeated #ifdef EBUG - char **longlist = MALLOC(char*, optsize); - char *shortlist = MALLOC(char, optsize); + char **longlist = MALLOC(char*, optsize); + char *shortlist = MALLOC(char, optsize); #endif - // fill short/long parameters and make a simple checking - for(i = 0; i < optsize; i++, loptr++, opts++){ - // check - assert(opts->name); // check name + // fill short/long parameters and make a simple checking + for(i = 0; i < optsize; i++, loptr++, opts++){ + // check + assert(opts->name); // check name #ifdef EBUG - longlist[i] = strdup(opts->name); + longlist[i] = strdup(opts->name); #endif - if(opts->has_arg){ - assert(opts->type != arg_none); // check error with arg type - assert(opts->argptr); // check pointer - } - if(opts->type != arg_none) // if there is a flag without arg, check its pointer - assert(opts->argptr); - // fill long_options - // don't do memcmp: what if there would be different alignment? - loptr->name = opts->name; - loptr->has_arg = (opts->has_arg < MULT_PAR) ? opts->has_arg : 1; - loptr->flag = opts->flag; - loptr->val = opts->val; - // fill short options if they are: - if(!opts->flag){ + if(opts->has_arg){ + assert(opts->type != arg_none); // check error with arg type + assert(opts->argptr); // check pointer + } + if(opts->type != arg_none) // if there is a flag without arg, check its pointer + assert(opts->argptr); + // fill long_options + // don't do memcmp: what if there would be different alignment? + loptr->name = opts->name; + loptr->has_arg = (opts->has_arg < MULT_PAR) ? opts->has_arg : 1; + loptr->flag = opts->flag; + loptr->val = opts->val; + // fill short options if they are: + if(!opts->flag){ #ifdef EBUG - shortlist[i] = (char) opts->val; + shortlist[i] = (char) opts->val; #endif - *soptr++ = opts->val; - if(loptr->has_arg) // add ':' if option has required argument - *soptr++ = ':'; - if(loptr->has_arg == 2) // add '::' if option has optional argument - *soptr++ = ':'; - } - } - // sort all lists & check for repeating + *soptr++ = opts->val; + if(loptr->has_arg) // add ':' if option has required argument + *soptr++ = ':'; + if(loptr->has_arg == 2) // add '::' if option has optional argument + *soptr++ = ':'; + } + } + // sort all lists & check for repeating #ifdef EBUG - int cmpstringp(const void *p1, const void *p2){ - return strcmp(* (char * const *) p1, * (char * const *) p2); - } - int cmpcharp(const void *p1, const void *p2){ - return (int)(*(char * const)p1 - *(char *const)p2); - } - qsort(longlist, optsize, sizeof(char *), cmpstringp); - qsort(shortlist,optsize, sizeof(char), cmpcharp); - char *prevl = longlist[0], prevshrt = shortlist[0]; - for(i = 1; i < optsize; ++i){ - if(longlist[i]){ - if(prevl){ - if(strcmp(prevl, longlist[i]) == 0) ERRX("double long arguments: --%s", prevl); - } - prevl = longlist[i]; - } - if(shortlist[i]){ - if(prevshrt){ - if(prevshrt == shortlist[i]) ERRX("double short arguments: -%c", prevshrt); - } - prevshrt = shortlist[i]; - } - } + int cmpstringp(const void *p1, const void *p2){ + return strcmp(* (char * const *) p1, * (char * const *) p2); + } + int cmpcharp(const void *p1, const void *p2){ + return (int)(*(char * const)p1 - *(char *const)p2); + } + qsort(longlist, optsize, sizeof(char *), cmpstringp); + qsort(shortlist,optsize, sizeof(char), cmpcharp); + char *prevl = longlist[0], prevshrt = shortlist[0]; + for(i = 1; i < optsize; ++i){ + if(longlist[i]){ + if(prevl){ + if(strcmp(prevl, longlist[i]) == 0) ERRX("double long arguments: --%s", prevl); + } + prevl = longlist[i]; + } + if(shortlist[i]){ + if(prevshrt){ + if(prevshrt == shortlist[i]) ERRX("double short arguments: -%c", prevshrt); + } + prevshrt = shortlist[i]; + } + } #endif - // now we have both long_options & short_options and can parse `getopt_long` - while(1){ - int opt; - int oindex = 0, optind = 0; // oindex - number of option in argv, optind - number in options[] - if((opt = getopt_long(*argc, *argv, short_options, long_options, &oindex)) == -1) break; - if(opt == '?'){ - opt = optopt; - optind = get_optind(opt, options); - if(options[optind].has_arg == NEED_ARG || options[optind].has_arg == MULT_PAR) - showhelp(optind, options); // need argument - } - else{ - if(opt == 0 || oindex > 0) optind = oindex; - else optind = get_optind(opt, options); - } - opts = &options[optind]; - if(opt == 0 && opts->has_arg == NO_ARGS) continue; // only long option changing integer flag - // now check option - if(opts->has_arg == NEED_ARG || opts->has_arg == MULT_PAR) - if(!optarg) showhelp(optind, options); // need argument - void *aptr; - if(opts->has_arg == MULT_PAR){ - aptr = get_aptr(opts->argptr, opts->type); - }else - aptr = opts->argptr; - bool result = TRUE; - // even if there is no argument, but argptr != NULL, think that optarg = "1" - if(!optarg) optarg = "1"; - switch(opts->type){ - default: - case arg_none: - if(opts->argptr) *((int*)aptr) += 1; // increment value - break; - case arg_int: - result = myatoll(aptr, optarg, arg_int); - break; - case arg_longlong: - result = myatoll(aptr, optarg, arg_longlong); - break; - case arg_double: - result = myatod(aptr, optarg, arg_double); - break; - case arg_float: - result = myatod(aptr, optarg, arg_float); - break; - case arg_string: - result = (*((void**)aptr) = (void*)strdup(optarg)); - break; - case arg_function: - result = ((argfn)aptr)(optarg); - break; - } - if(!result){ - showhelp(optind, options); - } - } - *argc -= optind; - *argv += optind; + // now we have both long_options & short_options and can parse `getopt_long` + while(1){ + int opt; + int oindex = 0, optind = 0; // oindex - number of option in argv, optind - number in options[] + if((opt = getopt_long(*argc, *argv, short_options, long_options, &oindex)) == -1) break; + if(opt == '?'){ + opt = optopt; + optind = get_optind(opt, options); + if(options[optind].has_arg == NEED_ARG || options[optind].has_arg == MULT_PAR) + showhelp(optind, options); // need argument + } + else{ + if(opt == 0 || oindex > 0) optind = oindex; + else optind = get_optind(opt, options); + } + opts = &options[optind]; + if(opt == 0 && opts->has_arg == NO_ARGS) continue; // only long option changing integer flag + // now check option + if(opts->has_arg == NEED_ARG || opts->has_arg == MULT_PAR) + if(!optarg) showhelp(optind, options); // need argument + void *aptr; + if(opts->has_arg == MULT_PAR){ + aptr = get_aptr(opts->argptr, opts->type); + }else + aptr = opts->argptr; + bool result = TRUE; + // even if there is no argument, but argptr != NULL, think that optarg = "1" + if(!optarg) optarg = "1"; + switch(opts->type){ + default: + case arg_none: + if(opts->argptr) *((int*)aptr) += 1; // increment value + break; + case arg_int: + result = myatoll(aptr, optarg, arg_int); + break; + case arg_longlong: + result = myatoll(aptr, optarg, arg_longlong); + break; + case arg_double: + result = myatod(aptr, optarg, arg_double); + break; + case arg_float: + result = myatod(aptr, optarg, arg_float); + break; + case arg_string: + result = (*((void**)aptr) = (void*)strdup(optarg)); + break; + case arg_function: + result = ((argfn)aptr)(optarg); + break; + } + if(!result){ + showhelp(optind, options); + } + } + *argc -= optind; + *argv += optind; } /** @@ -335,19 +335,19 @@ void parseargs(int *argc, char ***argv, myoption *options){ * first - sort by short options; second - sort arguments without sort opts (by long options) */ static int argsort(const void *a1, const void *a2){ - const myoption *o1 = (myoption*)a1, *o2 = (myoption*)a2; - const char *l1 = o1->name, *l2 = o2->name; - int s1 = o1->val, s2 = o2->val; - int *f1 = o1->flag, *f2 = o2->flag; - // check if both options has short arg - if(f1 == NULL && f2 == NULL){ // both have short arg - return (s1 - s2); - }else if(f1 != NULL && f2 != NULL){ // both don't have short arg - sort by long - return strcmp(l1, l2); - }else{ // only one have short arg -- return it - if(f2) return -1; // a1 have short - it is 'lesser' - else return 1; - } + const myoption *o1 = (myoption*)a1, *o2 = (myoption*)a2; + const char *l1 = o1->name, *l2 = o2->name; + int s1 = o1->val, s2 = o2->val; + int *f1 = o1->flag, *f2 = o2->flag; + // check if both options has short arg + if(f1 == NULL && f2 == NULL){ // both have short arg + return (s1 - s2); + }else if(f1 != NULL && f2 != NULL){ // both don't have short arg - sort by long + return strcmp(l1, l2); + }else{ // only one have short arg -- return it + if(f2) return -1; // a1 have short - it is 'lesser' + else return 1; + } } /** @@ -358,57 +358,57 @@ static int argsort(const void *a1, const void *a2){ * @exit: run `exit(-1)` !!! */ void showhelp(int oindex, myoption *options){ - int max_opt_len = 0; // max len of options substring - for right indentation - const int bufsz = 255; - char buf[bufsz+1]; - myoption *opts = options; - assert(opts); - assert(opts[0].name); // check whether there is at least one options - if(oindex > -1){ // print only one message - opts = &options[oindex]; - printf(" "); - if(!opts->flag && isalpha(opts->val)) printf("-%c, ", opts->val); - printf("--%s", opts->name); - if(opts->has_arg == 1) printf("=arg"); - else if(opts->has_arg == 2) printf("[=arg]"); - printf(" %s\n", _(opts->help)); - exit(-1); - } - // header, by default is just "progname\n" - printf("\n"); - if(strstr(helpstring, "%s")) // print progname - printf(helpstring, __progname); - else // only text - printf("%s", helpstring); - printf("\n"); - // count max_opt_len - do{ - int L = strlen(opts->name); - if(max_opt_len < L) max_opt_len = L; - }while((++opts)->name); - max_opt_len += 14; // format: '-S , --long[=arg]' - get addition 13 symbols - opts = options; - // count amount of options - int N; for(N = 0; opts->name; ++N, ++opts); - if(N == 0) exit(-2); - // Now print all help (sorted) - opts = options; - qsort(opts, N, sizeof(myoption), argsort); - do{ - int p = sprintf(buf, " "); // a little indent - if(!opts->flag) // .val is short argument - p += snprintf(buf+p, bufsz-p, "-%c, ", opts->val); - p += snprintf(buf+p, bufsz-p, "--%s", opts->name); - if(opts->has_arg == 1) // required argument - p += snprintf(buf+p, bufsz-p, "=arg"); - else if(opts->has_arg == 2) // optional argument - p += snprintf(buf+p, bufsz-p, "[=arg]"); - assert(p < max_opt_len); // there would be magic if p >= max_opt_len - printf("%-*s%s\n", max_opt_len+1, buf, _(opts->help)); // write options & at least 2 spaces after - ++opts; - }while(--N); - printf("\n\n"); - exit(-1); + int max_opt_len = 0; // max len of options substring - for right indentation + const int bufsz = 255; + char buf[bufsz+1]; + myoption *opts = options; + assert(opts); + assert(opts[0].name); // check whether there is at least one options + if(oindex > -1){ // print only one message + opts = &options[oindex]; + printf(" "); + if(!opts->flag && isalpha(opts->val)) printf("-%c, ", opts->val); + printf("--%s", opts->name); + if(opts->has_arg == 1) printf("=arg"); + else if(opts->has_arg == 2) printf("[=arg]"); + printf(" %s\n", _(opts->help)); + exit(-1); + } + // header, by default is just "progname\n" + printf("\n"); + if(strstr(helpstring, "%s")) // print progname + printf(helpstring, __progname); + else // only text + printf("%s", helpstring); + printf("\n"); + // count max_opt_len + do{ + int L = strlen(opts->name); + if(max_opt_len < L) max_opt_len = L; + }while((++opts)->name); + max_opt_len += 14; // format: '-S , --long[=arg]' - get addition 13 symbols + opts = options; + // count amount of options + int N; for(N = 0; opts->name; ++N, ++opts); + if(N == 0) exit(-2); + // Now print all help (sorted) + opts = options; + qsort(opts, N, sizeof(myoption), argsort); + do{ + int p = sprintf(buf, " "); // a little indent + if(!opts->flag) // .val is short argument + p += snprintf(buf+p, bufsz-p, "-%c, ", opts->val); + p += snprintf(buf+p, bufsz-p, "--%s", opts->name); + if(opts->has_arg == 1) // required argument + p += snprintf(buf+p, bufsz-p, "=arg"); + else if(opts->has_arg == 2) // optional argument + p += snprintf(buf+p, bufsz-p, "[=arg]"); + assert(p < max_opt_len); // there would be magic if p >= max_opt_len + printf("%-*s%s\n", max_opt_len+1, buf, _(opts->help)); // write options & at least 2 spaces after + ++opts; + }while(--N); + printf("\n\n"); + exit(-1); } /** @@ -418,80 +418,80 @@ void showhelp(int oindex, myoption *options){ * @return TRUE if all OK */ bool get_suboption(char *str, mysuboption *opt){ - int findsubopt(char *par, mysuboption *so){ - int idx = 0; - if(!par) return -1; - while(so[idx].name){ - if(strcasecmp(par, so[idx].name) == 0) return idx; - ++idx; - } - return -1; // badarg - } - bool opt_setarg(mysuboption *so, int idx, char *val){ - mysuboption *soptr = &so[idx]; - bool result = FALSE; - void *aptr = soptr->argptr; - switch(soptr->type){ - default: - case arg_none: - if(soptr->argptr) *((int*)aptr) += 1; // increment value - result = TRUE; - break; - case arg_int: - result = myatoll(aptr, val, arg_int); - break; - case arg_longlong: - result = myatoll(aptr, val, arg_longlong); - break; - case arg_double: - result = myatod(aptr, val, arg_double); - break; - case arg_float: - result = myatod(aptr, val, arg_float); - break; - case arg_string: - result = (*((void**)aptr) = (void*)strdup(val)); - break; - case arg_function: - result = ((argfn)aptr)(val); - break; - } - return result; - } - char *tok; - bool ret = FALSE; - char *tmpbuf; - tok = strtok_r(str, ":,", &tmpbuf); - do{ - char *val = strchr(tok, '='); - int noarg = 0; - if(val == NULL){ // no args - val = "1"; - noarg = 1; - }else{ - *val++ = '\0'; - if(!*val || *val == ':' || *val == ','){ // no argument - delimeter after = - val = "1"; noarg = 1; - } - } - int idx = findsubopt(tok, opt); - if(idx < 0){ - /// " : %s" - WARNX(_("Wrong parameter: %s"), tok); - goto returning; - } - if(noarg && opt[idx].has_arg == NEED_ARG){ - /// "%s: !" - WARNX(_("%s: argument needed!"), tok); - goto returning; - } - if(!opt_setarg(opt, idx, val)){ - /// " \"%s\" \"%s\"" - WARNX(_("Wrong argument \"%s\" of parameter \"%s\""), val, tok); - goto returning; - } - }while((tok = strtok_r(NULL, ":,", &tmpbuf))); - ret = TRUE; + int findsubopt(char *par, mysuboption *so){ + int idx = 0; + if(!par) return -1; + while(so[idx].name){ + if(strcasecmp(par, so[idx].name) == 0) return idx; + ++idx; + } + return -1; // badarg + } + bool opt_setarg(mysuboption *so, int idx, char *val){ + mysuboption *soptr = &so[idx]; + bool result = FALSE; + void *aptr = soptr->argptr; + switch(soptr->type){ + default: + case arg_none: + if(soptr->argptr) *((int*)aptr) += 1; // increment value + result = TRUE; + break; + case arg_int: + result = myatoll(aptr, val, arg_int); + break; + case arg_longlong: + result = myatoll(aptr, val, arg_longlong); + break; + case arg_double: + result = myatod(aptr, val, arg_double); + break; + case arg_float: + result = myatod(aptr, val, arg_float); + break; + case arg_string: + result = (*((void**)aptr) = (void*)strdup(val)); + break; + case arg_function: + result = ((argfn)aptr)(val); + break; + } + return result; + } + char *tok; + bool ret = FALSE; + char *tmpbuf; + tok = strtok_r(str, ":,", &tmpbuf); + do{ + char *val = strchr(tok, '='); + int noarg = 0; + if(val == NULL){ // no args + val = "1"; + noarg = 1; + }else{ + *val++ = '\0'; + if(!*val || *val == ':' || *val == ','){ // no argument - delimeter after = + val = "1"; noarg = 1; + } + } + int idx = findsubopt(tok, opt); + if(idx < 0){ + /// " : %s" + WARNX(_("Wrong parameter: %s"), tok); + goto returning; + } + if(noarg && opt[idx].has_arg == NEED_ARG){ + /// "%s: !" + WARNX(_("%s: argument needed!"), tok); + goto returning; + } + if(!opt_setarg(opt, idx, val)){ + /// " \"%s\" \"%s\"" + WARNX(_("Wrong argument \"%s\" of parameter \"%s\""), val, tok); + goto returning; + } + }while((tok = strtok_r(NULL, ":,", &tmpbuf))); + ret = TRUE; returning: - return ret; + return ret; } diff --git a/HSFW_management/parseargs.h b/HSFW_management/parseargs.h index b8351d9..a0ac099 100644 --- a/HSFW_management/parseargs.h +++ b/HSFW_management/parseargs.h @@ -26,11 +26,11 @@ #include #ifndef TRUE - #define TRUE true + #define TRUE true #endif #ifndef FALSE - #define FALSE false + #define FALSE false #endif // macro for argptr @@ -44,35 +44,35 @@ typedef bool(*argfn)(void *arg); * WARNING! * My function change value of flags by pointer, so if you want to use another type * make a latter conversion, example: - * char charg; - * int iarg; - * myoption opts[] = { - * {"value", 1, NULL, 'v', arg_int, &iarg, "char val"}, ..., end_option}; - * ..(parse args).. - * charg = (char) iarg; + * char charg; + * int iarg; + * myoption opts[] = { + * {"value", 1, NULL, 'v', arg_int, &iarg, "char val"}, ..., end_option}; + * ..(parse args).. + * charg = (char) iarg; */ typedef enum { - arg_none = 0, // no arg - arg_int, // integer - arg_longlong, // long long - arg_double, // double - arg_float, // float - arg_string, // char * - arg_function // parse_args will run function `bool (*fn)(char *optarg, int N)` + arg_none = 0, // no arg + arg_int, // integer + arg_longlong, // long long + arg_double, // double + arg_float, // float + arg_string, // char * + arg_function // parse_args will run function `bool (*fn)(char *optarg, int N)` } argtype; /* * Structure for getopt_long & help * BE CAREFUL: .argptr is pointer to data or pointer to function, - * conversion depends on .type + * conversion depends on .type * * ATTENTION: string `help` prints through macro PRNT(), bu default it is gettext, * but you can redefine it before `#include "parseargs.h"` * * if arg is string, then value wil be strdup'ed like that: - * char *str; - * myoption opts[] = {{"string", 1, NULL, 's', arg_string, &str, "string val"}, ..., end_option}; - * *(opts[1].str) = strdup(optarg); + * char *str; + * myoption opts[] = {{"string", 1, NULL, 's', arg_string, &str, "string val"}, ..., end_option}; + * *(opts[1].str) = strdup(optarg); * in other cases argptr should be address of some variable (or pointer to allocated memory) * * NON-NULL argptr should be written inside macro APTR(argptr) or directly: (void*)argptr @@ -81,22 +81,22 @@ typedef enum { * */ typedef enum{ - NO_ARGS = 0, // first three are the same as in getopt_long - NEED_ARG = 1, - OPT_ARG = 2, - MULT_PAR + NO_ARGS = 0, // first three are the same as in getopt_long + NEED_ARG = 1, + OPT_ARG = 2, + MULT_PAR } hasarg; typedef struct{ - // these are from struct option: - const char *name; // long option's name - hasarg has_arg; // 0 - no args, 1 - nesessary arg, 2 - optionally arg, 4 - need arg & key can repeat (args are stored in null-terminated array) - int *flag; // NULL to return val, pointer to int - to set its value of val (function returns 0) - int val; // short opt name (if flag == NULL) or flag's value - // and these are mine: - argtype type; // type of argument - void *argptr; // pointer to variable to assign optarg value or function `bool (*fn)(char *optarg, int N)` - const char *help; // help string which would be shown in function `showhelp` or NULL + // these are from struct option: + const char *name; // long option's name + hasarg has_arg; // 0 - no args, 1 - nesessary arg, 2 - optionally arg, 4 - need arg & key can repeat (args are stored in null-terminated array) + int *flag; // NULL to return val, pointer to int - to set its value of val (function returns 0) + int val; // short opt name (if flag == NULL) or flag's value + // and these are mine: + argtype type; // type of argument + void *argptr; // pointer to variable to assign optarg value or function `bool (*fn)(char *optarg, int N)` + const char *help; // help string which would be shown in function `showhelp` or NULL } myoption; /* @@ -104,10 +104,10 @@ typedef struct{ * used in parse_subopts() */ typedef struct{ - const char *name; - hasarg has_arg; - argtype type; - void *argptr; + const char *name; + hasarg has_arg; + argtype type; + void *argptr; } mysuboption; // last string of array (all zeros) diff --git a/HSFW_management/usefull_macros.c b/HSFW_management/usefull_macros.c index 7f3d38b..3f38a31 100644 --- a/HSFW_management/usefull_macros.c +++ b/HSFW_management/usefull_macros.c @@ -26,11 +26,11 @@ * @return double value: time in seconds */ double dtime(){ - double t; - struct timeval tv; - gettimeofday(&tv, NULL); - t = tv.tv_sec + ((double)tv.tv_usec)/1e6; - return t; + double t; + struct timeval tv; + gettimeofday(&tv, NULL); + t = tv.tv_sec + ((double)tv.tv_usec)/1e6; + return t; } /******************************************************************************\ @@ -50,22 +50,22 @@ int (*_WARN)(const char *fmt, ...); * @return number of printed symbols */ int r_pr_(const char *fmt, ...){ - va_list ar; int i; - printf(RED); - va_start(ar, fmt); - i = vprintf(fmt, ar); - va_end(ar); - printf(OLDCOLOR); - return i; + va_list ar; int i; + printf(RED); + va_start(ar, fmt); + i = vprintf(fmt, ar); + va_end(ar); + printf(OLDCOLOR); + return i; } int g_pr_(const char *fmt, ...){ - va_list ar; int i; - printf(GREEN); - va_start(ar, fmt); - i = vprintf(fmt, ar); - va_end(ar); - printf(OLDCOLOR); - return i; + va_list ar; int i; + printf(GREEN); + va_start(ar, fmt); + i = vprintf(fmt, ar); + va_end(ar); + printf(OLDCOLOR); + return i; } /* * print red error/warning messages (if output is a tty) @@ -73,20 +73,20 @@ int g_pr_(const char *fmt, ...){ * @return number of printed symbols */ int r_WARN(const char *fmt, ...){ - va_list ar; int i = 1; - fprintf(stderr, RED); - va_start(ar, fmt); - if(globErr){ - errno = globErr; - vwarn(fmt, ar); - errno = 0; - globErr = 0; - }else - i = vfprintf(stderr, fmt, ar); - va_end(ar); - i++; - fprintf(stderr, OLDCOLOR "\n"); - return i; + va_list ar; int i = 1; + fprintf(stderr, RED); + va_start(ar, fmt); + if(globErr){ + errno = globErr; + vwarn(fmt, ar); + errno = 0; + globErr = 0; + }else + i = vfprintf(stderr, fmt, ar); + va_end(ar); + i++; + fprintf(stderr, OLDCOLOR "\n"); + return i; } static const char stars[] = "****************************************"; @@ -97,49 +97,49 @@ static const char stars[] = "****************************************"; * @return number of printed symbols */ int s_WARN(const char *fmt, ...){ - va_list ar; int i; - i = fprintf(stderr, "\n%s\n", stars); - va_start(ar, fmt); - if(globErr){ - errno = globErr; - vwarn(fmt, ar); - errno = 0; - globErr = 0; - }else - i = +vfprintf(stderr, fmt, ar); - va_end(ar); - i += fprintf(stderr, "\n%s\n", stars); - i += fprintf(stderr, "\n"); - return i; + va_list ar; int i; + i = fprintf(stderr, "\n%s\n", stars); + va_start(ar, fmt); + if(globErr){ + errno = globErr; + vwarn(fmt, ar); + errno = 0; + globErr = 0; + }else + i = +vfprintf(stderr, fmt, ar); + va_end(ar); + i += fprintf(stderr, "\n%s\n", stars); + i += fprintf(stderr, "\n"); + return i; } int r_pr_notty(const char *fmt, ...){ - va_list ar; int i; - i = printf("\n%s\n", stars); - va_start(ar, fmt); - i += vprintf(fmt, ar); - va_end(ar); - i += printf("\n%s\n", stars); - return i; + va_list ar; int i; + i = printf("\n%s\n", stars); + va_start(ar, fmt); + i += vprintf(fmt, ar); + va_end(ar); + i += printf("\n%s\n", stars); + return i; } /** * Run this function in the beginning of main() to setup locale & coloured output */ void initial_setup(){ - // setup coloured output - if(isatty(STDOUT_FILENO)){ // make color output in tty - red = r_pr_; green = g_pr_; - }else{ // no colors in case of pipe - red = r_pr_notty; green = printf; - } - if(isatty(STDERR_FILENO)) _WARN = r_WARN; - else _WARN = s_WARN; - // Setup locale - setlocale(LC_ALL, ""); - setlocale(LC_NUMERIC, "C"); + // setup coloured output + if(isatty(STDOUT_FILENO)){ // make color output in tty + red = r_pr_; green = g_pr_; + }else{ // no colors in case of pipe + red = r_pr_notty; green = printf; + } + if(isatty(STDERR_FILENO)) _WARN = r_WARN; + else _WARN = s_WARN; + // Setup locale + setlocale(LC_ALL, ""); + setlocale(LC_NUMERIC, "C"); #if defined GETTEXT_PACKAGE && defined LOCALEDIR - bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); - textdomain(GETTEXT_PACKAGE); + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); + textdomain(GETTEXT_PACKAGE); #endif } @@ -153,10 +153,10 @@ void initial_setup(){ * @return pointer to allocated memory area */ void *my_alloc(size_t N, size_t S){ - void *p = calloc(N, S); - if(!p) ERR("malloc"); - //assert(p); - return p; + void *p = calloc(N, S); + if(!p) ERR("malloc"); + //assert(p); + return p; } /** @@ -166,35 +166,35 @@ void *my_alloc(size_t N, size_t S){ * @return stuct with mmap'ed file or die */ mmapbuf *My_mmap(char *filename){ - int fd; - char *ptr; - size_t Mlen; - struct stat statbuf; - /// " !" - if(!filename) ERRX(_("No filename given!")); - if((fd = open(filename, O_RDONLY)) < 0) - /// " %s " - ERR(_("Can't open %s for reading"), filename); - if(fstat (fd, &statbuf) < 0) - /// " stat %s" - ERR(_("Can't stat %s"), filename); - Mlen = statbuf.st_size; - if((ptr = mmap (0, Mlen, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) - /// " mmap" - ERR(_("Mmap error for input")); - /// " mmap' " - if(close(fd)) ERR(_("Can't close mmap'ed file")); - mmapbuf *ret = MALLOC(mmapbuf, 1); - ret->data = ptr; - ret->len = Mlen; - return ret; + int fd; + char *ptr; + size_t Mlen; + struct stat statbuf; + /// " !" + if(!filename) ERRX(_("No filename given!")); + if((fd = open(filename, O_RDONLY)) < 0) + /// " %s " + ERR(_("Can't open %s for reading"), filename); + if(fstat (fd, &statbuf) < 0) + /// " stat %s" + ERR(_("Can't stat %s"), filename); + Mlen = statbuf.st_size; + if((ptr = mmap (0, Mlen, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) + /// " mmap" + ERR(_("Mmap error for input")); + /// " mmap' " + if(close(fd)) ERR(_("Can't close mmap'ed file")); + mmapbuf *ret = MALLOC(mmapbuf, 1); + ret->data = ptr; + ret->len = Mlen; + return ret; } void My_munmap(mmapbuf *b){ - if(munmap(b->data, b->len)) - /// " munmap" - ERR(_("Can't munmap")); - FREE(b); + if(munmap(b->data, b->len)) + /// " munmap" + ERR(_("Can't munmap")); + FREE(b); } @@ -205,24 +205,24 @@ static struct termios oldt, newt; // terminal flags static int console_changed = 0; // run on exit: void restore_console(){ - if(console_changed) - tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // return terminal to previous state - console_changed = 0; + if(console_changed) + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // return terminal to previous state + console_changed = 0; } // initial setup: void setup_con(){ - if(console_changed) return; - tcgetattr(STDIN_FILENO, &oldt); - newt = oldt; - newt.c_lflag &= ~(ICANON | ECHO); - if(tcsetattr(STDIN_FILENO, TCSANOW, &newt) < 0){ - /// " " - WARN(_("Can't setup console")); - tcsetattr(STDIN_FILENO, TCSANOW, &oldt); - signals(0); //quit? - } - console_changed = 1; + if(console_changed) return; + tcgetattr(STDIN_FILENO, &oldt); + newt = oldt; + newt.c_lflag &= ~(ICANON | ECHO); + if(tcsetattr(STDIN_FILENO, TCSANOW, &newt) < 0){ + /// " " + WARN(_("Can't setup console")); + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + signals(0); //quit? + } + console_changed = 1; } /** @@ -230,20 +230,20 @@ void setup_con(){ * @return char readed */ int read_console(){ - int rb; - struct timeval tv; - int retval; - fd_set rfds; - FD_ZERO(&rfds); - FD_SET(STDIN_FILENO, &rfds); - tv.tv_sec = 0; tv.tv_usec = 10000; - retval = select(1, &rfds, NULL, NULL, &tv); - if(!retval) rb = 0; - else { - if(FD_ISSET(STDIN_FILENO, &rfds)) rb = getchar(); - else rb = 0; - } - return rb; + int rb; + struct timeval tv; + int retval; + fd_set rfds; + FD_ZERO(&rfds); + FD_SET(STDIN_FILENO, &rfds); + tv.tv_sec = 0; tv.tv_usec = 10000; + retval = select(1, &rfds, NULL, NULL, &tv); + if(!retval) rb = 0; + else { + if(FD_ISSET(STDIN_FILENO, &rfds)) rb = getchar(); + else rb = 0; + } + return rb; } /** @@ -252,10 +252,10 @@ int read_console(){ * @return character readed */ int mygetchar(){ // getchar() without need of pressing ENTER - int ret; - do ret = read_console(); - while(ret == 0); - return ret; + int ret; + do ret = read_console(); + while(ret == 0); + return ret; } @@ -267,10 +267,10 @@ static int comfd = -1; // TTY fd // run on exit: void restore_tty(){ - if(comfd == -1) return; - ioctl(comfd, TCSANOW, &oldtty ); // return TTY to previous state - close(comfd); - comfd = -1; + if(comfd == -1) return; + ioctl(comfd, TCSANOW, &oldtty ); // return TTY to previous state + close(comfd); + comfd = -1; } #ifndef BAUD_RATE @@ -278,31 +278,31 @@ void restore_tty(){ #endif // init: void tty_init(char *comdev){ - DBG("\nOpen port...\n"); - if ((comfd = open(comdev,O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0){ - WARN("Can't use port %s\n",comdev); - ioctl(comfd, TCSANOW, &oldtty); // return TTY to previous state - close(comfd); - signals(0); // quit? - } - DBG(" OK\nGet current settings... "); - if(ioctl(comfd,TCGETA,&oldtty) < 0){ // Get settings - /// " " - WARN(_("Can't get settings")); - signals(0); - } - tty = oldtty; - tty.c_lflag = 0; // ~(ICANON | ECHO | ECHOE | ISIG) - tty.c_oflag = 0; - tty.c_cflag = BAUD_RATE|CS8|CREAD|CLOCAL; // 9.6k, 8N1, RW, ignore line ctrl - tty.c_cc[VMIN] = 0; // non-canonical mode - tty.c_cc[VTIME] = 5; - if(ioctl(comfd,TCSETA,&tty) < 0){ - /// " " - WARN(_("Can't set settings")); - signals(0); - } - DBG(" OK\n"); + DBG("\nOpen port...\n"); + if ((comfd = open(comdev,O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0){ + WARN("Can't use port %s\n",comdev); + ioctl(comfd, TCSANOW, &oldtty); // return TTY to previous state + close(comfd); + signals(0); // quit? + } + DBG(" OK\nGet current settings... "); + if(ioctl(comfd,TCGETA,&oldtty) < 0){ // Get settings + /// " " + WARN(_("Can't get settings")); + signals(0); + } + tty = oldtty; + tty.c_lflag = 0; // ~(ICANON | ECHO | ECHOE | ISIG) + tty.c_oflag = 0; + tty.c_cflag = BAUD_RATE|CS8|CREAD|CLOCAL; // 9.6k, 8N1, RW, ignore line ctrl + tty.c_cc[VMIN] = 0; // non-canonical mode + tty.c_cc[VTIME] = 5; + if(ioctl(comfd,TCSETA,&tty) < 0){ + /// " " + WARN(_("Can't set settings")); + signals(0); + } + DBG(" OK\n"); } /** * Read data from TTY @@ -311,26 +311,26 @@ void tty_init(char *comdev){ * @return amount of readed bytes */ size_t read_tty(uint8_t *buff, size_t length){ - ssize_t L = 0; - fd_set rfds; - struct timeval tv; - int retval; - FD_ZERO(&rfds); - FD_SET(comfd, &rfds); - tv.tv_sec = 0; tv.tv_usec = 50000; // wait for 50ms - retval = select(comfd + 1, &rfds, NULL, NULL, &tv); - if (!retval) return 0; - if(FD_ISSET(comfd, &rfds)){ - if((L = read(comfd, buff, length)) < 1) return 0; - } - return (size_t)L; + ssize_t L = 0; + fd_set rfds; + struct timeval tv; + int retval; + FD_ZERO(&rfds); + FD_SET(comfd, &rfds); + tv.tv_sec = 0; tv.tv_usec = 50000; // wait for 50ms + retval = select(comfd + 1, &rfds, NULL, NULL, &tv); + if (!retval) return 0; + if(FD_ISSET(comfd, &rfds)){ + if((L = read(comfd, buff, length)) < 1) return 0; + } + return (size_t)L; } int write_tty(uint8_t *buff, size_t length){ - ssize_t L = write(comfd, buff, length); - if((size_t)L != length){ - WARN("Write error!"); - return 1; - } - return 0; + ssize_t L = write(comfd, buff, length); + if((size_t)L != length){ + WARN("Write error!"); + return 1; + } + return 0; } diff --git a/HSFW_management/usefull_macros.h b/HSFW_management/usefull_macros.h index ab968a4..52dd4fa 100644 --- a/HSFW_management/usefull_macros.h +++ b/HSFW_management/usefull_macros.h @@ -38,12 +38,12 @@ * GETTEXT */ #include -#define _(String) gettext(String) -#define gettext_noop(String) String -#define N_(String) gettext_noop(String) +#define _(String) gettext(String) +#define gettext_noop(String) String +#define N_(String) gettext_noop(String) #else -#define _(String) (String) -#define N_(String) (String) +#define _(String) (String) +#define N_(String) (String) #endif #include #include @@ -59,9 +59,9 @@ /* * Coloured messages output */ -#define RED "\033[1;31;40m" -#define GREEN "\033[1;32;40m" -#define OLDCOLOR "\033[0;0;0m" +#define RED "\033[1;31;40m" +#define GREEN "\033[1;32;40m" +#define OLDCOLOR "\033[0;0;0m" /* * ERROR/WARNING messages @@ -78,13 +78,13 @@ extern void signals(int sig); * debug mode, -DEBUG */ #ifdef EBUG - #define FNAME() fprintf(stderr, "\n%s (%s, line %d)\n", __func__, __FILE__, __LINE__) - #define DBG(...) do{fprintf(stderr, "%s (%s, line %d): ", __func__, __FILE__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, "\n");} while(0) + #define FNAME() fprintf(stderr, "\n%s (%s, line %d)\n", __func__, __FILE__, __LINE__) + #define DBG(...) do{fprintf(stderr, "%s (%s, line %d): ", __func__, __FILE__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n");} while(0) #else - #define FNAME() do{}while(0) - #define DBG(...) do{}while(0) + #define FNAME() do{}while(0) + #define DBG(...) do{}while(0) #endif //EBUG /* @@ -92,7 +92,7 @@ extern void signals(int sig); */ #define ALLOC(type, var, size) type * var = ((type *)my_alloc(size, sizeof(type))) #define MALLOC(type, size) ((type *)my_alloc(size, sizeof(type))) -#define FREE(ptr) do{if(ptr){free(ptr); ptr = NULL;}}while(0) +#define FREE(ptr) do{free(ptr); ptr = NULL;}while(0) double dtime(); @@ -105,8 +105,8 @@ void initial_setup(); // mmap file typedef struct{ - char *data; - size_t len; + char *data; + size_t len; } mmapbuf; mmapbuf *My_mmap(char *filename); void My_munmap(mmapbuf *b); diff --git a/getopt/cmdlnopts/parseargs.c b/getopt/cmdlnopts/parseargs.c index 07182a5..b235752 100644 --- a/getopt/cmdlnopts/parseargs.c +++ b/getopt/cmdlnopts/parseargs.c @@ -1,4 +1,4 @@ -/* +/* geany_encoding=koi8-r * parseargs.c - parsing command line arguments & print help * * Copyright 2013 Edward V. Emelianoff @@ -286,7 +286,7 @@ void parseargs(int *argc, char ***argv, myoption *options){ else optind = get_optind(opt, options); } opts = &options[optind]; - //if(opt == 0 && opts->has_arg == NO_ARGS) continue; // only long option changing integer flag + // if(opt == 0 && opts->has_arg == NO_ARGS) continue; // only long option changing integer flag // now check option if(opts->has_arg == NEED_ARG || opts->has_arg == MULT_PAR) if(!optarg) showhelp(optind, options); // need argument diff --git a/sockmsgs.c b/sockmsgs.c index 3cd1447..7d12576 100644 --- a/sockmsgs.c +++ b/sockmsgs.c @@ -168,8 +168,6 @@ void server_(int sock){ } // Main loop while(1){ - fd_set readfds; - struct timeval timeout; socklen_t size = sizeof(struct sockaddr_in); struct sockaddr_in their_addr; int newsock;