int test(char *in, const char *right) { char *tmp; verb_printf("trying %s\n", in); tmp = a_chomp(in); verb_printf("\tgot %s\n", tmp); verb_printf("\twanted %s\n", right); return(strcmp(tmp, right)); }
MODULE_STATIC int mod_unload(void) { WRLOCK_LANG_CONFIG ; verb_printf("Lang stopped\n"); return(MOD_CODE_OK); }
int test(const char *in, const char *right, ...) { char *tmp; int ret; va_list arg_list; verb_printf("trying %s\n", in); va_start(arg_list, right); tmp = a_vsprintf_malloc(in, arg_list); va_end(arg_list); if(!tmp) test_fail(); verb_printf("\tgot %s\n", tmp); verb_printf("\twanted %s\n", right); ret = strcmp(tmp, right); a_free(tmp); return ret; }
/* analize string parameter of style file */ static void convline(char *buff1, int start, char *buff2) { int i,j,cc; for (i=start,j=cc=0;;i++) { if (buff1[i]=='\"') { if (cc==0) { cc=1; } else { buff2[j]='\0'; break; } } else if ((buff1[i]=='\n')||(buff1[i]=='\0')) { if (cc==1) { buff2[j++]='\n'; } if (fgets(buff1,4095,fp)==NULL) { buff2[j]='\0'; break; } i= -1; } else if (cc==1) { if ((unsigned char)buff1[i]>0x80) { int len = multibytelen((unsigned char)buff1[i]); if (len<0) { verb_printf(efp,"\nWarning: Illegal input of lead byte 0x%x in UTF-8.", (unsigned char)buff1[i]); continue; } while(len--) { buff2[j++]=buff1[i++]; } i--; continue; } else if (buff1[i]=='\\' && !escape_mode) { i++; if (buff1[i]=='\\') buff2[j]='\\'; else if (buff1[i]=='n') buff2[j]='\n'; else if (buff1[i]=='t') buff2[j]='\t'; else if (buff1[i]=='r') buff2[j]='\r'; else if (buff1[i]=='\"') buff2[j]='\"'; } else buff2[j]=buff1[i]; j++; } } }
void set_icu_attributes() { int i,attr; char *pos, *tmp; for (i=0;i<UCOL_ATTRIBUTE_COUNT;i++) icu_attributes[i]=UCOL_DEFAULT; tmp=icu_attr_str; if (pos=strstr(tmp,"alternate:")) { pos+=10; attr=UCOL_ALTERNATE_HANDLING; if (strstr(pos,"shifted")) icu_attributes[attr]=UCOL_SHIFTED; else if (strstr(pos,"non-ignorable")) icu_attributes[attr]=UCOL_NON_IGNORABLE; else verb_printf(efp,"\nWarning: Illegal input for icu_attributes (alternate)."); } if (pos=strstr(tmp,"strength:")) { pos+=9; attr=UCOL_STRENGTH; if (strstr(pos,"primary")) icu_attributes[attr]=UCOL_PRIMARY; else if (strstr(pos,"secondary")) icu_attributes[attr]=UCOL_SECONDARY; else if (strstr(pos,"tertiary")) icu_attributes[attr]=UCOL_TERTIARY; else if (strstr(pos,"quaternary")) icu_attributes[attr]=UCOL_QUATERNARY; else if (strstr(pos,"identical")) icu_attributes[attr]=UCOL_IDENTICAL; else verb_printf(efp,"\nWarning: Illegal input for icu_attributes (strength)."); } if (pos=strstr(tmp,"french-collation:")) { pos+=17; attr=UCOL_FRENCH_COLLATION; if (strstr(pos,"on")) icu_attributes[attr]=UCOL_ON; else if (strstr(pos,"off")) icu_attributes[attr]=UCOL_OFF; else verb_printf(efp,"\nWarning: Illegal input for icu_attributes (french-collation)."); } if (pos=strstr(tmp,"case-first:")) { pos+=11; attr=UCOL_CASE_FIRST; if (strstr(pos,"off")) icu_attributes[attr]=UCOL_OFF; else if (strstr(pos,"upper-first")) icu_attributes[attr]=UCOL_UPPER_FIRST; else if (strstr(pos,"lower-first")) icu_attributes[attr]=UCOL_LOWER_FIRST; else verb_printf(efp,"\nWarning: Illegal input for icu_attributes (case-first)."); } if (pos=strstr(tmp,"case-level:")) { pos+=11; attr=UCOL_CASE_LEVEL; if (strstr(pos,"on")) icu_attributes[attr]=UCOL_ON; else if (strstr(pos,"off")) icu_attributes[attr]=UCOL_OFF; else verb_printf(efp,"\nWarning: Illegal input for icu_attributes (case-level)."); } if (pos=strstr(tmp,"normalization-mode:")) { pos+=19; attr=UCOL_NORMALIZATION_MODE; if (strstr(pos,"on")) icu_attributes[attr]=UCOL_ON; else if (strstr(pos,"off")) icu_attributes[attr]=UCOL_OFF; else verb_printf(efp,"\nWarning: Illegal input for icu_attributes (normalization-mode)."); } }
int main(int argc, char **argv) { int i,j,cc=0,startpagenum=-1,ecount=0,chkopt=1; const char *envbuff; UVersionInfo icuVersion; char icu_version[U_MAX_VERSION_STRING_LENGTH] = ""; #ifdef WIN32 char **av; int ac; _setmaxstdio(2048); #endif kpse_set_program_name(argv[0], "upmendex"); #ifdef WIN32 file_system_codepage = CP_UTF8; is_cp932_system = 0; if (get_command_line_args_utf8("utf-8", &ac, &av)) { argv = av; argc = ac; } #endif kp_ist.var_name = "INDEXSTYLE"; kp_ist.path = DEFAULT_INDEXSTYLES; /* default path. */ kp_ist.suffix = "ist"; KP_entry_filetype(&kp_ist); kp_dict.var_name = "INDEXDICTIONARY"; kp_dict.path = DEFAULT_INDEXDICTS; /* default path */ kp_dict.suffix = "dict"; KP_entry_filetype(&kp_dict); /* check options */ for (i=1,j=0; i<argc && j<256; i++) { if ((argv[i][0]=='-')&&(strlen(argv[i])>=2)&&chkopt) { switch (argv[i][1]) { case 'c': bcomp=1; break; case 'd': if ((argv[i][2]=='\0')&&(i+1<argc)) { dicfile=xstrdup(argv[++i]); } else { dicfile=xstrdup(&argv[i][2]); } break; case 'f': force=1; break; case 'g': gflg=1; break; case 'i': fsti=1; break; case 'l': lorder=1; break; case 'o': if ((argv[i][2]=='\0')&&(i+1<argc)) { indfile=xstrdup(argv[++i]); } else { indfile=xstrdup(&argv[i][2]); } break; case 'p': if ((argv[i][2]=='\0')&&(i+1<argc)) { i++; if (strcmp(argv[i],"any")==0) fpage=2; else if (strcmp(argv[i],"odd")==0) fpage=3; else if (strcmp(argv[i],"even")==0) fpage=4; else { fpage=1; startpagenum=atoi(argv[i]); } } else { if (strcmp(&argv[i][2],"any")==0) fpage=2; else if (strcmp(&argv[i][2],"odd")==0) fpage=3; else if (strcmp(&argv[i][2],"even")==0) fpage=4; else { fpage=1; startpagenum=atoi(&argv[i][2]); } } break; case 'q': verb=0; break; case 't': if ((argv[i][2]=='\0')&&(i+1<argc)) { logfile=xstrdup(argv[++i]); } else { logfile=xstrdup(&argv[i][2]); } break; case 'r': prange=0; break; case 's': if ((argv[i][2]=='\0')&&(i+1<argc)) { styfile=xstrdup(argv[++i]); } else { styfile=xstrdup(&argv[i][2]); } break; case 'v': debug=1; break; case '-': if (strlen(argv[i])==2) chkopt=0; if (strcmp(argv[i],"--help")!=0) break; default: u_getVersion(icuVersion); u_versionToString(icuVersion, icu_version); fprintf(stderr,"upmendex - index processor, %s (%s).\n",VERSION, TL_VERSION); fprintf(stderr," Copyright 2009 ASCII MEDIA WORKS, 2015-2016 TANAKA Takuji\n"); fprintf(stderr," using ICU version %s\n",icu_version); fprintf(stderr,"usage:\n"); fprintf(stderr,"%% upmendex [-ilqrcgf] [-s sty] [-d dic] [-o ind] [-t log] [-p no] [--] [idx0 idx1 ...]\n"); fprintf(stderr,"options:\n"); fprintf(stderr,"-i use stdin as the input file.\n"); fprintf(stderr,"-l use letter ordering.\n"); fprintf(stderr,"-q quiet mode.\n"); fprintf(stderr,"-r disable implicit page formation.\n"); fprintf(stderr,"-c compress blanks. (ignore leading and trailing blanks.)\n"); fprintf(stderr,"-g make Japanese index head <%s>.\n", AKASATANAutf8); fprintf(stderr,"-f force to output unknown scripts.\n"); fprintf(stderr,"-s sty take sty as style file.\n"); fprintf(stderr,"-d dic take dic as dictionary file.\n"); fprintf(stderr,"-o ind take ind as the output index file.\n"); fprintf(stderr,"-t log take log as the error log file.\n"); fprintf(stderr,"-p no set the starting page number of index.\n"); fprintf(stderr,"idx... input files.\n"); exit(0); break; } } else { cc=strlen(argv[i]); if (cc<4) cc+=4; else if (strcmp(&argv[i][cc-4],".idx")) cc+=4; idxfile[j]=xmalloc(cc+1); strcpy(idxfile[j++],argv[i]); } } idxcount=j+fsti; /* check option errors */ if (idxcount==0) idxcount=fsti=1; if (styfile==NULL) { envbuff=kpse_var_value("INDEXDEFAULTSTYLE"); if (envbuff!=NULL) { styfile=xstrdup(envbuff); } } /* init hangul tumunja table */ u_strcpy(tumunja,GANADA); if (styfile!=NULL) styread(styfile); if (!indfile &&(idxcount-fsti>0)) { indfile=xmalloc(strlen(idxfile[0]+6)); for (i=strlen(idxfile[0]); i>=0; i--) { if (idxfile[0][i]=='.') { strncpy(indfile,idxfile[0],i); sprintf(&indfile[i],".ind"); break; } } if (i==-1) sprintf(indfile,"%s.ind",idxfile[0]); } if (!logfile && (idxcount-fsti > 0)) { logfile=xmalloc(strlen(idxfile[0]+6)); for (i=strlen(idxfile[0]); i>=0; i--) { if (idxfile[0][i]=='.') { strncpy(logfile,idxfile[0],i); sprintf(&logfile[i],".ilg"); break; } } if (i==-1) sprintf(logfile,"%s.ilg",idxfile[0]); } if (logfile && kpse_out_name_ok(logfile)) efp=fopen(logfile,"wb"); if(efp == NULL) { efp=stderr; logfile=xstrdup("stderr"); } set_icu_attributes(); if (strcmp(argv[0],"makeindex")==0) { verb_printf(efp,"This is Not `MAKEINDEX\', But `UPMENDEX\' %s (%s).\n", VERSION, TL_VERSION); } else { verb_printf(efp,"This is upmendex %s (%s).\n", VERSION, TL_VERSION); } /* init kanatable */ initkanatable(); /* read dictionary */ ecount+=dicread(dicfile); switch (letter_head) { case 0: case 1: if (gflg==1) { u_strcpy(atama,akasatana); } else { u_strcpy(atama,aiueo); } break; case 2: if (gflg==1) { u_strcpy(atama,AKASATANA); } else { u_strcpy(atama,AIUEO); } break; default: break; } /* read idx file */ lines=0; ecount=0; ind=xmalloc(sizeof(struct index)); for (i=0; i<idxcount-fsti; i++) { ecount+=idxread(idxfile[i],lines); } if (fsti==1) { ecount+=idxread(NULL,lines); } verb_printf(efp,"%d entries accepted, %d rejected.\n",acc,reject); if (ecount!=0) { verb_printf(efp,"%d errors, written in %s.\n",ecount,logfile); lines=0; } if (lines==0) { verb_printf(efp,"Nothing written in output file.\n"); if (efp!=stderr) fclose(efp); exit(255); } /* sort index */ verb_printf(efp,"Sorting index."); scount=0; wsort(ind,lines); verb_printf(efp,"...done(%d comparisons).\n",scount); /* sort pages */ verb_printf(efp,"Sorting pages."); scount=0; pagesort(ind,lines); verb_printf(efp,"...done(%d comparisons).\n",scount); /* get last page */ if ((fpage>1)&&(idxcount-fsti>0)) cc=lastpage(idxfile[0]); switch (fpage) { case 2: startpagenum=cc+1; break; case 3: if ((cc+1)%2==0) startpagenum=cc+2; else startpagenum=cc+1; break; case 4: if ((cc+1)%2==1) startpagenum=cc+2; else startpagenum=cc+1; break; default: break; } /* write indfile */ verb_printf(efp,"Making index file."); indwrite(indfile,ind,startpagenum); verb_printf(efp,"...done.\n"); if (idxcount-fsti==0) indfile=xstrdup("stdout"); verb_printf(efp,"%d warnings, written in %s.\n",warn,logfile); verb_printf(efp,"Output written in %s.\n",indfile); if (efp!=stderr) fclose(efp); return 0; }
MODULE_STATIC int mod_config(char *config, int i) { char *p = config; WRLOCK_LANG_CONFIG ; while( *p && IS_SPACE(*p) ) p++; if ( !strncasecmp(p, "CharsetAgent", 12) ) { char *ptr, *agent, *t; struct charset *cs = NULL; p+=12; t = p; while( (agent = (char*)strtok_r(t, " ", &ptr)) ) { /* t is not NULL only on first item which must be charset name. */ /* there was when we add charset name as agentname on second string */ /* Fixed by Peter S. Voronov */ if ( t && !cs && !(cs = lookup_charset_by_name(charsets, agent))) { cs = add_new_charset(&charsets, agent); if ( !cs ) { verb_printf("Can't create charset\n"); goto done; } t = NULL ; continue; } if ( cs && !t) add_to_string_list(&cs->CharsetAgent, agent); t = NULL ; } if ( cs ) { struct string_list *list = cs->CharsetAgent; while(list) { verb_printf("Agent: %s\n", list->string); list = list->next; } } } else if ( !strncasecmp(p, "default_charset", 15) ) { p += 15; while (*p && IS_SPACE(*p) ) p++; strncpy(default_charset, p, sizeof(default_charset)-1); } else if ( !strncasecmp(p, "CharsetRecodeTable", 18) ) { char charset[80], path[MAXPATHLEN]; struct charset *cs; FILE *Tf; if ( sscanf(p+18, " %80s %128s", (char*)&charset, (char*)&path) == 2 ) { verb_printf("<<recodetable for %s: %s>>\n", charset, path); if ( !(cs=lookup_charset_by_name(charsets, charset)) ) { cs = add_new_charset(&charsets, charset); if ( !cs ) { verb_printf("Can't create charset\n"); goto done; } } /* load table */ if ( cs->Table ) xfree(cs->Table); cs->Table = malloc(128); if ( cs->Table ) { int i; for(i=0;i<128;i++) cs->Table[i] = i+128 ; } Tf = fopen(path, "r"); if ( Tf ) { int f, t; while( !feof(Tf) ) { char buf[80]; buf[0] = 0; fgets(buf, sizeof(buf), Tf); if ( sscanf(buf, "%x%x", &f, &t) == 2 ) { if ( f >= 128 ) cs->Table[((unsigned)f & 0xff)-128] = (unsigned) t; } } fclose(Tf); } else verb_printf("Can't open %m: \n"); } } done: UNLOCK_LANG_CONFIG ; return(MOD_CODE_OK); }
// read parameters from the battor's eeprom int param_read_eeprom(eeprom_params* params) { uint8_t tries = 0; uint8_t magic[4] = {0x31, 0x10, 0x31, 0x10}; uint8_t type; while (tries++ < CONTROL_ATTEMPTS) { memset(params, 0, sizeof(eeprom_params)); control(CONTROL_TYPE_READ_EEPROM, sizeof(eeprom_params), 0, 0); usleep(CONTROL_SLEEP_US); // since EEPROM is sent in ACK, wait for it uart_rx_bytes(&type, params, sizeof(eeprom_params)); if (memcmp(magic, params->magic, sizeof(magic)) == 0) { verb_printf("param_read_eeprom:%s\n", ""); verb_printf("\tmagic: %0X%0X%0X%0X\n", params->magic[0], params->magic[1], params->magic[2], params->magic[3]); verb_printf("\tversion: %d\n", params->version); verb_printf("\tserialno: %s\n", params->serialno); verb_printf("\ttimestamp: %d\n", params->timestamp); verb_printf("\tR1: %f\n", params->R1); verb_printf("\tR2: %f\n", params->R2); verb_printf("\tR3: %f\n", params->R3); verb_printf("\tgainL: %f\n", params->gainL); verb_printf("\tgainL_R1corr: %f\n", params->gainL_R1corr); verb_printf("\tgainL_U1off: %f\n", params->gainL_U1off); verb_printf("\tgainL_amppot: %d\n", params->gainL_amppot); verb_printf("\tgainH: %f\n", params->gainH); verb_printf("\tgainH_R1corr: %f\n", params->gainH_R1corr); verb_printf("\tgainH_U1off: %f\n", params->gainH_U1off); verb_printf("\tgainH_amppot: %d\n", params->gainH_amppot); verb_printf("\tsd_sr: %d\n", params->sd_sr); verb_printf("\tsd_tdiv: %d\n", params->sd_tdiv); verb_printf("\tsd_tovf: %d\n", params->sd_tovf); verb_printf("\tsd_filpot: %d\n", params->sd_filpot); verb_printf("\tuart_sr: %d\n", params->uart_sr); verb_printf("\tuart_tdiv: %d\n", params->uart_tdiv); verb_printf("\tuart_tovf: %d\n", params->uart_tovf); verb_printf("\tuart_filpot: %d\n", params->uart_filpot); // TODO check the EEPROM CRC break; } } if (tries >= CONTROL_ATTEMPTS) return -1; else return 0; }