> John,
>
[quoted text clipped - 87 lines]
> }
>
<snip for brevity>
I couldn't agree more. Well said!
First of all, thanks for your help. Maybe this will help clear some
things up.
>>>> What should s_Convert_Array actually do?
below is a representation of an array recieved from 4D
element 1 = "774774322333999666644333322555885000000666374446666311"
element 2 = "IIIIIIIIIIII000000000000000000000000000000000000000000"
element 3 = "AAAA55333633352444B99420000HHHHHHH00333463333114555855"
element 4 = "33333311111144433000PPPP000000000000000333330033888555"
element 5 = "5557742220006666631110000000000000000000KKKKKKKK000000"
element 6 = "777774533774111111111133222422222000000666693335555544"
element 7 = "666330666552444441322222000000000000333333666661777430"
element 8 = "333552666685522200000000000555552000000555584777555885"
element 9 = "333330555550111143522333444552222000000333111111444441"
element 10 = "555552333441333220000000666330000000000477774111222222"
element 11 = "222221544441666330333330000333330000000222222111666663"
element 12 = "333330111111433330333441111111000000000555330000777774"
Using the difficulty as 9 the following array is returned by the 4D
plugin (9 is subtracted from the ascii value of each position in all
12 elements)
element 1 = "000000000000000000000000000000000000000000000000000000"
element 2 = "999999999999000000000000000000000000000000000000000000"
element 3 = "111100000000000000200000000888888800000000000000000000"
element 4 = "00000000000000000000GGGG000000000000000000000000000000"
element 5 = "0000000000000000000000000000000000000000BBBBBBBB000000"
element 6 = "000000000000000000000000000000000000000000000000000000"
element 7 = "000000000000000000000000000000000000000000000000000000"
element 8 = "000000000000000000000000000000000000000000000000000000"
element 9 = "000000000000000000000000000000000000000000000000000000"
element 10 = "000000000000000000000000000000000000000000000000000000"
element 11 = "000000000000000000000000000000000000000000000000000000"
element 12 = "000000000000000000000000000000000000000000000000000000"
using the same array at the beginning and a difficulty of 2 the
following array is returned:
element 1 = "552552100111777444422111100333663000000444152224444100"
element 2 = "GGGGGGGGGGGG000000000000000000000000000000000000000000"
element 3 = "888833111411130222977200000FFFFFFF00111241111002333633"
element 4 = "11111100000022211000NNNN000000000000000111110011666333"
element 5 = "3335520000004444410000000000000000000000IIIIIIII000000"
element 6 = "555552311552000000000011000200000000000444471113333322"
element 7 = "444110444330222220100000000000000000111111444440555210"
element 8 = "111330444463300000000000000333330000000333362555333663"
element 9 = "111110333330000021300111222330000000000111000000222220"
element 10 = "333330111220111000000000444110000000000255552000000000"
element 11 = "000000322220444110111110000111110000000000000000444441"
element 12 = "111110000000211110111220000000000000000333110000555552"
>>>>>>why the two nested while loops?
As an inexperienced C "hacker" I was not able to get FOR loops to work
so I went with the WHILE loops and my own counter. I would rather use
FOR loops.
>>>>>you've been warned :-)
Yes, I know. I'm just trying to hack my way through this. I'm
working on it.
> - caution with the sizeof(DayArray ). DayArray is of type PA_Variable,
> and this:http://www.4d.com/docs/CMU/CMU84858.HTMtells me that that
> is a struct containing a union - not suited to determine how many
> characters are in that array.
Should I send the array length as another parameter? It will always
be 54 characters long with varying numbers of elements. Can't I just
make that assumption in the C code?
> 4D seems to have invented their own type system here, and you'll have
> to check their documentation on how to access it - as you're already
[quoted text clipped - 3 lines]
> - To convert a character of type '0'-'9', 'A'-'F' to a number value
> ranging from 0 to 15, there's a few approaches you can take.
I don't want to use hex values. I would like to stick to the ascii
values because I may be using other letters of the alphabet. That
gives me 36 different values (26 alpha and 10 numbers) instead of just
16.
John Mosby - 10 Feb 2010 04:05 GMT
Below is new code that actually compiles in XCode with a warning on
one line near the bottom. This is when the return array is assigned.
I don't have any idea what the warning means or how to correct the
problem.
/*
--------------------------------------------------------------------------------
#
# 4DPlugin.c
# source generated by 4D Plugin Wizard
# Project : new Project
# author : subaru
# 1/29/10
#
# This plugin should recieve two variable from the main 4D program.
#
# The first variable from 4D --------------
# One will be an array of length 54 composed of
# characters (0-9 and A-Z). Each element represents a schedule day.
Each character in the element represents a
# 10 minute block of time in the schedule. When the character is 0
(zero) there is nothing scheduled for that time.
# The difficulty of the the 10 minute time block increases as the
ascii value of the character that represents it
# increases in value from 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,..... etc.
#
# The second variable from 4D --------------
# This variable will be an integer value that represents the
difficulty of the new appointment.
# This value should be subtracted from the ascii value of the
character that represents each 10 minute
# time block. The harder the new appointment the smaller the value
of the variable for the difficulty.
#
--------------------------------------------------------------------------------
*/
#include "4DPluginAPI.h"
#include "4DPlugin.h"
void PluginMain( long selector, PA_PluginParameters params )
{
switch( selector )
{
// --- schedule Plugin
case 1 :
s_Convert_Array( params );
break;
}
}
// -------------------------------- schedule Plugin
-------------------------------
void s_Convert_Array( PA_PluginParameters params )
{
PA_Variable DayArray; //an array of characters of length 54 from 4d
short Difficulty; //an interger denoting difficulty of an
appointment
PA_Variable FinishedArray; // completed array returned to 4D
char returnValue[256];
DayArray = PA_GetVariableParameter( params, 1 );
Difficulty = PA_GetShortParameter( params, 2 );
// --- write the code of s_Convert_Array here...
{
int counter = 0;
int array_size = sizeof(DayArray);
int Day_Difficulty_AsciiValue; //used to hold one character
int slot_number;
char slot_char;
while (counter < array_size) //array_size should be the number of
elements of array DayArray
{
counter++;
int counter2 = 0;
while (counter2 < 55) //stepping through each character of DayArray
{
counter2++;
Day_Difficulty_AsciiValue =
(int)DayArray.uValue.fArray.fData[counter2]; // function to convert
a char in array to ascii value
if (Day_Difficulty_AsciiValue>=65) // is character a letter
slot_number = Day_Difficulty_AsciiValue-7-48;
else //character is a number
slot_number = Day_Difficulty_AsciiValue-48;
slot_number = slot_number - Day_Difficulty_AsciiValue;
if(slot_number<0)
slot_number = 0;
// convert the number to the characters 0-1,A-Z
// 48 is the number of ascii values before the numbers begin
// 7 is the numbere of unused ascii values between the numbers and
capital letters
if(slot_number>=10) //number will be converted to a character
slot_char = (char)(slot_number+48+7);
else // this will be a number
slot_char = (char)(slot_number+48);
FinishedArray.uValue.fArray.fData[counter2] = slot_char; // store
the character back into the original array to be passed to 4D
//WARNING WHEN COMPILING... THE ABOVE LINE HAS THE WARNING...
// warning: assignment makes pointer from integer without a cast
}
}
}
PA_SetVariableParameter( params, 3, FinishedArray, 1 );
PA_ReturnString( params, returnValue );
}
Gilles Kohl - 15 Feb 2010 07:28 GMT
>First of all, thanks for your help. Maybe this will help clear some
>things up.
>
>>>>> What should s_Convert_Array actually do?
>
>below is a representation of an array recieved from 4D
An example isn't of much use here - what is the _intention_ of the
routine? What is the purpose you want to achieve - why do you need a
plug-in?
As far as I can tell you're getting an array of time slot priorities
and a "difficulty", and somehow subtract the latter from the former, I
find it hard to understand why the 4D programmers left this as an
exercise for the user?
>element 1 = "774774322333999666644333322555885000000666374446666311"
>element 2 = "IIIIIIIIIIII000000000000000000000000000000000000000000"
[quoted text clipped - 12 lines]
>plugin (9 is subtracted from the ascii value of each position in all
>12 elements)
IIRC, if the subtraction would go below '0', the result is replaced by
'0'? How high can "difficulty" go? Is it an actual value, or is it
following this same strange "digits, then letters" encoding scheme?
[snip]
>>>>>>>why the two nested while loops?
>As an inexperienced C "hacker" I was not able to get FOR loops to work
>so I went with the WHILE loops and my own counter. I would rather use
>FOR loops.
Example:
int dayCount = PA_GetArraySize(DayArray);
int day;
PA_Variable newDayArray = PA_CreateArray(dayCount);
// loop over all days
for(day = 0; day < dayCount; day++) {
// get current element
PA_Variable currentDay =
PA_GetArrayElementAtIndex(DayArray, day);
int characterCount = PA_GetArraySize(currentElement);
PA_Variable newDay = PA_CreateArray(characterCount);
// loop over characters
for(i = 0; i < characterCount; i++) {
char prio = PA_GetArrayElementAtIndex(currentDay, i);
prio = ComputeNewPrio(prio, difficulty);
PA_SetArrayElementAtIndex(newDay, i, prio);
}
SetArrayElementAtIndex(newDayArray, day, newDay);
}
Most of the PA_xxx routines are of my invention - they illustrate the
way you'll probably have to handle interop with the 4D types. Check
their documentation. ComputeNewPrio is your logic to substract a
difficulty value from a character.
>>>>>>you've been warned :-)
>Yes, I know. I'm just trying to hack my way through this. I'm
[quoted text clipped - 8 lines]
>be 54 characters long with varying numbers of elements. Can't I just
>make that assumption in the C code?
That depends on how "cast in stone" that constant is. Could it change
if the user configured another work day, e.g. from 8am to 8pm?
> FinishedArray.uValue.fArray.fData[counter2] = slot_char; // store
> the character back into the original array to be passed to 4D
> //WARNING WHEN COMPILING... THE ABOVE LINE HAS THE WARNING...
> // warning: assignment makes pointer from integer without a cast
AFAICT without knowing the 4D types, you're mixing levels of
indirection here - you have two-dimensional data (elements or lines or
strings, whatever you want to call them, and characters, difficulties
or priorities. You even have two nested loops to iterate over the
characters in the elements.
But you never actually use your first "counter" except to initialize
and increment it! Which means that you're not really accessing
characters at all - what you think is a character is probably a
pointer to the start of the array element.
Also, note that you're not handling 54, but 55 elements in your outer
loop.
I'm afraid you won't be able to "cheat" this. You'll need to learn the
basics of C, read the 4D interop docs, and also spend more time
_thinking_ about your problem before you start typing - the above two
problems have nothing to do with being unfamiliar with C.
Regards,
Gilles.