//funzione che ritorna il puntatore all'ennesima parola della stringa s char * parola( char* s, int n ){ s=findchar(s); for(; n>0 ; n--){ s=findchar(findspace(s)); } return s; }
int main(void) { char string[LIMIT]; char *chloc; char ch; // test findchar() printf("Enter a string to search: "); fgets(string, LIMIT, stdin); while (string[0] != '\n') { printf("Enter a character to search for: "); ch = getchar(); // discard rest of line if any if (ch != '\n') while (getchar() != '\n') continue; chloc = findchar(string, ch); if (chloc == NULL) printf("Character %c not found in %s", ch, string); else printf("Character %c found at index %lu in %s", ch, chloc - string, string); // get new input printf("Enter a string to search (empty line to quit): "); fgets(string, LIMIT, stdin); } puts("Bye"); return 0; }
replace_single_character_in_place(PyStringObject *self, char from_c, char to_c, Py_ssize_t maxcount) { char *self_s, *result_s, *start, *end, *next; Py_ssize_t self_len; PyStringObject *result; /* The result string will be the same size */ self_s = PyString_AS_STRING(self); self_len = PyString_GET_SIZE(self); next = findchar(self_s, self_len, from_c); if (next == NULL) { /* No matches; return the original string */ return return_self(self); } /* Need to make a new string */ result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len); if (result == NULL) return NULL; result_s = PyString_AS_STRING(result); Py_MEMCPY(result_s, self_s, self_len); /* change everything in-place, starting with this one */ start = result_s + (next-self_s); *start = to_c; start++; end = result_s + self_len; while (--maxcount > 0) { next = findchar(start, end-start, from_c); if (next == NULL) break; *next = to_c; start = next+1; } return result; }
//funzione che conta le parole da cui è formata la stirnga int numero(char *s){ int i=0,n=0; char* g=s; for(i;s[i]!='\0';i++){ g=parola(s,n); int l=strlen(estraiparola(g)); i=(findchar(g+l)-s)-1; n++; } return n++; }
int main(int argc, char *argv[]) { char test[100]; unsigned int task=0; File pp[2]; int n; while(1) { if(!task) { printf("# >:"); n=readLine(test,100); if(n>0) { //printf("readLine: %s\n",test); if(strcmp(test,"exit")==0) { syssleep(100); return 0; } task=forkExec(test,pp); if(task==0) printf("FILE NOT FOUND\n"); } } if(task) { n=readFile(pp[0],test,100); if(n>0) { test[n]=0; printf(test); } if(n==-1) { task=0; closeFile(pp[1]); } n=get(test,100); if(n>0) { if(findchar(test,3,0)>=0) kill(task); writeFile(pp[1],test,n); } } syssleep(100); } }
countchar(const char *target, Py_ssize_t target_len, char c, Py_ssize_t maxcount) { Py_ssize_t count=0; const char *start=target; const char *end=target+target_len; while ( (start=findchar(start, end-start, c)) != NULL ) { count++; if (count >= maxcount) break; start += 1; } return count; }
int gettoken ( /* b=pos (0-...) to search ln; assumes b points to 1st */ char *ln, /* char of token (no error chking except EOL) */ int b /* ln=search $tring */ ) { /* Returns last char. pos of token (offset from ln) */ int i; /* or ERROR (-1) if b is out of range */ register char *lnptr; lnptr = &ln[b]; if (b >= strlen (ln)) /* prevent starting at end of line */ return ERROR; /* b is outside ln range */ if (i = findchar (lnptr, ' ')) /* token terminated w/space */ return i - 2 + b; return (strlen (ln) - 1); /* token terminated by NULL */ }
void wordSearchII_helper2(vector<vector<char> > &board, unordered_set<string>&hash_set, string &subset, vector<string>&result, vector<vector<int>>&isVisited, int x, int y, int max_wordLen, int index, vector<string> &words) { if ( index >= max_wordLen || 0 == findchar(words, index, board[x][y])) { return; } subset.push_back(board[x][y]); isVisited[x][y] = 1; if ( hash_set.find(subset) != hash_set.end()) { hash_set.erase(subset); result.push_back(subset); } int n = board.size(); int m = board[0].size(); if ( x+1 < n && isVisited[x+1][y] == 0) { wordSearchII_helper2(board, hash_set, subset, result, isVisited, x+1, y, max_wordLen, index+1, words); } if ( x-1 >= 0 && isVisited[x-1][y] == 0) { wordSearchII_helper2(board, hash_set, subset, result, isVisited, x-1, y, max_wordLen, index+1, words); } if ( y-1 >= 0 && isVisited[x][y-1] == 0) { wordSearchII_helper2(board, hash_set, subset, result, isVisited, x, y-1, max_wordLen, index+1, words); } if ( y+1 < m && isVisited[x][y+1] == 0) { wordSearchII_helper2(board, hash_set, subset, result, isVisited, x, y+1, max_wordLen, index+1, words); } subset.pop_back(); isVisited[x][y] = 0; }
replace_delete_single_character(PyStringObject *self, char from_c, Py_ssize_t maxcount) { char *self_s, *result_s; char *start, *next, *end; Py_ssize_t self_len, result_len; Py_ssize_t count; PyStringObject *result; self_len = PyString_GET_SIZE(self); self_s = PyString_AS_STRING(self); count = countchar(self_s, self_len, from_c, maxcount); if (count == 0) { return return_self(self); } result_len = self_len - count; /* from_len == 1 */ assert(result_len>=0); if ( (result = (PyStringObject *) PyString_FromStringAndSize(NULL, result_len)) == NULL) return NULL; result_s = PyString_AS_STRING(result); start = self_s; end = self_s + self_len; while (count-- > 0) { next = findchar(start, end-start, from_c); if (next == NULL) break; Py_MEMCPY(result_s, start, next-start); result_s += (next-start); start = next+1; } Py_MEMCPY(result_s, start, end-start); return result; }
void echoCommand(xQueueHandle *outputQueue, char *line) { char str[81] = "\n\r\3"; int i = findchar(line, ' '); // Incase space after "echo" isnt found or there are no text if (i == -1 || line[i+1] == '\0') { if(xQueueSendToBack(*outputQueue, (void *) str, (portTickType) 100) != pdPASS) { sciDebug("ERROR %s:%d\n\r", __FUNCTION__, __LINE__); } } else { sprintf(str, "%s\n\r\3", &line[i+1]); if(xQueueSendToBack(*outputQueue, (void *) str, (portTickType) 100) != pdPASS) { sciDebug("ERROR %s:%d\n\r", __FUNCTION__, __LINE__); } } }
NSIS_ENTRYPOINT_GUINOCRT EXTERN_C void NSISWinMainNOCRT() { int ret = 0; const TCHAR *m_Err = _LANG_ERRORWRITINGTEMP; int cl_flags = 0; TCHAR *realcmds; TCHAR seekchar=_T(' '); TCHAR *cmdline; InitCommonControls(); SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); #if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT) { extern HRESULT g_hres; g_hres=OleInitialize(NULL); } #endif // load shfolder.dll before any script code is executed to avoid // weird situations where SetOutPath or even the extraction of // shfolder.dll will cause unexpected behavior. // // this also prevents the following: // // SetOutPath "C:\Program Files\NSIS" # maybe read from reg // File shfolder.dll // Delete $PROGRAMFILES\shfolder.dll # can't be deleted, as the // # new shfolder.dll is used // # to find its own path. g_SHGetFolderPath = myGetProcAddress(MGA_SHGetFolderPath); { // workaround for bug #1008632 // http://sourceforge.net/tracker/index.php?func=detail&aid=1008632&group_id=22049&atid=373085 // // without this, SHGetSpecialFolderLocation doesn't always recognize // some special folders, like the desktop folder for all users, on // Windows 9x. unlike SHGetSpecialFolderPath, which is not available // on all versions of Windows, SHGetSpecialFolderLocation doesn't try // too hard to make sure the caller gets what he asked for. so we give // it a little push in the right direction by doing part of the work // for it. // // part of what SHGetFileInfo does, is to convert a path into an idl. // to do this conversion, it first needs to initialize the list of // special idls, which are exactly the idls we use to get the paths // of special folders (CSIDL_*). SHFILEINFO shfi; SHGetFileInfo(_T(""), 0, &shfi, sizeof(SHFILEINFO), 0); } mystrcpy(g_caption,_LANG_GENERIC_ERROR); mystrcpy(state_command_line, GetCommandLine()); #ifdef NSIS_CONFIG_VISIBLE_SUPPORT g_hInstance = GetModuleHandle(NULL); #endif//NSIS_CONFIG_VISIBLE_SUPPORT cmdline = state_command_line; if (*cmdline == _T('\"')) seekchar = *cmdline++; cmdline=findchar(cmdline, seekchar); cmdline=CharNext(cmdline); realcmds=cmdline; while (*cmdline) { // skip over any spaces while (*cmdline == _T(' ')) cmdline++; // get char we should look for to get the next parm seekchar = _T(' '); if (cmdline[0] == _T('\"')) { cmdline++; seekchar = _T('\"'); } // is it a switch? if (cmdline[0] == _T('/')) { cmdline++; #define END_OF_ARG(c) (c == _T(' ') || c == _T('\0')) #if defined(NSIS_CONFIG_VISIBLE_SUPPORT) && defined(NSIS_CONFIG_SILENT_SUPPORT) if (cmdline[0] == _T('S') && END_OF_ARG(cmdline[1])) cl_flags |= FH_FLAGS_SILENT; #endif//NSIS_CONFIG_SILENT_SUPPORT && NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_CRC_SUPPORT if (CMP4CHAR(cmdline, _T("NCRC")) && END_OF_ARG(cmdline[4])) cl_flags |= FH_FLAGS_NO_CRC; #endif//NSIS_CONFIG_CRC_SUPPORT if (CMP4CHAR(cmdline-2, _T(" /D="))) { *(cmdline-2)=_T('\0'); // keep this from being passed to uninstaller if necessary mystrcpy(state_install_directory,cmdline+2); break; // /D= must always be last } } // skip over our parm cmdline = findchar(cmdline, seekchar); // skip the quote if (*cmdline == _T('\"')) cmdline++; } GetTempPath(NSIS_MAX_STRLEN, state_temp_dir); if (!ValidateTempDir()) { GetWindowsDirectory(state_temp_dir, NSIS_MAX_STRLEN - 5); // leave space for \Temp mystrcat(state_temp_dir, _T("\\Temp")); if (!ValidateTempDir()) { // Bug #2909242: // When running at <= Low IL we cannot write to %Temp% but we can try the temp folder used by IE. // There does not seem to be a API to get the low temp dir directly, so we build the path on our own GetTempPath(NSIS_MAX_STRLEN - 4, state_temp_dir); // leave space for \Low mystrcat(state_temp_dir, _T("Low")); // If we don't call SetEnvironmentVariable // child processes will use %temp% and not %temp%\Low // and some apps probably can't handle a read only %temp% // Do it before ValidateTempDir() because it appends a backslash. // TODO: Should this be moved to ValidateTempDir() so it also updates for %windir%\Temp? SetEnvironmentVariable(_T("TEMP"), state_temp_dir); SetEnvironmentVariable(_T("TMP"), state_temp_dir); if (!ValidateTempDir()) { goto end; } } } DeleteFile(state_language); m_Err = loadHeaders(cl_flags); if (m_Err) goto end; #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT if (g_is_uninstaller) { TCHAR *p = findchar(state_command_line, 0); // state_command_line has state_install_directory right after it in memory, so reading // a bit over state_command_line won't do any harm while (p >= state_command_line && !CMP4CHAR(p, _T(" _?="))) p--; m_Err = _LANG_UNINSTINITERROR; if (p >= state_command_line) { *p=0; // terminate before "_?=" p+=4; // skip over " _?=" if (is_valid_instpath(p)) { mystrcpy(state_install_directory, p); mystrcpy(state_output_directory, p); m_Err = 0; } else { goto end; } } else { int x; mystrcat(state_temp_dir,_T("~nsu.tmp")); // check if already running from uninstaller temp dir // this prevents recursive uninstaller calls if (!lstrcmpi(state_temp_dir,state_exe_directory)) goto end; CreateDirectory(state_temp_dir,NULL); SetCurrentDirectory(state_temp_dir); if (!state_install_directory[0]) mystrcpy(state_install_directory,state_exe_directory); mystrcpy(g_usrvars[0], realcmds); SET2CHAR(g_usrvars[1], _T("A\0")); for (x = 0; x < 26; x ++) { static TCHAR buf2[NSIS_MAX_STRLEN]; GetNSISString(buf2,g_header->str_uninstchild); // $TEMP\$1u_.exe DeleteFile(buf2); // clean up after all the other ones if they are there if (m_Err) // not done yet { // copy file if (CopyFile(state_exe_path,buf2,TRUE)) { HANDLE hProc; #ifdef NSIS_SUPPORT_MOVEONREBOOT MoveFileOnReboot(buf2,NULL); #endif GetNSISString(buf2,g_header->str_uninstcmd); // '"$TEMP\$1u_.exe" $0 _?=$INSTDIR\' hProc=myCreateProcess(buf2); if (hProc) { CloseHandle(hProc); // success m_Err = 0; } } } g_usrvars[1][0]++; } #ifdef NSIS_SUPPORT_MOVEONREBOOT MoveFileOnReboot(state_temp_dir,NULL); #endif goto end; } } #endif//NSIS_CONFIG_UNINSTALL_SUPPORT g_exec_flags.errlvl = -1; ret = ui_doinstall(); #ifdef NSIS_CONFIG_LOG #if !defined(NSIS_CONFIG_LOG_ODS) && !defined(NSIS_CONFIG_LOG_STDOUT) log_write(1); #endif//!NSIS_CONFIG_LOG_ODS && !NSIS_CONFIG_LOG_STDOUT #endif//NSIS_CONFIG_LOG end: CleanUp(); #if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT) OleUninitialize(); #endif if (m_Err) { my_MessageBox(m_Err, MB_OK | MB_ICONSTOP | (IDOK << 21)); ExitProcess(2); } #ifdef NSIS_SUPPORT_REBOOT if (g_exec_flags.reboot_called) { BOOL (WINAPI *OPT)(HANDLE, DWORD,PHANDLE); BOOL (WINAPI *LPV)(LPCTSTR,LPCTSTR,PLUID); BOOL (WINAPI *ATP)(HANDLE,BOOL,PTOKEN_PRIVILEGES,DWORD,PTOKEN_PRIVILEGES,PDWORD); OPT=myGetProcAddress(MGA_OpenProcessToken); LPV=myGetProcAddress(MGA_LookupPrivilegeValue); ATP=myGetProcAddress(MGA_AdjustTokenPrivileges); if (OPT && LPV && ATP) { HANDLE hToken; TOKEN_PRIVILEGES tkp; if (OPT(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { LPV(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; ATP(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); } } if (!ExitWindowsEx(EWX_REBOOT,0)) ExecuteCallbackFunction(CB_ONREBOOTFAILED); } #endif//NSIS_SUPPORT_REBOOT if (g_exec_flags.errlvl != -1) ret = g_exec_flags.errlvl; ExitProcess(ret); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow) { int ret = 0; const char *m_Err = _LANG_ERRORWRITINGTEMP; int cl_flags = 0; char *realcmds; char seekchar=' '; char *cmdline; InitCommonControls(); #if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT) { extern HRESULT g_hres; g_hres=OleInitialize(NULL); } #endif mystrcpy(g_caption,_LANG_GENERIC_ERROR); GetTempPath(NSIS_MAX_STRLEN, state_temp_dir); if (!ValidateTempDir()) { GetWindowsDirectory(state_temp_dir, NSIS_MAX_STRLEN - 5); // leave space for \Temp lstrcat(state_temp_dir, "\\Temp"); if (!ValidateTempDir()) { goto end; } } DeleteFile(state_command_line); lstrcpyn(state_command_line, GetCommandLine(), NSIS_MAX_STRLEN); #ifdef NSIS_CONFIG_VISIBLE_SUPPORT g_hInstance = GetModuleHandle(NULL); #endif//NSIS_CONFIG_VISIBLE_SUPPORT cmdline = state_command_line; if (*cmdline == '\"') seekchar = *cmdline++; cmdline=findchar(cmdline, seekchar); cmdline=CharNext(cmdline); realcmds=cmdline; while (*cmdline) { // skip over any spaces while (*cmdline == ' ') cmdline++; // get char we should look for to get the next parm seekchar = ' '; if (cmdline[0] == '\"') { cmdline++; seekchar = '\"'; } // is it a switch? if (cmdline[0] == '/') { cmdline++; // this only works with spaces because they have just one bit on #define END_OF_ARG(c) (((c)|' ')==' ') #if defined(NSIS_CONFIG_VISIBLE_SUPPORT) && defined(NSIS_CONFIG_SILENT_SUPPORT) if (cmdline[0] == 'S' && END_OF_ARG(cmdline[1])) cl_flags |= FH_FLAGS_SILENT; #endif//NSIS_CONFIG_SILENT_SUPPORT && NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_CRC_SUPPORT if (*(LPDWORD)cmdline == CHAR4_TO_DWORD('N','C','R','C') && END_OF_ARG(cmdline[4])) cl_flags |= FH_FLAGS_NO_CRC; #endif//NSIS_CONFIG_CRC_SUPPORT if (*(LPDWORD)(cmdline-2) == CHAR4_TO_DWORD(' ', '/', 'D','=')) { cmdline[-2]=0; // keep this from being passed to uninstaller if necessary mystrcpy(state_install_directory,cmdline+2); break; // /D= must always be last } } // skip over our parm cmdline = findchar(cmdline, seekchar); // skip the quote if (*cmdline == '\"') cmdline++; } m_Err = loadHeaders(cl_flags); if (m_Err) goto end; #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT if (g_is_uninstaller) { char *p = findchar(realcmds, 0); // state_command_line has state_install_directory right after it in memory, so reading // a bit over state_command_line won't do any harm while (p >= realcmds && *(LPDWORD)p != CHAR4_TO_DWORD(' ', '_', '?', '=')) p--; m_Err = _LANG_UNINSTINITERROR; if (p >= realcmds) { *p=0; // terminate before "_?=" p+=4; // skip over " _?=" if (is_valid_instpath(p)) { mystrcpy(state_install_directory, p); mystrcpy(state_output_directory, p); m_Err = 0; } else { goto end; } } else { int x; for (x = 0; x < 26; x ++) { static char s[]="A~NSISu_.exe"; static char buf2[NSIS_MAX_STRLEN*2]; static char ibuf[NSIS_MAX_STRLEN]; buf2[0]='\"'; mystrcpy(buf2+1,state_temp_dir); lstrcat(buf2,s); DeleteFile(buf2+1); // clean up after all the other ones if they are there if (m_Err) // not done yet { // get current name int l=GetModuleFileName(g_hInstance,ibuf,sizeof(ibuf)); // check if it is ?~NSISu_.exe - if so, f**k it if (!lstrcmpi(ibuf+l-(sizeof(s)-2),s+1)) break; // copy file if (CopyFile(ibuf,buf2+1,FALSE)) { HANDLE hProc; #ifdef NSIS_SUPPORT_MOVEONREBOOT MoveFileOnReboot(buf2+1,NULL); #endif if (state_install_directory[0]) mystrcpy(ibuf,state_install_directory); else trimslashtoend(ibuf); lstrcat(buf2,"\" "); lstrcat(buf2,realcmds); lstrcat(buf2," _?="); lstrcat(buf2,ibuf); // add a trailing backslash to make sure is_valid_instpath will not fail when it shouldn't addtrailingslash(buf2); hProc=myCreateProcess(buf2,state_temp_dir); if (hProc) { CloseHandle(hProc); // success m_Err = 0; } } } s[0]++; } goto end; } } #endif//NSIS_CONFIG_UNINSTALL_SUPPORT g_exec_flags.errlvl = -1; ret = ui_doinstall(); #ifdef NSIS_CONFIG_LOG #ifndef NSIS_CONFIG_LOG_ODS log_write(1); #endif//!NSIS_CONFIG_LOG_ODS #endif//NSIS_CONFIG_LOG end: CleanUp(); #if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT) OleUninitialize(); #endif if (m_Err) { my_MessageBox(m_Err, MB_OK | MB_ICONSTOP | (IDOK << 20)); ExitProcess(2); return 0; } #ifdef NSIS_SUPPORT_REBOOT if (g_exec_flags.reboot_called) { HANDLE h=GetModuleHandle("ADVAPI32.dll"); if (h) { BOOL (WINAPI *OPT)(HANDLE, DWORD,PHANDLE); BOOL (WINAPI *LPV)(LPCTSTR,LPCTSTR,PLUID); BOOL (WINAPI *ATP)(HANDLE,BOOL,PTOKEN_PRIVILEGES,DWORD,PTOKEN_PRIVILEGES,PDWORD); OPT=(void*)GetProcAddress(h,"OpenProcessToken"); LPV=(void*)GetProcAddress(h,"LookupPrivilegeValueA"); ATP=(void*)GetProcAddress(h,"AdjustTokenPrivileges"); if (OPT && LPV && ATP) { HANDLE hToken; TOKEN_PRIVILEGES tkp; if (OPT(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { LPV(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; ATP(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); } } } if (!ExitWindowsEx(EWX_REBOOT,0)) ExecuteCallbackFunction(CB_ONREBOOTFAILED); } #endif//NSIS_SUPPORT_REBOOT if (g_exec_flags.errlvl != -1) ret = g_exec_flags.errlvl; ExitProcess(ret); return 0; }
line *new_line( char *str, char lastcmd, int linenum ) { line *l = (line *)malloc( sizeof(line) ); int colon; int rparen, lparen; int i; char *contemp = NULL; // temp variable for condex string colon = findchar( str, ':' ); // get the position of the colon l->next = NULL; l->linenum = linenum; // is it a blank string? if( !strcmp(str, "") ) { l->cmd = lastcmd; l->args = NULL; l->cond = NULL; return l; } if( colon == -1 ) { // if there is no colon, it's an error err( NO_COLON, str ); } /* Notes for the 3/3/00 rewrite * There are 3 different possiblities for what will be the first character * in the line: * * 1) A letter signifing the command name (this includes 'Y' and 'N') * 2) A colon, meaning that we should use the last command for this one, too * 3) A left parentheses, like above, but with a conditional expression * */ if( colon != strlen(str)-1 ) { l->args = new_string_from( str, colon+1, strlen(str)-colon+1 ); ltrim( l->args ); } else { l->args = new_string( "" ); } /* * Here, we'll handle the second case first, because it is the easiest. * The command is the same as the last command, and everything after the * first character constitutes the arguments. */ if( str[0] == ':' ) { l->cmd = lastcmd; l->cond = NULL; return l; } /* * Now the third case. Like the second case, everything after the colon * forms the arguments. But we have to find the right parentheses in order * to create a conditional expression. The command is the same as the * previous one. */ if( str[0] == '(' ) { l->cmd = lastcmd; rparen = findchar( str, ')' ); if( rparen == -1 ) { // If there is no right parentheses, we signal an error err( NO_RPAREN, str ); } // otherwise, create a temporary string, and make a new condex // contemp = new_string_from( str, 1, rparen-1 ); contemp = new_string_from( str, 1, rparen-1 ); l->cond = new_condex( contemp ); free( contemp ); return l; } /* * Finally, the first case. This itself has four possibilities: * * 1) There is no conditional expression * 2) There is a conditional expression in parentheses * 3) There is a 'Y' as the conditional * 4) There is an 'N' as the conditional */ l->cmd = str[0]; // l->args = new_string_from( str, colon+1, strlen(str)-colon+1 ); lparen = findchar( str, '(' ); if( (lparen == -1)|| (lparen > colon) ) { // Now, we can see if there is a Y or N somehwere.. for( i=1; i<colon; i++ ) { if( toupper(str[i]) == 'Y' ) { l->cond = new_condex( "Y" ); return l; } else if( toupper(str[i]) == 'N' ) { l->cond = new_condex( "N" ); return l; } } // If we didn't find Y or N, there is no condex, so just return l->cond = NULL; return l; } // Now we have a conditional expression, so create a new condex and return rparen = findchar( str, ')' ); if( rparen == -1 ) { err( NO_RPAREN, str ); } // contemp = new_string_from( str, lparen+1, rparen-1 ); contemp = new_string_from( str, lparen+1, rparen-2 ); l->cond = new_condex( contemp ); free( contemp ); return l; }
unsigned char *SaraUeRtn( unsigned char *TempIndx ) { if ( isttnl( *( TempIndx + 1 ) ) ) { /* Check vowel routine here */ if ( ( TempIndx + 2 ) <= RightMargin ) { return( TempIndx + 2 ); } } else { switch ( *( TempIndx - 1 ) ) { case RoreReo: if ( findchar( *( TempIndx + 1 ), ":換" ) ) { if ( !istrvwl( *( TempIndx + 2 ) ) && TempIndx + 2 <= RightMargin ) { return( TempIndx + 1 ); } } else { return( TempIndx ); } break; case HorNokHook: switch ( *( TempIndx + 1 ) ) { case KoreGai: case DoreDek: case MoreMar: return( TempIndx - 2 ); default: return( TempIndx ); } case HorHeeb: if ( *( TempIndx + 1 ) == NgorNgoo ) { return( TempIndx - 2 ); } else { return( TempIndx ); } case OrAng: if ( findchar( *( TempIndx + 1 ), ":換" ) ) { if ( TempIndx + 1 <= RightMargin ) { return( TempIndx + 1 ); } else { return( TempIndx - 2 ); } } else { return( TempIndx ); } default: if ( ( TempIndx + 1 ) <= RightMargin ) { return( TempIndx + 1 ); } } } /* Check to cut in front */ /* if ( !findchar( *( TempIndx - 1), "港壇" ) ) { return( TempIndx - 2 ); } else { return( FAIL ); } */ /* corrected by Subun */ /* modified by Subun : date 24 May, 1988 */ switch ( *( TempIndx - 1 ) ) { case NoreNoo: if ( !findchar( *( TempIndx - 2 ), "ぜ僕" ) ) { return( TempIndx - 2 ); } break; case MoreMar: if ( *( TempIndx - 2 ) != HorHeeb ) { return( TempIndx - 2 ); } else { return( TempIndx - 3 ); } /* cut before HorHeep */ case RoreReo: if ( !findchar( *( TempIndx - 2 ), "さ讃" ) ) { return( TempIndx - 2 ); } break; case LoreLing: if ( !findchar( *( TempIndx - 2 ), ",脅瞥" ) ) { return( TempIndx - 2 ); } break; default: return( TempIndx - 2 ); } return( FAIL ); }
unsigned char *SaraRWithTonal( register unsigned char *TempIndx ) { register unsigned char *TempIndxm2 = TempIndx - 2; /* for return point before a - 1 */ register unsigned char *TempIndxm4 = TempIndx - 4; /* unsigned char chbufm1 = *( TempIndx - 1 ); */ unsigned char chbufp1 = *( TempIndx + 1 ); /* _èÒ _éÒ _ëÒ Rtn */ switch ( *( TempIndx - 1 ) ) { case MaiEk: /* _èÒ */ switch ( *( TempIndx - 2 ) ) { case HorNokHook: case KoreRakung: return( TempIndx ); case KorKai: case NgorNgoo: if ( !( findchar( chbufp1, "§¹ÁÂÇ" ) ) ) { /* §èÒ§ ¢èÒ§*/ return ( TempIndx ); } break; case PoreParn: case ToreTao: case ThorToong: if ( findchar( chbufp1, "§¹Â" ) ) { /* µèÒ ¶èÒ ¾èÒ */ /* cut after a+1 or before a-2 */ return( ( TempIndx + 1 ) <= RightMargin ) ? TempIndx + 1 : TempIndx - 3; } break; case KoreKwai: case ChorChing: if ( chbufp1 != NgorNgoo && chbufp1 != YoreYak ) { return( TempIndx ); } break; case HorHeeb: case YoreYak: if ( chbufp1 != NgorNgoo && chbufp1 != NoreNoo && chbufp1 != MoreMar ) { /* ËèÒ§ */ return( TempIndx ); } break; case KoreGai: case ForFa: if ( chbufp1 != YoreYak ) { /* ½èÒ */ return( TempIndx ); } break; case JoreJarn: case BoreBaimai: if ( chbufp1 != NgorNgoo && chbufp1 != YoreYak && chbufp1 != WoreWaan ) { /* ºèÒÇ */ return ( TempIndx ); } break; case ShoreChang: if ( chbufp1 != NgorNgoo ) { return( TempIndx ); } break; case SoreSoe: if ( chbufp1 != NoreNoo ) { /* «èÒ¹ */ return( TempIndx ); } break; case DoreDek: case PorPeng: case OrAng: if ( chbufp1 != NgorNgoo && chbufp1 != NoreNoo && chbufp1 != WoreWaan ) { /* ÍèÒÇ */ return( TempIndx ); } break; case ToreTaharn: if ( chbufp1 != NoreNoo && chbufp1 != MoreMar ) { /* ·èÒÁ ·èÒ¹ */ return ( TempIndx ); } break; case NoreNoo: case MoreMar: if ( chbufp1 != NoreNoo && chbufp1 != YoreYak ) { /* ¹èÒ¹ ÁèÒ */ return( TempIndx ); } break; case PorePla: case WoreWaan: if ( !( findchar( chbufp1, "§¹ÂÇ" ) ) ) { /* »èÒÇ ÇèÒ¹*/ return( TempIndx ); } break; case RoreReo: if ( !( findchar( chbufp1, "§¹ÁÂ" ) ) ) { /* ÃèÒ¹ */ return( TempIndx ); } break; case LoreLing: if ( chbufp1 != NgorNgoo && chbufp1 != MoreMar && chbufp1 != WoreWaan ) { /* ËÅèÒÇ ÅèÒÁ */ return( TempIndx ); } break; case SoreSeo: if ( chbufp1 != NgorNgoo && chbufp1 != NoreNoo && chbufp1 != YoreYak ) { /* ÊèÒ¹ */ } break; } if ( findchar( *TempIndxm2, "¢¤¦ª«´¸¿ÈËÍ" ) || istlcon( *TempIndxm2 ) ) { return( TempIndx - 3 ); /* cut before a - 2 */ } break; case MaiToe: /* _éÒ */ switch ( *( TempIndx - 2 ) ) { case YoreYing: case ThorToong: case ForeFun: case HorNokHook: return( TempIndx ); case DoreDek: case RoreReo: if ( !( findchar( chbufp1, "§¹ÁÂÇ" ) ) ) { return( TempIndx ); } break; case KoreGai: if ( !( findchar( chbufp1, "§¹ÁÇ" ) ) ) { /* ¡éÒÇ */ return ( TempIndx ); } break; case MoreMar: case LoreLing: if ( !( findchar( chbufp1, "§¹ÁÂ" ) ) ) { /* ËÁéÒ */ return( TempIndx ); } break; case KorKai: if ( !( findchar( chbufp1, "§¹¾ÁÇ" ) ) ) { return( TempIndx ); } break; case HorHeeb: if ( chbufp1 != NgorNgoo && chbufp1 != MoreMar && chbufp1 != WoreWaan ) { /* ËéÒÁ */ return( TempIndx ); } break; case KoreKwai: if ( chbufp1 != NoreNoo && chbufp1 != NgorNgoo ) { /* ¤éÒ§ */ return( TempIndx ); } break; case NgorNgoo: if ( chbufp1 != NgorNgoo && chbufp1 != WoreWaan ) { /* §éÒÇ */ return( TempIndx ); } break; case JoreJarn: if ( chbufp1 != NgorNgoo && chbufp1 != WoreWaan && chbufp1 != NoreNoo ) { /* ¨éÒ§ */ return( TempIndx ); } break; case ShoreChang: if ( chbufp1 != NgorNgoo ) { /* ªéÒ§ */ return ( TempIndx ); } break; case SoreSoe: case PorPeng: case ForFa: case YoreYak: if ( chbufp1 != YoreYak ) { /* ÂéÒ */ return( TempIndx ); } break; case ToreTao: if ( chbufp1 != YoreYak && chbufp1 != NoreNoo ) { /* µéÒ¹ */ return( TempIndx ); } break; case ToreTaharn: if ( chbufp1 != YoreYak && chbufp1 != NgorNgoo && chbufp1 != WoreWaan ) { /* ·éÒÇ */ return( TempIndx ); } break; case NoreNoo: if ( chbufp1 != WoreWaan ) { /* ¹éÒÇ */ return( TempIndx ); } break; case BoreBaimai: case PorePla: case WoreWaan: if ( chbufp1 != YoreYak && chbufp1 != NgorNgoo && chbufp1 != NoreNoo ) { /* ÇéÒ */ return( TempIndx ); } break; case OrAng: if ( chbufp1 != YoreYak && chbufp1 != NgorNgoo ) { /* ÍéÒ§ */ return( TempIndx ); } break; } if ( findchar( *TempIndxm2, "¢¤¦ª«´¸¿ÈËÍ" ) || istlcon( *TempIndxm2 ) ) { return( TempIndx - 3 ); /* cut before a - 2 */ } break; case MaiJattawa: /* _ëÒ */ return( TempIndx ); } if ( *( TempIndx - 3 ) == HorHeeb && findchar( *TempIndxm2, "¹ÁÂÃÅÇ" ) ) { return( TempIndxm4 ); /* cut before HorHeeb */ } return( NULL ); }
FORCE_INLINE int NSISCALL ui_doinstall(void) { header *header = g_header; static WNDCLASS wc; // richedit subclassing and bgbg creation // detect default language // more information at: // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_0xrn.asp LANGID (WINAPI *GUDUIL)(); static const char guduil[] = "GetUserDefaultUILanguage"; GUDUIL = myGetProcAddress(TEXT("KERNEL32.dll"), (char *) guduil); if (GUDUIL) { // Windows ME/2000+ myitoa(state_language, GUDUIL()); } else { *(DWORD*)state_language = CHAR4_TO_DWORD('0', 'x', 0, 0); { // Windows 9x static const TCHAR reg_9x_locale[] = TEXT("Control Panel\\Desktop\\ResourceLocale"); myRegGetStr(HKEY_CURRENT_USER, reg_9x_locale, NULL, g_tmp); } if (!g_tmp[0]) { // Windows NT // This key exists on 9x as well, so it's only read if ResourceLocale wasn't found static const TCHAR reg_nt_locale_key[] = TEXT(".DEFAULT\\Control Panel\\International"); static const TCHAR reg_nt_locale_val[] = TEXT("Locale"); myRegGetStr(HKEY_USERS, reg_nt_locale_key, reg_nt_locale_val, g_tmp); } mystrcat(state_language, g_tmp); } // set default language set_language(); // initialize auto close flag g_exec_flags.autoclose=g_flags&CH_FLAGS_AUTO_CLOSE; // read install directory from registry if (!is_valid_instpath(state_install_directory)) { if (header->install_reg_key_ptr) { myRegGetStr( (HKEY)header->install_reg_rootkey, GetNSISStringNP(header->install_reg_key_ptr), GetNSISStringNP(header->install_reg_value_ptr), ps_tmpbuf ); if (ps_tmpbuf[0]) { TCHAR *p=ps_tmpbuf; TCHAR *e; if (p[0]==TEXT('\"')) { TCHAR *p2; p++; p2 = findchar(p, TEXT('"')); *p2 = 0; } // p is the path now, check for .exe extension e=p+mystrlen(p)-4; if (e > p) { // if filename ends in .exe, and is not a directory, remove the filename if (!lstrcmpi(e, TEXT(".exe"))) // check extension { DWORD d; d=GetFileAttributes(p); if (d == INVALID_FILE_ATTRIBUTES || !(d&FILE_ATTRIBUTE_DIRECTORY)) { // if there is no back-slash, the string will become empty, but that's ok because // it would make an invalid instdir anyway trimslashtoend(p); } } } mystrcpy(state_install_directory,addtrailingslash(p)); } } } if (!is_valid_instpath(state_install_directory)) { GetNSISString(state_install_directory,header->install_directory_ptr); } #ifdef NSIS_CONFIG_LOG if (g_flags & CH_FLAGS_SILENT_LOG && !g_is_uninstaller) { #if !defined(NSIS_CONFIG_LOG_ODS) && !defined(NSIS_CONFIG_LOG_STDOUT) build_g_logfile(); #endif log_dolog=1; } #endif #ifdef NSIS_CONFIG_VISIBLE_SUPPORT g_hIcon=LoadImage(g_hInstance,MAKEINTRESOURCE(IDI_ICON2),IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_SHARED); #ifdef NSIS_SUPPORT_BGBG if (header->bg_color1 != -1) { QTCHAR cn = CHAR4_TO_DWORD(TEXT('_'), TEXT('N'), TEXT('b'), 0); RECT vp; extern LRESULT CALLBACK BG_WndProc(HWND, UINT, WPARAM, LPARAM); wc.lpfnWndProc = BG_WndProc; wc.hInstance = g_hInstance; wc.hIcon = g_hIcon; //wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.lpszClassName = (LPCTSTR)&cn; if (!RegisterClass(&wc)) return 0; SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0); m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,(LPCTSTR)&cn,0,WS_POPUP, vp.left,vp.top,vp.right-vp.left,vp.bottom-vp.top,0,NULL,g_hInstance,NULL); } #endif//NSIS_SUPPORT_BGBG #endif//NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_SUPPORT_CODECALLBACKS // Select language if (ExecuteCallbackFunction(CB_ONINIT)) return 2; set_language(); #endif #ifdef NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_SILENT_SUPPORT if (!g_exec_flags.silent) #endif//NSIS_CONFIG_SILENT_SUPPORT { #ifdef NSIS_SUPPORT_BGBG ShowWindow(m_bgwnd, SW_SHOW); #endif//NSIS_SUPPORT_BGBG #ifdef NSIS_CONFIG_LICENSEPAGE { // load richedit DLL static TCHAR str1[]=TEXT("RichEd20.dll"); #ifdef UNICODE static wchar_t str2[]=L"RichEdit20W"; #else static char str2[]="RichEdit20A"; #endif if (!LoadLibrary(str1)) { *(DTCHAR*)(str1+6) = CHAR2_TO_WORD(TEXT('3'),TEXT('2')); LoadLibrary(str1); } // make richedit20a point to RICHEDIT if (!GetClassInfo(NULL,str2,&wc)) { str2[8]=0; GetClassInfo(NULL,str2,&wc); wc.lpszClassName = str2; str2[8]=TEXT('2'); RegisterClass(&wc); } } #endif { int ret=DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_INST+dlg_offset),0,DialogProc); #if defined(NSIS_SUPPORT_CODECALLBACKS) && defined(NSIS_CONFIG_ENHANCEDUI_SUPPORT) ExecuteCallbackFunction(CB_ONGUIEND); #endif return ret; } } #endif//NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_SILENT_SUPPORT #ifdef NSIS_CONFIG_VISIBLE_SUPPORT else #endif//NSIS_CONFIG_VISIBLE_SUPPORT { if (install_thread(NULL)) { #ifdef NSIS_SUPPORT_CODECALLBACKS if (!g_quit_flag) ExecuteCallbackFunction(CB_ONINSTFAILED); #endif//NSIS_SUPPORT_CODECALLBACKS return 2; } #ifdef NSIS_SUPPORT_CODECALLBACKS ExecuteCallbackFunction(CB_ONINSTSUCCESS); #endif//NSIS_SUPPORT_CODECALLBACKS return 0; } #endif//NSIS_CONFIG_SILENT_SUPPORT }
static void jpeg2ascii(char *url, char **ascii) { int i = 0, j = 0, l = 0, x = 0, y = 0, r = 0, g = 0, b = 0; int width = 0, height = 0; int row_stride = 0, count = 0, counter = 0, offset = 0, sigma = 0, sample = 0; double yiq = 0.0, yiq_sum = 0.0, yyy = 0.0; double mean = 0.0, sample_mean = 0.0; char *result = NULL; unsigned char *jpegdata = NULL, *yiqs = NULL; struct jpeg_decompress_struct cinfo_decompress; struct jpeg_error_mgr jerr; struct curl_response response; FILE *jpegfile = NULL; JSAMPARRAY pJpegBuffer; CURL *curl; CURLcode res; response.memory = malloc(1); response.size = 0; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, get_write); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response); res = curl_easy_perform(curl); if (res != CURLE_OK) { printf("Error: %s\n", curl_easy_strerror(res)); goto cleanup; } } cinfo_decompress.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo_decompress); jpeg_mem_src(&cinfo_decompress, (unsigned char *)response.memory, response.size); jpeg_read_header(&cinfo_decompress, TRUE); jpeg_start_decompress(&cinfo_decompress); width = cinfo_decompress.output_width; height = cinfo_decompress.output_height; row_stride = width * cinfo_decompress.output_components; pJpegBuffer = (*cinfo_decompress.mem->alloc_sarray)((j_common_ptr) &cinfo_decompress, JPOOL_IMAGE, row_stride, 1); jpegdata = malloc(sizeof(char) * (width * height * 3) + 1); yiqs = malloc(sizeof(char) * (height * width + width) + 1); result = malloc(sizeof(char) * (width * height) + 1); strcpy(result, ""); count = 0; counter = 0; y = 0; while (cinfo_decompress.output_scanline < cinfo_decompress.output_height) { jpeg_read_scanlines(&cinfo_decompress, pJpegBuffer, 1); for (x = 0; x < width; x++) { r = pJpegBuffer[0][cinfo_decompress.output_components * x]; g = pJpegBuffer[0][cinfo_decompress.output_components * x + 1]; b = pJpegBuffer[0][cinfo_decompress.output_components * x + 2]; jpegdata[counter] = r; jpegdata[counter + 1] = g; jpegdata[counter + 2] = b; offset = y * width + x; yiq = ((r * 0.299) + (g * 0.587) + (b * 0.114)); yiqs[offset] = yiq; yiq_sum += yiq; count++; counter += 3; } y++; } mean = yiq_sum / count; sigma = 0; for (i = 0, l = height * width + width; i < l; i++) { if (yiqs[i] != '\0') { sigma += pow(yiqs[i] - mean, 2); } } sigma = sqrt(sigma / count); count = 0; for (y = 0; y < height - 2; y += 8) { for (x = 0; x < width - 2; x += 4) { sample = 0; sample_mean = 0.0; for (i = y; i < y + 2; i++) { for (j = x; j < x + 2; j++) { r = jpegdata[((i * width) + j) * 3]; g = jpegdata[((i * width) + j) * 3 + 1]; b = jpegdata[((i * width) + j) * 3 + 2]; yyy = yiqs[i * width + j]; if (yyy < mean) { sample |= 0b0001; } sample <<= 1; sample_mean += yyy; } } sample_mean /= 4; sample >>= 1; result[count++] = findchar(sample, sample_mean, mean, sigma); } result[count++] = '\n'; } result[count] = '\0'; *ascii = malloc(sizeof(char) * strlen(result) + 1); strcpy(*ascii, result); cleanup: if (jpegfile) { fclose(jpegfile); } if (jpegdata) { free(jpegdata); } if (yiqs) { free(yiqs); } if (result) { free(result); } }
unsigned char *HunAkadRtn( register unsigned char *TempIndx ) { register unsigned char *plus1 = TempIndx + 1; register unsigned char *minus2 = TempIndx - 2; if ( plus1 <= RightMargin ) { switch ( *( plus1 ) ) { case KoreGai: if ( findchar( *( TempIndx - 1 ), "¡§ª«´µ¶º»¿ÁÇË" ) ) { return( plus1 ); } break; case NgorNgoo: switch ( *( TempIndx - 1 ) ) { case SoreSeo: if ( *( TempIndx + 2 ) != KorKai && *( TempIndx + 2 ) != KoreRakung ) { return( plus1 ); } break; case RoreReo: if ( !nstrcmp( "¡Ãѧ´ì", minus2 ) ) { return( TempIndx - 3 ); } else { return( plus1 ); } default: return( plus1 ); } break; case DoreDek: return( plus1 ); case NoreNoo: if ( *( TempIndx + 3 ) != Karan ) { return( plus1 ); } break; case YoreYak: if ( !nstrcmp( "¹Ñ¹ì", TempIndx - 1 ) ) { return( minus2 ); } else { return( plus1 ); } case SoreSeo: if ( *( TempIndx + 4 ) != Karan ) { return( plus1 ); } break; case WoreWaan: switch ( *( TempIndx + 2 ) ) { case SaraAh: if ( TempIndx + 2 <= RightMargin ) { return( TempIndx + 2 ); } break; case RoreReo: if ( *( TempIndx + 3 ) == Karan ) { return( minus2 ); } break; default: return( plus1 ); } break; default: if ( isttnl( *( plus1 ) ) ) { if ( *( TempIndx + 4 ) == Karan ) { return( minus2 ); } else { if ( TempIndx + 2 <= RightMargin ) { return( TempIndx + 2 ); } } } } switch ( *( TempIndx - 1 ) ) { case NgorNgoo: return( plus1 ); case NoreNoo: if ( !findchar( *( plus1 ), "µ¹Â" ) ) { return( plus1 ); } break; case MoreMar: if ( !findchar( *( plus1 ), "¤¹Ç" ) ) { return( plus1 ); } break; case RoreReo: if ( !findchar( *( plus1 ), "¡µ¾È" ) ) { return( plus1 ); } break; case HorHeeb: if ( *( plus1 ) != ToreTao && *( plus1 ) != NoreNoo ) { return( plus1 ); } break; case HorNokHook: return( plus1 ); } } if ( findchar( *( TempIndx - 1 ), "¢¤¦ª«±³¶¸»¼½¾¿ÈÊÍÎ" ) ) { return( minus2 ); } else { switch ( *( TempIndx - 1 ) ) { case KoreGai: return( *minus2 == SoreSeo ? FAIL : minus2 ); case NgorNgoo: switch ( *minus2 ) { case HorHeeb: return( TempIndx - 3 ); case SoreSeo: return( FAIL ); default: return( minus2 ); } case JoreJarn: return( ( *minus2 == KorKai ) ? FAIL : minus2 ); case DoreDek: return( ( *minus2 == SoreSeo ) ? FAIL : minus2 ); case ToreTao: return( ( *minus2 == KoreGai ) ? FAIL : minus2 ); case ToreTaharn: switch ( *minus2 ) { case HorHeeb: return( TempIndx - 3 ); case WoreWaan: return( FAIL ); default: return( minus2 ); } case BoreBaimai: return( ( *minus2 == ChorChing ) ? TempIndx - 3 : minus2 ); case PoreSumpao: return( ( *minus2 == OrAng ) ? FAIL : minus2 ); case WoreWaan: return( findchar( *minus2, "¡¢¤¨©µ¶¸ÊË" ) ? FAIL : minus2 ); case HorHeeb: return( findchar( *minus2, "ÁÃÍ" ) ? FAIL : minus2 ); } } return( FAIL ); }
int READ_GRIBMAP (char *filename, Grib1_Tables *grib_tables, int *ret) { FILE *mapptr; char line[MAX_LINE_CHARS]; int dummy; int parmidx; int nxtidx, elemidx, charidx; char elems[6][MAX_LINE_CHARS]; int tablenum; /* Open parameter table file */ mapptr = fopen(filename, "r"); if (mapptr == NULL) { fprintf(stderr,"Could not open %s\n",filename); *ret=1; return 1; } /* Skip over comments at begining of gribmap file */ while (fgets(line,500,mapptr)) { if (line[0] != '#') break; } tablenum = 0; grib_tables->num_tables = 1; grib_tables->grib_table_info = (Grib1_Table_Info *)calloc(1,sizeof(Grib1_Table_Info)); if (grib_tables->grib_table_info == NULL) { fprintf(stderr,"Could not allocate space for grib_table_info\n"); *ret = 1; return 1; } grib_tables->grib_table_info[tablenum].num_entries = 0; sscanf(line,"%d:%d:%d:%d",&dummy, &(grib_tables->grib_table_info[tablenum].center), &(grib_tables->grib_table_info[tablenum].subcenter), &(grib_tables->grib_table_info[tablenum].parmtbl)); /* * Read each line of parameter table, and store information in the * structure. */ while (fgets(line,MAX_LINE_CHARS,mapptr) != NULL) { /* Split up the elements that are seperated by : */ nxtidx = 0; elemidx = 0; while ((charidx = findchar(line + nxtidx,':')) >= 0) { strncpy(elems[elemidx],line + nxtidx,charidx); elems[elemidx][charidx] = '\0'; elemidx++; nxtidx += (charidx + 1); } parmidx = atoi(elems[0]); /* * Check to see if this line specifies the next grib table. If so, * break out */ if (parmidx == -1) { grib_tables->num_tables++; tablenum++; grib_tables->grib_table_info = (Grib1_Table_Info *) realloc(grib_tables->grib_table_info, grib_tables->num_tables*sizeof(Grib1_Table_Info)); if (grib_tables->grib_table_info == NULL) { fprintf(stderr, "Could not re-allocate space for grib_table_info\n"); *ret = 1; return 1; } grib_tables->grib_table_info[tablenum].num_entries = 0; sscanf(line,"%d:%d:%d:%d",&dummy, &(grib_tables->grib_table_info[tablenum].center), &(grib_tables->grib_table_info[tablenum].subcenter), &(grib_tables->grib_table_info[tablenum].parmtbl)); continue; } /* Assure that we have not gone beyond 256 entries! */ if (grib_tables->grib_table_info[tablenum].num_entries >= 256) { fprintf(stderr, "Error: Invalid number of lines in table %d in, \n skipping line: %s \n", tablenum,line); break; } /* Grab the last field */ strcpy(elems[elemidx],line + nxtidx); /* Split up comma-seperated field of wrf varnames */ nxtidx = 0; elemidx = 0; /* Allocate number of elements in wrf_param */ grib_tables->grib_table_info[tablenum].wrf_param[parmidx] = (char **)malloc(1*sizeof(char *)); if (grib_tables->grib_table_info[tablenum].wrf_param[parmidx] == NULL) { fprintf(stderr, "Error allocating space for wrf_param[%d], exiting\n", parmidx); *ret = 1; return 1; } while ((charidx = findchar(elems[3]+nxtidx,',')) >= 0) { /* Allocate number of elements in wrf_param */ grib_tables->grib_table_info[tablenum].wrf_param[parmidx] = (char **) realloc(grib_tables->grib_table_info[tablenum].wrf_param[parmidx], (elemidx+2)*sizeof(char *)); if (grib_tables->grib_table_info[tablenum].wrf_param[parmidx] == NULL) { perror(""); fprintf(stderr, "Error allocating space for wrf_param[%d], exiting\n", parmidx); *ret = 1; return 1; } grib_tables->grib_table_info[tablenum].wrf_param[parmidx][elemidx] = (char *)malloc((charidx+2)*sizeof(char)); if (grib_tables->grib_table_info[tablenum].wrf_param[parmidx][elemidx] == NULL) { perror(""); fprintf(stderr, "Error allocating space for wrf_param[%d][%d], exiting\n", parmidx,elemidx); *ret = 1; return 1; } strncpy(grib_tables->grib_table_info[tablenum].wrf_param[parmidx][elemidx], elems[3]+nxtidx,charidx); grib_tables->grib_table_info[tablenum].wrf_param[parmidx][elemidx][charidx] = '\0'; elemidx++; nxtidx += (charidx + 1); } /* Grab the last field */ if (strlen(elems[3] + nxtidx) <= 0) { /* Case for no specified WRF fields */ grib_tables->grib_table_info[tablenum].wrf_param[parmidx][elemidx] = (char *)malloc(1*sizeof(char)); if (grib_tables->grib_table_info[tablenum].wrf_param[parmidx][elemidx] == NULL) { perror(""); fprintf(stderr, "Error allocating space for wrf_param[%d][%d], exiting\n", parmidx,elemidx); *ret = 1; return 1; } grib_tables->grib_table_info[tablenum].wrf_param[parmidx][elemidx][0] = '\0'; grib_tables->grib_table_info[tablenum].num_wrf_params[parmidx] = 0; } else { /* Allocate space for last element */ grib_tables->grib_table_info[tablenum].wrf_param[parmidx][elemidx] = (char *)malloc((strlen(elems[3] + nxtidx)+1)*sizeof(char)); if (grib_tables->grib_table_info[tablenum].wrf_param[parmidx][elemidx] == NULL) { perror(""); fprintf(stderr, "Error allocating space for wrf_param[%d][%d], exiting\n", parmidx,elemidx); *ret = 1; return 1; } strcpy(grib_tables->grib_table_info[tablenum].wrf_param[parmidx][elemidx], elems[3] + nxtidx); grib_tables->grib_table_info[tablenum].num_wrf_params[parmidx] = elemidx + 1; } grib_tables->grib_table_info[tablenum].parm_id[parmidx]=atoi(elems[0]); grib_tables->grib_table_info[tablenum].dec_sc_factor[parmidx]=atoi(elems[4]); grib_tables->grib_table_info[tablenum].num_entries++; } *ret=0; return 0; }
static /* reads from one $instrument to the next */ void readinstsec(Inst *inst, Nextp **nextlist, Rat *grpmul, Rat *timesig, Rat *curtime, Rat *lastbar, Rat *lastnote, Note **notetop, Note **ln, Tempo **tempop, int *accidentals, int *octaves, int *vertical, int *key, int *barkey, int *transpose, char *endchar) { static Rat durdiv = { 4L, 1L }; int c, z, lastpitchclass; char s[128], *sp; Rat ratstack, rattmp; Note *pn, *nn, *pn2 = NULL; Strlist *ps; Nextp *nextpp; #ifdef DEBUG printf("Reading instrument section: %s\n", inst->name); #endif pn = (*notetop); for (;;) { findchar(&c); if (strchr(endchar, c)) break; #ifdef DEBUG printf("Processing char: %c\n", c); #endif switch (c) { case 't': if (findint(&c)) { scoterror(Str("Tempo must be specified")); break; } if ((*tempop)->next) { scoterror(Str("Redefinition of tempo")); break; } (*tempop)->next = (Tempo *) malloc(sizeof(Tempo)); *tempop = (*tempop)->next; (*tempop)->next = NULL; ratass(&((*tempop)->time), curtime); (*tempop)->val = c; break; case '!': efindword(s); if ((c = strlen(s)) < 2) scoterror(Str("Must specify 2 or more letters of keyword")); if (!strncmp(s, "accidentals", c)) { if (findonoff(accidentals)) scoterror(Str("Must be \"on\" or \"off\"")); #ifdef DEBUG printf(" accidentals %s\n", accidentals ? "on" : "off"); #endif } else if (!strncmp(s, "octaves", c)) { if (findonoff(octaves)) scoterror(Str("Must be \"on\" or \"off\"")); #ifdef DEBUG printf(" ocatves %s\n", *octaves ? "on" : "off"); #endif } else if (!strncmp(s, "vertical", c)) { if (findonoff(vertical)) scoterror(Str("Must be \"on\" or \"off\"")); #ifdef DEBUG printf(" vertical %s\n", *vertical ? "on" : "off"); #endif } else if (!strncmp(s, "timesignature", c)) { efindword(s); if ((sscanf(s, "%lu/%lu", ×ig->num, ×ig->denom) != 2) || (&(timesig->denom) == 0) ) { scoterror(Str("Invalid time signature")); timesig->num = 0; timesig->denom = 1; } #ifdef DEBUG printf(" time sig=%lu/%lu\n", timesig->num, timesig->denom); #endif ratstack.num = 4; ratstack.denom = 1; ratmul(timesig, timesig, &ratstack); #ifdef DEBUG printf(" measure length=%f\n", ratval(timesig)); #endif } else if (!strncmp(s, "key", c)) { int y; efindword(s); for (z = 0; z < PITCHCLASSES; z++) key[z] = 0; c = y = 0; for (z = 0; s[z] != (char) 0; z++) switch ((int) s[z]) { case '#': c = y + 1; y++; break; case '-': c = y - 1; y--; break; default: if (!isalpha(s[z])) scoterror(Str("Bad key signature")); key[letterval((int) s[z])] = c; y = 0; } for (z = 0; z < PITCHCLASSES; z++) barkey[z] = key[z]; } else if (!strncmp(s, "transpose", c)) { efindword(s); *transpose = 0; for (z = 0; s[z]; z++) { switch (s[z]) { case ',': (*transpose) -= NOTESPEROCT; break; case '\'': (*transpose) += NOTESPEROCT; break; case '=': (*transpose) = 0; break; case '#': (*transpose)++; break; case '-': (*transpose)--; break; default: (*transpose) += naturals[letterval((int) s[z])]; } } } else if (!strncmp(s, "next", c)) { efindword(s); if (sscanf(s, "p%d", &c) != 1) { scoterror(Str("Invalid field")); efindword(s); break; } efindword(s); if (sscanf(s, "p%d", &z) != 1) { scoterror(Str("Invalid field")); break; } if (*nextlist == NULL) { *nextlist = (Nextp *) malloc(sizeof(Nextp)); nextpp = (*nextlist); nextpp->next = NULL; } else { nextpp = (*nextlist); if ((c == nextpp->dst) || (z == nextpp->src)) scoterror(Str("Nested next-parameter passing")); while (nextpp->next) { nextpp = nextpp->next; if ((c == nextpp->dst) || (z == nextpp->src)) scoterror(Str("Nested next-parameter passing")); } nextpp->next = (Nextp *) malloc(sizeof(Nextp)); nextpp = nextpp->next; nextpp->next = NULL; } nextpp->src = c; nextpp->dst = z; } else scoterror(Str("Unrecognised keyword")); break; case '{': findint(&c); expectchar(':'); if (!c) { ratstack.num = 2L; ratstack.denom = 3L; } else { ratstack.denom = (unsigned long) c; findint(&c); if (!c) { for (z = 1; (unsigned long) z < ratstack.denom; z *= 2); z /= 2; ratstack.num = (unsigned long) z; } else ratstack.num = (unsigned long) c; expectchar(':'); } ratmul(grpmul, grpmul, &ratstack); readinstsec(inst, nextlist, grpmul, timesig, curtime, lastbar, lastnote, notetop, ln, tempop, accidentals, octaves, vertical, key, barkey, transpose, ":"); ratdiv(grpmul, grpmul, &ratstack); expectchar(':'); expectchar('}'); break; case '(': ratass(&ratstack, curtime); if (pn == (*notetop)) { readinstsec(inst, nextlist, grpmul, timesig, curtime, lastbar, lastnote, notetop, ln, tempop, accidentals, octaves, vertical, key, barkey, transpose, ")"); pn = (*notetop); } else { readinstsec(inst, nextlist, grpmul, timesig, curtime, lastbar, lastnote, &pn2->next, ln, tempop, accidentals, octaves, vertical, key, barkey, transpose, ")"); pn = pn2->next; } expectchar(')'); ratass(lastnote, &ratstack); break; case '/': ratadd(lastbar, lastbar, timesig); if ((timesig->num) && (ratcmp(lastbar, curtime))) { scoterror(Str("Wrong number of beats in bar")); ratass(lastbar, curtime); } for (z = 0; z < PITCHCLASSES; z++) barkey[z] = key[z]; break; case '<': if (pn == NULL) { scoterror(Str("Syntax error: cannot back up")); break; } if (pn->next == NULL) { pn->next = (Note *) malloc(sizeof(Note)); initnote(pn->next); pn->next->instrum = pn->instrum + 0.01; } pn2 = pn; pn = pn->next; ratass(curtime, lastnote); break; default: #ifdef DEBUG printf("Reading note\n"); printf(" time=%lu/%lu\n", curtime->num, curtime->denom); printf(" =%f\n", ratval(curtime)); #endif scotungetc(); nn = (Note *) malloc(sizeof(Note)); nn->p = NULL; nn->written = FALSE; if (*notetop == NULL) { pn = (*ln) = (*notetop) = (Note *) malloc(sizeof(Note)); initnote(*notetop); (*notetop)->instrum = (double) inst->number + 0.01; } else if (ratcmp(curtime, lastnote)) pn = (*notetop); nn->instrum = pn->instrum; #ifdef DEBUG printf(" instrument #%f\n", nn->instrum); #endif if (*vertical) strlistcopy(&nn->carryp, &(*ln)->carryp); else strlistcopy(&nn->carryp, &pn->carryp); for (nextpp = (*nextlist); nextpp; nextpp = nextpp->next) { sp = findparam(nextpp->dst, &nn->carryp); if (!strcmp(sp, ".")) strcpy(sp, NEXTP); } ratass(&nn->start, curtime); if (!findint(&c)) { ratstack.num = (unsigned long) c; ratstack.denom = 1L; ratdiv(&nn->dur, &durdiv, &ratstack); ratass(&ratstack, &nn->dur); rattmp.num = 1L; rattmp.denom = 2L; for (;;) { findchar(&c); if (c != '.') break; ratmul(&ratstack, &ratstack, &rattmp); ratadd(&nn->dur, &nn->dur, &ratstack); } } else { if (*vertical) ratass(&nn->dur, &((*ln)->lastdur)); else ratass(&nn->dur, &pn->lastdur); findchar(&c); } ratass(&nn->lastdur, &nn->dur); ratmul(&nn->dur, &nn->dur, grpmul); #ifdef DEBUG printf(" duration=%f\n", ratval(&nn->dur)); printf(" c=%c\n", c); #endif if (c == '=') { nn->octave = 8; lastpitchclass = 0; } else { nn->octave = pn->octave; lastpitchclass = pn->pitchclass; scotungetc(); } for (;;) { findchar(&c); if (c == '\'') nn->octave++; else if (c == ',') nn->octave--; else break; } if (c == 'r') { ratass(lastnote, curtime); ratmul(&rattmp, &nn->lastdur, grpmul); ratadd(curtime, curtime, &rattmp); ratass(&(*ln)->lastdur, &nn->lastdur); ratass(&pn->lastdur, &nn->lastdur); freenote(nn); break; } else { nn->pitchclass = letterval(c); if (*octaves) { c = nn->pitchclass - lastpitchclass; if (c < -(PITCHCLASSES / 2)) nn->octave++; else if (c > PITCHCLASSES / 2) nn->octave--; } } nn->accid = 0; nn->accmod = FALSE; for (;;) { findchar(&c); if (c == '#') { nn->accid++; nn->accmod = TRUE; } else if (c == '-') { nn->accid--; nn->accmod = TRUE; } else if (c == 'n') { nn->accid = 0; nn->accmod = TRUE; } else break; } if (!nn->accmod) nn->accid = barkey[nn->pitchclass]; else if (*accidentals) barkey[nn->pitchclass] = nn->accid; #ifdef DEBUG printf(" transpose=%d\n", *transpose); printf(" octave=%d pitchclass=%d accid=%d transpose=%d pitch=%f\n", nn->octave, nn->pitchclass, nn->accid, *transpose, pitchval(nn->octave, nn->pitchclass, nn->accid, *transpose)); #endif if (c == '_') { findchar(&c); if (c == '_') { nn->tie = TRUE; nn->slur = 0; findchar(&c); } else { nn->slur = 1; nn->tie = FALSE; } } else { nn->slur = 0; nn->tie = FALSE; } if (pn->slur & 1) nn->slur += 2; #ifdef DEBUG printf(" slur=%d tie=%d\n", nn->slur, nn->tie); #endif if (pn->tie) { ratadd(&rattmp, &pn->start, &pn->dur); if (ratcmp(&rattmp, curtime)) scoterror(Str("Improper tie")); if (((nn->octave != pn->octave) || (nn->pitchclass != pn->pitchclass) || ((nn->accid != pn->accid) && (nn->accmod))) && (pitchval(nn->octave, nn->pitchclass, nn->accid, *transpose) != pitchval(pn->octave, pn->pitchclass, pn->accid, *transpose))) scoterror(Str("Tie between different pitches")); ratadd(&pn->dur, &pn->dur, &nn->dur); ratass(&pn->lastdur, &nn->lastdur); pn->slur += nn->slur; pn->tie = nn->tie; freenote(nn); nn = pn; if (c == (char) '[') scoterror(Str("Warning: params changed on tie")); } else { ps = nn->p = (Strlist *) malloc(sizeof(Strlist)); for (z = 0; z < 4; z++) { ps->next = (Strlist *) malloc(sizeof(Strlist)); ps = ps->next; } ps->next = NULL; } ps = nn->p; sprintf(ps->str, "%.02f", nn->instrum); ps = ps->next; sprintf(ps->str, "%g", ratval(&nn->start)); ps = ps->next; sprintf(ps->str, "%g", ratval(&nn->dur)); ps = ps->next; sprintf(ps->str, "%d", nn->slur); ps = ps->next; sprintf(ps->str, "%.02f", pitchval(nn->octave, nn->pitchclass, nn->accid, *transpose)); if (c == '[') { char *pars; int pnum; pars = readparams(inst); #ifdef DEBUG printf("Params: %s\n", pars); #endif z = 0; pnum = 6; while (strchr(" \t\r\n", (int) pars[z])) z++; for (;;) { if (pars[z] == (char) ']') break; c = 0; while (!strchr(" \t\r\n:]", (int) pars[z])) s[c++] = pars[z++]; s[c] = (char) 0; #ifdef DEBUG printf("Read: %s\n", s); #endif while (strchr(" \t\r\n", (int) pars[z])) z++; if (pars[z] == (char) ':') { pnum = atoi(s); if (pnum < 6) scoterror(Str("Parameter number out of range")); z++; while (strchr(" \t\r\n", (int) pars[z])) z++; continue; } #ifdef DEBUG printf("Param #%d: %s\n", pnum, s); #endif if (s[0] == (char) '\'') { addparam(pnum, &s[1], &nn->p); addparam(pnum, ".", &nn->carryp); } else { addparam(pnum, s, &nn->p); addparam(pnum, s, &nn->carryp); } pnum++; } free(pars); } else scotungetc(); if ((nn != pn) && (!pn->written)) { #ifdef DEBUG printf(" doing nextp stuff:\n"); #endif for (nextpp = (*nextlist); nextpp; nextpp = nextpp->next) { #ifdef DEBUG printf(" carrying p%d to p%d?\n", nextpp->src, nextpp->dst); #endif if (!strcmp(findparam(nextpp->dst, &pn->carryp), NEXTP)) { sp = findparam(nextpp->dst, &pn->p); if (!strcmp(sp, ".")) { char *sp2; sp2 = findparam(nextpp->src, &nn->p); if (!strcmp(sp2, ".")) sp2 = findparam(nextpp->src, &nn->carryp); strcpy(sp, sp2); #ifdef DEBUG printf(" Yes.\n"); #endif } } } writenote(pn); } if ((!(*nextlist)) && (!nn->tie)) writenote(nn); if (nn != pn) { if (!pn->written) scoterror(Str("Lost previous note: not written")); #ifdef DEBUG if (pn->next == nn) printf("* pn->next==nn\n"); #endif nn->next = pn->next; #ifdef DEBUG if (pn2 == nn) printf("* pn2==nn\n"); #endif if (pn == *notetop) *notetop = nn; else pn2->next = nn; freenote(pn); pn = nn; #ifdef DEBUG if (nn->next == nn) printf("* Circular list created\n"); #endif } #ifdef DEBUG printf(" nn linked into note list\n"); printf(" curtime=%lu/%lu\n", curtime->num, curtime->denom); printf(" nn->dur=%lu/%lu\n", nn->dur.num, nn->dur.denom); #endif *ln = nn; ratass(lastnote, curtime); ratmul(&rattmp, &nn->lastdur, grpmul); ratadd(curtime, curtime, &rattmp); #ifdef DEBUG printf(" curtime=%lu/%lu\n", curtime->num, curtime->denom); printf(" Done with note\n"); #endif } } scotungetc(); }
replace_single_character(PyStringObject *self, char from_c, const char *to_s, Py_ssize_t to_len, Py_ssize_t maxcount) { char *self_s, *result_s; char *start, *next, *end; Py_ssize_t self_len, result_len; Py_ssize_t count, product; PyStringObject *result; self_s = PyString_AS_STRING(self); self_len = PyString_GET_SIZE(self); count = countchar(self_s, self_len, from_c, maxcount); if (count == 0) { /* no matches, return unchanged */ return return_self(self); } /* use the difference between current and new, hence the "-1" */ /* result_len = self_len + count * (to_len-1) */ product = count * (to_len-1); if (product / (to_len-1) != count) { PyErr_SetString(PyExc_OverflowError, "replace string is too long"); return NULL; } result_len = self_len + product; if (result_len < 0) { PyErr_SetString(PyExc_OverflowError, "replace string is too long"); return NULL; } if ( (result = (PyStringObject *) PyString_FromStringAndSize(NULL, result_len)) == NULL) return NULL; result_s = PyString_AS_STRING(result); start = self_s; end = self_s + self_len; while (count-- > 0) { next = findchar(start, end-start, from_c); if (next == NULL) break; if (next == start) { /* replace with the 'to' */ Py_MEMCPY(result_s, to_s, to_len); result_s += to_len; start += 1; } else { /* copy the unchanged old then the 'to' */ Py_MEMCPY(result_s, start, next-start); result_s += (next-start); Py_MEMCPY(result_s, to_s, to_len); result_s += to_len; start = next+1; } } /* Copy the remainder of the remaining string */ Py_MEMCPY(result_s, start, end-start); return result; }
FORCE_INLINE int NSISCALL ui_doinstall(void) { header *header = g_header; static WNDCLASS wc; // richedit subclassing and bgbg creation // detect default language // more information at: // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_0xrn.asp LANGID (WINAPI *GUDUIL)(); GUDUIL = myGetProcAddress(MGA_GetUserDefaultUILanguage); if (GUDUIL) { // Windows ME/2000+ myitoa(state_language, GUDUIL()); } else { static const TCHAR reg_9x_locale[] = _T("Control Panel\\Desktop\\ResourceLocale"); static const TCHAR reg_nt_locale_key[] = _T(".DEFAULT\\Control Panel\\International"); const TCHAR *reg_nt_locale_val = ®_9x_locale[30]; // = _T("Locale") with opt state_language[0] = _T('0'); state_language[1] = _T('x'); state_language[2] = 0; { // Windows 9x myRegGetStr(HKEY_CURRENT_USER, reg_9x_locale, NULL, g_tmp, 0); } if (!g_tmp[0]) { // Windows NT // This key exists on 9x as well, so it's only read if ResourceLocale wasn't found myRegGetStr(HKEY_USERS, reg_nt_locale_key, reg_nt_locale_val, g_tmp, 0); } mystrcat(state_language, g_tmp); } // set default language set_language(); // initialize auto close flag g_exec_flags.autoclose=g_flags&CH_FLAGS_AUTO_CLOSE; #ifdef NSIS_CONFIG_PLUGIN_SUPPORT // initialize plugin api g_exec_flags.plugin_api_version=NSISPIAPIVER_CURR; #endif // read install directory from registry if (!is_valid_instpath(state_install_directory)) { if (header->install_reg_key_ptr) { myRegGetStr( (HKEY)header->install_reg_rootkey, GetNSISStringNP(header->install_reg_key_ptr), GetNSISStringNP(header->install_reg_value_ptr), ps_tmpbuf, 0 ); if (ps_tmpbuf[0]) { TCHAR *p=ps_tmpbuf; TCHAR *e; if (p[0]==_T('\"')) { TCHAR *p2; p++; p2 = findchar(p, _T('"')); *p2 = 0; } // p is the path now, check for .exe extension e=p+mystrlen(p)-4; if (e > p) { // if filename ends in .exe, and is not a directory, remove the filename if (!lstrcmpi(e, _T(".exe"))) // check extension { DWORD d; d=GetFileAttributes(p); if (d == INVALID_FILE_ATTRIBUTES || !(d&FILE_ATTRIBUTE_DIRECTORY)) { // if there is no back-slash, the string will become empty, but that's ok because // it would make an invalid instdir anyway trimslashtoend(p); } } } mystrcpy(state_install_directory,addtrailingslash(p)); } } } if (!is_valid_instpath(state_install_directory)) { GetNSISString(state_install_directory,header->install_directory_ptr); } #ifdef NSIS_CONFIG_LOG if (g_flags & CH_FLAGS_SILENT_LOG && !g_is_uninstaller) { #if !defined(NSIS_CONFIG_LOG_ODS) && !defined(NSIS_CONFIG_LOG_STDOUT) build_g_logfile(); #endif log_dolog=1; } #endif #ifdef NSIS_CONFIG_VISIBLE_SUPPORT g_hIcon=LoadImage(g_hInstance,MAKEINTRESOURCE(IDI_ICON2),IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_SHARED); #ifdef NSIS_SUPPORT_BGBG if (header->bg_color1 != -1) { LPCTSTR cn = _T("_Nb"); RECT vp; extern LRESULT CALLBACK BG_WndProc(HWND, UINT, WPARAM, LPARAM); wc.lpfnWndProc = BG_WndProc; wc.hInstance = g_hInstance; wc.hIcon = g_hIcon; //wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.lpszClassName = cn; if (!RegisterClass(&wc)) return 0; SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0); m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,cn,0,WS_POPUP, vp.left,vp.top,vp.right-vp.left,vp.bottom-vp.top,0,NULL,g_hInstance,NULL); } #endif//NSIS_SUPPORT_BGBG #endif//NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_SUPPORT_CODECALLBACKS // Select language if (ExecuteCallbackFunction(CB_ONINIT)) return 2; set_language(); #endif #ifdef NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_SILENT_SUPPORT if (!g_exec_flags.silent) #endif//NSIS_CONFIG_SILENT_SUPPORT { #ifdef NSIS_SUPPORT_BGBG ShowWindow(m_bgwnd, SW_SHOW); #endif//NSIS_SUPPORT_BGBG #ifdef NSIS_CONFIG_LICENSEPAGE { // load richedit DLL static const TCHAR riched20[]=_T("RichEd20"); static const TCHAR riched32[]=_T("RichEd32"); #ifdef UNICODE static const TCHAR richedit20t[]=_T("RichEdit20W"); #else static const TCHAR richedit20t[]=_T("RichEdit20A"); #endif static const TCHAR richedit[]=_T("RichEdit"); if (!LoadLibrary(riched20)) { LoadLibrary(riched32); // Win95 only ships with v1.0, NT4 has v2.0: web.archive.org/web/20030607222419/http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/aboutricheditcontrols.asp } // make richedit20a/w point to RICHEDIT if (!GetClassInfo(NULL,richedit20t,&wc)) { GetClassInfo(NULL,richedit,&wc); wc.lpszClassName = richedit20t; RegisterClass(&wc); } } #endif { int ret=DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_INST+dlg_offset),0,DialogProc); #if defined(NSIS_SUPPORT_CODECALLBACKS) && defined(NSIS_CONFIG_ENHANCEDUI_SUPPORT) ExecuteCallbackFunction(CB_ONGUIEND); #endif #ifdef NSIS_CONFIG_PLUGIN_SUPPORT Plugins_SendMsgToAllPlugins(NSPIM_GUIUNLOAD); #endif return ret; } } #endif//NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_SILENT_SUPPORT #ifdef NSIS_CONFIG_VISIBLE_SUPPORT else #endif//NSIS_CONFIG_VISIBLE_SUPPORT { if (install_thread(NULL)) { #ifdef NSIS_SUPPORT_CODECALLBACKS if (!g_quit_flag) ExecuteCallbackFunction(CB_ONINSTFAILED); #endif//NSIS_SUPPORT_CODECALLBACKS return 2; } #ifdef NSIS_SUPPORT_CODECALLBACKS ExecuteCallbackFunction(CB_ONINSTSUCCESS); #endif//NSIS_SUPPORT_CODECALLBACKS return 0; } #endif//NSIS_CONFIG_SILENT_SUPPORT }
FORCE_INLINE int NSISCALL ui_doinstall(void) { header *header = g_header; static WNDCLASS wc; // richedit subclassing and bgbg creation g_exec_flags.autoclose=g_flags&CH_FLAGS_AUTO_CLOSE; set_language(); if (!is_valid_instpath(state_install_directory)) { if (header->install_reg_key_ptr) { myRegGetStr( (HKEY)header->install_reg_rootkey, GetNSISStringNP(header->install_reg_key_ptr), GetNSISStringNP(header->install_reg_value_ptr), ps_tmpbuf ); if (ps_tmpbuf[0]) { char *p=ps_tmpbuf; char *e; if (p[0]=='\"') { char *p2; p++; p2 = findchar(p, '"'); *p2 = 0; } // p is the path now, check for .exe extension e=p+mystrlen(p)-4; if (e > p) { // if filename ends in .exe, and is not a directory, remove the filename if (!lstrcmpi(e, ".exe")) // check extension { DWORD d; d=GetFileAttributes(p); if (d == INVALID_FILE_ATTRIBUTES || !(d&FILE_ATTRIBUTE_DIRECTORY)) { // if there is no back-slash, the string will become empty, but that's ok because // it would make an invalid instdir anyway trimslashtoend(p); } } } mystrcpy(state_install_directory,addtrailingslash(p)); } } } if (!is_valid_instpath(state_install_directory)) { GetNSISString(state_install_directory,header->install_directory_ptr); } #ifdef NSIS_CONFIG_LOG if (g_flags & CH_FLAGS_SILENT_LOG && !g_is_uninstaller) { #ifndef NSIS_CONFIG_LOG_ODS build_g_logfile(); #endif log_dolog=1; } #endif #ifdef NSIS_CONFIG_VISIBLE_SUPPORT g_hIcon=LoadImage(g_hInstance,MAKEINTRESOURCE(IDI_ICON2),IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_SHARED); #ifdef NSIS_SUPPORT_BGBG if (header->bg_color1 != -1) { DWORD cn = CHAR4_TO_DWORD('_', 'N', 'b', 0); RECT vp; extern LRESULT CALLBACK BG_WndProc(HWND, UINT, WPARAM, LPARAM); wc.lpfnWndProc = BG_WndProc; wc.hInstance = g_hInstance; wc.hIcon = g_hIcon; //wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.lpszClassName = (LPCSTR)&cn; if (!RegisterClass(&wc)) return 0; SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0); m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,(LPCSTR)&cn,0,WS_POPUP, vp.left,vp.top,vp.right-vp.left,vp.bottom-vp.top,0,NULL,g_hInstance,NULL); } #endif//NSIS_SUPPORT_BGBG #endif//NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_SUPPORT_CODECALLBACKS // Select language if (ExecuteCallbackFunction(CB_ONINIT)) return 2; set_language(); #endif #ifdef NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_SILENT_SUPPORT if (!g_exec_flags.silent) #endif//NSIS_CONFIG_SILENT_SUPPORT { #ifdef NSIS_SUPPORT_BGBG ShowWindow(m_bgwnd, SW_SHOW); #endif//NSIS_SUPPORT_BGBG #ifdef NSIS_CONFIG_LICENSEPAGE { // load richedit DLL static char str1[]="RichEd20.dll"; static char str2[]="RichEdit20A"; if (!LoadLibrary(str1)) { *(WORD*)(str1+6) = CHAR2_TO_WORD('3','2'); LoadLibrary(str1); } // make richedit20a point to RICHEDIT if (!GetClassInfo(NULL,str2,&wc)) { str2[8]=0; GetClassInfo(NULL,str2,&wc); wc.lpszClassName = str2; str2[8]='2'; RegisterClass(&wc); } } #endif { int ret=DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_INST+dlg_offset),0,DialogProc); #if defined(NSIS_SUPPORT_CODECALLBACKS) && defined(NSIS_CONFIG_ENHANCEDUI_SUPPORT) ExecuteCallbackFunction(CB_ONGUIEND); #endif return ret; } } #endif//NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_SILENT_SUPPORT #ifdef NSIS_CONFIG_VISIBLE_SUPPORT else #endif//NSIS_CONFIG_VISIBLE_SUPPORT { if (install_thread(NULL)) { #ifdef NSIS_SUPPORT_CODECALLBACKS if (!g_quit_flag) ExecuteCallbackFunction(CB_ONINSTFAILED); #endif//NSIS_SUPPORT_CODECALLBACKS return 2; } #ifdef NSIS_SUPPORT_CODECALLBACKS ExecuteCallbackFunction(CB_ONINSTSUCCESS); #endif//NSIS_SUPPORT_CODECALLBACKS return 0; } #endif//NSIS_CONFIG_SILENT_SUPPORT }
/** SARA AR Without Tonal mark Rtn * * Date Written : Monday, 9 May, 1988 3:16:47 PM */ unsigned char *SaraRWithoutTnl( register unsigned char *TempIndx ) { register unsigned char *TempIndxm2 = TempIndx - 2; /* for return point before A-1 */ register unsigned char *TempIndxm3 = TempIndx - 3; /* for return point before A-2 */ unsigned char chbufp1 = *( TempIndx + 1 ); unsigned char chbufm1 = *( TempIndx - 1 ); unsigned char chbufm2 = *TempIndxm2; if ( findchar( chbufp1, "¢«¬®°±²Í" ) || istlcon( chbufp1 ) ) { return( TempIndx ); } else { switch ( chbufp1 ) { case PoreParn: if ( findchar( chbufm1, "¡ÀÃ" ) == 0 ) { /* ÀÒ¾ */ return( TempIndx ); /* cut after a */ } break; case KoreKwai: if ( findchar( chbufm1, "¹ÀÃÍ" ) == 0 ) { /* ÀÒ¤ */ return( TempIndx ); } break; case PorePla: if ( findchar( chbufm1, "¤¬´ºÉÊ" ) == 0 ) { /* ¤Ò» */ return( TempIndx ); } break; case SoreSeo: if ( findchar( chbufm1, "¡¤¾ÁÅÇÈÊÍ" ) == 0 ) { /* ÇÒÊ */ return( TempIndx ); } break; case KoreRakung: if ( chbufm1 != MoreMar ) { /* ÁÒ¦ */ return( TempIndx ); } break; case JoreJarn: if ( findchar( chbufm1, "¡¹Í" ) == 0 ) { /* ¡Ò¨ */ return( TempIndx ); } break; case ShoreChang: if ( chbufm1 != RoreReo && chbufm1 != OrAng ) { /* ÍÒªÒ */ return( TempIndx ); } break; case YoreYing: /* this mean if not found do (same as 'if ( findchar( chbufm1, "¡ÃÅÇË" ) == 0 ) */ if ( !( findchar( chbufm1, "¡ÃÅÇË" ) ) ) { /* ¡Ò¨¹ */ return( TempIndx ); } break; case NoreNane: if ( chbufm1 != YoreYing && chbufm1 != MoreMar ) { /* Ò³*/ return( TempIndx ); } break; case ThorToong: if ( chbufm1 != NoreNoo ) { /* ¹Ò¶ */ return( TempIndx ); } break; case ToreTong: if ( chbufm1 != YoreYak && chbufm1 != PoreParn ) { /* ¾Ò¸ */ return( TempIndx ); } break; case ToreTaharn: if ( !( findchar( chbufm1, "¹º¾ÁÇÊ" ) ) ) { /* ÇÒ· */ return( TempIndx ); } break; case ForeFun: if ( chbufm1 != RoreReo && chbufm1 != LoreLing ) { /* ¡ÃÒ¿ */ return( TempIndx ); } break; case PoreSumpao: if ( chbufm1 != LoreLing ) { /* ÅÒÀ */ return( TempIndx ); } break; case SoreSala: if ( !( findchar( chbufm1, "¡Ã¹ºÈ" ) ) ) { /* ÍÒ¡ÒÈ */ return( TempIndx ); } break; case SoreRusi: if ( chbufm1 != DoreDek && chbufm1 != PoreSumpao ) { /* ´ÒÉ´Ò */ return( TempIndx ); } break; } } /* Front Cut Section */ if ( findchar( chbufm1, "¢¤¦ª«¯°±²³´¸¿ÈÌÍ" ) || istlcon( chbufm1 ) ) { return( TempIndxm2 ); /* cut before A-1 */ } else { if ( *TempIndxm2 == HorHeeb && findchar( chbufm1, "¹ÁÂÃÅÇ" ) ) { return( TempIndxm3 ); /* cut before HorHeeb */ } switch ( chbufm1 ) { case KoreGai: if ( chbufm2 != PorPeng && chbufm2 != SoreSeo ) { /* ¼¡Ò */ return( TempIndxm2 ); /* cut before a-1 */ } break; case NgorNgoo: if ( findchar( chbufp1, "´¹ºÁÂ" ) ) { if ( chbufm2 != PorPeng && chbufm1 != HorHeeb ) { return( TempIndxm2 ); /*cut before a - 1 */ } } else { return( TempIndx ); /* cut after a */ } break; case JoreJarn: if ( !( chbufm2 == KorKai && chbufp1 == YoreYak ) ) { /* ¢¨Ò */ return ( TempIndxm2 ); /* cut before a -1 */ } else { return( TempIndx - 3 ); /* cut before KorKai */ } case PorePla: if ( chbufm2 != SoreSeo ) { /* ʻҠ*/ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case NoreNane: if ( chbufm2 != PorePla ) { /* »³ÒÁ */ return ( TempIndxm2 ); /* cut before a - 1 */ } else { if ( chbufp1 != MoreMar ) { return( TempIndx ); } } break; case NoreNoo: if ( !( findchar( chbufm2, "¢©·¸¾ÇÊËÍ" ) ) ) { /* ¢¹Ò¹ */ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case SoreSeo: if ( chbufm2 != SoreSeo || chbufp1 != RoreReo ) { /* ÊÊÒà */ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case RoreReo: if ( !( findchar( chbufm2, "¡¢¤¦¨ªµ·¹º»¾¿ÈÊË" ) ) ) { /* ¡ÃÒ */ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case MoreMar: if ( !( findchar( chbufm2, "¢ªÉÊË" ) ) ) { /* ÊÁÒ¤Á */ return( TempIndxm2 ); /* cut before a - 1 */ } break; case YoreYak: if ( !( findchar( chbufm2, "¢ª¾ÊËÍ" ) ) ) { /* ¢ÂÒ */ return( TempIndxm2 ); /* cut before a - 1 */ } break; case WoreWaan: if ( !( findchar( chbufm2, "¡¢¤¨ªµ¶·¼ÀÊË" ) ) ) { /* ¡ÇÒ§ */ return( TempIndxm2 ); /* cut before a - 1 */ } break; case LoreLing: if ( !( findchar( chbufm2, "¡¢¨©ª´µ¶·»¼¾¿ÁÊËÍ" ) ) ) { /* ¡ÅÒ§ */ return( TempIndxm2 ); /*cut before a - 1 */ } break; case ToreTaharn: if ( chbufm2 != PorePla && chbufm2 != KoreGai && chbufm2 != KoreKwai ) { /* ¡·Ò */ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case ToreTao: if ( chbufm2 != SoreSeo && chbufm2 != KoreGai ) { /* ʵҧ¤ì */ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case HorHeeb: if ( chbufm2 != MoreMar && chbufm2 != SoreSeo && chbufm2 != ToreTaharn ) { /* ËÁÒ */ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case BoreBaimai: if ( chbufm2 != SoreSeo && chbufm2 != ShoreChang ) { /* ʺÒ */ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case PoreParn: if ( chbufm2 != SoreSeo ) { /* ʾҹ */ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case ThorToong: if ( chbufm2 != SoreSeo && chbufm2 != ToreTao ) { /* µ¶Ò */ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case PoreSumpao: if ( chbufm2 != SoreSeo && chbufm2 != NoreNoo ) { /* ¹ÀÒ */ return ( TempIndxm2 ); /* cut before a - 1 */ } break; case DoreChada: if ( chbufm2 != ShoreChang ) { /* ª®Ò */ return( TempIndxm2 ); /* cut before a-1 */ } break; } } return ( NULL ); }
uint8_t GoLine(void) { register uint8_t li; register uint8_t *lp; register unsigned int bi; //printf("\n#%d:%s\n",CLine,CmdInp); //printf("\n*lnum=%d A=%d\n",CLine,Vars[0]); Gp = CmdInp + 1; switch(CmdInp[0]){ case STOP: STOPPROG(ESTOP); case BEEP: lp = findchar(CmdInp, ','); if(lp) { *lp = 0; bi = ExpPars1(); Gp=lp+1; Beep(bi,ExpPars1()); } return(0); case DIM: Gp+=2;//( li = ExpPars1(); if(CmdInp[1] != SIGNEDBYTE && CmdInp[1] != UNSIGNEDBYTE)//type of array li = li << 1;//two byte on item if(li <= (MAXBMEMSIZE-1)){ /* lp = Vars[TOVAR(CmdInp[1])]; if(lp > FirstPrgLine) lfree(lp);*/ lp = lmalloc(li+1,LlP); if(!lp) STOPPROG(EALLOC); *lp = CmdInp[1];//type of array lp++; //printf("\n*%p %c %d %d %s\n",lp,*(lp-1),*(lp-2),li,CmdInp); li = CmdInp[2];//name of array // if(SYMISVAR(li)) Vars[TOVAR(li)] = (unsigned int)lp; return(0); } STOPPROG(EERROR); return(0); case LET: lp = findchar(CmdInp, '='); Gp = lp+1; bi = ExpPars1(); // if(!SYMISVAR(li)) if(*(lp-1) == ')'){ *lp = 0; Gp = CmdInp+2;// '(' li = ExpPars1();//array index lp = (uint8_t *)Vars[TOVAR(CmdInp[1])]; //printf("\n+%p %c %d %d %d\n",lp,*(lp-1),*(lp-2),li,bi); if(*(lp-2) > (li+2)){// switch(*(lp-1)){//type of array case SIGNEDBYTE: *(((char *)lp + li)) = bi; break; case UNSIGNEDBYTE: *(((uint8_t *)lp + li)) = bi; break; default: // case SIGNEDWORD: *(((int *)lp + li)) = bi; break; /* case UNSIGNEDWORD: *(((unsigned int *)lp + li)) = bi; break; */ } } else STOPPROG(EERROR);//TODO } else Vars[TOVAR(CmdInp[1])] = bi; return(0); case AT: lp = findchar(CmdInp, ','); if(lp) { *lp = 0; li = ExpPars1();//x if(li< LCDTWIDTH) #ifdef AVR xt=li*LCDSYMWIDTH; else xt=(LCDTWIDTH-1)*LCDSYMWIDTH; #else xt=li; else xt=(LCDTWIDTH-1); #endif Gp=lp+1; li = ExpPars1();//y if(li< LCDTHEIGHT) yt=li; else yt=LCDTHEIGHT-1; #ifdef AVR st7565_command(CMD_SET_DISP_START_LINE | ((LCDTHEIGHT-1)*8)+8); #else printf( "%c[%d;%dH", 27, yt+1, xt+1 ); // установили курсор в позицию fflush( stdout ); #endif } return(0); case OUT: lp = findchar(CmdInp, ','); if(lp) { *lp = 0; li = ExpPars1();//port Gp=lp+1; out_port(li,ExpPars1()); } return(0); case REM: return(0); case LOAD: FreePrg(); ReplaceChar(CmdInp+2, '"', 0); loadprg((const char *)(CmdInp+2)); PrgLineP = FirstPrgLine; return(1); case INPUT: lp = (uint8_t *)(Vars + TOVAR(CmdInp[1]));//pointer to var Gp++;//to '(' or 0 if(*Gp == '(') li = ExpPars1();//index else li = 255; lgets(CmdInp); if(CmdInp[0]==BREAK_KEY) STOPPROG(EINTERUPT); Gp=CmdInp; bi = ExpPars1(); if(li < MAXBMEMSIZE){ lp = (uint8_t *)(*((unsigned int *)lp)); if(*(lp-2) > (li+2)){// switch(*(lp-1)){//type of array case SIGNEDBYTE: *(((char *)lp + li)) = bi; break; case UNSIGNEDBYTE: *(((uint8_t *)lp + li)) = bi; break; default: *(((int *)lp + li)) = bi; break; } } else STOPPROG(EERROR);//TODO } else *lp = (int)bi; return(0); case IF: lp = findchar(CmdInp, THEN); if(lp){ *lp = 0; if(ExpPars1()){ strcpy((char *)CmdInp,(const char *)(lp+1)); return(2);; } }else STOPPROG(EERROR); return(0); case PRINT: li = strlen((const char *)CmdInp); while(Gp && *Gp){ if(*Gp == '"'){ Gp++; lp =findchar(Gp ,'"'); *lp = 0; lputs((char *)(Gp)); Gp = lp+1; } else{ if(*Gp == '$'){ Gp++; lputchar(ExpPars1()); } else lputint(ExpPars1()); } //printf("\n++ %s\n",Gp); Gp =findchar(Gp ,','); if(Gp) Gp++; } if(CmdInp[li-1]!=';') lputchar('\n'); return(0); case PAUSE: bi = ExpPars1(); delay_ms(bi); return(0); case GOTO: PrgLineP = GetPrgLine(ExpPars1(),0); if(!PrgLineP){ STOPPROG(EGOTONOWHERE); } return(1) ; case GOSUB: SubStack[SubStackP] = PrgLineP->next; SubStackP++; if(SubStackP >= SMAX){ STOPPROG(EGSOVF); } PrgLineP = GetPrgLine(ExpPars1(),0); if(!PrgLineP){ STOPPROG(EGOTONOWHERE); } return(1); case RETURN: if(SubStackP < 1){ STOPPROG(ERETWOG); } --SubStackP; PrgLineP = SubStack[SubStackP]; return(1); case FOR : lp = findchar(CmdInp, TO); if(lp){ *lp = 0; Gp = CmdInp+ 3; li = TOVAR(CmdInp[1]); if(li>LMAX) STOPPROG(ELOPSOVF); Vars[li] = ExpPars1(); Gp = lp + 1; LoopVar[li].var_to = ExpPars1(); LoopVar[li].line_begin = PrgLineP->next; }else STOPPROG(EERROR); return(0); case NEXT: li = TOVAR(CmdInp[1]); if(++Vars[li] <= LoopVar[li].var_to){ PrgLineP = LoopVar[li].line_begin; return(1); } break; }