📄 readjnb.c
字号:
// Must read this value
iBytesRead = fid.Read(&iValue, sizeof(iValue)); // 0x06 0x00 0x00 0x00
if(cM7 != iValue)
{
printf("Error : 55\n");
LT_execute("type -a $OMRDJNB.Errors.general;");
return 55;
}
iBytesRead = fid.Read(&iValue, sizeof(iValue)); // Block decision
iBytesRead = fid.Read(&iIgnore, sizeof(iIgnore)); // Ignore this (duplicate column #?)
iBytesRead = fid.Read(&iIgnore, sizeof(iIgnore)); // Ignore this
iBytesRead = fid.Read(&iIgnore, sizeof(iIgnore)); // Ignore this (duplicate column #?)
iBytesRead = fid.Read(&iNumRows, sizeof(iNumRows)); // Indexed from zero
iBytesRead = fid.Read(&iIgnore, sizeof(iIgnore)); // Ignore this
iBytesRead = fid.Read(&iIgnore, sizeof(iIgnore)); // Ignore this
iPos = fid.GetPosition();
// Read the 'block' (see developer's documentation) of FILETYPE2 DATA_RECORD values
char wksname[25];
LT_get_str("%H", wksname, 25);
Dataset ThisCol(wksname, iThisCol);
ThisCol.SetSize(iNumRows + 1);
// Decision to read first or second block
// fid.Seek(iPos + 15, file::begin);
// iBytesRead = fid.Read(&cTag, 1);
// if(cTag < 15 || cTag == 22)
if(!(iValue & 16))
{
// Read the first block
// skip over column name - may be long name
fid.Seek(iPos + 15, file::begin);
iBytesRead = fid.Read(&cTag, 1);
if(cTag < 16)
{
iPos += 16;
fid.Seek(iPos, file::begin);
}
else
{
fid.Seek(iPos + 4, file::begin);
iBytesRead = fid.Read(&iValue, sizeof(iValue));
iPos += (16 + iValue);
fid.Seek(iPos, file::begin);
}
}
else
{
// Read the second block
iPos += 16 * (iNumRows + 2);
fid.Seek(iPos, file::begin);
}
for(iThisRow = 0; iThisRow <= iNumRows ; iThisRow++)
{
// Read individual rows of Type 2 data here
fid.Seek(iPos + 15, file::begin);
iBytesRead = fid.Read(&cTag, 1);
fid.Seek(iPos, file::begin); // 'backup'
switch(cTag)
{
case 18: // Ignore
case 21: // Ignore
iPos +=16;
fid.Seek(iPos, file::begin);
break;
case 22: // This is a double
iBytesRead = fid.Read(&dValue, sizeof(dValue));
ThisCol[iThisRow] = dValue;
iPos +=16;
fid.Seek(iPos, file::begin);
break;
case 32: // This is Long text
iBytesRead = fid.Read(&iIgnore, sizeof(iIgnore));
iBytesRead = fid.Read(&iLength, sizeof(iLength));
iPos += 16;
fid.Seek(iPos, file::begin);
if(iLength < 254)
{
if(iLength > 24)
{
// Must prepare Origin for this
LT_set_var("width", iLength);
LT_set_var("thiscol", iThisCol + 1);
LT_execute("wks.col$(thiscol).twidth = width;");
}
for(iIgnore = 0; iIgnore < iLength; iIgnore++)
{
// copy string
iBytesRead = fid.Read(&cChar, 1);
cBuffer[iIgnore] = cChar;
}
cBuffer[iIgnore] = 0;
// write the value
ThisCol.SetText(iThisRow, cBuffer);
iPos += iLength;
}
else
{
// it better be
}
break;
case 255: // Ignore
iPos +=16;
fid.Seek(iPos, file::begin);
break;
default: // Treat this as short text of length 'cTag'
if(cTag < 16)
{
for(iIgnore = 0; iIgnore < cTag ; iIgnore++)
{
iBytesRead = fid.Read(&cChar, 1);
cBuffer[iIgnore] = cChar;
}
cBuffer[iIgnore] = 0;
ThisCol.SetText(iThisRow, cBuffer);
iPos += 16;
fid.Seek(iPos, file::begin);
}
else
{
// who knows
}
} // End switch(cTag)
}
break;
default:
// Can't happen
} // End switch(iFileType) for DATA_RECORD
break;
case NAME_RECORD:
// Reading Name
// Must read this value
iBytesRead = fid.Read(&iValue, sizeof(iValue));
if(cM9 != iValue)
{
printf("Error : 61\n");
LT_execute("type -a $OMRDJNB.Errors.general;");
return 61;
}
// Must read this value
iBytesRead = fid.Read(&iValue, sizeof(iValue));
if(cM10 != iValue)
{
printf("Error : 62\n");
LT_execute("type -a $OMRDJNB.Errors.general;");
return 62;
}
// Must read this value
iBytesRead = fid.Read(&iValue, sizeof(iValue));
if(cM11 != iValue)
{
printf("Error : 63\n");
LT_execute("type -a $OMRDJNB.Errors.general;");
return 63;
}
switch(iFileType)
{
case FILETYPE1: // This is a FILETYPE1 NAME_RECORD
// This code does not handle Type1
break;
case FILETYPE2: // This is a FILETYPE2 NAME_RECORD
// Must read this value
iBytesRead = fid.Read(&iValue, sizeof(iValue));
if(cM15 != iValue)
{
printf("Error : 67\n");
LT_execute("type -a $OMRDJNB.Errors.general;");
return 67;
}
// Read an ASCIIZ value, then skip ahead
iPos = fid.GetPosition(); // mark here
for(iIgnore = 0; iIgnore <= 255; iIgnore ++)
{
iBytesRead = fid.Read(&cChar, 1);
cBuffer[iIgnore] = cChar;
if(cChar == 0) iIgnore = 255;
}
iPos += 256;
fid.Seek(iPos, file::begin);
// Must read this value
iBytesRead = fid.Read(&iValue, sizeof(iValue));
if(cM16 != iValue)
{
printf("Error : 68\n");
LT_execute("type -a $OMRDJNB.Errors.general;");
return 68;
}
// Must read this value
iBytesRead = fid.Read(&iValue, sizeof(iValue));
if(cM17 != iValue)
{
printf("Error : 69\n");
LT_execute("type -a $OMRDJNB.Errors.general;");
return 69;
}
// Read which column this is (indexed from zero)
iBytesRead = fid.Read(&iThisCol, sizeof(iThisCol));
// and set the label
LT_set_var("thiscol", iThisCol);
LT_set_str("%N", cBuffer);
LT_execute("wks.col$(thiscol+1).label$ = %N;");
break;
default:
// This can't happen
} // End switch(iFileType)
break;
case EOF_RECORD:
// Reading EOF
iStatus = 0;
break;
default:
iStatus = 41;
printf("%u\n",*piRecordType);
printf("Error : 41\n");
LT_execute("type -a $OMRDJNB.Errors.general;");
} // End switch(*piRecordType)
iLastPos += *piOffset;
if(iLastPos >= iFileSize)
{
iDone = 1;
}
else
{
fid.Seek(iLastPos, file::begin);
iBytesRead = fid.Read(&cChar, 1); // This is the Record Type
*piRecordType = (uint) cChar;
*piRecordType = *piRecordType & 255;
iBytesRead = fid.Read(&cChar, 1); // This we assume is OK
iBytesRead = fid.Read(&cChar, 1); // This we assume is OK
iBytesRead = fid.Read(&cChar, 1); // This we assume is OK
iBytesRead = fid.Read(piOffset, sizeof(uint));
}
}
LT_execute("wks.labels();");
return 0;
}
// The filter function versions
int ImportJNB(Page& pgTarget, TreeNode& trFilter, LPCSTR lpcszFile, int nFile)
{
double dResult;
string strWksName;
if(pgTarget.GetType() == EXIST_WKS)
{
pgTarget.GetName(strWksName);
}
else
{
WorksheetPage pg;
pg.Create("origin.otp", CREATE_VISIBLE);
pg.GetName(strWksName);
}
LT_set_str("%B", strWksName);
LT_execute("win -a %B;");
LT_set_str("%A", lpcszFile);
LT_execute("result = run.section(ordjnb,main);");
LT_get_var("result", &dResult);
return 0;
}
int ImportSPW(Page& pgTarget, TreeNode& trFilter, LPCSTR lpcszFile, int nFile)
{
string strFileName;
string strPathName;
double dResult;
string strWksName;
if(pgTarget.GetType() == EXIST_WKS)
{
pgTarget.GetName(strWksName);
}
else
{
WorksheetPage pg;
pg.Create("origin.otp", CREATE_VISIBLE);
pg.GetName(strWksName);
}
// Old LabTalk function requires Path in %B and filename in %A
LT_set_str("%B", strWksName);
LT_execute("win -a %B;");
strFileName = GetFileName(lpcszFile);
strPathName = GetFilePath(lpcszFile);
LT_set_str("%A", strFileName);
LT_set_str("%B", strPathName);
LT_execute("result = run.section(appfile,SPWIN);");
LT_get_var("result", &dResult);
return 0;
}
int ImportSPD(Page& pgTarget, TreeNode& trFilter, LPCSTR lpcszFile, int nFile)
{
string strFileName;
string strPathName;
double dResult;
string strWksName;
if(pgTarget.GetType() == EXIST_WKS)
{
pgTarget.GetName(strWksName);
}
else
{
WorksheetPage pg;
pg.Create("origin.otp", CREATE_VISIBLE);
pg.GetName(strWksName);
}
// Old LabTalk function requires Path in %B and filename in %A
LT_set_str("%B", strWksName);
LT_execute("win -a %B;");
strFileName = GetFileName(lpcszFile);
strPathName = GetFilePath(lpcszFile);
LT_set_str("%A", strFileName);
LT_set_str("%B", strPathName);
LT_execute("result = run.section(appfile,SPDOS);");
LT_get_var("result", &dResult);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -