Scripts discussion (1)

Discuss and announce AkelPad plugins
Locked
  • Author
  • Message
KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

The script FileInfo.js now also shows detailed statistics of the text.

Offline
Posts: 767
Joined: Mon Sep 28, 2009 10:03 am
Location: Minsk, Belarus

Post by se7h »

Infocatcher
разместите пожалуйста все свои скрипты в Script Collection, запарился их искать :)

Offline
Posts: 1873
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

se7h
Уфф, вроде, всё: viewtopic.php?p=9924#p9924.
Но кое-что и правда не совсем дописано, кое-что можно улучшить, а что-то – и вовсе переписать, но пока нет особой необходимости.

Ну вот, ограничение на длину. Придется делить на части.

Offline
Posts: 767
Joined: Mon Sep 28, 2009 10:03 am
Location: Minsk, Belarus

Post by se7h »

Infocatcher
респект!

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

I changed the name of the script from SelectRange.js to SelectRangeText.js.
I had not noticed before, the script SelectRange.js was placed by Instructor.
Both scripts have different functionality.
I'm sorry everyone for the confusion.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

I have a question.
Date.toLocaleString() method returns the date as long.
How to convert long date to short date, according to the locale settings of the operating system?

Offline
Posts: 2248
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

KDJ
All information about built-in JScript's, JavaScript's, ActionScript's and other ECMA262 standard implementations objects you can find on pages of standard. For instance here(2.35MB).(Сhapter 15.9 for your case. Or here you can find more friendly description.)

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

FeyFre, thank you for the book ECMA (readings for several months :D).
But I do not see the JS function, that returns a short date.
I have such settings in the system:
short date format: "dd-MM-yyyy",
long date format: "dd MMMM yyyy".
Date.toLocaleDateString() method returns a long date. You can convert to using the functions getDate(), getMonth(), getFullYear(). But I do not know, how to read from the system short date format.

Offline
Posts: 2248
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

KDJ, if something missing in JS, you always can get it from system using AkelPad.SystemFunction().Call("syslibrary::syscall",params).
I have already showed you how to get system time using system calls.

Code: Select all

//! FROM WinNT.h
//! Typical values for first param of GetDateFormat and GetDateFormat syscalls
//! (or specified locale value. see MAKELCID define)
var LOCALE_USER_DEFAULT = 1024;
var LOCALE_SYSTEM_DEFAULT = 2048;
var LOCALE_INVARIANT = 127;

//! FROM WinNLS.h
// Date Flags for GetDateFormat(SECOND PARAM)
var DATE_SHORTDATE        =   0x00000001  // use short date picture
var DATE_LONGDATE         =   0x00000002  // use long date picture
var DATE_USE_ALT_CALENDAR =   0x00000004  // use alternate calendar (if any)
//! Only for >=Windows 2000
var DATE_YEARMONTH  = 0x00000008  // use year month picture
var DATE_LTRREADING = 0x00000010  // add marks for left to right reading order layout
var DATE_RTLREADING = 0x00000020  // add marks for right to left reading order layout
//!
// Time Flags for GetTimeFormat(SECOND PARAM)
var TIME_NOMINUTESORSECONDS = 0x00000001  // do not use minutes or seconds
var TIME_NOSECONDS          = 0x00000002  // do not use seconds
var TIME_NOTIMEMARKER       = 0x00000004  // do not use time marker
var TIME_FORCE24HOURFORMAT  = 0x00000008  // always use 24 hour format
// Date/Time Flags for both GetTimeFormat and GetDateFormat(SECOND PARAM) (OR-ed)
var LOCALE_NOUSEROVERRIDE = 0x80000000;
var LOCALE_USE_CP_ACP     = 0x40000000;

var oSys = AkelPad.SystemFunction();
var lpstr = AkelPad.MemAlloc(256*_TSIZE);
AkelPad.MemCopy(lpstr, "", _TSTR);
var systime = AkelPad.MemAlloc(16 /*sizeof_SYSTEMTIME*/);
oSys.Call("kernel32::GetSystemTime", systime);
oSys.Call("kernel32::GetDateFormat"+_TCHAR,
			LOCALE_USER_DEFAULT,
			DATE_SHORTDATE,
			systime,
			0,
			lpstr,255);
var str = AkelPad.MemRead(lpstr, _TSTR);
AkelPad.MessageBox(0, str, "GetDateFormat"+_TCHAR, 0 /*MB_OK*/);
oSys.Call("kernel32::GetTimeFormat"+_TCHAR,
			LOCALE_USER_DEFAULT,
			TIME_FORCE24HOURFORMAT,
			systime,
			0,
			lpstr,255);
str = AkelPad.MemRead(lpstr, _TSTR);
AkelPad.MessageBox(0, str, "GetTimeFormat"+_TCHAR, 0 /*MB_OK*/);

AkelPad.MemFree(systime);
AkelPad.MemFree(lpstr);

You should read MSDN carefully.

Offline
Posts: 1873
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

convertEscapes.js 0.1.1 - 2010-11-16
Добавил восстановление обратных слешей внутри строковых литералов.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Thanks FeyFre.
It seems to me, that I understand how it works.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

The following code crashes AkelPad.

Code: Select all

var nBufferSize = 8;
var lpBuffer;
var i;

for (i = 0; i < 1000; ++i)
{
  lpBuffer = AkelPad.MemAlloc(nBufferSize);
  AkelPad.MemCopy(lpBuffer,     0, 4); //DT_WORD
  AkelPad.MemCopy(lpBuffer + 2, 0, 4);
  AkelPad.MemCopy(lpBuffer + 4, 0, 4);
  AkelPad.MemCopy(lpBuffer + 6, 0, 4);

  AkelPad.MemFree(lpBuffer);
}
This happens when executing the function:
AkelPad.MemCopy(lpBuffer + 6, 0, 4);
But not always. That is why I gave the count to 1000. This gives confidence that the error occurs.
I checked on two computers with Windows XP.
And where is the bug?

Offline
Posts: 2248
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

KDJ, you are right, there is a bug in method.
4 Instructor:
IDocument.c
#line 950 #line 959 должно быть sizeof(WORD) и sizeof(BYTE)
иначе запись портит служебные данные кучи(я как раз недавно в одном плагине тоже такой недосмотр нашел).

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

But you can skip this error. It should enlarge the buffer size of 1 byte:
lpBuffer = AkelPad.MemAlloc(nBufferSize + 1);

Offline
Posts: 767
Joined: Mon Sep 28, 2009 10:03 am
Location: Minsk, Belarus

Post by se7h »

Instructor
реально доработать ChmKeyword.js так, чтобы можно было одновременно открывать несколько окон справки, то есть, фактически, была возможность выполнения других скриптов при открытом CHM-файле?
Locked